即使使用 -g3 或 -ggdb3 或 -gdwarf-4 也不存在 gdb 宏符号 [英] gdb macro symbols not present even when using -g3 or -ggdb3 or -gdwarf-4

查看:26
本文介绍了即使使用 -g3 或 -ggdb3 或 -gdwarf-4 也不存在 gdb 宏符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 C 文件(sample.c):

I have this C file (sample.c):

#include <stdio.h>
#define M 42
#define ADD(x) (M + x)
int main ()
{
  printf("%d
", M);
  printf("%d
", ADD(2));
  return 0;
}

我用来编译的:

$ gcc -O0 -Wall -g3 sample.c -o sample

然后调试

$ gdb ./sample
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 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-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /tmp/sample...done.
(gdb) macro list
(gdb) macro expand ADD(2)
expands to: ADD(2)
(gdb) print M
No symbol "M" in current context.
(gdb) q

这曾经有效.我需要它来工作,因为我正在使用 #define 硬件外围设备和内存地址名称的库.

This used to work. I need this to work because I am using libraries which #define names for hardware peripherals and memory addresses.

这似乎与 Sourceware 上显示的行为直接矛盾gdb 站点.

我做错了什么?

推荐答案

看起来宏需要以一种或另一种方式引入范围".如果您完全按照链接到的页面中的示例进行操作,它们就会像宣传的那样工作(至少它们对我有用).

Looks like the macros need to be "brought in scope" one way or another. If you follow exactly the examples in the page you link to, they work as advertised (at least they do for me).

示例(t.c 是您的源文件):

Example (t.c is your source file):

$ gcc -O0 -g3 t.c
$ gdb ./a.out 
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
...
Reading symbols from .../a.out...done.
(gdb) info macro ADD
The symbol `ADD' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
             // Macros not loaded yet
(gdb) list main
1   #include <stdio.h>
2   #define M 42
3   #define ADD(x) (M + x)
4   int main ()
5   {
6     printf("%d
", M);
7     printf("%d
", ADD(2));
8     return 0;
9   }
(gdb) info macro ADD
Defined at /home/foo/tmp/t.c:3
#define ADD(x) (M + x)
             // Macros "in scope"/loaded
(gdb) macro expand ADD(42)
expands to: (42 + 42)
(gdb) macro expand M      
expands to: 42
(gdb) macro expand ADD(M)
expands to: (42 + 42)
(gdb) 

或者:

$ gdb ./a.out 
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
...
Reading symbols from .../a.out...done.
(gdb) macro expand ADD(1)
expands to: ADD(1)
             // Macros not available yet
(gdb) break main
Breakpoint 1 at 0x400538: file t.c, line 6.
(gdb) r
Starting program: /home/foo/tmp/a.out 
Breakpoint 1, main () at t.c:6
6     printf("%d
", M);
(gdb) macro expand ADD(1)
expands to: (42 + 1)
             // Macros loaded
(gdb) 

这篇关于即使使用 -g3 或 -ggdb3 或 -gdwarf-4 也不存在 gdb 宏符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆