3

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 Answers2

3

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
  • 97,814
  • 39
  • 186
  • 310
  • 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 Feb 04 '10 at 08:34
0

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
  • 3,995
  • 26
  • 30
  • 2
    The question specifically says "watchpoint", not "conditional breakpoint". – Paul R Feb 04 '10 at 09:50
  • 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 as watch var_name But 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 tried commands breakpoint_no > watch var_name > c > end I have the debug package installed so I think symbols shouldn't be an issue. The GDB version i am using is gdb 6.8-debian I am not sure whats the missing link – Sachin Shetye Feb 05 '10 at 00:55