Here is an example that works for me. Environment: Debian Lenny amd64 8 GB RAM (probably doesn't matter) Linux 2.6.26-1-amd64 echo 0 >/proc/sys/kernel/randomize_va_space # important! linux-image-amd64 2.6.26+17 gcc 4:4.3.2-2 gdb 6.8-3 emacs 22.2+2-5
Code: --------------------------------------- /* gcc -W -Wall -Wextra -O0 -g3 -o tt tt.c */ #include <stdio.h> #include <assert.h> #include <stdlib.h> int main(int argc, char *argv[]) { int *arr = 0; if (argc) { arr = malloc(1000000 * sizeof(int)); arr[300000] = 17; printf("arr[300000] = %d\n",arr[300000]); argv = argv; } return 0; } --------------------------------------- Compile: gcc -W -Wall -Wextra -O0 -g3 -o tt tt.c Debug (in Emacs): emacs & M-x gdb gdb --annotate=3 tt b main r # stops in main b 16 # the printf line c p arr[300000] # gives $1 = 17 p &arr[300000] # gives $2 = (int *) 0x7ffff77e2f90 on my system watch *(int *) 0x7ffff77e2f90 # gives Hardware watchpoint 3: *(int *) 140737345630096 c # gives Program exited normally r # gives the following output --------------------------------- Starting program: /home/cfischer/tmp/tt Error in re-setting breakpoint 3: Cannot access memory at address 0x7ffff77e2f90 Error in re-setting breakpoint 3: Cannot access memory at address 0x7ffff77e2f90 Error in re-setting breakpoint 3: Cannot access memory at address 0x7ffff77e2f90 Cannot access memory at address 0x7ffff77e2f90 (gdb) Debugger aborted --------------------------------- -- Claus Fischer <claus.fisc...@clausfischer.com> http://www.clausfischer.com/
signature.asc
Description: Digital signature