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
ae7e2a5c
Commit
ae7e2a5c
authored
Jun 04, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make argument_list a template function so it works with Types too
parent
fd008e4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
26 deletions
+39
-26
src/semantic_analyser.cpp
src/semantic_analyser.cpp
+5
-5
src/types.cpp
src/types.cpp
+6
-19
src/types.h
src/types.h
+28
-2
No files found.
src/semantic_analyser.cpp
View file @
ae7e2a5c
...
...
@@ -74,11 +74,11 @@ void SemanticAnalyser::visit(Map &map)
if
(
search
!=
map_args_
.
end
())
{
if
(
search
->
second
!=
args
)
{
err_
<<
"Argument mismatch for "
<<
map
.
ident
<<
": "
;
err_
<<
"trying to access with arguments:
[
"
;
for
(
Type
t
:
args
)
{
err_
<<
typestr
(
t
)
<<
" "
;
}
err_
<<
"
]
\n\t
when map expects arguments: [
"
;
for
(
Type
t
:
search
->
second
)
{
err_
<<
typestr
(
t
)
<<
" "
;
}
err_
<<
"
]
\n
"
<<
std
::
endl
;
err_
<<
"trying to access with arguments: "
;
err_
<<
argument_list
(
args
,
true
);
err_
<<
"
\n\t
when map expects arguments:
"
;
err_
<<
argument_list
(
search
->
second
,
true
);
err_
<<
"
\n
"
<<
std
::
endl
;
}
}
else
{
...
...
src/types.cpp
View file @
ae7e2a5c
#include <iostream>
#include <sstream>
#include "types.h"
namespace
ebpf
{
namespace
bpftrace
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Type
type
)
{
os
<<
typestr
(
type
);
return
os
;
}
std
::
string
typestr
(
Type
t
)
{
switch
(
t
)
...
...
@@ -38,23 +43,5 @@ bpf_prog_type progtype(ProbeType t)
}
}
std
::
string
argument_list
(
const
std
::
vector
<
uint64_t
>
&
items
)
{
return
argument_list
(
items
,
items
.
size
());
}
std
::
string
argument_list
(
const
std
::
vector
<
uint64_t
>
&
items
,
size_t
n
)
{
if
(
n
==
0
)
return
""
;
std
::
ostringstream
list
;
list
<<
"["
;
for
(
size_t
i
=
0
;
i
<
n
-
1
;
i
++
)
list
<<
items
.
at
(
i
)
<<
", "
;
list
<<
items
.
at
(
n
-
1
)
<<
"]"
;
return
list
.
str
();
}
}
// namespace bpftrace
}
// namespace ebpf
src/types.h
View file @
ae7e2a5c
#pragma once
#include <ostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>
...
...
@@ -17,6 +19,8 @@ enum class Type
count
,
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Type
type
);
enum
class
ProbeType
{
kprobe
,
...
...
@@ -26,8 +30,6 @@ enum class ProbeType
std
::
string
typestr
(
Type
t
);
bpf_probe_attach_type
attachtype
(
ProbeType
t
);
bpf_prog_type
progtype
(
ProbeType
t
);
std
::
string
argument_list
(
const
std
::
vector
<
uint64_t
>
&
items
);
std
::
string
argument_list
(
const
std
::
vector
<
uint64_t
>
&
items
,
size_t
n
);
class
Probe
{
...
...
@@ -37,5 +39,29 @@ public:
std
::
string
name
;
};
template
<
typename
T
>
std
::
string
argument_list
(
const
std
::
vector
<
T
>
&
items
,
size_t
n
,
bool
show_empty
=
false
)
{
if
(
n
==
0
)
{
if
(
show_empty
)
return
"[]"
;
return
""
;
}
std
::
ostringstream
list
;
list
<<
"["
;
for
(
size_t
i
=
0
;
i
<
n
-
1
;
i
++
)
list
<<
items
.
at
(
i
)
<<
", "
;
list
<<
items
.
at
(
n
-
1
)
<<
"]"
;
return
list
.
str
();
}
template
<
typename
T
>
std
::
string
argument_list
(
const
std
::
vector
<
T
>
&
items
,
bool
show_empty
=
false
)
{
return
argument_list
(
items
,
items
.
size
(),
show_empty
);
}
}
// namespace bpftrace
}
// namespace ebpf
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