简体   繁体   中英

gdb C code in linux - Address out of bounds

I have the following C code:

#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;

    }

now I use gdb for debugging and I do following steps:

gdb str
break main
run
x/s $esp

but here I get the "Address out if bounds" error... could any body tell me how I can solve it? thank you

That's because you're on a 64 bit machine, $esp is a 32 bit register. You'll want to do x/s $rsp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM