-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add -prefix-serialized-debugging-options #39138
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
Conversation
See #17665 for a related earlier change. |
Thanks, I can definitelty see how this can be useful. Is my understanding correct that this effectively implements LLDB's |
Yes, that is the idea. I haven't thought about using the dSYM remapping dictionary yet, but I think that could be handled.
I considered it, but couldn't think of a case where you would want to use a different map for the swiftmodule debugging options than for the regular debugging info. Do you think this is worthwhile?
They are, this change will skip over the flags during serialization. It may make sense to pull this into a separate commit / PR.
That is a case I had not considered. The complexity of handling that would be part of the upcoming PR that modifies LLDB to provide the targets source-map to the |
I don't think there is a good reason to serialize -fdebug-prefix-map in a .swiftmodule, because the option is for debug info, which is irelevant when importing a serialized Swift AST. (Related side question: Is the debug prefix map applied to source locations inside the serialized AST in .swiftmodule that was compiled with -fdebug-prefix-map?)
LLDB has two mechanisms for remapping paths that operate at different layers:
Supporting (2) is tricky because in the expression context, we don't have a ready mapping between symbol file and imported Swift modules, so it can be tricky to discern which remapping dictionary to apply. However, I think that if you are trying to build a distributed build system, then properly supporting (2) is the way to go, because a properly implemented system where dsyms are automatically fitted with that e correct remapping dictionary can be completely transparent to the end-user. |
clang has |
I'm not 100% I follow, but the debug prefixes we are using are the ones passed via
Yes, I see your point. It seems a little messy to add yet another mapping flag for this (this would make 3 now I think) but how about
As far as our use case goes we do not need to support dSYMs or even apply inverse mappings, all paths except Xcode |
I would like to avoid duplicating functionality that already exists in LLDB in the Swift compiler, because it can lead to hard-to-debug issues. I think we could do the following: This patch is about remapping Clang options. Those options need to get passed to the Clang compiler instance that is owned by ClangImporter. ClangImporter is created in LLDB by SwiftASTContext. If we modified ClangImporter to take a callback for remapping compiler flags, we could set that to a function similar to SwiftASTContext::RemapClangImporterOptions(). LLDB would no longer manually call RemapClangImporterOptions(), it would get called through the callback. Then we only have a single implementation of path remapping, which is owned by LLDB, and it will tie in nicely with logging and make it much more transparent what's going on. |
Agreed.
It seems in both the Swift serialization path and LLDB we are getting
Then we could call this function in both the Swift serialization path and LLDB to handle |
5ef7928
to
cbf528f
Compare
I updated this to use a separate |
I think CompilerInvocation is supposed to store the result of having built a full compiler invocation so the callback might fit better into either a class that builds a CompilerInvocation, or into ClangImporter, who receives the extra args. I thought ClangImporter's constructor would be a natural place to put the callback because it's LLDB who is creating ClangImporter: |
IIUC I think what you are suggesting is that we would add a callback param as part of the constructor to the ClangImporter and then we feed the ClangImporter the unmapped args and when they are actually used internally by the ClangImporter it would call the callback function to do path fixup, is that the idea? I can see how that would work for the LLDB case, but for Swift we want the ClangImporter to keep using the existing unmodified paths, its only during serialization that we would want to remap the paths to have prefixes. Maybe I am not following 100% though. |
cbf528f
to
8cf7a46
Compare
To summarize an offline conversation. I was conflating two things here:
This PR deals with (1). My initial concern was that having an -fdebug option affect .swiftmodule files would be unexpected. However, there serialized paths are there primarily for the debugger, so I think I've come around to being okay with just unconditionally applying the prefix map to .swiftmodule serialized search paths, too. |
@artemcm @adrian-prantl just checking where we stand with this one, are further changes required or is this good for testing and merging? |
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.
This change makes sense and looks good to me.
auto Next = std::next(Arg); | ||
if (Next != E && | ||
StringRef(*Next).endswith("unextended-module-overlay.yaml")) { | ||
++Arg; | ||
continue; | ||
} | ||
} else if (arg.startswith("-fdebug-prefix-map=")) { |
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.
Please add a brief comment to explain why we skip this flag.
@swift-ci please test |
This commit adds a function to remap the clang arguments passed during compilation. This is intented to be shared across the Swift compiler and LLDB to apply path remapping for debug info paths.
This commit adds the `-prefix-serialized-debugging-options` flag, which is used to apply the debug prefix map to serialized debugging options embedded in the swiftmodule files.
This is intended to be used from LLDB to apply the remappings specified in target.source-map to remap any serialized Swiftmodule search paths that were prefixed using `-prefix-serialized-debugging-options`.
8cf7a46
to
49f37ab
Compare
@swift-ci please test |
Reverts #39138 This is causing a failure on Windows: https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019/6659/consoleText
This commit adds a new frontend flag that applies debug path prefixing to the paths serialized in swiftmodule files. This makes it possible to use swiftmodule files that have been built on different machines by applying the inverse map when debugging, in a similar fashion to source path prefixing. The inverse mapping in LLDB will be handled in a follow up PR. Second pass at #39138 Tests updated to handle windows path separators. This reverts commit f5aa95b.
Hi @rmaz, Thanks for this feature. As @adrian-prantl pointed,
Is this already supported by LLDB? I am testing debugger with For instance, if to take the sample project from this issue and to add You've mentioned that
was there a follow-up on this? |
Apologies, that one slipped off the radar, our use case requires no remapping as we prefix all the paths to be relative to the repo root. I can take a pass at adding remapping via the |
This commit adds a new frontend flag that applies debug path prefixing to the
paths serialized in swiftmodule files. This makes it possible to use swiftmodule
files that have been built on different machines by applying the inverse map
when debugging, in a similar fashion to source path prefixing.
The inverse mapping in LLDB will be handled in a follow up PR.