Luis Machado [Sun, 11 Sep 2022 19:47:18 +0000 (20:47 +0100)]
[aarch64] Enable pointer authentication support for aarch64 bare metal/kernel mode addresses
At the moment GDB only handles pointer authentication (pauth) for userspace
addresses and if we're debugging a Linux-hosted program.
The Linux Kernel can be configured to use pauth instructions for some
additional security hardening, but GDB doesn't handle this well.
To overcome this limitation, GDB needs a couple things:
1 - The target needs to advertise pauth support.
2 - The hook to remove non-address bits from a pointer needs to be registered
in aarch64-tdep.c as opposed to aarch64-linux-tdep.c.
There is a patch for QEMU that addresses the first point, and it makes
QEMU's gdbstub expose a couple more pauth mask registers, so overall we will
have up to 4 pauth masks (2 masks or 4 masks):
pauth_dmask
pauth_cmask
pauth_dmask_high
pauth_cmask_high
pauth_dmask and pauth_cmask are the masks used to remove pauth signatures
from userspace addresses. pauth_dmask_high and pauth_cmask_high masks are used
to remove pauth signatures from kernel addresses.
The second point is easily addressed by moving code around.
When debugging a Linux Kernel built with pauth with an unpatched GDB, we get
the following backtrace:
#0 __fput (file=0xffff0000c17a6400) at /repos/linux/fs/file_table.c:296
#1 0xffff8000082bd1f0 in ____fput (work=<optimized out>) at /repos/linux/fs/file_table.c:348
#2 0x30008000080ade30 [PAC] in ?? ()
#3 0x30d48000080ade30 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
With a patched GDB, we get something a lot more meaningful:
#0 __fput (file=0xffff0000c1bcfa00) at /repos/linux/fs/file_table.c:296
#1 0xffff8000082bd1f0 in ____fput (work=<optimized out>) at /repos/linux/fs/file_table.c:348
#2 0xffff8000080ade30 [PAC] in task_work_run () at /repos/linux/kernel/task_work.c:179
#3 0xffff80000801db90 [PAC] in resume_user_mode_work (regs=0xffff80000a96beb0) at /repos/linux/include/linux/resume_user_mode.h:49
#4 do_notify_resume (regs=regs@entry=0xffff80000a96beb0, thread_flags=4) at /repos/linux/arch/arm64/kernel/signal.c:1127
#5 0xffff800008fb9974 [PAC] in prepare_exit_to_user_mode (regs=0xffff80000a96beb0) at /repos/linux/arch/arm64/kernel/entry-common.c:137
#6 exit_to_user_mode (regs=0xffff80000a96beb0) at /repos/linux/arch/arm64/kernel/entry-common.c:142
#7 el0_svc (regs=0xffff80000a96beb0) at /repos/linux/arch/arm64/kernel/entry-common.c:638
#8 0xffff800008fb9d34 [PAC] in el0t_64_sync_handler (regs=<optimized out>) at /repos/linux/arch/arm64/kernel/entry-common.c:655
#9 0xffff800008011548 [PAC] in el0t_64_sync () at /repos/linux/arch/arm64/kernel/entry.S:586
Backtrace stopped: Cannot access memory at address 0xffff80000a96c0c8
Clément Chigot [Fri, 13 Jan 2023 09:21:07 +0000 (10:21 +0100)]
ld/testsuite: don't output to /dev/null
Mingw doesn't have /dev/null and thus "-o /dev/null" will fail.
Currently, all the options are checked using this "-o /dev/null",
resulting in them being disabled on mingw hosts.
Fix that by outputting to a real file for all targets.
ld/ChangeLog:
* testsuite/config/default.exp: Replace "-o /dev/null" by a
file.
Alan Modra [Tue, 21 Feb 2023 05:45:59 +0000 (16:15 +1030)]
Both FAIL and PASS "check sections 2"?
* testsuite/ld-checks/checks.exp (check sections 2): Don't
continue on with rest of test past first fail.
Alan Modra [Tue, 21 Feb 2023 05:49:51 +0000 (16:19 +1030)]
ld-libs test on alpha-vms
* testsuite/ld-libs/libs.exp: Don't run for alpha-vms.
Alan Modra [Mon, 20 Feb 2023 23:27:49 +0000 (09:57 +1030)]
alpha-*-vms missing libraries
For this:
./ld-new: cannot find -limagelib: No such file or directory
./ld-new: cannot find -lstarlet: No such file or directory
./ld-new: cannot find -lsys$public_vectors: No such file or directory
the logs showed
creating dummy tmpdir/libimagelib:
creating dummy No
creating dummy such
etc.
So rubbish instead of tmpdir/libimagelib.a and the other required libs.
* testsuite/config/default.exp: Correct regex detecting missing
libraries automatically searched by alpha-dec-vms-ld.
GDB Administrator [Tue, 21 Feb 2023 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Fri, 17 Feb 2023 19:12:11 +0000 (12:12 -0700)]
Redefine FUNCTION in doc.str
FUNCTION is identical to func, so simplify doc.str.
2023-02-17 Tom Tromey <tom@tromey.com>
* doc/doc.str (FUNCTION): Call func.
Tom Tromey [Fri, 17 Feb 2023 19:12:11 +0000 (12:12 -0700)]
Hoist the SECTION comment in opncls.c
The opening and closing node in BFD starts:
File: bfd.info, [...]
/* Set to N to open the next N BFDs using an alternate id space. */
extern unsigned int bfd_use_reserved_id;
2.13 Opening and closing BFDs
=============================
That is, there's a stray C comment and declaration before any other
text or subsections.
This occurs because the code fragment for bfd_use_reserved_id comes
before the SECTION comment. Hoisting it makes this a little nicer.
2023-02-17 Tom Tromey <tom@tromey.com>
* opncls.c: Hoist the SECTION comment.
Tom Tromey [Fri, 17 Feb 2023 19:12:11 +0000 (12:12 -0700)]
Don't use chew comments for static functions
I found a few static functions in the BFD manual. These can't be
called by any user of the library, so I don't think it's useful to put
them in the manual. This patch removes the chew markup from their
comments.
2023-02-17 Tom Tromey <tom@tromey.com>
* opncls.c (bfd_get_debug_link_info_1, separate_debug_file_exists)
(separate_alt_debug_file_exists, find_separate_debug_file)
(get_build_id, get_build_id_name, check_build_id_file): Don't use
chew comments.
Tom Tromey [Fri, 17 Feb 2023 19:12:11 +0000 (12:12 -0700)]
Fix formatting of long function description in chew output
Currently, if a function description spans a line, the resulting info
can look like this:
-- Function: long bfd_canonicalize_reloc
(bfd *abfd, asection *sec, arelent **loc, asymbol **syms); Call the
back end associated with the open BFD ABFD and translate the
external form of the relocation information attached to SEC into
the internal canonical form. Place the table into memory at LOC,
That is, the function prototype runs together with the text in an ugly
way. This patch fixes this by introducing a new primitive, so that
the generated Texinfo can be a bit nicer. Now this output looks like:
-- Function: long bfd_canonicalize_reloc (bfd *abfd, asection *sec,
arelent **loc, asymbol **syms);
Call the back end associated with the open BFD ABFD and translate
the external form of the relocation information attached to SEC
2023-02-17 Tom Tromey <tom@tromey.com>
* doc/doc.str (SYNOPSIS): Use collapse_whitespace.
* doc/chew.c (collapse_whitespace): New function.
(main): Register collapse_whitespace.
Andreas Schwab [Tue, 14 Feb 2023 17:07:19 +0000 (18:07 +0100)]
opcodes: style m68k disassembler output
Simon Marchi [Mon, 20 Feb 2023 16:52:40 +0000 (11:52 -0500)]
gdb: revert one erroneous bool-ification change
Commit
42c13555ff88 ("Change value::m_stack to bool") erroneously
changed a `0` to `false` in this call to read_value_memory. This
parameter is `LONGEST bit_offset`, it should stay `0`.
Change-Id: I128df6834cf8055ec6a7051e237e379978d3d651
Clément Chigot [Wed, 18 Jan 2023 13:44:39 +0000 (14:44 +0100)]
ld/testsuite: handle Windows drive letter in a noinit test
The regexp in "noinit sections (ld -r)" is skipping the file path before
the first ":". However, on Windows, a path can start with "C:". Adjust
the regexp to allow such cases.
ld/ChangeLog:
* testsuite/ld-elf/noinit-sections-2.l: Allow Windows paths
(starting with C:).
Clément Chigot [Thu, 12 Jan 2023 10:02:25 +0000 (11:02 +0100)]
ld/testsuite: adjust to Windows path separator.
In some tests, the path reported on Windows will have a \ instead of a
/. This occurs when a file is concatened with the search path in
ldfile.c.: "ld -Ltmpdir -ltext" will result into "tmpdir\libtext.a".
ld/ChangeLog:
* testsuite/ld-elf/retain5.map: Allow \ path separator.
* testsuite/ld-plugin/plugin-10.d: Likewise.
* testsuite/ld-plugin/plugin-11.d: Likewise.
* testsuite/ld-plugin/plugin-18.d: Likewise.
* testsuite/ld-plugin/plugin-19.d: Likewise.
* testsuite/ld-plugin/plugin-20.d: Likewise.
* testsuite/ld-plugin/plugin-22.d: Likewise.
Andrew Burgess [Thu, 16 Feb 2023 09:22:43 +0000 (09:22 +0000)]
gdb/doc: Consistency fixes for GDB/MI documentation
I noticed two inconsistencies in the GDB/MI documentation, which this
commit addresses:
1. Each MI command is introduced like this:
@subheading The @code{-command-name} Command
Except for a few of the tracing command, which just use:
@subheading -command-name
In this commit I've updated all these trace commands to use the
more common format.
2. Each MI command starts with a @subheading, and then the details
of that command are split up using multiple @subsubheading
entries.
Except for a few commands which use @subheading for the top-level
command, and then continue to use @subheading for each part of
the command description.
In this commit I've updated these to use @subsubheading where
appropriate.
Nick Clifton [Mon, 20 Feb 2023 11:32:52 +0000 (11:32 +0000)]
So the linker from producing an export data table when run with --exclude-all-symbols.
PR 30004 * pe-dll.c (pe_dll_build_sections): Do not build an edata section if all symbols are being excluded.
Tom de Vries [Mon, 20 Feb 2023 11:20:14 +0000 (12:20 +0100)]
[gdb/symtab] Trust epilogue unwind info for unknown or non-gcc producer
Currently we only trust epilogue unwind info only for gcc >= 4.5.0.
This has the effect that we don't trust epilogue unwind info for:
- unknown producers (CU without DW_AT_producer attribute)
- non-gcc producers (say, clang).
Instead, only distrust epilogue unwind info only for gcc < 4.5.0.
Tom de Vries [Mon, 20 Feb 2023 11:20:14 +0000 (12:20 +0100)]
[gdb/symtab] Trust epilogue unwind info for unknown producer (-g0 case)
For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with
.eh_frame section), start using the dwarf2 unwinder instead of the
"amd64 epilogue override" unwinder, by returning true in
compunit_epilogue_unwind_valid for cust == nullptr.
This has effect both on the amd64 and i386 targets, but only add amd64
test-case gdb.base/unwind-on-each-insn-amd64-2.exp.
Tom de Vries [Mon, 20 Feb 2023 11:20:14 +0000 (12:20 +0100)]
[gdb/tdep] Add amd64/i386 epilogue override unwinders
For amd64 the current frame-unwinders are:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
python NORMAL_FRAME
amd64 epilogue NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
amd64 sigtramp SIGTRAMP_FRAME
amd64 prologue NORMAL_FRAME
...
For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with
.eh_frame section), we'd like to start using the dwarf2 unwinder instead of
the "amd64 epilogue" unwinder, by returning true in
compunit_epilogue_unwind_valid for cust == nullptr.
But we'd run into the following problem for a -g0
-fno-asynchronous-unwind-tables (without .debug_info and .eh_frame section)
exec:
- the "amd64 epilogue" unwinder would not run
(because compunit_epilogue_unwind_valid () == true)
- the dwarf2 unwinder would also not run
(because there's no .eh_frame info).
Fix this by:
- renaming the "amd64 epilogue" unwinder to "amd64 epilogue override", and
- adding a fallback "amd64 epilogue" after the dwarf unwinders,
while making sure that only one of the two is active. Likewise for i386. NFC.
For amd64, this results in this change:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
inline INLINE_FRAME
python NORMAL_FRAME
-amd64 epilogue NORMAL_FRAME
+amd64 epilogue override NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
+amd64 epilogue NORMAL_FRAME
amd64 sigtramp SIGTRAMP_FRAME
amd64 prologue NORMAL_FRAME
...
And for i386:
...
$ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders"
The target architecture is set to "i386".
dummy DUMMY_FRAME
dwarf2 tailcall TAILCALL_FRAME
iline INLINE_FRAME
-i386 epilogue NORMAL_FRAME
+i386 epilogue override NORMAL_FRAME
dwarf2 NORMAL_FRAME
dwarf2 signal SIGTRAMP_FRAME
+i386 epilogue NORMAL_FRAME
i386 stack tramp NORMAL_FRAME
i386 sigtramp SIGTRAMP_FRAME
i386 prologue NORMAL_FRAME
...
Tom de Vries [Mon, 20 Feb 2023 11:20:14 +0000 (12:20 +0100)]
[gdb/tdep] Fix amd64/i386_stack_frame_destroyed_p
The use of compunit_epilogue_unwind_valid in both amd64_stack_frame_destroyed_p
and i386_stack_frame_destroyed_p is problematic, in the sense that the
functions no longer match their documented behaviour.
Fix this by moving the use of compunit_epilogue_unwind_valid to
amd64_epilogue_frame_sniffer and i386_epilogue_frame_sniffer. No functional
changes.
Tom de Vries [Mon, 20 Feb 2023 11:20:14 +0000 (12:20 +0100)]
[gdb/symtab] Factor out compunit_epilogue_unwind_valid
Factor out compunit_epilogue_unwind_valid from both
amd64_stack_frame_destroyed_p and i386_stack_frame_destroyed_p. No functional
changes.
Also add a comment in the new function about the assumption that in absence of
producer information, epilogue unwind info is invalid.
Approved-By: Tom Tromey <tom@tromey.com>
Tom de Vries [Mon, 20 Feb 2023 10:16:02 +0000 (11:16 +0100)]
[gdb/testsuite] Add xfail case in gdb.python/py-record-btrace.exp
I came across:
...
gdb) PASS: gdb.python/py-record-btrace.exp: prepare record: stepi 100
python insn = r.instruction_history^M
warning: Non-contiguous trace at instruction 1 (offset = 0x3e10).^M
(gdb) FAIL: gdb.python/py-record-btrace.exp: prepare record: python insn = r.i\
nstruction_history
...
I'm assuming it's the same root cause as for the already present XFAIL.
Fix this by recognizing above warning in the xfail regexp.
Tested on x86_64-linux, although sofar I was not able to trigger the warning
again.
Approved-By: Markus T. Metzger <markus.t.metzger@intel.com>
Tom de Vries [Mon, 20 Feb 2023 10:16:02 +0000 (11:16 +0100)]
[gdb/testsuite] Fix gdb.threads/schedlock.exp for gcc 4.8.5
Since commit
9af467b8240 ("[gdb/testsuite] Fix gdb.threads/schedlock.exp on
fast cpu"), the test-case fails for gcc 4.8.5.
The problem is that for gcc 4.8.5, the commit turned a two-line loop:
...
(gdb) next
78 while (*myp > 0)
(gdb) next
81 MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb) next
78 while (*myp > 0)
...
into a three-line loop:
...
(gdb) next
83 MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb) next
84 cnt++;
(gdb) next
85 }
(gdb) next
83 MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb)
...
and the test-case doesn't expect this.
Fix this by reverting back to the original loop shape as much as possible by:
- removing the cnt++ line
- replacing "while (1)" with "while (one)", where one is a volatile variable
set to 1.
Tested on x86_64-linux, using compilers:
- gcc 4.8.5, 7.5.0, 12.2.1
- clang 4.0.1, 13.0.1
Alan Modra [Mon, 20 Feb 2023 00:44:59 +0000 (11:14 +1030)]
In-memory nested archives
alpha-linuxecoff has compressed archives that are decompressed to a
bfd-in-memory. We'd need to handle quite a lot of corner cases to
support nesting of such archives, so just stop it before we run into
segfaults later.
* opncls.c (_bfd_new_bfd_contained_in): Prohibit nested
archives in memory.
GDB Administrator [Mon, 20 Feb 2023 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Fri, 20 Jan 2023 14:46:51 +0000 (07:46 -0700)]
Convert contained_in to method
This converts contained_in to be a method of block.
Tom Tromey [Fri, 20 Jan 2023 14:20:38 +0000 (07:20 -0700)]
Make block members 'private'
This changes block to make the data members 'private'.
Tom Tromey [Fri, 20 Jan 2023 14:16:34 +0000 (07:16 -0700)]
Remove allocate_block and allocate_global_block
This removes allocate_block and allocate_global_block in favor of
simply calling 'new'.
Tom Tromey [Fri, 20 Jan 2023 14:14:46 +0000 (07:14 -0700)]
Have global_block inherit from block
This changes global_block to inherit from block, which is what was
always intended.
Tom Tromey [Fri, 20 Jan 2023 14:12:02 +0000 (07:12 -0700)]
Use 'new' for block and global_block
This changes block and global_block to add initializers, and then to
use 'new' for allocation.
Tom Tromey [Fri, 20 Jan 2023 14:11:46 +0000 (07:11 -0700)]
Fix memory leak in mdebugread.c
mdebugread.c allocates blocks on the heap. However, this is a memory
leak if the corresponding objfile is ever destroyed.
This patch changes this code to use allocate_block instead, fixing a
FIXME from 2003.
I don't know how to test this patch.
Tom Tromey [Fri, 20 Jan 2023 03:25:55 +0000 (20:25 -0700)]
Remove ALL_BLOCK_SYMBOLS
This removes ALL_BLOCK_SYMBOLS in favor of foreach.
Tom Tromey [Fri, 20 Jan 2023 03:21:10 +0000 (20:21 -0700)]
Remove ALL_BLOCK_SYMBOLS_WITH_NAME
This removes ALL_BLOCK_SYMBOLS_WITH_NAME in favor of foreach.
Tom Tromey [Fri, 20 Jan 2023 03:14:25 +0000 (20:14 -0700)]
Convert explicit iterator uses to foreach
This converts most existing explicit uses of block_iterator to use
foreach with the range iterator instead.
Tom Tromey [Fri, 20 Jan 2023 01:44:38 +0000 (18:44 -0700)]
Introduce a block iterator wrapper
This introduces a C++-style iterator that wraps the existing
block_iterator. It also adds a range adapter. These will be used in
a later patch.
Tom Tromey [Fri, 20 Jan 2023 01:41:21 +0000 (18:41 -0700)]
Combine both styles of block iterator
This merges the two styles of block iterator, having the
initialization API decide which to use based on an optional parameter.
Tom Tromey [Fri, 20 Jan 2023 01:36:17 +0000 (18:36 -0700)]
Store 'name' in block_iterator
This changes the block_iterator to store the 'name' that is used by
block_iter_match_next. This avoids any problem where the name could
be passed inconsistently, and also makes the subsequent patches easier
to understand.
Tom Tromey [Fri, 20 Jan 2023 00:50:30 +0000 (17:50 -0700)]
Convert block_static_link to method
This converts block_static_link to be a method. This was mostly
written by script.
Tom Tromey [Tue, 17 Jan 2023 13:39:07 +0000 (06:39 -0700)]
Convert set_block_compunit_symtab to method
This converts set_block_compunit_symtab to be a method. This was
mostly written by script.
Tom Tromey [Tue, 17 Jan 2023 01:14:47 +0000 (18:14 -0700)]
Convert block_static_block and block_global_block to methods
This converts block_static_block and block_global_block to be methods.
This was mostly written by script. It was simpler to convert them at
the same time because they're often used near each other.
Tom Tromey [Tue, 17 Jan 2023 00:48:19 +0000 (17:48 -0700)]
Convert block_containing_function to method
This converts block_containing_function to be a method. This was
mostly written by script.
Tom Tromey [Tue, 17 Jan 2023 00:44:20 +0000 (17:44 -0700)]
Convert block_linkage_function to method
This converts block_linkage_function to be a method. This was mostly
written by script.
Tom Tromey [Tue, 17 Jan 2023 00:39:55 +0000 (17:39 -0700)]
Convert more block functions to methods
This converts block_scope, block_set_scope, block_using, and
block_set_using to be methods. These are all done at once to make it
easier to also convert block_initialize_namespace at the same time.
This was mostly written by script.
Tom Tromey [Tue, 17 Jan 2023 00:27:28 +0000 (17:27 -0700)]
Convert block_inlined_p to method
This converts block_inlined_p to be a method. This was mostly written
by script.
Tom Tromey [Tue, 17 Jan 2023 00:24:16 +0000 (17:24 -0700)]
Convert block_gdbarch to method
This converts block_gdbarch to be a method. This was mostly written
by script.
Tom Tromey [Tue, 17 Jan 2023 00:16:44 +0000 (17:16 -0700)]
Convert block_objfile to method
This converts block_objfile to be a method. This was mostly written
by script.
Tom Tromey [Fri, 20 Jan 2023 00:22:04 +0000 (17:22 -0700)]
Don't allow NULL as an argument to block_global_block
block_global_block has special behavior when the block is NULL.
Remove this and patch up the callers instead.
Tom Tromey [Fri, 20 Jan 2023 00:20:09 +0000 (17:20 -0700)]
Don't allow NULL as an argument to block_static_block
block_static_block has special behavior when the block is NULL.
Remove this and patch up the callers instead.
Tom Tromey [Fri, 20 Jan 2023 00:13:22 +0000 (17:13 -0700)]
Don't allow NULL as an argument to block_using
block_using has special behavior when the block is NULL.
Remove this. No caller seems to be affected.
Tom Tromey [Fri, 20 Jan 2023 00:37:15 +0000 (17:37 -0700)]
Don't allow NULL as an argument to block_scope
block_scope has special behavior when the block is NULL.
Remove this and patch up the callers instead.
Tom Tromey [Tue, 17 Jan 2023 00:04:39 +0000 (17:04 -0700)]
Avoid extra allocations in block
block_set_scope and block_set_using unconditionally allocate the block
namespace object. However, this isn't truly needed, so arrange to
only allocate when it is.
Tom Tromey [Tue, 17 Jan 2023 00:04:55 +0000 (17:04 -0700)]
Rearrange block.c to avoid a forward declaration
Moving block_initialize_namespace before its callers lets us avoid a
forward declaration.
Alan Modra [Sat, 18 Feb 2023 04:01:45 +0000 (14:31 +1030)]
Buffer overflow in evax_bfd_print_eobj
* vms-alpha.c (evax_bfd_print_eobj): Rewrite header handling,
sanity checking rec_len. Check bfd_malloc return.
Tom Tromey [Wed, 15 Feb 2023 23:09:35 +0000 (16:09 -0700)]
Avoid memory leak in chew
An earlier patch of mine introduced a memory leak in chew. The bug
was that the new "variable" word didn't free the following word. This
patch fixes it by arranging to transfer ownership of the name to the
variable itself.
* doc/chew.c (add_variable): New function, from
add_intrinsic_variable.
(add_intrinsic_variable): Call add_variable.
(compile): Call add_variable.
GDB Administrator [Sun, 19 Feb 2023 00:00:12 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 14 Feb 2023 00:44:54 +0000 (17:44 -0700)]
Fix "start" for D, Rust, etc
The new DWARF indexer broke "start" for some languages.
For D, it is broken because, while the code in cooked_index_shard::add
specifically excludes Ada, it fails to exclude D. This means that the
C "main" will be detected as "main" here -- whereas what is intended
is for the code in find_main_name to use d_main_name to find the name.
The Rust compiler, on the other hand, uses DW_AT_main_subprogram.
However, the code in dwarf2_build_psymtabs_hard fails to create a
fully-qualified name, so the name always ends up as plain "main".
For D and Ada, a very simple approach suffices: remove the check
against "main" from cooked_index_shard::add. This also has the
benefit of slightly speeding up DWARF indexing. I assume this
approach will work for Pascal and Modula-2 as well, but I don't have a
way to test those at present.
For Rust, though, this is not sufficient. And, computing the
fully-qualified name in dwarf2_build_psymtabs_hard will crash, because
cooked_index_entry::full_name uses the canonical name -- and that is
not computed until after canonicalization.
However, we don't want to wait for canonicalization to be done before
computing the main name. That would remove any benefit from doing
canonicalization is the background.
This patch solves this dilemma by noticing that languages using
DW_AT_main_subprogram are, currently, disjoint from languages
requiring canonicalization. Because of this, we can add a parameter
to full_name to let us avoid crashes, slowdowns, and races here.
This is kind of tricky and ugly, so I've tried to comment it
sufficiently.
While doing this, I had to change gdb.dwarf2/main-subprogram.exp. A
different possibility here would be to ignore the canonicalization
needs of C in this situation, because those only affect certain types.
However, I chose this approach because the test case is artificial
anyhow.
A long time ago, in an earlier threading attempt, I changed the global
current_language to be a function (hidden behind a macro) to let us
attempt lazily computing the current language. Perhaps this approach
could still be made to work. However, that also seemed rather tricky,
more so than this patch.
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30116
Tom Tromey [Fri, 17 Feb 2023 00:52:07 +0000 (17:52 -0700)]
Fix crash in go_symbol_package_name
go_symbol_package_name package name asserts that it is only passed a
Go symbol, but this is not enforced by one caller. It seems simplest
to just check and return early in this case.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17876
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Tom Tromey [Fri, 17 Feb 2023 00:36:29 +0000 (17:36 -0700)]
Avoid manual memory management in go-lang.c
I noticed a couple of spots in go-lang.c that could be improved by
using unique_ptr.
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
GDB Administrator [Sat, 18 Feb 2023 00:00:11 +0000 (00:00 +0000)]
Automatic date update in version.in
Andrew Burgess [Fri, 17 Feb 2023 10:15:27 +0000 (10:15 +0000)]
gdb: fix regression in gdb.xml/maint_print_struct.exp
A regression in gdb.xml/maint_print_struct.exp was introduced with
commit:
commit
81b86eced24f905545b58aa6c27478104c364976
Date: Fri Jan 6 09:30:40 2023 -0700
Do not record a rejected target description
The test relied on an invalid target description being stored within
the tdesc_info of the current inferior, the above commit stopped this
behaviour.
Update the test to check that the invalid architecture is NOT stored,
and then check printing the target description directly from the
file.
Approved-By: Tom Tromey <tromey@adacore.com>
Vladimir Mezentsev [Fri, 17 Feb 2023 03:35:35 +0000 (19:35 -0800)]
gprofng: fix Dwarf reader for DW_TAG_subprogram
gprofng/ChangeLog
2023-02-16 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
* src/Dwarf.cc: Skip DW_TAG_subprogram when DW_AT_declaration is 1.
Vladimir Mezentsev [Fri, 17 Feb 2023 03:00:47 +0000 (19:00 -0800)]
gprofng: PR30036 Build failure on aarch64 w/ glibc: symbol `pwrite64' is already defined
gprofng/ChangeLog
2023-02-16 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
PR gprofng/30036
* libcollector/iotrace.c: Define creat64 and pwrite64 only when
__USE_LARGEFILE64 and __USE_FILE_OFFSET64 are not defined.
* libcollector/mmaptrace.c: Likewise for mmap64.
Aditya Vidyadhar Kamath [Fri, 17 Feb 2023 15:07:44 +0000 (09:07 -0600)]
Fix multi-threaded debugging under AIX
Multi-threaded debugging using the libpthdebug debug interface
is currently broken due to multiple issues.
When debugging a single inferior, we were getting assertion
failures in get_aix_thread_info as no tp->priv structure was
allocated for the main thread.
We fixed this by switching the main
thread from a (pid, 0, 0) ptid_t to a (pid, 0, tid) ptid_t and
allocaing the tp->priv structure in sync_threadlists.
As a result, the switch_to_thread call in pdc_read_data could
now fail since the main thread no longer uses (pid, 0, 0).
So we replaced the call by only switching inferior_ptid, the current
inferior, and the current address space (like proc-service.c).
Add similar switching to pdc_write_data where it was missing
completely.
When debugging multiple inferiors, an additional set of
problems prevented correct multi-threaded debugging:
First of all, aix-thread.c used to have a number of global
variables holding per-inferior information.
We switched hese
to a per-inferior data structure instead.
Also, sync_threadlists was getting confused as we were
comparing the list of threads returned by libpthdebug
for *one* process with GDB's list of threads for *all*
processes. Now we only use he GDB threads of the current
inferior instead.
We also skip calling pd_activate
from pd_enable if that in_initial_library_scan flag is
true for the current inferior.
Finally, the presence of the thread library in any but
the first inferior was not correctly detected due to a
bug in solib-aix.c, where the BFD file name for shared
library members was changed when the library was loaded
for the first time, which caused the library to no longer
be recognized by name when loaded a second time.
Tom Tromey [Fri, 17 Feb 2023 17:24:16 +0000 (10:24 -0700)]
Remove two unnecessary returns in ada-lang.c
I found a couple of spots in ada-lang.c where a return follows a call
to error. These are unnecessary because error never returns.
Tom de Vries [Fri, 17 Feb 2023 14:33:18 +0000 (15:33 +0100)]
[gdb/testsuite] Simplify gdb.arch/amd64-disp-step-avx.exp
On SLE-11, with glibc 2.11.3, I run into:
...
(gdb) PASS: gdb.arch/amd64-disp-step-avx.exp: vex3: \
var128 has expected value after
continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x0000000000400283 in _exit (status=0) at \
../sysdeps/unix/sysv/linux/_exit.c:33^M
33 ../sysdeps/unix/sysv/linux/_exit.c: No such file or directory.^M
(gdb) FAIL: gdb.arch/amd64-disp-step-avx.exp: \
continue until exit at amd64-disp-step-avx
...
This is not related to gdb, we get the same result by just running the exec.
The problem is that the test-case:
- calls glibc's _exit, and
- uses -nostartfiles -static, putting the burden for any necessary
initialization for calling glibc's _exit on the test-case itself.
So, when we get to the second insn in _exit:
...
000000000040acb0 <_exit>:
40acb0: 48 63 d7 movslq %edi,%rdx
40acb3: 64 4c 8b 14 25 00 00 mov %fs:0x0,%r10
...
no glibc-related initialization is done, and we run into the segfault.
Adding this (borrowed from __libc_start_main) in _start in the .S file is
sufficient to fix it:
...
.rept 200
nop
+ call __pthread_initialize_minimal
.endr
...
But that already doesn't compile with say glibc 2.31, and regardless I think
this sort of fix is too fragile.
We could of course fix this by simply not running to exit. But ideally we'd
have an exec that doesn't segfault when you just run it.
Alternatively, we could hand-code an _exit syscall and bypass glibc
all together. But I'd rather fix this in a way that simplifies the test-case.
Taking a step back, the -nostartfiles -static was added to address that the
xmm registers were not zero at main (which AFAICT is a valid thing to happen).
[ The change itself silently broke the test-case, needing further fixing by
commit
40310f30a51 ("gdb: make gdb.arch/amd64-disp-step-avx.exp actually test
displaced stepping"). ]
Instead, simplify things by reverting to the original situation:
- no -nostartfiles -static compilation flags,
- no _start in the .S file,
- use exit instead of _exit in the .S file,
and fix the original problem by setting the xmm registers to zero rather than
checking that they're zero.
Now that we're no longer forcing -static, add nopie to the flags to prevent
compilation failure with target board unix/-fPIE/-pie.
Tested on x86_64-linux.
PR testsuite/30132
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30132
Alan Modra [Fri, 17 Feb 2023 03:20:18 +0000 (13:50 +1030)]
ld test asciz and ascii fails
Fix these fails:
alpha-dec-vms +FAIL: ld-scripts/asciz
alpha-dec-vms +FAIL: ld-scripts/ascii
i386-go32 +FAIL: ld-scripts/asciz
sh-coff +FAIL: ld-scripts/asciz
It's better to positively select targets for .section support than to
try to exclude all targets that don't. Make a new is_coff_format so
we can easily select such.
binutils/
* testsuite/lib/binutils-common.exp (is_coff_format): New.
ld/
* testsuite/ld-scripts/ascii.d: Use is_elf_format and
is_coff_format to select targets, exclude ti coff.
* testsuite/ld-scripts/asciz.d: Likewise. Accept trailing zeros.
Alan Modra [Fri, 17 Feb 2023 01:56:13 +0000 (12:26 +1030)]
Wild pointer reads in _bfd_ecoff_locate_line
* ecofflink.c (mk_fdrtab): Sanity check fdr procedure descriptor
pointer and isymBase. Set fdrtab_len after possible discards.
Use size_t vars and catch possible size overflows.
GDB Administrator [Fri, 17 Feb 2023 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in
Alan Modra [Thu, 16 Feb 2023 10:17:44 +0000 (20:47 +1030)]
PR30046, power cmpi leads to unknown architecture
PowerPC ELF always uses bfd_arch_powerpc, so we shouldn't allow the
gas -mpwr, -mpwr2 or -mpwrx options to choose bfd_arch_rs6000.
Given the possible values of ppc_cpu, I think the as_fatal at the end
of ppc_arch will never be reached, so it can be deleted and the code
simplified a little.
PR 30046
* config/tc-ppc.c (ppc_arch): Return bfd_arch_powerpc for ELF.
Delete dead code.
Tom Tromey [Thu, 16 Feb 2023 17:27:26 +0000 (10:27 -0700)]
Rename parameter of create_ada_exception_catchpoint
create_ada_exception_catchpoint has a parameter named "disabled", but
both its callers and callees use it to mean "enabled". This is
confusing, so this patch renames the parameter.
Tom Tromey [Wed, 11 Jan 2023 18:37:25 +0000 (11:37 -0700)]
Update the 'g' packet documentation
The 'g' packet documentation references a macro that no longer exists,
and it also claims that the 'x' response for an unavailable register
is limited to trace frames. This patch updates the documentation to
reflect what I think is currently correct.
Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Eli Zaretskii <eliz@gnu.org>
Change-Id: I863baa3b9293059cfd4aa3d534602cbcb693ba87
Nick Clifton [Thu, 16 Feb 2023 16:27:08 +0000 (16:27 +0000)]
Add support for the ASCII directive inside linker scripts.
* ldlex.l: Add ASCII token.
* ldgram.y: Add parsing of the ASCII command.
* ldlang.c (lang_add_string): Add maximum size parameter. Move escape character handling code into separate function.
* ldlang.h (lang_add_string): Update prototype.
* NEWS: Mention the new feature.
* ld.texi (Output Section Data): Document the new directives.
* testsuite/ld-scripts/asciz.t: Adjust to work on more architectures and to test more aspects of the ASCIZ directive.
* testsuite/ld-scripts/asciz.d: Adjust to match the changes to the test linker script.
* testsuite/ld-scripts/ascii.d: New test driver.
* testsuite/ld-scripts/ascii.s: New test assembler source.
* testsuite/ld-scripts/ascii.t: New test script.
* testsuite/ld-scripts/script.exp: Run the new test.
Tom Tromey [Thu, 16 Feb 2023 15:10:59 +0000 (08:10 -0700)]
Constify ada_main_name
Unlike the other *_main_name functions, ada_main_name returns a
non-const "char *". This is strange, though, because the caller
should not in fact modify or free this pointer. This patch changes
this function to constify its return type.
Tom Tromey [Thu, 16 Feb 2023 15:08:31 +0000 (08:08 -0700)]
Remove unused declaration from ada-lang.h
I stumbled across this declaration in ada-lang.h. I don't know what
function did, but it no longer exists, so remove the declaration.
Tested by rebuilding.
Alan Modra [Wed, 15 Feb 2023 22:45:57 +0000 (09:15 +1030)]
Delete PROGRESS macros
I don't see much point in cluttering the source with the PROGRESS
macros, which of course do nothing at all with the definitions in
progress.h. progress.h is unchanged apart from the copyright comment
since commit
d4d4c53c68f0 in 1994.
binutils/
* ar.c: Don't include progress.h, or invoke PROGRESS macros.
* nm.c: Likewise.
* objcopy.c: Likewise.
* objdump.c: Likewise.
gas/
* as.h: Don't include progress.h.
* as.c: Don't invoke PROGRESS macros.
* write.c: Likewise.
include/
* progress.h: Delete.
ld/
* ldmain.c: Don't include progress.h, or invoke PROGRESS macros.
Alan Modra [Wed, 15 Feb 2023 22:58:29 +0000 (09:28 +1030)]
gas_init
Rename gas_late_init to plain gas_init, to reinforce the idea that
this is where the bulk of gas initialisation belongs. Also reorder
some initialisation.
* as.c (gas_init): Rename from gas_late_init. Open output
file and arrange for dump_statistics to be called here rather
than in main. Create .gasversion. local symbol earlier,
because we can.
Jan Beulich [Thu, 16 Feb 2023 08:56:50 +0000 (09:56 +0100)]
RISC-V: as_warn() already emits a newline
Therefore there shouldn't be any at the end of the format string.
Andrew Burgess [Wed, 15 Feb 2023 11:42:12 +0000 (11:42 +0000)]
gdb/doc: document MI -remove-inferior command
Back in 2010 the -remove-inferior command was added in commit
a79b8f6ea8c2, unfortunately this command was never added to the
documentation.
This commit addresses that oversight.
Approved-By: Eli Zaretskii <eliz@gnu.org>
Jan Beulich [Thu, 16 Feb 2023 08:40:08 +0000 (09:40 +0100)]
x86/gas: replace inappropriate assertion when parsing registers
PR gas/30117
Once a symbol had its expression evaluated, the "segment" of the symbol
may be reg_section if a register is merely involved in the expression,
not just when the expression references a "plain" register. Therefore
the first of the assertions put in place by
4d1bb7955a8b was too strict.
Convert it to an if() to deal with situations like this one found by
fuzzing:
x=s
s=%eax+0
y=s
or $6,x
In non-debug builds this also avoids potentially silently generating bad
code.
GDB Administrator [Thu, 16 Feb 2023 00:00:23 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 14 Feb 2023 17:21:58 +0000 (10:21 -0700)]
Return bool from more value methods
There are several more value methods that currently return 'int' but
that should return 'bool'. This patch updates these.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Tom Tromey [Tue, 14 Feb 2023 17:16:26 +0000 (10:16 -0700)]
Have value::bits_synthetic_pointer return bool
This changes value::bits_synthetic_pointer to return bool and fixes up
some fallout from this.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Tom Tromey [Tue, 14 Feb 2023 16:43:26 +0000 (09:43 -0700)]
Change value::m_stack to bool
This changes value::m_stack to be a bool and updates the various uses.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Tom Tromey [Tue, 14 Feb 2023 16:40:35 +0000 (09:40 -0700)]
Change value::m_initialized to bool
This changes value::m_initialized to be a bool and updates the various
uses.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Tom Tromey [Tue, 14 Feb 2023 16:37:47 +0000 (09:37 -0700)]
Change value::m_lazy to bool
This changes value::m_lazy to be a bool and updates the various uses.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Tom Tromey [Tue, 14 Feb 2023 16:34:53 +0000 (09:34 -0700)]
Change value::m_modifiable to bool
This changes value::m_modifiable to be a bool and updates the various
uses.
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Pedro Alves [Thu, 9 Feb 2023 18:31:07 +0000 (18:31 +0000)]
Don't throw quit while handling inferior events, part II
I noticed that if Ctrl-C was typed just while GDB is evaluating a
breakpoint condition in the background, and GDB ends up reaching out
to the Python interpreter, then the breakpoint condition would still
fail, like:
c&
Continuing.
(gdb) Error in testing breakpoint condition:
Quit
That happens because while evaluating the breakpoint condition, we
enter Python, and end up calling PyErr_SetInterrupt (it's called by
gdbpy_set_quit_flag, in frame #0):
(top-gdb) bt
#0 gdbpy_set_quit_flag (extlang=0x558c68f81900 <extension_language_python>) at ../../src/gdb/python/python.c:288
#1 0x0000558c6845f049 in set_quit_flag () at ../../src/gdb/extension.c:785
#2 0x0000558c6845ef98 in set_active_ext_lang (now_active=0x558c68f81900 <extension_language_python>) at ../../src/gdb/extension.c:743
#3 0x0000558c686d3e56 in gdbpy_enter::gdbpy_enter (this=0x7fff2b70bb90, gdbarch=0x558c6ab9eac0, language=0x0) at ../../src/gdb/python/python.c:212
#4 0x0000558c68695d49 in python_on_memory_change (inferior=0x558c6a830b00, addr=0x555555558014, len=4, data=0x558c6af8a610 "") at ../../src/gdb/python/py-inferior.c:146
#5 0x0000558c6823a071 in std::__invoke_impl<void, void (*&)(inferior*, unsigned long, long, unsigned char const*), inferior*, unsigned long, long, unsigned char const*> (__f=@0x558c6a8ecd98: 0x558c68695d01 <python_on_memory_change(inferior*, CORE_ADDR, ssize_t, bfd_byte const*)>) at /usr/include/c++/11/bits/invoke.h:61
#6 0x0000558c68237591 in std::__invoke_r<void, void (*&)(inferior*, unsigned long, long, unsigned char const*), inferior*, unsigned long, long, unsigned char const*> (__fn=@0x558c6a8ecd98: 0x558c68695d01 <python_on_memory_change(inferior*, CORE_ADDR, ssize_t, bfd_byte const*)>) at /usr/include/c++/11/bits/invoke.h:111
#7 0x0000558c68233e64 in std::_Function_handler<void (inferior*, unsigned long, long, unsigned char const*), void (*)(inferior*, unsigned long, long, unsigned char const*)>::_M_invoke(std::_Any_data const&, inferior*&&, unsigned long&&, long&&, unsigned char const*&&) (__functor=..., __args#0=@0x7fff2b70bd40: 0x558c6a830b00, __args#1=@0x7fff2b70bd38:
93824992247828, __args#2=@0x7fff2b70bd30: 4, __args#3=@0x7fff2b70bd28: 0x558c6af8a610 "") at /usr/include/c++/11/bits/std_function.h:290
#8 0x0000558c6830a96e in std::function<void (inferior*, unsigned long, long, unsigned char const*)>::operator()(inferior*, unsigned long, long, unsigned char const*) const (this=0x558c6a8ecd98, __args#0=0x558c6a830b00, __args#1=
93824992247828, __args#2=4, __args#3=0x558c6af8a610 "") at /usr/include/c++/11/bits/std_function.h:590
#9 0x0000558c6830a620 in gdb::observers::observable<inferior*, unsigned long, long, unsigned char const*>::notify (this=0x558c690828c0 <gdb::observers::memory_changed>, args#0=0x558c6a830b00, args#1=
93824992247828, args#2=4, args#3=0x558c6af8a610 "") at ../../src/gdb/../gdbsupport/observable.h:166
#10 0x0000558c68309d95 in write_memory_with_notification (memaddr=0x555555558014, myaddr=0x558c6af8a610 "", len=4) at ../../src/gdb/corefile.c:363
#11 0x0000558c68904224 in value_assign (toval=0x558c6afce910, fromval=0x558c6afba6c0) at ../../src/gdb/valops.c:1190
#12 0x0000558c681e3869 in expr::assign_operation::evaluate (this=0x558c6af8e150, expect_type=0x0, exp=0x558c6afcfe60, noside=EVAL_NORMAL) at ../../src/gdb/expop.h:1902
#13 0x0000558c68450c89 in expr::logical_or_operation::evaluate (this=0x558c6afab060, expect_type=0x0, exp=0x558c6afcfe60, noside=EVAL_NORMAL) at ../../src/gdb/eval.c:2330
#14 0x0000558c6844a896 in expression::evaluate (this=0x558c6afcfe60, expect_type=0x0, noside=EVAL_NORMAL) at ../../src/gdb/eval.c:110
#15 0x0000558c6844a95e in evaluate_expression (exp=0x558c6afcfe60, expect_type=0x0) at ../../src/gdb/eval.c:124
#16 0x0000558c682061ef in breakpoint_cond_eval (exp=0x558c6afcfe60) at ../../src/gdb/breakpoint.c:4971
...
The fix is to disable cooperative SIGINT handling while handling
inferior events, so that SIGINT is saved in the global quit flag, and
not in the extension language, while handling an event.
This commit augments the testcase added by the previous commit to test
this scenario as well.
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: Idf8ab815774ee6f4b45ca2d0caaf30c9b9f127bb
Pedro Alves [Fri, 10 Feb 2023 19:23:01 +0000 (19:23 +0000)]
GC get_active_ext_lang
get_active_ext_lang is not used anywhere. Delete it.
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I4c2b6d0d11291103c098e4db1d6ea449875c96b7
Pedro Alves [Thu, 9 Feb 2023 13:46:28 +0000 (13:46 +0000)]
Don't throw quit while handling inferior events
This implements what I suggested here:
https://inbox.sourceware.org/gdb-patches/
ab97c553-f406-b094-cdf3-
ba031fdea925@palves.net/
Here is the current default quit_handler, a function that ends up
called by the QUIT macro:
void
default_quit_handler (void)
{
if (check_quit_flag ())
{
if (target_terminal::is_ours ())
quit ();
else
target_pass_ctrlc ();
}
}
As we can see above, when the inferior is running in the foreground,
then a Ctrl-C is translated into a call to target_pass_ctrlc().
The target_terminal::is_ours() case above is there to handle the
scenario where GDB has the terminal, meaning it is handling some
command the user typed, like "list", or "p a + b" or some such.
However, when the inferior is running on the background, say with
"c&", GDB also has the terminal. Run control handling is now done in
the "background". The CLI is responsive to user commands. If users
type Ctrl-C, they're expecting it to interrupt whatever command they
next type in the CLI, which again, could be "list", "p a + b", etc.
It's as if background run control was handled by a separate thread,
and the Ctrl-C is meant to go to the main thread, handling the CLI.
However, when handling an event, inside fetch_inferior_event &
friends, a Ctrl-C _also_ results in a Quit exception, from the same
default_quit_handler function shown above. This quit aborts run
control handling, breakpoint condition evaluation, etc., and may even
leave run control in an inconsistent state.
The testcase added by this patch illustrates this. The test program
just loops a number of times calling the "foo" function.
The idea is to set a breakpoint in the "foo" function with a condition
that sends SIGINT to GDB, and then evaluates to false, which results
in the program being re-resumed in the background. The SIGINT-sending
emulates pressing Ctrl-C just while GDB was evaluating the breakpoint
condition, except, it's more deterministic.
It looks like this:
(gdb) p $counter = 0
$1 = 0
(gdb) b foo if $counter++ == 10 || $_shell("kill -SIGINT `pidof gdb`") != 0
Breakpoint 2 at 0x555555555131: file gdb.base/bg-exec-sigint-bp-cond.c, line 21.
(gdb) c&
Continuing.
(gdb)
After that background continue, the breakpoint should be hit 10 times,
and we should see 10 "Quit" being printed on the screen. As if the
user typed Ctrl-C on the prompt a number of times with no inferior
running:
(gdb) <<< Ctrl-C
(gdb) Quit <<< Ctrl-C
(gdb) Quit <<< Ctrl-C
(gdb)
However, here's what you see instead:
(gdb) c&
Continuing.
(gdb) Quit
(gdb)
Just one Quit, and nothing else. If we look at the thread's state, we see:
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7ffff7d6f740 (LWP 112192) "bg-exec-sigint-" foo () at gdb.base/bg-exec-sigint-bp-cond.c:21
So the thread stopped, but we didn't report a stop...
Issuing another continue shows the same immediate-and-silent-stop:
(gdb) c&
Continuing.
(gdb) Quit
(gdb) p $counter
$2 = 2
As mentioned, since the run control handling, and breakpoint and
watchpoint evaluation, etc. are running in the background from the
perspective of the CLI, when users type Ctrl-C in this situation,
they're thinking of aborting whatever other command they were typing
or running at the prompt, not the run control side, not the previous
"c&" command.
So I think that we should install a custom quit_handler while inside
fetch_inferior_event, where we already disable pagination and other
things for a similar reason. This custom quit handler does nothing if
GDB has the terminal, and forwards Ctrl-C to the inferior otherwise.
With the patch implementing that, and the same testcase, here's what
you see instead:
(gdb) p $counter = 0
$1 = 0
(gdb) b foo if $counter++ == 10 || $_shell("kill -SIGINT `pidof gdb`") != 0
Breakpoint 2 at 0x555555555131: file gdb.base/bg-exec-sigint-bp-cond.c, line 21.
(gdb) c&
Continuing.
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb) Quit
(gdb)
Breakpoint 2, foo () at gdb.base/bg-exec-sigint-bp-cond.c:21
21 return 0;
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I1f10d99496a7d67c94b258e45963e83e439e1778
Pedro Alves [Wed, 8 Feb 2023 16:06:23 +0000 (16:06 +0000)]
Add new "$_shell(CMD)" internal function
For testing a following patch, I wanted a way to send a SIGINT to GDB
from a breakpoint condition. And I didn't want to do it from a Python
breakpoint or Python function, as I wanted to exercise non-Python code
paths. So I thought I'd add a new $_shell internal function, that
runs a command under the shell, and returns the exit code. With this,
I could write:
(gdb) b foo if $_shell("kill -SIGINT $gdb_pid") != 0 || <other condition>
I think this is generally useful, hence I'm proposing it here.
Here's the new function in action:
(gdb) p $_shell("true")
$1 = 0
(gdb) p $_shell("false")
$2 = 1
(gdb) p $_shell("echo hello")
hello
$3 = 0
(gdb) p $_shell("foobar")
bash: line 1: foobar: command not found
$4 = 127
(gdb) help function _shell
$_shell - execute a shell command and returns the result.
Usage: $_shell (command)
Returns the command's exit code: zero on success, non-zero otherwise.
(gdb)
NEWS and manual changes included.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Eli Zaretskii <eliz@gnu.org>
Change-Id: I7e36d451ee6b428cbf41fded415ae2d6b4efaa4e
Pedro Alves [Fri, 10 Feb 2023 11:55:00 +0000 (11:55 +0000)]
Make "ptype INTERNAL_FUNCTION" in Ada print like other languages
Currently, printing the type of an internal function in Ada shows
double <>s, like:
(gdb) with language ada -- ptype $_isvoid
type = <<internal function>>
while all other languages print it with a single <>, like:
(gdb) with language c -- ptype $_isvoid
type = <internal function>
I don't think there's a reason that Ada needs to be different. We
currently print the double <>s because we take this path in
ada_print_type:
switch (type->code ())
{
default:
gdb_printf (stream, "<");
c_print_type (type, "", stream, show, level, language_ada, flags);
gdb_printf (stream, ">");
break;
... and the type's name already has the <>s.
Fix this by simply adding an early check for
TYPE_CODE_INTERNAL_FUNCTION.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: Ic2b6527b9240a367471431023f6e27e6daed5501
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30105
Pedro Alves [Fri, 10 Feb 2023 11:32:35 +0000 (11:32 +0000)]
Fix "ptype INTERNAL_FUNC" (PR gdb/30105)
Currently, looking at the type of an internal function, like below,
hits an odd error:
(gdb) ptype $_isvoid
type = <internal function>type not handled in c_type_print_varspec_prefix()
That is an error thrown from
c-typeprint.c:c_type_print_varspec_prefix, where it reads:
...
case TYPE_CODE_DECFLOAT:
case TYPE_CODE_FIXED_POINT:
/* These types need no prefix. They are listed here so that
gcc -Wall will reveal any types that haven't been handled. */
break;
default:
error (_("type not handled in c_type_print_varspec_prefix()"));
break;
Internal function types have type code TYPE_CODE_INTERNAL_FUNCTION,
which is not explicitly handled by that switch.
That comment quoted above says that gcc -Wall will reveal any types
that haven't been handled, but that's not actually true, at least with
modern GCCs. You would need to enable -Wswitch-enum for that, which
we don't. If I do enable that warning, then I see that we're missing
handling for the following type codes:
TYPE_CODE_INTERNAL_FUNCTION,
TYPE_CODE_MODULE,
TYPE_CODE_NAMELIST,
TYPE_CODE_XMETHOD
TYPE_CODE_MODULE and TYPE_CODE_NAMELIST and Fortran-specific, so it'd
be a little weird to handle them here.
I tried to reach this code with TYPE_CODE_XMETHOD, but couldn't figure
out how to. ptype on an xmethod isn't treated specially, it just
complains that the method doesn't exist. I've extended the
gdb.python/py-xmethods.exp testcase to make sure of that.
My thinking is that whatever type code we add next, the most likely
scenario is that it won't need any special handling, so we'd just be
adding another case to that "do nothing" list. If we do need special
casing for whatever type code, I think that tests added at the same
time as the feature would uncover it anyhow. If we do miss adding the
special casing, then it still looks better to me to print the type
somewhat incompletely than to error out and make it harder for users
to debug whatever they need. So I think that the best thing to do
here is to just remove all those explicit "do nothing" cases, along
with the error default case.
After doing that, I decided to write a testcase that iterates over all
supported languages doing "ptype INTERNAL_FUNC". That revealed that
Pascal has a similar problem, except the default case hits a
gdb_assert instead of an error:
(gdb) with language pascal -- ptype $_isvoid
type =
../../src/gdb/p-typeprint.c:268: internal-error: type_print_varspec_prefix: unexpected type
A problem internal to GDB has been detected,
further debugging may prove unreliable.
That is fixed by this patch in the same way.
You'll notice that the new testcase special-cases the Ada expected
output:
} elseif {$lang == "ada"} {
gdb_test "ptype \$_isvoid" "<<internal function>>"
} else {
gdb_test "ptype \$_isvoid" "<internal function>"
}
That will be subject of the following patch.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: I81aec03523cceb338b5180a0b4c2e4ad26b4c4db
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30105
Simon Marchi [Tue, 14 Feb 2023 19:55:58 +0000 (14:55 -0500)]
gdb/dwarf2: split .debug_names reading code to own file
Move everything related to reading .debug_names from read.c to
read-debug-names.c. The only entry point exposed by
read-debug-names.{c,h} is dwarf2_read_debug_names.
Change-Id: I18b23f3c7a61b14abc3a46e4bf559bc2d078e8bc
Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Tue, 14 Feb 2023 19:55:57 +0000 (14:55 -0500)]
gdb/dwarf2: split .gdb_index reading code to own file
Move everything related to reading .gdb_index from read.c to
read-gdb-index.c. The only entry point exposed by read-gdb-index.{c,h}
is dwarf2_read_gdb_index.
Change-Id: I1e32c8f0720086538de8d2f612f27545377099bc
Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Tue, 14 Feb 2023 19:55:56 +0000 (14:55 -0500)]
gdb/dwarf2: move some things to read.h
The following 2 patches move .gdb_index and .debug_names reading code to
their own file. Prepare this by exposing some things used by that code
to read.h.
Change-Id: If8ef135758a2ff0ab3b765cc92596da8189f3bbd
Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Thu, 9 Feb 2023 18:54:26 +0000 (13:54 -0500)]
gdb: fix dealloc function not being called for frame 0
Tom de Vries reported [1] a regression in gdb.btrace/record_goto.exp
caused by
6d3717d4c4 ("gdb: call frame unwinders' dealloc_cache methods
through destroying the frame cache"). This issue is caught by ASan. On
a non-ASan build, it may or may not cause a crash or some other issue, I
haven't tried.
I managed to narrow it down to:
$ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.btrace/record_goto/record_goto -ex "start" -ex "record btrace" -ex "next"
... and then doing repeatedly "record goto 19" and "record goto 27".
Eventually, I get:
(gdb) record goto 27
=================================================================
==
1527735==ERROR: AddressSanitizer: heap-use-after-free on address 0x6210003392a8 at pc 0x55e4c26eef86 bp 0x7ffd229f24e0 sp 0x7ffd229f24d8
READ of size 8 at 0x6210003392a8 thread T0
#0 0x55e4c26eef85 in bfcache_eq /home/simark/src/binutils-gdb/gdb/record-btrace.c:1639
#1 0x55e4c37cdeff in htab_find_slot_with_hash /home/simark/src/binutils-gdb/libiberty/hashtab.c:659
#2 0x55e4c37ce24a in htab_find_slot /home/simark/src/binutils-gdb/libiberty/hashtab.c:703
#3 0x55e4c26ef0c6 in bfcache_new /home/simark/src/binutils-gdb/gdb/record-btrace.c:1653
#4 0x55e4c26f1242 in record_btrace_frame_sniffer /home/simark/src/binutils-gdb/gdb/record-btrace.c:1820
#5 0x55e4c1b926a1 in frame_unwind_try_unwinder /home/simark/src/binutils-gdb/gdb/frame-unwind.c:136
#6 0x55e4c1b930d7 in frame_unwind_find_by_frame(frame_info_ptr, void**) /home/simark/src/binutils-gdb/gdb/frame-unwind.c:196
#7 0x55e4c1bb867f in get_frame_type(frame_info_ptr) /home/simark/src/binutils-gdb/gdb/frame.c:2925
#8 0x55e4c2ae6798 in print_frame_info(frame_print_options const&, frame_info_ptr, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:1049
#9 0x55e4c2ade3e1 in print_stack_frame(frame_info_ptr, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:367
#10 0x55e4c26fda03 in record_btrace_set_replay /home/simark/src/binutils-gdb/gdb/record-btrace.c:2779
#11 0x55e4c26fddc3 in record_btrace_target::goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/record-btrace.c:2843
#12 0x55e4c2de2bb2 in target_goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/target.c:4169
#13 0x55e4c275ed98 in record_goto(char const*) /home/simark/src/binutils-gdb/gdb/record.c:372
#14 0x55e4c275edba in cmd_record_goto /home/simark/src/binutils-gdb/gdb/record.c:383
0x6210003392a8 is located 424 bytes inside of 4064-byte region [0x621000339100,0x62100033a0e0)
freed by thread T0 here:
#0 0x7f6ca34a5b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123
#1 0x55e4c38a4c17 in rpl_free /home/simark/src/binutils-gdb/gnulib/import/free.c:44
#2 0x55e4c1bbd378 in xfree<void> /home/simark/src/binutils-gdb/gdb/../gdbsupport/gdb-xfree.h:37
#3 0x55e4c37d1b63 in call_freefun /home/simark/src/binutils-gdb/libiberty/obstack.c:103
#4 0x55e4c37d25a2 in _obstack_free /home/simark/src/binutils-gdb/libiberty/obstack.c:280
#5 0x55e4c1bad701 in reinit_frame_cache() /home/simark/src/binutils-gdb/gdb/frame.c:2112
#6 0x55e4c27705a3 in registers_changed_ptid(process_stratum_target*, ptid_t) /home/simark/src/binutils-gdb/gdb/regcache.c:564
#7 0x55e4c27708c7 in registers_changed_thread(thread_info*) /home/simark/src/binutils-gdb/gdb/regcache.c:573
#8 0x55e4c26fd922 in record_btrace_set_replay /home/simark/src/binutils-gdb/gdb/record-btrace.c:2772
#9 0x55e4c26fddc3 in record_btrace_target::goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/record-btrace.c:2843
#10 0x55e4c2de2bb2 in target_goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/target.c:4169
#11 0x55e4c275ed98 in record_goto(char const*) /home/simark/src/binutils-gdb/gdb/record.c:372
#12 0x55e4c275edba in cmd_record_goto /home/simark/src/binutils-gdb/gdb/record.c:383
previously allocated by thread T0 here:
#0 0x7f6ca34a5e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x55e4c0b55c60 in xmalloc /home/simark/src/binutils-gdb/gdb/alloc.c:57
#2 0x55e4c37d1a6d in call_chunkfun /home/simark/src/binutils-gdb/libiberty/obstack.c:94
#3 0x55e4c37d1c20 in _obstack_begin_worker /home/simark/src/binutils-gdb/libiberty/obstack.c:141
#4 0x55e4c37d1ed7 in _obstack_begin /home/simark/src/binutils-gdb/libiberty/obstack.c:164
#5 0x55e4c1bad728 in reinit_frame_cache() /home/simark/src/binutils-gdb/gdb/frame.c:2113
#6 0x55e4c27705a3 in registers_changed_ptid(process_stratum_target*, ptid_t) /home/simark/src/binutils-gdb/gdb/regcache.c:564
#7 0x55e4c27708c7 in registers_changed_thread(thread_info*) /home/simark/src/binutils-gdb/gdb/regcache.c:573
#8 0x55e4c26fd922 in record_btrace_set_replay /home/simark/src/binutils-gdb/gdb/record-btrace.c:2772
#9 0x55e4c26fddc3 in record_btrace_target::goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/record-btrace.c:2843
#10 0x55e4c2de2bb2 in target_goto_record(unsigned long) /home/simark/src/binutils-gdb/gdb/target.c:4169
#11 0x55e4c275ed98 in record_goto(char const*) /home/simark/src/binutils-gdb/gdb/record.c:372
#12 0x55e4c275edba in cmd_record_goto /home/simark/src/binutils-gdb/gdb/record.c:383
The problem is a stale entry in the bfcache hash table (in
record-btrace.c), left across a reinit_frame_cache. This entry points
to something that used to be allocated on the frame obstack, that has
since been wiped by reinit_frame_cache.
Before the aforementioned, unwinder deallocation functions were called
by iterating on the frame chain, starting with the sentinel frame, like
so:
/* Tear down all frame caches. */
for (frame_info *fi = sentinel_frame; fi != NULL; fi = fi->prev)
{
if (fi->prologue_cache && fi->unwind->dealloc_cache)
fi->unwind->dealloc_cache (fi, fi->prologue_cache);
if (fi->base_cache && fi->base->unwind->dealloc_cache)
fi->base->unwind->dealloc_cache (fi, fi->base_cache);
}
After that patch, we relied on the fact that all frames are (supposedly)
in the frame_stash. A deletion function was added to the frame_stash
hash table, so that dealloc functions would be called when emptying the
frame stash. There is one case, however, where a frame_info is not in
the frame stash. That is when we create the frame_info for the current
frame (level 0, unwound from the sentinel frame), but don't compute its
frame id. The computation of the frame id for that frame (and only that
frame, AFAIK) is done lazily. And putting a frame_info in the frame stash
requires knowing its id. So a frame 0 whose frame id is not computed
yet is necessarily not in the frame stash.
When replaying with btrace, record_btrace_frame_sniffer insert entries
corresponding to frames in the "bfcache" hash table. It then relies on
record_btrace_frame_dealloc_cache being called for each frame to remove
all those entries when the frames get invalidated. If a frame reinit
happens while frame 0's id is not computed (and therefore that frame is
not in frame_stash), record_btrace_frame_dealloc_cache does not get
called for it, and it leaves a stale entry in bfcache. That then leads
to a use-after-free when that entry is accessed later, which ASan
catches.
The proposed solution is to explicitly call frame_info_del on frame 0,
if it exists, and if its frame id is not computed. If its frame id is
computed, it is expected that it will be in the frame stash, so it will
be "deleted" through that.
[1] https://inbox.sourceware.org/gdb-patches/
20230130200249.131155-1-simon.marchi@efficios.com/T/#mcf1340ce2906a72ec7ed535ec0c97dba11c3d977
Reported-By: Tom de Vries <tdevries@suse.de>
Tested-By: Tom de Vries <tdevries@suse.de>
Change-Id: I2351882dd511f3bbc01e4152e9db13b69b3ba384
Tom Tromey [Wed, 8 Feb 2023 04:43:37 +0000 (21:43 -0700)]
Remove RETURNS from BFD chew comments
When reading the BFD manual, I noticed text like this:
-- Function: bool bfd_close (bfd *abfd);
Close a BFD. If the BFD was open for writing, then pending
operations are completed and the file written out and closed. If
...
*Returns*
'TRUE' is returned if all is ok, otherwise 'FALSE'.
The *Returns*, like the *Synopsis* in the earlier patch, is
un-info-like. It's also used inconsistently.
This patch removes all the uses of the RETURNS word and removes it
entirely from the chew scripts. Now this example reads:
-- Function: bool bfd_close (bfd *abfd);
Close a BFD. If the BFD was open for writing, then pending
operations are completed and the file written out and closed. If
...
'TRUE' is returned if all is ok, otherwise 'FALSE'.
In a few cases I had to slightly reword the comment. There were also
a couple of cases where there was redundant text. In these cases I
just dropped the RETURNS copy.
2023-02-07 Tom Tromey <tom@tromey.com>
* bfd.c, cache.c, compress.c, opncls.c: Remove RETURNS from
documentation comments.
* doc/doc.str, doc/proto.str (RETURNS): Remove.
Tom Tromey [Wed, 8 Feb 2023 04:40:53 +0000 (21:40 -0700)]
Use @deftypefn in chew output
When reading the BFD info manual, function definitions looked very
strange to me:
*Synopsis*
long bfd_get_mtime (bfd *abfd);
*Description*
Return the file modification time (as read from the file system, or from
the archive header for archive members).
The *Synopsis* and *Description* text in particular is very un-info-like.
To fix this, I tried removing the *Synopsis* text and having FUNCTION
use @deftypefn instead. However, this ended up requiring some new
state, because SYNOPSIS can appear without FUNCTION. This in turn
required "catstrif" (I considered adding FORTH-style if-else-then, but
in the end decided on an ad hoc approach).
After this the result looks like:
-- Function: long bfd_get_mtime (bfd *abfd);
Return the file modification time (as read from the file system, or
from the archive header for archive members).
This patch also reorders a few documentation comments to ensure that
SYNOPSIS comes before DESCRIPTION. This is the more common style and
is also now required by doc.str.
2023-02-07 Tom Tromey <tom@tromey.com>
* syms.c (bfd_decode_symclass, bfd_is_undefined_symclass)
(bfd_symbol_info): Reorder documentation comment.
* doc/doc.str (synopsis_seen): New variable.
(SYNOPSIS): Set synopsis_seen. Emit @deftypefn.
(DESCRIPTION): Use synopsis_seen.
* doc/chew.c (catstrif): New function.
(main): Add catstrif intrinsic.
(compile): Recognize "variable" command.
Tom Tromey [Tue, 7 Feb 2023 19:14:54 +0000 (12:14 -0700)]
Change internalmode to be an intrinsic variable
Currently, internalmode is a special word to set an internal state
variable. Because this series adds variables anyway, change this to
be a variable instead.
I saw some commits in the history that made sure that chew did not
leak memory, so I put some extra effort into trying to handle this for
variables as well.
2023-02-07 Tom Tromey <tom@tromey.com>
* doc/proto.str (external, internal, ifinternal, ENUMEQ, ENUMDOC):
Update.
* doc/chew.c (internalmode): Remove.
(add_intrinsic_variable): New function.
(main): Add internalmode as intrinsic.
(internal_mode): Remove global.
(maybecatstr): Update.
(free_words): Free variables.
Tom Tromey [Tue, 7 Feb 2023 19:03:37 +0000 (12:03 -0700)]
Use intptr_t rather than long in chew
To implement variables in chew, it's convenient to have a
pointer-sized integer on the stack. To this end, use intptr_t rather
than long.
2023-02-07 Tom Tromey <tom@tromey.com>
* doc/chew.c (pcu) <l>: Now intptr_t.
(internal_mode, istack, isp): Likewise.
(bang, atsign): Use intptr_t.