Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
42ce08fc
Commit
42ce08fc
authored
Sep 30, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TracepointFormatParser: Fix list of integer types which may need adjusting
parent
6e4ff5a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
21 deletions
+65
-21
src/tracepoint_format_parser.cpp
src/tracepoint_format_parser.cpp
+5
-21
tests/tracepoint_format_parser.cpp
tests/tracepoint_format_parser.cpp
+60
-0
No files found.
src/tracepoint_format_parser.cpp
View file @
42ce08fc
...
...
@@ -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"
;
}
...
...
tests/tracepoint_format_parser.cpp
View file @
42ce08fc
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment