[PATCH 10/13] gdb/testsuite: add .debug_loclists tests
Simon Marchi
simon.marchi@polymtl.ca
Fri Jan 29 15:57:20 GMT 2021
On 2021-01-29 5:13 a.m., Zoran Zaric wrote:
>>>>
>>>> Add tests for the various issues fixed in the previous patches.
>>>>
>>>> Add a new "loclists" procedure to the DWARF assembler, to allow
>>>> generating .debug_loclists sections.
>>>>
>>>
>>> Thank you for this contribution.
>>>
>>> Having a loclists support in DWARF assembler gives us so considerable testing flexibility and decouples the gdb testing even more from what compiler is expected to generate.
>>>
>>> The only thing missing now (at least in my mind) is the CFI support but that is a big project for the future.
>>
>> Given that:
>>
>> - the actual assembler (GNU as or other) already has support for
>> specifying and generating CFI, and
>> - a test case that wants to use specific CFI would contain some
>> assembly code already, to control exactly which instructions are
>> generated
>
> This is not exactly true, you can always define a CFI that doesn't need any assembly code considering that register values can be set from the the test itself or if only CFI register rules that target a memory locations are used.
Isn't a CFI table essentially a big mapping that says:
- At address X + 0, here's how you'll find the saved registers
- At address X + 2, here's how you'll find the saved registers
- ... and so on
So ultimately you want in your test case to know exactly which
instructions are generated, and their addresses, to generate the CFI
table, don't you? And for that, won't you write assembly?
I'm not sure I know what "CFI register rules that target a memory
location" means. A register from a previous frame that is currently
saved in memory? I don't really understand what that changes.
> With the new extensions that I've contributed (and are currently under the review) the register rules mechanism now supports any location description to be part of the DWARF expression. With this extension, you can imagine that a very complex DWARF expression that doesn't use any potentially ABI sensitive resource, can still be written and tested in the same way as any variable location.
Hmm but in the end it's still just a sequence of opcodes, isn't it?
If a compiler is to ever emit such an expression, it would have to emit
it using CFI directives in the assembly code, so we could always write
the same expression by hand directly in assembly, couldn't we?
> Another option is to only hand write a CFI table for the top level function (frame 0) and design a way to merge the original CFI generated by the compiler for other functions with the hand written one.
I don't remember how exactly things are merged by the linker, but I
suppose that would work. But again, you'd probably want to write that
top-level frame 0 function in assembly - I think. Or if don't need to
write different rules for different instructions in the function, I
guess that function could be written in C, and you make CFI rules for
the whole function's range. But you'd need a way to tell the compiler
to not generate CFI for that particular function.
>
> Also, with a potential new operation DW_OP_LLVM_call_frame_entry_reg described at length here:
>
> https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html
>
> This would allow us to test any CFI expression of the frame we are currently stopped in.
>
>>
>> I don't think our assembler needs to know how to generate CFI, you'd
>> just write it in platform-specific assembly.
>>
>
> But, isn't this the case for any part of the DWARF assembler functionality?
>
> Writing any complex DWARF expression fast in any assembly is hard and time consuming.
No, you can't express symbolically any DWARF expression at the assembly
level. For example, you can't describe the tree of DWARF DIEs using
directives in assembly. All you can do is output the raw bytes using
the .byte and friends directives, but that wouldn't be humanly feasible.
So instead we have this higher level language (our DWARF assembler)
where we describe the tree of DIEs and have it output the .byte
directives for us.
But in the case of CFI, the assembler has directives to express
symbolically everything we need to express today: the directives
".cfi_def_cfa_offset" and friends. You write them interleaved with the
assembly code, and the assembler generates the corresponding CFI tables.
And this is also how the compiler works, it emits CFI directives
interleaved with the assembly code. So if we want to test a particular
DWARF CFI construct, it's probably because the compiler generates it,
which means the assembler supports it, which means we can also write a
test case for it by hand (in assembly). Or maybe I'm mistaken and some
compilers generate CFI tables as bytes directly?
>
> I agree that adding a CFI support requires more thought and effort and better understanding about how the CFI works and what is safe to use from a test writer perspective, but I can definitely see the benefit of adding that support in the future.
In the event we want to test a CFI construct that isn't yet supported by
the assembler, then it could make sense to write own assembler that
emits the right bytes directly.
Simon
More information about the Gdb-patches
mailing list