Bug 418795 - command line to inform valgrind of symbols for code that is loaded outside of the normal flow
Summary: command line to inform valgrind of symbols for code that is loaded outside of...
Status: RESOLVED NOT A BUG
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 3.15 SVN
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-13 00:47 UTC by Jefferson Carpenter
Modified: 2020-03-13 05:45 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jefferson Carpenter 2020-03-13 00:47:12 UTC
SUMMARY

gdb has an "add-symbol-file" command to inform the debugger of the symbols to use for code loaded into a certain address.  It would be nice if Valgrind had this feature too.  In addition to giving more complete stack traces for errors that occur in dynamically loaded code, this can be used in conjunction with suppression files to suppress errors in such code.

Use case: Debugging windows executables under wine, the subroutine `chkstk` is called, and part of the correct behavior for that function is to read past the end of the stack.  These executables are loaded outside of the normal dlopen flow, and so valgrind does not have symbol information.  The chkstk errors can be suppressed using --ignore-range-below-sp, but this could prevent valgrind from picking up real errors.


STEPS TO REPRODUCE (Desired behavior):

1. valgrind --suppressions=chkstk.supp --add-symbol-file=./main.exe@0x0040100 --trace-children-yes wine main.exe

No desire on the specific command line syntax for adding symbol info.


OBSERVED RESULT (Desired result):

With a suitable suppressions file, valgrind ignores errors that occur in __chkstk_ms.

Without the suppressions file, trace includes:

    Invalid read of size 4
       at 0x402424: __chkstk_ms (cygwin.S:158)

Instead of:

    Invalid read of size 4
       at 0x402424: ???


ADDITIONAL INFORMATION:

I asked about this feature in this email thread https://sourceforge.net/p/valgrind/mailman/message/36810610/

Julian did suggest using --ignore-range-below-sp but did not say the feature was a bad idea, so I am posting it here.
Comment 1 Jefferson Carpenter 2020-03-13 05:32:47 UTC
It looks like VG_(di_notify_mmap) could be modified to load symbols for the exe in this case.  That would be a better solution.
Comment 2 Jefferson Carpenter 2020-03-13 05:45:53 UTC
Sorry, this isn't very well defined.