Commit Graph

114924 Commits

Author SHA1 Message Date
Simon Marchi
3d654fa72d gdb: add interp::on_param_changed method
Same idea as previous patches, but for command_param_changed.

Change-Id: I7c2196343423360da05f016f8ffa871c064092bb
2023-05-30 15:07:26 -04:00
Simon Marchi
19081eb5f1 gdb: add interp::on_breakpoint_modified method
Same idea as previous patches, but for breakpoint_modified.

Change-Id: I4f0a9edea912de431e32451d74224b2022a7c328
2023-05-30 15:07:26 -04:00
Simon Marchi
e4239559f4 gdb: add interp::on_breakpoint_deleted method
Same idea as previous patches, but for breakpoint_deleted.

Change-Id: I59c231ce963491bb1eee1432ee1090138f09e19c
2023-05-30 15:07:26 -04:00
Simon Marchi
e7692320db gdb: add interp::on_breakpoint_created method
Same idea as previous patches, but for breakpoint_created.

Change-Id: I614113c924edc243590018b8fb3bf69cb62215ef
2023-05-30 15:07:26 -04:00
Simon Marchi
c27ec5c09f gdb: add interp::on_tsv_modified method
Same idea as previous patches, but for tsv_modified.

Change-Id: I55454a2386d5450040b3a353909b26f389a43682
2023-05-30 15:07:26 -04:00
Simon Marchi
f0dffaff4f gdb: add interp::on_tsv_deleted method
Same idea as previous patches, but for tsv_deleted.

Change-Id: I71b0502b493da7b6e293bee02aeca98de83d4b75
2023-05-30 15:07:26 -04:00
Simon Marchi
bf506f275a gdb: add interp::on_tsv_created method
Same idea as previous patches, but for tsv_created.

Change-Id: I9c30ecfdbd78ca015d613f43a0c0aef6c7eb32b5
2023-05-30 15:07:26 -04:00
Simon Marchi
0bc845fc98 gdb: add interp::on_traceframe_changed method
Same idea as previous patches, but for traceframe_changed.

Change-Id: Ia473f07d70d57b30aca0094d0e0585d7e0d95637
2023-05-30 15:07:26 -04:00
Simon Marchi
7603ea6afa gdb: add interp::on_about_to_proceed method
Same idea as previous patches, but for about_to_proceed.  We only need
(and want, as far as the mi_interp implementation is concerned) to
notify the interpreter that caused the proceed.

Change-Id: Id259bca10dbc3d43d46607ff7b95243a9cbe2f89
2023-05-30 15:07:26 -04:00
Simon Marchi
d711fe3b0f gdb: add interp::on_solib_unloaded method
Same idea as previous patches, but for solib_unloaded.

Change-Id: Iad847de93f0b38b5c90679a173d3beeaed7af6c5
2023-05-30 15:07:26 -04:00
Simon Marchi
f648548100 gdb: add interp::on_solib_loaded method
Same idea as previous patches, but for solib_loaded

Change-Id: I85edb0a4b377f4b2c39ffccf31cb75f38bae0f55
2023-05-30 15:07:26 -04:00
Simon Marchi
52d98df742 gdb: add interp::on_target_resumed method
Same idea as previous patches, but for target_resumed.

Change-Id: I66fa28d1d41a1f3c4fb0d6a470137d493eac3c8c
2023-05-30 15:07:26 -04:00
Simon Marchi
44fbffc69d gdb: add interp::on_record_changed method
Same idea as previous patches, but for record_changed

Change-Id: I5eeeacd703af8401c315060514c94e8e6439cc40
2023-05-30 15:07:26 -04:00
Simon Marchi
2646bfa763 gdb: add interp::on_inferior_removed method
Same idea as previous patches, but for inferior_removed.

Change-Id: I7971840bbbdcfabf77e2ded7584830c9dfdd10d0
2023-05-30 15:07:26 -04:00
Simon Marchi
d38086cce9 gdb: add interp::on_inferior_disappeared method
Same idea as previous patches, but for inferior_disappeared.

For symmetry with on_inferior_appeared, I named this one
on_inferior_disappeared, despite the observer being called
inferior_exit.  This is called when detaching an inferior, so I think
that calling it "disappeared" is a bit less misleading (the observer
should probably be renamed later).

Change-Id: I372101586bc9454997953c1e540a2a6685f53ef6
2023-05-30 15:07:26 -04:00
Simon Marchi
0c613e170e gdb: add interp::on_inferior_appeared method
Same idea as previous patches, but for inferior_appeared.

Change-Id: Ibe4feba34274549a886b1dfb5b3f8d59ae79e1b5
2023-05-30 15:07:26 -04:00
Simon Marchi
023c6d45d7 gdb: add interp::on_inferior_added method
Same idea as previous patches, but for inferior_added.

mi_interp::init avoided using mi_inferior_added, since, as the comment
used to say, it would notify all MI interpreters.  Now, it's easy to
only notify the new interpreter, so it's possible to just call the
on_inferior_added method in mi_interp::init.

Change-Id: I0eddbd5367217d1c982516982089913019ef309f
2023-05-30 15:07:26 -04:00
Simon Marchi
8e7af84345 gdb: add interp::on_thread_exited method
Same idea as previous patches, but for thread_exited.

Change-Id: I4be974cbe58cf635453fef503c2d77c82522cbd9
2023-05-30 15:07:26 -04:00
Simon Marchi
30e7e0a917 gdb: add interp::on_new_thread method
Same idea as previous patches, but for new_thread.

Change-Id: Ib70ae3421b736fd69d86c4e7c708bec349aa256c
2023-05-30 15:07:26 -04:00
Simon Marchi
77cd03e27c gdb: add interp::on_user_selected_context_changed method
Same as previous patches, but for user_selected_context_changed.

Change-Id: I40de15be897671227d4bcf3e747f0fd595f0d5be
2023-05-30 15:07:26 -04:00
Simon Marchi
2736b77153 gdb: add interp::on_command_error method
Same idea as the previous patches, but for command_error.

Change-Id: If6098225dd72fad8be13b3023b35bc8bc48efb9d
2023-05-30 15:07:26 -04:00
Simon Marchi
c3d321de3f gdb: add interp::on_sync_execution_done method
Same as previous patches, but for sync_execution_done.  Except that
here, we only want to notify the interpreter that is executing the
command, not all interpreters.

Change-Id: I729c719447b5c5f29af65dbf6fed9132e2cd308b
2023-05-30 15:07:26 -04:00
Simon Marchi
2e5dbfab56 gdb: add interp::on_no_history method
Same as previous patches, but for no_history.

Change-Id: I06930fe7cb4082138c6c5496c5118fe4951c10da
2023-05-30 15:07:26 -04:00
Simon Marchi
bf64d1d5bf gdb: add interp::on_exited method
Same as previous patch, but for exited.  Remove the exited observable,
since nothing uses it anymore, and we don't have anything coming that
will use it.

Change-Id: I358cbea0159af56752dfee7510d6a86191e722bb
2023-05-30 15:07:26 -04:00
Simon Marchi
d6bd2ef5f4 gdb: add interp::on_signal_exited method
Same as previous patch, but for signal_exited.  Remove the signal_exited
observable, since nothing uses it anymore, and we don't have anything
coming that will use it.

Change-Id: I0dca1eab76338bf27be755786e3dad3241698b10
2023-05-30 15:07:26 -04:00
Simon Marchi
8782926771 gdb: add interp::on_normal_stop method
Same idea as the previous patch, but for the normal_stop event.

Change-Id: I4fc8ca8a51c63829dea390a2b6ce30b77f9fb863
2023-05-30 15:07:26 -04:00
Simon Marchi
3f75a984d2 gdb: add interp::on_signal_received method
Instead of having the interpreter code registering observers for the
signal_received observable, add a "signal_received" virtual method to
struct interp.  Add a interps_notify_signal_received function that loops
over all UIs and calls the signal_received method on the interpreter.
Finally, add a notify_signal_received function that calls
interps_notify_signal_received and then notifies the observers.  Replace
all existing notifications to the signal_received observers with calls
to notify_signal_received.

Before this patch, the CLI and MI code both register a signal_received
observer.  These observer go over all UIs, and, for those that have a
interpreter of the right kind, print the stop notifiation.

After this patch, we have just one "loop over all UIs", inside
interps_notify_signal_received.  Since the interp::on_signal_received
method gets called once for each interpreter, the implementations only
need to deal with the current interpreter (the "this" pointer).

The motivation for this patch comes from a future patch, that makes the
amdgpu code register an observer to print a warning after the CLI's
signal stop message.  Since the amdgpu and the CLI code both use
observers, the order of the two messages is not stable, unless we define
the priority using the observer dependency system.  However, the
approach of using virtual methods on the interpreters seems like a good
change anyway, I think it's more straightforward and simple to
understand than the current solution that uses observers.  We are sure
that the amdgpu message gets printed after the CLI message, since
observers are notified after interpreters.

Keep the signal_received, even if nothing uses if, because we will be
using it in the upcoming amdgpu patch implementing the warning described
above.

Change-Id: I4d8614bb8f6e0717f4bfc2a59abded3702f23ac4
2023-05-30 15:07:26 -04:00
Tom de Vries
37d9880d65 [gdb] Mention --with/without-system-readline for --configuration
Simon reported that the new test-case gdb.tui/pr30056.exp fails with system
readline.

This is because the test-case requires a fix in readline that's present in our
in-repo copy of readline, but most likely not in any system readline yet.

Fix this by:
- mentioning --with-system-readline or --without-system-readline in the
  configuration string.
- adding a new proc with_system_readline that makes this information available
  in the testsuite.
- using this in test-case gdb.tui/pr30056.exp to declare it unsupported for
  --with-system-readline.

Tested on x86_64-linux.

Reported-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-05-30 17:49:31 +02:00
Nick Clifton
35f8b0595f Slight wording improvement for the -Ur documentation 2023-05-30 16:12:18 +01:00
Nick Clifton
10d6a2b1a0 Improve header information displayed with objdump -P for PE binaries.
* od-pe.c (targ_info): New array.
  (get_target_specific_info): New function.
  (decode_machine_number): Retire.  Use get_target_specific_info instead.
  (is_pe_object_magic): Likewise.
  (dump_pe_file_header): Display more information.
  Rework layout to be similar to that from 'objdump -p'.
  Add code to handle larger than normnal AOUT headers.
2023-05-30 15:43:24 +01:00
mengqinggang
2bd766d624 LoongArch: ld: Add support for linker relaxation.
Add ld relax support and testsuits.

ld/ChangeLog:

	* emultempl/loongarchelf.em: Regenerated.
	* testsuite/ld-elf/compressed1d.d: Xfail loongarch*-*.
	* testsuite/ld-elf/pr26936.d: Likewise.
	* testsuite/ld-loongarch-elf/disas-jirl.d: Regenerated.
	* testsuite/ld-loongarch-elf/disas-jirl-32.d: Regenerated.
	* testsuite/ld-loongarch-elf/jmp_op.d: Likewise.
	* testsuite/ld-loongarch-elf/macro_op.d: Likewise.
	* testsuite/ld-loongarch-elf/macro_op_32.d: Likewise.
	* testsuite/ld-loongarch-elf/relax-align.dd: New test.
	* testsuite/ld-loongarch-elf/relax-align.s: New test.
	* testsuite/ld-loongarch-elf/relax.exp: New test.
	* testsuite/ld-loongarch-elf/relax.s: New test.
	* testsuite/ld-loongarch-elf/uleb128.dd: New test.
	* testsuite/ld-loongarch-elf/uleb128.s: New test.
2023-05-30 19:56:48 +08:00
mengqinggang
56576f4a72 LoongArch: gas: Add support for linker relaxation.
Add gas -mrelax and -mno-relax option.
Add R_LARCH_RELAX reloc for instrction if it can be relaxed.
ADD R_LARCH_ALIGN reloc for align pseudo instruction because relax.
Add ADD/SUB reloc pair for debug and exception data to calculate symbol
substraction because relax.

gas/ChangeLog:

	* config/tc-loongarch.c:
	(struct loongarch_cl_insn): New macro_id member.
	(enum options): New OPTION_RELAX and OPTION_NO_RELAX.
	(struct option): New mrelax and mno-relax.
	(md_parse_option): Likewise.
	(get_internal_label):
	(loongarch_args_parser_can_match_arg_helper): Generate relax reloc.
	(move_insn): Set fx_frag and fx_where if exist.
	(append_fixp_and_insn): Call frag_wane and frag_new for linker relax
	relocs.
	(loongarch_assemble_INSNs): New loongarch_cl_insn pointer parameter.
	(md_assemble): Fix function call.
	(fix_reloc_insn): Likewise.
	(md_apply_fix): Generate ADD/SUB reloc pair for debug and exception
	data.
	(loongarch_fix_adjustable): Delete.
	(md_convert_frag): Generate new fix.
	(loongarch_pre_output_hook): New function.
	(loongarch_make_nops): Likewise.
	(loongarch_frag_align_code): Likewise.
	(loongarch_insert_uleb128_fixes): Likewise.
	(loongarch_md_finish): Likewise.
	* config/tc-loongarch.h
	(md_allow_local_subtract): New macro define.
	(loongarch_frag_align_code): New declare.
	(md_do_align): Likewise.
	(loongarch_fix_adjustable): Delete.
	(tc_fix_adjustable): New macro define.
	(TC_FORCE_RELOCATION_SUB_SAME): Likewise.
	(TC_LINKRELAX_FIXUP): Likewise.
	(TC_FORCE_RELOCATION_LOCAL): Likewise.
	(DWARF2_USE_FIXED_ADVANCE_PC): Likewise.
	(MD_APPLY_SYM_VALUE): Likewise.
	(tc_symbol_new_hook): New extern.
	(NOP_OPCODE): Delete.
	(loongarch_pre_output_hook): New macro define.
	(md_pre_output_hook): Likewise.
	(md_finish): Likewise.
	(loongarch_md_finish): New extern.
	* testsuite/gas/all/align.d: Mark as unsupported on LoongArch.
	* testsuite/gas/all/gas.exp: Xfail loongarch*-*.
	* testsuite/gas/all/relax.d: Likewise.
	* testsuite/gas/elf/dwarf-5-irp.d: Likewise.
	* testsuite/gas/elf/dwarf-5-loc0.d: Likewise.
	* testsuite/gas/elf/dwarf-5-macro-include.d: Likewise.
	* testsuite/gas/elf/dwarf-5-macro.d: Likewise.
	* testsuite/gas/elf/dwarf2-11.d: Likewise.
	* testsuite/gas/elf/dwarf2-15.d: Likewise.
	* testsuite/gas/elf/dwarf2-16.d: Likewise.
	* testsuite/gas/elf/dwarf2-17.d: Likewise.
	* testsuite/gas/elf/dwarf2-18.d: Likewise.
	* testsuite/gas/elf/dwarf2-19.d: Likewise.
	* testsuite/gas/elf/dwarf2-5.d: Likewise.
	* testsuite/gas/elf/ehopt0.d: Likewise.
	* testsuite/gas/elf/elf.exp: Likewise.
	* testsuite/gas/elf/section11.d: Likewise.
	* testsuite/gas/lns/lns.exp: Likewise.
	* testsuite/gas/loongarch/jmp_op.d: Regenerated.
	* testsuite/gas/loongarch/li.d: Likewise.
	* testsuite/gas/loongarch/macro_op.d: Likewise.
	* testsuite/gas/loongarch/macro_op_32.d: Likewise.
	* testsuite/gas/loongarch/macro_op_large_abs.d: Likewise.
	* testsuite/gas/loongarch/macro_op_large_pc.d: Likewise.
	* testsuite/gas/loongarch/relax_align.d: New test.
	* testsuite/gas/loongarch/relax_align.s: New test.
	* testsuite/gas/loongarch/uleb128.d: New test.
	* testsuite/gas/loongarch/uleb128.s: New test.
2023-05-30 19:56:46 +08:00
mengqinggang
7624446235 LoongArch: binutils: Add support for linker relaxation.
Add support for relocs related to relax to readelf.

binutils/ChangeLog:

	* readelf.c (target_specific_reloc_handling): Handle ULEB128 reloc.
	(is_32bit_inplace_add_reloc): Handle new reloc.
	(is_32bit_inplace_sub_reloc): Likewise.
	(is_64bit_inplace_add_reloc): Likewise.
	(is_64bit_inplace_sub_reloc): Likewise.
	(is_16bit_inplace_add_reloc): Likewise.
	(is_16bit_inplace_sub_reloc): Likewise.
	(is_8bit_inplace_add_reloc): Likewise.
	(is_8bit_inplace_sub_reloc): Likewise.
	(is_6bit_inplace_sub_reloc): Likewise.
	(is_6bit_inplace_add_reloc): New function.
	(apply_relocations): Handle new reloc.
	* testsuite/binutils-all/readelf.exp: Add -mno-relax option
	for LoongArch.
2023-05-30 19:56:45 +08:00
mengqinggang
7ad9de1188 LoongArch: opcodes: Add support for linker relaxation.
Set gas default to enable relax.

opcodes/ChangeLog:

	* loongarch-opc.c (struct loongarch_ASEs_option): New member relax
	with the default value 1.
2023-05-30 19:56:43 +08:00
mengqinggang
1b6fccd28d LoongArch: bfd: Add support for linker relaxation.
Add relax support and related relocs in bfd.

bfd/ChangeLog:

	* bfd-in2.h: Add relocs related to relax.
	* elfnn-loongarch.c (struct loongarch_elf_link_hash_table): New integer
	pointer (data_segment_phase) to monitor the data segment phase.
	(loongarch_elf_check_relocs): Swap B21/B26 reloc sequence.
	(loongarch_elf_adjust_dynamic_symbol): Fix code format.
	(loongarch_reloc_rewrite_imm_insn): Fix function call.
	(perform_relocation): Handle new relocs related to relax.
	(RELOCATE_CALC_PC32_HI20): Fix code format.
	(RELOCATE_CALC_PC64_HI32): Likewise.
	(loongarch_elf_relocate_section): Handle new relocs related to relax.
	(loongarch_relax_delete_bytes): New function.
	(loongarch_relax_pcala_addi): Likewise.
	(loongarch_relax_pcala_ld): Likewise.
	(bfd_elfNN_loongarch_set_data_segment_info): Likewise.
	(loongarch_relax_align): Likewise.
	(loongarch_elf_relax_section): Likewise.
	(bfd_elfNN_bfd_relax_section): New macro define.
	* elfxx-loongarch.c (reloc_bits): New bfd point parameter.
	(reloc_bits_b16): Likewise.
	(reloc_bits_b21): Likewise.
	(reloc_bits_b26): Likewise.
	(loongarch_adjust_reloc_bitsfield): Likewise.
	(reloc_bits_pcrel20_s2): New function.
	(loongarch_elf_add_sub_reloc): Likewise.
	(loongarch_elf_add_sub_reloc_uleb128): Likewise.
	(loongarch_write_unsigned_leb128): New function.
	* elfxx-loongarch.h (loongarch_adjust_reloc_bitsfield): New bfd point
	parameter.
	(bfd_elf32_loongarch_set_data_segment_info): New declare.
	(bfd_elf64_loongarch_set_data_segment_info): Likewise.
	(loongarch_write_unsigned_leb128): Likewise.
	* libbfd.h: Add relocs related to relax.
	* reloc.c: Add relocs related to relax.
2023-05-30 19:56:41 +08:00
mengqinggang
57a930e3bf LoongArch: include: Add support for linker relaxation.
Add relocs and gas LARCH_opts.relax option.

include/ChangeLog:

	* elf/loongarch.h: Add relocs.
	* opcode/loongarch.h: Add LARCH_opts.relax and macro LARCH_NOP.
2023-05-30 19:56:40 +08:00
Nick Clifton
7b9e7db083 Add support for an ARMMAGIC value of 0xa00 to the PE dumper. 2023-05-30 11:42:16 +01:00
Alan Modra
796029320e arm-pe objdump -P
arm-pe looks to be a very old PE implementation, incompatible with
current arm-wince-pe.  arm-pe has different relocations and uses
ARMMAGIC which has this comment: "I just made this up".  Well, OK, I
don't know the history but it was probably before Microsoft "just made
up" their constants for ARM windows CE.

This patch supports objdump -P for arm-pe, and another magic constant
that may appear in object files.  (I don't think binutils generates
files using ARMV7PEMAGIC aka IMAGE_FILE_MACHINE_ARMNT.)

	* od-pe.c (is_pe_object_magic): Handle IMAGE_FILE_MACHINE_ARMNT
	and ARMMAGIC.
2023-05-30 12:59:55 +09:30
Alan Modra
20c52e689a Define IMAGE_FILE_MACHINE_ARMNT
Same value as ARMV7PEMAGIC.
https://learn.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants

	* coff/pe.h (IMAGE_FILE_MACHINE_ARMNT): Define.
2023-05-30 12:51:57 +09:30
Alan Modra
0b32bdabdc Don't define COFF_MAGIC
This macro was unused apart from aout/encap.h, which has been deleted.

	* config/tc-arm.h (COFF_MAGIC): Don't define.
	* config/tc-sh.h (COFF_MAGIC): Don't define.
	* config/tc-z80.h (COFF_MAGIC): Don't define.
	* config/tc-z8k.h (COFF_MAGIC): Don't define.
2023-05-30 12:51:39 +09:30
Alan Modra
e193947c3b Delete include/aout/encap.h
This file is unused and as the header comment says, obsolete.
2023-05-30 12:51:22 +09:30
Alan Modra
9fa2b95974 Regen binutils POTFILES.in
for od-pe.c
2023-05-30 12:51:07 +09:30
GDB Administrator
93ec7cca41 Automatic date update in version.in 2023-05-30 00:00:40 +00:00
Tom de Vries
e20baea129 [gdb/testsuite] Fix linefeed scrolling in tuiterm
I came across a bug in the implementation of line feed in tuiterm, and added a
unit test that exposes it.

Before sending the line feed we have:
...
Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 3):
    0 abcdefgh
    1 ijklmnop
    2 qrstuvwx
    3 yz01234
...
and after it we have:
...
Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 1):
    0 ijklmnop
    1 qrstuvwx
    2 yz01234
    3 yz01234
...

Note how the cursor started at row 3 and after the line feed ended up at
row 1, while it should have stayed in row 3.

Fix this by moving "incr _cur_row -1" one level up in the loop nest in
proc _ctl_0x0a.

Tested on x86_64-linux.
2023-05-29 22:11:05 +02:00
Simon Marchi
f818c32ba4 gdb/mi: fix ^running record with multiple MI interpreters
I stumbled on the mi_proceeded and running_result_record_printed
globals, which are shared by all MI interpreter instances (it's unlikely
that people use multiple MI interpreter instances, but it's possible).
After poking at it, I found this bug:

1. Start GDB in MI mode
2. Add a second MI interpreter with the new-ui command
3. Use -exec-run on the second interpreter

This is the output I get on the first interpreter:

    =thread-group-added,id="i1"
    ~"Reading symbols from a.out...\n"
    ~"New UI allocated\n"
    (gdb)
    =thread-group-started,id="i1",pid="94718"
    =thread-created,id="1",group-id="i1"
    ^running
    *running,thread-id="all"

And this is the output I get on the second intepreter:

    =thread-group-added,id="i1"
    (gdb)
    -exec-run
    =thread-group-started,id="i1",pid="94718"
    =thread-created,id="1",group-id="i1"
    *running,thread-id="all"

The problem here is that the `^running` reply to the -exec-run command
is printed on the wrong UI.  It is printed on the first one, it should
be printed on the second (the one on which we sent the -exec-run).

What happens under the hood is that captured_mi_execute_command, while
executing a command for the second intepreter, clears the
running_result_record_printed and mi_proceeded globals.
mi_about_to_proceed then sets mi_proceeded.  Then, mi_on_resume_1 gets
called for the first intepreter first.  Since the

    !running_result_record_printed && mi_proceeded

condition is true, it prints a ^running, and sets
running_result_record_printed.  When mi_on_resume_1 gets called for the
second interpreter, running_result_record_printed is already set, so
^running is not printed there.

It took me a while to understand the relationship between these two
variables.  I think that in the end, this is what we want to track:

 1. When executing an MI command, take note if that command causes a
    "proceed".  This is done in mi_about_to_proceed.
 2. In mi_on_resume_1, if the command indeed caused a "proceed", we want
    to output a ^running record.  And we want to remember that we did,
    because...
 3. Back in captured_mi_execute_command, if we did not output a
    ^running, we want to output a ^done.

Moving those two variables to the mi_interp struture appears to fix it.
Only for the interpreter doing the -exec-run command does the
running_result_record_printed flag get cleared, and therefore only or
that one does the ^running record get printed.

Add a new test for this, that does pretty much what the reproducer above
shows.  Without the fix, the test fails because
mi_send_resuming_command_raw never sees the ^running record.

Change-Id: I63ea30e6cb61a8e1dd5ef03377e6003381a9209b
Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2023-05-29 10:09:24 -04:00
GDB Administrator
417bfaa9b5 Automatic date update in version.in 2023-05-29 00:00:47 +00:00
Tom de Vries
85f4cf41a8 [readline] Fix double free in _rl_scxt_dispose
Consider the following scenario.  We start gdb in TUI mode:
...
$ gdb -q -tui
...
and type ^R which gives us the reverse-isearch prompt in the cmd window:
...
(reverse-i-search)`':
...
and then type "foo", right-arrow-key, and ^C.

In TUI mode, gdb uses a custom rl_getc_function tui_getc.

When pressing the right-arrow-key, tui_getc:
- attempts to scroll the TUI src window, without any effect, and
- returns 0.

The intention of returning 0 is mentioned here in tui_dispatch_ctrl_char:
...
  /* We intercepted the control character, so return 0 (which readline
     will interpret as a no-op).  */
  return 0;
...

However, after this 0 is returned by the rl_read_key () call in
_rl_search_getchar, _rl_read_mbstring is called, which incorrectly interprets
0 as the first part of an utf-8 multibyte char, and tries to read the next
char.

In this state, the ^C takes effect and we run into a double free because
_rl_isearch_cleanup is called twice.

Both these issues need fixing independently, though after fixing the first we
no longer trigger the second.

The first issue is caused by the subtle difference between:
- a char array containing 0 chars, which is zero-terminated, and
- a char array containing 1 char, which is zero.

In mbrtowc terms, this is the difference between:
...
  mbrtowc (&wc, "", 0, &ps);
...
which returns -2, and:
...
  mbrtowc (&wc, "", 1, &ps);
...
which returns 0.

Note that _rl_read_mbstring calls _rl_get_char_len without passing it an
explicit length parameter, and consequently it cannot distinguish between the
two, and defaults to the "0 chars" choice.

Note that the same problem doesn't exist in _rl_read_mbchar.

Fix this by defaulting to the "1 char" choice in _rl_get_char_len:
...
-  if (_rl_utf8locale && l > 0 && UTF8_SINGLEBYTE(*src))
+  if (_rl_utf8locale && l >= 0 && UTF8_SINGLEBYTE(*src))
...

The second problem happens when the call to _rl_search_getchar in
_rl_isearch_callback returns.  At that point _rl_isearch_cleanup has already
been called from the signal handler, but we proceed regardless, using a cxt
pointer that has been freed.

Fix this by checking for "RL_ISSTATE (RL_STATE_ISEARCH)" after the call to
_rl_search_getchar:
...
   c = _rl_search_getchar (cxt);
+  if (!RL_ISSTATE (RL_STATE_ISEARCH))
+    return 1;
...

Tested on x86_64-linux.

Approved-By: Chet Ramey <chet.ramey@case.edu>

PR tui/30056
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30056
2023-05-28 10:17:57 +02:00
GDB Administrator
040f24e2eb Automatic date update in version.in 2023-05-28 00:00:41 +00:00
Nelson Chu
225df051d3 [PR ld/22263][PR ld/25694] RISC-V: Avoid dynamic TLS relocs in PIE.
Lots of targets already fixed the TEXTREL problem for TLS in PIE.

* For PR ld/25694,
In the check_reloc, refer to spare and loongarch, they don't need to reserve
any local dynamic reloc for TLS LE in pie/pde, and similar to other targets.
So it seems like riscv was too conservative to estimate the TLS LE before.
Just break and don't goto static_reloc for TLS LE in pie/pde can fix the
TEXTREL problem.

* For PR ld/22263,
The risc-v code for TLS GD/IE in the relocate_section seems same as MIPS port.
So similar to MIPS, pr22570, commits 9143e72c6d and 1cb83cac9a, it seems
also the right way to do the same thing for risc-v.

On risc-v, fixes
FAIL: Build pr22263-1

RISC-V haven't supported the TLS transitions, so will need the same fix (use
bfd_link_dll) in the future.

bfd/
	PR ld/22263
	PR ld/25694
	* elfnn-riscv.c (riscv_elf_check_relocs): Replace bfd_link_pic with
	bfd_link_dll for TLS IE.  Don't need to reserve the local dynamic
	relocation for TLS LE in pie/pde, and report error in pic just like
	before.
	(riscv_elf_relocate_section): For TLS GD/IE, use bfd_link_dll rather
	than !bfd_link_pic in determining the dynamic symbol index.  Avoid
	the index of -1.
2023-05-27 09:24:25 +08:00
GDB Administrator
a70d5ba34c Automatic date update in version.in 2023-05-27 00:00:37 +00:00