GDB条件中断功能参数 [英] GDB conditional break on function parameter

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

问题描述

我想在函数参数上设置一个断点,如果该断点大于某个值.伪代码如下:

I'm wanting to set a breakpoint on a function parameter if it is greater than a certain value. Dummy code below:

int main(void)
{
    uint64_t num = 123456;
    uint64_t x   = 847534;

    uint64_t other = (num*x) - (x/num);

    .... other stuff here (multithreaded stuff)

    calc(other);
}

void calc(uint64_t size)
{
    ...do some stuff with size
}

我尝试通过以下方式设置断点:

I've tried to set a breakpoint by:

(gdb) b calc if size == 852479

但是它不知道大小是多少,因为它是我猜测的参数.如果参数等于某个数字,我将如何中断.不能选择中断对该函数的所有调用,因为在多线程环境中该函数被调用十亿次.

but it does not know what size is since it is a parameter I'm guessing. How would I break if the parameter equals a certain number. It is NOT an option to break on all the calls to this function because it gets called a billion times in the multithreaded environment.

推荐答案

假定 x86-64调用约定在GNU/Linux平台上,您可以直接检查%rdi (64位)寄存器以检查函数的第一个参数:

Assuming x86-64 calling conventions on GNU/Linux platform you could examine %rdi (64-bit) register directly to check function's first parameter:

b calc if $rdi == 852479

即使您没有加载调试符号(这也没有代码列表,即通过 list calc ),这使您可以中断函数 calc .

This allows you to break on function calc even if you don't have debugging symbols loaded (thus no code listing, i.e. by list calc).

请注意,如果优化编译器内联函数,则此方法将失败.

Note that this method would fail if function is inlined by optimizing compiler.

这篇关于GDB条件中断功能参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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