How to add a second "this" (sort of, or maybe do something totally different)

Nat! nat@mulle-kybernetik.com
Fri Feb 25 00:28:35 GMT 2022


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.


More information about the Gdb mailing list