<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - SBValue.GetNumChildren() returns wrong value for double indirections"
   href="https://bugs.llvm.org/show_bug.cgi?id=45988">45988</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SBValue.GetNumChildren() returns wrong value for double indirections
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jarin@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
```</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>