* Checking variable scope
@ 2006-11-22 11:32 Rob Quill
2006-11-22 19:10 ` Jim Blandy
0 siblings, 1 reply; 10+ messages in thread
From: Rob Quill @ 2006-11-22 11:32 UTC (permalink / raw)
To: gdb
Hi,
I am trying to make it possible to be able to check if a variable is
in scope at a given time. My current implementation for this involves
adding a parameter to parse_expression, and the parsing functions it
calls, all the way until it gets to the line:
if (sym == 0)
error ("No symbol \"%s\" in specified context.", copy_name ($3));
in c-exp.y
as which point it doesn't call error, but calls another function which
returns a value signifing that the variable is not in scope.
Whilst this is OK, in that it (should) work, I was wondering if anyone
had a neater way of implementing it?
Thanks for your time.
Rob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-22 11:32 Checking variable scope Rob Quill
@ 2006-11-22 19:10 ` Jim Blandy
2006-11-23 13:09 ` Rob Quill
0 siblings, 1 reply; 10+ messages in thread
From: Jim Blandy @ 2006-11-22 19:10 UTC (permalink / raw)
To: Rob Quill; +Cc: gdb
"Rob Quill" <rob.quill@gmail.com> writes:
> I am trying to make it possible to be able to check if a variable is
> in scope at a given time. My current implementation for this involves
> adding a parameter to parse_expression, and the parsing functions it
> calls, all the way until it gets to the line:
>
> if (sym == 0)
> error ("No symbol \"%s\" in specified context.", copy_name ($3));
>
> in c-exp.y
>
> as which point it doesn't call error, but calls another function which
> returns a value signifing that the variable is not in scope.
>
> Whilst this is OK, in that it (should) work, I was wondering if anyone
> had a neater way of implementing it?
Why not call lookup_symbol directly? You can get the block that needs
with block_for_pc_sect. Are you selecting the location by source
position, or PC, or what?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-22 19:10 ` Jim Blandy
@ 2006-11-23 13:09 ` Rob Quill
2006-11-27 19:46 ` Jim Blandy
0 siblings, 1 reply; 10+ messages in thread
From: Rob Quill @ 2006-11-23 13:09 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb
Hi,
I am stepping through the program, so I suppose I'd be looking to see
if the variable is in scope at the location of the PC.
How would I call lookup_symbol, given that information? I had a brief
look, but I wasn't sure what parameters to pass to the function, or
how to get the right values.
Thanks for your help.
Rob
On 22/11/06, Jim Blandy <jimb@codesourcery.com> wrote:
>
> "Rob Quill" <rob.quill@gmail.com> writes:
> > I am trying to make it possible to be able to check if a variable is
> > in scope at a given time. My current implementation for this involves
> > adding a parameter to parse_expression, and the parsing functions it
> > calls, all the way until it gets to the line:
> >
> > if (sym == 0)
> > error ("No symbol \"%s\" in specified context.", copy_name ($3));
> >
> > in c-exp.y
> >
> > as which point it doesn't call error, but calls another function which
> > returns a value signifing that the variable is not in scope.
> >
> > Whilst this is OK, in that it (should) work, I was wondering if anyone
> > had a neater way of implementing it?
>
> Why not call lookup_symbol directly? You can get the block that needs
> with block_for_pc_sect. Are you selecting the location by source
> position, or PC, or what?
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-23 13:09 ` Rob Quill
@ 2006-11-27 19:46 ` Jim Blandy
2006-11-28 11:47 ` Rob Quill
0 siblings, 1 reply; 10+ messages in thread
From: Jim Blandy @ 2006-11-27 19:46 UTC (permalink / raw)
To: Rob Quill; +Cc: gdb
"Rob Quill" <rob.quill@gmail.com> writes:
> I am stepping through the program, so I suppose I'd be looking to see
> if the variable is in scope at the location of the PC.
>
> How would I call lookup_symbol, given that information? I had a brief
> look, but I wasn't sure what parameters to pass to the function, or
> how to get the right values.
You can pass NULL for 'symtab' and 'is_a_field_of_this', and
VAR_DOMAIN for domain. block is the scoping block containing the PC.
I don't know where you're calling things from, so I can't really tell
you how to get the current PC.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-27 19:46 ` Jim Blandy
@ 2006-11-28 11:47 ` Rob Quill
2006-11-28 19:43 ` Jim Blandy
0 siblings, 1 reply; 10+ messages in thread
From: Rob Quill @ 2006-11-28 11:47 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb
On 27/11/06, Jim Blandy <jimb@codesourcery.com> wrote:
>
> "Rob Quill" <rob.quill@gmail.com> writes:
> > I am stepping through the program, so I suppose I'd be looking to see
> > if the variable is in scope at the location of the PC.
> >
> > How would I call lookup_symbol, given that information? I had a brief
> > look, but I wasn't sure what parameters to pass to the function, or
> > how to get the right values.
>
> You can pass NULL for 'symtab' and 'is_a_field_of_this', and
> VAR_DOMAIN for domain. block is the scoping block containing the PC.
> I don't know where you're calling things from, so I can't really tell
> you how to get the current PC.
>
The aim would be to add a command to gdb, in_scope (or similar) which
can be used from a GDB script to check if a variable is in scope
without throwing an error if is isn't. As currently if I do "print a"
and a is not in scope then I get an error and the script stops, which
is fine. But even better would be if I were able to check if a was in
scope and only print (or do other things with it) if it was.
Does that help explain where I would be calling things from? As I
understand it, current when you do "print a" it tries to parse a, as
it is possible to print expressions etc, and when is parsing in, in
exp_c.y, it throws errors if the variable is not in scope.
So currently my code sets a global variable check_scope, and in
exp_c.y, if check_scope is 1, then an internal variable is set if the
variable is not in scope, and an _error() is thrown, with an empty
string, and when running a script and an error is encountered, if the
error message is the empty string then the error is ignored.
Obviously this is not a particularly neat way of doing it, and I'm
sure there is a better way, so any help is appreciated.
Thanks
Rob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-28 11:47 ` Rob Quill
@ 2006-11-28 19:43 ` Jim Blandy
[not found] ` <baf6008d0611290519i4e25c51bt865320b09c756ec8@mail.gmail.com>
0 siblings, 1 reply; 10+ messages in thread
From: Jim Blandy @ 2006-11-28 19:43 UTC (permalink / raw)
To: Rob Quill; +Cc: gdb
"Rob Quill" <rob.quill@gmail.com> writes:
> The aim would be to add a command to gdb, in_scope (or similar) which
> can be used from a GDB script to check if a variable is in scope
> without throwing an error if is isn't. As currently if I do "print a"
> and a is not in scope then I get an error and the script stops, which
> is fine. But even better would be if I were able to check if a was in
> scope and only print (or do other things with it) if it was.
Why don't you add a new expression operator, $in_scope(a), which
evaluates to zero or one? You could just imitate the other code in
the parser and expression evaluator, so this should be straightforward
to implement, and then you could use it in GDB script conditional
commands.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Checking variable scope
[not found] ` <baf6008d0611290519i4e25c51bt865320b09c756ec8@mail.gmail.com>
@ 2006-11-29 13:20 ` Rob Quill
2006-11-29 18:44 ` Jim Blandy
0 siblings, 1 reply; 10+ messages in thread
From: Rob Quill @ 2006-11-29 13:20 UTC (permalink / raw)
To: gdb
On 28/11/06, Jim Blandy <jimb@codesourcery.com> wrote:
>
> "Rob Quill" <rob.quill@gmail.com> writes:
> > The aim would be to add a command to gdb, in_scope (or similar) which
> > can be used from a GDB script to check if a variable is in scope
> > without throwing an error if is isn't. As currently if I do "print a"
> > and a is not in scope then I get an error and the script stops, which
> > is fine. But even better would be if I were able to check if a was in
> > scope and only print (or do other things with it) if it was.
>
> Why don't you add a new expression operator, $in_scope(a), which
> evaluates to zero or one? You could just imitate the other code in
> the parser and expression evaluator, so this should be straightforward
> to implement, and then you could use it in GDB script conditional
> commands.
>
Could you elaborate on this a bit please? I'm not really sure what you
mean and how to go about implementing it.
Thanks,
Rob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-29 13:20 ` Rob Quill
@ 2006-11-29 18:44 ` Jim Blandy
2006-11-29 19:06 ` Daniel Jacobowitz
0 siblings, 1 reply; 10+ messages in thread
From: Jim Blandy @ 2006-11-29 18:44 UTC (permalink / raw)
To: Rob Quill; +Cc: gdb
"Rob Quill" <rob.quill@gmail.com> writes:
> On 28/11/06, Jim Blandy <jimb@codesourcery.com> wrote:
>>
>> "Rob Quill" <rob.quill@gmail.com> writes:
>> > The aim would be to add a command to gdb, in_scope (or similar) which
>> > can be used from a GDB script to check if a variable is in scope
>> > without throwing an error if is isn't. As currently if I do "print a"
>> > and a is not in scope then I get an error and the script stops, which
>> > is fine. But even better would be if I were able to check if a was in
>> > scope and only print (or do other things with it) if it was.
>>
>> Why don't you add a new expression operator, $in_scope(a), which
>> evaluates to zero or one? You could just imitate the other code in
>> the parser and expression evaluator, so this should be straightforward
>> to implement, and then you could use it in GDB script conditional
>> commands.
>>
>
> Could you elaborate on this a bit please? I'm not really sure what you
> mean and how to go about implementing it.
Right now, c-exp.y parses a C expression into an expression,
represented using the structure in expression.h, and evaluated by the
code in eval.c. But c-exp.y actually recognizes an extended grammar,
with special additions for debugging, like the @ operator and array
literals.
I'm suggesting that you extend the grammar even further, by allowing
one to say things like this (assume there is no binding for 'a' in
scope, but there is a binding for 'b' in scope):
(gdb) print $in_scope(a)
$1 = 0
(gdb) print $in_scope(b)
$1 = 1
(gdb)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-29 18:44 ` Jim Blandy
@ 2006-11-29 19:06 ` Daniel Jacobowitz
2006-11-29 19:08 ` Jim Blandy
0 siblings, 1 reply; 10+ messages in thread
From: Daniel Jacobowitz @ 2006-11-29 19:06 UTC (permalink / raw)
To: Jim Blandy; +Cc: Rob Quill, gdb
On Wed, Nov 29, 2006 at 10:44:33AM -0800, Jim Blandy wrote:
> I'm suggesting that you extend the grammar even further, by allowing
> one to say things like this (assume there is no binding for 'a' in
> scope, but there is a binding for 'b' in scope):
>
> (gdb) print $in_scope(a)
> $1 = 0
> (gdb) print $in_scope(b)
> $1 = 1
> (gdb)
Is extending the grammar really necessary? That will already parse;
it's the same as you'd use for a convenience variable named in_scope
holding a function pointer.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Checking variable scope
2006-11-29 19:06 ` Daniel Jacobowitz
@ 2006-11-29 19:08 ` Jim Blandy
0 siblings, 0 replies; 10+ messages in thread
From: Jim Blandy @ 2006-11-29 19:08 UTC (permalink / raw)
To: Rob Quill; +Cc: gdb
Daniel Jacobowitz <drow@false.org> writes:
> On Wed, Nov 29, 2006 at 10:44:33AM -0800, Jim Blandy wrote:
>> I'm suggesting that you extend the grammar even further, by allowing
>> one to say things like this (assume there is no binding for 'a' in
>> scope, but there is a binding for 'b' in scope):
>>
>> (gdb) print $in_scope(a)
>> $1 = 0
>> (gdb) print $in_scope(b)
>> $1 = 1
>> (gdb)
>
> Is extending the grammar really necessary? That will already parse;
> it's the same as you'd use for a convenience variable named in_scope
> holding a function pointer.
I think so, because you need to prevent the reference to 'a' from
producing an error when you parse the expression.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-11-29 19:08 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-22 11:32 Checking variable scope Rob Quill
2006-11-22 19:10 ` Jim Blandy
2006-11-23 13:09 ` Rob Quill
2006-11-27 19:46 ` Jim Blandy
2006-11-28 11:47 ` Rob Quill
2006-11-28 19:43 ` Jim Blandy
[not found] ` <baf6008d0611290519i4e25c51bt865320b09c756ec8@mail.gmail.com>
2006-11-29 13:20 ` Rob Quill
2006-11-29 18:44 ` Jim Blandy
2006-11-29 19:06 ` Daniel Jacobowitz
2006-11-29 19:08 ` Jim Blandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox