dqask02082 2016-11-14 06:48
浏览 220

使用gdb遇到问号调试Go代码

I read golang official gdb document here https://golang.org/doc/gdb

And I'm curious about what causes question mark when inspecting the stack.

(gdb) bt  # backtrace
#0  regexp.TestFind (t=0xf8404a89c0) at /home/user/go/src/regexp/find_test.go:148
#1  0x000000000042f60b in testing.tRunner (t=0xf8404a89c0, test=0x573720) at /home/user/go/src/testing/testing.go:156
#2  0x000000000040df64 in runtime.initdone () at /home/user/go/src/runtime/proc.c:242
#3  0x000000f8404a89c0 in ?? ()
#4  0x0000000000573720 in ?? ()
#5  0x0000000000000000 in ?? ()

So, Is the gdb optimizations caused the question mark? Or what on earth result in such question mark?

One more question, How can I retrieve the message hiden behind question mark?

  • 写回答

1条回答 默认 最新

  • dpthuyh1678 2016-11-14 07:24
    关注

    The code, probably, has stripped debugging symbols:

    gcc -s
    

    You can see that behavior with this simple sample

    #include <stdio.h>
    
    void riskyCode() {
      char *error_str = "This code will fail with SIGSEGV";
      *error_str = 'g';
    }
    
    int c() {
      riskyCode();
      return 1;
    }
    
    int b() {
      return c();
    }
    
    int a() {
      return b();
    }
    
    int main() {
      return a();
    }
    

    Compile it like this

    gcc -s -O0 -o main main.c
    

    And run code in gdb

    gdb main
    > run
    

    Then, you will see ?? in stack locations

    bt
    #0  0x000000000040056a in ?? ()
    #1  0x000000000040057d in ?? ()
    #2  0x0000000000400592 in ?? ()
    #3  0x00000000004005a2 in ?? ()
    #4  0x00000000004005b2 in ?? ()
    #5  0x00002aaaaacebc36 in __libc_start_main () from /lib64/libc.so.6
    #6  0x0000000000400429 in ?? ()
    #7  0x00007fffffff93f8 in ?? ()
    #8  0x000000000000001c in ?? ()
    #9  0x0000000000000001 in ?? ()
    #10 0x00007fffffff9ca2 in ?? ()
    #11 0x0000000000000000 in ?? ()
    

    Try to use very same library, but compiled with debugging symbols?

    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿