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?

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)