[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is a virtual thunk

From: John V. Shahid
Subject: Re: What is a virtual thunk
Date: Fri, 05 Oct 2007 14:18:07 -0400

On Thu, 2007-10-04 at 11:10 -0700, wrote:
> I am seeing the following, for GDB  step into a function.

What function ?

>  Somehow the
> debug information is not there and it shows me some other file.
> Please help with me with this.
>   I have compiled with -g all the way.
> #0  0x42bb6e76 in virtual thunk to
> vhpiVssPortDeclC::vhpiGetValue(vhpiValueT*) () at util.hh:178

The "virtual thunk" or "adjuster thunk" is a piece of code that adjusts
the offset of a pointer or reference to an object. For example:

========================= Test.cpp ============================
class P {
                void pvf(int x) {this.x = x;}
                int x;
class R {
                void pvf(int x) {//do nothing}
class S : P, R {
                void pvf(int x) { this.x = x * 2;}
#include <stdlib.h>
int main(void)
        S s;
        S* ps = &s;
        P* pp = ps;//A pointer to a S object is also a pointer to a P object
        //By polymorphism the following call should be dispatched to the
        //overriding version of pvf (i.e. x = x * 2). But this function 
        //expects a pointer to a S object (i.e. the "this" pointer), yet
        //the function can be called on either a S object pointer, P 
        //object pointer or R object pointer due to multiple 
        //which requires the adjuster thunk to technically changes the 
        //pointer from either a P pointer or R pointer to S pointer.
        //The adjuster thunk is called first to change the offset and 
        //then the function is called.
        return EXIT_SUCCESS;
=========================== End of Test.cpp ==========================

Stepping a couple of steps through the adjuster thunk should eventually
take you to the beginning of your function.

John V. Shahid <>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]