Commit Graph

120256 Commits

Author SHA1 Message Date
Jan Beulich
af3394d97a ELF: SHF_STRINGS isn't really tied to SHF_MERGE
It's not overly useful without it, but the spec doesn't name any
dependency between the two. People may want to use it for purely
informational purposes, for example. Adjust, in particular, entity size
processing to be engaged if either flag is set, as mandated by the spec.
2024-11-18 11:36:57 +01:00
Jan Beulich
70ab7e0acf ELF: SHF_MERGE vs SHT_NOBITS
bfd/merge.c puts in quite some effort to track mergable sections. That's
all wasted for sections which don't have contents, as for them
_bfd_write_merged_section() will never be called.

With the combination not having any useful effect, also warn about this
in gas.
2024-11-18 11:36:30 +01:00
Jan Beulich
d5cbf916be gas/ELF: also reject merge entity size being zero
This won't have any useful effect, so is at best marginally less bogus
than a negative value.

The change actually points out a flawed (for Arm) testcase: @ is a
comment character there.
2024-11-18 11:35:57 +01:00
Jens Remus
76445f36a2 s390: Add arch15 Concurrent-Functions Facility insns
opcodes/
	* s390-opc.txt: Add arch15 Concurrent-Functions Facility
	instructions.
	* s390-opc.c (INSTR_SSF_RRDRD2, MASK_SSF_RRDRD2): New SSF
	instruction format variant.

gas/testsuite/
	* gas/s390/zarch-arch15.d: Tests for arch15 Concurrent-Functions
	Facility instructions.
	* gas/s390/zarch-arch15.s: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-11-18 10:42:21 +01:00
Jens Remus
b0588b2173 s390: Add arch15 instruction names
opcodes/
	* s390-opc.txt: Add arch15 instruction names.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-11-18 10:42:21 +01:00
Tom de Vries
8b2ea4bcbc [gdb] Fix some typos
Run gdb/contrib/spellcheck.sh on directories gdb*.

Fix typo:
...
unkown -> unknown
...

Tested on x86_64-linux.
2024-11-18 09:46:31 +01:00
Tom de Vries
57e43f6ea5 [gdb/contrib] Add spellcheck.sh --print-dictionary
Add an option --print-dictionary to spellcheck.sh that allows us to inspect
the effective dictionary.

Verified with shellcheck.
2024-11-18 09:42:04 +01:00
Tom de Vries
92a5cfde2f [gdb/contrib] Allow thru in spellcheck.sh
Eli mentioned that "thru" is a widely-accepted shorthand [1].

Skip the "thru->through" rule by adding an overriding identity rule
"thru->thru".

Verified with shellcheck.

[1] https://sourceware.org/pipermail/gdb-patches/2024-November/213380.html
2024-11-18 09:42:03 +01:00
Sam James
a2f774427e
gprofng: fix -std=gnu23 compatibility wrt unprototyped functions
C23 removes support for unprototyped functions. Fix function pointer types
accordingly.

This does not fix all instances, there's a few left as I commented on in
PR32374 (e.g. setitimer which I have a local workaround for but it involves
a glibc implementation detail; the Linaro precommit CI tester pointed that
out too, so dropped that).

ChangeLog:
	PR gprofng/32374

	* libcollector/collector.c (collector_sample): Fix prototype.
	* libcollector/envmgmt.c (putenv): Ditto.
	(_putenv): Ditto.
	(__collector_putenv): Ditto.
	(setenv): Ditto.
	(_setenv): Ditto.
	(__collector_setenv): Ditto.
	(unsetenv): Ditto.
	(_unsetenv): Ditto.
	(__collector_unsetenv): Ditto.
	* libcollector/jprofile.c (open_experiment): Ditto.
	(__collector_jprofile_enable_synctrace): Ditto.
	(jprof_find_asyncgetcalltrace): Ditto.
	* libcollector/libcol_util.c (__collector_util_init): Ditto.
	(ARCH): Ditto.
	* libcollector/mmaptrace.c (collector_func_load): Ditto.
	(collector_func_unload): Ditto.
	* libcollector/unwind.c (__collector_ext_unwind_init): Ditto.
	* src/collector_module.h: Ditto.
2024-11-18 05:12:56 +00:00
Sam James
bf447eec6d
ld: fix -std=gnu23 compatibility wrt _Bool
GCC trunk now defaults to -std=gnu23. We return false in a few places
which can't work when true/false are a proper type (_Bool). Return NULL
where appropriate instead of false. All callers handle this appropriately.

ChangeLog:
	PR ld/32372

	* pdb.c (add_stream): Return NULL.
2024-11-18 03:09:16 +00:00
Sam James
eeff15bc88
binutils: fix -std=gnu23 compatibility wrt _Bool
GCC trunk now defaults to -std=gnu23. We return false in a few places
which can't work when true/false are a proper type (_Bool). Return NULL
where appropriate instead of false. All callers handle this appropriately.

ChangeLog:
	PR ld/32372

	* prdbg.c (visibility_name): Return NULL.
2024-11-18 03:09:15 +00:00
Sam James
8ebe62f3f0
opcodes: fix -std=gnu23 compatibility wrt static_assert
static_assert is declared in C23 so we can't reuse that identifier:
* Define our own static_assert conditionally;

* Rename "static assert" hacks to _N as we do already in some places
  to avoid a conflict.

ChangeLog:
	PR ld/32372

        * i386-gen.c (static_assert): Define conditionally.
        * mips-formats.h (MAPPED_INT): Rename identifier.
        (MAPPED_REG): Rename identifier.
        (OPTIONAL_MAPPED_REG): Rename identifier.
        * s390-opc.c (static_assert): Define conditionally.
2024-11-18 03:09:15 +00:00
Sam James
931e4f9b09
bfd: fix -std=gnu23 compatibility wrt _Bool
GCC trunk now defaults to -std=gnu23. We return false in a few places
which can't work when true/false are a proper type (_Bool). Return NULL
where appropriate instead of false. All callers handle this appropriately.

ChangeLog:
	PR ld/32372

	* elf32-ppc.c (ppc_elf_tls_setup): Return NULL.
        * elf32-xtensa.c (translate_reloc_bfd_fix): Ditto.
        (translate_reloc): Ditto.
        * elf64-ppc.c (update_local_sym_info): Ditto.
        * mach-o.c (bfd_mach_o_lookup_uuid_command): Ditto.
        * xsym.c (bfd_sym_read_name_table): Ditto.
2024-11-18 03:09:14 +00:00
GDB Administrator
5b61986ac1 Automatic date update in version.in 2024-11-18 00:00:30 +00:00
H.J. Lu
c0e7f91064 x86-64: Always check IBT PLT before BND PLT
Since BND PLT has been deprecated and the same IBT PLT is used for both
x86-64 and x32, always check IBT PLT before BND PLT when synthesizing
PLT symtab.

	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Always check
	elf_x86_64_lazy_ibt_plt and elf_x86_64_non_lazy_ibt_plt first.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-11-17 09:21:47 +08:00
Ijaz, Abdul B
9dc89f2b27 gdb: Update linkage name lookup function to allow mst_file_data/bss types.
From the commit 667ed4b14d onward, instead
of normal name GDB looks for the "jit_descriptor" linkage name in the JIT
code initialization.  Without this change, the function
"lookup_minimal_symbol_linkage", only matches the non-static data.  So in
case jit_debugger is static type then setting up breakpoint in the JIT code
fails.  Issue is seen for the intel compilers, where jit_debug_descriptor has
static type i.e. "mst_file_data".  Hence lookup_minimal_symbol_linkage returns
nullptr for it.  So, in this case breakpoint does not hit in the JIT code.
To resolve this, the commit introduces a new boolean argument to the
lookup_minimal_symbol_linkage function.  This argument allows the function to
also match mst_file_data and mst_file_bss types when set to true.  The
function is called with this new argument set to true only from JIT code
initialization handling, ensuring that the current behavior remains unchanged
for other cases.  Because handling of static types of data symbols for all cases
result in regression for "gdb.base/print-file-var.exp" test.

Example of minsym for the JIT code emitted by the intel compilers where
lookup_minimal_symbol_linkage fails without this change because jit_debugger
type is "mst_file_data".

(top-gdb) p *msymbol
$1 = {<general_symbol_info> =
{m_name = 0x7fffcc77dc95 "__jit_debug_descriptor",
m_value = {ivalue = 84325936, block = 0x506b630,
bytes = 0x506b630 <error: Cannot access memory at address 0x506b630>,
address = 0x506b630, unrel_addr = (unknown: 0x506b630),
common_block = 0x506b630, chain = 0x506b630},
language_specific = {obstack = 0x0, demangled_name = 0x0},
m_language = language_unknown, ada_mangled = 0, m_section = 29},
m_size = 24, filename = 0x55555a751b70 "JITLoaderGDB.cpp",
m_type = mst_file_data, created_by_gdb = 0,
m_target_flag_1 = 0, m_target_flag_2 = 0, m_has_size = 1,
name_set = 1, hash_next = 0x55555b86e4f0, demangled_hash_next = 0x0}

Updated the test "jit-elf-so.exp" to test the static type of jit_descriptor
object.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-17 02:02:11 +01:00
H.J. Lu
231a8ab70f x86-64: Drop x32 references in PLT entry variables
e9c11d58b9 x86-64: Remove BND from 64-bit IBT PLT

removed the BND prefix from 64-bit IBT PLT by using x32 IBT PLT.

Drop x32 references in PLT entry variables.

	* elf64-x86-64.c (elf_x86_64_lazy_ibt_plt_entry): Renamed to ...
	(elf_x86_64_lazy_bnd_ibt_plt_entry): This.
	(elf_x32_lazy_ibt_plt_entry): Renamed to ...
	(elf_x86_64_lazy_ibt_plt_entry): This.
	(elf_x86_64_non_lazy_ibt_plt_entry): Renamed to ...
	(elf_x86_64_non_lazy_bnd_ibt_plt_entry): This.
	(elf_x32_non_lazy_ibt_plt_entry): Renamed to ...
	(elf_x86_64_non_lazy_ibt_plt_entry): This.
	(elf_x86_64_eh_frame_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_eh_frame_lazy_bnd_ibt_plt): This.
	(elf_x32_eh_frame_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_eh_frame_lazy_ibt_plt): This.
	(elf_x86_64_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_lazy_bnd_ibt_plt): This.  Updated.
	(elf_x32_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_lazy_ibt_plt): This.  Updated.
	(elf_x86_64_non_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_non_lazy_bnd_ibt_plt): This.  Updated.
	(elf_x32_non_lazy_ibt_plt): Renamed to ...
	(elf_x86_64_non_lazy_ibt_plt): This.  Updated.
	(elf_x86_64_get_synthetic_symtab): Updated.
	(elf_x86_64_link_setup_gnu_properties): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-11-17 08:48:28 +08:00
GDB Administrator
ece531604d Automatic date update in version.in 2024-11-17 00:00:53 +00:00
Tom Tromey
2abed72b2c Use bool for solib::symbols_loaded
This changes solib::symbols_loaded to be of type 'bool'.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-11-16 08:45:57 -07:00
GDB Administrator
63a8afc8e9 Automatic date update in version.in 2024-11-16 00:00:41 +00:00
Barnabás Pőcze
8eba92c9e2 PR 32359, --dependency-file: wrong error message if fopen fails
Use of %E in ld error messages requires bfd_error to be set.
2024-11-16 10:07:12 +10:30
Tom de Vries
f80d7a791b [gdb/symtab] Fix segfault with dwp file
Consider the following test-case:
...
$ cat test.c
int main (void) { return 0; }
$ clang -g -gsplit-dwarf test.c -o test
$ llvm-dwp -e test -o test.dwp
...

This runs into a segmentation fault:
...
$ gdb -q -batch test
Fatal signal: Segmentation fault
...

The segmentation fault happens because in read_dwo_str_index this line sets p
to nullptr:
...
  const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer;
...
while the following code expects it to point to some data.

The section we're trying to read is:
...
(gdb) p reader->dwo_file->sections.str_offsets
$4 = {s = {section = 0xffffcc00a9d0, containing_section = 0xffffcc00a9d0},
  buffer = 0x0, size = 28, virtual_offset = 0, readin = false, is_virtual = true}
...

At first glance, the section is not readin, but actually it is.

This is a virtual section, meaning part of a containing section:
...
(gdb) p *reader->dwo_file->sections.str_offsets.s.containing_section
$8 = {s = {section = 0xffffcc00cde8, containing_section = 0xffffcc00cde8},
  buffer = 0xffffcc009650 "\030", size = 28, virtual_offset = 0, readin = true,
  is_virtual = false}
...
which is readin.

Fix this in create_dwp_v2_or_v5_section by initializing the buffer of the
virtual section using the buffer of the containing section:
...
  result.buffer = section->buffer + offset;
...

Unfortunately it's difficult to write a test-case for this.  We'll have to
teach the dwarf assembler to generate dwp files.

Tested on aarch64-linux.

This is a partial fix for PR symtab/31497.

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

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31497
2024-11-15 22:48:37 +01:00
Tom Tromey
a7d1f26ec3 Improvements to gdb.LazyString documentation
I noticed the gdb.LazyString documentation did not mention how to
create one.  Then, while adding this, I found a couple other ways that
this documentation could be clarified.

Approved-By: Eli Zaretskii <eliz@gnu.org>
2024-11-15 13:14:37 -07:00
Andrew Burgess
82eff6743b gdb/testsuite: skip gdb.opt/inline-entry.exp for gcc 7 and older
It was pointed out that the recently added gdb.opt/inline-entry.exp
test would fail when run using gcc 7 and earlier, on an x86-64 target:

  https://inbox.sourceware.org/gdb-patches/9fe35ea1-d99b-444d-bd1b-e3a1f108dd77@suse.de

Bernd Edlinger points out that, for gcc, the test relies on the
-gstatement-frontiers work which was added in gcc 8.x:

  https://inbox.sourceware.org/gdb-patches/DU2PR08MB10263357597688D9D66EA745CE4242@DU2PR08MB10263.eurprd08.prod.outlook.com

For gcc 7.x and older, without the -gstatement-frontiers work, the
compiler uses DW_AT_entry_pc differently, which leads to a poorer
debug experience.

Here is the interesting source line from inline-entry.c:

  if ((global && bar (1)) || bar (2))

And here's some of the relevant disassembly output:

  Dump of assembler code for function main:
     0x401020 <+0>:	mov    0x3006(%rip),%eax	(1)
     0x401026 <+6>:	test   %eax,%eax		(2)
     0x401028 <+8>:	mov    0x2ffe(%rip),%eax	(3)
     0x40102e <+14>:	je     0x401038 <main+24>	(4)
     0x401030 <+16>:	sub    $0x1,%eax		(5)
     0x401033 <+19>:	jne    0x40103d <main+29>	(6)

Lines (1), (2), and (4) represent the check of 'global'.  However,
line (3) is actually the first instruction for 'bar' which has been
inlined.  Lines (5) and (6) are also part of the first inlined 'bar'
function.

If the check of 'global' returns false then the first call to 'bar'
should never happen, this is accomplished by the branch at (4) being
taken.

For gcc 8+, gcc generates a DW_AT_entry_pc with the value 0x401030,
this is where GDB places a breakpoint for 'bar', and this address is
after the branch at line (4), and so, if the call to 'bar' never
happens, the breakpoint is never hit.

For gcc 7 and older, gcc generates a DW_AT_entry_pc with the value
0x401028, which is the first address associated with the inline 'bar'
function.  Unfortunately, this address is also before the check of
'global' has completed, this means that GDB hits the 'bar' breakpoint
before the inferior has decided if 'bar' should actually be called or
not.

I don't think there's really much GDB can do in the older gcc
versions, we are placing the breakpoint at the entry point, and this
is within bar.  Given that this test does really depend on the newer
gcc behaviour, I think the only sensible solution is to skip this test
when an older version of gcc is being used.

I've incorporated the check for -gstatement-frontiers support that
Bernd suggested and now the test will be skipped for older versions of
GCC.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-11-15 19:22:13 +00:00
GDB Administrator
75e1141293 Automatic date update in version.in 2024-11-15 00:00:26 +00:00
Andrew Burgess
8518ce5fc2 gdb/python: missing PyObject_IsTrue error check in bppy_init
As with the previous two commits, this commit fixes a location where
we called PyObject_IsTrue without including an error check, this time
in bppy_init.

The 'qualified' argument is supposed to be a bool, the docs say:

  The optional QUALIFIED argument is a boolean that allows
  interpreting the function passed in 'spec' as a fully-qualified
  name.  It is equivalent to 'break''s '-qualified' flag (*note
  Linespec Locations:: and *note Explicit Locations::).

It's not totally clear that the only valid values are True or False,
but I'm choosing to interpret the docs that way, and so I've added a
PyBool_Type check during argument parsing.  Now, if a non-bool is
passed the user will get a TypeError during argument parsing.  I've
added a test to cover this case.

This is a potentially breaking change to the Python API, but hopefully
this will not impact too many people.  I've added a NEWS entry to
highlight this change.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2024-11-14 19:34:44 +00:00
Andrew Burgess
ad39b4aae8 gdb/python: missing PyObject_IsTrue error check in micmdpy_set_installed
Like the previous commit, I discovered that in micmdpy_set_installed
we were calling PyObject_IsTrue, but not checking for a possible error
value being returned.

The micmdpy_set_installed function implements the
gdb.MICommand.installed attribute, and the documentation indicates that
this attribute should only be assigned a bool:

  This attribute is read-write, setting this attribute to 'False'
  will uninstall the command, removing it from the set of available
  commands.  Setting this attribute to 'True' will install the
  command for use.

So I propose that instead of using PyObject_IsTrue we use
PyBool_Check, and if the new value fails this check we raise an
error.  We can then compare the new value to Py_True directly instead
of calling PyObject_IsTrue.

This is a potentially breaking change to the Python API, but hopefully
this will not impact too many people, and the fix is pretty
easy (switch to using a bool).  I've added a NEWS entry to draw
attention to this change.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-14 19:34:44 +00:00
Andrew Burgess
5209b83f53 gdb/python: missing PyObject_IsTrue error check in py-arch.c
Building on the previous two commits, I was auditing our uses of
PyObject_IsTrue looking for places where we were missing an error
check.

The gdb.Architecture.integer_type() function takes a 'signed' argument
which should be a 'bool', and the docs do say:

  If SIGNED is not specified, it defaults to 'True'.  If SIGNED is
  'False', the returned type will be unsigned.

Currently we use PyObject_IsTrue, but we are missing an error check.

To fix this I've tightened the code to enforce the bool requirement at
the point that the arguments are parsed.  With that done I can remove
the call to PyObject_IsTrue and instead compare to Py_True directly,
the object in question will always be a PyBool_Type.

However, we were testing that passing a non-bool argument for 'signed'
is treated as Py_False, this was added with this commit:

  commit 90fe61ced1
  Date:   Mon Nov 29 13:53:06 2021 +0000

      gdb/python: don't use the 'p' format for parsing args

which is when the PyObject_IsTrue call was added.  Given that the docs
do seem pretty clear that only True or False are suitable argument
values, my proposal is that we just remove these tests and instead
test that any non-bool argument value for 'signed' gives a TypeError.

This is a breaking change to the Python API, however, my hope is that
this is such a edge case that it will not cause too many problem.
I've added a NEWS entry to highlight this change though.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2024-11-14 19:34:43 +00:00
Andrew Burgess
d8a2c719da gdb/python: remove some additional PyObject_IsTrue calls
After the previous commit I audited all our uses of PyObject_IsTrue
looking for places where we were missing an error check.  I did find
some that are missing error checks in places where we really should
have error checks, and I'll fix those in later commits.

This commit however, focuses on those locations where PyObject_IsTrue
is called, there is no error check, and the error check isn't really
necessary because we already know that the object we are dealing with
is of type PyBool_Type.

Inline with the previous commit, in these cases I have removed the
PyObject_IsTrue call, and replaced it with a comparison against
Py_True.  In one location where it is not obvious that the object we
have is PyBool_Type I've added an assert, but in the other cases the
comparison to Py_True immediately follows a PyBool_Check call, so an
assert would be redundant.

I've added a test for the gdb.Value.format_string styling argument
being passed a non-bool value as this wasn't previously being tested,
though this new test will pass before and after this commit.

There should be no functional change after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-14 19:34:43 +00:00
Andrew Burgess
dcf4c48453 gdb/python: remove PyObject_IsTrue call in gdbpy_handle_missing_debuginfo
In this review:

  https://inbox.sourceware.org/gdb-patches/87wmirfzih.fsf@tromey.com

Tom pointed out that using PyObject_IsTrue as I was doing, though
technically fine, at least appears to be missing an error check, and
that it would be better to compare to Py_True directly.  I made that
change in the patch Tom was commenting on, but I'd actually copied
that code from elsewhere in python/python.c, so this commit updates
the original code inline with Tom's review feedback.

There should be no functional change after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-14 19:34:43 +00:00
GDB Administrator
768f23b94f Automatic date update in version.in 2024-11-14 00:00:31 +00:00
Tom de Vries
580f291cb8 [gdb/tdep] Handle syscall clock_gettime64 for arm-linux
When running test-case gdb.reverse/time-reverse.exp on arm-linux, I run into:
...
(gdb) continue^M
Continuing.^M
Process record and replay target doesn't support syscall number 403^M
Process record does not support instruction 0xdf00 at address 0xf7ebf774.^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0xf7ebf774 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6^M
(gdb) FAIL: $exp: mode=c: continue to breakpoint: marker2
...

Syscall number 403 stands for clock_gettime64 on arm-linux.

Fix this by handling 403 in arm_canonicalize_syscall, and handling
gdb_sys_clock_gettime64 elsewhere.

Since i386_canonicalize_syscall is the identity function, enum value
gdb_sys_clock_gettime64 gets a value to match i386, which also happens to be
403.

Tested on arm-linux.

Approved-By: Guinevere Larsen <guinevere@redhat.com> (record-full)
2024-11-13 22:41:35 +01:00
Tom de Vries
5cb0406bb6 [gdb/contrib] Handle capitalized words in spellcheck.sh
The dictionary contains a few entries with capital letters:
...
$ grep -E '[A-Z]' .git/wikipedia-common-misspellings.txt | wc -l
143
...
but they don't look too interesting in the gdb context (for instance,
Habsbourg->Habsburg), so filter them out.

That leaves us with entries looking only like "foobat->foobar", so add
handling of capitalized words, such that we also rewrite "Foobat" to "Foobar".

Tested on aarch64-linux.  Verified with shellcheck.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-11-13 22:38:19 +01:00
Tom de Vries
74b9033e6f [gdb/contrib] Add "doens't->doesn't" to common-misspellings.txt
Add "doens't->doesn't" to gdb/contrib/common-misspellings.txt, and run
gdb/contrib/spellcheck.sh to fix this in a few files.

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-11-13 21:06:58 +01:00
Tom de Vries
ee126995f5 [gdb/contrib] Handle double quotes in spellcheck.sh
Add handling of double quotes in gdb/contrib/spellcheck.sh, and fix the
following typos:
...
inheritence -> inheritance
psuedo -> pseudo
succeded -> succeeded
...

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-11-13 21:06:58 +01:00
Tom de Vries
0d1f7e2765 [gdb/contrib] Handle parentheses in spellcheck.sh
Currently, text adjacent to parentheses is not spell-checked:
...
$ cat tmp.txt
(upto)
$ ./gdb/contrib/spellcheck.sh tmp.txt
$
...

Add handling of parentheses, such that we get:
...
$ ./gdb/contrib/spellcheck.sh tmp.txt
upto -> up to
$
...

Rerun spellcheck.sh, resulting in a few "thru->through" replacements.

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-11-13 21:06:58 +01:00
Tom de Vries
e2fa415cfd [precommit] Add some documentation in .pre-commit-config.yaml
Add some documention to .pre-commit-config.yaml that explains:
- what the file is,
- how it can be used, and
- how to skip specific hooks in case of trouble.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-13 21:03:42 +01:00
Tom de Vries
6e4577fc29 [gdb/tdep] Fix recording of T1 push
When running test-case gdb.reverse/recursion.exp on arm-linux with target
board unix/-mthumb, I run into:
...
(gdb) PASS: gdb.reverse/recursion.exp: Skipping recursion from inside
reverse-next^M
bar (x=4195569) at /home/linux/gdb/src/gdb/testsuite/gdb.reverse/recursion.c:34^M
34        int r = foo (x);^M
(gdb) FAIL: gdb.reverse/recursion.exp: print frame when stepping out
...

The problem is the recording of the T1 push instruction [1,2], specifically:
...
000004d8 <foo>:
 4d8:   b580            push    {r7, lr}
...

The current code fails to add a memory record for the memory written with the
value of the lr register.

Fix this by adding the missing memory record.

Tested on arm-linux.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Luis Machado <luis.machado@arm.com>

[1] https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Instruction-Details/Encoding-of-lists-of-ARM-core-registers
[2] https://developer.arm.com/documentation/ddi0597/2024-09/T32-Instructions-by-Encoding/16-bit?lang=en#pushpop16
2024-11-13 19:44:21 +01:00
Tom de Vries
76b9b6eb9c [gdb/tdep] Handle sycall statx for arm-linux
When running test-case gdb.reverse/fstatat-reverse.exp on arm-linux, I run
into:
...
(gdb) continue^M
Continuing.^M
Process record and replay target doesn't support syscall number 397^M
Process record does not support instruction 0xdf00 at address 0xf7ebf774.^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0xf7ebf774 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6^M
(gdb) FAIL: gdb.reverse/fstatat-reverse.exp: continue to breakpoint: marker2
...

Syscall number 397 stands for statx on arm-linux.

Fix this by handling 397 in arm_canonicalize_syscall.

Tested on arm-linux.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Luis Machado <luis.machado@arm.com>
2024-11-13 19:37:04 +01:00
Bernd Edlinger
5d9887ffa2 gdb: stepping between inline functions with multiple ranges
I (Andrew) have split this small change from a larger patch which was
posted here:

  https://inbox.sourceware.org/gdb-patches/AS1PR01MB9465608EBD5D62642C51C428E4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com

And I have written the stand alone test for this issue.  The original
patch included this paragraph to explain this change (I've fixed one
typo in this text replacing 'program' with 'function'):

  ... it may happen that the infrun machinery steps from one inline
  range to another inline range of the same inline function.  That can
  look like jumping back and forth from the calling function to the
  inline function, while really the inline function just jumps from a
  hot to a cold section of the code, i.e. error handling.

The important thing that happens here is that both the outer function
and the inline function must both have multiple ranges.  When the
inferior is within the inline function and moves from one range to
another it is critical that the address we stop at is the start of a
range in both the outer function and the inline function.

The diagram below represents how the functions are split and aligned:

                           (A)       (B)
  bar:         |------------|         |---|
  foo:   |------------------|         |--------|

The inferior is stepping through 'bar' and eventually reaches
point (A) at which point control passes to point (B).

Currently, when the inferior stops, GDB notices that both 'foo' and
'bar' start at address (B), and so GDB uses the inline frame mechanism
to skip 'bar' and tells the user that the inferior is in 'foo'.

However, as we were in 'bar' before the step then it makes sense that
we should be in 'bar' after the step, and this is what the patch does.

There are two tests using the DWARF assembler, the first checks the
above situation and ensures that GDB reports 'bar' after the step.

The second test is similar, but after the step we enter a new range
where a different inline function starts, something like this:

                           (A)       (B)
  bar:         |------------|
  baz:                                |---|
  foo:   |------------------|         |--------|

In this case as we step at (A) and land at (B) we leave 'bar' and
expect to stop in 'foo', GDB shouldn't automatically enter 'baz' as
that is a completely different inline function.  And this is, indeed,
what we see.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2024-11-13 13:50:21 +00:00
Andrew Burgess
b9de07a5ff gdb: fix handling of DW_AT_entry_pc of inlined subroutines
The entry PC for a DIE, e.g. an inline function, might not be the base
address of the DIE.  Currently though, in block::entry_pc(), GDB
always returns the base address (low-pc or the first address of the
first range) as the entry PC.

This commit extends the block class to carry the entry PC as a
separate member variable.  Then the DWARF reader is extended to read
and set the entry PC for the block.  Now in block::entry_pc(), if the
entry PC has been set, this is the value returned.

If the entry-pc has not been set to a specific value then the old
behaviour of block::entry_pc() remains, GDB will use the block's base
address.  Not every DIE will set the entry-pc, but GDB still needs to
have an entry-pc for every block, so the existing logic supplies the
entry-pc for any block where the entry-pc was not set.

The DWARF-5 spec for reading the entry PC is a super-set of the spec
as found in DWARF-4.  For example, if there is no DW_AT_entry_pc then
DWARF-4 says to use DW_AT_low_pc while DWARF-5 says to use the base
address, which is DW_AT_low_pc or the first address in the first range
specified by DW_AT_ranges if there is no DW_AT_low_pc.

I have taken the approach of just implementing the DWARF-5 spec for
everyone.  There doesn't seem to be any benefit to deliberately
ignoring a ranges based entry PC value for DWARF-4.  If some naughty
compiler has emitted that, then lets use it.

Similarly, DWARF-4 says that DW_AT_entry_pc is an address.  DWARF-5
allows an address or a constant, where the constant is an offset from
the base address.  I allow both approaches for all DWARF versions.
There doesn't seem to be any downsides to this approach.

I ran into an issue when testing this patch where GCC would have the
DW_AT_entry_pc point to an empty range.  When GDB parses the ranges
any empty ranges are ignored.  As a consequence, the entry-pc appears
to be outside the address range of a block.

The empty range problem is certainly something that we can, and should
address, but that is not the focus of this patch, so for now I'm
ignoring that problem.  What I have done is added a check: if the
DW_AT_entry_pc is outside the range of a block then the entry-pc is
ignored, GDB will then fall-back to its default algorithm for
computing the entry-pc.

If/when in the future we address the empty range problem, these
DW_AT_entry_pc attributes will suddenly become valid and GDB will
start using them.  Until then, GDB continues to operate as it always
has.

An early version of this patch stored the entry-pc within the block
like this:

  std::optional<CORE_ADDR> m_entry_pc;

However, a concern was raised that this, on a 64-bit host, effectively
increases the size of block by 16-bytes (8-bytes for the CORE_ADDR,
and 8-bytes for the std::optional's bool plus padding).

If we remove the std::optional part and just use a CORE_ADDR then we
need to have a "special" address to indicate if m_entry_pc is in use
or not.  I don't really like using special addresses; different
targets can access different address ranges, even zero is a valid
address on some targets.

However, Bernd Edlinger suggested storing the entry-pc as an offset,
and I think that will resolve my concerns.  So, we store the entry-pc
as a signed offset from the block's base address (the first address of
the first range, or the start() address value if there are now
ranges).  Remember, ranges can be out of order, in which case the
first address of the first range might be greater than the entry-pc.

When GDB needs to read the entry-pc we can add the offset onto the
blocks base address to recalculate it.

With this done, on a 64-bit host, block only needs to increase by
8-bytes.

The inline-entry.exp test was originally contributed by Bernd here:

  https://inbox.sourceware.org/gdb-patches/AS1PR01MB94659E4D9B3F4A6006CC605FE4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com

though I have made some edits, making more use of lib/gdb.exp
functions, making the gdb_test output patterns a little tighter, and
updating the test to run with Clang.  I also moved the test to
gdb.opt/ as that seemed like a better home for it.

Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
2024-11-13 13:41:27 +00:00
Mark Harmstone
b3aa594daa gas: add .cv_ucomp and .cv_scomp pseudo-directives
Add .cv_ucomp and .cv_scomp pseudo-directives for object files for
Windows targets, which encode compressed CodeView integers according to
the algorithm in CVCompressData in
https://github.com/Microsoft/microsoft-pdb/blob/master/include/cvinfo.h.
This is essentially Microsoft's answer to the LEB128, though used in far
fewer places.

CodeView uses these to encode the "binary annotations" in the
S_INLINESITE symbol, which express the relationship between code offsets
and line numbers in inlined functions. This has to be done in the
assembler as GCC doesn't know how many bytes each instruction takes up.
There's no equivalent for this for MSVC or LLVM, as in both cases the
assembler and compiler are integrated.

.cv_ucomp represents an unsigned big-endian integer between 0 and 0x1fffffff,
taking up 1, 2, or 4 bytes:

Value between 0 and 0x7f:

	0aaaaaaa -> 0aaaaaaa (identity-mapped)

Value between 0x80 and 0x3fff:

	00aaaaaa bbbbbbbb -> 10aaaaaa bbbbbbbb

Value between 0x4000 and 0x1fffffff:
	000aaaaa bbbbbbbb ccccccccc dddddddd ->
	110aaaaa bbbbbbbb ccccccccc dddddddd

.cv_scomp represents a signed big-endian integer between -0xfffffff and
0xfffffff, encoded according to EncodeSignedInt32 in cvinfo.h. The
absolute value of the integer is shifted left one bit, the LSB set
for a negative value, and the result expressed as if it were a
.cv_ucomp: cv_scomp(x) = cv_ucomp((abs(x) << 1) | (x < 0 ? 1 : 0))
2024-11-13 03:11:35 +00:00
GDB Administrator
2e7d431af8 Automatic date update in version.in 2024-11-13 00:00:15 +00:00
Mark Wielaard
14bc3b1b83 bfd: Add WARN_CFLAGS_FOR_BUILD to doc/chew.c build, fix warnings
doc/chew.c was compiled without any warning flags set. Adding the
common warnings for build showed various issues with non-static
functions missing prototypes and globals with common names (ptr and
idx) that shadowed local arguments or variables.

     * doc/local.mk (doc/chew.stamp): Add WARN_CFLAGS_FOR_BUILD.
     * Makefile.in: Regenerate.
     * doc/chew.c (idx): Rename to pos_idx.
     (ptr): Rename to buf_ptr.
     (xmalloc): Make static.
     (xrealloc): Likewise.
     (xstrdup): Likewise.
     (nextword): Likewise.
     (newentry): Likewise.
     (add_to_definition): Likewise.
     (add_intrinsic): Likewise.
     (compile): Likewise.
     (icopy_past_newline): Rename idx to pos_idx, ptr to buf_ptr.
     (get_stuff_in_command): Likewise.
     (skip_past_newline): Likewise.
     (perform): Likewise.
     (main): Likewise.
2024-11-12 22:39:33 +01:00
Andrew Burgess
06b8b0ad97 gdb/testsuite: some cleanups in gdb.base/annota{1,3}.exp tests
Fedora GDB has, for years, carried an out of tree patch for the
gdb.base/annota{1,3}.exp tests.  The patch simply adds a call to 'set
breakpoint pending off' near the start of each test.

Normally GDB tests are written using gdb_test or gdb_test_multiple,
with gdb_test being a wrapper around gdb_test_multiple.  Inside
gdb_test_multiple we add a test pattern which detects if GDB offers
the user an interactive yes/no prompt and immediately fails the test.

What this means is that if something goes wrong with a test like:

  gdb_test "break main" ".*"

and GDB ends up offering this prompt:

  Make breakpoint pending on future shared library load? (y or [n])

then instead of hanging waiting for the test to timeout, DejaGNU will
spot the interactive prompt and immediately fail the test.

In the gdb.base/annota{1,3}.exp tests we turn on GDB's annotation
mode, and many of the tests in these scripts are written using
send_gdb and gdb_expect or gdb_expect_list.  This is done because in
the past, gdb_test_multiple and friends were hard-coded to use the
"normal" GDB prompt, and these tests instead expect the annotated
prompt.  Specifically, gdb_test_multiple expects '$gdb_prompt $' as
the full prompt, that is the value of $gdb_prompt followed by a single
white space.  The annotation tests do update the value of $gdb_prompt,
but with annotations on there is no trailing whitespace, so
gdb_test_multiple's default behaviour doesn't work, which is why the
test scripts originally avoided using gdb_test_multiple.

As a result none of the tests in these files would early exit if we
got an interactive yes/no prompt, and instead we'd be relying on each
test to timeout, which could take a while.

However, gdb_test_multiple now accepts a -prompt argument, so we can
modify the prompt we are looking for, which is neat.

So, I started off by going through these tests an changing all of the
tests that create a breakpoint to use gdb_test, passing the -prompt
option to change the prompt.

While doing that I noticed some other things that I could improve in
these tests, I've cleaned up the use of standard_testfile, switched to
use prepare_for_testing, and removed some redundant clean_restart and
'set height 0' calls (set height 0 is done within clean_restart, which
is called by prepare_for_testing).

I've updated some comments which said "we can't use gdb_test" to say
"we can use gdb_test with -prompt option", and I've removed some
commented out debug code (e.g. setting 'exp_internal').

Finally, I ran these two tests through check-all-boards, and spotted
that annota1.exp failed when using a remote host.  This is because one
test checks for a full path to the binary in some output, and with a
remote host the binary ends up being copied and the path is not as
expected.

I'm assuming that checking the full path is important, so I've
disabled this test on remote host boards.

After all these changes I checked using 'make check-all-boards' and
there are no unexpected results on either of these tests.

Tested-By: Tom de Vries <tdevries@suse.de>
Acked-By: Tom de Vries <tdevries@suse.de>
2024-11-12 14:41:23 +00:00
Andrew Burgess
26885b2b6c gdb/testsuite: fix duplicate test names in gdb.trace/
After this commit:

  commit 35f09cd5d7
  Date:   Wed Jul 31 15:04:25 2024 +0200

      [gdb/testsuite] Detect trailing-text-in-parentheses duplicates

we are now seeing some duplicate test names in gdb.trace/ tests when
using native-gdbserver or native-extended-gdbserver boards.  This is
all due to tests that use some text in trailing parenthesis to make
the test name unique.

I've gone through and edited the test names as best I could to make
them all unique.  Hopefully the updated test names should all make
sense.

On my machine I'm no longer seeing any duplicates with either of the
boards listed above.

Acked-By: Tom de Vries <tdevries@suse.de>
2024-11-12 14:35:38 +00:00
Andrew Burgess
31fa6221bf gdb/readline: don't get stuck thinking an EOF arrived
It was brought to my attention[1] that if a user makes use of Ctrl+d
to quit from a secondary prompt (e.g. the prompt used to enter lines
for the 'commands' command) then GDB will start displaying some
unexpected blank lines.  Here's an example:

  Reading symbols from /tmp/hello.x...
  (gdb) break main
  Breakpoint 1 at 0x401198: file hello.c, line 18.
  (gdb) commands
  Type commands for breakpoint(s) 1, one per line.
  End with a line saying just "end".
  >quit			# <----------- Use Ctrl+d to quit here.
  (gdb) show architecture
			# <----------- This blank line is unexpected.
  The target architecture is set to "auto" (currently "i386:x86-64").
  (gdb)

I've marked up where I press 'Ctrl+d', and also the unexpected blank
line.

This issue will only happen if bracketed-paste-mode is in use.  If
this has been disabled (e.g. in ~/.inputrc) then this issue will not
occur.

The blank line is not just emitted for the 'show architecture'
command.  The blank line is actually caused by an extra '\n' character
emitted by readline after it has gathered a complete line of input,
and so will occur for any command.

The problem is caused by readline getting "stuck" in a state where it
thinks that an EOF has just been delivered.  This state is set when
the 'Ctrl+d' does deliver an EOF, but then this state is never fully
reset.  As a result, every time readline completes a line, it thinks
that the line was completed due to an EOF and so adds an extra '\n'
character.

Obviously the real fix for this issue is to patch readline, and I do
have a patch for that[2], however, version 8.2 of readline has been
released, and contains this issue.  As such, if GDB is linked against
the system readline, and that system readline is 8.2, then we can
expect to see this issue.

There's a pretty simple, and cheap workaround that we can add to GDB
that will mitigate this issue.

I propose that we add this workaround to GDB.  If/when the readline
patch is accepted then I'll back-port this to our local readline copy,
but retaining the workaround will be harmless, and will make GDB play
nicer with system readline libraries (version 8.2).

[1] https://inbox.sourceware.org/gdb-patches/34ef5438-8644-44cd-8537-5068e0e5e434@redhat.com
[2] https://lists.gnu.org/archive/html/bug-readline/2024-10/msg00014.html

Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-11-12 14:07:35 +00:00
Andrew Burgess
b0c6153ccf gdb/readline: add readline library version to 'show configuration'
When debugging readline issues I'd like an easy way to know (for sure)
what version of readline GDB is using.  This could also be useful when
writing readline tests, knowing the precise readline version will
allow us to know if we expect a test to pass or not.

Add the readline library version to the output of the 'show
configuration' command.  Also include a suffix indicating if we are
using the system readline, or the statically linked in readline.

The information about static readline vs shared readline can be
figured out from the configure command output, but having it repeated
in the readline version line makes it super easy to grok within tests,
and it's super cheap, so I don't see this as a problem.
2024-11-12 13:58:19 +00:00
Andrew Burgess
1048062a3f gdbserver: pass osabi to GDB in more target descriptions
Problem Description
-------------------

On a Windows machine I built gdbserver, configured for the target
'x86_64-w64-mingw32', then on a GNU/Linux machine I built GDB with
support for all target (--enable-targets=all).

On the Windows machine I start gdbserver with a small test binary:

  $ gdbserver 192.168.129.25:54321 C:\some\directory\executable.exe

On the GNU/Linux machine I start GDB without the test binary, and
connect to gdbserver.

As I have not given GDB the test binary, my expectation is that GDB
would connect to gdbserver and then download the file over the remote
protocol, but instead I was presented with this message:

  (gdb) target remote 192.168.129.25:54321
  Remote debugging using 192.168.129.25:54321
  warning: C:\some\directory\executable.exe: No such file or directory.
  0x00007ffa3e1e1741 in ?? ()
  (gdb)

What I found is that if I told GDB where to find the binary, like
this:

  (gdb) file target:C:/some/directory/executable.exe
  A program is being debugged already.
  Are you sure you want to change the file? (y or n) y
  Reading C:/some/directory/executable.exe from remote target...
  warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
  Reading C:/some/directory/executable.exe from remote target...
  Reading symbols from target:C:/some/directory/executable.exe...
  (gdb)

then GDB would download the executable.

The Actual Issue
----------------

I tracked the problem down to exec_file_find (solib.c).  The remote
target was passing an absolute Windows filename (beginning with "C:/"
in this case), but in exec_file_find GDB was failing the
IS_TARGET_ABSOLUTE_PATH call, and so was treating the filename as
relative.

The IS_TARGET_ABSOLUTE_PATH call was failing because GDB thought that
the file system kind was "unix", and as the filename didn't start with
a "/" it assumed the filename was not absolute.

But I'm connecting to a Windows target and 'target-file-system-kind'
was set to "auto", so GDB should be figuring out that the target
file-system is "dos-based".

Looking in effective_target_file_system_kind (filesystem.c), we find
that the logic of "auto" is delegated to the current gdbarch.  However
in windows-tdep.c we see:

  set_gdbarch_has_dos_based_file_system (gdbarch, 1);

So if we are using a Windows gdbarch we should have "dos-based"
filesystems.  What this means is that after connecting to the remote
target GDB has selected the wrong gdbarch.

What's happening is that the target description sent back by the
remote target only includes the x86-64 registers.  There's no
information about which OS we're on.  As a consequence, GDB picks the
first x86-64 gdbarch which can handle the provided register set, which
happens to be a GNU/Linux gdbarch.

And indeed, there doesn't appear to be anywhere in gdbserver that sets
the osabi on the target descriptions. Some target descriptions do have
their osabi set when the description is created, e.g. in:

  gdb/arch/amd64.c	- Sets GNU/Linux osabi when appropriate.
  gdb/arch/i386.c	- Likewise.
  gdb/arch/tic6x.c	- Always set GNU/Linux osabi.

There are also some cases in gdb/features/*.c where the tdesc is set,
but these locations are only called from GDB, not from gdbserver.

This means that many target descriptions are created without an osabi,
gdbserver does nothing to fix this, and the description is returned to
GDB without an osabi included.  This leaves GDB having to guess what
the target osabi is, and in some cases, GDB can get this wrong.

Proposed Solution
-----------------

I propose to change init_target_desc so that it requires an gdb_osabi
to be passed in, this will then be used to set the target_desc osabi
field.

I believe that within gdbserver init_target_desc is called for every
target_desc, so this should mean that every target_desc has an
opportunity to set the osabi to something sane.

I did consider passing the osabi into the code which creates the
target_desc objects, but that would require updating far more code, as
each target has its own code for creating target descriptions.
The approach taken here requires minimal changes and forces every
user of init_target_desc to think about what the correct osabi is.

In some cases, e.g. amd64, where the osabi is already set when the
target_desc is created, the init_target_desc call will override the
current value, however, we should always be replacing it with the same
actual value.  i.e. if the target_desc is created with the osabi set
to GNU/Linux, then this should only happen when gdbserver is built for
GNU/Linux, in which case the init_target_desc should also be setting
the osabi to GNU/Linux.

The Tricky Bits
---------------

Some targets, like amd64, use a features based approach for creating
target_desc objects, there's a function in arch/amd64.c which creates
a target_desc, adds features too it, and returns the new target_desc.
This target_desc is then passed to an init_target_desc call within
gdbserver.  This is the easy case to handle.

Then there are other targets which instead have a fixed set of xml
files, each of which is converted into a .dat file, which is then used
to generate a .cc file, which is compiled into gdbserver.  The
generated .cc file creates the target_desc object and calls
init_target_desc on it.  In this case though the target description
that is sent to GDB isn't generated from the target_desc object, but
is instead the contents of the fixed xml file.  For this case the
osabi which we pass to init_target_desc should match the osabi that
exists in the fixed xml file.

Luckily, in the previous commit I copied the osabi information from
the fixed xml files into the .dat files.  So in this commit I have
extended regdat.sh to read the osabi from the .dat file and use it in
the generated init_target_desc call.

The problem with some of these .dat base targets is that their fixed
xml files don't currently contain any osabi information, and the file
names don't indicate that they are Linux only (despite them currently
only being used from gdbserver for Linux targets), so I don't
currently feel confident adding any osabi information to these files.
An example would be features/rs6000/powerpc-64.xml.  For now I've just
ignored these cases.  The init_target_desc will use GDB_OSABI_UNKNOWN
which is the default.  This means that for these targets nothing
changes from the current behaviour.  But many other targets do now
pass the osabi back.  Targets that do pass the osabi back are
improved with this commit.

Conclusion
----------

Now when I connect to the Windows remote the target description
returned includes the osabi name.  With this extra information GDB
selects the correct gdbarch object, which means that GDB understands
the target has a "dos-based" file-system.  With that correct GDB
understands that the filename it was given is absolute, and so fetches
the file from the remote as we'd like.

Reviewed-By: Kevin Buettner <kevinb@redhat.com>
2024-11-12 12:51:36 +00:00
Andrew Burgess
06e9986d02 gdb/regformats: add osabi information to generated .dat files
Some gdbserver targets generate their target description based on the
gdb/regformats/*.dat files.  These .dat files are generated from a
matching xml file in gdb/features/.

Lets consider a concrete example:

Take gdb/features/or1k-linux.xml, this file is processed by
gdb/features/Makefile to create gdb/regformats/or1k-linux.dat.

When gdbserver is built for the or1k target the file
or1k-linux-generated.cc is generated using the
gdb/regformats/regdat.sh script.  This .cc file is then compiled and
linked into gdbserver.

The or1k-linux-generated.cc file contains the function
init_registers_or1k_linux which is called from within gdbserver, this
function creates a target_desc object and sets its xmltarget field to
a fixed string.  This fixed string is the xml filename that was
originally used to generate the xml file, in this case or1k-linux.xml.

Additionally, as part of the gdbserver build the file or1k-linux.xml
is converted to a string and placed in the file
xml-builtin-generated.cc which is then built into gdbserver.

Now when GDB asks gdbserver for the target description, gdbserver
returns the fixed xmltarget string, which is the name of an xml file.
GDB will then ask gdbserver for that file and gdbserver will return
the contents of that file thanks to the xml-builtin-generated.cc
file's contents.

This is all rather complicated, but it does work.  So what's the
problem that I'm fixing?

Well or1k-linux.xml does contain the osabi information, so this will
be returned from gdbserver to GDB.  That's good.

However, the target_desc object created in init_registers_or1k_linux
will not have its osabi set correctly.

Now this doesn't really matter too much except
init_registers_or1k_linux includes a call to init_target_desc.

In the next commit I want to extend init_target_desc to require an
osabi to be passed in.  The motivation for this will be explained in
the next commit, but if we accept for a moment that this is something
that should be done, then the question is what osabi should we use in
init_registers_or1k_linux?

Ideally we'd use the osabi which is set in or1k-linux.xml.  If we do
that then everything will remain consistent, which is a good thing.

And so, to get the osabi from or1k-linux.xml into
init_registers_or1k_linux, we first need to get the osabi information
into or1k-linux.dat file, and this is what this commit does.

I've added a new xsl script print-osabi.xsl and updated
gdb/features/Makefile to make use of this script.  Then I regenerated
all of the .dat files.  Now every .dat file contains either:

  osabi:GNU/Linux
  osabi:unknown

The first is for xml files containing <osabi>GNU/Linux</osabi> and the
second is for xml files that don't contain an osabi element.

This commit doesn't attempt to make use of the osabi information in
the .dat files, that will come in the next commit.  There should be no
user visible changes after this commit.

Approved-By: Kevin Buettner <kevinb@redhat.com>
2024-11-12 12:51:36 +00:00