4 ms·
> If we want to find the address of a global variable in our program, all we need to do is look up the name of the variable in the symbol table, and then add th
by philh 10y ago
> If we want to find the address of a global variable in our program, all we need to do is look up the name of the variable in the symbol table, and then add that to the start of the range in /proc/whatever/maps, and we're done!
We just saw three ranges in ///maps:
5598a9605000-5598a9886000 r-xp 00000000 [...]
5598a9a86000-5598a9a8b000 r--p 00281000 [...]
5598a9a8b000-5598a9a8d000 rw-p 00286000 [...]
what are these? The r??p look like permissions, read/write/execute/something, but how do we know which one to look for the variable in?
(And what are the numbers afterwards? 00281000 on the second line is the length of the range on the first line, but then there's a gap of 00200000 between the end of the first range and the start of the second. 00286000 on the third line is again 00200000 less than the distance from the start of the first range and the start of the second.)
- teraflop 10y agoThe man page for /proc (yes, there is one) explains what all those fields mean. In this case, each of those mappings corresponds to one of the sections in the binary. The permissions indicate that the first one is executable code, the second is read-only data, and the third is writable (copy-on-write). The number after the permissions is an offset into the underlying file. I suspect the article is glossing over some details e.g. how gdb figures out which mapping corresponds to which section, but it gets the basic idea across.
- pkaye 10y agoWow in all these years using Linux I never thought of looking for the man page for /proc. Lots of info there...