Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-bin-debugger / tools / mrdb / cmdprint.c
1 /*
2 ** cmdprint.c - mruby debugger print command functions
3 **
4 */
5
6 #include <string.h>
7 #include "mrdb.h"
8 #include <mruby/value.h>
9 #include <mruby/class.h>
10 #include <mruby/compile.h>
11 #include <mruby/error.h>
12 #include <mruby/numeric.h>
13 #include <mruby/string.h>
14 #include "apiprint.h"
15
16 dbgcmd_state
17 dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
18 {
19   mrb_value expr;
20   mrb_value result;
21   mrb_value s;
22   uint8_t wcnt;
23   int ai;
24
25   if (mrdb->wcnt <= 1) {
26     puts("Parameter not specified.");
27     return DBGST_PROMPT;
28   }
29
30   ai = mrb_gc_arena_save(mrb);
31
32   /* eval expr */
33   expr = mrb_str_new_cstr(mrb, NULL);
34   for (wcnt=1; wcnt<mrdb->wcnt; wcnt++) {
35     expr = mrb_str_cat_lit(mrb, expr, " ");
36     expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]);
37   }
38
39   result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
40
41   /* $print_no = result */
42   s = mrb_str_cat_lit(mrb, result, "\0");
43   printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
44
45   if (mrdb->print_no == 0) {
46     mrdb->print_no = 1;
47   }
48
49   mrb_gc_arena_restore(mrb, ai);
50
51   return DBGST_PROMPT;
52 }
53
54 dbgcmd_state
55 dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb)
56 {
57   return dbgcmd_print(mrb, mrdb);
58 }
59
60 dbgcmd_state
61 dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb)
62 {
63   mrb_value result;
64   mrb_value s;
65   int ai;
66
67   ai = mrb_gc_arena_save(mrb);
68
69   result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1);
70
71   s = mrb_str_cat_lit(mrb, result, "\0");
72   printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
73
74   if (mrdb->print_no == 0) {
75     mrdb->print_no = 1;
76   }
77
78   mrb_gc_arena_restore(mrb, ai);
79
80   return DBGST_PROMPT;
81 }