Skip to content

Commit d23d90c

Browse files
authored
Merge pull request #7862 from Michael137/bugfix/lldb-loclist-cpp-member-to-20230725
[cherry-pick][stable/20230725] [lldb][Symbol] Make sure we decrement PC before checking location list
2 parents 8def20e + 8a451f5 commit d23d90c

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

lldb/source/Symbol/Variable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ bool Variable::LocationIsValidForFrame(StackFrame *frame) {
227227
// contains the current address when converted to a load address
228228
return m_location_list.ContainsAddress(
229229
loclist_base_load_addr,
230-
frame->GetFrameCodeAddress().GetLoadAddress(target_sp.get()));
230+
frame->GetFrameCodeAddressForSymbolication().GetLoadAddress(
231+
target_sp.get()));
231232
}
232233
}
233234
return false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
C_SOURCES := main.c
1+
CXX_SOURCES := main.cpp
22
CFLAGS_EXTRAS := -O1
33
include Makefile.rules

lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@
77

88

99
class LocationListLookupTestCase(TestBase):
10-
def setUp(self):
11-
# Call super's setUp().
12-
TestBase.setUp(self)
13-
14-
@skipIf(oslist=["linux"], archs=["arm"])
15-
def test_loclist(self):
16-
self.build()
10+
def launch(self) -> lldb.SBProcess:
1711
exe = self.getBuildArtifact("a.out")
18-
19-
# Create a target by the debugger.
2012
target = self.dbg.CreateTarget(exe)
2113
self.assertTrue(target, VALID_TARGET)
2214
self.dbg.SetAsync(False)
@@ -27,12 +19,32 @@ def test_loclist(self):
2719
self.assertTrue(process.IsValid())
2820
self.assertTrue(process.is_stopped)
2921

30-
# Find `main` on the stack, then
31-
# find `argv` local variable, then
32-
# check that we can read the c-string in argv[0]
22+
return process
23+
24+
def check_local_vars(self, process: lldb.SBProcess, check_expr: bool):
25+
# Find `bar` on the stack, then
26+
# make sure we can read out the local
27+
# variables (with both `frame var` and `expr`)
3328
for f in process.GetSelectedThread().frames:
34-
if f.GetDisplayFunctionName() == "main":
29+
frame_name = f.GetDisplayFunctionName()
30+
if frame_name is not None and frame_name.startswith("Foo::bar"):
3531
argv = f.GetValueForVariablePath("argv").GetChildAtIndex(0)
3632
strm = lldb.SBStream()
3733
argv.GetDescription(strm)
3834
self.assertNotEqual(strm.GetData().find("a.out"), -1)
35+
36+
if check_expr:
37+
process.GetSelectedThread().SetSelectedFrame(f.idx)
38+
self.expect_expr("this", result_type="Foo *")
39+
40+
@skipIf(oslist=["linux"], archs=["arm"])
41+
@skipIfDarwin
42+
def test_loclist_frame_var(self):
43+
self.build()
44+
self.check_local_vars(self.launch(), check_expr=False)
45+
46+
@skipIf(archs=no_match(["aarch64", "arm"]))
47+
@skipUnlessDarwin
48+
def test_loclist_expr(self):
49+
self.build()
50+
self.check_local_vars(self.launch(), check_expr=True)

lldb/test/API/functionalities/location-list-lookup/main.c

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <cstdio>
2+
#include <cstdlib>
3+
4+
void func(int in);
5+
6+
struct Foo {
7+
int x;
8+
[[clang::noinline]] void bar(char **argv);
9+
};
10+
11+
int main(int argc, char **argv) {
12+
Foo f{.x = 5};
13+
std::printf("%p\n", &f.x);
14+
f.bar(argv);
15+
return f.x;
16+
}
17+
18+
void Foo::bar(char **argv) {
19+
std::printf("%p %p\n", argv, this);
20+
std::abort(); /// 'this' should be still accessible
21+
}
22+
23+
void func(int in) { printf("%d\n", in); }

0 commit comments

Comments
 (0)