From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12589 invoked by alias); 16 Dec 2009 23:01:20 -0000 Received: (qmail 12387 invoked by uid 22791); 16 Dec 2009 23:01:16 -0000 X-SWARE-Spam-Status: No, hits=-0.0 required=5.0 tests=AWL,BAYES_00,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 207-114-238-160.static.twtelecom.net (HELO mail.stratos.com) (207.114.238.160) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Dec 2009 23:01:11 +0000 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Cross-platform, multithreaded debugging (x86 to ARM) with gdb and gdbserver not recognizing threads Date: Wed, 16 Dec 2009 23:01:00 -0000 Message-ID: <597A11B8CF75534EBE76656E186BF106E0135E@stella.stratos.local> From: "Jason Machacek" To: Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00096.txt.bz2 Hello everyone, I recently ran into an issue where my embedded application became too large to run natively under GDB. Unfortunately, my SBC provider doesn't supply a precompiled version of GDB, so I've been trying to build a GDB/gdbserver combination myself. My application is a C++ app with several threads running. I can successfully build both GDB (native x86 with --target=3Darm-linux specified) and gdbserver (ARM-native). However, when I connect to gdbserver on my target with gdb, it doesn't understand that it's a multithreaded application--it breaks on each context switch (SIG32) and can't figure out what instruction it's looking at. I found a 2005 thread from this mailing list (http://www.cygwin.com/ml/gdb/2005-11/msg00364.html) and several other messages from other places that set me on the right track, but I'm still not quite there. Here are the commands I used to build GDB (x86): # cd gdb-6.7.1/ # PATH=3D$PATH:/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/bin/ ./configure --target=3Darm-linux --disable-sim --disable-tcl --enable-threads --enable-shared # make Here are the commands I used to build gdbserver (ARM): # cd gdb/gdbserver/ # PATH=3D$PATH:/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/bin CC=3D/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/bin/arm-linux-gcc ./configure --host=3Darm-linux --target=3Darm-linux --enable-threads --enable-shared # make I execute the gdbserver binary on the target: $ ./gdbserver :12345 app Process app created; pid =3D 270 Listening on port 12345 I then connect to the target from the host like so: # ../gdb-6.7.1/gdb/gdb app GNU gdb 6.7.1 Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=3Di686-pc-linux-gnu --target=3Darm-linux"... (gdb) set solib-absolute-prefix /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/ (gdb) file app Load new symbol table from "/home/jmachacek/juice/juice/src/app"? (y or n) y Reading symbols from /home/jmachacek/juice/juice/src/app...done. (gdb) target remote 10.0.150.55:12345 Remote debugging using 10.0.150.55:12345 0x2aaaba70 in _start () from /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/ld-linux.so .2 (gdb) So far so good. "info threads" and "info shared" look okay: (gdb) info threads * 1 Thread 270 0x2aaaba70 in _start () from /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/ld-linux.so .2 (gdb) info shared =46rom To Syms Read Shared Object Library 0x2aaaba70 0x2aabd888 Yes /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/ld-linux.so .2 (gdb) I can debug to main() with no problem: (gdb) b main Breakpoint 1 at 0x20808: file Main/Main.cpp, line 41. (gdb) c Continuing. Breakpoint 1, main (argc=3D1, argv=3D0x7ffffec4) at Main/Main.cpp:41 41 BSP_init(argc, argv);=20 (gdb) bt #0 main (argc=3D1, argv=3D0x7ffffec4) at Main/Main.cpp:41 (gdb) At this point, I use 'c' to start running and GDB stops when it receives SIG32 (which appears to be generated when the CPU switches between threads): (gdb) c Continuing. Program received signal SIG32, Real-time event 32. 0x2abd49e8 in ?? () (gdb) bt #0 0x2abd49e8 in ?? () (gdb) info threads * 1 Thread 270 0x2abd49e8 in ?? () warning: Couldn't restore frame in current thread, at frame 0 0x2abd49e8 in ?? () (gdb) info shared warning: .dynamic section for "/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libm.so.6" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libgcc_s.s o.1" is not at the expected address (wrong library or version mismatch?) warning: .dynamic section for "/opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libc.so.6" is not at the expected address (wrong library or version mismatch?) =46rom To Syms Read Shared Object Library 0x2aaaba70 0x2aabd888 Yes /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/ld-linux.so .2 0x2aacc050 0x2aad5e1c No /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libpthread. so.0 0x2ab254c4 0x2ab5d5d0 No /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libm.so.6 0x2ab9ab84 0x2aba12d8 No /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libgcc_s.so .1 0x2abc0f80 0x2acbd404 No /opt/crosstool/gcc-3.4.4-glibc-2.3.2/arm-linux/arm-linux/lib/libc.so.6 (gdb) The warnings in "info shared" are due to libc being statically linked in my application. Can anyone help me figure out why I'm unable to get gdb/gdbserver to work properly with my target? Thanks very much, Jason Jason Machacek | Stratos Product Development | Software Engineer | (206) 576-7312