在我的C程序中使用gdb需要帮助

时间:2012-10-17 23:50:00

标签: c assembly

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

1 个答案:

答案 0 :(得分: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.