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
bb2e6fd2
Commit
bb2e6fd2
authored
Nov 19, 2018
by
Dale Hamel
Committed by
Alastair Robertson
Nov 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt to correctly handle indirect struct fields
parent
5c459761
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
src/clang_parser.cpp
src/clang_parser.cpp
+31
-1
No files found.
src/clang_parser.cpp
View file @
bb2e6fd2
...
...
@@ -38,6 +38,33 @@ static void remove_struct_prefix(std::string &str)
str
.
erase
(
0
,
7
);
}
static
CXCursor
get_indirect_field_parent_struct
(
CXCursor
c
)
{
CXCursor
parent
=
clang_getCursorSemanticParent
(
c
);
while
(
!
clang_Cursor_isNull
(
parent
)
&&
clang_Cursor_isAnonymous
(
parent
))
parent
=
clang_getCursorSemanticParent
(
parent
);
return
parent
;
}
static
std
::
string
get_parent_struct_name
(
CXCursor
c
)
{
CXCursor
parent
=
get_indirect_field_parent_struct
(
c
);
return
get_clang_string
(
clang_getCursorSpelling
(
parent
));
}
static
int
get_indirect_field_offset
(
CXCursor
c
)
{
int
offset
=
0
;
CXCursor
parent
=
get_indirect_field_parent_struct
(
c
);
auto
ident
=
get_clang_string
(
clang_getCursorSpelling
(
c
));
offset
=
clang_Type_getOffsetOf
(
clang_getCursorType
(
parent
),
ident
.
c_str
())
/
8
;
return
offset
;
}
static
SizedType
get_sized_type
(
CXType
clang_type
)
{
auto
size
=
clang_Type_getSizeOf
(
clang_type
);
...
...
@@ -225,7 +252,7 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
if
(
clang_getCursorKind
(
c
)
==
CXCursor_FieldDecl
)
{
auto
struct_name
=
get_
clang_string
(
clang_getCursorSpelling
(
parent
)
);
auto
struct_name
=
get_
parent_struct_name
(
c
);
auto
ident
=
get_clang_string
(
clang_getCursorSpelling
(
c
));
auto
offset
=
clang_Cursor_getOffsetOfField
(
c
)
/
8
;
auto
type
=
clang_getCanonicalType
(
clang_getCursorType
(
c
));
...
...
@@ -234,6 +261,9 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
auto
ptypestr
=
get_clang_string
(
clang_getTypeSpelling
(
ptype
));
auto
ptypesize
=
clang_Type_getSizeOf
(
ptype
);
if
(
clang_Cursor_isAnonymous
(
parent
))
offset
=
get_indirect_field_offset
(
c
);
if
(
struct_name
==
""
)
struct_name
=
ptypestr
;
remove_struct_prefix
(
struct_name
);
...
...
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