zig icon indicating copy to clipboard operation
zig copied to clipboard

come up with a testing strategy for testing debug info

Open andrewrk opened this issue 5 years ago • 4 comments

We need some programmatic way of writing test cases for debug info so that we don't have to manually interact with gdb or other debuggers to verify that debug info is working correctly.

andrewrk avatar Aug 12 '20 05:08 andrewrk

Is there any prior art or example code to sketch out the idea you had in mind?

matu3ba avatar May 28 '22 16:05 matu3ba

Would a script doing the following be helpful ?

  • takes some zig code that eg contains some constant, generate an executable
  • generates a .gdbinit file that print said constant on startup and exit
  • starts gdb with the executable and the gdbinit and write stderr to a file
  • parses the gdb output and compare it to some expected output

This seems a bit brittle but OTOH it directly tests what the user will see and therefore is probably a good target.

gwenzek avatar May 31 '22 09:05 gwenzek

ideally the resulting executables could be examined with std.dwarf and not call out to gdb at all

nektro avatar May 31 '22 15:05 nektro

FYI LLVM does it like I described: https://github.com/llvm/llvm-project/blob/35efe1d806358df6e45dde8218a143138dd8f0a8/cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.gdb In the same folder you have a binary which creates a number of local variables with different types. The gdb script set a breakpoints into the code and display each local.

The FileCheck binary asserts that the output matches the inline comments.

gwenzek avatar Nov 01 '22 06:11 gwenzek

Probably interesting paper (or follow-up papers): "Who’s Debugging the Debuggers? Exposing Debug Information Bugs in Optimized Binaries" by Di Luna et al.

matu3ba avatar Jan 16 '23 08:01 matu3ba