简体   繁体   中英

LLDB Data Formatter for References

I'm currently developing data formatters for my own types. However, I encounter some problems to print references.

#include <iostream>

class Circle
{
  protected:
    double R;
    double a;
    double b;

  public:
    Circle():R(1), a(0), b(0)
    {
    }
};

int main()
{
  Circle A;
  Circle & B = A;

  return 0;
}

And I use type summary add to customize my own data formatters

(lldb) type summary add -s "The circle is (R = ${var.R}, a = ${var.a}, b = ${var.b})" Circle

Now it goes very well for non-references, for example

(lldb) frame variable A
(Circle) A = The circle is (R = 1, a = 0, b = 0)

However, for references,

(lldb) frame variable B
(Circle &const) B = 0x00007fffffffd200 The circle is (R = 1, a = 0, b = 0): {
  R = 1
  a = 0
  b = 0
}

for which the contents after ":" is not wanted.

What should I do to deal with the references? I know it is possible to use --skip-references to disable the output for references, but I do hope I can format references just as usual types.

That's a bug. There's an option to the summary formatters: --expand that's supposed to control whether we only show the summary, or show the summary and the children of the value being printed. If you add --expand when you add your summary, you'll see that the struct version now also prints the child elements. It looks like that setting is ignored for references.

Please file a bug with bugs.llvm.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM