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
d0d5eae2
Commit
d0d5eae2
authored
Feb 06, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to read script from command line argument
parent
6cbeb0a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
11 deletions
+64
-11
src/driver.cpp
src/driver.cpp
+17
-4
src/driver.h
src/driver.h
+3
-4
src/main.cpp
src/main.cpp
+44
-3
No files found.
src/driver.cpp
View file @
d0d5eae2
...
...
@@ -2,21 +2,34 @@
#include "driver.h"
extern
FILE
*
yyin
;
extern
void
*
yy_scan_string
(
const
char
*
yystr
);
namespace
ebpf
{
namespace
bpftrace
{
int
Driver
::
parse
()
int
Driver
::
parse
_stdin
()
{
return
parser_
.
parse
();
}
int
Driver
::
parse
(
const
std
::
string
&
f
)
int
Driver
::
parse_str
(
const
std
::
string
&
script
)
{
void
*
buffer
=
yy_scan_string
(
script
.
c_str
());
int
result
=
parser_
.
parse
();
free
(
buffer
);
return
result
;
}
int
Driver
::
parse_file
(
const
std
::
string
&
f
)
{
if
(
!
(
yyin
=
fopen
(
f
.
c_str
(),
"r"
)))
{
std
::
cerr
<<
"
Could not open file
"
<<
std
::
endl
;
std
::
cerr
<<
"
Error: Could not open file '"
<<
f
<<
"'
"
<<
std
::
endl
;
return
-
1
;
}
return
parser_
.
parse
();
int
result
=
parser_
.
parse
();
fclose
(
yyin
);
return
result
;
}
}
// namespace bpftrace
...
...
src/driver.h
View file @
d0d5eae2
...
...
@@ -6,8 +6,6 @@
#define YY_DECL ebpf::bpftrace::Parser::symbol_type yylex(ebpf::bpftrace::Driver &driver)
YY_DECL
;
extern
FILE
*
yyin
;
namespace
ebpf
{
namespace
bpftrace
{
...
...
@@ -15,8 +13,9 @@ class Driver {
public:
Driver
()
:
parser_
(
*
this
)
{
}
int
parse
();
int
parse
(
const
std
::
string
&
f
);
int
parse_stdin
();
int
parse_str
(
const
std
::
string
&
script
);
int
parse_file
(
const
std
::
string
&
f
);
void
error
(
const
location
&
l
,
const
std
::
string
&
m
)
{
...
...
src/main.cpp
View file @
d0d5eae2
#include <iostream>
#include <unistd.h>
#include "bpftrace.h"
#include "codegen_llvm.h"
#include "driver.h"
...
...
@@ -7,14 +8,54 @@
using
namespace
ebpf
::
bpftrace
;
void
usage
()
{
std
::
cerr
<<
"Usage:"
<<
std
::
endl
;
std
::
cerr
<<
" bpftrace filename"
<<
std
::
endl
;
std
::
cerr
<<
" bpftrace -e 'script'"
<<
std
::
endl
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
result
;
Driver
driver
;
if
(
argc
==
1
)
result
=
driver
.
parse
();
std
::
string
script
;
int
c
;
while
((
c
=
getopt
(
argc
,
argv
,
"e:"
))
!=
-
1
)
{
switch
(
c
)
{
case
'e'
:
script
=
optarg
;
break
;
default:
usage
();
return
1
;
}
}
if
(
script
.
empty
())
{
// There should only be 1 non-option argument (the script file)
if
(
optind
!=
argc
-
1
)
{
usage
();
return
1
;
}
char
*
file_name
=
argv
[
optind
];
result
=
driver
.
parse_file
(
file_name
);
}
else
result
=
driver
.
parse
(
argv
[
1
]);
{
// Script is provided as a command line argument
if
(
optind
!=
argc
)
{
usage
();
return
1
;
}
result
=
driver
.
parse_str
(
script
);
}
if
(
result
)
return
result
;
...
...
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