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
40b0e3ca
Commit
40b0e3ca
authored
Sep 23, 2018
by
Brendan Gregg
Committed by
GitHub
Sep 23, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #109 from iovisor/debug-unoptimized-code
add verbose debug output with -dd
parents
35bd1134
d741c913
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
14 deletions
+57
-14
docs/reference_guide.md
docs/reference_guide.md
+2
-0
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+14
-2
src/ast/codegen_llvm.h
src/ast/codegen_llvm.h
+1
-1
src/attached_probe.cpp
src/attached_probe.cpp
+2
-2
src/bpftrace.cpp
src/bpftrace.cpp
+2
-2
src/bpftrace.h
src/bpftrace.h
+25
-1
src/main.cpp
src/main.cpp
+10
-5
tests/codegen.cpp
tests/codegen.cpp
+1
-1
No files found.
docs/reference_guide.md
View file @
40b0e3ca
...
...
@@ -103,6 +103,7 @@ OPTIONS:
-p PID PID for enabling USDT probes
-v verbose messages
-d debug info dry run
-dd verbose debug info dry run
EXAMPLES:
bpftrace -l '*sleep*'
...
...
@@ -201,6 +202,7 @@ kprobe:hrtimer_nanosleep
## 5. `-d`: Debug Output
The
`-d`
option produces debug output, and does not run the program. This is mostly useful for debugging issues with bpftrace itself.
You can also use
`-dd`
to produce a more verbose debug output, which will also print unoptimized IR.
**If you are an end-user of bpftrace, you should not normally need the `-d` or `-v` options, and you can skip to the [Language](#language) section.**
...
...
src/ast/codegen_llvm.cpp
View file @
40b0e3ca
...
...
@@ -1317,7 +1317,7 @@ void CodegenLLVM::createStrcmpFunction()
b_
.
CreateRet
(
b_
.
getInt1
(
0
));
}
std
::
unique_ptr
<
BpfOrc
>
CodegenLLVM
::
compile
(
boo
l
debug
,
std
::
ostream
&
out
)
std
::
unique_ptr
<
BpfOrc
>
CodegenLLVM
::
compile
(
DebugLeve
l
debug
,
std
::
ostream
&
out
)
{
createLog2Function
();
createLinearFunction
();
...
...
@@ -1355,11 +1355,23 @@ std::unique_ptr<BpfOrc> CodegenLLVM::compile(bool debug, std::ostream &out)
*/
LLVMAddAlwaysInlinerPass
(
reinterpret_cast
<
LLVMPassManagerRef
>
(
&
PM
));
PMB
.
populateModulePassManager
(
PM
);
if
(
debug
==
DebugLevel
::
kFullDebug
)
{
raw_os_ostream
llvm_ostream
(
out
);
llvm_ostream
<<
"Before optimization
\n
"
;
llvm_ostream
<<
"-------------------
\n\n
"
;
module_
->
print
(
llvm_ostream
,
nullptr
,
false
,
true
);
}
PM
.
run
(
*
module_
.
get
());
if
(
debug
)
if
(
debug
!=
DebugLevel
::
kNone
)
{
raw_os_ostream
llvm_ostream
(
out
);
if
(
debug
==
DebugLevel
::
kFullDebug
)
{
llvm_ostream
<<
"
\n
After optimization
\n
"
;
llvm_ostream
<<
"------------------
\n\n
"
;
}
module_
->
print
(
llvm_ostream
,
nullptr
,
false
,
true
);
}
...
...
src/ast/codegen_llvm.h
View file @
40b0e3ca
...
...
@@ -55,7 +55,7 @@ public:
void
createLog2Function
();
void
createLinearFunction
();
void
createStrcmpFunction
();
std
::
unique_ptr
<
BpfOrc
>
compile
(
bool
debug
=
fals
e
,
std
::
ostream
&
out
=
std
::
cerr
);
std
::
unique_ptr
<
BpfOrc
>
compile
(
DebugLevel
debug
=
DebugLevel
::
kNon
e
,
std
::
ostream
&
out
=
std
::
cerr
);
private:
Node
*
root_
;
...
...
src/attached_probe.cpp
View file @
40b0e3ca
...
...
@@ -236,7 +236,7 @@ void AttachedProbe::load_prog()
// Redirect stderr, so we don't get error messages from BCC
int
old_stderr
,
new_stderr
;
fflush
(
stderr
);
if
(
bt_debug
)
if
(
bt_debug
!=
DebugLevel
::
kNone
)
log_level
=
15
;
else
{
...
...
@@ -265,7 +265,7 @@ void AttachedProbe::load_prog()
}
// Restore stderr
if
(
bt_debug
==
fals
e
)
if
(
bt_debug
==
DebugLevel
::
kNon
e
)
{
fflush
(
stderr
);
dup2
(
old_stderr
,
2
);
...
...
src/bpftrace.cpp
View file @
40b0e3ca
...
...
@@ -17,7 +17,7 @@
namespace
bpftrace
{
bool
bt_debug
=
fals
e
;
DebugLevel
bt_debug
=
DebugLevel
::
kNon
e
;
bool
bt_verbose
=
false
;
int
BPFtrace
::
add_probe
(
ast
::
Probe
&
p
)
...
...
@@ -89,7 +89,7 @@ int BPFtrace::add_probe(ast::Probe &p)
probe
.
name
=
attach_point
->
name
(
func
);
probe
.
freq
=
attach_point
->
freq
;
probe
.
loc
=
0
;
probe
.
index
=
attach_point
->
index
(
func
)
>
0
?
probe
.
index
=
attach_point
->
index
(
func
)
>
0
?
attach_point
->
index
(
func
)
:
p
.
index
();
probes_
.
push_back
(
probe
);
}
...
...
src/bpftrace.h
View file @
40b0e3ca
...
...
@@ -17,11 +17,35 @@
namespace
bpftrace
{
class
BpfOrc
;
enum
class
DebugLevel
;
// globals
extern
boo
l
bt_debug
;
extern
DebugLeve
l
bt_debug
;
extern
bool
bt_verbose
;
enum
class
DebugLevel
{
kNone
,
kDebug
,
kFullDebug
};
inline
DebugLevel
operator
++
(
DebugLevel
&
level
,
int
)
{
switch
(
level
)
{
case
DebugLevel
:
:
kNone
:
level
=
DebugLevel
::
kDebug
;
break
;
case
DebugLevel
:
:
kDebug
:
level
=
DebugLevel
::
kFullDebug
;
break
;
case
DebugLevel
:
:
kFullDebug
:
// NOTE (mmarchini): should be handled by the caller
level
=
DebugLevel
::
kNone
;
break
;
}
return
level
;
}
class
BPFtrace
{
public:
...
...
src/main.cpp
View file @
40b0e3ca
...
...
@@ -23,6 +23,7 @@ void usage()
std
::
cerr
<<
" -p PID PID for enabling USDT probes"
<<
std
::
endl
;
std
::
cerr
<<
" -v verbose messages"
<<
std
::
endl
;
std
::
cerr
<<
" -d debug info dry run"
<<
std
::
endl
<<
std
::
endl
;
std
::
cerr
<<
" -dd verbose debug info dry run"
<<
std
::
endl
<<
std
::
endl
;
std
::
cerr
<<
"EXAMPLES:"
<<
std
::
endl
;
std
::
cerr
<<
"bpftrace -l '*sleep*'"
<<
std
::
endl
;
std
::
cerr
<<
" list probes containing
\"
sleep
\"
"
<<
std
::
endl
;
...
...
@@ -46,7 +47,11 @@ int main(int argc, char *argv[])
switch
(
c
)
{
case
'd'
:
bt_debug
=
true
;
bt_debug
++
;
if
(
bt_debug
==
DebugLevel
::
kNone
)
{
usage
();
return
1
;
}
break
;
case
'v'
:
bt_verbose
=
true
;
...
...
@@ -66,7 +71,7 @@ int main(int argc, char *argv[])
}
}
if
(
bt_verbose
&&
bt_debug
)
if
(
bt_verbose
&&
(
bt_debug
!=
DebugLevel
::
kNone
)
)
{
// TODO: allow both
std
::
cerr
<<
"USAGE: Use either -v or -d."
<<
std
::
endl
;
...
...
@@ -125,7 +130,7 @@ int main(int argc, char *argv[])
if
(
pid_str
)
bpftrace
.
pid_
=
atoi
(
pid_str
);
if
(
bt_debug
)
if
(
bt_debug
!=
DebugLevel
::
kNone
)
{
ast
::
Printer
p
(
std
::
cout
);
driver
.
root_
->
accept
(
p
);
...
...
@@ -140,14 +145,14 @@ int main(int argc, char *argv[])
if
(
err
)
return
err
;
err
=
semantics
.
create_maps
(
bt_debug
);
err
=
semantics
.
create_maps
(
bt_debug
!=
DebugLevel
::
kNone
);
if
(
err
)
return
err
;
ast
::
CodegenLLVM
llvm
(
driver
.
root_
,
bpftrace
);
auto
bpforc
=
llvm
.
compile
(
bt_debug
);
if
(
bt_debug
)
if
(
bt_debug
!=
DebugLevel
::
kNone
)
return
0
;
// Empty signal handler for cleanly terminating the program
...
...
tests/codegen.cpp
View file @
40b0e3ca
...
...
@@ -93,7 +93,7 @@ void test(const std::string &input, const std::string expected_output)
std
::
stringstream
out
;
ast
::
CodegenLLVM
codegen
(
driver
.
root_
,
bpftrace
);
codegen
.
compile
(
true
,
out
);
codegen
.
compile
(
DebugLevel
::
kDebug
,
out
);
std
::
string
full_expected_output
=
header
+
expected_output
;
EXPECT_EQ
(
full_expected_output
,
out
.
str
());
...
...
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