Commit Graph

109575 Commits

Author SHA1 Message Date
Joel Brobecker
ba09d2a8cd Update gdb/NEWS after GDB 12 branch creation.
This commit a new section for the next release branch, and renames
the section of the current branch, now that it has been cut.
2022-03-20 09:17:42 +04:00
Joel Brobecker
05d00250d3 Bump version to 13.0.50.DATE-git.
Now that the GDB 12 branch has been created,
this commit bumps the version number in gdb/version.in to
13.0.50.DATE-git

For the record, the GDB 12 branch was created
from commit 2be64de603.

Also, as a result of the version bump, the following changes
have been made in gdb/testsuite:

	* gdb.base/default.exp: Change $_gdb_major to 13.
2022-03-20 09:07:22 +04:00
liuzhensong
2be64de603 ld:LoongArch: Add test cases to adapt to LoongArch32 and LoongArch64
ld/testsuite/ld-loongarch-elf

  *  ld-loongarch-elf.exp:  Test LoongArch32 and LoongArch64 testcases respectively.
  *  jmp_op.d: Fix bug in test LoongArch32.
  *  disas-jirl-32.d: New test case for LoongArch32.
  *  disas-jirl-32.s: New test case for LoongArch32.
  *  disas-jirl.d: Skip test case LoongArch32.
  *  macro_op_32.d: New test case for LoongArch32.
  *  macro_op_32.s: New test case for LoongArch32.
  *  macro_op.d: Skip test case LoongArch32.
2022-03-20 09:37:13 +08:00
liuzhensong
96a671f281 gas:LoongArch: Fix "make check" pr21884 fail in LoongArch32.
gas/config/
    * tc-loongarch.c: Add function to select target mach.
    * tc-loongarch.h: Define macro TARGET_MACH.
2022-03-20 09:37:12 +08:00
liuzhensong
2a04204dff ld: loongarch: Skip unsupport test cases.
ld/testsuite/ld-elf/
    * eh5.d		Skip loongarch64 target.
    * pr21884.d		Skip loongarch* targets.
    * pr26936.d		Skip loongarch* targets.
2022-03-20 09:37:12 +08:00
liuzhensong
d218dba3f4 LoongArch: Fix LD check fails.
Some test cases about ifunc.

  bfd/
    * elfnn-loongarch.c
    * elfxx-loongarch.h

   === ld Summary ===
  of expected passes             1430
  of expected failures           11
  of untested testcases          1
  of unsupported tests           154
2022-03-20 09:37:12 +08:00
liuzhensong
3b14682a43 LoongArch: Update ABI eflag in elf header.
Update LoongArch ABI eflag in elf header.
    ilp32s  0x5
    ilp32f  0x6
    ilp32d  0x7
    lp64s   0x1
    lp64f   0x2
    lp64d   0x3

  bfd/
    * elfnn-loongarch.c Check object flags while ld.

  gas/
    * tc-loongarch.c Write eflag to elf header.

  include/elf
        * loongarch.h Define ABI number.
2022-03-20 09:37:12 +08:00
liuzhensong
1848a40fdd gas:LoongArch: Fix wrong line number in .debug_line
The dwarf2_emit_insn() can create debuginfo of line. But it is called
  too late in append_fixp_and_insn. It causes extra offs when debuginfo
  of line sets address.

  gas/config/
    * tc-loongarch.c
2022-03-20 09:37:12 +08:00
liuzhensong
5fb13d7ef4 gas:LoongArch: Fix segment error in compilation due to too long symbol name.
Change "char buffer[8192];" into "char *buffer =
  (char *) malloc(1000 +  6 * len_str);" in function
  loongarch_expand_macro_with_format_map.

  gas/
    * config/tc-loongarch.c

  include/
    * opcode/loongarch.h

  opcodes/
    * loongarch-coder.c
2022-03-20 09:37:12 +08:00
liuzhensong
748594bc07 LoongArch: Use functions instead of magic numbers.
Replace the magic numbers in gas(tc-loongarch.c) and
  bfd(elfnn-loongarch.c) with the functions defined in
  the howto table(elfxx-loongarch.c).

  gas/
    * config/tc-loongarch.c: use functions.

  bfd/
    * elfnn-loongarch.c: use functions.
    * elfxx-loongarch.c: define functions.
    * elfxx-loongarch.h
2022-03-20 09:37:12 +08:00
liuzhensong
e36144c932 ubsan: loongarch : signed integer shift overflow.
opcodes/
	* loongarch-coder.c :
	  int32_t ret = 0;
	  ret <<= sizeof (ret) * 8 - len;
	  ret >>= sizeof (ret) * 8 - len;
	  ...
	  Avoid ubsan warning.
2022-03-20 09:37:12 +08:00
GDB Administrator
1ab7a698a8 Automatic date update in version.in 2022-03-20 00:00:06 +00:00
Simon Marchi
6f3dfea03a gdb/python: remove gdb._mi_commands dict
The motivation for this patch is the fact that py-micmd.c doesn't build
with Python 2, due to PyDict_GetItemWithError being a Python 3-only
function:

      CXX    python/py-micmd.o
    /home/smarchi/src/binutils-gdb/gdb/python/py-micmd.c: In function ‘int micmdpy_uninstall_command(micmdpy_object*)’:
    /home/smarchi/src/binutils-gdb/gdb/python/py-micmd.c:430:20: error: ‘PyDict_GetItemWithError’ was not declared in this scope; did you mean ‘PyDict_GetItemString’?
      430 |   PyObject *curr = PyDict_GetItemWithError (mi_cmd_dict.get (),
          |                    ^~~~~~~~~~~~~~~~~~~~~~~
          |                    PyDict_GetItemString

A first solution to fix this would be to try to replace
PyDict_GetItemWithError equivalent Python 2 code.  But I looked at why
we are doing this in the first place: it is to maintain the
`gdb._mi_commands` Python dictionary that we use as a `name ->
gdb.MICommand object` map.  Since the `gdb._mi_commands` dictionary is
never actually used in Python, it seems like a lot of trouble to use a
Python object for this.

My first idea was to replace it with a C++ map
(std::unordered_map<std::string, gdbpy_ref<micmdpy_object>>).  While
implementing this, I realized we don't really need this map at all.  The
mi_command_py objects registered in the main MI command table can own
their backing micmdpy_object (that's a gdb.MICommand, but seen from the
C++ code).  To know whether an mi_command is an mi_command_py, we can
use a dynamic cast.  Since there's one less data structure to maintain,
there are less chances of messing things up.

 - Change mi_command_py::m_pyobj to a gdbpy_ref, the mi_command_py is
   now what keeps the MICommand alive.
 - Set micmdpy_object::mi_command in the constructor of mi_command_py.
   If mi_command_py manages setting/clearing that field in
   swap_python_object, I think it makes sense that it also takes care of
   setting it initially.
 - Move a bunch of checks from micmdpy_install_command to
   swap_python_object, and make them gdb_asserts.
 - In micmdpy_install_command, start by doing an mi_cmd_lookup.  This is
   needed to know whether there's a Python MI command already registered
   with that name.  But we can already tell if there's a non-Python
   command registered with that name.  Return an error if that happens,
   rather than waiting for insert_mi_cmd_entry to fail.  Change the
   error message to "name is already in use" rather than "may already be
   in use", since it's more precise.

I asked Andrew about the original intent of using a Python dictionary
object to hold the command objects.  The reason was to make sure the
objects get destroyed when the Python runtime gets finalized, not later.
Holding the objects in global C++ data structures and not doing anything
more means that the held Python objects will be decref'd after the
Python interpreter has been finalized.  That's not desirable.  I tried
it and it indeed segfaults.

Handle this by adding a gdbpy_finalize_micommands function called in
finalize_python.  This is the mirror of gdbpy_initialize_micommands
called in do_start_initialization.  In there, delete all Python MI
commands.  I think it makes sense to do it this way: if it was somehow
possible to unload Python support from GDB in the middle of a session
we'd want to unregister any Python MI command.  Otherwise, these MI
commands would be backed with a stale PyObject or simply nothing.

Delete tests that were related to `gdb._mi_commands`.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: I060d5ebc7a096c67487998a8a4ca1e8e56f12cd3
2022-03-18 20:29:57 -04:00
GDB Administrator
03a5735dbd Automatic date update in version.in 2022-03-19 00:00:06 +00:00
Pedro Alves
b7e077222e Fix crash with stepi, no debug info, and "set debug infrun 1"
A stepi in a function without debug info with "set debug infrun 1"
crashes GDB since commit c8353d682f (gdb/infrun: some extra infrun
debug print statements), due to a reference to
"tp->current_symtab->filename" when tp->current_symtab is null.

This commit adds the missing null check.  The output in this case
becomes:

  [infrun] set_step_info: symtab = <null>, line = 0, step_frame_id = {stack=0x7fffffffd980,code=0x0000000000456c30,!special}, step_stack_frame_id = {stack=0x7fffffffd980,code=0x0000000000456c30,!special}

Change-Id: I5171a9d222bc7e15b9dba2feaba7d55c7acd99f8
2022-03-18 19:25:09 +00:00
Tom Tromey
da729c5ccd Implement gdbarch_stack_frame_destroyed_p for aarch64
The internal AdaCore testsuite has a test that checks that an
out-of-scope watchpoint is deleted.  This fails on some aarch64
configurations, reporting an extra stop:

    (gdb) continue
    Continuing.

    Thread 3 hit Watchpoint 2: result

    Old value = 64
    New value = 0
    0x0000000040021648 in pck.get_val (seed=0, off_by_one=false) at [...]/pck.adb:13
    13	   end Get_Val;

I believe what is happening here is that the variable is stored at:

    <efa>   DW_AT_location    : 2 byte block: 91 7c 	(DW_OP_fbreg: -4)

and the extra stop is reported just before a return, when the ldp
instruction is executed:

   0x0000000040021644 <+204>:	ldp	x29, x30, [sp], #48
   0x0000000040021648 <+208>:	ret

This instruction modifies the frame base calculation, and so the test
picks up whatever memory is pointed to in the callee frame.

Implementing the gdbarch hook gdbarch_stack_frame_destroyed_p fixes
this problem.

As usual with this sort of patch, it has passed internal testing, but
I don't have a good way to try it with dejagnu.  So, I don't know
whether some existing test covers this.  I suspect there must be one,
but it's also worth noting that this test passes for aarch64 in some
configurations -- I don't know what causes one to fail and another to
succeed.
2022-03-18 11:01:43 -06:00
Nick Clifton
0a30596cfa Fix Build issues due to patch "gprofng: a new GNU profiler"
Find and fix more places where clock_gettime() and CLOCK_MONOTONIC_RAW are used.
2022-03-18 15:46:33 +00:00
Simon Marchi
f0cf07f341 gdb: run black to format some Python files
Seems like some leftovers from previous commits.

Change-Id: I7155ccdf7a4fef83bcb3d60320252c3628efdb83
2022-03-18 11:40:21 -04:00
Viorel Preoteasa
a747a286b9 Fix ld-arm bug in encoding of blx calls jumping from thumb to arm instructions
PR 28924
	* elf32-arm.c (THM_MAX_FWD_BRANCH_OFFSET): Fix definition.
	(THM2_MAX_FWD_BRANCH_OFFSET): Likewise.
2022-03-18 15:32:28 +00:00
Jan Beulich
c4d0963383 x86: also fold remaining multi-vector-size shift insns
By slightly relaxing the checking in operand_type_register_match() we
can fold the vector shift insns with an XMM source as well. While
strictly speaking an overlap in just one size (see the code comment) is
not enough (both operands could have multiple sizes with just a single
common one), this is good enough for all templates we have, or which
could sensibly / usefully appear (within the scope of the present
operand matching model).

Tightening this a little would be possible, but would require broadcast
related information to be passed into the function.
2022-03-18 10:55:45 +01:00
Jan Beulich
a548407ec2 x86: drop stray CheckRegSize from VEXTRACT{F,I}32X4
They have only a single operand allowing multiple sizes, hence there are
no pairs of operands to check for consistent size.
2022-03-18 10:55:20 +01:00
Jan Beulich
22c3694052 x86: fold certain AVX2 templates into their AVX counterparts
Like for AVX512VL we can make the handling of operand sizes a little
more flexible to allow reducing the number of templates we have.
2022-03-18 10:54:53 +01:00
Tsukasa OI
41d6ac5da6 RISC-V: Cache management instructions
This commit adds 'Zicbom' / 'Zicboz' instructions.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Add handling for
	new instruction classes.

include/ChangeLog:

	* opcode/riscv-opc.h (MATCH_CBO_CLEAN, MASK_CBO_CLEAN,
	MATCH_CBO_FLUSH, MASK_CBO_FLUSH, MATCH_CBO_INVAL,
	MASK_CBO_INVAL, MATCH_CBO_ZERO, MASK_CBO_ZERO): New macros.
	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	classes INSN_CLASS_ZICBOM and INSN_CLASS_ZICBOZ.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Add cache-block management
	instructions.
2022-03-18 15:32:22 +08:00
Tsukasa OI
3b374308d3 RISC-V: Prefetch hint instructions and operand set
This commit adds 'Zicbop' hint instructions.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Add handling for
	new instruction class.

gas/ChangeLog:

	* config/tc-riscv.c (riscv_ip): Add handling for new operand
	type 'f' (32-byte aligned pseudo S-type immediate for prefetch
	hints).
	(validate_riscv_insn): Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (MATCH_PREFETCH_I, MASK_PREFETCH_I,
	MATCH_PREFETCH_R, MASK_PREFETCH_R, MATCH_PREFETCH_W,
	MASK_PREFETCH_W): New macros.
	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	class INSN_CLASS_ZICBOP.

opcodes/ChangeLog:

	* riscv-dis.c (print_insn_args): Add handling for new operand
	type.
	* riscv-opc.c (riscv_opcodes): Add prefetch hint instructions.
2022-03-18 15:32:16 +08:00
Alan Modra
5fac3f02ed PR28977 tc-i386.c internal error in parse_register
PR 28977
	* config/tc-i386.c (parse_register): Handle X_op not O_register
	as for a non-reg_section symbol.  Simplify array bounds check.
2022-03-18 17:24:13 +10:30
Alan Modra
9e2c342294 Tidy gas current_frame before exit
Releases some obstack memory on an error path.

	* cond.c (cond_finish_check): Call cond_exit_macro.
2022-03-18 16:37:36 +10:30
Alan Modra
ecc263d676 ubsan: logical_input_line signed integer overflow
To avoid a completely useless fuzzing ubsan "bug" report, I decided to
make logical_input_line unsigned.

	* input-scrub.c (logical_input_line): Make unsigned.
	(struct input_save): Here too.
	(input_scrub_reinit, input_scrub_close, bump_line_counters),
	(as_where): Adjust to suit.
2022-03-18 16:37:36 +10:30
GDB Administrator
9ef0cc6c3a Automatic date update in version.in 2022-03-18 00:00:08 +00:00
H.J. Lu
cac97c41c2 gprofng: Skip jsynprog with a broken javac
On CET enabled Linux/x86-64 machines, one can get

$ javac simple.java
Error: dl failure on line 894
Error: failed /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-6.fc35.x86_64/jre/lib/amd64/server/libjvm.so, because /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-6.fc35.x86_64/jre/lib/amd64/server/libjvm.so: rebuild shared object with SHSTK support enabled

Set GPROFNG_BROKEN_JAVAC to "yes" only with a broken javac and skip the
jsynprog test with a broken javac.

	PR gprofng/28965
	* Makefile.am (GPROFNG_BROKEN_JAVAC): New.
	(check-DEJAGNU): Pass GPROFNG_BROKEN_JAVAC to runtest.
	* configure.ac (GPROFNG_BROKEN_JAVAC): New AC_SUBST.  Set to yes
	with a broken javac.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* testsuite/gprofng.display/display.exp: Skip jsynprog with a
	broken javac.
2022-03-17 10:28:58 -07:00
John Baldwin
0e30a3b0f2 Remove fall throughs in core_target::xfer_partial.
The cases for TARGET_OBJECT_LIBRARIES and TARGET_OBJECT_LIBRARIES_AIX
can try to fetch different data objects (such as
TARGET_OBJECT_SIGNAL_INFO) if gdbarch methods for the requested data
aren't present.  Return with TARGET_XFER_E_IO if the gdbarch method
isn't present instead.
2022-03-17 09:37:59 -07:00
Pedro Alves
575b4c298a gdb: Remove support for S+core
GCC removed support for score back in 2014 already.  Back then, we
basically agreed about removing it from GDB too, but it ended up being
forgotten.  See:

 https://sourceware.org/pipermail/gdb/2014-October/044643.html

Following through this time around.

Change-Id: I5b25a1ff7bce7b150d6f90f4c34047fae4b1f8b4
2022-03-17 15:39:19 +00:00
Tom Tromey
d32cbc04e3 Add another test for Ada Wide_Wide_String
In an earlier patch, I had written that I wanted to add this test:

      ptype Wide_Wide_String'("literal")

... but that it failed with the distro GNAT.  Further investigation
showed that it could be made to work by adding a function using
Wide_Wide_String to the program -- this caused the type to end up in
the debug info.

This patch adds the test.  I'm checking this in.
2022-03-17 06:46:13 -06:00
Alan Modra
c9178f285a ubsan: Null dereference in parse_module
* vms-alpha.c (parse_module): Sanity check that DST__K_RTNBEG
	has set module->func_table for DST__K_RTNEND.  Check return
	of bfd_zalloc.
2022-03-17 21:32:44 +10:30
Alan Modra
98c445c0b9 asan: Buffer overflow in evax_bfd_print_dst
With "name" a char*, the length at name[0] might be negative, escaping
buffer limit checks.

	* vms-alpha.c (evax_bfd_print_dst): Make name an unsigned char*.
	(evax_bfd_print_emh): Likewise.
2022-03-17 21:32:44 +10:30
Alan Modra
0c6a3cd135 asan: Buffer overflow in som_set_reloc_info
* som.c (som_set_reloc_info): Add symcount parameter.  Don't
	access symbols past symcount.  Don't access fixup past end_fixups.
	(som_slurp_reloc_table): Adjust som_set_reloc_info calls.
2022-03-17 21:32:44 +10:30
Alan Modra
4c5f3d0c9e asan: use of uninitialized value in buffer_and_nest
More occurences of the same as commit d12b8d620c.

	* macro.c (buffer_and_nest): Sanity check length in buffer
	before calling strncasecmp.
2022-03-17 21:32:44 +10:30
Alan Modra
6109e902f1 gprofng configure target tests
${target} in configure.ac should be the canonical target, so that for
example, someone configuring with --target=x86_64-linux will match
x86_64-*-linux*.

	* configure.ac: Invoke AC_CANONICAL_TARGET.
	* libcollector/configure.ac: Likewise.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* doc/Makefile.in: Regenerate.
	* gp-display-html/Makefile.in: Regenerate.
	* libcollector/Makefile.in: Regenerate.
	* libcollector/configure: Regenerate.
	* src/Makefile.in: Regenerate.
2022-03-17 21:32:44 +10:30
Alan Modra
c55f2b9c61 Re: asan: buffer overflow in peXXigen.c
In the process of fixing a buffer overflow in commit fe69d4fcf0,
I managed to introduce a fairly obvious NULL pointer dereference..

	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Don't
	segfault on not finding section.  Wrap overlong lines.
2022-03-17 21:32:44 +10:30
Alan Modra
0d1064face asan: buffer overflows after calling ignore_rest_of_line
operand() is not a place that should be calling ignore_rest_of_line.
ignore_rest_of_line shouldn't increment input_line_pointer if already
at buffer limit.

	* expr.c (operand): Don't call ignore_rest_of_line.
	* read.c (s_mri_common): Likewise.
	(ignore_rest_of_line): Don't increment input_line_pointer if
	already at buffer_limit.
2022-03-17 21:32:44 +10:30
Alan Modra
df573325cb Re: bfd: add AMDGCN architecture
* po/SRC-POTFILES.in: Regenerate.
2022-03-17 21:32:43 +10:30
Jan Beulich
ed971d9fa6 x86: don't accept base architectures as extensions
The -march= intentions are quite clear: A base architecture may be
followed by any number of extensions. Accepting a base architecture in
place of an extension will at best result in confusion, as the first of
the two (or more) items specified simply would not take effect, due to
being overridden by the later one(s).
2022-03-17 11:05:56 +01:00
Jan Beulich
13ed231a0f x86: never set i386_cpu_flags' "unused" field
Setting this field risks cpu_flags_all_zero() mistakenly returning
"false" when the object passed in was e.g. the result of ANDing together
two objects which had the bit set, or ANDNing together an object with
the field set and one with the field clear.

While there also avoid setting CpuNo64: Like Cpu64 this is driven
differently anyway and hence shouldn't be set anywhere by default.

Note that the moving of the two items in i386-gen.c's cpu_flags[] is
only for documentation purposes (and slight reducing of overhead), as
the fields are sorted anyway upon program start.
2022-03-17 11:05:11 +01:00
Jan Beulich
ad9de929c3 x86: unify CPU flag on/off processing
There's no need for the arbitrary special "unknown" token: Simply
recognize the leading ~ and process everything else the same, merely
recording whether to set individual fields to 1 or 0.

While there exclude CpuIAMCU from CPU_UNKNOWN_FLAGS - CPU_IAMCU_FLAGS
override cpu_arch_flags anyway when -march=iamcu is passed, and there's
no reason to have the stray flag set even if no insn actually is keyed
to it.
2022-03-17 11:04:41 +01:00
Jan Beulich
b1f8a900fd x86: add another IAMCU testcase
Now that {L,K}1OM support is gone, and with it the brokenness in
check_cpu_arch_compatible(), put in place a test making sure that only
extensions can be enabled via .arch for IAMCU, and that the base
architecture cannot be changed.
2022-03-17 11:03:22 +01:00
Jan Beulich
c085ab00c7 x86: drop L1OM/K1OM support from gas
This was only rudimentary support anyway; none of the sub-architecture
specific insns were ever supported.
2022-03-17 11:02:42 +01:00
Jan Beulich
648d04db39 x86: assorted IAMCU CPU checking fixes
The checks done by check_cpu_arch_compatible() were halfway sensible
only at the time where only L1OM support was there. The purpose,
however, has always been to prevent bad uses of .arch (turning off the
base CPU "feature" flag) while at the same time permitting extensions to
be enabled / disabled. In order to achieve this (and to prevent
regressions when L1OM and K1OM support are removed)
- set CpuIAMCU in CPU_IAMCU_FLAGS,
- adjust the IAMCU check in the function itself (the other two similarly
  broken checks aren't adjusted as they're slated to be removed anyway),
- avoid calling the function for extentions (which would never have the
  base "feature" flag set),
- add a new testcase actually exercising ".arch iamcu" (which would also
  regress with the planned removal).
2022-03-17 11:01:38 +01:00
GDB Administrator
4417601f70 Automatic date update in version.in 2022-03-17 00:00:16 +00:00
Andrew Burgess
a6b413d24c gdb: work around prompt corruption caused by bracketed-paste-mode
In this commit:

  commit b4f26d541a
  Date:   Tue Mar 2 13:42:37 2021 -0700

      Import GNU Readline 8.1

We imported readline 8.1 into GDB.  As a consequence bug PR cli/28833
was reported.  This bug spotted that, when the user terminated GDB by
sending EOF (usually bound to Ctrl+d), the last prompt would become
corrupted.  Here's what happens, the user is sat at a prompt like
this:

  (gdb)

And then the user sends EOF (Ctrl+d), we now see this:

  quit)
  ... gdb terminates, and we return to the shell ...

Notice the 'quit' was printed over the prompt.

This problem is a result of readline 8.1 enabling bracketed paste mode
by default.  This problem is present in readline 8.0 too, but in that
version of readline bracketed paste mode is off by default, so a user
will not see the bug unless they specifically enable the feature.

Bracketed paste mode is available in readline 7.0 too, but the bug
is not present in this version of readline, see below for why.

What causes this problem is how readline disables bracketed paste
mode.  Bracketed paste mode is a terminal feature that is enabled and
disabled by readline emitting a specific escape sequence.  The problem
for GDB is that the escape sequence to disable bracketed paste mode
includes a '\r' character at the end, see this thread for more
details:

  https://lists.gnu.org/archive/html/bug-bash/2018-01/msg00097.html

The change to add the '\r' character to the escape sequence used to
disable bracketed paste mode was introduced between readline 7.0 and
readline 8.0, this is why the bug would not occur when using older
versions of readline (note: I don't know if its even possible to build
GDB using readline 7.0.  That really isn't important, I'm just
documenting the history of this issue).

So, the escape sequence to disable bracketed paste mode is emitted
from the readline function rl_deprep_terminal, this is called after
the user has entered a complete command and pressed return, or, if the
user sends EOF.

However, these two cases are slightly different.  In the first case,
when the user has entered a command and pressed return, the cursor
will have moved to the next, empty, line, before readline emits the
escape sequence to leave bracketed paste mode.  The final '\r'
character moves the cursor back to the beginning of this empty line,
which is harmless.

For the EOF case though, this is not what happens.  Instead, the
escape sequence to leave bracketed paste mode is emitted on the same
line as the prompt.  The final '\r' moves the cursor back to the start
of the prompt line.  This leaves us ready to override the prompt.

It is worth noting, that this is not the intended behaviour of
readline, in rl_deprep_terminal, readline should emit a '\n' character
when EOF is seen.  However, due to a bug in readline this does not
happen (the _rl_eof_found flag is never set).  This is the first
readline bug that effects GDB.

GDB prints the 'quit' message from command_line_handler (in
event-top.c), this function is called (indirectly) from readline to
process the complete command line, but also in the EOF case (in which
case the command line is set to nullptr).  As this is part of the
callback to process a complete command, this is called after readline
has disabled bracketed paste mode (by calling rl_deprep_terminal).

And so, when bracketed paste mode is in use, rl_deprep_terminal leaves
the cursor at the start of the prompt line (in the EOF case), and
command_line_handler then prints 'quit', which overwrites the prompt.

The solution to this problem is to print the 'quit' message earlier,
before rl_deprep_terminal is called.  This is easy to do by using the
rl_deprep_term_function hook.  It is this hook that usually calls
rl_deprep_terminal, however, if we replace this with a new function,
we can print the 'quit' string, and then call rl_deprep_terminal
ourselves.  This allows the 'quit' to be printed before
rl_deprep_terminal is called.

The problem here is that there is no way in rl_deprep_terminal to know
if readline is processing EOF or not, and as a result, we don't know
when we should print 'quit'.  This is the second readline bug that
effects GDB.

Both of these readline issues are discussed in this thread:

  https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00021.html

The result of that thread was that readline was patched to address
both of these issues.

Now it should be easy to backport the readline fix to GDB's in tree
copy of readline, and then change GDB to make use of these fixes to
correctly print the 'quit' string.

However, we are just about to branch GDB 12, and there is concern from
some that changing readline this close to a new release is a risky
idea, see this thread:

  https://sourceware.org/pipermail/gdb-patches/2022-March/186391.html

So, this commit doesn't change readline at all.  Instead, this commit
is the smallest possible GDB change in order to avoid the prompt
corruption.

In this commit I change GDB to print the 'quit' string on the line
after the prompt, but only when bracketed paste mode is on.  This
avoids the overwriting issue, the user sees this:

  (gdb)
  quit
  ... gdb terminates, and returns to the shell ...

This isn't ideal, but is better than the existing behaviour.  After
GDB 12 has branched, we can backport the readline fix, and apply a
real fix to GDB.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833
2022-03-16 18:01:09 +00:00
Fangrui Song
260ecdcec4 objcopy --weaken-symbol: apply to STB_GNU_UNIQUE symbols
PR binutils/28926
    * objcopy.c (filter_symbols): Apply weaken to STB_GNU_UNIQUE symbols
    * NEWS: Mention feature.
    * testsuite/binutils-all/objcopy.exp (objcopy_test_symbol_manipulation): New test.
    * testsuite/binutils-all/weaken-gnu-unique.s: New.
2022-03-16 09:40:13 -07:00
Tom Tromey
b1b9c4115e Reimplement array concatenation for Ada and D
This started as a patch to implement string concatenation for Ada.
However, while working on this, I looked at how this code could
possibly be called.  It turns out there are only two users of
concat_operation: Ada and D.  So, in addition to implementing this for
Ada, this patch rewrites value_concat, removing the odd "concatenate
or repeat" semantics, which were completely unused.  As Ada and D both
seem to represent strings using TYPE_CODE_ARRAY, this removes the
TYPE_CODE_STRING code from there as well.
2022-03-16 09:28:13 -06:00