Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jonas Maebe <jonas.maebe@elis.ugent.be>
To: gdb@sourceware.org
Subject: Skipping over trampolines/stubs
Date: Wed, 01 Apr 2009 19:08:00 -0000	[thread overview]
Message-ID: <4B835C7C-B28E-4552-87E0-25D803741FA3@elis.ugent.be> (raw)

Hi,

We have a language construct whereby some calls have to be rerouted  
via a small stubs/trampolines. When encountering such a stub, gdb  
currently does not step into them, because the have no line info  
available (and hence gdb also does not step into the target call  
unless you manually place a breakpoint at the destination).

When the stub is generated in the same source file as where its  
destination lies, I can easily generate the same source info for the  
stub as for the target code, and then everything works fine (at least  
with DWARF; stabs would also require a fake procedure body, at least  
on Mac OS X).

The problem is if the target code is located in a different source  
file. I think I can hack our compiler so it can figure out whether  
that other source file was compiled with debug information and if so,  
what the file/line information of the source file of the target code  
would be, but
it wouldn't be easy and kind of messy.

So I'm wondering whether there's maybe some trick that you can use to  
make gdb step through arbitrary stubs somehow (maybe some kind of fake  
line information that it always ignores and just skips over), or  
whether there is another possible approach.

Thanks,


Jonas

PS, the actual implementation details: it's in case of interfaces in  
Free Pascal (similar to Java interfaces). When you call an interface  
method using a class instance, the self pointer needs to be adjusted  
before the interface method is entered (it has to be changed so it  
points to the interface's vmt). This is done using a small stub, to  
avoid having to inline this code everywhere (it's kind of bulky in  
some cases).

These stubs have to be generated in the source files containing the  
implementations of classes that implements an interface and not in the  
source file of the interface itself, because the adjustment of the  
self pointer depends on the class (depending on how many interfaces it  
implements, and in which order).

Here are a couple of examples of such stubs (the first for a function  
using the stdcall calling convention, the second for one using the  
Borland-style fastcall calling convention):

.globl  _WRPR_P$PROGRAM_TMYCLASS_$_IINTERFACE_$_0_ 
$__SYSTEM_TINTERFACEDOBJECT_$__QUERYINTERFACE$TGUID$formal$$LONGINT
_WRPR_P$PROGRAM_TMYCLASS_$_IINTERFACE_$_0_$__SYSTEM_TINTERFACEDOBJECT_ 
$__QUERYINTERFACE$TGUID$formal$$LONGINT:
         subl    $12,4(%esp)
         jmp     L_SYSTEM_TINTERFACEDOBJECT_$__QUERYINTERFACE$TGUID 
$formal$$LONGINT$stub

.globl  _WRPR_P$PROGRAM_TMYCLASS_$_IINTERFACE_$_3_$__P 
$PROGRAM_TMYCLASS_$__MYDO
_WRPR_P$PROGRAM_TMYCLASS_$_IINTERFACE_$_3_$__P$PROGRAM_TMYCLASS_$__MYDO:
         subl    $12,%eax
         pushl   %ebx
         pushl   %eax
         movl    (%eax),%eax
         movl    80(%eax),%eax
         movl    %eax,4(%esp)
         popl    %eax
         ret


             reply	other threads:[~2009-04-01 19:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-01 19:08 Jonas Maebe [this message]
2009-04-01 19:14 ` Daniel Jacobowitz
2009-04-01 20:15   ` Jonas Maebe
2009-04-01 20:20     ` Daniel Jacobowitz
2009-04-01 21:40       ` Jonas Maebe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B835C7C-B28E-4552-87E0-25D803741FA3@elis.ugent.be \
    --to=jonas.maebe@elis.ugent.be \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox