forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 344
Test cleanups #3399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adrian-prantl
merged 2 commits into
swiftlang:stable/20210726
from
adrian-prantl:test-cleanups
Oct 13, 2021
Merged
Test cleanups #3399
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
all: a.out dlopen_module | ||
all: libNewerTarget.dylib a.out dlopen_module | ||
|
||
SWIFT_SOURCES=main.swift | ||
SWIFTFLAGS_EXTRAS=-target x86_64-apple-macosx10.10 -Xfrontend -disable-target-os-checking -I$(BUILDDIR) | ||
LD_EXTRAS=-lNewerTarget -L$(BUILDDIR) | ||
|
||
include Makefile.rules | ||
|
||
# This test only works on macOS 10.11+. | ||
|
||
a.out: main.swift libNewerTarget.dylib | ||
$(SWIFTC) -sdk "$(SWIFTSDKROOT)" -target x86_64-apple-macosx10.10 -g -Onone $^ -lNewerTarget -L$(shell pwd) -o $@ $(SWIFTFLAGS) -I$(shell pwd) -Xfrontend -disable-target-os-checking | ||
ifneq "$(CODESIGN)" "" | ||
$(CODESIGN) -s - "$@" | ||
endif | ||
|
||
dlopen_module: main.m libNewerTarget.dylib | ||
$(CC) -framework Foundation $^ -mmacos-version-min=10.8 -o $@ $(CFLAGS) | ||
ifneq "$(CODESIGN)" "" | ||
$(CODESIGN) -s - "$@" | ||
endif | ||
dlopen_module: dlopen_module.m libNewerTarget.dylib | ||
$(MAKE) -f $(MAKEFILE_RULES) \ | ||
CXX= \ | ||
OBJC_SOURCES=dlopen_module.m \ | ||
EXE=dlopen_module \ | ||
LD_EXTRAS="-framework Foundation -mmacos-version-min=10.8" | ||
|
||
lib%.dylib: %.swift | ||
$(SWIFTC) -sdk "$(SWIFTSDKROOT)" -target x86_64-apple-macosx10.11 -g -Onone $^ -emit-library -module-name $(shell basename $< .swift) -emit-module -Xlinker -install_name -Xlinker @executable_path/$@ | ||
ifneq "$(CODESIGN)" "" | ||
$(CODESIGN) -s - "$@" | ||
endif | ||
$(MAKE) -f $(MAKEFILE_RULES) \ | ||
DYLIB_ONLY=YES \ | ||
DYLIB_NAME=$(patsubst lib%.dylib,%,$@) \ | ||
DYLIB_SWIFT_SOURCES=$(patsubst lib%.dylib,%.swift,$@) \ | ||
SWIFTFLAGS_EXTRAS="-target x86_64-apple-macosx10.11" | ||
|
||
clean:: | ||
rm -rf *.swiftmodule *.swiftdoc *.dSYM *~ lib*.dylib a.out dlopen_module *.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lldb/test/API/lang/swift/deployment_target/dlopen_module.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <Foundation/Foundation.h> | ||
#include <dlfcn.h> | ||
#include <libgen.h> | ||
#include <limits.h> | ||
|
||
@protocol FooProtocol | ||
- (void)f; | ||
@end | ||
|
||
int main(int argc, const char **argv) { | ||
char dylib[PATH_MAX]; | ||
strlcpy(dylib, dirname(argv[0]), PATH_MAX); | ||
strlcat(dylib, "/libNewerTarget.dylib", PATH_MAX); | ||
dlopen(dylib, RTLD_LAZY); | ||
Class<FooProtocol> fooClass = NSClassFromString(@"NewerTarget.Foo"); | ||
[[[fooClass alloc] init] f]; | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimingham I don't feel good about this change, but it was necessary. Is this supposed to work for a regex breakpoint in a dylib that is going to be dlopened later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this worked due to a freak accident before: main.swift main.o file replaced the main.m main.o and so the breakpoint was resolved at startup even though the dylib wasn't yet loaded?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work but it looks like there's a bug in the SBTarget bindings. This works:
But this, which should be equivalent, does not:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check that run_to_source_breakpoint does the right thing with the exe_module & file arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure this code is not using run_to_source_breakpoint correctly. The exe_name argument is the name of the module you are going to use to create the target. The
bkpt_module
argument is for the name of the module you are supposed to set the breakpoint in. If that's not specified, we set it in the main executable module.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. The test code you had above used a different version of BreakpointCreateBySourceRegex, not passing lists but a FileSpec for the file and a char * for the module name. That one does seem to work, and also doesn't require the module, only the file name:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So IIUC, this should fail at the point where you try to set the breakpoint in run_to_source_breakpoint with the error that the breakpoint has no locations, but if you changed run_to_source_breakpoint to take a parameter to turn off the test, this should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR
The overload of SBTarget::CreateBreakpointWithSourceRegex that takes a list of files & a list of modules doesn't work, but lldbutil.run_to_source_breakpoint doesn't use that one, it uses the one that takes on file and one module, and that one does work.
lldbutil.run_to_source_breakpoint asserts that the breakpoint have at least one location pre run, which won't be the case for your test. Probably best to fix that by adding a
has_locations_before_run
parameter torun_to_source_breakpoint
for the case where the breakpoint is expected to only take in a dynamically loaded library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason your fix works is because it DOESN'T check that
bpkt
has any locations when you set it. It would be better to fix that by fixing run_to_source_breakpoint.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like: