Repository navigation
Expand file tree
/
Copy pathtypes.cpp
More file actions
161 lines (138 loc) · 4.3 KB
/
Copy pathtypes.cpp
File metadata and controls
161 lines (138 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include <algorithm>
#include "types.h"
namespace bpftrace {
std::ostream &operator<<(std::ostream &os, Type type)
{
os << typestr(type);
return os;
}
std::ostream &operator<<(std::ostream &os, const SizedType &type)
{
if (type.type == Type::cast)
{
os << type.cast_type;
}
else if (type.type == Type::integer)
{
os << (type.is_signed ? "" : "unsigned ") << "int" << 8*type.size;
}
else if (type.type == Type::array)
{
os << (type.is_signed ? "" : "unsigned ") << "int" << 8 * type.pointee_size;
os << "[" << type.size << "]";
}
else if (type.type == Type::string)
{
os << type.type << "[" << type.size << "]";
}
else
{
os << type.type;
}
if (type.is_pointer)
os << "*";
return os;
}
bool SizedType::IsEqual(const SizedType &t) const
{
return type == t.type && size == t.size && is_signed == t.is_signed;
}
bool SizedType::operator!=(const SizedType &t) const
{
return !IsEqual(t);
}
bool SizedType::operator==(const SizedType &t) const
{
return IsEqual(t);
}
bool SizedType::IsArray() const
{
return type == Type::array || type == Type::string ||
type == Type::usym || type == Type::inet ||
(type == Type::cast && !is_pointer);
}
bool SizedType::IsStack() const
{
return type == Type::ustack || type == Type::kstack;
}
std::string typestr(Type t)
{
switch (t)
{
case Type::none: return "none"; break;
case Type::integer: return "integer"; 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;
case Type::min: return "min"; break;
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::ustack: return "ustack"; break;
case Type::string: return "string"; break;
case Type::ksym: return "ksym"; break;
case Type::usym: return "usym"; break;
case Type::cast: return "cast"; break;
case Type::join: return "join"; break;
case Type::probe: return "probe"; break;
case Type::username: return "username"; break;
case Type::inet: return "inet"; break;
case Type::stack_mode:return "stack mode";break;
case Type::array: return "array"; break;
default:
std::cerr << "call or probe type not found" << std::endl;
abort();
}
}
ProbeType probetype(const std::string &probeName)
{
ProbeType retType = ProbeType::invalid;
auto v = std::find_if(PROBE_LIST.begin(), PROBE_LIST.end(),
[&probeName] (const ProbeItem& p) {
return (p.name == probeName ||
p.abbr == probeName);
});
if (v != PROBE_LIST.end())
retType = v->type;
return retType;
}
std::string probetypeName(const std::string &probeName)
{
std::string res = probeName;
auto v = std::find_if(PROBE_LIST.begin(), PROBE_LIST.end(),
[&probeName] (const ProbeItem& p) {
return (p.name == probeName ||
p.abbr == probeName);
});
if (v != PROBE_LIST.end())
res = v->name;
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;
}
} // namespace bpftrace