public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Evaluating an expression in a given scope
@ 2005-09-07 12:44 Vladimir Prus
  2005-09-07 13:15 ` Daniel Jacobowitz
  2005-09-07 13:57 ` Daniel Jacobowitz
  0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Prus @ 2005-09-07 12:44 UTC (permalink / raw)
  To: gdb


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Evaluating an expression in a given scope
  2005-09-07 12:44 Evaluating an expression in a given scope Vladimir Prus
@ 2005-09-07 13:15 ` Daniel Jacobowitz
  2005-09-07 13:50   ` Vladimir Prus
  2005-09-07 13:57 ` Daniel Jacobowitz
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2005-09-07 13:15 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb

On Wed, Sep 07, 2005 at 04:39:52PM +0400, Vladimir Prus wrote:
> 
> Hello!
> 
> Does gdb provides a clean way to evaluate an expression in a given scope
> (file:line)? 

No, not really.  File:line doesn't match unambiguously to scope,
either, so it's not clear what the interface should look like... I
think I'd use $pc instead.

> 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.

... eww... I suppose that'd work.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Evaluating an expression in a given scope
  2005-09-07 13:15 ` Daniel Jacobowitz
@ 2005-09-07 13:50   ` Vladimir Prus
  2005-09-07 13:53     ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Prus @ 2005-09-07 13:50 UTC (permalink / raw)
  To: gdb

Daniel Jacobowitz wrote:

> On Wed, Sep 07, 2005 at 04:39:52PM +0400, Vladimir Prus wrote:
>> 
>> Hello!
>> 
>> Does gdb provides a clean way to evaluate an expression in a given scope
>> (file:line)?
> 
> No, not really.  File:line doesn't match unambiguously to scope,
> either, so it's not clear what the interface should look like... I
> think I'd use $pc instead.

You mean that variable can some into scope in the middle of assembler code
for a source-language line? Say:

   int i = j, j = 10;

? Well, true! Though it's really a corner case

- Volodya

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Evaluating an expression in a given scope
  2005-09-07 13:50   ` Vladimir Prus
@ 2005-09-07 13:53     ` Daniel Jacobowitz
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2005-09-07 13:53 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb

On Wed, Sep 07, 2005 at 05:45:20PM +0400, Vladimir Prus wrote:
> Daniel Jacobowitz wrote:
> 
> > On Wed, Sep 07, 2005 at 04:39:52PM +0400, Vladimir Prus wrote:
> >> 
> >> Hello!
> >> 
> >> Does gdb provides a clean way to evaluate an expression in a given scope
> >> (file:line)?
> > 
> > No, not really.  File:line doesn't match unambiguously to scope,
> > either, so it's not clear what the interface should look like... I
> > think I'd use $pc instead.
> 
> You mean that variable can some into scope in the middle of assembler code
> for a source-language line? Say:
> 
>    int i = j, j = 10;
> 
> ? Well, true! Though it's really a corner case

No.  Think about inlining, template expansion, macro definitions with
line numbers (which gcc doesn't do today but could in the future).  A
line is not an unambiguous reference to GDB's notion of a "scope".

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Evaluating an expression in a given scope
  2005-09-07 12:44 Evaluating an expression in a given scope Vladimir Prus
  2005-09-07 13:15 ` Daniel Jacobowitz
@ 2005-09-07 13:57 ` Daniel Jacobowitz
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2005-09-07 13:57 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb

On Wed, Sep 07, 2005 at 04:39:52PM +0400, Vladimir Prus wrote:
> 
> Hello!
> 
> Does gdb provides a clean way to evaluate an expression in a given scope
> (file:line)? 

BTW: unlike the other post, this is something I believe GDB should do. 
In fact, GDB already needs to do it, for much the same reasons -
restoring breakpoints as shared libraries are loaded and unloaded.
We just don't have an interface for it yet.  $pc isn't a great way to
identify scopes either.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-09-07 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07 12:44 Evaluating an expression in a given scope Vladimir Prus
2005-09-07 13:15 ` Daniel Jacobowitz
2005-09-07 13:50   ` Vladimir Prus
2005-09-07 13:53     ` Daniel Jacobowitz
2005-09-07 13:57 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).