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
a4aa9518
Commit
a4aa9518
authored
Sep 13, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes:
https://github.com/iovisor/bpftrace/issues/6
parent
0b79d156
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
4 deletions
+61
-4
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+2
-2
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+3
-0
src/bpftrace.cpp
src/bpftrace.cpp
+51
-0
src/bpftrace.h
src/bpftrace.h
+2
-0
src/lexer.l
src/lexer.l
+1
-1
src/printf.cpp
src/printf.cpp
+1
-1
src/types.h
src/types.h
+1
-0
No files found.
src/ast/codegen_llvm.cpp
View file @
a4aa9518
...
...
@@ -54,10 +54,10 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_
=
b_
.
CreateAnd
(
pidtgid
,
0xffffffff
);
}
}
else
if
(
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
)
else
if
(
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"username"
)
{
Value
*
uidgid
=
b_
.
CreateGetUidGid
();
if
(
builtin
.
ident
==
"uid"
)
if
(
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"username"
)
{
expr_
=
b_
.
CreateAnd
(
uidgid
,
0xffffffff
);
}
...
...
src/ast/semantic_analyser.cpp
View file @
a4aa9518
...
...
@@ -76,6 +76,9 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin
.
type
=
SizedType
(
Type
::
name
,
8
);
probe_
->
need_expansion
=
true
;
}
else
if
(
builtin
.
ident
==
"username"
)
{
builtin
.
type
=
SizedType
(
Type
::
username
,
8
);
}
else
{
builtin
.
type
=
SizedType
(
Type
::
none
,
0
);
err_
<<
"Unknown builtin variable: '"
<<
builtin
.
ident
<<
"'"
<<
std
::
endl
;
...
...
src/bpftrace.cpp
View file @
a4aa9518
...
...
@@ -206,6 +206,8 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
auto
args
=
std
::
get
<
1
>
(
bpftrace
->
printf_args_
[
printf_id
]);
std
::
vector
<
uint64_t
>
arg_values
;
std
::
vector
<
std
::
unique_ptr
<
char
>>
resolved_symbols
;
std
::
vector
<
std
::
unique_ptr
<
char
>>
resolved_usernames
;
char
*
name
;
for
(
auto
arg
:
args
)
{
...
...
@@ -243,6 +245,11 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
bpftrace
->
resolve_usym
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
),
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
+
8
)).
c_str
()));
arg_values
.
push_back
((
uint64_t
)
resolved_symbols
.
back
().
get
());
break
;
case
Type
:
:
username
:
resolved_usernames
.
emplace_back
(
strdup
(
bpftrace
->
resolve_uid
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
)).
c_str
()));
arg_values
.
push_back
((
uint64_t
)
resolved_usernames
.
back
().
get
());
break
;
case
Type
:
:
name
:
name
=
strdup
(
bpftrace
->
resolve_name
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
)).
c_str
());
arg_values
.
push_back
((
uint64_t
)
name
);
...
...
@@ -654,6 +661,8 @@ int BPFtrace::print_map(IMap &map, uint32_t top, uint32_t div)
std
::
cout
<<
resolve_sym
(
*
(
uintptr_t
*
)
value
.
data
());
else
if
(
map
.
type_
.
type
==
Type
::
usym
)
std
::
cout
<<
resolve_usym
(
*
(
uintptr_t
*
)
value
.
data
(),
*
(
uint64_t
*
)(
value
.
data
()
+
8
));
else
if
(
map
.
type_
.
type
==
Type
::
username
)
std
::
cout
<<
resolve_uid
(
*
(
uint64_t
*
)(
value
.
data
()))
<<
std
::
endl
;
else
if
(
map
.
type_
.
type
==
Type
::
string
)
std
::
cout
<<
value
.
data
()
<<
std
::
endl
;
else
if
(
map
.
type_
.
type
==
Type
::
count
||
map
.
type_
.
type
==
Type
::
sum
)
...
...
@@ -1101,6 +1110,48 @@ std::string BPFtrace::get_stack(uint64_t stackidpid, bool ustack, int indent)
return
stack
.
str
();
}
std
::
string
BPFtrace
::
resolve_uid
(
uintptr_t
addr
)
{
std
::
string
file_name
=
"/etc/passwd"
;
std
::
string
uid
=
std
::
to_string
(
addr
);
std
::
string
username
=
""
;
std
::
ifstream
file
(
file_name
);
if
(
file
.
fail
())
{
std
::
cerr
<<
strerror
(
errno
)
<<
": "
<<
file_name
<<
std
::
endl
;
return
username
;
}
std
::
string
line
;
bool
found
=
false
;
while
(
std
::
getline
(
file
,
line
)
&&
!
found
)
{
auto
fields
=
split_string
(
line
,
':'
);
if
(
fields
[
2
]
==
uid
)
{
found
=
true
;
username
=
fields
[
0
];
}
}
file
.
close
();
return
username
;
}
std
::
vector
<
std
::
string
>
BPFtrace
::
split_string
(
std
::
string
&
str
,
char
split_by
)
{
std
::
vector
<
std
::
string
>
elems
;
std
::
stringstream
ss
(
str
);
std
::
string
value
;
while
(
std
::
getline
(
ss
,
value
,
split_by
))
{
elems
.
push_back
(
value
);
}
return
elems
;
}
std
::
string
BPFtrace
::
resolve_sym
(
uintptr_t
addr
,
bool
show_offset
)
{
struct
bcc_symbol
sym
;
...
...
src/bpftrace.h
View file @
a4aa9518
...
...
@@ -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
);
std
::
string
resolve_uid
(
uintptr_t
addr
);
uint64_t
resolve_kname
(
const
char
*
name
);
uint64_t
resolve_uname
(
const
char
*
name
,
const
char
*
path
);
std
::
string
resolve_name
(
uint64_t
name_id
);
...
...
@@ -87,6 +88,7 @@ private:
static
std
::
string
exec_system
(
const
char
*
cmd
);
static
std
::
string
hist_index_label
(
int
power
);
static
std
::
string
lhist_index_label
(
int
number
);
static
std
::
vector
<
std
::
string
>
split_string
(
std
::
string
&
str
,
char
split_by
);
std
::
vector
<
uint8_t
>
find_empty_key
(
IMap
&
map
,
size_t
size
)
const
;
};
...
...
src/lexer.l
View file @
a4aa9518
...
...
@@ -46,7 +46,7 @@ path :(\\.|[_\-\./a-zA-Z0-9])*:
<COMMENT>"EOF" driver.error(loc, std::string("end of file during comment"));
<COMMENT>.|"\n" ;
pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name|curtask|rand|ctx {
pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name|curtask|rand|ctx
|username
{
return Parser::make_BUILTIN(yytext, loc); }
{path} { return Parser::make_PATH(yytext, loc); }
{map} { return Parser::make_MAP(yytext, loc); }
...
...
src/printf.cpp
View file @
a4aa9518
...
...
@@ -33,7 +33,7 @@ std::string verify_format_string(const std::string &fmt, std::vector<Field> args
for
(
int
i
=
0
;
i
<
num_args
;
i
++
,
token_iter
++
)
{
Type
arg_type
=
args
.
at
(
i
).
type
.
type
;
if
(
arg_type
==
Type
::
sym
||
arg_type
==
Type
::
usym
||
arg_type
==
Type
::
name
)
if
(
arg_type
==
Type
::
sym
||
arg_type
==
Type
::
usym
||
arg_type
==
Type
::
name
||
arg_type
==
Type
::
username
)
arg_type
=
Type
::
string
;
// Symbols should be printed as strings
int
offset
=
1
;
...
...
src/types.h
View file @
a4aa9518
...
...
@@ -32,6 +32,7 @@ enum class Type
cast
,
join
,
name
,
username
,
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Type
type
);
...
...
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