gdb 可以调试 gcc 风格的嵌套 C 函数吗?

发布于 2024-12-12 03:02:05 字数 57 浏览 0 评论 0原文

是否可以让 gdb 调试器使用 gcc 样式的嵌套函数?如果是这样,需要什么版本的 gcc/gdb?

Is it possible to get the gdb debugger to work with gcc-style nested functions? If so, what versions of gcc/gdb are needed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

英雄似剑 2024-12-19 03:02:05

看起来还没有。有一个相应的错误 http://sourceware.org/bugzilla/show_bug.cgi? id=8300

Looks like no yet. There is a corresponding bug for it http://sourceware.org/bugzilla/show_bug.cgi?id=8300.

℡Ms空城旧梦 2024-12-19 03:02:05

看来 gcc/gdb 已经掌握了它的窍门。对于早期版本,它不起作用,但这里是一个简单会话的记录:

jla@jla-desktop$ gdb --version
GNU gdb (GDB) Fedora (7.2-51.fc14)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
~
jla@jla-desktop$ gcc --version
gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

~
jla@jla-desktop$ cat hello.c
#include<stdio.h>

void main(void)
{
    char* hello="hello";
    int sub(int a){
        int b;
        int c;
        b=a;
        a++;
        c=a;
        return a+b+c;
    }

    printf("%s(%i)\n", hello, sub(3));
}

~
jla@jla-desktop$ gcc -ggdb3 hello.c -o hello
~
jla@jla-desktop$ gdb hello
GNU gdb (GDB) Fedora (7.2-51.fc14)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jla/hello...done.
(gdb) b main
Breakpoint 1 at 0x80483f1: file hello.c, line 5.
(gdb) list
1   #include<stdio.h>
2   
3   void main(void)
4   {
5       char* hello="hello";
6       int sub(int a){
7           int b;
8           int c;
9           b=a;
10          a++;
(gdb) r
Starting program: /home/jla/hello 

Breakpoint 1, main () at hello.c:5
5       char* hello="hello";
Missing separate debuginfos, use: debuginfo-install glibc-2.13-2.i686
(gdb) info locals
hello = 0x7aeff4 "|\355z"
(gdb) s
15      printf("%s(%i)\n", hello, sub(3));
(gdb) s
sub (a=3) at hello.c:9
9           b=a;
(gdb) info locals
b = 134518388
c = 0
(gdb) p a
$1 = 3
(gdb) p b
$2 = 134518388
(gdb) p c
$3 = 0
(gdb) where
#0  sub (a=3) at hello.c:9
#1  0x08048405 in main () at hello.c:15
(gdb) 

It appears that gcc/gdb have got the hang of it. With earlier versions it just didn't work, but here's a transcript of a simple session:

jla@jla-desktop$ gdb --version
GNU gdb (GDB) Fedora (7.2-51.fc14)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
~
jla@jla-desktop$ gcc --version
gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

~
jla@jla-desktop$ cat hello.c
#include<stdio.h>

void main(void)
{
    char* hello="hello";
    int sub(int a){
        int b;
        int c;
        b=a;
        a++;
        c=a;
        return a+b+c;
    }

    printf("%s(%i)\n", hello, sub(3));
}

~
jla@jla-desktop$ gcc -ggdb3 hello.c -o hello
~
jla@jla-desktop$ gdb hello
GNU gdb (GDB) Fedora (7.2-51.fc14)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jla/hello...done.
(gdb) b main
Breakpoint 1 at 0x80483f1: file hello.c, line 5.
(gdb) list
1   #include<stdio.h>
2   
3   void main(void)
4   {
5       char* hello="hello";
6       int sub(int a){
7           int b;
8           int c;
9           b=a;
10          a++;
(gdb) r
Starting program: /home/jla/hello 

Breakpoint 1, main () at hello.c:5
5       char* hello="hello";
Missing separate debuginfos, use: debuginfo-install glibc-2.13-2.i686
(gdb) info locals
hello = 0x7aeff4 "|\355z"
(gdb) s
15      printf("%s(%i)\n", hello, sub(3));
(gdb) s
sub (a=3) at hello.c:9
9           b=a;
(gdb) info locals
b = 134518388
c = 0
(gdb) p a
$1 = 3
(gdb) p b
$2 = 134518388
(gdb) p c
$3 = 0
(gdb) where
#0  sub (a=3) at hello.c:9
#1  0x08048405 in main () at hello.c:15
(gdb) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文