GDB在不需要的位置断裂 [英] GDB breaking at unwanted position

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

问题描述

当我在某个函数上放置断点并键入run时,函数参数不正确.示例:

 (gdb)中断add_numbers0x1149处的断点1:文件program.c,第4行.(gdb)运行启动程序:/home/aleksandar/Desktop/program程序c:4处的断点1,add_numbers(n1 = 21845,n2 = 1431654909)4 { 

我希望它说n1 = 5,n2 = 6而不是n1 = 21845,n2 = 1431654909.一切正常,程序给出正确的输出,但是不知道为什么gdb在函数add_numbers处中断时参数不正确

我是使用GBD调试的新手.有人可以解释吗?

这是C代码:

  #include< stdio.h>int add_numbers(int n1,int n2){整数和= n1 + n2;返回总和}int main(){整数x = 5;整数y = 6;int suma = add_numbers(x,y);printf("Suma je%d \ n",suma);返回0;} 

反汇编输出:

 (gdb)异常函数add_numbers的汇编代码转储:=>0x0000555555555149< + 0> ;: endbr640x000055555555514d< + 4> ;:推送%rbp0x000055555555514e< + 5> ;: mov%rsp,%rbp0x0000555555555151< + 8> ;: mov%edi,-0x14(%rbp)0x0000555555555154< + 11> ;: mov%esi,-0x18(%rbp)0x0000555555555157< + 14> ;: mov -0x14(%rbp),%edx0x000055555555515a< + 17> ;: mov -0x18(%rbp),%eax0x000055555555515d< + 20> ;:添加%edx,%eax0x000055555555515f< + 22> ;: mov%eax,-0x4(%rbp)0x0000555555555162< + 25> ;: mov -0x4(%rbp),%eax0x0000555555555165< + 28> ;: pop%rbp0x0000555555555166< + 29> ;: retq 

GDB版本

  aleksandar @ ubuntu:〜/Desktop $ gdb -versionGNU gdb(Ubuntu 9.2-0ubuntu1〜20.04)9.2版权所有(C)2020自由软件基金会,Inc.许可GPLv3 +:GNU GPL版本3或更高版本< http://gnu.org/licenses/gpl.html>这是免费软件:您可以自由更改和重新分发它.在法律允许的范围内,没有任何担保. 

解决方案

使用 9.2-0ubuntu1〜20.04 gcc 9.3.0-17ubuntu1〜20.04 复制.>

这是GDB中的 bug 在主干网上已固定( 11.0.50.20210307-git ).

您可以通过使用 -fcf-protection = none 标志构建程序来解决此问题.

When I place a breakpoint at a certain function, and type run, function parameters aren't correct. Example:

(gdb) break add_numbers
Breakpoint 1 at 0x1149: file program.c, line 4.
(gdb) run
Starting program: /home/aleksandar/Desktop/program 

Breakpoint 1, add_numbers (n1=21845, n2=1431654909) at program.c:4
4   {

I expect it to say n1=5, n2=6 instead of n1=21845, n2=1431654909. Everything works fine, program gives correct output, but dont know why parameters aren't right when gdb breaks at function add_numbers

I'm new to debugging with GBD. Can someone explain?

Here is C code:

#include <stdio.h>

int add_numbers(int n1, int n2)
{
    int sum = n1 + n2;
    return sum;
}

int main(){
    int x = 5;
    int y = 6;
    int suma = add_numbers(x,y);
    printf("Suma je %d\n", suma);
    return 0;
}

Disassembly output:

(gdb) disas
Dump of assembler code for function add_numbers:
=> 0x0000555555555149 <+0>: endbr64 
   0x000055555555514d <+4>: push   %rbp
   0x000055555555514e <+5>: mov    %rsp,%rbp
   0x0000555555555151 <+8>: mov    %edi,-0x14(%rbp)
   0x0000555555555154 <+11>:    mov    %esi,-0x18(%rbp)
   0x0000555555555157 <+14>:    mov    -0x14(%rbp),%edx
   0x000055555555515a <+17>:    mov    -0x18(%rbp),%eax
   0x000055555555515d <+20>:    add    %edx,%eax
   0x000055555555515f <+22>:    mov    %eax,-0x4(%rbp)
   0x0000555555555162 <+25>:    mov    -0x4(%rbp),%eax
   0x0000555555555165 <+28>:    pop    %rbp
   0x0000555555555166 <+29>:    retq 

GDB version

aleksandar@ubuntu:~/Desktop$ gdb -version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

解决方案

Reproduced using 9.2-0ubuntu1~20.04 and gcc 9.3.0-17ubuntu1~20.04.

This is a bug in GDB, fixed on trunk (11.0.50.20210307-git).

You can work around it by building your program with -fcf-protection=none flag.

这篇关于GDB在不需要的位置断裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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