-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Issue #141 reminded me that we need a better way to populate the module list that doesn't rely on the contents of /proc/<pid>/maps
because the latter might not be accessible or because the way the libraries are laid out makes it hard to coalesce the various entries that show up in that file.
The most robust way to do this I can think of is by using the debugger rendez-vous which - by virtue of being used by all debuggers - should be pretty much always available and less finicky than /proc/<pid>/maps
.
Here's what we should do: first of all we'll have to find the DT_DEBUG
dynamic section inside the executable of the process we're dumping. That section should contain the r_debug
structure (note that while I'm pointing to the code in glibc this should also work for bionic, musl, ...). We should verify we're using the right version (r_version == 1
IIRC) and then follow r_link_mal
. Each entry in that list is a link_map
structure that points to one of the modules in the system. From there it's just a matter of parsing the ELF header which will give us the size of the module as well as the rest of the information we care about (like the SONAME and build ID).
Of course we could keep the /proc/<pid>/maps
path as a fallback in case it fails, but I suspect this would be more reliable than that, not less. Also, it wouldn't require I/O which is a plus.