[llvm-dev] Have the debugger show an away with a dynamic size?

Robinson, Paul via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 13 12:35:20 PST 2020


If you use the Clang options `-emit-llvm -S` it will produce a .ll file containing the textual IR produced by Clang.
Use this to compile a simple C example using a VLA and it should give you a model of the IR and metadata you would need to produce.  I used a source something like this:
    int foo(int s) {
      int a[s];
      int i;
      for (i = 0; i < s; ++i)
        a[i] = s;
      return 0;
    }

What I see is a DILocalVariable for “a” that has a type that is a DICompositeType with DW_TAG_array_type, and the `elements` array of the DICompositeType points to a DISubrange whose `count` points to a DILocalVariable that is the upper bound.

The resulting DWARF looks okay to me, although I admit I haven’t actually tried running gdb on it to make sure.

I haven’t looked up the DIBuilder APIs, if that’s what you are looking for, but based on what you said, it sounds like you would be able to work that out yourself.
HTH,
--paulr

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Levo DeLellis via llvm-dev
Sent: Thursday, February 13, 2020 1:03 PM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Have the debugger show an away with a dynamic size?

Hi. I searched and the closest thing I could find was this http://lists.llvm.org/pipermail/llvm-dev/2018-February/121348.html

Currently a known sized array looks and debugs as expected. I use llvm.dbg.declare with DICompositeType tag: DW_TAG_array_type and the size field. In my language arrays are always passed around with a pointer and size pair. I'd like debugging to show up as nicely instead of a pointer addr with no information about the elements. How would I do this? I don't use the C API, I output llvm-ir directly. I was hoping I can call llvm.dbg.declare/addr/value to specify the pointer, name and size of the variable but I really have no idea how to pass the size to the debugger.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200213/be26208e/attachment.html>


More information about the llvm-dev mailing list