]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
14 months agoRemove RETURNS from BFD chew comments
Tom Tromey [Wed, 8 Feb 2023 04:43:37 +0000 (21:43 -0700)] 
Remove RETURNS from BFD chew comments

When reading the BFD manual, I noticed text like this:

     -- Function: bool bfd_close (bfd *abfd);
 Close a BFD. If the BFD was open for writing, then pending
 operations are completed and the file written out and closed.  If
    ...
       *Returns*
    'TRUE' is returned if all is ok, otherwise 'FALSE'.

The *Returns*, like the *Synopsis* in the earlier patch, is
un-info-like.  It's also used inconsistently.

This patch removes all the uses of the RETURNS word and removes it
entirely from the chew scripts.  Now this example reads:

     -- Function: bool bfd_close (bfd *abfd);
 Close a BFD. If the BFD was open for writing, then pending
 operations are completed and the file written out and closed.  If
    ...
 'TRUE' is returned if all is ok, otherwise 'FALSE'.

In a few cases I had to slightly reword the comment.  There were also
a couple of cases where there was redundant text.  In these cases I
just dropped the RETURNS copy.

2023-02-07  Tom Tromey  <tom@tromey.com>

* bfd.c, cache.c, compress.c, opncls.c: Remove RETURNS from
documentation comments.
* doc/doc.str, doc/proto.str (RETURNS): Remove.

14 months agoUse @deftypefn in chew output
Tom Tromey [Wed, 8 Feb 2023 04:40:53 +0000 (21:40 -0700)] 
Use @deftypefn in chew output

When reading the BFD info manual, function definitions looked very
strange to me:

    *Synopsis*
 long bfd_get_mtime (bfd *abfd);
       *Description*
    Return the file modification time (as read from the file system, or from
    the archive header for archive members).

The *Synopsis* and *Description* text in particular is very un-info-like.

To fix this, I tried removing the *Synopsis* text and having FUNCTION
use @deftypefn instead.  However, this ended up requiring some new
state, because SYNOPSIS can appear without FUNCTION.  This in turn
required "catstrif" (I considered adding FORTH-style if-else-then, but
in the end decided on an ad hoc approach).

After this the result looks like:

 -- Function: long bfd_get_mtime (bfd *abfd);
     Return the file modification time (as read from the file system, or
     from the archive header for archive members).

This patch also reorders a few documentation comments to ensure that
SYNOPSIS comes before DESCRIPTION.  This is the more common style and
is also now required by doc.str.

2023-02-07  Tom Tromey  <tom@tromey.com>

* syms.c (bfd_decode_symclass, bfd_is_undefined_symclass)
(bfd_symbol_info): Reorder documentation comment.
* doc/doc.str (synopsis_seen): New variable.
(SYNOPSIS): Set synopsis_seen.  Emit @deftypefn.
(DESCRIPTION): Use synopsis_seen.
* doc/chew.c (catstrif): New function.
(main): Add catstrif intrinsic.
(compile): Recognize "variable" command.

14 months agoChange internalmode to be an intrinsic variable
Tom Tromey [Tue, 7 Feb 2023 19:14:54 +0000 (12:14 -0700)] 
Change internalmode to be an intrinsic variable

Currently, internalmode is a special word to set an internal state
variable.  Because this series adds variables anyway, change this to
be a variable instead.

I saw some commits in the history that made sure that chew did not
leak memory, so I put some extra effort into trying to handle this for
variables as well.

2023-02-07  Tom Tromey  <tom@tromey.com>

* doc/proto.str (external, internal, ifinternal, ENUMEQ, ENUMDOC):
Update.
* doc/chew.c (internalmode): Remove.
(add_intrinsic_variable): New function.
(main): Add internalmode as intrinsic.
(internal_mode): Remove global.
(maybecatstr): Update.
(free_words): Free variables.

14 months agoUse intptr_t rather than long in chew
Tom Tromey [Tue, 7 Feb 2023 19:03:37 +0000 (12:03 -0700)] 
Use intptr_t rather than long in chew

To implement variables in chew, it's convenient to have a
pointer-sized integer on the stack.  To this end, use intptr_t rather
than long.

2023-02-07  Tom Tromey  <tom@tromey.com>

* doc/chew.c (pcu) <l>: Now intptr_t.
(internal_mode, istack, isp): Likewise.
(bang, atsign): Use intptr_t.

14 months agoRemove the paramstuff word
Tom Tromey [Tue, 7 Feb 2023 18:52:24 +0000 (11:52 -0700)] 
Remove the paramstuff word

The chew "paramstuff" word has been a no-op since:

    commit c58b95236ce4c9345c4fa76e7ef16762e5229380
    Author: Alan Modra <amodra@gmail.com>
    Date:   Sun Jun 29 10:06:40 2003 +0000

Convert to C90 and a few tweaks.

Remove it and its one use.

2023-02-07  Tom Tromey  <tom@tromey.com>

* doc/proto.str (SYNOPSIS): Don't use paramstuff.
* doc/chew.c (paramstuff): Remove.
(main): Don't add paramstuff intrinsic.

14 months agoAdd copyright headers to the .str files
Tom Tromey [Tue, 7 Feb 2023 18:39:16 +0000 (11:39 -0700)] 
Add copyright headers to the .str files

The .str script files don't have copyright headers, but I think they
should.  I used the same dates that chew.c uses, which I think makes
sense because these are inputs to chew.

2023-02-07  Tom Tromey  <tom@tromey.com>

* doc/doc.str, doc/proto.str: Add copyright header.

14 months agoSimplify @node use in BFD documentation
Tom Tromey [Tue, 7 Feb 2023 18:34:56 +0000 (11:34 -0700)] 
Simplify @node use in BFD documentation

The BFD docs currently specify all the parameters to @node.  However,
this results in bad navigation in certain nodes -- the "space" command
in info doesn't know how to find the next node.

I think this style of @node is a leftover from ancient times.
Makeinfo can figure out the node structure on its own now, so simplify
everything to a single-argument @node.

2023-02-07  Tom Tromey  <tom@tromey.com>

* doc/webassembly.texi (File layout): Remove second argument from
@node.
* doc/bfd.texi: Use single-argument @node everywhere.

14 months agoRemove H_CFLAGS from doc/local.mk
Tom Tromey [Wed, 8 Feb 2023 04:15:51 +0000 (21:15 -0700)] 
Remove H_CFLAGS from doc/local.mk

I couldn't see that H_CFLAGS is defined anywhere, so remove it.

2023-02-07  Tom Tromey  <tom@tromey.com>

* Makefile.in: Rebuild.
* doc/local.mk (%D%/chew.stamp): Don't use H_CFLAGS.

14 months agogdb: store internalvars in an std::map
Simon Marchi [Tue, 14 Feb 2023 19:23:27 +0000 (14:23 -0500)] 
gdb: store internalvars in an std::map

In a test downstream in ROCgdb, we had a test case failing when
GDB_REVERSE_INIT_FUNCTIONS was set.  The test was assuming a particular
order in the output of "show convenience".  And the order changes when
running with GDB_REVERSE_INIT_FUNCTIONS.

I think that a nice way to fix it is to make the output of "show
convenience" sorted, and therefore stable.  Ideally, I think that the
the user-visible behavior of GDB should not change when using
GDB_REVERSE_INIT_FUNCTIONS.  Plus, it makes the output of "show
convenience" look nice, not that it's really important.

Implement this by storing the internal vars in an std::map, which is a
sorted container.

Change-Id: I1fca7e7877cc984a3a3432c7639d45e68d437241
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: add constructor to internalvar
Simon Marchi [Tue, 14 Feb 2023 19:23:26 +0000 (14:23 -0500)] 
gdb: add constructor to internalvar

Add a constructor that takes the name as a parameter.  Initialize the
next and kind fields inline.

Change-Id: Ic4db0aba85f1da9f12f3eee0ac62c0e5ef0cfe88
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: use std::string for internalvar::name
Simon Marchi [Tue, 14 Feb 2023 19:23:25 +0000 (14:23 -0500)] 
gdb: use std::string for internalvar::name

Change internalvar::name to std::string, automating memory management.
It becomes necessary to allocate internalvar with new instead of XNEW.

I didn't find how to trigger the code in complete_internalvar.  It is
called from condition_completer, so it should be by using the
"condition" command, but I never managed to get in the right code path.

Change-Id: I814d61361663e7becb8f3fb5f58c0180cdc414bc
Approved-By: Tom Tromey <tom@tromey.com>
14 months agoDo not record a rejected target description
Tom Tromey [Fri, 6 Jan 2023 16:30:40 +0000 (09:30 -0700)] 
Do not record a rejected target description

When connecting to a certain target, gdb issues a warning about the
target description:

    (gdb) target remote localhost:7947
    Remote debugging using localhost:7947
    warning: Architecture rejected target-supplied description

If you then kill the inferior and change the exec-file, this will
happen:

    (gdb) file bar
    Architecture of file not recognized.

After this, debugging doesn't work very well.

What happens here is that, despite the warning,
target_find_description records the downloaded description in the
target_desc_info.  Then the "file" command ends up calling
set_gdbarch_from_file, which uses that description.

It seems to me that, because the architecture rejected the
description, it should not be used.  That is what this patch
implements.

14 months agogdb/manual: Move @findex entries
Pedro Alves [Mon, 13 Feb 2023 16:14:55 +0000 (16:14 +0000)] 
gdb/manual: Move @findex entries

The manual currently has many cases like these:

 @item $_gdb_setting_str (@var{setting})
 @findex $_gdb_setting_str@r{, convenience function}

As suggested by Eli, move the @findex entries before @item so that the
index records the position of @item, and the Info reader places you
there when you use index-search.

I went over all @findex calls in the manual, and most are like the
above.  Most either appear before @item, or before @subheading, like:

 @subheading The @code{-break-after} Command
 @findex -break-after

I fixed all of them.

There are findex entries in annotate.texinfo,python.texi, and
stabs.texinfo as well, though those all look right to me already.

Tested by typing "i _isvoid" (@item case) and "i -complete"
(@subheading case) in an Info reader, and checking where those took
me.

Change-Id: Idb6903b0bb39ff03f93524628dcef86b5585c97e
Suggested-By: Eli Zaretskii <eliz@gnu.org>
14 months agoobjdump read_section_stabs
Alan Modra [Wed, 15 Feb 2023 10:50:47 +0000 (21:20 +1030)] 
objdump read_section_stabs

This function is used to read sections other than stabs, and there is
now another version of it that extracts different info from the bfd
section.  Rename it and return the bfd section instead of assorted
fields of the bfd section.

* objcopy.c (read_section): Renamed from read_section_stabs.
Delete size_ptr and entsize_ptr params, add contents param.
Return asection pointer.  Don't unnecessarily free contents on
failure from bfd_malloc_and_get_section.
(find_stabs_section): Use read_section.
(dump_ctf, dump_section_sframe): Likewise.
(read_section_sframe): Delete.

14 months agoobjdump -G memory leak
Alan Modra [Wed, 15 Feb 2023 08:13:20 +0000 (18:43 +1030)] 
objdump -G memory leak

* objdump.c (find_stabs_section): Free stabs.

14 months agoFix the linker's merge4 test for the HPPA architecture.
Nick Clifton [Wed, 15 Feb 2023 09:26:10 +0000 (09:26 +0000)] 
Fix the linker's merge4 test for the HPPA architecture.

 PR 30078 * testsuite/ld-elf/merge4b.s: Use .asciz instead of .string in order to avoid the special behaviour of the .string directive on HPPA architectures.

14 months agogdb, fortran: Fix quad floating-point type for ifort compiler.
Felix Willgerodt [Mon, 13 Feb 2023 10:02:23 +0000 (11:02 +0100)] 
gdb, fortran: Fix quad floating-point type for ifort compiler.

I fixed this a while ago for ifx, one of the two Intel compilers, in
8d624a9d8050ca96e154215c7858ac5c2d8b0b19.

Apparently I missed that the older ifort Intel compiler actually emits
slightly different debug info again:

0x0000007a:   DW_TAG_base_type
                DW_AT_byte_size (0x20)
                DW_AT_encoding (DW_ATE_complex_float)
                DW_AT_name ("COMPLEX(16)")

0x00000081:   DW_TAG_base_type
                DW_AT_byte_size (0x10)
                DW_AT_encoding (DW_ATE_float)
                DW_AT_name ("REAL(16)")

This fixes two failures in gdb.fortran/complex.exp with ifort.

Approved-By: Tom Tromey <tom@tromey.com>
14 months agogas: buffer_and_nest() needs to pass nul-terminated string to temp_ilp()
Jan Beulich [Wed, 15 Feb 2023 07:46:02 +0000 (08:46 +0100)] 
gas: buffer_and_nest() needs to pass nul-terminated string to temp_ilp()

In 7545aa2dd2eb ("gas: improve interaction between read_a_source_file()
and s_linefile()") I didn't pay attention to the dual purpose of the
nul character previously used. This was to a fair degree because of the
open-coding of certain operations. Insert the earlier found line
terminator instead of a hard-coded newline, and do so early in this
special case (bypassing the later general insertion point). Plus
properly use sb_terminate() to mark the end of the string. (Note that
saved_eol_char was misnamed: Without calling sb_terminate() there's
simply random data at that position in the buffer.)

14 months agoMore ecoff sanity checks
Alan Modra [Wed, 15 Feb 2023 05:58:07 +0000 (16:28 +1030)] 
More ecoff sanity checks

Change FIX so that unused pointers that escape the UPDATE_RAW_END
sanity checks won't result in overflows.  Also sanity check the local
sym fdr isymBase and csym values.

* ecoff.c (_bfd_ecoff_slurp_symbolic_info): Define FIX to set
pointers into swapped internal data to NULL if count is zero.
Sanity check local sym fdr_ptr->isymBase and fdr_ptr->csym.

14 months agobinutils stabs type list
Alan Modra [Tue, 14 Feb 2023 21:21:00 +0000 (07:51 +1030)] 
binutils stabs type list

Fuzzers have found that specifying a large stab type number results in
lots of memory being requested, as the list is extended with a 16
element array at a time until we reach the given stab type.  It also
takes a long time.  Of course normal sane stab types use small
positive integers, but it's not hard to modify the code to handle type
numbers starting anyhere.

* stabs.c (struct stab_types): Add base_index.
(stab_find_slot): Simplify filenum check.  Delete type number
check.  Don't allocate entire array from 0 to type number,
allocate a sparse array.

14 months agoAutomatic date update in version.in
GDB Administrator [Wed, 15 Feb 2023 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoRemove a use of pagination_enabled
Tom Tromey [Sat, 28 Jan 2023 15:23:52 +0000 (08:23 -0700)] 
Remove a use of pagination_enabled

I noticed that the TUI temporarily sets pagination_enabled and
gdb_stdout in one spot.  However, I don't believe these settings are
necessary here, as a ui_file is passed to
gdbarch_print_registers_info.  This patch removes these settings.

14 months agogdb/dwarf2: rename some things, index -> gdb_index
Simon Marchi [Mon, 13 Feb 2023 14:55:56 +0000 (09:55 -0500)] 
gdb/dwarf2: rename some things, index -> gdb_index

This renaming helps make it clearer that these entites (classes,
functions) are specific to .gdb_index only, they are not shared with the
.debug_names handling.

Change-Id: I1a3cf3dbf450b62d1a0879d9aedd26397abdfd13
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: cast return value of std::unique_ptr::release to void
Simon Marchi [Mon, 13 Feb 2023 19:55:13 +0000 (14:55 -0500)] 
gdb: cast return value of std::unique_ptr::release to void

My editor shows warnings like:

     value.c:2784: warning: The value returned by this function should be used
     value.c:2784: note: cast the expression to void to silence this warning [bugprone-unused-return-value]

These warnings come from clangd, so ultimately from one of the clang
static analyzers (probably clang-tidy).

Silence these warnings by casting to void.  Add a comment to explain
why this unusual thing is done.

Change-Id: I58323959c0baf9f1b20a8d596e4c58dc77c6809a
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: remove unnecessary tui directory check in configure
Simon Marchi [Tue, 14 Feb 2023 16:37:16 +0000 (11:37 -0500)] 
gdb: remove unnecessary tui directory check in configure

I suppose this was possible in the CVS days for the tui directory to be
missing, but it's not really possible nowaday.  Well, a user could
delete the directory from their source tree but... it doesn't make
sense.  Remove the check for that directory in configure.

Change-Id: Iea1412f5e5482ed003015030132ec22150c7d0b3
Approved-By: Tom Tromey <tom@tromey.com>
14 months agoDo not cast away const in agent_run_command
Tom Tromey [Tue, 14 Feb 2023 14:03:11 +0000 (07:03 -0700)] 
Do not cast away const in agent_run_command

While investigating something else, I noticed some weird code in
agent_run_command (use of memcpy rather than strcpy).  Then I noticed
that 'cmd' is used as both an in and out parameter, despite being
const.

Casting away const like this is bad.  This patch removes the const and
fixes the memcpy.  I also added a static assert to assure myself that
the code in gdbserver is correct -- gdbserver is passing its own
buffer directly to agent_run_command.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
14 months ago[gdb/testsuite] Add xfail in gdb.python/py-record-btrace.exp
Tom de Vries [Tue, 14 Feb 2023 12:15:49 +0000 (13:15 +0100)] 
[gdb/testsuite] Add xfail in gdb.python/py-record-btrace.exp

There's a HW bug affecting Processor Trace on some Intel processors
(Ice Lake to Raptor Lake microarchitectures).

The bug was exposed by linux kernel commit 670638477aed
("perf/x86/intel/pt: Opportunistically use single range output mode"),
added in version v5.5.0, and was worked around by commit ce0d998be927
("perf/x86/intel/pt: Fix sampling using single range output") in version
6.1.0.

The bug manifests (on a Performance-core of an i7-1250U, an Alder Lake cpu) in
a single test-case:
...
(gdb) python insn = r.instruction_history^M
warning: Decode error (-20) at instruction 33 (offset = 0x3d6a, \
  pc = 0x400501): compressed return without call.^M
(gdb) FAIL: gdb.python/py-record-btrace.exp: prepare record: \
  python insn = r.instruction_history
...

Add a corresponding XFAIL.

Note that the i7-1250U has both Performance-cores and Efficient-cores, and on
an Efficient-Core the test-case runs without any problems, so if the testsuite
run is not pinned to a specific cpu, the test may either PASS or XFAIL.

Tested on x86_64-linux:
- openSUSE Leap 15.4 with linux kernel version 5.14.21
- openSUSE Tumbleweed with linux kernel version 6.1.8

PR testsuite/30075
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30075

14 months ago Mention that the -plugin command line option is used to load plugins.
Nick Clifton [Tue, 14 Feb 2023 12:01:06 +0000 (12:01 +0000)] 
 Mention that the -plugin command line option is used to load plugins.

14 months ago[gdb/testsuite] Factor out proc linux_kernel_version
Tom de Vries [Tue, 14 Feb 2023 10:53:54 +0000 (11:53 +0100)] 
[gdb/testsuite] Factor out proc linux_kernel_version

Factor out new proc linux_kernel_version from test-case
gdb.arch/i386-pkru.exp.

Tested on x86_64-linux.

14 months agoASCIZ Command for output section
Ulf Samuelsson [Tue, 14 Feb 2023 10:13:28 +0000 (10:13 +0000)] 
ASCIZ Command for output section

Adds a new directive to the linker script syntax: ASCIZ.
This inserts a zero-terminated string into the output at the place where it is used.

14 months agogas: correct symbol name comparison in .startof./.sizeof. handling
Jan Beulich [Tue, 14 Feb 2023 07:35:02 +0000 (08:35 +0100)] 
gas: correct symbol name comparison in .startof./.sizeof. handling

In 162c6aef1f3a ("gas: fold symbol table entries generated for
.startof.() / .sizeof.()") I screwed up quite badly, inverting the case
sensitive and case insensitive comparison functions.

14 months agox86: {LD,ST}TILECFG use an extension opcode
Jan Beulich [Tue, 14 Feb 2023 07:34:42 +0000 (08:34 +0100)] 
x86: {LD,ST}TILECFG use an extension opcode

It being zero and happening to work right now doesn't mean the insns
shouldn't be spelled out properly.

14 months agogas: improve interaction between read_a_source_file() and s_linefile()
Jan Beulich [Tue, 14 Feb 2023 07:34:03 +0000 (08:34 +0100)] 
gas: improve interaction between read_a_source_file() and s_linefile()

read_a_source_file() would bump line numbers only when seeing a newline,
whereas is_end_of_line[] indicates further end-of-line characters, in
particular the nul character. s_linefile() attempts to compensate for
the bump, but was too aggressive with this so far: It should only adjust
when a newline ends the line. To facilitate such a check, the check for
nothing else on the line needs to move ahead, which luckily is easily
possible: The relevant two conditions match, and the function can
simply return from the body of that earlier instance of the conditional.

The more strict treatment in s_linefile() then requires an adjustment
to buffer_and_nest()'s invocation of the function: The line terminator
now needs to be a newline, not nul.

14 months agoFix build bug in ppc-linux-nat.c
Tom Tromey [Tue, 14 Feb 2023 07:28:47 +0000 (00:28 -0700)] 
Fix build bug in ppc-linux-nat.c

The buildbot pointed out that my value refactoring series introduced a
bug in ppc-linux-nat.c:

../../binutils-gdb/gdb/ppc-linux-nat.c: In member function â€˜int ppc_linux_nat_target::num_memory_accesses(const std::vector<gdb::ref_ptr<value, value_ref_policy> >&)’:
../../binutils-gdb/gdb/ppc-linux-nat.c:2458:44: error: expected unqualified-id before â€˜->’ token
 2458 |       if (VALUE_LVAL (v) == not_lval || v->->deprecated_modifiable () == 0)

I don't know how that happened, but I am checking in this patch which
I think should fix it.  It just removes the second "->".

I can't readily test this, so perhaps there's another bug lurking
after this one.

14 months agoAutomatic date update in version.in
GDB Administrator [Tue, 14 Feb 2023 00:00:22 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoRely on value_ref_ptr::operator->
Tom Tromey [Fri, 10 Feb 2023 17:48:50 +0000 (10:48 -0700)] 
Rely on value_ref_ptr::operator->

Simon pointed out some spots were doing val.get()->mumble, where val
is a value_ref_ptr.  These were introduced by the function-to-method
script, replacing older code that passed the result of .get() to a
function.

Now that value.h is using methods, we can instead rely on operator->.
This patch replaces all the newly-introduced instances of this.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove deprecated_lval_hack
Tom Tromey [Thu, 9 Feb 2023 13:55:48 +0000 (06:55 -0700)] 
Remove deprecated_lval_hack

This removes deprecated_lval_hack and the VALUE_LVAL macro, replacing
all uses with a call to value::lval.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoIntroduce set_lval method on value
Tom Tromey [Thu, 9 Feb 2023 13:35:33 +0000 (06:35 -0700)] 
Introduce set_lval method on value

This introduces the set_lval method on value, one step toward removing
deprecated_lval_hack.  Ultimately I think the goal should be for some
of these set_* methods to be replaced with constructors; but I haven't
done this, as the series is already too long.  Other 'deprecated'
methods can probably be handled the same way.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoMake ~value private
Tom Tromey [Wed, 1 Feb 2023 15:34:58 +0000 (08:34 -0700)] 
Make ~value private

At the end of this series, I belatedly realized that values should
only be destroyed by value_decref.  This patch marks the the
destructor private to enforce this.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoMake struct value data members private
Tom Tromey [Wed, 1 Feb 2023 15:25:40 +0000 (08:25 -0700)] 
Make struct value data members private

This hoists the 'private' in struct value to also encompass the data
members.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn record_latest_value into a method
Tom Tromey [Sun, 12 Feb 2023 15:04:07 +0000 (08:04 -0700)] 
Turn record_latest_value into a method

record_latest_value now access some internals of struct value, so turn
it into a method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoAdd value::set_modifiable
Tom Tromey [Wed, 1 Feb 2023 15:25:21 +0000 (08:25 -0700)] 
Add value::set_modifiable

This introduces a value::set_modifiable and changes a couple of spots
to use it.

I'm not completely sure the comments by deprecated_modifiable are
correct any more.  Perhaps they should be removed and the method
renamed.  Like so many before me, though, I've deferred investigation
of the issue.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn various value copying-related functions into methods
Tom Tromey [Wed, 1 Feb 2023 14:27:50 +0000 (07:27 -0700)] 
Turn various value copying-related functions into methods

This patch turns a grab bag of value functions to methods of value.
These are done together because their implementations are
interrelated.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn preserve_one_value into method
Tom Tromey [Wed, 1 Feb 2023 04:11:38 +0000 (21:11 -0700)] 
Turn preserve_one_value into method

This changes preserve_one_value to be a method of value.  Much of this
patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn some xmethod functions into methods
Tom Tromey [Wed, 1 Feb 2023 03:59:39 +0000 (20:59 -0700)] 
Turn some xmethod functions into methods

This turns value_from_xmethod, result_type_of_xmethod, and
call_xmethod to be methods of value.  value_from_xmethod is a static
"constructor" now.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoChange some code to use value methods
Tom Tromey [Wed, 1 Feb 2023 03:54:26 +0000 (20:54 -0700)] 
Change some code to use value methods

A few functions in value.c were accessing the internal fields of
struct value.  However, in these cases it seemed simpler to change
them to use the public API rather than convert them to be methods.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn set_value_component_location into method
Tom Tromey [Tue, 31 Jan 2023 23:26:38 +0000 (16:26 -0700)] 
Turn set_value_component_location into method

This turns set_value_component_location into a method of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_non_lval and value_force_lval into methods
Tom Tromey [Tue, 31 Jan 2023 23:23:22 +0000 (16:23 -0700)] 
Turn value_non_lval and value_force_lval into methods

This changes value_non_lval and value_force_lval to be methods of
value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn many optimized-out value functions into methods
Tom Tromey [Tue, 31 Jan 2023 23:13:08 +0000 (16:13 -0700)] 
Turn many optimized-out value functions into methods

This turns many functions that are related to optimized-out or
availability-checking to be methods of value.  The static function
value_entirely_covered_by_range_vector is also converted to be a
private method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_copy into a method
Tom Tromey [Tue, 31 Jan 2023 21:43:22 +0000 (14:43 -0700)] 
Turn value_copy into a method

This turns value_copy into a method of value.  Much of this was
written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoFully qualify calls to copy in value.c
Tom Tromey [Tue, 31 Jan 2023 21:51:24 +0000 (14:51 -0700)] 
Fully qualify calls to copy in value.c

A coming patch will add value::copy, so this namespace-qualifies
existing calls to 'copy' in value.c, to ensure it will still compile
after that change is done.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn remaining value_contents functions into methods
Tom Tromey [Tue, 31 Jan 2023 21:38:30 +0000 (14:38 -0700)] 
Turn remaining value_contents functions into methods

This turns the remaining value_contents functions -- value_contents,
value_contents_all, value_contents_for_printing, and
value_contents_for_printing_const -- into methods of value.  It also
converts the static functions require_not_optimized_out and
require_available to be private methods.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_incref and value_decref into methods
Tom Tromey [Tue, 31 Jan 2023 21:25:29 +0000 (14:25 -0700)] 
Turn value_incref and value_decref into methods

This changes value_incref and value_decref to be methods of value.
Much of this patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoMove value_ref_policy methods out-of-line
Tom Tromey [Tue, 31 Jan 2023 21:22:13 +0000 (14:22 -0700)] 
Move value_ref_policy methods out-of-line

This moves the value_ref_policy methods to be defined out-of-line.
This is a necessary step to change value_incref and value_decref to be
methods of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_bits_synthetic_pointer into a method
Tom Tromey [Tue, 31 Jan 2023 21:17:50 +0000 (14:17 -0700)] 
Turn value_bits_synthetic_pointer into a method

This changes value_bits_synthetic_pointer to be a method of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_contents_eq into a method
Tom Tromey [Tue, 31 Jan 2023 21:11:48 +0000 (14:11 -0700)] 
Turn value_contents_eq into a method

This changes value_contents_eq to be a method of value.  It also
converts the static function value_contents_bits_eq into a private
method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn allocate_value_contents into a method
Tom Tromey [Tue, 31 Jan 2023 20:59:56 +0000 (13:59 -0700)] 
Turn allocate_value_contents into a method

This turns the static function allocate_value_contents into a method
on value.  It is temporarily public, until some users are converted.
set_limited_array_length is converted as well.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_fetch_lazy into a method
Tom Tromey [Tue, 31 Jan 2023 20:53:55 +0000 (13:53 -0700)] 
Turn value_fetch_lazy into a method

This changes value_fetch_lazy to be a method of value.  A few helper
functions are converted as well, to avoid problems in later patches
when the data members are all made private.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn some value_contents functions into methods
Tom Tromey [Tue, 31 Jan 2023 20:45:40 +0000 (13:45 -0700)] 
Turn some value_contents functions into methods

This turns value_contents_raw, value_contents_writeable, and
value_contents_all_raw into methods on value.  The remaining functions
will be changed later in the series; they were a bit trickier and so I
didn't include them in this patch.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_zero into static "constructor"
Tom Tromey [Tue, 31 Jan 2023 20:41:35 +0000 (13:41 -0700)] 
Turn value_zero into static "constructor"

This turns value_zero into a static "constructor" of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn allocate_optimized_out_value into static "constructor"
Tom Tromey [Tue, 31 Jan 2023 20:30:54 +0000 (13:30 -0700)] 
Turn allocate_optimized_out_value into static "constructor"

This turns allocate_optimized_out_value into a static "constructor" of
value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn allocate_computed_value into static "constructor"
Tom Tromey [Tue, 31 Jan 2023 20:29:49 +0000 (13:29 -0700)] 
Turn allocate_computed_value into static "constructor"

This turns allocate_computed_value into a static "constructor" of
value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn allocate_value into a static "constructor"
Tom Tromey [Tue, 31 Jan 2023 20:25:17 +0000 (13:25 -0700)] 
Turn allocate_value into a static "constructor"

This changes allocate_value to be a static "constructor" of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn allocate_value_lazy into a static "constructor"
Tom Tromey [Tue, 31 Jan 2023 20:24:00 +0000 (13:24 -0700)] 
Turn allocate_value_lazy into a static "constructor"

This changes allocate_value_lazy to be a static "constructor" of
struct value.

I considered trying to change value to use ordinary new/delete, but it
seems to me that due to reference counting, we may someday want to
change these static constructors to return value_ref_ptr instead.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn more deprecated_* functions into methods
Tom Tromey [Tue, 31 Jan 2023 19:46:20 +0000 (12:46 -0700)] 
Turn more deprecated_* functions into methods

This changes deprecated_value_internalvar_hack,
deprecated_value_internalvar_hack, and deprecated_value_regnum_hack
into methods on value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_address and set_value_address functions into methods
Tom Tromey [Tue, 31 Jan 2023 19:27:30 +0000 (12:27 -0700)] 
Turn value_address and set_value_address functions into methods

This changes the value_address and set_value_address functions to be
methods of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_initialized and set_value_initialized functions into methods
Tom Tromey [Tue, 31 Jan 2023 19:22:01 +0000 (12:22 -0700)] 
Turn value_initialized and set_value_initialized functions into methods

This changes the value_initialized and set_value_initialized functions
to be methods of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoConvert value_lval_const and deprecated_lval_hack to methods
Tom Tromey [Tue, 31 Jan 2023 19:16:29 +0000 (12:16 -0700)] 
Convert value_lval_const and deprecated_lval_hack to methods

This converts the value_lval_const and deprecated_lval_hack functions
to be methods on value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_computed_closure and value_computed_funcs functions into methods
Tom Tromey [Tue, 31 Jan 2023 19:12:39 +0000 (12:12 -0700)] 
Turn value_computed_closure and value_computed_funcs functions into methods

This changes the value_computed_funcs and value_computed_closure
functions to be methods of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_stack and set_value_stack functions into methods
Tom Tromey [Tue, 31 Jan 2023 18:11:17 +0000 (11:11 -0700)] 
Turn value_stack and set_value_stack functions into methods

This changes the value_stack and set_value_stack functions to be
methods of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_lazy and set_value_lazy functions into methods
Tom Tromey [Tue, 31 Jan 2023 17:52:04 +0000 (10:52 -0700)] 
Turn value_lazy and set_value_lazy functions into methods

This changes the value_lazy and set_value_lazy functions to be methods
of value.  Much of this patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn some value offset functions into method
Tom Tromey [Tue, 31 Jan 2023 17:40:38 +0000 (10:40 -0700)] 
Turn some value offset functions into method

This changes various offset-related functions to be methods of value.
Much of this patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_enclosing_type into method
Tom Tromey [Tue, 31 Jan 2023 17:19:10 +0000 (10:19 -0700)] 
Turn value_enclosing_type into method

This changes value_enclosing_type to be a method of value.  Much of
this patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn deprecated_value_modifiable into method
Tom Tromey [Tue, 31 Jan 2023 17:17:10 +0000 (10:17 -0700)] 
Turn deprecated_value_modifiable into method

This changes deprecated_value_modifiable to be a method of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_offset into method
Tom Tromey [Tue, 31 Jan 2023 17:05:01 +0000 (10:05 -0700)] 
Turn value_offset into method

This changes value_offset to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_parent into method
Tom Tromey [Tue, 31 Jan 2023 16:56:33 +0000 (09:56 -0700)] 
Turn value_parent into method

This changes value_parent to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_bitpos into method
Tom Tromey [Tue, 31 Jan 2023 16:44:47 +0000 (09:44 -0700)] 
Turn value_bitpos into method

This changes value_bitpos to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_bitsize into method
Tom Tromey [Tue, 31 Jan 2023 16:38:22 +0000 (09:38 -0700)] 
Turn value_bitsize into method

This changes value_bitsize to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_arch into method
Tom Tromey [Tue, 31 Jan 2023 15:31:48 +0000 (08:31 -0700)] 
Turn value_arch into method

This changes value_arch to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn deprecated_set_value_type into a method
Tom Tromey [Tue, 31 Jan 2023 15:24:35 +0000 (08:24 -0700)] 
Turn deprecated_set_value_type into a method

This changes deprecated_set_value_type to be a method of value.  Much
of this patch was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoTurn value_type into method
Tom Tromey [Tue, 31 Jan 2023 14:52:09 +0000 (07:52 -0700)] 
Turn value_type into method

This changes value_type to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoMove struct value to value.h
Tom Tromey [Tue, 31 Jan 2023 14:46:56 +0000 (07:46 -0700)] 
Move struct value to value.h

This moves struct value to value.h.  For now, all members remain
public, but this is a temporary state -- by the end of the series
we'll add 'private'.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoMove ~value body out-of-line
Tom Tromey [Tue, 31 Jan 2023 14:41:09 +0000 (07:41 -0700)] 
Move ~value body out-of-line

struct value is going to move to value.h, but to avoid having
excessive code there, first move the destructor body out-of-line.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRename all fields of struct value
Tom Tromey [Tue, 31 Jan 2023 14:40:33 +0000 (07:40 -0700)] 
Rename all fields of struct value

This renames all the fields of struct value, in preparation for the
coming changes.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoPR30120: fix x87 fucomp misassembled
Michael Matz [Mon, 13 Feb 2023 17:20:44 +0000 (18:20 +0100)] 
PR30120: fix x87 fucomp misassembled

this fixes the entry for 'fucomp' to use the correct Reg value
(otherwise it's assembled as 'fucom').

14 months agoRemove unused imports from gdb's Python code
Tom Tromey [Mon, 13 Feb 2023 17:16:05 +0000 (10:16 -0700)] 
Remove unused imports from gdb's Python code

The "sys" import is unused in several Python files.  This removes this
line from all the places where it is unnecessary.

14 months agogdb/tui: don't leak the known_window_types map
Andrew Burgess [Thu, 12 Jan 2023 16:18:53 +0000 (16:18 +0000)] 
gdb/tui: don't leak the known_window_types map

This commit finishes the task that was started in the previous
commit.

Now that all Python TUI window factories are correctly deleted when
the Python interpreter is shut down, we no longer need to dynamically
allocate the known_window_types map in tui-layout.c

This commit changes known_window_types to a statically allocated data
structure, removes the dynamic allocation from
initialize_known_windows, and then replaces lots of '->' with '.'
throughout this file.

There should be no user visible changes after this commit.

Reviewed-By: Tom Tromey <tom@tromey.com>
14 months agogdb/python: deallocate tui window factories at Python shut down
Andrew Burgess [Thu, 12 Jan 2023 15:47:17 +0000 (15:47 +0000)] 
gdb/python: deallocate tui window factories at Python shut down

The previous commit relied on spotting when a Python defined TUI
window factory was deleted.  I spotted that the window factories are
not deleted when GDB shuts down its Python environment, they are only
deleted when one window factory replaces another.  Consider this
example Python script:

  class TestWindowFactory:
      def __init__(self, msg):
          self.msg = msg
          print("Entering TestWindowFactory.__init__: %s" % self.msg)

      def __call__(self, tui_win):
          print("Entering TestWindowFactory.__call__: %s" % self.msg)
          return TestWindow(tui_win, self.msg)

      def __del__(self):
          print("Entering TestWindowFactory.__del__: %s" % self.msg)

  gdb.register_window_type("test_window", TestWindowFactory("A"))
  gdb.register_window_type("test_window", TestWindowFactory("B"))

And this GDB session:

  (gdb) source tui.py
  Entering TestWindowFactory.__init__: A
  Entering TestWindowFactory.__init__: B
  Entering TestWindowFactory.__del__: B
  (gdb) quit

Notice that when the 'B' window replaces the 'A' window we see the 'A'
object being deleted.  But, when Python is shut down (after the
'quit') the 'B' object is never deleted.

Instead, GDB retains a reference to the window factory object, which
forces the Python object to remain live even after the Python
interpreter itself has been shut down.

The references themselves are held in a dynamically allocated
std::unordered_map (in tui/tui-layout.c) which is never deallocated,
thus the underlying Python references are never decremented to zero,
and so GDB never tries to delete these Python objects.

This commit is the first half of the work to clean up this edge case.

All gdbpy_tui_window_maker objects (the objects that implement the
TUI window factory callback for Python defined TUI windows), are now
linked together into a global list using the intrusive list mechanism.

When GDB shuts down the Python interpreter we can now walk this global
list and release the reference that is held to the underlying Python
object.  By releasing this reference the Python object will now be
deleted.

I've added a new assert in gdbpy_tui_window_maker::operator(), this
will catch the case where we somehow end up in here after having
reset the reference to the underlying Python object.  I don't think
this should ever happen though as we only clear the references when
shutting down the Python interpreter, and the ::operator() function is
only called when trying to apply a new TUI layout - something that
shouldn't happen while GDB itself is shutting down.

This commit does not update the std::unordered_map in tui-layout.c,
that will be done in the next commit.

Reviewed-By: Tom Tromey <tom@tromey.com>
14 months agogdb/python: allow Python TUI windows to be replaced
Andrew Burgess [Thu, 12 Jan 2023 15:47:11 +0000 (15:47 +0000)] 
gdb/python: allow Python TUI windows to be replaced

The documentation for gdb.register_window_type says:

  "...  It's an error to try to replace one of the built-in windows,
  but other window types can be replaced. ..."

I take this to mean that if I imported a Python script like this:

  gdb.register_window_type('my_window', FactoryFunction)

Then GDB would have a new TUI window 'my_window', which could be
created by calling FactoryFunction().  If I then, in the same GDB
session imported a script which included:

  gdb.register_window_type('my_window', UpdatedFactoryFunction)

Then GDB would replace the old 'my_window' factory with my new one,
GDB would now call UpdatedFactoryFunction().

This is pretty useful in practice, as it allows users to iterate on
their window implementation within a single GDB session.

However, right now, this is not how GDB operates.  The second call to
register_window_type is basically ignored and the old window factory
is retained.

This is because in tui_register_window (tui/tui-layout.c) we use
std::unordered_map::emplace to insert the new factory function, and
emplace doesn't replace an existing element in an unordered_map.

In this commit, before the emplace call, I now search for an already
existing element, and delete any matching element from the map, the
emplace call will then add the new factory function.

Reviewed-By: Tom Tromey <tom@tromey.com>
14 months agoFix doc build dependencies for --with-system-readline
Keith Seitz [Mon, 13 Feb 2023 14:14:40 +0000 (06:14 -0800)] 
Fix doc build dependencies for --with-system-readline

PR build/30108 concerns building gdb documentation with
--with-sytem-readline.  If the in-tree readline directory is
missing, though, the docs will fail to build:

make[4]: Entering directory '/home/keiths/work/readline-doc-issue/linux/gdb/doc'
make[4]: *** No rule to make target '../../../src/gdb/doc/../../readline/readline/doc/rluser.texi', needed by 'gdb.info'.  Stop.

The listed file (and hsuser.texi) are conditionally included by gdb.texinfo.
When system readline is used, gdb/configure.ac will leave
READLINE_TEXI_INCFLAGS empty, causing doc/Makefile.in to output a line to
$BUILD/doc/GDBvn.texi with "@set SYSTEM_READLINE".  This surpresses the
inclusion of the missing files. They are not needed or used in this
scenario.

However, GDB_DOC_SOURCE_INCLUDES always lists these two files as dependencies,
thus provoking the build error whenever readline/ is missing.

This patch fixes this by creating (essentially) a conditional setting of the
dependencies to be included from readline.

14 months agoFix PR30079: abort on mingw
Michael Matz [Thu, 9 Feb 2023 14:29:00 +0000 (15:29 +0100)] 
Fix PR30079: abort on mingw

the early-out in wild_sort is not enough, it might still be
that filenames are equal _and_ the wildcard list doesn't specify
a sort order either.  Don't call compare_section then.

Tested on all targets.

14 months ago_bfd_ecoff_slurp_symbol_table buffer overflow
Alan Modra [Mon, 13 Feb 2023 11:45:05 +0000 (22:15 +1030)] 
_bfd_ecoff_slurp_symbol_table buffer overflow

Add missing bounds check, and tidy the existing bounds checking.

* ecoff.c (_bfd_ecoff_slurp_symbol_table): Break overlong lines.
Set bfd_error.  Bounds check internal_sym.iss.

14 months agoopcodes/mips: disassemble unknown micromips instructions as two shorts
Andrew Burgess [Fri, 6 Jan 2023 16:42:23 +0000 (16:42 +0000)] 
opcodes/mips: disassemble unknown micromips instructions as two shorts

Before commit:

  commit 2438b771ee07be19d5b01ea55e077dd8b7cef445
  Date:   Wed Nov 2 15:53:43 2022 +0000

      opcodes/mips: use .word/.short for undefined instructions

unknown 32-bit microMIPS instructions were disassembled as a raw
32-bit number with no '.word' directive.  The above commit changed
this and added a '.word' directive before the 32-bit number.

It was pointed out on the mailing list, that for microMIPS it would be
better to display such 32-bit instructions using a '.short' directive
followed by two 16-bit values.

This commit updates the mips disassembler to do this, and adds a new
test that validates this output.

14 months agogdb/testsuite: handle differences in guile error string output
Andrew Burgess [Mon, 13 Feb 2023 11:19:57 +0000 (11:19 +0000)] 
gdb/testsuite: handle differences in guile error string output

A new guile test added in commit:

  commit 0a9ccb9dd79384f3ba3f8cd75940e8868f3b526f
  Date:   Mon Feb 6 13:04:16 2023 +0000

      gdb: only allow one of thread or task on breakpoints or watchpoints

fails for some versions of guile.  It turns out that some versions of
guile emit an error like this:

  (gdb) guile (set-breakpoint-thread! bp 1)
  ERROR: In procedure set-breakpoint-thread!:
  In procedure gdbscm_set_breakpoint_thread_x: cannot set both task and thread attributes
  Error while executing Scheme code.

while other versions of guile emit the error like this:

  (gdb) guile (set-breakpoint-thread! bp 1)
  ERROR: In procedure set-breakpoint-thread!:
  ERROR: In procedure gdbscm_set_breakpoint_thread_x: cannot set both task and thread attributes
  Error while executing Scheme code.

notice the extra 'ERROR: ' on the second line of output.  This commit
updates the test regexp to handle this optional 'ERROR: ' string.

14 months agostabs.c static state
Alan Modra [Mon, 13 Feb 2023 09:58:41 +0000 (20:28 +1030)] 
stabs.c static state

Move all the function local static state variables to file scope,
in order to tidy memory on exit and to reinit everything for that
annoying oss-fuzz.  Also fix a couple memory leaks.

* read.h (read_begin, read_end): Declare.
* read.c (read_begin): Call stabs_begin.
(read_end): Call stabs_end.
* stabs.c (stabs_begin, stabs_end): New functions.
(in_dot_func_p): Delete, use current_function_label instead.
(cached_sec): Move from s_stab_generic.
(last_asm_file, file_label_count): Move from generate_asm_file.
(line_label_count, prev_lineno, prev_line_file): Move from
stabs_generate_asm_lineno.
(void_emitted_p): Move from stabs_generate_asm_func.
(endfunc_label_count): Move from stabs_generate_asm_endfunc.
(stabs_generate_asm_lineno): Simplify setting of
prev_line_file.
(stabs_generate_asm_func): Don't leak current_function_label.
(stabs_generate_asm_endfunc): Likewise.

14 months agoSplit off gas init to functions
Alan Modra [Mon, 13 Feb 2023 09:54:52 +0000 (20:24 +1030)] 
Split off gas init to functions

With some slight reordering.

* as.c (gas_early_init, gas_late_init): New functions, split..
(main): ..from here.

14 months agogdb/testsuite: look for hipcc in env(ROCM_PATH)
Lancelot SIX [Tue, 7 Feb 2023 15:13:47 +0000 (15:13 +0000)] 
gdb/testsuite: look for hipcc in env(ROCM_PATH)

If the hipcc compiler cannot be found in dejagnu's tool_root_dir, look
for it in $::env(ROCM_PATH) (if set).  If hipcc is still not found,
fallback to "hipcc" so the compiler will be searched in the PATH.  This
removes the fallback to the hard-coded "/opt/rocm/bin" prefix.

This change is done so ROCM tools are searched in a uniform manner.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/testsuite: allow_hipcc_tests tests the hipcc compiler
Lancelot SIX [Sat, 4 Feb 2023 23:57:07 +0000 (23:57 +0000)] 
gdb/testsuite: allow_hipcc_tests tests the hipcc compiler

Update allow_hipcc_tests so all gdb.rocm tests are skipped if we do not
have a working hipcc compiler available.

To achieve this, adjust gdb_simple_compile to ensure that the hip
program is saved in a ".cpp" file before calling hipcc otherwise
compilation will fail.

One thing to note is that it is possible to have a hipcc installed with
a CUDA backend.  Compiling with this back-end will successfully result
in an application, but GDB cannot debug it (at least for the offload
part). In the context of the gdb.rocm tests, we want to detect such
situation where gdb_simple_compile would give a false positive.

To achieve this, this patch checks that there is at least one AMDGPU
device available and that hipcc can compile for this or those targets.
Detecting the device is done using the rocm_agent_enumerator tool which
is installed with the all ROCm installations (it is used by hipcc to
detect identify targets if this is not specified on the comand line).

This patch also makes the allow_hipcc_tests proc a cached proc.

Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/testsuite: require amd-dbgapi support to run rocm tests
Lancelot SIX [Mon, 6 Feb 2023 19:08:13 +0000 (19:08 +0000)] 
gdb/testsuite: require amd-dbgapi support to run rocm tests

Update allow_hipcc_tests to check that GDB has the amd-dbgapi support
built-in.  Without this support, all tests using hipcc and the rocm
stack will fail.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/testsuite: Rename skip_hipcc_tests to allow_hipcc_tests
Lancelot SIX [Mon, 6 Feb 2023 18:05:31 +0000 (18:05 +0000)] 
gdb/testsuite: Rename skip_hipcc_tests to allow_hipcc_tests

Rename skip_hipcc_tests to allow_hipcc_tests so it can be used as a
"require" predicate in tests.

Use require in gdb.rocm/simple.exp.

Approved-By: Simon Marchi <simon.marchi@efficios.com>