This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit.h
142 lines (120 loc) · 4.82 KB
/
emit.h
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
// backend generation
// Copyright (C) 2014-2015 Serguei Makarov
//
// This file is part of EBT, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
#ifndef EBT_EMIT_H
#define EBT_EMIT_H
// Diagnostic option. After terminating, the script prints a summary of
// how many times each probe handler was invoked.
#define PROBE_COUNTERS
#include <vector>
#include <map>
#include <set>
/* from util.h */
struct translator_output;
#include "ir.h"
// ----------------------------
// --- DBT client templates ---
// ----------------------------
// The client template organizes basic probes by mechanism:
typedef std::map<basic_probe_type, std::vector<basic_probe *> > probe_map;
class client_template {
protected:
ebt_module *module;
probe_map basic_probes;
std::vector<ebt_function *> functions;
std::vector<ebt_global *> globals;
public:
client_template(ebt_module *module);
virtual void register_probe(basic_probe *bp);
virtual void register_function(ebt_function *f);
virtual void register_global(ebt_global *g);
virtual void emit(translator_output& o) = 0;
};
// Prettyprints the compiled basic probes for diagnostic purposes:
class fake_client_template: public client_template {
public:
fake_client_template(ebt_module *module) : client_template(module) {}
void emit(translator_output& o);
};
// Emits a client written in C for the DynamoRIO framework:
class dr_client_template: public client_template {
// Optional features enabled when a probe requires them:
bool wants_opcode; // -- #include "runtime/opcodes.h"
bool wants_forward; // -- // forward declarations
bool wants_bb_callback; // -- dr_register_exit_event(exit_event);
bool wants_exit_callback; // -- dr_register_bb_event(bb_event);
bool wants_mechanism(basic_probe_type bt);
// Standard names for various generated variables:
// TODOXXX
// Groups of declarations:
void emit_globals (translator_output& o);
void emit_functions (translator_output& o, bool forward = false);
void emit_probe_handlers (translator_output& o, bool forward = false);
void emit_basic_block_callback (translator_output& o, bool forward = false);
void emit_exit_callback (translator_output& o, bool forward = false);
// -- some components have the option to emit forward declarations.
// Helpers to emit specific boilerplate:
void emit_global_initialization (translator_output& o, ebt_global *g);
void emit_event_invocations (translator_output& o, basic_probe_type bt);
void emit_event_instrumentation (translator_output& o, basic_probe_type bt);
// Client code can either invoke a handler directly,
// or ask DR to instrument target code with a clean call.
public:
dr_client_template(ebt_module *module);
void emit(translator_output& o);
};
// TODOXXX REWRITE AND STUB OUT BELOW
// TODOXXX start stupidly simple with the context mapping
//typedef std::map<std::string, std::string> ebt_context;
// class dr_client_template: public client_template {
// std::vector<handler *> all_handlers; // -- used to iterate through handlers
// std::set<unsigned> seen_handlers; // -- used to avoid duplicates in all_handlers
//
// c_unparser unparser;
// static ebt_context ctxvars; // TODOXXX initialize
//
// bool have(basic_probe_type mechanism) const;
//
// /* standard names for various generated variables */
// std::string global(unsigned id) const;
// std::string global_mutex(unsigned id) const;
//
// #ifdef PROBE_COUNTERS
// std::string probecounter(unsigned id) const;
// std::string probecount_mutex(unsigned id) const;
// #endif
//
// std::string chain_label(unsigned id) const;
// std::string condvar(unsigned hid, int cid) const;
// std::string handlerfn(unsigned id) const;
//
// void emit_condition_chain(translator_output& o,
// std::vector<basic_probe *> chain,
// bool handle_inline = false);
// void emit_handler(translator_output& o, handler *h);
//
// void emit_begin_callback(translator_output& o);
// void emit_exit_callback(translator_output& o);
// void emit_bb_callback(translator_output& o);
//
// void emit_function_decls(translator_output& o, bool forward = false);
// void emit_global_data(translator_output &o);
// public:
// dr_client_template(ebt_module *module) : client_template(module) {}
// void register_probe(basic_probe *bp);
// void emit(translator_output& o);
// };
// ---------------------------------------------------------------
// --- generic C "unparser", used for any C/C++ output formats ---
// ---------------------------------------------------------------
// TODOXXX
// class c_unparser {
// public:
// c_unparser();
// void emit_expr(translator_output& o, expr *e, ebt_context *ctx) const;
// };
#endif // EBT_EMIT_H