c - 当线程卡在 64 位主机上的 syscall 32 位程序中时进行调试

标签 c gdb system-calls 32bit-64bit libc

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

Debug view in eclipse. Gdb native 显示相同。

learned出现这种情况是因为 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)

设置架构 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 上都是相同的二进制文件。

关于c - 当线程卡在 64 位主机上的 syscall 32 位程序中时进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42827774/

相关文章:

编译 -ansi -pedantic -Wall 自动切换 gcc

c - MPI死锁梯形函数的线性减少

c - 如何在使用 open() 时设置文件的共享模式

c - 为什么每次在 GDB 中构建 + 反汇编函数时都会得到相同的地址?

c++ - gdb 只显示发生错误的函数(segmentation fault)

linux - 扫描一个整数并在 NASM 中打印区间 (1, integer)

c - TCP 套接字实现总是给出旧值

c - 在gdb中调试时如何检查哪个文件声明了变量?

linux - ioctl 的工作原理(2)

interrupt - 为什么使用中断处理系统调用?