deliverable/binutils-gdb.git
3 years agoconstify elfNN_bed
Alan Modra [Tue, 15 Dec 2020 14:12:21 +0000 (00:42 +1030)] 
constify elfNN_bed

elfNN_bed was made writable as an expedient means of communicating
ld -z max-page-size and ld -z common-page-size values to BFD linker
code, and even for objcopy to communicate segment alignment between
copy_private_bfd_data, rewrite_elf_program_header and
assign_file_positions_for_load_sections.  Some time later elfNN_bed
elf_osabi was written by gas.  It turns out none of these
modifications to elfNN_bed was necessary, so make it const again.

include/
* bfdlink.h (struct bfd_link_info): Add maxpagesize and
commonpagesize.
bfd/
* elfxx-target.h (elfNN_bed): Constify.
* bfd.c (bfd_elf_set_pagesize): Delete.
(bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete.
* elf.c (get_program_header_size): Get commonpagesize from
link info.
(_bfd_elf_map_sections_to_segments): Get maxpagesize from link info.
(assign_file_positions_for_load_sections): Likewise.
(assign_file_positions_for_non_load_sections): Likewise.
(rewrite_elf_program_header): Add maxpagesize param.  Set map_p_align.
(copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize.
Instead pass maxpagesize to rewrite_elf_program_header.
* elf32-nds32.c (relax_range_measurement): Add link_info param.
Get maxpagesize from link_info.  Adjust caller.
* bfd-in2.h: Regenerate.
gas/
* config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
(obj_elf_type): Likewise.
ld/
* ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
* emultempl/elf.em: Use link_info rather than config
for maxpagesize and commonpagesize.
* emultempl/ppc32elf.em: Likewise.
* ldexp.c (fold_binary, fold_name): Likewise.
* ldemul.c (after_parse_default): Likewise.
(set_output_arch_default): Don't call bfd_emul_set_maxpagesize
or bfd_emul_set_commonpagesize.

3 years agoelflink.c constify
Alan Modra [Tue, 15 Dec 2020 14:10:15 +0000 (00:40 +1030)] 
elflink.c constify

* elflink.c (elf_flags_to_names): Constify.

3 years agoXCOFF constify
Alan Modra [Tue, 15 Dec 2020 11:40:27 +0000 (22:10 +1030)] 
XCOFF constify

There are occasions where it is reasonable to use a macro defining
function parameters, but this isn't one of them.  Use typedefs
instead, which also simplifies declaring a const array of function
pointers.

* libxcoff.h (struct xcoff_backend_data_rec): Constify
_xcoff_glink_code.
(XCOFF_RELOC_FUNCTION_ARGS, XCOFF_COMPLAIN_FUNCTION_ARGS): Delete.
(xcoff_reloc_function, xcoff_complain_function): New typedef.
(xcoff_calculate_relocation, xcoff_complain_overflow),
(xcoff_reloc_type_noop, xcoff_reloc_type_fail),
(xcoff_reloc_type_pos, xcoff_reloc_type_neg),
(xcoff_reloc_type_rel, xcoff_reloc_type_toc),
(xcoff_reloc_type_ba, xcoff_reloc_type_crel): Update declaration.
* coff-rs6000.c (xcoff_reloc_type_br): Declare using typedef.
(xcoff_complain_overflow_dont_func): Likewise.
(xcoff_complain_overflow_bitfield_func): Likewise.
(xcoff_complain_overflow_signed_func): Likewise.
(xcoff_complain_overflow_unsigned_func): Likewise.
(xcoff_calculate_relocation, xcoff_complain_overflow): Constify.
(xcoff_glink_code): Constify.
* coff64-rs6000.c (xcoff64_reloc_type_br): Declare using typedef.
(xcoff64_calculate_relocation, xcoff64_glink_code): Constify.

3 years agoxtensa constify
Alan Modra [Tue, 15 Dec 2020 11:39:06 +0000 (22:09 +1030)] 
xtensa constify

Move lots of read-only arrays to .rodata.

include/
* xtensa-isa-internal.h (xtensa_format_internal),
(xtensa_slot_internal, xtensa_operand_internal),
(xtensa_arg_internal, xtensa_iclass_internal),
(xtensa_opcode_internal, xtensa_regfile_internal),
(xtensa_interface_internal, xtensa_funcUnit_internal),
(xtensa_state_internal, xtensa_sysreg_internal): Constify.
bfd/
* elf32-xtensa.c (narrowable, widenable): Constify.
* xtensa-modules.c: Constify many arrays.

3 years agoppc64 constify
Alan Modra [Tue, 15 Dec 2020 11:38:46 +0000 (22:08 +1030)] 
ppc64 constify

Nothing to see here.

* elf64-ppc.c (synthetic_opd): Constify.

3 years agoarc constify
Alan Modra [Tue, 15 Dec 2020 11:38:20 +0000 (22:08 +1030)] 
arc constify

Move a read-only array to .rodata.

* arc-plt.h (plt_versions): Constify.
* elf32-arc.c (arc_get_plt_version): Constify return pointer,
adjust uses throughout.

3 years agoLose some COFF/PE static vars, and peicode.h constify
Alan Modra [Tue, 15 Dec 2020 11:39:30 +0000 (22:09 +1030)] 
Lose some COFF/PE static vars, and peicode.h constify

This patch tidies some COFF and PE code that unnecessarily used static
variables to communicate between functions.

* coffcode.h (pelength, peheader): Delete static variables.
(coff_apply_checksum): Instead, define them as auto vars, and pass..
(coff_read_word, coff_compute_checksum): ..to here.  Delete
unnecessary forward declarations.
* pei-x86_64.c (pdata_count): Delete static variable.
(struct pex64_paps): New.
(pex64_print_all_pdata_sections, pex64_bfd_print_pdata): Pass
a pex64_paps for counting.
* peicode.h (jtab): Constify.

3 years agogdb: multi-line support for "document" command
Rae Kim [Wed, 16 Dec 2020 03:51:09 +0000 (22:51 -0500)] 
gdb: multi-line support for "document" command

"document" command executed in python, gdb.execute("document
<comname>\n...\nend\n"), will wait for user input. Python extension stops
working from that point.

multi-line suport was introduced in commit 56bcdbea2. But "document" support
seem to be implemented.

gdb/ChangeLog:

2020-12-02  Rae Kim  <rae.kim@gmail.com>

* cli/cli-script.c (do_document_command): Rename from
document_command. Handle multi-line input.
(multi_line_command_p): Handle document_control.
(build_command_line): Likewise.
(execute_control_command_1): Likewise.
(process_next_line): Likewise.
(document_command): Call do_document_command.
* cli/cli-script.h (enum command_control_type): Add
document_control.

gdb/testsuite/ChangeLog:

2020-12-02  Rae Kim  <rae.kim@gmail.com>
* gdb.base/document.exp: New test.

Change-Id: Ice262b980c05051de4c106af9f3fde5b2a6df6fe

3 years agoAdd expected type parameter to evaluate_expression
Tom Tromey [Wed, 16 Dec 2020 01:35:13 +0000 (18:35 -0700)] 
Add expected type parameter to evaluate_expression

While working on the expression rewrite, I found a few spots that
called the internal functions of the expression evaluator, just to
pass in an expected type.  This patch adds a parameter to
evaluate_expression so that these functions can avoid this dependency.

Regression tested on x86-64 Fedora 28.

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

* stap-probe.c (stap_probe::evaluate_argument): Use
evaluate_expression.
* dtrace-probe.c (dtrace_probe::evaluate_argument): Use
evaluate_expression.
* value.h (evaluate_expression): Add expect_type parameter.
* objc-lang.c (print_object_command): Call evaluate_expression.
* eval.c (evaluate_expression): Add expect_type parameter.

3 years agoIntroduce expression::first_opcode
Tom Tromey [Wed, 16 Dec 2020 01:14:42 +0000 (18:14 -0700)] 
Introduce expression::first_opcode

This adds a new helper method, expression::first_opcode, that extracts
the outermost opcode of an expression.  This simplifies some patches
in the expression rewrite series.

Note that this patch requires the earlier patch to avoid manual
dissection of OP_TYPE operations.

2020-12-15  Tom Tromey  <tom@tromey.com>

* varobj.c (varobj_create): Use first_opcode.
* value.c (init_if_undefined_command): Use first_opcode.
* typeprint.c (whatis_exp): Use first_opcode.
* tracepoint.c (validate_actionline): Use first_opcode.
(encode_actions_1): Use first_opcode.
* stack.c (return_command): Use first_opcode.
* expression.h (struct expression) <first_opcode>: New method.
* eval.c (parse_and_eval_type): Use first_opcode.
* dtrace-probe.c (dtrace_process_dof_probe): Use first_opcode.

3 years agoClean up arguments to evaluate_subexp_do_call
Tom Tromey [Wed, 16 Dec 2020 00:53:34 +0000 (17:53 -0700)] 
Clean up arguments to evaluate_subexp_do_call

I noticed hat evaluate_subexp_do_call takes an array of arguments and
a count -- but, unlike the usual convention, the count does not
include the first element.

This patch changes this function to match call_function_by_hand --
passing the callee separately, and using an array_view for the
arguments.  This makes it simpler to understand.

Regression tested on x86-64 Fedora 28.

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

* f-lang.c (evaluate_subexp_f): Update.
* expression.h (evaluate_subexp_do_call): Update.
* eval.c (evaluate_subexp_do_call): Add callee parameter.  Replace
nargs, argvec with array_view.
(evaluate_funcall): Update.

3 years agoC++-ify Ada component interval handling
Tom Tromey [Wed, 16 Dec 2020 00:39:57 +0000 (17:39 -0700)] 
C++-ify Ada component interval handling

The Ada component interval handling code, used for aggregate
assignments, does a pre-pass over the sub-expressions so that it can
size an array.  For my expression rewrite, it was handy to C++-ify
this.

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

* ada-lang.c (num_component_specs): Remove.
(assign_aggregate): Update.
(aggregate_assign_positional, aggregate_assign_from_choices)
(aggregate_assign_others, add_component_interval): Change
arguments.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 16 Dec 2020 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoCosmetic improvements for OSABI access.
Cary Coutant [Tue, 15 Dec 2020 22:37:22 +0000 (14:37 -0800)] 
Cosmetic improvements for OSABI access.

Add accessor methods to elfcpp::Ehdr class for EI_OSABI and EI_ABIVERSION;
use those to simplify initialization of Osabi class and eliminate the need
to template the class.

elfcpp/
* elfcpp.h (class Ehdr): Add get_ei_osabi and get_ei_abiversion methods.

gold/
* dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and
get_ei_abiversion methods.
* incremental.cc (make_sized_incremental_binary): Likewise.
* object.cc (Sized_relobj_file::Sized_relobj_file): Likewise.
(make_elf_sized_object): Likewise.
* object.h (class Osabi): Make the class untemplated.

3 years agogold: Add missing ChangeLog entries for commit ff4bc37d7
H.J. Lu [Tue, 15 Dec 2020 15:37:59 +0000 (07:37 -0800)] 
gold: Add missing ChangeLog entries for commit ff4bc37d7

3 years agoHighlight deprecated commands using title style
Tom Tromey [Tue, 15 Dec 2020 15:07:32 +0000 (08:07 -0700)] 
Highlight deprecated commands using title style

After Andrew's latest patch, I noticed that the deprecation warnings
could use the (so-called) title style when printing command names.
This patch implements this idea.

gdb/ChangeLog
2020-12-15  Tom Tromey  <tromey@adacore.com>

* cli/cli-decode.c (deprecated_cmd_warning): Use title style for
command names.

gdb/testsuite/ChangeLog
2020-12-15  Tom Tromey  <tromey@adacore.com>

* gdb.base/style.exp: Add deprecation tests.

3 years agoPR27071, gas bugs uncovered by fuzzing
Alan Modra [Tue, 15 Dec 2020 11:24:09 +0000 (21:54 +1030)] 
PR27071, gas bugs uncovered by fuzzing

PR 27071
* config/obj-elf.c (elf_obj_symbol_clone_hook): New function.
(elf_format_ops): Set symbol_clone_hook.
* config/obj-elf.h (elf_obj_symbol_clone_hook): Declare.
(obj_symbol_clone_hook): Define.
* listing.c (buffer_line): Avoid integer overflow on paper_width
set to zero.

3 years agoAdd support for the SDIV and UDIV instructions to the ARM simulator.
Jens Bauer [Tue, 15 Dec 2020 12:40:35 +0000 (12:40 +0000)] 
Add support for the SDIV and UDIV instructions to the ARM simulator.

* armemu.c (handle_v6_insn): Add support for SDIV and UDIV.
* thumbemu.c (handle_T2_insn): Likewise.

3 years ago[gdb/testsuite] Handle PS1 quirk in gdb.base/multi-line-starts-subshell.exp
Tom de Vries [Tue, 15 Dec 2020 09:18:23 +0000 (10:18 +0100)] 
[gdb/testsuite] Handle PS1 quirk in gdb.base/multi-line-starts-subshell.exp

On SLE-11, I run into:
...
(gdb) if 1^M
 >shell HOME=/dev/null PS1="gdb-subshell$ " /bin/sh^M
 >end^M
hostname:/dir> FAIL: gdb.base/multi-line-starts-subshell.exp: \
  spawn subshell from multi-line (timeout)
...

The problem is that the PS1 setting has no effect, due to a bug on older
openSUSE/SLE version.  The mechanism there is:
- /etc/profile sets ENV=/etc/bash.bashrc
- /bin/sh is started
- /bin/sh executes ENV, in other words /etc/bash.bashrc
- during the execution of /etc/bash.bashrc, PS1 is set unconditionally

Fix this by setting PS1 after spawning the subshell.

Tested on x86_64-linux.

2020-12-15  Tom de Vries  <tdevries@suse.de>

PR testsuite/26952
* gdb.base/multi-line-starts-subshell.exp: Set PS1 after spawning
shell.

3 years agoImplement and document -z unique / -z nounique handling in gold
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:55 +0000 (17:25 +0000)] 
Implement and document -z unique / -z nounique handling in gold

* layout.cc (Layout::finish_dynamic_section): Set DF_GNU_1_UNIQUE.
* options.h (class General_options): Handle -z unique, -z nounique.

3 years agoDefine DT_GNU_FLAGS_1 and DF_GNU_1_UNIQUE for gold
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:54 +0000 (17:25 +0000)] 
Define DT_GNU_FLAGS_1 and DF_GNU_1_UNIQUE for gold

* elfcpp.h (enum DT): New enum member DT_GNU_FLAGS_1.
(enum DF_GNU_1): New enum DF_GNU_1 containing DF_GNU_1_UNIQUE.

3 years agoHandle DT_GNU_FLAGS_1 in readelf
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:53 +0000 (17:25 +0000)] 
Handle DT_GNU_FLAGS_1 in readelf

* readelf.c (get_dynamic_type): Handle DT_GNU_FLAGS_1.
(process_dynamic_section): Likewise.

3 years agoDocument -z unique/-z nounique in the ld man page and help output
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:52 +0000 (17:25 +0000)] 
Document -z unique/-z nounique in the ld man page and help output

* ld.texi (Options): Document -z unique and -z nounique.
* lexsup.c (elf_shlib_list_options): Likewise.

3 years agoHandle -z unique/-z nounique in ld
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:51 +0000 (17:25 +0000)] 
Handle -z unique/-z nounique in ld

Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.

bfd/
* elflink.c (bfd_elf_size_dynamic_sections): Call
_bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section.
include/
* bfdlink.h (struct bfd_link_info): New field gnu_flags_1.
ld/
* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
Parse -z unique / -z nounique options.

3 years agoDefine a new DT_GNU_FLAGS_1 dynamic section for ld, readelf et al
Vivek Das Mohapatra [Mon, 14 Dec 2020 17:25:50 +0000 (17:25 +0000)] 
Define a new DT_GNU_FLAGS_1 dynamic section for ld, readelf et al

DT_GNU_FLAGS_1 added to the DT_VALRNGLO-DT_VALRNGHI range.
DT_GNU_FLAGS_1 value DF_GNU_1_UNIQUE added.

* elf/common.h (DT_GNU_FLAGS_1, DF_GNU_1_UNIQUE): Define.

3 years agogdb/testsuite: fix typo in gdb_test_multiple doc
Simon Marchi [Tue, 15 Dec 2020 04:45:17 +0000 (23:45 -0500)] 
gdb/testsuite: fix typo in gdb_test_multiple doc

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_test_multiple): Fix typo in doc.

Change-Id: Ieb188b3382395ce951bfba5a5f25aaea0f89ebf9

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 15 Dec 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoKeep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD...
Cary Coutant [Mon, 14 Dec 2020 23:46:47 +0000 (15:46 -0800)] 
Keep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD ELFOSABIs.

2020-12-14  H.J. Lu  <hjl.tools@gmail.com>
    Cary Coutant  <ccoutant@gmail.com>

elfcpp/
PR gold/27039
* elfcpp.h (SHF): Add SHF_GNU_RETAIN.

gold/
     PR gold/27039
* layout.cc (Layout::layout): Strip SHF_GNU_RETAIN.
* object.cc (Sized_relobj_file::Sized_relobj_file): Initialize osabi_.
(Sized_relobj_file::do_layout): Keep SHF_GNU_RETAIN sections for
GNU/FreBSD ELFOSABIs.
* object.h (Osabi) New class.
(Sized_relobj_file): Add osabi() and osabi_.
* testsuite/Makefile.am (check_SCRIPTS): Add retain.sh.
(check_DATA): Add retain_1.out retain_2.out.
(MOSTLYCLEANFILES): Add retain_1 retain_2.
(retain_1.out): New target.
(retain_1): Likewise.
(retain_1.o): Likewise.
(retain_2.out): Likewise.
(retain_2): Likewise.
(retain_2.o): Likewise.
* testsuite/Makefile.in: Regenerate.
* testsuite/retain.sh: New file.
* testsuite/retain_1.s: Likewise.
* testsuite/retain_2.s: Likewise.

3 years agoAdd form used for SPECIAL_expr as comment in testsuite Dwarf Assembler
Mark Wielaard [Mon, 14 Dec 2020 19:00:50 +0000 (20:00 +0100)] 
Add form used for SPECIAL_expr as comment in testsuite Dwarf Assembler

Replace the "SPECIAL_expr" comment with either "DW_FORM_block" or
"DW_FORM_exprloc" in the abbrev.

gdb/testsuite/ChangeLog:

* lib/dwarf.exp (Dwarf::_handle_attribute): Handle SPECIAL_expr
specially, set attr_form_comment to the actual FORM string used.

3 years agoUse DW_FORM_exprloc in testsuite Dwarf Assembler for DWARF version 4+.
Mark Wielaard [Mon, 14 Dec 2020 16:38:09 +0000 (17:38 +0100)] 
Use DW_FORM_exprloc in testsuite Dwarf Assembler for DWARF version 4+.

Since DWARF version 4 expressions are represented by DW_FORM_exprloc
instead of a block form. Support this in the testsuite Dwarf Assembler
by setting the SPECIAL_expr form once we know the CU version.

This doesn't change any testsuite results, it just makes the produced
DWARF valid. gdb also accepts expressions in block form for DWARF
version 4 and above, but this is technically incorrect.

gdb/testsuite/ChangeLog:

* lib/dwarf.exp (Dwarf::_read_constants): Don't set
_constants(SPECIAL_expr) here, but set it...
(Dwarf::cu): ...here based on _cu_version.

3 years ago[gdb/testsuite] Don't pass -fPIC to gdb_compile_shlib
Tom de Vries [Mon, 14 Dec 2020 17:16:40 +0000 (18:16 +0100)] 
[gdb/testsuite] Don't pass -fPIC to gdb_compile_shlib

When running test-case gdb.base/info-shared.exp, I see in gdb.log:
...
Executing on host: \
  gcc ... -fPIC -fpic -c -o info-shared-solib1.c.o info-shared-solib1.c
...

The -fPIC comes from the test-case:
...
if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
         [list additional_flags=-fPIC]] != "" } {
...
but the -fpic, which overrides the -fPIC comes from gdb_compile_shlib.

The proc gdb_compile_shlib adds the -fpic or similar dependent on platform
and compiler.  However, in some cases it doesn't add anything, which is
probably why all those test-case pass -fPIC.

Fix this by removing -fPIC from all the calls to gdb_compile_shlib, and
ensuring that gdb_compile_shlib takes care of adding it, if required.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-14  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_compile_shlib): Make sure it's not necessary to
pass -fPIC.
* gdb.ada/catch_ex_std.exp: Don't pass -fPIC to gdb_compile_shlib.
* gdb.base/break-probes.exp: Same.
* gdb.base/ctxobj.exp: Same.
* gdb.base/dso2dso.exp: Same.
* gdb.base/global-var-nested-by-dso.exp: Same.
* gdb.base/info-shared.exp: Same.
* gdb.base/jit-reader-simple.exp: Same.
* gdb.base/print-file-var.exp: Same.
* gdb.base/skip-solib.exp: Same.
* gdb.btrace/dlopen.exp: Same.

3 years agoDo not manually dissect OP_TYPE operations
Tom Tromey [Mon, 14 Dec 2020 16:43:20 +0000 (09:43 -0700)] 
Do not manually dissect OP_TYPE operations

Some code in GDB will examine the structure of an expression to see if
it starts with OP_TYPE, and then proceed to extract the type by hand.

There is no need to do this dissection manually.  evaluate_type does
the same thing via an "allowed" API.

This patch changes such code to use evaluate_type.  In two cases this
simplifies the code.

Regression tested on x86-64 Fedora 28.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tom@tromey.com>

* dtrace-probe.c (dtrace_process_dof_probe): Use value_type.
* typeprint.c (whatis_exp): Always use evaluate_type.
(maintenance_print_type): Likewise.  Simplify.

3 years ago[gdb/testsuite] Handle missing xz in gdb.base/gnu-debugdata.exp
Tom de Vries [Mon, 14 Dec 2020 16:05:11 +0000 (17:05 +0100)] 
[gdb/testsuite] Handle missing xz in gdb.base/gnu-debugdata.exp

When running test-case gdb.base/gnu-debugdata.exp on SLE-11, I run into:
...
FAIL: gdb.base/gnu-debugdata.exp: xz
...

The fact that xz is not installed does not mean there's a fail, merely that
the test is unsupported.

Fix this by detecting the "spawn failed" reply in run_on_host and issuing
UNSUPPORTED instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-14  Tom de Vries  <tdevries@suse.de>

PR testsuite/26963
* lib/gdb.exp (run_on_host): Declare test unsupported if spawn fails.

3 years ago[gdb/testsuite] Handle no glibc debuginfo in gdb.base/solib-corrupted.exp
Tom de Vries [Mon, 14 Dec 2020 16:05:11 +0000 (17:05 +0100)] 
[gdb/testsuite] Handle no glibc debuginfo in gdb.base/solib-corrupted.exp

When running test-case gdb.base/solib-corrupted.exp on SLE-11, I get:
...
(gdb) PASS: gdb.base/solib-corrupted.exp: normal list
p/x _r_debug->r_map->l_next = _r_debug->r_map^M
'_r_debug' has unknown type; cast it to its declared type^M
(gdb) FAIL: gdb.base/solib-corrupted.exp: make solibs looping
...

The reason that _r_debug has unknown type is that glibc debuginfo is not
installed.  The test-case attempts to detect this but doesn't handle this
particular error string.

Fix this by adding the "unknown type" line to the regexp detecting missing
glibc debuginfo.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-14  Tom de Vries  <tdevries@suse.de>

PR testsuite/26962
* gdb.base/solib-corrupted.exp: Handle "'_r_debug' has unknown type;
cast it to its declared type".

3 years ago[gdb/testsuite] Handle shell prompt in batch-preserve-term-settings.exp
Tom de Vries [Mon, 14 Dec 2020 16:05:11 +0000 (17:05 +0100)] 
[gdb/testsuite] Handle shell prompt in batch-preserve-term-settings.exp

On SLE-11, I run into:
...
FAIL: gdb.base/batch-preserve-term-settings.exp: batch run: spawn shell \
  (timeout)
...

The problem is that the shell prompt has PS1="\h:\w> ", but the test expects
a shell prompt ending in a space preceded by either '$' or '#':
...
set shell_prompt_re "\[$#\] "
...

We could easily fix this by adding '>' to shell_prompt_re, but this wouldn't
work for other PS1 setting.

Fix this instead by setting the shell prompt to "gdb-subshell$ " (as in
gdb.base/multi-line-starts-subshell.exp).

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-14  Tom de Vries  <tdevries@suse.de>

PR testsuite/26951
* gdb.base/batch-preserve-term-settings.exp: Use "gdb-subshell$ " as
shell prompt.

3 years agoHandle block-local names for Ada
Tom Tromey [Mon, 14 Dec 2020 15:14:06 +0000 (08:14 -0700)] 
Handle block-local names for Ada

GNAT can generate a mangled name with "B_N" (where N is a number) in
the middle, like "hello__B_1__fourth.0".  This is used for names local
to a block.  Multiple levels of block-local name can also occur, a
possibility that was neglected by v1 of this patch.  This patch
changes gdb to handle these names.

The wild name matcher is updated a straightforward way.  The full
matcher is rewritten.  The hash function is updated to ensure that
this works.

This version does not seem to have the performance problems that
affected v1.  In particular, the previously-slow "bt" problem has been
fixed.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* dictionary.c (language_defn::search_name_hash): Ignore "B".
* ada-lang.c (advance_wild_match): Ignore "B".
(full_match): Remove.
(do_full_match): Rewrite.

gdb/testsuite/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* gdb.ada/nested.exp: Add new tests.
* gdb.ada/nested/hello.adb (Fourth, Fifth): New procedures.

3 years agoUse exact match in get_var_value
Tom Tromey [Mon, 14 Dec 2020 15:14:06 +0000 (08:14 -0700)] 
Use exact match in get_var_value

get_var_value is only used when an exact match is needed.  This
changes this function to ensure this sort of matching is done.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (get_var_value): Only consider exact matches.

3 years agoBe more careful when rewriting thick pointer array type
Tom Tromey [Mon, 14 Dec 2020 14:42:23 +0000 (07:42 -0700)] 
Be more careful when rewriting thick pointer array type

To handle thick pointers with -fgnat-encodings=minimal, gdb will
rewrite the underlying array type to remove the bounds.  However, if
the same DWARF type is used both for a thick pointer and for an
ordinary array, this will have the side effect of removing the bounds
from the array.  This breaks the printing of objects of this type.

This patch fixes the problem by copying the array type, its range, and
its bounds.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (rewrite_array_type): New function.
        (quirk_ada_thick_pointer_struct): Use rewrite_array_type.

gdb/testsuite/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* gdb.dwarf2/ada-thick-pointer.exp: New file.

3 years agoHandle fixed-point division by zero
Tom Tromey [Mon, 14 Dec 2020 14:35:45 +0000 (07:35 -0700)] 
Handle fixed-point division by zero

fixed_point_binop did not account for division by zero.  This would
lead to gdb getting SIGFPE and subsequently cause some test cases to
hang.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* valarith.c (fixed_point_binop): Call error on division by zero.

gdb/testsuite/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

* gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero.

3 years agoAdd a plugin for processing static library dependencies.
Howard Chu [Mon, 14 Dec 2020 14:26:11 +0000 (14:26 +0000)] 
Add a plugin for processing static library dependencies.

* libdep_plugin.c: New file: Processes archives that contain a
special library dependencies element.
* Makefile.am: Add build rules for libdep_plugin.
* Makefile.in: Regenerate.
* NEWS: Mention the new plugin.
* ld.texi: Document the new plugin.

3 years agoPut bfd_section_from_shdr loop detection array in elf_tdata
Alan Modra [Mon, 14 Dec 2020 09:06:47 +0000 (19:36 +1030)] 
Put bfd_section_from_shdr loop detection array in elf_tdata

The static variables used by bfd_section_from_shdr to detect loops
in ELF sections have a problem:  Comparing a BFD pointer doesn't
guarantee that the current bfd is the same as the one previously used
to allocate the sections_being_created array.  For example, doing
   size bad_elf_1 bad_elf_2
with two corrupted ELF files containing section loops will leave the
section_being_created array allocated for the first file and since
bfd_close is called for bad_elf_1 before bfd_elf_2 is opened, it is
possible that the BFD for the second file is allocated in the same
memory as the first file.  If bad_elf_2 has more sections than
bad_elf_1 then we might write beyond the end of the array.

So this patch implements the FIXME Nick put in a comment about
attaching the array to the BFD.

* elf-bfd.h (struct elf_obj_tdata): Add being_created.
* elf.c (bfd_section_from_shdr): Delete static vars for loop
detection.  Use new tdata variable instead.
* elfcode.h (elf_object_p): Allocate being_created.

3 years agoPR26836, memory leak in parse_args
Alan Modra [Mon, 14 Dec 2020 09:04:20 +0000 (19:34 +1030)] 
PR26836, memory leak in parse_args

PR 26836
* lexsup.c (parse_args): Free really_longopts, longopts and
shortopts.

3 years agoFix a use of an uninitialised variable in the bfd linker.
Nick Clifton [Mon, 14 Dec 2020 12:40:13 +0000 (12:40 +0000)] 
Fix a use of an uninitialised variable in the bfd linker.

PR 27050
* lexsup.c (parse_args): Ensure that the longind local variable is
set.

3 years agoSolaris 11.4 ld build failure
Alan Modra [Mon, 14 Dec 2020 01:14:43 +0000 (11:44 +1030)] 
Solaris 11.4 ld build failure

/usr/include/sys/mman.h:81:0: note: this is the location of the previous definition
 #define SHARED  0x10

PR 27064
* deffilep.y (SHARED_K): Rename from SHARED.  Update uses.

3 years agorx-elf FAIL: SHF_GNU_RETAIN sections 27
Alan Modra [Sun, 13 Dec 2020 23:27:55 +0000 (09:57 +1030)] 
rx-elf FAIL: SHF_GNU_RETAIN sections 27

rx-elf is an odd target with non-standard names for default text, data
and bss sections.  This patch tweaks a new test to make it pass.

* testsuite/gas/elf/section27.s: Reorder .text, .data and .bss
so that output section order does not depend on those sections
being already created.  Use ".section .text" rather than ".text".

3 years agosim/mips/cp1.c: Include <stdlib.h> for abort() declaration
Pavel I. Kryukov [Mon, 14 Dec 2020 03:02:05 +0000 (07:02 +0400)] 
sim/mips/cp1.c: Include <stdlib.h> for abort() declaration

sim/mips/ChangeLog:

* cp1.c: Include <stdlib.h>

3 years agoRe-enable incremental tests that were failing with GCC 9+.
Cary Coutant [Mon, 14 Dec 2020 00:50:13 +0000 (16:50 -0800)] 
Re-enable incremental tests that were failing with GCC 9+.

gold/
PR gold/23539
PR gold/24123
* testsuite/Makefile.am (incremental_copy_test): Re-enable for GCC 9+.
(incremental_comdat_test_1): Likewise.
* testsuite/Makefile.in: Regenerate.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 14 Dec 2020 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoFix incremental tests using gcc 9, which adds Gnu properties sections.
Cary Coutant [Sun, 13 Dec 2020 23:20:10 +0000 (15:20 -0800)] 
Fix incremental tests using gcc 9, which adds Gnu properties sections.

During an incremental link, we should simply ignore the Gnu properties
sections. We were not handling them properly -- failing to process the
properties from the base file. While that could be fixed, the property
sections are meant for deployed binaries, and incremental linking is
for development, so keeping the properties sections just adds to the
likelihood of forcing a full link sooner.

gold/
PR gold/23539
* object.cc (Sized_relobj_file::layout_gnu_property_section): Ignore
Gnu properties during incremental links.

3 years agoFix incremental linking with rodata merge sections.
Cary Coutant [Sun, 13 Dec 2020 23:19:41 +0000 (15:19 -0800)] 
Fix incremental linking with rodata merge sections.

When processing the incremental update, incoming .rodata merge sections
do not match the corresponding section in the base file, because the
SHF_MERGE flag had not been masked out of the latter.

gold/
PR gold/24123
* layout.cc (Layout::init_fixed_output_section): Mask out flags that
should be ignored when matching sections.

3 years agoUpdate ELF headers and readelf with recent e_machine assignments.
Cary Coutant [Fri, 11 Dec 2020 22:05:53 +0000 (14:05 -0800)] 
Update ELF headers and readelf with recent e_machine assignments.

binutils/
* readelf.c (get_machine_name): Update list of e_machine values.

include/
* elf/common.h: Update list of e_machine values.

3 years agoConstify parse_and_eval_type
Tom Tromey [Sun, 13 Dec 2020 16:51:42 +0000 (09:51 -0700)] 
Constify parse_and_eval_type

I noticed that the argumen to parse_and_eval_type could be "const".
This patch implements this change.

I wonder if this could be removed.  It's only called via
check_stub_method_group, which seems questionable to me.  However, I
didn't look into doing this.

gdb/ChangeLog
2020-12-13  Tom Tromey  <tom@tromey.com>

* gdbtypes.c (safe_parse_type): Make argument const.
* value.h (parse_and_eval_type): Make argument const.
* eval.c (parse_and_eval_type): Make argument const.

3 years ago[gdb/testsuite] Fix gdb.base/endianity.exp with gcc-4.8
Tom de Vries [Sun, 13 Dec 2020 16:22:40 +0000 (17:22 +0100)] 
[gdb/testsuite] Fix gdb.base/endianity.exp with gcc-4.8

When running test-case gdb.base/endianity.exp using gcc-4.8, we get:
...
(gdb) x/x &o.v^M
0x7fffffffd120: 0x00000004^M
(gdb) XFAIL: gdb.base/endianity.exp: x/x &o.v
x/xh &o.w^M
0x7fffffffd124: 0x0003^M
(gdb) FAIL: gdb.base/endianity.exp: x/xh &o.w
...

The gcc 4.8 compiler does not support the scalar_storage_order attribute, so
the testcase is compiled without that attribute, and the expected results are
different.

Fix this by rather than xfailing, skipping the tests if the compiler does not
support the scalar_storage_order attribute.

Tested on x86_64-linux, with gcc-4.8, gcc-7, and clang-10.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

PR testsuite/26953
* gdb.base/endianity.exp: Skip tests requiring scalar_storage_order
attribute support if compiler doesn't support it.

3 years ago[gdb/testsuite] Handle ada in gdb_compile_shlib
Tom de Vries [Sun, 13 Dec 2020 15:25:19 +0000 (16:25 +0100)] 
[gdb/testsuite] Handle ada in gdb_compile_shlib

The single test-case in the testsuite that creates an ada shared library is
gdb.ada/catch_ex_std.exp.

The test-case does use gdb_compile_shlib, but with a few tweaks that make sure
things are properly handled for ada.

Move the ada-specific code to gdb_compile_shlib, such that gdb_compile_sh can
be used for ada shared libs without tweaks.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_compile_shlib): Handle ada.
* gdb.ada/catch_ex_std.exp: Use gdb_compile_shlib to compile from
source to shared lib.  Add ada to options.

3 years ago[gdb/testsuite] Avoid gnatbind/gnatlink in gdb.ada/catch_ex_std.exp
Tom de Vries [Sun, 13 Dec 2020 15:25:19 +0000 (16:25 +0100)] 
[gdb/testsuite] Avoid gnatbind/gnatlink in gdb.ada/catch_ex_std.exp

There's a single test-case in the testsuite that explicitly calls gnatbind and
gnatlink: gdb.ada/catch_ex_std.exp.

Instead, use gnatmake and pass specific gnatbind and gnatlink options using
gnatmake passthrough options -bargs and -largs.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

* gdb.ada/catch_ex_std.exp: Use gnatmake -bargs and -largs instead of
calling gnatbind and gnatlink.

3 years agogdb: new command 'maint flush dcache'
Andrew Burgess [Fri, 20 Nov 2020 19:34:21 +0000 (19:34 +0000)] 
gdb: new command 'maint flush dcache'

Add a new command to flush the dcache.

gdb/ChangeLog:

* NEWS: Mention new commands.
* target-dcache.c: Add 'cli/cli-cmds.h' include.
(maint_flush_dcache_command): New function.
(_initialize_target_dcache): Create new 'maint flush dcache'
command.

gdb/doc/ChangeLog:

* gdb.texinfo (Caching Target Data): Document 'maint flush
dcache'.

gdb/testsuite/ChangeLog:

* gdb.base/dcache-flush.c: New file.
* gdb.base/dcache-flush.exp: New file.

3 years agogdb: introduce new 'maint flush ' prefix command
Andrew Burgess [Fri, 20 Nov 2020 19:08:06 +0000 (19:08 +0000)] 
gdb: introduce new 'maint flush ' prefix command

We currently have two flushing commands 'flushregs' and 'maint
flush-symbol-cache'.  I'm planning to add at least one more so I
thought it might be nice if we bundled these together into one place.

And so I created the 'maint flush ' command prefix.  Currently there
are two commands:

  (gdb) maint flush symbol-cache
  (gdb) maint flush register-cache

Unfortunately, even though both of the existing flush commands are
maintenance commands, I don't know how keen we about deleting existing
commands for fear of breaking things in the wild.  So, both of the
existing flush commands 'maint flush-symbol-cache' and 'flushregs' are
still around as deprecated aliases to the new commands.

I've updated the testsuite to use the new command syntax, and updated
the documentation too.

gdb/ChangeLog:

* NEWS: Mention new commands, and that the old commands are now
deprecated.
* cli/cli-cmds.c (maintenanceflushlist): Define.
* cli/cli-cmds.h (maintenanceflushlist): Declare.
* maint.c (_initialize_maint_cmds): Initialise
maintenanceflushlist.
* regcache.c: Add 'cli/cli-cmds.h' include.
(reg_flush_command): Add header comment.
(_initialize_regcache): Create new 'maint flush register-cache'
command, make 'flushregs' an alias.
* symtab.c: Add 'cli/cli-cmds.h' include.
(_initialize_symtab): Create new 'maint flush symbol-cache'
command, make old command an alias.

gdb/doc/ChangeLog:

* gdb.texinfo (Symbols): Document 'maint flush symbol-cache'.
(Maintenance Commands): Document 'maint flush register-cache'.

gdb/testsuite/ChangeLog:

* gdb.base/c-linkage-name.exp: Update to use new 'maint flush ...'
commands.
* gdb.base/killed-outside.exp: Likewise.
* gdb.opt/inline-bt.exp: Likewise.
* gdb.perf/gmonster-null-lookup.py: Likewise.
* gdb.perf/gmonster-print-cerr.py: Likewise.
* gdb.perf/gmonster-ptype-string.py: Likewise.
* gdb.python/py-unwind.exp: Likewise.

3 years agox86: Do not dump DS/CS segment overrides for branch hints
Borislav Petkov [Fri, 11 Dec 2020 23:12:24 +0000 (00:12 +0100)] 
x86: Do not dump DS/CS segment overrides for branch hints

I've made all labels normal labels so that there's no confusion between
the different targets which is which and I match them in the .d files
with .* as Alan suggested.

Hex offsets I match with [0-9a-fx]+ since some targets prefix them with
0x, some don't, etc.

* testsuite/gas/i386/align-branch-9.s: Don't use labels that are
automatically local for ELF targets.
* testsuite/gas/i386/branch.s: Likewise.
* testsuite/gas/i386/x86-64-align-branch-9.s: Likewise.
* testsuite/gas/i386/x86-64-branch.s: Likewise.
* testsuite/gas/i386/align-branch-9.d: Adjust to match more targets.
* testsuite/gas/i386/branch.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-9.d: Likewise.
* testsuite/gas/i386/x86-64-branch.d: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 13 Dec 2020 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 12 Dec 2020 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: improve the warning given for deprecated aliases with a prefix
Andrew Burgess [Thu, 10 Dec 2020 16:03:31 +0000 (16:03 +0000)] 
gdb: improve the warning given for deprecated aliases with a prefix

Consider this GDB session:

  (gdb) define set xxx_yyy
  Type commands for definition of "set xxx_yyy".
  End with a line saying just "end".
  >echo in set xxx_yyy command\n
  >end
  (gdb) alias set qqq_aaa=set xxx_yyy
  (gdb) maintenance deprecate set qqq_aaa
  (gdb) set qqq_aaa
  Warning: 'qqq_aaa', an alias for the command 'xxx_yyy' is deprecated.
  No alternative known.

  in set xxx_yyy command
  (gdb)

Notice the warning mentions 'qqq_aaa' and 'xxx_yyy', I consider this
to be wrong.  I think the proper warning should read:

  (gdb) set qqq_aaa
  Warning: 'set qqq_aaa', an alias for the command 'set xxx_yyy', is deprecated.
  No alternative known.

With the 'set' prefixes added and a comma before the final 'is
deprecated'.  That is what this patch does.  The expected results are
updated as needed.

gdb/ChangeLog:

* cli/cli-decode.c (deprecated_cmd_warning): Ignore the prefix
result from lookup_cmd_composition_1, use the prefixes from both
the command and the alias instead.
(lookup_cmd_composition_1): Initial prefix command is the based on
the search list being passed in.  Simplify the logic for tracking
the prefix command.  Replace a use of alloca with a local
std::string.

gdb/testsuite/ChangeLog:

* gdb.base/commands.exp: Update expected results.

3 years agogdb: make deprecated_cmd_warning i18n friendly
Andrew Burgess [Thu, 10 Dec 2020 14:47:18 +0000 (14:47 +0000)] 
gdb: make deprecated_cmd_warning i18n friendly

Rewrite deprecated_cmd_warning to be i18n friendly.  While I'm going
through the function I also cleaned up some whitespace issues,
replaced uses of NULL with nullptr, and moved some comments to avoid
having to add { ... }.

Though the message being printed has a 'Warning: ' prefix I could have
changed from using printf_filtered to use warning, however, I haven't
done that in this commit as that would change what GDB outputs and I
wanted this commit NOT to change the output.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* cli/cli-decode.c (deprecated_cmd_warning): Use nullptr instead
of NULL.  Don't print message piece by piece, but sentence at a
time to allow internationalisation.  Some whitespace cleanup.

3 years agogdb: give deprecated command warning for aliases with a prefix
Andrew Burgess [Thu, 10 Dec 2020 13:19:40 +0000 (13:19 +0000)] 
gdb: give deprecated command warning for aliases with a prefix

I noticed that deprecated aliases that have a prefix don't give a
deprecated command warning.  For example looking in mi/mi-main.c we
see this:

  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &setlist);
  deprecate_cmd (c, "set mi-async");
  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &showlist);
  deprecate_cmd (c, "show mi-async");

So both 'set target-async' and 'show target-async' are deprecated and
should be giving a warning, however, in use we see no warning given.

This is a consequence of how the code that should give this
warning (deprecated_cmd_warning) performs a second command lookup in
order to distinguish between aliases and real commands, and that the
code that calls this (lookup_cmd_1) strips off prefix commands as it
calls itself recursively.

As a result when we are considering an alias like 'set target-async'
we first enter lookup_cmd_1 with text = "set target-async", we spot
the 'set' command prefix and then recursively call lookup_cmd_1 with
text = "target-async".

We spot that 'target-async' is a known alias but that it is
deprecated, and so call deprecated_cmd_warning passing in the value of
text, which remember is now "target-async".

In deprecated_cmd_warning we again perform a command lookup starting
from the top-level cmdlist, but now we're trying to find just
"target-async", this fails (as this command requires the 'set' prefix,
and so no warning is given.

I resolved this issue by passing a command list to the function
deprecated_cmd_warning, this is the list in which the command can be
found.

A new test is added to cover this case.

However, there is an additional problem which will be addressed in a
subsequent patch.

Consider this GDB session:

  (gdb) define set xxx_yyy
  Type commands for definition of "set xxx_yyy".
  End with a line saying just "end".
  >echo in set xxx_yyy command\n
  >end
  (gdb) alias set qqq_aaa=set xxx_yyy
  (gdb) maintenance deprecate set qqq_aaa
  (gdb) set qqq_aaa
  Warning: 'qqq_aaa', an alias for the command 'xxx_yyy' is deprecated.
  No alternative known.

  in set xxx_yyy command
  (gdb)

Notice the warning mentions 'qqq_aaa' and 'xxx_yyy', I consider this
to be wrong.  I think the proper warning should read:

  (gdb) set qqq_aaa
  Warning: 'set qqq_aaa', an alias for the command 'set xxx_yyy' is deprecated.
  No alternative known.

With the 'set' prefixes added.  A later patch will resolve this
issue.

gdb/ChangeLog:

PR cli/15104
* cli/cli-decode.c (lookup_cmd_1): Pass command list to
deprecated_cmd_warning.
(deprecated_cmd_warning): Take extra parameter, call
lookup_cmd_composition_1 and pass new parameter through.
(lookup_cmd_composition_1): New function, takes implementation of
lookup_cmd_composition but with extra parameter.
(lookup_cmd_composition): Now calls lookup_cmd_composition_1
passing in cmdlist.
* command.h (deprecated_cmd_warning): Add extra parameter to
declaration.
* top.c (execute_command): Pass cmdlist to deprecated_cmd_warning.

gdb/testsuite/ChangeLog:

PR cli/15104
* gdb.base/commands.exp: Add additional tests.
* gdb.base/completion.exp: Add additional tests.

3 years agogdb: don't warn about deprecated aliases during tab completion
Andrew Burgess [Tue, 8 Dec 2020 17:32:34 +0000 (17:32 +0000)] 
gdb: don't warn about deprecated aliases during tab completion

Consider this gdb session, where on line #3 tab completion is used:

  (gdb) alias xxx_yyy_zzz=break
  (gdb) maint deprecate xxx_yyy_zzz
  (gdb) xxx_yyy_<TAB>

The third line then updates to look like this:

  (gdb) xxx_yyy_Warning: 'xxx_yyy_zzz', an alias for the command 'break' is deprecated.
  No alternative known.

  zzz

What's happened is during tab completion the alias has been resolved
to the actual command being aliased, and at this stage the warning is
issued.  Clearly this is not what we want during tab completion.

In this commit I add a new parameter to the lookup function, a boolean
that indicates if the lookup is being done as part of completion.
This flag is used to suppress the warning.  Now we get the expected
behaviour, the alias completes without any warning, but the warning is
still given once the user executes the alias.

gdb/ChangeLog:

* cli/cli-decode.c (lookup_cmd_1): Move header comment into
command.h, add extra parameter, and use this to guard giving a
warning.
* command.h (lookup_cmd_1): Add comment from cli/cli-decode.c,
include argument names in declaration, add new argument.
* completer.c (complete_line_internal_1): Remove unneeded
brackets, pass extra argument to lookup_cmd_1.

gdb/testsuite/ChangeLog:

* gdb.base/completion.exp: Add additional tests.

3 years agogdbsupport: make use of safe-ctype functions from libiberty
Andrew Burgess [Fri, 20 Nov 2020 17:23:03 +0000 (17:23 +0000)] 
gdbsupport: make use of safe-ctype functions from libiberty

Make use of the safe-ctype replacements for the standard ctype
character checking functions in gdbsupport/common-utils.cc.  The
gdbsupport library is included into both gdb and gdbserver, and on the
gdbserver side there are two targets, gdbserver itself, and also
libinproctrace.so.

libiberty was already being included in the gdbserver link command,
but was missing from the libinproctrace.so link.  As a result, after
changing gdbsupport/common-utils.cc to depend on libiberty,
libinproctrace.so would no longer link until I modified its link line.

gdbserver/ChangeLog:

* Makefile.in (IPA_LIB): Include libiberty library.

gdbsupport/ChangeLog:

* gdbsupport/common-utils.cc: Change 'ctype.h' include to
'safe-ctype.h'.
(extract_string_maybe_quoted): Use safe-ctype function versions.
(is_digit_in_base): Likewise.
(digit_to_int): Likewise.
(strtoulst): Likewise.
(skip_spaces): Likewise.
(skip_to_space): Likewise.

3 years agogdb: make debug_infrun a bool
Simon Marchi [Fri, 11 Dec 2020 19:02:52 +0000 (14:02 -0500)] 
gdb: make debug_infrun a bool

gdb/ChangeLog:

* infrun.h (debug_infrun): Make a bool.
* infrun.c (debug_infrun): Make a bool.
(_initialize_infrun): Use add_setshow_boolean_cmd to define "set
debug infrun".

Change-Id: If934106a6d3f879b93d265855eb705b1d606339a

3 years agogdb: factor out debug_prefixed_printf_cond
Simon Marchi [Fri, 11 Dec 2020 18:48:11 +0000 (13:48 -0500)] 
gdb: factor out debug_prefixed_printf_cond

The same pattern happens often to define a "debug_printf" macro:

    #define displaced_debug_printf(fmt, ...) \
      do \
        { \
          if (debug_displaced) \
     debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
        } \
      while (0)

Move this pattern behind a helper macro, debug_prefixed_printf_cond and
update the existing macros to use it.

gdb/ChangeLog:

* displaced-stepping.h (displaced_debug_printf): Use
debug_prefixed_printf_cond.
* dwarf2/read.c (dwarf_read_debug_printf): Likewise.
(dwarf_read_debug_printf_v): Likewise.
* infrun.h (infrun_debug_printf): Likewise.
* linux-nat.c (linux_nat_debug_printf): Likewise.

gdbsupport/ChangeLog:

* common-debug.h (debug_prefixed_printf_cond): New.
* event-loop.h (event_loop_debug_printf): Use
debug_prefixed_printf_cond.

Change-Id: I1ff48b98b8d1cc405d1c7e8da8ceadf4e3a17f99

3 years ago[gdb/testsuite] Update gdb.arch/i386-mpx-call.exp for -m32
Tom de Vries [Fri, 11 Dec 2020 17:26:40 +0000 (18:26 +0100)] 
[gdb/testsuite] Update gdb.arch/i386-mpx-call.exp for -m32

When running test-case gdb.arch/i386-mpx-call.exp with target board unix/-m32,
we run into:
...
(gdb) continue^M
Continuing.^M
(gdb) FAIL: gdb.arch/i386-mpx-call.exp: upper_bnd0: continue to a bnd violation
...

Let's look first for reference at -m64, where the test passes.

The test-case uses -mmpx -fcheck-pointer-bounds to generate pointer checks in
the exec.  Effectively, -fcheck-pointer-bounds modifies the calling ABI: a
call passes pointer bounds as well as arguments.  The call to upper (with
four pointer arguments and an int argument, passed in 5 registers) is modified
like this:
...
   lea    -0xa0(%rbp),%rcx
   lea    -0x80(%rbp),%rdx
   lea    -0x60(%rbp),%rsi
   lea    -0x40(%rbp),%rax
   mov    $0x0,%r8d
+  bndmov -0x110(%rbp),%bnd3
+  bndmov -0x100(%rbp),%bnd2
+  bndmov -0xf0(%rbp),%bnd1
+  bndmov -0xe0(%rbp),%bnd0
   mov    %rax,%rdi
-  callq  <upper>
+  bnd callq <upper>
...
passsing the four pointer bounds in bounds registers BND0-3.

The top-level mechanism of the test is as follows:
- run the exec to after all mallocs are done, such that all pointer variables
  are valid
- do inferior calls, similar to those present in the program

The inferior call mechanism doesn't differentiate between a call to a function
compiled with -fcheck-pointer-bounds, and one without.  It merely resets the
bound registers to all-allowed state (see amd64_push_dummy_call), to make sure
the checks don't trigger during the inferior call.  [ This is the same as what
happens when executing a call without bnd prefix when the BNDPRESERVE bit of
the BNDCFG register is set to 0, a provision for calling an instrumented
function using a non-instrumented call. ]

First, two inferior calls are done (default_run and verify_default_values)
with the bound registers unmodified by the test.  So, the memory accesses are
performed with the bounds registers set by amd64_push_dummy_call to
all-allowed, and the bounds checks do not trigger.

Then we try to do an inferior call with modified bounds registers, set to
none-allowed.  In order to do that, we set a breakpoint at *upper before
doing the inferior call.  Once we hit the breakpoint during the inferior call,
the bounds registers are set to none-allowed, and we continue expecting to run
into an triggered bounds check, which takes the shape of a sigsegv.

Back to -m32.  Here, the pointer arguments are passed in memory rather than
registers, so with -fcheck-pointer-bounds, the pointer bounds are placed in
the Bounds Table using bndstx:
...
  movl   $0x0,0x10(%eax)
  lea    -0x70(%ebp),%edx
  mov    %edx,0xc(%eax)
  lea    -0x5c(%ebp),%edx
  mov    %edx,0x8(%eax)
  lea    -0x48(%ebp),%edx
  mov    %edx,0x4(%eax)
  lea    -0x34(%ebp),%edx
  mov    %edx,(%eax)
  lea    0xc(%eax),%edx
  mov    0xc(%eax),%ecx
  bndmov -0xa8(%ebp),%bnd1
  bndstx %bnd1,(%edx,%ecx,1)
  lea    0x8(%eax),%edx
  mov    0x8(%eax),%ecx
  bndmov -0xa0(%ebp),%bnd3
  bndstx %bnd3,(%edx,%ecx,1)
  lea    0x4(%eax),%edx
  mov    0x4(%eax),%ecx
  bndmov -0x98(%ebp),%bnd1
  bndstx %bnd1,(%edx,%ecx,1)
  mov    (%eax),%edx
  bndmov -0x90(%ebp),%bnd3
  bndstx %bnd3,(%eax,%edx,1)
  bnd call 804893f <upper>
...

Again, the bounds registers are reset at the start of the inferior call by
amd64_push_dummy_call, and modified by the test-case, but neither has any
effect.  The code in upper reads the pointer bounds from the Bounds Table, not
from the bounds registers.

Note that for a test.c with an out-of-bounds access:
...
$ cat test.c
void foo (int *a) { volatile int v = a[1]; }
int main (void) { int a; foo (&a); return 0; }
$ gcc test.c -mmpx -fcheck-pointer-bounds -g -m32
$ ./a.out
Saw a #BR! status 1 at 0x804848d
...
and inferior call foo (&a) right before "bnd call foo" (at the point that the
bounds for a are setup in the bounds table) doesn't trigger a bounds violation:
...
(gdb) call foo (&a)
(gdb)
...
This is because the bounds table doesn't associate a pointer with bounds, but
rather a pair of pointer and pointer location.  So, the bound is setup for &a,
with as location the pushed argument in the frame.  The inferior call however
executes in a dummy frame, so the bound is checked for &a with as location the
pushed argument in the dummy frame, which is different, so the bounds check
doesn't trigger.

In conclusion, this is expected behaviour.

Update the test-case to not expect to override effective pointer bounds using
the bounds registers when the bounds passing is done via the Bounds Table.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-11  Tom de Vries  <tdevries@suse.de>

PR testsuite/26991
* gdb.arch/i386-mpx-call.exp: Don't expect to trigger bounds
        violations by setting bounds registers if the bounds are passed in the
        Bounds Table.

3 years agoAvoid side effects in expression lexers
Tom Tromey [Fri, 11 Dec 2020 16:59:15 +0000 (09:59 -0700)] 
Avoid side effects in expression lexers

I noticed that some of the lexers were calling write_dollar_variable
from the lexer.  This seems like a bad practice, so this patch moves
the side effects into the parsers.

I tested this by re-running gdb.fortran and gdb.modula2; the Pascal
compiler on my machine seems not to work, so I couldn't test
gdb.pascal.

I note that the type-tracking in the Pascal is also incorrect, in that
a convenience variable's type may change between parsing and
evaluation (or even during the course of evaluation).

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* p-exp.y (intvar): Remove global.
(DOLLAR_VARIABLE): Change type.
(start): Update.
(exp): Call write_dollar_variable here...
(yylex): ... not here.
* m2-exp.y (DOLLAR_VARIABLE): Change type.
(variable): Call write_dollar_variable here...
(yylex): ... not here.
* f-exp.y (DOLLAR_VARIABLE): Change type.
(exp): Call write_dollar_variable here...
(yylex): ... not here.

3 years agoAdd support for the .bss pseudo-op to the Z80 assembler.
Nick Clifton [Fri, 11 Dec 2020 16:49:38 +0000 (16:49 +0000)] 
Add support for the .bss pseudo-op to the Z80 assembler.

PR 27047
* config/tc-z80.c (s_bss): New function.
(md_pseudo_table): Add bss entry.

3 years agoinstall_variable cannot fail
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
install_variable cannot fail

I noticed that install_variable will never return false, so this patch
changes the return type to void.  I couldn't find a spot in history
where it did return false, maybe it's always been like this.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (varobj_create): Update.
(install_variable): Return void.

3 years agoUse gdbpy_ref in instantiate_pretty_printer
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Use gdbpy_ref in instantiate_pretty_printer

This changes instantiate_pretty_printer to use gdbpy_ref, removing a
call to Py_DECREF.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (instantiate_pretty_printer): Use gdbpy_ref.

3 years agoRemove varobj_clear_saved_item
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Remove varobj_clear_saved_item

One call to varobj_clear_saved_item is from the varobj destructor.
This is no longer needed, so this patch removes the call; then inlines
the function into the sole remaining caller.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (varobj_clear_saved_item): Remove.
(update_dynamic_varobj_children): Update.
(varobj::~varobj): Don't call varobj_clear_saved_item.

3 years agoChange varobj_item::value to a value_ref_ptr
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change varobj_item::value to a value_ref_ptr

This changes varobj_item::value to be a value_ref_ptr, removing some
manual management.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (install_dynamic_child, varobj_clear_saved_item)
(update_dynamic_varobj_children, create_child)
(create_child_with_value): Update.
* varobj-iter.h (struct varobj_item) <value>: Now a
value_ref_ptr.
* python/py-varobj.c (py_varobj_iter::next): Call release_value.

3 years agoChange varobj_dynamic::child_iter to unique_ptr
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change varobj_dynamic::child_iter to unique_ptr

This changes varobj_dynamic::child_iter to be a unique_ptr, removing
some manual management.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (struct varobj_dynamic) <child_iter>: Now unique_ptr.
(varobj_get_iterator): Return unique_ptr.
(update_dynamic_varobj_children, install_visualizer)
(varobj::~varobj): Update.
* python/python-internal.h (py_varobj_get_iterator): Return
unique_ptr.
* python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr.

3 years agoChange varobj_dynamic::saved_item to unique_ptr
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change varobj_dynamic::saved_item to unique_ptr

This changes varobj_dynamic::saved_item to be a unique_ptr.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (struct varobj_dynamic) <saved_item>: Now unique_ptr.
(varobj_clear_saved_item, update_dynamic_varobj_children):
Update.

3 years agoChange varobj_iter::next to return unique_ptr
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change varobj_iter::next to return unique_ptr

This changes varobj_iter::next to return a unique_ptr.  This fits in
with the ongoing theme of trying to express these ownership transfers
via the type system.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (update_dynamic_varobj_children): Update.
* varobj-iter.h (struct varobj_iter) <next>: Change return type.
* python/py-varobj.c (struct py_varobj_iter) <next>: Change return
type.
(py_varobj_iter::next): Likewise.

3 years agoC++-ify varobj iteration
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
C++-ify varobj iteration

This changes the varobj iteration code to use a C++ class rather than
a C struct with a separate "ops" structure.  The only implementation
is updated to use inheritance.  This simplifies the code quite nicely.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (update_dynamic_varobj_children, install_visualizer)
(varobj::~varobj): Update.
* varobj-iter.h (struct varobj_iter): Change to interface class.
(struct varobj_iter_ops): Remove.
(varobj_iter_next, varobj_iter_delete): Remove.
* python/py-varobj.c (struct py_varobj_iter): Derive from
varobj_iter.  Add constructor, destructor.  Rename members.
(py_varobj_iter::~py_varobj_iter): Rename from
py_varobj_iter_dtor.
(py_varobj_iter::next): Rename from py_varobj_iter_next.
(py_varobj_iter_ops): Remove.
(py_varobj_iter): Rename from py_varobj_iter_ctor.
(py_varobj_iter_new): Remove.
(py_varobj_get_iterator): Update.

3 years agoChange all_root_varobjs to take a function_view
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change all_root_varobjs to take a function_view

This changes all_root_varobjs to take a function_view.  This
simplifies some of the callers, in particular we can remove a data
type that only existed to be passed through.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.h (all_root_varobjs): Take a function_view.
* varobj.c (all_root_varobjs): Take a function_view.
(varobj_invalidate_iter): Remove unused parameter.
(varobj_invalidate): Update.
* mi/mi-cmd-var.c (struct mi_cmd_var_update): Remove.
(mi_cmd_var_update_iter): Change parameters.

3 years agoChange varobj.c:rootlist to a std::list
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Change varobj.c:rootlist to a std::list

This changes varobj.c:rootlist to be a std::list.  This lets us remove
some code.  std::list is chosen because its iterator invalidation
approach suits the all_root_varobjs API.

I considered replacing all_root_varobjs with "external iteration", but
haven't gotten around to doing so.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (struct varobj_root) <next>: Remove.
(struct vlist): Remove.
(rootlist): Now a std::list.
(install_variable, uninstall_variable, all_root_varobjs): Update.

3 years agoUse htab_t in varobj
Tom Tromey [Fri, 11 Dec 2020 16:33:36 +0000 (09:33 -0700)] 
Use htab_t in varobj

varobj.c currently has its own hash table implementation.  This patch
replaces it with htab_t, simplifying the code.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* varobj.c (VAROBJ_TABLE_SIZE): Remove.
(varobj_table): Now htab_t.
(varobj_get_handle, install_variable, uninstall_variable):
Update.
(hash_varobj, eq_varobj_and_string): New functions.
(hash_varobj): Update.

3 years agoMake bp_location derive from refcounted_object
Tom Tromey [Fri, 11 Dec 2020 16:21:53 +0000 (09:21 -0700)] 
Make bp_location derive from refcounted_object

This changes bp_location to derive from refcounted_object, introduces
a ref_ptr specialization for this type, and then changes
bpstats::bp_location_at to use that specialization.  This removes some
manual reference counting and simplifies the code.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* inline-frame.c (stopped_by_user_bp_inline_frame): Update.
* ada-lang.c (check_status_exception): Update.
* breakpoint.c (free_bp_location): Remove.
(decref_bp_location): Use bp_location_ref_policy.
(bpstats::bpstats): Don't call incref_bp_location.
(bpstats::~bpstats): Remove.
(bpstats::bpstats): Update.
(bpstat_check_watchpoint, bpstat_check_breakpoint_conditions)
(bp_location::bp_location): Update.
(incref_bp_location): Remove.
(bkpt_print_it): Update.
* breakpoint.h (class bp_location): Derive from
refcounted_object.
(struct bpstats): Remove destructor.
<bp_location_at>: Now a bp_location_ref_ptr.
<refc>: Remove.
(bp_location_ref_ptr): New typedef.
(struct bp_location_ref_policy): New.

3 years agoRemove scoped_inc_dec_ref
Tom Tromey [Fri, 11 Dec 2020 16:21:53 +0000 (09:21 -0700)] 
Remove scoped_inc_dec_ref

We can remove scoped_inc_dec_ref by changing the sole user to instead
keep a vector of thread_info_ref objects.  This removes some manual
reference counting and simplifies the code a bit.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* thread.c (class scoped_inc_dec_ref): Remove.
(tp_array_compar_ascending, tp_array_compar_descending): Change
parameter types.
(thread_apply_all_command): Use thread_info_ref.

3 years agoUse thread_info_ref in stop_context
Tom Tromey [Fri, 11 Dec 2020 16:21:53 +0000 (09:21 -0700)] 
Use thread_info_ref in stop_context

This changes stop_context to use a thread_info_ref, removing some
manual reference counting.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* infrun.c (struct stop_context) <thread>: Now a thread_info_ref.
(stop_context::stop_context): Update.
(stop_context::~stop_context): Remove.

3 years agoChange current_inferior_ to be a inferior_ref
Tom Tromey [Fri, 11 Dec 2020 16:21:53 +0000 (09:21 -0700)] 
Change current_inferior_ to be a inferior_ref

This changes current_inferior_ to be an inferior_ref, removing some
manual reference counting.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* inferior.c (current_inferior_): Change type.
(current_inferior, set_current_inferior, initialize_inferiors):
Update.

3 years agoUse thread_info_ref in enable_thread_stack_temporaries
Tom Tromey [Fri, 11 Dec 2020 16:21:53 +0000 (09:21 -0700)] 
Use thread_info_ref in enable_thread_stack_temporaries

This changes enable_thread_stack_temporaries to use a thread_info_ref,
removing some manual reference counting.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

* gdbthread.h (class enable_thread_stack_temporaries) <m_thr>:
Change type.

3 years agoHandle CPU offset for Ravenscar
Tom Tromey [Tue, 17 Nov 2020 18:25:02 +0000 (11:25 -0700)] 
Handle CPU offset for Ravenscar

The Ravenscar support assumes that the thread ID is the same as the
CPU ID that appears in the Ada task structure.  However, on some
systems, gdbserver will report thread IDs that are off by some
constant.  This can happen, e.g., with qemu in a scenario where there
is an additional (unreported) CPU in the emulation.

The Ada Ravenscar runtimes have been modified to store this offset in
a global variable.  This patch changes gdb to read this variable, when
it exists, and apply the offset to the base CPU ID.  This fixes some
crashes that otherwise occur.

2020-12-11  Tom Tromey  <tromey@adacore.com>

* ada-tasks.c (struct ada_tasks_pspace_data) <cpu_id_offset>: New
field.
(ada_get_tcb_types_info): Look for __gnat_gdb_cpu_first_id.
(read_atcb): Use cpu_id_offset.

3 years agoFix a build problem when using FreeBSD 12.
Sebastian Huber [Fri, 11 Dec 2020 13:27:45 +0000 (13:27 +0000)] 
Fix a build problem when using FreeBSD 12.

* ar.c (write_archive): Cast iostream pointer to FILE *.
* arsup.c (ar_save): Likewise.
* objcopy.c (copy_file): Likewise.

3 years ago[gdb/testsuite] Fix gdb.base/float128.exp with --with-mpfr=no
Tom de Vries [Fri, 11 Dec 2020 12:55:04 +0000 (13:55 +0100)] 
[gdb/testsuite] Fix gdb.base/float128.exp with --with-mpfr=no

When configuring gdb using --with-mpfr=no and running test-case
gdb.base/float128.exp, we run into:
...
FAIL: gdb.base/float128.exp: print large128 (GDB may be missing MPFR support!)
...

Fix this by detecting that gdb was build without mpfr using the show
configuration command, and changing the FAIL into UNSUPPORTED.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-11  Tom de Vries  <tdevries@suse.de>

PR testsuite/26954
* gdb.base/float128.exp: Detect and handle no mpfr support.

3 years agogdb/testsuite: fix race condition in gdb.multi/multi-arch-exec.exp
Simon Marchi [Fri, 11 Dec 2020 00:55:56 +0000 (19:55 -0500)] 
gdb/testsuite: fix race condition in gdb.multi/multi-arch-exec.exp

That test fails intermittently for me.  The problem is a race condition
between the exec syscall and GDB resuming threads.

The initial situation is that we have two threads, let's call them
"leader" and "other".  Leader is the one who is going to do the exec.
We stop at the breakpoint on the all_started function, so both threads
are stopped.  When resuming, GDB resumes leader first and other second.
However, between resuming the two threads, leader has time to run and do
its exec, making other disappear.  When GDB tries to resume other, it is
ino longer there.  We get some "Couldn't get registers: No such
process." messages, and the state is a bit messed up.

The issue can be triggered consistently by adding a small delay after
the resume syscall:

    diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
    index d5a062163c7..9540339a9da 100644
    --- a/gdb/inf-ptrace.c
    +++ b/gdb/inf-ptrace.c
    @@ -308,6 +308,8 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
       gdb_ptrace (request, ptid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
       if (errno != 0)
         perror_with_name (("ptrace"));
    +  for (int i = 0 ; i < 100; i++)
    +    usleep (10000);
     }

     /* Wait for the child specified by PTID to do something.  Return the

This patch is about fixing the test to avoid this, since the test is not
about testing this particular corner case.  Handling of multi-threaded
program doing execs should be improved too, but that's not the goal of
this patch.

Fix it by adding a synchronization point in the test to make sure both
threads were resumed by GDB before doing the exec.  I added two
pthread_barrier_wait calls in each thread (for a total of three).  I
think adding one call in each thread would not be enough, because this
could happen:

- both threads reach the first barrier
- the "other" thread is scheduled so has time to run and hit the second
  barrier
- the "leader" thread hits the all_started function breakpoint, causing
  both threads to be stopped by GDB
- GDB resumes the "leader" thread
- Since the "other" thread has already reached the second barrier, the
  "leader" thread is free to run past its second barrier and do the
  exec, while GDB still hasn't resumed the second one

By adding two barrier calls in each thread, I think we are good.  The test
passes consistently for me, even with the artificial delay added.

gdb/testsuite/ChangeLog:

PR gdb/24694
* gdb.multi/multi-arch-exec.c (thread_start, main): Add barrier
calls.

Change-Id: I25c8ea9724010b6bf20b42691c716235537d0e27

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 11 Dec 2020 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years ago[gdb/testsuite] Fix gdb.tui/new-layout.exp with tcl 8.5
Tom de Vries [Thu, 10 Dec 2020 22:44:49 +0000 (23:44 +0100)] 
[gdb/testsuite] Fix gdb.tui/new-layout.exp with tcl 8.5

In commit 4d91ddd342 "[gdb/testsuite] Fix unbalanced braces in
gdb.tui/new-layout.exp", I tried to fix a problem with test-case
gdb.tui/new-layout.exp when running with tcl 8.5.

However, at that point I only had access to the log containing the failure,
and unfortunately my patch turned out not to be effective.

So, finally fix this problem by guarding the problematic code with:
...
if { [tcl_version_at_least 8 6] } { ... }
...

Tested on x86_64-linux, specifically SLE-11 where I ran into the failure.

gdb/testsuite/ChangeLog:

2020-12-10  Tom de Vries  <tdevries@suse.de>

PR testsuite/26947
* gdb.tui/new-layout.exp: Don't execute tests with unbalanced curly
braces for tcl 8.5 and earlier.

3 years agoFix off-by-one error in ada_fold_name
Kevin Buettner [Tue, 8 Dec 2020 21:07:45 +0000 (14:07 -0700)] 
Fix off-by-one error in ada_fold_name

I'm seeing a libstdc++ assertion failure when running GDB's "maint selftest"
command when GDB is configured with the following CFLAGS and CXXFLAGS as
part of the configure line:

  CFLAGS='-D_GLIBCXX_DEBUG -g3 -O0' CXXFLAGS='-D_GLIBCXX_DEBUG -g3 -O0'

This is what I see when running the self tests:

(gdb) maint selftest
Running selftest aarch64-analyze-prologue.
Running selftest aarch64-process-record.
Running selftest arm-record.
Running selftest arm_analyze_prologue.
Running selftest array_view.
Running selftest child_path.
Running selftest cli_utils.
Running selftest command_structure_invariants.
Running selftest copy_bitwise.
Running selftest copy_integer_to_size.
Running selftest cp_remove_params.
Running selftest cp_symbol_name_matches.
Running selftest dw2_expand_symtabs_matching.
/usr/include/c++/11/string_view:211: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
Aborted (core dumped)

Here's a partial stack trace:

  #0  0x00007ffff6ef6262 in raise () from /lib64/libc.so.6
  #1  0x00007ffff6edf8a4 in abort () from /lib64/libc.so.6
  #2  0x00000000004249bf in std::__replacement_assert (
      __file=0xef7480 "/usr/include/c++/11/string_view", __line=211,
      __function=0xef7328 "constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::ba"...,
      __condition=0xef7311 "__pos < this->_M_len")
      at /usr/include/c++/11/x86_64-redhat-linux/bits/c++config.h:2624
  #3  0x0000000000451737 in std::basic_string_view<char, std::char_traits<char> >::operator[] (this=0x7fffffffc200, __pos=8)
      at /usr/include/c++/11/string_view:211
  #4  0x00000000004329f5 in ada_fold_name (name="function")
      at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988

And, looking at frame #4...

(top-gdb) up 4
    at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988
988 fold_buffer[i] = tolower (name[i]);
(top-gdb) p i
$1 = 8
(top-gdb) p name.size()
$2 = 8

My patch adjusts the comparison to only copy name.size() characters
from the string.  I've added a separate statement for NUL character
termination of fold_buffer[].

gdb/ChangeLog:

* ada-lang.c (ada_fold_name): Fix off-by-one error.

3 years agoRemove spurious newline on debug printf
Luis Machado [Thu, 10 Dec 2020 15:16:21 +0000 (12:16 -0300)] 
Remove spurious newline on debug printf

I noticed a spurious newline on infrun debugging output. The following patch
fixes that. I'll push as obvious.

gdb/ChangeLog:

2020-12-10  Luis Machado  <luis.machado@linaro.org>

* breakpoint.c (should_be_inserted): Don't output newline.

3 years ago[AArch64] SVE/FPSIMD fixup for big endian
Luis Machado [Wed, 18 Mar 2020 16:06:05 +0000 (13:06 -0300)] 
[AArch64] SVE/FPSIMD fixup for big endian

The FPSIMD dump in signal frames and ptrace FPSIMD dump in the SVE context
structure follows the target endianness, whereas the SVE dumps are
endianness-independent (LE).

Therefore, when the system is in BE mode, we need to reverse the bytes
for the FPSIMD data.

Given the V registers are larger than 64-bit, I've added a way for value
bytes to be set, as opposed to passing a 64-bit fixed quantity. This fits
nicely with the unwinding *_got_bytes function and makes the trad-frame
more flexible and capable of saving larger registers.

The memory for the bytes is allocated via the frame obstack, so it gets freed
after we're done inspecting the frame.

gdb/ChangeLog:

2020-12-10  Luis Machado  <luis.machado@linaro.org>

* aarch64-linux-tdep.c (aarch64_linux_restore_vreg) New function.
(aarch64_linux_sigframe_init): Call aarch64_linux_restore_vreg.
* aarch64-tdep.h (V_REGISTER_SIZE): Move to ...
* arch/aarch64.h: ... here.
* nat/aarch64-sve-linux-ptrace.c: Include endian.h.
(aarch64_maybe_swab128): New function.
(aarch64_sve_regs_copy_to_reg_buf)
(aarch64_sve_regs_copy_from_reg_buf): Adjust FPSIMD entries.
* trad-frame.c (trad_frame_reset_saved_regs): Initialize
the data field.
(TF_REG_VALUE_BYTES): New enum value.
(trad_frame_value_bytes_p): New function.
(trad_frame_set_value_bytes): New function.
(trad_frame_set_reg_value_bytes): New function.
(trad_frame_get_prev_register): Handle register values saved as bytes.
* trad-frame.h (trad_frame_set_reg_value_bytes): New prototype.
(struct trad_frame_saved_reg) <data>: New field.
(trad_frame_set_value_bytes): New prototype.
(trad_frame_value_bytes_p): New prototype.

3 years agogdb: move bfd_open_from_target_memory to gdb_bfd
Mihails Strasuns [Mon, 7 Dec 2020 19:54:03 +0000 (20:54 +0100)] 
gdb: move bfd_open_from_target_memory to gdb_bfd

This function allows to create a BFD handle using an accessible memory
range in a target memory.  It is currently contained in a JIT module but
this functionality may be of wider usefullness - for example, reading
ELF binaries contained within a core dump.

gdb/ChangeLog:
2020-12-07  Mihails Strasuns  <mihails.strasuns@intel.com>

* jit.c (mem_bfd*, bfd_open_from_target_memory): Removed.
* gdb_bfd.h (gdb_bfd_open_from_target_memory): New function.
* gdb_bfd.c (mem_bfd*, gdb_bfd_open_from_target_memory): New functions.

3 years agoRISC-V: Add sext.[bh] and zext.[bhw] pseudo instructions.
Nelson Chu [Wed, 9 Dec 2020 05:53:22 +0000 (13:53 +0800)] 
RISC-V: Add sext.[bh] and zext.[bhw] pseudo instructions.

https://github.com/riscv/riscv-asm-manual/pull/61

We aleady have sext.w, so just add sext.b, sext.h, zext.b, zext.h
and zext.w.  In a certain sense, zext.b is not a pseudo - It is an
alias of andi.  Similarly, sext.b and sext.h are aliases of other
rvb instructions, when we enable b extension; But they are pseudos
when we just enable rvi.  However, this patch does not consider the
rvb cases.  Besides, zext.w is only valid in rv64.

gas/
    * config/tc-riscv.c (riscv_ext): New function.  Use md_assemblef
    to expand the zext and sext pseudos, to give them a chance to be
    expanded into c-ext instructions.
    (macro): Handle M_ZEXTH, M_ZEXTW, M_SEXTB and M_SEXTH.
    * testsuite/gas/riscv/ext.s: New testcase.
    * testsuite/gas/riscv/ext-32.d: Likewise.
    * testsuite/gas/riscv/ext-64.d: Likewise.
include/
    * opcode/riscv.h (M_ZEXTH, M_ZEXTW, M_SEXTB, M_SEXTH.): Added.
opcodes/
    * riscv-opc.c (riscv_opcodes): Add sext.[bh] and zext.[bhw].

3 years agoRISC-V: Dump CSR according to the elf privileged spec attributes.
Nelson Chu [Tue, 8 Dec 2020 06:39:01 +0000 (14:39 +0800)] 
RISC-V: Dump CSR according to the elf privileged spec attributes.

opcodes/
    * disassemble.h (riscv_get_disassembler): Declare.
    * disassemble.c (disassembler): Changed to riscv_get_disassembler.
    * riscv-dis.c (riscv_get_disassembler): Check the elf privileged spec
    attributes before calling print_insn_riscv.
    (parse_riscv_dis_option): Same as the assembler, the priority of elf
    attributes are higher than the options.  If we find the privileged
    attributes, but the -Mpriv-spec= is different, then output error/warning
    and still use the elf attributes set.

3 years agoRISC-V: Control fence.i and csr instructions by zifencei and zicsr.
Nelson Chu [Wed, 2 Dec 2020 09:18:35 +0000 (17:18 +0800)] 
RISC-V: Control fence.i and csr instructions by zifencei and zicsr.

bfd/
    * elfxx-riscv.c (riscv_ext_dont_care_version): New function.  Return
    TRUE if we don't care the versions of the extensions.  These extensions
    are added to the subset list for special purposes, with the explicit
    versions or the RISCV_UNKNOWN_VERSION versions.
    (riscv_parse_add_subset): If we do care the versions of the extension,
    and the versions are unknown, then report errors for the non-implicit
    extensions, and return directly for the implicit one.
    (riscv_arch_str1): Do not output i extension after e, and the extensions
    which versions are unknown.
gas/
    * config/tc-riscv.c (riscv_multi_subset_supports): Handle INSN_CLASS_ZICSR
    and INSN_CLASS_ZIFENCEI.
    * testsuite/gas/riscv/march-imply-i.s: New testcase.
    * testsuite/gas/riscv/march-imply-i2p0-01.d: New testcase.  The version
    of i is less than 2.1, and zi* are supported in the chosen spec, so
    enable the fence.i and csr instructions, also output the implicit zi* to
    the arch string.
    * testsuite/gas/riscv/march-imply-i2p0-02.d: Likewise, but the zi* are
    not supported in the spec 2.2.  Enable the related instructions since
    i's version is less than 2.1, but do not output them.
    * testsuite/gas/riscv/march-imply-i2p1-01.d: New testcase.  The version
    of i is 2.1, so don't add it's implicit zi*, and disable the related
    instructions.
    * testsuite/gas/riscv/march-imply-i2p1-01.l: Likewise.
    * testsuite/gas/riscv/march-imply-i2p1-02.d: Likewise, and set the zi*
    explicitly, so enable the related instructions.
    * testsuite/gas/riscv/march-imply-i2p0.d: Removed.
    * testsuite/gas/riscv/march-imply-i2p1.d: Removed.
include/
    * opcode/riscv.h: Add INSN_CLASS_ZICSR and INSN_CLASS_ZIFENCEI.
opcodes/
    * riscv-opc.c (riscv_opcodes): Control fence.i and csr instructions by
    zifencei and zicsr.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Dec 2020 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

This page took 0.0517 seconds and 4 git commands to generate.