This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Uprobes: howto calculate the probe offset


Prasanna S Panchamukhi wrote:
> 	/*Calculate the offset */
> 	$cat /proc/1/mmaps
> 	$08048000-0804f000 r-xp 00000000 08:02 1144758    /sbin/init
> 	$0804f000-08050000 rw-p 00007000 08:02 1144758    /sbin/init
> 	$09d5d000-09d7e000 rw-p 09d5d000 00:00 0
> 	$4ec56000-4ec6b000 r-xp 00000000 08:02 1111946    /lib/ld-2.3.4.so
> 	$4ec6b000-4ec6c000 r--p 00015000 08:02 1111946    /lib/ld-2.3.4.so
> 	$4ec6c000-4ec6d000 rw-p 00016000 08:02 1111946    /lib/ld-2.3.4.so
> 	$4ec6f000-4ed93000 r-xp 00000000 08:02 1111959    /lib/tls/libc-2.3.4.so
> 	^^^^^^^^
> 	$4ed93000-4ed94000 r--p 00124000 08:02 1111959    /lib/tls/libc-2.3.4.so
> 	$4ed94000-4ed97000 rw-p 00125000 08:02 1111959    /lib/tls/libc-2.3.4.so
> 	$4ed97000-4ed99000 rw-p 4ed97000 00:00 0
> 
> 	/* Lookup where the libc-2.3.4.so is mapped. From above you can see
> 	   the beginning map address is 0x4ec6f000 */
> 	$uprobe.offset  =
> 		(unsigned long)(((unsinged long)urpobe.kp.address) - 0x4ec6f000)
> 			= 0x4ecb1420 -  0x4ec6f000;
> 			= 0x42420;

That's not how you in general can compute the offset.

You have to look at each loaded segment in the program header (PT_LOAD
entries).  For each segment you can determine an offset which is the
difference between the actual address used when loading the DSO and the
p_vaddr in the file.

Then, whenever you look up a symbol, determine which segment the symbol
is in (compare the address with [p_vaddr,p_vaddr+p_memsz) and add the
offset for that segment to the address of the symbol as defined in the
symbol table.

It'll for simple cases create the same result as you have above.  But
your's is a lucky guess which can fail.

-- 
â Ulrich Drepper â Red Hat, Inc. â 444 Castro St â Mountain View, CA â

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]