Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It does not show vtable and vptr assignment #553

Open
rajendrasp opened this issue Aug 1, 2023 · 2 comments
Open

It does not show vtable and vptr assignment #553

rajendrasp opened this issue Aug 1, 2023 · 2 comments

Comments

@rajendrasp
Copy link

The tool does not show me memory layout of the program including vtable. And constructor implementation does not show vptr assignment. Any plan to add these?

@andreasfertig
Copy link
Owner

Hello @rajendrasp,

thanks for raising this question.

Addressing the vtable:
What you're asking for isn't represented in the AST at the front-end stage. This is the main reason C++ Insights currently doesn't show that information. I have some idea of how to implement support for this, but it would be limited to the Itanium ABI, which is different from Microsoft and others.

Since you raised the question, how would you like to see the transformation?

Regarding the memory layout:
I'm not sure what you're missing here. There is an option to show padding information, giving you memory layout information.

Andreas

@rajendrasp
Copy link
Author

For vtable, I was thinking of seeing the memory layout of compiled object. Microsoft Visual C++ has following undocumented options that give layout information.

/d1reportSingleClassLayoutXXX
/d1reportAllClassLayout

https://stackoverflow.com/questions/2138890/layout-of-compiled-objects

Following is what it ouputs for a multiply-inherited classes.

Library.cpp

class IHen size(8):
+---
0 | +--- (base class IObject)
0 | | {vfptr}
| +---
+---

IHen::$vftable@:
| &IHen_meta
| 0
0 | &IObject::AddRef
1 | &IObject::Release
2 | &IObject::As
3 | &IHen::Cluck
4 | &IHen::Roost

IHen::Cluck this adjustor: 0
IHen::Roost this adjustor: 0

class IHen2 size(8):
+---
0 | +--- (base class IHen)
0 | | +--- (base class IObject)
0 | | | {vfptr}
| | +---
| +---
+---

IHen2::$vftable@:
| &IHen2_meta
| 0
0 | &IObject::AddRef
1 | &IObject::Release
2 | &IObject::As
3 | &IHen::Cluck
4 | &IHen::Roost
5 | &IHen2::Forage

IHen2::Forage this adjustor: 0

class Hen size(24):
+---
0 | +--- (base class IHen2)
0 | | +--- (base class IHen)
0 | | | +--- (base class IObject)
0 | | | | {vfptr}
| | | +---
| | +---
| +---
8 | +--- (base class IOfflineChicken)
8 | | +--- (base class IObject)
8 | | | {vfptr}
| | +---
| +---
16 | m_count
| (size=4)
+---

Hen::$vftable@IHen2@:
| &Hen_meta
| 0
0 | &Hen::AddRef
1 | &Hen::Release
2 | &Hen::As
3 | &Hen::Cluck
4 | &Hen::Roost
5 | &Hen::Forage

Hen::$vftable@IOfflineChicken@:
| -8
0 | &thunk: this-=8; goto Hen::AddRef
1 | &thunk: this-=8; goto Hen::Release
2 | &thunk: this-=8; goto Hen::As
3 | &Hen::Load
4 | &Hen::Save

I do not understand why thunk is used instead of just saying &Hen::AddRef in vtable "Hen::$vftable@IOfflineChicken@:".

But this is something I was hoping for with a bit of better presentation in the cppinsights.

I was also looking for code that initialises the this->_vptr in constructors. And compiler generated code in destructor if there is any.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants