GNU gdb无法进入模板功能(OS X Mavericks) [英] GNU gdb can not step into template functions (OS X Mavericks)

查看:171
本文介绍了GNU gdb无法进入模板功能(OS X Mavericks)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在OS X Mavericks(10.9.2)下安装了 gdb 7.7 (来自GNU资源)。我对它进行了签名,所以无论何时调试不包含模板的 c ++ 文件,它都能正常工作。但是,它无法进入模板功能(可以进入常规功能,但只是无法进入模板化功能)。当我在调试会话中键入 step 命令时,它只是跨越该函数,就好像调试符号不存在于模板函数中一样。我的模板函数甚至不是一个成员函数,它只是一个在 main.cpp 中定义的简单函数。



我使用 g ++ -g -O0 main.cpp 来编译我的程序(我使用 g ++ 4.8.2 from macports 而不是 clang ++ ),甚至试过 -fno-inline ,仍然是同样的行为,不能进入模板功能。这是OS X Mavericks下的 gdb 已知问题吗?或者,任何人都可以重现该错误?



我的代码:

  #include< iostream> 

模板< typename T> // template
void f(T x)
{
std :: cout<< 在f:<<的std :: ENDL;
std :: cout<< x<<的std :: ENDL;
}

void g()//非模板
{
std :: cout<< 它在这里工作! <<的std :: ENDL;
std :: cout<< 退出g()...<<的std :: ENDL;


int main()
{
f< double>(12.3); // gdb不会进入f()
g(); // gdb步入g()
}

无法跨入<$ c $在 f< double>(12.3)的断点之后,c> f 。
如果我的代码中 f()是一个常规函数,比如 g(),那么它步入。
Thanks!

更新: gdb 可以在任何其他操作系统下使用,例如 Linux / Windows的/ solaris的。这似乎是与OS X有关的问题。

 读取a.out ... done中的符号。 
(gdb)反汇编main
函数main()的汇编代码转储:
0x0000000100000d62< + 0> ;: push%rbp
0x0000000100000d63< + 1> ;: mov% rsp,%rbp
0x0000000100000d66< + 4> ;: movabs $ 0x402899999999999a,%rax
0x0000000100000d70< + 14> ;: movq%rax,%xmm0
0x0000000100000d75< + 19> ;: callq 0x100000e44
0x0000000100000d7a< + 24> ;: callq 0x100000d0c< g()>
0x0000000100000d7f< + 29>:mov $ 0x0,%eax
0x0000000100000d84< + 34> ;: pop%rbp
0x0000000100000d85< + 35> ;: retq
汇编程序结束倾倒。
(gdb)

现在我们在 main()

 (gdb)b main 
在0x100000d66处的断点1:file src / templated_bug.cpp,第22行。
(gdb)r
启动程序:/Users/vlad/template_gdb_bug/a.out

断点1,main()在src /templated_bug.cpp:22
22 f< double>(12.3);
(gdb)s
在f:
12.3
23 g();
(gdb)s
g()at src / templated_bug.cpp:16
16 cout<<它在此工作!<< endl;
(gdb)s
它可以在这里使用!
17 cout<<退出g()...<< endl;
(gdb)s
退出g()...
18}
(gdb)s
main()在src / templated_bug.cpp:24
24}
(gdb)s
[下1(进程50945)正常退出]
(gdb)

正如你所看到的,它不会进入 f(),但是 g() 。此外,

 (gdb)反汇编f 
在当前上下文中没有符号f。

然而,对于另一个函数 g()

 (gdb)反汇编g 
转储用于函数g()的汇编代码:
0x0000000100000d0c< + 0> ;: push%rbp
0x0000000100000d0d< + 1> ;: mov%rsp,%rbp
0x0000000100000d10< + 4> :0x193(%rip),%rsi#0x100000eaa
0x0000000100000d17< + 11> ;: mov 0x2ea(%rip),%rax#0x100001008
0x0000000100000d1e< +18> ;: mov%rax, rdi
0x0000000100000d21< + 21> ;: callq 0x100000e5c
0x0000000100000d26< + 26> ;: mov 0x2e3(%rip),%rdx#0x100001010
0x0000000100000d2d< + 33> ;: mov%rdx ,%rsi
0x0000000100000d30 <+ 36>:mov%rax,%rdi
0x0000000100000d33 <+ 39>:callq 0x100000e4a
0x0000000100000d38< + 44> ;: lea 0x17a(%rip) ,%rsi#0x100000 eb9
0x0000000100000d3f< + 51> ;: mov 0x2c2(%rip),%rax#0x100001008
0x0000000100000d46< + 58> ;: mov%rax,%rdi
0x0000000100000d49< + 61> :callq 0x100000e5c
0x0000000100000d4e< + 66> ;: mov 0x2bb(%rip),%rdx#0x100001010
0x0000000100000d55< + 73> ;: mov%rdx,%rsi
0x0000000100000d58< 76>:mov%rax,%rdi
0x0000000100000d5b< + 79> ;: callq 0x100000e4a
0x0000000100000d60< + 84> ;: pop%rbp
0x0000000100000d61< +85> ;: retq
汇编器转储结束。


解决方案

在gdb的MacOS端口进入命令。作为解决方法,您可以在函数start处设置断点,以便进入模板函数:

 (gdb)b f 断点1在0x1000015ab:文件./gdb_tmpl.cpp,第6行。
(gdb)运行
启动程序:/Users/vershov/tmp/tests/a.out

断点1,f< double> (x = 12.300000000000001)在./gdb_tmpl.cpp:6
6 std :: cout<< 在f:<<的std :: ENDL;

另外,您可以反汇编它,只需使用正确的命令即可:

 (gdb)disass f 
在当前上下文中没有符号f。
(gdb)disass f< double>
函数f的汇编代码转储< double>(double):
0x0000000100001590< + 0> ;: push%rbp
0x0000000100001591< + 1> ;: mov%rsp,%rbp
0x0000000100001594< + 4>:sub $ 0x40,%rsp
0x0000000100001598< + 8> ;: mov 0xa71(%rip),%rdi#0x100002010
0x000000010000159f< + 15>:lea 0x9a0(%rip),%rsi#0x100001f46
...


I have installed gdb 7.7 (from GNU sources) under OS X Mavericks (10.9.2). I codesigned it, so it works fine whenever I debug a c++ file that does not contain templates. However, it is unable to step into template functions (can step into regular functions, but just fails to step into templated ones). When I type step command in a debugging session, it just steps over the function, as if the debugging symbols are not present for the template function. My template function is not even a member function, is just a simple function defined inside the main.cpp.

I compile my program with g++ -g -O0 main.cpp (I use g++4.8.2 from macports and not clang++), even tried -fno-inline, still same behaviour, cannot step into template functions. Is this a gdb known problem under OS X Mavericks? Or, can anyone reproduce the bug?

my code:

#include <iostream>

template <typename T> // template
void f(T x)
{
    std::cout << "In f:" << std::endl;
    std::cout << x << std::endl;
}

void g() // non-template
{
    std::cout << "It works here!" << std::endl;
    std::cout << "Exiting g()..." << std::endl;
}

int main() 
{
    f<double>(12.3); // gdb does not step into f()
    g(); // gdb steps into g()
}

Can not step in f after a breakpoint at f<double>(12.3). If f() is a regular function, such as g() in my code, then it steps into. Thanks!

Update: gdb works as it should under any other OS, such as linux/windows/solaris. It seems to be a problem related to OS X.

Reading symbols from a.out...done.
(gdb) disassemble main
Dump of assembler code for function main():
   0x0000000100000d62 <+0>: push   %rbp
   0x0000000100000d63 <+1>: mov    %rsp,%rbp
   0x0000000100000d66 <+4>: movabs $0x402899999999999a,%rax
   0x0000000100000d70 <+14>:    movq   %rax,%xmm0
   0x0000000100000d75 <+19>:    callq  0x100000e44
   0x0000000100000d7a <+24>:    callq  0x100000d0c <g()>
   0x0000000100000d7f <+29>:    mov    $0x0,%eax
   0x0000000100000d84 <+34>:    pop    %rbp
   0x0000000100000d85 <+35>:    retq
End of assembler dump.
(gdb)

Now we set a breakpoint at the entry of main()

(gdb) b main
Breakpoint 1 at 0x100000d66: file src/templated_bug.cpp, line 22.
(gdb) r
Starting program: /Users/vlad/template_gdb_bug/a.out

Breakpoint 1, main () at src/templated_bug.cpp:22
22      f<double>(12.3);
(gdb) s
In f:
12.3
23      g();
(gdb) s
g () at src/templated_bug.cpp:16
16      cout<<"It works here!"<<endl;
(gdb) s
It works here!
17      cout<<"Exiting g()..."<<endl;
(gdb) s
Exiting g()...
18  }
(gdb) s
main () at src/templated_bug.cpp:24
24  }
(gdb) s
[Inferior 1 (process 50945) exited normally]
(gdb)

As you can see, it does not step inside f() but steps inside g(). Moreover,

(gdb) disassemble f
No symbol "f" in current context.

However, for another function g() that is non-template, the symbols are loaded and I can disassemble it.

(gdb) disassemble g
Dump of assembler code for function g():
   0x0000000100000d0c <+0>: push   %rbp
   0x0000000100000d0d <+1>: mov    %rsp,%rbp
   0x0000000100000d10 <+4>: lea    0x193(%rip),%rsi        # 0x100000eaa
   0x0000000100000d17 <+11>:    mov    0x2ea(%rip),%rax        # 0x100001008
   0x0000000100000d1e <+18>:    mov    %rax,%rdi
   0x0000000100000d21 <+21>:    callq  0x100000e5c
   0x0000000100000d26 <+26>:    mov    0x2e3(%rip),%rdx        # 0x100001010
   0x0000000100000d2d <+33>:    mov    %rdx,%rsi
   0x0000000100000d30 <+36>:    mov    %rax,%rdi
   0x0000000100000d33 <+39>:    callq  0x100000e4a
   0x0000000100000d38 <+44>:    lea    0x17a(%rip),%rsi        # 0x100000eb9
   0x0000000100000d3f <+51>:    mov    0x2c2(%rip),%rax        # 0x100001008
   0x0000000100000d46 <+58>:    mov    %rax,%rdi
   0x0000000100000d49 <+61>:    callq  0x100000e5c
   0x0000000100000d4e <+66>:    mov    0x2bb(%rip),%rdx        # 0x100001010
   0x0000000100000d55 <+73>:    mov    %rdx,%rsi
   0x0000000100000d58 <+76>:    mov    %rax,%rdi
   0x0000000100000d5b <+79>:    callq  0x100000e4a
   0x0000000100000d60 <+84>:    pop    %rbp
   0x0000000100000d61 <+85>:    retq
End of assembler dump.

解决方案

In seems there is an issues with the step into command at MacOS port of gdb. As workaround you could set breakpoint at the function start to step into the template function:

(gdb) b f<double>
Breakpoint 1 at 0x1000015ab: file ./gdb_tmpl.cpp, line 6.
(gdb) run
Starting program: /Users/vershov/tmp/tests/a.out 

Breakpoint 1, f<double> (x=12.300000000000001) at ./gdb_tmpl.cpp:6
6       std::cout << "In f:" << std::endl;

Also, you could disassemble it, just use correct command:

(gdb) disass f
No symbol "f" in current context.
(gdb) disass f<double>
Dump of assembler code for function f<double>(double):
   0x0000000100001590 <+0>: push   %rbp
   0x0000000100001591 <+1>: mov    %rsp,%rbp
   0x0000000100001594 <+4>: sub    $0x40,%rsp
   0x0000000100001598 <+8>: mov    0xa71(%rip),%rdi        # 0x100002010
   0x000000010000159f <+15>:    lea    0x9a0(%rip),%rsi        # 0x100001f46
...

这篇关于GNU gdb无法进入模板功能(OS X Mavericks)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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