Commit Graph

120277 Commits

Author SHA1 Message Date
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
Guinevere Larsen
51de3d886c gdb/record: add support to AVX unpack instructions
This commit adds support to recording instructions to unpack high
or low data from XMM registers, identified by the mnemonics in the
form: VPUNPCK [L|H] [BW|WD|DQ|QDQ].
All these instructions are encoded the exact same way, and only affect
the destination register, making them trivial to implement together.

It also updates the test gdb.reverse/i386-avx-reverse.exp to test these
new instructions.  The test always uses ymm because the vpunpck
instructions overwrite the high bits, so we have to be able to record
the full ymm register, not just the output size.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Guinevere Larsen
4b672a4a6d gdb/record: add support to vmovd and vmovq instructions
This commit adds support to the x86_64 AVX instructions vmovd and vmovq.
The programmers manuals for Intel and AMD describe these 2 instructions
as being almost the same, but my local testing, using gcc 13.2 on Fedora
39, showed several differences and inconsistencies.

The instruction is supposed to always use the 3-byte VEX prefix, but I
could only find 2-byte versions. The instructions aren't differentiated
by the VEX.w bit, but by opcodes and VEX.pp.

This patch adds a test with many different uses for both vmovd and
vmovq. It also updates the test gdb.reverse/step-precsave.exp to
reference the generic "missing avx support" bug open in the bug tracker
(17346), instead of pointing to one that specifically calls out to
vmovd instructions.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23188
Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Guinevere Larsen
13f0113676 gdb: Start supporting AVX instruction
This patch introduces the information needed to properly identify the
VEX prefix, used to signal an AVX and AVX2 instruction, and introduces
a helper function to handle all AVX instruction, instead of adding to
the 3000 line long recording function.

This new function will temporarily set the current thread as "not
executing" so that it can read from pseudo registers as we record, since
most AVX/AVX2 instructions would benefit from recording ymm registers.

The new helper also handles unsupported instructions so that the largest
part of the i386_process_record doesn't have to be shifted by 2 spaces,
which made an unreadably big patch file.

The only expected difference to the end user added by this patch is a
small change to the unsupported message. This patch also updates the
test gdb.reverse/step-precsave.exp, by recognizing the new output.

As a note for the future, we don't handle xmm16-31 and ymm16-31 because
those require the EVEX prefix, meaning avx512 support.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Guinevere Larsen
2f46cda83b gdb: Allow replayed threads to read and write pseudo registers
In an effort to support AVX instructions when recording, we need to
allow replaying threads to access pseudo registers. Currently, if
we try to do that gdb will fail in a call to validate_registers_access,
because the thread is executing so GDB thinks it is unsafe to read
pseudo registers.

When replaying, the thread is really executing for all intents and
purposes, but the execution is just having GDB change values on
registers, so it will always be safe to read and write pseudo registers.
This commit changes functions that check for register access to allow
access when we are replaying. The check to whether we are replaying must
not happen when writing a core file, as record_full_list could be nullptr,
so we only check it if the thread is executing.

As of this commit, I don't know of a way to trigger this commit without
AVX support on record, so a test isn't provided. However, as soon as
record-full supports saving ymm registers, the AVX tests will test this
as well.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-28 10:46:33 -03:00
Jim Lin
917ed12066 RISC-V: Fix typo in gas/testsuite/gas/riscv/mapping.s
gas/
        * gas/riscv/mapping.s: Fix typo.
        * gas/riscv/mapping-dis.d: Fix typo.
        * gas/riscv/mapping-symbols.d. Fix typo.
2024-10-28 11:13:44 +08:00
GDB Administrator
b391a8b043 Automatic date update in version.in 2024-10-28 00:00:27 +00:00
Andrew Burgess
a723c56efb gdb/testsuite: avoid intermittent failures on a debuginfod test
I saw a failure in gdb.debuginfod/build-id-no-debug-warning.exp which
I could only produce one time.

Normally the test output looks like this:

  file /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug
  Reading symbols from /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug...
  Downloading separate debug info for /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug...
  Reading symbols from /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.client_cache/0c30f589cc4f2c0fb22c8914d042ddf39c9a3885/debuginfo...
  (gdb) PASS: gdb.debuginfod/build-id-no-debug-warning.exp: local_debuginfod: debuginfod running, info downloaded, no war

But one time I saw this:

  file /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug
  Reading symbols from /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug...
  Downloading 6.77 K separate debug info for /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.build-id/0c/30f589cc4f2c0fb22c8914d042ddf39c9a3885.debug...
  Reading symbols from /tmp/build/gdb/testsuite/outputs/gdb.debuginfod/build-id-no-debug-warning/.client_cache/0c30f589cc4f2c0fb22c8914d042ddf39c9a3885/debuginfo...
  (gdb) FAIL: gdb.debuginfod/build-id-no-debug-warning.exp: local_debuginfod: debuginfod running, info downloaded, no warnings

The difference is the "Downloading separate debug info for ..." line
has gained an extra '6.77 K' component.  When I got the FAIL the
machine was under heavy load, so I suspect everything was running
pretty slow.  I think the size is only added when the debuginfod
download is taking its time.

Anyway, the test in question is not expecting to see a size, which is
why it failed.

Every other debuginfod test does allow for an optional size being
printed, so lets update this test to also accept an optional size,
this should prevent failures like this in the future.
2024-10-27 09:06:29 +00:00
GDB Administrator
9af55b9568 Automatic date update in version.in 2024-10-27 00:00:22 +00:00
Tom de Vries
4be75f1fad [gdb/testsuite] Fix gdb.dwarf2/dwp-symlink.exp with target board fission-dwp
There are two test-cases that only run when the target board produces .dwp
files, gdb.dwarf2/dwp-sepdebug.exp and gdb.dwarf2/dwp-symlink.exp.

When running those test-cases with target board fission-dwp, I run into:
...
(gdb) ptype main^M
warning: Could not find DWO CU dwp-symlink0.dwo(0x496f1a7405c37a61) \
  referenced by CU at offset 0xa6 [in module dwp-symlink]^M
type = <unknown return type> ()^M
(gdb) FAIL: gdb.dwarf2/dwp-symlink.exp: binary default, dwp at symlink
...
coming from:
...
 # This case cannot work.
 gdb_test "ptype main" {type = int \(\)} "binary default, dwp at symlink"
...

I had a bit of difficulty understanding what the test-case does/tries to do,
so to build some understanding I reproduced the behaviour outside of the
test-case:
...
$ cat start.c
void _start (void) {}
$ gcc -gsplit-dwarf start.c -nostdlib
$ gdb -q -batch a.out -ex "print _start"
$1 = {void (void)} 0x400144 <_start>
$ dwp -e a.out
$ rm start.dwo
$ gdb -q -batch a.out -ex "print _start"
$1 = {void (void)} 0x400144 <_start>
$ ln -s a.out b.out
$ gdb -q -batch b.out -ex "print _start"
$1 = {void (void)} 0x400144 <_start>
$ mv a.out.dwp b.out.dwp
$ gdb -q -batch b.out -ex "print _start"
$1 = {void (void)} 0x400144 <_start>
$ gdb -q -batch a.out -ex "print _start"
During symbol reading: Could not find DWO CU start.dwo(0x8bdfd613387aa145) \
  referenced by CU at offset 0x0 [in module a.out]
warning: Could not find DWO CU start.dwo(0x8bdfd613387aa145) \
  referenced by CU at offset 0x0 [in module a.out]
$1 = {<text variable, no debug info>} 0x400144 <_start>
...
and agreed, that cannot work: the DWO CU required in a.out is in b.out.dwp,
and there's no way to find b.out.dwp starting from a.out.

The fact that a FAIL is produced is incorrect, gdb does nothing wrong.

Fix this by checking for the warning text instead.

While we're at it, fix this PATH as well:
...
(gdb) cd /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink^M
Working directory /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink.^M
(gdb) PASS: gdb.dwarf2/dwp-symlink.exp: cd \
  /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink
PATH: gdb.dwarf2/dwp-symlink.exp: cd \
  /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink
...

While we're at it, use string_to_regexp to simplify the test-case.

Tested on x86_64-linux, with target board fission-dwp.
2024-10-26 14:48:44 +02:00
Andrew Burgess
2bba460587 gdb/testsuite: fix test pattern after switch to -lbl matching
After commit:

  commit a1ccc78ea7
  Date:   Fri Oct 25 06:14:03 2024 +0200

      [gdb/testsuite] Fix some test-cases for check-read1 (-lbl)

I notice that gdb.base/sect-cmd.exp would sometimes fail.  The problem
is that by switching to line by line matching we now need to ensure
that the gdb_test_multiple patterns match up to the end of the line,
but don't actually include the trailing \r\n (yeah, our line by line
matching is weird).  We need to be especially careful anywhere '.*' is
used as this can potentially match content on a subsequent line.

I have replaced '.*' with '\[^\r\n\]*(?=\r\n)', matching everything up
to the end of the line, but not the end of line itself, and I've made
use of '(?=\r\n)' in a couple of other places to ensure we match up to
the end of the line, but don't match the line terminator itself.
2024-10-26 11:31:31 +01:00
Tom de Vries
5a43f7f040 [gdb] Don't create registry keys in destructor
Creating a registry key using emplace calls new:
...
      DATA *result = new DATA (std::forward<Args> (args)...);
...
which can throw a bad alloc, which will terminate gdb if called from a
destructor.

Fix this in a few places.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-26 08:40:07 +02:00
Alan Modra
b3ee98cda4 tekhex.c tidy writesym
Simplifies the code a little.  No functional changes.
2024-10-26 10:28:10 +10:30
Alan Modra
6ecc44f698 PR32300, --dependency-file: link dependencies are not all collected
PR 32300
	PR 31904
Revert patch accidentally committed with 057a2b4c4b
2024-10-26 10:25:38 +10:30
Tom de Vries
3d17c88172 [gdb] Handle bad alloc in gdb_rl_callback_read_char_wrapper_noexcept
Say we simulate a bad alloc in exceptions_state_mc_init:
...
 jmp_buf *
 exceptions_state_mc_init ()
 {
+  {
+    static bool throw_bad_alloc = true;
+    if (throw_bad_alloc)
+      {
+       throw_bad_alloc = false;
+
+       va_list dummy;
+       throw gdb_quit_bad_alloc (gdb_exception_quit ("bad alloc", dummy));
+      }
+  }
   catchers.emplace_front ();
   return &catchers.front ().buf;
 }
...

After starting gdb and typing "q", gdb terminates:
...
$ gdb -q
(gdb) terminate called after throwing an instance of 'gdb_quit_bad_alloc'
  what():  std::bad_alloc
...
because the bad alloc (thrown in TRY_SJLJ) is caught by the noexcept on
gdb_rl_callback_read_char_wrapper_noexcept:
...
static struct gdb_exception
gdb_rl_callback_read_char_wrapper_noexcept () noexcept
{
  struct gdb_exception gdb_expt;

  /* C++ exceptions can't normally be thrown across readline (unless
     it is built with -fexceptions, but it won't by default on many
     ABIs).  So we instead wrap the readline call with a sjlj-based
     TRY/CATCH, and rethrow the GDB exception once back in GDB.  */
  TRY_SJLJ
...

Fix this by renaming gdb_rl_callback_read_char_wrapper_noexcept to
gdb_rl_callback_read_char_wrapper_sjlj and calling it from a wrapper function
that catches the bad alloc expection:
...
static struct gdb_exception
gdb_rl_callback_read_char_wrapper_noexcept () noexcept
{
  try
    {
      return gdb_rl_callback_read_char_wrapper_sjlj ();
    }
  catch (gdb_exception &ex)
    {
      return std::move (ex);
    }
}
...
getting us instead:
...
$ gdb -q
(gdb) bad alloc
(gdb) q
...

Tested on aarch64-linux.
2024-10-25 12:48:18 +02:00
Tom de Vries
c33568d2c1 [gdb/testsuite] Fix gdb.cp/exceptprint.exp with check-read1
Fix test-case gdb.cp/exceptprint.exp with make target check-read1 by limiting
the output of skip_libstdcxx_probe_tests_prompt by making the used command
more precise: using "info probes stap libstdcxx" instead of "info probes".

Tested on x86_64-linux.
2024-10-25 06:14:03 +02:00
Tom de Vries
5c15d62074 [gdb/testsuite] Fix gdb.threads/ia64-sigill.exp with check-read1
Fix test-case gdb.threads/ia64-sigill.exp with make target check-read1 by
using a custom line-by-line exp_continue clause:
...
    -re "\r\n\[^\r\n\]*(?=\r\n\[^\r\n\]*\r\n)" {
	exp_continue
    }
...
which drops a line each time it finds two lines in the buffer.

This allows the other clauses to use two-line patterns.

Tested on x86_64-linux.
2024-10-25 06:14:03 +02:00
Tom de Vries
a1ccc78ea7 [gdb/testsuite] Fix some test-cases for check-read1 (-lbl)
I ran the testsuite in an environment simulating a stressed system in
combination with check-read1.  This exposes a few more FAILs.

Fix some by using -lbl.

Tested on x86_64-linux.
2024-10-25 06:14:03 +02:00
Tom de Vries
c593605f5f [gdb/testsuite] Fix some test-cases for check-read1 (pipe/grep)
I ran the testsuite in an environment simulating a stressed system in
combination with check-read1.  This exposes a few more FAILs.

Fix some by using pipe / grep to filter out unnecessary output.

Tested on x86_64-linux.
2024-10-25 06:14:03 +02:00
Tom de Vries
d411083069 [gdb/testsuite] Fix some test-cases for check-read1 (gdb_test_lines)
I ran the testsuite in an environment simulating a stressed system in
combination with check-read1.  This exposes a few more FAILs.

Fix some by using gdb_test_lines, as well as related gdb_get_lines.

Tested on x86_64-linux.
2024-10-25 06:14:03 +02:00
GDB Administrator
be6d665abd Automatic date update in version.in 2024-10-25 00:00:31 +00:00
Tom Tromey
ce61f407ac Add locking when reading BFD sections
This adds some per-BFD locking to gdb_bfd_map_section and
gdb_bfd_get_full_section_contents.

It turned out that the background DWARF reader could race with the
auto-load code, because the reader might try to mmap a section when
the main thread was trying to read in .debug_gdb_scripts.

The current BFD threading model is that only BFD globals will be
locked, so any multi-threaded use of a BFD has to be handled specially
by the application.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31626
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2024-10-24 14:17:47 -06:00
Tom Tromey
abbc4d4435 Use gdb_bfd_get_full_section_contents in auto-load.c
This changes auto-load.c ot use gdb_bfd_get_full_section_contents.
This shouldn't change any behavior, but makes it easier to add locking
in a subsequent patch.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2024-10-24 14:17:47 -06:00
Alan Modra
86b26b453f Replace uses of asprintf with xasprintf
xasprintf has a nicer interface and behaves like xmalloc as far as
memory is concerned, ie. no need to check a return status and the
program exits with an error on OOM.

binutils/
	* dwarf.c (load_debug_sup_file): Replace asprintf with xasprintf.
	* nm.c (get_elf_symbol_type, get_coff_symbol_type): Likewise.
	* objdump.c (dump_ctf_indent_lines): Likewise.
	* readelf.c (display_lto_symtab, dump_ctf_indent_lines): Likewise.
	* windres.c (main): Likewise.
	* configure.ac: Remove asprintf from AC_CHECK_DECLS.
	* config.in: Regenerate.
	* configure: Regenerate.
gas/
	* config/tc-kvx.c (kvx_emit_single_noop): Simplify.
	* config/tc-riscv.c (md_assemblef): Replace asprintf with xasprintf.
	* read.c (s_nop, do_s_func): Likewise.
	* stabs.c (stabs_generate_asm_func): Likewise.
	(stabs_generate_asm_endfunc): Likewise.
	* configure.ac: Remove asprintf from AC_CHECK_DECLS.
	* config.in: Regenerate.
	* configure: Regenerate.
ld/
	* ldlang.c (lang_leave_overlay_section): Replace xmalloc+sprintf
	with xasprintf.  Localise vars.
	* lexsup.c (parse_args): Replace asprintf with xasprintf.
	* pe-dll.c (make_head, make_tail, make_one): Likewise.
	(make_singleton_name_thunk, make_import_fixup_entry): Likewise.
	(make_runtime_pseudo_reloc): Likewise.
	(pe_create_runtime_relocator_reference): Likewise.
	* configure.ac: Remove asprintf from AC_CHECK_DECLS.
	* config.in: Regenerate.
	* configure: Regenerate.
2024-10-24 17:58:00 +10:30
Alan Modra
8b5a212495 tekhex object file output fixes
writevalue didn't handle 64-bit values, dropping the high 32 bits,
and also wrote any value in the range [0,15] as 0.

	* tekhex.c (first_phase): Handle *ABS* symbols.
	(writevalue): Rewrite.
2024-10-24 17:58:00 +10:30
GDB Administrator
4598f83eac Automatic date update in version.in 2024-10-24 00:00:32 +00:00
Guinevere Larsen
05eba57965 gdb/testsuite: introduce dwarf5 option to gdb_compile
A few tests on the testsuite require dwarf5 to work. Up until now, the
way to do this was to explicitly add the command line flag -gdwarf-5.
This isn't very portable, in case a compiler requires a different flag
to emit dwarf5.

This commit adds a new option to gdb_compile that would be able to add
the correct flag (if known) or error out in case we are unable to tell
which flag to use. It also changes the existing tests to use this
general option instead of hard coding -gdwarf-5.

Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
2024-10-23 14:16:37 -03:00
GDB Administrator
538271a1e0 Automatic date update in version.in 2024-10-23 00:00:49 +00:00
Tom Tromey
04ce6b03d9 Implement 'Object_Size
This patch started as an attempt to allow the 'Size attribute to be
applied to types, and not just objects.

However, that turns out to be difficult due to the Ada semantcs of
'Size.  In particular, Ada requires 'Size to denote the size of the
representation of the value, so for example Boolean'Size must be 1.
Implementing this properly requires information not readily available
to gdb... and while we could synthesize this information in many
cases, it also seemed to me that this wasn't strictly very useful when
debugging.

So instead, this patch adds support for the 'Object_Size attribute,
which is somewhat closer to 'sizeof'.

Note also that while 'Object_Size is defined for some dynamic types, I
chose not to implement this here, as again this information is not
readily available -- and I think it's preferable to error than to
print something that might be incorrect.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-10-22 12:04:06 -06:00
Michael Matz
8483536dea stringmerge: don't presize hash table
originally the reason for pre-sizing was that that's easier
for a multi-threaded use of the hash table.  That hasn't materialized
yet, so there's not much sense in using the very very conservative
estimates for pre-sizing.  Doing the resize on-demand, whenever we
actually need to add a new entry doesn't change performance.

	bfd/
	merge.c (sec_merge_hash_insert): Resize as needed from here ...
	(record_section): ... not from here.  Don't calculate estimates,
	return bool instead of three-state, regard all errors as soft
	errors.
	(_bfd_merge_sections): Adjust.
2024-10-22 14:14:32 +02:00
Stephan Rohr
4689c9b946 gdbserver: use 'gdb::function_view' in 'find_*' and 'for_each_*'
Remove the templated versions of 'find_thread', 'for_each_thread' and
'find_thread_in_random' and replace the template function argument with
'gdb::function_view'.  The usage of 'gdb::function_view' produces less
cryptic messages on errors and documents well the types of the
parameters taken by the callback and its return type.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-22 04:41:55 -07:00
Tom de Vries
a03c03f84a [gdb/testsuite] Handle maint set dwarf synchronous off default
I ran the testsuite with a patch setting dwarf_synchronous to false by
default, and ran into FAILs in test-cases gdb.dwarf2/dw2-inter-cu-error.exp
and gdb.dwarf2/dw2-inter-cu-error-2.exp, because the expected DWARF errors did
not show up as a result of the file command.

Fix this by forcing "maint set dwarf synchronous on".

Add the same in gdb.base/index-cache.exp, where this is also required.

Tested on aarch64-linux.
2024-10-22 09:23:26 +02:00
Tom de Vries
485d9cab65 [gdb/testsuite] Improve class name in gdb.dwarf2/self-spec.exp
I ran into:
...
(gdb) pipe maint print objfiles self-spec | grep c1^M
    name:       c1^M
    canonical:  c1^M
    qualified:  c1^M
    [3] ((addrmap *) 0xfffedfc1f010)^M
(gdb) FAIL: gdb.dwarf2/self-spec.exp: class c1 in cooked index
...

Fix this by renaming the class from c1 to class1.

Tested on aarch64-linux.
2024-10-22 09:23:25 +02:00
Tom de Vries
9858f29e6a [gdb] Handle EINTR in run_under_shell
When building gdb with -O2 -fsanitize=thread and running test-case
gdb.base/bg-exec-sigint-bp-cond.exp, I run into:
...
(gdb) c&^M
Continuing.^M
(gdb) Quit^M
(gdb) quit_count=1
^M
Breakpoint 2, foo () at bg-exec-sigint-bp-cond.c:23^M
23        return 0;^M
FAIL: $exp: no force memory write: \
  SIGINT does not interrupt background execution
...

What happens is that:
- the breakpoint hits
- while evaluating the condition of the breakpoint,
  $_shell("kill -INT <pid-of-gdb>") is called, handled by run_under_shell
- in run_under_shell, a vfork is issued
- in the vfork child, execl executes the kill command
- in the vfork parent, waitpid is called to wait for the result of the kill
  command
- waitpid returns -1 with errno set to EINTR
- run_under_shell doesn't check the result of waitpid, and returns the
  value of local variable status.  Since waitpid returned -1, status was
  not assigned a value, so it's uninitialized, and happens to be
  non-zero
- the breakpoint condition evaluates to true, because
  $_shell("kill -INT <pid-of-gdb>") != 0
- the breakpoint triggers a stop, which the test-case doesn't expect.

Fix this by using gdb::handle_eintr to call waitpid in run_under_shell.

Also handle the case that waitpid returns an error other than EINTR, using
perror_with_name.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR gdb/30695
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30695
2024-10-22 08:53:51 +02:00
Lulu Cai
3790b9f7ff LoongArch: Force relocation for every reference to the global offset table
Local absolute symbols are resolved at assembly stage and the symbol
value is placed in the relocation addend. But non-zero addend will
cause an assertion failure during linking.

Forces emission of relocations to defer resolution of local abs symbols
until link time.

bfd/

        * elfnn-loongarch.c (loongarch_elf_relax_section): Determine
          absolute symbols in advance to avoid ld crash.

gas/

        * config/tc-loongarch.c (loongarch_force_relocation): New
          function to force relocation.
        * config/tc-loongarch.h (TC_FORCE_RELOCATION): New macros
          to force relocation.
        (loongarch_force_relocation): Function declaration.
        * testsuite/gas/loongarch/localpic.d: New test.
        * testsuite/gas/loongarch/localpic.s: New test.
2024-10-22 12:01:41 +08:00
GDB Administrator
4806ed93bc Automatic date update in version.in 2024-10-22 00:00:23 +00:00
Tom de Vries
21769084e4 [gdb/symtab] Fix incorrect filenames with inter-CU refs
With target board unix we get:
...
$ gdb -q -batch outputs/gdb.cp/cplusfuncs/cplusfuncs \
  -ex "info function operator\*"
All functions matching regular expression "operator\*":

File /home/vries/gdb/src/gdb/testsuite/gdb.cp/cplusfuncs.cc:
72:     void foo::operator*(foo&);
85:     void foo::operator*=(foo&);
...
but with target board cc-with-dwz-m:
...
All functions matching regular expression "operator\*":

File /usr/lib/gcc/aarch64-redhat-linux/14/include/stddef.h:
72:     void foo::operator*(foo&);
85:     void foo::operator*=(foo&);
...

The first operator:
...
$ c++filt _ZN3foomlERS_
foo::operator*(foo&)
...
matches address 0x410250 which is defined here in the CU in the exec:
...
 <1><10f1>: Abbrev Number: 13 (DW_TAG_subprogram)
    <10f2>   DW_AT_specification: <alt 0x93>
    <10f6>   DW_AT_decl_line   : 72
    <10f7>   DW_AT_decl_column : 7
    <10f7>   DW_AT_object_pointer: <0x1106>
    <10f9>   DW_AT_low_pc      : 0x410250
    <1101>   DW_AT_high_pc     : 32
    <1102>   DW_AT_frame_base  : 1 byte block: 9c       (DW_OP_call_frame_cfa)
    <1104>   DW_AT_call_all_calls: 1
...
and declared here in the PU in the .dwz file:
...
 <2><93>: Abbrev Number: 20 (DW_TAG_subprogram)
    <94>   DW_AT_external    : 1
    <94>   DW_AT_name        : operator*
    <98>   DW_AT_decl_file   : 2
    <98>   DW_AT_decl_line   : 10
    <99>   DW_AT_decl_column : 9
    <9a>   DW_AT_linkage_name: _ZN3foomlERS_
    <9e>   DW_AT_accessibility: 1       (public)
    <9e>   DW_AT_declaration : 1
    <9e>   DW_AT_object_pointer: <0xa2>
...

When creating a new symbol for the operator, the DW_AT_decl_file attribute is
looked up, and found to be 2.

The 2 is supposed to be mapped using the PU, which has this file name table:
...
 The File Name Table (offset 0x78, lines 3, columns 2):
  Entry Dir     Name
  0     0       <dwz>
  1     1       stddef.h
  2     2       cplusfuncs.cc
...

Instead, it's mapped using the CU, which has this file name table:
...
 The File Name Table (offset 0x34, lines 3, columns 2):
  Entry Dir     Name
  0     1       cplusfuncs.cc
  1     1       cplusfuncs.cc
  2     2       stddef.h
...

This is PR symtab/30814.  There's a similar PR for lto, PR symtab/25771, where
the same problem happens for two CUs.

Fix this by using the correct file name table.

Add a dwarf assembly test-case for PR25771.

Tested on aarch64-linux.

Reviewed-By: Tom Tromey <tom@tromey.com>

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25771
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30814
2024-10-21 19:10:44 +02:00
Alexandra Hájková
0cb7f3a837 gdbreplay: Add --debug-logging option
As gdbreplay communicates with GDB, it outputs all the remote
protocol communication it reads from the remotelogfile to stderr.
This patch disables this behavior by default but adds the new
--debug-logging option which turns printing the packets
to stderr on again.

The motivation for this change is to make it possible to use
gdbreplay with TCL tests. Printing the whole remotelog file out
seems to overflow the expect cache wich causes gdbreplay to not
to get the packet its expects and results in going out of sync
with GDB. Other motivation is making communication between GDB
and gdbreplay faster as printing bigger remotelogfile takes
considerable amount of time.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2024-10-21 16:38:18 +02:00
Alexandra Hájková
32ffcd0737 gdbreplay: Use getopt_long to parse command line arguments
Approved-By: Tom Tromey <tom@tromey.com>
2024-10-21 16:38:09 +02:00
Tom de Vries
3be7119db2 [gdb/contrib] Handle dot in spellcheck.sh
Add handling of '.' in gdb/contrib/spellcheck.sh.

While we're at, simplify the sed invocation by using a single s command
instead of 3 s commands.

Also introduce sed_join and grep_join.

Fix the following common misspellings:
...
bandwith -> bandwidth
emmitted -> emitted
immediatly -> immediately
suprize -> surprise
thru -> through
transfered -> transferred
...

Verified with shellcheck.
2024-10-21 15:19:25 +02:00
Tom de Vries
6c80e57caa [gdb/contrib] Speed up spellcheck.sh --check
Speed up gdb/contrib/shellcheck.sh by caching the grep pattern.

Without cached grep pattern:
...
$ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c

real    0m2,750s
user    0m0,013s
sys     0m0,032s
...
and with cached grep pattern:
...
$ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c

real    0m0,192s
user    0m0,022s
sys     0m0,024s
...

Tested on aarch64-linux.
2024-10-21 15:07:02 +02:00
Tom de Vries
84fbbb5e61 [gdb/contrib] Add spellcheck.sh --check
Add a new option --check to gdb/contrib/spellcheck.sh, to do the spell
check and bail out ASAP with an exit code of 1 if misspelled words were
found, or 0 otherwise.

Verified with shellcheck.
2024-10-21 15:07:02 +02:00
Andrew Burgess
9ee8849814 gdb/guile: add get-basic-type
A question was asked on stackoverflow.com about the guile function
get-basic-type[1] which is mentioned in the docs along with an example
of its use.

The problem is, the function was apparently never actually added to
GDB.  But it turns out that it's pretty easy to implement, so lets add
it now.  Better late than never.

The implementation mirrors the Python get_basic_type function.  I've
added a test which is a copy of the documentation example.

One issue is that the docs suggest that the type will be returned as
just "int", however, I'm not sure what this actually means.  It makes
more sense that the function return a gdb:type object which would be
represented as "#<gdb:type int>", so I've updated the docs to show
this output.

[1] https://stackoverflow.com/questions/79058691/unbound-variable-get-basic-type-in-gdb-guile-session

Reviewed-By: Kevin Buettner <kevinb@redhat.com>
2024-10-21 10:36:32 +01:00
Tom de Vries
ced885161b [gdb/build, c++20] Fix more deprecated implicit capture of this
When building gdb with -std=c++20 I run into:
...
gdb/dwarf2/cooked-index.c: In lambda function:
gdb/dwarf2/cooked-index.c:471:47: error: implicit capture of ‘this’ via \
  ‘[=]’ is deprecated in C++20 [-Werror=deprecated]
  471 |   gdb::thread_pool::g_thread_pool->post_task ([=] ()
      |                                               ^
gdb/dwarf2/cooked-index.c:471:47: note: add explicit ‘this’ or ‘*this’ capture
...

Fix this and two more spots by removing the capture default, and explicitly
listing all captures.

Tested on x86_64-linux.
2024-10-21 08:04:07 +02:00
GDB Administrator
0740c33685 Automatic date update in version.in 2024-10-21 00:00:24 +00:00
Andrew Burgess
48a0a7ca5e gdb: fix 'maint info inline-frames' after 'stepi'
There is an invalid assumption within 'maint info inline-frames' which
triggers an assert:

  (gdb) stepi
  0x000000000040119d	18	  printf ("Hello World\n");
  (gdb) maintenance info inline-frames
  ../../src/gdb/inline-frame.c:554: internal-error: maintenance_info_inline_frames: Assertion `it != inline_states.end ()' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  ----- Backtrace -----
  ... etc ...

The problem is this assert:

  /* Stopped threads always have cached inline_state information.  */
  gdb_assert (it != inline_states.end ());

If you check out infrun.c and look in handle_signal_stop for the call
to skip_inline_frames then you'll find a rather large comment that
explains that we don't always compute the inline state information for
performance reasons.  So the assertion is not valid.

I've updated the code so that if there is cached information we use
that, but if there is not then we just create our own information for
the current $pc of the current thread.

This means that, if there is cached information, GDB still correctly
shows which frame the inferior is in (it might not be in the inner
most frame).

If there is no cached information we will always display the inferior
as being in the inner most frame, but that's OK, because if
skip_inline_frames has not been called then GDB will have told the
user they are in the inner most frame, so everything lines up.

I've extended the test to check 'maint info inline-frames' after a
stepi which would previously have triggered the assertion.
2024-10-20 21:54:13 +01:00
Tom Tromey
40ae603e6e Use std::make_unique in more places
I searched for spots using ".reset (new ...)" and replaced most of
these with std::make_unique.  I think this is a bit cleaner and more
idiomatic.

Regression tested on x86-64 Fedora 40.

Reviewed-By: Klaus Gerlicher<klaus.gerlicher@intel.com>
2024-10-20 10:13:05 -06:00
Alan Modra
32dc367249 Report bfd_merge_sections error
PR 32260
bfd/
	* elfxx-target.h (bfd_elfNN_bfd_merge_sections): Default to
	bfd_generic_merge_sections when using the generic linker.
	* elflink.c (_bfd_elf_merge_sections): Return error from
	_bfd_merge_sections.  Abort on wrong hash table.
ld/
	* ldlang.c (lang_process): Report bfd_merge_sections error.
2024-10-20 17:15:53 +10:30
GDB Administrator
17b145510f Automatic date update in version.in 2024-10-20 00:00:20 +00:00
Tom Tromey
3fbf1a34f1 Capture the current directory and debug directory in DWARF reader
This changes the DWARF reader to capture the current working directory
and the current debug directory.  This avoids races when the DWARF
reader is working in the background.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
2024-10-19 13:18:00 -06:00