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
e6b0ebf6
Commit
e6b0ebf6
authored
Sep 07, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes:
https://github.com/iovisor/bpftrace/issues/3
parent
9196c222
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
0 deletions
+87
-0
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+7
-0
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+8
-0
src/bpftrace.cpp
src/bpftrace.cpp
+35
-0
src/bpftrace.h
src/bpftrace.h
+1
-0
tests/codegen.cpp
tests/codegen.cpp
+17
-0
tests/parser.cpp
tests/parser.cpp
+11
-0
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+8
-0
No files found.
src/ast/codegen_llvm.cpp
View file @
e6b0ebf6
...
...
@@ -302,6 +302,13 @@ void CodegenLLVM::visit(Call &call)
call
.
vargs
->
front
()
->
accept
(
*
this
);
b_
.
CreateProbeReadStr
(
buf
,
call
.
type
.
size
,
expr_
);
expr_
=
buf
;
}
else
if
(
call
.
func
==
"kaddr"
)
{
uint64_t
addr
;
auto
&
name
=
static_cast
<
String
&>
(
*
call
.
vargs
->
at
(
0
)).
str
;
addr
=
bpftrace_
.
resolve_kname
(
name
.
c_str
());
expr_
=
b_
.
getInt64
(
addr
);
}
else
if
(
call
.
func
==
"join"
)
{
...
...
src/ast/semantic_analyser.cpp
View file @
e6b0ebf6
...
...
@@ -209,6 +209,14 @@ void SemanticAnalyser::visit(Call &call)
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"kaddr"
)
{
if
(
check_nargs
(
call
,
1
))
{
if
(
check_arg
(
call
,
Type
::
string
,
0
,
true
))
{
;
}
}
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"printf"
)
{
check_assignment
(
call
,
false
,
false
);
if
(
check_varargs
(
call
,
1
,
7
))
{
...
...
src/bpftrace.cpp
View file @
e6b0ebf6
...
...
@@ -1117,6 +1117,41 @@ std::string BPFtrace::resolve_sym(uintptr_t addr, bool show_offset)
return
symbol
.
str
();
}
uint64_t
BPFtrace
::
resolve_kname
(
const
char
*
name
)
{
uint64_t
addr
=
0
;
std
::
string
file_name
=
"/proc/kallsyms"
;
std
::
ifstream
file
(
file_name
);
if
(
file
.
fail
())
{
std
::
cerr
<<
strerror
(
errno
)
<<
": "
<<
file_name
<<
std
::
endl
;
return
addr
;
}
std
::
string
line
;
std
::
string
search
=
"
\\
b( "
;
search
+=
name
;
std
::
regex
e
(
search
+
")"
);
std
::
smatch
match
;
while
(
std
::
getline
(
file
,
line
)
&&
addr
==
0
)
{
auto
found
=
std
::
regex_search
(
line
,
match
,
e
);
if
(
found
)
{
std
::
string
first_word
=
line
.
substr
(
0
,
line
.
find
(
" "
));
addr
=
std
::
stoull
(
first_word
,
0
,
16
);
}
}
file
.
close
();
return
addr
;
}
std
::
string
BPFtrace
::
resolve_usym
(
uintptr_t
addr
,
int
pid
,
bool
show_offset
)
{
struct
bcc_symbol
sym
;
...
...
src/bpftrace.h
View file @
e6b0ebf6
...
...
@@ -37,6 +37,7 @@ public:
std
::
string
get_stack
(
uint64_t
stackidpid
,
bool
ustack
,
int
indent
=
0
);
std
::
string
resolve_sym
(
uintptr_t
addr
,
bool
show_offset
=
false
);
std
::
string
resolve_usym
(
uintptr_t
addr
,
int
pid
,
bool
show_offset
=
false
);
uint64_t
resolve_kname
(
const
char
*
name
);
std
::
string
resolve_name
(
uint64_t
name_id
);
int
pid_
;
...
...
tests/codegen.cpp
View file @
e6b0ebf6
...
...
@@ -1024,6 +1024,23 @@ attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
}
TEST
(
codegen
,
call_kaddr
)
{
test
(
"kprobe:f { @x = kaddr(
\"
avenrun
\"
) }"
,
R"EXPECTED(; Function Attrs: nounwind
declare i64 @llvm.bpf.pseudo(i64, i64) #0
BDG run bpftrace_test, and copy-n-paste the '+' diff output here until bpftrace_test passes this test
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
attributes #0 = { nounwind }
attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
}
TEST
(
codegen
,
call_hist
)
{
test
(
"kprobe:f { @x = hist(pid) }"
,
...
...
tests/parser.cpp
View file @
e6b0ebf6
...
...
@@ -299,6 +299,17 @@ TEST(Parser, call_unknown_function)
" call: myfunc
\n
"
);
}
TEST
(
Parser
,
call_kaddr
)
{
test
(
"kprobe:f { @ = kaddr(
\"
avenrun
\"
) }"
,
"Program
\n
"
" kprobe:f
\n
"
" =
\n
"
" map: @
\n
"
" call: kaddr
\n
"
" string: avenrun
\n
"
);
}
TEST
(
Parser
,
multiple_probes
)
{
test
(
"kprobe:sys_open { 1; } kretprobe:sys_open { 2; }"
,
...
...
tests/semantic_analyser.cpp
View file @
e6b0ebf6
...
...
@@ -253,6 +253,14 @@ TEST(semantic_analyser, call_usym)
test
(
"kprobe:f { usym(
\"
hello
\"
); }"
,
10
);
}
TEST
(
semantic_analyser
,
call_kaddr
)
{
test
(
"kprobe:f { kaddr(
\"
avenrun
\"
); }"
,
0
);
test
(
"kprobe:f { @x = kaddr(
\"
avenrun
\"
); }"
,
0
);
test
(
"kprobe:f { kaddr(); }"
,
1
);
test
(
"kprobe:f { kaddr(123); }"
,
1
);
}
TEST
(
semantic_analyser
,
call_reg
)
{
test
(
"kprobe:f { reg(
\"
ip
\"
); }"
,
0
);
...
...
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