This is an archive of the discontinued LLVM Phabricator instance.

Implement an "I'm dtrace, please retain all debug types" option.
AbandonedPublic

Authored by aprantl on Mar 29 2016, 11:47 AM.

Details

Summary

As noted in the review thread for http://reviews.llvm.org/D18477 on llvm-commits, DWARF consumers such as dtrace's ctfconvert expect debug info for types to survive even if the underlying code that references those types has been optimized away.
This patch moves this logic from the backend, where it used to be unconditionally executed, into clang. For more info on this functionality check out DwarfDebug::collectDeadVariables(), added in r107027.

This code in this patch listens to the driver option -gfull, and lowers it to the new cc1 option -debug-retain-types (1).
When -debug-retain-types is present, CGDebugInfo will retain every(2) type it creates.

Implementation notes:

  1. I decided not use -fno-eliminate-unused-debug-symbols for consistency with our other cc1 debug options.
  2. I’m minimizing the set of retained types by only retaining top-level types.

Diff Detail

Repository
rL LLVM

Event Timeline

aprantl updated this revision to Diff 51960.Mar 29 2016, 11:47 AM
aprantl retitled this revision from to Implement an "I'm dtrace, please retain all debug types" option..
aprantl updated this object.
aprantl added reviewers: dblaikie, dexonsmith.
aprantl set the repository for this revision to rL LLVM.
aprantl added a subscriber: cfe-commits.
aprantl abandoned this revision.Apr 5 2016, 3:14 PM

Meanwhile I made an experiment and compiled XNU with D18477 and compared the debug info from before and after and found no missing types at all. It is plausible that r107027 was added to work around the fact that six years ago LLVM was a lot worse at preserving debug info for local variables. It is also possible that the call graph of the kernel changed in the mean time or a combination of both.

dblaikie edited edge metadata.Apr 6 2016, 8:19 AM
dblaikie added a subscriber: dblaikie.

Okey dokey - I know one of the things we did (& I don't know when it
happened compared to this change) is emit a hard list of variables onto any
subprogram for an optimized (non -O0) function. So we never lose variables
due to optimizations, or at least that's the intent.

As for D18477, I'm not sure why collectDeadVariables became dead with your
change - I imagine we still want to stuff dead variables into the
subprograms we did create (the ones that weren't /entirely/ optimized away
(ones with remaining inlined instances, etc)) - but maybe we do that
elsewhere?