33#include "gdbsupport/gdb_vecs.h"
78 std::vector<struct insn_info> *info,
79 std::vector<int> *to_do,
80 enum bfd_endian byte_order,
unsigned int addr_size,
81 const gdb_byte *op_ptr,
const gdb_byte *op_end)
83 const gdb_byte *
const base = op_ptr;
87 gdb_assert ((*info)[start].visited);
88 stack_depth = (*info)[start].depth;
90 while (op_ptr < op_end)
92 enum dwarf_location_atom op = (
enum dwarf_location_atom) *op_ptr;
95 int ndx = op_ptr - base;
97#define SET_CHECK_DEPTH(WHERE) \
98 if ((*info)[WHERE].visited) \
100 if ((*info)[WHERE].depth != stack_depth) \
101 error (_("inconsistent stack depths")); \
106 (*info)[WHERE].visited = 1; \
107 (*info)[WHERE].depth = stack_depth; \
297 case DW_OP_deref_size:
301 case DW_OP_plus_uconst:
325 case DW_OP_call_frame_cfa:
329 case DW_OP_GNU_push_tls_address:
330 case DW_OP_form_tls_address:
331 (*info)[ndx].is_tls = 1;
337 offset = op_ptr + offset - base;
340 if (!(*info)[offset].visited)
341 to_do->push_back (offset);
343 (*info)[offset].label = 1;
350 offset = op_ptr + offset - base;
354 if (!(*info)[offset].visited)
355 to_do->push_back (offset);
357 (*info)[offset].label = 1;
364 error (_(
"unhandled DWARF op: %s"), get_DW_OP_name (op));
368 gdb_assert (op_ptr == op_end);
370#undef SET_CHECK_DEPTH
391 int *need_tempvar,
int *is_tls,
392 const gdb_byte *op_ptr,
const gdb_byte *op_end,
394 std::vector<struct insn_info> *info)
396 std::vector<int> to_do;
399 info->resize (op_end - op_ptr);
402 (*info)[0].depth = initial_depth;
403 (*info)[0].visited = 1;
405 while (!to_do.empty ())
407 int ndx = to_do.back ();
411 byte_order, addr_size,
417 for (i = 0; i < op_end - op_ptr; ++i)
419 if ((*info)[i].depth > stack_depth)
420 stack_depth = (*info)[i].depth;
421 if ((*info)[i].is_tls)
425 return stack_depth + 1;
430#define GCC_UINTPTR "__gdb_uintptr"
431#define GCC_INTPTR "__gdb_intptr"
439 "%*s__gdb_stack[++__gdb_tos] = (" GCC_UINTPTR ") %s;\n",
440 indent,
"", hex_string (l));
454 gdb_printf (stream,
"%*s__gdb_stack[__gdb_tos + 1] = ", indent,
"");
455 va_start (args, format);
456 stream->
vprintf (format, args);
458 stream->
puts (
";\n");
460 gdb_printf (stream,
"%*s++__gdb_tos;\n", indent,
"");
474 gdb_printf (stream,
"%*s__gdb_stack[__gdb_tos] = ", indent,
"");
475 va_start (args, format);
476 stream->
vprintf (format, args);
478 stream->
puts (
";\n");
491 gdb_printf (stream,
"%*s__gdb_stack[__gdb_tos - 1] = ", indent,
"");
492 va_start (args, format);
493 stream->
vprintf (format, args);
495 stream->
puts (
";\n");
496 gdb_printf (stream,
"%*s--__gdb_tos;\n", indent,
"");
506 stream->
printf (
"__label_%u_%s", scope, pulongest (target));
518 if (
regnum >= registers_used.size ())
519 error (_(
"Expression uses \"cooked\" register and cannot be compiled."));
520 registers_used[
regnum] =
true;
529 std::vector<bool> ®isters_used,
535 pushf (indent, stream,
547 std::vector<bool> ®isters_used,
557 pushf (indent, stream,
559 regname.
c_str (), hex_string (offset));
593 const char *type_name,
594 const char *result_name,
595 struct symbol *sym, CORE_ADDR pc,
597 std::vector<bool> ®isters_used,
598 unsigned int addr_size,
599 const gdb_byte *op_ptr,
const gdb_byte *op_end,
606 static unsigned int scope;
609 const gdb_byte *
const base = op_ptr;
610 int need_tempvar = 0;
612 std::vector<struct insn_info> info;
617 gdb_printf (stream,
"%*s__attribute__ ((unused)) %s %s;\n",
618 indent,
"", type_name, result_name);
623 &need_tempvar, &is_tls,
624 op_ptr, op_end, initial != NULL,
640 error (_(
"Symbol \"%s\" cannot be used because "
641 "there is no selected frame"),
646 error (_(
"Symbol \"%s\" cannot be used for compilation evaluation "
647 "as its address has not been found."),
650 warning (_(
"Symbol \"%s\" is thread-local and currently can only "
651 "be referenced from the current thread in "
656 indent,
"", result_name,
657 core_addr_to_string (val->
address ()));
658 gdb_printf (stream,
"%*s}\n", indent - 2,
"");
663 indent,
"", stack_depth);
667 gdb_printf (stream,
"%*sint __gdb_tos = -1;\n", indent,
"");
670 pushf (indent, stream,
"%s", core_addr_to_string (*initial));
672 while (op_ptr < op_end)
674 enum dwarf_location_atom op = (
enum dwarf_location_atom) *op_ptr;
675 uint64_t uoffset,
reg;
678 stream->
printf (
"%*s", indent - 2,
"");
679 if (info[op_ptr - base].label)
684 stream->
printf (
"/* %s */\n", get_DW_OP_name (op));
727 push (indent, stream, op - DW_OP_lit0);
737 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
739 push (indent, stream, uoffset);
743 push (indent, stream,
748 push (indent, stream,
753 push (indent, stream,
758 push (indent, stream,
763 push (indent, stream,
768 push (indent, stream,
773 push (indent, stream,
778 push (indent, stream,
784 push (indent, stream, uoffset);
826 (
arch, op - DW_OP_reg0));
884 const gdb_byte *datastart;
886 const struct block *b;
893 error (_(
"No block found for address"));
898 error (_(
"No function found for block"));
901 &datastart, &datalen);
907 xsnprintf (fb_name,
sizeof (fb_name),
"__frame_base_%ld",
908 (
long) (op_ptr - base));
913 arch, registers_used, addr_size,
914 datastart, datastart + datalen,
915 NULL, per_cu, per_objfile);
917 pushf (indent, stream,
"%s + %s", fb_name, hex_string (offset));
922 pushf (indent, stream,
"__gdb_stack[__gdb_tos]");
926 gdb_printf (stream,
"%*s--__gdb_tos;\n", indent,
"");
931 pushf (indent, stream,
"__gdb_stack[__gdb_tos - %s]",
937 "%*s__gdb_tmp = __gdb_stack[__gdb_tos - 1];\n",
940 "%*s__gdb_stack[__gdb_tos - 1] = "
941 "__gdb_stack[__gdb_tos];\n",
943 gdb_printf (stream, (
"%*s__gdb_stack[__gdb_tos] = "
949 pushf (indent, stream,
"__gdb_stack[__gdb_tos - 1]");
954 "__gdb_stack[__gdb_tos];\n"),
957 "%*s__gdb_stack[__gdb_tos] = "
958 "__gdb_stack[__gdb_tos - 1];\n",
961 "%*s__gdb_stack[__gdb_tos - 1] = "
962 "__gdb_stack[__gdb_tos -2];\n",
964 gdb_printf (stream,
"%*s__gdb_stack[__gdb_tos - 2] = "
970 case DW_OP_deref_size:
975 if (op == DW_OP_deref_size)
982 error (_(
"Unsupported size %d in %s"),
983 size, get_DW_OP_name (op));
988 "%*s__gdb_stack[__gdb_tos] = "
989 "*((__gdb_int_%s *) "
990 "__gdb_stack[__gdb_tos]);\n",
996 unary (indent, stream,
997 "((" GCC_INTPTR ") __gdb_stack[__gdb_tos]) < 0 ? "
998 "-__gdb_stack[__gdb_tos] : __gdb_stack[__gdb_tos]");
1002 unary (indent, stream,
"-__gdb_stack[__gdb_tos]");
1006 unary (indent, stream,
"~__gdb_stack[__gdb_tos]");
1009 case DW_OP_plus_uconst:
1011 unary (indent, stream,
"__gdb_stack[__gdb_tos] + %s",
1017 ") __gdb_stack[__gdb_tos-1]) / (("
1023 "((" GCC_INTPTR ") __gdb_stack[__gdb_tos-1]) >> "
1024 "__gdb_stack[__gdb_tos]");
1028 binary (indent, stream, "%s", "__gdb_stack[__gdb_tos-1] " #OP \
1029 " __gdb_stack[__gdb_tos]"); \
1052#define COMPARE(OP) \
1053 binary (indent, stream, \
1054 "(((" GCC_INTPTR ") __gdb_stack[__gdb_tos-1]) " #OP \
1056 ") __gdb_stack[__gdb_tos]))"); \
1073 case DW_OP_call_frame_cfa:
1076 CORE_ADDR text_offset;
1078 const gdb_byte *cfa_start, *cfa_end;
1082 &text_offset, &cfa_start, &cfa_end))
1095 xsnprintf (cfa_name,
sizeof (cfa_name),
1096 "__cfa_%ld", (
long) (op_ptr - base));
1100 sym, pc,
arch, registers_used,
1103 &text_offset, per_cu, per_objfile);
1104 pushf (indent, stream,
"%s", cfa_name);
1114 print_label (stream, scope, op_ptr + offset - base);
1115 stream->
puts (
";\n");
1123 ") __gdb_stack[__gdb_tos--]) != 0) goto ",
1125 print_label (stream, scope, op_ptr + offset - base);
1126 stream->
puts (
";\n");
1133 error (_(
"unhandled DWARF op: %s"), get_DW_OP_name (op));
1137 gdb_printf (stream,
"%*s%s = __gdb_stack[__gdb_tos];\n",
1138 indent,
"", result_name);
1139 gdb_printf (stream,
"%*s}\n", indent - 2,
"");
1146 struct symbol *sym, CORE_ADDR pc,
1148 std::vector<bool> ®isters_used,
1149 unsigned int addr_size,
1150 const gdb_byte *op_ptr,
const gdb_byte *op_end,
1155 arch, registers_used, addr_size, op_ptr, op_end,
1156 NULL, per_cu, per_objfile);
1163 const char *result_name,
1165 struct symbol *sym, CORE_ADDR pc,
1167 std::vector<bool> ®isters_used,
1168 unsigned int addr_size,
1169 const gdb_byte *op_ptr,
const gdb_byte *op_end,
1174 sym, pc,
arch, registers_used,
1175 addr_size, op_ptr, op_end, NULL, per_cu,
const struct block * block_for_pc(CORE_ADDR pc)
const char * c_str() const
virtual void puts(const char *str)
void vprintf(const char *, va_list) ATTRIBUTE_PRINTF(2
void printf(const char *,...) ATTRIBUTE_PRINTF(2
const char * c_get_mode_for_size(int size)
#define COMPILE_I_SIMPLE_REGISTER_ARG_NAME
std::string compile_register_name_mangled(struct gdbarch *gdbarch, int regnum)
static void push(int indent, string_file *stream, ULONGEST l)
static void do_compile_dwarf_expr_to_c(int indent, string_file *stream, const char *type_name, const char *result_name, struct symbol *sym, CORE_ADDR pc, struct gdbarch *arch, std::vector< bool > ®isters_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, CORE_ADDR *initial, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
static void unary(int indent, string_file *stream, const char *format,...) ATTRIBUTE_PRINTF(3
static void pushf_register(int indent, string_file *stream, std::vector< bool > ®isters_used, struct gdbarch *gdbarch, int regnum, uint64_t offset)
void compile_dwarf_bounds_to_c(string_file *stream, const char *result_name, const struct dynamic_prop *prop, struct symbol *sym, CORE_ADDR pc, struct gdbarch *arch, std::vector< bool > ®isters_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
#define SET_CHECK_DEPTH(WHERE)
static void print_label(string_file *stream, unsigned int scope, int target)
static void pushf(int indent, string_file *stream, const char *format,...) ATTRIBUTE_PRINTF(3
static int compute_stack_depth(enum bfd_endian byte_order, unsigned int addr_size, int *need_tempvar, int *is_tls, const gdb_byte *op_ptr, const gdb_byte *op_end, int initial_depth, std::vector< struct insn_info > *info)
static void note_register(int regnum, std::vector< bool > ®isters_used)
static void pushf_register_address(int indent, string_file *stream, std::vector< bool > ®isters_used, struct gdbarch *gdbarch, int regnum)
void compile_dwarf_expr_to_c(string_file *stream, const char *result_name, struct symbol *sym, CORE_ADDR pc, struct gdbarch *arch, std::vector< bool > ®isters_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
static void compute_stack_depth_worker(int start, int *need_tempvar, std::vector< struct insn_info > *info, std::vector< int > *to_do, enum bfd_endian byte_order, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end)
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
int dwarf2_fetch_cfa_info(struct gdbarch *gdbarch, CORE_ADDR pc, struct dwarf2_per_cu_data *data, int *regnum_out, LONGEST *offset_out, CORE_ADDR *text_offset_out, const gdb_byte **cfa_start_out, const gdb_byte **cfa_end_out)
void dwarf_expr_require_composition(const gdb_byte *op_ptr, const gdb_byte *op_end, const char *op_name)
const gdb_byte * safe_read_sleb128(const gdb_byte *buf, const gdb_byte *buf_end, int64_t *r)
const gdb_byte * safe_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
struct value * read_var_value(struct symbol *var, const struct block *var_block, frame_info_ptr frame)
frame_info_ptr get_selected_frame(const char *message)
static void ATTRIBUTE_PRINTF(1, 0)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
int dwarf_reg_to_regnum_or_error(struct gdbarch *arch, ULONGEST dwarf_reg)
void func_get_frame_base_dwarf_block(struct symbol *framefunc, CORE_ADDR pc, const gdb_byte **start, size_t *length)
struct symbol * linkage_function() const
const char * print_name() const
CORE_ADDR text_section_offset() const
struct gdbarch * arch() const
enum lval_type lval() const
struct value::@203::@204 reg
void gdb_printf(struct ui_file *stream, const char *format,...)