sas added a comment. In http://reviews.llvm.org/D22294#483250, @clayborg wrote:
> In http://reviews.llvm.org/D22294#483213, @sas wrote: > > > @jingham, @clayborg, this is indeed a bit fragile as having to specify your > > rewrite maps manually when debugging is very error-prone. I have a patch > > that fetches the path to the rewrite map from the debug info, I'm waiting > > for this one to go in to upload that other diff (trying to make changes > > smaller so the review is easier). The way I do this is by looking at the > > flags that were passed to the compiler, and get the path to the rewrite map > > from there automatically, which then requires no user interaction for this > > to work. > > > If we have the compiler modify the DWARF by adding a linkage name to the > appropriate DW_TAG_subproggram, then we won't need any rewrite file stuff at > all. > > In http://reviews.llvm.org/D22294#483242, @fjricci wrote: > > > @clayborg: As you saw when running the test with debug info enabled, we > > might end up calling the non-rewritten `putchar()`, which is due to the > > compiler emitting debug symbols with the non-rewritten name. The `-g0` > > option is just a workaround until we can fix that. > > > > I suppose Adrian Prantl's idea of modifying the emitted DWARF to add a > > linkage name attached to the function would work. Does that mean we would > > only add an entry for the rewritten symbol when lldb parses the DWARF, and > > ignore the non-rewritten function name? > > > Basically the DWARF currently looks like: > > 0x0000002e: DW_TAG_subprogram [2] * > DW_AT_low_pc( 0x0000000000000000 ) > DW_AT_high_pc( 0x000000000000000e ) > DW_AT_frame_base( rbp ) > DW_AT_name( "putchar" ) > DW_AT_decl_file( > "/Volumes/work/gclayton/Desktop/symbol_rewriter/main.c" ) > DW_AT_decl_line( 3 ) > DW_AT_prototyped( 0x01 ) > DW_AT_type( {0x0000007a} ( int ) ) > DW_AT_external( 0x01 ) > > > And we would modify it to emit this: > > 0x0000002e: DW_TAG_subprogram [2] * > DW_AT_low_pc( 0x0000000000000000 ) > DW_AT_high_pc( 0x000000000000000e ) > DW_AT_frame_base( rbp ) > DW_AT_name( "putchar" ) > DW_AT_linkage_name( "__my_putchar" ) <<< Added by compiler > DW_AT_decl_file( > "/Volumes/work/gclayton/Desktop/symbol_rewriter/main.c" ) > DW_AT_decl_line( 3 ) > DW_AT_prototyped( 0x01 ) > DW_AT_type( {0x0000007a} ( int ) ) > DW_AT_external( 0x01 ) > > > If we do this, then we don't need any modifications for the rewrite stuff at > all? I think some understanding of the rewrites from the debugger is still required because the user will still enter commands like `call putchar('a')` and expect the `putchar()` they wrote to be called. That `putchar()` they expect is now called `_my_putchar()` and unless we rewrite the symbol they typed, they'll end up calling the non-rewritten `putchar()`. One thing to note is that adding the `DW_AT_linkage_name` entry to `DW_TAG_subprogram` will fix the bug that we are working around in the unit tests with `-g0`, so that is required regardless. http://reviews.llvm.org/D22294 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits