public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* How to add a second "this" (sort of, or maybe do something totally different)
@ 2022-02-25  0:28 Nat!
  2022-03-08 22:00 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Nat! @ 2022-02-25  0:28 UTC (permalink / raw)
  To: gdb

Hi

my problem is this:

I have lots of functions (actually compiled Objective-C methods), that 
look very similiar:

void     *foo1( id self, unsigned int _cmd, struct { int a; void * b;}  
*_param);
void     *foo2( id self, unsigned int _cmd, struct { double a; void * 
b;}  *_param);
void     *foo3( id self, unsigned int _cmd, struct { int a; int b; int 
c; }  *_param);

and so on. The first two parameters are always the same.

The actual method parameters are accessed indirectly through "_param".  
So the functions may have looked like this in the Objective-C source code:

int     foo1:(int) a :(void *) b;
void foo2:(double) a :(void *) b;
char  *foo3:(int) a :(int) b :(int) c;

As the programmer passes "a", "b" and not "_param", it would be nice to 
get the debugger to print "_param->a", if the user enters "p a". gdb can 
already do this expansion for "this" or "self". As it's Objective-C, the 
"this" for the debugger is taken and it's "self". The user doesn't have 
to type "p self->_ivar" but can use "p _ivar" to access instance 
variables. That's nice, but doesn't extend to "_param".

I am looking for the least effort route to support something like this 
for "_param" as well, in gdb. What would be really great, would be to 
also show the struct fields in the stack trace instead of "_param".

Ciao
    Nat!


P.S.

Getting the compiler to output some fake dwarf "DW_TAG_formal_parameter" 
for each struct field with a computed dwarf expression, is maybe the 
proper way it could be done. But that's not least effort for me by a 
long shot.

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

* Re: How to add a second "this" (sort of, or maybe do something totally different)
  2022-02-25  0:28 How to add a second "this" (sort of, or maybe do something totally different) Nat!
@ 2022-03-08 22:00 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-03-08 22:00 UTC (permalink / raw)
  To: Nat!; +Cc: gdb

>>>>> ">" == Nat!  <nat@mulle-kybernetik.com> writes:

>> The actual method parameters are accessed indirectly through
>> "_param".  So the functions may have looked like this in the
>> Objective-C source code:

>> int     foo1:(int) a :(void *) b;
>> void foo2:(double) a :(void *) b;
>> char  *foo3:(int) a :(int) b :(int) c;

If this is an Objective-C compiler and/or ABI thing, then gdb could be
taught about it directly, I suppose.  I'm not sure how well the existing
Objective-C code in gdb works, so it may require other changes as well.

>> I am looking for the least effort route to support something like this
>> for "_param" as well, in gdb. What would be really great, would be to 
>> also show the struct fields in the stack trace instead of "_param".

gdb has limited support for this kind of thing.  I don't think there's a
good way, currently, do augment 'print' like this.  That would requiring
hooking into expression parsing / evaluation somehow.

For stack traces in particular, a "frame filter" can synthesize
'variables' like this.

>> Getting the compiler to output some fake dwarf
>> "DW_TAG_formal_parameter" for each struct field with a computed dwarf
>> expression, is maybe the proper way it could be done. But that's not
>> least effort for me by a long shot.

Parameters are tricky because gdb can also do inferior calls, so it has
to understand some of these details in a way that DWARF doesn't express.

Tom

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

end of thread, other threads:[~2022-03-08 22:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25  0:28 How to add a second "this" (sort of, or maybe do something totally different) Nat!
2022-03-08 22:00 ` Tom Tromey

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