binutils-gdb.git
4 years agoLinker: If the type is pie the results should be an executable which entry point...
Frediano Ziglio [Tue, 22 Sep 2020 11:48:04 +0000 (12:48 +0100)]
Linker: If the type is pie the results should be an executable which entry point should be an executable entry point, not a DLL one.

* emultempl/pe.em (set_entry_point): Only use the DLL entry point
for DLLs.
* emultempl/pep.em (set_entry_point): Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 22 Sep 2020 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoUpdate the binutils documentation to make it clear the the --strip-unneeded option...
Ludovic Court?s [Mon, 21 Sep 2020 15:08:55 +0000 (16:08 +0100)]
Update the binutils documentation to make it clear the the --strip-unneeded option of objcopy and strip implies the --strip-debug option.

* doc/binutils.texi (objcopy, strip): Say that
        '--strip-unneeded' implies '--strip-debug'.

4 years agoFix sparc prologue skipping
Tom Tromey [Mon, 21 Sep 2020 13:09:10 +0000 (07:09 -0600)]
Fix sparc prologue skipping

sparc can fail at inline prologue skipping.  Andrew Burgess tracked
this down to sparc32_skip_prologue, which should use
skip_prologue_using_sal rather than its hand-rolled variant.

I don't have a good way to test this with the gdb test suite (is there
a board file for using qemu?  That would help), but it fixes a
regression in the internal AdaCore test suite.  We've had this patch
internally at AdaCore for a while, but I just now finally got around
to making sure that backing it out reintroduces the problem.

gdb/ChangeLog
2020-09-21  Tom Tromey  <tromey@adacore.com>

* sparc-tdep.c (sparc32_skip_prologue): Use
skip_prologue_using_sal.

4 years agorx-dis.c:103:3: suspicious concatenation of string literals
Alan Modra [Mon, 21 Sep 2020 08:50:58 +0000 (18:20 +0930)]
rx-dis.c:103:3: suspicious concatenation of string literals

* rx-dis.c (flag_names): Add missing comma.
(register_names, flag_names, double_register_names),
(double_register_high_names, double_register_low_names),
(double_control_register_names, double_condition_names): Remove
trailing commas.

4 years agoPR26569, R_RISCV_RVC_JUMP results in buffer overflow
Alan Modra [Wed, 16 Sep 2020 22:14:53 +0000 (07:44 +0930)]
PR26569, R_RISCV_RVC_JUMP results in buffer overflow

This patch corrects "size" and "bitsize" in R_RISCV_RVC_* reloc howtos
so that elfnn-riscv.c:perform_relocation doesn't access past the end
of a section.  I've also corrected "size" in the R_RISCV_CALL* reloc
howtos since these relocs apply to two consecutive instructions.  That
caused fallout in the assembler with complaints about "fixup not
contained within frag" due to tc-riscv.c:append_insn finishing off a
frag after the auipc insn making up a "call" macro.  Which is a little
rude since the CALL reloc also relocates the following jalr.  Fixed by
changing the frag handling a little.

I've also changed R_RISCV_ALIGN and R_RISCV_TPREL_ADD marker reloc
howtos to look like R_RISCV_NONE, and corrected dst_mask for numerous
relocs, not that it matters very much.

bfd/
PR 26569
* elfxx-riscv.c (howto_table): Correct size and bitsize of
R_RISCV_RVC_BRANCH, R_RISCV_RVC_JUMP, and R_RISCV_RVC_LUI.
Correct size for R_RISCV_TLS_DTPMOD32, R_RISCV_TLS_DTPREL32,
R_RISCV_CALL, and R_RISCV_CALL_PLT.  Make R_RISCV_TPREL_ADD and
R_RISCV_ALIGN like R_RISCV_NONE.  Correct dst_mask many relocs.
gas/
* config/tc-riscv.c (append_insn): Don't tie off frags at CALL
relocs.
(riscv_call): Tie them off after the jalr.
(md_apply_fix): Zero fx_size of RELAX fixup.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 21 Sep 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoFix mi_gdb_exit with secondary MI channels
Pedro Alves [Sun, 20 Sep 2020 14:58:26 +0000 (15:58 +0100)]
Fix mi_gdb_exit with secondary MI channels

Tests that use a secondary MI channel (i.e., either tests that call
mi_gdb_start with separate-mi-tty, or all tests when
FORCE_SEPARATE_MI_TTY=1 is specified on the make check command line),
don't close GDB correctly.

E.g., if you run gdb.mi/mi-exec-run.exp in a loop:

  while true; do make check TESTS="gdb.mi/mi-exec-run.exp"; done

you can see more than one gdb running at the same time:

  $ ps -ef | grep -v grep | grep "gdb/gdb"
  pedro      40507       1  7 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40562       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40727       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40786       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory

This commit fixes it.

gdb/testsuite/ChangeLog:

* lib/mi-support.exp (mi_uncatched_gdb_exit) Switch to the main
spawn_id before calling remote_close.  Close secondary MI channel.

4 years agoRobustify gdb.base/testenv.exp:find_env
Pedro Alves [Sun, 20 Sep 2020 14:58:09 +0000 (15:58 +0100)]
Robustify gdb.base/testenv.exp:find_env

If printing 'envp[$i]' in find_env fails, the testcase goes into an
infinite loop:

 Running /home/pedro/rocm/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.base/testenv.exp ...
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[0] ? envp[0] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[1] ? envp[1] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[2] ? envp[2] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[3] ? envp[3] : ""
 ...
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[2519] ? envp[2519] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[2520] ? envp[2520] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[2521] ? envp[2521] : ""
 ..
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[5128] ? envp[5128] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[5129] ? envp[5129] : ""
 FAIL: gdb.base/testenv.exp: test_inherit_env_var: test1: printf "var1: %s\n", envp[5130] ? envp[5130] : ""
 ...

Fix that by bailing out of the loop on failure.

gdb/testsuite/ChangeLog:

* gdb.base/testenv.exp (find_env): Bail out if printing 'envp[$i]'
fails.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 20 Sep 2020 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoUse gdb_bfd_sections in generic_load
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in generic_load

This changes generic_load to avoid bfd_map_over_sections, in favor of
iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* symfile.c (add_section_size_callback): Remove.
(load_one_section): Rename from load_section_callback.  Change
parameters.
(generic_load): Use foreach.

4 years agoUse gdb_bfd_sections in build_section_table
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in build_section_table

This changes build_section_table to avoid bfd_map_over_sections, in
favor of iteration.  In this situation it seemed simple to just remove
the helper function entirely.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* exec.c (add_to_section_table): Remove.
(build_section_table): Use foreach.

4 years agoUse gdb_bfd_sections in elf_symfile_read
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in elf_symfile_read

This changes elf_symfile_read to avoid bfd_map_over_sections, in favor
of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* elfread.c (elf_locate_sections): Change parameters.
(elf_symfile_read): Use foreach.

4 years agoUse gdb_bfd_sections in restore_command
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in restore_command

This changes restore_command to avoid bfd_map_over_sections, in favor
of iteration.  A helper data structure can also be removed by this
patch.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* cli/cli-dump.c (struct callback_data): Remove.
(restore_one_section): Rename from restore_section_callback.
Change parameters.
(restore_binary_file): Change parameters.
(restore_command): Use foreach.

4 years agoUse gdb_bfd_sections in gcore_memory_sections
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in gcore_memory_sections

This changes gcore_memory_sections to avoid bfd_map_over_sections, in
favor of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* gcore.c (make_output_phdrs): Remove 'ignored' parameter.
(gcore_copy_callback): Likewise.
(gcore_memory_sections): Use foreach.

4 years agoUse gdb_bfd_sections in ELF osabi tag sniffing
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in ELF osabi tag sniffing

This changes some ELF osabi tag-sniffing functions to avoid
bfd_map_over_sections, in favor of iteration.  I could only readily
test the generic one.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* osabi.h (generic_elf_osabi_sniff_abi_tag_sections): Update.
* osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Change
parameters.
(generic_elf_osabi_sniffer): Use foreach.
* mips-sde-tdep.c (mips_sde_elf_osabi_sniffer): Use foreach.
* arm-tdep.c (arm_elf_osabi_sniffer): Use foreach.

4 years agoUse gdb_bfd_sections in dwarf2/read.c
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in dwarf2/read.c

This changes some functions in dwarf2/read.c to avoid
bfd_map_over_sections, in favor of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (locate_dwz_sections): Change parameters.
(dwarf2_get_dwz_file): Use foreach.
(dwarf2_locate_dwo_sections): Change parameters.
(open_and_init_dwo_file): Use foreach.
(dwarf2_locate_common_dwp_sections): Change parameters.
(open_and_init_dwp_file): Use foreach.

4 years agoUse gdb_bfd_sections in symfile.c
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in symfile.c

This changes some functions in symfile.c to avoid
bfd_map_over_sections, in favor of iteration.  Some helper types can
also be removed due to this change.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* symfile.h: (find_lowest_section): Don't declare.
* symfile.c (find_lowest_section): Now static.  Change
parameters.
(struct place_section_arg): Remove.
(place_section): Change parameters.
(addr_info_make_relative): Use foreach.
(symfile_dummy_outputs): Remove.
(default_symfile_relocate): Use foreach.

4 years agoUse gdb_bfd_sections in build_objfile_section_table
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in build_objfile_section_table

This changes build_objfile_section_table to avoid
bfd_map_over_sections, in favor of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* objfiles.c (add_to_objfile_sections): Rename from
add_to_objfile_sections_full.
(add_to_objfile_sections): Remove.
(build_objfile_section_table): Use foreach.

4 years agoUse gdb_bfd_sections in get_stap_base_address
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in get_stap_base_address

This changes get_stap_base_address to avoid bfd_map_over_sections, in
favor of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* stap-probe.c (get_stap_base_address_1): Remove.
(get_stap_base_address): Use foreach.

4 years agoUse gdb_bfd_sections in gdb_bfd_close_or_warn
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in gdb_bfd_close_or_warn

This changes gdb_bfd_close_or_warn to avoid bfd_map_over_sections, in
favor of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* gdb_bfd.c (free_one_bfd_section): Remove 'abfd' and 'ignore'
parameters.
(gdb_bfd_close_or_warn): Use foreach.

4 years agoUse gdb_bfd_sections in core_target_open
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Use gdb_bfd_sections in core_target_open

This changes core_target_open to avoid bfd_map_over_sections, in favor
of iteration.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* corelow.c (add_to_thread_list): Change parameters.
(core_target_open): Use foreach.

4 years agoAdd a new overload of gdb_bfd_sections
Tom Tromey [Sat, 19 Sep 2020 17:54:49 +0000 (11:54 -0600)]
Add a new overload of gdb_bfd_sections

This adds a new overload of gdb_bfd_sections, that accepts a
gdb_bfd_ref_ptr.  This also fixes the formatting of the existing
function, since I happened to notice it was mildly off.

gdb/ChangeLog
2020-09-19  Tom Tromey  <tom@tromey.com>

* gdb_bfd.h (gdb_bfd_sections): New overload.  Fix formatting of
existing function.

4 years agogdb/fortran: Change whitespace when printing arrays
Andrew Burgess [Thu, 21 May 2020 16:35:51 +0000 (17:35 +0100)]
gdb/fortran: Change whitespace when printing arrays

This commit makes the whitespace usage when printing Fortran arrays
more consistent, and more inline with how we print C arrays.

Currently a 2 dimensional Fotran array is printed like this, I find
the marked whitespace unpleasant:

  (( 1, 2, 3) ( 4, 5, 6) )
    ^          ^        ^

After this commit the same array is printed like this:

  ((1, 2, 3) (4, 5, 6))

Which seems more inline with how we print C arrays, in the case of C
arrays we don't add extra whitespace before the first element.

gdb/ChangeLog:

* f-valprint.c (f77_print_array_1): Adjust printing of whitespace
for arrays.

gdb/testsuite/ChangeLog:

* gdb.fortran/array-slices.exp: Update expected results.
* gdb.fortran/class-allocatable-array.exp: Likewise.
* gdb.fortran/multi-dim.exp: Likewise.
* gdb.fortran/vla-type.exp: Likewise.
* gdb.mi/mi-vla-fortran.exp: Likewise.

4 years agogdb/fortran: Move Fortran expression handling into f-lang.c
Andrew Burgess [Thu, 7 May 2020 15:27:16 +0000 (16:27 +0100)]
gdb/fortran: Move Fortran expression handling into f-lang.c

The Fortran specific OP_F77_UNDETERMINED_ARGLIST is currently handled
in the generic expression handling code.  There's no reason why this
should be the case, so this commit moves handling of this into Fortran
specific files.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* eval.c: Remove 'f-lang.h' include.
(value_f90_subarray): Moved to f-lang.c.
(eval_call): Renamed to...
(evaluate_subexp_do_call): ...this, is no longer static, header
comment moved into header file.
(evaluate_funcall): Update call to eval_call.
(skip_undetermined_arglist): Moved to f-lang.c.
(fortran_value_subarray): Likewise.
(evaluate_subexp_standard): OP_F77_UNDETERMINED_ARGLIST handling
moved to evaluate_subexp_f.
(calc_f77_array_dims): Moved to f-lang.c
* expprint.c (print_subexp_funcall): New function.
(print_subexp_standard): OP_F77_UNDETERMINED_ARGLIST handling
moved to print_subexp_f, OP_FUNCALL uses new function.
(dump_subexp_body_funcall): New function.
(dump_subexp_body_standard): OP_F77_UNDETERMINED_ARGLIST handling
moved to dump_subexp_f, OP_FUNCALL uses new function.
* expression.h (evaluate_subexp_do_call): Declare.
* f-lang.c (value_f90_subarray): Moved from eval.c.
(skip_undetermined_arglist): Likewise.
(calc_f77_array_dims): Likewise.
(fortran_value_subarray): Likewise.
(evaluate_subexp_f): Add OP_F77_UNDETERMINED_ARGLIST support.
(operator_length_f): Likewise.
(print_subexp_f): Likewise.
(dump_subexp_body_f): Likewise.
* fortran-operator.def (OP_F77_UNDETERMINED_ARGLIST): Move
declaration of this operation to here.
* parse.c (operator_length_standard): OP_F77_UNDETERMINED_ARGLIST
support moved to operator_length_f.
* parser-defs.h (dump_subexp_body_funcall): Declare.
(print_subexp_funcall): Declare.
* std-operator.def (OP_F77_UNDETERMINED_ARGLIST): Moved to
fortran-operator.def.

4 years agogdb/fortran: Clean up array/string expression evaluation
Andrew Burgess [Wed, 6 May 2020 17:53:21 +0000 (18:53 +0100)]
gdb/fortran: Clean up array/string expression evaluation

This commit is a refactor of part of the Fortran array and string
handling code.

The current code is split into two blocks, linked, weirdly, with a
goto.  After this commit all the code is moved to its own function,
and arrays and strings are now handled using the same code; this will
be useful later when I want to add array stride support where strings
will want to be treated just like arrays, but is a good clean up even
without the array stride work, which is why I'm merging it now.

For now the new function is added as a static within eval.c, even
though the function is Fortran only.  A following commit will remove
some of the Fortran specific code from eval.c into one of the Fortran
specific files, including this new function.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* eval.c (fortran_value_subarray): New function, content is taken
from...
(evaluate_subexp_standard): ...here, in two places.  Now arrays
and strings both call the new function.
(calc_f77_array_dims): Add header comment, handle strings.

4 years agogdb: Update i386_analyze_prologue to skip endbr32
Victor Collod [Sat, 19 Sep 2020 00:53:02 +0000 (17:53 -0700)]
gdb: Update i386_analyze_prologue to skip endbr32

With -m32 -fcf-protection, GCC generates an `endbr32` instruction at the
function entry:

[hjl@gnu-cfl-2 gdb]$ cat /tmp/x.c
int
main(void)
{
  return 0;
}
[hjl@gnu-cfl-2 gdb]$ gcc -g -fcf-protection /tmp/x.c -m32
(gdb) b main
Breakpoint 1 at 0x8049176: file /tmp/x.c, line 3.
(gdb) r
Breakpoint 1, main () at /tmp/x.c:3
3 {
(gdb) disass
Dump of assembler code for function main:
=> 0x08049176 <+0>: endbr32
   0x0804917a <+4>: push   %ebp
   0x0804917b <+5>: mov    %esp,%ebp
   0x0804917d <+7>: mov    $0x0,%eax
   0x08049182 <+12>: pop    %ebp
   0x08049183 <+13>: ret
End of assembler dump.
(gdb)

Update i386_analyze_prologue to skip `endbr32`:

(gdb) b main
Breakpoint 1 at 0x804917d: file /tmp/x.c, line 4.
(gdb) r
Breakpoint 1, main () at /tmp/x.c:4
4   return 0;
(gdb) disass
Dump of assembler code for function main:
   0x08049176 <+0>: endbr32
   0x0804917a <+4>: push   %ebp
   0x0804917b <+5>: mov    %esp,%ebp
=> 0x0804917d <+7>: mov    $0x0,%eax
   0x08049182 <+12>: pop    %ebp
   0x08049183 <+13>: ret
End of assembler dump.
(gdb)

Tested with

$ make check RUNTESTFLAGS="--target_board='unix{-m32,}' i386-prologue-skip-cf-protection.exp"

on Fedora 32/x86-64.

2020-0X-YY  Victor Collod  <vcollod@nvidia.com>

gdb/ChangeLog:

PR gdb/26635
* i386-tdep.c (i386_skip_endbr): Add a helper function to skip endbr.
(i386_analyze_prologue): Call i386_skip_endbr.

gdb/testsuite/ChangeLog:

PR gdb/26635
* gdb.arch/amd64-prologue-skip-cf-protection.exp: Make the test
compatible with i386, and move it to...
* gdb.arch/i386-prologue-skip-cf-protection.exp: ... here.
* gdb.arch/amd64-prologue-skip-cf-protection.c: Move to...
* gdb.arch/i386-prologue-skip-cf-protection.c: ... here.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 19 Sep 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoMake target_wait options use enum flags
Tom Tromey [Fri, 18 Sep 2020 20:20:44 +0000 (14:20 -0600)]
Make target_wait options use enum flags

This changes TARGET_WNOHANG to be a member of an enum, rather than a
define, and also adds a DEF_ENUM_FLAGS_TYPE for this type.  Then, it
changes target_wait and the various target wait methods to use this
type rather than "int".

This didn't catch any bugs, but it seems like a decent cleanup
nevertheless.

I did not change deprecated_target_wait_hook, since that's only used
out-of-tree (by Insight), and there didn't seem to be a need.

I can't build some of these targets, so I modified them on a
best-effort basis.  I don't think this patch should go in before the
release branch is made.

gdb/ChangeLog
2020-09-18  Tom Tromey  <tromey@adacore.com>

* windows-nat.c (struct windows_nat_target) <wait>: Update.
(windows_nat_target::wait): Update.
* target/wait.h (enum target_wait_flag): New.  Use
DEF_ENUM_FLAGS_TYPE.
* target/target.h (target_wait): Change type of options.
* target.h (target_options_to_string, default_target_wait):
Update.
(struct target_ops) <wait>: Change type of options.
* target.c (target_wait, default_target_wait, do_option): Change
type of "options".
(target_options_to_string): Likewise.
* target-delegates.c: Rebuild.
* target-debug.h (target_debug_print_target_wait_flags): Rename
from target_debug_print_options.
* sol-thread.c (class sol_thread_target) <wait>: Update.
(sol_thread_target::wait): Update.
* rs6000-nat.c (class rs6000_nat_target) <wait>: Update.
(rs6000_nat_target::wait): Update.
* remote.c (class remote_target) <wait, wait_ns, wait_as>:
Update.
(remote_target::wait_ns, remote_target::wait_as): Change type of
"options".
(remote_target::wait): Update.
* remote-sim.c (struct gdbsim_target) <wait>: Update.
(gdbsim_target::wait): Update.
* record-full.c (class record_full_base_target) <wait>: Update.
(record_full_wait_1): Change type of "options".
(record_full_base_target::wait): Update.
* record-btrace.c (class record_btrace_target) <wait>: Update.
(record_btrace_target::wait): Update.
* ravenscar-thread.c (struct ravenscar_thread_target) <wait>:
Update.
(ravenscar_thread_target::wait): Update.
* procfs.c (class procfs_target) <wait>: Update.
(procfs_target::wait): Update.
* obsd-nat.h (class obsd_nat_target) <wait>: Update.
* obsd-nat.c (obsd_nat_target::wait): Update.
* nto-procfs.c (struct nto_procfs_target) <wait>: Update.
(nto_procfs_target::wait): Update.
* nbsd-nat.h (struct nbsd_nat_target) <wait>: Update.
* nbsd-nat.c (nbsd_wait): Change type of "options".
(nbsd_nat_target::wait): Update.
* linux-thread-db.c (class thread_db_target) <wait>: Update.
(thread_db_target::wait): Update.
* linux-nat.h (class linux_nat_target) <wait>: Update.
* linux-nat.c (linux_nat_target::wait): Update.
(linux_nat_wait_1): Update.
* infrun.c (do_target_wait_1, do_target_wait): Change type of
"options".
* inf-ptrace.h (struct inf_ptrace_target) <wait>: Update.
* inf-ptrace.c (inf_ptrace_target::wait): Update.
* go32-nat.c (struct go32_nat_target) <wait>: Update.
(go32_nat_target::wait): Update.
* gnu-nat.h (struct gnu_nat_target) <wait>: Update.
* gnu-nat.c (gnu_nat_target::wait): Update.
* fbsd-nat.h (class fbsd_nat_target) <wait>: Update.
* fbsd-nat.c (fbsd_nat_target::wait): Update.
* darwin-nat.h (class darwin_nat_target) <wait>: Update.
* darwin-nat.c (darwin_nat_target::wait): Update.
* bsd-uthread.c (struct bsd_uthread_target) <wait>: Update.
(bsd_uthread_target::wait): Update.
* aix-thread.c (class aix_thread_target) <wait>: Update.
(aix_thread_target::wait): Update.

gdbserver/ChangeLog
2020-09-18  Tom Tromey  <tromey@adacore.com>

* netbsd-low.h (class netbsd_process_target) <wait>: Update.
* netbsd-low.cc (netbsd_waitpid, netbsd_wait)
(netbsd_process_target::wait): Change type of target_options.
* win32-low.h (class win32_process_target) <wait>: Update.
* win32-low.cc (win32_process_target::wait): Update.
* target.h (class process_stratum_target) <wait>: Update.
(mywait): Update.
* target.cc (mywait, target_wait): Change type of "options".
* linux-low.h (class linux_process_target) <wait, wait_1>:
Update.
* linux-low.cc (linux_process_target::wait)
(linux_process_target::wait_1): Update.

4 years agogdb: Fix use after free bug in compile_object_run
Andrew Burgess [Fri, 18 Sep 2020 17:23:06 +0000 (18:23 +0100)]
gdb: Fix use after free bug in compile_object_run

In this commit:

  commit 6108fd1823f9cf036bbbe528ffcdf2fee489b40a
  Date:   Thu Sep 17 11:47:50 2020 -0600

      Use htab_up in type copying

A use after free bug was introduced.  In compile-object-run.c, in the
function compile_object_run, the code used to look like this:

    htab_t copied_types;

    /* .... snip .... */

    /* OBJFILE may disappear while FUNC_TYPE still will be in use.  */
    copied_types = create_copied_types_hash (objfile);
    func_type = copy_type_recursive (objfile, func_type, copied_types);
    htab_delete (copied_types);

    /* .... snip .... */

    call_function_by_hand_dummy (func_val, NULL, args,
                                 do_module_cleanup, data);

The copied_types table exists on the obstack of objfile, but is
deleted once the call to copy_type_recursive has been completed.

After the change the code now looks like this:

    /* OBJFILE may disappear while FUNC_TYPE still will be in use.  */
    htab_up copied_types = create_copied_types_hash (objfile);
    func_type = copy_type_recursive (objfile, func_type, copied_types.get ());

    /* .... snip .... */

    call_function_by_hand_dummy (func_val, NULL, args,
                                 do_module_cleanup, data);

The copied_types is now a unique_ptr and deleted automatically when it
goes out of scope.

The problem however is that objfile, and its included obstack, may be
deleted by the call to do_module_cleanup, which is called by
call_function_by_hand_dummy.

This means that in the new code the objfile, and its obstack, are
deleted before copied_types is deleted, and as copied_types is on the
objfiles obstack, we are now reading undefined memory.

The solution in this commit is to wrap the call to
create_copied_types_hash and copy_type_recursive into a new static
helper function.  The htab_up will then be deleted within the new
function's scope, before objfile is deleted.

This resolves some non-deterministic test failures I was seeing in
gdb.compile/*.exp tests.

gdb/ChangeLog:

* compile/compile-object-run.c (create_copied_type_recursive): New
function.
(compile_object_run): Use new function.

4 years agobpf: xBPF SDIV, SMOD instructions
David Faust [Fri, 18 Sep 2020 16:56:43 +0000 (09:56 -0700)]
bpf: xBPF SDIV, SMOD instructions

Add gas and opcodes support for two xBPF-exclusive ALU operations:
SDIV (signed division) and SMOD (signed modulo), and add tests for
them in gas.

cpu/
* bpf.cpu (insn-op-code-alu): Add SDIV and SMOD.
(define-alu-insn-bin, daib): Take ISAs as an argument.
(define-alu-instructions): Update calls to daib pmacro with
ISAs; add sdiv and smod.

gas/
* testsuite/gas/bpf/alu-xbpf.d: New file.
* testsuite/gas/bpf/alu-xbpf.s: Likewise.
* testsuite/gas/bpf/alu32-xbpf.d: Likewise.
* testsuite/gas/bpf/alu32-xbpf.d: Likewise.
* testuiste/gas/bpf/bpf.exp: Run new tests.

opcodes/
* bpf-desc.c: Regenerate.
* bpf-desc.h: Likewise.
* bpf-opc.c: Likewise.
* bpf-opc.h: Likewise.

4 years agosim/m32r: return register sizes after fetch and store
Andrew Burgess [Sun, 13 Sep 2020 20:48:31 +0000 (21:48 +0100)]
sim/m32r: return register sizes after fetch and store

The m32r simulator currently always returns -1 for the register size
after both a fetch and a store.  In the fetch case GDB is forgiving of
this, but in the store case GDB treats a return value of -1 as an
error.

This commit updates the m32r simulator to return a valid register size
when fetching or storing a register.  This fixes any GDB test that
writes to a register, which will include any GDB test that makes an
inferior call, for example gdb.base/break.exp.

sim/m32r/ChangeLog:

* m32r.c (m32rbf_register_size): New function.
(m32rbf_fetch_register): Use new function.
(m32rbf_store_register): Likewise.

4 years agoMention x86_64 Cygwin core file support in NEWS.
Jon Turney [Fri, 21 Aug 2020 16:16:49 +0000 (17:16 +0100)]
Mention x86_64 Cygwin core file support in NEWS.

gdb/ChangeLog:

2020-08-21  Jon Turney  <jon.turney@dronecode.org.uk>

* NEWS: Mention x86_64 Cygwin core file support.

4 years agoAdd handling for 64-bit module addresses in Cygwin core dumps
Jon Turney [Mon, 29 Jun 2020 16:11:51 +0000 (17:11 +0100)]
Add handling for 64-bit module addresses in Cygwin core dumps

Add handling for 64-bit module addresses when processing '.module' fake
sections in Cygwin core dumps.

gdb/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

* windows-tdep.c (NOTE_INFO_MODULE, NOTE_INFO_MODULE64): Define.
(core_process_module_section): Handle NOTE_INFO_MODULE64.

4 years agoPromote windows_core_xfer_shared_libraries and windows_core_pid_to_str
Jon Turney [Tue, 30 Jun 2020 15:52:41 +0000 (16:52 +0100)]
Promote windows_core_xfer_shared_libraries and windows_core_pid_to_str

Move windows_core_xfer_shared_libraries() and windows_core_pid_to_str()
to windows-tdep, and use in amd64-windows-tdep.c to handle Cygwin x86_64
core dumps.

v2:
Keep _initialize function at the bottom of the file.

gdb/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

* windows-tdep.h: Add prototypes.
* i386-windows-tdep.c(windows_core_xfer_shared_libraries): Move.
(i386_windows_core_pid_to_str): Move and rename ...
* windows-tdep.c (windows_core_xfer_shared_libraries): ... to here
(windows_core_pid_to_str): ... and here.
* amd64-windows-tdep.c (amd64_windows_init_abi_common): Register here.

4 years agoAdd amd64_windows_gregset_reg_offset
Jon Turney [Tue, 30 Jun 2020 15:37:20 +0000 (16:37 +0100)]
Add amd64_windows_gregset_reg_offset

Register a gregset_reg_offset array for Cygwin x86_64 core dump parsing
(this causes the generic i386_iterate_over_regset_sections() '.reg'
section iterator to get installed by i386_gdbarch_init()).

gdb/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

* amd64-windows-tdep.c(amd64_windows_gregset_reg_offset): Add.
(amd64_windows_init_abi_common): ... and register.

4 years agoAdd sniffer for Cygwin x86_64 core dumps
Jon Turney [Mon, 29 Jun 2020 15:20:13 +0000 (16:20 +0100)]
Add sniffer for Cygwin x86_64 core dumps

Similarly to existing i386_cygwin_core_osabi_sniffer()

gdb/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

* amd64-windows-tdep.c (amd64_cygwin_core_osabi_sniffer): New.
(_initialize_amd64_windows_tdep): Register amd64_cygwin_core_osabi_sniffer.

4 years agoFix "thread find" with multiple inferiors/targets (PR gdb/26631)
Pedro Alves [Fri, 18 Sep 2020 12:40:18 +0000 (13:40 +0100)]
Fix "thread find" with multiple inferiors/targets (PR gdb/26631)

"thread find" with multiple inferiors got broken with the multi-target
work:

 Thread 1 "gdb" hit Breakpoint 1, internal_error (...) at ../../src/gdbsupport/errors.cc:51
 51      {
 (top-gdb) bt
 #0  internal_error (file=0xffffd4d0 <error: Cannot access memory at address 0xffffd4d0>, line=0, fmt=0x555556330320 "en_US.UTF-8") at ../../src/gdbsupport/errors.cc:51
 #1  0x0000555555bca4c7 in target_thread_name (info=0x555556801290) at ../../src/gdb/target.c:2035
 #2  0x0000555555beb07a in thread_find_command (arg=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/thread.c:1959
 #3  0x000055555572ec49 in do_const_cfunc (c=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:95
 #4  0x0000555555732abd in cmd_func (cmd=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:2181
 #5  0x0000555555bf1245 in execute_command (p=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/top.c:664
 #6  0x00005555559cad10 in catch_command_errors (command=0x555555bf0c31 <execute_command(char const*, int)>, arg=0x7fffffffe082 "thread find 1", from_tty=0) at ../../src/gdb/main.c:457
 #7  0x00005555559cc33d in captured_main_1 (context=0x7fffffffdb60) at ../../src/gdb/main.c:1218
 #8  0x00005555559cc571 in captured_main (data=0x7fffffffdb60) at ../../src/gdb/main.c:1243
 #9  0x00005555559cc5e8 in gdb_main (args=0x7fffffffdb60) at ../../src/gdb/main.c:1268
 #10 0x0000555555623816 in main (argc=17, argv=0x7fffffffdc78) at ../../src/gdb/gdb.c:32

The problem is that we're not switching to the inferior/target before
calling target methods, which trips on an assertion put in place
exactly to catch this sort of problem.

gdb/testsuite/ChangeLog:

PR gdb/26631
* gdb.multi/multi-target-thread-find.exp: New file.

gdb/ChangeLog:

PR gdb/26631
* thread.c (thread_find_command): Switch inferior before calling
target methods.

4 years agoSplit gdb.multi/multi-target.exp into separate testcases
Pedro Alves [Fri, 18 Sep 2020 12:40:18 +0000 (13:40 +0100)]
Split gdb.multi/multi-target.exp into separate testcases

gdb.multi/multi-target.exp sets up a debug environment with multiple
gdbservers, multiple native processes, and multiple cores, which has
proved useful for exercising a number of multi-target scenarios.

But, as we add more tests to gdb.base/multi-target.exp, it is growing
a bit too large (making a bit cumbersome to debug) and too slow to run
(if you have glibc debug info).

This commit thus splits the multi-target.exp into several testcases,
one per use case.  The common setup code is moved to a new
multi-target.exp.tcl file that is included by all the resulting
multi-target testcases.

gdb/testsuite/ChangeLog:

* gdb.multi/multi-target-continue.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target-info-inferiors.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target-interrupt.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target-no-resumed.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target-ping-pong-next.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target.exp.tcl: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target.exp: Delete.

4 years agoEnsure that space allocated by assembler directives converts from an octet count...
Nick Clifton [Fri, 18 Sep 2020 12:28:46 +0000 (13:28 +0100)]
Ensure that space allocated by assembler directives converts from an octet count to a byte count.

PR 26556
* read.c (bss_alloc): Convert size parameter from octets to
bytes.

4 years agogdb/testsuite: Add missing expected results
Andrew Burgess [Thu, 2 Jul 2020 08:32:51 +0000 (09:32 +0100)]
gdb/testsuite: Add missing expected results

The tests in this script are driven from two lists of expected
results, one of the lists is missing some data so DejaGNU ends up
passing the empty string to gdb_test, which means the test always
passes.

This commit adds the missing expected results into the script.  The
tests still pass so there's no change in the results, but we are now
actually checking GDB's behaviour.

gdb/testsuite/ChangeLog:

* gdb.fortran/array-slices.exp: Add missing message data.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 18 Sep 2020 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb.cp/call-c.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:43 +0000 (23:33 +0100)]
gdb.cp/call-c.exp C++ify

Make the testcase work when built with a C++ compiler.

gdb/testsuite/ChangeLog:

* gdb.cp/call-c-1.c (foo) [__cplusplus]: Add extern "C".

4 years agogdb.python/py-frame-inline.exp and C++
Pedro Alves [Thu, 17 Sep 2020 22:33:43 +0000 (23:33 +0100)]
gdb.python/py-frame-inline.exp and C++

Make the testcase work when built with a C++ compiler.

gdb/testsuite/ChangeLog:

* gdb.python/py-frame-inline.exp: Adjust to optionally expect a
full prototype.

4 years agogdb.python/py-as-string.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:43 +0000 (23:33 +0100)]
gdb.python/py-as-string.exp C++ify

Make the testcase buildable with a C++ compiler.

gdb/testsuite/ChangeLog:

* gdb.python/py-as-string.c: Add cast.

4 years agogdb.base/sizeof.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:43 +0000 (23:33 +0100)]
gdb.base/sizeof.exp C++ify

Fixes:

  src/gdb/testsuite/gdb.base/sizeof.c:54:9: error: cannot initialize a variable of type 'char *' with an lvalue of type 'void *'

... when the testcase is built with a C++ compiler.

gdb/testsuite/ChangeLog:

* gdb.base/sizeof.c (fill): Add cast.

4 years agogdb.base/share-env-with-gdbserver.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:42 +0000 (23:33 +0100)]
gdb.base/share-env-with-gdbserver.exp C++ify

gdb/testsuite/ChangeLog:

* gdb.base/share-env-with-gdbserver.c (main): Add cast.

4 years agogdb.base/{prologue,symbol-alias}.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:42 +0000 (23:33 +0100)]
gdb.base/{prologue,symbol-alias}.exp C++ify

Make these testcases work when compiled as C++ programs.

These testcases use the alias attribute, which requires passing in the
target function's mangled name in C++.  To avoid having to figure out
how the functions are mangled, explicitly specify a linkage name.
This is preferred over 'extern "C"' because that doesn't work with
static functions.

gdb/testsuite/ChangeLog:

* gdb.base/prologue.c [__cplusplus] (marker): Explicitly specify
linkage name.
* gdb.base/prologue.exp: Use print /d.
* gdb.base/symbol-alias.exp: Handle C++ output.
* gdb.base/symbol-alias2.c: Handle C++ output.
[__cplusplus] (func): Explicitly specify linkage name.

4 years agogdb.python/py-nested-maps.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:42 +0000 (23:33 +0100)]
gdb.python/py-nested-maps.exp C++ify

This adjusts gdb.python/py-nested-maps.c to make it buildable as C++ program.

key_t is renamed because of:

  src/gdb/testsuite/gdb.python/py-nested-maps.c:23:8: error: definition of type 'key_t' conflicts with typedef of the same name
  struct key_t
 ^
  /usr/include/x86_64-linux-gnu/sys/types.h:121:17: note: 'key_t' declared here
  typedef __key_t key_t;
  ^

gdb/testsuite/ChangeLog:

* gdb.python/py-nested-maps.c (struct key_t): Rename to...
(struct my_key_t): ... this.  Adjust all references.
(struct value_t): Rename to ...
(struct my_value_t): ... this.  Adjust all references.
(create_map, add_map_element, create_map_map)
(add_map_map_element): Add casts.

4 years agogdb.python/{py-framefilter-mi,py-framefilter}.c C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:42 +0000 (23:33 +0100)]
gdb.python/{py-framefilter-mi,py-framefilter}.c C++ify

This adjusts:

 gdb.python/{py-framefilter-mi,py-framefilter}.c

to make them buildable as C++ programs.

gdb/testsuite/ChangeLog:

* gdb.python/py-framefilter-mi.c (funca): Add casts.
* gdb.python/py-framefilter.c.c (funca, func2): Add casts.

4 years agogdb.mi/var-cmd.c C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:41 +0000 (23:33 +0100)]
gdb.mi/var-cmd.c C++ify

This adjusts gdb.mi/var-cmd.c to make it buildable as a C++ program.

gdb/testsuite/ChangeLog:

* gdb.mi/var-cmd.c (do_anonymous_type_tests): Add cast.

4 years agogdb.base/{exprs,ptype,ptype1,setvar,whatis}.c C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:41 +0000 (23:33 +0100)]
gdb.base/{exprs,ptype,ptype1,setvar,whatis}.c C++ify

This adjusts:

 gdb.base/{exprs,ptype,ptype1,setvar,whatis}.c,

to make them buildable as C++ programs.

gdb/testsuite/ChangeLog:

* gdb.base/exprs.c: Replace 'this' with 'self' throughout.
* gdb.base/ptype.c: : Replace 'this' with 'self' throughout.
(charfoo, intfoo): Define full prototype.
* gdb.base/ptype1.c (charfoo): Define full prototype.
* gdb.base/setvar.c: Replace 'this' with 'self' throughout.
* gdb.base/whatis.c: Replace 'this' with 'self' throughout.

4 years agogdb.base/charset.{c,exp} C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:41 +0000 (23:33 +0100)]
gdb.base/charset.{c,exp} C++ify

Adjust gdb.base/charset.{c,exp} so that the testcase works when
compiled as a C++ program.

wchar_t is built-in in C++, so don't make a phony typedef.

The "print /d" is so that we also get "1" instead of "true" in C++
mode.

gdb/testsuite/ChangeLog:

* gdb.base/charset.c [__cplusplus] (wchar_t, char16_t, char32_t):
Don't define.
(utf_32_string): Compile for both C and C++.
* gdb.base/charset.exp: Use "print /d".

4 years agogdb.base/watchpoint.{c,exp}
Pedro Alves [Thu, 17 Sep 2020 22:33:41 +0000 (23:33 +0100)]
gdb.base/watchpoint.{c,exp}

Adjust gdb.base/watchpoint.c so that it can be built as a C++ program.

Fixes:
gdb compile failed, src/gdb/testsuite/gdb.base/watchpoint.c:33:16: error: initializer-string for array of chars is too long [-fpermissive]
   33 | char buf[30] = "testtesttesttesttesttesttestte";
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/gdb/testsuite/gdb.base/watchpoint.c:62:14: error: expected unqualified-id before 'nullptr'
   62 | struct foo5 *nullptr;
      |              ^~~~~~~

gdb/testsuite/ChangeLog:

* gdb.base/watchpoint.c (buf): Make it 31 bytes.
(nullptr): Rename to ...
(null_ptr): ... this.
* gdb.base/watchpoint.exp: Adjust to rename.

4 years agogdb.base/printcmds.c C++-ify
Pedro Alves [Thu, 17 Sep 2020 22:33:41 +0000 (23:33 +0100)]
gdb.base/printcmds.c C++-ify

Adjust gdb.base/printcmds.c to make it buildable as a C++ program.

gdb/testsuite/ChangeLog:

* gdb.base/printcmds.c (three, flag_enum_without_zero)
(three_not_flag): Add casts.

4 years agogdb.base/examine-backward.exp C++ify and Clang
Pedro Alves [Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)]
gdb.base/examine-backward.exp C++ify and Clang

Adjust gdb.base/examine-backward.exp to let the testcase build and run
as a C++ program, built with either G++ or Clang++.

The change to use unsigned char instead of plain char is to avoid
narrowing warnings:

  gdb compile failed, src/gdb/testsuite/gdb.base/examine-backward.c:55:1: error: narrowing conversion of '227' from 'int' to 'char' [-Wnarrowing]
     55 | };
| ^

gdb/testsuite/ChangeLog:

* gdb.base/examine-backward.c (Barrier, TestStrings): Now unsigned
char array.
(main): Add references to Barrier, TestStrings, TestStringsH and
TestStringsW.
* gdb.base/examine-backward.exp: Issue "set print asm-demangle on"
and expect a full prototype in C++.

4 years agogdb.base/nested-addr.{c,exp} C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)]
gdb.base/nested-addr.{c,exp} C++ify

Adjust gdb.base/nested-addr.exp to let the testcase build and run as a
C++ program.  "print /d" is used so we get "= 1" instead of "= true"
in C++ mode.

gdb/testsuite/ChangeLog:

* gdb.base/nested-addr.c (main): Add cast.
* gdb.base/nested-addr.exp: Use "print /d".

4 years agogdb.base/break.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)]
gdb.base/break.exp C++ify

Some adjustments to make gdb.base/break.exp work when compiled as a
C++ program.  Passes cleanly with Clang++, but not with G++.  The
latter puts a breakpoint at an unexpected line in one case.  It seems
like a bug that gcc and g++ behave differently here.

gdb/testsuite/ChangeLog:

* gdb.base/break.exp (func): New.  Use it throughout when
expecting a function name.

4 years agogdb.base/display.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)]
gdb.base/display.exp C++ify

This makes the testcase work when compiled with C++ compiler.

gdb/testsuite/ChangeLog:

* gdb.base/display.exp: Issue "set print asm-demangle on".

4 years agogdb.base/find.exp C++ify
Pedro Alves [Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)]
gdb.base/find.exp C++ify

This makes the testcase work when compiled with C++ compiler.

We need #include <string.h> for memset.

gdb/testsuite/ChangeLog:

* gdb.base/find.c: Include <string.h>.
(init_bufs): Add cast.
* gdb.base/find.exp: Issue "set print asm-demangle on".

4 years agoChange management of tdesc_arch_data
Tom Tromey [Thu, 17 Sep 2020 20:11:38 +0000 (14:11 -0600)]
Change management of tdesc_arch_data

While working on something else, I noticed that tdesc_data_cleanup
took a void* parameter.  Looking more into this, I found that
tdesc_use_registers expected a transfer of ownership.

I think it's better to express this sort of thing via the type system,
when possible.  This patch changes tdesc_data_alloc to return a unique
pointer, changes tdesc_use_registers to accept an rvalue reference,
and then adapts all the users.

Note that a deleter structure is introduced to avoid having to move
tdesc_arch_data to the header file.

2020-09-17  Tom Tromey  <tromey@adacore.com>

* tic6x-tdep.c (tic6x_gdbarch_init): Update.
* target-descriptions.h (struct tdesc_arch_data_deleter): New.
(tdesc_arch_data_up): New typedef.
(tdesc_use_registers, tdesc_data_alloc): Update.
(tdesc_data_cleanup): Don't declare.
* target-descriptions.c (tdesc_data_alloc): Return a
tdesc_arch_data_up.
(tdesc_arch_data_deleter::operator()): Rename from
tdesc_data_cleanup.  Change argument type.
(tdesc_use_registers): Change early_data to an rvalue reference.
(tdesc_use_registers): Don't use delete.
* sparc-tdep.c (sparc32_gdbarch_init): Update.
* s390-tdep.c (s390_gdbarch_init): Update.
* rx-tdep.c (rx_gdbarch_init): Update.
* rs6000-tdep.c (rs6000_gdbarch_init): Update.
* riscv-tdep.c (riscv_gdbarch_init): Update.
* or1k-tdep.c (or1k_gdbarch_init): Update.
* nios2-tdep.c (nios2_gdbarch_init): Update.
* nds32-tdep.c (nds32_gdbarch_init): Update.
* mips-tdep.c (mips_gdbarch_init): Update.
* microblaze-tdep.c (microblaze_gdbarch_init): Update.
* m68k-tdep.c (m68k_gdbarch_init): Update.
* i386-tdep.c (i386_gdbarch_init): Update.
* arm-tdep.c (arm_gdbarch_init): Update.
* arc-tdep.c (arc_tdesc_init): Update.
(arc_gdbarch_init): Update.
* aarch64-tdep.c (aarch64_gdbarch_init): Update.

4 years agoFix ctrl-c when debugging WOW64 processes
Hannes Domani [Thu, 17 Sep 2020 17:10:16 +0000 (19:10 +0200)]
Fix ctrl-c when debugging WOW64 processes

DebugBreakProcess starts a new thread in the target process with the
entry point DbgUiRemoteBreakin, where an int3 triggers a breakpoint
exception for gdb.

But this uses DbgUiRemoteBreakin of the 64bit ntdll.dll even for
WOW64 processes.
It stops in 64bit code, Wow64GetThreadContext reports a wrong pc without
the int3, and gdb lets the target process continue.

So this uses DbgUiRemoteBreakin of the 32bit ntdll.dll as the thread
entry point for WOW64 processes instead.

gdb/ChangeLog:

2020-09-17  Hannes Domani  <ssbssa@yahoo.de>

* windows-nat.c (ctrl_c_handler): Use 32bit DbgUiRemoteBreakin
for WOW64 processes.

4 years agoUse htab_up in dwarf2/read.c
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in dwarf2/read.c

This changes dwarf2/read.c to use htab_up rather than explicit calls
to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (compute_compunit_symtab_includes): Use htab_up.

4 years agoUse htab_up in type copying
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in type copying

This changes create_copied_types_hash to return an htab_up, then
modifies the callers to avoid explicit use of htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* value.c (preserve_values): Update.
* python/py-type.c (save_objfile_types): Update.
* guile/scm-type.c (save_objfile_types): Update.
* gdbtypes.h (create_copied_types_hash): Return htab_up.
* gdbtypes.c (create_copied_types_hash): Return htab_up.
* compile/compile-object-run.c (compile_object_run): Update.

4 years agoUse htab_up in typedef_hash_table
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in typedef_hash_table

This changes typedef_hash_table to use htab_up rather than explicit
calls to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* typeprint.h (class typedef_hash_table) <~typedef_hash_table>:
Remove.
<m_table>: Now htab_up.
* typeprint.c (typedef_hash_table::recursively_update)
(typedef_hash_table::add_template_parameters)
(typedef_hash_table::typedef_hash_table): Update.
(typedef_hash_table::~typedef_hash_table): Remove.
(typedef_hash_table::typedef_hash_table)
(typedef_hash_table::find_global_typedef)
(typedef_hash_table::find_typedef): Update.

4 years agoUse htab_up in target-descriptions.c
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in target-descriptions.c

This changes target-descriptions.c to use htab_up rather than explicit
calls to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* target-descriptions.c (tdesc_use_registers): Use htab_up.

4 years agoUse htab_up in linespec.c
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in linespec.c

This changes linespec.c to use htab_up rather than explicit calls to
htab_delete.  Note that a use still exists in this file, because
linespec_state hasn't been converted to have a real destructor.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* linespec.c (class decode_compound_collector)
<~decode_compound_collector>: Remove.
<m_unique_syms>: Now htab_up.
(decode_compound_collector::operator ()): Update.
(class symtab_collector) <~symtab_collector>: Remove.
<m_symtab_table>: Now htab_up.
(symtab_collector::operator ()): Update.

4 years agoUse htab_up in filename_seen_cache
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in filename_seen_cache

This changes filename_seen_cache to use htab_up, rather than explicit
calls to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* filename-seen-cache.c (filename_seen_cache::filename_seen_cache)
(filename_seen_cache::clear): Update.
(~filename_seen_cache): Remove.
(filename_seen_cache::seen): Update.
* filename-seen-cache.h (class filename_seen_cache) <m_tab>: Now
htab_up.
<~filename_seen_cache>: Remove.
<traverse>: Update.

4 years agoUse htab_up in completion_tracker
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in completion_tracker

This changes completion_tracker to use htab_up, rather than explicit
calls to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* completer.c (completion_tracker::discard_completions)
(completion_tracker::~completion_tracker)
(completion_tracker::maybe_add_completion)
(completion_tracker::remove_completion)
(completion_tracker::recompute_lowest_common_denominator)
(completion_tracker::build_completion_result): Update.
* completer.h (class completion_tracker) <have_completions>:
Update.
<m_entries_hash>: Now htab_up.

4 years agoUse htab_up in breakpoint.c
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in breakpoint.c

This changes breakpoint.c to use htab_up rather than an explicit
htab_delete.  This simplifies the code somewhat.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* breakpoint.c (ambiguous_names_p): Use htab_up.

4 years agoUse htab_up in auto-load.c
Tom Tromey [Thu, 17 Sep 2020 17:47:50 +0000 (11:47 -0600)]
Use htab_up in auto-load.c

This changes auto-load.c to use htab_up, rather than manually calling
htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

* auto-load.c (struct auto_load_pspace_info)
<~auto_load_pspace_info, auto_load_pspace_info>: Remove.
<loaded_script_files, loaded_script_texts>: Change type to
htab_up.
(~auto_load_pspace_info) Remove.
(init_loaded_scripts_info, maybe_add_script_file)
(maybe_add_script_text, auto_load_info_scripts): Update.

4 years agoMake c-exp.y:name_obstack static
Tom Tromey [Thu, 17 Sep 2020 14:06:01 +0000 (08:06 -0600)]
Make c-exp.y:name_obstack static

c-exp.y:name_obstack is not static, but should be.  This patch makes
the change.  Tested by rebuilding.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tromey@adacore.com>

* c-exp.y (name_obstack): Now static.

4 years agoSkip IFUNC relocations in debug sections ignored by ld.so. Fixes some ld test failur...
Mikael Pettersson [Thu, 17 Sep 2020 09:45:39 +0000 (10:45 +0100)]
Skip IFUNC relocations in debug sections ignored by ld.so.  Fixes some ld test failures on sparc-linux-gnu.

PR ld/18808
* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Skip IFUNC
relocations in debug sections, change abort to _bfd_error_handler.

4 years agogdb/riscv: fix decode of c.sdsp instruction
Chungyi Chi [Thu, 17 Sep 2020 08:45:50 +0000 (09:45 +0100)]
gdb/riscv: fix decode of c.sdsp instruction

The decode of c.sdsp was incorrectly claiming to be a 4-byte store
instead of an 8-byte store.

gdb/ChangeLog:

* riscv-tdep.c (riscv-insn::decode): Fix recorded insn type.

4 years agoTidy gas i386.exp
Alan Modra [Thu, 17 Sep 2020 08:02:59 +0000 (17:32 +0930)]
Tidy gas i386.exp

Possibly a quirk of my version of tcl, but I see "nm-new --help" being
run on non-x86 targets.

* testsuite/gas/i386/i386.exp: Return early if not x86.

4 years agoopcodes/csky: return the default disassembler when there is no bfd
Andrew Burgess [Wed, 16 Sep 2020 09:12:39 +0000 (10:12 +0100)]
opcodes/csky: return the default disassembler when there is no bfd

The disassembler function should return a valid disassembler function
even when there is no BFD present.  This is implied (I believe) by the
comment in dis-asm.h which says the BFD may be NULL.  Further, it
makes sense when considering that the disassembler is used in GDB, and
GDB may connect to a target and perform debugging even without a BFD
being supplied.

This commit makes the csky_get_disassembler function return the
default disassembler configuration when no bfd is supplied, this is
the same default configuration as is used when a BFD is supplied, but
the BFD has no attributes section.

Before the change configuring GDB with --enable-targets=all and
running the tests gdb.base/all-architectures-2.exp results in many
errors, but after this change there are no failures.

opcodes/ChangeLog:

* csky-dis.c (csky_get_disassembler): Don't return NULL when there
is no BFD.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 17 Sep 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: use bool in the solib catchpoint area
Simon Marchi [Wed, 16 Sep 2020 21:26:30 +0000 (17:26 -0400)]
gdb: use bool in the solib catchpoint area

Use bool instead of int in struct solib_catchpoint and in init_catchpoint &
related functions.

gdb/ChangeLog:

* breakpoint.h (init_catchpoint): Change int parameter to bool.
(add_solib_catchpoint): Likewise.
* breakpoint.c (struct solib_catchpoint) <is_load>: Change type
to bool.
(add_solib_catchpoint): Change int parameter/variable to bool.
(catch_load_or_unload): Likewise.
(init_catchpoint): Likewise.
(create_fork_vfork_event_catchpoint): Likewise.
(catch_fork_command_1): Likewise.
(catch_exec_command_1): Likewise.

Change-Id: I1faf4506e9109f3ccdd7229ba766dc7d77aa7aa0

4 years agogdb: update instance_flags field name in gdb-gdb.py.in
Simon Marchi [Wed, 16 Sep 2020 20:43:39 +0000 (16:43 -0400)]
gdb: update instance_flags field name in gdb-gdb.py.in

Commit 314ad88df63c ("Use type_instance_flags more throughout") changed
the name of field type::instance_flags to type::m_instance_flags.  It
however missed changing it in the gdb-gdb.py.in file, which results in
this when trying to use the pretty-printer:

    (top-gdb) p *val.type
    Traceback (most recent call last):
      File "/home/smarchi/build/binutils-gdb/gdb/gdb-gdb.py", line 116, in to_string
        % TypeFlagsPrinter(self.val['instance_flags']))
      File "/home/smarchi/build/binutils-gdb/gdb/gdb-gdb.py", line 76, in __str__
        flag_list = [flag.short_name for flag in TYPE_FLAGS
      File "/home/smarchi/build/binutils-gdb/gdb/gdb-gdb.py", line 77, in <listcomp>
        if self.val & flag.value]
    gdb.error: Argument to arithmetic operation not a number or boolean.
    $7 =

This patch fixes it.

gdb/ChangeLog:

* gdb-gdb.py.in (class StructTypePrettyPrinter) <to_string>:
Change instance_flags to m_instance_flags.

Change-Id: Ib5e03c08fe41ca11cd71998f2b1c58052879ce95

4 years agoMatch demangled name in "skip"
Tom Tromey [Wed, 16 Sep 2020 15:49:36 +0000 (09:49 -0600)]
Match demangled name in "skip"

PR gdb/26598 notes that, before commit bcfe6157ca28 ("Use the linkage
name if it exists"), the "skip" command would match the demangled name
of a symbol, but now only matches the linkage name.

This patch fixes this regression.  I looked at all calls to
function_name_is_marked_for_skip, and only one used the linkage name.

2020-09-16  Tom Tromey  <tromey@adacore.com>

PR gdb/26598:
* infrun.c (fill_in_stop_func): Use find_pc_partial_function_sym.

gdb/testsuite/ChangeLog
2020-09-16  Tom Tromey  <tromey@adacore.com>

PR gdb/26598:
* gdb.base/skipcxx.exp: New file.
* gdb.base/skipcxx.cc: New file.

4 years agoAssume FreeBSD kernels always report exec events.
John Baldwin [Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)]
Assume FreeBSD kernels always report exec events.

FreeBSD kernels have reported exec events via the PL_FLAG_EXEC flag
since 8.2 release.  The most recent release that did not support this
flag is 7.4 released in November of 2011.

Note that the FreeBSD native target already assumed that PL_FLAG_SCE
and PL_FLAG_SCX were always supported on systems supporting
PT_LWPINFO, but those flags were added at the same time as
PL_FLAG_EXEC.  Building the native target on a system without
PL_FLAG_EXEC would have failed to build before this change already as
a result.

gdb/ChangeLog:

* fbsd-nat.c (fbsd_nat_target::wait): Always check for
PL_FLAG_EXEC.
(fbsd_nat_target::insert_exec_catchpoint)
(fbsd_nat_target::remove_exec_catchpoint): Always define.
* fbsd-nat.h (fbsd_nat_target::insert_exec_catchpoint)
(fbsd_nat_target::remove_exec_catchpoint): Always declare.

4 years agoRequire kinfo_get_file and kinfo_get_vmmap for FreeBSD hosts.
John Baldwin [Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)]
Require kinfo_get_file and kinfo_get_vmmap for FreeBSD hosts.

FreeBSD systems have provided these functions in libutil since 7.1
release.  The most recent release without support is 6.4 released in
November of 2008.

This also requires libutil-freebsd on GNU/kFreeBSD systems.  I assume
that those systems have supported kinfo_get_file and kinfo_get_vmmap
over a similar timeframe.

gdb/ChangeLog:

* configure.ac: Remove check for kinfo_getvmmap().
* configure, config.in: Regenerate.
* fbsd-nat.c (fbsd_read_mapping): Remove
(fbsd_nat_target::find_memory_regions): Remove the procfs version.
(fbsd_nat_target::info_proc): Assume kinfo_getfile() and
kinfo_get_vmmap() are always present.

gdbsupport/ChangeLog:

* common.m4 (GDB_AC_COMMON): Refactor checks for kinfo_getfile().
* configure, config.in: Regenerate.

4 years agoAssume FreeBSD hosts include support for fetching signal information.
John Baldwin [Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)]
Assume FreeBSD hosts include support for fetching signal information.

The current layout of siginfo_t and support for fetching it has been
included in FreeBSD kernels since 7.0 release.  The most recent
release without support is 6.4 released in November of 2008.

gdb/ChangeLog:

* fbsd-nat.c: Always include support for
TARGET_OBJECT_SIGNAL_INFO.

4 years agoAssume KERN_PROC_PATHNAME is present on FreeBSD hosts.
John Baldwin [Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)]
Assume KERN_PROC_PATHNAME is present on FreeBSD hosts.

FreeBSD kernels have included this sysctl since 6.0 release.  The most
recent release without support is 5.5 which was released in May of
2006.

Both the sysctl and the /proc/<pid>/exe file call the same function in
the kernel to obtain the path (vn_fullpath).  If the sysctl fails, the
readlink call will also fail, so there is no need to keep the readlink
fallback.

gdb/ChangeLog:

* fbsd-nat.c (fbsd_nat_target::pid_to_exec_file): Always use
sysctl and remove procfs fallback.

4 years agoAssume that PT_LWPINFO is always defined on FreeBSD hosts.
John Baldwin [Wed, 16 Sep 2020 18:40:04 +0000 (11:40 -0700)]
Assume that PT_LWPINFO is always defined on FreeBSD hosts.

FreeBSD kernels have included support for this since 5.0 release.
The most recent release without support is 4.11 which was released
in January of 2005.

gdb/ChangeLog:

* fbsd-nat.c: Assume PT_LWPINFO is always defined.
* fbsd-nat.h: Likewise.

4 years ago[gdb/testsuite] Fix gdb.dlang/watch-loc.exp on ppc64
Tom de Vries [Wed, 16 Sep 2020 16:04:37 +0000 (18:04 +0200)]
[gdb/testsuite] Fix gdb.dlang/watch-loc.exp on ppc64

On ppc64, we run into:
...
/tmp/ccKXURmw.s: Assembler messages:^M
/tmp/ccKXURmw.s:99: Error: can't resolve \
  `_Dmain_end' {.text section} - `_Dmain' {.opd section}^M
compiler exited with status 1
...

The unresolvable entity comes from the .debug_aranges section hardcoded in
watch-loc.c:
...
"      .4byte  _Dmain \n"      // Address
"      .4byte  _Dmain_end - _Dmain \n" // Length
...
where _Dmain is the function label for function _Dmain, and _Dmain_end is a
label after function _Dmain:
...
int _Dmain (void)
{
  asm ("_Dmain_label: .globl _Dmain_label");
  return 0;
}

asm ("_Dmain_end: .globl _Dmain_end");
...

The problem is that the two labels are not in the same section, because _Dmain
ends up in the .opd section, which "contains the official procedure
descriptors.  A pointer to a function shall reference a procedure descriptor in
this section."

Fix this by using function_range instead to get the length.

Also, fix the address part to not use _Dmain, but instead use the function
start as returned by function_range.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-09-16  Tom de Vries  <tdevries@suse.de>

PR testsuite/26617
* gdb.dlang/watch-loc.c: Only add .debug_aranges if
        WITH_DEBUG_SECTIONS is defined.
(xstr, str): New macro.
(.debug_aranges): Use DMAIN_START_0/1/2 and DMAIN_LENGTH
to get start and size of _Dmain.
* gdb.dlang/watch-loc.exp: Pass DMAIN_START_0/1/2 and DMAIN_LENGTH
using additional_flags.

4 years agoAdd -Av9 to AFLAGS_PIC and AFLAGS_PIE in the ld test suite on SPARC.
Mikael Pettersson [Wed, 16 Sep 2020 15:20:51 +0000 (16:20 +0100)]
Add -Av9 to AFLAGS_PIC and AFLAGS_PIE in the ld test suite on SPARC.

* testsuite/ld-elf/shared.exp: Add -Av9 to AFLAGS_PIE on sparc.
* testsuite/ld-elf/tls.exp: Add -Av9 to AFLAGS_PIC on sparc.

4 years agoOops - failed to commit change to verilog.c. Trying again.
Nick Clifton [Wed, 16 Sep 2020 15:19:53 +0000 (16:19 +0100)]
Oops - failed to commit change to verilog.c.  Trying again.

* verilog.c (verilog_write_address): Properly handle 64-bit
addresses to avoid truncation of the high part.

4 years agogdb/breakpoint: make a copy of the "commands" command's argument
Tankut Baris Aktemur [Fri, 11 Sep 2020 13:04:01 +0000 (15:04 +0200)]
gdb/breakpoint: make a copy of the "commands" command's argument

When GDB reads commands from the input, its internal buffer is re-used
for each line.  This is usually just fine because commands are
executed in order; by the time we read the next line, we are already
done with the current line.  However, a problematic case is breakpoint
commands that are input from a script.  The header (e.g. commands 1 2)
is overwritten with the next line before the breakpoint numbers are
processed completely.

For example, suppose we have the following script:

  break main
  break main
  commands 1 2
    print 100123
  end

and source this script:

  (gdb) source script.gdb
  Breakpoint 1 at 0x1245: file main.cpp, line 27.
  Breakpoint 2 at 0x1245: file main.cpp, line 27.
  No breakpoint number 123.

Note the "No breakpoint number 123." error message.  This happens
because GDB first reads "commands 1 2" into its internal buffer

  buffer -> "commands 1 2"

and then starts parsing the breakpoint numbers.  After parsing the first
token, the "next token" pointer is as below:

  buffer -> "commands 1 2"
  next-token -----------^

So, if we continue parsing, we would tokenize "2" correctly.  However,
before parsing the next number, GDB reads the commands to attach them
to breakpoint 1.  Reading the commands causes the buffer to be
overwritten:

  buffer -> "  print 100123"
  next-token -----------^

So, the next time we parse the breakpoint number, we read "123".

To fix, simply create a copy of the arguments of the header.

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

* breakpoint.c (commands_command_1): Make a copy of the 'arg'
argument.

gdb/testsuite/ChangeLog:
2020-09-16  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.base/bp-cmds-sourced-script.c: New file.
* gdb.base/bp-cmds-sourced-script.exp: New test.
* gdb.base/bp-cmds-sourced-script.gdb: New file.

4 years agoelf/x86-64: Adjust relocation for PE/x86-64 inputs
H.J. Lu [Wed, 16 Sep 2020 14:11:16 +0000 (07:11 -0700)]
elf/x86-64: Adjust relocation for PE/x86-64 inputs

PE linker calls _bfd_relocate_contents to resolve relocation, instead of
bfd_perform_relocation.  But ELF linker calls bfd_perform_relocation, not
_bfd_relocate_contents.  When linking PE/x86-64 inputs to generate ELF
output, we need to adjust PE/x86-64 relocations in bfd_perform_relocation.

Enable PE/x86-64 in bfd together with PEI/x86-64.  Update run_ld_link_tests
to handle bzip2 binary inputs.

bfd/

PR ld/26583
* config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec
to x86_64_pei_vec.
* reloc.c: Include "coff/internal.h".
(bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs.

ld/

PR ld/26583
* testsuite/ld-x86-64/pe-x86-64-1.od: New file.
* testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2: Likewise.
* testsuite/ld-x86-64/pe-x86-64.exp: Likewise.
* testsuite/lib/ld-lib.exp (run_ld_link_tests): Handle bz2 binary
inputs.

4 years ago[gdb/testsuite] Detect gdb prompt after monitor exit
Tom de Vries [Wed, 16 Sep 2020 12:53:26 +0000 (14:53 +0200)]
[gdb/testsuite] Detect gdb prompt after monitor exit

With this gdbserver-support.exp patch:
...
@@ -451,8 +451,10 @@ proc gdbserver_exit { is_mi } {
      # We use expect rather than gdb_expect because
      # we want to suppress printing exception messages, otherwise,
      # remote_expect, invoked by gdb_expect, prints the exceptions.
+     set have_prompt 0
      expect {
  -i "$gdb_spawn_id" -re "$gdb_prompt $" {
+     set have_prompt 1
      exp_continue
  }
  -i "$server_spawn_id" eof {
@@ -463,6 +465,7 @@ proc gdbserver_exit { is_mi } {
                    warning "Timed out waiting for EOF in server after $monitor_exit"
                }
      }
+     gdb_assert {$have_prompt}
  }
     }
     close_gdbserver
...
and with this in parallel:
...
$ stress -c 5
...
we run into this and similar FAILs:
...
FAIL: gdb.multi/multi-target.exp: continue: non-stop=on: $have_prompt
...

In more detail:
...
(gdb) PASS: gdb.multi/multi-target.exp: continue: non-stop=on: inferior 5
Remote debugging from host ::1, port 40712^M
Process build/gdb/testsuite/outputs/gdb.multi/multi-target/multi-target \
  created; pid = 11098^M
monitor exit^M
Killing process(es): 11098^M
FAIL: gdb.multi/multi-target.exp: continue: non-stop=on: $have_prompt
spawn build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory \
  build/gdb/testsuite/../data-directory^M
...

After issuing a "monitor exit" command, we should always get a prompt back, so
check for that.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-09-16  Tom de Vries  <tdevries@suse.de>

* lib/gdbserver-support.exp (gdbserver_exit): Make sure we
get the gdb prompt after issuing "monitor exit".

4 years agobfd: verilog hex dump backend should handle 64-bit addresses
Anatoly Parshintsev [Wed, 16 Sep 2020 12:17:24 +0000 (13:17 +0100)]
bfd: verilog hex dump backend should handle 64-bit addresses

       * verilog.c (verilog_write_address): Properly handle 64-bit
addresses to avoid truncation of the high part.

4 years ago[gdb/testsuite] Catch condition evaluation errors in gdb_assert
Tom de Vries [Wed, 16 Sep 2020 11:27:32 +0000 (13:27 +0200)]
[gdb/testsuite] Catch condition evaluation errors in gdb_assert

When running test-case gdb.base/watchpoint-stops-at-right-insn.exp, we may run
into a tcl error, which can be reproduced reliably using this trigger patch:
...
+       set hw_watch_pc ""
        gdb_assert {$sw_watch_pc == $hw_watch_pc} \
  "hw watchpoint stops at right instruction"
...
such that we have:
...
ERROR: tcl error sourcing watchpoint-stops-at-right-insn.exp.
ERROR: missing operand at _@_
in expression "0x4004b7 == _@_"
    (parsing expression "0x4004b7 == ")
    invoked from within
"expr $sw_watch_pc == $hw_watch_pc"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 expr $condition"
    (procedure "gdb_assert" line 6)
    invoked from within
"gdb_assert {$sw_watch_pc == $hw_watch_pc} \
  "hw watchpoint stops at right instruction""
...

A similar problem was fixed in commit 5f0e2eb79e "GDB/testsuite: Fix a
catastrophic step-over-no-symbols.exp failure", by making the assert condition
more robust:
...
-    gdb_assert {$before_addr != $after_addr} "advanced"
+    gdb_assert {{[string is integer -strict $before_addr] \
+                && [string is integer -strict $after_addr] \
+                && $before_addr != $after_addr}} "advanced"
...

Fix this instead in gdb_assert, by catching errors while evaluating the assert
condition.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-09-16  Tom de Vries  <tdevries@suse.de>

PR testsuite/26624
* lib/gdb.exp (gdb_assert): Catch errors in condition evaluation.

4 years agogdb: Remove language_data struct
Andrew Burgess [Tue, 4 Aug 2020 16:13:40 +0000 (17:13 +0100)]
gdb: Remove language_data struct

The language_data type, from which language_defn inherits, is now
empty, and this commit removes it.

Each language is updated to no longer create and use a language_data
struct.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete.
(ada_language): Remove references to ada_language_data.
* c-lang.c (c_language_data): Delete.
(c_language): Remove references to c_language_data.
(cplus_language_data): Delete.
(cplus_language): Remove references to cplus_language_data.
(asm_language_data): Delete.
(asm_language): Remove references to asm_language_data.
(minimal_language_data): Delete.
(minimal_language): Remove references to minimal_language_data.
* d-lang.c (d_language_data): Delete.
(d_language): Remove references to d_language_data.
* f-lang.c (f_language_data): Delete.
(f_language): Remove references to f_language_data.
* go-lang.c (go_language_data): Delete.
(go_language): Remove references to go_language_data.
* language.c (unknown_language_data): Delete.
(unknown_language): Remove references to unknown_language_data.
(auto_language_data): Delete.
(auto_language): Remove references to auto_language_data.
* language.h (language_data): Delete struct.
(language_defn): No longer inherit from language_data.
* m2-lang.c (m2_language_data): Delete.
(m2_language): Remove references to m2_language_data.
* objc-lang.c (objc_language_data): Delete.
(objc_language): Remove references to objc_language_data.
* opencl-lang.c (opencl_language_data): Delete.
(opencl_language): Remove references to opencl_language_data.
* p-lang.c (pascal_language_data): Delete.
(pascal_language): Remove references to pascal_language_data.
* rust-lang.c (rust_language_data): Delete.
(rust_language): Remove references to rust_language_data.

4 years agogdb: Convert language_data::la_op_print_tab to a method
Andrew Burgess [Tue, 4 Aug 2020 16:07:59 +0000 (17:07 +0100)]
gdb: Convert language_data::la_op_print_tab to a method

Convert language_data::la_op_print_tab member variable to a virtual
method language_defn::opcode_print_table.  I changed the name in order
to make it clearer (I hope) what the method does.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_op_print_tab
initializer.
(ada_language::opcode_print_table): New member function.
* c-lang.c (c_language_data): Remove la_op_print_tab initializer.
(c_language::opcode_print_table): New member function.
(cplus_language_data): Remove la_op_print_tab initializer.
(cplus_language::opcode_print_table): New member function.
(asm_language_data): Remove la_op_print_tab initializer.
(asm_language::opcode_print_table): New member function.
(minimal_language_data): Remove la_op_print_tab initializer.
(minimal_language::opcode_print_table): New member function.
* d-lang.c (d_language_data): Remove la_op_print_tab initializer.
(d_language::opcode_print_table): New member function.
* expprint.c (print_subexp_standard): Update call to
opcode_print_table.
(op_string): Likewise.
* f-lang.c (f_language_data): Remove la_op_print_tab initializer.
(f_language::opcode_print_table): New member function.
* go-lang.c (go_language_data): Remove la_op_print_tab
initializer.
(go_language::opcode_print_table): New member function.
* language.c (unknown_language_data): Remove la_op_print_tab
initializer.
(unknown_language::opcode_print_table): New member function.
(auto_language_data): Remove la_op_print_tab initializer.
(auto_language::opcode_print_table): New member function.
* language.h (language_data): Remove la_op_print_tab field.
(language_defn::opcode_print_table): Declare new member function.
* m2-lang.c (m2_language_data): Remove la_op_print_tab
initializer.
(m2_language::opcode_print_table): New member function.
* objc-lang.c (objc_language_data): Remove la_op_print_tab
initializer.
(objc_language::opcode_print_table): New member function.
* opencl-lang.c (opencl_language_data): Remove la_op_print_tab
initializer.
(opencl_language::opcode_print_table): New member function.
* p-lang.c (pascal_language_data): Remove la_op_print_tab
initializer.
(pascal_language::opcode_print_table): New member function.
* rust-lang.c (rust_language_data): Remove la_op_print_tab
initializer.
(rust_language::opcode_print_table): New member function.

4 years agogdb: Convert language_data::la_exp_desc to a method
Andrew Burgess [Tue, 4 Aug 2020 15:31:56 +0000 (16:31 +0100)]
gdb: Convert language_data::la_exp_desc to a method

Convert language_data::la_exp_desc member variable to a virtual
method language_defn::expression_ops.  The change of names brings this
method more into line with the existing varobj_ops method, that also
returns a table of function pointers.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_exp_desc initializer.
(ada_language::expression_ops): New member function.
* c-lang.c (c_language_data): Remove la_exp_desc initializer.
(c_language::expression_ops): New member function.
(cplus_language_data): Remove la_exp_desc initializer.
(cplus_language::expression_ops): New member function.
(asm_language_data): Remove la_exp_desc initializer.
(asm_language::expression_ops): New member function.
(minimal_language_data): Remove la_exp_desc initializer.
(minimal_language::expression_ops): New member function.
* d-lang.c (d_language_data): Remove la_exp_desc initializer.
(d_language::expression_ops): New member function.
* eval.c (evaluate_subexp): Update call to expression_ops.
* expprint.c (print_subexp): Likewise.
(op_name): Likewise.
(dump_subexp_body): Likewise.
* f-lang.c (f_language_data): Remove la_exp_desc initializer.
(f_language::expression_ops): New member function.
* go-lang.c (go_language_data): Remove la_exp_desc initializer.
(go_language::expression_ops): New member function.
* language.c (language_defn::expression_ops): New function.
(unknown_language_data): Remove la_exp_desc initializer.
(auto_language_data): Likewise.
* language.h (language_data): Remove la_exp_desc field.
(language_defn::expression_ops): Declare new member function.
* m2-lang.c (m2_language_data): Remove la_exp_desc initializer.
(m2_language::expression_ops): New member function.
* objc-lang.c (objc_language_data): Remove la_exp_desc
initializer.
* opencl-lang.c (opencl_language_data): Remove la_exp_desc
initializer.
(opencl_language::expression_ops): New member function.
* p-lang.c (pascal_language_data): Remove la_exp_desc initializer.
* parse.c (operator_length): Update call to expression_ops.
(exp_iterate): Likewise.
* rust-lang.c (rust_language_data): Remove la_exp_desc
initializer.
(ruse_language::expression_ops): New member function.

4 years agogdb: Convert language_data::la_varobj_ops to a method
Andrew Burgess [Tue, 4 Aug 2020 14:59:52 +0000 (15:59 +0100)]
gdb: Convert language_data::la_varobj_ops to a method

Convert language_data::la_varobj_ops member variable to a virtual
method language_defn::varobj_ops.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_varobj_ops
initializer.
(ada_language::varobj_ops): New member function.
* c-lang.c (c_language_data): Remove la_varobj_ops
initializer.
(cplus_language_data): Likewise.
(cplus_language::varobj_ops): New member function.
(asm_language_data): Remove la_varobj_ops initializer.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (language_defn::varobj_ops): New function.
(unknown_language_data): Remove la_varobj_ops
initializer.
(auto_language_data): Likewise.
* language.h (language_data): Remove la_varobj_ops field.
(language_defn::varobj_ops): Declare new member function.
* m2-lang.c (m2_language_data): Remove la_varobj_ops initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
* varobj.c (varobj_create): Update call to varobj_ops.
* varobj.h (default_varobj_ops): Delete define.

4 years agogdb: Convert language_data::la_macro_expansion to a method
Andrew Burgess [Fri, 31 Jul 2020 14:56:15 +0000 (15:56 +0100)]
gdb: Convert language_data::la_macro_expansion to a method

Convert language_data::la_macro_expansion member variable to a virtual
method language_defn::macro_expansion.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_macro_expansion
initializer.
* c-lang.c (c_language_data): Likewise.
(c_language::macro_expansion): New member function.
(cplus_language_data): Likewise.
(cplus_language::macro_expansion): New member function.
(asm_language_data): Likewise.
(asm_language::macro_expansion): New member function.
(minimal_language_data): Likewise.
(minimal_language::macro_expansion): New member function.
* d-lang.c (d_language_data): Remove la_macro_expansion
initializer.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (language_data): Remove la_macro_expansion field.
(language_defn::macro_expansion): New member function.
* m2-lang.c (m2_language_data): Remove la_macro_expansion
initializer.
* objc-lang.c (objc_language_data): Likewise.
(objc_language::macro_expansion): New member function.
* opencl-lang.c (opencl_language_data): Likewise.
(opencl_language::macro_expansion): New member function.
* p-lang.c (pascal_language_data): Remove la_macro_expansion
initializer.
* rust-lang.c (rust_language_data): Likewise.
* symtab.c (default_collect_symbol_completion_matches_break_on):
Update call to macro_expansion.

4 years agogdb: Convert language_data::la_array_ordering to a method
Andrew Burgess [Sun, 12 Jul 2020 15:00:06 +0000 (16:00 +0100)]
gdb: Convert language_data::la_array_ordering to a method

Convert language_data::la_array_ordering member variable to a virtual
method language_defn::array_ordering.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_array_ordering
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(asm_language_data): Likewise.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* dwarf2/read.c (read_array_order): Update for call to
array_ordering.
* f-lang.c (f_language_data): Remove la_array_ordering
initializer.
(f_language::array_ordering): New member function.
* go-lang.c (go_language_data): Remove la_array_ordering
initializer.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_array_ordering field.
(language_defn::array_ordering): New member function.
* m2-lang.c (m2_language_data): Remove la_array_ordering
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Convert language_data::la_case_sensitivity to a method
Andrew Burgess [Sun, 12 Jul 2020 14:09:52 +0000 (15:09 +0100)]
gdb: Convert language_data::la_case_sensitivity to a method

Convert language_data::la_case_sensitivity member variable to a virtual
method language_defn::case_sensitivity.

This is mostly straight forward.  The only slight problem is that I
ended up deleting this comment from ada-lang.c:

  /* Yes, Ada is case-insensitive, but that's not quite what this
     means.  */

However, as the comment (which has existed since Ada support was first
added to GDB) doesn't explain _why_ Ada sets case sensitivity to on
despite being a generally case insensitive language, this doesn't
really help me much.

If I understood _why_ the setting doesn't quite mean what it seems to
mean (at least as far as Ada is concerned) then I would extend the
comment on language_defn::case_sensitivity (in language.h) to include
the detail, and note how this impacts Ada.  But as it stands I've just
deleted the comment for now.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove la_case_sensitivity
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(asm_language_data): Likewise.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
(f_language::case_sensitivity): New member function.
* go-lang.c (go_language_data): Remove la_case_sensitivity
initializer.
* language.c (enum case_mode): Moved here from language.h.
(case_mode): Make static.
(show_case_command): Update for case_sensitivity being a method.
(set_case_command): Likewise.
(set_range_case): Likewise.
(unknown_language_data): Remove la_case_sensitivity initializer.
(auto_language_data): Likewise.
* language.h (case_mode): Delete, move enum declaration to
language.c.
(language_data): Delete la_case_sensitivity field.
(language_defn::case_sensitivity): New member function.
* m2-lang.c (m2_language_data): Remove la_case_sensitivity
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.