[Lldb-commits] [PATCH] D88483: Add possibility to get module from SBType
Ilya Bukonkin via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 20 14:08:45 PDT 2020
fallkrum added a comment.
In D88483#2342225 <https://reviews.llvm.org/D88483#2342225>, @jingham wrote:
> In D88483#2341538 <https://reviews.llvm.org/D88483#2341538>, @fallkrum wrote:
>
>> Thanks a lot Jim for explanations, now it makes sense to me.
>> Have one more question on class Type. Writing API test for the patch defined 2 functions like this:
>>
>> void *func1(int) {
>> return NULL;
>> }
>>
>> void *func2(int) {
>> return NULL;
>> }
>>
>> Tried to find function type using target.FindFirstType('func1') and got nothing as a result. Call to module.GetTypes().GetTypeAtIndex(0).GetName() contained:
>> "void *(int)". Looking through clang::Decls found out that clang::FunctionDecl is child of clang::ValueDecl and it finally became clear to me that "func1", "func2" are not types at all but simply symbols (variables?) of the same type "void *(int)". Therefore module where above 2 functions were declared contained only 1 type "void *(int)". Investigating how DWARFASTParser works noticed that it do generates 2 Type instances for 2 defined functions with m_name variable set to "func1", "func2" respectively and m_compiler_type referencing the same "void *(int)" (but not in it's string representation of course).
>> So the question is: Does class Type represents not only a type but also a variable (symbol or identifier, don't know how to name it correctly in this situation)?
>
> My understanding is that functions have a type but aren't types themselves. I'm not sure where you are seeing us make Type's for functions, can you say more about that?
I can describe how to see it really happens. Attached a compiled executable with debug info in a separate file. Defined only 1 function in function_type.c:
int main (int argc, const char * argv[]) {
return 0;
}
Steps:
1. launch lldb with executable from attachment (i do it from command line: lldb /path/to/function_type)
2. attach to lldb with another debugger.
3. in another debugger set breakpoint on Type constructor:
lldb_private::Type::Type(unsigned long long, lldb_private::SymbolFile*, lldb_private::ConstString, llvm::Optional<unsigned long long>, lldb_private::SymbolContextScope*, unsigned long long, lldb_private::Type::EncodingDataType, lldb_private::Declaration const&, lldb_private::CompilerType const&, lldb_private::Type::ResolveState, unsigned int)
(i set it slightly below, on "if (byte_size) {", on my version of sources line 154)
4. continue another debugger
5. in lldb with function_type target execute command:
lldb.target.GetModuleAtIndex(0).GetTypes().GetSize()
6. After several continuations it should stop inside Type constructor with input name = "main" and compiler_type for function type.
7. e compiler_type.GetTypeName() will give result:
"int (int, const char **)"
Hope this will help.
F13396272: function_type.zip <https://reviews.llvm.org/F13396272>
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88483/new/
https://reviews.llvm.org/D88483
More information about the lldb-commits
mailing list