[Lldb-commits] [PATCH] D53530: Fix (and improve) the support for C99 variable length array types
Greg Clayton via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 1 21:39:01 PDT 2018
clayborg added a comment.
In https://reviews.llvm.org/D53530#1284267, @aprantl wrote:
> > I didn't realize that the string int [] is produced by ValueObject itself; I think this makes this option more palatable to me. I'll give it a try.
>
> So, it turns out it isn't. The only way to get the length into the typename is to hack ClangASTContext::GetTypeName to replace the training "[]" of what clang returns as the typename with a different string. The main problem with this is that this will only work for outermost types.
>
> Something that has been requested in the past is to support C structs with trailing array members, such as
>
> struct variable_size {
> unsigned length;
> int __attribute__((size=.length)) elements[]; // I just made up this attribute, but you get the basic idea.
> };
>
>
> in a similar fashion. When printing such a struct, there's no way of safely injecting the size into array type string any more.
> If we dynamically created the correctly-sized array type instead, this would work just fine.
>
> I haven't yet understood the motivation behind why overriding GetNumChildren/GetTypeName/GetChildAtIndex is preferable over creating a dynamic type in the language runtime. Is there something that I need to know?
Creating a new dynamic type every time you stop seems like a lot of work and a possible waste of memory. You will need to see if you already have such a type ("int[4]" already exists) and use it if it does each time you stop. Any type that can change dynamically should easily be able to be detected by the type system in GetNumChildren(...) with the right execution context and and a dynamic type name can also easily be calculated in the type system. One option would be to just display "int[]" and have a summary for any dynamic array types that says "size = 4". Then we don't have to touch the typename.
https://reviews.llvm.org/D53530
More information about the lldb-commits
mailing list