GDB:断点不会被击中 [英] GDB : breakpoint does not get hit

查看:114
本文介绍了GDB:断点不会被击中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个用-g和-O编译器标志编译的大二进制文件。问题在于,在使用gdb进行调试时,在某些文件/行中设置断点不会在该文件/行处中断,或者会在其他行中中断。我知道这可能是由于-O编译器标志(用于优化)。不幸的是,我无法移除编译器-O标志,因为有许多脚本级别需要注意。

We have a large binary compiled with -g and -O compiler flags. The issue is that setting the breakpoint in some files/line does not breaks at that file/line or breaks in some other line while debugging using gdb. I understand that this could be due to due to the -O compiler flag (used for optimization). Unfortunately I am not in a position to remove the compiler -O flag as there are many a scripts level that I need to take care.

我如何确保使代码在我想要的文件/行位置中断?是否有一行代码,我可以添加它将永远不会优化或使用gdb调试时会中断 - 我试过这样的事情 -

How can I ensure to make the code breaks at a file/line place I want? Is there a line of code that I can add which will always be not optimized or will break when debugging using gdb - I tried something like this -

int x;
int y;

int x; int y;

但是仍然GDB断点无法正常工作 - 我如何正确设置它?

But still then the GDB break point did not work properly - how can I set it correctly?

推荐答案

有两个问题我可以考虑,内联和优化。由于没有标准的方式来告诉编译器禁用内联和/或优化,所以您只能以编译器特定的方式执行它。

To disable inlining in GCC, you can use __attribute__((noinline)) on the method.

禁用在GCC中内联,您可以在该方法上使用 __ attribute __((noinline))

禁止编译器优化功能(并且,未经测试,可为您提供稳定的代码行,您可以在其中设置断点),只需将其添加到代码中;

To disallow the compiler to optimise functions away (and, untested, give you a stable line of code where you can set your breakpoint), just add this to the code;

asm ("");

这些都记录在 at this page

这篇关于GDB:断点不会被击中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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