This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Variable objects for strings


Currently if you create a variable object for mystring on line 6 and list its
children (1), GDB will detect it has changed going from 6 to 7 but not going
from line 7 to 8.  This is because it is only looking at the first character.
However, the manual says:

   EXPRESSION is any expression valid on the current language set (must
not begin with a `*'), or one of the following:

   * `*ADDR', where ADDR is the address of a memory cell

   * `*ADDR-ADDR' -- a memory address range (TBD)

Is it possible for GDB to detect that 4 bytes have been allocated to mystring
and watch this block?  Clearly memory could be reallocated or the pointer
moved, and I don't know if GDB can always detect this, but I think this would
be better than the current arrangement.

Nick


1:   main()
2:   {
3:    char* mystring;
4:    mystring = malloc (4);
5:    strcpy (mystring, "big");
6:    strcpy (mystring, "pig");
7:    strcpy (mystring, "peg");
8:   }


(gdb)
-break-insert 6
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x080483df",func="main",file="temp.c",line="6",times="0"}
(gdb)
-exec-run
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",frame={addr="0x080483df",func="main",args=[],file="temp.c",fullname="/home/nickrob/temp.c",line="6"}
(gdb)
-var-create - * mystring
^done,name="var1",numchild="1",type="char *"
(gdb)
-var-list-children var1
^done,numchild="1",children=[child={name="var1.*mystring",exp="*mystring",numchi ld="0",type="char"}]
(gdb)
-exec-next
^running
(gdb)
*stopped,reason="end-stepping-range",thread-id="0",frame={addr="0x080483f2",func ="main",args=[],file="temp.c",fullname="/home/nickrob/temp.c",line="7"}
(gdb)
-var-update --all-values var1
^done,changelist=[{name="var1.*mystring",value="112 'p'",in_scope="true",type_ch anged="false"}]
(gdb)
-exec-next
^running
(gdb)
*stopped,reason="end-stepping-range",thread-id="0",frame={addr="0x08048405",func ="main",args=[],file="temp.c",fullname="/home/nickrob/temp.c",line="8"}
(gdb)
-var-update --all-values var1
^done,changelist=[]
(gdb)
p mystring
&"p mystring\n"
~"$2 = 0x8f42008 \"peg\""
~"\n"
^done
(gdb)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]