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
38276a11
Commit
38276a11
authored
Oct 16, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes:
https://github.com/iovisor/bpftrace/issues/12
parent
51500dfb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
35 deletions
+66
-35
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+14
-11
src/types.cpp
src/types.cpp
+15
-24
src/types.h
src/types.h
+24
-0
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+13
-0
No files found.
src/ast/semantic_analyser.cpp
View file @
38276a11
...
...
@@ -677,30 +677,33 @@ void SemanticAnalyser::visit(Predicate &pred)
void
SemanticAnalyser
::
visit
(
AttachPoint
&
ap
)
{
if
(
ap
.
provider
==
"kprobe"
||
ap
.
provider
==
"kretprobe"
)
{
auto
type
=
probetypeName
(
ap
.
provider
);
type
=
type
==
""
?
ap
.
provider
:
type
;
if
(
type
==
"kprobe"
||
type
==
"kretprobe"
)
{
if
(
ap
.
target
!=
""
)
err_
<<
"kprobes should not have a target"
<<
std
::
endl
;
if
(
ap
.
func
==
""
)
err_
<<
"kprobes should be attached to a function"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"uprobe"
||
ap
.
provider
==
"uretprobe"
)
{
else
if
(
type
==
"uprobe"
||
type
==
"uretprobe"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"uprobes should have a target"
<<
std
::
endl
;
if
(
ap
.
func
==
""
)
err_
<<
"uprobes should be attached to a function"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"usdt"
)
{
else
if
(
type
==
"usdt"
)
{
if
(
ap
.
target
==
""
||
ap
.
func
==
""
)
err_
<<
"usdt probe must have a target"
<<
std
::
endl
;
struct
stat
s
;
if
(
stat
(
ap
.
target
.
c_str
(),
&
s
)
!=
0
)
err_
<<
"usdt target file "
<<
ap
.
target
<<
" does not exist"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"tracepoint"
)
{
else
if
(
type
==
"tracepoint"
)
{
if
(
ap
.
target
==
""
||
ap
.
func
==
""
)
err_
<<
"tracepoint probe must have a target"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"profile"
)
{
else
if
(
type
==
"profile"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"profile probe must have unit of time"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"hz"
&&
...
...
@@ -713,7 +716,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<=
0
)
err_
<<
"profile frequency should be a positive integer"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"interval"
)
{
else
if
(
type
==
"interval"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"interval probe must have unit of time"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"ms"
&&
...
...
@@ -722,7 +725,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
if
(
ap
.
func
!=
""
)
err_
<<
"interval probe must have an integer frequency"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"software"
)
{
else
if
(
type
==
"software"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"software probe must have a software event name"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"cpu-clock"
&&
ap
.
target
!=
"cpu"
&&
...
...
@@ -742,7 +745,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<
0
)
err_
<<
"software count should be a positive integer"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"hardware"
)
{
else
if
(
type
==
"hardware"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"hardware probe must have a hardware event name"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"cpu-cycles"
&&
ap
.
target
!=
"cycles"
&&
...
...
@@ -760,16 +763,16 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<
0
)
err_
<<
"hardware frequency should be a positive integer"
<<
std
::
endl
;
}
else
if
(
ap
.
provider
==
"BEGIN"
||
ap
.
provider
==
"END"
)
{
else
if
(
type
==
"BEGIN"
||
type
==
"END"
)
{
if
(
ap
.
target
!=
""
||
ap
.
func
!=
""
)
err_
<<
"BEGIN/END probes should not have a target"
<<
std
::
endl
;
if
(
is_final_pass
())
{
if
(
ap
.
provider
==
"BEGIN"
)
{
if
(
type
==
"BEGIN"
)
{
if
(
has_begin_probe_
)
err_
<<
"More than one BEGIN probe defined"
<<
std
::
endl
;
has_begin_probe_
=
true
;
}
if
(
ap
.
provider
==
"END"
)
{
if
(
type
==
"END"
)
{
if
(
has_end_probe_
)
err_
<<
"More than one END probe defined"
<<
std
::
endl
;
has_end_probe_
=
true
;
...
...
src/types.cpp
View file @
38276a11
...
...
@@ -55,33 +55,24 @@ std::string typestr(Type t)
ProbeType
probetype
(
const
std
::
string
&
type
)
{
if
(
type
==
"kprobe"
)
return
ProbeType
::
kprobe
;
else
if
(
type
==
"kretprobe"
)
return
ProbeType
::
kretprobe
;
else
if
(
type
==
"uprobe"
)
return
ProbeType
::
uprobe
;
else
if
(
type
==
"uretprobe"
)
return
ProbeType
::
uretprobe
;
else
if
(
type
==
"usdt"
)
return
ProbeType
::
usdt
;
else
if
(
type
==
"BEGIN"
)
return
ProbeType
::
uprobe
;
else
if
(
type
==
"END"
)
return
ProbeType
::
uprobe
;
else
if
(
type
==
"tracepoint"
)
return
ProbeType
::
tracepoint
;
else
if
(
type
==
"profile"
)
return
ProbeType
::
profile
;
else
if
(
type
==
"interval"
)
return
ProbeType
::
interval
;
else
if
(
type
==
"software"
)
return
ProbeType
::
software
;
else
if
(
type
==
"hardware"
)
return
ProbeType
::
hardware
;
for
(
int
i
=
0
;
i
<
sizeof
(
PROBE_LIST
);
i
++
)
{
if
(
type
==
PROBE_LIST
[
i
].
name
||
type
==
PROBE_LIST
[
i
].
abbr
)
return
PROBE_LIST
[
i
].
type
;
}
abort
();
}
std
::
string
probetypeName
(
const
std
::
string
&
type
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
PROBE_LIST
);
i
++
)
{
if
(
type
==
PROBE_LIST
[
i
].
name
||
type
==
PROBE_LIST
[
i
].
abbr
)
return
PROBE_LIST
[
i
].
name
;
}
return
""
;
}
uint64_t
asyncactionint
(
AsyncAction
a
)
{
return
(
uint64_t
)
a
;
...
...
src/types.h
View file @
38276a11
...
...
@@ -72,8 +72,32 @@ enum class ProbeType
hardware
,
};
struct
ProbeItem
{
std
::
string
name
;
std
::
string
abbr
;
ProbeType
type
;
};
const
ProbeItem
PROBE_LIST
[]
=
{
{
"kprobe"
,
"k"
,
ProbeType
::
kprobe
},
{
"kretprobe"
,
"kr"
,
ProbeType
::
kretprobe
},
{
"uprobe"
,
"u"
,
ProbeType
::
uprobe
},
{
"uretprobe"
,
"ur"
,
ProbeType
::
uretprobe
},
{
"usdt"
,
"usdt"
,
ProbeType
::
usdt
},
{
"BEGIN"
,
"BEGIN"
,
ProbeType
::
uprobe
},
{
"END"
,
"END"
,
ProbeType
::
uprobe
},
{
"tracepoint"
,
"t"
,
ProbeType
::
tracepoint
},
{
"profile"
,
"p"
,
ProbeType
::
profile
},
{
"interval"
,
"i"
,
ProbeType
::
interval
},
{
"software"
,
"s"
,
ProbeType
::
software
},
{
"hardware"
,
"h"
,
ProbeType
::
hardware
}
};
std
::
string
typestr
(
Type
t
);
ProbeType
probetype
(
const
std
::
string
&
type
);
std
::
string
probetypeName
(
const
std
::
string
&
type
);
class
Probe
{
...
...
tests/semantic_analyser.cpp
View file @
38276a11
...
...
@@ -638,6 +638,19 @@ TEST(semantic_analyser, field_access_is_internal)
EXPECT_EQ
(
true
,
var_assignment2
->
var
->
type
.
is_internal
);
}
TEST
(
semantic_analyser
,
probe_short_name
)
{
test
(
"t:a:b { args }"
,
0
);
test
(
"k:f { pid }"
,
0
);
test
(
"kr:f { pid }"
,
0
);
test
(
"u:path:f { 1 }"
,
0
);
test
(
"ur:path:f { 1 }"
,
0
);
test
(
"p:hz:997 { 1 }"
,
0
);
test
(
"h:cache-references:1000000 { 1 }"
,
0
);
test
(
"s:faults:1000 { 1 }"
,
0
);
test
(
"i:s:1 { 1 }"
,
0
);
}
}
// namespace semantic_analyser
}
// namespace test
}
// namespace bpftrace
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