Bug 203380 - Add a client request to register debug info for code ranges
Summary: Add a client request to register debug info for code ranges
Status: CONFIRMED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 3.5 SVN
Platform: unspecified All
: NOR wishlist
Target Milestone: blocking3.6.0
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-11 02:25 UTC by Nicholas Nethercote
Modified: 2025-11-19 10:55 UTC (History)
4 users (show)

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


Attachments
starting point patch (5.58 KB, patch)
2009-08-11 02:25 UTC, Nicholas Nethercote
Details
test (1.75 KB, text/plain)
2009-08-11 02:28 UTC, Nicholas Nethercote
Details
WIP (10.02 KB, patch)
2011-03-04 03:32 UTC, David Anderson
Details
Majorly revised and improved patch (10.18 KB, patch)
2023-04-28 06:49 UTC, Julian Seward
Details
Majorly revised and improved patch, take 2 (with debug printing removed) (10.03 KB, patch)
2023-04-28 06:54 UTC, Julian Seward
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicholas Nethercote 2009-08-11 02:25:01 UTC
This would be useful for JIT compilers.

These pages have some more discussion:

http://tirania.org/blog/archive/2007/Jun-29.html
http://idea.opensuse.org/content/ideas/valgrind-support-for-mono

The first link has a patch which I've attached to this bug.  The patch isn't very clean, but it's a starting point.
Comment 1 Nicholas Nethercote 2009-08-11 02:25:59 UTC
Created attachment 36062 [details]
starting point patch
Comment 2 Nicholas Nethercote 2009-08-11 02:28:03 UTC
Created attachment 36063 [details]
test

A test.  As is, it prints a stack trace with ??? in it.  But if notify_jit_function() has the client request added to it, it'll print a nicer stack trace.
Comment 3 David Anderson 2011-03-04 03:32:36 UTC
Created attachment 57659 [details]
WIP

Updated patch that integrates into the API a little differently. Also fixes an off-by-one error in the binary search, and lets you deregister JIT code.

I'm using this to get cachegrind & callgrind results for SpiderMonkey generated code, but right now only cachegrind is giving back meaningful results.
Comment 4 Josef Weidendorfer 2011-03-04 11:21:30 UTC
Callgrind relates its counter arrays to ELF objects, and tries to reuse these
counters if a shared library is unmapped and remapped on to a different address.
This does not work nicely with code generated in anonymous memory, ie. that
should be a special case.

Another issue is that Callgrind relates hit/miss counters also per
guest instruction. So, if the same JavaScript code is translated multiple
times, Callgrind will print out a lot of different instruction addresses
for the same JavaScript source (with --dump-instr=yes). But as KCachegrind
can not show machine code annotation here anyway, it does not really matter.
Comment 5 Konstantin Olkhovskiy 2013-05-21 12:33:33 UTC
Will this RFE be implemented some day?
It would be extremely useful for users of LuaJIT and other folks using some JIT compiled code.
Comment 6 Julian Seward 2023-04-28 06:49:45 UTC
Created attachment 158504 [details]
Majorly revised and improved patch

Here's a revised and improved patch that I have used recently for profiling webassembly applications running on SpiderMonkey.  It's still not particularly sophisticated, but works well enough to be useful.  It retains the basic design of earlier versions of the patch, in that it stands outside the per-object DebugInfo mechanism used for AOT code.  Hence it is localised complexity that does not impact the existing mechanisms.
Comment 7 Julian Seward 2023-04-28 06:54:54 UTC
Created attachment 158505 [details]
Majorly revised and improved patch, take 2 (with debug printing removed)
Comment 8 Edd Barrett 2025-11-19 10:55:37 UTC
Hi.

Julian's latest patch still applies and works on today's valgrind. Thanks for this Julian.

I was able to cachegrind our JIT and assign names to our dynamically compiled code ranges and view them in kcachegrind.

Before, the JITted code would be clumped into the `???` record in the output file, which was rendered as a `(unknown)` in kcachegrind.

(I spoke to a few people in #valgrind-dev IRC and it seems that there is still interest in including this feature in valgrind)

One refinement that would be useful (if possible) would be the ability to specify a "dummy" source file to each JITted location so that we can filter by only those using the "source file" grouping feature in kcachegrind. If you use this at the moment, JITted code will be mixed in with all of the other "unknown" code in the profile.

By allowing the user to specify their own "source file" (rather than, e.g. hard-coding the source file to "JIT"), it would be possible to give different "source files" to different tiers of a multi-tier JIT, which I think would be useful.