This changes the compunit_symtab iterator to return references rather
than pointers, following the style of some other recent changes.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Now that compunit_symtab can have a destructor, it can use
std::unique_ptr rather than an explicit 'delete'.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
This patch changes compunit_symtab to be allocated on the heap, using
'new'. It also changes the container that holds these in the objfile.
I chose to use an intrusive_list to store compunit_symtab because I
think pointer stability is needed here.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33435
Approved-By: Simon Marchi <simon.marchi@efficios.com>
All 2 callers of this overload pass NULL. Remove the parameter and pass
nullptr explicitly to find_function_start_sal_1.
Change-Id: Ie20e7c8ad980cd7af99b6ba9c23f4da19febc1bc
While working on new Python API to create new function types I realized
that there's no easy way to create a new function type and control where
it is going to be allocated (whether in gdbarch's obstack or objfile's).
Functions lookup_function_type and lookup_function_type_with_arguments
always allocate at the same obstack as its return type.
This is not sufficient for the new Python API - the user may use any
type it can get hold of. For example, one may want to create a function
returning arch-owned type and taking one argument of objfile-owned type.
In that case we need to allocate the new type on that very objfile's
obstack.
This commit introduces new function - create_function_type - that takes
type_allocator as first parameter, allowing caller to control the
allocation. Existing functions (lookup_function_type and
lookup_function_type_with_arguments) are reimplemented by means of new
create_function_type.
Approved-By: Tom Tromey <tom@tromey.com>
... and const. There's no reason to have the compiler copy an anonymous
.rodata object onto the stack. And there's also no reason to allow the
array to be modifiable.
While in the common case sections like .reloc don't need to be accessed
by a binary (that's the job of the loader), there are rare cases where
the situation is different. Unconditionally forcing the discardable flag
is therefore unhelpful. Avoid doing so when SEC_ALLOC is set, which
would in particular be the case when .reloc isn't (solely) linker-
generated.
While adjusting the comment, drop the wrong (stale?) following sentence:
.rsrc, as per its table entry, doesn't need to be writable. And
commenting on it wanting to be readable would then need to be repeated
for all other sections as well.
Without SEC_READONLY, even the default .text section would end up with
the IMAGE_SCN_MEM_WRITE flag, which is clearly wrong. (Afaict the flag,
oddly enough, doesn't affect the final linked binary, so there likely
are more anomalies.)
However, as suggested by Richard Earnshaw, PE's requirements are really
target independent. Consolidate SEC_CODE, SEC_DATA, SEC_READONLY,
SEC_LINK_ONCE, and SEC_LINK_DUPLICATES into target-independent code. Yet
of course targets not using CREATE_*_COFF_TARGET_VEC() won't benefit.
Note that in coff-arm.c the EXTRA_S_FLAGS conditional was also stale
(leftover from EPOC removal), and hence can go away.
This is once again just so the target won't need excluding in a
forthcoming new testcase, which requires no padding at the end of at
least some of the sections.
Even when !DLL_SUPPORT, an executable may still want to have base
relocations created. Avoid doing so by default, though, to not alter
prior behavior.
With this, an xfail can (and actually should) go away (or else we end up
with an XPASS).
M*Core uses pe-dll.c, but has no entry in the table. Add both big and
little endian ones. Many of the entries aren't relevant when targeting
PE+; move the #endif accordingly. The MIPS entry is actually
questionable altogether: No mips*-*-* target uses pe-dll.c or pep-dll.c.
As I lack sufficient knowledge of the target, introduction of
jmp_mcore_bytes[] will need to be handled by someone else.
This is just so the target won't need excluding in a forthcoming new
testcase. Without doing so objdump would fail saying "option -P/--private
not supported by this file".
_bfd_XXi_swap_scnhdr_out() will want to use the section's flags. Some
call sites don't have a BFD section available, and hence pass NULL. Code
using the parameter will therefore need to apply appropriate care.
Before teaching _bfd_XXi_swap_scnhdr_out() to respect SEC_ALLOC when
considering whether to force IMAGE_SCN_MEM_DISCARDABLE for a section,
make sure we won't "invert" present wrong behavior when transforming an
incoming object's section attributes to an outgoing one's (objcopy or
"ld -r"): Right now, IMAGE_SCN_MEM_DISCARDABLE would appear out of the
blue for certain sections. We don't want the opposite, though, i.e. we
want avoid silently dropping IMAGE_SCN_MEM_DISCARDABLE when it's present
for an incoming object's section.
In line with bfd's styp_to_sec_flags(), set SEC_ALLOC for code/data
sections. Tie the setting to SEC_LOAD, not avoid inadvertently producing
a .bss-like section.
Both really want to be SEC_DATA, even if _bfd_XXi_swap_scnhdr_out()
makes sure that IMAGE_SCN_CNT_INITIALIZED_DATA is set in the final
section header. Otoh, .reloc - being IMAGE_SCN_MEM_DISCARDABLE at least
by default - shouldn't have SEC_ALLOC set.
In an early form of the patch I also dropped SEC_ALLOC for .reloc. While
I've undone that, I think the then necessary testsuite adjustments still
want retaining:
1) I can't explain why the removal of _both_ SEC_ALLOC and SEC_LOAD for
.reloc causes ld-scripts/provide-8 to XPASS on PE targets. Placing a
symbol outside of the image isn't well-defined in PE anyway though, so
convert the xfail-s to notarget-s.
2) The ld-pe/pe-aarch64 fragility is now dealt with in a separate patch.
Recently AIX internal CI is broken.
The error is as follows:
--------------------------------
aix-thread.c: In function 'void sync_threadlists(pid_t)':
aix-thread.c:857:53: error: cannot convert 'thread_info' to 'thread_info*' in initialization
857 | for (struct thread_info *it : all_threads_safe ())
| ^
aix-thread.c: In lambda function:
aix-thread.c:899:61: warning: declaration of 'thread' shadows a previous local [-Wshadow=compatible-local]
899 | thread = iterate_over_threads ([&] (struct thread_info *thread)
----------------------------------
This patch is similar to the commit https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_git_-3Fp-3Dbinutils-2Dgdb.git-3Ba-3Dcommitdiff-3Bh-3D675a17a8a5cde1d8be86536df2ae6366ef0ec759&d=DwIDAg&c=BSDicqBQBDjDI9RkVyTcHQ&r=f-oUQ8ByG1nZ71OI9p76qywCPh7mxzU69hBYnkP9Nis&m=qpgW6gyN_lC_b0fBRhcWkqlvNDmUtHBTvyqGcCZxnuN6vnvJaehZ2WVuFVicJ9oD&s=UtdzAKmXnBH1ZTFOUTmFC9vTwxxralJIDjbYWsCsLYA&e=
all_threads_safe() returns an all_threads_safe_range which is like an iterator to iterate for loops.
AIX is adjusting its code in aix-thread.c for the same.
After applying this patch,
Sample test case output:
------------
gmake check RUNTESTFLAGS='gdb.threads/thread_events.exp CC_FOR_TARGET="/opt/freeware/bin/gcc" CXX_FOR_TARGET="/opt/freeware/bin/g++" CXXFLAGS_FOR_TARGET="-O0 -w -g -gdwarf -maix64" CFLAGS_FOR_TARGET="-O0 -w -g -gdwarf -maix64"'
gmake check-single
gmake[1]: Entering directory '/upstream_gdb/binutils-gdb/gdb/testsuite'
rm -f *core* gdb.sum gdb.log
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Using /opt/freeware/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /opt/freeware/share/dejagnu/config/unix.exp as generic interface file for target.
Using /upstream_gdb/binutils-gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
Running /upstream_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_events.exp ...
=== gdb Summary ===
/upstream_gdb/binutils-gdb/gdb/gdb version 18.0.50.20251010-git -nw -nx -q -iex "set height 0" -iex "set width 0" -data-directory /upstream_gdb/binutils-gdb/gdb/data-directory -iex "set interactive-mode on"
=== gdb Summary ===
/upstream_gdb/binutils-gdb/gdb/gdb version 18.0.50.20251010-git -nw -nx -q -iex "set height 0" -iex "set width 0" -data-directory /upstream_gdb/binutils-gdb/gdb/data-directory -iex "set interactive-mode on"
gmake[1]: Leaving directory '/upstream_gdb/binutils-gdb/gdb/testsuite'
Approved By: Ulrich Weigand <ulrich.weigand@de.ibm.com>
For one, all PadLock insns depend on CR4.FXSR to be enabled, which means
they ought to be taking FXSR as a prereq.
Furthermore none of them permits a REPNE prefix; such forms are documented
to cause #UD. (This is mainly relevant for XSTORE, which doesn't include a
REP prefix in its base encoding. For the others this merely is a change in
what diagnostic is issued.)
Finally it is documented that an operand size prefix also causes #UD.
_bfd_merged_section_offset() treats trailing symbols specially: That of
the retained section will be assigned the section size, while all ones in
replaced sections will be set to zero (which will then have output offset
added, i.e. generally the size of the retained section). However, in
neither case will the function change the section. Hence such trailing
symbols, when not originating from the retained section, will appear to
live in excluded sections, when they really belong to the sole retained
one.
Replace the section in all cases, and uniformly return section size.
A check in print_insn_aarch64_word asserted that part of the encoding
space couldn't contain any valid encodings, and then returned ERR_NYI
("Not Yet Implemented", perhaps?) for these values. However, some of
the new FEAT_MOP4 instructions will trigger the assert. The check seems
to be outdated, and is clearly no longer valid, so it can just be
deleted.
Additionally, there are no other assignments of ERR_NYI, so delete all
remaining references to this error type.
Update aarch64_{ins|ext}_simple_index to use constant fields, and swap
the order of the index and regno fields, so that the regno occupies the
last five bits. (Splitting/combining a variable length value and a
fixed length value is easiest if the fixed length value occupies the
least significant bits.)
Many instructions have constraints on the range of registers they can
use. This means that some bits in the register number are fixed, and
therefore aren't mapped to a field in the instruction encoding.
Currently we use various adhoc rules to handle these fixed bits, but
this doesn't handle all cases and we often have to write new code to
support new combinations of permitted registers.
This patch allows these constant bits to instead be specified in the
same structure used to represent instruction fields. Uses of the new
constant fields will be introduced in subsequent patches.
linespec.c has a symtab_collector class that is readily replaced by a
lambda. I think the result is more clear.
I considered using the unordered_dense 'extract' method as well, to
make the code a bit more efficient -- but it wasn't clear to me if the
ordering of the vector mattered, and so I've just added a comment.
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
After the "search via psyms" series, there's no need for
iterate_over_symtabs to first check the expanded symtabs -- the
callback will now be called for every relevant symtab, including ones
that were already expanded before the search.
Cleaning this up enables some other cleanups. In particular,
iterate_over_some_symtabs is not needed in its current form, so here
I've renamed it, made it static, and made it search just a single
compunit symtab.
While there I cleaned up the "invert" logic in
objfile::map_symtabs_matching_filename.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30738
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
cooked_index_functions::map_symbol_filenames returns 'void' but also
does "return ... expression". While valid, this seems strange. This
patch removes the unnecessary 'return'.
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
This patch changes the free function map_symbol_filenames to be a
method of program_space. This seems a bit cleaner, and also lets us
hoist a use of the global into the callers.
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
This patch adds the EIO and ENOSYS errno values supported by GDB's
File-I/O to section E.14.9: Errno Values of the GDB manual [1] that were
presumably inadvertently omitted; both can be seen in the enum
fileio_error:gdbsupport/fileio.h and corresponding function
host_to_fileio_error:gdbsupport/fileio.cc as FILEIO_{EIO,ENOSYS}.
FILEIO_SUCCESS remains excluded from the manual, because its stated
purpose (commit b872057a6) is to internally represent the absence of an
error value from the remote, and it's not actually an error number.
[1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Errno-Values.html
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This code:
if (in->ptr[idx] == '!')
{
idx++;
sb_add_char (acc, in->ptr[idx++]);
}
and similar code in the other loop, blindly accessed the next element
of the string buffer without first checking idx against in->len,
leading to uninitialised accesses or buffer overruns. Fix that, and
tidy the loops so that the function always returns the index one past
the last char consumed. (It could return idx == in->len + 1).
* macro.c (getstring): Don't access past end of input string
buffer. Tidy loops. Don't return an index past in->len.
gdb.tui/gdb.sh (used by test gdb.tui/tuiterm-2.exp) doesn't run well
when /bin/sh is dash:
$ bash testsuite/gdb.tui/gdb.sh
foo^C
$ dash testsuite/gdb.tui/gdb.sh
footestsuite/gdb.tui/gdb.sh: 20: read: arg count
shellcheck actually points it out:
In testsuite/gdb.tui/gdb.sh line 20:
read
^--^ SC3061 (warning): In POSIX sh, read without a variable is undefined.
^--^ SC2162 (info): read without -r will mangle backslashes.
Fix the issue by passing the `_` dummy variable. Using that particular
variable will not cause shellcheck to whine about it being unused. Also
add `-r` to make it happy.
Change-Id: Ida3eddbfa3473487743fc96615baf735b4773738
This fixes relocation handling in situations where hh->owner and
hh->sym_indx were not initialized.
2025-10-08 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
PR binutils/6511
* elf64-hppa.c (global_sym_index): New from ia64.
(elf64_hppa_check_relocs): Only set hh->eh.ref_regular if we
have a regular definition.
(elf64_hppa_check_relocs): Add missing NEED_DYNREL to need_entry
assignment.
(elf64_hppa_check_relocs): Stash symbol index and section
earlier.
(allocate_global_data_dlt): Initialize hh->owner and hh->sym_indx
if not initialized.
(allocate_global_data_opd): Likewise. Remove redundant checks
for NULL hh.
(allocate_dynrel_entries): Check for discarded
hppa_info->other_rel_sec section. Add assert rent->sec->owner
== hh->owner.
(elf64_hppa_finalize_dynreloc): Check for discarded
hppa_info->other_rel_sec section.
(elf_hppa_final_link_relocate): Return bfd_reloc_ok if we
have R_PARISC_NONE relocation.
With test-case gdb.server/fetch-exec-and-args.exp, on aarch64-linux I run into:
...
(gdb) break 28^M
Breakpoint 1 at 0xfffff7fd7b8c: file ../sysdeps/aarch64/dl-start.S, line 30.^M
(gdb) continue^M
Continuing.^M
^M
Breakpoint 1, _start () at ../sysdeps/aarch64/dl-start.S:30^M
30 mov x0, sp^M
(gdb) PASS: $exp: packet=on: test_exec_and_arg_fetch: \
continue to breakpoint: run to breakpoint
print argc^M
No symbol "argc" in current context.^M
(gdb) FAIL: $exp: packet=on: test_exec_and_arg_fetch: print argc
...
The problem is that the "break 28" is not specific about the file.
Fix this by setting the breakpoint on fetch-exec-and-args.c:28.
Tested on aarch64-linux.
PR testsuite/33522
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33522
With test-case gdb.python/py-corefile.exp I run into:
...
PASS: $exp: test mapped files data: show-build-ids
ERROR: tcl error sourcing gdb.python/py-corefile.exp.
ERROR: bad option "0x1fa178": \
must be -nobackslashes, -nocommands, or -novariables
while executing
"subst 0x$offset + 0"
...
Fix this using "[subst 0x$offset]" instead.
Tested on x86_64-linux.
I am currently upstreaming some patches from ROCgdb that were made a few
years ago. This series cleans up how the CLI and MI access parameters
for multiple inferiors.
A preceding patch (702991711a ("gdb: Have setter and getter callbacks
for settings")) allowed for per-inferior getter/setter functions of some
inferior-specific settings. Over the years a few changes were accepted
upstream (cc09d372f6 ("gdb: make set/show args work with
$_gdb_setting_str")) that implemented those capabilities.
This patch adds a few tests to verify that those settings are properly
set and accessed from the CLI, MI as well as the python interface.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I7a5eab210c84d6a6782a32125f68bde34d9a2339
Approved-By: Andrew Burgess <aburgess@redhat.com>
If a setting does not provide a "show" function, we fall back to the
deprecated_show_value_hack function to print the value in a generic
way. The current version ignores the `file` parameter specifying the
output file in favor of always using gdb_stdout.
To make things consistent with how the values are printed using a
regular show command, the proposed change makes the function use the
ui_file parameter it receives (even though do_show_command passes
gdb_stdout).
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I54028ed654a1fa4d955e6e46f979472c8d98ace9
Approved-By: Andrew Burgess <aburgess@redhat.com>
When calling the `show` command on a few inferior-specific settings
(inferior-tty, args, cwd), GDB will recompute the values despite them
being provided by a getter.
For instance, When `show cwd` is called, `do_show_command` will query
the value of the `cwd` through `get_inferior_cwd`, which already gets
the per-inferior value. The current version seems to be a workaround
from when settings could not provide a getter function and per-inferior
settings could thus not be implemented properly, forcing the `show`
implementation to recompute the value itself.
The changes clean up the code and makes the show command trust the
values it is being forwarded, as they will always be computed by the
getter function.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3b25f61f9101d98a6df7d50cee50131aec7e25c9
Approved-By: Andrew Burgess <aburgess@redhat.com>
The target description filename command pair ("(set|get) tdesc
filename") uses a rather indirect way to set the variable for the
inferior, using a scratch variable to pass the value. While most other
inferior-specific parameters were updated to the more direct
getter/setter style functions, I believe this parameter was an
oversight.
This patch removes the intermediate string and directly accesses the
tdesc filename for the current inferior.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I2a87c65c9931ec91d15f854b32ac8279fe7077be
Approved-By: Andrew Burgess <aburgess@redhat.com>