No symbol "xxx" in current context

gdb调试时报找不到符号(No symbol "pthread_cond_t" in current context.),可用如下方式让其显示出来。

首先:另外创建个源文件,对gdb中无法显示类型信息的类型定义变量,如foo.c文件。用 -g选项编译

bash$ cat foo.c
#include <pthread.h>
pthread_cond_t p;
pthread_mutex_t m;
bash$ gcc -g -c foo.c

然后:使用add-symbol-file将foo.o文件的符号添加至hello二进制文件中

<span style="color:#222222;">(gdb) add-symbol-file foo.o </span><strong><span style="color:#ff0000;">0</span></strong><span style="color:#222222;">
add symbol table from file "foo.o" at
        .text_addr = 0x0
(y or n) y
Reading symbols from /data/home/jakciehan/tmp/pthread_test/foo.o...done.
(gdb) p *(pthread_mutex_t *)(0xbfa4bc74)
$1 = {
  __data = {
    __lock = 2, 
    __count = 0, 
    __owner = 8205, 
    __kind = 0, 
    __nusers = 1, 
    {
      __spins = 0, 
      __list = {
        __next = 0x0
      }
    }
  }, 
  __size = "\002\000\000\000\000\000\000\000\r \000\000\000\000\000\000\001\000\000\000\000\000\000", 
  __align = 2
}</span>




你可能感兴趣的:(C++,gdb,调试)