mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-24 12:35:55 +08:00
dda83cd783
Many spots incorrectly use only spaces for indentation (for example, there are a lot of spots in ada-lang.c). I've always found it awkward when I needed to edit one of these spots: do I keep the original wrong indentation, or do I fix it? What if the lines around it are also wrong, do I fix them too? I probably don't want to fix them in the same patch, to avoid adding noise to my patch. So I propose to fix as much as possible once and for all (hopefully). One typical counter argument for this is that it makes code archeology more difficult, because git-blame will show this commit as the last change for these lines. My counter counter argument is: when git-blaming, you often need to do "blame the file at the parent commit" anyway, to go past some other refactor that touched the line you are interested in, but is not the change you are looking for. So you already need a somewhat efficient way to do this. Using some interactive tool, rather than plain git-blame, makes this trivial. For example, I use "tig blame <file>", where going back past the commit that changed the currently selected line is one keystroke. It looks like Magit in Emacs does it too (though I've never used it). Web viewers of Github and Gitlab do it too. My point is that it won't really make archeology more difficult. The other typical counter argument is that it will cause conflicts with existing patches. That's true... but it's a one time cost, and those are not conflicts that are difficult to resolve. I have also tried "git rebase --ignore-whitespace", it seems to work well. Although that will re-introduce the faulty indentation, so one needs to take care of fixing the indentation in the patch after that (which is easy). gdb/ChangeLog: * aarch64-linux-tdep.c: Fix indentation. * aarch64-ravenscar-thread.c: Fix indentation. * aarch64-tdep.c: Fix indentation. * aarch64-tdep.h: Fix indentation. * ada-lang.c: Fix indentation. * ada-lang.h: Fix indentation. * ada-tasks.c: Fix indentation. * ada-typeprint.c: Fix indentation. * ada-valprint.c: Fix indentation. * ada-varobj.c: Fix indentation. * addrmap.c: Fix indentation. * addrmap.h: Fix indentation. * agent.c: Fix indentation. * aix-thread.c: Fix indentation. * alpha-bsd-nat.c: Fix indentation. * alpha-linux-tdep.c: Fix indentation. * alpha-mdebug-tdep.c: Fix indentation. * alpha-nbsd-tdep.c: Fix indentation. * alpha-obsd-tdep.c: Fix indentation. * alpha-tdep.c: Fix indentation. * amd64-bsd-nat.c: Fix indentation. * amd64-darwin-tdep.c: Fix indentation. * amd64-linux-nat.c: Fix indentation. * amd64-linux-tdep.c: Fix indentation. * amd64-nat.c: Fix indentation. * amd64-obsd-tdep.c: Fix indentation. * amd64-tdep.c: Fix indentation. * amd64-windows-tdep.c: Fix indentation. * annotate.c: Fix indentation. * arc-tdep.c: Fix indentation. * arch-utils.c: Fix indentation. * arch/arm-get-next-pcs.c: Fix indentation. * arch/arm.c: Fix indentation. * arm-linux-nat.c: Fix indentation. * arm-linux-tdep.c: Fix indentation. * arm-nbsd-tdep.c: Fix indentation. * arm-pikeos-tdep.c: Fix indentation. * arm-tdep.c: Fix indentation. * arm-tdep.h: Fix indentation. * arm-wince-tdep.c: Fix indentation. * auto-load.c: Fix indentation. * auxv.c: Fix indentation. * avr-tdep.c: Fix indentation. * ax-gdb.c: Fix indentation. * ax-general.c: Fix indentation. * bfin-linux-tdep.c: Fix indentation. * block.c: Fix indentation. * block.h: Fix indentation. * blockframe.c: Fix indentation. * bpf-tdep.c: Fix indentation. * break-catch-sig.c: Fix indentation. * break-catch-syscall.c: Fix indentation. * break-catch-throw.c: Fix indentation. * breakpoint.c: Fix indentation. * breakpoint.h: Fix indentation. * bsd-uthread.c: Fix indentation. * btrace.c: Fix indentation. * build-id.c: Fix indentation. * buildsym-legacy.h: Fix indentation. * buildsym.c: Fix indentation. * c-typeprint.c: Fix indentation. * c-valprint.c: Fix indentation. * c-varobj.c: Fix indentation. * charset.c: Fix indentation. * cli/cli-cmds.c: Fix indentation. * cli/cli-decode.c: Fix indentation. * cli/cli-decode.h: Fix indentation. * cli/cli-script.c: Fix indentation. * cli/cli-setshow.c: Fix indentation. * coff-pe-read.c: Fix indentation. * coffread.c: Fix indentation. * compile/compile-cplus-types.c: Fix indentation. * compile/compile-object-load.c: Fix indentation. * compile/compile-object-run.c: Fix indentation. * completer.c: Fix indentation. * corefile.c: Fix indentation. * corelow.c: Fix indentation. * cp-abi.h: Fix indentation. * cp-namespace.c: Fix indentation. * cp-support.c: Fix indentation. * cp-valprint.c: Fix indentation. * cris-linux-tdep.c: Fix indentation. * cris-tdep.c: Fix indentation. * darwin-nat-info.c: Fix indentation. * darwin-nat.c: Fix indentation. * darwin-nat.h: Fix indentation. * dbxread.c: Fix indentation. * dcache.c: Fix indentation. * disasm.c: Fix indentation. * dtrace-probe.c: Fix indentation. * dwarf2/abbrev.c: Fix indentation. * dwarf2/attribute.c: Fix indentation. * dwarf2/expr.c: Fix indentation. * dwarf2/frame.c: Fix indentation. * dwarf2/index-cache.c: Fix indentation. * dwarf2/index-write.c: Fix indentation. * dwarf2/line-header.c: Fix indentation. * dwarf2/loc.c: Fix indentation. * dwarf2/macro.c: Fix indentation. * dwarf2/read.c: Fix indentation. * dwarf2/read.h: Fix indentation. * elfread.c: Fix indentation. * eval.c: Fix indentation. * event-top.c: Fix indentation. * exec.c: Fix indentation. * exec.h: Fix indentation. * expprint.c: Fix indentation. * f-lang.c: Fix indentation. * f-typeprint.c: Fix indentation. * f-valprint.c: Fix indentation. * fbsd-nat.c: Fix indentation. * fbsd-tdep.c: Fix indentation. * findvar.c: Fix indentation. * fork-child.c: Fix indentation. * frame-unwind.c: Fix indentation. * frame-unwind.h: Fix indentation. * frame.c: Fix indentation. * frv-linux-tdep.c: Fix indentation. * frv-tdep.c: Fix indentation. * frv-tdep.h: Fix indentation. * ft32-tdep.c: Fix indentation. * gcore.c: Fix indentation. * gdb_bfd.c: Fix indentation. * gdbarch.sh: Fix indentation. * gdbarch.c: Re-generate * gdbarch.h: Re-generate. * gdbcore.h: Fix indentation. * gdbthread.h: Fix indentation. * gdbtypes.c: Fix indentation. * gdbtypes.h: Fix indentation. * glibc-tdep.c: Fix indentation. * gnu-nat.c: Fix indentation. * gnu-nat.h: Fix indentation. * gnu-v2-abi.c: Fix indentation. * gnu-v3-abi.c: Fix indentation. * go32-nat.c: Fix indentation. * guile/guile-internal.h: Fix indentation. * guile/scm-cmd.c: Fix indentation. * guile/scm-frame.c: Fix indentation. * guile/scm-iterator.c: Fix indentation. * guile/scm-math.c: Fix indentation. * guile/scm-ports.c: Fix indentation. * guile/scm-pretty-print.c: Fix indentation. * guile/scm-value.c: Fix indentation. * h8300-tdep.c: Fix indentation. * hppa-linux-nat.c: Fix indentation. * hppa-linux-tdep.c: Fix indentation. * hppa-nbsd-nat.c: Fix indentation. * hppa-nbsd-tdep.c: Fix indentation. * hppa-obsd-nat.c: Fix indentation. * hppa-tdep.c: Fix indentation. * hppa-tdep.h: Fix indentation. * i386-bsd-nat.c: Fix indentation. * i386-darwin-nat.c: Fix indentation. * i386-darwin-tdep.c: Fix indentation. * i386-dicos-tdep.c: Fix indentation. * i386-gnu-nat.c: Fix indentation. * i386-linux-nat.c: Fix indentation. * i386-linux-tdep.c: Fix indentation. * i386-nto-tdep.c: Fix indentation. * i386-obsd-tdep.c: Fix indentation. * i386-sol2-nat.c: Fix indentation. * i386-tdep.c: Fix indentation. * i386-tdep.h: Fix indentation. * i386-windows-tdep.c: Fix indentation. * i387-tdep.c: Fix indentation. * i387-tdep.h: Fix indentation. * ia64-libunwind-tdep.c: Fix indentation. * ia64-libunwind-tdep.h: Fix indentation. * ia64-linux-nat.c: Fix indentation. * ia64-linux-tdep.c: Fix indentation. * ia64-tdep.c: Fix indentation. * ia64-tdep.h: Fix indentation. * ia64-vms-tdep.c: Fix indentation. * infcall.c: Fix indentation. * infcmd.c: Fix indentation. * inferior.c: Fix indentation. * infrun.c: Fix indentation. * iq2000-tdep.c: Fix indentation. * language.c: Fix indentation. * linespec.c: Fix indentation. * linux-fork.c: Fix indentation. * linux-nat.c: Fix indentation. * linux-tdep.c: Fix indentation. * linux-thread-db.c: Fix indentation. * lm32-tdep.c: Fix indentation. * m2-lang.c: Fix indentation. * m2-typeprint.c: Fix indentation. * m2-valprint.c: Fix indentation. * m32c-tdep.c: Fix indentation. * m32r-linux-tdep.c: Fix indentation. * m32r-tdep.c: Fix indentation. * m68hc11-tdep.c: Fix indentation. * m68k-bsd-nat.c: Fix indentation. * m68k-linux-nat.c: Fix indentation. * m68k-linux-tdep.c: Fix indentation. * m68k-tdep.c: Fix indentation. * machoread.c: Fix indentation. * macrocmd.c: Fix indentation. * macroexp.c: Fix indentation. * macroscope.c: Fix indentation. * macrotab.c: Fix indentation. * macrotab.h: Fix indentation. * main.c: Fix indentation. * mdebugread.c: Fix indentation. * mep-tdep.c: Fix indentation. * mi/mi-cmd-catch.c: Fix indentation. * mi/mi-cmd-disas.c: Fix indentation. * mi/mi-cmd-env.c: Fix indentation. * mi/mi-cmd-stack.c: Fix indentation. * mi/mi-cmd-var.c: Fix indentation. * mi/mi-cmds.c: Fix indentation. * mi/mi-main.c: Fix indentation. * mi/mi-parse.c: Fix indentation. * microblaze-tdep.c: Fix indentation. * minidebug.c: Fix indentation. * minsyms.c: Fix indentation. * mips-linux-nat.c: Fix indentation. * mips-linux-tdep.c: Fix indentation. * mips-nbsd-tdep.c: Fix indentation. * mips-tdep.c: Fix indentation. * mn10300-linux-tdep.c: Fix indentation. * mn10300-tdep.c: Fix indentation. * moxie-tdep.c: Fix indentation. * msp430-tdep.c: Fix indentation. * namespace.h: Fix indentation. * nat/fork-inferior.c: Fix indentation. * nat/gdb_ptrace.h: Fix indentation. * nat/linux-namespaces.c: Fix indentation. * nat/linux-osdata.c: Fix indentation. * nat/netbsd-nat.c: Fix indentation. * nat/x86-dregs.c: Fix indentation. * nbsd-nat.c: Fix indentation. * nbsd-tdep.c: Fix indentation. * nios2-linux-tdep.c: Fix indentation. * nios2-tdep.c: Fix indentation. * nto-procfs.c: Fix indentation. * nto-tdep.c: Fix indentation. * objfiles.c: Fix indentation. * objfiles.h: Fix indentation. * opencl-lang.c: Fix indentation. * or1k-tdep.c: Fix indentation. * osabi.c: Fix indentation. * osabi.h: Fix indentation. * osdata.c: Fix indentation. * p-lang.c: Fix indentation. * p-typeprint.c: Fix indentation. * p-valprint.c: Fix indentation. * parse.c: Fix indentation. * ppc-linux-nat.c: Fix indentation. * ppc-linux-tdep.c: Fix indentation. * ppc-nbsd-nat.c: Fix indentation. * ppc-nbsd-tdep.c: Fix indentation. * ppc-obsd-nat.c: Fix indentation. * ppc-ravenscar-thread.c: Fix indentation. * ppc-sysv-tdep.c: Fix indentation. * ppc64-tdep.c: Fix indentation. * printcmd.c: Fix indentation. * proc-api.c: Fix indentation. * producer.c: Fix indentation. * producer.h: Fix indentation. * prologue-value.c: Fix indentation. * prologue-value.h: Fix indentation. * psymtab.c: Fix indentation. * python/py-arch.c: Fix indentation. * python/py-bpevent.c: Fix indentation. * python/py-event.c: Fix indentation. * python/py-event.h: Fix indentation. * python/py-finishbreakpoint.c: Fix indentation. * python/py-frame.c: Fix indentation. * python/py-framefilter.c: Fix indentation. * python/py-inferior.c: Fix indentation. * python/py-infthread.c: Fix indentation. * python/py-objfile.c: Fix indentation. * python/py-prettyprint.c: Fix indentation. * python/py-registers.c: Fix indentation. * python/py-signalevent.c: Fix indentation. * python/py-stopevent.c: Fix indentation. * python/py-stopevent.h: Fix indentation. * python/py-threadevent.c: Fix indentation. * python/py-tui.c: Fix indentation. * python/py-unwind.c: Fix indentation. * python/py-value.c: Fix indentation. * python/py-xmethods.c: Fix indentation. * python/python-internal.h: Fix indentation. * python/python.c: Fix indentation. * ravenscar-thread.c: Fix indentation. * record-btrace.c: Fix indentation. * record-full.c: Fix indentation. * record.c: Fix indentation. * reggroups.c: Fix indentation. * regset.h: Fix indentation. * remote-fileio.c: Fix indentation. * remote.c: Fix indentation. * reverse.c: Fix indentation. * riscv-linux-tdep.c: Fix indentation. * riscv-ravenscar-thread.c: Fix indentation. * riscv-tdep.c: Fix indentation. * rl78-tdep.c: Fix indentation. * rs6000-aix-tdep.c: Fix indentation. * rs6000-lynx178-tdep.c: Fix indentation. * rs6000-nat.c: Fix indentation. * rs6000-tdep.c: Fix indentation. * rust-lang.c: Fix indentation. * rx-tdep.c: Fix indentation. * s12z-tdep.c: Fix indentation. * s390-linux-tdep.c: Fix indentation. * score-tdep.c: Fix indentation. * ser-base.c: Fix indentation. * ser-mingw.c: Fix indentation. * ser-uds.c: Fix indentation. * ser-unix.c: Fix indentation. * serial.c: Fix indentation. * sh-linux-tdep.c: Fix indentation. * sh-nbsd-tdep.c: Fix indentation. * sh-tdep.c: Fix indentation. * skip.c: Fix indentation. * sol-thread.c: Fix indentation. * solib-aix.c: Fix indentation. * solib-darwin.c: Fix indentation. * solib-frv.c: Fix indentation. * solib-svr4.c: Fix indentation. * solib.c: Fix indentation. * source.c: Fix indentation. * sparc-linux-tdep.c: Fix indentation. * sparc-nbsd-tdep.c: Fix indentation. * sparc-obsd-tdep.c: Fix indentation. * sparc-ravenscar-thread.c: Fix indentation. * sparc-tdep.c: Fix indentation. * sparc64-linux-tdep.c: Fix indentation. * sparc64-nbsd-tdep.c: Fix indentation. * sparc64-obsd-tdep.c: Fix indentation. * sparc64-tdep.c: Fix indentation. * stabsread.c: Fix indentation. * stack.c: Fix indentation. * stap-probe.c: Fix indentation. * stubs/ia64vms-stub.c: Fix indentation. * stubs/m32r-stub.c: Fix indentation. * stubs/m68k-stub.c: Fix indentation. * stubs/sh-stub.c: Fix indentation. * stubs/sparc-stub.c: Fix indentation. * symfile-mem.c: Fix indentation. * symfile.c: Fix indentation. * symfile.h: Fix indentation. * symmisc.c: Fix indentation. * symtab.c: Fix indentation. * symtab.h: Fix indentation. * target-float.c: Fix indentation. * target.c: Fix indentation. * target.h: Fix indentation. * tic6x-tdep.c: Fix indentation. * tilegx-linux-tdep.c: Fix indentation. * tilegx-tdep.c: Fix indentation. * top.c: Fix indentation. * tracefile-tfile.c: Fix indentation. * tracepoint.c: Fix indentation. * tui/tui-disasm.c: Fix indentation. * tui/tui-io.c: Fix indentation. * tui/tui-regs.c: Fix indentation. * tui/tui-stack.c: Fix indentation. * tui/tui-win.c: Fix indentation. * tui/tui-winsource.c: Fix indentation. * tui/tui.c: Fix indentation. * typeprint.c: Fix indentation. * ui-out.h: Fix indentation. * unittests/copy_bitwise-selftests.c: Fix indentation. * unittests/memory-map-selftests.c: Fix indentation. * utils.c: Fix indentation. * v850-tdep.c: Fix indentation. * valarith.c: Fix indentation. * valops.c: Fix indentation. * valprint.c: Fix indentation. * valprint.h: Fix indentation. * value.c: Fix indentation. * value.h: Fix indentation. * varobj.c: Fix indentation. * vax-tdep.c: Fix indentation. * windows-nat.c: Fix indentation. * windows-tdep.c: Fix indentation. * xcoffread.c: Fix indentation. * xml-syscall.c: Fix indentation. * xml-tdesc.c: Fix indentation. * xstormy16-tdep.c: Fix indentation. * xtensa-config.c: Fix indentation. * xtensa-linux-nat.c: Fix indentation. * xtensa-linux-tdep.c: Fix indentation. * xtensa-tdep.c: Fix indentation. gdbserver/ChangeLog: * ax.cc: Fix indentation. * dll.cc: Fix indentation. * inferiors.h: Fix indentation. * linux-low.cc: Fix indentation. * linux-nios2-low.cc: Fix indentation. * linux-ppc-ipa.cc: Fix indentation. * linux-ppc-low.cc: Fix indentation. * linux-x86-low.cc: Fix indentation. * linux-xtensa-low.cc: Fix indentation. * regcache.cc: Fix indentation. * server.cc: Fix indentation. * tracepoint.cc: Fix indentation. gdbsupport/ChangeLog: * common-exceptions.h: Fix indentation. * event-loop.cc: Fix indentation. * fileio.cc: Fix indentation. * filestuff.cc: Fix indentation. * gdb-dlfcn.cc: Fix indentation. * gdb_string_view.h: Fix indentation. * job-control.cc: Fix indentation. * signals.cc: Fix indentation. Change-Id: I4bad7ae6be0fbe14168b8ebafb98ffe14964a695
1431 lines
38 KiB
C
1431 lines
38 KiB
C
/* DWARF 2 Expression Evaluator.
|
||
|
||
Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||
|
||
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/>. */
|
||
|
||
#include "defs.h"
|
||
#include "symtab.h"
|
||
#include "gdbtypes.h"
|
||
#include "value.h"
|
||
#include "gdbcore.h"
|
||
#include "dwarf2.h"
|
||
#include "dwarf2/expr.h"
|
||
#include "dwarf2/loc.h"
|
||
#include "dwarf2/read.h"
|
||
#include "gdbsupport/underlying.h"
|
||
#include "gdbarch.h"
|
||
|
||
/* Cookie for gdbarch data. */
|
||
|
||
static struct gdbarch_data *dwarf_arch_cookie;
|
||
|
||
/* This holds gdbarch-specific types used by the DWARF expression
|
||
evaluator. See comments in execute_stack_op. */
|
||
|
||
struct dwarf_gdbarch_types
|
||
{
|
||
struct type *dw_types[3];
|
||
};
|
||
|
||
/* Allocate and fill in dwarf_gdbarch_types for an arch. */
|
||
|
||
static void *
|
||
dwarf_gdbarch_types_init (struct gdbarch *gdbarch)
|
||
{
|
||
struct dwarf_gdbarch_types *types
|
||
= GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf_gdbarch_types);
|
||
|
||
/* The types themselves are lazily initialized. */
|
||
|
||
return types;
|
||
}
|
||
|
||
/* Return the type used for DWARF operations where the type is
|
||
unspecified in the DWARF spec. Only certain sizes are
|
||
supported. */
|
||
|
||
struct type *
|
||
dwarf_expr_context::address_type () const
|
||
{
|
||
struct dwarf_gdbarch_types *types
|
||
= (struct dwarf_gdbarch_types *) gdbarch_data (this->gdbarch,
|
||
dwarf_arch_cookie);
|
||
int ndx;
|
||
|
||
if (this->addr_size == 2)
|
||
ndx = 0;
|
||
else if (this->addr_size == 4)
|
||
ndx = 1;
|
||
else if (this->addr_size == 8)
|
||
ndx = 2;
|
||
else
|
||
error (_("Unsupported address size in DWARF expressions: %d bits"),
|
||
8 * this->addr_size);
|
||
|
||
if (types->dw_types[ndx] == NULL)
|
||
types->dw_types[ndx]
|
||
= arch_integer_type (this->gdbarch,
|
||
8 * this->addr_size,
|
||
0, "<signed DWARF address type>");
|
||
|
||
return types->dw_types[ndx];
|
||
}
|
||
|
||
/* Create a new context for the expression evaluator. */
|
||
|
||
dwarf_expr_context::dwarf_expr_context (dwarf2_per_objfile *per_objfile)
|
||
: gdbarch (NULL),
|
||
addr_size (0),
|
||
ref_addr_size (0),
|
||
recursion_depth (0),
|
||
max_recursion_depth (0x100),
|
||
location (DWARF_VALUE_MEMORY),
|
||
len (0),
|
||
data (NULL),
|
||
initialized (0),
|
||
per_objfile (per_objfile)
|
||
{
|
||
}
|
||
|
||
/* Push VALUE onto the stack. */
|
||
|
||
void
|
||
dwarf_expr_context::push (struct value *value, bool in_stack_memory)
|
||
{
|
||
stack.emplace_back (value, in_stack_memory);
|
||
}
|
||
|
||
/* Push VALUE onto the stack. */
|
||
|
||
void
|
||
dwarf_expr_context::push_address (CORE_ADDR value, bool in_stack_memory)
|
||
{
|
||
push (value_from_ulongest (address_type (), value), in_stack_memory);
|
||
}
|
||
|
||
/* Pop the top item off of the stack. */
|
||
|
||
void
|
||
dwarf_expr_context::pop ()
|
||
{
|
||
if (stack.empty ())
|
||
error (_("dwarf expression stack underflow"));
|
||
|
||
stack.pop_back ();
|
||
}
|
||
|
||
/* Retrieve the N'th item on the stack. */
|
||
|
||
struct value *
|
||
dwarf_expr_context::fetch (int n)
|
||
{
|
||
if (stack.size () <= n)
|
||
error (_("Asked for position %d of stack, "
|
||
"stack only has %zu elements on it."),
|
||
n, stack.size ());
|
||
return stack[stack.size () - (1 + n)].value;
|
||
}
|
||
|
||
/* Require that TYPE be an integral type; throw an exception if not. */
|
||
|
||
static void
|
||
dwarf_require_integral (struct type *type)
|
||
{
|
||
if (type->code () != TYPE_CODE_INT
|
||
&& type->code () != TYPE_CODE_CHAR
|
||
&& type->code () != TYPE_CODE_BOOL)
|
||
error (_("integral type expected in DWARF expression"));
|
||
}
|
||
|
||
/* Return the unsigned form of TYPE. TYPE is necessarily an integral
|
||
type. */
|
||
|
||
static struct type *
|
||
get_unsigned_type (struct gdbarch *gdbarch, struct type *type)
|
||
{
|
||
switch (TYPE_LENGTH (type))
|
||
{
|
||
case 1:
|
||
return builtin_type (gdbarch)->builtin_uint8;
|
||
case 2:
|
||
return builtin_type (gdbarch)->builtin_uint16;
|
||
case 4:
|
||
return builtin_type (gdbarch)->builtin_uint32;
|
||
case 8:
|
||
return builtin_type (gdbarch)->builtin_uint64;
|
||
default:
|
||
error (_("no unsigned variant found for type, while evaluating "
|
||
"DWARF expression"));
|
||
}
|
||
}
|
||
|
||
/* Return the signed form of TYPE. TYPE is necessarily an integral
|
||
type. */
|
||
|
||
static struct type *
|
||
get_signed_type (struct gdbarch *gdbarch, struct type *type)
|
||
{
|
||
switch (TYPE_LENGTH (type))
|
||
{
|
||
case 1:
|
||
return builtin_type (gdbarch)->builtin_int8;
|
||
case 2:
|
||
return builtin_type (gdbarch)->builtin_int16;
|
||
case 4:
|
||
return builtin_type (gdbarch)->builtin_int32;
|
||
case 8:
|
||
return builtin_type (gdbarch)->builtin_int64;
|
||
default:
|
||
error (_("no signed variant found for type, while evaluating "
|
||
"DWARF expression"));
|
||
}
|
||
}
|
||
|
||
/* Retrieve the N'th item on the stack, converted to an address. */
|
||
|
||
CORE_ADDR
|
||
dwarf_expr_context::fetch_address (int n)
|
||
{
|
||
struct value *result_val = fetch (n);
|
||
enum bfd_endian byte_order = gdbarch_byte_order (this->gdbarch);
|
||
ULONGEST result;
|
||
|
||
dwarf_require_integral (value_type (result_val));
|
||
result = extract_unsigned_integer (value_contents (result_val),
|
||
TYPE_LENGTH (value_type (result_val)),
|
||
byte_order);
|
||
|
||
/* For most architectures, calling extract_unsigned_integer() alone
|
||
is sufficient for extracting an address. However, some
|
||
architectures (e.g. MIPS) use signed addresses and using
|
||
extract_unsigned_integer() will not produce a correct
|
||
result. Make sure we invoke gdbarch_integer_to_address()
|
||
for those architectures which require it. */
|
||
if (gdbarch_integer_to_address_p (this->gdbarch))
|
||
{
|
||
gdb_byte *buf = (gdb_byte *) alloca (this->addr_size);
|
||
struct type *int_type = get_unsigned_type (this->gdbarch,
|
||
value_type (result_val));
|
||
|
||
store_unsigned_integer (buf, this->addr_size, byte_order, result);
|
||
return gdbarch_integer_to_address (this->gdbarch, int_type, buf);
|
||
}
|
||
|
||
return (CORE_ADDR) result;
|
||
}
|
||
|
||
/* Retrieve the in_stack_memory flag of the N'th item on the stack. */
|
||
|
||
bool
|
||
dwarf_expr_context::fetch_in_stack_memory (int n)
|
||
{
|
||
if (stack.size () <= n)
|
||
error (_("Asked for position %d of stack, "
|
||
"stack only has %zu elements on it."),
|
||
n, stack.size ());
|
||
return stack[stack.size () - (1 + n)].in_stack_memory;
|
||
}
|
||
|
||
/* Return true if the expression stack is empty. */
|
||
|
||
bool
|
||
dwarf_expr_context::stack_empty_p () const
|
||
{
|
||
return stack.empty ();
|
||
}
|
||
|
||
/* Add a new piece to the dwarf_expr_context's piece list. */
|
||
void
|
||
dwarf_expr_context::add_piece (ULONGEST size, ULONGEST offset)
|
||
{
|
||
this->pieces.emplace_back ();
|
||
dwarf_expr_piece &p = this->pieces.back ();
|
||
|
||
p.location = this->location;
|
||
p.size = size;
|
||
p.offset = offset;
|
||
|
||
if (p.location == DWARF_VALUE_LITERAL)
|
||
{
|
||
p.v.literal.data = this->data;
|
||
p.v.literal.length = this->len;
|
||
}
|
||
else if (stack_empty_p ())
|
||
{
|
||
p.location = DWARF_VALUE_OPTIMIZED_OUT;
|
||
/* Also reset the context's location, for our callers. This is
|
||
a somewhat strange approach, but this lets us avoid setting
|
||
the location to DWARF_VALUE_MEMORY in all the individual
|
||
cases in the evaluator. */
|
||
this->location = DWARF_VALUE_OPTIMIZED_OUT;
|
||
}
|
||
else if (p.location == DWARF_VALUE_MEMORY)
|
||
{
|
||
p.v.mem.addr = fetch_address (0);
|
||
p.v.mem.in_stack_memory = fetch_in_stack_memory (0);
|
||
}
|
||
else if (p.location == DWARF_VALUE_IMPLICIT_POINTER)
|
||
{
|
||
p.v.ptr.die_sect_off = (sect_offset) this->len;
|
||
p.v.ptr.offset = value_as_long (fetch (0));
|
||
}
|
||
else if (p.location == DWARF_VALUE_REGISTER)
|
||
p.v.regno = value_as_long (fetch (0));
|
||
else
|
||
{
|
||
p.v.value = fetch (0);
|
||
}
|
||
}
|
||
|
||
/* Evaluate the expression at ADDR (LEN bytes long). */
|
||
|
||
void
|
||
dwarf_expr_context::eval (const gdb_byte *addr, size_t len)
|
||
{
|
||
int old_recursion_depth = this->recursion_depth;
|
||
|
||
execute_stack_op (addr, addr + len);
|
||
|
||
/* RECURSION_DEPTH becomes invalid if an exception was thrown here. */
|
||
|
||
gdb_assert (this->recursion_depth == old_recursion_depth);
|
||
}
|
||
|
||
/* Helper to read a uleb128 value or throw an error. */
|
||
|
||
const gdb_byte *
|
||
safe_read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
|
||
uint64_t *r)
|
||
{
|
||
buf = gdb_read_uleb128 (buf, buf_end, r);
|
||
if (buf == NULL)
|
||
error (_("DWARF expression error: ran off end of buffer reading uleb128 value"));
|
||
return buf;
|
||
}
|
||
|
||
/* Helper to read a sleb128 value or throw an error. */
|
||
|
||
const gdb_byte *
|
||
safe_read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
|
||
int64_t *r)
|
||
{
|
||
buf = gdb_read_sleb128 (buf, buf_end, r);
|
||
if (buf == NULL)
|
||
error (_("DWARF expression error: ran off end of buffer reading sleb128 value"));
|
||
return buf;
|
||
}
|
||
|
||
const gdb_byte *
|
||
safe_skip_leb128 (const gdb_byte *buf, const gdb_byte *buf_end)
|
||
{
|
||
buf = gdb_skip_leb128 (buf, buf_end);
|
||
if (buf == NULL)
|
||
error (_("DWARF expression error: ran off end of buffer reading leb128 value"));
|
||
return buf;
|
||
}
|
||
|
||
|
||
/* Check that the current operator is either at the end of an
|
||
expression, or that it is followed by a composition operator or by
|
||
DW_OP_GNU_uninit (which should terminate the expression). */
|
||
|
||
void
|
||
dwarf_expr_require_composition (const gdb_byte *op_ptr, const gdb_byte *op_end,
|
||
const char *op_name)
|
||
{
|
||
if (op_ptr != op_end && *op_ptr != DW_OP_piece && *op_ptr != DW_OP_bit_piece
|
||
&& *op_ptr != DW_OP_GNU_uninit)
|
||
error (_("DWARF-2 expression error: `%s' operations must be "
|
||
"used either alone or in conjunction with DW_OP_piece "
|
||
"or DW_OP_bit_piece."),
|
||
op_name);
|
||
}
|
||
|
||
/* Return true iff the types T1 and T2 are "the same". This only does
|
||
checks that might reasonably be needed to compare DWARF base
|
||
types. */
|
||
|
||
static int
|
||
base_types_equal_p (struct type *t1, struct type *t2)
|
||
{
|
||
if (t1->code () != t2->code ())
|
||
return 0;
|
||
if (t1->is_unsigned () != t2->is_unsigned ())
|
||
return 0;
|
||
return TYPE_LENGTH (t1) == TYPE_LENGTH (t2);
|
||
}
|
||
|
||
/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_reg* return the
|
||
DWARF register number. Otherwise return -1. */
|
||
|
||
int
|
||
dwarf_block_to_dwarf_reg (const gdb_byte *buf, const gdb_byte *buf_end)
|
||
{
|
||
uint64_t dwarf_reg;
|
||
|
||
if (buf_end <= buf)
|
||
return -1;
|
||
if (*buf >= DW_OP_reg0 && *buf <= DW_OP_reg31)
|
||
{
|
||
if (buf_end - buf != 1)
|
||
return -1;
|
||
return *buf - DW_OP_reg0;
|
||
}
|
||
|
||
if (*buf == DW_OP_regval_type || *buf == DW_OP_GNU_regval_type)
|
||
{
|
||
buf++;
|
||
buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
|
||
if (buf == NULL)
|
||
return -1;
|
||
buf = gdb_skip_leb128 (buf, buf_end);
|
||
if (buf == NULL)
|
||
return -1;
|
||
}
|
||
else if (*buf == DW_OP_regx)
|
||
{
|
||
buf++;
|
||
buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
|
||
if (buf == NULL)
|
||
return -1;
|
||
}
|
||
else
|
||
return -1;
|
||
if (buf != buf_end || (int) dwarf_reg != dwarf_reg)
|
||
return -1;
|
||
return dwarf_reg;
|
||
}
|
||
|
||
/* If <BUF..BUF_END] contains DW_FORM_block* with just DW_OP_breg*(0) and
|
||
DW_OP_deref* return the DWARF register number. Otherwise return -1.
|
||
DEREF_SIZE_RETURN contains -1 for DW_OP_deref; otherwise it contains the
|
||
size from DW_OP_deref_size. */
|
||
|
||
int
|
||
dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf, const gdb_byte *buf_end,
|
||
CORE_ADDR *deref_size_return)
|
||
{
|
||
uint64_t dwarf_reg;
|
||
int64_t offset;
|
||
|
||
if (buf_end <= buf)
|
||
return -1;
|
||
|
||
if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
|
||
{
|
||
dwarf_reg = *buf - DW_OP_breg0;
|
||
buf++;
|
||
if (buf >= buf_end)
|
||
return -1;
|
||
}
|
||
else if (*buf == DW_OP_bregx)
|
||
{
|
||
buf++;
|
||
buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
|
||
if (buf == NULL)
|
||
return -1;
|
||
if ((int) dwarf_reg != dwarf_reg)
|
||
return -1;
|
||
}
|
||
else
|
||
return -1;
|
||
|
||
buf = gdb_read_sleb128 (buf, buf_end, &offset);
|
||
if (buf == NULL)
|
||
return -1;
|
||
if (offset != 0)
|
||
return -1;
|
||
|
||
if (*buf == DW_OP_deref)
|
||
{
|
||
buf++;
|
||
*deref_size_return = -1;
|
||
}
|
||
else if (*buf == DW_OP_deref_size)
|
||
{
|
||
buf++;
|
||
if (buf >= buf_end)
|
||
return -1;
|
||
*deref_size_return = *buf++;
|
||
}
|
||
else
|
||
return -1;
|
||
|
||
if (buf != buf_end)
|
||
return -1;
|
||
|
||
return dwarf_reg;
|
||
}
|
||
|
||
/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_fbreg(X) fill
|
||
in FB_OFFSET_RETURN with the X offset and return 1. Otherwise return 0. */
|
||
|
||
int
|
||
dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
|
||
CORE_ADDR *fb_offset_return)
|
||
{
|
||
int64_t fb_offset;
|
||
|
||
if (buf_end <= buf)
|
||
return 0;
|
||
|
||
if (*buf != DW_OP_fbreg)
|
||
return 0;
|
||
buf++;
|
||
|
||
buf = gdb_read_sleb128 (buf, buf_end, &fb_offset);
|
||
if (buf == NULL)
|
||
return 0;
|
||
*fb_offset_return = fb_offset;
|
||
if (buf != buf_end || fb_offset != (LONGEST) *fb_offset_return)
|
||
return 0;
|
||
|
||
return 1;
|
||
}
|
||
|
||
/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
|
||
in SP_OFFSET_RETURN with the X offset and return 1. Otherwise return 0.
|
||
The matched SP register number depends on GDBARCH. */
|
||
|
||
int
|
||
dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
|
||
const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
|
||
{
|
||
uint64_t dwarf_reg;
|
||
int64_t sp_offset;
|
||
|
||
if (buf_end <= buf)
|
||
return 0;
|
||
if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
|
||
{
|
||
dwarf_reg = *buf - DW_OP_breg0;
|
||
buf++;
|
||
}
|
||
else
|
||
{
|
||
if (*buf != DW_OP_bregx)
|
||
return 0;
|
||
buf++;
|
||
buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
|
||
if (buf == NULL)
|
||
return 0;
|
||
}
|
||
|
||
if (dwarf_reg_to_regnum (gdbarch, dwarf_reg)
|
||
!= gdbarch_sp_regnum (gdbarch))
|
||
return 0;
|
||
|
||
buf = gdb_read_sleb128 (buf, buf_end, &sp_offset);
|
||
if (buf == NULL)
|
||
return 0;
|
||
*sp_offset_return = sp_offset;
|
||
if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
|
||
return 0;
|
||
|
||
return 1;
|
||
}
|
||
|
||
/* The engine for the expression evaluator. Using the context in this
|
||
object, evaluate the expression between OP_PTR and OP_END. */
|
||
|
||
void
|
||
dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||
const gdb_byte *op_end)
|
||
{
|
||
enum bfd_endian byte_order = gdbarch_byte_order (this->gdbarch);
|
||
/* Old-style "untyped" DWARF values need special treatment in a
|
||
couple of places, specifically DW_OP_mod and DW_OP_shr. We need
|
||
a special type for these values so we can distinguish them from
|
||
values that have an explicit type, because explicitly-typed
|
||
values do not need special treatment. This special type must be
|
||
different (in the `==' sense) from any base type coming from the
|
||
CU. */
|
||
struct type *address_type = this->address_type ();
|
||
|
||
this->location = DWARF_VALUE_MEMORY;
|
||
this->initialized = 1; /* Default is initialized. */
|
||
|
||
if (this->recursion_depth > this->max_recursion_depth)
|
||
error (_("DWARF-2 expression error: Loop detected (%d)."),
|
||
this->recursion_depth);
|
||
this->recursion_depth++;
|
||
|
||
while (op_ptr < op_end)
|
||
{
|
||
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr++;
|
||
ULONGEST result;
|
||
/* Assume the value is not in stack memory.
|
||
Code that knows otherwise sets this to true.
|
||
Some arithmetic on stack addresses can probably be assumed to still
|
||
be a stack address, but we skip this complication for now.
|
||
This is just an optimization, so it's always ok to punt
|
||
and leave this as false. */
|
||
bool in_stack_memory = false;
|
||
uint64_t uoffset, reg;
|
||
int64_t offset;
|
||
struct value *result_val = NULL;
|
||
|
||
/* The DWARF expression might have a bug causing an infinite
|
||
loop. In that case, quitting is the only way out. */
|
||
QUIT;
|
||
|
||
switch (op)
|
||
{
|
||
case DW_OP_lit0:
|
||
case DW_OP_lit1:
|
||
case DW_OP_lit2:
|
||
case DW_OP_lit3:
|
||
case DW_OP_lit4:
|
||
case DW_OP_lit5:
|
||
case DW_OP_lit6:
|
||
case DW_OP_lit7:
|
||
case DW_OP_lit8:
|
||
case DW_OP_lit9:
|
||
case DW_OP_lit10:
|
||
case DW_OP_lit11:
|
||
case DW_OP_lit12:
|
||
case DW_OP_lit13:
|
||
case DW_OP_lit14:
|
||
case DW_OP_lit15:
|
||
case DW_OP_lit16:
|
||
case DW_OP_lit17:
|
||
case DW_OP_lit18:
|
||
case DW_OP_lit19:
|
||
case DW_OP_lit20:
|
||
case DW_OP_lit21:
|
||
case DW_OP_lit22:
|
||
case DW_OP_lit23:
|
||
case DW_OP_lit24:
|
||
case DW_OP_lit25:
|
||
case DW_OP_lit26:
|
||
case DW_OP_lit27:
|
||
case DW_OP_lit28:
|
||
case DW_OP_lit29:
|
||
case DW_OP_lit30:
|
||
case DW_OP_lit31:
|
||
result = op - DW_OP_lit0;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
case DW_OP_addr:
|
||
result = extract_unsigned_integer (op_ptr,
|
||
this->addr_size, byte_order);
|
||
op_ptr += this->addr_size;
|
||
/* Some versions of GCC emit DW_OP_addr before
|
||
DW_OP_GNU_push_tls_address. In this case the value is an
|
||
index, not an address. We don't support things like
|
||
branching between the address and the TLS op. */
|
||
if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
|
||
result += this->per_objfile->objfile->text_section_offset ();
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
case DW_OP_addrx:
|
||
case DW_OP_GNU_addr_index:
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
result = this->get_addr_index (uoffset);
|
||
result += this->per_objfile->objfile->text_section_offset ();
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_GNU_const_index:
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
result = this->get_addr_index (uoffset);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
case DW_OP_const1u:
|
||
result = extract_unsigned_integer (op_ptr, 1, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 1;
|
||
break;
|
||
case DW_OP_const1s:
|
||
result = extract_signed_integer (op_ptr, 1, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 1;
|
||
break;
|
||
case DW_OP_const2u:
|
||
result = extract_unsigned_integer (op_ptr, 2, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 2;
|
||
break;
|
||
case DW_OP_const2s:
|
||
result = extract_signed_integer (op_ptr, 2, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 2;
|
||
break;
|
||
case DW_OP_const4u:
|
||
result = extract_unsigned_integer (op_ptr, 4, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 4;
|
||
break;
|
||
case DW_OP_const4s:
|
||
result = extract_signed_integer (op_ptr, 4, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 4;
|
||
break;
|
||
case DW_OP_const8u:
|
||
result = extract_unsigned_integer (op_ptr, 8, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 8;
|
||
break;
|
||
case DW_OP_const8s:
|
||
result = extract_signed_integer (op_ptr, 8, byte_order);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
op_ptr += 8;
|
||
break;
|
||
case DW_OP_constu:
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
result = uoffset;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_consts:
|
||
op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
|
||
result = offset;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
/* The DW_OP_reg operations are required to occur alone in
|
||
location expressions. */
|
||
case DW_OP_reg0:
|
||
case DW_OP_reg1:
|
||
case DW_OP_reg2:
|
||
case DW_OP_reg3:
|
||
case DW_OP_reg4:
|
||
case DW_OP_reg5:
|
||
case DW_OP_reg6:
|
||
case DW_OP_reg7:
|
||
case DW_OP_reg8:
|
||
case DW_OP_reg9:
|
||
case DW_OP_reg10:
|
||
case DW_OP_reg11:
|
||
case DW_OP_reg12:
|
||
case DW_OP_reg13:
|
||
case DW_OP_reg14:
|
||
case DW_OP_reg15:
|
||
case DW_OP_reg16:
|
||
case DW_OP_reg17:
|
||
case DW_OP_reg18:
|
||
case DW_OP_reg19:
|
||
case DW_OP_reg20:
|
||
case DW_OP_reg21:
|
||
case DW_OP_reg22:
|
||
case DW_OP_reg23:
|
||
case DW_OP_reg24:
|
||
case DW_OP_reg25:
|
||
case DW_OP_reg26:
|
||
case DW_OP_reg27:
|
||
case DW_OP_reg28:
|
||
case DW_OP_reg29:
|
||
case DW_OP_reg30:
|
||
case DW_OP_reg31:
|
||
dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_reg");
|
||
|
||
result = op - DW_OP_reg0;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
this->location = DWARF_VALUE_REGISTER;
|
||
break;
|
||
|
||
case DW_OP_regx:
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
|
||
dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
|
||
|
||
result = reg;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
this->location = DWARF_VALUE_REGISTER;
|
||
break;
|
||
|
||
case DW_OP_implicit_value:
|
||
{
|
||
uint64_t len;
|
||
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
|
||
if (op_ptr + len > op_end)
|
||
error (_("DW_OP_implicit_value: too few bytes available."));
|
||
this->len = len;
|
||
this->data = op_ptr;
|
||
this->location = DWARF_VALUE_LITERAL;
|
||
op_ptr += len;
|
||
dwarf_expr_require_composition (op_ptr, op_end,
|
||
"DW_OP_implicit_value");
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_stack_value:
|
||
this->location = DWARF_VALUE_STACK;
|
||
dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
|
||
goto no_push;
|
||
|
||
case DW_OP_implicit_pointer:
|
||
case DW_OP_GNU_implicit_pointer:
|
||
{
|
||
int64_t len;
|
||
|
||
if (this->ref_addr_size == -1)
|
||
error (_("DWARF-2 expression error: DW_OP_implicit_pointer "
|
||
"is not allowed in frame context"));
|
||
|
||
/* The referred-to DIE of sect_offset kind. */
|
||
this->len = extract_unsigned_integer (op_ptr, this->ref_addr_size,
|
||
byte_order);
|
||
op_ptr += this->ref_addr_size;
|
||
|
||
/* The byte offset into the data. */
|
||
op_ptr = safe_read_sleb128 (op_ptr, op_end, &len);
|
||
result = (ULONGEST) len;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
|
||
this->location = DWARF_VALUE_IMPLICIT_POINTER;
|
||
dwarf_expr_require_composition (op_ptr, op_end,
|
||
"DW_OP_implicit_pointer");
|
||
}
|
||
break;
|
||
|
||
case DW_OP_breg0:
|
||
case DW_OP_breg1:
|
||
case DW_OP_breg2:
|
||
case DW_OP_breg3:
|
||
case DW_OP_breg4:
|
||
case DW_OP_breg5:
|
||
case DW_OP_breg6:
|
||
case DW_OP_breg7:
|
||
case DW_OP_breg8:
|
||
case DW_OP_breg9:
|
||
case DW_OP_breg10:
|
||
case DW_OP_breg11:
|
||
case DW_OP_breg12:
|
||
case DW_OP_breg13:
|
||
case DW_OP_breg14:
|
||
case DW_OP_breg15:
|
||
case DW_OP_breg16:
|
||
case DW_OP_breg17:
|
||
case DW_OP_breg18:
|
||
case DW_OP_breg19:
|
||
case DW_OP_breg20:
|
||
case DW_OP_breg21:
|
||
case DW_OP_breg22:
|
||
case DW_OP_breg23:
|
||
case DW_OP_breg24:
|
||
case DW_OP_breg25:
|
||
case DW_OP_breg26:
|
||
case DW_OP_breg27:
|
||
case DW_OP_breg28:
|
||
case DW_OP_breg29:
|
||
case DW_OP_breg30:
|
||
case DW_OP_breg31:
|
||
{
|
||
op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
|
||
result = this->read_addr_from_reg (op - DW_OP_breg0);
|
||
result += offset;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
}
|
||
break;
|
||
case DW_OP_bregx:
|
||
{
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
|
||
op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
|
||
result = this->read_addr_from_reg (reg);
|
||
result += offset;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
}
|
||
break;
|
||
case DW_OP_fbreg:
|
||
{
|
||
const gdb_byte *datastart;
|
||
size_t datalen;
|
||
|
||
op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
|
||
|
||
/* Rather than create a whole new context, we simply
|
||
backup the current stack locally and install a new empty stack,
|
||
then reset it afterwards, effectively erasing whatever the
|
||
recursive call put there. */
|
||
std::vector<dwarf_stack_value> saved_stack = std::move (stack);
|
||
stack.clear ();
|
||
|
||
/* FIXME: cagney/2003-03-26: This code should be using
|
||
get_frame_base_address(), and then implement a dwarf2
|
||
specific this_base method. */
|
||
this->get_frame_base (&datastart, &datalen);
|
||
eval (datastart, datalen);
|
||
if (this->location == DWARF_VALUE_MEMORY)
|
||
result = fetch_address (0);
|
||
else if (this->location == DWARF_VALUE_REGISTER)
|
||
result = this->read_addr_from_reg (value_as_long (fetch (0)));
|
||
else
|
||
error (_("Not implemented: computing frame "
|
||
"base using explicit value operator"));
|
||
result = result + offset;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
in_stack_memory = true;
|
||
|
||
/* Restore the content of the original stack. */
|
||
stack = std::move (saved_stack);
|
||
|
||
this->location = DWARF_VALUE_MEMORY;
|
||
}
|
||
break;
|
||
|
||
case DW_OP_dup:
|
||
result_val = fetch (0);
|
||
in_stack_memory = fetch_in_stack_memory (0);
|
||
break;
|
||
|
||
case DW_OP_drop:
|
||
pop ();
|
||
goto no_push;
|
||
|
||
case DW_OP_pick:
|
||
offset = *op_ptr++;
|
||
result_val = fetch (offset);
|
||
in_stack_memory = fetch_in_stack_memory (offset);
|
||
break;
|
||
|
||
case DW_OP_swap:
|
||
{
|
||
if (stack.size () < 2)
|
||
error (_("Not enough elements for "
|
||
"DW_OP_swap. Need 2, have %zu."),
|
||
stack.size ());
|
||
|
||
dwarf_stack_value &t1 = stack[stack.size () - 1];
|
||
dwarf_stack_value &t2 = stack[stack.size () - 2];
|
||
std::swap (t1, t2);
|
||
goto no_push;
|
||
}
|
||
|
||
case DW_OP_over:
|
||
result_val = fetch (1);
|
||
in_stack_memory = fetch_in_stack_memory (1);
|
||
break;
|
||
|
||
case DW_OP_rot:
|
||
{
|
||
if (stack.size () < 3)
|
||
error (_("Not enough elements for "
|
||
"DW_OP_rot. Need 3, have %zu."),
|
||
stack.size ());
|
||
|
||
dwarf_stack_value temp = stack[stack.size () - 1];
|
||
stack[stack.size () - 1] = stack[stack.size () - 2];
|
||
stack[stack.size () - 2] = stack[stack.size () - 3];
|
||
stack[stack.size () - 3] = temp;
|
||
goto no_push;
|
||
}
|
||
|
||
case DW_OP_deref:
|
||
case DW_OP_deref_size:
|
||
case DW_OP_deref_type:
|
||
case DW_OP_GNU_deref_type:
|
||
{
|
||
int addr_size = (op == DW_OP_deref ? this->addr_size : *op_ptr++);
|
||
gdb_byte *buf = (gdb_byte *) alloca (addr_size);
|
||
CORE_ADDR addr = fetch_address (0);
|
||
struct type *type;
|
||
|
||
pop ();
|
||
|
||
if (op == DW_OP_deref_type || op == DW_OP_GNU_deref_type)
|
||
{
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
cu_offset type_die_cu_off = (cu_offset) uoffset;
|
||
type = get_base_type (type_die_cu_off, 0);
|
||
}
|
||
else
|
||
type = address_type;
|
||
|
||
this->read_mem (buf, addr, addr_size);
|
||
|
||
/* If the size of the object read from memory is different
|
||
from the type length, we need to zero-extend it. */
|
||
if (TYPE_LENGTH (type) != addr_size)
|
||
{
|
||
ULONGEST datum =
|
||
extract_unsigned_integer (buf, addr_size, byte_order);
|
||
|
||
buf = (gdb_byte *) alloca (TYPE_LENGTH (type));
|
||
store_unsigned_integer (buf, TYPE_LENGTH (type),
|
||
byte_order, datum);
|
||
}
|
||
|
||
result_val = value_from_contents_and_address (type, buf, addr);
|
||
break;
|
||
}
|
||
|
||
case DW_OP_abs:
|
||
case DW_OP_neg:
|
||
case DW_OP_not:
|
||
case DW_OP_plus_uconst:
|
||
{
|
||
/* Unary operations. */
|
||
result_val = fetch (0);
|
||
pop ();
|
||
|
||
switch (op)
|
||
{
|
||
case DW_OP_abs:
|
||
if (value_less (result_val,
|
||
value_zero (value_type (result_val), not_lval)))
|
||
result_val = value_neg (result_val);
|
||
break;
|
||
case DW_OP_neg:
|
||
result_val = value_neg (result_val);
|
||
break;
|
||
case DW_OP_not:
|
||
dwarf_require_integral (value_type (result_val));
|
||
result_val = value_complement (result_val);
|
||
break;
|
||
case DW_OP_plus_uconst:
|
||
dwarf_require_integral (value_type (result_val));
|
||
result = value_as_long (result_val);
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
|
||
result += reg;
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
|
||
case DW_OP_and:
|
||
case DW_OP_div:
|
||
case DW_OP_minus:
|
||
case DW_OP_mod:
|
||
case DW_OP_mul:
|
||
case DW_OP_or:
|
||
case DW_OP_plus:
|
||
case DW_OP_shl:
|
||
case DW_OP_shr:
|
||
case DW_OP_shra:
|
||
case DW_OP_xor:
|
||
case DW_OP_le:
|
||
case DW_OP_ge:
|
||
case DW_OP_eq:
|
||
case DW_OP_lt:
|
||
case DW_OP_gt:
|
||
case DW_OP_ne:
|
||
{
|
||
/* Binary operations. */
|
||
struct value *first, *second;
|
||
|
||
second = fetch (0);
|
||
pop ();
|
||
|
||
first = fetch (0);
|
||
pop ();
|
||
|
||
if (! base_types_equal_p (value_type (first), value_type (second)))
|
||
error (_("Incompatible types on DWARF stack"));
|
||
|
||
switch (op)
|
||
{
|
||
case DW_OP_and:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
result_val = value_binop (first, second, BINOP_BITWISE_AND);
|
||
break;
|
||
case DW_OP_div:
|
||
result_val = value_binop (first, second, BINOP_DIV);
|
||
break;
|
||
case DW_OP_minus:
|
||
result_val = value_binop (first, second, BINOP_SUB);
|
||
break;
|
||
case DW_OP_mod:
|
||
{
|
||
int cast_back = 0;
|
||
struct type *orig_type = value_type (first);
|
||
|
||
/* We have to special-case "old-style" untyped values
|
||
-- these must have mod computed using unsigned
|
||
math. */
|
||
if (orig_type == address_type)
|
||
{
|
||
struct type *utype
|
||
= get_unsigned_type (this->gdbarch, orig_type);
|
||
|
||
cast_back = 1;
|
||
first = value_cast (utype, first);
|
||
second = value_cast (utype, second);
|
||
}
|
||
/* Note that value_binop doesn't handle float or
|
||
decimal float here. This seems unimportant. */
|
||
result_val = value_binop (first, second, BINOP_MOD);
|
||
if (cast_back)
|
||
result_val = value_cast (orig_type, result_val);
|
||
}
|
||
break;
|
||
case DW_OP_mul:
|
||
result_val = value_binop (first, second, BINOP_MUL);
|
||
break;
|
||
case DW_OP_or:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
result_val = value_binop (first, second, BINOP_BITWISE_IOR);
|
||
break;
|
||
case DW_OP_plus:
|
||
result_val = value_binop (first, second, BINOP_ADD);
|
||
break;
|
||
case DW_OP_shl:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
result_val = value_binop (first, second, BINOP_LSH);
|
||
break;
|
||
case DW_OP_shr:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
if (!value_type (first)->is_unsigned ())
|
||
{
|
||
struct type *utype
|
||
= get_unsigned_type (this->gdbarch, value_type (first));
|
||
|
||
first = value_cast (utype, first);
|
||
}
|
||
|
||
result_val = value_binop (first, second, BINOP_RSH);
|
||
/* Make sure we wind up with the same type we started
|
||
with. */
|
||
if (value_type (result_val) != value_type (second))
|
||
result_val = value_cast (value_type (second), result_val);
|
||
break;
|
||
case DW_OP_shra:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
if (value_type (first)->is_unsigned ())
|
||
{
|
||
struct type *stype
|
||
= get_signed_type (this->gdbarch, value_type (first));
|
||
|
||
first = value_cast (stype, first);
|
||
}
|
||
|
||
result_val = value_binop (first, second, BINOP_RSH);
|
||
/* Make sure we wind up with the same type we started
|
||
with. */
|
||
if (value_type (result_val) != value_type (second))
|
||
result_val = value_cast (value_type (second), result_val);
|
||
break;
|
||
case DW_OP_xor:
|
||
dwarf_require_integral (value_type (first));
|
||
dwarf_require_integral (value_type (second));
|
||
result_val = value_binop (first, second, BINOP_BITWISE_XOR);
|
||
break;
|
||
case DW_OP_le:
|
||
/* A <= B is !(B < A). */
|
||
result = ! value_less (second, first);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_ge:
|
||
/* A >= B is !(A < B). */
|
||
result = ! value_less (first, second);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_eq:
|
||
result = value_equal (first, second);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_lt:
|
||
result = value_less (first, second);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_gt:
|
||
/* A > B is B < A. */
|
||
result = value_less (second, first);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
case DW_OP_ne:
|
||
result = ! value_equal (first, second);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
default:
|
||
internal_error (__FILE__, __LINE__,
|
||
_("Can't be reached."));
|
||
}
|
||
}
|
||
break;
|
||
|
||
case DW_OP_call_frame_cfa:
|
||
result = this->get_frame_cfa ();
|
||
result_val = value_from_ulongest (address_type, result);
|
||
in_stack_memory = true;
|
||
break;
|
||
|
||
case DW_OP_GNU_push_tls_address:
|
||
case DW_OP_form_tls_address:
|
||
/* Variable is at a constant offset in the thread-local
|
||
storage block into the objfile for the current thread and
|
||
the dynamic linker module containing this expression. Here
|
||
we return returns the offset from that base. The top of the
|
||
stack has the offset from the beginning of the thread
|
||
control block at which the variable is located. Nothing
|
||
should follow this operator, so the top of stack would be
|
||
returned. */
|
||
result = value_as_long (fetch (0));
|
||
pop ();
|
||
result = this->get_tls_address (result);
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
case DW_OP_skip:
|
||
offset = extract_signed_integer (op_ptr, 2, byte_order);
|
||
op_ptr += 2;
|
||
op_ptr += offset;
|
||
goto no_push;
|
||
|
||
case DW_OP_bra:
|
||
{
|
||
struct value *val;
|
||
|
||
offset = extract_signed_integer (op_ptr, 2, byte_order);
|
||
op_ptr += 2;
|
||
val = fetch (0);
|
||
dwarf_require_integral (value_type (val));
|
||
if (value_as_long (val) != 0)
|
||
op_ptr += offset;
|
||
pop ();
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_nop:
|
||
goto no_push;
|
||
|
||
case DW_OP_piece:
|
||
{
|
||
uint64_t size;
|
||
|
||
/* Record the piece. */
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
|
||
add_piece (8 * size, 0);
|
||
|
||
/* Pop off the address/regnum, and reset the location
|
||
type. */
|
||
if (this->location != DWARF_VALUE_LITERAL
|
||
&& this->location != DWARF_VALUE_OPTIMIZED_OUT)
|
||
pop ();
|
||
this->location = DWARF_VALUE_MEMORY;
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_bit_piece:
|
||
{
|
||
uint64_t size, uleb_offset;
|
||
|
||
/* Record the piece. */
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uleb_offset);
|
||
add_piece (size, uleb_offset);
|
||
|
||
/* Pop off the address/regnum, and reset the location
|
||
type. */
|
||
if (this->location != DWARF_VALUE_LITERAL
|
||
&& this->location != DWARF_VALUE_OPTIMIZED_OUT)
|
||
pop ();
|
||
this->location = DWARF_VALUE_MEMORY;
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_GNU_uninit:
|
||
if (op_ptr != op_end)
|
||
error (_("DWARF-2 expression error: DW_OP_GNU_uninit must always "
|
||
"be the very last op."));
|
||
|
||
this->initialized = 0;
|
||
goto no_push;
|
||
|
||
case DW_OP_call2:
|
||
{
|
||
cu_offset cu_off
|
||
= (cu_offset) extract_unsigned_integer (op_ptr, 2, byte_order);
|
||
op_ptr += 2;
|
||
this->dwarf_call (cu_off);
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_call4:
|
||
{
|
||
cu_offset cu_off
|
||
= (cu_offset) extract_unsigned_integer (op_ptr, 4, byte_order);
|
||
op_ptr += 4;
|
||
this->dwarf_call (cu_off);
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_GNU_variable_value:
|
||
{
|
||
sect_offset sect_off
|
||
= (sect_offset) extract_unsigned_integer (op_ptr,
|
||
this->ref_addr_size,
|
||
byte_order);
|
||
op_ptr += this->ref_addr_size;
|
||
result_val = value_cast (address_type,
|
||
this->dwarf_variable_value (sect_off));
|
||
}
|
||
break;
|
||
|
||
case DW_OP_entry_value:
|
||
case DW_OP_GNU_entry_value:
|
||
{
|
||
uint64_t len;
|
||
CORE_ADDR deref_size;
|
||
union call_site_parameter_u kind_u;
|
||
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
|
||
if (op_ptr + len > op_end)
|
||
error (_("DW_OP_entry_value: too few bytes available."));
|
||
|
||
kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (op_ptr, op_ptr + len);
|
||
if (kind_u.dwarf_reg != -1)
|
||
{
|
||
op_ptr += len;
|
||
this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_DWARF_REG,
|
||
kind_u,
|
||
-1 /* deref_size */);
|
||
goto no_push;
|
||
}
|
||
|
||
kind_u.dwarf_reg = dwarf_block_to_dwarf_reg_deref (op_ptr,
|
||
op_ptr + len,
|
||
&deref_size);
|
||
if (kind_u.dwarf_reg != -1)
|
||
{
|
||
if (deref_size == -1)
|
||
deref_size = this->addr_size;
|
||
op_ptr += len;
|
||
this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_DWARF_REG,
|
||
kind_u, deref_size);
|
||
goto no_push;
|
||
}
|
||
|
||
error (_("DWARF-2 expression error: DW_OP_entry_value is "
|
||
"supported only for single DW_OP_reg* "
|
||
"or for DW_OP_breg*(0)+DW_OP_deref*"));
|
||
}
|
||
|
||
case DW_OP_GNU_parameter_ref:
|
||
{
|
||
union call_site_parameter_u kind_u;
|
||
|
||
kind_u.param_cu_off
|
||
= (cu_offset) extract_unsigned_integer (op_ptr, 4, byte_order);
|
||
op_ptr += 4;
|
||
this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_PARAM_OFFSET,
|
||
kind_u,
|
||
-1 /* deref_size */);
|
||
}
|
||
goto no_push;
|
||
|
||
case DW_OP_const_type:
|
||
case DW_OP_GNU_const_type:
|
||
{
|
||
int n;
|
||
const gdb_byte *data;
|
||
struct type *type;
|
||
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
cu_offset type_die_cu_off = (cu_offset) uoffset;
|
||
|
||
n = *op_ptr++;
|
||
data = op_ptr;
|
||
op_ptr += n;
|
||
|
||
type = get_base_type (type_die_cu_off, n);
|
||
result_val = value_from_contents (type, data);
|
||
}
|
||
break;
|
||
|
||
case DW_OP_regval_type:
|
||
case DW_OP_GNU_regval_type:
|
||
{
|
||
struct type *type;
|
||
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
cu_offset type_die_cu_off = (cu_offset) uoffset;
|
||
|
||
type = get_base_type (type_die_cu_off, 0);
|
||
result_val = this->get_reg_value (type, reg);
|
||
}
|
||
break;
|
||
|
||
case DW_OP_convert:
|
||
case DW_OP_GNU_convert:
|
||
case DW_OP_reinterpret:
|
||
case DW_OP_GNU_reinterpret:
|
||
{
|
||
struct type *type;
|
||
|
||
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
|
||
cu_offset type_die_cu_off = (cu_offset) uoffset;
|
||
|
||
if (to_underlying (type_die_cu_off) == 0)
|
||
type = address_type;
|
||
else
|
||
type = get_base_type (type_die_cu_off, 0);
|
||
|
||
result_val = fetch (0);
|
||
pop ();
|
||
|
||
if (op == DW_OP_convert || op == DW_OP_GNU_convert)
|
||
result_val = value_cast (type, result_val);
|
||
else if (type == value_type (result_val))
|
||
{
|
||
/* Nothing. */
|
||
}
|
||
else if (TYPE_LENGTH (type)
|
||
!= TYPE_LENGTH (value_type (result_val)))
|
||
error (_("DW_OP_reinterpret has wrong size"));
|
||
else
|
||
result_val
|
||
= value_from_contents (type,
|
||
value_contents_all (result_val));
|
||
}
|
||
break;
|
||
|
||
case DW_OP_push_object_address:
|
||
/* Return the address of the object we are currently observing. */
|
||
result = this->get_object_address ();
|
||
result_val = value_from_ulongest (address_type, result);
|
||
break;
|
||
|
||
default:
|
||
error (_("Unhandled dwarf expression opcode 0x%x"), op);
|
||
}
|
||
|
||
/* Most things push a result value. */
|
||
gdb_assert (result_val != NULL);
|
||
push (result_val, in_stack_memory);
|
||
no_push:
|
||
;
|
||
}
|
||
|
||
/* To simplify our main caller, if the result is an implicit
|
||
pointer, then make a pieced value. This is ok because we can't
|
||
have implicit pointers in contexts where pieces are invalid. */
|
||
if (this->location == DWARF_VALUE_IMPLICIT_POINTER)
|
||
add_piece (8 * this->addr_size, 0);
|
||
|
||
this->recursion_depth--;
|
||
gdb_assert (this->recursion_depth >= 0);
|
||
}
|
||
|
||
void _initialize_dwarf2expr ();
|
||
void
|
||
_initialize_dwarf2expr ()
|
||
{
|
||
dwarf_arch_cookie
|
||
= gdbarch_data_register_post_init (dwarf_gdbarch_types_init);
|
||
}
|