binutils-gdb/gdb/dwarf2/expr.h

324 lines
11 KiB
C
Raw Normal View History

* dwarf2expr.h: Tweak comment. (struct dwarf_expr_context): Use `gdb_byte *' in read_mem and get_frame_base function pointers. (read_uleb128, read_sleb128): Change return type and types of first two arguments to `gdb_byte *'. (dwarf2_read_address): Change types of first two arguments to `gdb_byte *'. * dwarf2expr.c: Tweak comment. (dwarf_expr_eval): Change type of second argument to `gdb_byte *'. (read_uleb128, read_sleb128): Change return type and types of first two arguments to `gdb_byte *'. (dwarf2_read_address): Change types of first two arguments to `gdb_byte *'. (execute_stack_op): Change types of last two arguments to `gdb_byte *'. Use `gdb_byte *' for byte buffers. * dwarf2loc.h: Tweak comment. (struct dwarf2_locexpr_baton, struct dwarf2_loclist_baton): Use `gdb_byte *' for byte buffers. * dwarf2loc.c (find_location_expression): Change return type to `gdb_byte *'. Use `gdb_byte *' for byte buffers. Change length to `unsigned int'. (dwarf_expr_read_reg): Use `gdb_byte *' for byte buffer. Remove bogus cast. (dwarf_expr_read_mem): Change type of second argument to `gdb_byte *'. (dwarf_expr_frame_base): Change type of second argument to `gdb_byte **'. (dwarf2_evaluate_loc_desc): Change type of third argument to `gdb_byte *'. (needs_frame_read_mem): Change type of second argument to `gdb_byte *'. (needs_frame_frame_base): Change type of second argument `gdb_byte **'. Use gdb_byte for lit0. (dwarf2_tracepoint_var_ref): Change type of fourth argument to `gdb_byte *'. Use `gdb_byte *' for byte buffer. (loclist_read_variable, loclist_tracepoint_var_ref): Use `gdb_byte *' for byte buffer. * dwarf2-frame.c (struct dwarf2_cie, struct dwarf2_fde) (struct dwarf2_frame_state): Use gdb_byte instead of `unsigned char'. (read_reg): Use `gdb_byte *' for byte buffers. Remove redundant cast. (read_mem): Change second argument to `gdb_byte *'. (no_get_frame_base): Change second argument to `gdb_byte **'. (execute_stack_op): Change first argument to `gdb_byte *'. (execute_cfa_program): Change first two arguments to `gdb_byte *'. Use gdb_byte instead of `unsigned int'. Use temprorary variable to store result of read_uleb128. (struct comp_unit): Use `gdb_byte *' for byte buffers. (read_1_byte, read_4_bytes, read_8_bytes): Change last argument to `gdb_byte *'. (read_unsigned_leb128, read_signed_leb128): Change second argument to `gdb_byte *'. Use gdb_byte instead of `unsigned char'. (read_initial_length): Change second argument to `gdb_byte *'. Remove redundant casts. (read_encoded_value): Use gdb_byte instead of `unsigned char'. Remove bogus casts. (decode_frame_entry_1): Change return type and second argument to `gdb_byte *'. Use `gdb_byte *' for byte buffers. Use gdb_byte instead of `unsigned char'. (decode_frame_entry): Change return type and second argument to `gdb_byte *'. Use `gdb_byte *' for byte buffers. (dwarf2_build_frame_info): Use `gdb_byte *' for byte buffers.
2005-07-12 21:06:54 +08:00
/* DWARF 2 Expression Evaluator.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
* dwarf2expr.h: Tweak comment. (struct dwarf_expr_context): Use `gdb_byte *' in read_mem and get_frame_base function pointers. (read_uleb128, read_sleb128): Change return type and types of first two arguments to `gdb_byte *'. (dwarf2_read_address): Change types of first two arguments to `gdb_byte *'. * dwarf2expr.c: Tweak comment. (dwarf_expr_eval): Change type of second argument to `gdb_byte *'. (read_uleb128, read_sleb128): Change return type and types of first two arguments to `gdb_byte *'. (dwarf2_read_address): Change types of first two arguments to `gdb_byte *'. (execute_stack_op): Change types of last two arguments to `gdb_byte *'. Use `gdb_byte *' for byte buffers. * dwarf2loc.h: Tweak comment. (struct dwarf2_locexpr_baton, struct dwarf2_loclist_baton): Use `gdb_byte *' for byte buffers. * dwarf2loc.c (find_location_expression): Change return type to `gdb_byte *'. Use `gdb_byte *' for byte buffers. Change length to `unsigned int'. (dwarf_expr_read_reg): Use `gdb_byte *' for byte buffer. Remove bogus cast. (dwarf_expr_read_mem): Change type of second argument to `gdb_byte *'. (dwarf_expr_frame_base): Change type of second argument to `gdb_byte **'. (dwarf2_evaluate_loc_desc): Change type of third argument to `gdb_byte *'. (needs_frame_read_mem): Change type of second argument to `gdb_byte *'. (needs_frame_frame_base): Change type of second argument `gdb_byte **'. Use gdb_byte for lit0. (dwarf2_tracepoint_var_ref): Change type of fourth argument to `gdb_byte *'. Use `gdb_byte *' for byte buffer. (loclist_read_variable, loclist_tracepoint_var_ref): Use `gdb_byte *' for byte buffer. * dwarf2-frame.c (struct dwarf2_cie, struct dwarf2_fde) (struct dwarf2_frame_state): Use gdb_byte instead of `unsigned char'. (read_reg): Use `gdb_byte *' for byte buffers. Remove redundant cast. (read_mem): Change second argument to `gdb_byte *'. (no_get_frame_base): Change second argument to `gdb_byte **'. (execute_stack_op): Change first argument to `gdb_byte *'. (execute_cfa_program): Change first two arguments to `gdb_byte *'. Use gdb_byte instead of `unsigned int'. Use temprorary variable to store result of read_uleb128. (struct comp_unit): Use `gdb_byte *' for byte buffers. (read_1_byte, read_4_bytes, read_8_bytes): Change last argument to `gdb_byte *'. (read_unsigned_leb128, read_signed_leb128): Change second argument to `gdb_byte *'. Use gdb_byte instead of `unsigned char'. (read_initial_length): Change second argument to `gdb_byte *'. Remove redundant casts. (read_encoded_value): Use gdb_byte instead of `unsigned char'. Remove bogus casts. (decode_frame_entry_1): Change return type and second argument to `gdb_byte *'. Use `gdb_byte *' for byte buffers. Use gdb_byte instead of `unsigned char'. (decode_frame_entry): Change return type and second argument to `gdb_byte *'. Use `gdb_byte *' for byte buffers. (dwarf2_build_frame_info): Use `gdb_byte *' for byte buffers.
2005-07-12 21:06:54 +08:00
Contributed by Daniel Berlin <dan@dberlin.org>.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#if !defined (DWARF2EXPR_H)
#define DWARF2EXPR_H
Sort includes for files gdb/[a-f]*.[chyl]. This patch sorts the include files for the files [a-f]*.[chyl]. The patch was written by a script. Tested by the buildbot. I will follow up with patches to sort the remaining files, by sorting a subset, testing them, and then checking them in. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> * ft32-tdep.c: Sort headers. * frv-tdep.c: Sort headers. * frv-linux-tdep.c: Sort headers. * frame.c: Sort headers. * frame-unwind.c: Sort headers. * frame-base.c: Sort headers. * fork-child.c: Sort headers. * findvar.c: Sort headers. * findcmd.c: Sort headers. * filesystem.c: Sort headers. * filename-seen-cache.h: Sort headers. * filename-seen-cache.c: Sort headers. * fbsd-tdep.c: Sort headers. * fbsd-nat.h: Sort headers. * fbsd-nat.c: Sort headers. * f-valprint.c: Sort headers. * f-typeprint.c: Sort headers. * f-lang.c: Sort headers. * extension.h: Sort headers. * extension.c: Sort headers. * extension-priv.h: Sort headers. * expprint.c: Sort headers. * exec.h: Sort headers. * exec.c: Sort headers. * exceptions.c: Sort headers. * event-top.c: Sort headers. * event-loop.c: Sort headers. * eval.c: Sort headers. * elfread.c: Sort headers. * dwarf2read.h: Sort headers. * dwarf2read.c: Sort headers. * dwarf2loc.c: Sort headers. * dwarf2expr.h: Sort headers. * dwarf2expr.c: Sort headers. * dwarf2-frame.c: Sort headers. * dwarf2-frame-tailcall.c: Sort headers. * dwarf-index-write.h: Sort headers. * dwarf-index-write.c: Sort headers. * dwarf-index-common.c: Sort headers. * dwarf-index-cache.h: Sort headers. * dwarf-index-cache.c: Sort headers. * dummy-frame.c: Sort headers. * dtrace-probe.c: Sort headers. * disasm.h: Sort headers. * disasm.c: Sort headers. * disasm-selftests.c: Sort headers. * dictionary.c: Sort headers. * dicos-tdep.c: Sort headers. * demangle.c: Sort headers. * dcache.h: Sort headers. * dcache.c: Sort headers. * darwin-nat.h: Sort headers. * darwin-nat.c: Sort headers. * darwin-nat-info.c: Sort headers. * d-valprint.c: Sort headers. * d-namespace.c: Sort headers. * d-lang.c: Sort headers. * ctf.c: Sort headers. * csky-tdep.c: Sort headers. * csky-linux-tdep.c: Sort headers. * cris-tdep.c: Sort headers. * cris-linux-tdep.c: Sort headers. * cp-valprint.c: Sort headers. * cp-support.c: Sort headers. * cp-namespace.c: Sort headers. * cp-abi.c: Sort headers. * corelow.c: Sort headers. * corefile.c: Sort headers. * continuations.c: Sort headers. * completer.h: Sort headers. * completer.c: Sort headers. * complaints.c: Sort headers. * coffread.c: Sort headers. * coff-pe-read.c: Sort headers. * cli-out.h: Sort headers. * cli-out.c: Sort headers. * charset.c: Sort headers. * c-varobj.c: Sort headers. * c-valprint.c: Sort headers. * c-typeprint.c: Sort headers. * c-lang.c: Sort headers. * buildsym.c: Sort headers. * buildsym-legacy.c: Sort headers. * build-id.h: Sort headers. * build-id.c: Sort headers. * btrace.c: Sort headers. * bsd-uthread.c: Sort headers. * breakpoint.h: Sort headers. * breakpoint.c: Sort headers. * break-catch-throw.c: Sort headers. * break-catch-syscall.c: Sort headers. * break-catch-sig.c: Sort headers. * blockframe.c: Sort headers. * block.c: Sort headers. * bfin-tdep.c: Sort headers. * bfin-linux-tdep.c: Sort headers. * bfd-target.c: Sort headers. * bcache.c: Sort headers. * ax-general.c: Sort headers. * ax-gdb.h: Sort headers. * ax-gdb.c: Sort headers. * avr-tdep.c: Sort headers. * auxv.c: Sort headers. * auto-load.c: Sort headers. * arm-wince-tdep.c: Sort headers. * arm-tdep.c: Sort headers. * arm-symbian-tdep.c: Sort headers. * arm-pikeos-tdep.c: Sort headers. * arm-obsd-tdep.c: Sort headers. * arm-nbsd-tdep.c: Sort headers. * arm-nbsd-nat.c: Sort headers. * arm-linux-tdep.c: Sort headers. * arm-linux-nat.c: Sort headers. * arm-fbsd-tdep.c: Sort headers. * arm-fbsd-nat.c: Sort headers. * arm-bsd-tdep.c: Sort headers. * arch-utils.c: Sort headers. * arc-tdep.c: Sort headers. * arc-newlib-tdep.c: Sort headers. * annotate.h: Sort headers. * annotate.c: Sort headers. * amd64-windows-tdep.c: Sort headers. * amd64-windows-nat.c: Sort headers. * amd64-tdep.c: Sort headers. * amd64-sol2-tdep.c: Sort headers. * amd64-obsd-tdep.c: Sort headers. * amd64-obsd-nat.c: Sort headers. * amd64-nbsd-tdep.c: Sort headers. * amd64-nbsd-nat.c: Sort headers. * amd64-nat.c: Sort headers. * amd64-linux-tdep.c: Sort headers. * amd64-linux-nat.c: Sort headers. * amd64-fbsd-tdep.c: Sort headers. * amd64-fbsd-nat.c: Sort headers. * amd64-dicos-tdep.c: Sort headers. * amd64-darwin-tdep.c: Sort headers. * amd64-bsd-nat.c: Sort headers. * alpha-tdep.c: Sort headers. * alpha-obsd-tdep.c: Sort headers. * alpha-nbsd-tdep.c: Sort headers. * alpha-mdebug-tdep.c: Sort headers. * alpha-linux-tdep.c: Sort headers. * alpha-linux-nat.c: Sort headers. * alpha-bsd-tdep.c: Sort headers. * alpha-bsd-nat.c: Sort headers. * aix-thread.c: Sort headers. * agent.c: Sort headers. * addrmap.c: Sort headers. * ada-varobj.c: Sort headers. * ada-valprint.c: Sort headers. * ada-typeprint.c: Sort headers. * ada-tasks.c: Sort headers. * ada-lang.c: Sort headers. * aarch64-tdep.c: Sort headers. * aarch64-ravenscar-thread.c: Sort headers. * aarch64-newlib-tdep.c: Sort headers. * aarch64-linux-tdep.c: Sort headers. * aarch64-linux-nat.c: Sort headers. * aarch64-fbsd-tdep.c: Sort headers. * aarch64-fbsd-nat.c: Sort headers. * aarch32-linux-nat.c: Sort headers.
2019-04-03 10:04:24 +08:00
#include "leb128.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-07 03:38:10 +08:00
#include "gdbtypes.h"
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache Evaluating DWARF expressions (such as location expressions) requires knowing about the current objfile. For example, it may call functions like dwarf2_fetch_die_loc_sect_off, which currently obtain the dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object. However, since we are going to remove this dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need to obtain the current dwarf2_per_objfile by parmeter. If we go up the stack, we see that the DWARF expression contexts (dwarf_expr_context and the classes that derive from it) need to store the dwarf2_per_objfile, to be able to pass it to those functions that will need it. This patch adds a constructor to all these dwarf_expr_context variants, accepting a dwarf2_per_objfile parameter. This dwarf2_per_objfile generally comes from a symbol baton created earlier. For frame-related expressions, the dwarf2_per_objfile object must be passed through the dwarf2_frame_cache object. This lead to the dwarf2_frame_find_fde function returning (by parameter) a dwarf2_per_objfile object. I then realized that this made the existing "out_offset" parameter redundant. This offset is `objfile->text_section_offset ()`, so it can be recomputed from the dwarf2_per_objfile object at any time. I therefore opted to remove this output parameter, as well as the offset field of dwarf2_frame_cache. *Note*, there's one spot I'm particularly unsure about. In dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and overwrite the offset value in the context, along with a bunch of other state. This is because we might be about to evaluate something in a different CU that the current one. If the two CUs are in the same objfile, then the text_offset is the same, as it's a property of the objfile. However, if the two CUs are possibly in different objfiles, then it means the text_offsets are different. It would also mean we would need to save and restore the dwarf2_per_objfile in the context. Is that even possible? gdb/ChangeLog: * dwarf2/expr.h (struct dwarf_expr_context) <dwarf_expr_context>: Add dwarf2_per_objfile parameter. <offset>: Remove. <per_objfile>: New member. * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add dwarf2_per_objfile parameter. Don't set offset, set per_objfile. (dwarf_expr_context::execute_stack_op): Use offset from objfile. * dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter) a dwarf2_per_objfile object instead of an offset. (class dwarf_expr_executor) <dwarf_expr_executor>: Add constructor. (execute_stack_op): Add dwarf2_per_objfile parameter, pass it to dwarf2_expr_executor constructor. Don't set offset. (dwarf2_fetch_cfa_info): Update. (struct dwarf2_frame_cache) <text_offset>: Remove. <per_objfile>: New field. (dwarf2_frame_cache): Update. (dwarf2_frame_prev_register): Update. * dwarf2/loc.c (class dwarf_evaluate_loc_desc) <dwarf_evaluate_loc_desc>: Add constructor. (dwarf2_evaluate_loc_desc_full): Update. (dwarf2_locexpr_baton_eval): Update. (class symbol_needs_eval_context) <symbol_needs_eval_context>: Add constructor. (dwarf2_loc_desc_get_symbol_read_needs): Update. Change-Id: I14df060669cc36ad04759f1708c6d7b1fda77727
2020-05-27 23:14:01 +08:00
struct dwarf2_per_objfile;
/* The location of a value. */
enum dwarf_value_location
{
/* The piece is in memory.
The value on the dwarf stack is its address. */
DWARF_VALUE_MEMORY,
/* The piece is in a register.
The value on the dwarf stack is the register number. */
DWARF_VALUE_REGISTER,
/* The piece is on the dwarf stack. */
DWARF_VALUE_STACK,
/* The piece is a literal. */
DWARF_VALUE_LITERAL,
/* The piece was optimized out. */
gdb * opencl-lang.c (lval_func_check_synthetic_pointer): New function. * value.h (struct lval_funcs) <indirect, check_synthetic_pointer>: New fields. (value_bits_synthetic_pointer): Declare. * value.c (value_bits_synthetic_pointer): New function. * valprint.c (valprint_check_validity): Handle synthetic pointers. * valops.c (value_ind): Use new 'indirect' lval_funcs method. * valarith.c (value_ptradd): Use set_value_component_location. * p-valprint.c (pascal_object_print_value_fields): Handle synthetic pointers. * jv-valprint.c (java_print_value_fields): Handle synthetic pointers. * dwarf2read.c (dwarf_stack_op_name): Add DW_OP_GNU_implicit_pointer. (dwarf2_fetch_die_location_block): Add get_frame_pc, baton arguments. Handle location lists. (fill_in_loclist_baton): New function. (dwarf2_symbol_mark_computed): Use it. * dwarf2loc.h (dwarf2_find_location_expression): Declare. (dwarf2_fetch_die_location_block): Add get_frame_pc, baton arguments. * dwarf2loc.c (dwarf2_find_location_expression): Rename from find_location_expression. No longer static. Update all callers. (dwarf_expr_frame_pc): New function. (per_cu_dwarf_call): Add get_frame_pc, baton arguments. Update all callers. (struct piece_closure) <per_cu>: New field. (allocate_piece_closure): Add per_cu argument. (read_pieced_value): Handle DWARF_VALUE_IMPLICIT_POINTER. (check_pieced_value_bits): Remove validity argument, add check_for argument. Handle DWARF_VALUE_IMPLICIT_POINTER. (check_pieced_value_validity, check_pieced_value_invalid): Update. (check_pieced_synthetic_pointer): New function. (get_frame_address_in_block_wrapper): New function. (indirect_pieced_value): New function. (pieced_value_funcs): Update. (invalid_synthetic_pointer): New function. (dwarf2_evaluate_loc_desc_full): Rename from dwarf2_evaluate_loc_desc. Add byte_offset argument. (dwarf2_evaluate_loc_desc): Rewrite. (dwarf2_loc_desc_needs_frame): Set new field on context. (get_ax_pc): New function. (disassemble_dwarf_expression): Handle DW_OP_GNU_implicit_pointer. * dwarf2expr.h (enum dwarf_value_location) <DWARF_VALUE_IMPLICIT_POINTER>: New constant. (struct dwarf_expr_context) <get_frame_pc>: New field. (struct dwarf_expr_piece) <v.ptr>: New field. * dwarf2expr.c (add_piece): Handle DWARF_VALUE_IMPLICIT_POINTER. (execute_stack_op): Handle DW_OP_GNU_implicit_pointer. * dwarf2-frame.c (no_get_frame_pc): New function. (execute_stack_op): Set new field on context. * cp-valprint.c (cp_print_value_fields): Handle synthetic pointers. gdb/testsuite * gdb.dwarf2/implptr.exp: New file. * gdb.dwarf2/implptr.c: New file. * gdb.dwarf2/implptr.S: New file.
2010-11-30 05:18:16 +08:00
DWARF_VALUE_OPTIMIZED_OUT,
/* The piece is an implicit pointer. */
DWARF_VALUE_IMPLICIT_POINTER
};
/* A piece of an object, as recorded by DW_OP_piece or DW_OP_bit_piece. */
struct dwarf_expr_piece
{
enum dwarf_value_location location;
union
{
struct
{
/* This piece's address, for DWARF_VALUE_MEMORY pieces. */
CORE_ADDR addr;
/* Non-zero if the piece is known to be in memory and on
the program's stack. */
bool in_stack_memory;
} mem;
/* The piece's register number, for DWARF_VALUE_REGISTER pieces. */
int regno;
/* The piece's literal value, for DWARF_VALUE_STACK pieces. */
struct value *value;
struct
{
/* A pointer to the data making up this piece,
for DWARF_VALUE_LITERAL pieces. */
const gdb_byte *data;
/* The length of the available data. */
ULONGEST length;
} literal;
/* Used for DWARF_VALUE_IMPLICIT_POINTER. */
struct
{
/* The referent DIE from DW_OP_implicit_pointer. */
sect_offset die_sect_off;
/* The byte offset into the resulting data. */
LONGEST offset;
} ptr;
} v;
/* The length of the piece, in bits. */
ULONGEST size;
/* The piece offset, in bits. */
ULONGEST offset;
};
/* The dwarf expression stack. */
struct dwarf_stack_value
{
Make dwarf_expr_context::stack an std::vector Replace the manually managed array with a vector. It is mostly straightforward, except maybe one thing in execute_stack_op, in the handling of DW_OP_fbreg. When the code stumbles on that opcode while evaluating an expression, it needs to evaluate a subexpression to find where the fb reg has been saved. Rather than creating a new context, it reuses the current context. It saves the size of the stack before and restores the stack to that size after. I think we can do a little bit better by saving the current stack locally and installing a new empty stack. This way, if the subexpression is malformed and underflows, we'll get an exception. Before, it would have overwritten the top elements of the top-level expression. The evaluation of the top-level expression would have then resumed with the same stack size, but possibly some corrupted elements. gdb/ChangeLog: * dwarf2expr.h (dwarf_stack_value): Add constructor. (dwarf_expr_context) <~dwarf_expr_context>: Define as default. <stack>: Change type to std::vector. <stack_len, stack_allocated>: Remove. <grow_stack>: Remove. * dwarf2expr.c (dwarf_expr_context::dwarf_expr_context): Adjust. (dwarf_expr_context::~dwarf_expr_context): Remove. (dwarf_expr_context::grow_stack): Remove. (dwarf_expr_context::push): Adjust. (dwarf_expr_context::pop): Adjust. (dwarf_expr_context::fetch): Adjust. (dwarf_expr_context::fetch_in_stack_memory): Adjust. (dwarf_expr_context::stack_empty_p): Adjust. (dwarf_expr_context::execute_stack_op): Adjust.
2017-09-15 04:36:57 +08:00
dwarf_stack_value (struct value *value_, int in_stack_memory_)
: value (value_), in_stack_memory (in_stack_memory_)
{}
gdb PR gdb/12617: * value.h (value_from_contents): Declare. * value.c (value_from_contents): New function. * dwarf2read.c (dwarf_stack_op_name): Add new values. (dwarf2_get_die_type): New function. * dwarf2loc.c (dwarf_expr_get_base_type): New function. (allocate_piece_closure): Acquire reference to values. (read_pieced_value): Update for value-based expressions. (write_pieced_value): Likewise. (free_pieced_value_closure): Call value_free as needed. (dwarf2_evaluate_loc_desc_full): Set get_base_type field. Update for value-based expressions. * dwarf2loc.h (dwarf2_get_die_type): Declare. * dwarf2expr.h (struct dwarf_stack_value) <value>: Change type. <get_base_type>: New field. (struct dwarf_expr_piece) <v.value>: Change type. <v.regno>: New field. (struct dwarf_expr_context) <mark>: New field. (dwarf_expr_piece, dwarf_expr_fetch): Update. (dwarf_expr_pop, dwarf_expr_push): Remove. (dwarf_expr_push_address): Declare. * dwarf2expr.c (dwarf_arch_cookie): New global. (struct dwarf_gdbarch_types): New. (dwarf_gdbarch_types_init, dwarf_expr_address_type): New functions. (dwarf_expr_push): Change type of 'value' argument. Update. Now static. (dwarf_expr_push_address): New function. (dwarf_expr_pop): Now static. (dwarf_expr_fetch): Change return type. (dwarf_require_integral): New function. (dwarf_expr_fetch): Simplify. (add_piece): Update. (base_types_equal_p, dwarf_get_base_type, get_unsigned_type): New functions. (execute_stack_op) <sign_ext>: Remove. Use values for DWARF stack. <DW_OP_GNU_const_type, DW_OP_GNU_deref_type, DW_OP_GNU_regval_type, DW_OP_GNU_convert, DW_OP_GNU_reinterpret>: New cases. (_initialize_dwarf2expr): New function. (add_piece): Update. (new_dwarf_expr_context): Set new field. (free_dwarf_expr_context): Call value_free_to_mark. * dwarf2-frame.c (no_base_type): New function. (execute_stack_op): Set get_base_type field. Update. gdb/testsuite * gdb.dwarf2/typeddwarf.S: New file. * gdb.dwarf2/typeddwarf.c: New file. * gdb.dwarf2/typeddwarf.exp: New file.
2011-05-13 01:40:55 +08:00
struct value *value;
/* True if the piece is in memory and is known to be on the program's stack.
It is always ok to set this to zero. This is used, for example, to
optimize memory access from the target. It can vastly speed up backtraces
on long latency connections when "set stack-cache on". */
bool in_stack_memory;
};
/* The expression evaluator works with a dwarf_expr_context, describing
its current state and its callbacks. */
struct dwarf_expr_context
{
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
dwarf_expr_context (dwarf2_per_objfile *per_objfile,
int addr_size);
Make dwarf_expr_context::stack an std::vector Replace the manually managed array with a vector. It is mostly straightforward, except maybe one thing in execute_stack_op, in the handling of DW_OP_fbreg. When the code stumbles on that opcode while evaluating an expression, it needs to evaluate a subexpression to find where the fb reg has been saved. Rather than creating a new context, it reuses the current context. It saves the size of the stack before and restores the stack to that size after. I think we can do a little bit better by saving the current stack locally and installing a new empty stack. This way, if the subexpression is malformed and underflows, we'll get an exception. Before, it would have overwritten the top elements of the top-level expression. The evaluation of the top-level expression would have then resumed with the same stack size, but possibly some corrupted elements. gdb/ChangeLog: * dwarf2expr.h (dwarf_stack_value): Add constructor. (dwarf_expr_context) <~dwarf_expr_context>: Define as default. <stack>: Change type to std::vector. <stack_len, stack_allocated>: Remove. <grow_stack>: Remove. * dwarf2expr.c (dwarf_expr_context::dwarf_expr_context): Adjust. (dwarf_expr_context::~dwarf_expr_context): Remove. (dwarf_expr_context::grow_stack): Remove. (dwarf_expr_context::push): Adjust. (dwarf_expr_context::pop): Adjust. (dwarf_expr_context::fetch): Adjust. (dwarf_expr_context::fetch_in_stack_memory): Adjust. (dwarf_expr_context::stack_empty_p): Adjust. (dwarf_expr_context::execute_stack_op): Adjust.
2017-09-15 04:36:57 +08:00
virtual ~dwarf_expr_context () = default;
void push_address (CORE_ADDR value, bool in_stack_memory);
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
/* Evaluate the expression at ADDR (LEN bytes long) in a given PER_CU
and FRAME context.
AS_LVAL defines if the returned struct value is expected to be a
value (false) or a location description (true).
TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET describe the expected struct
value representation of the evaluation result.
The ADDR_INFO property can be specified to override the range of
memory addresses with the passed in buffer. */
value *evaluate (const gdb_byte *addr, size_t len, bool as_lval,
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
dwarf2_per_cu_data *per_cu, frame_info *frame,
const struct property_addr_info *addr_info = nullptr,
struct type *type = nullptr,
struct type *subobj_type = nullptr,
LONGEST subobj_offset = 0);
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
private:
Make dwarf_expr_context::stack an std::vector Replace the manually managed array with a vector. It is mostly straightforward, except maybe one thing in execute_stack_op, in the handling of DW_OP_fbreg. When the code stumbles on that opcode while evaluating an expression, it needs to evaluate a subexpression to find where the fb reg has been saved. Rather than creating a new context, it reuses the current context. It saves the size of the stack before and restores the stack to that size after. I think we can do a little bit better by saving the current stack locally and installing a new empty stack. This way, if the subexpression is malformed and underflows, we'll get an exception. Before, it would have overwritten the top elements of the top-level expression. The evaluation of the top-level expression would have then resumed with the same stack size, but possibly some corrupted elements. gdb/ChangeLog: * dwarf2expr.h (dwarf_stack_value): Add constructor. (dwarf_expr_context) <~dwarf_expr_context>: Define as default. <stack>: Change type to std::vector. <stack_len, stack_allocated>: Remove. <grow_stack>: Remove. * dwarf2expr.c (dwarf_expr_context::dwarf_expr_context): Adjust. (dwarf_expr_context::~dwarf_expr_context): Remove. (dwarf_expr_context::grow_stack): Remove. (dwarf_expr_context::push): Adjust. (dwarf_expr_context::pop): Adjust. (dwarf_expr_context::fetch): Adjust. (dwarf_expr_context::fetch_in_stack_memory): Adjust. (dwarf_expr_context::stack_empty_p): Adjust. (dwarf_expr_context::execute_stack_op): Adjust.
2017-09-15 04:36:57 +08:00
/* The stack of values. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
std::vector<dwarf_stack_value> m_stack;
2008-03-18 Ulrich Weigand <uweigand@de.ibm.com> Jim Blandy <jimb@codesourcery.com> Daniel Jacobowitz <drow@false.org> * dwarf2expr.h (struct dwarf_expr_context): Add ADDR_SIZE member. (dwarf2_read_address): Update prototype. * dwarf2expr.c (unsigned_address_type): Add ADDR_SIZE parameter. (signed_address_type): Likewise. (dwarf2_read_address): Replace BYTES_READ parameter with ADDR_SIZE. (execute_stack_op): Update calls to unsigned_address_type, signed_address_type and dwarf2_read_address. Fix implementation of DW_OP_deref_size. * dwarf2loc.h (dwarf2_per_cu_objfile): Add prototype. (dwarf2_per_cu_addr_size): Likewise. (struct dwarf2_locexpr_baton): Replace OBJFILE with PER_CU. (struct dwarf2_loclist_baton): Likewise. * dwarf2loc.c (find_location_expression): Update calls to dwarf2_read_address. Use dwarf2_per_cu_objfile and dwarf2_per_cu_addr_size to retrieve PER_CU parameters. (locexpr_describe_location): Likewise. (dwarf2_evaluate_loc_desc): Replace OBJFILE with PER_CU parameter. Set ctx->addr_size to dwarf2_per_cu_addr_size (per_cu). (dwarf2_loc_desc_needs_frame): Add PER_CU parameter. Set ctx->addr_size to dwarf2_per_cu_addr_size (per_cu). (locexpr_read_variable): Update dwarf2_evaluate_loc_desc call. (loclist_read_variable): Likewise. (locexpr_read_needs_frame): Update dwarf2_loc_desc_needs_frame call. * dwarf2read.c (dwarf2_symbol_mark_computed): Set baton->per_cu instead of baton->objfile. (dwarf2_per_cu_obfile): New function. (dwarf2_per_cu_addr_size): Likewise. * dwarf2-frame.c (struct comp_unit): Move higher. (struct dwarf2_cie): Add UNIT and ADDR_SIZE members. (execute_stack_op): Add ADDR_SIZE parameter; set ctx->addr_size. (execute_cfa_program): Add FDE parameter. Replace EH_FRAME_P parameter by using fde->eh_frame_p. Use read_encoded_value to implement DW_CFA_set_loc. (struct dwarf2_frame_cache): Add ADDR_SIZE member. (dwarf2_frame_cache): Set cache->addr_size. Update calls to execute_stack_op and execute_cfa_program. (dwarf2_frame_prev_register): Update calls to execute_stack_op. (size_of_encoded_value): Remove. (read_encoded_value): Add PTR_LEN and FUNC_BASE parameters. Remove call to size_of_encoded_value. Implement DW_EH_PE_funcrel. (add_cie): Set cie->unit backlink. (decode_frame_entry_1): Set cie->addr_size. Update calls to read_encoded_value. (dwarf2_build_frame_info): Allocate UNIT on objfile obstack.
2008-03-19 03:40:47 +08:00
/* Target address size in bytes. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
int m_addr_size = 0;
2008-03-18 Ulrich Weigand <uweigand@de.ibm.com> Jim Blandy <jimb@codesourcery.com> Daniel Jacobowitz <drow@false.org> * dwarf2expr.h (struct dwarf_expr_context): Add ADDR_SIZE member. (dwarf2_read_address): Update prototype. * dwarf2expr.c (unsigned_address_type): Add ADDR_SIZE parameter. (signed_address_type): Likewise. (dwarf2_read_address): Replace BYTES_READ parameter with ADDR_SIZE. (execute_stack_op): Update calls to unsigned_address_type, signed_address_type and dwarf2_read_address. Fix implementation of DW_OP_deref_size. * dwarf2loc.h (dwarf2_per_cu_objfile): Add prototype. (dwarf2_per_cu_addr_size): Likewise. (struct dwarf2_locexpr_baton): Replace OBJFILE with PER_CU. (struct dwarf2_loclist_baton): Likewise. * dwarf2loc.c (find_location_expression): Update calls to dwarf2_read_address. Use dwarf2_per_cu_objfile and dwarf2_per_cu_addr_size to retrieve PER_CU parameters. (locexpr_describe_location): Likewise. (dwarf2_evaluate_loc_desc): Replace OBJFILE with PER_CU parameter. Set ctx->addr_size to dwarf2_per_cu_addr_size (per_cu). (dwarf2_loc_desc_needs_frame): Add PER_CU parameter. Set ctx->addr_size to dwarf2_per_cu_addr_size (per_cu). (locexpr_read_variable): Update dwarf2_evaluate_loc_desc call. (loclist_read_variable): Likewise. (locexpr_read_needs_frame): Update dwarf2_loc_desc_needs_frame call. * dwarf2read.c (dwarf2_symbol_mark_computed): Set baton->per_cu instead of baton->objfile. (dwarf2_per_cu_obfile): New function. (dwarf2_per_cu_addr_size): Likewise. * dwarf2-frame.c (struct comp_unit): Move higher. (struct dwarf2_cie): Add UNIT and ADDR_SIZE members. (execute_stack_op): Add ADDR_SIZE parameter; set ctx->addr_size. (execute_cfa_program): Add FDE parameter. Replace EH_FRAME_P parameter by using fde->eh_frame_p. Use read_encoded_value to implement DW_CFA_set_loc. (struct dwarf2_frame_cache): Add ADDR_SIZE member. (dwarf2_frame_cache): Set cache->addr_size. Update calls to execute_stack_op and execute_cfa_program. (dwarf2_frame_prev_register): Update calls to execute_stack_op. (size_of_encoded_value): Remove. (read_encoded_value): Add PTR_LEN and FUNC_BASE parameters. Remove call to size_of_encoded_value. Implement DW_EH_PE_funcrel. (add_cie): Set cie->unit backlink. (decode_frame_entry_1): Set cie->addr_size. Update calls to read_encoded_value. (dwarf2_build_frame_info): Allocate UNIT on objfile obstack.
2008-03-19 03:40:47 +08:00
/* The current depth of dwarf expression recursion, via DW_OP_call*,
DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
depth we'll tolerate before raising an error. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
int m_recursion_depth = 0, m_max_recursion_depth = 0x100;
/* Location of the value. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
dwarf_value_location m_location = DWARF_VALUE_MEMORY;
/* For DWARF_VALUE_LITERAL, the current literal value's length and
gdb * opencl-lang.c (lval_func_check_synthetic_pointer): New function. * value.h (struct lval_funcs) <indirect, check_synthetic_pointer>: New fields. (value_bits_synthetic_pointer): Declare. * value.c (value_bits_synthetic_pointer): New function. * valprint.c (valprint_check_validity): Handle synthetic pointers. * valops.c (value_ind): Use new 'indirect' lval_funcs method. * valarith.c (value_ptradd): Use set_value_component_location. * p-valprint.c (pascal_object_print_value_fields): Handle synthetic pointers. * jv-valprint.c (java_print_value_fields): Handle synthetic pointers. * dwarf2read.c (dwarf_stack_op_name): Add DW_OP_GNU_implicit_pointer. (dwarf2_fetch_die_location_block): Add get_frame_pc, baton arguments. Handle location lists. (fill_in_loclist_baton): New function. (dwarf2_symbol_mark_computed): Use it. * dwarf2loc.h (dwarf2_find_location_expression): Declare. (dwarf2_fetch_die_location_block): Add get_frame_pc, baton arguments. * dwarf2loc.c (dwarf2_find_location_expression): Rename from find_location_expression. No longer static. Update all callers. (dwarf_expr_frame_pc): New function. (per_cu_dwarf_call): Add get_frame_pc, baton arguments. Update all callers. (struct piece_closure) <per_cu>: New field. (allocate_piece_closure): Add per_cu argument. (read_pieced_value): Handle DWARF_VALUE_IMPLICIT_POINTER. (check_pieced_value_bits): Remove validity argument, add check_for argument. Handle DWARF_VALUE_IMPLICIT_POINTER. (check_pieced_value_validity, check_pieced_value_invalid): Update. (check_pieced_synthetic_pointer): New function. (get_frame_address_in_block_wrapper): New function. (indirect_pieced_value): New function. (pieced_value_funcs): Update. (invalid_synthetic_pointer): New function. (dwarf2_evaluate_loc_desc_full): Rename from dwarf2_evaluate_loc_desc. Add byte_offset argument. (dwarf2_evaluate_loc_desc): Rewrite. (dwarf2_loc_desc_needs_frame): Set new field on context. (get_ax_pc): New function. (disassemble_dwarf_expression): Handle DW_OP_GNU_implicit_pointer. * dwarf2expr.h (enum dwarf_value_location) <DWARF_VALUE_IMPLICIT_POINTER>: New constant. (struct dwarf_expr_context) <get_frame_pc>: New field. (struct dwarf_expr_piece) <v.ptr>: New field. * dwarf2expr.c (add_piece): Handle DWARF_VALUE_IMPLICIT_POINTER. (execute_stack_op): Handle DW_OP_GNU_implicit_pointer. * dwarf2-frame.c (no_get_frame_pc): New function. (execute_stack_op): Set new field on context. * cp-valprint.c (cp_print_value_fields): Handle synthetic pointers. gdb/testsuite * gdb.dwarf2/implptr.exp: New file. * gdb.dwarf2/implptr.c: New file. * gdb.dwarf2/implptr.S: New file.
2010-11-30 05:18:16 +08:00
data. For DWARF_VALUE_IMPLICIT_POINTER, LEN is the offset of the
target DIE of sect_offset kind. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
ULONGEST m_len = 0;
const gdb_byte *m_data = nullptr;
/* Initialization status of variable: Non-zero if variable has been
initialized; zero otherwise. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
int m_initialized = 0;
/* A vector of pieces.
Each time DW_OP_piece is executed, we add a new element to the
end of this array, recording the current top of the stack, the
current location, and the size given as the operand to
DW_OP_piece. We then pop the top value from the stack, reset the
location, and resume evaluation.
The Dwarf spec doesn't say whether DW_OP_piece pops the top value
from the stack. We do, ensuring that clients of this interface
expecting to see a value left on the top of the stack (say, code
evaluating frame base expressions or CFA's specified with
DW_CFA_def_cfa_expression) will get an error if the expression
actually marks all the values it computes as pieces.
If an expression never uses DW_OP_piece, num_pieces will be zero.
(It would be nice to present these cases as expressions yielding
a single piece, so that callers need not distinguish between the
no-DW_OP_piece and one-DW_OP_piece cases. But expressions with
no DW_OP_piece operations have no value to place in a piece's
'size' field; the size comes from the surrounding data. So the
two cases need to be handled separately.) */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
std::vector<dwarf_expr_piece> m_pieces;
Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache Evaluating DWARF expressions (such as location expressions) requires knowing about the current objfile. For example, it may call functions like dwarf2_fetch_die_loc_sect_off, which currently obtain the dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object. However, since we are going to remove this dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need to obtain the current dwarf2_per_objfile by parmeter. If we go up the stack, we see that the DWARF expression contexts (dwarf_expr_context and the classes that derive from it) need to store the dwarf2_per_objfile, to be able to pass it to those functions that will need it. This patch adds a constructor to all these dwarf_expr_context variants, accepting a dwarf2_per_objfile parameter. This dwarf2_per_objfile generally comes from a symbol baton created earlier. For frame-related expressions, the dwarf2_per_objfile object must be passed through the dwarf2_frame_cache object. This lead to the dwarf2_frame_find_fde function returning (by parameter) a dwarf2_per_objfile object. I then realized that this made the existing "out_offset" parameter redundant. This offset is `objfile->text_section_offset ()`, so it can be recomputed from the dwarf2_per_objfile object at any time. I therefore opted to remove this output parameter, as well as the offset field of dwarf2_frame_cache. *Note*, there's one spot I'm particularly unsure about. In dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and overwrite the offset value in the context, along with a bunch of other state. This is because we might be about to evaluate something in a different CU that the current one. If the two CUs are in the same objfile, then the text_offset is the same, as it's a property of the objfile. However, if the two CUs are possibly in different objfiles, then it means the text_offsets are different. It would also mean we would need to save and restore the dwarf2_per_objfile in the context. Is that even possible? gdb/ChangeLog: * dwarf2/expr.h (struct dwarf_expr_context) <dwarf_expr_context>: Add dwarf2_per_objfile parameter. <offset>: Remove. <per_objfile>: New member. * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add dwarf2_per_objfile parameter. Don't set offset, set per_objfile. (dwarf_expr_context::execute_stack_op): Use offset from objfile. * dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter) a dwarf2_per_objfile object instead of an offset. (class dwarf_expr_executor) <dwarf_expr_executor>: Add constructor. (execute_stack_op): Add dwarf2_per_objfile parameter, pass it to dwarf2_expr_executor constructor. Don't set offset. (dwarf2_fetch_cfa_info): Update. (struct dwarf2_frame_cache) <text_offset>: Remove. <per_objfile>: New field. (dwarf2_frame_cache): Update. (dwarf2_frame_prev_register): Update. * dwarf2/loc.c (class dwarf_evaluate_loc_desc) <dwarf_evaluate_loc_desc>: Add constructor. (dwarf2_evaluate_loc_desc_full): Update. (dwarf2_locexpr_baton_eval): Update. (class symbol_needs_eval_context) <symbol_needs_eval_context>: Add constructor. (dwarf2_loc_desc_get_symbol_read_needs): Update. Change-Id: I14df060669cc36ad04759f1708c6d7b1fda77727
2020-05-27 23:14:01 +08:00
/* We evaluate the expression in the context of this objfile. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
dwarf2_per_objfile *m_per_objfile;
Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache Evaluating DWARF expressions (such as location expressions) requires knowing about the current objfile. For example, it may call functions like dwarf2_fetch_die_loc_sect_off, which currently obtain the dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object. However, since we are going to remove this dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need to obtain the current dwarf2_per_objfile by parmeter. If we go up the stack, we see that the DWARF expression contexts (dwarf_expr_context and the classes that derive from it) need to store the dwarf2_per_objfile, to be able to pass it to those functions that will need it. This patch adds a constructor to all these dwarf_expr_context variants, accepting a dwarf2_per_objfile parameter. This dwarf2_per_objfile generally comes from a symbol baton created earlier. For frame-related expressions, the dwarf2_per_objfile object must be passed through the dwarf2_frame_cache object. This lead to the dwarf2_frame_find_fde function returning (by parameter) a dwarf2_per_objfile object. I then realized that this made the existing "out_offset" parameter redundant. This offset is `objfile->text_section_offset ()`, so it can be recomputed from the dwarf2_per_objfile object at any time. I therefore opted to remove this output parameter, as well as the offset field of dwarf2_frame_cache. *Note*, there's one spot I'm particularly unsure about. In dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and overwrite the offset value in the context, along with a bunch of other state. This is because we might be about to evaluate something in a different CU that the current one. If the two CUs are in the same objfile, then the text_offset is the same, as it's a property of the objfile. However, if the two CUs are possibly in different objfiles, then it means the text_offsets are different. It would also mean we would need to save and restore the dwarf2_per_objfile in the context. Is that even possible? gdb/ChangeLog: * dwarf2/expr.h (struct dwarf_expr_context) <dwarf_expr_context>: Add dwarf2_per_objfile parameter. <offset>: Remove. <per_objfile>: New member. * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add dwarf2_per_objfile parameter. Don't set offset, set per_objfile. (dwarf_expr_context::execute_stack_op): Use offset from objfile. * dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter) a dwarf2_per_objfile object instead of an offset. (class dwarf_expr_executor) <dwarf_expr_executor>: Add constructor. (execute_stack_op): Add dwarf2_per_objfile parameter, pass it to dwarf2_expr_executor constructor. Don't set offset. (dwarf2_fetch_cfa_info): Update. (struct dwarf2_frame_cache) <text_offset>: Remove. <per_objfile>: New field. (dwarf2_frame_cache): Update. (dwarf2_frame_prev_register): Update. * dwarf2/loc.c (class dwarf_evaluate_loc_desc) <dwarf_evaluate_loc_desc>: Add constructor. (dwarf2_evaluate_loc_desc_full): Update. (dwarf2_locexpr_baton_eval): Update. (class symbol_needs_eval_context) <symbol_needs_eval_context>: Add constructor. (dwarf2_loc_desc_get_symbol_read_needs): Update. Change-Id: I14df060669cc36ad04759f1708c6d7b1fda77727
2020-05-27 23:14:01 +08:00
Move frame context info to dwarf_expr_context Following 15 patches in this patch series is cleaning up the design of the DWARF expression evaluator (dwarf_expr_context) to make future extensions of that evaluator easier and cleaner to implement. There are three subclasses of the dwarf_expr_context class (dwarf_expr_executor, dwarf_evaluate_loc_desc and evaluate_for_locexpr_baton). Here is a short description of each class: - dwarf_expr_executor is evaluating a DWARF expression in a context of a Call Frame Information. The overridden methods of this subclass report an error if a specific DWARF operation, represented by that method, is not allowed in a CFI context. The source code of this subclass lacks the support for composite as well as implicit pointer location description. - dwarf_evaluate_loc_desc can evaluate any expression with no restrictions. All of the methods that this subclass overrides are actually doing what they are intended to do. This subclass contains a full support for all location description types. - evaluate_for_locexpr_baton subclass is a specialization of the dwarf_evaluate_loc_desc subclass and it's function is to add support for passed in buffers. This seems to be a way to go around the fact that DWARF standard lacks a bit offset support for memory location descriptions as well as using any location description for the push object address functionality. It all comes down to this question: what is a function of a DWARF expression evaluator? Is it to evaluate the expression in a given context or to check the correctness of that expression in that context? Currently, the only reason why there is a dwarf_expr_executor subclass is to report an invalid DWARF expression in a context of a CFI, but is that what the evaluator is supposed to do considering that the evaluator is not tied to a given DWARF version? There are more and more vendor and GNU extensions that are not part of the DWARF standard, so is it that impossible to expect that some of the extensions could actually lift the previously imposed restrictions of the CFI context? Not to mention that every new DWARF version is lifting some restrictions anyway. The thing that makes more sense for an evaluator to do, is to take the context of an evaluation and checks the requirements of every operation evaluated against that context. With this approach, the evaluator would report an error only if parts of the context, necessary for the evaluation, are missing. If this approach is taken, then the unification of the dwarf_evaluate_loc_desc, dwarf_expr_executor and dwarf_expr_context is the next logical step. This makes a design of the DWARF expression evaluator cleaner and allows more flexibility when supporting future vendor and GNU extensions. Additional benefit here is that now all evaluators have access to all location description types, which means that a vendor extended CFI rules could support composite location description as well. This also means that a new evaluator interface can be changed to return a single struct value (that describes the result of the evaluation) instead of a caller poking around the dwarf_expr_context internal data for answers (like it is done currently). This patch starts the merging process by moving the frame context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a frame information to be resolved, if that information is not present. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_frame): New function. (read_addr_from_reg): Add from frame.c. (dwarf_expr_context::dwarf_expr_context): Add frame info to dwarf_expr_context. (dwarf_expr_context::read_addr_from_reg): Remove. (dwarf_expr_context::get_reg_value): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_frame_base): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::execute_stack_op): Call frame context info check. Remove use of read_addr_from_reg method. * dwarf2/expr.h (struct dwarf_expr_context): Add frame info member, read_addr_from_reg, get_reg_value and get_frame_base declaration. (read_addr_from_reg): Move to expr.c. * dwarf2/frame.c (read_addr_from_reg): Move to dwarf_expr_context. (dwarf_expr_executor::read_addr_from_reg): Remove. (dwarf_expr_executor::get_frame_base): Remove. (dwarf_expr_executor::get_reg_value): Remove. (execute_stack_op): Use read_addr_from_reg function instead of read_addr_from_reg method. * dwarf2/loc.c (dwarf_evaluate_loc_desc::get_frame_base): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::get_reg_value): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::read_addr_from_reg): Remove. (dwarf2_locexpr_baton_eval):Use read_addr_from_reg function instead of read_addr_from_reg method.
2020-09-14 23:05:14 +08:00
/* Frame information used for the evaluation. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
frame_info *m_frame = nullptr;
Convert dwarf_expr_context_funcs to methods This patch converts the function pointers in dwarf_expr_context_funcs into methods on dwarf_expr_context, and then updates the various implementations and callers to follow. NB this patch uses "override" (which caught a couple of renaming bugs during development) -- but this is C++11, so this patch at least has to wait for Pedro's patch that adds the OVERRIDE macro. After this patch it would be possible to do one more, that makes various members of dwarf_expr_context "protected"; but I haven't done this. 2016-10-21 Tom Tromey <tom@tromey.com> * dwarf2loc.c (struct dwarf_expr_context_funcs): Don't declare. (dwarf_expr_read_addr_from_reg, dwarf_expr_get_reg_value) (dwarf_expr_read_mem, dwarf_expr_frame_base): Rename; turn into methods. (get_frame_pc_for_per_cu_dwarf_call): New function. (dwarf_expr_frame_cfa, dwarf_expr_frame_pc) (dwarf_expr_tls_address): Rename; turn into methods. (per_cu_dwarf_call): Remove arguments. Use get_frame_pc_for_per_cu_dwarf_call. (dwarf_evaluate_loc_desc): New class. (dwarf_expr_dwarf_call, dwarf_expr_context) (dwarf_expr_push_dwarf_reg_entry_value) (dwarf_expr_get_addr_index, dwarf_expr_get_obj_addr): Rename; turn into methods. (dwarf_expr_ctx_funcs): Remove. (dwarf2_evaluate_loc_desc_full): Update. (dwarf2_locexpr_baton_eval): Update. (symbol_needs_eval_context): New class. (symbol_needs_read_addr_from_reg, symbol_needs_get_reg_value) (symbol_needs_read_mem, symbol_needs_frame_base) (symbol_needs_frame_cfa, symbol_needs_tls_address) (symbol_needs_dwarf_call, needs_dwarf_reg_entry_value): Rename; turn into methods. (needs_get_addr_index, needs_get_obj_addr): Remove; turn into methods. (symbol_needs_ctx_funcs): Remove. (dwarf2_loc_desc_get_symbol_read_needs): Update. * dwarf2expr.h (struct dwarf_expr_context_funcs): Remove; turn contents into methods. (struct dwarf_expr_context) <baton, funcs>: Remove. <read_addr_from_reg, get_reg_value, read_mem, get_frame_base, get_frame_cfa, get_frame_pc, get_tls_address, dwarf_call, impl_get_base_type, push_dwarf_block_entry_value, get_addr_index, get_object_address>: Declare new methods. (ctx_no_get_frame_base, ctx_no_get_frame_cfa) (ctx_no_get_frame_pc, ctx_no_get_tls_address, ctx_no_dwarf_call) (ctx_no_get_base_type, ctx_no_push_dwarf_reg_entry_value) (ctx_no_get_addr_index): Don't declare. * dwarf2expr.c (get_base_type): Use impl_get_base_type. (execute_stack_op): Update. (ctx_no_get_frame_base, ctx_no_get_frame_cfa) (ctx_no_get_frame_pc, ctx_no_get_tls_address, ctx_no_dwarf_call) (ctx_no_get_base_type, ctx_no_push_dwarf_reg_entry_value) (ctx_no_get_addr_index): Remove; now methods on dwarf_expr_context. * dwarf2-frame.c (read_addr_from_reg): Take a frame_info, not a baton. (class dwarf_expr_executor): New class. (get_reg_value, read_mem): Rename, turn into methods. (execute_stack_op): Use dwarf_expr_executor.
2016-09-26 22:59:13 +08:00
Move compilation unit info to dwarf_expr_context This patch moves the compilation unit context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a compilation unit information to be resolved, which is not available. With this change, it also makes sense to always acquire ref_addr_size information from the compilation unit context, considering that all DWARF operations that refer to that information require a compilation unit context to be present during their evaluation. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_per_cu): New function. (dwarf_expr_context::dwarf_expr_context): Add compilation unit context information. (dwarf_expr_context::get_base_type): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_addr_index): Remove method. (dwarf_expr_context::dwarf_variable_value): Remove method. (dwarf_expr_context::execute_stack_op): Call compilation unit context info check. Inline get_addr_index and dwarf_variable_value methods. * dwarf2/expr.h (struct dwarf_expr_context): Add compilation context info. (dwarf_expr_context::get_addr_index): Remove method. (dwarf_expr_context::dwarf_variable_value): Remove method. (dwarf_expr_context::ref_addr_size): Remove member. * dwarf2/frame.c (dwarf_expr_executor::get_addr_index): Remove method. (dwarf_expr_executor::dwarf_variable_value): Remove method. * dwarf2/loc.c (sect_variable_value): Expose function. (dwarf_evaluate_loc_desc::get_addr_index): Remove method. (dwarf_evaluate_loc_desc::dwarf_variable_value): Remove method. (class dwarf_evaluate_loc_desc): Move compilation unit context information to dwarf_expr_context class. * dwarf2/loc.h (sect_variable_value): Expose function.
2020-09-15 00:02:29 +08:00
/* Compilation unit used for the evaluation. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
dwarf2_per_cu_data *m_per_cu = nullptr;
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
/* Property address info used for the evaluation. */
const struct property_addr_info *m_addr_info = nullptr;
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
void eval (const gdb_byte *addr, size_t len);
struct type *address_type () const;
void push (struct value *value, bool in_stack_memory);
bool stack_empty_p () const;
void add_piece (ULONGEST size, ULONGEST offset);
void execute_stack_op (const gdb_byte *op_ptr, const gdb_byte *op_end);
void pop ();
struct value *fetch (int n);
CORE_ADDR fetch_address (int n);
bool fetch_in_stack_memory (int n);
Move frame context info to dwarf_expr_context Following 15 patches in this patch series is cleaning up the design of the DWARF expression evaluator (dwarf_expr_context) to make future extensions of that evaluator easier and cleaner to implement. There are three subclasses of the dwarf_expr_context class (dwarf_expr_executor, dwarf_evaluate_loc_desc and evaluate_for_locexpr_baton). Here is a short description of each class: - dwarf_expr_executor is evaluating a DWARF expression in a context of a Call Frame Information. The overridden methods of this subclass report an error if a specific DWARF operation, represented by that method, is not allowed in a CFI context. The source code of this subclass lacks the support for composite as well as implicit pointer location description. - dwarf_evaluate_loc_desc can evaluate any expression with no restrictions. All of the methods that this subclass overrides are actually doing what they are intended to do. This subclass contains a full support for all location description types. - evaluate_for_locexpr_baton subclass is a specialization of the dwarf_evaluate_loc_desc subclass and it's function is to add support for passed in buffers. This seems to be a way to go around the fact that DWARF standard lacks a bit offset support for memory location descriptions as well as using any location description for the push object address functionality. It all comes down to this question: what is a function of a DWARF expression evaluator? Is it to evaluate the expression in a given context or to check the correctness of that expression in that context? Currently, the only reason why there is a dwarf_expr_executor subclass is to report an invalid DWARF expression in a context of a CFI, but is that what the evaluator is supposed to do considering that the evaluator is not tied to a given DWARF version? There are more and more vendor and GNU extensions that are not part of the DWARF standard, so is it that impossible to expect that some of the extensions could actually lift the previously imposed restrictions of the CFI context? Not to mention that every new DWARF version is lifting some restrictions anyway. The thing that makes more sense for an evaluator to do, is to take the context of an evaluation and checks the requirements of every operation evaluated against that context. With this approach, the evaluator would report an error only if parts of the context, necessary for the evaluation, are missing. If this approach is taken, then the unification of the dwarf_evaluate_loc_desc, dwarf_expr_executor and dwarf_expr_context is the next logical step. This makes a design of the DWARF expression evaluator cleaner and allows more flexibility when supporting future vendor and GNU extensions. Additional benefit here is that now all evaluators have access to all location description types, which means that a vendor extended CFI rules could support composite location description as well. This also means that a new evaluator interface can be changed to return a single struct value (that describes the result of the evaluation) instead of a caller poking around the dwarf_expr_context internal data for answers (like it is done currently). This patch starts the merging process by moving the frame context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a frame information to be resolved, if that information is not present. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_frame): New function. (read_addr_from_reg): Add from frame.c. (dwarf_expr_context::dwarf_expr_context): Add frame info to dwarf_expr_context. (dwarf_expr_context::read_addr_from_reg): Remove. (dwarf_expr_context::get_reg_value): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_frame_base): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::execute_stack_op): Call frame context info check. Remove use of read_addr_from_reg method. * dwarf2/expr.h (struct dwarf_expr_context): Add frame info member, read_addr_from_reg, get_reg_value and get_frame_base declaration. (read_addr_from_reg): Move to expr.c. * dwarf2/frame.c (read_addr_from_reg): Move to dwarf_expr_context. (dwarf_expr_executor::read_addr_from_reg): Remove. (dwarf_expr_executor::get_frame_base): Remove. (dwarf_expr_executor::get_reg_value): Remove. (execute_stack_op): Use read_addr_from_reg function instead of read_addr_from_reg method. * dwarf2/loc.c (dwarf_evaluate_loc_desc::get_frame_base): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::get_reg_value): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::read_addr_from_reg): Remove. (dwarf2_locexpr_baton_eval):Use read_addr_from_reg function instead of read_addr_from_reg method.
2020-09-14 23:05:14 +08:00
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
/* Fetch the result of the expression evaluation in a form of
a struct value, where TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET
describe the source level representation of that result.
AS_LVAL defines if the fetched struct value is expected to
be a value or a location description. */
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
value *fetch_result (struct type *type, struct type *subobj_type,
LONGEST subobj_offset, bool as_lval);
Simplify dwarf_expr_context class interface Idea of this patch is to get a clean and simple public interface for the dwarf_expr_context class, looking like: - constructor, - destructor, - push_address method and - evaluate method. Where constructor should only ever require a target architecture information. This information is held in per object file (dwarf2_per_objfile) structure, so it makes sense to keep that structure as a constructor argument. It also makes sense to get the address size from that structure, but unfortunately that interface doesn't exist at the moment, so the dwarf_expr_context class user needs to provide that information. The push_address method is used to push a CORE_ADDR as a value on top of the DWARF stack before the evaluation. This method can be later changed to push any struct value object on the stack. The evaluate method is the method that evaluates a DWARF expression and provides the evaluation result, in a form of a single struct value object that describes a location. To do this, the method requires a context of the evaluation, as well as expected result type information. If the type information is not provided, the DWARF generic type will be used instead. To avoid storing the gdbarch information in the evaluator object, that information is now always acquired from the per_objfile object. All data members are now private and only visible to the evaluator class, so a m_ prefix was added to all of their names to reflect that. To make this distinction clear, they are also accessed through objects this pointer, wherever that was not the case before. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add address size argument. (dwarf_expr_context::read_mem): Change to use property_addr_info structure. (dwarf_expr_context::evaluate): New function. (dwarf_expr_context::execute_stack_op): Change to use property_addr_info structure. * dwarf2/expr.h (struct dwarf_expr_context): New evaluate declaration. Change eval and fetch_result method to private. (dwarf_expr_context::gdbarch): Remove member. (dwarf_expr_context::stack): Make private and add m_ prefix. (dwarf_expr_context::addr_size): Make private and add m_ prefix. (dwarf_expr_context::recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::max_recursion_depth): Make private and add m_ prefix. (dwarf_expr_context::len): Make private and add m_ prefix. (dwarf_expr_context::data): Make private and add m_ prefix. (dwarf_expr_context::initialized): Make private and add m_ prefix. (dwarf_expr_context::pieces): Make private and add m_ prefix. (dwarf_expr_context::per_objfile): Make private and add m_ prefix. (dwarf_expr_context::frame): Make private and add m_ prefix. (dwarf_expr_context::per_cu): Make private and add m_ prefix. (dwarf_expr_context::addr_info): Make private and add m_ prefix. * dwarf2/frame.c (execute_stack_op): Change to call evaluate method. * dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Change to call evaluate method. (dwarf2_locexpr_baton_eval): Change to call evaluate method.
2020-09-17 17:28:20 +08:00
Move frame context info to dwarf_expr_context Following 15 patches in this patch series is cleaning up the design of the DWARF expression evaluator (dwarf_expr_context) to make future extensions of that evaluator easier and cleaner to implement. There are three subclasses of the dwarf_expr_context class (dwarf_expr_executor, dwarf_evaluate_loc_desc and evaluate_for_locexpr_baton). Here is a short description of each class: - dwarf_expr_executor is evaluating a DWARF expression in a context of a Call Frame Information. The overridden methods of this subclass report an error if a specific DWARF operation, represented by that method, is not allowed in a CFI context. The source code of this subclass lacks the support for composite as well as implicit pointer location description. - dwarf_evaluate_loc_desc can evaluate any expression with no restrictions. All of the methods that this subclass overrides are actually doing what they are intended to do. This subclass contains a full support for all location description types. - evaluate_for_locexpr_baton subclass is a specialization of the dwarf_evaluate_loc_desc subclass and it's function is to add support for passed in buffers. This seems to be a way to go around the fact that DWARF standard lacks a bit offset support for memory location descriptions as well as using any location description for the push object address functionality. It all comes down to this question: what is a function of a DWARF expression evaluator? Is it to evaluate the expression in a given context or to check the correctness of that expression in that context? Currently, the only reason why there is a dwarf_expr_executor subclass is to report an invalid DWARF expression in a context of a CFI, but is that what the evaluator is supposed to do considering that the evaluator is not tied to a given DWARF version? There are more and more vendor and GNU extensions that are not part of the DWARF standard, so is it that impossible to expect that some of the extensions could actually lift the previously imposed restrictions of the CFI context? Not to mention that every new DWARF version is lifting some restrictions anyway. The thing that makes more sense for an evaluator to do, is to take the context of an evaluation and checks the requirements of every operation evaluated against that context. With this approach, the evaluator would report an error only if parts of the context, necessary for the evaluation, are missing. If this approach is taken, then the unification of the dwarf_evaluate_loc_desc, dwarf_expr_executor and dwarf_expr_context is the next logical step. This makes a design of the DWARF expression evaluator cleaner and allows more flexibility when supporting future vendor and GNU extensions. Additional benefit here is that now all evaluators have access to all location description types, which means that a vendor extended CFI rules could support composite location description as well. This also means that a new evaluator interface can be changed to return a single struct value (that describes the result of the evaluation) instead of a caller poking around the dwarf_expr_context internal data for answers (like it is done currently). This patch starts the merging process by moving the frame context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a frame information to be resolved, if that information is not present. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_frame): New function. (read_addr_from_reg): Add from frame.c. (dwarf_expr_context::dwarf_expr_context): Add frame info to dwarf_expr_context. (dwarf_expr_context::read_addr_from_reg): Remove. (dwarf_expr_context::get_reg_value): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_frame_base): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::execute_stack_op): Call frame context info check. Remove use of read_addr_from_reg method. * dwarf2/expr.h (struct dwarf_expr_context): Add frame info member, read_addr_from_reg, get_reg_value and get_frame_base declaration. (read_addr_from_reg): Move to expr.c. * dwarf2/frame.c (read_addr_from_reg): Move to dwarf_expr_context. (dwarf_expr_executor::read_addr_from_reg): Remove. (dwarf_expr_executor::get_frame_base): Remove. (dwarf_expr_executor::get_reg_value): Remove. (execute_stack_op): Use read_addr_from_reg function instead of read_addr_from_reg method. * dwarf2/loc.c (dwarf_evaluate_loc_desc::get_frame_base): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::get_reg_value): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::read_addr_from_reg): Remove. (dwarf2_locexpr_baton_eval):Use read_addr_from_reg function instead of read_addr_from_reg method.
2020-09-14 23:05:14 +08:00
/* Return the location expression for the frame base attribute, in
START and LENGTH. The result must be live until the current
expression evaluation is complete. */
void get_frame_base (const gdb_byte **start, size_t *length);
Move compilation unit info to dwarf_expr_context This patch moves the compilation unit context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a compilation unit information to be resolved, which is not available. With this change, it also makes sense to always acquire ref_addr_size information from the compilation unit context, considering that all DWARF operations that refer to that information require a compilation unit context to be present during their evaluation. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_per_cu): New function. (dwarf_expr_context::dwarf_expr_context): Add compilation unit context information. (dwarf_expr_context::get_base_type): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_addr_index): Remove method. (dwarf_expr_context::dwarf_variable_value): Remove method. (dwarf_expr_context::execute_stack_op): Call compilation unit context info check. Inline get_addr_index and dwarf_variable_value methods. * dwarf2/expr.h (struct dwarf_expr_context): Add compilation context info. (dwarf_expr_context::get_addr_index): Remove method. (dwarf_expr_context::dwarf_variable_value): Remove method. (dwarf_expr_context::ref_addr_size): Remove member. * dwarf2/frame.c (dwarf_expr_executor::get_addr_index): Remove method. (dwarf_expr_executor::dwarf_variable_value): Remove method. * dwarf2/loc.c (sect_variable_value): Expose function. (dwarf_evaluate_loc_desc::get_addr_index): Remove method. (dwarf_evaluate_loc_desc::dwarf_variable_value): Remove method. (class dwarf_evaluate_loc_desc): Move compilation unit context information to dwarf_expr_context class. * dwarf2/loc.h (sect_variable_value): Expose function.
2020-09-15 00:02:29 +08:00
/* Return the base type given by the indicated DIE at DIE_CU_OFF.
This can throw an exception if the DIE is invalid or does not
represent a base type. */
struct type *get_base_type (cu_offset die_cu_off);
/* Execute DW_AT_location expression for the DWARF expression
subroutine in the DIE at DIE_CU_OFF in the CU. Do not touch
STACK while it being passed to and returned from the called DWARF
subroutine. */
void dwarf_call (cu_offset die_cu_off);
/* Push on DWARF stack an entry evaluated for DW_TAG_call_site's
parameter matching KIND and KIND_U at the caller of specified BATON.
If DEREF_SIZE is not -1 then use DW_AT_call_data_value instead of
DW_AT_call_value. */
void push_dwarf_reg_entry_value (call_site_parameter_kind kind,
call_site_parameter_u kind_u,
int deref_size);
/* Read LENGTH bytes at ADDR into BUF. This method also handles the
case where a caller of the evaluator passes in some data,
but with the address being 0. In this situation, we arrange for
memory reads to come from the passed-in buffer. */
void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length);
};
Move frame context info to dwarf_expr_context Following 15 patches in this patch series is cleaning up the design of the DWARF expression evaluator (dwarf_expr_context) to make future extensions of that evaluator easier and cleaner to implement. There are three subclasses of the dwarf_expr_context class (dwarf_expr_executor, dwarf_evaluate_loc_desc and evaluate_for_locexpr_baton). Here is a short description of each class: - dwarf_expr_executor is evaluating a DWARF expression in a context of a Call Frame Information. The overridden methods of this subclass report an error if a specific DWARF operation, represented by that method, is not allowed in a CFI context. The source code of this subclass lacks the support for composite as well as implicit pointer location description. - dwarf_evaluate_loc_desc can evaluate any expression with no restrictions. All of the methods that this subclass overrides are actually doing what they are intended to do. This subclass contains a full support for all location description types. - evaluate_for_locexpr_baton subclass is a specialization of the dwarf_evaluate_loc_desc subclass and it's function is to add support for passed in buffers. This seems to be a way to go around the fact that DWARF standard lacks a bit offset support for memory location descriptions as well as using any location description for the push object address functionality. It all comes down to this question: what is a function of a DWARF expression evaluator? Is it to evaluate the expression in a given context or to check the correctness of that expression in that context? Currently, the only reason why there is a dwarf_expr_executor subclass is to report an invalid DWARF expression in a context of a CFI, but is that what the evaluator is supposed to do considering that the evaluator is not tied to a given DWARF version? There are more and more vendor and GNU extensions that are not part of the DWARF standard, so is it that impossible to expect that some of the extensions could actually lift the previously imposed restrictions of the CFI context? Not to mention that every new DWARF version is lifting some restrictions anyway. The thing that makes more sense for an evaluator to do, is to take the context of an evaluation and checks the requirements of every operation evaluated against that context. With this approach, the evaluator would report an error only if parts of the context, necessary for the evaluation, are missing. If this approach is taken, then the unification of the dwarf_evaluate_loc_desc, dwarf_expr_executor and dwarf_expr_context is the next logical step. This makes a design of the DWARF expression evaluator cleaner and allows more flexibility when supporting future vendor and GNU extensions. Additional benefit here is that now all evaluators have access to all location description types, which means that a vendor extended CFI rules could support composite location description as well. This also means that a new evaluator interface can be changed to return a single struct value (that describes the result of the evaluation) instead of a caller poking around the dwarf_expr_context internal data for answers (like it is done currently). This patch starts the merging process by moving the frame context information and support from dwarf_expr_executor and dwarf_evaluate_loc_desc to dwarf_expr_context evaluator. The idea is to report an error when a given operation requires a frame information to be resolved, if that information is not present. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_frame): New function. (read_addr_from_reg): Add from frame.c. (dwarf_expr_context::dwarf_expr_context): Add frame info to dwarf_expr_context. (dwarf_expr_context::read_addr_from_reg): Remove. (dwarf_expr_context::get_reg_value): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_frame_base): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::execute_stack_op): Call frame context info check. Remove use of read_addr_from_reg method. * dwarf2/expr.h (struct dwarf_expr_context): Add frame info member, read_addr_from_reg, get_reg_value and get_frame_base declaration. (read_addr_from_reg): Move to expr.c. * dwarf2/frame.c (read_addr_from_reg): Move to dwarf_expr_context. (dwarf_expr_executor::read_addr_from_reg): Remove. (dwarf_expr_executor::get_frame_base): Remove. (dwarf_expr_executor::get_reg_value): Remove. (execute_stack_op): Use read_addr_from_reg function instead of read_addr_from_reg method. * dwarf2/loc.c (dwarf_evaluate_loc_desc::get_frame_base): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::get_reg_value): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::read_addr_from_reg): Remove. (dwarf2_locexpr_baton_eval):Use read_addr_from_reg function instead of read_addr_from_reg method.
2020-09-14 23:05:14 +08:00
/* Return the value of register number REG (a DWARF register number),
read as an address in a given FRAME. */
CORE_ADDR read_addr_from_reg (frame_info *frame, int reg);
void dwarf_expr_require_composition (const gdb_byte *, const gdb_byte *,
const char *);
gdb/ Implement basic support for DW_TAG_GNU_call_site. * block.c: Include gdbtypes.h and exceptions.h. (call_site_for_pc): New function. * block.h (call_site_for_pc): New declaration. * defs.h: Include hashtab.h. (make_cleanup_htab_delete, core_addr_hash, core_addr_eq): New declarations. * dwarf2-frame.c (dwarf2_frame_ctx_funcs): Install ctx_no_push_dwarf_reg_entry_value. * dwarf2expr.c (read_uleb128, read_sleb128): Support R as NULL. (dwarf_block_to_dwarf_reg): New function. (execute_stack_op) <DW_OP_GNU_entry_value>: Implement it. (ctx_no_push_dwarf_reg_entry_value): New function. * dwarf2expr.h (struct dwarf_expr_context_funcs): New field push_dwarf_reg_entry_value. (ctx_no_push_dwarf_reg_entry_value, dwarf_block_to_dwarf_reg): New declarations. * dwarf2loc.c: Include gdbcmd.h. (dwarf_expr_ctx_funcs): New forward declaration. (entry_values_debug, show_entry_values_debug, call_site_to_target_addr) (dwarf_expr_reg_to_entry_parameter) (dwarf_expr_push_dwarf_reg_entry_value): New. (dwarf_expr_ctx_funcs): Install dwarf_expr_push_dwarf_reg_entry_value. (dwarf2_evaluate_loc_desc_full): Handle NO_ENTRY_VALUE_ERROR. (needs_dwarf_reg_entry_value): New function. (needs_frame_ctx_funcs): Install it. (_initialize_dwarf2loc): New function. * dwarf2loc.h (entry_values_debug): New declaration. * dwarf2read.c (struct dwarf2_cu): New field call_site_htab. (read_call_site_scope): New forward declaration. (process_full_comp_unit): Copy call_site_htab. (process_die): Support DW_TAG_GNU_call_site. (read_call_site_scope): New function. (dwarf2_get_pc_bounds): Support NULL HIGHPC. (dwarf_tag_name): Support DW_TAG_GNU_call_site. (cleanup_htab): Delete. (write_psymtabs_to_index): Use make_cleanup_htab_delete instead of it. * exceptions.h (enum errors): New NO_ENTRY_VALUE_ERROR. * gdb-gdb.py (StructMainTypePrettyPrinter): Support FIELD_LOC_KIND_DWARF_BLOCK. * gdbtypes.h (enum field_loc_kind): New entry FIELD_LOC_KIND_DWARF_BLOCK. (struct main_type): New loc entry dwarf_block. (struct call_site, FIELD_DWARF_BLOCK, SET_FIELD_DWARF_BLOCK) (TYPE_FIELD_DWARF_BLOCK): New. * python/py-type.c: Include dwarf2loc.h. (check_types_equal): Support FIELD_LOC_KIND_DWARF_BLOCK. New internal_error call on unknown FIELD_LOC_KIND. * symtab.h (struct symtab): New field call_site_htab. * utils.c (do_htab_delete_cleanup, make_cleanup_htab_delete) (core_addr_hash, core_addr_eq): New functions. gdb/testsuite/ Implement basic support for DW_TAG_GNU_call_site. * gdb.arch/Makefile.in (EXECUTABLES): Add amd64-entry-value. * gdb.arch/amd64-entry-value.cc: New file. * gdb.arch/amd64-entry-value.exp: New file.
2011-10-10 03:21:39 +08:00
int dwarf_block_to_dwarf_reg (const gdb_byte *buf, const gdb_byte *buf_end);
gdb/ Display @entry parameter values even for references. * ada-valprint.c (ada_val_print_1) <TYPE_CODE_REF>: Try also coerce_ref_if_computed. * c-valprint.c (c_val_print) <TYPE_CODE_REF>: Likewise. * dwarf2expr.c (dwarf_block_to_dwarf_reg_deref): New function. (execute_stack_op) <DW_OP_GNU_entry_value>: Add -1 deref_size to the existing push_dwarf_reg_entry_value call. Add new detection calling dwarf_block_to_dwarf_reg_deref. Update the error message. (ctx_no_push_dwarf_reg_entry_value): New parameter deref_size. * dwarf2expr.h (struct dwarf_expr_context_funcs) <push_dwarf_reg_entry_value>: Add new parameter deref_size, describe it in the comment. (ctx_no_push_dwarf_reg_entry_value): Add new parameter deref_size. (dwarf_block_to_dwarf_reg_deref): New declaration. * dwarf2loc.c (dwarf_entry_parameter_to_value): Add new parameter deref_size, describe it in the function comment. New variables data_src and size, fetch the alternative block accoring to DEREF_SIZE. (dwarf_expr_push_dwarf_reg_entry_value): Add new parameter deref_size, describe it in the function comment. Fetch the alternative block accoring to DEREF_SIZE. (entry_data_value_coerce_ref, entry_data_value_copy_closure) (entry_data_value_free_closure, entry_data_value_funcs): New. (value_of_dwarf_reg_entry): New variables checked_type, target_type, outer_val, target_val, val and addr. Try to fetch and create also referenced value content. (pieced_value_funcs): NULL value for coerce_ref. (needs_dwarf_reg_entry_value): Add new parameter deref_size. * f-valprint.c (f_val_print) <TYPE_CODE_REF>: Try also coerce_ref_if_computed. * opencl-lang.c (opencl_value_funcs): NULL value for coerce_ref. * p-valprint.c (pascal_val_print) <TYPE_CODE_REF>: Likewise. * stack.c (read_frame_arg): Compare also dereferenced values. * value.c (value_computed_funcs): Make the parameter v const, use value_lval_const for it. (value_lval_const, coerce_ref_if_computed): New function. (coerce_ref): New variable retval. Call also coerce_ref_if_computed. * value.h (struct lval_funcs): New field coerce_ref. (value_computed_funcs): Make the parameter v const. (value_lval_const, coerce_ref_if_computed): New declarations. gdb/testsuite/ Display @entry parameter values even for references. * gdb.arch/amd64-entry-value.cc (reference, datap, datap_input): New functions. (main): New variables regvar, nodatavarp, stackvar1, stackvar2. Call reference and datap_input. * gdb.arch/amd64-entry-value.exp (reference, breakhere_reference): New breakpoints. (continue to breakpoint: entry_reference: reference) (entry_reference: bt at entry) (continue to breakpoint: entry_reference: breakhere_reference) (entry_reference: bt, entry_reference: ptype regparam) (entry_reference: p regparam, entry_reference: ptype regparam@entry) (entry_reference: p regparam@entry, entry_reference: p &regparam@entry) (entry_reference: p regcopy, entry_reference: p nodataparam) (entry_reference: p nodataparam@entry): New tests.
2011-10-10 03:43:41 +08:00
int dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf,
const gdb_byte *buf_end,
CORE_ADDR *deref_size_return);
gdb/ Display @entry parameter values (without references). * dwarf2expr.c (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): New functions. * dwarf2expr.h (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): New declarations. * dwarf2loc.c (dwarf2_find_location_expression): Support location list entry record. (dwarf_entry_parameter_to_value, value_of_dwarf_reg_entry) (value_of_dwarf_block_entry, locexpr_read_variable_at_entry): New functions. (dwarf2_locexpr_funcs): Install locexpr_read_variable_at_entry. (loclist_read_variable_at_entry): New function. (dwarf2_loclist_funcs): Install loclist_read_variable_at_entry. * dwarf2read.c (read_call_site_scope): Support also DW_OP_fbreg in DW_AT_location, call dwarf_block_to_sp_offset for it. * frame.h (print_entry_values_no, print_entry_values_only) (print_entry_values_preferred, print_entry_values_if_needed) (print_entry_values_both, print_entry_values_compact) (print_entry_values_default, print_entry_values): New declarations. (struct frame_arg): New field entry_kind. (read_frame_arg): New parameter entryargp. * mi/mi-cmd-stack.c (list_arg_or_local): New gdb_assert for arg->entry_kind. Optionally print the `@entry' suffix. (list_args_or_locals): New variable entryarg, initialize it. Initialize also entry_kind of arg and entryarg. Conditionalize list_arg_or_local for arg, add list_arg_or_local for entryarg. Call xfree for entryarg.error. * stack.c (print_entry_values_no, print_entry_values_only) (print_entry_values_preferred, print_entry_values_if_needed) (print_entry_values_both, print_entry_values_compact) (print_entry_values_default, print_entry_values_choices) (print_entry_values): New variables. (print_frame_arg): New gdb_assert for arg->entry_kind. Optionally print the `@entry' suffix, possibly in combination for print_entry_values_compact. (read_frame_arg): New parameter entryargp, new variables entryval, entryval_error and val_equal. Read in also entryargp, respect print_entry_values, compare the values using val_equal, fill in also argp->entry_kind (together with entryargp->entry_kind). (print_frame_args): New variable entryarg, initialize it. Conditionalize print_frame_arg for arg, add print_frame_arg for entryarg. Call xfree for entryarg.error. (_initialize_stack): Call add_setshow_enum_cmd for `entry-values'. * symtab.h (struct symbol_computed_ops): New field read_variable_at_entry. gdb/doc/ Display @entry parameter values (without references). * gdb.texinfo (Tail Call Frames): Add anchor. Add self tail call example. (Print Settings): New description of set print entry-values and show print entry-values. gdb/testsuite/ Display @entry parameter values (without references). * gdb.arch/amd64-entry-value.cc (locexpr, stacktest, data, data2) (different, validity, invalid): New functions. (main): Call them. * gdb.arch/amd64-entry-value.exp: New breakpoints breakhere_locexpr, stacktest, breakhere_stacktest, different, breakhere_different, breakhere_validity and breakhere_invalid. (entry: bt): Update for @entry. (entry_locexpr: *, entry_stack: *, entry_equal: *, entry_different: *) (entry_validity: *, entry_invalid: *): Many new tests. * gdb.base/break.exp (run until breakpoint set at small function, optimized file): Accept also the @entry suffix. * gdb.mi/Makefile.in (PROGS): Add mi2-amd64-entry-value. * gdb.mi/mi2-amd64-entry-value.c: New files. * gdb.mi/mi2-amd64-entry-value.exp: New files.
2011-10-10 03:34:19 +08:00
int dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
CORE_ADDR *fb_offset_return);
int dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
const gdb_byte *buf_end,
CORE_ADDR *sp_offset_return);
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
/* Wrappers around the leb128 reader routines to simplify them for our
purposes. */
static inline const gdb_byte *
gdb_read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
uint64_t *r)
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
{
size_t bytes_read = read_uleb128_to_uint64 (buf, buf_end, r);
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
if (bytes_read == 0)
return NULL;
return buf + bytes_read;
}
static inline const gdb_byte *
gdb_read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
int64_t *r)
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
{
size_t bytes_read = read_sleb128_to_int64 (buf, buf_end, r);
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
if (bytes_read == 0)
return NULL;
return buf + bytes_read;
}
static inline const gdb_byte *
gdb_skip_leb128 (const gdb_byte *buf, const gdb_byte *buf_end)
{
size_t bytes_read = skip_leb128 (buf, buf_end);
if (bytes_read == 0)
return NULL;
return buf + bytes_read;
}
extern const gdb_byte *safe_read_uleb128 (const gdb_byte *buf,
const gdb_byte *buf_end,
uint64_t *r);
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
extern const gdb_byte *safe_read_sleb128 (const gdb_byte *buf,
const gdb_byte *buf_end,
int64_t *r);
* dwarf2-frame.c (struct dwarf2_cie): Make initial_instructions, end "const gdb_byte *". (struct dwarf2_fde): Make instructions, end "const gdb_byte *". (execute_cfa_program): Update to match API of leb128 functions. (read_1_byte, read_4_bytes, read_8_bytes): Make buf parameter "const gdb_byte *". (read_unsigned_leb128, read_signed_leb128): Delete. (read_initial_length): Change type of buf argument to "const gdb_byte *". (read_encoded_value): Update to match API of leb128 functions. (decode_frame_entry): Change result to "const gdb_byte *", and similarly for "start" parameter. (decode_frame_entry_1): Ditto. Use new leb128 reader functions. (dwarf2_build_frame_info): Change local frame_ptr to "const gdb_byte *". * dwarf2expr.c (safe_read_uleb128, safe_read_sleb128): Replaces read_uleb128, read_sleb128. All callers updated. (safe_skip_leb128): New function. (dwarf_block_to_dwarf_reg): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_skip_leb128 instead of read_uleb128. (dwarf_block_to_dwarf_reg_deref): Update to match API of leb128 functions. Call gdb_read_uleb128, gdb_read_sleb128 instead of read_uleb128, read_sleb128. (dwarf_block_to_fb_offset, dwarf_block_to_sp_offset): Ditto. (execute_stack_op): Update to match API of leb128 functions. * dwarf2expr.h: #include "leb128.h". (read_uleb128, read_sleb128): Delete. (gdb_read_uleb128, gdb_read_sleb128, gdb_skip_leb128): New functions. (safe_read_uleb128, safe_read_sleb128, safe_skip_leb128): Declare. * dwarf2loc.c (debug_loc_kind): New enum. (decode_debug_loc_addresses): New function. (decode_debug_loc_dwo_addresses): New function. (dwarf2_find_location_expression): Rewrite. (dwarf2_compile_expr_to_ax): Update to match API of leb128 functions. (locexpr_describe_location_piece): Ditto. (disassemble_dwarf_expression): Ditto. (locexpr_describe_location_1): Ditto. (loclist_describe_location): Rewrite. * dwarf2loc.h (dwarf2_loclist_baton): New member "from_dwo". * dwarf2read.c (die_reader_specs): New member "buffer_end". (dwarf2_section_buffer_overflow_complaint): Renamed from dwarf2_macros_too_long_complaint. All callers updated. (skip_leb128): Delete. (init_cu_die_reader): Initialize reader->buffer_end. (skip_one_die): Replace call to skip_leb128 with safe_skip_leb128. (skip_form_bytes): New arg buffer_end. All callers updated. Replace call to skip_leb128 with gdb_skip_leb128. (skip_unknown_opcode): New arg mac_end. All callers updated. (fill_in_loclist_baton): Initialize baton->from_dwo.
2012-05-23 02:45:22 +08:00
extern const gdb_byte *safe_skip_leb128 (const gdb_byte *buf,
const gdb_byte *buf_end);
#endif /* DWARF2EXPR_H */