英文:
Debugging go code with gdb encountering question mark
问题
我阅读了Golang官方的GDB文档,链接在这里:https://golang.org/doc/gdb
我对在检查堆栈时导致问号出现的原因很好奇。
(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 ?? ()
那么,是GDB的优化导致了问号吗?或者到底是什么导致了这样的问号?
还有一个问题,我如何获取问号后面隐藏的消息?
英文:
I read golang official gdb document here <strike>https://golang.org/doc/gdb</strike>
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
得分: 1
代码可能已经剥离了调试符号:
gcc -s
你可以通过以下简单示例来观察这种行为:
#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();
}
像这样编译它:
gcc -s -O0 -o main main.c
然后在gdb中运行代码:
gdb main
> run
然后,你将在堆栈位置看到"??":
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 ?? ()
尝试使用相同的库,但是带有调试符号编译?
英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论