shared object file path that is executed by the current thread

二次信任 提交于 2020-01-06 07:35:49

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/15132424/shared-object-file-path-that-is-executed-by-the-current-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!