2

I have a host machine running 64-bit Linux in x86, and a target board running 32-bit Linux in ARM. I am using gdb-multiarch on the host machine to debug core dump files generated from a multi-threaded binary running on the target board. The debugging seems to work (at least the basic things such as bt, info threads, etc).

However, I see warnings related to libthread_db on startup. I learned that you can use set debug libthread-db 1 to get some extra debug message, and this is what I observed:

  1. First, I see the libthread_db from the host machine is being loaded. This fails due to a version mismatch but that seems completely reasonable in my opinion. After all, why would the libpthread from my target board be compatible with the libthread_db on my host machine?
Trying host libthread_db library: libthread_db.so.1.
Host libthread_db.so.1 resolved to: /lib/x86_64-linux-gnu/libthread_db.so.1.
td_ta_new failed: versions of libpthread and libthread_db do not match
  1. Then, I see the libthread_db from the target board is being loaded (I have the ARM shared libraries on my host machine). It appears that it failed because dlopen is expecting a 64-bit shared library, but this doesn't make sense to me because the core dump is generated from a 32-bit binary.
Trying host libthread_db library: <snipped path>/lib/libthread_db.so.1.
dlopen failed:  <snipped path>/lib/libthread_db.so.1: wrong ELF class: ELFCLASS32.
thread_db_load_search returning 0
  1. Finally, gdb-multiarch complains that thread debugging isn't available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

What am I doing wrong that's preventing libthread_db from being loaded properly?

1 Answer 1

1

What am I doing wrong that's preventing libthread_db from being loaded properly?

You aren't doing anything wrong, but you need to have an x86_64 version of libthread_db.so.1 which is the same version as GLIBC on your 32-bit ARM target.

Alternatively you could use 32-bit GDB on the host. That GDB would be able to dlopen <snipped path>/lib/libthread_db.so.1. Since your target is 32-bit, you are not gaining anything by using 64-bit GDB on the host.

Update:

exactly what gdb is using libthread_db.so.1 for?

GDB does not know about internals of libpthread.so.0, so it dynamically loads libthread_db.so.1 and asks it to e.g. enumerate threads and tell GDB about them.

Obviously for this dynamic loading (dlopen) to work, libthread_db.so.1 must match GDB bitness and architecture. But in order for libthread_db to know about internals of libpthread.so.0, it must version-match libpthread.so.0 used by the target.

You might ask: how can libthread_db enumerate threads in the target process? Doesn't it need to know memory contents of the inferior (being debugged) process?

Why yes, it does, and it uses GDB to perform inferior reads and writes.

That is, GDB calls into libthread_db, which calls back into GDB for low-level inferior memory and register access, then uses the info provided by GDB to construct higher-level concepts (active threads, etc.).

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

4 Comments

Could you share some insight on exactly what gdb is using libthread_db.so.1 for? I am still confused why gdb would want to use a x86_64 version of libthread_db.so.1 when I'm doing cross-platform debugging on an ARM target. Regardless, I am glad to hear that I'm not doing something terribly wrong in my gdb setup!
One more question about your suggestion to use 32-bit GDB on the x86 host machine. You mentioned that libthread_db.so.1 and GDB must match in bitness and architecture. However, my <snipped path>/lib/libthread_db.so.1 is 32-bit and built for ARM (I'm not sure if this detail was clear earlier). Wouldn't this mean there's a mismatch in architecture if I use the 32-bit GDB?
@KenLin Yes, your i*86 GDB will not be able to use ARM libthread_db.so.1. You need to build a copy which matches target libpthread.so.0 version, but for the host on which GDB runs.
I see! I believe the gap in my knowledge was not realizing that GDB can use a x86 libthread_db to know about the internals of an ARM libpthread, as long as they version-match. (Put differently, there is no requirement for libthread_db and libpthread to match in architecture). Thanks for the help!

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.