linux中的gdb C代码 - 地址超出范围

时间:2014-01-02 20:23:57

标签: c linux gdb

我有以下C代码:

#include <stdio.h>

    char strA[80] = {"string to be used for demonstration purposes."};
    char strB[80];

    int main(void){
      char *pA;      //A pointer to type char
      char *pB;      //Another pointer to type char
      puts(strA);    //Show string A
      pA = strA;     //Point pA to string A
      puts(pA);      //Show what pA is pointing to
      //printf("pA = %s",  pA);
      pB = strB;     //Point pB to string B           
      putchar('\n'); //Move down one line on the screen

      while(*pA != '\0'){
        *pB++ = *pA++;
      }

      *pB = '\0';
      puts(strB);    //Show string B on the screen

      return 0;

    }

现在我使用gdb进行调试,并执行以下步骤:

gdb str
break main
run
x/s $esp

但是我在这里得到“Address out if bounds”错误... 有谁可以告诉我如何解决它? 谢谢

1 个答案:

答案 0 :(得分:7)

那是因为你在64位机器上,$ esp是一个32位寄存器。你想做x/s $ rsp