-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Fix SBThread::StepOverUntil for discontinuous functions #123046
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74d4363
[lldb] Fix SBThread::StepOverUntil for discontinuous functions
labath 160a68d
reformat
labath da52a02
feedback
labath b9fb108
compatibility with older GNU ld
labath cd3d787
..and with lld
labath a00392e
and format
labath b257017
Add GetRangeContainingLoadAddress
labath 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
134 changes: 134 additions & 0 deletions
134
lldb/test/API/functionalities/thread/step_until/TestStepUntilAPI.py
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,134 @@ | ||
| import lldb | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
|
|
||
| class StepUntilTestCase(TestBase): | ||
labath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
|
|
||
| self.main_source = "main.c" | ||
| self.main_spec = lldb.SBFileSpec(self.main_source) | ||
| self.less_than_two = line_number("main.c", "Less than 2") | ||
| self.greater_than_two = line_number("main.c", "Greater than or equal to 2.") | ||
| self.back_out_in_main = line_number("main.c", "Back out in main") | ||
| self.in_foo = line_number("main.c", "In foo") | ||
|
|
||
| def _build_dict_for_discontinuity(self): | ||
| return dict( | ||
| CFLAGS_EXTRAS="-funique-basic-block-section-names " | ||
| + "-ffunction-sections -fbasic-block-sections=list=" | ||
| + self.getSourcePath("function.list"), | ||
| LD_EXTRAS="-Wl,--section-ordering-file=" | ||
| + self.getSourcePath("symbol.order"), | ||
| ) | ||
|
|
||
| def _do_until(self, build_dict, args, until_line, expected_line): | ||
| self.build(dictionary=build_dict) | ||
| launch_info = lldb.SBLaunchInfo(args) | ||
| _, _, thread, _ = lldbutil.run_to_source_breakpoint( | ||
| self, "At the start", self.main_spec, launch_info | ||
| ) | ||
|
|
||
| self.assertSuccess( | ||
| thread.StepOverUntil(self.frame(), self.main_spec, until_line) | ||
| ) | ||
|
|
||
| self.runCmd("process status") | ||
|
|
||
| line = self.frame().GetLineEntry().GetLine() | ||
| self.assertEqual( | ||
| line, expected_line, "Did not get the expected stop line number" | ||
| ) | ||
|
|
||
| def _assertDiscontinuity(self): | ||
| target = self.target() | ||
| foo = target.FindFunctions("foo") | ||
| self.assertEqual(len(foo), 1) | ||
| foo = foo[0] | ||
|
|
||
| call_me = self.target().FindFunctions("call_me") | ||
| self.assertEqual(len(call_me), 1) | ||
| call_me = call_me[0] | ||
|
|
||
| foo_addr = foo.function.GetStartAddress().GetLoadAddress(target) | ||
| found_before = False | ||
| found_after = False | ||
| for range in call_me.function.GetRanges(): | ||
| addr = range.GetBaseAddress().GetLoadAddress(target) | ||
| if addr < foo_addr: | ||
| found_before = True | ||
| if addr > foo_addr: | ||
| found_after = True | ||
|
|
||
| self.assertTrue( | ||
| found_before and found_after, | ||
| "'foo' is not between 'call_me'" + str(foo) + str(call_me), | ||
| ) | ||
|
|
||
| def test_hitting(self): | ||
| """Test SBThread.StepOverUntil - targeting a line and hitting it.""" | ||
| self._do_until(None, None, self.less_than_two, self.less_than_two) | ||
|
|
||
| @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"]) | ||
| def test_hitting_discontinuous(self): | ||
| """Test SBThread.StepOverUntil - targeting a line and hitting it -- with | ||
| discontinuous functions""" | ||
| self._do_until( | ||
| self._build_dict_for_discontinuity(), | ||
| None, | ||
| self.less_than_two, | ||
| self.less_than_two, | ||
| ) | ||
| self._assertDiscontinuity() | ||
|
|
||
| def test_missing(self): | ||
| """Test SBThread.StepOverUntil - targeting a line and missing it by stepping out to call site""" | ||
| self._do_until( | ||
| None, ["foo", "bar", "baz"], self.less_than_two, self.back_out_in_main | ||
| ) | ||
|
|
||
| @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"]) | ||
| def test_missing_discontinuous(self): | ||
| """Test SBThread.StepOverUntil - targeting a line and missing it by | ||
| stepping out to call site -- with discontinuous functions""" | ||
| self._do_until( | ||
| self._build_dict_for_discontinuity(), | ||
| ["foo", "bar", "baz"], | ||
| self.less_than_two, | ||
| self.back_out_in_main, | ||
| ) | ||
| self._assertDiscontinuity() | ||
|
|
||
| def test_bad_line(self): | ||
| """Test that we get an error if attempting to step outside the current | ||
| function""" | ||
| self.build() | ||
| _, _, thread, _ = lldbutil.run_to_source_breakpoint( | ||
| self, "At the start", self.main_spec | ||
| ) | ||
| self.assertIn( | ||
| "step until target not in current function", | ||
| thread.StepOverUntil( | ||
| self.frame(), self.main_spec, self.in_foo | ||
| ).GetCString(), | ||
| ) | ||
|
|
||
| @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"]) | ||
| def test_bad_line_discontinuous(self): | ||
| """Test that we get an error if attempting to step outside the current | ||
| function -- and the function is discontinuous""" | ||
| self.build(dictionary=self._build_dict_for_discontinuity()) | ||
| _, _, thread, _ = lldbutil.run_to_source_breakpoint( | ||
| self, "At the start", self.main_spec | ||
| ) | ||
| self.assertIn( | ||
| "step until target not in current function", | ||
| thread.StepOverUntil( | ||
| self.frame(), self.main_spec, self.in_foo | ||
| ).GetCString(), | ||
| ) | ||
| self._assertDiscontinuity() | ||
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 @@ | ||
| !call_me |
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .text : { | ||
| *(.text.call_me) | ||
| *(.text.foo) | ||
| *(.text.call_me.call_me.__part.1) | ||
| *(.text.call_me.call_me.__part.2) | ||
| *(.text.call_me.call_me.__part.3) | ||
| } |
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.
Why isn't there an AddressRanges::ContainsLoadAddress? Seems silly to have to write this loop by hand.
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.
AddressRanges is a typedef for vector.
How about using
Block::GetRangeContainingLoadAddress(Function::GetAddressRanges just returns the data from the function Block) for this instead (see new version of the patch)? Other possibilities might be:ContainsLoadAddress(ArrayRef<AddressRange>, addr_t, 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.
It feels awkward to have to manually dial up the function block to see if an address exists in that function. I'd vote for
Function::GetRangeContainingLoadAddress- that just seems like something a Function should be able to tell you.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.
SG