Commit Graph

101704 Commits

Author SHA1 Message Date
Simon Marchi 62982abdee gdb: allocate symfile_segment_data with new
- Allocate this structure with new instead of XNEW, use a unique pointer
  to manage its lifetime.
- Change a few functions to return a unique   pointer instead of a
  plain pointer.
- Change free_symfile_segment_data to be symfile_segment_data's
  destructor.

gdb/ChangeLog:

	* symfile.h (struct symfile_segment_data): Initialize fields.
	<~symfile_segment_data>: Add.
	(symfile_segment_data_up): New.
	(struct sym_fns) <sym_segments>: Return a
	symfile_segment_data_up.
	(default_symfile_segments): Return a symfile_segment_data_up.
	(free_symfile_segment_data): Remove.
	(get_symfile_segment_data): Return a symfile_segment_data_up.
	* symfile.c (default_symfile_segments): Likewise.
	(get_symfile_segment_data): Likewise.
	(free_symfile_segment_data): Remove.
	(symfile_find_segment_sections): Update.
	* elfread.c (elf_symfile_segments): Return a
	symfile_segment_data_up.
	* remote.c (remote_target::get_offsets): Update.
	* solib-target.c (solib_target_relocate_section_addresses):
	Update.
	* symfile-debug.c (debug_sym_segments): Return a
	symfile_segment_data_up.
2020-05-19 12:18:36 -04:00
H.J. Lu 8ac10c5bfc Allow readelf to issue warnings if checking is enabled and there are discrepancies between the dynamic tags and the dynamic sections.
PR binutils/25809
	* readelf.c (process_program_headers): Warn if the PT_DYNAMIC
	segment doesn't match the .dynamic section and checks are
	enabled.
	(struct filedata): Add dynamic_symtab_section and
	dynamic_strtab_section fields.
	(process_section_headers): Set dynamic_symtab_section to the
	.dynsym section.  Set dynamic_strtab_section to the .dynstr
	section.
	(process_dynamic_section): Warn if the .dynsym section doesn't
	match DT_SYMTAB and DT_SYMENT or the .dynstr section doesn't
	DT_STRTAB and DT_STRSZ.  But only if checks are enabled.
2020-05-19 16:47:12 +01:00
Stafford Horne 7e94cf6cb0 OpenRISC BFD fixups for Glibc:
or1k: Fix static linking when with .rela.got relocations
  or1k: Fix dynamic TLS symbol flag
  or1k: Add TLS mask to handle multiple model access
  or1k: Fix issue with multiple PCREL relocations
  or1k: TLS offset to use tcb size and section alignment
  or1k: refactor: Rename p to sec_relocs
  or1k: refactor: Rename s to sgot and splt
  or1k: Add dynamic flag to tpoff

bfd	* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Rename srela
	to relgot.
	(or1k_elf_relocate_section): Access srelgot via
	htab->root.srelgot.  Add assertions for srelgot->contents.
	Introduce local variable for srelgot to not reuse global
	sreloc.
	(or1k_elf_relocate_section): Fixup dynamic symbol detection.
	(or1k_set_got_and_rela_sizes): New function.
	(or1k_initial_exec_offset): New function.
	(TLS_GD, TLS_IE, TLS_LD, TLS_LE): Redefine macros as masks.
	(or1k_elf_relocate_section): Allow for TLS to handle multiple
	model access.
	(or1k_elf_check_relocs): Use OR to set TLS access.
	(allocate_dynrelocs): Use or1k_set_got_and_rela_sizes to set
	sizes.
	(or1k_elf_size_dynamic_sections): Use
	or1k_set_got_and_rela_sizes to set sizes.
	(or1k_elf_relocate_section): Fixup PCREL relocation calculation.
	(TCB_SIZE): New macro.
	(tpoff): Use TCB_SIZE and alignment to calculate offset.
	(allocate_dynrelocs, readonly_dynrelocs, or1k_elf_check_relocs)
	(or1k_elf_size_dynamic_sections): Rename p to sec_relocs.
	(allocate_dynrelocs): Rename s to splt or sgot based on usage.
	(tpoff): Add dynamic boolean argument.
	(or1k_elf_relocate_section): Pass dynamic flag to tpoff.
2020-05-19 14:26:33 +01:00
Alexander Fedotov 164446e04c Fix the ARM assembler to generate a Realtime profile for armv8-r.
PR 25992
gas	* config/tc-arm.c : Add arm_ext_v8r feature.
	(it_fsm_post_encode): Check arm_ext_v8r feature.
	(get_aeabi_cpu_arch_from_fset): Check arm_ext_v8r feature.

include	* opcode/arm.h (ARM_EXT2_V8R): Define. Modified ARM_AEXT2_V8R.
2020-05-19 12:45:42 +01:00
Stafford Horne a501eb446f or1k: Regenerate opcodes after removing 32-bit support
opcodes/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	PR 25184
	* or1k-asm.c: Regenerate.
	* or1k-desc.c: Regenerate.
	* or1k-desc.h: Regenerate.
	* or1k-dis.c: Regenerate.
	* or1k-ibld.c: Regenerate.
	* or1k-opc.c: Regenerate.
	* or1k-opc.h: Regenerate.
	* or1k-opinst.c: Regenerate.
2020-05-19 20:41:03 +09:00
Stafford Horne ae440402f5 or1k: Remove 64-bit support, it's not used and it breaks 32-bit hosts
Reported by Rich Felker when building on 32-bit hosts.  Backwards jump
negative offsets were not calculated correctly due to improper 32-bit
to 64-bit zero-extension.  The 64-bit fields are present because we
are mixing 32-bit and 64-bit architectures in our cpu descriptions.

Removing 64-bit fixes the issue.  We don't use 64-bit, there is an architecture
spec for 64-bit but no implementations or simulators.  My thought is if
we need them in the future we should do the proper work to support both
32-bit and 64-bit implementations co-existing then.

cpu/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	PR 25184
	* or1k.cpu (arch or1k): Remove or64 and or64nd machs.
	(ORBIS-MACHS, ORFPX32-MACHS): Remove pmacros.
	(cpu or1k64bf, mach or64, mach or64nd): Remove definitions.
	* or1kcommon.cpu (h-fdr): Remove hardware.
	* or1korfpx.cpu (rDDF, rADF, rBDF): Remove operand definitions.
	(float-regreg-insn): Remove lf- mnemonic -d instruction pattern.
	(float-setflag-insn-base): Remove lf-sf mnemonic -d pattern.
	(float-cust-insn): Remove "lf-cust" cust-num "-d" pattern.
	(lf-rem-d, lf-itof-d, lf-ftoi-d, lf-madd-d): Remove.
2020-05-19 20:40:27 +09:00
Siddhesh Poyarekar 7e05773767 [PATCH v3] aarch64: Emit jump slot for conditional branch to undefined symbols
The linker silently writes out a conditional branch to 0 if the
target symbol in R_AARCH64_CONDBR19 or R_AARCH64_TSTBR14 relocations is
undefined.  Emit a PLT instead so that behaviour is the same for these
relocations as the llvm linker.

The special behaviour for undefined weak symbols, where conditional
branches to such symbols result in a branch unto themselves, has been
retained.  This is because the weak-undefined.s test explicitly checks
for that, leading me to conclude that it's expected behaviour.

bfd	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Club
	BFD_RELOC_AARCH64_BRANCH19 and BFD_RELOC_AARCH64_TSTBR14
	cases with BFD_RELOC_AARCH64_JUMP26.
	(elfNN_aarch64_check_relocs): Likewise.

ld	* testsuite/ld-aarch64/aarch64-elf.exp: New test
	emit-relocs-560.
	* testsuite/ld-aarch64/emit-relocs-560.d: New file.
	* testsuite/ld-aarch64/emit-relocs-560.s: New file.
2020-05-19 11:07:52 +01:00
Alan Modra 607b483327 Use bfd_get_filename throughout ld
* emultempl/beos.em (sort_by_file_name): Use bfd_get_filename
	rather than accessing bfd->filename directly.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/spuelf.em (embedded_spu_file): Likewise.
	* ldlang.c (input_statement_is_archive_path, wild_sort),
	(check_excluded_libs): Likewise.
	* ldmain.c (add_archive_element): Likewise.
	* ldmisc.c (vfinfo): Likewise.
	* pe-dll.c (auto_export, generate_edata, pe_create_import_fixup),
	(pe_dll_generate_implib, pe_process_import_defs): Likewise.
	* plugin.c (plugin_object_p): Likewise.
2020-05-19 12:57:15 +09:30
Alan Modra 69f57659c3 Use bfd_get_filename throughout gas
* write.c (write_contents): Use bfd_get_filename rather than
	accessing bfd->filename directly.  Use bfd_section_name rather
	than accessing section->name directly.
2020-05-19 12:55:27 +09:30
Alan Modra c177f3771c Use bfd_get_filename throughout binutils
* ar.c (map_over_members, get_pos_bfd, delete_members, move_members),
	(replace_members): Use bfd_get_filename rather than accessing
	bfd->filename directly.
	* arsup.c (map_over_list, ar_delete, ar_replace, ar_extract): Likewise.
	* binemul.c (do_ar_emul_append): Likewise.
	* coffgrok.c (coff_grok): Likewise.
2020-05-19 12:35:56 +09:30
Alan Modra 765cf5f623 Use bfd_get_filename throughout bfd
* aix5ppc-core.c (xcoff64_core_file_matches_executable_p): Use
	bfd_get_filename rather than accessing bfd->filename directly.
	* aout-target.h (MY (object_p)): Likewise.
	* aoutx.h (aout_find_nearest_line, aout_link_write_symbols): Likewise.
	* archive.c (find_nested_archive, _bfd_generic_read_ar_hdr_mag),
	(_bfd_construct_extended_name_table, _bfd_bsd44_write_ar_hdr),
	(_bfd_archive_bsd44_construct_extended_name_table),
	(_bfd_write_archive_contents, _bfd_compute_and_write_armap),
	(_bfd_bsd_write_armap): Likewise.
	* bfd.c (bfd_errmsg, _bfd_doprnt): Likewise.
	* cache.c (bfd_open_file): Likewise.
	* ecoff.c (_bfd_ecoff_write_armap): Likewise.
	* ecofflink.c (bfd_ecoff_debug_accumulate_other): Likewise.
	* elf32-bfin.c (bfinfdpic_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_final_link): Likewise.
	* elf32-nds32.c (nds32_elf_output_symbol_hook),
	(patch_tls_desc_to_ie): Likewise.
	* elf32-spu.c (sort_bfds, print_one_overlay_section),
	(spu_elf_auto_overlay): Likewise.
	* elf64-hppa.c (elf_hppa_final_link): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_size_dynamic_sections): Likewise.
	* elfcore.h (elf_core_file_matches_executable_p): Likewise.
	* elflink.c (bfd_elf_size_dynamic_sections),
	(elf_link_input_bfd): Likewise.
	* linker.c (_bfd_generic_link_output_symbols): Likewise.
	* mach-o.c (bfd_mach_o_follow_dsym),
	(bfd_mach_o_close_and_cleanup): Likewise.
	* opncls.c (_bfd_delete_bfd, _maybe_make_executable),
	(find_separate_debug_file, get_build_id_name): Likewise.
	* pdp11.c (aout_find_nearest_line, aout_link_write_symbols): Likewise.
	* plugin.c (bfd_plugin_open_input): Likewise.
	* rs6000-core.c (rs6000coff_core_file_matches_executable_p): Likewise.
	* som.c (som_write_armap): Likewise.
	* srec.c (srec_write_record, srec_write_symbols): Likewise.
	* vms-lib.c (_bfd_vms_lib_get_imagelib_file),
	(_bfd_vms_lib_write_archive_contents): Likewise.
	* xcofflink.c (xcoff_link_add_dynamic_symbols): Likewise.
2020-05-19 12:35:03 +09:30
Alan Modra 0e1d094e96 Clear all local_symbol.lsy_flags
* symbols.c (local_symbol_make): Init all of lsy_flags.
2020-05-19 10:51:04 +09:30
Alan Modra 39a1432c09 win32 typo fix
PR 25713
	* bfdio.c (_bfd_real_fopen): Typo fix.
2020-05-19 10:51:04 +09:30
GDB Administrator 3ecde59918 Automatic date update in version.in 2020-05-19 00:00:17 +00:00
Rainer Orth e52a0f1bd9 Avoid short i386 register names on Solaris/x86 [PR25981]
This is the 32-bit companion to

	Remove unused ps_lgetLDT etc. on Solaris/x86 [PR25981]
        https://sourceware.org/pipermail/gdb-patches/2020-May/168713.html

A 32-bit-default gdb fails to compile with the updated <sys/regset.h>.
While it is also affected by the lack of a GS definition, which the
compantion patch above fixes, it also fails to compile i386-sol2-nat.c like
this

/vol/src/gnu/gdb/hg/master/git/gdb/i386-sol2-nat.c:181:3: error: 'EAX' was not declared in this scope
  181 |   EAX, ECX, EDX, EBX,
      |   ^~~

and several more.

While this could be fixed by either including <ucontext.h> here or
provding fallback definitions of the register macros, I chose to do what
the 64-bit-default code in the same file
(amd64_sol2_gregset32_reg_offset[]) does, namely just hardcode the
numeric values instead.  They are part of the ABI and thus guaranteed
not to change.

With this patch, a i386-pc-solaris2.11 configuration on master compiles
again, however, it doesn't work.  However, I could successfully test it
on the gdb-9 branch.

Compiling and testing proved to be messy, unfortunately:

* For one, Solaris <sys/procfs.h> and largefile support used to be
  mutually exclusive (fixed in Solaris 11.4 and Illumos), which was
  exacerbated by the fact that g++ predefines _FILE_OFFSET_BITS=64 since
  GCC 9.1.0.  For now I've worked around this by adding
  -U_FILE_OFFSET_BITS to CXXFLAGS and configuring with
  --disable-largefile.  I hope to clean this up in a future patch.

* gdb still defaults to startup-with-shell on.  However, /bin/bash is a
  64-bit executable which cannot be debugged by a 32-bit gdb.  I hacked
  around that part by pointing $SHELL at a 32-bit bash before running
  make check.

	PR build/25981
	* i386-sol2-nat.c [PR_MODEL_NATIVE != PR_MODEL_LP64] (regmap):
	Hardcode register numbers.
2020-05-18 17:59:43 +02:00
Rainer Orth 7f20433998 Remove unused ps_lgetLDT etc. on Solaris/x86 [PR25981]
As reported in PR build/25981, a future Solaris 11.4 update will soon
remove the short i386 register names like SS etc. from <sys/regset.h>.
They could leak into user code (e.g. via <signal.h> -> <sys/signal.h> ->
<sys/ucontext.h>) and pollute the user namespace.  Affected code would
have a hard time avoiding the issue: LLVM is one of those.

While the short names are required to be present by the i386 psABI, that
document only demands that they exist in <ucontext.h>, which is what the
upcoming update assures.

With this change, in a 64-bit-default configuration, procfs.c fails to
compile on Solaris/x86:

/vol/src/gnu/gdb/hg/master/git/gdb/procfs.c: In function 'ssd* procfs_find_LDT_entry(ptid_t)':
/vol/src/gnu/gdb/hg/master/git/gdb/procfs.c:1643:18: error: 'GS' was not declared in this scope
 1643 |   key = (*gregs)[GS] & 0xffff;
      |                  ^~
make[2]: *** [Makefile:1607: procfs.o] Error 1

Initially I meant to provide a definition using the planned replacement
macro, but closer inspection revealed a better way.  procfs_find_LDT_entry
and its helper proc_get_LDT_entry are only used to implement ps_lgetLDT,
one of the callback functions required by libthread_db.so.1
(cf. <proc_service.h>).  While that function is still documented as being
required even in Solaris 11.4, I found that calls to it had been removed
long ago in Solaris 9, so just removing the three functions above is the
easiest fix.

The following patch does just that.  It compiled successfully on
amd64-pc-solaris2.11, however, as reported in PR gdb/25939, master is
completely broken on Solaris since the multi-target patch.  The patch
applies cleanly to the gdb-9 branch and there I could test it
successfully.

	PR build/25981
	* procfs.c [(__i386__ || __x86_64__) && sun] (proc_get_LDT_entry,
	procfs_find_LDT_entry): Remove.
	* procfs.h [(__i386__ || __x86_64__) && sun] (struct ssd,
	procfs_find_LDT_entry): Remove.
	* sol-thread.c [(__i386__ || __x86_64__) && sun] (ps_lgetLDT):
	Remove.
2020-05-18 17:56:00 +02:00
Nick Clifton ed02cdb5b7 Fix a use-after-free bug in the BFD library when scanning a corrupt ELF file.
PR 26005
	* elf.c (bfd_section_from_shdr): Use bfd_malloc to allocate memory
	for the sections_being_created array.
2020-05-18 15:52:03 +01:00
Tom de Vries 1d72769534 [gdb/testsuite] Use with_test_prefix in gdb.base/gdb-caching-proc.exp
When running test-case gdb.base/gdb-caching-proc.exp all passes are unique,
but fails might not be.

Fix this by using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-18  Tom de Vries  <tdevries@suse.de>

	* gdb.base/gdb-caching-proc.exp: Use with_test_prefix.
2020-05-18 16:33:37 +02:00
Douglas B Rupp 3edf7b9f2c Show AIX gc'd symbol address adjustments in map file
* ldemul.h (ldemul_print_symbol): New.
	(ld_emulation_xfer_type) <print_symbol): Likewise.
	* ldemul.c (ldemul_print_symbol): New.
	* ldlang.c (SECTION_NAME_MAP_LANGTH): Move to ...
	(print_one_symbol): Make global and move declaration to ...
	(print_all_symbols): Rename print_one_symbol to ldemul_print_symbol
	(print_input_section): Likewise
	* ldlang.h: ... here.
	* emultempl/aix.em (gld${EMULATION_NAME}_print_symbol): New.
	(ld_emulation_xfer_struct): Use it.
	* emultempl/armcoff.em (ld_emulation_xfer_struct): Add print_symbol
	and default to NULL.
	* emultempl/beos.em (ld_emulation_xfer_struct): Likewise
	* emultempl/elf.em (ld_emulation_xfer_struct): Likewise
	* emultempl/generic.em (ld_emulation_xfer_struct): Likewise
	* emultempl/linux.em (ld_emulation_xfer_struct): Likewise
	* emultempl/msp430.em (ld_emulation_xfer_struct): Likewise
	* emultempl/pe.em (ld_emulation_xfer_struct): Likewise
	* emultempl/pep.em (ld_emulation_xfer_struct): Likewise
	* emultempl/ticoff.em (ld_emulation_xfer_struct): Likewise
	* emultempl/vanilla.em (ld_emulation_xfer_struct): Likewise
2020-05-18 22:41:32 +09:30
Sergei Trofimovich 6e0c75f7c4 [PATCH] ld: fix s/claimi/claim/ typo
* ldmain.c (add_archive_element): Fix s/claimi/claim/ typo
	in info message.
2020-05-18 13:51:23 +01:00
Nick Clifton e6ddf2af20 Updated translations for the gprof and ld sub-directories 2020-05-18 13:47:11 +01:00
Alan Modra 7a87e9c805 ECOFF slurp_relocs thinko
In git commit 806470a219 I swapped the order of internal vs. external
relocs memory allocation in ecoff_slurp_reloc_table, the idea being
that the external reloc size can be sanity checked against file size.
However, that fails badly with bfd_alloc memory where releasing any
block also releases all more recently allocated blocks.

	* ecoff.c (ecoff_slurp_reloc_table): Malloc external_relocs so
	they can be freed without also freeing internal_relocs.
2020-05-18 20:56:39 +09:30
Jaydeep Chauhan ca859a8939 Fix the BFD library to handle Windows pathnames with more than 260 characters and UNIX style directory separators.
PR 25713
	* bfdio.c (_bfd_real_fopen): Convert UNIX style sirectory
	separators into DOS style when creating a WIN32 fullpath.
2020-05-18 11:36:26 +01:00
Nick Clifton 5e365e474b Prevent a potential use-after-fee memory corruption bug in the linker (for PE format files).
PR 25993
	* emultempl/pe.em (_after_open): Check for duplicate filename
	pointers before renaming the dll.
	* emultempl/pep.em (_after_open): Likewise.
2020-05-18 10:28:52 +01:00
Alan Modra d402189f2f Re: Fix tight loop on recursively-defined symbols
sy_resolving ought to not be set for a struct local_symbol, but it is
apparent from local_symbol_make that the field is not initialised.

	* symbols.c (resolve_symbol_value): Invoke LOCAL_SYMBOL_CHECK
	before looking at add_symbol->sy_flags.sy_resolving.
2020-05-18 13:46:27 +09:30
liuhongt 503648e41e Don't handle lret/iret when -mlfence-before-ret=[or|not|shl|yes] since they are invalid in SGX enclaves.
gas/ChangeLog
	* gas/config/tc-i386.c: Not handle lret/iret.
	* gas/testsuite/gas/i386/lfence-ret-a.d: Adjust testcase.
	* gas/testsuite/gas/i386/lfence-ret-b.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret-c.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret-d.d: Ditto.
	* gas/testsuite/gas/i386/lfence-ret.s: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-a.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-b.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-c.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-d.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret-e.d: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret.s: Ditto.
	* gas/testsuite/gas/i386/x86-64-lfence-ret.e: Deleted.
2020-05-18 10:23:59 +08:00
GDB Administrator 07a78c5956 Automatic date update in version.in 2020-05-18 00:00:14 +00:00
Stafford Horne 83d27139ca binutils: Add myself as maintainer for OpenRISC
binutils/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	* MAINTAINERS (OR1K): Add myself as maintainer.
2020-05-18 05:27:13 +09:00
Pedro Alves 7f32a4d5ae Stop considering hw and sw breakpoint locations duplicates (PR gdb/25741)
In the following conditions:

  - A target with hardware breakpoints available, and
  - A target that uses software single stepping,
  - An instruction at ADDRESS loops back to itself,

Now consider the following steps:

  1. The user places a hardware breakpoint at ADDRESS (an instruction
  that loops to itself),

  2. The inferior runs and hits the breakpoint at ADDRESS,

  3. The user tells GDB to 'continue'.

In #3 when the user tells GDB to continue, GDB first disables the
hardware breakpoint at ADDRESS, and then inserts a software
single-step breakpoint at ADDRESS.  The original user-created
breakpoint was a hardware breakpoint, while the single-step breakpoint
will be a software breakpoint.

GDB continues and immediately hits the software single-step
breakpoint.

GDB then deletes the software single-step breakpoint by calling
delete_single_step_breakpoints, which eventually calls
delete_breakpoint, which, once the breakpoint (and its locations) are
deleted, calls update_global_location_list.

During update_global_location_list GDB spots that we have an old
location (the software single step breakpoint location) that is
inserted, but being deleted, and a location (the original hardware
breakpoint) at the same address which we are keeping, but which is not
currently inserted, GDB then calls breakpoint_locations_match on these
two locations.

Currently the locations do match, and so GDB calls swap_insertion
which swaps the "inserted" state of the two locations.  The user
created hardware breakpoint is marked as inserted, while the GDB
internal software single step breakpoint is now marked as not
inserted.  After this GDB returns through the call stack and leaves
delete_single_step_breakpoints.

After this GDB continues with its normal "stopping" process, as part
of this stopping process GDB removes all the breakpoints from the
target.  Due to the swap it is now the user-created hardware
breakpoint that is marked as inserted, so it is this breakpoint GDB
tries to remove.

The problem is that GDB inserted the software single-step breakpoint
as a software breakpoint, but is now trying to remove the hardware
breakpoint.  The problem is removing a software breakpoint is very
different to removing a hardware breakpoint, this could result is some
undetected undefined behaviour, or as in the original bug report (PR
gdb/25741), could result in the target throwing an error.

With "set breakpoint always-inserted on", we can easily reproduce this
against GDBserver.  E.g.:

  (gdb) hbreak main
  Sending packet: $m400700,40#28...Packet received: 89e58b....
  Sending packet: $m400736,1#fe...Packet received: 48
  Hardware assisted breakpoint 1 at 0x400736: file threads.c, line 57.
  Sending packet: $Z1,400736,1#48...Packet received: OK
  Packet Z1 (hardware-breakpoint) is supported

  (gdb) b main
  Note: breakpoint 1 also set at pc 0x400736.
  Sending packet: $m400736,1#fe...Packet received: 48
  Breakpoint 2 at 0x400736: file threads.c, line 57.

  (gdb) del
  Delete all breakpoints? (y or n) y
  Sending packet: $z0,400736,1#67...Packet received: E01
  warning: Error removing breakpoint 2

This patch adds a testcase that does exactly that.

Trying to enhance GDB to handle this scenario while continuing to
avoid inserting redundant software and hardware breakpoints at the
same address turns out futile, because, given non-stop and breakpoints
always-inserted, if the user:

 #1 - inserts a hw breakpoint, then
 #2 - inserts a sw breakpoint at the same address, and then
 #3 - removes the original hw breakpoint,

GDB would have to make sure to insert the sw breakpoint before
removing the hw breakpoint, to avoid running threads missing the
breakpoint.  I.e., there's always going to be a window where a target
needs to be able to handle both sw and a hw breakpoints installed at
the same address.  You can see more detailed description of that issue
here:
https://sourceware.org/pipermail/gdb-patches/2020-April/167738.html

So the fix here is to just stop considering software breakpoints and
hw breakpoints duplicates, and let GDB insert sw and hw breakpoints at
the same address.

The central change is to make breakpoint_locations_match consider the
location's type too.  There are several other changes necessary to
actually make that that work correctly, however:

- We need to handle the duplicates detection better.  Take a look at
  the loop at the tail end of update_global_location_list.  Currently,
  because breakpoint locations aren't sorted by type, we can end up
  with, at the same address, a sw break, then a hw break, then a sw
  break, etc.  The result is that that second sw break won't be
  considered a duplicate of the first sw break.  Seems like we already
  handle that incorrectly for range breakpoints.

- The "set breakpoint auto-hw on" handling is moved out of
  insert_bp_location to update_global_location_list, before the
  duplicates determination.

  Moving "set breakpoint auto-hw off" handling as well and downgrading
  it to a warning+'disabling the location' was considered too, but in
  the end discarded, because we want to error out with internal and
  momentary breakpoints, like software single-step breakpoints.
  Disabling such locations at update_global_location_list time would
  make GDB lose control of the inferior.

- In update_breakpoint_locations, the logic of matching old locations
  with new locations, in the have_ambiguous_names case, is updated to
  still consider sw vs hw locations the same.

- Review all ALL_BP_LOCATIONS_AT_ADDR uses, and update those that
  might need to be updated, and update comments for those that don't.
  Note that that macro walks all locations at a given address, and
  doesn't call breakpoint_locations_match.

The result against GDBserver (with "set breakpoint
condition-evaluation host" to avoid seeing confusing reinsertions) is:

 (gdb) hbreak main
 Sending packet: $m400736,1#fe...Packet received: 48
 Hardware assisted breakpoint 1 at 0x400736: file main.c, line 57.
 Sending packet: $Z1,400736,1#48...Packet received: OK

 (gdb) b main
 Note: breakpoint 1 also set at pc 0x400736.
 Sending packet: $m400736,1#fe...Packet received: 48
 Breakpoint 4 at 0x400736: file main.c, line 57.
 Sending packet: $Z0,400736,1#47...Packet received: OK

 (gdb) del 3
 Sending packet: $z1,400736,1#68...Packet received: OK

gdb/ChangeLog:
2020-05-17  Pedro Alves  <palves@redhat.com>
	    Andrew Burgess  <andrew.burgess@embecosm.com>
	    Keno Fischer  <keno@juliacomputing.com>

	PR gdb/25741
	* breakpoint.c (build_target_condition_list): Update comments.
	(build_target_command_list): Update comments and skip matching
	locations.
	(insert_bp_location): Move "set breakpoint auto-hw on" handling to
	a separate function.  Simplify "set breakpoint auto-hw off"
	handling.
	(insert_breakpoints): Update comment.
	(tracepoint_locations_match): New parameter.  For breakpoints,
	compare location types too, if the caller wants to.
	(handle_automatic_hardware_breakpoints): New functions.
	(bp_location_is_less_than): Also sort by location type and
	hardware breakpoint length.
	(update_global_location_list): Handle "set breakpoint auto-hw on"
	here.
	(update_breakpoint_locations): Ask breakpoint_locations_match to
	ignore location types.

gdb/testsuite/ChangeLog:
2020-05-17  Pedro Alves  <palves@redhat.com>

	PR gdb/25741
	* gdb.base/hw-sw-break-same-address.exp: New file.
2020-05-17 19:17:56 +01:00
GDB Administrator 966dc1a27c Automatic date update in version.in 2020-05-17 00:00:06 +00:00
Pedro Alves 7cfd74cfc6 Fix gdb.multi/multi-re-run.exp with native-gdbserver
The new exec-file-mismatch feature reveals that when running
gdb.multi/multi-re-run.exp against --target_board=native-gdbserver,
we've been starting gdbserver with the wrong program:

 (gdb) spawn /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/../../gdbserver/gdbserver --once localhost:2347 /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/te
 stsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2
 Process /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2 created; pid = 6280
 Listening on port 2347
 target remote localhost:2347
 Remote debugging using localhost:2347
 warning: Mismatch between current exec-file /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-1
 and automatically determined exec-file /home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2
 exec-file-mismatch handling is currently "ask"
 Load new symbol table from "/home/pedro/brno/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run-2"? (y or n) Quit
 (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: running to all_started in runto

The problem is that gdb_reload uses the last loaded file as binary to
spawn, but we load the program for inferior 2 and then switch to
inferior 1 and run it, so the last loaded file is the program for
inferior 2.

Fix this by tweaking last_loaded_file.

gdb/testsuite/ChangeLog:
2020-05-16  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-re-run.exp (test_re_run): Switch
	LAST_LOADED_FILE accordingly.
2020-05-16 18:59:10 +01:00
Simon Marchi 7d93a1e0b6 gdb: remove TYPE_NAME macro
Remove `TYPE_NAME`, changing all the call sites to use `type::name`
directly.  This is quite a big diff, but this was mostly done using sed
and coccinelle.  A few call sites were done by hand.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_NAME): Remove.  Change all cal sites to use
	type::name instead.
2020-05-16 12:36:05 -04:00
Simon Marchi d0e39ea27c gdb: add type::name / type::set_name
Add the `name` and `set_name` methods on `struct type`, in order to
remove the `TYPE_NAME` macro.  In this patch, the `TYPE_NAME` macro is
changed to use `type::name`, so all the call sites that are used to set
the type name are changed to use `type::set_name`.  The next patch will
remove `TYPE_NAME` completely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <name, set_name>: New methods.
	(TYPE_CODE): Use type::name.  Change all call sites used to set
	the name to use type::set_name instead.
2020-05-16 12:36:05 -04:00
Tom Tromey 2dab0c7ba0 Remove ALL_UIS
Continuing my goal of removing the "ALL_*" iterator macros, this
removes ALL_UIS, replacing it with an iterator adaptor.

gdb/ChangeLog
2020-05-16  Tom Tromey  <tom@tromey.com>

	* top.c (quit_force): Update.
	* infrun.c (handle_no_resumed): Update.
	* top.h (all_uis): New function.
	(ALL_UIS): Remove.
2020-05-16 09:58:46 -06:00
Simon Marchi 59f7bd8d2b gdb: fix -Wtautological-overlap-compare warning in mips-linux-tdep.c
When building with clang 11, I get:

  CXX    mips-linux-tdep.o
/home/smarchi/src/binutils-gdb/gdb/mips-linux-tdep.c:643:30: error: overlapping comparisons always evaluate to true [-Werror,-Wtautological-overlap-compare]
      if (insn != 0x03e07821 || insn != 0x03e07825)
          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/home/smarchi/src/binutils-gdb/gdb/mips-linux-tdep.c:636:30: error: overlapping comparisons always evaluate to true [-Werror,-Wtautological-overlap-compare]
      if (insn != 0x03e0782d || insn != 0x03e07825)
          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Indeed, given two different values, `insn` will always be different to
one of them, and these conditions always be true.

This code is meant to return if `insn` isn't one of these two values, so
the `||` should be replaced with `&&`.

gdb/ChangeLog:

	* mips-linux-tdep.c (mips_linux_in_dynsym_stub): Fix condition.
2020-05-16 11:21:41 -04:00
H.J. Lu 56770bdab2 Sync config with GCC
Sync with GCC
	2020-05-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR bootstrap/95147
	* cet.m4 (GCC_CET_FLAGS): Also check if -fcf-protection works
	when defaulting to auto.

	2020-05-14  H.J. Lu  <hongjiu.lu@intel.com>

	* cet.m4 (GCC_CET_FLAGS): Change default to auto.
2020-05-16 06:07:12 -07:00
Pedro Alves 9bf058f094 Fix IA64 GNU/Linux build
This commit should fix:

 ../../gdb/ia64-linux-nat.c: In function ‘void enable_watchpoints_in_psr(ptid_t)’:
 ../../gdb/ia64-linux-nat.c:535:56: error: no matching function for call to ‘get_thread_regcache(ptid_t&)’
    struct regcache *regcache = get_thread_regcache (ptid);
							 ^
 In file included from ../../gdb/ia64-linux-nat.c:25:0:
 ../../gdb/regcache.h:35:25: note: candidate: regcache* get_thread_regcache(process_stratum_target*, ptid_t)
  extern struct regcache *get_thread_regcache (process_stratum_target *target,
			  ^
 ../../gdb/regcache.h:35:25: note:   candidate expects 2 arguments, 1 provided
 ../../gdb/regcache.h:39:25: note: candidate: regcache* get_thread_regcache(thread_info*)
  extern struct regcache *get_thread_regcache (thread_info *thread);
			  ^
 ../../gdb/regcache.h:39:25: note:   no known conversion for argument 1 from ‘ptid_t’ to ‘thread_info*’

gdb/ChangeLog:
2020-05-16  Pedro Alves  <palves@redhat.com>

	* ia64-linux-nat.c
	(ia64_linux_nat_target) <enable_watchpoints_in_psr(ptid_t)>:
	Declare method.
	(enable_watchpoints_in_psr): Now a method of ia64_linux_nat_target.
2020-05-16 12:26:56 +01:00
Tankut Baris Aktemur 8bbf03947d gdbserver/linux-ia64-low: fix a build-breaking typo
During the gdbserver c++'ification refactoring, I apparently made a
typo that broke build in ia64 targets.

gdbserver/ChangeLog:
2020-05-16  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* linux-ia64-low.cc (ia64_target::sw_breakpoint_from_kind):
	Fix incorrect 'gdb_assert_no_reached' to 'gdb_assert_not_reached'.
	(ia64_target::low_breakpoint_at): Ditto.
2020-05-16 10:45:40 +02:00
Simon Marchi 8f86ae1a18 gdb: remove unnecessary struct typedef in sparc64-tdep.c
When building with clang 11, I get:

      CXX    sparc64-tdep.o
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:89:15: error: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Werror,-Wnon-c-typedef-for-linkage]
    typedef struct
                  ^
                   adi_stat_t
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:103:16: note: type is not C-compatible due to this default member initializer
      int tag_fd = 0;
                   ^
    /home/smarchi/src/binutils-gdb/gdb/sparc64-tdep.c:111:3: note: type is given name 'adi_stat_t' for linkage purposes by this typedef declaration
    } adi_stat_t;
      ^

The typedef is not needed in C++ anyway, just remove them.

gdb/ChangeLog:

	* sparc64-tdep.c (adi_stat_t): Remove typedef (leaving struct).
	(sparc64_adi_info): Likewise.
2020-05-15 22:17:40 -04:00
GDB Administrator 1c5dd7a572 Automatic date update in version.in 2020-05-16 00:00:09 +00:00
Tom Tromey d6bc0792ed Remove lookup_objfile_from_block
lookup_objfile_from_block mostly duplicates the functionality of
block_objfile, but in a less efficient way.  This patch removes this
function and changes the callers to use block_objfile instead.

Tested by the buildbot.

gdb/ChangeLog
2020-05-15  Tom Tromey  <tom@tromey.com>

	* symtab.c (lookup_language_this, lookup_symbol_aux): Use
	block_objfile.
	(lookup_objfile_from_block): Remove.
	(lookup_symbol_in_block, lookup_symbol_in_static_block)
	(lookup_global_symbol): Use block_objfile.
	* symtab.h (lookup_objfile_from_block): Don't declare.
	* printcmd.c (clear_dangling_display_expressions): Use
	block_objfile.
	* parse.c (operator_check_standard): Use block_objfile.
2020-05-15 16:24:07 -06:00
Tom Tromey 8c14c3a373 Remove allocate_symbol et al
This removes allocate_symbol, allocate_template_symbol, and
initialize_objfile_symbol in favor of changing the default values for
symbol members, and updating the one per-arch caller.

gdb/ChangeLog
2020-05-15  Tom Tromey  <tom@tromey.com>

	* language.c (language_alloc_type_symbol): Set
	SYMBOL_SECTION.
	* symtab.c (initialize_objfile_symbol): Remove.
	(allocate_symbol): Remove.
	(allocate_template_symbol): Remove.
	* dwarf2/read.c (fixup_go_packaging): Use "new".
	(new_symbol): Use "new".
	(read_variable): Don't call initialize_objfile_symbol.  Use
	"new".
	(read_func_scope): Use "new".
	* xcoffread.c (process_xcoff_symbol): Don't call
	initialize_objfile_symbol.
	(SYMBOL_DUP): Remove.
	* coffread.c (process_coff_symbol, coff_read_enum_type): Use
	"new".
	* symtab.h (allocate_symbol, initialize_objfile_symbol)
	(allocate_template_symbol): Don't declare.
	(struct symbol): Add copy constructor.  Change defaults.
	* jit.c (finalize_symtab): Use "new".
	* ctfread.c (ctf_add_enum_member_cb, new_symbol, ctf_add_var_cb):
	Use "new".
	* stabsread.c (patch_block_stabs, define_symbol, read_enum_type)
	(common_block_end): Use "new".
	* mdebugread.c (parse_symbol): Use "new".
	(new_symbol): Likewise.
2020-05-15 16:11:34 -06:00
Philippe Waroquiers 5b4a1a8dbe Update NEWS and documentation for help and apropos changes.
gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention changes to help and apropos.

gdb/doc/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Help): Document the help and apropos changes.
	(Aliases): Document new meaning of -a abbreviation flag.
2020-05-15 22:17:46 +02:00
Philippe Waroquiers 57b4f16e49 Ensure class_alias is only used for user-defined aliases.
This commit finally does the (small) change that started this patch
series.

It ensures that the class_alias is only used for user-defined aliases.
So, the few GDB pre-defined aliases that were using the 'class_alias'
class are now using a real help class, typically the class of
the aliased command.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* command.h (enum command_class): Improve comments, document
	that class_alias is for user-defined aliases, give the class
	name for each class, remove unused class_xdb.
	* cli/cli-decode.c (add_com_alias): Document THECLASS intended usage.
	* breakpoint.c (_initialize_breakpoint): Replace class_alias
	by a precise class.
	* infcmd.c (_initialize_infcmd): Likewise.
	* reverse.c (_initialize_reverse): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* symfile.c (_initialize_symfile): Likewise.
	* tracepoint.c (_initialize_tracepoint): Likewise.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Verify 'help aliases' shows user defined aliases.
2020-05-15 22:17:46 +02:00
Philippe Waroquiers 7c05caf72d Fix/improve 'apropos' output
Similarly to 'help CLASS', apropos possibly shows several
times the same help (for the command and for each of its aliases).

This patch changes 'apropos' so that the help for a command and
all its aliases is shown once.

So, apropos_cmd now skips all aliases/abbreviations, as these are printed
as part of the help of the aliased command.

When 'apropos' prints the help of a command, function 'help_cmd' now
unconditionally print the command name and its possible aliases (as we must
indicate to the user the command/aliases for which the help is printed).

When 'help somecommand' prints the help of a command, if the command is not
aliased, the command name is not printed (to avoid a useless first line), but if
it has aliases, then the command name and all its aliases are now printed.
In addition to provide to the user the choice of the best way to
type a command, it also avoids the strange behaviour that the output
of 'help somealias' does not mention somealias.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.c (apropos_cmd): Produce output for aliases
	when their aliased command is traversed.
	(help_cmd): Add fput_command_names_styled call to
	output command name and aliases when command has an alias.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/help.exp: Test apropos and help for commands
	having aliases.  Fixed comments not starting with an
	upper-case letter or not finishing with a dot.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 3b3aaacba1 Fix/improve 'help CLASS' output
Currently, help CLASS possibly shows several times the same help,
as it shows it once for the command, and once for each alias.

The final objective of this patch series is to have class_alias used only
for user defined aliases, not anymore for aliases predefined by GDB.
The command 'help aliases' will then only show the user defined aliases.
So, the idea is that GDB predefined aliases will be shown together
with their aliased command.

This commit changes 'help CLASS' so that a command is shown once in the output,
with all its aliases.
This ensures:
  * that the user has only to read once the same help text
  * and sees the command and all its aliases in a glance, a.o. allowing
    the user to choose the preferred way (e.g. the shortest one,
    or the most mnemonic one) to type the command.

For example, the old output:
   (gdb) help stack
   ...
   List of commands:

   backtrace -- Print backtrace of all stack frames, or innermost COUNT frames.
   bt -- Print backtrace of all stack frames, or innermost COUNT frames.
   ...
(note that 'where' is not shown in this output)

becomes
   (gdb) help stack
   ...
   List of commands:

   backtrace, where, bt -- Print backtrace of all stack frames, or innermost COUNT frames.
   ...

The output layout chosen is to have the command first, followed by all its
aliases separated by a comma.  Note that the command and alias names are
title-styled.  For sure, other layouts could be discussed, but this one is IMO
readable and compact.

The function 'help_cmd_list' can be simplified by removing the prefix argument,
as the prefixname of a command can now be retrieved in the GDB command tree
structure.

This also fixes the fact that 'help aliases' wrongly shows a long
list of (non-alias) when defining an alias for a prefix command.
For example, after:
    (gdb) alias montre = show
  then
    (gdb) help aliases
  shows hundreds of sub-commands starting with the non aliased command,
  such as:
    montre -- Generic command for showing things about the debugger.
    show ada -- Generic command for showing Ada-specific settings.
    show ada print-signatures -- Show whether the output of formal ...
    ....

'help_cmd_list' is also made static, as it is only used inside cli-decode.c.

Note that the 'help CLASS' is somewhat broken, in the sense that it
sometimes shows too many commands (commands not belonging to CLASS)
and sometimes shows not enough commands (not showing some commands
belonging to CLASS).
For example, 'help breakpoints' shows the command
'disable pretty-printer' and 'disable unwinder', not related to breakpoints.
On the other end, 'help stack' does not show 'disable unwinder'
while 'disable unwinder' is defined in unwinders.py as belonging to class_stack.
Fixing the missing commands is easy to do,
but fixing the excess commands is not straightforward, as many
subcommands have a class 'no_class' or 'all_class'.
Possibly, some of this might be improved/fixed in another patch series.

With this patch series, the 'abbrev flag' has as only remaining purpose
to avoid having the abbreviation alias appearing in the completion list,
so change 'help alias' accordingly.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.h (help_cmd_list): Remove declaration.
	* cli/cli-decode.c (help_cmd_list): Declare as static,
	remove prefix argument, use bool for recurse arg, rework to show the aliases of
	a command together with the command.
	(fput_command_name_styled, fput_command_names_styled): New functions.
	(print_help_for_command): Remove prefix arg, use bool for recurse arg, use
	fput_command_name_styled.
	(help_list, help_all): Update callers to remove prefix arg and use bool recurse.
	* cli/cli-cmds.c (_initialize_cli_cmds): Update alias_command doc.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Update help output check.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 7aa1b46f43 Fix inconsistent output of prefix and bugs in 'show' command
cmd_show_list function implements the 'show' command.

cmd_show_list output is inconsistent: it sometimes shows a prefix
and sometimes does not.
For example, in the below, you see that there is a prefix before
each value, except for 'enabled'.

    (gdb) show style
    style address background:  The "address" style background color is: none
    style address foreground:  The "address" style foreground color is: blue
    style address intensity:  The "address" style display intensity is: normal
    enabled:  CLI output styling is enabled.
    style filename background:  The "filename" style background color is: none
    ...

There are other inconsistencies or bugs e.g. in
the below we see twice insn-number-max, once with a prefix
and once without prefix : last line, just before the value of
instruction-history-size which is itself without prefix.

    (gdb) show record
    record btrace bts buffer-size:  The record/replay bts buffer size is 65536.
    record btrace cpu:  btrace cpu is 'auto'.
    record btrace pt buffer-size:  The record/replay pt buffer size is 16384.
    record btrace replay-memory-access:  Replay memory access is read-only.
    record full insn-number-max:  Record/replay buffer limit is 200000.
    record full memory-query:  Whether query if PREC cannot record memory change of next instruction is off.
    record full stop-at-limit:  Whether record/replay stops when record/replay buffer becomes full is on.
    function-call-history-size:  Number of functions to print in "record function-call-history" is 10.
    insn-number-max:  instruction-history-size:  Number of instructions to print in "record instruction-history" is 10.
    (gdb)

Also, some values are output several times due to some aliases, so avoid outputting duplicated
values by skipping all aliases.

Now that the command structure has a correct 'back-pointer' from a command
to its prefix command, we can simplify cmd_show_list by removing its prefix argument
and at the same time fix the output inconsistencies and bugs.

gdb/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-setshow.h (cmd_show_list): Remove prefix argument.
	* cli/cli-decode.c (do_show_prefix_cmd): Likewise.
	* command.h (cmd_show_list): Likewise.
	* dwarf2/index-cache.c (show_index_cache_command): Likewise.
	* cli/cli-setshow.c (cmd_show_list): Use the prefix to produce the output.  Skip aliases.

gdb/testsuite/ChangeLog

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/default.exp: Update output following fixes.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 89bcba74f8 command-def-selftests.c: detect missing or wrong prefix cmd in subcommands.
This test revealed a number of problems that are fixed in the previous commit.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* unittests/command-def-selftests.c (traverse_command_structure):
	Verify all commands of a list have the same prefix command and
	that only the top cmdlist commands have a null prefix.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 3f4d92ebdf Fix the problems reported by prefix check of command-def-selftests.c
The next commit updates command-def-selftests.c to detect missing
or wrong prefix commands in a list of subcommands.
This command structure selftest detects a series of problems
that are fixed by this commit.

Many commands have a null prefix command, e.g.
    (gdb) maintenance selftest command_str
    Running selftest command_structure_invariants.
    list 0x560417949cb8 reachable via prefix 'append binary '.  command 'memory' has null prefixcmd
    list 0x560417949cb8 reachable via prefix 'append binary '.  command 'value' has null prefixcmd
    ...

Most of these are fixed by the following changes:
  * do_add_cmd searches the prefix command having the list
    in which the command is added.
    This ensures that a command defined after its prefix command
    gets the correct prefix command.
  * Due to the GDB initialization order, a GDB file can define
    a subcommand before the prefix command is defined.
    So, have add_prefix_cmd calling a new recursive function
    'update_prefix_field_of_prefix_commands' to set the prefix
    command of all sub-commands that are now reachable from
    this newly defined prefix command.  Note that this recursive
    call replaces the function 'set_prefix_cmd' that was providing
    a partial solution to this problem.

Following that, 2 python commands (defined after all the other GDB
commands) got a wrong prefix command, e.g. "info frame-filter" has
as prefix command the "i" alias of "info".  This is fixed by having
lookup_cmd_for_prefixlist returning the aliased command rather than
the alias.

After that, one remaining problem:
    (gdb) maintenance selftest command_str
    Running selftest command_structure_invariants.
    list 0x55f320272298 reachable via prefix 'set remote '.  command 'system-call-allowed' has null prefixcmd
    Self test failed: self-test failed at ../../classfix/gdb/unittests/command-def-selftests.c:196
    Ran 1 unit tests, 1 failed
    (gdb)

Caused by initialize_remote_fileio that was taking the address of
its arguments remote_set_cmdlist and remote_show_cmdlist instead
of receiving the correct values to use as list.

2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.c (lookup_cmd_for_prefix): Return the aliased command
	as prefix, not one of its aliases.
	(set_cmd_prefix): Remove.
	(do_add_cmd): Centralize the setting of the prefix of a command, when
	command is defined after its full chain of prefix commands.
	(add_alias_cmd): Remove call to set_cmd_prefix, as do_add_cmd does it.
	(add_setshow_cmd_full): Likewise.
	(update_prefix_field_of_prefixed_commands): New function.
	(add_prefix_cmd): Replace non working call to set_cmd_prefix by
	update_prefix_field_of_prefixed_commands.
	* gdb/remote-fileio.c (initialize_remote_fileio): Use the real
	addresses of remote_set_cmdlist and remote_show_cmdlist given
	as argument, not the address of an argument.
	* gdb/remote-fileio.h (initialize_remote_fileio): Likewise.
	* gdb/remote.c (_initialize_remote): Likewise.
2020-05-15 22:17:45 +02:00
Philippe Waroquiers 0605465feb Fix problem that alias can be defined or not depending on the order.
When an alias name starts with the name of another alias,
GDB was accepting to define the aliases in one order (short first, long after),
but refused it the other way around.

So, fix the logic to recognise an already existing alias by using
lookup_cmd_composition.

Also, this revealed a bug in lookup_cmd_composition:
when the searched command is a prefix command, lookup_cmd_composition
was not returning the fact that a command was found even if the
TEXT to parse was fully consumed.

gdb/ChangeLog
YYYY-MM-DD  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (alias_command): Check for an existing alias
	using lookup_cmd_composition, as valid_command_p is too strict
	and forbids aliases that are the prefix of an existing alias
	or command.
	* cli/cli-decode.c (lookup_cmd_composition): Ensure a prefix
	command is properly recognised as a valid command.

gdb/testsuite/ChangeLog
2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/alias.exp: Test aliases starting with a prefix of
	another alias.
2020-05-15 22:17:45 +02:00