views:

345

answers:

2

I am trying to set up a watchpoint to monitor a variable in a package consisting of many C++ files.

There are many files

abc.cpp qwe.cpp .. xyz.cpp and so on

I want to monitor a variable 'temp' in some function qwerty() in the file abc.cpp How do I set the watchpoint ?

I tried

watch abc.cpp::temp watch abc.cpp:temp watch temp

but I see the errors No symbols 'abc.cpp::temp','abc.cpp:temp','temp' not in current context Also a info watchpoints tells me that no watchpoints are set. Note that I can set the breakpoints successfully for the same variable

+2  A: 

I always set a breakpoint in the function, then set the watchpoint when I hit it, so that I'm in the context, then delete the breakpoint as appropriate.

bmargulies
Indeed - for local variables you really have to do it this way, since a watchpoint is just an address range, so once you leave the scope in which the variable is defined the watchpoint may be triggered by anything else that uses the same address range on the stack.
Paul R
A: 

Do you want to make conditional breakpoints? If then you can use the commands below.

(gdb) break abc::qwerty()
(gdb) condition 1 temp=1 // If you want to break when the value of temp = 1.

Jagannath
The question specifically says "watchpoint", not "conditional breakpoint".
Paul R
well I tried setting up a breakpoint in the function, where I want to monitor the variable being changed. Once its hit, I set up the watchpoint simply aswatch var_nameBut for some reason I do not hit the watchpoint. I am sure that the var_name is written into by the program. [its an assignment to var_name]I also triedcommands breakpoint_no> watch var_name> c> endI have the debug package installed so I think symbols shouldn't be an issue. The GDB version i am using is gdb 6.8-debianI am not sure whats the missing link
Sachin Shetye