[lldb-dev] [Bug 45988] New: SBValue.GetNumChildren() returns wrong value for double indirections

via lldb-dev lldb-dev at lists.llvm.org
Mon May 18 22:47:03 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45988

            Bug ID: 45988
           Summary: SBValue.GetNumChildren() returns wrong value for
                    double indirections
           Product: lldb
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: lldb-dev at lists.llvm.org
          Reporter: jarin at google.com
                CC: jdevlieghere at apple.com, llvm-bugs at lists.llvm.org

SBValue::GetNumChildren seems to look through two pointer indirections, but
SBValue::GetChildAtIndex only through one.

If we have a value with pointer to a pointer to a struct, then GetNumChildren()
on that value will return the number of fields of the struct, but
GetChildAtIndex(0) will return the pointer to the struct and GetChildAtIndex(1)
will return the Invalid SBValue sentinel.

Repro:

```
$ cat a.cc
struct Inner
{ 
  int a;
  int b;
};

struct Outer
{ 
  Inner *inner;
};

int main()
{ 
  Inner inner{42, 56};
  Outer outer{&inner};
  return 0;  // break here
}

$ cat a.py
import lldb
import os

debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTargetWithFileAndTargetTriple("a.out",
"x86_64-pc-linux")
main_bp = target.BreakpointCreateByLocation("a.cc", 16)
process = target.LaunchSimple (None, None, os.getcwd())
thread = process.selected_thread
frame = thread.GetSelectedFrame()

print(frame.EvaluateExpression("&(outer.inner)").GetNumChildren())
print(frame.EvaluateExpression("&(outer.inner)").GetChildAtIndex(0))
print(frame.EvaluateExpression("&(outer.inner)").GetChildAtIndex(1))

$ python a.py
2
(Inner *) *$1 = 0x00007ffedf89e290
No value
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20200519/e1347e58/attachment.html>


More information about the lldb-dev mailing list