This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Python enabled gdb: accessing local variables
- From: Tom Tromey <tromey at redhat dot com>
- To: Alex Presniakov <flagist0 at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Tue, 21 Jul 2009 09:56:38 -0600
- Subject: Re: Python enabled gdb: accessing local variables
- References: <e2c151c30907210658r69350dc2t2b938a05792c2a7d@mail.gmail.com>
- Reply-to: tromey at redhat dot com
>>>>> "Alex" == Alex Presniakov <flagist0@gmail.com> writes:
Alex> First, I can't access local variables using 'python' command -- for
Alex> example, "python print i" returns an error "NameError: name 'i' is not
Alex> defined".
This accesses the Python variable 'i', not the variable 'i' in the
inferior.
You probably want gdb.parse_and_eval, but we haven't merged that yet.
Alex> But if I access this variable from convenience function,
Alex> everything goes right (Also, I'm even not sure that gdb sees debug
Alex> symbols -- "python print gdb.current_objfile" returns None).
The current objfile is usually None. It is only valid when debuginfo is
actually being read.
Alex> And is there any difference between running python code from
Alex> scripts and from interpreter?
Not really. There may be differences that are intrinsic to Python, like
if you use import the code is evalled in a module or whatever.
Alex> Second, gdb gets segfault if I eval 'source -p somefile' more than
Alex> one time.
Please file a bug report. Include a stack trace of gdb if you can. If
it is dependent on the contents of the file, then include the file as
well.
Alex> And the last question. I'm trying to add command that compares
Alex> buffers.
Alex> def invoke(self,first,second,len):
The arguments to invoke are supplied by gdb. You can't provide just any
function signature here, it has to be the one specified in the manual:
def invoke (self, arg, from_tty):
The meaning of the arguments is also described in the manual.
Tom