Skip to content

Commit 5632738

Browse files
committed
make StubbedPointer an explicit C++ type
1 parent 9359757 commit 5632738

File tree

9 files changed

+60
-24
lines changed

9 files changed

+60
-24
lines changed

oi/OITraceCode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,5 @@ struct validate_offset {
143143
static constexpr bool value = true;
144144
static_assert(ExpectedOffset == ActualOffset);
145145
};
146+
147+
enum class StubbedPointer : uintptr_t {};

oi/type_graph/DrgnParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,13 @@ static drgn_type* getPtrUnderlyingType(drgn_type* type) {
464464

465465
Type& DrgnParser::enumeratePointer(struct drgn_type* type) {
466466
if (!chasePointer()) {
467-
return makeType<Primitive>(type, Primitive::Kind::UIntPtr);
467+
return makeType<Primitive>(type, Primitive::Kind::StubbedPointer);
468468
}
469469

470470
struct drgn_type* pointeeType = drgn_type_type(type).type;
471471

472472
if (drgn_type_kind(getPtrUnderlyingType(type)) == DRGN_TYPE_FUNCTION) {
473-
return makeType<Primitive>(type, Primitive::Kind::UIntPtr);
473+
return makeType<Primitive>(type, Primitive::Kind::StubbedPointer);
474474
}
475475

476476
Type& t = enumerateType(pointeeType);

oi/type_graph/TypeGraph.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ Primitive& TypeGraph::makeType<Primitive>(Primitive::Kind kind) {
5959
case Primitive::Kind::Bool:
6060
static Primitive pBool{kind};
6161
return pBool;
62-
case Primitive::Kind::UIntPtr:
63-
static Primitive pUIntPtr{kind};
64-
return pUIntPtr;
62+
case Primitive::Kind::StubbedPointer:
63+
static Primitive pStubbedPointer{kind};
64+
return pStubbedPointer;
6565
case Primitive::Kind::Void:
6666
static Primitive pVoid{kind};
6767
return pVoid;

oi/type_graph/Types.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,21 @@ std::string Primitive::getName(Kind kind) {
5757
return "long double";
5858
case Kind::Bool:
5959
return "bool";
60-
case Kind::UIntPtr:
61-
return "uintptr_t";
60+
case Kind::StubbedPointer:
61+
return "StubbedPointer";
6262
case Kind::Void:
6363
case Kind::Incomplete:
6464
return "void";
6565
}
6666
}
6767

68+
std::string_view Primitive::inputName() const {
69+
static const std::string kStubbedPointer = "uintptr_t (stubbed)";
70+
if (kind_ == Kind::StubbedPointer)
71+
return kStubbedPointer;
72+
return name_;
73+
}
74+
6875
std::size_t Primitive::size() const {
6976
switch (kind_) {
7077
case Kind::Int8:
@@ -93,7 +100,7 @@ std::size_t Primitive::size() const {
93100
return 16;
94101
case Kind::Bool:
95102
return 1;
96-
case Kind::UIntPtr:
103+
case Kind::StubbedPointer:
97104
return sizeof(uintptr_t);
98105
case Kind::Void:
99106
case Kind::Incomplete:

oi/type_graph/Types.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ class Primitive : public Type {
485485
Float128, // TODO can we generate this?
486486
Bool,
487487

488-
UIntPtr, // Really an alias, but useful to have as its own primitive
489-
488+
StubbedPointer,
490489
Void,
491490
Incomplete, // Behaves the same as Void, but alerts us that the type was
492491
// stubbed out due to incomplete DWARF
@@ -502,9 +501,7 @@ class Primitive : public Type {
502501
virtual const std::string& name() const override {
503502
return name_;
504503
}
505-
virtual std::string_view inputName() const override {
506-
return name_;
507-
}
504+
virtual std::string_view inputName() const override;
508505
virtual size_t size() const override;
509506
virtual uint64_t align() const override {
510507
return size();

test/TypeGraphParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Primitive::Kind getKind(std::string_view kindStr) {
4545
return Primitive::Kind::Float128;
4646
if (kindStr == "bool")
4747
return Primitive::Kind::Bool;
48-
if (kindStr == "uintptr_t")
49-
return Primitive::Kind::UIntPtr;
48+
if (kindStr == "StubbedPointer")
49+
return Primitive::Kind::StubbedPointer;
5050
if (kindStr == "void")
5151
return Primitive::Kind::Void;
5252
if (kindStr == "void (incomplete)")

test/integration/std_pair.toml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
includes = ["vector", "utility", "cstdint"]
22
[cases]
33
[cases.uint64_uint64]
4-
oil_skip = 'tests need updating for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/310
54
param_types = ["std::pair<std::uint64_t, std::uint64_t>&"]
65
setup = "return {{0, 1}};"
76
expect_json = '''
@@ -14,8 +13,13 @@ includes = ["vector", "utility", "cstdint"]
1413
}
1514
]
1615
'''
16+
expect_json_v2 = '''[
17+
{"staticSize": 16, "exclusiveSize": 0, "members": [
18+
{"typeNames": ["uint64_t"], "staticSize": 8, "exclusiveSize": 8},
19+
{"typeNames": ["uint64_t"], "staticSize": 8, "exclusiveSize": 8}
20+
]}
21+
]'''
1722
[cases.uint64_uint32]
18-
oil_skip = 'tests need updating for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/310
1923
param_types = ["std::pair<std::uint64_t, std::uint32_t>&"]
2024
setup = "return {{0, 1}};"
2125
# Should still have static size of 16 due to padding
@@ -29,8 +33,28 @@ includes = ["vector", "utility", "cstdint"]
2933
}
3034
]
3135
'''
36+
expect_json_v2 = '''[
37+
{"staticSize": 16, "exclusiveSize": 4, "members": [
38+
{"typeNames": ["uint64_t"], "staticSize": 8, "exclusiveSize": 8},
39+
{"typeNames": ["uint32_t"], "staticSize": 4, "exclusiveSize": 4}
40+
]}
41+
]'''
42+
43+
[cases.uint64_uint64_ptr]
44+
# Stubbed pointers were previously generated as a uintptr_t. Now they're
45+
# generated as a special StubbedPointer type. This previously caused
46+
# codegen problems as uintptr_t is a typedef of uint64_t and they'd both
47+
# be specialised on a template.
48+
param_types = ["std::pair<uint64_t, uint64_t*>&"]
49+
setup = "return {{0, nullptr}};"
50+
expect_json_v2 = '''[
51+
{"staticSize": 16, "exclusiveSize": 0, "members": [
52+
{"typeNames": ["uint64_t"], "staticSize": 8, "exclusiveSize": 8},
53+
{"typeNames": ["uintptr_t (stubbed)"], "staticSize": 8, "exclusiveSize": 8}
54+
]}
55+
]'''
56+
3257
[cases.vector_vector]
33-
oil_skip = 'tests need updating for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/310
3458
param_types = ["std::pair<std::vector<std::uint64_t>, std::vector<std::uint64_t>>&"]
3559
setup = "return {{std::initializer_list<std::uint64_t>({0,1,2}), std::initializer_list<std::uint64_t>({3,4,5,6})}};"
3660
expect_json = '''
@@ -57,3 +81,9 @@ includes = ["vector", "utility", "cstdint"]
5781
}
5882
]
5983
'''
84+
expect_json_v2 = '''[
85+
{"staticSize": 48, "exclusiveSize": 0, "members": [
86+
{"typeNames": ["std::vector<uint64_t, std::allocator<uint64_t>>"], "staticSize": 24, "exclusiveSize": 24},
87+
{"typeNames": ["std::vector<uint64_t, std::allocator<uint64_t>>"], "staticSize": 24, "exclusiveSize": 24}
88+
]}
89+
]'''

test/test_add_children.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) {
7070
[1] Pointer
7171
[0] Class: A (size: 16)
7272
Member: _vptr$A (offset: 0)
73-
Primitive: uintptr_t
73+
Primitive: StubbedPointer
7474
Member: int_a (offset: 8)
7575
Primitive: int32_t
7676
Function: ~A (virtual)
@@ -124,7 +124,7 @@ TEST_F(AddChildrenTest, InheritancePolymorphic) {
124124
[1] Pointer
125125
[0] Class: A (size: 16)
126126
Member: _vptr.A (offset: 0)
127-
Primitive: uintptr_t
127+
Primitive: StubbedPointer
128128
Member: int_a (offset: 8)
129129
Primitive: int32_t
130130
Function: operator=

test/test_drgn_parser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ TEST_F(DrgnParserTest, PointerNoFollow) {
356356
Member: a (offset: 0)
357357
Primitive: int32_t
358358
Member: b (offset: 8)
359-
Primitive: uintptr_t
359+
Primitive: StubbedPointer
360360
Member: c (offset: 16)
361-
Primitive: uintptr_t
361+
Primitive: StubbedPointer
362362
)",
363363
options);
364364
}
@@ -586,7 +586,7 @@ TEST_F(DrgnParserTest, VirtualFunctions) {
586586
[1] Pointer
587587
[0] Class: A (size: 16)
588588
Member: _vptr$A (offset: 0)
589-
Primitive: uintptr_t
589+
Primitive: StubbedPointer
590590
Member: int_a (offset: 8)
591591
Primitive: int32_t
592592
Function: ~A (virtual)
@@ -598,7 +598,7 @@ TEST_F(DrgnParserTest, VirtualFunctions) {
598598
[1] Pointer
599599
[0] Class: A (size: 16)
600600
Member: _vptr.A (offset: 0)
601-
Primitive: uintptr_t
601+
Primitive: StubbedPointer
602602
Member: int_a (offset: 8)
603603
Primitive: int32_t
604604
Function: operator=

0 commit comments

Comments
 (0)