From bc895dc9cce68bad11bdadcaf53c62c674b780ea Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Mon, 24 Jul 2023 05:14:53 -0700 Subject: [PATCH] DrgnParser: Always stub function pointers This makes CodeGen v2 behave the same as CodeGen v1, and there doesn't seem much point in following function pointers either. --- oi/type_graph/DrgnParser.cpp | 15 ++++++++++++++- test/test_add_children.cpp | 34 +++++++++++++++------------------- test/test_drgn_parser.cpp | 8 ++------ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/oi/type_graph/DrgnParser.cpp b/oi/type_graph/DrgnParser.cpp index a432db1..0a6bfbd 100644 --- a/oi/type_graph/DrgnParser.cpp +++ b/oi/type_graph/DrgnParser.cpp @@ -427,6 +427,17 @@ Typedef& DrgnParser::enumerateTypedef(struct drgn_type* type) { return makeType(type, name, t); } +static drgn_type* getPtrUnderlyingType(drgn_type* type) { + drgn_type* underlyingType = type; + + while (drgn_type_kind(underlyingType) == DRGN_TYPE_POINTER || + drgn_type_kind(underlyingType) == DRGN_TYPE_TYPEDEF) { + underlyingType = drgn_type_type(underlyingType).type; + } + + return underlyingType; +} + Type& DrgnParser::enumeratePointer(struct drgn_type* type) { if (!chasePointer()) { return makeType(type, Primitive::Kind::UIntPtr); @@ -434,7 +445,9 @@ Type& DrgnParser::enumeratePointer(struct drgn_type* type) { struct drgn_type* pointeeType = drgn_type_type(type).type; - // TODO why was old CodeGen following funciton pointers? + if (drgn_type_kind(getPtrUnderlyingType(type)) == DRGN_TYPE_FUNCTION) { + return makeType(type, Primitive::Kind::UIntPtr); + } Type& t = enumerateType(pointeeType); return makeType(type, t); diff --git a/test/test_add_children.cpp b/test/test_add_children.cpp index 59d74bd..4ce2e26 100644 --- a/test/test_add_children.cpp +++ b/test/test_add_children.cpp @@ -65,9 +65,7 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { [0] Pointer [1] Class: A (size: 16) Member: _vptr$A (offset: 0) -[2] Pointer -[3] Pointer - Primitive: void + Primitive: uintptr_t Member: int_a (offset: 8) Primitive: int32_t Function: ~A (virtual) @@ -75,20 +73,20 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { Function: A Function: A Child -[4] Class: B (size: 40) +[2] Class: B (size: 40) Parent (offset: 0) [1] Member: vec_b (offset: 16) -[5] Container: std::vector (size: 24) +[3] Container: std::vector (size: 24) Param Primitive: int32_t Param -[6] Class: allocator (size: 1) +[4] Class: allocator (size: 1) Param Primitive: int32_t Parent (offset: 0) -[7] Typedef: __allocator_base -[8] Class: new_allocator (size: 1) +[5] Typedef: __allocator_base +[6] Class: new_allocator (size: 1) Param Primitive: int32_t Function: new_allocator @@ -107,9 +105,9 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { Function: B Function: B Child -[9] Class: C (size: 48) +[7] Class: C (size: 48) Parent (offset: 0) - [4] + [2] Member: int_c (offset: 40) Primitive: int32_t Function: ~C (virtual) @@ -121,9 +119,7 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { [0] Pointer [1] Class: A (size: 16) Member: _vptr.A (offset: 0) -[2] Pointer -[3] Pointer - Primitive: void + Primitive: uintptr_t Member: int_a (offset: 8) Primitive: int32_t Function: operator= @@ -132,17 +128,17 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { Function: ~A (virtual) Function: myfunc (virtual) Child -[4] Class: B (size: 40) +[2] Class: B (size: 40) Parent (offset: 0) [1] Member: vec_b (offset: 16) -[5] Container: std::vector (size: 24) +[3] Container: std::vector (size: 24) Param Primitive: int32_t Param -[6] Class: allocator (size: 1) +[4] Class: allocator (size: 1) Parent (offset: 0) -[7] Class: new_allocator (size: 1) +[5] Class: new_allocator (size: 1) Param Primitive: int32_t Function: new_allocator @@ -162,9 +158,9 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) { Function: ~B (virtual) Function: myfunc (virtual) Child -[8] Class: C (size: 48) +[6] Class: C (size: 48) Parent (offset: 0) - [4] + [2] Member: int_c (offset: 40) Primitive: int32_t Function: operator= diff --git a/test/test_drgn_parser.cpp b/test/test_drgn_parser.cpp index f9c5ae4..ae97c37 100644 --- a/test/test_drgn_parser.cpp +++ b/test/test_drgn_parser.cpp @@ -543,9 +543,7 @@ TEST_F(DrgnParserTest, VirtualFunctions) { [0] Pointer [1] Class: A (size: 16) Member: _vptr$A (offset: 0) -[2] Pointer -[3] Pointer - Primitive: void + Primitive: uintptr_t Member: int_a (offset: 8) Primitive: int32_t Function: ~A (virtual) @@ -557,9 +555,7 @@ TEST_F(DrgnParserTest, VirtualFunctions) { [0] Pointer [1] Class: A (size: 16) Member: _vptr.A (offset: 0) -[2] Pointer -[3] Pointer - Primitive: void + Primitive: uintptr_t Member: int_a (offset: 8) Primitive: int32_t Function: operator=