Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lldb/source/ValueObject/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,8 +2138,22 @@ void ValueObject::GetExpressionPath(Stream &s,

ValueObject *parent = GetParent();

if (parent)
if (parent) {
parent->GetExpressionPath(s, epformat);
const CompilerType parentType = parent->GetCompilerType();
if (parentType.IsPointerType() &&
parentType.GetPointeeType().IsArrayType(nullptr, nullptr, nullptr)) {
// When the parent is a pointer to an array, then we have to:
// - follow the expression path of the parent with "[0]"
// (that will indicate dereferencing the pointer to the array)
// - and then follow that with this ValueObject's name
// (which will be something like "[i]" to indicate
// the i-th element of the array)
s.PutCString("[0]");
s.PutCString(GetName().GetCString());
return;
}
}

// if we are a deref_of_parent just because we are synthetic array members
// made up to allow ptr[%d] syntax to work in variable printing, then add our
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/python_api/value/get_expr_path/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C_SOURCES := main.c

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class ValueAPIGetExpressionPath(TestBase):
def test(self):
self.build()

_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "Break at this line", lldb.SBFileSpec("main.c")
)
frame = thread.GetFrameAtIndex(0)

self.assertEqual(frame.FindVariable("foo").get_expr_path(), "foo")
for i in range(2):
self.assertEqual(
frame.FindVariable("foo").GetChildAtIndex(i).get_expr_path(),
f"foo[{i}]",
)
for j in range(3):
self.assertEqual(
frame.FindVariable("foo")
.GetChildAtIndex(i)
.GetChildAtIndex(j)
.get_expr_path(),
f"foo[{i}][{j}]",
)
for k in range(4):
self.assertEqual(
frame.FindVariable("foo")
.GetChildAtIndex(i)
.GetChildAtIndex(j)
.GetChildAtIndex(k)
.get_expr_path(),
f"foo[{i}][{j}][{k}]",
)
self.assertEqual(frame.FindVariable("bar").get_expr_path(), "bar")
for j in range(3):
self.assertEqual(
frame.FindVariable("bar").GetChildAtIndex(j).get_expr_path(),
f"bar[0][{j}]",
)
for k in range(4):
self.assertEqual(
frame.FindVariable("bar")
.GetChildAtIndex(j)
.GetChildAtIndex(k)
.get_expr_path(),
f"bar[0][{j}][{k}]",
)
5 changes: 5 additions & 0 deletions lldb/test/API/python_api/value/get_expr_path/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int main() {
int foo[2][3][4];
int (*bar)[3][4] = foo;
return 0; // Break at this line
}
Loading