我正在学习汇编语言。 我正在使用 gdb 来了解如何从编写的 C 代码中获取信息。 我试图在每一行的开头查看 rip 寄存器,看看如何 这个程序的每个 C 语句中有多少字节的机器代码? 任何人都可以告诉我 gdb 中的命令来找到这些吗?
#include <stdio.h>
int main(void) {
register int wye;
int *ptr;
int ex;
ptr = &ex;
ex = 305441741;
wye = -1;
printf("Enter an integer: ");
scanf("%i", ptr);
wye += *ptr;
printf("The result is %i\n", wye);
return 0;
}
最佳答案
您可以执行的一些简短示例,以查看有关您的程序的一些事情。 $
是 shell 提示符,gdb>
是 gdb 提示符,所以不要输入:
$ gdb myprogram
... info about gdb and myprogram
gdb> disas main
... disassembly of the main function
gdb> break main
... sets a breakpoint in main; you see a message about this probably calling it breakpoint 1
gdb> run
... program starts and stops immediately at the start of main
gdb> i r
... lots of info about register contents
gdb> p $rip
... current instruction pointer (assuming x86_64)
gdb> s
... program runs for one source line.
gdb> p $rip
... ip has advanced a bit.
关于c - 在我的 C 程序中使用 gdb 需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12945163/