-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LLDB] Add empty Microsoft ABI language runtime #168941
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
Open
Nerixyz
wants to merge
1
commit into
llvm:main
Choose a base branch
from
Nerixyz:feat/lldb-ms-abi-take3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,8 @@ class CPPLanguageRuntime : public LanguageRuntime { | |
|
|
||
| bool IsSymbolARuntimeThunk(const Symbol &symbol) override; | ||
|
|
||
| static bool ShouldUseMicrosoftABI(Process *process); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than returning a bool, can we have an enum for the C++ runtime ABIs and have this return either Itanium or Microsoft? |
||
|
|
||
| protected: | ||
| // Classes that inherit from CPPLanguageRuntime can see and modify these | ||
| CPPLanguageRuntime(Process *process); | ||
|
|
||
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
6 changes: 6 additions & 0 deletions
6
lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABI/CMakeLists.txt
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,6 @@ | ||
| add_lldb_library(lldbPluginCXXMicrosoftABI PLUGIN | ||
| MicrosoftABILanguageRuntime.cpp | ||
|
|
||
| LINK_LIBS | ||
| lldbPluginCPPRuntime | ||
| ) |
71 changes: 71 additions & 0 deletions
71
lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABI/MicrosoftABILanguageRuntime.cpp
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,71 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MicrosoftABILanguageRuntime.h" | ||
|
|
||
| #include "lldb/Core/PluginManager.h" | ||
| #include "lldb/Target/Process.h" | ||
|
|
||
| using namespace lldb; | ||
| using namespace lldb_private; | ||
|
|
||
| LLDB_PLUGIN_DEFINE_ADV(MicrosoftABILanguageRuntime, CXXMicrosoftABI) | ||
|
|
||
| char MicrosoftABILanguageRuntime::ID = 0; | ||
|
|
||
| void MicrosoftABILanguageRuntime::Initialize() { | ||
| PluginManager::RegisterPlugin(GetPluginNameStatic(), | ||
| "Microsoft ABI for the C++ language", | ||
| CreateInstance); | ||
| } | ||
|
|
||
| void MicrosoftABILanguageRuntime::Terminate() { | ||
| PluginManager::UnregisterPlugin(CreateInstance); | ||
| } | ||
|
|
||
| LanguageRuntime * | ||
| MicrosoftABILanguageRuntime::CreateInstance(Process *process, | ||
| lldb::LanguageType language) { | ||
| if (!ShouldUseMicrosoftABI(process)) | ||
| return nullptr; | ||
|
|
||
| if (!(language == eLanguageTypeC_plus_plus || | ||
| language == eLanguageTypeC_plus_plus_03 || | ||
| language == eLanguageTypeC_plus_plus_11 || | ||
| language == eLanguageTypeC_plus_plus_14)) | ||
| return nullptr; | ||
|
|
||
| return new MicrosoftABILanguageRuntime(process); | ||
| } | ||
|
|
||
| llvm::Expected<LanguageRuntime::VTableInfo> | ||
| MicrosoftABILanguageRuntime::GetVTableInfo(ValueObject &in_value, | ||
| bool check_type) { | ||
| return llvm::createStringError("Not implemented"); | ||
| } | ||
|
|
||
| bool MicrosoftABILanguageRuntime::GetDynamicTypeAndAddress( | ||
| ValueObject &in_value, lldb::DynamicValueType use_dynamic, | ||
| TypeAndOrName &class_type_or_name, Address &address, | ||
| Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) { | ||
| return false; | ||
| } | ||
|
|
||
| TypeAndOrName MicrosoftABILanguageRuntime::FixUpDynamicType( | ||
| const TypeAndOrName &type_and_or_name, ValueObject &static_value) { | ||
| return type_and_or_name; | ||
| } | ||
|
|
||
| bool MicrosoftABILanguageRuntime::CouldHaveDynamicValue(ValueObject &in_value) { | ||
| return false; | ||
| } | ||
|
|
||
| lldb::BreakpointResolverSP MicrosoftABILanguageRuntime::CreateExceptionResolver( | ||
| const lldb::BreakpointSP &bkpt, bool catch_bp, bool throw_bp) { | ||
| return nullptr; | ||
| } |
67 changes: 67 additions & 0 deletions
67
lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABI/MicrosoftABILanguageRuntime.h
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,67 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_MICROSOFTABI_MICROSOFTABILANGUAGERUNTIME_H | ||
| #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_MICROSOFTABI_MICROSOFTABILANGUAGERUNTIME_H | ||
|
|
||
| #include "lldb/Core/Value.h" | ||
| #include "lldb/Symbol/Type.h" | ||
| #include "lldb/Target/LanguageRuntime.h" | ||
|
|
||
| #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" | ||
|
|
||
| namespace lldb_private { | ||
|
|
||
| class MicrosoftABILanguageRuntime : public CPPLanguageRuntime { | ||
| public: | ||
| static void Initialize(); | ||
|
|
||
| static void Terminate(); | ||
|
|
||
| static lldb_private::LanguageRuntime * | ||
| CreateInstance(Process *process, lldb::LanguageType language); | ||
|
|
||
| static llvm::StringRef GetPluginNameStatic() { return "microsoft-abi"; } | ||
|
|
||
| static char ID; | ||
|
|
||
| bool isA(const void *ClassID) const override { | ||
| return ClassID == &ID || CPPLanguageRuntime::isA(ClassID); | ||
| } | ||
|
|
||
| static bool classof(const LanguageRuntime *runtime) { | ||
| return runtime->isA(&ID); | ||
| } | ||
|
|
||
| llvm::Expected<LanguageRuntime::VTableInfo> | ||
| GetVTableInfo(ValueObject &in_value, bool check_type) override; | ||
|
|
||
| bool GetDynamicTypeAndAddress(ValueObject &in_value, | ||
| lldb::DynamicValueType use_dynamic, | ||
| TypeAndOrName &class_type_or_name, | ||
| Address &address, Value::ValueType &value_type, | ||
| llvm::ArrayRef<uint8_t> &local_buffer) override; | ||
|
|
||
| TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, | ||
| ValueObject &static_value) override; | ||
|
|
||
| bool CouldHaveDynamicValue(ValueObject &in_value) override; | ||
|
|
||
| llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } | ||
|
|
||
| lldb::BreakpointResolverSP | ||
| CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, | ||
| bool throw_bp) override; | ||
|
|
||
| private: | ||
| MicrosoftABILanguageRuntime(Process *process) : CPPLanguageRuntime(process) {} | ||
| }; | ||
|
|
||
| } // namespace lldb_private | ||
|
|
||
| #endif |
Oops, something went wrong.
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.
How does this distinguish whether the target process to be debugged is mingw or msvc style? Does this in the end just determine the style based on which flavour LLDB itself was built as?
Note that one process may include multiple DLLs that use both ABIs. (In particular, most mingw executables link in a bunch of MS DLLs that internally use their C++ ABI - even though we perhaps don't have debug info for them normally.)
And one may want to use a MSVC built LLDB for debugging mingw executables, or vice versa.
See 25c8a06 and 3c86789 for existing options that allow controlling which C++ ABI to use for interpreting things; these options allow controlling this on the level of each individual DLL. Can't the information from those preexisting options be used here, instead of inventing a new and less flexible approach?
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.
Right, this inherits the style LLDB was built as. The language runtime being tied to a process and language is too coarse for allowing mixed ABIs in different DLLs.
An alternative could be to handle both ABIs in the Itanium plugin (but rename it). So for dynamic types, it could check the module or determine the ABI based on the mangled symbol name. For exception breakpoints, all function names would need to be registered. Would that be a better idea?
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.
Hmm. I'm too unfamiliar with the LLDB aspects involved here to be able to have any clue about what you're suggesting (and how much extra complexity it would add) unfortunately... Also, can you give a quick high level explanation of which ABI aspects were covered by the existing switches added in 25c8a06, compared with what aspects of debugging this newly added code covers?
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.
If I understand correctly, then the changes in 25c8a06 mostly affected how the clang AST is created for modules.
By adding a language runtime that supports the MS ABI, I'm trying to add the capability to downcast references to a base class when using virtual inheritance and to break when C++ exceptions are thrown.
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 see - thanks for the explanation! So whichever way we deal with this, the old option for switching mode for the Clang AST should keep working to the extent it did before. Also CC @alvinhochun.
If it is possible to handle this in a more granular way (tied either to the same options as above) then that's certainly very much appreciated, but I guess it's not a blocker. I'd leave that judgement up to you, if you feel it'd be doable or if it'd be too much mess for a potentially uncommon case.
Btw, I occasionally try to get the LLDB tests running in mingw mode as well. I haven't got that finished up to a state where all tests pass, I'm currently at around 16 tests failing and 1 unexpectedly passing, but haven't had much time to devote to it lately.
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 do want to keep LLDB's ability to debug mixed DLLs from different ABIs simultaneously. Having separate plugins for each ABI won't work here (I think?), because they'd be tied to the same language.
Currently,
ItaniumABILanguageRuntimeinherits fromCPPLanguageRuntime. What about moving the methods from the Itanium ABI to the C++ language runtime plugin?GetDynamicTypeAndAddressandGetVTableInfowould then check for the value's module and branch based on that (to account for 25c8a06). @JDevlieghere do you have any thoughts on this?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 think what you're suggesting is the most pragmatic solution. The alternative is detangling the two and everywhere where we obtain a language runtime today, you would have to specify a language and an ABI and the ABI would be tied (and potentially shared) across modules. I think that's probably a lot of work for little benefit, so I'm fine with going with the more pragmatic approach.