From: frazer AT noneofyourbusiness DOT com (Scott Frazer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Why can't GDB set a variable? Date: Thu, 30 Jan 1997 01:07:21 GMT Organization: Ericsson Data Services Americas Lines: 71 Message-ID: <5cohig$8f9@cnn.exu.ericsson.se> References: <5co52q$hg0 AT news2 DOT delphi DOT com> NNTP-Posting-Host: pc340.rtp.ericsson.se To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp jrubin AT bix DOT com (jrubin) wrote: >GDB claims to be changing the value of the variable 'x', >but the program doesn't seem to notice. When GDB exits, >it reports failure to close the image file. >File test.c: >------------ >#include >int x = 1; >int main(void) >{ > printf("test.c: x = %d\n",x); > return 0; >} >-------------- >gcc -g test.c >gdb a.out >(gdb) p x >$1 = 1 >(gdb) set var x = 100 >(gdb) p x >$2 = 100 >(gdb) r >Starting program: c:/jsc/runtime/a.out >test.c: x = 1 >(gdb) q >warning: cannot close "c:/jsc/runtime/a.out": Permission denied (EACCES) I think it's because you have not started the program yet. I think initialized variables get set to their values when you first start your program. Here's what I got: C:\TEST>gdb a.out GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for GDB; type "show warranty" for details. GDB 4.16 (go32), Copyright 1996 Free Software Foundation, Inc... (gdb) hbreak main Hardware assisted breakpoint 1 at 0x1568: file test.c, line 7. (gdb) run Starting program: c:/test/a.out Breakpoint 1, main () at test.c:7 7 printf("test.c: x = %d\n",x); (gdb) p x $1 = 1 (gdb) set var x = 100 (gdb) continue Continuing. test.c: x = 100 Program exited normally. 0x10 in ?? () (gdb) q C:\TEST> BTW, I used a hardware break at main because I am running a DOS window under Win 3.11, and regular breakpoints don't work. Hope this helps, Scott