Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: Kurvivor19 on October 07, 2016, 01:20:31 PM

Title: Setup dgb for multi-threaded debug
Post by: Kurvivor19 on October 07, 2016, 01:20:31 PM
I am trying to compile and debud a multi-threaded program (pthreads). I have compiled it succesfully, however when i try to run it under gdb, i get "threading debug not available" warning every time.

I am using TinyCore, and i have installed gcc and gdb from extension repository, as usual.

What should i do to be able to debug threads under gdb? Are there extra packages i need to install or some settings that need to be enabled?
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 07, 2016, 10:44:03 PM
Do you get this message because the tinycore glibc is stripped?
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor19 on October 08, 2016, 05:05:36 AM
I do not really know the reason, or to be more precise, i do nt fully understand what these messages mean

Here is the full text of warning messages:
Quote
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "Set solib-search-path" or "set sysroot"?
warning: File "/tmp/tcloop/glibc_add_lib/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
<skilpped lines about security protection>
warning: Unable to find libthread_db matching inferior's hread library, thread debugging will not be available.
 
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 08, 2016, 06:12:59 AM
You get these messages because the tinycore glibc has the debugging symbols stripped out of it to make it smaller.

Usually this does not impact the debugging of other applications - if you use "threads all" (or whatever the command is in gdb) you should be OK, no?
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor19 on October 08, 2016, 07:20:14 AM
Well, it is the last message, which is
Quote
warning: Unable to find libthread_db matching inferior's hread library, thread debugging will not be available.
is what worries me.
No matter what i do, i seem unable to see anythreads beside main one when i list them. It seems that is expected behaviour  when libthread_db and libpthread do not match - but why are they not matching? It is certainly strange for libraries from same repository to fail to match.
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 08, 2016, 10:26:18 PM
I was recently dubugging something on tinycore and "thread apply all backtrace" showed the different threads.

libthread_db is in the glibc_add_lib extension, but I was not using the extension, are you?
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor19 on October 09, 2016, 02:26:53 AM
That extension was pulled together with gdb
To clarify: do you get any warnings?
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 09, 2016, 06:46:53 AM
Yes, but as long as you're not debugging glibc itself it should be OK
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 10, 2016, 12:33:03 AM
Well, in my case i still a) get warning about libthread_db and libpthread no matching b) do not see any threads except main one (listing with `thread apply all bt` ot `info threads`) even when several threads are running for sure.
this is very distressing for me
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 11, 2016, 07:10:23 AM
I see the same warning in the x86 and x86_64 versions of gdb.

Both libpthread-2.22.so and libthread_db-1.0.so are from the same version of glibc, so I'm not sure why the warnings are given.

As per google, plenty of people have the same problem, but I did not find any obvious solutions  :(
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 13, 2016, 09:28:31 AM
At stackoverflow, this
Quote
You have stripped libpthread.so.0 (don't do that).
is listed as possible reason
If that is the case, could not-stripped libpthread be provided?
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 13, 2016, 10:02:08 AM
Or, even, according to: http://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target - symbols can be provided in a separate tgx file, which would be consistent with TinyCore design
I am begging you to do that. I am quite desperate
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 14, 2016, 01:14:23 AM
I'm not sure about the script in the link you provided, but if I overwrite libpthread-2.22.so and libthread_db-1.0.so with versions containing debug symbols, I get this:
Code: [Select]
(gdb) run
Starting program: /usr/local/bin/fifth
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
[New Thread 0xb58eab40 (LWP 4402)]
[New Thread 0xb5860b40 (LWP 4403)]
[New Thread 0xb56f2b40 (LWP 4404)]

..which looks promising.

Now I need to think how to make this available...
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 14, 2016, 02:44:01 AM
Since i am using old version of tinycore (6, i believe, with 3.16.6 kernel), an instruction for how to build those libraries with symbols would suffice.
Title: Re: Setup dgb for multi-threaded debug
Post by: Juanito on October 14, 2016, 04:21:49 AM
see the second time glibc is built in:

http://tinycorelinux.net/6.x/x86/release/src/toolchain/compile_tc6_x86

..substitute "sudo make install_root=/tmp/pkg install" for "sudo make install" to avoid overwriting the existing files.
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 15, 2016, 01:15:34 PM
To clarify: you mean this part:
Code: [Select]
cd glibc-2.20

patch -Np1 -i ../glibc-2.20-fhs-1.patch

mkdir ../glibc-build
cd ../glibc-build

echo "CFLAGS += -march=i486 -mtune=i686 -Os -pipe" > configparms

../glibc-2.20/configure --prefix=/usr --libexecdir=/usr/lib/glibc --disable-profile --enable-kernel=3.8.13 --enable-obsolete-rpc

find . -name config.make -type f -exec sed -i 's/-O2/ /g' {} \;

make

touch /etc/ld.so.conf

make install
Is that correct?
From what i understand, that file you linked is a build log for old tinycore from another environment (thus typical cross-compilation activity of first building compiler that can compile to needed target and then using it). I can get sources from the same location

Trying it out now
Title: Re: Setup dgb for multi-threaded debug
Post by: Kurvivor on October 16, 2016, 09:36:17 AM
You are a life-saver
gdb_thread-db is indeed the package i needed. Now gdb says that it can debug threads, which i will now commence doing.
Thanks!