Commit 42ce08fc authored by Alastair Robertson's avatar Alastair Robertson

TracepointFormatParser: Fix list of integer types which may need adjusting

parent 6e4ff5a0
......@@ -98,29 +98,13 @@ std::string TracepointFormatParser::adjust_integer_types(const std::string &fiel
{
std::string new_type = field_type;
// Adjust integer fields to correctly sized types
if (size == 2)
if (size == 8)
{
if (new_type == "char" || new_type == "int8_t")
new_type = "s16";
if (new_type == "unsigned char" || new_type == "uint8_t")
new_type = "u16";
} else if (size == 4)
{
if (new_type == "char" || new_type == "short" ||
new_type == "int8_t" || new_type == "int16_t")
new_type = "s32";
if (new_type == "unsigned char" || new_type == "unsigned short" ||
new_type == "uint8_t" || new_type == "uint16_t")
new_type = "u32";
} else if (size == 8)
{
if (new_type == "char" || new_type == "short" || new_type == "int" ||
new_type == "int8_t" || new_type == "int16_t" ||
new_type == "int32_t")
if (field_type == "int")
new_type = "s64";
if (new_type == "unsigned char" || new_type == "unsigned short" ||
new_type == "unsigned int" || new_type == "uint8_t" ||
new_type == "uint16_t" || new_type == "uint32_t")
if (field_type == "unsigned int" || field_type == "unsigned" ||
field_type == "u32" || field_type == "pid_t" ||
field_type == "uid_t" || field_type == "gid_t")
new_type = "u64";
}
......
......@@ -89,6 +89,66 @@ TEST(tracepoint_format_parser, data_loc)
EXPECT_EQ(expected, result);
}
TEST(tracepoint_format_parser, adjust_integer_types)
{
std::string input =
" field:int arr[8]; offset:0; size:32; signed:1;\n"
" field:int int_a; offset:0; size:4; signed:1;\n"
" field:int int_b; offset:0; size:8; signed:1;\n"
" field:u32 u32_a; offset:0; size:4; signed:0;\n"
" field:u32 u32_b; offset:0; size:8; signed:0;\n"
" field:unsigned int uint_a; offset:0; size:4; signed:0;\n"
" field:unsigned int uint_b; offset:0; size:8; signed:0;\n"
" field:unsigned unsigned_a; offset:0; size:4; signed:0;\n"
" field:unsigned unsigned_b; offset:0; size:8; signed:0;\n"
" field:uid_t uid_a; offset:0; size:4; signed:0;\n"
" field:uid_t uid_b; offset:0; size:8; signed:0;\n"
" field:gid_t gid_a; offset:0; size:4; signed:0;\n"
" field:gid_t gid_b; offset:0; size:8; signed:0;\n"
" field:pid_t pid_a; offset:0; size:4; signed:1;\n"
" field:pid_t pid_b; offset:0; size:8; signed:0;\n";
std::string expected =
"struct _tracepoint_syscalls_sys_enter_read\n"
"{\n"
" int arr[8];\n"
" int int_a;\n"
" s64 int_b;\n"
" u32 u32_a;\n"
" u64 u32_b;\n"
" unsigned int uint_a;\n"
" u64 uint_b;\n"
" unsigned unsigned_a;\n"
" u64 unsigned_b;\n"
" uid_t uid_a;\n"
" u64 uid_b;\n"
" gid_t gid_a;\n"
" u64 gid_b;\n"
" pid_t pid_a;\n"
" u64 pid_b;\n"
"};\n";
std::istringstream format_file(input);
std::string result = MockTracepointFormatParser::get_tracepoint_struct_public(format_file, "syscalls", "sys_enter_read");
EXPECT_EQ(expected, result);
}
} // namespace tracepoint_format_parser
} // namespace test
} // namespace bpftrace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment