-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows lldb to work correctly if using the `-serialize-debugging-options` `swiftc` flag.
- Loading branch information
1 parent
f510cd2
commit f595e70
Showing
76 changed files
with
5,134 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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
131 changes: 131 additions & 0 deletions
131
examples/ios_app/test/fixtures/bwb.xcodeproj/rules_xcodeproj/swift_debug_settings.py
This file contains 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,131 @@ | ||
#!/usr/bin/python3 | ||
|
||
"""An lldb module that registers a stop hook to set swift settings.""" | ||
|
||
import lldb | ||
|
||
_BUNDLE_EXTENSIONS = [ | ||
".app", | ||
".appex", | ||
".bundle", | ||
".framework", | ||
".xctest", | ||
] | ||
|
||
_SETTINGS = { | ||
"x86_64-apple-ios15.0.0-simulator Example.app/Example_ExecutableName" : { | ||
"clang" : "-iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -I \"CoreUtilsObjC\" -I \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC/CoreUtilsObjC.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Utils/Utils.swift.modulemap\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all", | ||
"frameworks" : [ | ||
|
||
], | ||
"includes" : [ | ||
|
||
] | ||
}, | ||
"x86_64-apple-ios15.0.0-simulator ExampleObjcTests.xctest/ExampleObjcTests" : { | ||
"clang" : "-iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all -DAWESOME -iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -I \"CoreUtilsObjC\" -I \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC/CoreUtilsObjC.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Utils/Utils.swift.modulemap\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all", | ||
"frameworks" : [ | ||
|
||
], | ||
"includes" : [ | ||
|
||
] | ||
}, | ||
"x86_64-apple-ios15.0.0-simulator ExampleTests.xctest/ExampleTests" : { | ||
"clang" : "-iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -I \"CoreUtilsObjC\" -I \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC/CoreUtilsObjC.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Utils/Utils.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/TestingUtils/TestingUtils.swift.modulemap\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all -DAWESOME -iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all -DAWESOME -iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -I \"CoreUtilsObjC\" -I \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC/CoreUtilsObjC.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Utils/Utils.swift.modulemap\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all", | ||
"frameworks" : [ | ||
|
||
], | ||
"includes" : [ | ||
"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Example", | ||
"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/TestingUtils" | ||
] | ||
}, | ||
"x86_64-apple-ios15.0.0-simulator ExampleUITests.xctest/ExampleUITests" : { | ||
"clang" : "-iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all -iquote \".\" -iquote \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin\" -I \"CoreUtilsObjC\" -I \"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/CoreUtilsObjC/CoreUtilsObjC.swift.modulemap\" -fmodule-map-file=\"$(BAZEL_OUT)/ios-x86_64-min15.0-applebin_ios-ios_x86_64-dbg-ST-a0d0e3b8f217/bin/Utils/Utils.swift.modulemap\" -O0 -DDEBUG=1 -fstack-protector -fstack-protector-all", | ||
"frameworks" : [ | ||
|
||
], | ||
"includes" : [ | ||
|
||
] | ||
} | ||
} | ||
|
||
_FALLBACK_KEYS = { | ||
"x86_64-apple-ios-simulator Example.app/Example_ExecutableName" : "x86_64-apple-ios15.0.0-simulator Example.app/Example_ExecutableName", | ||
"x86_64-apple-ios-simulator ExampleObjcTests.xctest/ExampleObjcTests" : "x86_64-apple-ios15.0.0-simulator ExampleObjcTests.xctest/ExampleObjcTests", | ||
"x86_64-apple-ios-simulator ExampleTests.xctest/ExampleTests" : "x86_64-apple-ios15.0.0-simulator ExampleTests.xctest/ExampleTests", | ||
"x86_64-apple-ios-simulator ExampleUITests.xctest/ExampleUITests" : "x86_64-apple-ios15.0.0-simulator ExampleUITests.xctest/ExampleUITests" | ||
} | ||
|
||
def __lldb_init_module(debugger, _internal_dict): | ||
# Register the stop hook when this module is loaded in lldb | ||
debugger.HandleCommand( | ||
"target stop-hook add -P swift_debug_settings.StopHook", | ||
) | ||
|
||
def _get_relative_executable_path(module): | ||
for extension in _BUNDLE_EXTENSIONS: | ||
prefix, _, suffix = module.rpartition(extension) | ||
if prefix: | ||
return prefix.split("/")[-1] + extension + suffix | ||
return module.split("/")[-1] | ||
|
||
class StopHook: | ||
"An lldb stop hook class, that sets swift settings for the current module." | ||
|
||
def __init__(self, _target, _extra_args, _internal_dict): | ||
pass | ||
|
||
def handle_stop(self, exe_ctx, _stream): | ||
"Method that is called when the user stops in lldb." | ||
target_triple = exe_ctx.target.GetTriple() | ||
module = exe_ctx.frame.module.file.__get_fullpath__() | ||
executable_path = _get_relative_executable_path(module) | ||
key = f"{target_triple} {executable_path}" | ||
|
||
settings = _SETTINGS.get(key) | ||
if not settings: | ||
fallback_key = _FALLBACK_KEYS.get(key) | ||
if fallback_key: | ||
settings = _SETTINGS.get(fallback_key) | ||
|
||
if settings: | ||
frameworks = " ".join([ | ||
f'"{path}"' | ||
for path in settings["frameworks"] | ||
]) | ||
if frameworks: | ||
lldb.debugger.HandleCommand( | ||
f"settings set -- target.swift-framework-search-paths {frameworks}", | ||
) | ||
else: | ||
lldb.debugger.HandleCommand( | ||
"settings clear target.swift-framework-search-paths", | ||
) | ||
|
||
includes = " ".join([ | ||
f'"{path}"' | ||
for path in settings["includes"] | ||
]) | ||
if includes: | ||
lldb.debugger.HandleCommand( | ||
f"settings set -- target.swift-module-search-paths {includes}", | ||
) | ||
else: | ||
lldb.debugger.HandleCommand( | ||
"settings clear target.swift-module-search-paths", | ||
) | ||
|
||
clang = settings["clang"] | ||
if clang: | ||
lldb.debugger.HandleCommand( | ||
f"settings set -- target.swift-extra-clang-flags '{clang}'", | ||
) | ||
else: | ||
lldb.debugger.HandleCommand( | ||
"settings clear target.swift-extra-clang-flags", | ||
) | ||
|
||
return True |
This file contains 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
Oops, something went wrong.