Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb C code in linux - Address out of bounds

Tags:

c

linux

gdb

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

like image 876
MLSC Avatar asked Dec 04 '25 22:12

MLSC


1 Answers

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

like image 144
nos Avatar answered Dec 06 '25 13:12

nos