Gammon Forum
Entire forum
Programming
General
watching a variable change using GDB
watching a variable change using GDB
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Naka0naka
(3 posts) bio
|
Date
| Tue 23 Dec 2008 12:03 PM (UTC) |
Message
| I need to monitor a global variable as it changes. I intend to use hook-stop but how can I tell if the stop was due to the watch I set? Please advise. | top |
|
Posted by
| David Haley
USA (3,881 posts) bio
|
Date
| Reply #1 on Tue 23 Dec 2008 02:12 PM (UTC) |
Message
| As you can see in Nick's gdb guide [1], you get output like this when using watchpoints:
(gdb) cont
Continuing.
Hardware watchpoint 7: obj
Old value = (OBJ_DATA *) 0x0
New value = (OBJ_DATA *) 0x855f758
0x08119f0a in do_eat (ch=0x855e9a8, argument=0xbfffda24 "pie") at misc.c:686
686 if ( (obj = find_obj(ch, argument, TRUE)) == NULL )
(gdb)
[1] http://www.gammon.com.au/forum/?id=3653 |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|
Posted by
| Naka0naka
(3 posts) bio
|
Date
| Reply #2 on Wed 24 Dec 2008 12:32 AM (UTC) |
Message
| Thanks for the reply. I guess I did not explain the problem clear enough.
I want to watch a global variable passively, without having to type c or continue at the gdb prompt everytime the global variable was modified and stops at the gdb prompt.
I tried to use the following:
define hook-stop
continue
end
The hook-stop appears to work only for one stop and it didn't print out the watched info.
Please advise.
| top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #3 on Wed 24 Dec 2008 01:48 AM (UTC) Amended on Wed 24 Dec 2008 03:37 AM (UTC) by Nick Gammon
|
Message
| I got it to work like this ...
I chose a global variable (num_descriptors), and typed:
watch num_descriptors
I saw this:
(gdb) watch num_descriptors
Hardware watchpoint 1: num_descriptors
Then I typed "info watch" :
(gdb) info watch
Num Type Disp Enb Address What
1 hw watchpoint keep y num_descriptors
This shows it is watchpoint 1. Now I added commands to be executed:
(gdb) commands 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
> echo watchpoint reached!\n
> print num_descriptors
> cont
> end
Now after connecting with a new character (I already had one on) I see this:
Wed Dec 24 13:41:42 2008 :: Nick (10.0.0.102) has connected.
Hardware watchpoint 1: num_descriptors
Old value = 1
New value = 2
0x0810f5fe in new_descriptor(int) (new_desc=5) at comm.c:1098
1098 if( ++num_descriptors > sysdata.maxplayers )
watchpoint reached!
$4 = 2
The lines in italic are my command output, and the MUD continues without stopping at the watchpoint. Actually you can see that the output is pretty explanatory anyway, so all you really need is:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Naka0naka
(3 posts) bio
|
Date
| Reply #4 on Wed 24 Dec 2008 02:50 AM (UTC) |
Message
| Thanks Nick, that is the solution I'm looking for. | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
23,167 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.