Commit Graph

120176 Commits

Author SHA1 Message Date
Tom Tromey
ae2f3fa758 Turn decode_line_2_compare_items into operator<
This rewrites decode_line_2_compare_items to be an operator< on the
relevant type.  This simplifies the code a little.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-11-04 12:56:57 -07:00
Simon Marchi
0b4c9b5057 gdb: cleanup includes in *-typeprint.[ch]
Remove includes reported as unused by clangd.

Include "gdb-hashtab.h" in typeprint.h for the use of "htab_up".

Change-Id: I5b04ec14e71800e2d6ad622838e39b7033e168cf
2024-11-04 13:19:03 -05:00
Simon Marchi
a2d63ac679 gdb: cleanup includes in gdbtypes.h
Remove some includes reported as unused by clangd.

Change-Id: Ifc74f782d5aaafd1d719816821860352090c6667
2024-11-04 13:18:23 -05:00
Tom Tromey
8675d15227 Remove gdb::hash_enum
gdb::hash_enum is a workaround for a small oversight in C++11:
std::hash was not defined for enumeration types.  This was rectified
in C++14 and so we can remove the local workaround.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-11-04 10:49:06 -07:00
Andrew Burgess
ebc73070f4 gdb: use option framework for add-inferior and clone-inferior
Convert the add-inferior and clone-inferior commands to make use of
the option framework.  This improves the tab completion for these
commands.

Previously the add-inferior command used a trick to simulate
completion of -exec argument.  The command use filename completion for
everything on the command line, thus you could do:

  (gdb) add-inferior /path/to/some/fil<TAB>

and GDB would complete the file name, even though add-inferior doesn't
really take a filename as an argument.  This helped a little though
because, if the user did this:

  (gdb) add-inferior -exec /path/to/some/fil<TAB>

then the file name would be completed.  However, GDB didn't really
understand the options, so couldn't offer completion of the options
themselves.

After this commit, the add-inferior command makes use of the recently
added gdb::option::filename_option_def feature.  This means that the
user now has full completion of the option names, and that file names
will still complete for the '-exec' option, but will no longer
complete if the '-exec' option is not used.

I have also converted the clone-inferior command, though this command
does not use any file name options.  This command does now have proper
completion of the command options.
2024-11-04 16:11:51 +00:00
Andrew Burgess
3105b46ed1 gdb: add filename option support
This commit adds support for filename options to GDB's option
sub-system (see cli/cli-option.{c,h}).

The new filename options support quoted and escaped filenames, and tab
completion is fully supported.

This commit adds the new option, and adds these options to the
'maintenance test-options' command as '-filename', along with some
tests that exercise this new option.

I've split the -filename testing into two.  In gdb.base/options.exp we
use the -filename option with some arbitrary strings.  This tests that
GDB can correctly extract the value from a filename option, and that
GDB can complete other options after a filename option.  However,
these tests don't actually pass real filenames, nor do they test
filename completion.

In gdb.base/filename-completion.exp I have added some tests that test
the -filename option with real filenames, and exercise filename tab
completion.

This commit doesn't include any real uses of the new filename options,
that will come in the next commit.
2024-11-04 15:56:01 +00:00
Andrew Burgess
91f8973ba3 gdb/testsuite: spring clean the gdb.stabs/gdb11479.exp test
I had reason to look at the gdb.stabs/gdb11479.exp test script and
figured it could do with a small clean up.  I've:

  - Made use of standard_testfile and the variables it defines.

  - Made use of with_test_prefix and removed the prefix from the end
    of each test name.

  - Avoid overwriting the test binary when we recompile, instead use a
    different name for each recompilation.

  - Add '.' at the end of each comment.

There should be no changes in what is tested with this commit.

Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-11-04 15:51:40 +00:00
Aditya Vidyadhar Kamath
9247f05284 Fix AIX core dump while main thread exits.
Consider the test case:
void *thread_main(void *) {
  std::cout << getpid() << std::endl;
  sleep(20);
  return nullptr;
}

int main(void) {
  pthread_t thread;
  pthread_create(&thread, nullptr, thread_main, nullptr);
  pthread_join(thread, nullptr);

  return 0;
}

This program creates a thread via main that sleeps for 20 seconds.

When we debug this with gdb we get,
Reading symbols from ./test...
(gdb) b main
Breakpoint 1 at 0x10000934: file test.c, line 11.
(gdb) r
Starting program: /read_only_gdb/binutils-gdb/gdb/test

Breakpoint 1, main () at test.c:11
11   pthread_create(&thread, nullptr, thread_main, nullptr);
(gdb) c
Continuing.
15335884
[New Thread 258 (tid 31130079)]
Thread 2 received signal SIGINT, Interrupt.
[Switching to Thread 258 (tid 31130079)]
0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o)
(gdb) thread 1
[Switching to thread 1 (Thread 1 (tid 25493845))]
(gdb) c
Continuing.
[Thread 1 (tid 25493845) exited]
[Thread 258 (tid 31130079) exited]
inferior.c:405: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----

There are two bugs here. One is the core dump. The other is the main thread information
not captured.

So, while I was debugging the first part the reason, the reason I figured out was
the last for loop in sync_threadlists ().

Once both my threads exit we delete them as below:

for (struct thread_info *it : all_threads ())
      {
if (in_queue_threads.count (priv->pdtid) == 0
        && in_thread_list (proc_target, it->ptid)
        && pid == it->ptid.pid ())
      {
        delete_thread (it);
        data->exited_threads.insert (priv->pdtid);

But once these two threads are deleted, all_threads ()
has one more thread whose tid and pid are 0.

gdb) c
Continuing.
In for loop 8782296 is pid, 19857879 is tid
[Thread 1 (tid 19857879) exited]
In for loop 8782296 is pid, 30933401 is tid
[Thread 258 (tid 30933401) exited]
In for loop 0 is pid, 0 is tid
[Inferior 1 (process 8782296) exited normally]
(gdb) q

I used a printf in the for loop mentioned above for explaination.

You see the loop enters the third time with 0 as pid.

The reason being though the threads are removed but not deleted since they are
not deletable ().

Hence we use all_threads_safe () iterator instead.

The second part to the bug is the lack of information of the main thread.
Andrew was right here (https://sourceware.org/pipermail/gdb-patches/2024-September/211875.html)
Thank you Andrew.

The thread has loaded but then ptrace () call when we tried to fetch_regs_kernel_thread
failed. This returned EPERM as errno.

if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
        memset (gprs32, 0, sizeof (gprs32));

Hence all registers were set to 0 and we did not get the required infromation.
This issue will be fixed within the AIX ptrace call.

Approved By: Ulrich Weigand <ulrich.weigand@de.ibm.com>.
2024-11-04 02:42:05 -06:00
GDB Administrator
55e32b3c68 Automatic date update in version.in 2024-11-04 00:00:32 +00:00
GDB Administrator
69a9577358 Automatic date update in version.in 2024-11-03 00:00:17 +00:00
GDB Administrator
22d7506fb9 Automatic date update in version.in 2024-11-02 00:00:22 +00:00
Vladimir Mezentsev
d25ba4596e gprofng: use gprofng- prefix for gprofng binaries
gprofng application names have a gp- prefix (gp-display-text, gp-archive, etc.).
But our man pages use the gprofng- prefix (gprofng-display-text,
gprofng-archive, etc.).
I renamed the gprofng binaries and temporarily created the gp-* links for
compatibility with the old gprofng-gui.
We plan to remove these links in version 2.46.

gprofng/ChangeLog
2024-10-31  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* doc/gprofng-archive.texi: Rename gprofng application names.
	* doc/gprofng-collect-app.texi: Likewise.
	* doc/gprofng-display-html.texi: Likewise.
	* doc/gprofng-display-src.texi: Likewise.
	* doc/gprofng-display-text.texi: Likewise.
	* doc/gprofng.texi: Likewise.
	* doc/gprofng_ug.texi: Likewise.
	* gp-display-html/Makefile.am: Likewise.
	* gp-display-html/gp-display-html.in: Likewise.
	* libcollector/collector.c: Likewise.
	* src/Application.cc: Likewise.
	* src/Experiment.cc: Likewise.
	* src/Makefile.am: Likewise.
	* src/gp-archive.cc: Likewise.
	* src/gp-collect-app.cc: Likewise.
	* src/gp-display-src.cc: Likewise.
	* src/gp-display-text.cc: Likewise.
	* src/gprofng.cc: Likewise.
	* src/Makefile.in: Rebuild.
	* gp-display-html/Makefile.in: Rebuild.
2024-11-01 16:46:21 -07:00
Vladimir Mezentsev
e0c182c3ac Fix 32303 ./configure --help: replace --enable-gprofng with --disable-gprofng
ChangeLog
2024-10-31  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR 32303
	* configure.ac: Replace --enable-gprofng with --disable-gprofng
	* configure: Rebuild.
2024-11-01 16:32:33 -07:00
Indu Bhagat
47c88752f9 ld: generate SFrame stack trace info for .plt.got
PR/32298 sframe: no SFrame stack trace info generated for .plt.got

Add support to generate SFrame stack trace info for .plt.got section.
Enhance the current definition of struct elf_x86_sframe_plt to include
initialized SFrame FDE/FREs applicable for .plt.got section.  There are
two variants of .plt.got entries: 16 byte and 8 byte.

8 byte:
    ff 25 00 00 00 00     jmpq  *name@GOTPCREL(%rip)
    66 90                 xchg  %ax,%ax

16 byte:
    f3 0f 1e fa           endbr64
    ff 25 66 2f 00 00     jmpq  *name@GOTPCREL(%rip)
    66 0f 1f 44 00 00     nopw   0x0(%rax,%rax,1)

For the testcase, define some application symbols such that their PLT
entry is placed in .plt.got and ensure SFrame information is generated
with and without -z ibtplt.

ChangeLog:
	PR/32298
	* bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	PLT GOT entry size is different for IBT vs non IBT PLTs.
	* bfd/elfxx-x86.c (enum dynobj_sframe_plt_type): New enum for
	SFRAME_PLT_GOT.
	(_bfd_x86_elf_create_sframe_plt): Handle SFRAME_PLT_GOT.
	(_bfd_x86_elf_write_sframe_plt): Likewise.
	(_bfd_x86_elf_late_size_sections): Likewise.
	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
	* bfd/elfxx-x86.h (struct elf_x86_sframe_plt): Add new members
	to keep information about PLT GOT entries.
	(struct elf_x86_link_hash_table): Add support for creating
	SFrame section for .plt.got.
	* ld/testsuite/ld-x86-64/x86-64.exp: Add new tests.
	* ld/testsuite/ld-x86-64/sframe-pltgot-1.d: New test.
	* ld/testsuite/ld-x86-64/sframe-pltgot-1.s: New test.
	* ld/testsuite/ld-x86-64/sframe-pltgot-2.d: New test.
2024-11-01 15:36:35 -07:00
Josh Poimboeuf
938fb51218 ld: fix wrong SFrame info for lazy IBT PLT
Fix PR/32296 sframe: wrong SFrame info for pltN and .plt.sec for -z ibtplt

The x86 psABI defines a 2-PLT scheme for IBT which uses .plt and
.plt.sec entries.  It was observed that SFrame information for .plt.sec
section was incorrect.  The erroneous assumption was that SFrame stack
trace information for .plt.sec with lazy binding is the same as SFrame
stack trace information for .plt with lazy binding.  This is corrected
now by initializing a new SFrame PLT helper object
elf_x86_64_sframe_ibt_plt for lazy PLT with IBT.

Add a testcase where linking with -z ibtplt generates .plt.sec entries and
ensure correct SFrame information for it.

Committed by Indu Bhagat.

ChangeLog:
	PR/32296
	* bfd/elf64-x86-64.c (elf_x86_64_sframe_ibt_pltn_fre2): New
	definition elf_x86_64_sframe_ibt_plt.  Use it in
	elf_x86_64_sframe_plt.
	(elf_x86_64_link_setup_gnu_properties): Lazy IBT PLT entries are
	different from lazy PLT.
        * bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Adjust for
	SFrame for IBT PLT.
        * ld/testsuite/ld-x86-64/x86-64.exp: Add new test.
        * ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d: New test.
2024-11-01 15:36:03 -07:00
Josh Poimboeuf
1785837a25 ld: fix PR/32297
When _creating_ SFrame information for the linker created .plt.sec, the
code correctly checks for presence of .plt.sec.  When _writing_ the
SFrame section for the corresponding .plt.sec, however, the conditionals
were wrongly checking for splt.  This was causing an assertion at link
time.

This issue has been known to affect glibc build with SFrame enabled.

No testcase is added just yet.  A later commit ensures correct SFrame
stack trace information is created for .plt.got. A test case (where only
.plt and .plt.got are created) is added then.

PR/32297 sframe: bfd assertion with empty main on IBT enabled system

Committed by Indu Bhagat.

ChangeLog:
	PR/32297
	* bfd/elfxx-x86.c (_bfd_x86_elf_late_size_sections): Check for
	  plt_second member not for splt.
2024-11-01 15:31:21 -07:00
H.J. Lu
360f74a101 x86-64: Add a test for hidden undefined symbol
Linker should report an error for hidden undefined symbol when building
a shared library without the "recompile with -fPIC" message:

$ cat x.c
extern int foo __attribute__ ((visibility ("hidden")));

int
func (void)
{
  return foo;
}
$ gcc -c -fPIC -O2 x.c
$ objdump -dwr x.o

x.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <func>:
   0:	8b 05 00 00 00 00    	mov    0x0(%rip),%eax        # 6 <func+0x6>	2: R_X86_64_PC32	foo-0x4
   6:	c3                   	ret
$ ld -shared -o x.so x.o
ld: x.o: in function `func':
x.c:(.text+0x2): undefined reference to `foo'
ld: x.o: relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object
ld: final link failed: bad value
$

since -fPIC has been used.

	* testsuite/ld-x86-64/hidden6.d: New file.
	* testsuite/ld-x86-64/hidden6.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run hidden6.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-11-02 05:27:48 +08:00
Andrew Oates
086a2beb15 Fix compile error due to [[noreturn]] with clang
Since commit d9deb60b2e, I get the
following compiler error when building binutils (cross-compiling) on
macos:

 CXX    remote-sim.o
../../gdb/remote-sim.c:334:28: error: assigning to 'void (*)(host_callback *, const char *, ...) __attribute__((noreturn))' (aka 'void (*)(host_callback_struct *, const char *, ...) __attribute__((noreturn))') from incompatible type 'void (host_callback
*, const char *, ...)' (aka 'void (host_callback_struct *, const char *, ...)')
      gdb_callback.error = gdb_os_error;
                           ^~~~~~~~~~~~
1 error generated.

This appears to be due to the mismatch between ATTRIBUTE_NORETURN and
[[noreturn]] on gdb_os_error.  Reverting the change for gdb_os_error
resolves the issue.  Removing ATTTRIBUTE_NORETURN on the
declaration of host_callback::error also works, but deprives the
compiler of data.

Tested by compiling on macos both with the system clang, as well as with
GCC 14.  With clang, remote-sim.c does not compile (per above) without
this patch.  With GCC, it compiles with and without the patch (it
doesn't link, but AFAICT that is unrelated).

The clang bug is reported upstream at
https://github.com/llvm/llvm-project/issues/113511

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-01 11:13:54 -06:00
Tom Tromey
76367d2314 Add gdb.events.tui_enabled
This adds a new event source so that Python scripts can track whether
or not the TUI is presently enabled.

v2 of the patch renames "status" -> "enabled".

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32162
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-11-01 11:06:47 -06:00
GDB Administrator
893e4fd623 Automatic date update in version.in 2024-11-01 00:00:55 +00:00
Domani Johannes
820ebe46a4 Prevent use-after-free of bfd filename in gdb_bfd_close_or_warn
On Windows gcore is not implemented, and if you try it, you get an
heap-use-after-free error:

(gdb) gcore C:/gdb/build64/gdb-git-python3/gdb/testsuite/outputs/gdb.base/gcore-buffer-overflow/gcore-buffer-overflow.test
warning: cannot close "=================================================================
==10108==ERROR: AddressSanitizer: heap-use-after-free on address 0x1259ea503110 at pc 0x7ff6806e3936 bp 0x0062e01ed990 sp 0x0062e01ed140
READ of size 111 at 0x1259ea503110 thread T0
    #0 0x7ff6806e3935 in strlen C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:391
    #1 0x7ff6807169c4 in __pformat_puts C:/gcc/src/mingw-w64-v12.0.0/mingw-w64-crt/stdio/mingw_pformat.c:558
    #2 0x7ff6807186c1 in __mingw_pformat C:/gcc/src/mingw-w64-v12.0.0/mingw-w64-crt/stdio/mingw_pformat.c:2514
    #3 0x7ff680713614 in __mingw_vsnprintf C:/gcc/src/mingw-w64-v12.0.0/mingw-w64-crt/stdio/mingw_vsnprintf.c:41
    #4 0x7ff67f34419f in vsnprintf(char*, unsigned long long, char const*, char*) C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:484
    #5 0x7ff67f34419f in string_vprintf[abi:cxx11](char const*, char*) C:/gdb/src/gdb.git/gdbsupport/common-utils.cc:106
    #6 0x7ff67b37b739 in cli_ui_out::do_message(ui_file_style const&, char const*, char*) C:/gdb/src/gdb.git/gdb/cli-out.c:227
    #7 0x7ff67ce3d030 in ui_out::call_do_message(ui_file_style const&, char const*, ...) C:/gdb/src/gdb.git/gdb/ui-out.c:571
    #8 0x7ff67ce4255a in ui_out::vmessage(ui_file_style const&, char const*, char*) C:/gdb/src/gdb.git/gdb/ui-out.c:740
    #9 0x7ff67ce2c873 in ui_file::vprintf(char const*, char*) C:/gdb/src/gdb.git/gdb/ui-file.c:73
    #10 0x7ff67ce7f83d in gdb_vprintf(ui_file*, char const*, char*) C:/gdb/src/gdb.git/gdb/utils.c:1881
    #11 0x7ff67ce7f83d in vwarning(char const*, char*) C:/gdb/src/gdb.git/gdb/utils.c:181
    #12 0x7ff67f3530eb in warning(char const*, ...) C:/gdb/src/gdb.git/gdbsupport/errors.cc:33
    #13 0x7ff67baed27f in gdb_bfd_close_warning C:/gdb/src/gdb.git/gdb/gdb_bfd.c:437
    #14 0x7ff67baed27f in gdb_bfd_close_or_warn C:/gdb/src/gdb.git/gdb/gdb_bfd.c:646
    #15 0x7ff67baed27f in gdb_bfd_unref(bfd*) C:/gdb/src/gdb.git/gdb/gdb_bfd.c:739
    #16 0x7ff68094b6f2 in gdb_bfd_ref_policy::decref(bfd*) C:/gdb/src/gdb.git/gdb/gdb_bfd.h:82
    #17 0x7ff68094b6f2 in gdb::ref_ptr<bfd, gdb_bfd_ref_policy>::~ref_ptr() C:/gdb/src/gdb.git/gdbsupport/gdb_ref_ptr.h:91
    #18 0x7ff67badf4d2 in gcore_command C:/gdb/src/gdb.git/gdb/gcore.c:176

0x1259ea503110 is located 16 bytes inside of 4064-byte region [0x1259ea503100,0x1259ea5040e0)
freed by thread T0 here:
    #0 0x7ff6806b1687 in free C:/gcc/src/gcc-14.2.0/libsanitizer/asan/asan_malloc_win.cpp:90
    #1 0x7ff67f2ae807 in objalloc_free C:/gdb/src/gdb.git/libiberty/objalloc.c:187
    #2 0x7ff67d7f56e3 in _bfd_free_cached_info C:/gdb/src/gdb.git/bfd/opncls.c:247
    #3 0x7ff67d7f2782 in _bfd_delete_bfd C:/gdb/src/gdb.git/bfd/opncls.c:180
    #4 0x7ff67d7f5df9 in bfd_close_all_done C:/gdb/src/gdb.git/bfd/opncls.c:960
    #5 0x7ff67d7f62ec in bfd_close C:/gdb/src/gdb.git/bfd/opncls.c:925
    #6 0x7ff67baecd27 in gdb_bfd_close_or_warn C:/gdb/src/gdb.git/gdb/gdb_bfd.c:643
    #7 0x7ff67baecd27 in gdb_bfd_unref(bfd*) C:/gdb/src/gdb.git/gdb/gdb_bfd.c:739
    #8 0x7ff68094b6f2 in gdb_bfd_ref_policy::decref(bfd*) C:/gdb/src/gdb.git/gdb/gdb_bfd.h:82
    #9 0x7ff68094b6f2 in gdb::ref_ptr<bfd, gdb_bfd_ref_policy>::~ref_ptr() C:/gdb/src/gdb.git/gdbsupport/gdb_ref_ptr.h:91
    #10 0x7ff67badf4d2 in gcore_command C:/gdb/src/gdb.git/gdb/gcore.c:176

It happens because gdb_bfd_close_or_warn uses a bfd-internal name for
the failing-close warning, after the close is finished, and the name
already freed:

static int
gdb_bfd_close_or_warn (struct bfd *abfd)
{
  int ret;
  const char *name = bfd_get_filename (abfd);

  for (asection *sect : gdb_bfd_sections (abfd))
    free_one_bfd_section (sect);

  ret = bfd_close (abfd);

  if (!ret)
    gdb_bfd_close_warning (name,
			   bfd_errmsg (bfd_get_error ()));

  return ret;
}

Fixed by making a copy of the name for the warning.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-31 13:40:11 +01:00
Nelson Chu
6c4f88a10e gas/doc/riscv: Fixed misaligned instruction table
gas/
	* doc/c-riscv.texi: Fixed misaligned instruction table.
2024-10-31 11:45:57 +08:00
Nelson Chu
004a5bfc72 RISC-V: Dump instruction without checking architecture support as usual.
Since QEMU have supported -Max option to to enable all normal extensions,
the dis-assembler should also add an option, -M,max to do the same thing.
For the instruction, which have overlapped encodings like zfinx, will not
be considered by the -M,max option.

opcodes/
	* riscv-dis.c (all_ext): New static boolean.  If set, disassemble
	without checking architectire string.
	(riscv_disassemble_insn): Likewise.
	(parse_riscv_dis_option_without_args): Recognized -M,max option.
binutils/
	* NEWS: Updated.
2024-10-31 11:28:45 +08:00
GDB Administrator
4868f6025e Automatic date update in version.in 2024-10-31 00:00:21 +00:00
H.J. Lu
afc1f137e1 ld-elf/pr25207.d: Pass --no-rosegment to ld
Pass --no-rosegment to ld to support linker configured with
--enable-rosegment,

	PR ld/25207
	* ld-elf/pr25207.d: Pass --no-rosegment to ld.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-31 05:04:15 +08:00
Guinevere Larsen
b02e6f38a6 gdb: Update SECURITY.txt to mention extension scripts and internal errors
Given the recent CVE filed for GDB (CVE-2024-36699), I decided to update
the gdb/SECURITY.txt to be more explicit about some details. Specifically,
we now explicitly say that internal errors aren't security
vulnerabilities, and mention that users should review plugins before
running them, and under which conditions a plugin can cause a security
bug.

Reviewed-By: Tom Tromey <tom@tromey.com>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-30 14:27:07 -03:00
Tom de Vries
35d53ce642 [gdb/tdep] Use std::array in amd64-windows-tdep.c
I noticed commit 84786372e1 ("Fix size of register buffer") fixing a
stack-buffer-overflow found by AddressSanitizer in
amd64_windows_store_arg_in_reg:
...
-  gdb_byte buf[8];
+  gdb_byte buf[16];
...
and wondered if we could have found this without AddressSanitizer.

I realized that the problem is that this:
...
  gdb_byte buf[N];
  ...
  regcache->cooked_write (regno, buf);
...
is using the deprecated variant of cooked_write instead of the one using
gdb::array_view:
...
  /* Transfer of pseudo-registers.  */
  void cooked_write (int regnum, gdb::array_view<const gdb_byte> src);

  /* Deprecated overload of the above.  */
  void cooked_write (int regnum, const gdb_byte *src);
...
and consequently cooked_write does not know the size of buf.

Fix this by using std::array, and likewise in other places in
gdb/amd64-windows-tdep.c.

In the process I fixed another out of bounds access here:
...
	gdb_byte imm16[2];
  ...
	cache->prev_sp = cur_sp
	  + extract_unsigned_integer (imm16, 4, byte_order);
...
where we're reading 4 bytes from the 2-byte buffer imm16.

Tested by rebuilding on x86_64-linux.

Tested-By: Hannes Domani <ssbssa@yahoo.de>
2024-10-30 13:30:51 +01:00
Jan Beulich
5330d85af1 x86: add a helper to copy insn operand info
We're doing such in fairly many places, and yet more are likely to
appear; centralize the logic, much like we already have
swap_2_operands().

While there also correct mis-indentation in adjacent code in
process_operands().
2024-10-30 12:13:22 +01:00
Jan Beulich
a3db0f57df x86/APX: support JMPABS also in assembler
Without this APX support isn't really complete.

For Intel syntax displacement form is needed, such that symbolic
operands won't need prefixing by "offset". (The other form is actually
not used at all in Intel syntax.)

For the record: To restrict displacement form to Intel syntax is not
something I actually agree with.
2024-10-30 12:12:54 +01:00
Jan Beulich
d0a9378d98 x86/APX: squash REX prefix when REX2 is being emitted
We should not (silently) emit a REX prefix ahead of a REX2-encoded insn;
such encodings are illegal. Best we can do is fold the REX bits into the
REX2 prefix, and then zap the REX one from i.prefix[].
2024-10-30 12:12:24 +01:00
GDB Administrator
0a81e17f76 Automatic date update in version.in 2024-10-30 00:00:53 +00:00
Bernd Edlinger
7ffd4868a7 Fix signal unsafe call inside a signal
It can easily happen that the signal handler function
`handle_fatal_signal` uses various signal unsafe functions.
The problematic functions are `_` and `strsignal` which
can be pre-computed after the `setlocale` call is done.

Unfortunately when compiled with --disable-libbacktrace a
different code path is used, that calls the glibc function
`backtrace` which calls `malloc` and `free` and is therefore
also signal unsafe, that is probably unfixable, so there
is no attempt to fix anything in this code path.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31713#c9
2024-10-29 16:02:49 +01:00
Tom de Vries
51527eb809 [gdb/testsuite] Add read1 and readmore to make-check-all.sh
There are two useful ways to run a test-case, that are not represented by a
board file in gdb/testsuite/boards: check-read1 and check-readmore.

Consequently, they're not run either by make-check-all.sh.

Fix this by adding check-read1 and check-readmore to make-check-all.sh.

Tested on x86_64-linux.  Verified with shellcheck.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-10-29 12:59:44 +01:00
Nick Clifton
4a487e028c
Add a target to src-release.sh to crate a binutils release without Gold 2024-10-29 11:50:04 +00:00
Hakan Candar
f4e363cae2 ld/ELF: Add --image-base command line option to the ELF linker
LLD has dropped the option -Ttext-segment for specifying image base
addresses, instead forcing the use of the --image-base option for both
ELF and PE targets. As it stands, GNU LD and LLVM LLD are incompatible,
having two different options for the same functionality.

This patch enables the use of --image-base on ELF targets, advancing
consistency and compatibility.

See: https://reviews.llvm.org/D70468
     https://maskray.me/blog/2020-11-15-explain-gnu-linker-options#address-related
     https://sourceware.org/bugzilla/show_bug.cgi?id=25207

Moreover, a new test has been added to ensure -z separate-code behaviour
when used with -Ttext-segment stays the same. When this combination is
used, -Ttext-segment sets the address of the first segment (R), not the
text segment (RX), and like with -z noseparate-code, no segments lesser
than the specified address are created. If this behaviour was to change,
the first (R) segment of the ELF file would begin in a lesser address
than the specified text (RX) segment, breaking traditional use of this
option for specifying image base address.
2024-10-29 19:38:39 +10:30
Tom de Vries
80ac478511 [gdb/symtab] Handle multiple .debug_info sections
When compiling dw2-multiple-debug-info.c using -gdwarf-5
-fdebug-types-section, we end with two .debug_info sections in the object
file:
...
$ g++ gdb.dwarf2/dw2-multiple-debug-info.c -c -g \
    -gdwarf-5 \
    -fdebug-types-section
$ readelf -WS dw2-multiple-debug-info.o | grep -v RELA | grep .debug_info
  [10] .debug_info  PROGBITS        0 000128 0000cd 00  GC  0   0  8
  [12] .debug_info  PROGBITS        0 0001f8 0000ad 00   C  0   0  8
...

One of them contains the CU for dw2-multiple-debug-info.c, the other contains
the TU for the type of variable a.

When trying to print the type of variable a, we get:
...
$ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a"
'a' has unknown type; cast it to its declared type
...
because the TU hasn't been read.

Fix this by adding support for reading multiple .debug_info sections, similar
to how that is done for multiple .debug_types sections, getting us instead:
...
$ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a"
type = class sp1::A {
  ...
}
...

Tested on x86_64-linux.

PR symtab/32223
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32223
2024-10-29 10:08:04 +01:00
Ijaz, Abdul B
b0fdcd4706 fortran: Fix arrays of variable length strings for FORTRAN
Before this change resolve_dynamic_array_or_string was called for
all TYPE_CODE_ARRAY and TYPE_CODE_STRING types, but, in the end,
this function always called create_array_type_with_stride, which
creates a TYPE_CODE_ARRAY type.

Suppose we have

subroutine vla_array (arr1, arr2)
  character (len=*):: arr1 (:)
  character (len=5):: arr2 (:)

  print *, arr1 ! break-here
  print *, arr2
end subroutine vla_array

The "print arr1" and "print arr2" command at the "break-here" line
gives the following output:

(gdb) print arr1
$1 = <incomplete type>
(gdb) print arr2
$2 = ('abcde', 'abcde', 'abcde')
(gdb) ptype arr1
type = Type
End Type
(gdb) ptype arr2
type = character*5 (3)

Dwarf info using Intel® Fortran Compiler for such case contains following:
 <1><fd>: Abbrev Number: 12 (DW_TAG_string_type)
    <fe>   DW_AT_name        : (indirect string, offset: 0xd2): .str.ARR1
    <102>   DW_AT_string_length: 3 byte block: 97 23 8 (DW_OP_push_object_address; DW_OP_plus_uconst: 8)

After this change resolve_dynamic_array_or_string now calls
create_array_type_with_stride or create_string_type, so if the
incoming dynamic type is a TYPE_CODE_STRING then we'll get back a
TYPE_CODE_STRING type.  Now gdb shows following:

(gdb) p arr1
$1 = ('abddefghij', 'abddefghij', 'abddefghij', 'abddefghij', 'abddefghij')
(gdb) p arr2
$2 = ('abcde', 'abcde', 'abcde')
(gdb) ptype arr1
type = character*10 (5)
(gdb) ptype arr2
type = character*5 (3)

In case of GFortran, compiler emits DW_TAG_structure_type for string type
arguments of the subroutine and it has only DW_AT_declaration tag.  This
results in <incomplete type> in gdb.  So, following issue is raised in gcc
bugzilla "https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101826".

Fixing above issue introduce regression in gdb.fortran/mixed-lang-stack.exp,
i.e. the test forces the language to C/C++ and print a Fortran string value.
The string value is a dynamic type with code TYPE_CODE_STRING.

Before this commit the dynamic type resolution would always convert this to
a TYPE_CODE_ARRAY of characters, which the C value printing could handle.

But now after this commit we get a TYPE_CODE_STRING, which
neither the C value printing, or the generic value printing code can
support.  And so, I've added support for TYPE_CODE_STRING to the generic
value printing, all characters of strings are printed together till the
first null character.

Lastly, in gdb.opt/fortran-string.exp and gdb.fortran/string-types.exp
tests it expects type of character array in 'character (3)' format but now
after this change we get 'character*3', so tests are updated accordingly.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-29 09:28:41 +01:00
Lulu Cai
287938873c LoongArch: Corrected to GNU style code 2024-10-29 15:56:52 +08:00
Jan Beulich
5168ed9912 x86: use <xyz> for VFPCLASSP{S,D}
Just like VFPCLASSPH does. While the order of generated table entries
changes this way, the individual entries don't change.
2024-10-29 08:08:50 +01:00
Jan Beulich
c1a4b47e2a gas: make fix_new_exp()'s "exp" parameter const
This really should be only an input; in particular it looks bogus that
O_add expressions are even altered. That altering and the recursion are
even pointless: Once expanding what the inner call would do (with
O_symbol) it becomes clear that this is no different than the default
case. Simplify the code accordingly, retaining the comment.
2024-10-29 08:08:29 +01:00
Jan Beulich
641cf0e2c0 gas: constify md_{short,long}opts and md_longopts_size
First of all make the declarations globally visible, such that producer
and consumer actually share them.

For the latter two simply add const (as PPC already had it,), while for
the former achieve the effect by converting to an array: There's no need
for the extra level of indirection.
2024-10-29 08:08:02 +01:00
Kito Cheng
a8ff55b5b4 RISC-V: Update the doc to match ISA manual
ISA manual use funct* rather than func*[1] (e.g. funct7 rather than func7),
and I realized that may something I typo at beginning when I write the patch
for `.insn` support...:P

[1] https://github.com/riscv/riscv-isa-manual/blob/main/src/rv32.adoc#integer-register-register-operations
2024-10-29 13:06:17 +08:00
GDB Administrator
ad909bee05 Automatic date update in version.in 2024-10-29 00:00:56 +00:00
Hannes Domani
84786372e1 Fix size of register buffer
When calling a function with double arguments, I get this asan error:

==7920==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x0053131ece38 at pc 0x7ff79697a68f bp 0x0053131ec790 sp 0x0053131ebf40
READ of size 16 at 0x0053131ece38 thread T0
    #0 0x7ff79697a68e in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long long), void const*, void const*, unsigned long long) C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:814
    #1 0x7ff79697aebd in memcmp C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:845
    #2 0x7ff79697aebd in memcmp C:/gcc/src/gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:840
    #3 0x7ff7927e237f in regcache::raw_write(int, gdb::array_view<unsigned char const>) C:/gdb/src/gdb.git/gdb/regcache.c:874
    #4 0x7ff7927e3c85 in regcache::cooked_write(int, gdb::array_view<unsigned char const>) C:/gdb/src/gdb.git/gdb/regcache.c:914
    #5 0x7ff7927e5d89 in regcache::cooked_write(int, unsigned char const*) C:/gdb/src/gdb.git/gdb/regcache.c:933
    #6 0x7ff7911d5965 in amd64_windows_store_arg_in_reg C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:216

Address 0x0053131ece38 is located in stack of thread T0 at offset 40 in frame
    #0 0x7ff7911d565f in amd64_windows_store_arg_in_reg C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:208

  This frame has 4 object(s):
    [32, 40) 'buf' (line 211) <== Memory access at offset 40 overflows this variable

It's because the first 4 double arguments are passed via XMM registers,
and they need a buffer of 16 bytes, even if we only use 8 bytes of them.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 21:00:44 +01:00
Hannes Domani
f951f2dbb8 Don't copy memory for arguments if there are none
If amd64_windows_push_arguments is called with no arguments, then ARGS
can be NULL, and inside the passed-by-pointer block, memcpy is called
with this NULL, which is undefined behavior.

So this just disable the passed-by-pointer block if there are no
arguments.

Fixes the following ubsan error:
C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:244:12: runtime error: null pointer passed as argument 2, which is declared to never be null

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 21:00:12 +01:00
Simon Marchi
2930265f05 gdbserver: remove unused include in gdbthread.h
clangd reports gdbsupport/common-gdbthread.h as unused in gdbthread.h,
which seems right, so remove it.  Add it to two files that need it, but
were relying on the now-removed include.

Change-Id: I12916a044d0b15f346c4ad0e6527ce99a6d460e4
2024-10-28 13:58:52 -04:00
Simon Marchi
541b188182 gdbserver: fix formatting in gdbthread.h
Remove newlines after return type in declarations.

Change-Id: I00c6f35e063024cf6674d532454b67e6d0d98a19
2024-10-28 13:58:42 -04:00
Guinevere Larsen
77f6ff4461 gdb/record: add support to vzeroupper instruction
This commit adds recording support for the AVX instruction vzeroupper,
which zeroes the high bits of ymm registers 0..15.  In the programmer's
manual, it is explicitly states that ymm registers 16..31 won't be
affected if present, so we only need to record the first 16 registers.

We record ymm_h registers since only the higher bits are touched, and
that reduces the memory footprint of the instruction.

This instruction is tested differently as we want to confirm we're only
saving the relevant registers, and we want to ensure we're saving
all of them, so it makes use of "maint print record-instruction" to see
exactly what was recorded.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Guinevere Larsen
5bf288d5a8 gdb/record: support AVX instructions VMOVDQ(U|A) when recording
This commit adds support for the instructions VMOVDQU and VMOVDQA, used
to move values to/from 256 bit registers. Unfortunately, the
programmer's manual is very incomplete (if not wrong) about these
instructions, so the logic had to be reverse engineered from how gcc
actually encodes the instruction.

This commit also changes the memory regions from the test to store 256
bits, so its easier to test the instructions and that we're recording
ymm registers correctly.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Guinevere Larsen
6be89caafe gdb/record: Add recording support to vpbroadcast instructions
This commit adds recording support to all AVX and AVX2 instructions
of the form vpbroadcast. GDB is not yet concerned about AVX512 in
recording mode, so for now we only support the AVX2 registers and
instructions.

This commit also updates the gdb.reverse/i386-avx-reverse.exp to test
broadcast instructions.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00