当线程卡在 64 位主机上的系统调用 32 位程序中时进行调试

Debug when thread is stuck in syscall 32bit program on 64 bit host

我遇到一个或多个线程相互锁定的问题。我不知道那里发生了什么。调试器无法中断(线程 1),中断但无法获取回溯(线程 2+5)或显示回溯(线程 3)

Gdb native 显示相同。

之所以如此,是因为 libc 在汇编程序中实现了这一点,而 gdb 无法正确处理堆栈。有时(我不知道什么时候),我可以在汇编中做一些步骤,然后我看到回溯。

我刚刚尝试了一个 x64 程序,它工作正常。

查看我的示例代码:

#include <time.h>

int main()
{
    while(1)
    {
        struct timespec ts;
        ts.tv_sec = 1;
        ts.tv_nsec = 0;

        clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, 0);
    }
    return 1;
}

gdb 输出 32 位:

vagrant@PC41388-spvm-4650:/tmp$ gdb main32

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from main32...(no debugging symbols found)...done.

(gdb) r Starting program: /tmp/main32 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". ^C Program received signal

SIGINT, Interrupt. 0x55579cd9 in ?? () (gdb) bt

#0 0x55579cd9 in ?? ()

#1 0x555b0af3 in __libc_start_main (main=0x80484dd , argc=1, argv=0xffffcee4, init=0x8048520 <__libc_csu_init>, fini=0x8048590 <__libc_csu_fini>, rtld_fini=0x55564160 <_dl_fini>, stack_end=0xffffcedc) at libc-start.c:287

#2 0x08048401 in _start () (gdb)

gdb 输出 64 位:

vagrant@PC41388-spvm-4650:/tmp$ gdb main64

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from main64...(no debugging symbols found)...done.

(gdb) r Starting program: /tmp/main64 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". b ^C Program received signal SIGINT, Interrupt. 0x00002aaaaafe092a in __clock_nanosleep (clock_id=1, flags=0, req=0x7fffffffdc10, rem=0x2aaaaafe092a <__clock_nanosleep+58>) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:41 41 ../sysdeps/unix/sysv/linux/clock_nanosleep.c: No such file or directory.

(gdb) bt

#0 0x00002aaaaafe092a in __clock_nanosleep (clock_id=1, flags=0, req=0x7fffffffdc10, rem=0x2aaaaafe092a <__clock_nanosleep+58>) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:41

#1 0x0000000000400630 in main () (gdb)

set architecture i386 也无济于事。

更多新闻:info proc mapp 显示 x32 应用程序在 [vvar] 而 x64 应用程序在 libc。这可以解释为什么 gdb 找不到回溯。

所以我的问题是:是否有不同版本的 libc,它在哪里工作?我用的是ubuntu14.04.

我更新了一个更新的gdb版本(目前是最新的,7.12.1)。这解决了问题。

请注意,gbd:i386 在 lubuntu x64 上也不起作用,而在 lubuntu x32 下却运行良好。另请注意,main32 和 libc 在 lubuntu x64 和 x32 上的二进制文件相同。