Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
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
bcc
Commits
7575c64d
Commit
7575c64d
authored
May 05, 2016
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #530 from iovisor/bblanco_dev
Add check for number of arguments
parents
86b819a3
bc94d4c1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
7 deletions
+35
-7
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+19
-1
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+1
-1
tests/python/test_clang.py
tests/python/test_clang.py
+10
-0
tests/python/test_stackid.py
tests/python/test_stackid.py
+1
-1
tools/argdist.py
tools/argdist.py
+2
-2
tools/tplist.py
tools/tplist.py
+2
-2
No files found.
src/cc/frontends/clang/b_frontend_action.cc
View file @
7575c64d
...
...
@@ -32,6 +32,7 @@
namespace
ebpf
{
constexpr
int
MAX_CALLING_CONV_REGS
=
6
;
const
char
*
calling_conv_regs_x86
[]
=
{
"di"
,
"si"
,
"dx"
,
"cx"
,
"r8"
,
"r9"
};
...
...
@@ -255,6 +256,11 @@ bool BTypeVisitor::VisitFunctionDecl(FunctionDecl *D) {
if
(
D
->
isExternallyVisible
()
&&
D
->
hasBody
())
{
string
attr
=
string
(
"__attribute__((section(
\"
"
)
+
BPF_FN_PREFIX
+
D
->
getName
().
str
()
+
"
\"
)))
\n
"
;
rewriter_
.
InsertText
(
D
->
getLocStart
(),
attr
);
if
(
D
->
param_size
()
>
MAX_CALLING_CONV_REGS
+
1
)
{
error
(
D
->
getParamDecl
(
MAX_CALLING_CONV_REGS
+
1
)
->
getLocStart
(),
"too many arguments, bcc only supports in-register parameters"
);
return
false
;
}
// remember the arg names of the current function...first one is the ctx
fn_args_
.
clear
();
string
preamble
=
"{"
;
...
...
@@ -265,12 +271,24 @@ bool BTypeVisitor::VisitFunctionDecl(FunctionDecl *D) {
}
fn_args_
.
push_back
(
arg
);
if
(
fn_args_
.
size
()
>
1
)
{
// Move the args into a preamble section where the same params are
// declared and initialized from pt_regs.
// Todo: this init should be done only when the program requests it.
string
text
=
rewriter_
.
getRewrittenText
(
SourceRange
(
arg
->
getLocStart
(),
arg
->
getLocEnd
()));
arg
->
addAttr
(
UnavailableAttr
::
CreateImplicit
(
C
,
"ptregs"
));
size_t
d
=
fn_args_
.
size
()
-
2
;
const
char
*
reg
=
calling_conv_regs
[
d
];
preamble
+=
arg
->
getName
().
str
()
+
" = "
+
fn_args_
[
0
]
->
getName
().
str
()
+
"->"
+
string
(
reg
)
+
";"
;
preamble
+=
" "
+
text
+
" = "
+
fn_args_
[
0
]
->
getName
().
str
()
+
"->"
+
string
(
reg
)
+
";"
;
}
}
if
(
D
->
param_size
()
>
1
)
{
rewriter_
.
ReplaceText
(
SourceRange
(
D
->
getParamDecl
(
0
)
->
getLocEnd
(),
D
->
getParamDecl
(
D
->
getNumParams
()
-
1
)
->
getLocEnd
()),
fn_args_
[
0
]
->
getName
());
}
// for each trace argument, convert the variable from ptregs to something on stack
if
(
CompoundStmt
*
S
=
dyn_cast
<
CompoundStmt
>
(
D
->
getBody
()))
rewriter_
.
ReplaceText
(
S
->
getLBracLoc
(),
1
,
preamble
);
...
...
src/python/bcc/__init__.py
View file @
7575c64d
...
...
@@ -446,7 +446,7 @@ class BPF(object):
@
staticmethod
def
find_library
(
libname
):
return
lib
.
bcc_procutils_which_so
(
libname
)
return
lib
.
bcc_procutils_which_so
(
libname
.
encode
(
"ascii"
)).
decode
(
)
def
attach_uprobe
(
self
,
name
=
""
,
sym
=
""
,
addr
=
None
,
fn_name
=
""
,
pid
=-
1
,
cpu
=
0
,
group_fd
=-
1
):
...
...
tests/python/test_clang.py
View file @
7575c64d
...
...
@@ -328,5 +328,15 @@ BPF_TABLE("hash", struct bpf_tunnel_key, int, t1, 1);
t1
=
b
[
"t1"
]
print
(
t1
.
Key
().
remote_ipv4
)
def
test_too_many_args
(
self
):
text
=
"""
#include <uapi/linux/ptrace.h>
int many(struct pt_regs *ctx, int a, int b, int c, int d, int e, int f, int g) {
return 0;
}
"""
with
self
.
assertRaises
(
Exception
):
b
=
BPF
(
text
=
text
)
if
__name__
==
"__main__"
:
main
()
tests/python/test_stackid.py
View file @
7575c64d
...
...
@@ -47,7 +47,7 @@ int kprobe__htab_map_lookup_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
stackid
=
stack_entries
[
k
]
self
.
assertIsNotNone
(
stackid
)
stack
=
stack_traces
[
stackid
].
ip
self
.
assertEqual
(
b
.
ksym
(
stack
[
0
]),
b
"htab_map_lookup_elem"
)
self
.
assertEqual
(
b
.
ksym
(
stack
[
0
]),
"htab_map_lookup_elem"
)
if
__name__
==
"__main__"
:
...
...
tools/argdist.py
View file @
7575c64d
...
...
@@ -673,8 +673,8 @@ struct __string_t { char s[%d]; };
except
:
if
self
.
args
.
verbose
:
traceback
.
print_exc
()
elif
sys
.
exc_
type
is
not
SystemExit
:
print
(
sys
.
exc_
value
)
elif
sys
.
exc_
info
()[
0
]
is
not
SystemExit
:
print
(
sys
.
exc_
info
()[
1
]
)
self
.
_close_probes
()
if
__name__
==
"__main__"
:
...
...
tools/tplist.py
View file @
7575c64d
...
...
@@ -86,6 +86,6 @@ if __name__ == "__main__":
else
:
print_tracepoints
()
except
:
if
sys
.
exc_
type
is
not
SystemExit
:
print
(
sys
.
exc_
value
)
if
sys
.
exc_
info
()[
0
]
is
not
SystemExit
:
print
(
sys
.
exc_
info
()[
1
]
)
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