2

I have an embedded ARM application which is bundled with all the so-libraries stripped, including the libpthread.so. Sometimes the application gets stuck in some part of code and I want to be able to attach to it with gdb and see what's going on. The problem is that gdb refuses to load the needed threading support library, with the following messages:

Trying host libthread_db library: /home/me/debug_libs/libthread_db.so.1.
td_ta_new failed: application not linked with libthread
thread_db_load_search returning 0
warning: Unable to find libthread_db matching inferior's thread 
library, thread debugging will not be available.

Because of this I cannot debug the application, e.g. I cannot see current call stacks for all threads. After some investigation I suspect that the td_ta_new failing with the application not linked with libthread is caused by the stripped version of libpthread, which lacks the nptl_version symbol. Is there any way to bypass the error? The gdb is compiled for ARM and being run on the device itself. I have unstripped versions of the libraries, but the application is already running with the stripped libraries.

1 Answer 1

1

Is there any way to bypass the error?

A few ways that come to mind:

  1. Use add-symbol-file to override the stripped libpthread.so.0 with un-stripped one:

    (gdb) info shared libpthread.so # shows the path and memory address where stripped libpthread.so.0 is loaded (gdb) add-symbol-file /path/to/unstripped/libpthread.so.0 $address # should override with new symbols, and attempt to re-load libthread_db.so.1

  2. Run gdb -ex 'set sysroot /path/to/unstripped' ... where /path/to/unstripped is the path that mirrors installed tree (that is, if you are using /lib/libpthread.so.0, there should be /path/to/unstripped/lib/libpthread.so.0.

    I have not tested this, but I believe it should work.

  3. You could comment out the version check in GDB and rebuild it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Option 1 changed the reason of the td_ta_new failure from application not linked with libthread to generic error. I've tried both From and To addresses given by info shared libpthread.so. Option 2 works, but requires to have the whole tree mirrored. I've tried to use set solib-search-path instead, but with no luck (the stripped libpthread is loaded). Option 3 is brilliant, how could I forget about it!
@AlexChe Option 2 does not require copying the whole tree. You could populate the mirror with symbolic links to stripped libraries, and only replace libpthread.so.0 symlink with unstripped file.
Employed Russian (for some reason mentions stopped working for me), I meant that option 2 requires the whole structure mirrored (either unstripped, stripped or just links), which requires some work if there are a lot of binaries. Anyway, thanks for your great answer. I will probably avoid stripping libpthread in the first place, but will keep in mind your options just in case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.