The general path to the file of the object that is being executed by the current thread

Is there a way to get the file path / .so file name that the thread is currently executing? The program is written in C ++ and runs on a Linux 3.0 64-bit machine.

0
linux shared-libraries
source share
2 answers

You can sequentially read (inside your process) the file /proc/self/maps to get a memory map (including for shared objects) of the current process.

Then you can get your program counter (or caller’s number) and find in which segment it is. Perhaps relevant backtrace or GCC builtin_return_address .

You can also use the dladdr function.

See proc (5) , backtrace (3) , dladdr (3) man pages, as well as this answer .

additions

From the signal handler you can get the program counter when the signal was sent using sigaction (2) with SA_SIGINFO . The pointers to the sa_sigaction function get ucontext_t , from which you can get the program counter register (using C machine code). Then you can handle it.

I suggest exploring in detail what GCC does.

+1
source share

I think the closure is to get a list of all shared libraries loaded by your process. You can do this with either lsof or lsof .

0
source share

All Articles