MemViz v1.0.0
C++ Memory Layout Inspector
Loading...
Searching...
No Matches
VTableInspector.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <bit>
5#include <iostream>
6#include <cassert>
7#include <cstring>
8
9namespace memviz {
40 template<typename T>
41 static void inspectVTable(T *obj, size_t max_slots = 64) {
42 static_assert(std::is_polymorphic_v<T>);
43 assert(obj != nullptr);
44
45 void* raw = nullptr;
46 std::memcpy(&raw, obj, sizeof(raw));
47
48 if (!raw) {
49 std::cout << "\031[31m[ERROR]: unable to copy terminating inspectVTable\031[0m\n";
50 return ;
51 }
52
53 void** vtable = reinterpret_cast<void**>(raw);
54
55 for(size_t i = 0; i < max_slots; i++) {
56 if (vtable[i] == nullptr)
57 break;
58 std::cout<<"["<<i<<"]"<<vtable[i]<<std::endl;
59 }
60 }
61}
Definition BitCaster.hpp:5