Skip to content

[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

Closed

Conversation

dianqk
Copy link

@dianqk dianqk commented Jul 29, 2023

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

Copy link

@kastiglione kastiglione left a 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)

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)

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.

Copy link
Author

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.

Comment on lines +24 to +27
else:
symbol = symbolContext.GetSymbol()
self.assertIsNotNone(symbol)
instructions = list(symbol.GetInstructions(target))

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Author

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.

Comment on lines +31 to +33
control_flow_kind = inst.GetControlFlowKind(target)
if control_flow_kind == lldb.eInstructionControlFlowKindOther:
continue

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?

Copy link
Author

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.

@dianqk
Copy link
Author

dianqk commented Aug 2, 2023

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. SILDebugScope as a key may not be correct.

I'll debug it later.

@dianqk
Copy link
Author

dianqk commented Aug 5, 2023

I found the problem and I tried to submit a patch. https://reviews.llvm.org/D157184

@dianqk dianqk closed this Aug 5, 2023
@dianqk dianqk deleted the get-instuctions-from-symbol branch August 5, 2023 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants