使用 GDB 进行 MPI 调试 - 当前上下文中没有符号“i”

Een*_*oku 2 c ubuntu gdb mpi

我需要调试我用 C 编写的 MPI 应用程序。我想使用 GDB 手动附加到进程的系统,正如这里推荐的那样(第 6 段)。

问题是,当我尝试打印变量“i”的值时,出现此错误:

No symbol "i" in current context.
Run Code Online (Sandbox Code Playgroud)

同样的问题是set var i=5. 当我尝试运行时info local,它只是声明“无语言环境”。

  • 系统Ubuntu 14.04
  • MPICC cc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
  • GDB GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1。

我用命令编译我的代码

mpicc -o hello hello.c
Run Code Online (Sandbox Code Playgroud)

并执行它

mpiexec -n 2 ./hello
Run Code Online (Sandbox Code Playgroud)

我试图寻找这个问题,但解决方案通常是在 GCC 中不使用任何优化 (-O) 选项,但这对我没有用,因为我在这里没有使用它们中的任何一个,我正在编译与 MPICC。我已经尝试将 "i" 变量声明为volatile,并mpicc使用-gand启动-O0,但没有任何帮助。


DBG消息

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".
Attaching to process 3778
Reading symbols from /home/martin/Dokumenty/Programovani/mpi_trenink/hello...done.
Reading symbols from /usr/lib/x86_64-linux-gnu/libmpich.so.10...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libmpich.so.10
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /usr/lib/x86_64-linux-gnu/libmpl.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libmpl.so.1
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/librt-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/librt.so.1
Reading symbols from /usr/lib/libcr.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libcr.so.0
Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libpthread-2.19.so...done.
done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Loaded symbols for /lib/x86_64-linux-gnu/libpthread.so.0
Reading symbols from /lib/x86_64-linux-gnu/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libgcc_s.so.1
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libdl-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libdl.so.2
Reading symbols from /lib/x86_64-linux-gnu/libnss_files.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_files-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libnss_files.so.2
0x00007f493e53c9a0 in __nanosleep_nocancel ()
    at ../sysdeps/unix/syscall-template.S:81
81  ../sysdeps/unix/syscall-template.S: No such file or directory.
Run Code Online (Sandbox Code Playgroud)

我的代码

#include <stdio.h>
#include <mpi.h>

#include <unistd.h> // sleep()

int main(){
    MPI_Init(NULL, NULL);
    
    /* DEBUGGING STOP */

    int i = 0;
    while(i == 0){
        sleep(30);
    }

    int world_size;
    MPI_Comm_size( MPI_COMM_WORLD, &world_size );

    int process_id; // casto znaceno jako 'world_rank'
    MPI_Comm_rank( MPI_COMM_WORLD, &process_id );

    char processor_name[ MPI_MAX_PROCESSOR_NAME ];
    int name_len;
    MPI_Get_processor_name( processor_name, &name_len );

    printf("Hello! - sent from process %d running on processor %s.\n\
        Number of processors is %d.\n\
        Length of proc name is %d.\n\
        ***********************\n",
        process_id, processor_name, world_size, name_len);

    MPI_Finalize();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Hri*_*iev 5

GDB 很有可能在深入执行sleep(3)功能的同时打破流程。您可以通过首先发出bt(backtrace) 命令来检查:

(gdb) bt
#0  0x00000030e0caca3d in nanosleep () from /lib64/libc.so.6
#1  0x00000030e0cac8b0 in sleep () from /lib64/libc.so.6
#2  0x0000000000400795 in main (argc=1, argv=0x7fff64ae4688) at sleeper.c:9
Run Code Online (Sandbox Code Playgroud)

i不存在于 的框架中nanosleep

(gdb) info locals
No symbol table info available.
Run Code Online (Sandbox Code Playgroud)

main通过发出frame x命令来选择函数的堆栈帧(其中x是帧编号,2在所示示例中)。

(gdb) f 2
#2  0x0000000000400795 in main (argc=1, argv=0x7fff64ae4688) at sleeper.c:9
9          while(i == 0) { sleep(30); }
Run Code Online (Sandbox Code Playgroud)

i 现在应该在那里:

(gdb) info locals
i = 0
Run Code Online (Sandbox Code Playgroud)

如果 GDB 碰巧附加到错误的线程,您可能还需要更改活动线程。许多 MPI 库会产生额外的线程,例如使用英特尔 MPI:

(gdb) info threads
  3 Thread 0x7f8b9fada700 (LWP 39085)  0x00000030e0cdf1b3 in poll () from /lib64/libc.so.6
  2 Thread 0x7f8b9f0d9700 (LWP 39087)  0x00000030e0cdf1b3 in poll () from /lib64/libc.so.6
* 1 Thread 0x7f8ba1b51700 (LWP 39066)  0x00000030e0caca3d in nanosleep () from /lib64/libc.so.6
Run Code Online (Sandbox Code Playgroud)

标记*为的线程是正在检查的线程。如果其他线程处于活动状态,请使用thread 1命令切换到主线程。