简体   繁体   中英

gdb how to set breakpoint in dynamic library opened by dlopen

Afternoon,everbody. I have an application 'test' compiled by main.c . A dynamic liabrary 'libtest.so' which is compiled by test.cpp with '-g'. In main.c I invoke the 'libtest.so' with 'dlopen' . And now I want to set a breakpoint in test.cpp ,but the gdb never hit it. I do as follow:

gdb ./test -d /home/lcl/test

break test.cpp:35

run

can anybody give me some tips ,thanks!

You should first verify that dlopen is actually succeeding (it's likely that it's not).

To do so:

  • set a breakpoint in main.c after dlopen .
  • confirm that returned handle is not NULL

At that point, GDB should have loaded symbols for libtest.so , and libtest.so should show up in info shared GDB output.

If everything looks good, info break should show an active breakpoint in test.cpp:35 at some address. If that breakpoint is never hit, it's likely that you never actually exercise that line of code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM