]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 years agoUnify gdb printf functions
Tom Tromey [Sun, 2 Jan 2022 18:46:15 +0000 (11:46 -0700)] 
Unify gdb printf functions

Now that filtered and unfiltered output can be treated identically, we
can unify the printf family of functions.  This is done under the name
"gdb_printf".  Most of this patch was written by script.

2 years agoUnify gdb putc functions
Tom Tromey [Sun, 2 Jan 2022 18:42:07 +0000 (11:42 -0700)] 
Unify gdb putc functions

Now that filtered and unfiltered output can be treated identically, we
can unify the putc family of functions.  This is done under the name
"gdb_putc".  Most of this patch was written by script.

2 years agoUnify gdb puts functions
Tom Tromey [Sun, 2 Jan 2022 18:36:44 +0000 (11:36 -0700)] 
Unify gdb puts functions

Now that filtered and unfiltered output can be treated identically, we
can unify the puts family of functions.  This is done under the name
"gdb_puts".  Most of this patch was written by script.

2 years agoUnify vprintf functions
Tom Tromey [Sun, 2 Jan 2022 18:13:35 +0000 (11:13 -0700)] 
Unify vprintf functions

Now that filtered and unfiltered output can be treated identically, we
can unify the vprintf family of functions: vprintf_filtered,
vprintf_unfiltered, vfprintf_filtered and vfprintf_unfiltered.  (For
the gdb_stdout variants, recall that only printf_unfiltered gets truly
unfiltered output at this point.)  This removes one such function and
renames the remaining two to "gdb_vprintf".  All callers are updated.
Much of this patch was written by script.

2 years agoRemove fputs_styled_unfiltered
Tom Tromey [Sat, 1 Jan 2022 22:25:53 +0000 (15:25 -0700)] 
Remove fputs_styled_unfiltered

fputs_styled_unfiltered is only called from cli_ui_out, so remove it.
This area will be further simplified in future patches.

2 years agoChange the pager to a ui_file
Tom Tromey [Sat, 1 Jan 2022 20:18:17 +0000 (13:18 -0700)] 
Change the pager to a ui_file

This rewrites the output pager as a ui_file implementation.

A new header is introduced to declare the pager class.  The
implementation remains in utils.c for the time being, because there
are some static globals there that must be used by this code.  (This
could be cleaned up at some future date.)

I went through all the text output in gdb to ensure that this change
should be ok.  There are a few cases:

* Any existing call to printf_unfiltered is required to be avoid the
  pager.  This is ensured directly in the implementation.

* All remaining calls to the f*_unfiltered functions -- the ones that
  take an explicit ui_file -- either send to an unfiltered stream
  (e.g., gdb_stderr), which is obviously ok; or conditionally send to
  gdb_stdout

  I investigated all such calls by searching for:

    grep -e '\bf[a-z0-9_]*_unfiltered' *.[chyl] */*.[ch] | grep -v gdb_stdlog | grep -v gdb_stderr

  This yields a number of candidates to check.

  * The breakpoint _print_recreate family, and
    save_trace_state_variables.  These are used for "save" commands
    and so are fine.

  * Things printing to a temporary stream.  Obviously ok.

  * Disassembly selftests.

  * print_gdb_help - this is non-obvious, but ok because paging isn't
    yet enabled at this point during startup.

  * serial.c - doens't use gdb_stdout

  * The code in compile/.  This is all printing to a file.

  * DWARF DIE dumping - doesn't reference gdb_stdout.

* Calls to the _filtered form -- these are all clearly ok, because if
  they are using gdb_stdout, then filtering will still apply; and if
  not, then filtering never applied and still will not.

Therefore, at this point, there is no longer any distinction between
all the other _filtered and _unfiltered calls, and they can be
unified.

In this patch, take special note of the vfprintf_maybe_filtered and
ui_file::vprintf change.  This is one instance of the above idea,
erasing the distinction between filtered and unfiltered -- in this
part of the change, the "unfiltered_output" flag is never passe to
cli_ui_out.  Subsequent patches will go much further in this
direction.

Also note the can_emit_style_escape changes in ui-file.c.  Checking
against gdb_stdout or gdb_stderr was always a bit of a hack; and now
it is no longer needed, because this is decision can be more fully
delegated to the particular ui_file implementation.

ui_file::can_page is removed, because this patch removed the only call
to it.

I think this is the main part of fixing PR cli/7234.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7234

2 years agoRemove vfprintf_styled_no_gdbfmt
Tom Tromey [Sat, 1 Jan 2022 20:35:13 +0000 (13:35 -0700)] 
Remove vfprintf_styled_no_gdbfmt

This removes vfprintf_styled_no_gdbfmt, inlining it at the sole point
of call.

2 years agoAdd style-escape methods to ui_file
Tom Tromey [Sat, 1 Jan 2022 08:34:48 +0000 (01:34 -0700)] 
Add style-escape methods to ui_file

This adds emit_style_escape and reset_style methods to ui_file.  These
aren't used yet, but they will be once the pager is converted to be a
ui_file subclass.

2 years agoAdd puts_unfiltered method to ui_file
Tom Tromey [Fri, 31 Dec 2021 21:34:07 +0000 (14:34 -0700)] 
Add puts_unfiltered method to ui_file

When the pager is rewritten as a ui_file, gdb will still need a way to
bypass the filtering.  After examining a few approaches, I chose this
patch, which adds a puts_unfiltered method to ui_file.  For most
implementations of ui_file, this will just delegate to puts.  This
patch also switches printf_unfiltered to use the new method.

2 years agoOnly have one API for unfiltered output
Tom Tromey [Sat, 1 Jan 2022 19:18:47 +0000 (12:18 -0700)] 
Only have one API for unfiltered output

At the end of this series, the use of unfiltered output will be very
restricted -- only places that definitely need it will use it.  To
this end, I thought it would be good to reduce the number of
_unfiltered APIs that are exposed.  This patch changes gdb so that
only printf_unfiltered exists.  (After this patch, the f* variants
still exist as well, but those will be removed later.)

2 years agoRemove some uses of printf_unfiltered
Tom Tromey [Sat, 8 Jan 2022 23:31:44 +0000 (16:31 -0700)] 
Remove some uses of printf_unfiltered

A number of spots call printf_unfiltered only because they are in code
that should not be interrupted by the pager.  However, I believe these
cases are all handled by infrun's blanket ban on paging, and so can be
converted to the default (_filtered) API.

After this patch, I think all the remaining _unfiltered calls are ones
that really ought to be.  A few -- namely in complete_command -- could
be replaced by a scoped assignment to pagination_enabled, but for the
remainder, the code seems simple enough like this.

2 years agoUse unfiltered output in annotate.c
Tom Tromey [Sat, 8 Jan 2022 23:23:18 +0000 (16:23 -0700)] 
Use unfiltered output in annotate.c

It seems to me that annotations should not be filtered.  While it
might be weird for an annotation-based UI to use the pager, it's not,
I think, out of the question.  This patch makes this change.

2 years agogdb/remote: use current_inferior in read_ptid if multi-process not supported
Tankut Baris Aktemur [Tue, 29 Mar 2022 14:19:10 +0000 (16:19 +0200)] 
gdb/remote: use current_inferior in read_ptid if multi-process not supported

When parsing the ptid out of a reply package, if the multi-process
extensions are not supported, use current_inferior's pid as the pid of
the reported thread, instead of inferior_ptid.  This is needed because
the inferior_ptid may be null_ptid although a legit context exists,
due to a prior context switch via switch_to_inferior_no_thread.

Below is a scenario that illustrates what could go wrong.  First,
setup a multi-target scenario.  This is needed, because in a
multi-target setting, the inferior_ptid is cleared out before waiting
on targets.  The second inferior below sits on top of a remote target.
Multi-process packets are disabled.

  $ # First, spawn a process with PID 26253 to attach to later.
  $ gdb-up a.out
  Reading symbols from a.out...
  (gdb) maint set target-non-stop on
  (gdb) set remote multiprocess-feature-packet off
  (gdb) start
  ...
  (gdb) add-inferior -no-connection
  [New inferior 2]
  Added inferior 2
  (gdb) inferior 2
  [Switching to inferior 2 [<null>] (<noexec>)]
  (gdb) target extended-remote | gdbserver --multi -
  Remote debugging using | gdbserver --multi -
  Remote debugging using stdio
  (gdb) attach 26253
  Attaching to Remote target
  Attached; pid = 26253
  [New Thread 26253]
  [New inferior 3]
  Reading /tmp/a.out from remote target...
  ...
  [New Thread 26253]
  ...
  Reading /usr/local/lib/debug/....debug from remote target...
  >>> GDB seems to hang here.

After attaching to a process and reading some library files, GDB
seems to hang.  One interesting thing to note is that

  [New Thread 26253]

appears twice.  We also see

  [New inferior 3]

Running the same scenario with "debug infrun on" reveals more details.

  ...
  (gdb) attach 26253
  [infrun] scoped_disable_commit_resumed: reason=attaching
  Attaching to Remote target
  Attached; pid = 26253
  [New Thread 26253]
  [infrun] infrun_async: enable=1
  [infrun] attach_command: immediately after attach:
  [infrun] attach_command:   thread 26253.26253.0, executing = 1, resumed = 0, state = RUNNING
  [infrun] clear_proceed_status_thread: 26253.26253.0
  [infrun] reset: reason=attaching
  [infrun] maybe_set_commit_resumed_all_targets: not requesting commit-resumed for target native, no resumed threads
  [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed for target extended-remote
  [infrun] fetch_inferior_event: enter
    [infrun] scoped_disable_commit_resumed: reason=handling event
    [infrun] do_target_wait: Found 2 inferiors, starting at #1
    [infrun] random_pending_event_thread: None found.
    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) =
    [infrun] print_target_wait_results:   26253.26253.0 [Thread 26253],
    [infrun] print_target_wait_results:   status->kind = STOPPED, sig = GDB_SIGNAL_0
    [infrun] handle_inferior_event: status->kind = STOPPED, sig = GDB_SIGNAL_0
    [infrun] start_step_over: enter
      [infrun] start_step_over: stealing global queue of threads to step, length = 0
      [infrun] operator(): step-over queue now empty
    [infrun] start_step_over: exit
    [infrun] context_switch: Switching context from 0.0.0 to 26253.26253.0
    [infrun] handle_signal_stop: stop_pc=0x7f849d8cf151
    [infrun] stop_waiting: stop_waiting
    [infrun] stop_all_threads: starting
    [infrun] stop_all_threads: pass=0, iterations=0
  [New inferior 3]
  Reading /tmp/a.out from remote target...
  warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
  Reading /tmp/a.out from remote target...
  Reading symbols from target:/tmp/a.out...
  [New Thread 26253]
    [infrun] stop_all_threads:   4723.4723.0 not executing
    [infrun] stop_all_threads:   26253.26253.0 not executing
    [infrun] stop_all_threads:   42000.26253.0 executing, need stop
    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) =
    [infrun] print_target_wait_results:   -1.0.0 [Thread 0],
    [infrun] print_target_wait_results:   status->kind = IGNORE
    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) =
    [infrun] print_target_wait_results:   -1.0.0 [Thread 0],
    [infrun] print_target_wait_results:   status->kind = IGNORE

GDB tried to stop Thread 42000.26253.0, which does not exist, and we
are waiting for a stop event that will never happen.  The PID in
'42000.26253.0', namely 42000, is the PID of magic_null_ptid.
It comes from gdb/remote.c:read_ptid:

  /* Since the stub is not sending a process id, then default to
     what's in inferior_ptid, unless it's null at this point.  If so,
     then since there's no way to know the pid of the reported
     threads, use the magic number.  */
  if (inferior_ptid == null_ptid)
    pid = magic_null_ptid.pid ();
  else
    pid = inferior_ptid.pid ();

  if (obuf)
    *obuf = pp;
  return ptid_t (pid, tid);

Because multi-process was turned off, GDB did not parse an explicitly
specified PID.  Furthermore, inferior_ptid == null_ptid, and
eventually GDB picked the PID from magic_null_ptid.

If target-non-stop is not turned on at the beginning, the same bug
reveals itself as a duplicated thread as shown below.

  # Same setup as above, without 'maint set target-non-stop on'.
  ...
  (gdb) attach 26253
  Attaching to Remote target
  Attached; pid = 26253
  [New inferior 3]
  ...
  [New Thread 26253]
  ...
  (gdb) info threads
    Id   Target Id             Frame
    1.1  process 13517 "a.out" main () at test.c:3
  * 2.1  Thread 26253 "a.out"  0x00007f12750c5151 in read () from target:/lib/x86_64-linux-gnu/libc.so.6
    3.1  Thread 26253 "a.out"  Remote 'g' packet reply is too long (expected 560 bytes, got 2496 bytes): 00feffffffffffff000a3a75127f000051510c75127f0000000400000000000060d24ef6af5500000000000000000000680d000000000000b85b31e3fc7f0000c0283a75127f000000e55b75127f000010d04ef6af550000460200000000000060c73975127f0000a0d23975127f0000000a3a75127f0000000000000000000051510c75127f000046020000330000002b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f03000000000000ffff0000000000000000000000000000000000000000000080143a75127f000080143a75127f000040143a75127f000040143a75127f00007d0000007e0000007f00000080000000300c3a75127f0000300c3a75127f00000e000000000000000e0000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0400000004000000040000000400000020143a75127f000020143a75127f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801f0000000000000000000000e55b75127f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  (gdb)

Fix the problem by preferring current_inferior()'s pid instead of
magic_null_ptid.

Regression-tested on X86-64 Linux.

Co-authored-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
2 years agogdb/testsuite: fix test failure when building against readline v7
Andrew Burgess [Sat, 26 Mar 2022 13:41:33 +0000 (13:41 +0000)] 
gdb/testsuite: fix test failure when building against readline v7

The test added in the commit:

  commit a6b413d24ccc5d76179bab866834e11fd6fec294
  Date:   Fri Mar 11 14:44:03 2022 +0000

      gdb: work around prompt corruption caused by bracketed-paste-mode

Was not written with readline 7 in mind, only readline 8+.  Between
readline 7 and 8 the escape sequence used to disable bracketed paste
mode changed, an additional '\r' character was added to the end.  In
fact, it was the addition of this '\r' character that triggered the
issue for which the above commit is part of the solution.

Anyway, the test tries to spot the case where the output from GDB is
not perfect, but does have the above work around applied.  However,
the pattern in the test assumes that the problematic '\r' will be
present, and this is only true for readline 8+.  With readline 7 the
test was failing.

In this commit I generalise the pattern a little so that the test will
still KFAIL with readline 7.

It's a little unfortunate that the test is KFAILing with readline 7,
as without the problematic '\r' there's actually no reason that GDB
couldn't "do the right thing" in this case, in which case, the test
would PASS, but that would require changes within GDB itself.

My preference then is that initially we patch the test to get it
KFAILing, then in a separate commit I can modify GDB so that it can
PASS with readline 7.

2 years agogdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp
Andrew Burgess [Wed, 23 Mar 2022 15:23:47 +0000 (15:23 +0000)] 
gdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp

The test gdb.python/py-format-address.exp, added in commit:

  commit 25209e2c6979c3838e14e099f0333609810db280
  Date:   Sat Oct 23 09:59:25 2021 +0100

      gdb/python: add gdb.format_address function

included 3 copy & paste errors where the wrong address was used in the
expected output patterns.

The test compiles two almost identical test binaries (one function
changes its name, that's the only difference), two inferiors are
created, each inferior using one of the test binaries.

We then take the address of the name changing function in both
inferiors ('foo' in inferior 1 and 'bar' in inferior 2) and the tests
are carried out using these addresses.

What we're checking for is that symbols 'foo' and 'bar' show up in the
correct inferior, and that (as this test is for a Python API feature),
the user can have one inferior selected, but ask about the other
inferior, and see the correct symbol in the result.

The hope is that the two binaries will be laid out identically by the
compiler, and that 'foo' and 'bar' will be at the same address.  This
is fine, unless the executable is compiled as PIE (position
independent executable), in which case there is a problem.

The problem is that though inferior 1 is set running, the inferior 2
never is.  If the executables are compiled as PIE, then the address in
the inferior 2 will not have been resolved, while the address in the
inferior 1 will have been, and so the two addresses we use in the
tests will be different.

This issue was reported here:

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

The first part of the fix is to use the correct address variable in
the expected output patterns, with this change the tests pass even
when the executables are compiled as PIE.

A second part of this fix is to pass the 'nopie' option when we
compile the tests, this should ensure that the address obtained in
inferior 2 is the same as the address from inferior 1, which makes the
test more useful.

2 years agogdb/mi: fix use after free of frame_info causing spurious notifications
Andrew Burgess [Wed, 23 Mar 2022 19:00:35 +0000 (19:00 +0000)] 
gdb/mi: fix use after free of frame_info causing spurious notifications

In commit:

  commit a2757c4ed693cef4ecc4dcdcb2518353eb6b3c3f
  Date:   Wed Mar 16 15:08:22 2022 +0000

      gdb/mi: consistently notify user when GDB/MI client uses -thread-select

Changes were made to GDB to address some inconsistencies in when
notifications are sent from a MI terminal to a CLI terminal (when
multiple terminals are in use, see new-ui command).

Unfortunately, in order to track when the currently selected frame has
changed, that commit grabs a frame_info pointer before and after an MI
command has executed, and compares the pointers to see if the frame
has changed.

This is not safe.

If the frame cache is deleted for any reason then the frame_info
pointer captured before the command started, is no longer valid, and
any comparisons based on that pointer are undefined.

This was leading to random test failures for some folk, see:

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

This commit changes GDB so we no longer hold frame_info pointers, but
instead store the frame_id and frame_level, this is safe even when the
frame cache is flushed.

2 years agobfd/Dwarf2: gas doesn't mangle names
Jan Beulich [Tue, 29 Mar 2022 06:19:14 +0000 (08:19 +0200)] 
bfd/Dwarf2: gas doesn't mangle names

Include the language identifier emitted by gas in the set of ones where
no mangled names are expected. Even if there could be "hand-mangled"
names, gas doesn't emit DW_AT_linkage_name in the first place.

2 years agobfd/Dwarf2: make find-nearest-line returned function name consistent
Jan Beulich [Tue, 29 Mar 2022 06:18:49 +0000 (08:18 +0200)] 
bfd/Dwarf2: make find-nearest-line returned function name consistent

Prior to entering the enclosing "else if()" the earlier associated if()
checks function->is_linkage and, if set, uses function->name. The
comment in patch context precedes (and explains) the setting
function->is_linkage. Yet with the flag set, we should then also return
the function name, just like said earlier if() would do when we came
here a 2nd time for the same "addr". And indeed passing the same address
twice on addr2line's command line would resolve the function for the 2nd
instance, but not for the 1st (if this code path is taken). (This,
obviously, is particularly relevant when there's no ELF symbol table in
the first place, like would be the case - naturally - in PE/COFF
binaries, for example.)

2 years agogas/Dwarf: special-case .linefile only for macros
Jan Beulich [Tue, 29 Mar 2022 06:18:14 +0000 (08:18 +0200)] 
gas/Dwarf: special-case .linefile only for macros

Restrict the PR gas/16908 workaround to just macros, matching the
original intention as well as the comment there. For constructs like
.irp or .rept the reasoning doesn't apply, as there's no separate
"invocation" point which may be of interest to record (for, as said
there, short macros).

2 years agoRISC-V: correct FCVT.Q.L[U]
Jan Beulich [Tue, 29 Mar 2022 06:17:49 +0000 (08:17 +0200)] 
RISC-V: correct FCVT.Q.L[U]

While the spec isn't explicit about this, it pointing out the similarity
with the D extension ought to extend to the ignoring of a meaningless
rounding mode: "Note FCVT.D.W[U] always produces an exact result and is
unaffected by rounding mode." Hence the chosen encodings also ought to
match.

Note that to avoid breaking existing code the forms with a 3rd operand
are not removed, which means there continues to be a difference to
FCVT.D.W[U].

2 years agosim: add arch/.gdbinit stub scripts
Mike Frysinger [Tue, 22 Feb 2022 03:35:38 +0000 (22:35 -0500)] 
sim: add arch/.gdbinit stub scripts

Make it easy to load the common gdbinit script even when running in
the arch/ subdir instead of the top-level sim dir.

2 years agoasan: heap buffer overflow in pa_chk_field_selector
Alan Modra [Mon, 28 Mar 2022 07:21:30 +0000 (17:51 +1030)] 
asan: heap buffer overflow in pa_chk_field_selector

The buffer overflow showed up running the gas "all macro" test.

PR 29005
* config/tc-hppa.c (pa_chk_field_selector): Don't read past end
of line.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 29 Mar 2022 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAdd Rust parser check for end of expression
Tom Tromey [Fri, 18 Mar 2022 04:36:12 +0000 (22:36 -0600)] 
Add Rust parser check for end of expression

I noticed that "print 5," passed in Rust -- the parser wasn't checking
that the entire input was used.  This patch fixes the problem.  This
in turn pointed out another bug in the parser, namely that it didn't
lex the next token after handling a string token.  This is also fixed
here.

2 years agoSwitch gdb_stdlog to use timestamped_file
Tom Tromey [Fri, 31 Dec 2021 19:00:11 +0000 (12:00 -0700)] 
Switch gdb_stdlog to use timestamped_file

Currently, timestamps for logging are done by looking for the use of
gdb_stdlog in vfprintf_unfiltered.  This seems potentially buggy, in
that during logging or other redirects (like execute_fn_to_ui_file) we
might have gdb_stdout==gdb_stdlog and so, conceivably, wind up with
timestamps in a log when they were not desired.

It seems better, instead, for timestamps to be a property of the
ui_file itself.

This patch changes gdb to use the new timestamped_file for gdb_stdlog
where appropriate, and removes the special case from
vfprintf_unfiltered.

Note that this may somewhat change the output in some cases -- in
particular, when going through execute_fn_to_ui_file (or the _string
variant), timestamps won't be emitted.  This could be fixed in those
functions, but it wasn't clear to me whether this is really desirable.

Note also that this changes the TUI to send gdb_stdlog to gdb_stderr.
I imagine that the previous use of gdb_stdout here was inadvertent.
(And in any case it probably doesn't matter.)

2 years agoAdd new timestamped_file class
Tom Tromey [Fri, 31 Dec 2021 18:44:19 +0000 (11:44 -0700)] 
Add new timestamped_file class

This adds a "timestamped_file" subclass of ui_file.  This class adds a
timestamp to its output when appropriate.  That is, it follows the
rule already used in vfprintf_unfiltered of adding a timestamp at most
once per write.

The new class is not yet used.

2 years agoUse unique_ptr in CLI logging code
Tom Tromey [Fri, 31 Dec 2021 18:34:59 +0000 (11:34 -0700)] 
Use unique_ptr in CLI logging code

This changes the CLI logging code to avoid manual memory management
(to the extent possible) by using unique_ptr in a couple of spots.
This will come in handy in a later patch.

2 years agoSimplify the CLI set_logging logic
Tom Tromey [Fri, 31 Dec 2021 18:30:22 +0000 (11:30 -0700)] 
Simplify the CLI set_logging logic

The CLI's set_logging logic seemed unnecessarily complicated to me.
This patch simplifies it, with an eye toward changing it to use RAII
objects in a subsequent patch.

I did not touch the corresponding MI code.  That code seems incorrect
(nothing ever uses raw_stdlog, and nothing ever sets
saved_raw_stdlog).  I didn't attempt to fix this, because I question
whether this is even useful for MI.

2 years agoHandle multiple addresses in call_site_target
Tom Tromey [Fri, 19 Nov 2021 17:12:44 +0000 (10:12 -0700)] 
Handle multiple addresses in call_site_target

A large customer program has a function that is partitioned into hot
and cold parts.  A variable in a callee of this function is described
using DW_OP_GNU_entry_value, but gdb gets confused when trying to find
the caller.  I tracked this down to dwarf2_get_pc_bounds interpreting
the function's changes so that the returned low PC is the "wrong"
function.

Intead, when processing DW_TAG_call_site, the low PC of each range in
DW_AT_ranges should be preserved in the call_site_target.  This fixes
the variable lookup in the test case I have.

I didn't write a standalone test for this as it seemed excessively
complicated.

2 years agoChange call_site_target to iterate over addresses
Tom Tromey [Fri, 19 Nov 2021 16:28:51 +0000 (09:28 -0700)] 
Change call_site_target to iterate over addresses

In order to handle the case where a call site target might refer to
multiple addresses, we change the code to use a callback style.  Any
spot using call_site_target::address now passes in a callback function
that may be called multiple times.

2 years agoChange call_site_find_chain_1 to work recursively
Tom Tromey [Fri, 19 Nov 2021 16:23:09 +0000 (09:23 -0700)] 
Change call_site_find_chain_1 to work recursively

call_site_find_chain_1 has a comment claiming that recursive calls
would be too expensive.  However, I doubt this is so expensive; and
furthermore the explicit state management approach here is difficult
both to understand and to modify.  This patch changes this code to use
explicit recursion, so that a subsequent patch can generalize this
code without undue trauma.

Additionally, I think this patch detects a latent bug in the recursion
code.  (It's hard for me to be completely certain.)  The bug is that
when a new target_call_site is entered, the code does:

  if (target_call_site)
    {
      if (addr_hash.insert (target_call_site->pc ()).second)
{
  /* Successfully entered TARGET_CALL_SITE.  */

  chain.push_back (target_call_site);
  break;
}
    }

Here, if entering the target_call_site fails, then any tail_call_next
elements in this call site are not visited.  However, if this code
does happen to enter a call site, then the tail_call_next elements
will be visited during backtracking.  This applies when doing the
backtracking as well -- it will only continue through a given chain as
long as each element in the chain can successfully be visited.

I'd appreciate some review of this.  If this behavior is intentional,
it can be added to the new implementation.

2 years agoConstify chain_candidate
Tom Tromey [Fri, 19 Nov 2021 15:02:38 +0000 (08:02 -0700)] 
Constify chain_candidate

While investigating this bug, I wasn't sure if chain_candidate might
update 'chain'.  I changed it to accept a const reference, making it
clear that it cannot.  This simplifies the code a tiny bit as well.

2 years agoMake call_site_target members private
Tom Tromey [Thu, 18 Nov 2021 19:26:02 +0000 (12:26 -0700)] 
Make call_site_target members private

This makes the data members of call_site_target 'private'.  This lets
us remove most of its public API.  call_site_to_target_addr is changed
to be a method of this type.  This is a preparatory refactoring for
the fix at the end of this series.

2 years agoChange call_site_target to use custom type and enum
Tom Tromey [Thu, 18 Nov 2021 18:25:29 +0000 (11:25 -0700)] 
Change call_site_target to use custom type and enum

call_site_target reuses field_loc_kind and field_location.  However,
it has never used the full range of the field_loc_kind enum.  In a
subsequent patch, I plan to add a new 'kind' here, so it seemed best
to avoid this reuse and instead introduce new types here.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 28 Mar 2022 00:00:05 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 27 Mar 2022 00:00:06 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoRemove an unused declaration from value.h
Tom Tromey [Fri, 25 Mar 2022 19:59:23 +0000 (13:59 -0600)] 
Remove an unused declaration from value.h

value.h has a declaration of value_print_array_elements that is
incorrect.  In C, this would have been an error, but in C++ this is a
declaration of an overload that is neither defined nor used.  This
patch removes the declaration.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 26 Mar 2022 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agolibtool.m4: fix the NM="/nm/over/here -B/option/with/path" case
Nick Alcock [Fri, 3 Dec 2021 16:33:25 +0000 (16:33 +0000)] 
libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case

My previous nm patch handled all cases but one -- if the user set NM in
the environment to a path which contained an option, libtool's nm
detection tries to run nm against a copy of nm with the options in it:
e.g. if NM was set to "nm --blargle", and nm was found in /usr/bin, the
test would try to run "/usr/bin/nm --blargle /usr/bin/nm --blargle".
This is unlikely to be desirable: in this case we should run
"/usr/bin/nm --blargle /usr/bin/nm".

Furthermore, as part of this nm has to detect when the passed-in $NM
contains a path, and in that case avoid doing a path search itself.
This too was thrown off if an option contained something that looked
like a path, e.g. NM="nm -B../prev-gcc"; libtool then tries to run
"nm -B../prev-gcc nm" which rarely works well (and indeed it looks
to see whether that nm exists, finds it doesn't, and wrongly concludes
that nm -p or whatever does not work).

Fix all of these by clipping all options (defined as everything
including and after the first " -") before deciding whether nm
contains a path (but not using the clipped value for anything else),
and then removing all options from the path-modified nm before
looking to see whether that nm existed.

NM=my-nm now does a path search and runs e.g.
  /usr/bin/my-nm -B /usr/bin/my-nm

NM=/usr/bin/my-nm now avoids a path search and runs e.g.
  /usr/bin/my-nm -B /usr/bin/my-nm

NM="my-nm -p../wombat" now does a path search and runs e.g.
  /usr/bin/my-nm -p../wombat -B /usr/bin/my-nm

NM="../prev-binutils/new-nm -B../prev-gcc" now avoids a path search:
  ../prev-binutils/my-nm -B../prev-gcc -B ../prev-binutils/my-nm

This seems to be all combinations, including those used by GCC bootstrap
(which, before this commit, fails to bootstrap when configured
--with-build-config=bootstrap-lto, because the lto plugin is now using
--export-symbols-regex, which requires libtool to find a working nm,
while also using -B../prev-gcc to point at the lto plugin associated
with the GCC just built.)

Regenerate all affected configure scripts.

* libtool.m4 (LT_PATH_NM): Handle user-specified NM with
options, including options containing paths.

2 years agoRe: gas/Dwarf: improve debug info generation from .irp and alike blocks
Alan Modra [Thu, 24 Mar 2022 22:32:22 +0000 (09:02 +1030)] 
Re: gas/Dwarf: improve debug info generation from .irp and alike blocks

am33_2.0-linux is a mn10300 target.

* testsuite/gas/elf/dwarf-5-irp.d: xfail am33.

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 25 Mar 2022 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoRemove download size from debuginfod progress messages if unavailable
Aaron Merey [Wed, 23 Mar 2022 00:01:54 +0000 (20:01 -0400)] 
Remove download size from debuginfod progress messages if unavailable

Currently debuginfod progress update messages include the size of
each download:

  Downloading 7.5 MB separate debug info for /lib/libxyz.so.0

This value originates from the Content-Length HTTP header of the
transfer.  However this header is not guaranteed to be present for
each download.  This can happen when debuginfod servers compress files
on-the-fly at the time of transfer.  In this case gdb wrongly prints
"-0.00 MB" as the size.

This patch removes download sizes from progress messages when they are
not available.  It also removes usage of the progress bar until
a more thorough reworking of progress updating is implemented. [1]

[1] https://sourceware.org/pipermail/gdb-patches/2022-February/185798.html

2 years agosim: fix a comment typo in sim-load.c
Reuben Thomas [Wed, 23 Mar 2022 11:05:23 +0000 (11:05 +0000)] 
sim: fix a comment typo in sim-load.c

Fix a typo where the documentation refers to a function parameter by the
wrong name.

Change-Id: I99494efe62cd4aa76fb78a0bd5da438d35740ebe

2 years agosim: fix “alligned” typos
Reuben Thomas [Thu, 24 Mar 2022 12:05:21 +0000 (12:05 +0000)] 
sim: fix “alligned” typos

Change-Id: Ifd574e38524dd4f1cf0fc003e0c5c7499abc84a0

2 years agox86: mention dropped L1OM/K1OM support in ld/ as well
Jan Beulich [Thu, 24 Mar 2022 14:27:28 +0000 (15:27 +0100)] 
x86: mention dropped L1OM/K1OM support in ld/ as well

This amends e961c696dcb2 ("x86: drop L1OM/K1OM support from ld"). Also
remove the marker that I mistakenly added in c085ab00c7b2 ("x86: drop
L1OM/K1OM support from gas").

2 years agogdb/testsuite: remove gdb.python/pretty-print-call-by-hand.exp
Simon Marchi [Thu, 24 Mar 2022 14:21:10 +0000 (10:21 -0400)] 
gdb/testsuite: remove gdb.python/pretty-print-call-by-hand.exp

This test was added without a corresponding fix, with some setup_kfails.
However, it results in UNRESOLVED results when GDB is built with ASan.

  ERROR: GDB process no longer exists
  GDB process exited with wait status 1946871 exp7 0 1
  UNRESOLVED: gdb.python/pretty-print-call-by-hand.exp: frame print: backtrace test (PRMS gdb/28856)

Remove the test from the tree, I'll attach it to the Bugzilla bug
instead [1].

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=28856

Change-Id: Id95d8949fb8742874bd12aeac758aa4d7564d678

2 years agox86: drop L1OM/K1OM support from ld
Jan Beulich [Thu, 24 Mar 2022 08:38:55 +0000 (09:38 +0100)] 
x86: drop L1OM/K1OM support from ld

This was only rudimentary support anyway; none of the sub-architecture
specific insns were ever supported.

2 years agox86: drop L1OM special case from disassembler
Jan Beulich [Thu, 24 Mar 2022 08:38:19 +0000 (09:38 +0100)] 
x86: drop L1OM special case from disassembler

There wasn't any real support anyway: None of the sub-architecture
specific insns were ever supported.

2 years agoMAINTAINERS: add myself
Jan Beulich [Thu, 24 Mar 2022 08:35:56 +0000 (09:35 +0100)] 
MAINTAINERS: add myself

I much appreciate Nick offering this role to me. Nevertheless there's
still a lot for me to learn here.

At this occasion also update my email address in the pre-existing, much
more narrow entry.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 24 Mar 2022 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agogdb/testsuite: address test failures in gdb.mi/mi-multi-commands.exp
Andrew Burgess [Tue, 22 Mar 2022 10:23:26 +0000 (10:23 +0000)] 
gdb/testsuite: address test failures in gdb.mi/mi-multi-commands.exp

The gdb.mi/mi-multi-commands.exp test was added in commit:

  commit d08cbc5d3203118da5583296e49273cf82378042
  Date:   Wed Dec 22 12:57:44 2021 +0000

      gdb: unbuffer all input streams when not using readline

And then tweaked in commit:

  commit 144459531dd68a1287905079aaa131b777a8cc82
  Date:   Mon Feb 7 20:35:58 2022 +0000

      gdb/testsuite: relax pattern in new gdb.mi/mi-multi-commands.exp test

The second of these commits was intended to address periodic test
failures that I was seeing, and this change did fix some problems,
but, unfortunately, introduced other issues.

The problem is that the test relies on sending two commands to GDB in
a single write.  As the characters that make these two commands arrive
they are echoed to GDB's console.  However, there is a race between
how quickly the characters are echoed and how quickly GDB decides to
act on the incoming commands.

Usually, both commands are echoed in full before GDB acts on the first
command, but sometimes this is not the case, and GDB can execute the
first command before both commands are fully echoed to the console.
In this case, the output of the first command will be mixed in with
the echoing of the second command.

This mixing of the command echoing and the first command output is
what was causing failures in the original version of the test.

The second commit relaxed the expected output pattern a little, but
was still susceptible to failures, so this commit further relaxes the
pattern.

Now, we look for the first command output with no regard to what is
before, or after the command.  Then we look for the first mi prompt to
indicate that the first command has completed.

I believe that this change should make the test more stable than it
was before.

2 years agolibctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option
Nick Alcock [Fri, 18 Mar 2022 13:20:29 +0000 (13:20 +0000)] 
libctf: add LIBCTF_WRITE_FOREIGN_ENDIAN debugging option

libctf has always handled endianness differences by detecting
foreign-endian CTF dicts on the input and endian-flipping them: dicts
are always written in native endianness.  This makes endian-awareness
very low overhead, but it means that the foreign-endian code paths
almost never get routinely tested, since "make check" usually reads in
dicts ld has just written out: only a few corrupted-CTF tests are
actually in fixed endianness, and even they only test the foreign-
endian code paths when you run make check on a big-endian machine.
(And the fix is surely not to add more .s-based tests like that, because
they are a nightmare to maintain compared to the C-code-based ones.)

To improve on this, add a new environment variable,
LIBCTF_WRITE_FOREIGN_ENDIAN, which causes libctf to unconditionally
endian-flip at ctf_write time, so the output is always in the wrong
endianness.  This then tests the foreign-endian read paths properly
at open time.

Make this easier by restructuring the writeout code in ctf-serialize.c,
which duplicates the maybe-gzip-and-write-out code three times (once
for ctf_write_mem, with thresholding, and once each for
ctf_compress_write and ctf_write just so those can avoid thresholding
and/or compression).  Instead, have the latter two call the former
with thresholds of 0 or (size_t) -1, respectively.

The endian-flipping code itself gains a bit of complexity, because
one single endian-flipper (flip_types) was assuming the input to be
in foreign-endian form and assuming it could pull things out of the
input once they had been flipped and make sense of them. At the
cost of a few lines of duplicated initializations, teach it to
read before flipping if we're flipping to foreign-endianness instead
of away from it.

libctf/
* ctf-impl.h (ctf_flip_header): No longer static.
(ctf_flip): Likewise.
* ctf-open.c (flip_header): Rename to...
(ctf_flip_header): ... this, now it is not private to one file.
(flip_ctf): Rename...
(ctf_flip): ... this too.  Add FOREIGN_ENDIAN arg.
(flip_types): Likewise.  Use it.
(ctf_bufopen_internal): Adjust calls.
* ctf-serialize.c (ctf_write_mem): Add flip_endian path via
a newly-allocated bounce buffer.
(ctf_compress_write): Move below ctf_write_mem and reimplement
in terms of it.
(ctf_write): Likewise.
(ctf_gzwrite): Note that this obscure writeout function does not
support endian-flipping.

2 years agolibctf, ld: diagnose corrupted CTF header cth_strlen
Nick Alcock [Fri, 18 Mar 2022 00:49:11 +0000 (00:49 +0000)] 
libctf, ld: diagnose corrupted CTF header cth_strlen

The last section in a CTF dict is the string table, at an offset
represented by the cth_stroff header field.  Its length is recorded in
the next field, cth_strlen, and the two added together are taken as the
size of the CTF dict.  Upon opening a dict, we check that none of the
header offsets exceed this size, and we check when uncompressing a
compressed dict that the result of the uncompression is the same length:
but CTF dicts need not be compressed, and short ones are not.
Uncompressed dicts just use the ctf_size without checking it.  This
field is thankfully almost unused: it is mostly used when reserializing
a dict, which can't be done to dicts read off disk since they're
read-only.

However, when opening an uncompressed foreign-endian dict we have to
copy it out of the mmaped region it is stored in so we can endian-
swap it, and we use ctf_size when doing that.  When the cth_strlen is
corrupt, this can overrun.

Fix this by checking the ctf_size in all uncompressed cases, just as we
already do in the compressed case.  Add a new test.

This came to light because various corrupted-CTF raw-asm tests had an
incorrect cth_strlen: fix all of them so they produce the expected
error again.

libctf/
PR libctf/28933
* ctf-open.c (ctf_bufopen_internal): Always check uncompressed
CTF dict sizes against the section size in case the cth_strlen is
corrupt.

ld/
PR libctf/28933
* testsuite/ld-ctf/diag-strlen-invalid.*: New test,
derived from diag-cttname-invalid.s.
* testsuite/ld-ctf/diag-cttname-invalid.s: Fix incorrect cth_strlen.
* testsuite/ld-ctf/diag-cttname-null.s: Likewise.
* testsuite/ld-ctf/diag-cuname.s: Likewise.
* testsuite/ld-ctf/diag-parlabel.s: Likewise.
* testsuite/ld-ctf/diag-parname.s: Likewise.

2 years agoinclude, libctf, ld: extend variable section to contain functions too
Nick Alcock [Wed, 16 Mar 2022 15:29:25 +0000 (15:29 +0000)] 
include, libctf, ld: extend variable section to contain functions too

The CTF variable section is an optional (usually-not-present) section in
the CTF dict which contains name -> type mappings corresponding to data
symbols that are present in the linker input but not in the output
symbol table: the idea is that programs that use their own symbol-
resolution mechanisms can use this section to look up the types of
symbols they have found using their own mechanism.

Because these removed symbols (mostly static variables, functions, etc)
all have names that are unlikely to appear in the ELF symtab and because
very few programs have their own symbol-resolution mechanisms, a special
linker flag (--ctf-variables) is needed to emit this section.

Historically, we emitted only removed data symbols into the variable
section.  This seemed to make sense at the time, but in hindsight it
really doesn't: functions are symbols too, and a C program can look them
up just like any other type.  So extend the variable section so that it
contains all static function symbols too (if it is emitted at all), with
types of kind CTF_K_FUNCTION.

This is a little fiddly.  We relied on compiler assistance for data
symbols: the compiler simply emits all data symbols twice, once into the
symtypetab as an indexed symbol and once into the variable section.

Rather than wait for a suitably adjusted compiler that does the same for
function symbols, we can pluck unreported function symbols out of the
symtab and add them to the variable section ourselves.  While we're at
it, we do the same with data symbols: this is redundant right now
because the compiler does it, but it costs very little time and lets the
compiler drop this kludge and save a little space in .o files.

include/
* ctf.h: Mention the new things we can see in the variable
section.

ld/
* testsuite/ld-ctf/data-func-conflicted-vars.d: New test.

libctf/
* ctf-link.c (ctf_link_deduplicating_variables): Duplicate
symbols into the variable section too.
* ctf-serialize.c (symtypetab_delete_nonstatic_vars): Rename
to...
(symtypetab_delete_nonstatics): ... this.  Check the funchash
when pruning redundant variables.
(ctf_symtypetab_sect_sizes): Adjust accordingly.
* NEWS: Describe this change.

2 years agold, testsuite: improve CTF-availability test
Nick Alcock [Wed, 17 Nov 2021 14:47:44 +0000 (14:47 +0000)] 
ld, testsuite: improve CTF-availability test

The test for -gctf support in the compiler is used to determine when to
run the ld-ctf tests and most of those in libctf.  Unfortunately,
because it uses check_compiler_available and compile_one_cc, it will
fail whenever the compiler emits anything on stderr, even if it
actually does support CTF perfectly well.

So, instead, ask the compiler to emit assembler output and grep it for
references to ".ctf": this is highly unlikely to be present if the
compiler does not support CTF.  (This will need adjusting when CTF grows
support for non-ELF platforms that don't dot-prepend their section
names, but right now the linker doesn't link CTF on any such platforms
in any case.)

With this in place we can do things like run all the libctf tests under
leak sanitizers etc even if those spray warnings on simple CTF
compilations, rather than being blocked from doing so just when we would
most like to.

ld/
* testsuite/lib/ld-lib.exp (check_ctf_available): detect CTF
even if a CTF-capable compiler emits warnings.

2 years agogdb/python: remove Python 2/3 compatibility macros
Simon Marchi [Mon, 21 Mar 2022 14:07:41 +0000 (10:07 -0400)] 
gdb/python: remove Python 2/3 compatibility macros

New in this version:

 - Rebase on master, fix a few more issues that appeared.

python-internal.h contains a number of macros that helped make the code
work with both Python 2 and 3.  Remove them and adjust the code to use
the Python 3 functions.

Change-Id: I99a3d80067fb2d65de4f69f6473ba6ffd16efb2d

2 years agogdb/python: remove Python 2 support
Simon Marchi [Fri, 24 Dec 2021 01:20:46 +0000 (20:20 -0500)] 
gdb/python: remove Python 2 support

New in this version:

 - Add a PY_MAJOR_VERSION check in configure.ac / AC_TRY_LIBPYTHON.  If
   the user passes --with-python=python2, this will cause a configure
   failure saying that GDB only supports Python 3.

Support for Python 2 is a maintenance burden for any patches touching
Python support.  Among others, the differences between Python 2 and 3
string and integer types are subtle.  It requires a lot of effort and
thinking to get something that behaves correctly on both.  And that's if
the author and reviewer of the patch even remember to test with Python
2.

See this thread for an example:

  https://sourceware.org/pipermail/gdb-patches/2021-December/184260.html

So, remove Python 2 support.  Update the documentation to state that GDB
can be built against Python 3 (as opposed to Python 2 or 3).

Update all the spots that use:

 - sys.version_info
 - IS_PY3K
 - PY_MAJOR_VERSION
 - gdb_py_is_py3k

... to only keep the Python 3 portions and drop the use of some
now-removed compatibility macros.

I did not update the configure script more than just removing the
explicit references to Python 2.  We could maybe do more there, like
check the Python version and reject it if that version is not
supported.  Otherwise (with this patch), things will only fail at
compile time, so it won't really be clear to the user that they are
trying to use an unsupported Python version.  But I'm a bit lost in the
configure code that checks for Python, so I kept that for later.

Change-Id: I75b0f79c148afbe3c07ac664cfa9cade052c0c62

2 years agox86: reject relocations involving registers
Jan Beulich [Wed, 23 Mar 2022 11:31:29 +0000 (12:31 +0100)] 
x86: reject relocations involving registers

To prevent fatal or even internal errors, add a simple check to
i386_validate_fix(), rejecting relocations when their target symbol is
an equate of a register (or resolved to reg_section for any other
reason).

2 years agox86: improve resolution of register equates
Jan Beulich [Wed, 23 Mar 2022 11:31:04 +0000 (12:31 +0100)] 
x86: improve resolution of register equates

Allow transitive (or recursive) equates to work in addition to direct
ones. The only requirements are that
- the equate being straight of a register, i.e. no expressions involved
  (albeit I'm afraid something like "%eax + 0" will be viewed as %eax),
- at the point of use there's no forward ref left which cannot be
  resolved, yet.

2 years agoRevert "PR28977 tc-i386.c internal error in parse_register"
Jan Beulich [Wed, 23 Mar 2022 11:29:39 +0000 (12:29 +0100)] 
Revert "PR28977 tc-i386.c internal error in parse_register"

This reverts commit 5fac3f02edacfca458f7eeaaaa33a87e26e0e332,
which was superceeded / replaced by 4faaa10f3fab.

2 years agox86: don't attempt to resolve equates and alike from i386_parse_name()
Jan Beulich [Wed, 23 Mar 2022 11:28:53 +0000 (12:28 +0100)] 
x86: don't attempt to resolve equates and alike from i386_parse_name()

PR gas/28977

Perhaps right from its introduction in 4d1bb7955a8b it was wrong for
i386_parse_name() to call parse_register(). This being a hook from the
expression parser, it shouldn't be resolving e.g. equated symbols.
That's relevant only for all other callers of parse_register().

To compensate, in Intel syntax mode check_register() needs calling;
perhaps not doing so was an oversight right when the function was
introduced. This is necessary in particular to force EVEX encoding when
VRex registers are used (but of course also to reject bad uses of
registers, i.e. fully matching what parse_register() needs it for).

2 years agoUpdate the list of recognized m-profile TAG_CPU_ARCH_*
Luis Machado [Tue, 22 Mar 2022 17:01:47 +0000 (17:01 +0000)] 
Update the list of recognized m-profile TAG_CPU_ARCH_*

Check 3 additional variants previously not recognized:

- TAG_CPU_ARCH_V7E_M
- TAG_CPU_ARCH_V8M_BASE
- TAG_CPU_ARCH_V8M_MAIN

2 years agogas/Dwarf5: re-use file 0 line string table entry when faking file 0
Jan Beulich [Wed, 23 Mar 2022 07:48:24 +0000 (08:48 +0100)] 
gas/Dwarf5: re-use file 0 line string table entry when faking file 0

No need to emit the same string a 2nd time for file 1 in this case.

2 years agogas/Dwarf5: adjust .debug_line file 0 checking
Jan Beulich [Wed, 23 Mar 2022 07:48:02 +0000 (08:48 +0100)] 
gas/Dwarf5: adjust .debug_line file 0 checking

First of all when a table entry has a NULL filename, the two inner if()s
are better done the other way around: The 2nd doesn't depend on what the
first does. This then renders redundant half of the conditions of the
other if() and clarifies that subsequently only entry 0 is dealt with
(indicating that part of the comment was wrong). Finally for there to be
a usable name in slot 1, files_in_use needs to be larger than 1 and slot
1's (rather than slot 0's) name needs to be non-NULL.

2 years agogas/Dwarf5: drop dead code
Jan Beulich [Wed, 23 Mar 2022 07:47:41 +0000 (08:47 +0100)] 
gas/Dwarf5: drop dead code

Commit 3417bfca676f ("GAS: DWARF-5: Ensure that the 0'th entry in the
directory table contains the current... ") added a "dwarf_level < 5"
check to out_dir_and_file_list(). This rendered dead that branch of the
construct, due to the enclosing if()'s "DWARF2_LINE_VERSION >= 5".
Delete that code as well as the corresponding part of the comment.

While there also drop a redundant "dirs != NULL": "dirs" will always be
non-NULL when dirs_in_use is not zero.

2 years agogas/Dwarf: improve debug info generation from .irp and alike blocks
Jan Beulich [Wed, 23 Mar 2022 07:46:39 +0000 (08:46 +0100)] 
gas/Dwarf: improve debug info generation from .irp and alike blocks

Tying the bumping of the logical line number to reading from the
original source file looks wrong: Upon finishing of the processing of an
sb the original values will be restored anyway. Yet without bumping the
line counter uses of .line inside e.g. an .irp construct won't have the
intended effect: Such uses may be necessary to ensure proper debug info
is emitted in particular when switching sections inside the .irp body,
as dwarf2_gen_line_info() would bail without doing anything when it
finds the line number unchanged from what it saw last.

2 years agoELF32: don't silently truncate relocation addends
Jan Beulich [Wed, 23 Mar 2022 07:43:13 +0000 (08:43 +0100)] 
ELF32: don't silently truncate relocation addends

At least x86-64's x32 sub-mode and RISC-V's 32-bit mode calculate
addends as 64-bit values, but store them in signed 32-bit fields when
generating the file without encountering any earlier error. When the
relocated field is a 64-bit one, the value resulting after processing
the relocation record when linking (or the latest when loading) may
thus be wrong due to the truncation.

With the code change in place, one x32 testcase actually triggers the
new diagnostic. That one case of too large a (negative) addend is being
adjusted alongside the addition of a new testcase to actually trigger
the new error. (Note that due to internal BFD behavior the relocation in
.data doesn't get processed anymore after the errors in .text.)

Note that in principle it is possible to express 64-bit relocations in
ELF32, but this would require .rel relocations, i.e. with the addend
stored in the 64-bit field being relocated. But I guess it would be a
lot of effort for little gain to actually support this.

2 years agogas: retain whitespace between strings
Jan Beulich [Wed, 23 Mar 2022 07:41:54 +0000 (08:41 +0100)] 
gas: retain whitespace between strings

Macro arguments may be separated by commas or just whitespace. Macro
arguments may also be quoted (where one level of quotes is removed in
the course of determining the values for the respective formal
parameters). Furthermore this quote removal knows _two_ somewhat odd
escaping mechanisms: One, apparently in existence forever, is that a
pair of quotes counts as the escaping of a quote, with the pair being
transformed to a single quote in the course of quote removal. The other
(introduced by c06ae4f232e6) looks more usual on the surface in that it
deals with \" sequences, but it _retains_ the escaping \. Hence only the
former mechanism is suitable when the value to be used by the macro body
is to contain a quote. Yet this results in ambiguity of what "a""b" is
intended to mean; elsewhere (e.g. for .ascii) it represents two
successive string literals. However, in any event is the above different
from "a" "b": I don't think this can be viewed the same as "a""b" when
processing macro arguments.

Change the scrubber to retain such whitespace, by making the processing
of strings more similar to that of symbols. And indeed this appears to
make sense when taking into account that for quite a while gas has been
supporting quoted symbol names.

Taking a more general view, however, the change doesn't go quite far
enough. There are further cases where significant whitespace is removed
by the scrubber. The new testcase enumerates a few in its ".if 0"
section. I'm afraid the only way that I see to deal with this would be
to significantly simplify the scrubber, such that it wouldn't do much
more than collapse sequences of unquoted whitespace into a single blank.
To be honest problems in this area aren't really surprising when seeing
that there's hardly any checking of .macro use throughout the testsuite
(and in particular in the [relatively] generic tests under all/).

2 years agoOnly .so files are used in libcollector. Remove the other files.
Vladimir Mezentsev [Tue, 22 Mar 2022 22:15:04 +0000 (15:15 -0700)] 
Only .so files are used in libcollector. Remove the other files.

* libcollector/Makefile.am (install-data-local): Remove the *.la
and *.a libraries.
* libcollector/Makefile.in: Regenerate.

2 years agogdb: testsuite: use gdb_attach to fix jit-elf.exp
Tiezhu Yang [Thu, 17 Mar 2022 02:55:35 +0000 (10:55 +0800)] 
gdb: testsuite: use gdb_attach to fix jit-elf.exp

If /proc/sys/kernel/yama/ptrace_scope is 1, when execute the following
command without superuser:

  make check-gdb TESTS="gdb.base/jit-elf.exp"

we can see the following messages in gdb/testsuite/gdb.log:

  (gdb) attach 1650108
  Attaching to program: /home/yangtiezhu/build/gdb/testsuite/outputs/gdb.base/jit-elf/jit-elf-main, process 1650108
  ptrace: Operation not permitted.
  (gdb) FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: break here 1: attach

use gdb_attach to fix the above issue, at the same time, the clean_reattach
proc should return a value to indicate whether it worked, and the callers
should return early as well on failure.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp
Tiezhu Yang [Thu, 17 Mar 2022 02:25:09 +0000 (10:25 +0800)] 
gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp

If /proc/sys/kernel/yama/ptrace_scope is 1, when execute the following
command without superuser:

  make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"

we can see the following messages in gdb/testsuite/gdb.log:

  (gdb) attach 6500
  Attaching to process 6500
  ptrace: Operation not permitted.
  (gdb) PASS: gdb.base/attach-pie-noexec.exp: attach

It is obviously wrong, the expected result should be UNSUPPORTED in such
a case.

With this patch, we can see "Operation not permitted" in the log info,
and then we can do the following processes to test:
(1) set ptrace_scope as 0
    $ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
    $ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"
(2) use sudo
    $ sudo make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: testsuite: add new gdb_attach to check "attach" command
Tiezhu Yang [Thu, 17 Mar 2022 02:22:14 +0000 (10:22 +0800)] 
gdb: testsuite: add new gdb_attach to check "attach" command

This commit adds new gdb_attach to centralize the failure checking of
"attach" command. Return 0 if attach failed, otherwise return 1.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: testsuite: remove attach test from can_spawn_for_attach
Tiezhu Yang [Wed, 16 Mar 2022 06:36:09 +0000 (14:36 +0800)] 
gdb: testsuite: remove attach test from can_spawn_for_attach

As Pedro Alves said, caching procs should not issue pass/fail [1],
this commit removes attach test from can_spawn_for_attach, at the
same time, use "verbose -log" instead of "unsupported" to get a
trace about why a test run doesn't support spawning for attach.

[1] https://sourceware.org/pipermail/gdb-patches/2022-March/186311.html

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 23 Mar 2022 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAdd support for hardware breakpoints/watchpoints on FreeBSD/Aarch64.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
Add support for hardware breakpoints/watchpoints on FreeBSD/Aarch64.

This shares aarch64-nat.c and nat/aarch64-hw-point.c with the Linux
native target.  Since FreeBSD writes all of the debug registers in one
ptrace op, use an unordered_set<> to track the "dirty" state for
threads rather than bitmasks of modified registers.

2 years agofbsd-nat: Add a low_prepare_to_resume virtual method.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add a low_prepare_to_resume virtual method.

This method can be overridden by architecture-specific targets to
perform additional work before a thread is resumed.

2 years agofbsd-nat: Add a low_delete_thread virtual method.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add a low_delete_thread virtual method.

This method can be overridden by architecture-specific targets to
perform additional work when a thread is deleted.

Note that this method is only invoked on systems supporting LWP
events, but the pending use case (aarch64 debug registers) is not
supported on older kernels that do not support LWP events.

2 years agofbsd-nat: Add helper routine to fetch siginfo_t for a ptid.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add helper routine to fetch siginfo_t for a ptid.

2 years agoaarch64: Add an aarch64_nat_target mixin class.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
aarch64: Add an aarch64_nat_target mixin class.

This class includes platform-independent target methods for hardware
breakpoints and watchpoints using routines from
nat/aarch64-hw-point.c.

stopped_data_address is not platform-independent since the FAR
register holding the address for a breakpoint hit must be fetched in a
platform-specific manner.  However, aarch64_stopped_data_address is
provided as a helper routine which performs platform-independent
validation given the value of the FAR register.

For tracking the per-process debug register mirror state, use an
unordered_map indexed by pid as recently adopted in x86-nat.c rather
than a manual linked-list.

2 years agonat: Split out platform-independent aarch64 debug register support.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
nat: Split out platform-independent aarch64 debug register support.

Move non-Linux-specific support for hardware break/watchpoints from
nat/aarch64-linux-hw-point.c to nat/aarch64-hw-point.c.  Changes
beyond a simple split of the code are:

- aarch64_linux_region_ok_for_watchpoint and
  aarch64_linux_any_set_debug_regs_state renamed to drop linux_ as
  they are not platform specific.

- Platforms must implement the aarch64_notify_debug_reg_change
  function which is invoked from the platform-independent code when a
  debug register changes for a given debug register state.  This does
  not use the indirection of a 'low' structure as is done for x86.

- The handling for kernel_supports_any_contiguous_range is not
  pristine.  For non-Linux it is simply defined to true.  Some uses of
  this could perhaps be implemented as new 'low' routines for the
  various places that check it instead?

- Pass down ptid into aarch64_handle_breakpoint and
  aarch64_handle_watchpoint rather than using current_lwp_ptid which
  is only defined on Linux.  In addition, pass the ptid on to
  aarch64_notify_debug_reg_change instead of the unused state
  argument.

2 years agox86-fbsd-nat: Copy debug register state on fork.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
x86-fbsd-nat: Copy debug register state on fork.

Use the FreeBSD native target low_new_fork hook to copy the
per-process debug state from the parent to the child on fork.

2 years agofbsd-nat: Add a low_new_fork virtual method.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add a low_new_fork virtual method.

This method can be overridden by architecture-specific targets to
perform additional work when a new child process is forked.

2 years agoAdd an x86_fbsd_nat_target mixin class for FreeBSD x86 native targets.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
Add an x86_fbsd_nat_target mixin class for FreeBSD x86 native targets.

This class implements debug register support common between the i386
and amd64 native targets.

While here, remove #ifdef's for HAVE_PT_GETDBREGS in FreeBSD-specific
code.  The ptrace request has been present on FreeBSD x86
architectures since 4.0 (released in March 2000).  The last FreeBSD
release without this support is 3.5 released in June 2000.

2 years agox86-nat: Add x86_lookup_debug_reg_state.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
x86-nat: Add x86_lookup_debug_reg_state.

This function returns nullptr if debug register state does not yet
exist for a given process rather than creating new state.

2 years agox86-nat: Use an unordered_map to store per-pid debug reg state.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
x86-nat: Use an unordered_map to store per-pid debug reg state.

This replaces a manual linked list which used O(n) lookup and removal.

2 years agoRemove USE_SIGTRAP_SIGINFO condition for FreeBSD/x86 debug regs support.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
Remove USE_SIGTRAP_SIGINFO condition for FreeBSD/x86 debug regs support.

For BSD x86 targets, stopped_by_hw_breakpoint doesn't check siginfo_t
but inspects the DR6 register directly via PT_GETDBREGS.

2 years agoRemove two unused variables
Tom Tromey [Tue, 22 Mar 2022 17:20:28 +0000 (11:20 -0600)] 
Remove two unused variables

I found a couple of spots that declare a symtab_and_line but don't
actually use it.  I think this probably isn't detected as unused
because it has a constructor.

2 years agoFix return code in _bfd_dwarf2_find_nearest_line().
Steiner H Gunderson [Tue, 22 Mar 2022 15:32:32 +0000 (15:32 +0000)] 
Fix return code in _bfd_dwarf2_find_nearest_line().

* dwarf2.c (_bfd_dwarf2_find_nearest_line): if a function name is
found, but no line number info, then return a result of 2.

2 years agogdb/python: add gdb.format_address function
Andrew Burgess [Sat, 23 Oct 2021 08:59:25 +0000 (09:59 +0100)] 
gdb/python: add gdb.format_address function

Add a new function, gdb.format_address, which is a wrapper around
GDB's print_address function.

This method takes an address, and returns a string with the format:

  ADDRESS <SYMBOL+OFFSET>

Where, ADDRESS is the original address, formatted as hexadecimal,
SYMBOL is a symbol with an address lower than ADDRESS, and OFFSET is
the offset from SYMBOL to ADDRESS in decimal.

If there's no SYMBOL suitably close to ADDRESS then the
<SYMBOL+OFFSET> part is not included.

This is useful if a user wants to write a Python script that
pretty-prints addresses, the user no longer needs to do manual symbol
lookup, or worry about correctly formatting addresses.

Additionally, there are some settings that effect how GDB picks
SYMBOL, and whether the file name and line number should be included
with the SYMBOL name, the gdb.format_address function ensures that the
users Python script also benefits from these settings.

The gdb.format_address by default selects SYMBOL from the current
inferiors program space, and address is formatted using the
architecture for the current inferior.  However, a user can also
explicitly pass a program space and architecture like this:

  gdb.format_address(ADDRESS, PROGRAM_SPACE, ARCHITECTURE)

In order to format an address for a different inferior.

Notes on the implementation:

In py-arch.c I extended arch_object_to_gdbarch to add an assertion for
the type of the PyObject being worked on.  Prior to this commit all
uses of arch_object_to_gdbarch were guaranteed to pass this function a
gdb.Architecture object, but, with this commit, this might not be the
case.

So, with this commit I've made it a requirement that the PyObject be a
gdb.Architecture, and this is checked with the assert.  And in order
that callers from other files can check if they have a
gdb.Architecture object, I've added the new function
gdbpy_is_architecture.

In py-progspace.c I've added two new function, the first
progspace_object_to_program_space, converts a PyObject of type
gdb.Progspace to the associated program_space pointer, and
gdbpy_is_progspace checks if a PyObject is a gdb.Progspace or not.

2 years agoFix some stale header names from dwarf files
Luis Machado [Fri, 18 Mar 2022 12:00:35 +0000 (12:00 +0000)] 
Fix some stale header names from dwarf files

Some of these references were not updated when they were moved to a separate
directory.

2 years agoInstall gprofng libraries under $(pkglibdir)
Vladimir Mezentsev [Thu, 17 Mar 2022 16:57:28 +0000 (09:57 -0700)] 
Install gprofng libraries under $(pkglibdir)

gprofng/ChangeLog
2022-03-21  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

        PR gprofng/28972
* gprofng/libcollector/Makefile.am: Rename lib_LTLIBRARIES to
pkglib_LTLIBRARIES. Add install-data-local.
* gprofng/src/Makefile.am: Likewise.
* gprofng/src/envsets.cc (putenv_libcollector_ld_misc): New location of
the gprofng libraries.
* gprofng/configure.ac: Removed an unused GPROFNG_LIBDIR.
* gprofng/Makefile.am: Removed an unused GPROFNG_LIBDIR.  Add
install-data-local.
* gprofng/configure: Regenerate.
* gprofng/Makefile.in: Likewise.
* gprofng/doc/Makefile.in: Likewise.
* gprofng/gp-display-htmllibcollector/Makefile.in: Likewise.
* gprofng/libcollector/Makefile.in: Likewise.
* gprofng/src/Makefile.in: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 22 Mar 2022 00:00:06 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agogdb: Add missing #include in solib.h
Roland McGrath [Mon, 21 Mar 2022 19:04:48 +0000 (12:04 -0700)] 
gdb: Add missing #include in solib.h

The gdb_bfd_ref_ptr type is used in solib.h declarations.

2 years agoPR gdb/27570: missing support for debuginfod in core_target::build_file_mappings
Aaron Merey [Thu, 3 Mar 2022 01:00:59 +0000 (20:00 -0500)] 
PR gdb/27570: missing support for debuginfod in core_target::build_file_mappings

Add debuginfod support to core_target::build_file_mappings and
locate_exec_from_corefile_build_id to enable the downloading of
missing executables and shared libraries referenced in core files.

Also add debuginfod support to solib_map_sections so that previously
downloaded shared libraries can be retrieved from the local debuginfod
cache.

When core file shared libraries are found locally, verify that their
build-ids match the corresponding build-ids found in the core file.
If there is a mismatch, attempt to query debuginfod for the correct
build and print a warning if unsuccessful:

  warning: Build-id of /lib64/libc.so.6 does not match core file.

Also disable debuginfod when gcore invokes gdb.  Debuginfo is not
needed for core file generation so debuginfod queries will slow down
gcore unnecessarily.

2 years agogdb: Add soname to build-id mapping for core files
Aaron Merey [Wed, 2 Mar 2022 23:46:14 +0000 (18:46 -0500)] 
gdb: Add soname to build-id mapping for core files

Since commit aa2d5a422 gdb has been able to read executable and shared
library build-ids within core files.

Expand this functionality so that each core file bfd maintains a map of
soname to build-id for each shared library referenced in the core file.

This feature may be used to verify that gdb has found the correct shared
libraries for core files and to facilitate downloading shared libaries via
debuginfod.

2 years agoWatchpoint followed by catchpoint misreports watchpoint (PR gdb/28621)
Pedro Alves [Tue, 23 Nov 2021 14:19:07 +0000 (14:19 +0000)] 
Watchpoint followed by catchpoint misreports watchpoint (PR gdb/28621)

If GDB reports a watchpoint hit, and then the next event is not
TARGET_WAITKIND_STOPPED, but instead some event for which there's a
catchpoint, such that GDB calls bpstat_stop_status, GDB mistakenly
thinks the watchpoint triggered.  Vis, using foll-fork.c:

  (gdb) awatch v
  Hardware access (read/write) watchpoint 2: v
  (gdb) catch fork
  Catchpoint 3 (fork)
  (gdb) c
  Continuing.

  Hardware access (read/write) watchpoint 2: v

  Old value = 0
  New value = 5
  main () at gdb.base/foll-fork.c:16
  16        pid = fork ();
  (gdb)
  Continuing.

  Hardware access (read/write) watchpoint 2: v      <<<<
                                                    <<<< these lines are spurious
  Value = 5                                         <<<<

  Catchpoint 3 (forked process 1712369), arch_fork (ctid=0x7ffff7fa4810) at arch-fork.h:49
  49      arch-fork.h: No such file or directory.
  (gdb)

The problem is that when we handle the fork event, nothing called
watchpoints_triggered before calling bpstat_stop_status.  Thus, each
watchpoint's watchpoint_triggered field was still set to
watch_triggered_yes from the previous (real) watchpoint stop.
watchpoint_triggered is only current called in the handle_signal_stop
path, when handling TARGET_WAITKIND_STOPPED.

This fixes it by adding watchpoint_triggered calls in the other events
paths that call bpstat_stop_status.  But instead of adding them
explicitly, it adds a new function bpstat_stop_status_nowatch that
wraps bpstat_stop_status and calls watchpoint_triggered, and then
replaces most calls to bpstat_stop_status with calls to
bpstat_stop_status_nowatch.

This required constifying watchpoints_triggered.

New test included, which fails without the fix.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28621

Change-Id: I282b38c2eee428d25319af3bc842f9feafed461c

2 years agogdbserver: Fixup previous patch
Pedro Alves [Mon, 21 Mar 2022 16:58:23 +0000 (16:58 +0000)] 
gdbserver: Fixup previous patch

The previous prepare_resume_reply change missed updating the 'buf'
reference that overwrites the 'T', so if 'buf' was advanced, we'd
still overwrite the wrong character.  This fixes it.

Change-Id: Ia8ce433366b85af4e268c1c49e7b447da3130a4d

2 years agogdbserver: Fix incorrect assertion
Pedro Alves [Thu, 25 Nov 2021 19:07:36 +0000 (19:07 +0000)] 
gdbserver: Fix incorrect assertion

While playing with adding a new event kind, I noticed that
prepare_resume_reply TARGET_WAITKIND_FORKED, etc. advance 'buf', so if
we force-disable the T packet, we'd fail the *buf == 'T' assertion.

Fix it by tweaking the assertion to always look at the beginning of
the buffer.

Change-Id: I8c38e32353db115edcde418b3b1e8ba12343c22b

2 years agogdb: re-generate config.in
Simon Marchi [Mon, 21 Mar 2022 14:47:22 +0000 (10:47 -0400)] 
gdb: re-generate config.in

I'm getting this diff when running `autoreconf -vf`.

Change-Id: Id5f009d0f0481935c1ee9df5332cb4bf45fbd32d

2 years agogdb/x86: handle stap probe arguments in xmm registers
Andrew Burgess [Thu, 10 Mar 2022 16:57:18 +0000 (11:57 -0500)] 
gdb/x86: handle stap probe arguments in xmm registers

On x86 machines with xmm register, and with recent versions of
systemtap (and gcc?), it can occur that stap probe arguments will be
placed into xmm registers.

I notice this happening on a current Fedora Rawhide install with the
following package versions installed:

  $ rpm -q glibc systemtap gcc
  glibc-2.35.9000-10.fc37.x86_64
  systemtap-4.7~pre16468670g9f253544-1.fc37.x86_64
  gcc-12.0.1-0.12.fc37.x86_64

If I check the probe data in libc, I see this:

  $ readelf -n /lib64/libc.so.6
  ...
  stapsdt              0x0000004d       NT_STAPSDT (SystemTap probe descriptors)
    Provider: libc
    Name: pthread_start
    Location: 0x0000000000090ac3, Base: 0x00000000001c65c4, Semaphore: 0x0000000000000000
    Arguments: 8@%xmm1 8@1600(%rbx) 8@1608(%rbx)
  stapsdt              0x00000050       NT_STAPSDT (SystemTap probe descriptors)
    Provider: libc
    Name: pthread_create
    Location: 0x00000000000912f1, Base: 0x00000000001c65c4, Semaphore: 0x0000000000000000
    Arguments: 8@%xmm1 8@%r13 8@8(%rsp) 8@16(%rsp)
  ...

Notice that for both of these probes, the first argument is a uint64_t
stored in the xmm1 register.

Unfortunately, if I try to use this probe within GDB, then I can't
view the first argument.  Here's an example session:

  $ gdb $(which gdb)
  (gdb) start
  ...
  (gdb) info probes stap  libc pthread_create
  ...
  (gdb) break *0x00007ffff729e2f1       # Use address of probe.
  (gdb) continue
  ...
  (gdb) p $_probe_arg0
  Invalid cast.

What's going wrong?  If I re-run my session, but this time use 'set
debug stap-expression 1', this is what I see:

  (gdb) set debug stap-expression 1
  (gdb) p $_probe_arg0
  Operation: UNOP_CAST
   Operation: OP_REGISTER
    String: xmm1
   Type: uint64_t
  Operation: UNOP_CAST
   Operation: OP_REGISTER
    String: r13
   Type: uint64_t
  Operation: UNOP_CAST
   Operation: UNOP_IND
    Operation: UNOP_CAST
     Operation: BINOP_ADD
      Operation: OP_LONG
       Type: long
       Constant: 0x0000000000000008
      Operation: OP_REGISTER
       String: rsp
     Type: uint64_t *
   Type: uint64_t
  Operation: UNOP_CAST
   Operation: UNOP_IND
    Operation: UNOP_CAST
     Operation: BINOP_ADD
      Operation: OP_LONG
       Type: long
       Constant: 0x0000000000000010
      Operation: OP_REGISTER
       String: rsp
     Type: uint64_t *
   Type: uint64_t
  Invalid cast.
  (gdb)

The important bit is this:

  Operation: UNOP_CAST
   Operation: OP_REGISTER
    String: xmm1
   Type: uint64_t

Which is where we cast the xmm1 register to uint64_t.  And the final
piece of the puzzle is:

  (gdb) ptype $xmm1
  type = union vec128 {
      v8bf16 v8_bfloat16;
      v4f v4_float;
      v2d v2_double;
      v16i8 v16_int8;
      v8i16 v8_int16;
      v4i32 v4_int32;
      v2i64 v2_int64;
      uint128_t uint128;
  }

So, we are attempting to cast a union type to a scalar type, which is
not supporting in C/C++, and as a consequence GDB's expression
evaluator throws an error when we attempt to do this.

The first approach I considered for solving this problem was to try
and make use of gdbarch_stap_adjust_register.  We already have a
gdbarch method (gdbarch_stap_adjust_register) that allows us to tweak
the name of the register that we access.  Currently only x86
architectures use this to transform things like ax to eax in some
cases.

I wondered, what if we change gdbarch_stap_adjust_register to do more
than just change the register names?  What if this method instead
became gdbarch_stap_read_register.  This new method would return a
operation_up, and would take the register name, and the type we are
trying to read from the register, and return the operation that
actually reads the register.

The default implementation of this method would just use
user_reg_map_name_to_regnum, and then create a register_operation,
like we already do in stap_parse_register_operand.  But, for x86
architectures this method would fist possibly adjust the register
name, then do the default action to read the register.  Finally, for
x86 this method would spot when we were accessing an xmm register,
and, based on the type being pulled from the register, would extract
the correct field from the union.

The benefit of this approach is that it would work with the expression
types that GDB currently supports.  The draw back would be that this
approach would not be very generic.  We'd need code to handle each
sub-field size with an xmm register.  If other architectures started
using vector registers for probe arguments, those architectures would
have to create their own gdbarch_stap_read_register method.  And
finally, the type of the xmm registers comes from the type defined in
the target description, there's a risk that GDB might end up
hard-coding the names of type sub-fields, then if a target uses a
different target description, with different field names for xmm
registers, the stap probes would stop working.

And so, based on all the above draw backs, I rejected this first
approach.

My second plan involves adding a new expression type to GDB called
unop_extract_operation.  This new expression takes a value and a type,
during evaluation the value contents are fetched, and then a new value
is extracted from the value contents (based on type).  This is similar
to the following C expression:

  result_value = *((output_type *) &input_value);

Obviously we can't actually build this expression in this case, as the
input_value is in a register, but hopefully the above makes it clearer
what I'm trying to do.

The benefit of the new expression approach is that this code can be
shared across all architectures, and it doesn't care about sub-field
names within the union type.

The draw-backs that I see are potential future problems if arguments
are not stored within the least significant bytes of the register.
However if/when that becomes an issue we can adapt the
gdbarch_stap_read_register approach to allow architectures to control
how a value is extracted.

For testing, I've extended the existing gdb.base/stap-probe.exp test
to include a function that tries to force an argument into an xmm
register.  Obviously, that will only work on a x86 target, so I've
guarded the new function with an appropriate GCC define.  In the exp
script we use readelf to check if the probe exists, and is using the
xmm register.

If the probe doesn't exist then the associated tests are skipped.

If the probe exists, put isn't using the xmm register (which will
depend on systemtap/gcc versions), then again, the tests are skipped.

Otherwise, we can run the test.  I think the cost of running readelf
is pretty low, so I don't feel too bad making all the non-xmm targets
running this step.

I found that on a Fedora 35 install, with these packages installed, I
was able to run this test and have the probe argument be placed in an
xmm register:

  $ rpm -q systemtap gcc glibc
  systemtap-4.6-4.fc35.x86_64
  gcc-11.2.1-9.fc35.x86_64
  glibc-2.34-7.fc35.x86_64

Finally, as this patch adds a new operation type, then I need to
consider how to generate an agent expression for the new operation
type.

I have kicked the can down the road a bit on this.  In the function
stap_parse_register_operand, I only create a unop_extract_operation in
the case where the register type is non-scalar, this means that in
most cases I don't need to worry about generating an agent expression
at all.

In the xmm register case, when an unop_extract_operation will be
created, I have sketched out how the agent expression could be
handled, however, this code is currently not reached.  When we try to
generate the agent expression to place the xmm register on the stack,
GDB hits this error:

  (gdb) trace -probe-stap test:xmmreg
  Tracepoint 1 at 0x401166
  (gdb) actions
  Enter actions for tracepoint 1, one per line.
  End with a line saying just "end".
  >collect $_probe_arg0
  Value not scalar: cannot be an rvalue.

This is because GDB doesn't currently support placing non-scalar types
on the agent expression evaluation stack.  Solving this is clearly
related to the original problem, but feels a bit like a second
problem.  I'd like to get feedback on whether my approach to solving
the original problem is acceptable or not before I start looking at
how to handle xmm registers within agent expressions.