old-cross-binutils/gdb/aarch64-linux-tdep.c
Sergio Durigan Junior 410a0ff2df Remove `expout*' globals from parser-defs.h
This commit removes the "expout*" globals from our parser code, turning
them into a structure that is passed when an expression needs to be
evaluated.  This is the initial step to make our parser less
"globalized".

This is mostly a mechanical patch, which creates a structure containing
the "expout*" globals and then modify all the functions that handle them
in order to take the structure as argument.  It is big, and has been
reviewed at least 4 times, so I think everything is covered.

Below you can see the message links from the discussions:

- First attempt:

<https://sourceware.org/ml/gdb-patches/2012-01/msg00522.html>
Message-ID: <m3k44s7qej.fsf@gmail.com>

- Second attempt:

<https://sourceware.org/ml/gdb-patches/2012-06/msg00054.html>
Message-Id: <1338665528-5932-1-git-send-email-sergiodj@redhat.com>

- Third attempt:

<https://sourceware.org/ml/gdb-patches/2014-01/msg00949.html>
Message-Id: <1390629467-27139-1-git-send-email-sergiodj@redhat.com>

- Fourth (last) attempt:

<https://sourceware.org/ml/gdb-patches/2014-03/msg00546.html>
Message-Id: <1395463432-29750-1-git-send-email-sergiodj@redhat.com>

gdb/
2014-03-27  Sergio Durigan Junior  <sergiodj@redhat.com>

	Remove some globals from our parser.
	* language.c (unk_lang_parser): Add "struct parser_state"
	argument.
	* language.h (struct language_defn) <la_parser>: Likewise.
	* parse.c (expout, expout_size, expout_ptr): Remove variables.
	(initialize_expout): Add "struct parser_state" argument.
	Rewrite function to use the parser state.
	(reallocate_expout, write_exp_elt, write_exp_elt_opcode,
	write_exp_elt_sym, write_exp_elt_block, write_exp_elt_objfile,
	write_exp_elt_longcst, write_exp_elt_dblcst,
	write_exp_elt_decfloatcst, write_exp_elt_type,
	write_exp_elt_intern, write_exp_string, write_exp_string_vector,
	write_exp_bitstring, write_exp_msymbol, mark_struct_expression,
	write_dollar_variable): Likewise.
	(parse_exp_in_context_1): Use parser state.
	(insert_type_address_space): Add "struct parser_state" argument.
	Use parser state.
	(increase_expout_size): New function.
	* parser-defs.h: Forward declare "struct language_defn" and
	"struct parser_state".
	(expout, expout_size, expout_ptr): Remove extern declarations.
	(parse_gdbarch, parse_language): Rewrite macro declarations to
	accept the parser state.
	(struct parser_state): New struct.
	(initialize_expout, reallocate_expout, write_exp_elt_opcode,
	write_exp_elt_sym, write_exp_elt_longcst, write_exp_elt_dblcst,
	write_exp_elt_decfloatcst, write_exp_elt_type,
	write_exp_elt_intern, write_exp_string, write_exp_string_vector,
	write_exp_bitstring, write_exp_elt_block, write_exp_elt_objfile,
	write_exp_msymbol, write_dollar_variable,
	mark_struct_expression, insert_type_address_space): Add "struct
	parser_state" argument.
	(increase_expout_size): New function.
	* utils.c (do_clear_parser_state): New function.
	(make_cleanup_clear_parser_state): Likewise.
	* utils.h (make_cleanup_clear_parser_state): New function
	prototype.
	* aarch64-linux-tdep.c (aarch64_stap_parse_special_token):
	Update calls to write_exp* in order to pass the parser state.
	* arm-linux-tdep.c (arm_stap_parse_special_token): Likewise.
	* i386-tdep.c (i386_stap_parse_special_token_triplet): Likewise.
	(i386_stap_parse_special_token_three_arg_disp): Likewise.
	* ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise.
	* stap-probe.c (stap_parse_register_operand): Likewise.
	(stap_parse_single_operand): Likewise.
	(stap_parse_argument_1): Likewise.
	(stap_parse_argument): Use parser state.
	* stap-probe.h: Include "parser-defs.h".
	(struct stap_parse_info) <pstate>: New field.
	* c-exp.y (parse_type): Rewrite to use parser state.
	(yyparse): Redefine to c_parse_internal.
	(pstate): New global variable.
	(parse_number): Add "struct parser_state" argument.
	(write_destructor_name): Likewise.
	(type_exp): Update calls to write_exp* and similars in order to
	use parser state.
	(exp1, exp, variable, qualified_name, space_identifier,
	typename, typebase): Likewise.
	(write_destructor_name, parse_number, lex_one_token,
	classify_name, classify_inner_name, c_parse): Add "struct
	parser_state" argument.  Update function to use parser state.
	* c-lang.h: Forward declare "struct parser_state".
	(c_parse): Add "struct parser_state" argument.
	* ada-exp.y (parse_type): Rewrite macro to use parser state.
	(yyparse): Redefine macro to ada_parse_internal.
	(pstate): New variable.
	(write_int, write_object_renaming, write_var_or_type,
	write_name_assoc, write_exp_op_with_string, write_ambiguous_var,
	type_int, type_long, type_long_long, type_float, type_double,
	type_long_double, type_char, type_boolean, type_system_address):
	Add "struct parser_state" argument.
	(exp1, primary, simple_exp, relation, and_exp, and_then_exp,
	or_exp, or_else_exp, xor_exp, type_prefix, opt_type_prefix,
	var_or_type, aggregate, aggregate_component_list,
	positional_list, others, component_group,
	component_associations): Update calls to write_exp* and similar
	functions in order to use parser state.
	(ada_parse, write_var_from_sym, write_int,
	write_exp_op_with_string, write_object_renaming,
	find_primitive_type, write_selectors, write_ambiguous_var,
	write_var_or_type, write_name_assoc, type_int, type_long,
	type_long_long, type_float, type_double, type_long_double,
	type_char, type_boolean, type_system_address): Add "struct
	parser_state" argument.  Adjust function to use parser state.
	* ada-lang.c (parse): Likewise.
	* ada-lang.h: Forward declare "struct parser_state".
	(ada_parse): Add "struct parser_state" argument.
	* ada-lex.l (processInt, processReal): Likewise.  Adjust all
	calls to both functions.
	* f-exp.y (parse_type, parse_f_type): Rewrite macros to use
	parser state.
	(yyparse): Redefine macro to f_parse_internal.
	(pstate): New variable.
	(parse_number): Add "struct parser_state" argument.
	(type_exp, exp, subrange, typebase): Update calls to write_exp*
	and similars in order to use parser state.
	(parse_number): Adjust code to use parser state.
	(yylex): Likewise.
	(f_parse): New function.
	* f-lang.h: Forward declare "struct parser_state".
	(f_parse): Add "struct parser_state" argument.
	* jv-exp.y (parse_type, parse_java_type): Rewrite macros to use
	parser state.
	(yyparse): Redefine macro for java_parse_internal.
	(pstate): New variable.
	(push_expression_name, push_expression_name, insert_exp): Add
	"struct parser_state" argument.
	(type_exp, StringLiteral, Literal, PrimitiveType, IntegralType,
	FloatingPointType, exp1, PrimaryNoNewArray, FieldAccess,
	FuncStart, MethodInvocation, ArrayAccess, PostfixExpression,
	PostIncrementExpression, PostDecrementExpression,
	UnaryExpression, PreIncrementExpression, PreDecrementExpression,
	UnaryExpressionNotPlusMinus, CastExpression,
	MultiplicativeExpression, AdditiveExpression, ShiftExpression,
	RelationalExpression, EqualityExpression, AndExpression,
	ExclusiveOrExpression, InclusiveOrExpression,
	ConditionalAndExpression, ConditionalOrExpression,
	ConditionalExpression, Assignment, LeftHandSide): Update
	calls to write_exp* and similars in order to use parser state.
	(parse_number): Ajust code to use parser state.
	(yylex): Likewise.
	(java_parse): New function.
	(push_variable): Add "struct parser_state" argument.  Adjust
	code to user parser state.
	(push_fieldnames, push_qualified_expression_name,
	push_expression_name, insert_exp): Likewise.
	* jv-lang.h: Forward declare "struct parser_state".
	(java_parse): Add "struct parser_state" argument.
	* m2-exp.y (parse_type, parse_m2_type): Rewrite macros to use
	parser state.
	(yyparse): Redefine macro to m2_parse_internal.
	(pstate): New variable.
	(type_exp, exp, fblock, variable, type): Update calls to
	write_exp* and similars to use parser state.
	(yylex): Likewise.
	(m2_parse): New function.
	* m2-lang.h: Forward declare "struct parser_state".
	(m2_parse): Add "struct parser_state" argument.
	* objc-lang.c (end_msglist): Add "struct parser_state" argument.
	* objc-lang.h: Forward declare "struct parser_state".
	(end_msglist): Add "struct parser_state" argument.
	* p-exp.y (parse_type): Rewrite macro to use parser state.
	(yyparse): Redefine macro to pascal_parse_internal.
	(pstate): New variable.
	(parse_number): Add "struct parser_state" argument.
	(type_exp, exp1, exp, qualified_name, variable): Update calls to
	write_exp* and similars in order to use parser state.
	(parse_number, yylex): Adjust code to use parser state.
	(pascal_parse): New function.
	* p-lang.h: Forward declare "struct parser_state".
	(pascal_parse): Add "struct parser_state" argument.
	* go-exp.y (parse_type): Rewrite macro to use parser state.
	(yyparse): Redefine macro to go_parse_internal.
	(pstate): New variable.
	(parse_number): Add "struct parser_state" argument.
	(type_exp, exp1, exp, variable, type): Update calls to
	write_exp* and similars in order to use parser state.
	(parse_number, lex_one_token, classify_name, yylex): Adjust code
	to use parser state.
	(go_parse): Likewise.
	* go-lang.h: Forward declare "struct parser_state".
	(go_parse): Add "struct parser_state" argument.
2014-03-27 19:10:40 -03:00

440 lines
12 KiB
C

/* Target-dependent code for GNU/Linux AArch64.
Copyright (C) 2009-2014 Free Software Foundation, Inc.
Contributed by ARM Ltd.
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 "gdbarch.h"
#include "glibc-tdep.h"
#include "linux-tdep.h"
#include "aarch64-tdep.h"
#include "aarch64-linux-tdep.h"
#include "osabi.h"
#include "solib-svr4.h"
#include "symtab.h"
#include "tramp-frame.h"
#include "trad-frame.h"
#include "inferior.h"
#include "regcache.h"
#include "regset.h"
#include "cli/cli-utils.h"
#include "stap-probe.h"
#include "parser-defs.h"
#include "user-regs.h"
#include <ctype.h>
/* The general-purpose regset consists of 31 X registers, plus SP, PC,
and PSTATE registers, as defined in the AArch64 port of the Linux
kernel. */
#define AARCH64_LINUX_SIZEOF_GREGSET (34 * X_REGISTER_SIZE)
/* The fp regset consists of 32 V registers, plus FPCR and FPSR which
are 4 bytes wide each, and the whole structure is padded to 128 bit
alignment. */
#define AARCH64_LINUX_SIZEOF_FPREGSET (33 * V_REGISTER_SIZE)
/* Signal frame handling.
+----------+ ^
| saved lr | |
+->| saved fp |--+
| | |
| | |
| +----------+
| | saved lr |
+--| saved fp |
^ | |
| | |
| +----------+
^ | |
| | signal |
| | |
| | saved lr |-->interrupted_function_pc
+--| saved fp |
| +----------+
| | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
+--| saved fp |<- FP
| |
| |<- SP
+----------+
On signal delivery, the kernel will create a signal handler stack
frame and setup the return address in LR to point at restorer stub.
The signal stack frame is defined by:
struct rt_sigframe
{
siginfo_t info;
struct ucontext uc;
};
typedef struct
{
... 128 bytes
} siginfo_t;
The ucontext has the following form:
struct ucontext
{
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
struct sigcontext uc_mcontext;
};
typedef struct sigaltstack
{
void *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
struct sigcontext
{
unsigned long fault_address;
unsigned long regs[31];
unsigned long sp; / * 31 * /
unsigned long pc; / * 32 * /
unsigned long pstate; / * 33 * /
__u8 __reserved[4096]
};
The restorer stub will always have the form:
d28015a8 movz x8, #0xad
d4000001 svc #0x0
We detect signal frames by snooping the return code for the restorer
instruction sequence.
The handler then needs to recover the saved register set from
ucontext.uc_mcontext. */
/* These magic numbers need to reflect the layout of the kernel
defined struct rt_sigframe and ucontext. */
#define AARCH64_SIGCONTEXT_REG_SIZE 8
#define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
#define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
#define AARCH64_SIGCONTEXT_XO_OFFSET 8
/* Implement the "init" method of struct tramp_frame. */
static void
aarch64_linux_sigframe_init (const struct tramp_frame *self,
struct frame_info *this_frame,
struct trad_frame_cache *this_cache,
CORE_ADDR func)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
CORE_ADDR fp = get_frame_register_unsigned (this_frame, AARCH64_FP_REGNUM);
CORE_ADDR sigcontext_addr =
sp
+ AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
+ AARCH64_UCONTEXT_SIGCONTEXT_OFFSET;
int i;
for (i = 0; i < 31; i++)
{
trad_frame_set_reg_addr (this_cache,
AARCH64_X0_REGNUM + i,
sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
+ i * AARCH64_SIGCONTEXT_REG_SIZE);
}
trad_frame_set_reg_addr (this_cache, AARCH64_FP_REGNUM, fp);
trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM, fp + 8);
trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, fp + 8);
trad_frame_set_id (this_cache, frame_id_build (fp, func));
}
static const struct tramp_frame aarch64_linux_rt_sigframe =
{
SIGTRAMP_FRAME,
4,
{
/* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
{0xd2801168, -1},
/* svc 0x0 (o=0, l=1)
1101 0100 oooi iiii iiii iiii iii0 00ll */
{0xd4000001, -1},
{TRAMP_SENTINEL_INSN, -1}
},
aarch64_linux_sigframe_init
};
/* Fill GDB's register array with the general-purpose register values
in the buffer pointed by GREGS_BUF. */
void
aarch64_linux_supply_gregset (struct regcache *regcache,
const gdb_byte *gregs_buf)
{
int regno;
for (regno = AARCH64_X0_REGNUM; regno <= AARCH64_CPSR_REGNUM; regno++)
regcache_raw_supply (regcache, regno,
gregs_buf + X_REGISTER_SIZE
* (regno - AARCH64_X0_REGNUM));
}
/* The "supply_regset" function for the general-purpose register set. */
static void
supply_gregset_from_core (const struct regset *regset,
struct regcache *regcache,
int regnum, const void *regbuf, size_t len)
{
aarch64_linux_supply_gregset (regcache, (const gdb_byte *) regbuf);
}
/* Fill GDB's register array with the floating-point register values
in the buffer pointed by FPREGS_BUF. */
void
aarch64_linux_supply_fpregset (struct regcache *regcache,
const gdb_byte *fpregs_buf)
{
int regno;
for (regno = AARCH64_V0_REGNUM; regno <= AARCH64_V31_REGNUM; regno++)
regcache_raw_supply (regcache, regno,
fpregs_buf + V_REGISTER_SIZE
* (regno - AARCH64_V0_REGNUM));
regcache_raw_supply (regcache, AARCH64_FPSR_REGNUM,
fpregs_buf + V_REGISTER_SIZE * 32);
regcache_raw_supply (regcache, AARCH64_FPCR_REGNUM,
fpregs_buf + V_REGISTER_SIZE * 32 + 4);
}
/* The "supply_regset" function for the floating-point register set. */
static void
supply_fpregset_from_core (const struct regset *regset,
struct regcache *regcache,
int regnum, const void *regbuf, size_t len)
{
aarch64_linux_supply_fpregset (regcache, (const gdb_byte *) regbuf);
}
/* Implement the "regset_from_core_section" gdbarch method. */
static const struct regset *
aarch64_linux_regset_from_core_section (struct gdbarch *gdbarch,
const char *sect_name,
size_t sect_size)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
if (strcmp (sect_name, ".reg") == 0
&& sect_size == AARCH64_LINUX_SIZEOF_GREGSET)
{
if (tdep->gregset == NULL)
tdep->gregset = regset_alloc (gdbarch, supply_gregset_from_core,
NULL);
return tdep->gregset;
}
if (strcmp (sect_name, ".reg2") == 0
&& sect_size == AARCH64_LINUX_SIZEOF_FPREGSET)
{
if (tdep->fpregset == NULL)
tdep->fpregset = regset_alloc (gdbarch, supply_fpregset_from_core,
NULL);
return tdep->fpregset;
}
return NULL;
}
/* Implementation of `gdbarch_stap_is_single_operand', as defined in
gdbarch.h. */
static int
aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
{
return (*s == '#' || isdigit (*s) /* Literal number. */
|| *s == '[' /* Register indirection. */
|| isalpha (*s)); /* Register value. */
}
/* This routine is used to parse a special token in AArch64's assembly.
The special tokens parsed by it are:
- Register displacement (e.g, [fp, #-8])
It returns one if the special token has been parsed successfully,
or zero if the current token is not considered special. */
static int
aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
struct stap_parse_info *p)
{
if (*p->arg == '[')
{
/* Temporary holder for lookahead. */
const char *tmp = p->arg;
char *endp;
/* Used to save the register name. */
const char *start;
char *regname;
int len;
int got_minus = 0;
long displacement;
struct stoken str;
++tmp;
start = tmp;
/* Register name. */
while (isalnum (*tmp))
++tmp;
if (*tmp != ',')
return 0;
len = tmp - start;
regname = alloca (len + 2);
strncpy (regname, start, len);
regname[len] = '\0';
if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
error (_("Invalid register name `%s' on expression `%s'."),
regname, p->saved_arg);
++tmp;
tmp = skip_spaces_const (tmp);
/* Now we expect a number. It can begin with '#' or simply
a digit. */
if (*tmp == '#')
++tmp;
if (*tmp == '-')
{
++tmp;
got_minus = 1;
}
else if (*tmp == '+')
++tmp;
if (!isdigit (*tmp))
return 0;
displacement = strtol (tmp, &endp, 10);
tmp = endp;
/* Skipping last `]'. */
if (*tmp++ != ']')
return 0;
/* The displacement. */
write_exp_elt_opcode (&p->pstate, OP_LONG);
write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
write_exp_elt_longcst (&p->pstate, displacement);
write_exp_elt_opcode (&p->pstate, OP_LONG);
if (got_minus)
write_exp_elt_opcode (&p->pstate, UNOP_NEG);
/* The register name. */
write_exp_elt_opcode (&p->pstate, OP_REGISTER);
str.ptr = regname;
str.length = len;
write_exp_string (&p->pstate, str);
write_exp_elt_opcode (&p->pstate, OP_REGISTER);
write_exp_elt_opcode (&p->pstate, BINOP_ADD);
/* Casting to the expected type. */
write_exp_elt_opcode (&p->pstate, UNOP_CAST);
write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
write_exp_elt_opcode (&p->pstate, UNOP_CAST);
write_exp_elt_opcode (&p->pstate, UNOP_IND);
p->arg = tmp;
}
else
return 0;
return 1;
}
static void
aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
static const char *const stap_integer_prefixes[] = { "#", "", NULL };
static const char *const stap_register_prefixes[] = { "", NULL };
static const char *const stap_register_indirection_prefixes[] = { "[",
NULL };
static const char *const stap_register_indirection_suffixes[] = { "]",
NULL };
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
tdep->lowest_pc = 0x8000;
linux_init_abi (info, gdbarch);
set_solib_svr4_fetch_link_map_offsets (gdbarch,
svr4_lp64_fetch_link_map_offsets);
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
/* Shared library handling. */
set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe);
/* Enable longjmp. */
tdep->jb_pc = 11;
set_gdbarch_regset_from_core_section (gdbarch,
aarch64_linux_regset_from_core_section);
/* SystemTap related. */
set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
set_gdbarch_stap_register_indirection_prefixes (gdbarch,
stap_register_indirection_prefixes);
set_gdbarch_stap_register_indirection_suffixes (gdbarch,
stap_register_indirection_suffixes);
set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand);
set_gdbarch_stap_parse_special_token (gdbarch,
aarch64_stap_parse_special_token);
}
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_aarch64_linux_tdep;
void
_initialize_aarch64_linux_tdep (void)
{
gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX,
aarch64_linux_init_abi);
}