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
e9e699f8
Commit
e9e699f8
authored
Jan 25, 2019
by
Brendan Gregg
Committed by
GitHub
Jan 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #379 from iovisor/abort_messages
all abort()s should print an error message
parents
2b83b671
5c2ca5b9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
89 additions
and
14 deletions
+89
-14
src/ast/ast.cpp
src/ast/ast.cpp
+7
-2
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+19
-5
src/ast/irbuilderbpf.cpp
src/ast/irbuilderbpf.cpp
+1
-0
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+8
-0
src/attached_probe.cpp
src/attached_probe.cpp
+15
-3
src/bpftrace.cpp
src/bpftrace.cpp
+8
-0
src/map.cpp
src/map.cpp
+2
-0
src/mapkey.cpp
src/mapkey.cpp
+1
-0
src/types.cpp
src/types.cpp
+27
-4
src/types.h
src/types.h
+1
-0
No files found.
src/ast/ast.cpp
View file @
e9e699f8
#include "ast.h"
#include "parser.tab.hh"
#include <iostream>
namespace
bpftrace
{
namespace
ast
{
...
...
@@ -109,7 +110,9 @@ std::string opstr(Binop &binop)
case
bpftrace
:
:
Parser
::
token
::
BAND
:
return
"&"
;
case
bpftrace
:
:
Parser
::
token
::
BOR
:
return
"|"
;
case
bpftrace
:
:
Parser
::
token
::
BXOR
:
return
"^"
;
default:
abort
();
default:
std
::
cerr
<<
"unknown binary operator"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -120,7 +123,9 @@ std::string opstr(Unop &unop)
case
bpftrace
:
:
Parser
::
token
::
BNOT
:
return
"~"
;
case
bpftrace
:
:
Parser
::
token
::
MINUS
:
return
"-"
;
case
bpftrace
:
:
Parser
::
token
::
MUL
:
return
"dereference"
;
default:
abort
();
default:
std
::
cerr
<<
"unknown union operator"
<<
std
::
endl
;
abort
();
}
}
...
...
src/ast/codegen_llvm.cpp
View file @
e9e699f8
...
...
@@ -158,6 +158,7 @@ void CodegenLLVM::visit(Builtin &builtin)
}
else
{
std
::
cerr
<<
"unknown builtin
\"
"
<<
builtin
.
ident
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -462,7 +463,10 @@ void CodegenLLVM::visit(Call &call)
auto
&
reg_name
=
static_cast
<
String
&>
(
*
call
.
vargs
->
at
(
0
)).
str
;
int
offset
=
arch
::
offset
(
reg_name
);
if
(
offset
==
-
1
)
{
std
::
cerr
<<
"negative offset on reg() call"
<<
std
::
endl
;
abort
();
}
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
call
.
type
,
call
.
func
+
"_"
+
reg_name
);
Value
*
src
=
b_
.
CreateGEP
(
ctx_
,
b_
.
getInt64
(
offset
*
sizeof
(
uintptr_t
)));
...
...
@@ -677,7 +681,7 @@ void CodegenLLVM::visit(Call &call)
else
{
std
::
cerr
<<
"
Error:
missing codegen for function
\"
"
<<
call
.
func
<<
"
\"
"
<<
std
::
endl
;
std
::
cerr
<<
"missing codegen for function
\"
"
<<
call
.
func
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -738,6 +742,7 @@ void CodegenLLVM::visit(Binop &binop)
expr_
=
b_
.
CreateStrcmp
(
val
,
string_literal
,
true
);
break
;
default:
std
::
cerr
<<
"missing codegen to string operator
\"
"
<<
opstr
(
binop
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
b_
.
CreateLifetimeEnd
(
val
);
...
...
@@ -771,9 +776,15 @@ void CodegenLLVM::visit(Binop &binop)
case
bpftrace
:
:
Parser
::
token
::
BAND
:
expr_
=
b_
.
CreateAnd
(
lhs
,
rhs
);
break
;
case
bpftrace
:
:
Parser
::
token
::
BOR
:
expr_
=
b_
.
CreateOr
(
lhs
,
rhs
);
break
;
case
bpftrace
:
:
Parser
::
token
::
BXOR
:
expr_
=
b_
.
CreateXor
(
lhs
,
rhs
);
break
;
case
bpftrace
:
:
Parser
::
token
::
LAND
:
abort
();
// Handled earlier
case
bpftrace
:
:
Parser
::
token
::
LOR
:
abort
();
// Handled earlier
default:
abort
();
case
bpftrace
:
:
Parser
::
token
::
LAND
:
std
::
cerr
<<
"
\"
"
<<
opstr
(
binop
)
<<
"
\"
was handled earlier"
<<
std
::
endl
;
abort
();
case
bpftrace
:
:
Parser
::
token
::
LOR
:
std
::
cerr
<<
"
\"
"
<<
opstr
(
binop
)
<<
"
\"
was handled earlier"
<<
std
::
endl
;
abort
();
default:
std
::
cerr
<<
"missing codegen (LLVM) to string operator
\"
"
<<
opstr
(
binop
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
expr_
=
b_
.
CreateIntCast
(
expr_
,
b_
.
getInt64Ty
(),
false
);
...
...
@@ -804,7 +815,9 @@ void CodegenLLVM::visit(Unop &unop)
b_
.
CreateLifetimeEnd
(
dst
);
break
;
}
default:
abort
();
default:
std
::
cerr
<<
"missing codegen to union expression type"
<<
std
::
endl
;
abort
();
}
}
else
if
(
type
.
type
==
Type
::
cast
)
...
...
@@ -813,6 +826,7 @@ void CodegenLLVM::visit(Unop &unop)
}
else
{
std
::
cerr
<<
"missing codegen to union operator
\"
"
<<
opstr
(
unop
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
src/ast/irbuilderbpf.cpp
View file @
e9e699f8
...
...
@@ -123,6 +123,7 @@ llvm::Type *IRBuilderBPF::GetType(const SizedType &stype)
ty
=
getInt8Ty
();
break
;
default:
std
::
cerr
<<
stype
.
size
<<
" is not a valid type size for GetType"
<<
std
::
endl
;
abort
();
}
}
...
...
src/ast/semantic_analyser.cpp
View file @
e9e699f8
...
...
@@ -880,7 +880,11 @@ int SemanticAnalyser::create_maps(bool debug)
auto
search_args
=
map_key_
.
find
(
map_name
);
if
(
search_args
==
map_key_
.
end
())
{
std
::
cerr
<<
"map key
\"
"
<<
map_name
<<
"
\"
not found"
<<
std
::
endl
;
abort
();
}
auto
&
key
=
search_args
->
second
;
if
(
debug
)
...
...
@@ -892,7 +896,11 @@ int SemanticAnalyser::create_maps(bool debug)
// store lhist args to the bpftrace::Map
auto
map_args
=
map_args_
.
find
(
map_name
);
if
(
map_args
==
map_args_
.
end
())
{
std
::
cerr
<<
"map arg
\"
"
<<
map_name
<<
"
\"
not found"
<<
std
::
endl
;
abort
();
}
Expression
&
min_arg
=
*
map_args
->
second
.
at
(
1
);
Expression
&
max_arg
=
*
map_args
->
second
.
at
(
2
);
Expression
&
step_arg
=
*
map_args
->
second
.
at
(
3
);
...
...
src/attached_probe.cpp
View file @
e9e699f8
...
...
@@ -33,8 +33,10 @@ bpf_probe_attach_type attachtype(ProbeType t)
case
ProbeType
:
:
kretprobe
:
return
BPF_PROBE_RETURN
;
break
;
case
ProbeType
:
:
uprobe
:
return
BPF_PROBE_ENTRY
;
break
;
case
ProbeType
:
:
uretprobe
:
return
BPF_PROBE_RETURN
;
break
;
case
ProbeType
:
:
usdt
:
return
BPF_PROBE_ENTRY
;
break
;
default:
abort
();
case
ProbeType
:
:
usdt
:
return
BPF_PROBE_ENTRY
;
break
;
default:
std
::
cerr
<<
"invalid probe attachtype
\"
"
<<
probetypeName
(
t
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -52,7 +54,9 @@ bpf_prog_type progtype(ProbeType t)
case
ProbeType
:
:
interval
:
return
BPF_PROG_TYPE_PERF_EVENT
;
break
;
case
ProbeType
:
:
software
:
return
BPF_PROG_TYPE_PERF_EVENT
;
break
;
case
ProbeType
:
:
hardware
:
return
BPF_PROG_TYPE_PERF_EVENT
;
break
;
default:
abort
();
default:
std
::
cerr
<<
"program type not found"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -89,6 +93,7 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> func
attach_hardware
();
break
;
default:
std
::
cerr
<<
"invalid attached probe type
\"
"
<<
probetypeName
(
probe_
.
type
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -103,6 +108,7 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> func
attach_usdt
(
pid
);
break
;
default:
std
::
cerr
<<
"invalid attached probe type
\"
"
<<
probetypeName
(
probe_
.
type
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -141,6 +147,7 @@ AttachedProbe::~AttachedProbe()
case
ProbeType
:
:
hardware
:
break
;
default:
std
::
cerr
<<
"invalid attached probe type
\"
"
<<
probetypeName
(
probe_
.
type
)
<<
"
\"
at destructor"
<<
std
::
endl
;
abort
();
}
if
(
err
)
...
...
@@ -156,6 +163,7 @@ std::string AttachedProbe::eventprefix() const
case
BPF_PROBE_RETURN
:
return
"r_"
;
default:
std
::
cerr
<<
"invalid eventprefix"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -177,6 +185,7 @@ std::string AttachedProbe::eventname() const
case
ProbeType
:
:
tracepoint
:
return
probe_
.
attach_point
;
default:
std
::
cerr
<<
"invalid eventname probe
\"
"
<<
probetypeName
(
probe_
.
type
)
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -284,6 +293,7 @@ static unsigned kernel_version(int attempt)
return
0
;
}
std
::
cerr
<<
"invalid kernel version"
<<
std
::
endl
;
abort
();
}
...
...
@@ -472,6 +482,7 @@ void AttachedProbe::attach_profile()
}
else
{
std
::
cerr
<<
"invalid profile path
\"
"
<<
probe_
.
path
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
...
...
@@ -507,6 +518,7 @@ void AttachedProbe::attach_interval()
}
else
{
std
::
cerr
<<
"invalid interval path
\"
"
<<
probe_
.
path
<<
"
\"
"
<<
std
::
endl
;
abort
();
}
...
...
src/bpftrace.cpp
View file @
e9e699f8
...
...
@@ -307,6 +307,7 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
system
(
buffer
);
break
;
default:
std
::
cerr
<<
"printf() can only take up to 7 arguments ("
<<
args
.
size
()
<<
") provided"
<<
std
::
endl
;
abort
();
}
...
...
@@ -345,6 +346,7 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
arg_values
.
at
(
3
)
->
value
(),
arg_values
.
at
(
4
)
->
value
(),
arg_values
.
at
(
5
)
->
value
());
break
;
default:
std
::
cerr
<<
"printf() can only take up to 7 arguments ("
<<
args
.
size
()
<<
") provided"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -381,6 +383,7 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(const std::vec
*
reinterpret_cast
<
uint8_t
*>
(
arg_data
+
arg
.
offset
)));
break
;
default:
std
::
cerr
<<
"get_arg_values: invalid integer size. 8, 4, 2 and byte supported. "
<<
arg
.
type
.
size
<<
"provided"
<<
std
::
endl
;
abort
();
}
break
;
...
...
@@ -437,6 +440,7 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(const std::vec
8
)));
break
;
default:
std
::
cerr
<<
"invalid argument type"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -1680,7 +1684,11 @@ void BPFtrace::sort_by_key(std::vector<SizedType> key_args,
});
}
else
{
std
::
cerr
<<
"invalid integer argument size. 4 or 8 expected, but "
<<
arg
.
size
<<
" provided"
<<
std
::
endl
;
abort
();
}
}
else
if
(
arg
.
type
==
Type
::
string
)
{
...
...
src/map.cpp
View file @
e9e699f8
...
...
@@ -77,6 +77,7 @@ Map::Map(enum bpf_map_type map_type)
}
else
{
std
::
cerr
<<
"invalid map type"
<<
std
::
endl
;
abort
();
}
mapfd_
=
bpf_create_map
(
map_type
,
name
.
c_str
(),
key_size
,
value_size
,
max_entries
,
flags
);
...
...
@@ -92,6 +93,7 @@ Map::Map(enum bpf_map_type map_type)
name
=
"perf event"
;
break
;
default:
std
::
cerr
<<
"invalid map type"
<<
std
::
endl
;
abort
();
}
...
...
src/mapkey.cpp
View file @
e9e699f8
...
...
@@ -88,6 +88,7 @@ std::string MapKey::argument_value(BPFtrace &bpftrace,
case
Type
:
:
string
:
return
std
::
string
((
char
*
)
data
);
}
std
::
cerr
<<
"invalid mapkey argument type"
<<
std
::
endl
;
abort
();
}
...
...
src/types.cpp
View file @
e9e699f8
...
...
@@ -35,7 +35,7 @@ std::string typestr(Type t)
{
case
Type
:
:
none
:
return
"none"
;
break
;
case
Type
:
:
integer
:
return
"integer"
;
break
;
case
Type
:
:
hist
:
return
"hist"
;
break
;
case
Type
:
:
hist
:
return
"hist"
;
break
;
case
Type
:
:
lhist
:
return
"lhist"
;
break
;
case
Type
:
:
count
:
return
"count"
;
break
;
case
Type
:
:
sum
:
return
"sum"
;
break
;
...
...
@@ -43,15 +43,17 @@ std::string typestr(Type t)
case
Type
:
:
max
:
return
"max"
;
break
;
case
Type
:
:
avg
:
return
"avg"
;
break
;
case
Type
:
:
stats
:
return
"stats"
;
break
;
case
Type
:
:
kstack
:
return
"kstack"
;
break
;
case
Type
:
:
kstack
:
return
"kstack"
;
break
;
case
Type
:
:
ustack
:
return
"ustack"
;
break
;
case
Type
:
:
string
:
return
"string"
;
break
;
case
Type
:
:
ksym
:
return
"ksym"
;
break
;
case
Type
:
:
ksym
:
return
"ksym"
;
break
;
case
Type
:
:
usym
:
return
"usym"
;
break
;
case
Type
:
:
inet
:
return
"inet"
;
break
;
case
Type
:
:
cast
:
return
"cast"
;
break
;
case
Type
:
:
probe
:
return
"probe"
;
break
;
default:
abort
();
default:
std
::
cerr
<<
"call or probe type not found"
<<
std
::
endl
;
abort
();
}
}
...
...
@@ -87,6 +89,27 @@ std::string probetypeName(const std::string &probeName)
return
res
;
}
std
::
string
probetypeName
(
ProbeType
t
)
{
switch
(
t
)
{
case
ProbeType
:
:
invalid
:
return
"invalid"
;
break
;
case
ProbeType
:
:
kprobe
:
return
"kprobe"
;
break
;
case
ProbeType
:
:
kretprobe
:
return
"kretprobe"
;
break
;
case
ProbeType
:
:
uprobe
:
return
"uprobe"
;
break
;
case
ProbeType
:
:
uretprobe
:
return
"uretprobe"
;
break
;
case
ProbeType
:
:
usdt
:
return
"usdt"
;
break
;
case
ProbeType
:
:
tracepoint
:
return
"tracepoint"
;
break
;
case
ProbeType
:
:
profile
:
return
"profile"
;
break
;
case
ProbeType
:
:
interval
:
return
"interval"
;
break
;
case
ProbeType
:
:
software
:
return
"software"
;
break
;
case
ProbeType
:
:
hardware
:
return
"hardware"
;
break
;
default:
std
::
cerr
<<
"probe type not found"
<<
std
::
endl
;
abort
();
}
}
uint64_t
asyncactionint
(
AsyncAction
a
)
{
return
(
uint64_t
)
a
;
...
...
src/types.h
View file @
e9e699f8
...
...
@@ -99,6 +99,7 @@ const std::vector<ProbeItem> PROBE_LIST =
std
::
string
typestr
(
Type
t
);
ProbeType
probetype
(
const
std
::
string
&
type
);
std
::
string
probetypeName
(
const
std
::
string
&
type
);
std
::
string
probetypeName
(
ProbeType
t
);
class
Probe
{
...
...
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