使用GDB在main()之前调试错误 [英] Debug error before main() using GDB

查看:37
本文介绍了使用GDB在main()之前调试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用GDB执行main()函数之前,是否有调试链接错误或任何可能发生的错误的方法?

Is there anyway to debug a link error or any kind of error that may occur before the execution of the main() function using GDB?

推荐答案

反正还有调试链接错误

Is there anyway to debug a link error

大概是在询问运行时链接错误(例如,错误:libfoo.so:没有此类文件或目录"),而不是构建过程中的(静态)链接步骤.

Presumably you are asking about runtime link error (e.g. `error: libfoo.so: no such file or directory'), and not about (static) link step of your build process.

诀窍是在系统调用 exit 或(Linux上的 exit_group )上设置断点,例如捕获系统调用出口.然后,您将在 ld.so 中停止运行,以免它运行您的二进制文件.

The trick is to set a breakpoint on exit or (exit_group on Linux) system call with e.g. catch syscall exit. You will then be stopped inside ld.so at the point where it gives up running your binary.

还是使用GDB执行main()函数之前可能发生的任何类型的错误?

or any kind of error that may occur before the execution of the main() function using GDB?

任何其他类型的错误,例如 SIGSEGV 可以正常"调试-表示您根本不需要执行任何操作-GDB将会停止.对于其他错误,只需照常设置断点即可.

Any other kind of error, e.g. SIGSEGV can be debugged "normally" -- for signal you don't need to do anything at all -- GDB will just stop. For other errors, just set a breakpoint as usual.

这篇关于使用GDB在main()之前调试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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