namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
3.03k stars 444 forks source link

how to trace a dynamic lib #1926

Open realHarvey opened 4 months ago

realHarvey commented 4 months ago

I'm trying to trace my plugin of global planner in move_base in ROS,I compile my plugin to libsample.so. But uftrace record libsample.so return nothing to me "WARN: cannot open record data: uftrace.data: No data available"

honggyukim commented 4 months ago

Hi @realHarvey,

uftrace record libsample.so return nothing to me "WARN: cannot open record data: uftrace.data: No data available"

That's expected. You cannot run libsample.so itself so uftrace record libsample.so cannot be executed. You should run an executable binary instead.

If the target binary is named as a.out and it has a link to libsample.so, then you will be able to see the trace of libsample.so. But please make sure if the a.out is also compiled with one of tracable option such as -pg.

realHarvey commented 4 months ago

Thanks for your reply @honggyukim

I have tried to record the executable file uftrace record ./devel/move_base and it runs totally fine, I got a flame-graph. But still I cannot see those function name of libsample in the flame

In both my navigation pack(include move_base) and libsample workspace, I added add_compile_options(-pg) in CMakeLists.txt

namhyung commented 4 months ago

Please make sure you library (libsample) has the function (mcount) and your program (move_base) loads the library properly.

realHarvey commented 4 months ago

I can see it works properly in RVIZ

namhyung commented 4 months ago

Are you sure your program loaded the libsample you compiled with -pg? I suspect it might load another one in the library load path.

m9rco commented 1 month ago

There will be a problem here: if the -pg parameter is applied to the .so file, and then the specified binary file is compiled (also with -pg), many undefined errors in the .so file will be reported. @namhyung

namhyung commented 1 month ago

I don't understand what you mean. Why will it report undefined errors with -pg? It'd only add mcount and it's defined in libc.