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
0108702b
Commit
0108702b
authored
Sep 10, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes:
https://github.com/iovisor/bpftrace/issues/4
parent
84030219
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
4 deletions
+45
-4
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+8
-1
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+1
-1
src/bpftrace.cpp
src/bpftrace.cpp
+33
-2
src/bpftrace.h
src/bpftrace.h
+3
-0
No files found.
src/ast/codegen_llvm.cpp
View file @
0108702b
...
...
@@ -303,13 +303,20 @@ void CodegenLLVM::visit(Call &call)
b_
.
CreateProbeReadStr
(
buf
,
call
.
type
.
size
,
expr_
);
expr_
=
buf
;
}
else
if
(
call
.
func
==
"kaddr"
)
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
==
"uaddr"
)
{
uint64_t
addr
;
auto
&
name
=
static_cast
<
String
&>
(
*
call
.
vargs
->
at
(
0
)).
str
;
addr
=
bpftrace_
.
resolve_uname
(
name
.
c_str
());
expr_
=
b_
.
getInt64
(
addr
);
}
else
if
(
call
.
func
==
"join"
)
{
call
.
vargs
->
front
()
->
accept
(
*
this
);
...
...
src/ast/semantic_analyser.cpp
View file @
0108702b
...
...
@@ -209,7 +209,7 @@ void SemanticAnalyser::visit(Call &call)
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"kaddr"
)
{
else
if
(
call
.
func
==
"kaddr"
||
call
.
func
==
"uaddr"
)
{
if
(
check_nargs
(
call
,
1
))
{
if
(
check_arg
(
call
,
Type
::
string
,
0
,
true
))
{
;
...
...
src/bpftrace.cpp
View file @
0108702b
...
...
@@ -1145,8 +1145,7 @@ uint64_t BPFtrace::resolve_kname(const char *name)
if
(
found
)
{
std
::
string
first_word
=
line
.
substr
(
0
,
line
.
find
(
" "
));
addr
=
std
::
stoull
(
first_word
,
0
,
16
);
addr
=
read_address_from_output
(
line
);
}
}
...
...
@@ -1155,6 +1154,38 @@ uint64_t BPFtrace::resolve_kname(const char *name)
return
addr
;
}
uint64_t
BPFtrace
::
resolve_uname
(
const
char
*
name
)
{
uint64_t
addr
=
0
;
std
::
string
call_str
=
"objdump -tT /bin/bash | grep "
;
call_str
+=
name
;
const
char
*
call
=
call_str
.
c_str
();
auto
result
=
exec_system
(
call
);
addr
=
read_address_from_output
(
result
);
return
addr
;
}
std
::
string
BPFtrace
::
exec_system
(
const
char
*
cmd
)
{
std
::
array
<
char
,
128
>
buffer
;
std
::
string
result
;
std
::
shared_ptr
<
FILE
>
pipe
(
popen
(
cmd
,
"r"
),
pclose
);
if
(
!
pipe
)
throw
std
::
runtime_error
(
"popen() failed!"
);
while
(
!
feof
(
pipe
.
get
()))
{
if
(
fgets
(
buffer
.
data
(),
128
,
pipe
.
get
())
!=
nullptr
)
result
+=
buffer
.
data
();
}
return
result
;
}
uint64_t
BPFtrace
::
read_address_from_output
(
std
::
string
output
)
{
std
::
string
first_word
=
output
.
substr
(
0
,
output
.
find
(
" "
));
return
std
::
stoull
(
first_word
,
0
,
16
);
}
std
::
string
BPFtrace
::
resolve_usym
(
uintptr_t
addr
,
int
pid
,
bool
show_offset
)
{
struct
bcc_symbol
sym
;
...
...
src/bpftrace.h
View file @
0108702b
...
...
@@ -38,6 +38,7 @@ public:
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
);
uint64_t
resolve_uname
(
const
char
*
name
);
std
::
string
resolve_name
(
uint64_t
name_id
);
int
pid_
;
...
...
@@ -82,6 +83,8 @@ private:
static
uint64_t
reduce_value
(
const
std
::
vector
<
uint8_t
>
&
value
,
int
ncpus
);
static
uint64_t
min_value
(
const
std
::
vector
<
uint8_t
>
&
value
,
int
ncpus
);
static
uint64_t
max_value
(
const
std
::
vector
<
uint8_t
>
&
value
,
int
ncpus
);
static
uint64_t
read_address_from_output
(
std
::
string
output
);
static
std
::
string
exec_system
(
const
char
*
cmd
);
static
std
::
string
hist_index_label
(
int
power
);
static
std
::
string
lhist_index_label
(
int
number
);
std
::
vector
<
uint8_t
>
find_empty_key
(
IMap
&
map
,
size_t
size
)
const
;
...
...
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