4

我正在学习汇编语言。我正在使用 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;
}
4

1 回答 1

1

您可以做一些事情来查看有关您的程序的一些事情的简短示例。 $是 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.
于 2012-10-18T00:13:27.557 回答