8
8
#include < cstdio>
9
9
#include < cstdlib>
10
10
#include < cstring>
11
+ #include < iostream>
11
12
#include < stdexcept>
12
13
#include < thread>
13
14
14
15
#include " ../../src/Debug/debugger.h"
15
16
#include " ../../src/Utils/macros.h"
17
+ #include " ../../src/Utils/util.h"
18
+ #include " binary-info.h"
16
19
#include " warduino/config.h"
17
20
18
21
// Constants
@@ -267,6 +270,7 @@ int main(int argc, const char *argv[]) {
267
270
const char *proxy = nullptr ;
268
271
const char *baudrate = nullptr ;
269
272
const char *mode = " interpreter" ;
273
+ bool dump_info = false ;
270
274
271
275
const char *fname = nullptr ;
272
276
std::vector<StackValue> arguments = std::vector<StackValue>();
@@ -337,6 +341,8 @@ int main(int argc, const char *argv[]) {
337
341
arguments.push_back (
338
342
parseParameter (number, function.type ->params [i]));
339
343
}
344
+ } else if (!strcmp (" --dump-info" , arg)) {
345
+ dump_info = true ;
340
346
}
341
347
}
342
348
@@ -352,6 +358,40 @@ int main(int argc, const char *argv[]) {
352
358
}
353
359
354
360
if (m) {
361
+ if (dump_info) {
362
+ auto choicepoints = std::vector<uint32_t >();
363
+ for (uint8_t *choice_point : find_choice_points (m)) {
364
+ choicepoints.push_back (toVirtualAddress (choice_point, m));
365
+ }
366
+ auto after_choicepoints = std::vector<uint32_t >();
367
+ for (uint8_t *choice_point : find_choice_points (m, true )) {
368
+ after_choicepoints.push_back (toVirtualAddress (choice_point, m));
369
+ }
370
+ auto primitive_calls = std::vector<uint32_t >();
371
+ for (uint8_t *call_site : find_pc_before_primitive_calls (m)) {
372
+ primitive_calls.push_back (toVirtualAddress (call_site, m));
373
+ }
374
+ auto after_primitive_calls = std::vector<uint32_t >();
375
+ for (uint8_t *call_site : find_pc_after_primitive_calls (m)) {
376
+ after_primitive_calls.push_back (toVirtualAddress (call_site, m));
377
+ }
378
+ nlohmann::json json;
379
+ json[" choicepoints" ] = choicepoints;
380
+ json[" after_choicepoints" ] = after_choicepoints;
381
+ json[" primitive_calls" ] = primitive_calls;
382
+ json[" after_primitive_calls" ] = after_primitive_calls;
383
+
384
+ std::vector<std::string> fidx_mapping = std::vector<std::string>();
385
+ for (uint32_t fidx = 0 ; fidx < m->import_count ; fidx++) {
386
+ fidx_mapping.emplace_back (m->functions [fidx].import_field );
387
+ }
388
+ json[" primitive_fidx_mapping" ] = fidx_mapping;
389
+
390
+ std::cout << json << std::endl;
391
+ wac->unload_module (m);
392
+ exit (0 );
393
+ }
394
+
355
395
if (strcmp (mode, " proxy" ) == 0 ) {
356
396
// Run in proxy mode
357
397
wac->debugger ->proxify ();
0 commit comments