Debug info magic for arrays with a separate length field

In the language I’m compiling (Java), I’m generating structures which contain a trailing variable-length array, whose length is determined by a member of that structure.

What I can’t figure out is, what magic debug info do I have to provide in order to tell lldb that the length of the array is determined by the value of the structure member? Right now, lldb refuses to print most of these structures (particularly the ones whose arrays are arrays of i8) with an error like “error: supposed to interpret, but failed: Interpreter couldn’t read from memory”. I suspect it’s related to the lack of null-termination but it could be something else I suppose.

My IR for the structure which fails to be read is generally something like this:

%"class.[B" = type { i8 ; header
        , i8 ; (padding)
        , i16 ; (padding)
        , i32 ; typeId
        , %ref ; monitor
        , i32 ; defaultHashCode
        , i32 ; length
        , [0 x i8] ; content
         }

Thanks!

I’d start by looking at how clang emits debug info for a variable-length array (VLA) in C. This would have a runtime-defined length.

The only real difference for you is that the length isn’t in an independent variable, it’s a struct member. Which just happens to be the same struct where the array lives.

DWARF is perfectly okay with this–COBOL can do the same thing (runtime-bounded array where the bound is a struct member), and I was able to get reasonable DWARF output for it many years ago when I was tech lead for a COBOL compiler. That wasn’t using LLVM, but it should still be doable.

I had a feeling that it was doable, so thanks for confirming that. I guess it’s back to poring over the DWARF documentation again.