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
36d75e06
Commit
36d75e06
authored
Apr 21, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sym and usym builtins
parent
8bae57b9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
9 deletions
+38
-9
README.md
README.md
+7
-5
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+4
-0
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+10
-4
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+17
-0
No files found.
README.md
View file @
36d75e06
...
...
@@ -194,8 +194,10 @@ Variables:
-
`func`
- Name of the function currently being traced
Functions:
-
`quantize(int n)`
- produce a log2 histogram of values of
`n`
-
`count()`
- count the number of times this function is called
-
`delete()`
- delete the map element this is assigned to
-
`str(char *s)`
- returns the string pointed to by
`s`
-
`printf(char *fmt, ...)`
- write to stdout
-
`quantize(int n)`
- Produce a log2 histogram of values of
`n`
-
`count()`
- Count the number of times this function is called
-
`delete()`
- Delete the map element this is assigned to
-
`str(char *s)`
- Returns the string pointed to by
`s`
-
`printf(char *fmt, ...)`
- Write to stdout
-
`sym(void *p)`
- Resolve kernel address
-
`usym(void *p)`
- Resolve user space address (incomplete)
src/ast/codegen_llvm.cpp
View file @
36d75e06
...
...
@@ -160,6 +160,10 @@ void CodegenLLVM::visit(Call &call)
b_
.
CreateProbeReadStr
(
buf
,
call
.
type
.
size
,
expr_
);
expr_
=
buf
;
}
else
if
(
call
.
func
==
"sym"
||
call
.
func
==
"usym"
)
{
call
.
vargs
->
front
()
->
accept
(
*
this
);
}
else
if
(
call
.
func
==
"printf"
)
{
ArrayType
*
string_type
=
ArrayType
::
get
(
b_
.
getInt8Ty
(),
STRING_SIZE
);
...
...
src/ast/semantic_analyser.cpp
View file @
36d75e06
...
...
@@ -119,16 +119,22 @@ void SemanticAnalyser::visit(Call &call)
}
call
.
type
=
SizedType
(
Type
::
del
,
0
);
}
else
if
(
call
.
func
==
"str"
)
{
else
if
(
call
.
func
==
"str"
||
call
.
func
==
"sym"
||
call
.
func
==
"usym"
)
{
if
(
nargs
!=
1
)
{
err_
<<
"str
() should take 1 arguments ("
;
err_
<<
call
.
func
<<
"
() should take 1 arguments ("
;
err_
<<
nargs
<<
" provided)"
<<
std
::
endl
;
}
if
(
is_final_pass
()
&&
call
.
vargs
->
at
(
0
)
->
type
.
type
!=
Type
::
integer
)
{
err_
<<
"str
() only supports integer arguments"
;
err_
<<
call
.
func
<<
"
() only supports integer arguments"
;
err_
<<
" ("
<<
call
.
vargs
->
at
(
0
)
->
type
.
type
<<
" provided)"
<<
std
::
endl
;
}
call
.
type
=
SizedType
(
Type
::
string
,
STRING_SIZE
);
if
(
call
.
func
==
"str"
)
call
.
type
=
SizedType
(
Type
::
string
,
STRING_SIZE
);
else
if
(
call
.
func
==
"sym"
)
call
.
type
=
SizedType
(
Type
::
sym
,
8
);
else
if
(
call
.
func
==
"usym"
)
call
.
type
=
SizedType
(
Type
::
usym
,
8
);
}
else
if
(
call
.
func
==
"printf"
)
{
if
(
call
.
map
)
{
...
...
tests/semantic_analyser.cpp
View file @
36d75e06
...
...
@@ -101,6 +101,23 @@ TEST(semantic_analyser, call_str)
test
(
"kprobe:f { str(arg0); }"
,
0
);
test
(
"kprobe:f { @x = str(arg0); }"
,
0
);
test
(
"kprobe:f { str(); }"
,
1
);
test
(
"kprobe:f { str(
\"
hello
\"
); }"
,
10
);
}
TEST
(
semantic_analyser
,
call_sym
)
{
test
(
"kprobe:f { sym(arg0); }"
,
0
);
test
(
"kprobe:f { @x = sym(arg0); }"
,
0
);
test
(
"kprobe:f { sym(); }"
,
1
);
test
(
"kprobe:f { sym(
\"
hello
\"
); }"
,
10
);
}
TEST
(
semantic_analyser
,
call_usym
)
{
test
(
"kprobe:f { usym(arg0); }"
,
0
);
test
(
"kprobe:f { @x = usym(arg0); }"
,
0
);
test
(
"kprobe:f { usym(); }"
,
1
);
test
(
"kprobe:f { usym(
\"
hello
\"
); }"
,
10
);
}
TEST
(
semantic_analyser
,
map_reassignment
)
...
...
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