Is there a way to get the file path/file name of the .so that is currently under execution by a thread? The program is written in c++ and run on a 64-bit Linux 3.0 machine.
-
1Why exactly are you asking? What do you want to achieve?? – Basile Starynkevitch Feb 28 '13 at 10:02
-
@BasileStarynkevitch I want to get the .so that caused a program to crash. With this I can programmatically invoke addr2line utility to get the line number where the crash occurred. But thinking about it now, i realize that this approach won't work as the current execution unit of the thread will be the signal handler and not the original function that caused the crash. – Anirudh Jayakumar Feb 28 '13 at 11:40
-
http://stackoverflow.com/q/15129089/841108 is nearly the same question, by same author ..... – Basile Starynkevitch Feb 28 '13 at 18:07
2 Answers
You can sequentially read (from inside your process) the file /proc/self/maps
to get the memory mapping (including those for shared objects) of the current process.
Then you could get your program counter (or those of the caller) and find in which segment it is. Perhaps backtrace
or GCC builtin_return_address is relevant.
You might also use the dladdr
function.
See proc(5), backtrace(3), dladdr(3) man pages, and also this answer.
addenda
From a signal handler you could get the program counter when the signal was sent by using sigaction(2) with SA_SIGINFO
. The sa_sigaction
function pointers gets a ucontext_t
from which you could get the program counter register (using machine dependent C code). Then you could handle it.
I suggest looking into detail into what GCC is doing

- 1
- 1

- 223,805
- 18
- 296
- 547
I think the closes thing is to get a list of all shared libraries loaded by your process. You can do that either by using pmap
or lsof
.

- 131,725
- 17
- 180
- 271