GDB 在不需要的位置中断
GDB breaking at unwanted position
当我在某个函数下一个断点,然后输入运行,函数参数不正确。
示例:
(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 {
我希望它说的是 n1=5、n2=6 而不是 n1=21845、n2=1431654909。
一切正常,程序提供正确的输出,但不知道为什么当 gdb 在函数 add_numbers
中断时参数不正确
我刚开始使用 GBD 进行调试。有人可以解释一下吗?
这是C代码:
#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;
}
反汇编输出:
(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 版本
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.
当我在某个函数下一个断点,然后输入运行,函数参数不正确。 示例:
(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 {
我希望它说的是 n1=5、n2=6 而不是 n1=21845、n2=1431654909。 一切正常,程序提供正确的输出,但不知道为什么当 gdb 在函数 add_numbers
中断时参数不正确我刚开始使用 GBD 进行调试。有人可以解释一下吗?
这是C代码:
#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;
}
反汇编输出:
(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 版本
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.