Commit Graph

114839 Commits

Author SHA1 Message Date
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
Nick Clifton
45b8517aae Enhance objdump's --private option so that it can display the contents of PE format files.
* od-pe.c: New file: Dumps fields in PE format headers.
  * configure.ac (od_vectors): Add objdump_private_desc_pe for PE format targets. (od_files): Add od-pe for PE format targets.
  * configure: Regenerate.
  * Makefile.am (CFILES): Add od-pe.c (EXTRA_objdump_SOURCE): Likewise.
  * Makefile.in: Generate.
  * NEWS: Mention the new feature.
  * doc/binutils.texi: Document the new support.
  * objdump.c (wide_output): Change from local to global.
  * objdump.h (wide_output): Prototype. (objdump_private_desc_pe): Prototype.
  * testsuite/binutils-all/objdump.exp: Add a test of the new feature.
2023-05-26 15:41:20 +01:00
Andreas Schwab
5fd6b60d86 Remove duplicate definition
* coff/pe.h (IMAGE_FILE_MACHINE_AMD64): Remove duplicate
	definition.  Alphabetize.
2023-05-26 13:12:32 +02:00
Jan Beulich
93497bf9ab x86: fix disassembler build after 1a3b4f90bc
In commit 1a3b4f90bc ("x86: convert two pointers to (indexing)
integers") I neglected the fact that compilers may warn about comparing
ptrdiff_t (signed long) with size_t (unsigned long) values. Since just
before we've checked that the value is positive, simply add a cast
(despite my dislike for casts).
2023-05-26 12:44:52 +02:00
Tom de Vries
a3b86780b6 [gdb/testsuite] Add test-case gdb.tui/color-prompt.exp
Add a test-case that sets a prompt with color in TUI.

The line containing the prompt is shown by get_line_with_attrs as follows:
...
<fg:31>(gdb) <fg:default>
...

The 31 means red, but only for foreground colors, for background colors 41
means red.

Make this more readable by using color names for both foreground and
background, such that we have instead:
....
<fg:red>(gdb) <fg:default>
...

Tested on x86_64-linux.
2023-05-26 12:30:24 +02:00
Tom de Vries
52141e2def [gdb/testsuite] Add invisible and blinking attributes in tuiterm
I noticed curses using the invisible and blinking attributes.

Add these in tuiterm.

Tested on x86_64-linux.
2023-05-26 12:30:24 +02:00
Tom de Vries
7f05c98b81 [gdb/testsuite] Fix reverse attribute in tuiterm
I noticed in proc Term::_csi_m arguments that while parameters 7 and 27 are
supposed to set the reverse attribute to 1 and 0, in fact it's set to 1 in
both cases:
...
 		    7 {
			set _attrs(reverse) 1
		    }
  ...
		    27 {
			set _attrs(reverse) 1
 		    }
...

Fix this and add a regression test in gdb.tui/tuiterm.exp.

Tested on x86_64-linux.
2023-05-26 12:30:24 +02:00
Jan Beulich
86b96a79b8 iamcu: suppress tests which can't possibly work
With neither --32 nor --64 passed to gas, advanced features like AVX
aren't available without explicitly enabling them.
2023-05-26 10:14:34 +02:00
Jan Beulich
590a0fed02 x86-64: improve gas diagnostic when no 32-bit target is configured
Make this similar to --64 and --x32: Check whether a suitable target
exists.
2023-05-26 10:14:13 +02:00
Jan Beulich
a7aee0b577 x86-64: conditionalize tests using --32
Using this option doesn't really work when no support for any 32-bit
target was configured in (as is the case for at least cloudabi and
rdos).
2023-05-26 10:13:53 +02:00
Jan Beulich
fd0caa872c x86: split gas testsuite .exp file
The set of 32-bit-only and 64-bit-only tests has grown quite large. In
particular when one's after only the results for the 64-bit set, having
them live in a separate .exp file is easier / faster.
2023-05-26 10:13:29 +02:00
Jan Beulich
1a3b4f90bc x86: convert two pointers to (indexing) integers
This in particular reduces the number of pointers to non-const that we
have (and that could potentially be used for undue modification of
state). As a result, fetch_code()'s 2nd parameter can then also become
pointer-to-const.
2023-05-26 09:53:51 +02:00
Jan Beulich
d8acf37693 x86: disassembling over-long insns
The present way of dealing with them - misusing MAX_MNEM_SIZE, which has
nothing to do with insn length - leads to inconsistent results. Since we
allow for up to MAX_CODE_LENGTH - 1 prefix bytes (which then could be
followed by another MAX_CODE_LENGTH "normal" insn bytes until we're done
decoding), size the_buffer[] accordingly.

Move struct dis_private down to be able to use MAX_CODE_LENGTH without
moving its #define. While doing this also alter the order to have the
potentially large array last.
2023-05-26 09:53:25 +02:00
Jan Beulich
a4aa034a0a x86: use fixed-width type for codep and friends
This first of all removes a dependency on bfd_byte and unsigned char
being the same types. It further eliminates the need to mask by 0xff
when fetching values (which wasn't done fully consistently anyway),
improving code legibility.

While there, where possible add const.
2023-05-26 09:53:01 +02:00
Jan Beulich
778415f597 x86: figure braces aren't really part of mnemonics
Instead they're separators for pseudo-prefixes. Don't insert them in
mnemonic_chars[], handling them explicitly in parse_insn() instead. Note
that this eliminates the need for another separator after a pseudo-
prefix. While maybe not overly interesting for a following real
mnemonic, I view this as quite desirable between multiple successive
pseudo-prefixes (bringing things in line with the other use of figure
braces in AVX512's zeroing-masking).

Drop the unused is_mnemonic_char() at this occasion.
2023-05-26 09:42:03 +02:00
Jan Beulich
d2b1a14de3 x86: de-duplicate operand_special_chars[] wrt extra_symbol_chars[]
Having to add characters to both arrays can easily lead to oversights.
Consuming extra_symbol_chars[] when populating operand_chars[] also
allows to drop two special cases in md_begin().

Constify operand_special_chars[] at this occasion.
2023-05-26 09:41:41 +02:00
Indu Bhagat
540034ec40 sframe/doc: minor improvements for readability
libsframe/
	* sframe-spec.texi: Cosmetic fixes.
2023-05-25 23:44:15 -07:00
Indu Bhagat
83c219872b libsframe: revisit sframe_find_fre API
Inspite of implementing a rather simple functionality, this function was
relatively difficult to follow, and maintain.  Some changes are done now
to address that - refactor the function and use better names to make it
more readable.

The changes to the implementation do not cause any change in the
contract of the API.

libsframe/
        * sframe.c (sframe_fre_get_end_ip_offset): to here...
        (sframe_find_fre): Refactor some bits from...
2023-05-25 23:44:09 -07:00
Indu Bhagat
812d868850 libsframe: use const char * consistently for immutable FRE buffers
libsframe/
        * sframe.c (sframe_decode_fre): Use const char * datatype when
	handling buffer containing the FREs.
	(sframe_fre_get_end_ip_offset): Likewise.
	(sframe_find_fre): Likewise.
	(sframe_decoder_get_fre): Likewise.
2023-05-25 23:44:02 -07:00
Indu Bhagat
e80578bea7 libsframe: use uint8_t data type for FRE info related stubs
libsframe/
	* sframe.c: Use uint8_t for FRE offset count and FRE offset
	size.  Use uint8_t for FRE info word as well.
2023-05-25 23:43:45 -07:00
Alan Modra
9dc7ab5c01 PR22263 ld test
A number of targets that I test regularly fail the "Build pr22263-1"
test for various reasons.

arm-linux-gnueabi: "undefined reference to `__aeabi_read_tp'"
ia64-linux-gnu: "Explicit stops are ignored in auto mode"
m68k-linux-gnu: "undefined reference to `__m68k_read_tp'"
microblaze-linux-gnu: "undefined reference to `__tls_get_addr'"
nios2-linux-gnu, s390-linux-gnu and sh4-linux-gnu have a tprel reloc in .got
riscv64-linux-gnu has a dynamic relocation in text

So only riscv really fails the pr.  The rest fail due to test issues
or lack of a linker optimisation.  Lack of an optimisation isn't
really a fail, but it's worth keeping the test to ensure those
optimisations don't regress.  The xfail targets may not be an
exhaustive list.  This just tidies test results for those for which I
have cross compilers installed.

	PR 22263
	* testsuite/ld-elf/tls.exp: Split pr22263 test into two parts,
	one to check for -z text errors, the other to check tprel
	linker optimisation.  Supply needed symbols and assembler flags.
	xfail the linker optimisation on targets known to fail.
2023-05-26 12:14:36 +09:30
Tom Tromey
9158e49a70 Make MI commands const-correct
I've had this patch for a while now and figured I'd update it and send
it.  It changes MI commands to use a "const char * const" for their
argv parameter.

Regression tested on x86-64 Fedora 36.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
2023-05-25 19:00:02 -06:00
GDB Administrator
fb7cd8ccfe Automatic date update in version.in 2023-05-26 00:00:41 +00:00
Ciaran Woodward
3422b26537 Fix scoped_value_mark not working with empty value chain
The scoped_value_mark helper class was setting its internal
mark value to NULL to indicate that the value chain had already
been freed to mark.

However, value_mark() also returns NULL if the value chain is
empty at the time of call.

This lead to the situation that if the value chain was empty
at the time the scoped_value_mark was created, the class
would not correctly clean up the state when it was destroyed,
because it believed it had already been freed.

I noticed this because I was setting a watchpoint very early
in my debug session, and it was becoming a software watchpoint
rather than hardware. Running any command that called evaluate()
beforehand (such as 'x 0') would mean that a hardware watchpoint
was correctly used. After some careful examination of the
differences in execution, I noticed that values were being freed
later in the 'bad case', which lead me to notice the issue with
scoped_value_mark.
2023-05-25 12:47:03 -06:00
Simon Marchi
a1decfc1df gdb: remove breakpoint_pointer_iterator
Remove the breakpoint_pointer_iterator layer.  Adjust all users of
all_breakpoints and all_tracepoints to use references instead of
pointers.

Change-Id: I376826f812117cee1e6b199c384a10376973af5d
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:52:22 -04:00
Simon Marchi
410f4d7a76 gdbsupport: make filtered_iterator::operator* return the same thing as underlying iterator
This is the same idea as the previous patch, but for filtered_iterator.
Without this patch, I would see this when applying the patch that
removes reference_to_pointer_iterator from breakpoint_range:

      CXX    breakpoint.o
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c: In function ‘void download_tracepoint_locations()’:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:11007:41: error: cannot allocate an object of abstract type ‘breakpoint’
    11007 |   for (breakpoint &b : all_tracepoints ())
          |                                         ^
    In file included from /home/smarchi/src/binutils-gdb/gdb/gdbthread.h:26,
                     from /home/smarchi/src/binutils-gdb/gdb/infrun.h:21,
                     from /home/smarchi/src/binutils-gdb/gdb/gdbarch.h:28,
                     from /home/smarchi/src/binutils-gdb/gdb/arch-utils.h:23,
                     from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:21:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.h:619:8: note:   because the following virtual functions are pure within ‘breakpoint’:
      619 | struct breakpoint : public intrusive_list_node<breakpoint>
          |        ^~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:250:1: note:     ‘virtual breakpoint::~breakpoint()’
      250 | breakpoint::~breakpoint ()
          | ^~~~~~~~~~

Change-Id: I05285ff27d21cb0ab80cba392ec4e959167e3cd7
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:48:37 -04:00
Simon Marchi
679a4e92b3 gdbsupport: make basic_safe_iterator::operator* return the same thing as underlying iterator
Using the following patch that removes the reference_to_pointer_iterator
from breakpoint_range, I would get:

      CXX    breakpoint.o
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c: In function ‘void breakpoint_program_space_exit(program_space*)’:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:3030:46: error: cannot allocate an object of abstract type ‘breakpoint’
     3030 |   for (breakpoint &b : all_breakpoints_safe ())
          |                                              ^
    In file included from /home/smarchi/src/binutils-gdb/gdb/gdbthread.h:26,
                     from /home/smarchi/src/binutils-gdb/gdb/infrun.h:21,
                     from /home/smarchi/src/binutils-gdb/gdb/gdbarch.h:28,
                     from /home/smarchi/src/binutils-gdb/gdb/arch-utils.h:23,
                     from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:21:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.h:619:8: note:   because the following virtual functions are pure within ‘breakpoint’:
      619 | struct breakpoint : public intrusive_list_node<breakpoint>
          |        ^~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:250:1: note:     ‘virtual breakpoint::~breakpoint()’
      250 | breakpoint::~breakpoint ()
          | ^~~~~~~~~~

This is because the operator* method of the basic_safe_iterator iterator
wrapper returns a value_type.  So, even if the method of the underlying
iterator (breakpoint_iterator, an intrusive_list iterator) returns a
`breakpoint &`, the method of the wrapper returns a `breakpoint`.

I think it would make sense for iterator wrappers such as
basic_safe_iterator to return the exact same thing as the iterator they
wrap.  At least, it fixes my problem.

Change-Id: Ibbcd390ac03d2fb6ae4854923750c8d7c3c04e8a
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:44:52 -04:00
Simon Marchi
e2a1578868 gdb: link breakpoints with intrusive_list
Change-Id: I043d8d6f3dd864d80d5088f6ffc2c098337249ea
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:41:16 -04:00
Simon Marchi
b00b30b298 gdb: remove bp_location_pointer_iterator
Remove the bp_location_pointer_iterator layer.  Adjust all users of
breakpoint::locations to use references instead of pointers.

Change-Id: Iceed34f5e0f5790a9cf44736aa658be6d1ba1afa
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:40:58 -04:00
Simon Marchi
20afe380e8 gdb: use intrusive_list for breakpoint locations
Replace the hand-maintained linked lists of breakpoint locations with
and intrusive list.

 - Remove breakpoint::loc, add breakpoint::m_locations.

 - Add methods for the various manipulations that need to be done on the
   location list, while maintaining reasonably good encapsulation.

 - bp_location currently has a default constructor because of one use
   in hoist_existing_locations.  hoist_existing_locations now returns a
   bp_location_list, and doesn't need the default-constructor
   bp_location anymore, so remove the bp_location default constructor.

 - I needed to add a call to clear_locations in delete_breakpoint to
   avoid a use-after-free.

 - Add a breakpoint::last_loc method, for use in
   set_breakpoint_condition.

bp_location_range uses reference_to_pointer_iterator, so that all
existing callers of breakpoint::locations don't need to change right
now.  It will be removed in the next patch.

The rest of the changes are to adapt the call sites to use the new
methods, of breakpoint::locations, rather than breakpoint::loc directly.

Change-Id: I25f7ee3d66a4e914a0540589ac414b3b820b6e70
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:47:12 -04:00
Simon Marchi
774d21c10b gdbsupport: add missing increment/decrement operators to reference_to_pointer_iterator
Using the following patch, I would get this build failure:

      CXX    breakpoint.o
    In file included from /usr/include/c++/13.1.1/bits/stl_algobase.h:66,
                     from /usr/include/c++/13.1.1/bits/hashtable_policy.h:36,
                     from /usr/include/c++/13.1.1/bits/hashtable.h:35,
                     from /usr/include/c++/13.1.1/bits/unordered_map.h:33,
                     from /usr/include/c++/13.1.1/unordered_map:41,
                     from /usr/include/c++/13.1.1/functional:63,
                     from /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/ptid.h:35,
                     from /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:206,
                     from /home/smarchi/src/binutils-gdb/gdb/defs.h:26,
                     from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:20:
    /usr/include/c++/13.1.1/bits/stl_iterator_base_funcs.h: In instantiation of ‘constexpr void std::__advance(_BidirectionalIterator&, _Distance, bidirectional_iterator_tag) [with _BidirectionalIterator = reference_to_pointer_iterator<intrusive_list_iterator<bp_location, intrusive_base_node<bp_location> > >; _Distance = long int]’:
    /usr/include/c++/13.1.1/bits/stl_iterator_base_funcs.h:224:21:   required from ‘constexpr void std::advance(_InputIterator&, _Distance) [with _InputIterator = reference_to_pointer_iterator<intrusive_list_iterator<bp_location, intrusive_base_node<bp_location> > >; _Distance = long int]’
    /usr/include/c++/13.1.1/bits/stl_iterator_base_funcs.h:237:19:   required from ‘constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type) [with _InputIterator = reference_to_pointer_iterator<intrusive_list_iterator<bp_location, intrusive_base_node<bp_location> > >; typename iterator_traits<_Iter>::difference_type = long int]’
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:1073:19:   required from here
    /usr/include/c++/13.1.1/bits/stl_iterator_base_funcs.h:179:11: error: no match for ‘operator--’ (operand type is ‘reference_to_pointer_iterator<intrusive_list_iterator<bp_location, intrusive_base_node<bp_location> > >’)
      179 |           --__i;
          |           ^~~~~

This points out that while intrusive_list_iterator has an operator--,
the reference_to_pointer_iterator wrapper does not.  I'm not to sure why
the compiler chooses the overload of __advance that accepts a
_BidirectionalIterator, given that reference_to_pointer_iterator can't
be decremented, but adding those operators seems like the right thing to
do in any case, for completeness.

Change-Id: I8e2044b6734fadf0f21093047cf35bb7080dbdc3
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:47:12 -04:00
Simon Marchi
f5951b9ff8 gdb: add breakpoint::first_loc methods
Add convenience first_loc methods to struct breakpoint (const and
non-const overloads).  A subsequent patch changes the list of locations
to be an intrusive_list and makes the actual list private, so these
spots would need to change from:

    b->loc

to something ugly like:

    *b->locations ().begin ()

That would make the code much heavier and not readable.  There is a
surprisingly big number of places that access the first location of
breakpoints.  Whether this is correct, or these spots fail to consider
the possibility of multi-location breakpoints, I don't know.  But
anyhow, I think that using this instead:

 b->first_loc ()

conveys the intention better than the other two forms.

Change-Id: Ibbefe3e4ca6cdfe570351fe7e2725f2ce11d1e95
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:47:00 -04:00
Simon Marchi
9dc1523b57 gdb: add breakpoint "has locations" methods
Add three convenience methods to struct breakpoint:

 - has_locations: returns true if the breakpoint has at least one
   location
 - has_single_location: returns true if the breakpoint has exactly one
   location
 - has_multiple_locations: returns true if the breakpoint has more than
   one location

A subsequent patch changes the list of breakpoints to be an
intrusive_list, so all these spots would need to change.  But in any
case, I think that this:

  if (b->has_multiple_locations ())

conveys the intention better than:

  if (b->loc != nullptr && b->loc->next != nullptr)

Change-Id: Ib18c3605fd35d425ef9df82cb7aacff1606c6747
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:46:23 -04:00
Simon Marchi
5e632eca05 gdb: constify breakpoint::print_it parameter
The print_it method itself is const.  In a subsequent patch, the
locations that come out of a const breakpoint will be const as well.  It
will therefore be needed to make the last_loc output parameter const as
well.  Make that change now to reduce the size of the following patches.

Change-Id: I7ed962950bc9582646e31e2e42beca2a1c9c5105
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:46:23 -04:00
Simon Marchi
dbaa3bf640 gdb: make some breakpoint methods use this
Some implementations of breakpoint::check_status and
breakpoint::print_it do this:

    struct breakpoint *b = bs->breakpoint_at;

bs->breakpoint_at is always the same as `this` (we can get convinced by
looking at the call sites of check_status and print_it), so it would
just be clearer to access fields through `this` instead.

Change-Id: Ic542a64fcd88e31ae2aad6feff1da278c7086891
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:46:23 -04:00
Simon Marchi
26a69f095f gdb: get gdbarch from syscall_catchpoint instead of location
I noticed some methods of syscall_catchpoint doing this:

  struct gdbarch *gdbarch = loc->owner->gdbarch;

`loc` is the list of locations of this catchpoint.  Logically, the owner
the locations are this catchpoint.  So this just ends up getting
this->gdbarch.  Remove the unnecessary indirection through the loc.

syscall_catchpoint::print_recreate does something slightly different,
getting its arch from the loc:

  struct gdbarch *gdbarch = loc->gdbarch;

I suppose it's always going to be the same arch, so get it from the
catchpoint there too.

Change-Id: I6f6a6f8e0cd7cfb754cecfb6249e71ec12ba4855
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 08:46:23 -04:00