Discussion:
Reading a static variable in Python
Chris Johns
2010-03-10 03:38:09 UTC
Permalink
Hello,

I am adding pretty printers for RTEMS to gdb. In the RTEMS operating
system elements such as a semaphore are given an id. I would like to
print the actual semaphore data given a semaphore id. To do this I need
to read a kernel structure from a table indexed via a bit field in the
id. As an example the semaphore's table is declared in RTEMS as:

RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information;

How would I read the 10 element of the _Semaphore_Information in Python ?

I am stuck on how to create a new gdb.Value variable in Python.

Thanks
Chris
Tom Tromey
2010-03-10 17:05:03 UTC
Permalink
Chris> I am adding pretty printers for RTEMS to gdb. In the RTEMS operating
Chris> system elements such as a semaphore are given an id. I would like to
Chris> print the actual semaphore data given a semaphore id. To do this I
Chris> need to read a kernel structure from a table indexed via a bit field
Chris> in the id. As an example the semaphore's table is declared in RTEMS
Chris> as:

Chris> RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information;

This isn't really enough information for us to help you.
What does Objects_Information look like?

Chris> I am stuck on how to create a new gdb.Value variable in Python.

Use gdb.parse_and_eval. This wasn't added until after 7.0.

Tom
Chris Johns
2010-03-11 01:49:13 UTC
Permalink
Chris> I am adding pretty printers for RTEMS to gdb. In the RTEMS operating
Chris> system elements such as a semaphore are given an id. I would like to
Chris> print the actual semaphore data given a semaphore id. To do this I
Chris> need to read a kernel structure from a table indexed via a bit field
Chris> in the id. As an example the semaphore's table is declared in RTEMS
Chris> RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information;
This isn't really enough information for us to help you.
What does Objects_Information look like?
Yes sorry about that. It is a C struct [1].
Chris> I am stuck on how to create a new gdb.Value variable in Python.
Use gdb.parse_and_eval.
Nice. This is an excellent solution. I suppose being an expression it
can do the pointer maths as well. I was looking at ways to construct a
gdb.Value with a gdb.Symbol as an argument.
This wasn't added until after 7.0.
I am using a 7.1 snapshot as it has the 'source' command to load a
Python file. This is also an excellent addition.

Chris

[1]
http://www.rtems.org/onlinedocs/doxygen/cpukit/html/structObjects__Information.html
Tom Tromey
2010-03-11 16:53:11 UTC
Permalink
Tom> Use gdb.parse_and_eval.

Chris> Nice. This is an excellent solution. I suppose being an expression it
Chris> can do the pointer maths as well. I was looking at ways to construct a
Chris> gdb.Value with a gdb.Symbol as an argument.

Yes, strangely there doesn't seem to be a way to do that.
If you want this, feel free to file a bug report for it...

Tom
Phil Muldoon
2010-03-11 17:15:22 UTC
Permalink
Post by Tom Tromey
Tom> Use gdb.parse_and_eval.
Chris> Nice. This is an excellent solution. I suppose being an expression it
Chris> can do the pointer maths as well. I was looking at ways to construct a
Chris> gdb.Value with a gdb.Symbol as an argument.
Yes, strangely there doesn't seem to be a way to do that.
If you want this, feel free to file a bug report for it...
Frame's read_var function creates a gdb.Value from a given gdb.Symbol,
but obviously one needs the frame and the symbol for that. There was
a stub in the gdb.Symbol code to do this without a frame, but it was
very limited so I removed it. Frame's function read_var uses
read_var_value which needs a frame (well, for some reads -
symbol_read_needs_frame returns a mixed bag of results). Not sure if
it is possible to construct a value from a symbol without the frame in
all cases?

Cheers,

Phil
Tom Tromey
2010-03-11 17:57:57 UTC
Permalink
Phil> Not sure if it is possible to construct a value from a symbol
Phil> without the frame in all cases?

Not in all cases, but we could throw an exception if a frame is required.

Tom
Chris Johns
2010-03-11 23:40:29 UTC
Permalink
Tom> Use gdb.parse_and_eval.
Chris> Nice. This is an excellent solution. I suppose being an expression it
Chris> can do the pointer maths as well. I was looking at ways to construct a
Chris> gdb.Value with a gdb.Symbol as an argument.
Yes, strangely there doesn't seem to be a way to do that.
If you want this, feel free to file a bug report for it...
I am happy with the gdb.parse_and_eval solution. If a need arises I will
create a bug report.

Thanks
Chris

Loading...