public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* can pahole print a struct definition in a given CU?
@ 2012-12-24 14:15 Tristan Su
  2013-01-02 17:32 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Tristan Su @ 2012-12-24 14:15 UTC (permalink / raw)
  To: gdb

Hi,
I found pahole (python api) quite useful but jusst could not have it
print a struct in a given compilation unit.
With the ptype command:
(gdb) ptype S
but we can also specify the CU because the struct may have different
define in different CUs.
(gdb) ptype 'foo.c'::S

but pahale doesn't seem to support this:
(gdb) pahole  'foo.c'::S
Traceback (most recent call last):
  File "/usr/share/gdb/python/gdb/command/pahole.py", line 68, in invoke
    type = gdb.lookup_type (arg)
RuntimeError: No type named 'foo.c'::S.
Error occurred in Python command: No type named 'foo.c'::S.

Is that possible/easy to make pahole support this?

I'm using gdb 7.2 on x86-64.

Thanks,
Tristan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: can pahole print a struct definition in a given CU?
  2012-12-24 14:15 can pahole print a struct definition in a given CU? Tristan Su
@ 2013-01-02 17:32 ` Tom Tromey
  2013-01-02 18:56   ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2013-01-02 17:32 UTC (permalink / raw)
  To: Tristan Su; +Cc: gdb

>>>>> "Tristan" == Tristan Su <sooqing@gmail.com> writes:

Tristan> I found pahole (python api) quite useful but jusst could not have it
Tristan> print a struct in a given compilation unit.
Tristan> With the ptype command:
Tristan> (gdb) ptype S
Tristan> but we can also specify the CU because the struct may have different
Tristan> define in different CUs.
Tristan> (gdb) ptype 'foo.c'::S

Tristan> Is that possible/easy to make pahole support this?

I couldn't think of an easy way.  Though maybe that is just imagination
failure on my part :)

If I were doing this I would start by finding a way to expose
evaluate_type to Python, say via a flag to parse_and_eval.
Then I would make pahole use this.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: can pahole print a struct definition in a given CU?
  2013-01-02 17:32 ` Tom Tromey
@ 2013-01-02 18:56   ` Doug Evans
  2013-01-02 19:05     ` Tom Tromey
  2013-01-02 19:06     ` Doug Evans
  0 siblings, 2 replies; 5+ messages in thread
From: Doug Evans @ 2013-01-02 18:56 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Tristan Su, gdb

On Wed, Jan 2, 2013 at 10:31 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Tristan" == Tristan Su <sooqing@gmail.com> writes:
>
> Tristan> I found pahole (python api) quite useful but jusst could not have it
> Tristan> print a struct in a given compilation unit.
> Tristan> With the ptype command:
> Tristan> (gdb) ptype S
> Tristan> but we can also specify the CU because the struct may have different
> Tristan> define in different CUs.
> Tristan> (gdb) ptype 'foo.c'::S
>
> Tristan> Is that possible/easy to make pahole support this?
>
> I couldn't think of an easy way.  Though maybe that is just imagination
> failure on my part :)
>
> If I were doing this I would start by finding a way to expose
> evaluate_type to Python, say via a flag to parse_and_eval.
> Then I would make pahole use this.

I realize we're talking about types here, but there's a general
problem here, and there's another approach to choosing object foo from
source bar.c.  [This doesn't immediately help with the pahole issue
here, but it's a thought that occurred to me, so I'm writing it down.]

It's seems like what's needed is a handle on the symtab(CU), and then
a way to go from there, instead of encoding the symtab in the
expression.
Since expressions in the source work that way, making things like "p
'bar.c'::foo + 'baz.c'::foo" work seems like excessive generality.
[For completeness sake, I realize that works today and we can't break
it.  Still, I think there's room for improvement.]

Thus,
what about adding a "context" parameter to parse_and_eval, etc.?
And then provide a way to specify that context (e.g., both from the
CLI and from Python).

We'd still have to support "p 'bar.c'::foo + 'baz.c::foo'", but when,
e.g, cut-n-pasting expressions from source we shouldn't have to force
the user to insert 'bar.c::' in front of objects that gdb might end up
otherwise picking the wrong one for.

E.g., something like: (gdb) with-symtab bar.c p foo+baz
or whatever.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: can pahole print a struct definition in a given CU?
  2013-01-02 18:56   ` Doug Evans
@ 2013-01-02 19:05     ` Tom Tromey
  2013-01-02 19:06     ` Doug Evans
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2013-01-02 19:05 UTC (permalink / raw)
  To: Doug Evans; +Cc: Tristan Su, gdb

>>>>> "Doug" == Doug Evans <dje@google.com> writes:

Doug> Thus,
Doug> what about adding a "context" parameter to parse_and_eval, etc.?
Doug> And then provide a way to specify that context (e.g., both from the
Doug> CLI and from Python).

Doug> We'd still have to support "p 'bar.c'::foo + 'baz.c::foo'", but when,
Doug> e.g, cut-n-pasting expressions from source we shouldn't have to force
Doug> the user to insert 'bar.c::' in front of objects that gdb might end up
Doug> otherwise picking the wrong one for.

Doug> E.g., something like: (gdb) with-symtab bar.c p foo+baz
Doug> or whatever.

It would be fine by me.
I was just pointing out the simplest way to make pahole work the same
way ptype does.

Really I would like to roll the pahole functionality into ptype.
It is useful enough that there's no reason to need a second command for it.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: can pahole print a struct definition in a given CU?
  2013-01-02 18:56   ` Doug Evans
  2013-01-02 19:05     ` Tom Tromey
@ 2013-01-02 19:06     ` Doug Evans
  1 sibling, 0 replies; 5+ messages in thread
From: Doug Evans @ 2013-01-02 19:06 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Tristan Su, gdb

On Wed, Jan 2, 2013 at 11:56 AM, Doug Evans <dje@google.com> wrote:
> [...]
> Thus,
> what about adding a "context" parameter to parse_and_eval, etc.?
> And then provide a way to specify that context (e.g., both from the
> CLI and from Python).
>
>[...]
>
> E.g., something like: (gdb) with-symtab bar.c p foo+baz
> or whatever.

[Sorry for the followup.]
To make that work with breakpoint expressions, etc., it would be
preferable to still encode the symtab in the expression string, but at
an outer level and not embedded in it.
I realize this syntax is problematic, but for illustration's sake: p
(foo+baz)@bar.c

From Python: gdb.parse_and_eval ("foo+baz", symtab=blah) or whatever.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-02 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-24 14:15 can pahole print a struct definition in a given CU? Tristan Su
2013-01-02 17:32 ` Tom Tromey
2013-01-02 18:56   ` Doug Evans
2013-01-02 19:05     ` Tom Tromey
2013-01-02 19:06     ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).