Evaluating an expression in a given scope

Vladimir Prus
2005-09-07T12:44:02Z

Hello!

Does gdb provides a clean way to evaluate an expression in a given scope
(file:line)?

Here's the use case: while in file foo.cpp, line 200, user creates a
watchpoint for expression 'g'. He then stops the GUI debugger and restarts
it again. I want to store the watchpoint in some config file and recreate
it again, but to do that I need a way to create watchpoint at specific
scope. If I just use

print g
or
display g

righ away, this might print some other 'g', not the one visible on line 200
of foo.cpp.

I think I can do this with:

tbreak foo.cpp:100
jump foo.cpp:100
display g
jump <previous source position>

but I have concerns about this being reliable method.

- Volodya