Repository navigation
Expand file tree
/
Copy pathrequired_resources.cpp
More file actions
82 lines (74 loc) · 1.87 KB
/
Copy pathrequired_resources.cpp
File metadata and controls
82 lines (74 loc) · 1.87 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
#include <cereal/archives/binary.hpp>
#include <cereal/types/map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/types/optional.hpp>
#include <cereal/types/set.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/tuple.hpp>
#include <cereal/types/unordered_set.hpp>
#include <cereal/types/vector.hpp>
#include "required_resources.h"
namespace bpftrace {
void RequiredResources::save_state(std::ostream &out) const
{
cereal::BinaryOutputArchive archive(out);
archive(*this);
}
void RequiredResources::load_state(std::istream &in)
{
cereal::BinaryInputArchive archive(in);
archive(*this);
}
class Membuf : public std::streambuf {
public:
Membuf(uint8_t *begin, uint8_t *end)
{
auto *b = reinterpret_cast<char *>(begin);
auto *e = reinterpret_cast<char *>(end);
this->setg(b, b, e);
}
};
void RequiredResources::load_state(const uint8_t *ptr, size_t len)
{
auto *addr = const_cast<uint8_t *>(ptr);
Membuf mbuf(addr, addr + len);
std::istream istream(&mbuf);
cereal::BinaryInputArchive archive(istream);
archive(*this);
}
std::ostream &operator<<(std::ostream &os, const RuntimeErrorInfo &info)
{
switch (info.error_id) {
case RuntimeErrorId::HELPER_ERROR: {
// Helper errors are handled separately in output.
os << "";
break;
}
case RuntimeErrorId::DIVIDE_BY_ZERO: {
os << DIVIDE_BY_ZERO_MSG;
break;
}
case RuntimeErrorId::ARRAY_ACCESS_OOB: {
os << ARRAY_ACCESS_OOB_MSG;
break;
}
case RuntimeErrorId::CPU_COUNT_MISMATCH: {
os << CPU_COUNT_MISMATCH_MSG;
break;
}
case RuntimeErrorId::KSTACK: {
os << KSTACK_MSG;
break;
}
case RuntimeErrorId::USTACK: {
os << USTACK_MSG;
break;
}
case RuntimeErrorId::DW_USTACK_NO_DWARF: {
os << DW_USTACK_NO_DWARF_MSG;
break;
}
}
return os;
}
} // namespace bpftrace