This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Checking variable scope


"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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]