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
269c7388
Commit
269c7388
authored
Oct 07, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang_parser: Use BCC's KBuildHelper
To get full arguments to pass into Clang for reading kernel headers
parent
c3b69149
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
12 deletions
+44
-12
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/clang_parser.cpp
src/clang_parser.cpp
+42
-12
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
No files found.
src/CMakeLists.txt
View file @
269c7388
...
...
@@ -20,6 +20,7 @@ target_include_directories(bpftrace PUBLIC ${source_dir}/src/cc)
target_link_libraries
(
bpftrace
${
binary_dir
}
/src/cc/libbpf.a
)
target_link_libraries
(
bpftrace
${
binary_dir
}
/src/cc/libbcc-loader-static.a
)
target_link_libraries
(
bpftrace
${
binary_dir
}
/src/cc/libbcc.a
)
target_link_libraries
(
bpftrace
${
binary_dir
}
/src/cc/frontends/clang/libclang_frontend.a
)
target_link_libraries
(
bpftrace
${
LIBELF_LIBRARIES
}
)
install
(
TARGETS bpftrace DESTINATION bin
)
src/clang_parser.cpp
View file @
269c7388
...
...
@@ -3,6 +3,8 @@
#include <string.h>
#include <sys/utsname.h>
#include "frontends/clang/kbuild_helper.h"
#include "ast.h"
#include "bpftrace.h"
#include "clang_parser.h"
...
...
@@ -88,16 +90,28 @@ static SizedType get_sized_type(CXType clang_type)
// TODO add support for arrays
return
SizedType
(
Type
::
none
,
0
);
}
case
CXType_LongDouble
:
return
SizedType
(
Type
::
none
,
0
);
default:
// TODO just return Type::none?
auto
unknown_type
=
get_clang_string
(
clang_getTypeKindSpelling
(
clang_type
.
kind
));
std
::
cerr
<<
"Error: unknown clang CXType '"
<<
unknown_type
<<
"'"
<<
std
::
endl
;
abort
();
return
SizedType
(
Type
::
none
,
0
);
}
}
static
bool
is_dir
(
const
std
::
string
&
path
)
{
struct
stat
buf
;
if
(
::
stat
(
path
.
c_str
(),
&
buf
)
<
0
)
return
false
;
return
S_ISDIR
(
buf
.
st_mode
);
}
static
std
::
pair
<
bool
,
std
::
string
>
get_kernel_path_info
(
const
std
::
string
kdir
)
{
if
(
is_dir
(
kdir
+
"/build"
)
&&
is_dir
(
kdir
+
"/source"
))
return
std
::
make_pair
(
true
,
"source"
);
return
std
::
make_pair
(
false
,
"build"
);
}
void
ClangParser
::
parse
(
ast
::
Program
*
program
,
StructMap
&
structs
)
{
auto
input
=
program
->
c_definitions
;
...
...
@@ -145,18 +159,34 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
struct
utsname
utsname
;
uname
(
&
utsname
);
std
::
string
kernel_header_include_flag
=
std
::
string
(
"/lib/modules/"
)
+
utsname
.
release
+
"/build/include"
;
std
::
string
kernel_modules_dir
=
std
::
string
(
"/lib/modules/"
)
+
utsname
.
release
;
auto
kpath_info
=
get_kernel_path_info
(
kernel_modules_dir
);
auto
kpath
=
kernel_modules_dir
+
"/"
+
kpath_info
.
second
;
bool
has_kpath_source
=
kpath_info
.
first
;
CXIndex
index
=
clang_createIndex
(
1
,
1
);
CXTranslationUnit
translation_unit
;
const
char
*
const
args
[]
=
{
ebpf
::
DirStack
dstack
(
kpath
);
if
(
!
dstack
.
ok
())
return
;
ebpf
::
KBuildHelper
kbuild_helper
(
kpath
,
has_kpath_source
);
std
::
vector
<
std
::
string
>
kflags
;
kbuild_helper
.
get_flags
(
utsname
.
machine
,
&
kflags
);
std
::
vector
<
const
char
*>
args
=
{
"-I"
,
"/bpftrace/include"
,
"-I"
,
kernel_header_include_flag
.
c_str
(),
};
for
(
auto
&
flag
:
kflags
)
{
args
.
push_back
(
flag
.
c_str
());
}
CXIndex
index
=
clang_createIndex
(
1
,
1
);
CXTranslationUnit
translation_unit
;
CXErrorCode
error
=
clang_parseTranslationUnit2
(
index
,
"definitions.h"
,
args
,
sizeof
(
args
)
/
sizeof
(
char
*
),
&
args
[
0
],
args
.
size
(
),
unsaved_files
,
sizeof
(
unsaved_files
)
/
sizeof
(
CXUnsavedFile
),
CXTranslationUnit_None
,
&
translation_unit
);
...
...
tests/CMakeLists.txt
View file @
269c7388
...
...
@@ -31,6 +31,7 @@ target_include_directories(bpftrace_test PUBLIC ${source_dir}/src/cc)
target_link_libraries
(
bpftrace_test
${
binary_dir
}
/src/cc/libbpf.a
)
target_link_libraries
(
bpftrace_test
${
binary_dir
}
/src/cc/libbcc-loader-static.a
)
target_link_libraries
(
bpftrace_test
${
binary_dir
}
/src/cc/libbcc.a
)
target_link_libraries
(
bpftrace_test
${
binary_dir
}
/src/cc/frontends/clang/libclang_frontend.a
)
target_link_libraries
(
bpftrace_test
${
LIBELF_LIBRARIES
}
)
find_package
(
Threads REQUIRED
)
...
...
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