<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/92450>92450</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Puzzling interaction between type summary and synthetic children provider
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          wolfpld
      </td>
    </tr>
</table>

<pre>
    I'm trying to add pretty printing to some types in my code. Let's say I have the following program:

```c++
struct A { int a; };

int main()
{
    A a = { 2 };
    int b = 0;
}
```

I also have the following python script:

```python
import lldb

def Summary(value, dict):
 return f"Value: {value.GetChildMemberWithName('a').GetValueAsUnsigned()}"

class Printer:
    def __init__(self, val, dict):
        self.val = val

    def update(self):
        self.a = self.val.GetChildMemberWithName('a').GetValueAsUnsigned()

    def num_children(self):
        return 1

    def get_child_index(self, name):
        return int(name.lstrip('[').rstrip(']'))

    def get_child_at_index(self, index):
        return self.val.CreateValueFromExpression(f'child', f'int v={self.a}; v')

def __lldb_init_module(debugger, dict):
    debugger.HandleCommand('type summary add -F pp.Summary -x A')
    debugger.HandleCommand('type synthetic add -l pp.Printer -x A')
```

If *only* the type summary is enabled, I get the following result, as expected:

```gdb
(lldb) command script import pp.py
(lldb) b a.cpp:6
Breakpoint 1: where = a.out`main + 11 at a.cpp:6:9, address = 0x0000000000001124
(lldb) r
Process 496203 launched: '/home/wolf/test/a.out' (x86_64)
Process 496203 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555124 a.out`main at a.cpp:6:9
   3 int main()
   4    {
   5        A a = { 2 };
-> 6        int b = 0;
   7    }
(lldb) p a
(A) Value: 2
(lldb)
```

If *only* the synthetic provider is enabled, I get the following result, as expected:

```gdb
(lldb) p a
(A)  (child = 2)
```

But if *both* type handlers are enabled, the value passed to the summary provider is no longer valid:

```gdb
(lldb) p a
(A) Value: 0
```

I don't understand what's happening here. I would expect both summary and synthetic providers to provide valid output even if both are enabled. The summary provider might print out useful data, such as vector's capacity, that's not really related to any of the children that may be synthesized.

The following example suggests that summary and synthetic providers are supposed to get along together:

https://github.com/llvm/llvm-project/blob/f42f57b52dd279e6ae19270d063aeb8d59e3f11c/lldb/examples/synthetic/gnu_libstdcpp.py#L18-L51

The following example shows that a summary provider should be able to use synthetic provider facilities to access the data:

https://github.com/llvm/llvm-project/blob/f42f57b52dd279e6ae19270d063aeb8d59e3f11c/lldb/examples/synthetic/libcxx.py#L156-L158

I have tested this with lldb 17.0.6 and 19.0.0git (https://github.com/llvm/llvm-project.git revision 9a7f54ba4878c4e66c99430b52d8c014ab7b2a03).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV11v67gR_TX0yyCCREmW9OAHJ163AW6LBbptHw1KHFtsKVEgKce-v74YSnac2LndiwWKGoED82N0zpkzQ0o4pw494orlzyzfLMToW2NXb0bvBy0XtZHn1SvjRQfenlV_AG9ASAmDRe_PMFjV-3nYmQ7Bnwd0oHroztAYiRF8Q8944cCJM7xCK44IvkXYG63NG20drDlY0bF0zeINiy_fy3j6axh_pr8w6rwdGw9rYMUzqN6DYOkzsGLD0ufb3TTVCdUzXjJezTPFvAQAYA0CWLoJcfiHADRL2-swH78HLjafkN0-8BWEduYhvbNvTQ-usWrwX5GcFs3Yu8FYD1rL-natxD38bew6Yc-Ml0ehR2T8BaRqPFG8BAaLfrQ97Bnn_wiL0qBW2BD9Cf1Lq7T8C3Y12n8q3_5VdBhUKgTjBeMVrQkb1-7vfTCHnFUsNozzW0iNFs7Br-QBtO8IAIDA7naqV363Y7x0qPcE9ij0Q8zzh5ZFR6GD8rT25lmXqOMghcdrzC-CTMm9xPtjtB-A6Mdu11BAi_0PoMypSB6FOKCfQuxUL_F0I1IfoH0ZTfWe8ZIWRdp5q4aJBtXvRMR-GN1Mo18QeUch_B2Q-feXSK7yvlgUHoN6W2u6X06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