Commit Graph

98177 Commits

Author SHA1 Message Date
Tom de Vries da73816739 [gdb/testsuite] Fix unterminated string in gdb.objc/basicclass.exp
The test-case gdb.objc/basicclass.exp contains an unterminated string,
introduced in refactoring commit fa43b1d7ca "after gdb_run_cmd, gdb_expect ->
gdb_test_multiple/gdb_test".

Fix the unterminated string.

gdb/testsuite/ChangeLog:

2019-07-14  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24760
	* gdb.objc/basicclass.exp: Fix unterminated string.
2019-07-14 13:23:04 +02:00
Joel Brobecker 48b550c28a adjust src-release following the renaming of gdb/common/ to gdb/gdbsupport/
A recent change renamed the common/ directory into gdbsupport/ in gdb.
This causes problems in the getver function in the src-release script
which doesn't find the create-version.sh script anymore. As a result,
it falls back on using the version.in file verbatim, meaning that
the "DATE" placeholder doesn't get replaced with the snapshot date,
and the "-git" suffix doesn't get stripped. More precisely, we get
snapshots called "gdb-8.3.50-DATE-git.tar" instead of (e.g.)
"gdb-8.3-20190712.tar".

This commit fixes the issue by adding support for this situation.
I left the support for $tool/common/create-version.sh, because
the sim still uses that directory structure.

ChangeLog:

        * src-release (getver): If $tool/gdbsupport/create-version.sh
        exists, use that to determine the version number.
2019-07-13 18:00:32 -07:00
GDB Administrator a48654b6d4 Automatic date update in version.in 2019-07-14 00:00:54 +00:00
Alan Modra f26a32876b Dynamic TLS section symbols
It is possible to create shared libraries on PowerPC using
-ftls-model=inital-exec or -ftls-model=local-exec.  The first is half
reasonable, getting you a shared library that can't be dlopen'd but
otherwise is reasonable.  The second is quite bad.  Not only do you
lose being able to dlopen, the library also has dynamic text
relocations.  Worse, the TPREL16_LO, TPREL16_HA and other TPREL16
dynamic relocs emitted were wrong, resulting in wrong values being
applied by ld.so.

Using the first TLS section symbol in dynamic relocations for local
TLS symbols doesn't work.  It's wrong because TLS symbols used by TLS
relocs have values relative to the TLS segment, whereas the TLS
section symbols are addresses.  This patch instead uses a symbol index
of zero which is used elsewhere by PowerPC on dynamic TLS relocs.
It's not strictly ABI compliant to use a non-TLS symbol with TLS
relocs but symbol index zero can be interpreted as "no symbol".  Not
using the first TLS section symbol means it doesn't need to be dynamic.

The patch also fixes a further problem with PowerPC32 dynamic TPREL16*
relocs, which shouldn't have the symbol value in the addend as we do
for non-TLS symbols.

bfd/
	* elflink.c (_bfd_elf_omit_section_dynsym_default): Don't keep
	tls_sec.
	(_bfd_elf_init_1_index_section): Prefer not using TLS sections.
	(_bfd_elf_init_2_index_sections): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): When emitting dynamic
	relocations for local TLS symbols, use STN_UNDEF as the relocation
	symbol.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise, and don't
	leave TLS symbol value in the addend.
ld/
	* testsuite/ld-powerpc/tlsso.r: Update.
	* testsuite/ld-powerpc/tlsso32.g: Update.
	* testsuite/ld-powerpc/tlsso32.r: Update.
	* testsuite/ld-powerpc/tlstocso.r: Update.
	* testsuite/ld-cris/tls-dso-dtpoffd2.d: Update.
	* testsuite/ld-cris/tls-dso-dtpoffd4.d: Update.
	* testsuite/ld-cris/tls-dso-tpoffgotcomm1.d: Update.
	* testsuite/ld-cris/tls-gd-1.d: Update.
	* testsuite/ld-cris/tls-gd-1h.d: Update.
	* testsuite/ld-cris/tls-gd-2.d: Update.
	* testsuite/ld-cris/tls-gd-2h.d: Update.
	* testsuite/ld-cris/tls-ie-10.d: Update.
	* testsuite/ld-cris/tls-ie-11.d: Update.
	* testsuite/ld-cris/tls-ie-8.d: Update.
	* testsuite/ld-cris/tls-ie-9.d: Update.
	* testsuite/ld-cris/tls-js1.d: Update.
	* testsuite/ld-cris/tls-ld-4.d: Update.
	* testsuite/ld-cris/tls-ld-5.d: Update.
	* testsuite/ld-cris/tls-ld-6.d: Update.
	* testsuite/ld-cris/tls-ld-7.d: Update.
	* testsuite/ld-cris/tls-ldgd-14.d: Update.
	* testsuite/ld-cris/tls-ldgd-15.d: Update.
	* testsuite/ld-cris/tls-ldgdx-14.d: Update.
	* testsuite/ld-cris/tls-ldgdx-15.d: Update.
	* testsuite/ld-cris/tls-local-54.d: Update.
	* testsuite/ld-cris/tls-local-60.d: Update.
	* testsuite/ld-cris/tls-local-61.d: Update.
	* testsuite/ld-cris/tls-local-63.d: Update.
	* testsuite/ld-cris/tls-local-64.d: Update.
	* testsuite/ld-cris/tls-ok-30.d: Update.
	* testsuite/ld-cris/tls-ok-32.d: Update.
	* testsuite/ld-cris/tls-ok-34.d: Update.
	* testsuite/ld-mips-elf/tls-multi-got-1.got: Update.
	* testsuite/ld-mips-elf/tls-multi-got-1.r: Update.
	* testsuite/ld-mips-elf/tlsdyn-pie-o32.d: Update.
	* testsuite/ld-mips-elf/tlsdyn-pie-o32.got: Update.
	* testsuite/ld-mips-elf/tlslib-o32-hidden.got: Update.
	* testsuite/ld-mips-elf/tlslib-o32-ver.got: Update.
	* testsuite/ld-mips-elf/tlslib-o32.got: Update.
	* testsuite/ld-s390/tlspic.rd: Update.
	* testsuite/ld-s390/tlspic_64.rd: Update.
	* testsuite/ld-sparc/tlssunnopic32.rd: Update.
	* testsuite/ld-sparc/tlssunnopic64.rd: Update.
	* testsuite/ld-sparc/tlssunpic32.rd: Update.
	* testsuite/ld-sparc/tlssunpic64.rd: Update.
2019-07-13 09:57:50 +09:30
Alan Modra 7b2438015c PR24786, wrong LMA if first section in overlay is empty
This stops the first overlay section being ignored when empty,
losing its LMA assignment

	PR 24786
	* ldlang.h (enum section_type): Add first_overlay_section.
	* ldlang.c (lang_add_section): Adjust switch statement.
	(map_input_to_output_sections): Likewise.
	(lang_size_sections_1): Always set last_os for first overlay section.
	(lang_leave_overlay): Set sectype to first_overlay_section.
2019-07-13 09:57:50 +09:30
Alan Modra 0c951c25c6 [GOLD] PowerPC R_PPC64_PCREL_OPT support
* powerpc.cc (xlate_pcrel_opt): New function.
	(Target_powerpc::Relocate::relocate): Optimise PCREL34 and
	GOT_PCREL34 sequences marked with PCREL_OPT.
2019-07-13 09:57:50 +09:30
Alan Modra c9b8abb7af [GOLD] PowerPC got reloc optimisation
Note that gold won't remove unused GOT entries, in contrast to ld.bfd
which will.

	* powerpc.cc (Powerpc_relobj::make_got_relative): New function.
	(relative_value_is_known): New functions.
	(Target_powerpc::Relocate::relocate): Edit code using
	GOT16_HA, GOT16_LO_DS, and GOT_PCREL34 relocs.
2019-07-13 09:57:50 +09:30
Alan Modra e4dff7651b [GOLD] PowerPC relocations for prefix insns
Also use pc-relative instructions for notoc stubs.

elfcpp/
	* powerpc.h (R_PPC64_PCREL_OPT, R_PPC64_D34, R_PPC64_D34_LO),
	(R_PPC64_D34_HI30, R_PPC64_D34_HA30, R_PPC64_PCREL34),
	(R_PPC64_GOT_PCREL34, R_PPC64_PLT_PCREL34, R_PPC64_PLT_PCREL34_NOTOC),
	(R_PPC64_ADDR16_HIGHER34, R_PPC64_ADDR16_HIGHERA34),
	(R_PPC64_ADDR16_HIGHEST34, R_PPC64_ADDR16_HIGHESTA34),
	(R_PPC64_REL16_HIGHER34, R_PPC64_REL16_HIGHERA34),
	(R_PPC64_REL16_HIGHEST34, R_PPC64_REL16_HIGHESTA34),
	(R_PPC64_D28, R_PPC64_PCREL28): Define.
gold/
	* powerpc.cc (Target_powerpc): Add powerxx_stubs_ and accessor
	functions.
	(Target_powerpc::maybe_skip_tls_get_addr_call): Handle PLT_PCREL34
	and PLT_PCREL34_NOTOC relocs.
	(Powerpc_relocate_functions): Add addr34, addr34_hi, addr34_ha,
	addr28, addr16_higher34, addr16_highera34, addr16_highest34,
	addr16_highest34a functions.
	(li_11_0, ori_11_11_0, sldi_11_11_34): Define.
	(paddi_12_pc, pld_12_pc, pnop): Define.
	(d34, ha34): New inline functions.
	(Stub_table::add_plt_call_entry): Handle powerxx_stubs.
	(Stub_table::add_eh_frame): Likewise.
	(build_powerxx_offset): New function.
	(Stub_table::plt_call_size): Handle powerxx_stubs.
	(Stub_table::branch_stub_size): Likewise.
	(Stub_table::do_write): Likewise.
	(Target_powerpc::Scan::get_reference_flags): Handle new relocs.
	(Target_powerpc::Scan::reloc_needs_plt_for_ifunc: Likewise.
	(Target_powerpc::Scan::local, global, relocate): Likewise.
2019-07-13 09:57:50 +09:30
Alan Modra 220f99066d [GOLD] PowerPC notoc eh_frame
When generating notoc call and branch stubs without the benefit of
pc-relative insns, the stubs need to use LR to access the run time PC.
All LR changes must be described in .eh_frame if we're to support
unwinding through asynchronous exceptions.  That's what this patch
does.

The patch has gone through way too many iterations.  At first I
attempted to add multiple FDEs, one for each stub.  That ran into
difficulties with do_plt_fde_location which is only capable of setting
the address of a single FDE per Output_data section, and with removing
any FDEs added on a previous do_relax pass.  Removing FDEs (git commit
be897fb774) went overboard in matching the FDE contents.  That means
either stashing the contents created for add_eh_frame_for_plt to use
when calling remove_eh_frame_for_plt, or recreating contents on the
fly (*) just to remove FDEs.  In fact, FDE content matching is quite
unnecesary.  FDEs added by a previous do_relax pass are those with
u_.from_linker.post_map set.  So they can easily be recognised just by
looking at that flag.  This patch keeps that part of the multiple FDE
changes.

In the end I went for just one FDE per stub group to describe the call
stubs.  That's reasonably efficient for the common case of only
needing to describe the __tls_get_addr_opt call stub.  We don't expect
to be making many calls using notoc stubs without pc-relative insns.

*) Which has it's own set of problems.  The contents must be recreated
using the old stub layout, but .eh_frame size can affect stub
requirements so you need to temporarily keep the old .eh_frame size
when creating new stubs, then reset .eh_frame size before adding new
FDEs.

	* ehframe.cc (Fde::operator==): Delete.
	(Cie::remove_fde): Delete.
	(Eh_frame::remove_ehframe_for_plt): Delete fde_data and fde_length
	parameters.  Remove all post-map plt FDEs.
	* ehframe.h (Fde:post_map): Make const, add variant to compare plt.
	(Fde::operator==): Delete.
	(Cie::remove_fde): Implement here.
	(Cie::last_fde): New accessor.
	(Eh_frame::remove_ehframe_for_plt): Update prototype.
	* layout.cc (Layout::remove_eh_frame_for_plt): Delete fde_data and
	fde_length parameters.
	* layout.h (Layout::remove_eh_frame_for_plt): Update prototype.
	* powerpc.cc (Stub_table::tls_get_addr_opt_bctrl_): Delete.
	(Stub_table::plt_fde_len_, plt_fde_, init_plt_fde): Delete.
	(Stub_table::add_plt_call_entry): Don't set tls_get_addr_opt_bctrl_.
	(eh_advance): New function.
	(stub_sort): New function.
	(Stub_table::add_eh_frame): Emit eh_frame for notoc plt calls and
	branches as well as __tls_get_addr_opt plt call stub.
	(Stub_table::remove_eh_frame): Update to suit.
2019-07-13 09:57:50 +09:30
Alan Modra 32f5984419 [GOLD] PowerPC64 ELFv2 notoc support
Calls from notoc functions via the PLT need different stubs.  Even
calls to local functions requiring a valid toc pointer must go via a
stub.  This patch provides the support in gold.

elfcpp/
	* powerpc.h (R_PPC64_PLTSEQ_NOTOC, R_PPC64_PLTCALL_NOTOC): Define.
gold/
	* powerpc.cc (Target_powerpc::maybe_skip_tls_get_addr_call): Handle
	notoc calls.
	(is_branch_reloc): Template on size.  Return true for REL24_NOTOC.
	Update all callers.
	(max_branch_delta): Likewise.
	(Target_powerpc::Branch_info::make_stub): Add a stub for notoc
	calls to functions needing a valid toc pointer.
	(Target_powerpc::do_relax): Layout stubs again if any need resize.
	(add_12_11_12, addi_12_11, addis_12_11, ldx_12_11_12, ori_12_12_0),
	(oris_12_12_0, sldi_12_12_32): Define.
	(Stub_table::Plt_stub_ent): Add notoc_ and iter_ fields.
	(Stub_table::Branch_stub_key, Branch_stub_key_hash): Rename from
	Branch_stub_ent and Branch_stub_ent hash.  Remove save_res_ from key.
	(Stub_table::Branch_stub_ent): New struct.
	(class Stub_table): Add need_resize and resizing vars.
	(Stub_table::need_resize, branch_size): New accessors.
	(Stub_table::set_resizing): New function.
	(Stub_table::add_plt_call_entry): Handle notoc calls and resizing
	on seeing such or a tocsave stubs after a normal stub using the
	same sym.
	(Stub_table::add_long_branch_entry): Similarly.
	(Stub_table::find_long_branch_entry): Return a Branch_stub_ent*.
	(Stub_table::define_stub_syms): Adjust
	(Stub_table::build_tls_opt_head, build_tls_opt_tail): New functions.
	(build_notoc_offset): New function.
	(Stub_table::plt_call_size): Move out of line.  Handle notoc calls.
	(Stub_table::branch_stub_size): Similarly.
	(Stub_table::do_write): Separate loop for ELFv2 stubs, handling
	notoc calls.  Simplify ELFv1 loop.  Output notoc branch stubs.
	Use build_tls_opt_head and build_tls_opt_tail.
	(Target_powerpc::Scan::get_reference_flags): Handle REL24_NOTOC.
	(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Likewise,
	and PLTSEQ_NOTOC and PLTCALL_NOTOC.
	(Target_powerpc::Scan::local, global, relocate): Likewise.
2019-07-13 09:57:50 +09:30
GDB Administrator 154a0a90dd Automatic date update in version.in 2019-07-13 00:00:14 +00:00
Andrew Burgess 0d4e84ed37 gdb: Better support for dynamic properties with negative values
When the type of a property is smaller than the CORE_ADDR in which the
property value has been placed, and if the property is signed, then
sign extend the property value from its actual type up to the size of
CORE_ADDR.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Sign extend property
	value if its desired type is smaller than a CORE_ADDR and signed.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-ptype.exp: Print array with negative bounds.
	* gdb.fortran/vla-sizeof.exp: Print the size of an array with
	negative bounds.
	* gdb.fortran/vla-value.exp: Print elements of an array with
	negative bounds.
	* gdb.fortran/vla.f90: Setup an array with negative bounds for
	testing.
2019-07-12 12:09:55 +01:00
Andrew Burgess 9a49df9d4b gdb: Carry default property type around with dynamic properties
This commit is preparation for the next one, with the aim of better
supporting signed dynamic properties on targets where the address size
specified in the DWARF headers is smaller than a CORE_ADDR, for
example debugging an i386 application on x86-64.

Consider this small Fortran program 'bounds.f90':

    program test
      integer, allocatable :: array (:)
      allocate (array (-5:5))
      array(3) = 1
    end program test

Compiled with 'gfortran -m32 -g3 -O0 -o bounds bounds.f90'.  The DWARF
for 'array' looks like this:

   <2><97>: Abbrev Number: 10 (DW_TAG_variable)
      <98>   DW_AT_name        : (indirect string, offset: 0x0): array
      <9c>   DW_AT_decl_file   : 1
      <9d>   DW_AT_decl_line   : 2
      <9e>   DW_AT_type        : <0xaf>
      <a2>   DW_AT_location    : 2 byte block: 91 58              (DW_OP_fbreg: -40)
   <2><a5>: Abbrev Number: 11 (DW_TAG_lexical_block)
      <a6>   DW_AT_low_pc      : 0x80485c3
      <aa>   DW_AT_high_pc     : 0x8b
   <2><ae>: Abbrev Number: 0
   <1><af>: Abbrev Number: 12 (DW_TAG_array_type)
      <b0>   DW_AT_data_location: 2 byte block: 97 6              (DW_OP_push_object_address; DW_OP_deref)
      <b3>   DW_AT_allocated   : 4 byte block: 97 6 30 2e         (DW_OP_push_object_address; DW_OP_deref; DW_OP_lit0; DW_OP_ne)
      <b8>   DW_AT_type        : <0x2a>
   <2><bc>: Abbrev Number: 13 (DW_TAG_subrange_type)
      <bd>   DW_AT_lower_bound : 4 byte block: 97 23 10 6         (DW_OP_push_object_address; DW_OP_plus_uconst: 16; DW_OP_deref)
      <c2>   DW_AT_upper_bound : 4 byte block: 97 23 14 6         (DW_OP_push_object_address; DW_OP_plus_uconst: 20; DW_OP_deref)
      <c7>   DW_AT_byte_stride : 6 byte block: 97 23 c 6 34 1e    (DW_OP_push_object_address; DW_OP_plus_uconst: 12; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
   <2><ce>: Abbrev Number: 0

If we look at the DW_AT_lower_bound attribute, which will become a
dynamic property that GDB evaluates when needed by calling
dwarf2_evaluate_property.

The process of evaluating a dynamic property requires GDB to execute
each DW_OP_* operation, the results of these operations is held on a
stack of 'struct value *'s.

When the entire expression is evaluated the result is on top of the
stack.

If we look at DW_AT_lower_bound then the last operation is
DW_OP_deref, this loads a signed address the size of which matches the
DWARF address size, and so in our i386 on x86-64 situation, the top of
the stack will be a signed 4-byte value.

The problem is how these values are fetched from the stack.  Currently
they are always fetched by a call to dwarf_expr_context::fetch_address,
which converts the value to an unsigned value with a length matching
the values current length, before converting to a CORE_ADDR.  This
means we loose the signed nature of the property.

I wonder if the best solution for dealing with signed properties will
be to move away from an over reliance on fetch_address, and instead
come up with a new solution that considers the current type of the
value on the stack, and the type that the value needs to become;
basically a solution built around casting rather than assuming we
always want an address.

However, before we can start to even think about moving away from
fetch_address, there is a more urgent issue to fix, which is we don't
currently know what type each property should be.  We just hold the
value of the property in a CORE_ADDR as returned by fetch_address, and
rely on higher level code (outside of the DWARF expression evaluation
code) to fix things up for us.  This is what this patch aims to
address.

When creating a dynamic property (see attr_to_dynamic_prop in
dwarf2read.c) we can sometimes figure out the type of a property; if
the property is a reference to another DIE then it will have a
DW_AT_type attribute.

However, the DW_AT_lower_bound case above isn't a reference to another
DIE, it's just a DWARF expression.  We don't have any indication for
what type the property should have.

Luckily, the DWARF spec helps us out, for the lower and upper bounds
5.13 of the DWARFv5 spec tells us that without any other type
information the bounds are signed integers the same size as a DWARF
address.

It is my belief that we can find a suitable default type for every
dynamic property, either specified explicitly in the DWARF spec, or we
can infer an obvious choice if the spec doesn't help us.

This commit extends the creation of all dynamic properties to include
suggesting a suitable default type, all dynamic properties now always
carry their type around with them.

In later commits we can use this property type to ensure that the
value we extract from the DWARF stack is handled in a suitable manor
to correctly maintain its sign extension.

There should be no user visible changes from this commit.  The actual
fix to correctly support negative array bounds will come later.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Update to take account
	of changes to field names, and use new is_reference field to
	decide if a property is a reference or not.
	* dwarf2loc.h (struct dwarf2_locexpr_baton): Add 'is_reference'
	field.
	(struct dwarf2_property_baton): Update header comment, rename
	'referenced_type' to 'property_type' and update comments.
	* dwarf2read.c (attr_to_dynamic_prop): Add extra parameter to hold
	default property type, store in property baton, update to take
	accound of renamed field.
	(read_func_scope): Update call to attr_to_dynamic_prop.
	(read_array_type): Likewise.
	(dwarf2_per_cu_addr_sized_int_type): New function.
	(read_subrange_index_type): Move type finding code to
	dwarf2_per_cu_addr_sized_int_type.
	(read_subrange_type): Update calls to attr_to_dynamic_prop.
	(dwarf2_per_cu_addr_type): New function.
	(set_die_type): Update calls to attr_to_dynamic_prop.
2019-07-12 12:09:54 +01:00
Andrew Burgess b86352cfc1 gdb/dwarf: Ensure the target type of ranges is not void
If a DW_TAG_subrange_type DWARF entry has no DW_AT_type then a default
type based on the size of an address on the current target is assumed.
We store this type as the target type for GDB's range types.

Currently GDB can create ranges for which the target type is VOID,
this is incorrect but seems to cause no problems. I believe the reason
this doesn't cause any issues is because the languages (for example
Ada) that actually make use of a ranges target type also have
compilers that generate DWARF that includes a DW_AT_type attribute.

However, gfortran does not include a DW_AT_type, its DWARF instead
relies on the default target type.  This isn't currently a problem for
GDB as gfortran doesn't make use of the target type when printing
subranges, but it shouldn't hurt to fix this issue now.

I've added an assert into create_range_type that will catch this issue
if it comes up again.

This was tested on an x86-64/GNU-Linux machine with both the Ada and
gfortran compilers available with both '--target_board=unix' and
'--target_board=unix/-m32'.  There are no user visible changes after
this commit.

gdb/ChangeLog:

	* dwarf2read.c (read_subrange_index_type): New function.
	(read_subrange_type): Move code into new function and call it.
	* gdbtypes.c (create_range_type): Add some asserts.
2019-07-12 12:09:53 +01:00
Andrew Burgess 603490bf53 gdb: Convert dwarf2_evaluate_property to return bool
Convert dwarf2_evaluate_property to return a bool, there should be no
user visible change after this commit.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Change return type, and
	update return statements.
	* dwarf2loc.h (dwarf2_evaluate_property): Update return type on
	declaration, and update comment to match.
	* gdbtypes.c (resolve_dynamic_array): Update call to
	dwarf2_evaluate_property to match new return type.
2019-07-12 12:09:52 +01:00
Andrew Burgess 592f9d271c gdb: Update type of lower bound in value_subscripted_rvalue
The dynamic lower (and upper) bounds of ranges are stored as type
LONGEST (see union dynamic_prop_data in gdbtypes.h).  In most places
that range bounds are handled they are held in a LONGEST, however in
value_subscripted_rvalue the bound is placed into an int.

This commit changes value_subscripted_rvalue to use LONGEST, there
should be no user visible changes after this commit.

gdb/ChangeLog:

	* valarith.c (value_subscripted_rvalue): Change lowerbound
	parameter type from int to LONGEST.
	* value.h (value_subscripted_rvalue): Likewise in declaration.
2019-07-12 12:09:52 +01:00
Tom de Vries 830b67068c [readline] Fix heap-buffer-overflow in update_line
When:
- building trunk gdb with '-fsanitize=address -lasan',
- running gdb tests with "export ASAN_OPTIONS=detect_leaks=0",
I run into a heap-buffer-overflow failure for
gdb.base/utf8-identifiers.exp.

In more detail, the libasan error report looks like this:
...
=================================================================
==22340==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x619000054a80 at pc 0x7fcd0306b4c9 bp 0x7fffb1a8d880 sp 0x7fffb1a8d030
READ of size 32766 at 0x619000054a80 thread T0
    #0 0x7fcd0306b4c8  (/usr/lib64/libasan.so.4+0xae4c8)
    #1 0x15f12a1 in update_line
/data/gdb_versions/devel/src/readline/display.c:1377
    #2 0x15f03cb in rl_redisplay
/data/gdb_versions/devel/src/readline/display.c:1204
    #3 0x15bf932 in readline_internal_setup
/data/gdb_versions/devel/src/readline/readline.c:394
    #4 0x15fe723 in _rl_callback_newline
/data/gdb_versions/devel/src/readline/callback.c:89
    #5 0x15fe7ef in rl_callback_handler_install
/data/gdb_versions/devel/src/readline/callback.c:102
    #6 0xd7bce6 in gdb_rl_callback_handler_install(char const*)
/data/gdb_versions/devel/src/gdb/event-top.c:319
    #7 0xd7c0c6 in display_gdb_prompt(char const*)
/data/gdb_versions/devel/src/gdb/event-top.c:409
    #8 0xd7d6c1 in command_line_handler(std::unique_ptr<char,
gdb::xfree_deleter<char> >&&)
/data/gdb_versions/devel/src/gdb/event-top.c:776
    #9 0xd7b92a in gdb_rl_callback_handler
/data/gdb_versions/devel/src/gdb/event-top.c:217
    #10 0x15ff479 in rl_callback_read_char
/data/gdb_versions/devel/src/readline/callback.c:220
    #11 0xd7b4d5 in gdb_rl_callback_read_char_wrapper_noexcept
/data/gdb_versions/devel/src/gdb/event-top.c:175
    #12 0xd7b6b5 in gdb_rl_callback_read_char_wrapper
/data/gdb_versions/devel/src/gdb/event-top.c:192
    #13 0xd7c8aa in stdin_event_handler(int, void*)
/data/gdb_versions/devel/src/gdb/event-top.c:514
    #14 0xd76ca7 in handle_file_event
/data/gdb_versions/devel/src/gdb/event-loop.c:731
    #15 0xd7751f in gdb_wait_for_event
/data/gdb_versions/devel/src/gdb/event-loop.c:857
    #16 0xd7547e in gdb_do_one_event()
/data/gdb_versions/devel/src/gdb/event-loop.c:321
    #17 0xd75526 in start_event_loop()
/data/gdb_versions/devel/src/gdb/event-loop.c:370
    #18 0x101b04c in captured_command_loop
/data/gdb_versions/devel/src/gdb/main.c:331
    #19 0x101de73 in captured_main
/data/gdb_versions/devel/src/gdb/main.c:1173
    #20 0x101df03 in gdb_main(captured_main_args*)
/data/gdb_versions/devel/src/gdb/main.c:1188
    #21 0x872dba in main /data/gdb_versions/devel/src/gdb/gdb.c:32
    #22 0x7fcd00f2ff49 in __libc_start_main (/lib64/libc.so.6+0x20f49)
    #23 0x872bc9 in _start (/data/gdb_versions/devel/build/gdb/gdb+0x872bc9)

0x619000054a80 is located 0 bytes to the right of 1024-byte region
[0x619000054680,0x619000054a80)
allocated by thread T0 here:
    #0 0x7fcd03099510 in malloc (/usr/lib64/libasan.so.4+0xdc510)
    #1 0xae0078 in xmalloc
/data/gdb_versions/devel/src/gdb/common/common-utils.c:44
    #2 0x15eaccb in init_line_structures
/data/gdb_versions/devel/src/readline/display.c:458
    #3 0x15eb4d8 in rl_redisplay
/data/gdb_versions/devel/src/readline/display.c:526
    #4 0x15bf932 in readline_internal_setup
/data/gdb_versions/devel/src/readline/readline.c:394
    #5 0x15fe723 in _rl_callback_newline
/data/gdb_versions/devel/src/readline/callback.c:89
    #6 0x15fe7ef in rl_callback_handler_install
/data/gdb_versions/devel/src/readline/callback.c:102
    #7 0xd7bce6 in gdb_rl_callback_handler_install(char const*)
/data/gdb_versions/devel/src/gdb/event-top.c:319
    #8 0xd7c0c6 in display_gdb_prompt(char const*)
/data/gdb_versions/devel/src/gdb/event-top.c:409
    #9 0xaa041b in cli_interp_base::pre_command_loop()
/data/gdb_versions/devel/src/gdb/cli/cli-interp.c:286
    #10 0xf5342a in interp_pre_command_loop(interp*)
/data/gdb_versions/devel/src/gdb/interps.c:320
    #11 0x101b047 in captured_command_loop
/data/gdb_versions/devel/src/gdb/main.c:328
    #12 0x101de73 in captured_main
/data/gdb_versions/devel/src/gdb/main.c:1173
    #13 0x101df03 in gdb_main(captured_main_args*)
/data/gdb_versions/devel/src/gdb/main.c:1188
    #14 0x872dba in main /data/gdb_versions/devel/src/gdb/gdb.c:32
    #15 0x7fcd00f2ff49 in __libc_start_main (/lib64/libc.so.6+0x20f49)

SUMMARY: AddressSanitizer: heap-buffer-overflow
(/usr/lib64/libasan.so.4+0xae4c8)
Shadow bytes around the buggy address:
  0x0c3280002900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c3280002950:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3280002960: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3280002970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3280002990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c32800029a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==22340==ABORTING
...

I've written an assert in rl_redisplay that formulates the error condition:
...
@@ -1387,6 +1389,10 @@ rl_redisplay (void)
          cpos_adjusted = 0;
+         assert (last_lmargin + (_rl_screenwidth + visible_wrap_offset)
+                 <= line_size);
+         assert (lmargin + (_rl_screenwidth + (lmargin ? 0 : wrap_offset))
+                 <= line_size);
          update_line (&visible_line[last_lmargin],
                       &invisible_line[lmargin],
                       0,
                       _rl_screenwidth + visible_wrap_offset,
                       _rl_screenwidth + (lmargin ? 0 : wrap_offset),
                       0);
...
which triggers without needing the address sanitizer (or even an executable),
like this:
...
$ TERM=dumb gdb -q -ex "set width 0"
gdb: src/display.c:1393: rl_redisplay: Assertion
`last_lmargin + (_rl_screenwidth + visible_wrap_offset) <= line_size'
failed.
Aborted (core dumped)
...

The basic problem is this: visible_line and invisible_line have length
line_size, but the update_line call assumes that line_size is at least
_rl_screenwidth + 1.  Executing "set width 0" sets _rl_screenwidth to 32766 but
doesn't affect line_size, which is initialized to 1024.

Fix this by ensuring in init_line_structures and rl_redisplay that line_size
is at least _rl_screenwidth + 1.

Tested on x86_64-linux.

Reviewed by readline maintainer (
https://sourceware.org/ml/gdb-patches/2019-05/msg00566.html ).

readline/ChangeLog.gdb:

2019-07-12  Tom de Vries  <tdevries@suse.de>
	    Chet Ramey  <chet.ramey@case.edu>

	PR cli/24514
	* readline/display.c (init_line_structures, rl_redisplay): Ensure
	line_size is at	least _rl_screenwidth + 1.
2019-07-12 09:53:02 +02:00
GDB Administrator a89fdbdb20 Automatic date update in version.in 2019-07-12 00:00:19 +00:00
Andrew Burgess 60cfcb20ce gdb: Add command completers for some info commands
Add command completion for info variables, functions, args, and
locals.  This completer only completes the command line options as
these commands all take a regexp which GDB can't really offer
completions for.

gdb/ChangeLog:

	* cli/cli-utils.c (info_print_command_completer): New function.
	* cli/cli-utils.h: Add 'completer.h' include, and forward
	declaration for 'struct cmd_list_element'.
	(info_print_command_completer): Declare.
	* stack.c (_initialize_stack): Add completer for 'info locals' and
	'info args'.
	* symtab.c (_initialize_symtab): Add completer for 'info
	variables' and 'info functions'.
	* NEWS: Mention completion for additional info commands.
2019-07-11 20:19:24 +01:00
Andrew Burgess b16507e091 gdb: Make use of gdb::option framework for some info commands
Update the 'info variables', 'info functions', 'info locals', and
'info args' commands to make use of the gdb::options framework.

There should be no user visible changes after this commit as I have
left the help text generation using the existing mechanism, which
already tries to customise the text for each of the commands.

gdb/ChangeLog:

	* cli/cli-utils.c (extract_info_print_args): Delete.
	(extract_arg_maybe_quoted): Delete.
	(info_print_options_defs): New variable.
	(make_info_print_options_def_group): New function.
	(extract_info_print_options): Define new function.
	* cli/cli-utils.h (extract_info_print_args): Delete.
	(struct info_print_options): New structure.
	(extract_info_print_options): Declare new function.
	* stack.c (info_locals_command): Update to use new
	extract_info_print_options, also add a header comment.
	(info_args_command): Likewise.
	* symtab.c (info_variables_command): Likewise.
	(info_functions_command): Likewise.
2019-07-11 20:18:17 +01:00
Andrew Burgess 021d8588f6 gdb: Allow quoting around string options in the gdb::option framework
Currently string options must be a single string with no whitespace,
this limitation prevents the gdb::option framework being used in some
places.

After this commit, string options can be quoted in single or double
quotes, and quote characters can be escaped with a backslash if needed
to either place them within quotes, or to avoid starting a quoted
argument.

This test adds a new function extract_string_maybe_quoted which is
basically a copy of extract_arg_maybe_quoted from cli/cli-utils.c,
however, the cli-utils.c function will be deleted in the next commit.

There are tests to exercise the new quoting mechanism.

gdb/ChangeLog:

	* cli/cli-option.c (parse_option): Use extract_string_maybe_quoted
	to extract string arguments.
	* common/common-utils.c (extract_string_maybe_quoted): New function.
	* common/common-utils.h (extract_string_maybe_quoted): Declare.

gdb/testsuite/ChangeLog:

	* gdb.base/options.exp (expect_string): Dequote strings in
	results.
	(test-string): Test strings with different quoting and reindent.
2019-07-11 20:18:11 +01:00
Tom Tromey b777eb6de2 Remove init_cli_cmds
I noticed that init_cli_cmds only installs a command, and so doesn't
need to be handled specially.  This patch merges it into
_initialize_cli_cmds.

The help text is constructed dynamically, which is sometimes an
indication that special treatment is needed; but in this case it is
just to insert the value of "gdbinit", which is created at
compile-time and not modified; so this doesn't affect the result.

This version also removes the "gdbinit" global.  There's no need for
it, as GDBINIT can be used instead.  Note, though, that the help text
in question must still be dynamically constructed, in order to be
i18n-friendly.

gdb/ChangeLog
2019-07-11  Tom Tromey  <tromey@adacore.com>

	* main.c (get_init_files): Use GDBINIT, not gdbinit.
	* auto-load.c (file_is_auto_load_safe): Use GDBINIT, not gdbinit.
	* top.h (gdbinit): Don't declare.
	* cli/cli-cmds.c (init_cli_cmds): Remove, merging contents
	into...
	(_initialize_cli_cmds): ...here.  Use GDBINIT, not gdbinit.
	* top.c (gdb_init): Don't call init_cli_cmds.
	(gdbinit): Remove.
	* cli/cli-cmds.h (init_cli_cmds): Don't declare.
2019-07-11 10:28:27 -06:00
Tom Tromey 72ee03ff58 Fix use-after-move bug in add_thread_object
commit 05b08ac160 ("Reduce manual reference counting in
py-inferior.c") introduced a use-after-move bug in add_thread_object,
causing a test suite failure.  This patch fixes the bug.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-11  Tom Tromey  <tromey@adacore.com>

	* python/py-inferior.c (add_thread_object): Don't use thread_obj
	after it has been moved.
2019-07-11 09:15:18 -06:00
Simon Marchi 00db953196 Make value_must_coerce_to_target return a bool
... and move comment to header file.

gdb/ChangeLog:

	* valops.c (value_must_coerce_to_target): Change return type to
	bool.
	* value.h (value_must_coerce_to_target): Likewise.
2019-07-10 21:49:32 -04:00
Simon Marchi f2478a7e8b breakpoint: Make is_*point functions return bool
This includes changing the FILTER parameters of two functions
accordingly.  I also tried to normalize the function comments to our
current standards.

gdb/ChangeLog:

	* breakpoint.c (is_hardware_watchpoint): Remove
	forward-declaration.
	(is_masked_watchpoint): Change return type to bool.
	(is_tracepoint): Likewise.
	(is_breakpoint): Likewise.
	(is_hardware_watchpoint): Likewise.
	(is_watchpoint): Likewise.
	(is_no_memory_software_watchpoint): Likewise.
	(is_catchpoint): Likewise.
	(breakpoint_1): Make FILTER parameter's return type bool.
	is_masked_watchpoint): Change return type to bool.
	(save_breakpoints): Make FILTER parameter's return type bool.
	* breakpoint.h (is_breakpoint): Change return type to bool.
	(is_watchpoint): Likewise.
	(is_catchpoint): Likewise.
	(is_tracepoint): Likewise.
2019-07-10 21:20:50 -04:00
GDB Administrator 2ee0a9b7bc Automatic date update in version.in 2019-07-11 00:00:37 +00:00
Tom Tromey 0d12e84cfc Don't include gdbarch.h from defs.h
I touched symtab.h and was surprised to see how many files were
rebuilt.  I looked into it a bit, and found that defs.h includes
gdbarch.h, which in turn includes many things.

gdbarch.h is only needed by a minority ofthe files in gdb, so this
patch removes the include from defs.h and updates the fallout.

I did "wc -l" on the files in build/gdb/.deps; this patch reduces the
line count from 139935 to 137030; so there are definitely future
build-time savings here.

Note that while I configured with --enable-targets=all, it's possible
that some *-nat.c file needs an update.  I could not test all of
these.  The buildbot caught a few problems along these lines.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tom@tromey.com>

	* defs.h: Don't include gdbarch.h.
	* aarch64-ravenscar-thread.c, aarch64-tdep.c, alpha-bsd-tdep.h,
	alpha-linux-tdep.c, alpha-mdebug-tdep.c, arch-utils.h, arm-tdep.h,
	ax-general.c, btrace.c, buildsym-legacy.c, buildsym.h, c-lang.c,
	cli/cli-decode.h, cli/cli-dump.c, cli/cli-script.h,
	cli/cli-style.h, coff-pe-read.h, compile/compile-c-support.c,
	compile/compile-cplus.h, compile/compile-loc2c.c, corefile.c,
	cp-valprint.c, cris-linux-tdep.c, ctf.c, d-lang.c, d-namespace.c,
	dcache.c, dicos-tdep.c, dictionary.c, disasm-selftests.c,
	dummy-frame.c, dummy-frame.h, dwarf2-frame-tailcall.c,
	dwarf2expr.c, expression.h, f-lang.c, frame-base.c,
	frame-unwind.c, frv-linux-tdep.c, gdbarch-selftests.c, gdbtypes.h,
	go-lang.c, hppa-nbsd-tdep.c, hppa-obsd-tdep.c, i386-dicos-tdep.c,
	i386-tdep.h, ia64-vms-tdep.c, interps.h, language.c,
	linux-record.c, location.h, m2-lang.c, m32r-linux-tdep.c,
	mem-break.c, memattr.c, mn10300-linux-tdep.c, nios2-linux-tdep.c,
	objfiles.h, opencl-lang.c, or1k-linux-tdep.c, p-lang.c,
	parser-defs.h, ppc-tdep.h, probe.h, python/py-record-btrace.c,
	record-btrace.c, record.h, regcache-dump.c, regcache.h,
	riscv-fbsd-tdep.c, riscv-linux-tdep.c, rust-exp.y,
	sh-linux-tdep.c, sh-nbsd-tdep.c, source-cache.c,
	sparc-nbsd-tdep.c, sparc-obsd-tdep.c, sparc-ravenscar-thread.c,
	sparc64-fbsd-tdep.c, std-regs.c, target-descriptions.h,
	target-float.c, tic6x-linux-tdep.c, tilegx-linux-tdep.c, top.c,
	tracefile.c, trad-frame.c, type-stack.h, ui-style.c, utils.c,
	utils.h, valarith.c, valprint.c, varobj.c, x86-tdep.c,
	xml-support.h, xtensa-linux-tdep.c, cli/cli-cmds.h: Update.
	* s390-linux-nat.c, procfs.c, inf-ptrace.c: Likewise.
2019-07-10 14:53:53 -06:00
Tom Tromey f06f1252b0 Change Ada catchpoints to be bp_catchpoint
Like Pedro's earlier patches to change catchpoint to be of type
bp_catchpoint, this changes the Ada catchpoints to follow.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.h (is_ada_exception_catchpoint): Declare.
	* breakpoint.c (init_ada_exception_breakpoint): Register as
	bp_catchpoint.
	(print_one_breakpoint_location, print_one_breakpoint): Use
	is_ada_exception_catchpoint.
	* ada-lang.c (class ada_catchpoint_location): Pass
	bp_loc_software_breakpoint to bp_location constructor.
	(is_ada_exception_catchpoint): New function.

gdb/testsuite/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/mi_ex_cond.exp: Update expected results.
	* gdb.ada/mi_catch_ex_hand.exp: Update expected results.
	* gdb.ada/mi_catch_ex.exp: Update expected results.
	* gdb.ada/mi_catch_assert.exp: Update expected results.
	* gdb.ada/catch_ex.exp (catch_exception_info)
	(catch_exception_entry, catch_assert_entry)
	(catch_unhandled_entry): Update.
	* gdb.ada/catch_assert_if.exp: Update expected results.
2019-07-10 14:48:53 -06:00
Tom Tromey 7a5d944b9e Change arm-tdep.c to use type-safe registry
This changes arm-tdep.c to use the type-safe registry, removing a use
of VEC in the process.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* arm-tdep.c (arm_exidx_entry_s): Remove typedef.  Don't define
	VEC.
	(struct arm_exidx_entry): New method operator<.
	(struct arm_exidx_data) <section_maps>: Change type.
	(arm_exidx_data_free): Remove.
	(arm_exidx_data_key): Change type.  Move lower.
	(arm_exidx_new_objfile): Update.
	(arm_compare_exidx_entries): Remove.
	(arm_find_exidx_entry, _initialize_arm_tdep)
2019-07-10 14:34:11 -06:00
Tom Tromey 48c66e1d07 Change solib-spu.c to use type-safe registry
This changes solib-spu.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-spu.c (ocl_program_data_key): Change type.
	(append_ocl_sos, ocl_enable_break, _initialize_spu_solib):
	Update.
2019-07-10 14:34:11 -06:00
Tom Tromey a269fbf12d Change solib-aix.c to use type-safe registry
This changes solib-aix.c to use the type-safe registry, and removes a
use of VEC in the process.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-aix.c (lm_info_aix_p): Remove typedef.  Don't define VEC.
	(struct solib_aix_inferior_data) <library_list>: Change type.
	(solib_aix_inferior_data_handle): Change type.
	(get_solib_aix_inferior_data): Update.
	(solib_aix_free_library_list): Remove.
	(library_list_start_library): Update.
	(solib_aix_parse_libraries, solib_aix_get_library_list): Change
	return type.
	(solib_aix_get_library_list)
	(solib_aix_solib_create_inferior_hook, solib_aix_current_sos)
	(solib_aix_normal_stop_observer, _initialize_solib_aix): Update.
2019-07-10 14:34:09 -06:00
Tom Tromey c294730c54 Change solib-dsbt.c to use type-safe registry
This changes solib-dsbt.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-dsbt.c (struct dsbt_info): Add initializers.
	(solib_dsbt_pspace_data): Change type.
	(dsbt_pspace_data_cleanup): Remove.
	(get_dsbt_info, _initialize_dsbt_solib): Update.
2019-07-10 12:43:38 -06:00
Tom Tromey 9d52077d65 Change spu-tdep.c to use type-safe registry
This changes spu-tdep.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* spu-tdep.c (spu_overlay_data): Change type.
	(spu_get_overlay_table, spu_overlay_new_objfile)
	(_initialize_spu_tdep): Update.
2019-07-10 12:43:38 -06:00
Tom Tromey 22a20dca3a Change dbxread.c to use type-safe registry
This changes dbxread.c to use the type-safe registry.  In a couple of
spots, you'll see that dbx_objfile_data_key.emplace is called but the
result is not used; this is because those functions refer to the key
via the various DBX_* macros.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* gdb-stabs.h (struct dbx_symfile_info): Add initializers and
	destructor.
	(dbx_objfile_data_key): Change type and declare later.
	(DBX_SYMFILE_INFO): Rewrite.
	* dbxread.c (dbx_objfile_data_key): Change type.
	(dbx_symfile_init): Update.
	(~dbx_symfile_info): Rename from dbx_free_symfile_info.  Update.
	(coffstab_build_psymtabs, elfstab_build_psymtabs)
	(stabsect_build_psymtabs, _initialize_dbxread): Update.
2019-07-10 12:43:38 -06:00
Tom Tromey cb60f4208b Change jit.c to use type-safe registry
This changes jit.c to use the type-safe registry.  Only one of the
registry keys in jit.c is converted; the other is trickier and so I've
left it be for now.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* jit.c (jit_program_space_key): Change type.  Move lower.
	(get_jit_program_space_data): Update.
	(jit_program_space_data_cleanup): Remove.
	(jit_breakpoint_deleted, free_objfile_data, _initialize_jit):
	Update.
	(struct jit_program_space_data): Add initializers.
2019-07-10 12:43:35 -06:00
Tom Tromey 51df2ae302 Change solib-darwin.c to use type-safe registry
This changes solib-darwin.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-darwin.c (struct darwin_info): Add initializers.
	(solib_darwin_pspace_data): Change type.
	(darwin_pspace_data_cleanup): Remove.
	(get_darwin_info, _initialize_darwin_solib): Update.
2019-07-10 12:42:16 -06:00
Tom Tromey 18101a3525 Change remote-sim.c to use type-safe registry
This changes remote-sim.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* remote-sim.c (struct sim_inferior_data): Add initializers,
	constructor, and destructor.
	(sim_inferior_data_key): Change type.  Move lower.
	(check_for_duplicate_sim_descriptor): Update.
	(get_sim_inferior_data): Use new.  Update.
	(~sim_inferior_data_cleanup): Rename from
	sim_inferior_data_cleanup.  Simplify.
	(gdbsim_close_inferior, simulator_command)
	(sim_command_completer, _initialize_remote_sim): Update.
	(next_pid, INITIAL_PID): Move earlier.
2019-07-10 12:42:16 -06:00
Tom Tromey 05b08ac160 Reduce manual reference counting in py-inferior.c
This patch changes py-inferior.c to use gdbpy_ref<> when possible,
reducing the amount of manual reference counting.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* python/python-internal.h (create_thread_object): Return
	gdbpy_ref.
	* python/py-infthread.c (create_thread_object): Return gdbpy_ref.
	* python/py-inferior.c (struct threadlist_entry): Add
	constructor.
	<thread_obj>: Now a gdbpy_ref.
	(thread_to_thread_object): Update.
	(add_thread_object): Use new.
	(delete_thread_object): Use delete.
	(infpy_threads): Update.
	(py_free_inferior): Update.  Construct "inf_obj" after acquiring
	GIL.
2019-07-10 12:24:22 -06:00
Tom Tromey 32372d80ca Specialize value_cast error message for Ada
In Ada, the term for a cast is "type conversion".  AdaCore has been
carrying a local patch to specialize the error message in value_cast,
but it seemed fine to me for this to be part of gdb.  This also
removes a dead "return" statement.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* valops.c (value_cast): Specialize error message for Ada.
2019-07-10 12:18:39 -06:00
Hans-Peter Nilsson 43dd762689 arm-dis.c (print_insn_coprocessor): Rename index to index_operand.
Older gcc warns, arguably incorrectly, about name collisions between
global functions and function-local variable names.  Consesus has been
to rename local variables whenever this is spotted, hence committed as
obvious.  Note the pre-existing variable named idx; "index_operand"
seemed logical given the context.

	* arm-dis.c (print_insn_coprocessor): Rename index to
	index_operand.
2019-07-10 18:42:06 +02:00
Simon Marchi 5c458ae8f5 Update breakpoint_1's documentation
I noticed the documentation of breakpoint_1 way way out of date, so this
is an attempt to update it.  I have changed the parameter names to
something that seems clearer to me.

gdb/ChangeLog:

	* breakpoint.c (breakpoint_1): Update doc and parameter names.
2019-07-10 12:12:37 -04:00
Simon Marchi 4c462cb0ef Make some bpstat functions use bool
Change return type to bool and adjust function comments.

gdb/ChangeLog:

	* breakpoint.h (bpstat_explains_signal, bpstat_causes_stop,
	bpstat_should_step): Return bool, adjust comments.
	* breakpoint.c (bpstat_explains_signal, bpstat_causes_stop,
	bpstat_should_step): Likewise.
2019-07-10 12:10:51 -04:00
Alan Hayward 89abbcc26d Arm: Create feature files for Arm target descriptions
Add Arm to the list of feature target description targets and generate the
relevant C files.

Add arm-m-profile-with-fpa.xml as the feature version of the exisiting
arm-with-m-fpa-layout.xml.

Add extra comments to the Makefile for readability.

New files are not yet used.

gdb/ChangeLog:

	* features/Makefile: Use feature target descriptions for Arm.
	* features/arm/arm-core.c: Generate new file.
	* features/arm/arm-fpa.c: Likewise.
	* features/arm/arm-m-profile-with-fpa.xml: Likewise.
	* features/arm/arm-m-profile.c: Likewise.
	* features/arm/arm-vfpv2.c: Likewise.
	* features/arm/arm-vfpv3.c: Likewise.
	* features/arm/xscale-iwmmxt.c: Likewise.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Add Arm.
2019-07-10 14:20:49 +01:00
Richard Bunt b863685d70 Restore original GDB prompt in define.exp
define.exp will fail on a GDB which has set a custom prompt to identify
itself.  This is because the test resets the prompt to a hard coded
"(gdb)" but then verifies the success of this against the value in
$gdb_prompt, which is set to the custom prompt.

The original approach to fix this involved resetting the prompt to
$gdb_prompt rather than a hard coded "(gdb)". However it was noted during
review that $gdb_prompt is a regular expression rather than a string.
This is problematic because in general the prompt would be reset to a
regular expression rather than an instance of a string accepted by said
regular expression.

The fix used in this commit avoids the above issue by capturing the
literal prompt from running "show prompt" and uses this literal to
restore the previous prompt.

Regression tested with GCC 7.3.0 on x86_64, ppc64le, aarch64.

gdb/testsuite/ChangeLog:
2019-07-10  Richard Bunt  <richard.bunt@arm.com>
	Stephen Roberts  <stephen.roberts@arm.com>

	* gdb.base/define.exp: Restore original prompt.
2019-07-10 14:14:16 +01:00
Alan Hayward 166a82be89 Arm: Minor style cleanups
*When reading a target description, do the ptrace check before picking the
 target description.

*In wmmxregset functions, declare the counter inside the for.

*Call arm_linux_init_hwbp_cap from in arm_arch_setup - it doesn't belong in
 arm_read_description.

gdb/ChangeLog:

	* arm-linux-nat.c (arm_linux_nat_target::read_description): Check
	ptrace earlier,

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (arm_fill_wmmxregset, arm_store_wmmxregset):
	Move counter inside for.
	(arm_read_description): Check ptrace earlier.
	(arm_arch_setup): Call arm_linux_init_hwbp_cap here.
2019-07-10 11:59:34 +01:00
Alan Hayward 9fb4c7e9f0 Regenerate aarch64-pauth.c
aarch64-pauth.c was slightly out of sync with the generated version.
Regenerate it.

gdb/ChangeLog:

	* features/aarch64-pauth.c: Regenerate.
2019-07-10 11:47:13 +01:00
Simon Marchi e2d0f9803e Make bpstat_what::is_longjmp a bool
gdb/ChangeLog:

	* breakpoint.h (struct bpstat_what) <is_longjmp>: Change type to
	bool.
	(bpstat_what): Use false instead of 0.
2019-07-09 21:20:16 -04:00
GDB Administrator eb6ad40f24 Automatic date update in version.in 2019-07-10 00:00:22 +00:00
Pedro Alves a38118e5d1 Make "maint info breakpoints" show "catch catch/throw/rethrow" locations
This commit makes "maint info breakpoints" show the internal locations
of C++ exception catchpoints:

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch

With multiple locations:

 (gdb) maint info breakpoints
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch
 2.1                         y   0x000000000040545f <__cxa_begin_catch+95> inf 1
 2.2                         y   0x00007ffff71dbe0f <__cxxabiv1::__cxa_begin_catch(void*)+95> inf 1
 (gdb)

With a single location:

 (gdb) maint info breakpoints 2
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch inf 1
 2.1                         y   0x00007ffff7bc0b7f <__cxa_begin_catch+95> inf 1

With no locations:

 (gdb) maint info breakpoints 2
 Num     Type           Disp Enb Address            What
 2       catchpoint     keep y                      exception catch inf 1


Other catchpoints still show the same way, here a catch signal:

 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 3       catchpoint     keep y                      signal "<standard signals>"

 (gdb) maint info breakpoints
 Num     Type           Disp Enb Address            What
 3       catchpoint     keep y                      signal "<standard signals>"  inf 1
 (gdb)

Note: I considered making the locations be printed from within
breakpoint_ops::print_one(), but gave up given the handling for the
broken MI v2 output:

 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
     are outside.  */
  if (!use_fixed_output)
    bkpt_tuple_emitter.reset ();

in print_one_breakpoint.

gdb/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (is_exception_catchpoint): New.
	* breakpoint.c (print_one_breakpoint_location): New parameter
	'raw_loc'.  Handle it.  Use
	is_watchpoint/is_catchpoint/is_exception_catchpoint instead of
	looking at the breakpoint's type.
	(print_one_breakpoint): If handling "maint info breakpoints", also
	print locations of exception catchpoints.
	* breakpoint.h (is_exception_catchpoint): Declare.
2019-07-09 20:00:07 +01:00
Pedro Alves cb1e4e32c2 "catch catch/throw/rethrow", breakpoint -> catchpoint
Currently, with:

 (gdb) catch catch
 Catchpoint 1 (catch)
 (gdb) catch throw
 Catchpoint 2 (throw)
 (gdb) catch rethrow
 Catchpoint 3 (rethrow)

You get:

(gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep y   0x0000000000b122af exception catch
 2       breakpoint     keep y   0x0000000000b1288d exception throw
 3       breakpoint     keep y   0x0000000000b12931 exception rethrow

I think it doesn't make much sense usability-wise, to show a
catchpoint as a breakpoint.  The fact that GDB sets a breakpoint at
some magic address in the C++ run time is an implementation detail,
IMO.  And as seen in the previous patch, such a catchpoint can end up
with more than one location/address even, so showing a single address
isn't entirely accurate.

This commit hides the addresses from view, and makes GDB show
"catchpoint" for type as well:

  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  1       catchpoint     keep y                      exception catch
  2       catchpoint     keep y                      exception throw
  3       catchpoint     keep y                      exception rethrow

This comment in the code seems telling:

  /* We need to reset 'type' in order for code in breakpoint.c to do
     the right thing.  */
  cp->type = bp_breakpoint;

It kind of suggests that the reason catchpoints end up shown as
breakpoints was that it was easier to implement them that way, rather
than a desired property.

This commit fixes things up to make it possible to have bp_catch
breakpoints have software/hardware breakpoint locations, thus
eliminating the need for that hack:

 - redo breakpoint_address_is_meaningful in terms of the location's
   type rather than breakpoint type.
 - teach bpstat_what about stepping over the catchpoint locations.
 - install a allocate_location method for "catch catch/throw/rethrow",
   one that forces the location type.

Note that this also reverts the gdb hunk from:

  commit 2a8be20359
  Commit:     Tom Tromey <tom@tromey.com>
  CommitDate: Sat Oct 6 22:17:45 2018 -0600

      Fix Python gdb.Breakpoint.location crash

because now "catch throw" catchpoints hit the

   if (obj->bp->type != bp_breakpoint)
     Py_RETURN_NONE;

check above, and, adjusts the testcase to no longer expect to see the
catchpoint in the gdb.breakpoints() list.

(Note: might make sense to do the same to Ada exception catchpoints.)

gdb/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (print_one_exception_catchpoint): Skip the
	"addr" field.
	(allocate_location_exception_catchpoint): New.
	(handle_gnu_v3_exceptions): Don't reset 'type' to bp_breakpoint.
	(initialize_throw_catchpoint_ops): Install
	allocate_location_exception_catchpoint as allocate_location
	method.
	* breakpoint.c (bpstat_what) <bp_catch>: Set action to
	BPSTAT_WHAT_SINGLE if not stopping and the location's type is not
	bp_loc_other.
	(breakpoint_address_is_meaningful): Delete.
	(bl_address_is_meaningful): New.
	(breakpoint_locations_match): Adjust comment.
	(bp_location_from_bp_type): New, factored out of...
	(bp_location::bp_location(breakpoint *)): ... this.
	(bp_location::bp_location(breakpoint *, bp_loc_type)): New,
	factored out of...
	(bp_location::bp_location(breakpoint *)): ... this.  Reimplement.
	(bp_loc_is_permanent): Use bl_address_is_meaningful instead of
	breakpoint_address_is_meaningful.
	(bp_locations_compare): Adjust comment.
	(update_global_location_list): Use bl_address_is_meaningful
	instead of breakpoint_address_is_meaningful.
	* breakpoint.h (bp_location::bp_location(breakpoint *)): New
	explicit.
	(bp_location::bp_location(breakpoint *, bp_loc_type)): Declare.
	* python/py-breakpoint.c (bppy_get_location): No longer check
	whether location is null.

gdb/doc/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (C++ Exception GDB/MI Catchpoint Commands): Adjust
	examples to show type=catchpoint instead of type=breakpoint and an
	address.

gdb/testsuite/ChangeLog:
2019-07-09  Pedro Alves  <palves@redhat.com>

	* gdb.cp/catch-multi-stdlib.exp: Adjust expected "info
	breakpoints" output.
	* gdb.cp/exception.exp: Adjust expected "info breakpoints" output.
	* gdb.python/py-breakpoint.exp: No longer expect that "catch
	throw" creates breakpoint.
	* gdb.mi/mi-catch-cpp-exceptions.exp (setup_catchpoint): Expect
	'type="catchpoint"'.
2019-07-09 19:34:18 +01:00