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
46f2cb22
Commit
46f2cb22
authored
Sep 11, 2018
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow uaddr() to work on non-bash
parent
217d6017
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
10 deletions
+17
-10
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+8
-1
src/ast/codegen_llvm.h
src/ast/codegen_llvm.h
+1
-0
src/bpftrace.cpp
src/bpftrace.cpp
+7
-8
src/bpftrace.h
src/bpftrace.h
+1
-1
No files found.
src/ast/codegen_llvm.cpp
View file @
46f2cb22
...
...
@@ -314,7 +314,7 @@ void CodegenLLVM::visit(Call &call)
{
uint64_t
addr
;
auto
&
name
=
static_cast
<
String
&>
(
*
call
.
vargs
->
at
(
0
)).
str
;
addr
=
bpftrace_
.
resolve_uname
(
name
.
c_str
());
addr
=
bpftrace_
.
resolve_uname
(
name
.
c_str
()
,
path_
.
c_str
()
);
expr_
=
b_
.
getInt64
(
addr
);
}
else
if
(
call
.
func
==
"join"
)
...
...
@@ -864,6 +864,13 @@ void CodegenLLVM::visit(Probe &probe)
{
b_
.
getInt8PtrTy
()},
// struct pt_regs *ctx
false
);
// needed for uaddr() call:
for
(
auto
&
attach_point
:
*
probe
.
attach_points
)
{
path_
=
attach_point
->
target
;
// TODO: semantic analyser should ensure targets are equal when uaddr() is used
break
;
}
/*
* Most of the time, we can take a probe like kprobe:do_f* and build a
* single BPF program for that, called "s_kprobe:do_f*", and attach it to
...
...
src/ast/codegen_llvm.h
View file @
46f2cb22
...
...
@@ -66,6 +66,7 @@ private:
Value
*
ctx_
;
BPFtrace
&
bpftrace_
;
std
::
string
probefull_
;
std
::
string
path_
;
std
::
map
<
std
::
string
,
Value
*>
variables_
;
int
printf_id_
=
0
;
...
...
src/bpftrace.cpp
View file @
46f2cb22
...
...
@@ -1154,13 +1154,12 @@ uint64_t BPFtrace::resolve_kname(const char *name)
return
addr
;
}
uint64_t
BPFtrace
::
resolve_uname
(
const
char
*
name
)
uint64_t
BPFtrace
::
resolve_uname
(
const
char
*
name
,
const
char
*
path
)
{
uint64_t
addr
=
0
;
// TODO: switch from objdump to library call
std
::
string
call_str
=
"objdump -tT /bin/bash | grep "
;
call_str
+=
name
;
// TODO: switch from objdump to library call, perhaps bcc_resolve_symname()
std
::
string
call_str
=
std
::
string
(
"objdump -tT "
)
+
path
+
" | grep -w "
+
name
;
const
char
*
call
=
call_str
.
c_str
();
auto
result
=
exec_system
(
call
);
addr
=
read_address_from_output
(
result
);
...
...
@@ -1170,14 +1169,14 @@ uint64_t BPFtrace::resolve_uname(const char *name)
std
::
string
BPFtrace
::
exec_system
(
const
char
*
cmd
)
{
std
::
array
<
char
,
128
>
buffer
;
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
();
}
if
(
fgets
(
buffer
.
data
(),
128
,
pipe
.
get
())
!=
nullptr
)
result
+=
buffer
.
data
();
}
return
result
;
}
...
...
src/bpftrace.h
View file @
46f2cb22
...
...
@@ -38,7 +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
);
uint64_t
resolve_uname
(
const
char
*
name
,
const
char
*
path
);
std
::
string
resolve_name
(
uint64_t
name_id
);
int
pid_
;
...
...
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