免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6917 | 回复: 7
打印 上一主题 下一主题

gdbserver多线程进不去 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-13 09:44 |只看该作者 |倒序浏览
arm926,kernel版本:
Linux version 2.6.19.2 (root@video) (gcc version 4.1.1)
gdb版本gdb6.6,6.7都试过.
编译出来时是dynamic,程序dynamic和static都试过,
就是在另外的线程里停不下来.

代码:

static void *func(void *arg)
{
    while (1)
    {
        printf("new thread\n");
        sleep(3000);
    }
}

int main(int argc, char *argv[])
{
    pthread_t id;
    int a= 3;
    int ret;

    printf("hello,world %d\n", a);
    ret = pthread_create(&id, NULL, func, 0);
    printf("ID %d ret = %d\n", id, ret);
    while (1) {
        printf("main thread\n");
        sleep(1);
    }
    printf("hello,world %d\n", a);
}

gdb版本:
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-926ejs-linux".

谁碰到过这种问题?多多交流

论坛徽章:
0
2 [报告]
发表于 2007-12-14 08:49 |只看该作者
原帖由 boliyun 于 2007-12-13 09:44 发表
arm926,kernel版本:
Linux version 2.6.19.2 (root@video) (gcc version 4.1.1)
gdb版本gdb6.6,6.7都试过.
编译出来时是dynamic,程序dynamic和static都试过,
就是在另外的线程里停不下来.

代码:
...


描述具体一点,你做了哪些操作,想达到什么效果。“在另外的线程里停不下来.”是什么意思。

论坛徽章:
0
3 [报告]
发表于 2007-12-14 09:53 |只看该作者
我想在另外这个线程里面停下来,breakpoint,老兄没看明白嘛?
b func;
i b;
c;
结果exit normal了,没有在func里停下来.
就是这样.

论坛徽章:
0
4 [报告]
发表于 2007-12-14 10:38 |只看该作者
原帖由 boliyun 于 2007-12-14 09:53 发表
我想在另外这个线程里面停下来,breakpoint,老兄没看明白嘛?
b func;
i b;
c;
结果exit normal了,没有在func里停下来.
就是这样.


让一个程序停下来的方法有很多,你不说是打了断点停不下来,谁知道你的“想在另外这个线程里停下来”是怎么想的?以后要注意提问方式。

把gdb的set debug remote 1 打开,然后把调试过程发上来看看。

论坛徽章:
0
5 [报告]
发表于 2007-12-15 10:04 |只看该作者
调试过程如下:
1: 代码见1楼.
2:  $(CC) hello.c -g -I$(INC) -o test -lpthread
3:  copy至arm目标机
4: 目标机.gdbserver host:1234 test
5: 主机.gdb test
6: 主机:target remote xx.xx.xx.xx:1234
7: l main
8: l func
9: b func
10: c
11: exit normal.
另外:
1: file gdb/gdbserver/gdbserver
gdb/gdbserver/gdbserver: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped
2: file gdb/gdb
gdb/gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux 2.4.1, not stripped
3: readelf gdb/gdb -a | grep lib
      [Requesting program interpreter: /lib/ld-linux.so.2]
0x00000001 (NEEDED)                     Shared library: [libncurses.so.5]
0x00000001 (NEEDED)                     Shared library: [libm.so.6]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]

4: readelf gdb/gdbserver/gdbserver -a | grep lib
      [Requesting program interpreter: /lib/ld-linux.so.2]
0x00000001 (NEEDED)                     Shared library: [libthread_db.so.1]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]
0001b8d0  00008116 R_ARM_JUMP_SLOT   0000a828   __libc_start_main
    52: 00010e74     4 FUNC    GLOBAL DEFAULT   12 __libc_csu_fini
   122: 00010e78   108 FUNC    GLOBAL DEFAULT   12 __libc_csu_init
   129: 0000a828   524 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.0 (2)
   461: 00010e74     4 FUNC    GLOBAL DEFAULT   12 __libc_csu_fini
   531: 00010e78   108 FUNC    GLOBAL DEFAULT   12 __libc_csu_init
   538: 0000a828   524 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
  000000: Version: 1  File: libthread_db.so.1  Cnt: 3
  0x0040: Version: 1  File: libc.so.6  Cnt: 2

5: 比较过目标机和主机链接的pthread库,弄成一致.

set debug remote 1后主机信息如下:
gdb/gdb test
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-926ejs-linux"...
(gdb) target remote 192.168.0.199:1234
Remote debugging using 192.168.0.199:1234
0x40000880 in ?? () from /lib/ld-linux.so.2
(gdb) l func
11      #include <asm-arm/arch-mxc/pm_api.h>
12
13      #include <pthread.h>
14
15      static void *func(void *arg)
16      {
17          while (1)
18              {
19                      printf("new thread\n");
20              sleep(3000);
(gdb)
21              }
22      }
23      
24      /*!
25       * This the main function of the porogram.
26       *
27       * @param     argc  number of arguments sent to the program.
28       * @param     argv  array of strings containing the program arguments.
29       *
30       * @return    0 if program exited with no error. else returns -1.
(gdb)
31       *
32       */
33      int main(int argc, char *argv[])
34      {
35              pthread_t id;
36              int a= 3;
37              int ret;
38
39              printf("hello,world %d\n", a);
40              ret = pthread_create(&id, NULL, func, 0);
(gdb) b 19
Breakpoint 1 at 0x84ac: file hello.c, line 19.
(gdb) set de
debug                 debug-file-directory  debugvarobj           demangle-style        
(gdb) set debug remote 1
(gdb) c
Continuing.
Sending packet: $Z0,4000c0e0,4#02...Ack
Packet received:
Packet Z0 (software-breakpoint) is NOT supported
Sending packet: $m4000c0e0,4#b9...Ack
Packet received: 8401a0e1
Sending packet: $X4000c0e0,0:#da...Ack
Packet received: OK
binary downloading suppported by target
Sending packet: $X4000c0e0,4:\001\000\237?6d...Ack
Packet received: OK
Sending packet: $m84ac,4#fd...Ack
Packet received: 0c009fe5
Sending packet: $X84ac,4:\001\000\237?b1...Ack
Packet received: OK
Sending packet: $vCont?#49...Ack
Packet received: vCont;c;C;s;S
Packet vCont (verbose-resume) is supported
Sending packet: $vCont;c#a8...Ack
Packet received: T050b:a44990be;0d:504890be;0f:e0c00040;
Sending packet: $X4000c0e0,4:\204\001犪#e4...Ack
Packet received: OK
Sending packet: $X84ac,4:\f\000\237?b2...Ack
Packet received: OK
Sending packet: $m10654,d0#2d...Ack
Packet received: 010000000100000001000000430000000c0000002c8300000d000000f48500000400000028810000050000000482000006000000648100000a0000009a0000000b00000010000000150000001037024003000000240701000200000030000000140000001100000017000000fc82000011000000f482000012000000080000001300000008000000feffff6fb4820000ffffff6f02000000f0ffff6f9e820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sending packet: $m40023714,4#62...Ack
Packet received: 28370240
Sending packet: $m40023728,14#98...Ack
Packet received: 0000000020770140540601004c33024000000000
Sending packet: $m4002334c,14#c1...Ack
Packet received: 00000040f4800000502f024058b6014028370240
Sending packet: $m80f4,4#cf...Ack
Packet received: 2f6c6962
Sending packet: $m80f8,4#d3...Ack
Packet received: 2f6c642d
Sending packet: $m80fc,4#fe...Ack
Packet received: 6c696e75
Sending packet: $m8100,4#96...Ack
Packet received: 782e736f
Sending packet: $m8104,4#9a...Ack
Packet received: 2e320000
Sending packet: $m4001b658,14#c8...Ack
Packet received: 0040024040b6014018bf0340d8b801404c330240
Sending packet: $m4001b640,4#8e...Ack
Packet received: 2f6c6962
Sending packet: $m4001b644,4#92...Ack
Packet received: 2f6c6962
Sending packet: $m4001b648,4#96...Ack
Packet received: 70746872
Sending packet: $m4001b64c,4#c1...Ack
Packet received: 6561642e
Sending packet: $m4001b650,4#8f...Ack
Packet received: 736f2e30
Sending packet: $m4001b654,4#93...Ack
Packet received: 00000000
Sending packet: $m4001b8d8,14#f9...Ack
Packet received: 00f00340c8b8014020ef14400000000058b60140
Sending packet: $m4001b8c8,4#c7...Ack
Packet received: 2f6c6962
Sending packet: $m4001b8cc,4#f2...Ack
Packet received: 2f6c6962
Sending packet: $m4001b8d0,4#c0...Ack
Packet received: 632e736f
Sending packet: $m4001b8d4,4#c4...Ack
Packet received: 2e360000
Sending packet: $m40023710,4#5e...Ack
Packet received: 01000000
warning: .dynamic section for "/lib/libpthread.so.0" is not at the expected address (wrong library or version mismatch?)
warning: .dynamic section for "/lib/libc.so.6" is not at the expected address (wrong library or version mismatch?)
Sending packet: $qSymbol::#5b...Ack
Packet received: qSymbol:6e70746c5f76657273696f6e
Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d...Ack
Packet received: OK
Sending packet: $qSymbol::#5b...Ack
Packet received: qSymbol:6e70746c5f76657273696f6e
Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d...Ack
Packet received: OK
Sending packet: $m4000c0e0,4#b9...Ack
Packet received: 8401a0e1
Sending packet: $Hg0#df...Ack
Packet received: E01
Sending packet: $p19#da...Ack
Packet received:
Sending packet: $g#67...Ack
Packet received: 040000004c33024000000000000000000300000000000000d8bf034000000000644890bef864024000300240a44990bea3760240504890beb4db0040e0c0004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000a0
Sending packet: $m4000c0e4,4#bd...Ack
Packet received: 040080e2
Sending packet: $X4000c0e4,4:\001\000\237?71...Ack
Packet received: OK
Sending packet: $vCont;c#a8...Ack
Packet received: T050b:a44990be;0d:504890be;0f:e4c00040;
Sending packet: $X4000c0e4,4:\004\000\200?48...Ack
Packet received: OK
Sending packet: $m4000c0e0,4#b9...Ack
Packet received: 8401a0e1
Sending packet: $X4000c0e0,4:\001\000\237?6d...Ack
Packet received: OK
Sending packet: $m84ac,4#fd...Ack
Packet received: 0c009fe5
Sending packet: $X84ac,4:\001\000\237?b1...Ack
Packet received: OK
Sending packet: $vCont;c#a8...Ack
Packet received: T050b:a44990be;0d:dc4790be;0f:e0c00040;
Sending packet: $X4000c0e0,4:\204\001犪#e4...Ack
Packet received: OK
Sending packet: $X84ac,4:\f\000\237?b2...Ack
Packet received: OK
Sending packet: $m40023714,4#62...Ack
Packet received: 28370240
Sending packet: $m40023728,14#98...Ack
Packet received: 0000000020770140540601004c33024000000000
Sending packet: $m4002334c,14#c1...Ack
Packet received: 00000040f4800000502f024058b6014028370240
Sending packet: $m80f4,4#cf...Ack
Packet received: 2f6c6962
Sending packet: $m80f8,4#d3...Ack
Packet received: 2f6c642d
Sending packet: $m80fc,4#fe...Ack
Packet received: 6c696e75
Sending packet: $m8100,4#96...Ack
Packet received: 782e736f
Sending packet: $m8104,4#9a...Ack
Packet received: 2e320000
Sending packet: $m4001b658,14#c8...Ack
Packet received: 0040024040b6014018bf0340d8b801404c330240
Sending packet: $m4001b640,4#8e...Ack
Packet received: 2f6c6962
Sending packet: $m4001b644,4#92...Ack
Packet received: 2f6c6962
Sending packet: $m4001b648,4#96...Ack
Packet received: 70746872
Sending packet: $m4001b64c,4#c1...Ack
Packet received: 6561642e
Sending packet: $m4001b650,4#8f...Ack
Packet received: 736f2e30
Sending packet: $m4001b654,4#93...Ack
Packet received: 00000000
Sending packet: $m4001b8d8,14#f9...Ack
Packet received: 00f00340c8b8014020ef14400000000058b60140
Sending packet: $m4001b8c8,4#c7...Ack
Packet received: 2f6c6962
Sending packet: $m4001b8cc,4#f2...Ack
Packet received: 2f6c6962
Sending packet: $m4001b8d0,4#c0...Ack
Packet received: 632e736f
Sending packet: $m4001b8d4,4#c4...Ack
Packet received: 2e360000
Sending packet: $m40023710,4#5e...Ack
Packet received: 01000000
Sending packet: $m4000c0e0,4#b9...Ack
Packet received: 8401a0e1
Sending packet: $g#67...Ack
Packet received: 000000004c33024000000000000000000200000000000000d8ef144000000000e04790bea8ab044000300240a44990be6dfd0440dc4790beb4db0040e0c0004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000a0
Sending packet: $m4000c0e4,4#bd...Ack
Packet received: 040080e2
Sending packet: $X4000c0e4,4:\001\000\237?71...Ack
Packet received: OK
Sending packet: $vCont;c#a8...Ack
Packet received: T050b:a44990be;0d:dc4790be;0f:e4c00040;
Sending packet: $X4000c0e4,4:\004\000\200?48...Ack
Packet received: OK
Sending packet: $m4000c0e0,4#b9...Ack
Packet received: 8401a0e1
Sending packet: $X4000c0e0,4:\001\000\237?6d...Ack
Packet received: OK
Sending packet: $m84ac,4#fd...Ack
Packet received: 0c009fe5
Sending packet: $X84ac,4:\001\000\237?b1...Ack
Packet received: OK
Sending packet: $vCont;c#a8...Ack
Packet received: X05

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

目标机:
gdbserver host:1234 test &
mx27# Process test created; pid = 1683
Listening on port 1234
Remote debugging from host 192.168.0.1
hello,world 3
ID 1083516176 ret = 0

Child terminated with signal = 5

Child terminated with signal = 0x5 (SIGTRAP)
GDBserver exiting

没能进入多线程的断点.

希望高手指点一下,谢谢!!

[ 本帖最后由 boliyun 于 2007-12-15 10:06 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2007-12-17 11:48 |只看该作者
你的程序确实是因SIGTRAP而退出的,gdbserver发给gdb的最后一个序列是
“Packet received: X05”,就表示程序因SIGTRAP而退出。

在X05序列之前,gdb发给gdbserver的序列是“vCont;c”,这是继续目标程
序的运行,也就是说,此时目标程序只是处于暂停状态,暂停的原因是
gdbserver之前上报的遇到0x4000c0e4处的临时断点的序列,这个临时断点
是因为gdb要控制目标程序跨越0x4000c0e0处的断点而插入的。到此为止的
过程都是正确的。

gdb在目标程序跨越过0x4000c0e0处的断点之后,发出vCont序列让目标程序
继续运行,这是gdbserver就直接上报X05序列。按照ptrace系统调用的设计,
在gdbserver跟目标程序之间通过参数为PTRACE_ATTACH的ptrace系统调用建
立了调试关系之后,发送给目标程序的任何信号都将被gdbserver捕获并通知
gdb,由gdb来决定是否将信号实际交付给目标程序,但在你的测试中,最后
的这个SIGTRAP显然并没有被gdbserver捕获,当然也没有经过gdb的处理,
而是直接由操作系统交付给了目标程序,目标程序自己收到SIGTRAP的结果就是
coredump。

根据你的试验,程序遇到0x4000c0e0处的断点是可以正确地被gdbserver捕获
并通知gdb处理的,但此时是“主线程”遇到的这个断点。你在子线程函数里面
插入的断点只有子线程会遇到,因此,我们可以认为,导致子线程因SIGTRAP
退出的就是你插入的断点,但这个断点产生的SIGTRAP没有被gdbserver捕获,
而是直接交付给了目标程序,对此的唯一解释就是gdbserver跟子线程之间没有
通过参数为PTRACE_ATTACH的ptrace系统调用建立调试关系。

在gdb邮件列表中,11月底有过一次跟你的问题类似的讨论,邮件标题为
“gdbserver and "terminated with signal SIGTRAP"”,你可以去看看。
你可以把gdbserver代码里的linux-low.c里的debug_threads的初始值修改为1,
然后重新编译一下gdbserver,再把调试打印贴上来,以确认是同一问题。

在上述邮件列表讨论中,Daniel Jacobowitz说“The new code I've added
since 6.7.1 for thread creation might help. ”。因此,你可以把
gdb/gdbserver的版本换成6.7.1再试试。这个应该是个小问题。

论坛徽章:
0
7 [报告]
发表于 2007-12-21 09:21 |只看该作者
版主厉害,谢谢,我升级了6.7,不行.现在去试下6.7.1...

等我消息.

论坛徽章:
0
8 [报告]
发表于 2008-01-18 09:13 |只看该作者
不好意思,最近忙别的去了。continue。。。
现象还是一样6.7.1版本,
我用cvs下了最新的gdb,可是编译出了问题,有人用过cvs的版本嘛?出来交流下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP