gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 00:37:07 25 4
gpt4 key购买 nike

我需要调试我用 C 编写的 MPI 应用程序。我想使用带有手动附加到进程的 GDB 的系统,这是推荐的 here (第 6 段)。

问题是,当我尝试打印变量“i”的值时,我得到了这个错误:

No symbol "i" in current context.

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

并用

执行
mpiexec -n 2 ./hello

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


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.

我的代码

#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;
}

最佳答案

GDB 很可能会在深入执行 sleep(3) 函数时中断进程。您可以通过首先发出 bt(回溯)命令来检查:

(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

i 不在 nanosleep 的帧中:

(gdb) info locals
No symbol table info available.

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

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

i 现在应该在那里:

(gdb) info locals
i = 0

如果 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

标有* 的线程是被检查的线程。如果其他线程处于事件状态,则使用 thread 1 命令切换到主线程。

关于c - 使用 GDB 进行 MPI 调试 - 当前上下文中没有符号 "i",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27692186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com