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: Python enabled gdb: accessing local variables


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


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