-
Notifications
You must be signed in to change notification settings - Fork 339
[lldb] If the function cannot be found, use the symbol to get instructions. #7114
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
[lldb] If the function cannot be found, use the symbol to get instructions. #7114
Conversation
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.
thanks for working on this @dianqk
@@ -15,11 +15,25 @@ def test(self): | |||
target, _, thread, _ = lldbutil.run_to_source_breakpoint(self, "await f()", src) | |||
self.assertEqual(thread.frame[0].function.mangled, "$s1a5entryO4mainyyYaFZ") | |||
|
|||
function = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_")[0].function | |||
instructions = list(function.GetInstructions(target)) | |||
sym_ctx_list = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_", lldb.eFunctionNameTypeAuto) |
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.
eFunctionNameTypeAuto
is effectively the default parameter value, so it seems it can be left off.
instructions = list(function.GetInstructions(target)) | ||
sym_ctx_list = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_", lldb.eFunctionNameTypeAuto) | ||
self.assertEquals(sym_ctx_list.GetSize(), 1) | ||
symbolContext = sym_ctx_list.GetContextAtIndex(0) |
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.
for consistency, could you name this symbol_context
or symbol_ctx
, thanks.
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.
Sorry, my mistake.
I will update if this PR is still needed.
else: | ||
symbol = symbolContext.GetSymbol() | ||
self.assertIsNotNone(symbol) | ||
instructions = list(symbol.GetInstructions(target)) |
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 seems like the crux of the change, is that correct? Does this mean the test is being run without debug info? Or does it mean that even with debug info, somehow GetFunction
returns None
? If the reason for this else
case is understood, then could you add a comment explaining?
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.
Yes.
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 may know what the problem is. If I understand correctly, GetFunction
is taken from the debuginfo.
An incorrect DW_TAG_subprogram
caused the GetFunction
returns None
.
control_flow_kind = inst.GetControlFlowKind(target) | ||
if control_flow_kind == lldb.eInstructionControlFlowKindOther: | ||
continue |
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.
can you say why some instructions need to be skipped? Padding instructions?
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.
Yes. Getting from the symbol will include the padding directive at the end.
But I'm not clear on lldb's difference between GetSymbol and GetFunction.
I checked the generated debug information. I think that it generates debug message errors. 0x000000ef: DW_TAG_subprogram
DW_AT_low_pc (0x0000000100005d10)
DW_AT_high_pc (0x0000000100005d95)
DW_AT_frame_base (DW_OP_reg6 RBP)
- DW_AT_linkage_name ("$s1a5entryO4mainyyYaFZTQ0_")
- DW_AT_name ("main")
- DW_AT_decl_file ("/Users/dianqk/swift-project/llvm-project/lldb/test/API/lang/swift/async/stepping/step-in/task-switch/main.swift")
- DW_AT_decl_line (2)
- DW_AT_type (0x0000059a "$sytD")
- DW_AT_external (true)
+ DW_AT_specification (0x00000000000000b2 "$s1a5entryO4mainyyYaFZ")
+
0x0000010c: DW_TAG_formal_parameter
DW_AT_name ("self") I guess that this error is related to the following code.
I'll debug it later. |
I found the problem and I tried to submit a patch. https://reviews.llvm.org/D157184 |
In swiftlang/swift#67077, we split a method's debugging information into declaration and definition to address some compatibility issues under LTO.
However, a test case from lldb was found to have failed.
Sorry, I have no lldb related knowledge. This change may not be correct, so please let me know if there are any problems.
cc @kastiglione @adrian-prantl