Commit Graph

31154 Commits

Author SHA1 Message Date
Tom Tromey
2f98abe174 Introduce fortran_undetermined
This adds class fortran_undetermined, which implements
OP_F77_UNDETERMINED_ARGLIST.  fortran_range_operation is also added
here, as it is needed by fortran_undetermined.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_addr_operation) <get_expression>: New
	method.
	* f-lang.c (fortran_undetermined::value_subarray)
	(fortran_undetermined::evaluate): New methods.
	(fortran_prepare_argument): New overload.
	* f-exp.h (class fortran_range_operation)
	(class fortran_undetermined): New classes.
2021-03-08 07:28:30 -07:00
Tom Tromey
638fd74a61 Implement Rust funcall operation
This adds the special code needed to handle the Rust function call
operation.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_structop::evaluate_funcall): New method.
	* rust-exp.h (class rust_structop) <evaluate_funcall>: Declare
	method.
2021-03-08 07:28:29 -07:00
Tom Tromey
a00b7254fb Implement function call operations
This implement function call operations.

The current function call code relies on some very lengthy code
(evaluate_funcall is 398 lines...) to distinguish between the
different opcodes that might appear in the callee position.

Rather than try to replicate this, and have a function that tried to
dissect many different kinds of operation subclass, this patch instead
puts the work into the callee.  A new operation::evaluate_funcall
method is added, and then this is overridden in the classes that
require special treatment.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expression.h (class operation) <evaluate_funcall>: New methods.
	* expop.h (class scope_operation) <evaluate_funcall>: New method.
	(class var_value_operation) <evaluate_funcall>: New method.
	(class structop_base_operation) <evaluate_funcall>: New method.
	(class var_msym_value_operation) <evaluate_funcall>: New method.
	(class structop_member_base): New class.
	(class structop_member_operation): Derive from
	structop_member_base.
	(class structop_mptr_operation): Derive from
	structop_member_base.
	(class funcall_operation): New class.
	* eval.c (operation::evaluate_funcall)
	(var_value_operation::evaluate_funcall)
	(scope_operation::evaluate_funcall)
	(structop_member_base::evaluate_funcall)
	(structop_base_operation::evaluate_funcall): New methods.
2021-03-08 07:28:29 -07:00
Tom Tromey
1c02eb3035 Introduce array_operation
This adds class array_operation, which implements OP_ARRAY.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class array_operation): New.
	* eval.c (array_operation::evaluate_struct_tuple)
	(array_operation::evaluate): New methods.
2021-03-08 07:28:29 -07:00
Tom Tromey
e447908052 Introduce class adl_func_operation
This adds class adl_func_operation, which implements
argument-dependent lookup function calls.

Other function calls will be handled in a different way.  However,
because ADL calls were created in a single spot in the C++ parser, and
because they had different semantics from the other cases, it was
convenient to treat them specially.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class adl_func_operation): New.
	* eval.c (adl_func_operation::evaluate): New method.
2021-03-08 07:28:29 -07:00
Tom Tromey
95d49dfbba Introduce ada_unop_range_operation
This adds class ada_unop_range_operation, which implements
UNOP_IN_RANGE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_unop_in_range): No longer static.
	* ada-exp.h (class ada_unop_range_operation): New.
2021-03-08 07:28:28 -07:00
Tom Tromey
7c15d377de Implement some Ada unary operations
This implements a few Ada unary operations, using the existing
unop_operation template class.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_unop_neg, ada_atr_tag, ada_atr_size, ada_abs):
	No longer static.
	* ada-exp.h (ada_neg_operation, ada_atr_tag_operation)
	(ada_atr_size_operation, ada_abs_operation): New typedefs.
2021-03-08 07:28:28 -07:00
Tom Tromey
5019124b1d Implement the "&&" and "||" operators
This implements the "&&" and "||" operators.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class logical_and_operation)
	(class logical_or_operation): New.
	* eval.c (logical_and_operation::evaluate)
	(logical_or_operation::evaluate): New methods.
	* ax-gdb.c (logical_and_operation::do_generate_ax)
	(logical_or_operation::do_generate_ax): New methods.
2021-03-08 07:28:28 -07:00
Tom Tromey
2bc9b40ce1 Add two simple Modula-2 operations
This adds a couple of simple Modula-2 operations.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* m2-lang.c (eval_op_m2_high, eval_op_m2_subscript): No longer
	static.
	* m2-exp.h: New file.
2021-03-08 07:28:28 -07:00
Tom Tromey
5947d337d6 Introduce rust_aggregate_operation
This adds class rust_aggregate_operation, which implements
OP_AGGREGATE for Rust.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_aggregate_operation::evaluate): New method.
	* rust-exp.h (class rust_aggregate_operation): New.
2021-03-08 07:28:27 -07:00
Tom Tromey
e4407a202d Implement Rust field operations
This implements the field operations STRUCTOP_STRUCT and
STRUCTOP_ANONYMOUS, for Rust.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_struct_anon, eval_op_rust_structop):
	No longer static.
	* rust-exp.h (class rust_struct_anon): New.
	(class rust_structop): New.
2021-03-08 07:28:27 -07:00
Tom Tromey
9db6b6ddbd Introduce rust_range_operation
This adds class rust_range_operation, which implements OP_RANGE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_range): No longer static.
	* rust-exp.h (class rust_range_operation): New.
2021-03-08 07:28:27 -07:00
Tom Tromey
6ce1ad679a Introduce rust_subscript_operation
This adds class rust_subscript_operation, which implements
BINOP_SUBSCRIPT for Rust.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_subscript): No longer static.
	* rust-exp.h (class rust_subscript_operation): New.
2021-03-08 07:28:27 -07:00
Tom Tromey
11dd3dce44 Introduce rust_unop_ind_operation
This adds class rust_unop_ind_operation, which implements UNOP_IND for
Rust.  Rust requires a special case here to handle trait objects.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_ind): No longer static.  Add "opcode"
	parameter.
	(rust_evaluate_subexp): Update.
	* rust-exp.h (class rust_unop_ind_operation): New.
2021-03-08 07:28:27 -07:00
Tom Tromey
6fab435953 Implement some Rust operations
This implements some straightforward Rust operations, using existing
template classes.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_complement, eval_op_rust_array): No
	longer static.  Add "opcode" parameter.
	(rust_evaluate_subexp): Update.
	* rust-exp.h: New file.
2021-03-08 07:28:26 -07:00
Tom Tromey
9dcd3e2957 Implement several Fortran operations
This implements several straightforward Fortran operations, primarily
by reusing existing template classes.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_abs, eval_op_f_mod, eval_op_f_ceil)
	(eval_op_f_floor, eval_op_f_modulo, eval_op_f_cmplx)
	(eval_op_f_kind): No longer static.  Add "opcode" parameter.
	(evaluate_subexp_f): Update.
	* f-exp.h: New file.
2021-03-08 07:28:26 -07:00
Tom Tromey
fc715eb288 Introduce ada_ternop_range_operation
This adds class ada_ternop_range_operation, which implements
TERNOP_IN_RANGE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_ternop_range_operation::evaluate): New method.
	* ada-exp.h (class ada_ternop_range_operation): New.
2021-03-08 07:28:26 -07:00
Tom Tromey
cc6bd32eea Introduce ada_qual_operation
This adds class ada_qual_operation, which implements UNOP_QUAL.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_qual_operation::evaluate): New method.
	* ada-exp.h (class ada_qual_operation): New.
2021-03-08 07:28:26 -07:00
Tom Tromey
42fecb6183 Introduce ada_string_operation
This adds class ada_string_operation, which implements string
constants for Ada.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_string_operation::evaluate): New method.
	* ada-exp.h (class ada_string_operation): New.
2021-03-08 07:28:25 -07:00
Tom Tromey
03070ee9c7 Introduce ada_wrapped_operation
This adds class ada_wrapped_operation, which is used to wrap some
generic operations with a bit of Ada-specific handling.  This
corresponds to the old "default" case in ada_evaluate_subexp.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_wrapped_operation::evaluate): New method.
	* ada-exp.h: New file.
2021-03-08 07:28:25 -07:00
Tom Tromey
821e72d775 Introduce multi_subscript_operation
This adds class multi_subscript_operation, which implements
MULTI_SUBSCRIPT.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class multi_subscript_operation): New.
	* eval.c (multi_subscript_operation::evaluate): New method.
2021-03-08 07:28:25 -07:00
Tom Tromey
085734dd95 Introduce objc_msgcall_operation
This adds class objc_msgcall_operation, which implements
OP_OBJC_MSGCALL.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (objc_msgcall_operation::evaluate): New method.
	* c-exp.h (class objc_msgcall_operation): New.
2021-03-08 07:28:25 -07:00
Tom Tromey
e82a5afced Introduce var_value_operation
This adds class var_value_operation, which implements OP_VAR_VALUE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class var_value_operation): New.
	* eval.c (var_value_operation::evaluate)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_with_coercion)
	(var_value_operation::evaluate_for_sizeof)
	(var_value_operation::evaluate_for_cast): New methods.
	* ax-gdb.c (var_value_operation::do_generate_ax): New method.
2021-03-08 07:28:24 -07:00
Tom Tromey
d9ad79d880 Implement C++ cast operations
This adds class cxx_cast_operation, which is used to implement the C++
dynamic_cast and reinterpret_cast operations.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (cxx_cast_ftype): New typedef.
	(cxx_cast_operation): New template.
	(dynamic_cast_operation, reinterpret_cast_operation): New
	typedefs.
2021-03-08 07:28:24 -07:00
Tom Tromey
292382f47e Introduce unop_cast_type_operation
This adds class unop_cast_type_operation, which implements
UNOP_CAST_TYPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_cast_type_operation): New.
	* ax-gdb.c (unop_cast_type_operation::do_generate_ax): New
	method.
2021-03-08 07:28:24 -07:00
Tom Tromey
165a813a3a Introduce unop_cast_operation
This adds class unop_cast_operation, which implements UNOP_CAST.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_cast_operation): New.
	* ax-gdb.c (unop_cast_operation::do_generate_ax): New method.
2021-03-08 07:28:24 -07:00
Tom Tromey
e5946e1604 Introduce assign_modify_operation
This adds class assign_modify_operation, which implements
BINOP_ASSIGN_MODIFY.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class assign_modify_operation): New.
	* eval.c (eval_binop_assign_modify): No longer static.
	* ax-gdb.c (assign_modify_operation::do_generate_ax): New method.
2021-03-08 07:28:24 -07:00
Tom Tromey
4078678289 Introduce assign_operation
This adds class assign_operation, which implements BINOP_ASSIGN.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class assign_operation): New.
	* ax-gdb.c (assign_operation::do_generate_ax): New method.
2021-03-08 07:28:23 -07:00
Tom Tromey
44b675c89b Introduce type_instance_operation
This adds class type_instance_operation, which implements
TYPE_INSTANCE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class type_instance_operation): New.
	* eval.c (type_instance_operation::evaluate): New method.
2021-03-08 07:28:23 -07:00
Tom Tromey
f6b4232691 Introduce op_this_operation
This adds class op_this_operation, which implements OP_THIS.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class op_this_operation): New.
	* ax-gdb.c (op_this_operation::do_generate_ax): New method.
2021-03-08 07:28:23 -07:00
Tom Tromey
cbc18219d3 Implement UNOP_MEMVAL and UNOP_MEMVAL_TYPE
This adds class unop_memval_operation and unop_memval_type_operation,
which implement UNOP_MEMVAL and UNOP_MEMVAL_TYPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_memval_operation)
	(class unop_memval_type_operation): New.
	* eval.c (eval_op_memval): No longer static.
	(unop_memval_operation::evaluate_for_address)
	(unop_memval_type_operation::evaluate_for_address)
	(unop_memval_operation::evaluate_for_sizeof)
	(unop_memval_type_operation::evaluate_for_sizeof): New methods.
	* ax-gdb.c (unop_memval_operation::do_generate_ax)
	(unop_memval_type_operation::do_generate_ax): New methods.
2021-03-08 07:28:23 -07:00
Tom Tromey
ae4bb61e19 Introduce unop_alignof_operation
This adds class unop_alignof_operation, which implements UNOP_ALIGNOF.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_alignof_operation): New.
	* eval.c (eval_op_alignof): No longer static.
2021-03-08 07:28:22 -07:00
Tom Tromey
85d23bda83 Introduce unop_sizeof_operation
This adds class unop_sizeof_operation, which implements UNOP_SIZEOF.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_sizeof_operation): New.
	* ax-gdb.c (unop_sizeof_operation::do_generate_ax): New method.
2021-03-08 07:28:22 -07:00
Tom Tromey
14aff815df Introduce unop_addr_operation
This adds class unop_addr_operation, which implements UNOP_ADDR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_addr_operation): New.
	* ax-gdb.c (gen_expr_unop) <case UNOP_ADDR>: New.
2021-03-08 07:28:22 -07:00
Tom Tromey
929f3aa742 Introduce typeid_operation
This adds class typeid_operation, which implements OP_TYPEID.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class typeid_operation): New.
2021-03-08 07:28:22 -07:00
Tom Tromey
0af8829eb1 Introduce decltype_operation
This adds class decltype_operation, which implements OP_DECLTYPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class decltype_operation): New.
2021-03-08 07:28:22 -07:00
Tom Tromey
4efc574cb9 Introduce typeof_operation
This adds class typeof_operation, which implements OP_TYPEOF.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class typeof_operation): New.
2021-03-08 07:28:21 -07:00
Tom Tromey
5b5f5140e1 Introduce type_operation
This adds class type_operation, which implements OP_TYPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class type_operation): New.
	* eval.c (eval_op_type): No longer static.
2021-03-08 07:28:21 -07:00
Tom Tromey
876469ffa1 Introduce unop_ind_operation
This adds class unop_ind_operation, which implements UNOP_IND.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class unop_ind_base_operation)
	(class unop_ind_operation): New.
	* eval.c (eval_op_ind): No longer static.  Remove "op" parameter.
	(unop_ind_base_operation::evaluate_for_address)
	(unop_ind_base_operation::evaluate_for_sizeof): New method.
	* ax-gdb.c (gen_expr_unop) <case UNOP_IND>: New.
2021-03-08 07:28:21 -07:00
Tom Tromey
6d89e2962a Implement unary increment and decrement operations
This implements the unary increment and decrement operations, "++" and
"--".

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (unop_incr_operation): New template.
	(preinc_operation, predec_operation, postinc_operation)
	(postdec_operation): New typedefs.
	* eval.c (eval_op_preinc, eval_op_predec, eval_op_postinc)
	(eval_op_postdec): No longer static.
2021-03-08 07:28:21 -07:00
Tom Tromey
9307d17b7a Implement some unary operations
This introduces a couple of new template classes and then uses them to
implement some simple unary operations.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (unary_ftype): New typedef.
	(unop_operation, usual_ax_binop_operation): New templates.
	(unary_plus_operation, unary_neg_operation)
	(unary_complement_operation, unary_logical_not_operation): New
	typedefs.
	* eval.c (eval_op_plus, eval_op_neg, eval_op_complement)
	(eval_op_lognot): No longer static.
	* ax-gdb.c (gen_expr_unop): New function.
2021-03-08 07:28:20 -07:00
Tom Tromey
ae64ba58b3 Introduce comma_operation
This adds class comma_operation, which implements BINOP_COMMA.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ax-gdb.c (comma_operation::do_generate_ax): New method.
2021-03-08 07:28:20 -07:00
Tom Tromey
d4eff4c122 Introduce repeat_operation
This adds class repeat_operation, which implements BINOP_REPEAT.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class repeat_operation): New.
	* eval.c (eval_op_repeat): No longer static.  Remove "op"
	parameter.
	(evaluate_subexp_standard): Update.
	* ax-gdb.c (repeat_operation::do_generate_ax): New method.
2021-03-08 07:28:20 -07:00
Tom Tromey
46916f2bcb Implement binary comparison operations
This implements the binary comparison operations via a template class.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class comparison_operation): New.
	(equal_operation, notequal_operation, less_operation)
	(gtr_operation, geq_operation, leq_operation): New typedefs.
	* eval.c (eval_op_equal, eval_op_notequal, eval_op_less)
	(eval_op_gtr, eval_op_geq, eval_op_leq): No longer static.
2021-03-08 07:28:20 -07:00
Tom Tromey
224d6424ba Introduce subscript_operation
This adds class subscript_operation, which implements BINOP_SUBSCRIPT.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class subscript_operation): New.
	* eval.c (eval_op_subscript): No longer static.
2021-03-08 07:28:19 -07:00
Tom Tromey
373907ffb2 Introduce binop_operation
This adds two new template classes, binop_operation and
usual_ax_binop_operation, and then uses these to implement a number of
binary operations that follow similar patterns.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class binop_operation, class usual_ax_binop_operation):
	New.
	(exp_operation, intdiv_operation, mod_operation, mul_operation)
	(div_operation, rem_operation, lsh_operation, rsh_operation)
	(bitwise_and_operation, bitwise_ior_operation)
	(bitwise_xor_operation): New typedefs.
	* eval.c (eval_op_binary): No longer static.
2021-03-08 07:28:19 -07:00
Tom Tromey
5133d78b7b Introduce sub_operation
This adds class sub_operation, which implements BINOP_SUB.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class sub_operation): New.
	* eval.c (eval_op_sub): No longer static.  Remove "op" parameter.
	(evaluate_subexp_standard): Update.
2021-03-08 07:28:19 -07:00
Tom Tromey
a94323b607 Introduce add_operation
This adds class add_operation, which implements BINOP_ADD.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class add_operation): New.
	* eval.c (eval_op_add): No longer static.  Remove "op" parameter.
	(evaluate_subexp_standard): Update.
2021-03-08 07:28:19 -07:00
Tom Tromey
e51e26a090 Introduce concat_operation
This adds class concat_operation, which implements BINOP_CONCAT.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class concat_operation): New.
	* eval.c (eval_op_concat): No longer static.  Remove "op"
	parameter.
	(evaluate_subexp_standard): Update.
2021-03-08 07:28:19 -07:00
Tom Tromey
07f724a8c6 Introduce structop_member_operation and structop_mptr_operation
This adds class structop_member_operation and structop_mptr_operation,
which implement STRUCTOP_MEMBER and STRUCTOP_MPTR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class structop_member_operation)
	(class structop_mptr_operation): New.
	* eval.c (eval_op_member): No longer static.
2021-03-08 07:28:18 -07:00
Tom Tromey
ab0609be83 Introduce structop_ptr_operation
This adds class structop_ptr_operation, which implements STRUCTOP_PTR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class structop_ptr_operation): New.
	* eval.c (eval_op_structop_ptr): No longer static.  Remove "op"
	parameter.
2021-03-08 07:28:18 -07:00
Tom Tromey
808b22cfd7 Introduce structop_operation
This adds class structop_base_operation and structop_operation, which
implement STRUCTOP_STRUCT.  The base class exists to unify the
completion code between STRUCTOP_STRUCT and STRUCTOP_PTR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class structop_base_operation)
	(class structop_operation): New.
	* eval.c (eval_op_structop_struct): No longer static.
2021-03-08 07:28:18 -07:00
Tom Tromey
8cfd3e95b7 Introduce complex_operation
This adds class complex_operation, which implements OP_COMPLEX.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class complex_operation): New.
2021-03-08 07:28:18 -07:00
Tom Tromey
09db370026 Introduce objc_selector_operation
This adds class objc_selector_operation, which implements
OP_OBJC_SELECTOR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_objc_selector): No longer static.
	* c-exp.h (class objc_selector_operation): New.
2021-03-08 07:28:17 -07:00
Tom Tromey
06dc61b9df Introduce objc_nsstring_operation
This adds class objc_nsstring_operation, which implements
OP_OBJC_NSSTRING.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c: Include c-exp.h.
	* c-exp.h (class objc_nsstring_operation): New.
2021-03-08 07:28:17 -07:00
Tom Tromey
72d0a71134 Add c-exp.h and c_string_operation
This adds the new file c-exp.h, where C operation classes will be
declared.  The first such class, c_string_operation, is also added
here.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* c-lang.c (c_string_operation::evaluate): New method.
	* c-exp.h: New file.
2021-03-08 07:28:17 -07:00
Tom Tromey
9186293fd6 Introduce ternop_cond_operation
This adds class ternop_cond_operation, which implements TERNOP_COND.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class ternop_cond_operation): New.
	* ax-gdb.c (ternop_cond_operation::do_generate_ax): New method.
2021-03-08 07:28:17 -07:00
Tom Tromey
1594e0bb3d Introduce ternop_slice_operation
This adds class ternop_slice_operation, which implements TERNOP_SLICE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class ternop_slice_operation): New.
	* eval.c (eval_op_ternop): No longer static.
2021-03-08 07:28:17 -07:00
Tom Tromey
b50db09ff9 Introduce string_operation
This adds string_operation, which implements OP_STRING for most
languages (C has its own variant).

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class string_operation): New.
	* eval.c (eval_op_string): No longer static.
2021-03-08 07:28:16 -07:00
Tom Tromey
e6e01e16c5 Introduce internalvar_operation
This adds class internalvar_operation, which implements
OP_INTERNALVAR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class internalvar_operation): New.
	* ax-gdb.c (internalvar_operation::do_generate_ax): New method.
2021-03-08 07:28:16 -07:00
Tom Tromey
e6985c5e45 Introduce bool_operation
This adds class bool_operation, which implements OP_BOOL.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class bool_operation): New.
2021-03-08 07:28:16 -07:00
Tom Tromey
55bdbff857 Introduce register_operation
This adds class register_operation, which implements OP_REGISTER.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class register_operation): New.
	* eval.c (eval_op_register): No longer static.
	* ax-gdb.c (register_operation::do_generate_ax): New method.
2021-03-08 07:28:16 -07:00
Tom Tromey
247d935b83 Introduce last_operation
This adds class last_operation, which implements OP_LAST.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class last_operation): New.
2021-03-08 07:28:15 -07:00
Tom Tromey
176793957a Introduce func_static_var_operation
This adds class func_static_var_operation, which implements
OP_FUNC_STATIC_VAR.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class func_static_var_operation): New.
	* eval.c (eval_op_func_static_var): No longer static.
2021-03-08 07:28:15 -07:00
Tom Tromey
b5cc3923de Introduce var_entry_value_operation
This adds class var_entry_value_operation, which implements
OP_VAR_ENTRY_VALUE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class var_entry_value_operation): New.
	* eval.c (eval_op_var_entry_value): No longer static.
2021-03-08 07:28:15 -07:00
Tom Tromey
0c8effa32e Introduce var_msym_value_operation
This adds class var_msym_value_operation, which implements
OP_VAR_MSYM_VALUE.  A new method is added to class operation in order
to support a special case in minsym evaluation.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expression.h (class operation) <set_outermost>: New method.
	* expop.h (class var_msym_value_operation): New.
	* eval.c (eval_op_var_msym_value): No longer static.
	(var_msym_value_operation::evaluate_for_address)
	(var_msym_value_operation::evaluate_for_sizeof)
	(var_msym_value_operation::evaluate_for_cast): New methods.
	* ax-gdb.c (var_msym_value_operation::do_generate_ax): New
	method.
2021-03-08 07:28:15 -07:00
Tom Tromey
d336c29e3f Introduce long_const_operation
This adds class long_const_operation, which holds a scalar constant.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class long_const_operation): New.
	* ax-gdb.c (long_const_operation::do_generate_ax): New method.
2021-03-08 07:28:15 -07:00
Tom Tromey
d5ab122c48 Introduce scope_operation
This adds class scope_operation, an implementation of OP_SCOPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (class scope_operation): New.
	* eval.c (eval_op_scope): No longer static.
	(scope_operation::evaluate_for_address): New method.
	* ax-gdb.c (scope_operation::do_generate_ax): New method.
2021-03-08 07:28:14 -07:00
Tom Tromey
cae26a0cb0 Introduce float_const_operation
This adds class float_const_operation, an operation holding a
floating-point constant.  Unlike most other new operations, this one
requires a custom 'dump' method.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expprint.c (float_const_operation::dump): New method.
	* expop.h (float_data): New typedef.
	(class float_const_operation): New.
2021-03-08 07:28:14 -07:00
Tom Tromey
75f9892d43 Add two agent expression helper functions
This adds a couple of agent expression helper functions that will be
useful when implementing various operations.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expop.h (gen_expr_binop, gen_expr_structop): Declare.
	* ax-gdb.c (gen_expr_binop): New function.
	(gen_expr_structop): Likewise.
2021-03-08 07:28:14 -07:00
Tom Tromey
de401988ae Implement dumping
This patch implements the dumping methods for tuple_holding_operation.
A number of overloads are used.  Note that no default case is given.
This approach makes it simple to detect when a new overload is needed
-- compilation will fail.  (There is an example of this in a later
patch in the series.)

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expprint.c (expr::dump_for_expression): New functions.
	* expop.h (dump_for_expression): New overloads.
	(tuple_holding_operation::dump, tuple_holding_operation::do_dump):
	Update.
2021-03-08 07:28:14 -07:00
Tom Tromey
e2803273a0 Introduce class operation
This patch introduces class operation, the new base class for all
expression operations.

In the new approach, an operation is simply a class that presents a
certain interface.  Operations own their operands, and management is
done via unique_ptr.

The operation interface is largely ad hoc, based on the evolution of
expression handling in GDB.  Parts (for example,
evaluate_with_coercion) are probably redundant; however I took this
approach to try to avoid mixing different kinds of refactorings.

In some specific situations, rather than add a generic method across
the entire operation class hierarchy, I chose instead to use
dynamic_cast and specialized methods on certain concrete subclasses.
This will appear in some subsequent patches.

One goal of this work is to avoid the kinds of easy-to-make errors
that affected the old implementation.  To this end, some helper
subclasses are also added here.  These helpers automate the
implementation of the 'dump', 'uses_objfile', and 'constant_p'
methods.  Nearly every concrete operation that is subsequently added
will use these facilities.  (Note that the 'dump' implementation is
only outlined here, the body appears in the next patch.)

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* expression.h (expr::operation): New class.
	(expr::make_operation): New function.
	(expr::operation_up): New typedef.
	* expop.h: New file.
	* eval.c (operation::evaluate_for_cast)
	(operation::evaluate_for_address, operation::evaluate_for_sizeof):
	New methods.
	* ax-gdb.c (operation::generate_ax): New method.
2021-03-08 07:28:13 -07:00
Tom Tromey
e18c58f290 Split gen_expr_binop_rest
This splits gen_expr_binop_rest into two overloads.  One overload
retains the "pc" parameter, while the other does not, and furthermore
does not call gen_expr on the left-hand-side.  This split is useful
for subsequent patches in the new expression evaluation approach.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ax-gdb.c (gen_expr_binop_rest): Remove "pc" parameter.
	(gen_expr_binop_rest): New overload.
2021-03-08 07:28:13 -07:00
Tom Tromey
c0d7ed8ca8 Split out eval_multi_subscript
This splits MULTI_SUBSCRIPT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_multi_subscript): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:13 -07:00
Tom Tromey
dd5fd28346 Split out ada_binop_exp
This splits BINOP_EXP into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_binop_exp): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:13 -07:00
Tom Tromey
3848abd6e1 Change value_val_atr to ada_val_atr
This renames value_val_atr to ada_val_atr, changing its parameters to
more closely mirror other expression helpers.  The
EVAL_AVOID_SIDE_EFFECTS case is moved into this function as well.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_val_atr): Rename from value_val_atr.  Change
	parameters.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:13 -07:00
Tom Tromey
38dc70cfee Split out ada_binop_minmax
This splits OP_ATR_MIN and OP_ATR_MAX into a new function for future
use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_binop_minmax): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:12 -07:00
Tom Tromey
b84564fc8c Split out ada_unop_atr
This splits some Ada attribute operations into a new function for
future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_unop_atr): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:12 -07:00
Tom Tromey
b467efaa91 Split out ada_binop_in_bounds
This splits BINOP_IN_BOUNDS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_binop_in_bounds): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:12 -07:00
Tom Tromey
5ce19db80f Split out ada_ternop_slice
This splits TERNOP_SLICE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_ternop_slice): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:12 -07:00
Tom Tromey
214b13ac3b Split out ada_equal_binop
This splits BINOP_EQUAL and BINOP_NOTEQUAL into a new function for
future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_equal_binop): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:11 -07:00
Tom Tromey
faa1dfd751 Split out ada_mult_binop
This splits BINOP_MUL into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_mult_binop): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:11 -07:00
Tom Tromey
d05e24e61a Split out ada_abs
This splits UNOP_ABS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_abs): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:11 -07:00
Tom Tromey
68c757358f Split out ada_atr_size
This splits OP_ATR_SIZE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_atr_size): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:11 -07:00
Tom Tromey
020dbabe22 Split out ada_atr_tag
This splits OP_ATR_TAG into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_atr_tag): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:10 -07:00
Tom Tromey
7efc87ffcb Split out ada_unop_in_range
This splits UNOP_IN_RANGE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_unop_in_range): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:10 -07:00
Tom Tromey
82390ab88c Split out ada_unop_neg
This splits UNOP_NEG into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_unop_neg): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:10 -07:00
Tom Tromey
62d4bd947e Split out eval_ternop_in_range
This splits TERNOP_IN_RANGE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (eval_ternop_in_range): New function.
	(ada_evaluate_subexp): Use it.
2021-03-08 07:28:10 -07:00
Tom Tromey
3634f66996 Split out eval_opencl_assign
This splits BINOP_ASSIGN into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* opencl-lang.c (eval_opencl_assign): New function.
	(evaluate_subexp_opencl): Use it.
2021-03-08 07:28:09 -07:00
Tom Tromey
5e80600ed0 Split out eval_op_objc_msgcall
This splits OP_OBJC_MSGCALL into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_objc_msgcall): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:09 -07:00
Tom Tromey
fb5ba2ab26 Split out eval_binop_assign_modify
This splits BINOP_ASSIGN_MODIFY into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_binop_assign_modify): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:09 -07:00
Tom Tromey
a49881f73e Split out eval_op_m2_subscript
This splits BINOP_SUBSCRIPT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* m2-lang.c (eval_op_m2_subscript): New function.
	(evaluate_subexp_modula2): Use it.
2021-03-08 07:28:09 -07:00
Tom Tromey
41bdced5ae Split out eval_op_m2_high
This splits UNOP_HIGH into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* m2-lang.c (eval_op_m2_high): New function.
	(evaluate_subexp_modula2): Use it.
2021-03-08 07:28:09 -07:00
Tom Tromey
13ea014aee Split helper functions
This splits a couple of address-of and sizeof functions, so that the
body can be reused by the (coming) new expression code.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (evaluate_subexp_for_address_base): New function.
	(evaluate_subexp_for_address): Use it.
	(evaluate_subexp_for_sizeof_base): New function.
	(evaluate_subexp_for_sizeof): Use it.
2021-03-08 07:28:08 -07:00
Tom Tromey
1fa41fc710 Split out eval_op_rust_structop
This splits STRUCTOP_STRUCT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_structop): New function.
	(rust_evaluate_subexp): Use it.
2021-03-08 07:28:08 -07:00
Tom Tromey
575cae2335 Split out eval_op_rust_struct_anon
This splits STRUCTOP_ANONYMOUS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_struct_anon): New function.
	(rust_evaluate_subexp): Use it.
2021-03-08 07:28:08 -07:00
Tom Tromey
051042333d Split out eval_op_rust_array
This splits OP_ARRAY into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_array): New function.
	(rust_evaluate_subexp): Use it.
2021-03-08 07:28:08 -07:00
Tom Tromey
6fa9831f89 Split out eval_op_rust_complement
This splits UNOP_COMPLEMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_complement): New function.
	(rust_evaluate_subexp): Use it.
2021-03-08 07:28:07 -07:00
Tom Tromey
d123f9e4a3 Split out eval_op_rust_ind
This splits UNOP_IND into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_ind): New function.
	(rust_evaluate_subexp): Use it.
2021-03-08 07:28:07 -07:00
Tom Tromey
984af2cb26 Change parameters to rust_subscript
This changes the parameters to rust_subscript, making it more suitable
for reuse by the (coming) new expression code.  In particular,
rust_subscript no longer evaluates its subexpressions.  Instead, they
are passed in.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_subscript): Change parameters.
	(rust_evaluate_subexp): Update.
2021-03-08 07:28:07 -07:00
Tom Tromey
d148f80354 Change parameters to rust_range
This changes the parameters to rust_range, making it more suitable for
reuse by the (coming) new expression code.  In particular, rust_range
no longer evaluates its subexpressions.  Instead, they are passed in.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_range): Change parameters.
	(rust_evaluate_subexp): Update.
2021-03-08 07:28:07 -07:00
Tom Tromey
9cbd1c2011 Split out eval_op_f_allocated
This splits out a helper function, eval_op_f_allocated, that will be
used in a later patch.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_allocated): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:07 -07:00
Tom Tromey
3c18c49c63 Split out fortran_require_array
This splits out a helper function, fortran_require_array, that will be
used in a later patch.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (fortran_require_array): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:06 -07:00
Tom Tromey
216f6fcbef Split out eval_op_f_kind
This splits UNOP_FORTRAN_KIND into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_kind): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:06 -07:00
Tom Tromey
00f2db6f7d Split out eval_op_f_cmplx
This splits BINOP_FORTRAN_CMPLX into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_cmplx): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:06 -07:00
Tom Tromey
93b2b5fae2 Split out eval_op_f_modulo
This splits BINOP_FORTRAN_MODULO into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_modulo): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:06 -07:00
Tom Tromey
9f1a1f3c4f Split out eval_op_f_floor
This splits UNOP_FORTRAN_FLOOR into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_floor): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:06 -07:00
Tom Tromey
3dc41f3cdf Split out eval_op_f_ceil
This splits UNOP_FORTRAN_CEILING into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_ceil): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:05 -07:00
Tom Tromey
e08109f24b Split out eval_op_f_mod
This splits BINOP_MOD into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_mod): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:05 -07:00
Tom Tromey
cc05c68ee0 Split out eval_op_f_abs
This splits UNOP_ABS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* f-lang.c (eval_op_f_abs): New function.
	(evaluate_subexp_f): Use it.
2021-03-08 07:28:05 -07:00
Tom Tromey
aec95807f1 Split out eval_op_type
This splits OP_TYPE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_type): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:05 -07:00
Tom Tromey
a220ead5d4 Split out eval_op_postdec
This splits UNOP_POSTDECREMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_postdec): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:04 -07:00
Tom Tromey
abffe11606 Split out eval_op_postinc
This splits UNOP_POSTINCREMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_postinc): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:04 -07:00
Tom Tromey
9e1361b760 Split out eval_op_predec
This splits UNOP_PREDECREMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_predec): New file.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:04 -07:00
Tom Tromey
00f508843c Split out eval_op_preinc
This splits UNOP_PREINCREMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_preinc): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:04 -07:00
Tom Tromey
3aef2a0768 Split out eval_op_memval
This splits UNOP_MEMVAL into a new function for future use.  This new
function is also used to hande UNOP_MEMVAL_TYPE.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_memval): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:04 -07:00
Tom Tromey
acee94686b Split out eval_op_alignof
This splits UNOP_ALIGNOF into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_alignof): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:03 -07:00
Tom Tromey
786f70ee4d Split out eval_op_ind
This splits UNOP_IND into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_ind): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:03 -07:00
Tom Tromey
24338fb9d9 Split out eval_op_lognot
This splits UNOP_LOGICAL_NOT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_lognot): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:03 -07:00
Tom Tromey
1f09ec811e Split out eval_op_complement
This splits UNOP_COMPLEMENT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_complement): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:03 -07:00
Tom Tromey
606d105ff1 Split out eval_op_neg
This splits UNOP NEG into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_neg): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:02 -07:00
Tom Tromey
39f288bea9 Split out eval_op_plus
This splits UNOP_PLUS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_plus): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:02 -07:00
Tom Tromey
eed70b1c37 Split out eval_op_repeat
This splits BINOP_REPEAT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_repeat): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:02 -07:00
Tom Tromey
60cdd4871a Split out eval_op_leq
This splits BINOP_LEQ into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_leq): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:02 -07:00
Tom Tromey
96e3efd9b2 Split out eval_op_geq
This splits BINOP_GEQ into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_geq): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:02 -07:00
Tom Tromey
1f78d732ec Split out eval_op_gtr
This splits BINOP_GTR into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_gtr): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:01 -07:00
Tom Tromey
6cad134942 Split out eval_op_less
This splits BINOP_LESS into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_less): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:01 -07:00
Tom Tromey
1fcb355938 Split out eval_op_notequal
This splits BINOP_NOTEQUAL into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_notequal): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:01 -07:00
Tom Tromey
0cc96de858 Split out eval_op_equal
This splits BINOP_EQUAL into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_equal): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:01 -07:00
Tom Tromey
288d26bcd8 Split out eval_op_subscript
This splits BINOP_SUBSCRIPT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_subscript): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:00 -07:00
Tom Tromey
7cdcdd02b3 Split out eval_op_binary
This splits out a new eval_op_binary helper function.  This function
can handle several different binary operations:

    case BINOP_EXP:
    case BINOP_MUL:
    case BINOP_DIV:
    case BINOP_INTDIV:
    case BINOP_REM:
    case BINOP_MOD:
    case BINOP_LSH:
    case BINOP_RSH:
    case BINOP_BITWISE_AND:
    case BINOP_BITWISE_IOR:
    case BINOP_BITWISE_XOR:

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_binary): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:00 -07:00
Tom Tromey
d9790e22f4 Split out eval_op_sub
This splits BINOP_SUB into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_sub): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:00 -07:00
Tom Tromey
aedaf9ac06 Split out eval_op_add
This splits BINOP_ADD into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_add): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:00 -07:00
Tom Tromey
b7a96ed22e Split out eval_op_member
This splits STRUCTOP_MEMBER into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_member): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:28:00 -07:00
Tom Tromey
fb461aa39e Split out eval_op_structop_ptr
This splits STRUCTOP_PTR into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_structop_ptr): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:59 -07:00
Tom Tromey
3e96c4fc0f Split out eval_op_structop_struct
This splits STRUCTOP_STRUCT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_structop_struct): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:59 -07:00
Tom Tromey
f960a6176a Split out eval_op_ternop
This splits TERNOP_SLICE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_ternop): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:59 -07:00
Tom Tromey
5c2f201e8d Split out eval_op_concat
This splits BINOP_CONCAT into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_concat): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:59 -07:00
Tom Tromey
f871bae1ae Split out eval_op_objc_selector
This splits OP_OBJC_SELECTOR into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_objc_selector): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:58 -07:00
Tom Tromey
14a1c64a13 Split out eval_op_string
This splits OP_STRING into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_string): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:58 -07:00
Tom Tromey
ffff730bf6 Split out eval_op_register
This splits OP_REGISTER into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_register): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:58 -07:00
Tom Tromey
9b1d8af683 Split out eval_op_func_static_var
This splits OP_FUNC_STATIC_VAR into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_func_static_var): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:58 -07:00
Tom Tromey
c0df928969 Split out eval_op_var_msym_value
This splits OP_VAR_MSYM_VALUE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_var_msym_value): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:58 -07:00
Tom Tromey
50b98adc3c Split out eval_op_var_entry_value
This splits OP_VAR_ENTRY_VALUE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_var_entry_value): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:57 -07:00
Tom Tromey
ea2d29f7bc Split out eval_op_scope
This splits OP_SCOPE into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_scope): New function.
	(evaluate_subexp_standard): Use it.
2021-03-08 07:27:57 -07:00
Tom Tromey
01573d7360 Fix build bug in ada-lang.c
An earlier patch of mine introduced a build failure in ada-lang.c.  A
couple of "to_string" calls were not namespace-qualified.  In the
failing setup, the std string_view is being used, and so (apparently)
ADL doesn't find gdb::to_string.

This patch, from the bug, fixes the problem.

gdb/ChangeLog
2021-03-06  Chernov Sergey  <klen_s@mail.ru>

	PR gdb/27528:
	* ada-lang.c (ada_fold_name): Use gdb::to_string.
2021-03-06 09:38:26 -07:00
Tom Tromey
9938d15a01 Move dwarf2_get_dwz_file to dwarf2/dwz.h
This moves dwarf2_get_dwz_file and some helper code to dwarf2/dwz.h.
The main benefit of this is just shrinking dwarf2/read.c a little bit.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* dwarf2/sect-names.h (dwarf2_elf_names): Declare.
	* dwarf2/read.h (dwarf2_get_dwz_file): Move to dwz.h.
	* dwarf2/read.c (dwarf2_elf_names): No longer static.
	(locate_dwz_sections, dwz_search_other_debugdirs)
	(dwarf2_get_dwz_file): Move to dwz.c.
	* dwarf2/dwz.h (dwarf2_get_dwz_file): Move declaration from
	read.h.
	* dwarf2/dwz.c (locate_dwz_sections, dwz_search_other_debugdirs)
	(dwarf2_get_dwz_file): Move from read.c.
2021-03-06 09:26:40 -07:00
Tom Tromey
1803565556 Include scoped_fd.h in debuginfod-support.h
debuginfod-support.h requires scoped_fd, so include the header here.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* debuginfod-support.h: Include scoped_fd.h.
2021-03-06 09:26:39 -07:00
Tom Tromey
a7308ce01e Avoid crash on missing dwz file
If DWARF contains a reference to a "dwz" file, but there is no
.gnu_debugaltlink section, then gdb will crash.  This happens because
dwarf2_get_dwz_file will return NULL, but some callers do not expect
this.

This patch changes dwarf2_get_dwz_file so that callers can require a
dwz file.  Then, it updates the callers that are attempting to process
references to the dwz file to require one.

This includes a new testcase.  The dwarf.exp changes don't handle the
new forms exactly correctly -- they are only handled well enough to
let this test case complete.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (dwarf2_get_dwz_file): Add 'require' parameter.
	* dwarf2/read.c (dwarf2_get_dwz_file): Add 'require' parameter.
	(get_abbrev_section_for_cu, read_attribute_value)
	(get_debug_line_section): Update.
	* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.

gdb/testsuite/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* lib/dwarf.exp (_handle_DW_FORM): Treat DW_FORM_GNU_ref_alt and
	DW_FORM_GNU_strp_alt like DW_FORM_sec_offset.
	* gdb.dwarf2/dwznolink.exp: New file.
2021-03-06 09:26:39 -07:00
Tom Tromey
fbedd54644 Change section_is_p to a method on dwarf2_section_names
This replaces section_is_p with a method on dwarf2_section_names.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* dwarf2/sect-names.h (struct dwarf2_section_names) <matches>: New
	method.
	* dwarf2/read.c (section_is_p): Remove.
	(dwarf2_per_bfd::locate_sections)
	(dwarf2_per_bfd::locate_sections, locate_dwz_sections)
	(locate_v1_virtual_dwo_sections, dwarf2_locate_dwo_sections)
	(dwarf2_locate_common_dwp_sections)
	(dwarf2_locate_v2_dwp_sections, dwarf2_locate_v5_dwp_sections):
	Update.
2021-03-06 09:26:39 -07:00
Tom Tromey
c2a62a3d88 Create new file dwarf2/sect-names.h
This creates a new file, dwarf2/sect-names.h, and moves some
DWARF-specific type definitions from symfile.h into it.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* xcoffread.c: Include sect-names.h.
	* symfile.h (struct dwarf2_section_names, struct
	dwarf2_debug_sections): Move to dwarf2/sect-names.h.
	* dwarf2/sect-names.h: New file, from symfile.h.
	* dwarf2/read.c: Include sect-names.h.
2021-03-06 09:26:39 -07:00
Tom Tromey
4444f40757 Micro-optimize abbrev reading and storage
Currently, and abbrev_info points to a separately allocated array of
attr_abbrev objects.  This array is constructed in a temporary vector,
then copied to the abbrev table's obstack.

This patch changes abbrev_info to use the struct hack to store the
objects directly, and changes abbrev_table::read to avoid an extra
copy when allocating, using the "growing objects" capability of
obstacks.

This saves a bit of space, and also perhaps a little time.

2021-03-06  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_attribute): Make 'abbrev' const.
	* dwarf2/abbrev.c (abbrev_table::alloc_abbrev): Remove.
	(abbrev_table::read): Update.
	* dwarf2/abbrev.h (struct attr_abbrev): Move earlier.
	(struct abbrev_info): Reformat.
	<attrs>: Now an array.
	(struct abbrev_table) <alloc_abbrev>: Remove.
2021-03-06 09:17:28 -07:00
Weimin Pan
dd99cf0c58 CTF: add all members of an enum type to psymtab
With the following change which was made last April:

    [gdb] Use partial symbol table to find language for main
    commit d321419811

The ctf reader was modified to enter all members of an enum type,
similar to what the dwarf2 reader did, into the psymtab or gdb
won't be able to find them. In addition, the empty name checking
needed to be moved down so members of a unnamed enum were not left
out.

gdb/ChangeLog:

	* ctfread.c (ctf_psymtab_add_enums): New function.
	(ctf_psymtab_type_cb): call ctf_psymtab_add_enums.
2021-03-05 20:46:39 -05:00
Weimin Pan
844be3f240 CTF: set up debug info for function arguments
Added this support in read_func_kind_type after gcc started generating
CTF for function arguments.

Replaced XNEW with std::vector and NULL with nullptr.

Expanded gdb.base/ctf-ptype.exp to test function arguments. Also fixed
some typos.

gdb/ChangeLog:

	* ctfread.c (read_func_kind_type): Set up function arguments.

gdb/testsuite/ChangeLog:

	* gdb.base/ctf-ptype.exp: Add function tests and fix typos.
2021-03-05 20:46:39 -05:00
Andrew Burgess
b2668f28ee gdb/riscv: write CSRs into baremetal core dumps
Use the current target description to include CSRs into the RISC-V
baremetal core dumps.

Every CSR declared in the current target description will be included
in the core dump.

It will be critical for users that they have the same target
description in use when loading the core file as was in use when
writing the core file.  This should be fine if the user allows the
target description to be written into the core file.

In more detail, this commit adds a NT_RISCV_CSR note type.  The
contents of this section is a series of either 4-byte (on RV32
targets), or 8-byte (on RV64 targets) values.  Every CSR that is
mentioned in the current target description is written out in the
order the registers appear in the target description.  As a
consequence it is critical that the exact same target description,
including the same register order, is in use when the CSRs are loaded
from the core file.

gdb/ChangeLog:

	* riscv-none-tdep.c: Add 'user-regs.h' and 'target-description.h'
	includes.
	(riscv_csrset): New static global.
	(riscv_update_csrmap): New function.
	(riscv_iterate_over_regset_sections): Process CSRs.
2021-03-05 17:21:41 +00:00
Andrew Burgess
d782d24b32 gdb/riscv: make riscv target description names global
A later commit will need the names of the RISC-V target description
features in files other than riscv-tdep.c.  This commit just makes the
names global strings that can be accessed from other riscv-*.c files.

There should be no user visible changes after this commit.

gdb/ChangeLog:

        * riscv-tdep.c (riscv_feature_name_csr): Define.
        (riscv_feature_name_cpu): Define.
        (riscv_feature_name_fpu): Define.
        (riscv_feature_name_virtual): Define.
        (riscv_xreg_feature): Use riscv_feature_name_cpu.
        (riscv_freg_feature): Use riscv_feature_name_fpu.
        (riscv_virtual_feature): Use riscv_feature_name_virtual.
        (riscv_csr_feature): Use riscv_feature_name_csr.
        * riscv-tdep.h (riscv_feature_name_csr): Declare.
2021-03-05 17:21:41 +00:00
Andrew Burgess
fb8f3fc0c3 gdb/riscv: introduce bare metal core dump support
This commit adds the ability for bare metal RISC-V target to generate
core files from within GDB.

The intended use case is that a user will connect to a remote bare
metal target, debug up to some error condition, then generate a core
file in the normal way using:

  (gdb) generate-core-file

This core file can then be used to revisit the state of the remote
target without having to reconnect to the remote target.

The core file creation code is split between two new files.  In
elf-none-tdep.c is code for any architecture with the none
ABI (i.e. bare metal) when the BFD library is built with ELF support.

In riscv-none-tdep.c are the RISC-V specific parts.  This is where the
regset and regcache_map_entry structures are defined that control how
registers are laid out in the core file.  As this file could (in
theory at least) be used for a non-ELF bare metal RISC-V target, the
calls into elf-none-tdep.c are guarded with '#ifdef HAVE_ELF'.

Currently for RISC-V only the x-regs and f-regs (if present) are
written out.  In future commits I plan to add support for writing out
the RISC-V CSRs.

The core dump format is based around generating an ELF containing
sections for the writable regions of memory that a user could be
using.  Which regions are dumped rely on GDB's existing common core
dumping code, GDB will attempt to figure out the stack and heap as
well as copying out writable data sections as identified by the
original ELF.

Register information is added to the core dump using notes, just as it
is for Linux of FreeBSD core dumps.  The note types used consist of
the 3 basic types you would expect in a OS based core dump,
NT_PRPSINFO, NT_PRSTATUS, NT_FPREGSET.

The layout of these notes differs slightly (due to field sizes)
between RV32 and RV64.  Below I describe the data layout for each
note.  In all cases, all padding fields should be set to zero.

Note NT_PRPSINFO is optional.  Its data layout is:

  struct prpsinfo32_t		/* For RV32.  */
  {
    uint8_t padding[32];
    char fname[16];
    char psargs[80];
  }

  struct prpsinfo64_t		/* For RV64.  */
  {
    uint8_t padding[40];
    char fname[16];
    char psargs[80];
  }

Field 'fname' - null terminated string consisting of the basename of
    (up to the fist 15 characters of) the executable.  Any additional
    space should be set to zero.  If there's no executable name then
    this field can be set to all zero.

Field 'psargs' - a null terminated string up to 80 characters in
    length.  Any additional space should be filled with zero.  This
    field contains the full executable path and any arguments passed
    to the executable.  If there's nothing sensible to write in this
    field then fill it with zero.

Note NT_PRSTATUS is required, its data layout is:

  struct prstatus32_t		/* For RV32.  */
  {
    uint8_t padding_1[12];
    uint16_t sig;
    uint8_t padding_2[10];
    uint32_t thread_id;
    uint8_t padding_3[44];
    uint32_t x_regs[32];
    uint8_t padding_4[4];
  }

  struct prstatus64_t		/* For RV64.  */
  {
    uint8_t padding_1[12];
    uint16_t sig;
    uint8_t padding_2[18];
    uint32_t thread_id;
    uint8_t padding_3[76];
    uint64_t x_regs[32];
    uint8_t padding_4[4];
  }

Field 'sig' - the signal that stopped this thread.  It's implementation
    defined what this field actually means.  Within GDB this will be
    the signal number that the remote target reports as the stop
    reason for this thread.

Field 'thread_is' - the thread id for this thread.  It's implementation
    defined what this field actually means.  Within GDB this will be
    thread thread-id that is assigned to each remote thread.

Field 'x_regs' - at index 0 we store the program counter, and at
    indices 1 to 31 we store x-registers 1 to 31.  x-register 0 is not
    stored, its value is always zero anyway.

Note NT_FPREGSET is optional, its data layout is:

  fpregset32_t			/* For targets with 'F' extension.  */
  {
    uint32_t f_regs[32];
    uint32_t fcsr;
  }

  fpregset64_t			/* For targets with 'D' extension .  */
  {
    uint64_t f_regs[32];
    uint32_t fcsr;
  }

Field 'f_regs' - stores f-registers 0 to 31.

Field 'fcsr' - stores the fcsr CSR register, and is always 4-bytes.

The rules for ordering the notes is the same as for Linux.  The
NT_PRSTATUS note must come before any other notes about additional
register sets.  And for multi-threaded targets all registers for a
single thread should be grouped together.  This is because only
NT_PRSTATUS includes a thread-id, all additional register notes after
a NT_PRSTATUS are assumed to belong to the same thread until a
different NT_PRSTATUS is seen.

gdb/ChangeLog:

	* Makefile.in (ALL_TARGET_OBS): Add riscv-none-tdep.o.
	(ALLDEPFILES): Add riscv-none-tdep.c.
	* configure: Regenerate.
	* configure.ac (CONFIG_OBS): Add elf-none-tdep.o when BFD has ELF
	support.
	* configure.tgt (riscv*-*-*): Include riscv-none-tdep.c.
	* elf-none-tdep.c: New file.
	* elf-none-tdep.h: New file.
	* riscv-none-tdep.c: New file.
2021-03-05 17:21:41 +00:00
Andrew Burgess
95ce627aeb gdb: write target description into core file
When a core file is created from within GDB add the target description
into a note within the core file.

When loading a core file, if the target description note is present
then load the target description from the core file.

The benefit of this is that we can be sure that, when analysing the
core file within GDB, that we are using the exact same target
description as was in use at the time the core file was created.

GDB already supports a mechanism for figuring out the target
description from a given corefile; gdbarch_core_read_description.
This new mechanism (GDB adding the target description) is not going to
replace the old mechanism.  Core files generated outside of GDB will
not include a target description, and so GDB still needs to be able to
figure out a target description for these files.

My primary motivation for adding this feature is that, in a future
commit, I will be adding support for bare metal core dumps on some
targets.  For RISC-V specifically, I want to be able to dump all the
available control status registers.  As different targets will present
different sets of register in their target description, including
registers that are possibly not otherwise known to GDB I wanted a way
to capture these registers in the core dump.

I therefore need a mechanism to write out an arbitrary set of
registers, and to then derive a target description from this arbitrary
set when later loading the core file.  The obvious approach (I think)
is to just reuse the target description.

Once I'd decided to add support for writing out the target description
I could either choose to make this RISC-V only, or make it generic.  I
figure that having the target description in the core file doesn't
hurt, and _might_ be helpful.  So that's how I got here, general
support for including the target description in GDB generated core
files.

In previous versions of this patch I added the target description from
generic code (in gcore.c).  However, doing this creates a dependency
between GDB's common code and bfd ELF support.  As ELF support in gdb
is optional (for example the target x86_64-apple-darwin20.3.0 does not
include ELF support) then having gcore.c require ELF support would
break the GDB build in some cases.

Instead, in this version of the patch, writing the target description
note is done from each specific targets make notes function.  Each of
these now calls a common function in gcore-elf.c (which is only linked
in when bfd has ELF support).  And so only targets that are ELF based
will call the new function and we can therefore avoid an unconditional
dependency on ELF support.

gdb/ChangeLog:

	* corelow.c: Add 'xml-tdesc.h' include.
	(core_target::read_description): Load the target description from
	the core file when possible.
	* fbsd-tdep.c (fbsd_make_corefile_notes): Add target description
	note.
	* gcore-elf.c: Add 'gdbsupport/tdesc.h' include.
	(gcore_elf_make_tdesc_note): New function.
	* gcore-elf.h (gcore_elf_make_tdesc_note): Declare.
	* linux-tdep.c (linux_make_corefile_notes): Add target description
	note.
2021-03-05 17:21:41 +00:00
Andrew Burgess
f3a5df7bd6 gdb: unify parts of the Linux and FreeBSD core dumping code
While reviewing the Linux and FreeBSD core dumping code within GDB for
another patch series, I noticed that the code that collects the
registers for each thread and writes these into ELF note format is
basically identical between Linux and FreeBSD.

This commit merges this code and moves it into a new file gcore-elf.c.

The function find_signalled_thread is moved from linux-tdep.c to
gcore.c despite not being shared.  A later commit will make use of
this function.

I did merge, and then revert a previous version of this patch (commit
82a1fd3a49 for the original patch and 03642b7189 for the revert).
The problem with the original patch is that it introduced a
unconditional dependency between GDB and some ELF specific functions
in the BFD library, e.g. elfcore_write_prstatus and
elfcore_write_register_note.  It was pointed out in this mailing list
post:

  https://sourceware.org/pipermail/gdb-patches/2021-February/175750.html

that this change was breaking any build of GDB for non-ELF targets.
To confirm this breakage, and to test this new version of GDB I
configured and built for the target x86_64-apple-darwin20.3.0.

Where the previous version of this patch placed all of the common code
into gcore.c, which is included in all builds of GDB, this new patch
only places non-ELF specific generic code (i.e. find_signalled_thread)
into gcore.c, the ELF specific code is put into the new gcore-elf.c
file, which is only included in GDB if BFD has ELF support.

The contents of gcore-elf.c are referenced unconditionally from
linux-tdep.c and fbsd-tdep.c, this is fine, we previously always
assumed that these two targets required ELF support, and we continue
to make that assumption after this patch; nothing has changed there.

With my previous version of this patch the darwin target mentioned
above failed to build, but with the new version, the target builds
fine.

There are a couple of minor changes to the FreeBSD target after this
commit, but I believe that these are changes for the better:

(1) For FreeBSD we always used to record the thread-id in the core
file by using ptid_t.lwp ().  In contrast the Linux code did this:

    /* For remote targets the LWP may not be available, so use the TID.  */
    long lwp = ptid.lwp ();
    if (lwp == 0)
      lwp = ptid.tid ();

Both target now do this:

    /* The LWP is often not available for bare metal target, in which case
       use the tid instead.  */
    if (ptid.lwp_p ())
      lwp = ptid.lwp ();
    else
      lwp = ptid.tid ();

Which is equivalent for Linux, but is a change for FreeBSD.  I think
that all this means is that in some cases where GDB might have
previously recorded a thread-id of 0 for each thread, we might now get
something more useful.

(2) When collecting the registers for Linux we collected into a zero
initialised buffer.  By contrast on FreeBSD the buffer is left
uninitialised.  In the new code the buffer is always zero initialised.
I suspect once the registers are copied into the buffer there's
probably no gaps left so this makes no difference, but if it does then
using zeros rather than random bits of GDB's memory is probably a good
thing.

Otherwise, there should be no other user visible changes after this
commit.

Tested this on x86-64/GNU-Linux and x86-64/FreeBSD-12.2 with no
regressions.

gdb/ChangeLog:

	* Makefile.in (SFILES): Add gcore-elf.c.
	(HFILES_NO_SRCDIR): Add gcore-elf.h
	* configure: Regenerate.
	* configure.ac: Add gcore-elf.o to CONFIG_OBS if we have ELF
	support.
	* fbsd-tdep.c: Add 'gcore-elf.h' include.
	(struct fbsd_collect_regset_section_cb_data): Delete.
	(fbsd_collect_regset_section_cb): Delete.
	(fbsd_collect_thread_registers): Delete.
	(struct fbsd_corefile_thread_data): Delete.
	(fbsd_corefile_thread): Delete.
	(fbsd_make_corefile_notes): Call
	gcore_elf_build_thread_register_notes instead of the now deleted
	FreeBSD code.
	* gcore-elf.c: New file, the content was moved here from
	linux-tdep.c, functions were renamed and given minor cleanup.
	* gcore-elf.h: New file.
	* gcore.c (gcore_find_signalled_thread): Moved here from
	linux-tdep.c and given a new name.  Minor cleanups.
	* gcore.h (gcore_find_signalled_thread): Declare.
	* linux-tdep.c: Add 'gcore.h' and 'gcore-elf.h' includes.
	(struct linux_collect_regset_section_cb_data): Delete.
	(linux_collect_regset_section_cb): Delete.
	(linux_collect_thread_registers): Delete.
	(linux_corefile_thread): Call
	gcore_elf_build_thread_register_notes.
	(find_signalled_thread): Delete.
	(linux_make_corefile_notes): Call gcore_find_signalled_thread.
2021-03-05 17:21:40 +00:00
Simon Marchi
d1e93af64a gdb: set current thread in sparc_{fetch,collect}_inferior_registers (PR gdb/27147)
PR 27147 shows that on sparc64, GDB is unable to properly unwind:

Expected result (from GDB 9.2):

    #0  0x0000000000108de4 in puts ()
    #1  0x0000000000100950 in hello () at gdb-test.c:4
    #2  0x0000000000100968 in main () at gdb-test.c:8

Actual result (from GDB latest git):

    #0  0x0000000000108de4 in puts ()
    #1  0x0000000000100950 in hello () at gdb-test.c:4
    Backtrace stopped: previous frame inner to this frame (corrupt stack?)

The first failing commit is 5b6d1e4fa4 ("Multi-target support").  The cause
of the change in behavior is due to (thanks for Andrew Burgess for finding
this):

 - inferior_ptid is no longer set on entry of target_ops::wait, whereas
   it was set to something valid previously
 - deep down in linux_nat_target::wait (see stack trace below), we fetch
   the registers of the event thread
 - on sparc64, fetching registers involves reading memory (in
   sparc_supply_rwindow, see stack trace below)
 - reading memory (target_ops::xfer_partial) relies on inferior_ptid
   being set to the thread from which we want to read memory

This is where things go wrong:

    #0  linux_nat_target::xfer_partial (this=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, annex=0x0, readbuf=0x7feffe3b000 "", writebuf=0x0, offset=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3697
    #1  0x00000100007f5b10 in raw_memory_xfer_partial (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, readbuf=0x7feffe3b000 "", writebuf=0x0, memaddr=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/target.c:912
    #2  0x00000100007f60e8 in memory_xfer_partial_1 (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, readbuf=0x7feffe3b000 "", writebuf=0x0, memaddr=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/target.c:1043
    #3  0x00000100007f61b4 in memory_xfer_partial (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, readbuf=0x7feffe3b000 "", writebuf=0x0, memaddr=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/target.c:1072
    #4  0x00000100007f6538 in target_xfer_partial (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, annex=0x0, readbuf=0x7feffe3b000 "", writebuf=0x0, offset=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/target.c:1129
    #5  0x00000100007f7094 in target_read_partial (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, annex=0x0, buf=0x7feffe3b000 "", offset=8791798050744, len=8, xfered_len=0x7feffe3ae88) at /home/simark/src/binutils-gdb/gdb/target.c:1375
    #6  0x00000100007f721c in target_read (ops=0x10000fa2c40 <the_sparc64_linux_nat_target>, object=TARGET_OBJECT_MEMORY, annex=0x0, buf=0x7feffe3b000 "", offset=8791798050744, len=8) at /home/simark/src/binutils-gdb/gdb/target.c:1415
    #7  0x00000100007f69d4 in target_read_memory (memaddr=8791798050744, myaddr=0x7feffe3b000 "", len=8) at /home/simark/src/binutils-gdb/gdb/target.c:1218
    #8  0x0000010000758520 in sparc_supply_rwindow (regcache=0x10000fea4f0, sp=8791798050736, regnum=-1) at /home/simark/src/binutils-gdb/gdb/sparc-tdep.c:1960
    #9  0x000001000076208c in sparc64_supply_gregset (gregmap=0x10000be3190 <sparc64_linux_ptrace_gregmap>, regcache=0x10000fea4f0, regnum=-1, gregs=0x7feffe3b230) at /home/simark/src/binutils-gdb/gdb/sparc64-tdep.c:1974
    #10 0x0000010000751b64 in sparc_fetch_inferior_registers (regcache=0x10000fea4f0, regnum=80) at /home/simark/src/binutils-gdb/gdb/sparc-nat.c:170
    #11 0x0000010000759d68 in sparc64_linux_nat_target::fetch_registers (this=0x10000fa2c40 <the_sparc64_linux_nat_target>, regcache=0x10000fea4f0, regnum=80) at /home/simark/src/binutils-gdb/gdb/sparc64-linux-nat.c:38
    #12 0x00000100008146ec in target_fetch_registers (regcache=0x10000fea4f0, regno=80) at /home/simark/src/binutils-gdb/gdb/target.c:3287
    #13 0x00000100006a8c5c in regcache::raw_update (this=0x10000fea4f0, regnum=80) at /home/simark/src/binutils-gdb/gdb/regcache.c:584
    #14 0x00000100006a8d94 in readable_regcache::raw_read (this=0x10000fea4f0, regnum=80, buf=0x7feffe3b7c0 "") at /home/simark/src/binutils-gdb/gdb/regcache.c:598
    #15 0x00000100006a93b8 in readable_regcache::cooked_read (this=0x10000fea4f0, regnum=80, buf=0x7feffe3b7c0 "") at /home/simark/src/binutils-gdb/gdb/regcache.c:690
    #16 0x00000100006b288c in readable_regcache::cooked_read<unsigned long, void> (this=0x10000fea4f0, regnum=80, val=0x7feffe3b948) at /home/simark/src/binutils-gdb/gdb/regcache.c:777
    #17 0x00000100006a9b44 in regcache_cooked_read_unsigned (regcache=0x10000fea4f0, regnum=80, val=0x7feffe3b948) at /home/simark/src/binutils-gdb/gdb/regcache.c:791
    #18 0x00000100006abf3c in regcache_read_pc (regcache=0x10000fea4f0) at /home/simark/src/binutils-gdb/gdb/regcache.c:1295
    #19 0x0000010000507920 in save_stop_reason (lp=0x10000fc5b10) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:2612
    #20 0x00000100005095a4 in linux_nat_filter_event (lwpid=520983, status=1407) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3050
    #21 0x0000010000509f9c in linux_nat_wait_1 (ptid=..., ourstatus=0x7feffe3c8f0, target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3194
    #22 0x000001000050b1d0 in linux_nat_target::wait (this=0x10000fa2c40 <the_sparc64_linux_nat_target>, ptid=..., ourstatus=0x7feffe3c8f0, target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3432
    #23 0x00000100007f8ac0 in target_wait (ptid=..., status=0x7feffe3c8f0, options=...) at /home/simark/src/binutils-gdb/gdb/target.c:2000
    #24 0x00000100004ac17c in do_target_wait_1 (inf=0x1000116d280, ptid=..., status=0x7feffe3c8f0, options=...) at /home/simark/src/binutils-gdb/gdb/infrun.c:3464
    #25 0x00000100004ac3b8 in operator() (__closure=0x7feffe3c678, inf=0x1000116d280) at /home/simark/src/binutils-gdb/gdb/infrun.c:3527
    #26 0x00000100004ac7cc in do_target_wait (wait_ptid=..., ecs=0x7feffe3c8c8, options=...) at /home/simark/src/binutils-gdb/gdb/infrun.c:3540
    #27 0x00000100004ad8c4 in fetch_inferior_event () at /home/simark/src/binutils-gdb/gdb/infrun.c:3880
    #28 0x0000010000485568 in inferior_event_handler (event_type=INF_REG_EVENT) at /home/simark/src/binutils-gdb/gdb/inf-loop.c:42
    #29 0x000001000050d394 in handle_target_event (error=0, client_data=0x0) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:4060
    #30 0x0000010000ab5c8c in handle_file_event (file_ptr=0x10001207270, ready_mask=1) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:575
    #31 0x0000010000ab6334 in gdb_wait_for_event (block=0) at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:701
    #32 0x0000010000ab487c in gdb_do_one_event () at /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:212
    #33 0x0000010000542668 in start_event_loop () at /home/simark/src/binutils-gdb/gdb/main.c:348
    #34 0x000001000054287c in captured_command_loop () at /home/simark/src/binutils-gdb/gdb/main.c:408
    #35 0x0000010000544e84 in captured_main (data=0x7feffe3d188) at /home/simark/src/binutils-gdb/gdb/main.c:1242
    #36 0x0000010000544f2c in gdb_main (args=0x7feffe3d188) at /home/simark/src/binutils-gdb/gdb/main.c:1257
    #37 0x00000100000c1f14 in main (argc=4, argv=0x7feffe3d548) at /home/simark/src/binutils-gdb/gdb/gdb.c:32

There is a target_read_memory call in sparc_supply_rwindow, whose return
value is not checked.  That call fails, because inferior_ptid does not
contain a valid ptid, and uninitialized buffer contents is used.
Ultimately it results in a corrupt stop_pc.

target_ops::fetch_registers can be (and should remain, in my opinion)
independent of inferior_ptid, because the ptid of the thread from which
to fetch registers can be obtained from the regcache.  In other words,
implementations of target_ops::fetch_registers should not rely on
inferior_ptid having a sensible value on entry.

The sparc64_linux_nat_target::fetch_registers case is special, because it calls
a target method that is dependent on the inferior_ptid value
(target_read_inferior, and ultimately target_ops::xfer_partial).  So I would
say it's the responsibility of sparc64_linux_nat_target::fetch_registers to set
up inferior_ptid correctly prior to calling target_read_inferior.

This patch makes sparc64_linux_nat_target::fetch_registers (and
store_registers, since it works the same) temporarily set inferior_ptid.  If we
ever make target_ops::xfer_partial independent of inferior_ptid, setting
inferior_ptid won't be necessary, we'll simply pass down the ptid as a
parameter in some way.

I chose to set/restore inferior_ptid in sparc_fetch_inferior_registers, because
I am not convinced that doing so in an inner location (in sparc_supply_rwindow
for instance) would always be correct.  We have access to the ptid in
sparc_supply_rwindow (from the regcache), so we _could_ set inferior_ptid
there.  However, I don't want to just set inferior_ptid, as that would make it
not desync'ed with `current_thread ()` and `current_inferior ()`.  It's
preferable to use switch_to_thread instead, as that switches all the global
"current" stuff in a coherent way.  But doing so requires a `thread_info *`,
and getting a `thread_info *` from a ptid requires a `process_stratum_target
*`.  We could use `current_inferior()->process_target()` in
sparc_supply_rwindow for this (using target_read_memory uses the current
inferior's target stack anyway).  However, sparc_supply_rwindow is also used in
the context of BSD uthreads, where a thread stratum target defines threads.  I
presume the ptid in the regcache would be the ptid of the uthread, defined by
the thread stratum target (bsd_uthread_target).  Using
`current_inferior()->process_target()` would look up a ptid defined by the
thread stratum target using the process stratum target.  I don't think it would
give good results.  So I prefer playing it safe and looking up the thread
earlier, in sparc_fetch_inferior_registers.

I added some assertions (in sparc_supply_rwindow and others) to verify
that the regcache's ptid matches inferior_ptid.  That verifies that the
caller has properly set the correct global context.  This would have
caught (though a failed assertion) the current problem.

gdb/ChangeLog:

	PR gdb/27147
	* sparc-nat.h (sparc_fetch_inferior_registers): Add
	process_stratum_target parameter,
	sparc_store_inferior_registers): update callers.
	* sparc-nat.c (sparc_fetch_inferior_registers,
	sparc_store_inferior_registers): Add process_stratum_target
	parameter.  Switch current thread before calling
	sparc_supply_gregset / sparc_collect_rwindow.
	(sparc_store_inferior_registers): Likewise.
	* sparc-obsd-tdep.c (sparc32obsd_supply_uthread): Add assertion.
	(sparc32obsd_collect_uthread): Likewise.
	* sparc-tdep.c (sparc_supply_rwindow, sparc_collect_rwindow):
	Add assertion.
	* sparc64-obsd-tdep.c (sparc64obsd_collect_uthread,
	sparc64obsd_supply_uthread): Add assertion.

Change-Id: I16c658cd70896cea604516714f7e2428fbaf4301
2021-03-04 10:57:03 -05:00
Tom Tromey
1178743e4c Use "bool" in ada-lang.c
Christian suggested switching an "int" in ada-lang.c to "bool"
instead.  This patch makes this change.  Tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-03-04  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (struct match_data) <found_sym>: Now bool.
	(aux_add_nonlocal_symbols): Update.
	(ada_add_block_symbols): Change "found_sym" to bool.
2021-03-04 07:30:42 -07:00
Tom Tromey
1bfa81acbf Minor Ada-related cleanups
This patch addresses some review comments that I forgot to deal with
in an earlier patch.  See the comments here:

https://sourceware.org/pipermail/gdb-patches/2021-February/176278.html

For the most part this is fixing up comments, but it also includes
adding a constructor and initializers to "match_data".

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-03-03  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_resolve_function): Update comment.
	(is_nonfunction, add_symbols_from_enclosing_procs)
	(remove_extra_symbols): Likewise.
	(struct match_data): Add constructor, initializers.
	(add_nonlocal_symbols): Remove memset.
	(aux_add_nonlocal_symbols): Update comment.
	(ada_add_block_renamings, add_nonlocal_symbols)
	(ada_add_all_symbols): Likewise.
	* ada-exp.y (write_var_or_type): Clean up trailing whitespace.
2021-03-03 12:02:16 -07:00
Tom Tromey
bbcdf9ab73 Rewrite GNAT-encoded fixed point types in DWARF reader
gdb currently supports two different styles of fixed-point.  The
original style, where fixed point types are "GNAT encoded", is handled
primarily in the Ada code.  The newer style, encoded using DWARF, is
handled by the core of gdb.

This patch changes gdb to read the GNAT encodings in the DWARF reader
as well.  This removes some code and unifies the two paths.  As a
result, GNAT-encoded fixed-point now works a bit better.

One possible drawback of this change is that, if someone uses stabs,
then fixed-point might now stop working.  I consider stabs to be fully
obsolete, though, so I don't intend to address this.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (cast_from_gnat_encoded_fixed_point_type)
	(cast_to_gnat_encoded_fixed_point_type): Remove.
	(ada_value_cast, ada_evaluate_subexp): Update.
	(gnat_encoded_fixed_point_type_info)
	(ada_is_gnat_encoded_fixed_point_type)
	(gnat_encoded_fixed_point_delta)
	(gnat_encoded_fixed_point_scaling_factor): Remove.
	* ada-lang.h (ada_is_gnat_encoded_fixed_point_type)
	(gnat_encoded_fixed_point_delta)
	(gnat_encoded_fixed_point_scaling_factor): Don't declare.
	* ada-typeprint.c (print_gnat_encoded_fixed_point_type): Remove.
	(ada_print_type): Update.
	* ada-valprint.c (ada_value_print_num): Update.
	* dwarf2/read.c (ada_get_gnat_encoded_number)
	(ada_get_gnat_encoded_ratio): New functions.
	(finish_fixed_point_type): Use them.  Add parameters.
	(GNAT_FIXED_POINT_SUFFIX): New define.
	(gnat_encoded_fixed_point_type_info): New function.
	(read_base_type): Handle gnat encodings.

gdb/testsuite/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/fixed_points.exp: Remove most special cases for minimal
	encodings.
2021-03-02 13:08:25 -07:00
Tom Tromey
5f9febe0f6 Use std::string rather than grow_vect
This removes the "GROW_VECT" macro and helper function in favor of
simply using std::string in a few spots.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_fold_name, ada_variant_discrim_name)
	(ada_enum_name, scan_discrim_bound, to_fixed_range_type): Use
	std::string.
	(GROW_VECT): Remove.
	(grow_vect): Remove.
2021-03-02 13:00:46 -07:00
Tom Tromey
d1183b064c Return a vector from ada_lookup_symbol_list
This changes ada_lookup_symbol_list to return a std::vector, and
changes various other helper functions to follow.  This simplifies the
code, and makes it more type-safe (by using a vector where an obstack
had been used).

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.h (ada_lookup_symbol_list): Return a vector.
	* ada-lang.c (resolve_subexp): Update.
	(ada_resolve_function): Accept a vector.
	(is_nonfunction, add_defn_to_vec)
	(add_symbols_from_enclosing_procs): Likewise.
	(num_defns_collected, defns_collected): Remove.
	(remove_extra_symbols): Return a vector.
	(remove_irrelevant_renamings): Return void.
	(ada_add_local_symbols): Accept a vector.
	(struct match_data) <obstackp>: Remove.
	<resultp>: New member.
	(aux_add_nonlocal_symbols): Update.
	(ada_add_block_renamings, add_nonlocal_symbols)
	(ada_add_all_symbols): Accept a vector.
	(ada_lookup_symbol_list_worker, ada_lookup_symbol_list): Return a
	vector.
	(ada_lookup_symbol): Update.
	(ada_add_block_symbols): Accept a vector.
	(get_var_value, iterate_over_symbols): Update.
	* ada-exp.y (block_lookup, write_var_or_type, write_name_assoc):
	Update.
2021-03-02 13:00:45 -07:00
Tom Tromey
886d459fbe Simplify resolve_subexp by using C++ algorithms
This changes resolve_subexp to use any_of and the erase-remove idiom
to simplify the code somewhat.  This simplifies the next patch a bit.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (resolve_subexp): Use any_of and erase-remove idiom.
2021-03-02 13:00:45 -07:00
Tom Tromey
bdcccc5639 Use new for ada_symbol_cache
This changes the ada_symbol_cache to be allocated with 'new' and
managed via unique_ptr.  This simplifies the code somewhat.  Also,
ada_clear_symbol_cache is changed so that it does not allocate a
symbol cache just to clear it.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (struct ada_symbol_cache) <cache_space>: Now an
	auto_obstack.
	<root>: Initialize.
	(ada_pspace_data): Remove destructor.
	<sym_cache>: Now a unique_ptr.
	(ada_init_symbol_cache, ada_free_symbol_cache): Remove.
	(ada_get_symbol_cache): Use 'new'.
	(ada_clear_symbol_cache): Rewrite.
2021-03-02 13:00:45 -07:00
Tom Tromey
1228719f31 Check objfile->sf in ada-lang.c
Most places in gdb that reference objfile->sf also check that it is
not null.  It is valid for it to be null, because find_sym_fns can
return null for some kinds of object file.  However, it's rare to
encounter this scenario with Ada code.  I only encountered it when
looking at a fork of gdb that, I believe, makes its own objfiles
without setting 'sf'.

This patch changes ada-lang.c to check this field before using it.
This avoids any potential crash here.  There's no test case because
I'm not even sure this is possible to trip over with an unmodified
gdb.

There are some other unchecked uses in gdb, but at a quick glance they
all seem to be involved with symbol reading, which of course won't
happen when sf==null.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (add_nonlocal_symbols): Handle case where objfile->sf
	is null.
2021-03-02 12:00:44 -07:00
Lancelot SIX
bb3a4efe13 [PR gdb/27393] set directories: handle empty dirs.
As reported in gdb/27393, the 'directory' and 'set directories' commands
fail when parsing an empty dir name:

    (gdb) set directories ""
    /home/lsix/dev/gnu/binutils-gdb/gdbsupport/pathstuff.cc:132: internal-error: gdb::unique_xmalloc_ptr<char> gdb_abspath(const char*): Assertion `path != NULL && path[0] != '\0'' failed.

or

    (gdb) dir :
    /home/lsix/dev/gnu/binutils-gdb/gdbsupport/pathstuff.cc:132: internal-error: gdb::unique_xmalloc_ptr<char> gdb_abspath(const char*): Assertion `path != NULL && path[0] != '\0'' failed.

This patch fixes this issue by ignoring any attempt to add an empty
name to the source directories list.  'set dir ""' will reset the
directories list the same way 'set dir' would do it.

Tested on x86_64.
2021-02-27 14:29:39 +00:00
Kevin Buettner
26b43ca6e6 Fix date in ChangeLog 2021-02-25 16:00:43 -07:00
Kevin Buettner
0f977b7715 Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h>
I added the same comment for nat/aarch64-linux-hw-point.c yesterday.
Christian suggested adding the comment for the other file that I had
identified as including both <sys/ptrace.h> and <asm/ptrace.h>.

I searched the sources in gdb/, but found no other files which include
both of these headers.

If possible, I would prefer to see us use <sys/ptrace.h> when possible,
however, from past experience, I've found that this file does not always
contain all of the constants, etc. required by the particular source
file.

gdb/ChangeLog:

	* nat/aarch64-sve-linux-ptrace.h: Add comment regarding include
	order for <sys/ptrace.h> and <asm/ptrace.h>.
2021-02-25 15:30:32 -07:00
Simon Marchi
dffdd8b51f gdb: relax assertion in target_mourn_inferior
As reported in PR 26861, when killing an inferior on macOS, we hit the
assert:

    ../../gdb-10.1/gdb/target.c:2149: internal-error: void target_mourn_inferior(ptid_t): Assertion `ptid == inferior_ptid' failed.

This is because darwin_nat_target::kill passes a pid-only ptid to
target_mourn_inferior, with the pid of the current inferior:

    target_mourn_inferior (ptid_t (inf->pid));

... which doesn't satisfy the assert in target_mourn_inferior:

    gdb_assert (ptid == inferior_ptid);

The reason for this assertion is that target_mourn_inferior is a
prototype shared between GDB and GDBserver, so that shared code in
gdb/nat (used in both GDB and GDBserver) can call target_mourn_inferior.
In GDB's implementation, it is likely that some targets still rely on
inferior_ptid being set to "the current thread we are working on".  So
until targets are completely decoupled from inferior_ptid (at least
their mourn_inferior implementations), we need to ensure the passed in
ptid matches inferior_ptid, to ensure the calling code called
target_mourn_inferior with the right global context.

However, I think the assert is a bit too restrictive.  The
mourn_inferior operation works on an inferior, not a specific thread.
And by the time we call mourn_inferior, the threads of the inferior
don't exist anymore, the process is gone, so it doesn't really make
sense to require inferior_ptid to point a specific thread.

I looked at all the target_ops::mourn_inferior implementations, those
that read inferior_ptid only care about the pid field, which supports
the idea that only the inferior matters.  Other implementations look at
the current inferior (call `current_inferior ()`).

I think it would make sense to change target_mourn_inferior to accept
only a pid rather than a ptid.  It would then assert that the pid is the
same as the current inferior's pid.  However, this would be a quite
involved change, so I'll keep it for later.

To fix the macOS issue immediately, I propose to relax the assert to
only compare the pids, as is done in this patch.

Another solution would obviously be to make darwin_nat_target::kill pass
inferior_ptid to target_mourn_inferior.  However, the solution I propose
is more in line with where I think we want to go (passing a pid to
target_mourn_inferior).

gdb/ChangeLog:

	PR gdb/26861
	* target.c (target_mourn_inferior): Only compare pids in
	target_mourn_inferior.

Change-Id: If2439ccc5aa67272ea16148a43c5362ef23fb2b8
2021-02-25 15:52:29 -05:00
Jan Matyas
64d38fdd99 Fix initial thread state of non-threaded remote targets
This change fixes the initial state of the main thread of remote
targets which have no concept of threading. Such targets are
treated as single-threaded by gdb, and this single thread needs
to be initially set to the "resumed" state, in the same manner as
threads in thread-aware remote targets (see remote.c,
remote_target::remote_add_thread).

Without this fix, the following assert was triggered on thread-
unaware remote targets:

    remote_target::select_thread_for_ambiguous_stop_reply(const target_waitstatus*): Assertion `first_resumed_thread != nullptr' failed.

The bug can be reproduced using gdbserver

    * by disabling packets 'T' and 'qThreadInfo', or
    * by disabling all thread-related packets.

The test suite has been updated to include these two scenarios, see
gdb.server/stop-reply-no-thread.exp.

Change-Id: I2c39c9de17e8d6922a8c1b9e259eb316a554a43d
2021-02-25 15:38:54 -05:00
Jan Vrany
2450ad54ce gdb/mi: Remove extra \n from tsv and and traceframe notifications
An extra \n in calls to fprintf_unfiltered() caused invalid MI records
to be emitted:

   > gdb -i mi3 -ex "target remote :7000"
   =thread-group-added,id="i1"
   ~"GNU gdb (GDB) 11.0.50.20201019-git\n"
   ~"Copyright (C) 2020 Free Software Foundation, Inc.\n"
   ...
   ~"Remote debugging using :7001\n"
   =tsv-created,name="trace_timestamp",initial="0"\n
   =thread-group-started,id="i1",pid="304973"

This commit fixes the problem.

gdb/ChangeLog:

        * gdb/mi/mi-interp.c (mi_traceframe_changed): Remove trailing \n from output.
        (mi_tsv_created): Likewise.
        (mi_tsv_deleted): Likewise.
2021-02-25 16:22:13 +00:00
Tom de Vries
30c80d8833 [gdb/symtab] Fix wrong unit_type Dwarf Error
When running test-case gdb.dwarf2/fission-mix.exp using gcc-11 (and using the
tentative fix for PR27353 to get past that assertion failure), I run into:
...
(gdb) file fission-mix^M
Reading symbols from fission-mix...^M
Dwarf Error: wrong unit_type in compilation unit header \
  (is DW_UT_split_compile (0x05), should be DW_UT_type (0x02)) \
  [in module fission-mix2.dwo]^M
(No debugging symbols found in fission-mix)^M
...

The compilation unit that is complained about is:
...
Contents of the .debug_info.dwo section (loaded from fission-mix2.dwo):

  Compilation Unit @ offset 0x0:
   Length:        0x57 (32-bit)
   Version:       5
   Unit Type:     DW_UT_split_compile (5)
   Abbrev Offset: 0x0
   Pointer Size:  8
   DWO ID:        0x3e3930d3cc1805df
 <0><14>: Abbrev Number: 1 (DW_TAG_compile_unit)
...

And the dwarf error is triggered here in read_comp_unit_head:
...
        case DW_UT_split_compile:
          if (section_kind != rcuh_kind::COMPILE)
            error (_("Dwarf Error: wrong unit_type in compilation unit header "
                   "(is %s, should be %s) [in module %s]"),
                   dwarf_unit_type_name (cu_header->unit_type),
                   dwarf_unit_type_name (DW_UT_type), filename);
          break;
...
due to passing rcuh_kind::TYPE here in open_and_init_dwo_file:
...
      create_debug_type_hash_table (per_objfile, dwo_file.get (),
                                    &dwo_file->sections.info, dwo_file->tus,
                                    rcuh_kind::TYPE);
...

Fix this by changing the section_kind argument to create_debug_type_hash_table
to rcuh_kind::COMPILE, to reflect that we're passing &dwo_file->sections.info
rather than &dwo_file->sections.types.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-02-25  Tom de Vries  <tdevries@suse.de>

	PR symtab/27354
	* dwarf2/read.c (open_and_init_dwo_file): Use rcuh_kind::COMPILE as
	section_kind for &dwo_file->sections.info.
2021-02-25 15:41:49 +01:00
Andrew Burgess
68337b8be3 gdb/fortran: don't access non-existent type fields
When attempting to call a Fortran function for which there is no debug
information we currently trigger undefined behaviour in GDB by
accessing non-existent type fields.

The reason is that in order to prepare the arguments, for a call to a
Fortran function, we need to know the type of each argument.  If the
function being called has no debug information then obviously GDB
doesn't know about the argument types and we should either give the
user an error or pick a suitable default.  What we currently do is
just assume the field exist and access undefined memory, which is
clearly wrong.

The reason GDB needs to know the argument type is to tell if the
argument is artificial or not, artificial arguments will be passed by
value while non-artificial arguments will be passed by reference.

An ideal solution for this problem would be to allow the user to cast
the function to the correct type, we already do this to some degree
with the return value, for example:

  (gdb) print some_func_ ()
  'some_func_' has unknown return type; cast the call to its declared return type
  (gdb) print (integer) some_func_ ()
  $1 = 1

But if we could extend this to allow casting to the full function
type, GDB could figure out from the signature what are real
parameters, and what are artificial parameters.  Maybe something like
this:

  (gdb) print ((integer () (integer, double)) some_other_func_ (1, 2.3)

Alas, right now the Fortran expression parser doesn't seem to support
parsing function signatures, and we certainly don't have support for
figuring out real vs artificial arguments from a signature.

Still, I think we can prevent GDB from accessing undefined memory and
provide a reasonable default behaviour.

In this commit I:

  - Only ask if the argument is artificial if the type of the argument
  is actually known.

  - Unknown arguments are assumed to be artificial and passed by
  value (non-artificial arguments are pass by reference).

  - If an artificial argument is prefixed with '&' by the user then we
  treat the argument as pass-by-reference.

With these three changes we avoid undefined behaviour in GDB, and
allow the user, in most cases, to get a reasonably natural default
behaviour.

gdb/ChangeLog:

	PR fortran/26155
	* f-lang.c (fortran_argument_convert): Delete declaration.
	(fortran_prepare_argument): New function.
	(evaluate_subexp_f): Move logic to new function
	fortran_prepare_argument.

gdb/testsuite/ChangeLog:

	PR fortran/26155
	* gdb.fortran/call-no-debug-func.f90: New file.
	* gdb.fortran/call-no-debug-prog.f90: New file.
	* gdb.fortran/call-no-debug.exp: New file.
2021-02-25 10:33:12 +00:00
Andrew Burgess
faeb9f13c1 gdb/fortran: add support for ASSOCIATED builtin
This commit adds support for the ASSOCIATED builtin to the Fortran
expression evaluator.  The ASSOCIATED builtin takes one or two
arguments.

When passed a single pointer argument GDB returns a boolean indicating
if the pointer is associated with anything.

When passed two arguments the second argument should either be some a
pointer could point at or a second pointer.

If the second argument is a pointer target, then the result from
associated indicates if the pointer is pointing at this target.

If the second argument is another pointer, then the result from
associated indicates if the two pointers are pointing at the same
thing.

gdb/ChangeLog:

	* f-exp.y (f77_keywords): Add 'associated'.
	* f-lang.c (fortran_associated): New function.
	(evaluate_subexp_f): Handle FORTRAN_ASSOCIATED.
	(operator_length_f): Likewise.
	(print_unop_or_binop_subexp_f): New function.
	(print_subexp_f): Make use of print_unop_or_binop_subexp_f for
	FORTRAN_ASSOCIATED, FORTRAN_LBOUND, and FORTRAN_UBOUND.
	(dump_subexp_body_f): Handle FORTRAN_ASSOCIATED.
	(operator_check_f): Likewise.
	* std-operator.def: Add FORTRAN_ASSOCIATED.

gdb/testsuite/ChangeLog:

	* gdb.fortran/associated.exp: New file.
	* gdb.fortran/associated.f90: New file.
2021-02-25 10:09:11 +00:00
Andrew Burgess
170f4b23b6 gdb/fortran: add support for legacy .xor. operator
gfortran supports .xor. as an alias for .neqv., see:

  https://gcc.gnu.org/onlinedocs/gfortran/_002eXOR_002e-operator.html

this commit adds support for this operator to GDB.

gdb/ChangeLog:

	* f-exp.y (fortran_operators): Add ".xor.".

gdb/testsuite/ChangeLog:

	* gdb.fortran/dot-ops.exp (dot_operations): Test ".xor.".
2021-02-25 10:07:44 +00:00
Tom de Vries
aa659cfad6 [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const
With test-case gdb.cp/temargs.exp on target board \
unix/gdb:debug_flags=-gdwarf-5 I run into:
...
(gdb) info addr I^M
ERROR: GDB process no longer exists
GDB process exited with wait status 32286 exp19 0 0 CHILDKILLED SIGABRT SIGABRT
UNRESOLVED: gdb.cp/temargs.exp: test address of I in templ_m
...

This is a regression since commit 529908cbd0 "Remove DW_UNSND".

The problem is that this DW_AT_decl_file:
...
 <1><221>: Abbrev Number: 4 (DW_TAG_structure_type)
    <222>   DW_AT_name        : Base<double, 23, (& a_global), &S::f>
    <226>   DW_AT_byte_size   : 1
    <226>   DW_AT_decl_file   : 1
    <226>   DW_AT_decl_line   : 30
    <227>   DW_AT_sibling     : <0x299>
...
is not read by this code in new_symbol:
....
      attr = dwarf2_attr (die,
                          inlined_func ? DW_AT_call_file : DW_AT_decl_file,
                          cu);
      if (attr != nullptr && attr->form_is_unsigned ())
...
because DW_AT_decl_file has form DW_FORM_implicit_const:
...
   4      DW_TAG_structure_type    [has children]
    DW_AT_name         DW_FORM_strp
    DW_AT_byte_size    DW_FORM_implicit_const: 1
    DW_AT_decl_file    DW_FORM_implicit_const: 1
    DW_AT_decl_line    DW_FORM_data1
    DW_AT_sibling      DW_FORM_ref4
    DW_AT value: 0     DW_FORM value: 0
...
which is a signed LEB128, so attr->form_is_unsigned () returns false.

Fix this by introducing new functions is_nonnegative and as_nonnegative, and
use these instead of form_is_unsigned and as_unsigned.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-02-24  Tom de Vries  <tdevries@suse.de>

	PR symtab/27336
	* dwarf2/attribute.c (attribute::form_is_signed): New function
	factored out of ...
	* dwarf2/attribute.h (attribute::as_signed): ... here.
	(attribute::is_nonnegative, attribute::as_nonnegative): New function.
	(attribute::form_is_signed): Declare.
	* dwarf2/read.c (new_symbol): Use is_nonnegative and as_nonnegative
	for DW_AT_decl_file.
2021-02-24 23:58:42 +01:00
Kevin Buettner
268c77c1b0 Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h>
gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c: Add comment regarding include
	order for <sys/ptrace.h> and <asm/ptrace.h>.
2021-02-24 14:35:07 -07:00
Kevin Buettner
665af52ec2 Fix aarch64-linux-hw-point.c build problem
Due to a recent glibc header file change, the file
nat/aarch64-linux-hw-point.c no longer builds on Fedora rawhide.

An enum for PTRACE_SYSEMU is now provided by <sys/ptrace.h>.  In the
past, PTRACE_SYSEMU was defined only in <asm/ptrace.h>.  This is
what it looks like...

In <asm/ptrace.h>:

 #define PTRACE_SYSEMU		  31

In <sys/ptrace.h>:

enum __ptrace_request
{
  ...
  PTRACE_SYSEMU = 31,
 #define PT_SYSEMU PTRACE_SYSEMU

  ...
}

When <asm/ptrace.h> and <sys/ptrace.h> are both included in a source
file, we run into the following build problem when the former is
included before the latter:

In file included from nat/aarch64-linux-hw-point.c:26:
/usr/include/sys/ptrace.h:86:3: error: expected identifier before numeric constant
   86 |   PTRACE_SYSEMU = 31,
      |   ^~~~~~~~~~~~~

(There are more errors after this one too.)

The file builds without error when <asm/ptrace.h> is included after
<sys/ptrace.h>.  I found that this is already done in
nat/aarch64-sve-linux-ptrace.h (which is included by
nat/aarch64-linux-ptrace.c).

I've tested this change on Fedora rawhide and Fedora 33, both
running on an aarch64 machine.

gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
	<sys/ptrace.h>.
2021-02-24 12:54:39 -07:00
Andrew Burgess
dd80d75040 gdb: use std::string instead of a fixed size buffer
The 'section' command uses a fixed size buffer into which a section
name is copied.  This commit replaces this with a use of std::string
so we can now display very long section names.

The expected results of one test need to be updated.

gdb/ChangeLog:

	* exec.c (set_section_command): Move variable declarations into
	the function body, and use std::string instead of a fixed size
	buffer.

gdb/testsuite/ChangeLog:

	* gdb.base/sect-cmd.exp: Update expected results.
2021-02-24 16:58:05 +00:00
Andrew Burgess
336aa7b740 gdb: move get_section_table from exec_target to dummy_target
The only target that implements target_ops::get_section_table in a
meaningful way is exec_target.  This target calls back into the
program space to return the current global section_table.

The global section table is populated whenever the user provides GDB
with an executable, or when a symbol file is loaded, e.g. when a
dynamic library is loaded, or when the user does add-symbol-file.

I recently ran into a situation where a user, debugging a remote
target, was not supplying GDB with a main executable at all.  Instead
the user attached to the target then did add-symbol-file, and then
proceeded to debug the target.

This works fine, but it was noticed that even when
trust-readonly-sections was on GDB was still accessing the target to
get the contents of readonly sections.

The problem is that by not providing an executable there was no
exec_target in the target stack, and so when GDB calls the
target_ops::get_section_table function GDB ends up in
dummy_target::get_section_table, which just returns NULL.

What I want is that even when GDB doesn't have an exec_target in the
target stack, a call to target_ops::get_section_table will still
return the section_table from the current program space.

When considering how to achieve this my first though was, why is the
request for the section table going via the target stack at all?  The
set of sections loaded is a property of the program space, not the
target.  This is, after all, why the data is being stored in the
program space.

So I initially tried changing target_get_section_table so that,
instead of calling into the target it just returns
current_program_space->target_sections ().

This would be fine except for one issue, target_bfd (from
bfd-target.c).  This code is used from solib-svr4.c to create a
temporary target_ops structure that implements two functions
target_bfd::xfer_partial and target_bfd::get_section_table.

The purpose behind the code is to enable two targets, ppc64 and frv to
decode function descriptors from the dynamic linker, based on the
non-relocated addresses from within the dynamic linker bfd object.

Both of the implemented functions in target_bfd rely on the target_bfd
object holding a section table, and the ppc64 target requires that the
target_bfd implement ::get_section_table.

The frv target doesn't require ::get_section_table, instead it
requires the ::xfer_partial.  We could in theory change the ppc64
target to use the same approach as frv, however, this would be a bad
idea.  I believe that the frv target approach is broken.  I'll
explain:

The frv target calls get_target_memory_unsigned to read the function
descriptor.  The address being read is the non-relocated address read
from the dynamic linker in solib-srv4.c:enable_break.  Calling
get_target_memory_unsigned eventually ends up in target_xfer_partial
with an object type of TARGET_OBJECT_RAW_MEMORY.  This will then call
memory_xfer_check_region.  I believe that it is quite possible that a
the non-relocated addresses pulled from the dynamic linker could be in
a memory region that is not readable, while the relocated addresses
are in a readable memory region.  If this was ever the case for the
frv target then GDB would reject the attempt to read the non-relocated
function pointer.

In contrast the ppc64 target calls target_section_by_addr, which calls
target_get_section_table, which then calls the ::get_section_table
function on the target.

Thus, when reflecting on target_bfd we see two functions,
::xfer_partial and ::get_section_table.  The former is required by the
frv target, but that target is (I think) potentially broken.  While
the latter is required by the ppc64 target, but this forces
::get_section_table to exist as a target_ops member function.

So my original plan, have target_get_section_table NOT call a
target_ops member function appears to be flawed.

My next idea was to remove exec_target::get_section_table, and instead
move the implementation into dummy_target::get_section_table.
Currently the dummy_target implementation always returns NULL
indicating no section table, but plenty of other dummy_target member
functions do more than just return null values.

So now, dummy_target::get_section_table returns the section table from
the current program space.  This allows target_bfd to remain
unchanged, so ppc64 and frv should not be affected.

Making this change removes the requirement for the user to provide an
executable, GDB can now always access the section_table, as the
dummy_target always exists in the target stack.

Finally, there's a test that the target_section table is not empty in
the case where the user does add-symbol-file without providing an
executable.

gdb/ChangeLog:

	* exec.c (exec_target::get_section_table): Delete member function.
	(section_table_read_available_memory): Use current_top_target, not
	just the exec_ops target.
	* target-delegates.c: Regenerate.
	* target.c (default_get_section_table): New function.
	* target.h (target_ops::get_section_table): Change default
	behaviour to call default_get_section_table.
	(default_get_section_table): Declare.
2021-02-24 16:58:04 +00:00
Andrew Burgess
02f7d26b0b gdb: make the target_sections table private within program_space
Following on from earlier commits which made access to the
target_sections table more 'const', this commit makes the table
private within the program_space class and provides member functions
to access the table.

Ideally I would have liked for the new target_sections member
function (on program_space) to return a 'const' reference to the table
within the program_space.  Unfortunately, there are two places in
solib-*.c, where code outside of the program_space class modifies the
target_sections table, and so to support this we need to return a
non-const reference.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* exec.c (exec_target::close): Call new clear_target_sections
	function.
	(program_space::add_target_sections): Update name of member
	variable.
	(program_space::foreach_target_section): New function.
	(program_space::add_target_sections): Update name of member
	variable.
	(program_space::remove_target_sections): Likewise.
	(exec_one_fork): Use new target_sections member function.
	(exec_target::get_section_table): Likewise.
	(exec_target::files_info): Likewise.
	(set_section_command): Use new foreach_target_section member
	function.
	(exec_set_section_address): Likewise.
	(exec_target::has_memory): Use new target_sections member
	function.
	* progspace.h (program_space::clear_target_sections): New member
	function.
	(program_space::target_sections): Rename member variable to
	m_target_sections, replace with a new member function.
	(program_space::foreach_target_section): Declare new member
	function.
	(program_space::m_target_sections): New member variable.
	* solib-dsbt.c (scan_dyntag): Use new member function.
	* solib-svr4.c (scan_dyntag): Likewise.
2021-02-24 16:58:04 +00:00
Andrew Burgess
19cf757a87 gdb: spread a little 'const' through the target_section_table code
The code to access the target section table can be made more const, so
lets do that.  There should be no user visible changes after this
commit.

gdb/ChangeLog:

	* gdb/bfd-target.c (class target_bfd) <get_section_table>: Make
	return type const.
	* gdb/exec.c (struct exec_target) <get_section_table>: Likewise.
	(section_table_read_available_memory): Make local const.
	(exec_target::xfer_partial): Make local const.
	(print_section_info): Make parameter const.
	* gdb/exec.h (print_section_info): Likewise.
	* gdb/ppc64-tdep.c (ppc64_convert_from_func_ptr_addr): Make local
	const.
	* gdb/record-btrace.c (record_btrace_target::xfer_partial):
	Likewise.
	* gdb/remote.c (remote_target::remote_xfer_live_readonly_partial):
	Likewise.
	* gdb/s390-tdep.c (s390_load): Likewise.
	* gdb/solib-dsbt.c (scan_dyntag): Likewise.
	* gdb/solib-svr4.c (scan_dyntag): Likewise.
	* gdb/target-debug.h (target_debug_print_target_section_table_p):
	Rename to...
	(target_debug_print_const_target_section_table_p): ...this.
	* gdb/target-delegates.c: Regenerate.
	* gdb/target.c (target_get_section_table): Make return type const.
	(target_section_by_addr): Likewise.  Also make some locals const.
	(memory_xfer_partial_1): Make some locals const.
	* gdb/target.h (struct target_ops) <get_section_table>: Make
	return type const.
	(target_section_by_addr): Likewise.
	(target_get_section_table): Likewise.
2021-02-24 16:58:02 +00:00
Andrew Burgess
02a7930992 gdb: add a new 'maint info target-sections' command
We already have a command 'maint info sections', this command prints
all sections from all known object files.

However, GDB maintains a second section table internally.  This
section table is used when GDB wants to read directly from an object
file rather than actually reading memory on the target.  As such only
some sections (the allocatable ones) are added to this secondary
section table.

I recently ran into a situation where some of GDB's optimisations for
reading directly from the files were not working.  In 'maint info
sections' I could see that GDB knew about the object file, and did
know about the sections that it _should_ have been reading from.  But
I couldn't ask GDB which sections it had copied into its secondary
section table.

This commit adds a new command 'maint info target-sections' that fills
this gap.  This command lists only those sections that GDB has copied
into its secondary table.

You'll notice that the testsuite includes a comment indicating that
there's a bug in GDB.  Normally this is not something I would add to
the testsuite, instead we should raise an actual bugzilla bug and then
mark an xfail, however, a later patch in this series will remove this
comment once the actual bug in GDB is fixed.

gdb/ChangeLog:

	* NEWS: Mention new 'maint info target-sections' command.
	* maint.c (maintenance_info_target_sections): New function.
	(_initialize_maint_cmds): Register new command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Files): Document new 'maint info target-sections'
	command.

gdb/testsuite/ChangeLog:

	* gdb.base/maint-info-sections.exp: Add new tests.
	(check_maint_info_target_sections_output): New proc.
2021-02-24 16:58:02 +00:00
Andrew Burgess
895b7b4e4b gdb/riscv: select rv32 target by default when requested
GDB for RISC-V always uses target descriptions.  When the target
doesn't provide a target description then a default is selected.
Usually this default is selected based on the properties of the
executable being debugged.  However, when there is no executable being
debugged we currently fallback to the riscv:rv64 target description as
the default.  This leads to strange behaviour like this:

  $ gdb
  (gdb) set architecture riscv:rv32
  (gdb) p sizeof ($pc)
  $1 = 8

Despite the users specifically setting the architecture to riscv:rv32
GDB still thinks that the target has riscv:rv64 register sizes.

The above is a bit of a contrived situation.  I actually ran into this
situation while trying to connect to a running riscv:rv32 target
without supplying an executable (the target didn't provide a target
description).  When I tried to set a register on the target I ran into
errors because GDB was passing 8 bytes to the target rather than the
expected 4.  Even when I manually specified the architecture (as
above) I couldn't convince GDB to only send 4 bytes.

This patch fixes this issue.  Now, when we selected a default target
description we will make use of the user selected architecture to
guide our choice.  In the above example we now get:

  $ gdb
  (gdb) set architecture riscv:rv32
  (gdb) p sizeof ($pc)
  $1 = 4

And my real world example of connecting to a remote without an
executable works fine.

I've used the fact that we can ask GDB about $pc even when no
executable is loaded as the basis for a test to cover this situation.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_features_from_gdbarch_info): Rename to...
	(riscv_features_from_bfd): ...this.  Change parameter type to
	'bfd*', and update as required.
	(riscv_find_default_target_description): Update call to
	riscv_features_from_bfd.  Select a default xlen based on
	info.bfd_arch_info.
	(riscv_gdbarch_init): Update call to riscv_features_from_bfd.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-default-tdesc.exp: New file.
2021-02-24 16:06:54 +00:00
Andrew Burgess
bc3c0632a2 gdb: call value_ind for pointers to dynamic types in UNOP_IND evaluation
When evaluating and expression containing UNOP_IND in mode
EVAL_AVOID_SIDE_EFFECTS, GDB currently (mostly) returns the result of
a call to value_zero meaning we get back an object with the correct
type, but its contents are all zero.

If the target type contains fields with dynamic type then in order to
resolve these dynamic fields GDB will need to read the value of the
field from within the parent object.  In this case the field value
will be zero as a result of the call to value_zero mentioned above.

The idea behind EVAL_AVOID_SIDE_EFFECTS is to avoid the chance that
doing something like `ptype` will modify state within the target, for
example consider: ptype i++.

However, there is already precedence within GDB that sometimes, in
order to get accurate type results, we can't avoid reading from the
target, even when EVAL_AVOID_SIDE_EFFECTS is in effect.  For example I
would point to eval.c:evaluate_var_value, the handling of OP_REGISTER,
the handling of value_x_unop in many places.  I believe the Ada
expression evaluator also ignore EVAL_AVOID_SIDE_EFFECTS in some
cases.

I am therefor proposing that, in the case where a pointer points at a
dynamic type, we allow UNOP_IND to perform the actual indirection.
This allows accurate types to be displayed in more cases.

gdb/ChangeLog:

	* eval.c (evaluate_subexp_standard): Call value_ind for points to
	dynamic types in UNOP_IND.

gdb/testsuite/ChangeLog:

	* gdb.fortran/pointer-to-pointer.exp: Additional tests.
2021-02-24 15:51:29 +00:00
Simon Marchi
08ac57714c gdb/dwarf: create and destroy dwarf2_per_bfd's CUs-to-expand queue
As described in the log of patch "gdb/dwarf: add assertion in
maybe_queue_comp_unit", it would happen that a call to
maybe_queue_comp_unit would enqueue a CU in the to-expand queue while
nothing up the stack was processing the queue.  This is not desirable,
as items are then left lingering in the queue when we exit the
dwarf2/read code.  This is an inconsistent state.

The normal case of using the queue is when we go through
dw2_do_instantiate_symtab and process_queue.  As depended-on CUs are
found, they get added to the queue.  process_queue expands CUs until the
queue is empty.

To catch these cases where things are enqueued while nothing up the
stack is processing the queue, change dwarf2_per_bfd::queue to be an
optional.  The optional is instantiated in dwarf2_queue_guard, just
before where we call process_queue.  In the dwarf2_queue_guard
destructor, the optional gets reset.  Therefore, the queue object is
instantiated only when something up the stack is handling it.  If
another entry point tries to enqueue a CU for expansion, an assertion
will fail and we know we have something to fix.

dwarf2_queue_guard sounds like the good place for this, as it's
currently responsible for making sure the queue gets cleared if we exit
due to an error.

This also allows asserting that when age_comp_units or remove_all_cus
run, the queue is not instantiated, and gives us one more level of
assurance that we won't free the DIEs of a CU that is in the
CUs-to-expand queue.

gdb/ChangeLog:

	PR gdb/26828
	* dwarf2/read.c (dwarf2_queue_guard) <dwarf2_queue_guard>:
	Instantiate queue.
	(~dwarf2_queue_guard): Clear queue.
	(queue_comp_unit): Assert that queue is
	instantiated.
	(process_queue): Adjust.
	* dwarf2/read.h (struct dwarf2_per_bfd) <queue>: Make optional.

Change-Id: I8fe3d77845bb4ad3d309eac906acebe79d9f0a9d
2021-02-23 13:37:44 -05:00
Simon Marchi
616c069a3f gdb/dwarf: don't enqueue CU in maybe_queue_comp_unit if already expanded
The previous commit log described how items could be left lingering in
the dwarf2_per_bfd::queue and how that could cause trouble.

This patch fixes the issue by changing maybe_queue_comp_unit so that it
doesn't put a CU in the to-expand queue if that CU is already expanded.
This will make it so that when dwarf2_fetch_die_type_sect_off calls
follow_die_offset and maybe_queue_comp_unit, it won't enqueue the target
CU, because it will see the CU is already expanded.

This assumes that if a CU is dwarf2_fetch_die_type_sect_off's target CU,
it will have previously been expanded.  I think it is the case, but I
can't be 100% sure.  If that's not true, the assertions added in the
following patch will catch it, and it means we'll have to re-think a bit
more how things work (it wouldn't be well handled at all today anyway).

This fixes something else in maybe_queue_comp_unit that looks wrong.
Imagine the DIEs of a CU are loaded in memory, but that CU is not
expanded.  In that case, maybe_queue_comp_unit will use this early
return:

  /* If the compilation unit is already loaded, just mark it as
     used.  */
  dwarf2_cu *cu = per_objfile->get_cu (per_cu);
  if (cu != nullptr)
    {
      cu->last_used = 0;
      return 0;
    }

... so the CU won't be queued for expansion.  Whether the DIEs of a CU
are loaded in memory and whether that CU is expanded are two orthogonal
things, but that function appears to mix them.  So, move the queuing
above that check / early return, so that if the CU's DIEs are loaded in
memory but the CU is not expanded yet, it gets enqueued.

I tried to improve maybe_queue_comp_unit's documentation to clarify what
the return value means.  By clarifying this, I noticed that two callers
(follow_die_offset and follow_die_sig_1) access the CU's DIEs after
calling maybe_queue_comp_unit, only relying on maybe_queue_comp_unit's
return value to tell whether DIEs need to be loaded first or not.  As
explained in the new comment, this is problematic:
maybe_queue_comp_unit's return value doesn't tell whether DIEs are
currently loaded, it means whether maybe_queue_comp_unit requires the
caller to load them.  If the CU is already expanded but the DIEs to have
been freed, maybe_queue_comp_unit returns 0, meaning "I don't need you
to load the DIEs".  So if these two functions (follow_die_offset and
follow_die_sig_1) need to access the DIEs in any case, for their own
usage, they should make sure to load them if they are not loaded
already.  I therefore added an extra check to the condition they use,
making it so they will always load the DIEs if they aren't already.

From what I found, other callers don't care for the CU's DIEs, they call
maybe_queue_comp_unit to ensure the CU gets expanded eventually, but
don't care for it after that.

gdb/ChangeLog:

	PR gdb/26828
	* dwarf2/read.c (maybe_queue_comp_unit): Check if CU is expanded
	to decide whether or not to enqueue it for expansion.
	(follow_die_offset, follow_die_sig_1): Ensure we load the DIEs
	after calling maybe_queue_comp_unit.

Change-Id: Id98c6b60669f4b4b21b9be16d0518fc62bdf686a
2021-02-23 12:07:10 -05:00
Simon Marchi
897608ed56 gdb: linux-nat: make linux_nat_filter_event return void
I noticed that linux_nat_filter_event returns a value, but its caller
doesn't use it.  This has been since 9c02b52532 ("linux-nat.c: better
starvation avoidance, handle non-stop mode too").  Before that commit,
the return value was used to tell the caller whether to continue
processing that event or not.  But since then, the model is that we pull
all events from the kernel and linux_nat_filter_event just saves the
status to the lwp_info structure if it thinks it's relevant.  And the
caller, linux_nat_wait_1, selects a status at random amongst the threads
with a pending status.  So essentially, the return value of
linux_nat_filter_event does not have a reason to be anymore.  Change it
so it returns void.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_filter_event): Return void.

Change-Id: I35662868910f5122772ed92a512adfbf4da12d87
2021-02-23 10:56:41 -05:00
Tom Tromey
15908a11ba Change target_bfd_reopen to take a gdb_bfd_ref_ptr
While looking at Andrew's recent target sections series, I saw that
target_bfd_reopen took a "bfd *", leading to a call to new_reference.
However, because the only caller of target_bfd_reopen is already using
gdb_bfd_ref_ptr, this code can be simplified and the explicit call to
new_reference can be removed.

gdb/ChangeLog
2021-02-22  Tom Tromey  <tromey@adacore.com>

	* solib-svr4.c (enable_break): Update.
	* bfd-target.c (class target_bfd) <target_bfd>: Change parameter
	type.
	(target_bfd_reopen): Change parameter type.
	* bfd-target.h (target_bfd_reopen): Change parameter type.
2021-02-22 09:47:37 -07:00
Simon Marchi
f53fc42716 gdb: add asserts in thread code
Unlike the previous patch, I don't propose that we take this patch into
gdb-10-branch.

This patch adds two asserts, prompted by investigating and fixing the
bug fixed by the previous patch.

The assert in find_thread_ptid would have caught the original issue
before the segfault (I think it's slightly more use friendly).

The assert in add_thread_silent would have made it clear that the
solution proposed in [1] isn't the right one.  The solution ended up
passing nullptr as a target to add_thread.  We don't want that, because
add_thread_silent uses it to look up the inferior to which to add the
thread.  If the target is nullptr, we could find an inferior with the
same pid, but belonging to an unrelated target.  So we always want a
non-nullptr target in add_thread_silent.

gdb/ChangeLog:

	* thread.c (add_thread_silent): Add assert.
	(find_thread_ptid): Add assert.

[1] https://sourceware.org/pipermail/gdb-patches/2021-February/176202.html

Change-Id: Ie593ee45c5eb02235e8e9fbcda612d48ce883852
2021-02-22 11:42:03 -05:00
Simon Marchi
de146e1946 gdb: push target earlier in procfs_target::attach (PR 27435)
Since this is a GDB 9 -> 10 regression, I would like to push it to
gdb-10-branch.

This is a follow-up to:

  https://sourceware.org/pipermail/gdb-patches/2021-February/176202.html

This patch fixes a segfault seen when attaching to a process on Solaris.
The steps leading to the segfault are:

 - procfs_target::attach calls do_attach, at this point the inferior's
   process slot in the target stack is empty.
 - do_attach adds a thread with `add_thread (&the_procfs_target, ptid)`
 - in add_thread_silent, the passed target (&the_procfs_target) is
   passed to find_inferior_ptid
 - find_inferior_ptid returns nullptr, as there is no inferior with this
   ptid that has &the_procfs_target as its process target
 - the nullptr `inf` is passed to find_thread_ptid, which dereferences
   it, causing a segfault
 - back in procfs_target::attach, after do_attach, we push the
   the_procfs_target on the inferior's target stack, although we never
   reach this because the segfault happens before.

To fix this, I think we need to do the same as is done in
inf_ptrace_target::attach: push the target early and unpush it in case
the attach fails (and keep it if the attach succeeds).

Implement it by moving target_unpush_up to target.h, so it can be
re-used here.  Make procfs_target::attach use it.  Note that just like
is mentioned in inf_ptrace_target::attach, we should push the target
before calling target_pid_to_str, so that calling target_pid_to_str ends
up in procfs_target::pid_to_str.

Tested by trying to attach on a process on gcc211 on the gcc compile
farm.

gdb/ChangeLog:

	PR gdb/27435
	* inf-ptrace.c (struct target_unpusher): Move to target.h.
	(target_unpush_up): Likewise.
	* procfs.c (procfs_target::attach): Push target early.  Use
	target_unpush_up to unpush target in case of error.
	* target.h (struct target_unpusher): Move here.
	(target_unpush_up): Likewise.

Change-Id: I88aff8b20204e1ca1d792e27ac6bc34fc1aa0d52
2021-02-22 11:41:32 -05:00
Kevin Buettner
8488c357ce amd64-linux-siginfo.c: Adjust include order to avoid gnulib error
On Fedora rawhide, after updating to glibc-2.33, I'm seeing the
following build failure:

  CXX    nat/amd64-linux-siginfo.o
In file included from /usr/include/bits/sigstksz.h:24,
                 from /usr/include/signal.h:315,
                 from ../gnulib/import/signal.h:52,
                 from /ironwood1/sourceware-git/rawhide-gnulib/bld/../../worktree-gnulib/gdbserver/../gdb/nat/amd64-linux-siginfo.c:20:
../gnulib/import/unistd.h:663:3: error: #error "Please include config.h first."
  663 |  #error "Please include config.h first."
      |   ^~~~~

glibc-2.33 has changed signal.h to now include <bits/sigstksz.h> which,
in turn, includes <unistd.h>. For a gdb build, this causes the gnulib
version of unistd.h to be pulled in first.  The build failure shown
above happens because gnulib's config.h has not been included before
the include of <signal.h>.

The fix is simple - we just rearrange the order of the header file
includes to make sure that gdbsupport/commondefs.h is included before
attempting to include signal.h.  Note that gdbsupport/commondefs.h
includes <gnulib/config.h>.

Build and regression tested on Fedora 33.  On Fedora rawhide, GDB
builds again.

gdb/ChangeLog:

	* nat/amd64-linux-siginfo.c: Include "gdbsupport/common-defs.h"
	(which in turn includes <gnulib/config.h>) before include
	of <signal.h>.
2021-02-18 22:56:56 -07:00
Nelson Chu
5a9f5403c7 RISC-V: PR27158, fixed UJ/SB types and added CSS/CL/CS types for .insn.
* Renamed obsolete UJ/SB types and RVC types, also added CSS/CL(CS) types,

[VALID/EXTRACT/ENCODE macros]
BTYPE_IMM:            Renamed from SBTYPE_IMM.
JTYPE_IMM:            Renamed from UJTYPE_IMM.
CITYPE_IMM:           Renamed from RVC_IMM.
CITYPE_LUI_IMM:       Renamed from RVC_LUI_IMM.
CITYPE_ADDI16SP_IMM:  Renamed from RVC_ADDI16SP_IMM.
CITYPE_LWSP_IMM:      Renamed from RVC_LWSP_IMM.
CITYPE_LDSP_IMM:      Renamed from RVC_LDSP_IMM.
CIWTYPE_IMM:          Renamed from RVC_UIMM8.
CIWTYPE_ADDI4SPN_IMM: Renamed from RVC_ADDI4SPN_IMM.
CSSTYPE_IMM:          Added for .insn without special encoding.
CSSTYPE_SWSP_IMM:     Renamed from RVC_SWSP_IMM.
CSSTYPE_SDSP_IMM:     Renamed from RVC_SDSP_IMM.
CLTYPE_IMM:           Added for .insn without special encoding.
CLTYPE_LW_IMM:        Renamed from RVC_LW_IMM.
CLTYPE_LD_IMM:        Renamed from RVC_LD_IMM.
RVC_SIMM3:            Unused and removed.
CBTYPE_IMM:           Renamed from RVC_B_IMM.
CJTYPE_IMM:           Renamed from RVC_J_IMM.

* Added new operands and removed the unused ones,

C5: Unsigned CL(CS) immediate, added for .insn directive.
C6: Unsigned CSS immediate, added for .insn directive.
Ci: Unused and removed.
C<: Unused and removed.

bfd/
    PR 27158
    * elfnn-riscv.c (perform_relocation): Updated encoding macros.
    (_bfd_riscv_relax_call): Likewise.
    (_bfd_riscv_relax_lui): Likewise.
    * elfxx-riscv.c (howto_table): Likewise.
gas/
    PR 27158
    * config/tc-riscv.c (riscv_ip): Updated encoding macros.
    (md_apply_fix): Likewise.
    (md_convert_frag_branch): Likewise.
    (validate_riscv_insn): Likewise.  Also arranged operands, including
    added C5 and C6 operands, and removed unused Ci and C< operands.
    * doc/c-riscv.texi: Updated and added CSS/CL/CS types.
    * testsuite/gas/riscv/insn.d: Added CSS/CL/CS instructions.
    * testsuite/gas/riscv/insn.s: Likewise.
gdb/
    PR 27158
    * riscv-tdep.c (decode_ci_type_insn): Updated encoding macros.
    (decode_j_type_insn): Likewise.
    (decode_cj_type_insn): Likewise.
    (decode_b_type_insn): Likewise.
    (decode): Likewise.
include/
    PR 27158
    * opcode/riscv.h: Updated encoding macros.
opcodes/
    PR 27158
    * riscv-dis.c (print_insn_args): Updated encoding macros.
    * riscv-opc.c (MASK_RVC_IMM): defined to ENCODE_CITYPE_IMM.
    (match_c_addi16sp): Updated encoding macros.
    (match_c_lui): Likewise.
    (match_c_lui_with_hint): Likewise.
    (match_c_addi4spn): Likewise.
    (match_c_slli): Likewise.
    (match_slli_as_c_slli): Likewise.
    (match_c_slli64): Likewise.
    (match_srxi_as_c_srxi): Likewise.
    (riscv_insn_types): Added .insn css/cl/cs.
sim/
    PR 27158
    * riscv/sim-main.c (execute_i): Updated encoding macros.
2021-02-19 11:44:49 +08:00
Tom Tromey
26f53cd385 Introduce expression::evaluate
This introduces a new method, expression::evaluate, and changes the
top-level expression-evaluation functions to use it.  Stack temporary
handling is moved into this new method, which makes sense because that
handling was only done when "*pos == 0".

This patch avoids some temporary regressions related to stack
temporary in the larger expression rewrite series.  I've pulled it out
separately because it seems like a reasonable change in its own right,
and because it's better to avoid making that series even longer.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-02-18  Tom Tromey  <tom@tromey.com>

	* expression.h (struct expression) <evaluate>: Declare method.
	* eval.c (evaluate_subexp): Simplify.
	(expression::evaluate): New method.
	(evaluate_expression, evaluate_type): Use expression::evaluate.
2021-02-18 11:23:33 -07:00
Kevin Buettner
6a780b6766 Fix completion related libstdc++ assert when using -D_GLIBCXX_DEBUG
This commit fixes a libstdc++ assertion failure encountered when
running gdb.base/completion.exp.  In order to see this problem,
GDB must be built with the follow CFLAGS and CXXFLAGS as part
of the configure line:

  CFLAGS='-D_GLIBCXX_DEBUG' CXXFLAGS='-D_GLIBCXX_DEBUG'

(Also, this problem was encountered using Fedora rawhide.  It might
not be reproducible in Fedora versions prior to Fedora 34.)

Using the gdb.base/completion.exp test program, the problem can be
observed as follows:

[kev@rawhide-1 gdb]$ ./gdb -q testsuite/outputs/gdb.base/completion/completion
Reading symbols from testsuite/outputs/gdb.base/completion/completion...
(gdb) start
Temporary breakpoint 1 at 0x401179: file ../../worktree-master/gdb/testsuite/gdb.base/break.c, line 43.
Starting program: testsuite/outputs/gdb.base/completion/completion

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd718, envp=0x7fffffffd728) at ../../worktree-master/gdb/testsuite/gdb.base/break.c:43
43	    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
(gdb) p <TAB>/usr/include/c++/11/string_view:211: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
Aborted (core dumped)

(Note that I added "<TAB>" to make it clear where the tab key was
pressed.)

gdb/ChangeLog:

	* ada-lang.c (ada_fold_name): Check for non-empty string prior
	to accessing it.
	(ada_lookup_name_info): Likewise.
2021-02-17 17:26:55 -07:00
Mike Frysinger
adeab0c5b3 config/debuginfod: do not include pkg.m4 directly
Any code using AC_DEBUGINFOD from this dir is using -I../config when
running aclocal, so an explicit include on pkg.m4 is unnecessary:
aclocal will find the pkg.m4 in this dir just as easily.  This is
seen in the only two dirs that use AC_DEBUGINFOD (binutils & gdb)
as their aclocal.m4 already has m4_include on config m4 files.

The include as written only works if aclocal is run on a dir that is
at the same level of config/.  Any other depth will fail.
./
|-- config/
|-- binutils/    # works
|-- gdb/         # works
`-- sim/         # works
    `-- <port>/  # fails

It fails even if AC_DEBUGINFOD itself isn't used:
sim/bfin/ $ aclocal -I../../config
aclocal-1.15: error: ../../config/debuginfod.m4:8: file '../config/pkg.m4' does not exist
2021-02-13 00:15:11 -05:00
Tom de Vries
089436f787 [gdb/threads] Fix lin_thread_get_thread_signals for glibc 2.28
When running test-case gdb.threads/create-fail.exp on openSUSE Factory
(with glibc version 2.32) I run into:
...
(gdb) continue
Continuing.
[New Thread 0x7ffff7c83700 (LWP 626354)]
[New Thread 0x7ffff7482700 (LWP 626355)]
[Thread 0x7ffff7c83700 (LWP 626354) exited]
[New Thread 0x7ffff6c81700 (LWP 626356)]
[Thread 0x7ffff7482700 (LWP 626355) exited]
[New Thread 0x7ffff6480700 (LWP 626357)]
[Thread 0x7ffff6c81700 (LWP 626356) exited]
[New Thread 0x7ffff5c7f700 (LWP 626358)]
[Thread 0x7ffff6480700 (LWP 626357) exited]
pthread_create: 22: Invalid argument

Thread 6 "create-fail" received signal SIG32, Real-time event 32.
[Switching to Thread 0x7ffff5c7f700 (LWP 626358)]
0x00007ffff7d87695 in clone () from /lib64/libc.so.6
(gdb) FAIL: gdb.threads/create-fail.exp: iteration 1: run till end
...
The problem is that glibc-internal signal SIGCANCEL is not recognized by gdb.

There's code in check_thread_signals that is supposed to take care of that,
but it's not working because this code in lin_thread_get_thread_signals has
stopped working:
...
  /* NPTL reserves the first two RT signals, but does not provide any
     way for the debugger to query the signal numbers - fortunately
     they don't change.  */
  sigaddset (set, __SIGRTMIN);
  sigaddset (set, __SIGRTMIN + 1);
...

Since glibc commit d2dc5467c6 "Filter out NPTL internal signals (BZ #22391)"
(first released as part of glibc 2.28), a sigaddset with a glibc-internal
signal has no other effect than setting errno to EINVALID.

Fix this by eliminating the usage of sigset_t in check_thread_signals and
lin_thread_get_thread_signals.

The same problem was observed on Ubuntu 20.04.

Tested on x86_64-linux, openSUSE Factory.
Tested on aarch64-linux, Ubuntu 20.04 and Ubuntu 18.04.

gdb/ChangeLog:

2021-02-12  Tom de Vries  <tdevries@suse.de>

	PR threads/26228
	* linux-nat.c (lin_thread_get_thread_signals): Remove.
	(lin_thread_signals): New static var.
	(lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
	New function.
	* linux-nat.h (lin_thread_get_thread_signals): Remove.
	(lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
	Declare.
	* linux-thread-db.c (check_thread_signals): Use
	lin_thread_get_thread_signal_num and lin_thread_get_thread_signal.
2021-02-12 20:12:37 +01:00