@@ -112,6 +112,44 @@ int openListener(std::string Host, std::string PortStr) {
112
112
#endif // LLVM_ON_UNIX
113
113
}
114
114
115
+ // This must be kept in sync with gdb/gdb/jit.h .
116
+ extern " C" {
117
+
118
+ typedef enum {
119
+ JIT_NOACTION = 0 ,
120
+ JIT_REGISTER_FN,
121
+ JIT_UNREGISTER_FN
122
+ } jit_actions_t ;
123
+
124
+ struct jit_code_entry {
125
+ struct jit_code_entry *next_entry;
126
+ struct jit_code_entry *prev_entry;
127
+ const char *symfile_addr;
128
+ uint64_t symfile_size;
129
+ };
130
+
131
+ struct jit_descriptor {
132
+ uint32_t version;
133
+ // This should be jit_actions_t, but we want to be specific about the
134
+ // bit-width.
135
+ uint32_t action_flag;
136
+ struct jit_code_entry *relevant_entry;
137
+ struct jit_code_entry *first_entry;
138
+ };
139
+
140
+ // We put information about the JITed function in this global, which the
141
+ // debugger reads. Make sure to specify the version statically, because the
142
+ // debugger checks the version before we can set it during runtime.
143
+ extern struct jit_descriptor __jit_debug_descriptor;
144
+
145
+ static void *findLastDebugDescriptorEntryPtr () {
146
+ struct jit_code_entry *Last = __jit_debug_descriptor.first_entry ;
147
+ while (Last && Last->next_entry )
148
+ Last = Last->next_entry ;
149
+ return Last;
150
+ }
151
+ }
152
+
115
153
int main (int argc, char *argv[]) {
116
154
#if LLVM_ENABLE_THREADS
117
155
@@ -121,10 +159,11 @@ int main(int argc, char *argv[]) {
121
159
int InFD = 0 ;
122
160
int OutFD = 0 ;
123
161
162
+ std::vector<StringRef> TestOutputFlags;
163
+
124
164
if (argc < 2 )
125
165
printErrorAndExit (" insufficient arguments" );
126
166
else {
127
-
128
167
StringRef ConnectArg = argv[FirstProgramArg++];
129
168
#ifndef NDEBUG
130
169
if (ConnectArg == " debug" ) {
@@ -133,6 +172,11 @@ int main(int argc, char *argv[]) {
133
172
}
134
173
#endif
135
174
175
+ while (ConnectArg.starts_with (" test-" )) {
176
+ TestOutputFlags.push_back (ConnectArg);
177
+ ConnectArg = argv[FirstProgramArg++];
178
+ }
179
+
136
180
StringRef SpecifierType, Specifier;
137
181
std::tie (SpecifierType, Specifier) = ConnectArg.split (' =' );
138
182
if (SpecifierType == " filedescs" ) {
@@ -156,6 +200,10 @@ int main(int argc, char *argv[]) {
156
200
printErrorAndExit (" invalid specifier type \" " + SpecifierType + " \" " );
157
201
}
158
202
203
+ if (llvm::is_contained (TestOutputFlags, " test-jitloadergdb" ))
204
+ fprintf (stderr, " __jit_debug_descriptor.last_entry = 0x%016" PRIx64 " \n " ,
205
+ pointerToJITTargetAddress (findLastDebugDescriptorEntryPtr ()));
206
+
159
207
auto Server =
160
208
ExitOnErr (SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(
161
209
[](SimpleRemoteEPCServer::Setup &S) -> Error {
@@ -173,6 +221,11 @@ int main(int argc, char *argv[]) {
173
221
InFD, OutFD));
174
222
175
223
ExitOnErr (Server->waitForDisconnect ());
224
+
225
+ if (llvm::is_contained (TestOutputFlags, " test-jitloadergdb" ))
226
+ fprintf (stderr, " __jit_debug_descriptor.last_entry = 0x%016" PRIx64 " \n " ,
227
+ pointerToJITTargetAddress (findLastDebugDescriptorEntryPtr ()));
228
+
176
229
return 0 ;
177
230
178
231
#else
0 commit comments