2023-07-07 16:17:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "oi/SymbolService.h"
|
|
|
|
#include "oi/type_graph/AddChildren.h"
|
2023-08-15 15:27:20 +01:00
|
|
|
#include "oi/type_graph/NodeTracker.h"
|
2023-07-07 16:17:03 +01:00
|
|
|
#include "oi/type_graph/Printer.h"
|
|
|
|
#include "oi/type_graph/TypeGraph.h"
|
|
|
|
#include "test_drgn_parser.h"
|
|
|
|
|
|
|
|
using namespace type_graph;
|
|
|
|
|
|
|
|
class AddChildrenTest : public DrgnParserTest {
|
|
|
|
protected:
|
2023-08-16 19:15:09 +01:00
|
|
|
std::string run(std::string_view function,
|
|
|
|
DrgnParserOptions options) override;
|
2023-07-07 16:17:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string AddChildrenTest::run(std::string_view function,
|
2023-08-16 19:15:09 +01:00
|
|
|
DrgnParserOptions options) {
|
2023-07-07 16:17:03 +01:00
|
|
|
TypeGraph typeGraph;
|
2023-08-16 19:15:09 +01:00
|
|
|
auto drgnParser = getDrgnParser(typeGraph, options);
|
2023-07-07 16:17:03 +01:00
|
|
|
auto* drgnRoot = getDrgnRoot(function);
|
|
|
|
|
|
|
|
Type& type = drgnParser.parse(drgnRoot);
|
|
|
|
typeGraph.addRoot(type);
|
2023-08-15 15:27:20 +01:00
|
|
|
NodeTracker tracker;
|
2023-07-07 16:17:03 +01:00
|
|
|
|
|
|
|
auto pass = AddChildren::createPass(drgnParser, *symbols_);
|
2023-08-15 15:27:20 +01:00
|
|
|
pass.run(typeGraph, tracker);
|
2023-07-07 16:17:03 +01:00
|
|
|
|
|
|
|
std::stringstream out;
|
2023-08-15 15:27:20 +01:00
|
|
|
Printer printer{out, tracker, typeGraph.size()};
|
2023-07-07 16:17:03 +01:00
|
|
|
printer.print(type);
|
|
|
|
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AddChildrenTest, SimpleStruct) {
|
|
|
|
// Should do nothing
|
|
|
|
test("oid_test_case_simple_struct", R"(
|
2023-08-02 11:11:52 +01:00
|
|
|
[1] Pointer
|
|
|
|
[0] Struct: SimpleStruct (size: 16)
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: a (offset: 0)
|
|
|
|
Primitive: int32_t
|
|
|
|
Member: b (offset: 4)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: c (offset: 8)
|
|
|
|
Primitive: int64_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AddChildrenTest, InheritanceStatic) {
|
|
|
|
// Should do nothing
|
|
|
|
test("oid_test_case_inheritance_access_public", R"(
|
2023-08-16 20:40:36 +01:00
|
|
|
[4] Pointer
|
2023-08-02 11:11:52 +01:00
|
|
|
[0] Class: Public (size: 8)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-08-02 11:11:52 +01:00
|
|
|
[1] Class: Base (size: 4)
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: base_int (offset: 0)
|
2023-08-16 20:40:36 +01:00
|
|
|
[3] Typedef: int32_t
|
|
|
|
[2] Typedef: __int32_t
|
|
|
|
Primitive: int32_t
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: public_int (offset: 4)
|
2023-08-16 20:40:36 +01:00
|
|
|
[3]
|
2023-07-07 16:17:03 +01:00
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(AddChildrenTest, InheritancePolymorphic) {
|
2023-11-13 16:50:09 +00:00
|
|
|
testMultiCompilerGlob("oid_test_case_inheritance_polymorphic_a_as_a",
|
|
|
|
R"(
|
2023-08-02 11:11:52 +01:00
|
|
|
[1] Pointer
|
|
|
|
[0] Class: A (size: 16)
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: _vptr$A (offset: 0)
|
2023-09-21 16:57:08 +01:00
|
|
|
Primitive: StubbedPointer
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: int_a (offset: 8)
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: ~A (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
Function: A
|
|
|
|
Function: A
|
|
|
|
Child
|
2023-11-02 13:18:32 +00:00
|
|
|
[17] Class: B (size: 40)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-08-02 11:11:52 +01:00
|
|
|
[0]
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: vec_b (offset: 16)
|
2023-11-02 13:18:32 +00:00
|
|
|
[4] Class: vector<int, std::allocator<int> > (size: 24)
|
2023-07-07 16:17:03 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
2023-08-02 11:11:52 +01:00
|
|
|
[5] Class: allocator<int> (size: 1)
|
2023-07-07 16:17:03 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Parent (offset: 0)
|
2023-08-02 11:11:52 +01:00
|
|
|
[7] Typedef: __allocator_base<int>
|
2023-07-24 13:14:53 +01:00
|
|
|
[6] Class: new_allocator<int> (size: 1)
|
2023-07-07 16:17:03 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: new_allocator
|
|
|
|
Function: new_allocator
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
|
|
|
Function: _M_max_size
|
|
|
|
Function: allocator
|
|
|
|
Function: allocator
|
|
|
|
Function: operator=
|
|
|
|
Function: ~allocator
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
2023-11-02 13:18:32 +00:00
|
|
|
*
|
2023-07-07 16:17:03 +01:00
|
|
|
Function: ~B (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
Function: B
|
|
|
|
Function: B
|
|
|
|
Child
|
2023-11-02 13:18:32 +00:00
|
|
|
[19] Class: C (size: 48)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-11-02 13:18:32 +00:00
|
|
|
[17]
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: int_c (offset: 40)
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: ~C (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
Function: C
|
|
|
|
Function: C
|
|
|
|
)",
|
2023-11-02 13:18:32 +00:00
|
|
|
R"(
|
2023-08-02 11:11:52 +01:00
|
|
|
[1] Pointer
|
|
|
|
[0] Class: A (size: 16)
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: _vptr.A (offset: 0)
|
2023-09-21 16:57:08 +01:00
|
|
|
Primitive: StubbedPointer
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: int_a (offset: 8)
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: operator=
|
|
|
|
Function: A
|
|
|
|
Function: A
|
|
|
|
Function: ~A (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
Child
|
2023-11-02 13:18:32 +00:00
|
|
|
[13] Class: B (size: 40)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-08-02 11:11:52 +01:00
|
|
|
[0]
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: vec_b (offset: 16)
|
2023-11-02 13:18:32 +00:00
|
|
|
[4] Class: vector<int, std::allocator<int> > (size: 24)
|
2023-07-07 16:17:03 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
2023-08-02 11:11:52 +01:00
|
|
|
[5] Class: allocator<int> (size: 1)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-08-02 11:11:52 +01:00
|
|
|
[6] Class: new_allocator<int> (size: 1)
|
2023-07-07 16:17:03 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: new_allocator
|
|
|
|
Function: new_allocator
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
|
|
|
Function: _M_max_size
|
|
|
|
Function: allocator
|
|
|
|
Function: allocator
|
|
|
|
Function: operator=
|
|
|
|
Function: ~allocator
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
2023-11-02 13:18:32 +00:00
|
|
|
*
|
2023-07-07 16:17:03 +01:00
|
|
|
Function: operator=
|
|
|
|
Function: B
|
|
|
|
Function: B
|
|
|
|
Function: ~B (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
Child
|
2023-11-02 13:18:32 +00:00
|
|
|
[15] Class: C (size: 48)
|
2023-07-07 16:17:03 +01:00
|
|
|
Parent (offset: 0)
|
2023-11-02 13:18:32 +00:00
|
|
|
[13]
|
2023-07-07 16:17:03 +01:00
|
|
|
Member: int_c (offset: 40)
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: operator=
|
|
|
|
Function: C
|
|
|
|
Function: C
|
|
|
|
Function: ~C (virtual)
|
|
|
|
Function: myfunc (virtual)
|
|
|
|
)");
|
|
|
|
}
|