简体   繁体   中英

Using GDB to find what memory address a function corresponds to/ debugging

I have this basic program:

int initfunc(int *array, int len) {
  int i;
  for(i=1; i <= len; i++) {
    array[i] = i;
  }
 return 0;
}

int main(int argc, char* argv[]){

  int*  myarray=0;
  initfunc(myarray,10);
}

First i'm trying to figure out what the command in GDB to find what memory address main is stored in.

And also my error is at line 4 (array[i] = i), i'm trying to figure out what I need to do to get it to run. My professor wrote this program so I get that using these pointers probably isn't a good way to code this basic program. I just need some insight since i'm not too great with pointers.

before compile you must use -g for save symbol link to your execute file.

if you use gdb a.out you get error :

Reading symbols from TEMP...(no debugging symbols found)...done.

but if you use g++ -g test.cpp and now gdb show you :

Reading symbols from a.out...done.

And now you can use command-gdb

And see this : How to use GDB to find what function a memory address corresponds to

I figured it out, thanks for the insight. I just used breakpoints in GDB to figure out memory allocation for functions. I failed to mention I used -g in my makefile, so that part was already done. Also the memory allocation for the array wasn't present and that fixed the issue! Cheers

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