Commit Graph

193 Commits

Author SHA1 Message Date
Simon Marchi
d64c62fdb4 Convert target-descriptions.c to new hash table
This converts target-descriptions.c to use the new hash table.

Change-Id: I03dfc6053c9856c5578548afcfdf58abf8b7ec2c
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
2024-11-25 22:07:04 -05:00
Andrew Burgess
d2f8a107b7 gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabi
There is a single declaration of set_tdesc_osabi that is shared
between gdbserver/ and gdb/, this declaration takes a 'const char *'
argument which is the string representing an osabi.

Then in gdb/ we have an overload of set_tdesc_osabi which takes an
'enum gdb_osabi'.

In this commit I change the shared set_tdesc_osabi to be the version
which takes an 'enum gdb_osabi', and I remove the version which takes
a 'const char *'.  All users of set_tdesc_osabi are updated to pass an
'enum gdb_osabi'.

The features/ code, which is generated from the xml files, requires a
new function to be added to osabi.{c,h} which can return a string
representation of an 'enum gdb_osabi'.  With that new function in
place the features/ code is regenerated.

This change is being made to support the next commit.  In the next
commit gdbserver will be updated to call set_tdesc_osabi in more
cases.  The problem is that gdbserver stores the osabi as a string.
The issue here is that a typo in the gdbserver/ code might go
unnoticed and result in gdbserver sending back an invalid osabi
string.

To fix this we want gdbserver to pass an 'enum gdb_osabi' to the
set_tdesc_osabi function.  With that requirement in place it seems to
make sense if all calls to set_tdesc_osabi pass an 'enum gdb_osabi'.

There should be no user visible changes after this commit.

Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10 17:36:21 +01:00
Andrew Burgess
cb5997da94 gdb: make use of set_tdesc_osabi overload in features/ files
There are two versions of the set_tdesc_osabi function in GDB:

  void
  set_tdesc_osabi (struct target_desc *target_desc, const char *name)
  {
    set_tdesc_osabi (target_desc, osabi_from_tdesc_string (name));
  }

  void
  set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
  {
    target_desc->osabi = osabi;
  }

In the gdb/features/ files we call the second of these functions, like
this:

  set_tdesc_osabi (result.get (), osabi_from_tdesc_string ("GNU/Linux"));

This can be replaced with a call to the first set_tdesc_osabi
function, so lets do that.  I think that this makes the features/ code
slightly simpler and easier to understand.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10 17:36:21 +01:00
Andrew Burgess
e454ae416a gdb: allow quoted filenames for commands that have custom completion
This commit changes how GDB processes command arguments for the
following commands:

  compile file
  maint print c-tdesc
  save gdb-index

After this commit these commands will now expect their single filename
argument to be (optionally) quoted if it contains any special
characters (e.g. whit space or quotes).

If the filename does not contain any special characters then nothing
changes.  As an example:

   (gdb) save gdb-index /path/to/some/directory/

will work before and after this patch.  However, if the directory
name contains a white space then before this patch a user would write:

  (gdb) save gdb-index /path/to some/directory/

But this will now fail as GDB will consider this as two arguments,
'/path/to' and 'some/directory/'.  To pass this single directory name
a user must now do one of these:

  (gdb) save gdb-index "/path/to some/directory/"
  (gdb) save gdb-index '/path/to some/directory/'
  (gdb) save gdb-index /path/to\ some/directory/

This brings these commands into line with commands like 'file' and
'symbol-file', which have supported quoted filenames for a while.

The motivation for this change is to make handling of filename
arguments consistent throughout GDB.  We can't move to all commands
taking non-quoted filenames as the non-quoted style only allows for a
single argument.  Additionally, the non-quoted style doesn't allow for
filenames that end in white space (though this is probably pretty
rare).  So, if we want to have consistency the only choice is to move
towards supporting quote filenames.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-09-07 20:28:59 +01:00
Andrew Burgess
dc22ab49e9 gdb: deprecated filename_completer and associated functions
Following on from the previous commit, this commit marks the old
unquoted filename completion related functions as deprecated.

The aim of doing this is to make it more obvious to someone adding a
new command that they should not be using the older unquoted style
filename argument handling.

I split this change from the previous to make for an easier review.
This commit touches more files, but is _just_ function renaming.
Check out gdb/completer.{c,h} for what has been renamed.  All the
other files have just been updated to use the new names.

There should be no user visible changes after this commit.
2024-09-07 20:28:58 +01:00
Simon Marchi
91f378ddd0 gdb: pass inferior to gdbarch_update_p
Make the current inferior reference bubble up one level.  I think this
makes it clearer what gdbarch_update_p, which is update the passed
inferior's architecture (although the function name could probably be
better).

When gdbarch_find_by_info, it is possible for the new architecture's
init callback to be called.  I have not audited all of them (there are
just too many), it's possible that some of them do care about the
current inferior, for some reason (for instance, if one of them makes a
target call).  If so, they should be changed too.

Change-Id: I89f012188d7fdca395a830f4b013743565f26847
2024-08-12 11:10:02 -04:00
Simon Marchi
74e39223b5 gdb: pass inferior to target_current_description
Make the current inferior reference bubble up one level.

Change-Id: I441f954877749dc5a861ab03e881b529dafc2efd
2024-08-12 11:10:01 -04:00
Simon Marchi
5b9707eb87 gdb: remove gdbcmd.h
Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc).  To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h.  This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.

Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-25 12:59:02 -04:00
Simon Marchi
18d2988e5d gdb, gdbserver, gdbsupport: remove includes of early headers
Now that defs.h, server.h and common-defs.h are included via the
`-include` option, it is no longer necessary for source files to include
them.  Remove all the inclusions of these files I could find.  Update
the generation scripts where relevant.

Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837
Approved-By: Pedro Alves <pedro@palves.net>
2024-03-26 21:13:22 -04:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00
Simon Marchi
99d9c3b92c gdb: remove target_gdbarch
This function is just a wrapper around the current inferior's gdbarch.
I find that having that wrapper just obscures where the arch is coming
from, and that it's often used as "I don't know which arch to use so
I'll use this magical target_gdbarch function that gets me an arch" when
the arch should in fact come from something in the context (a thread,
objfile, symbol, etc).  I think that removing it and inlining
`current_inferior ()->arch ()` everywhere will make it a bit clearer
where that arch comes from and will trigger people into reflecting
whether this is the right place to get the arch or not.

Change-Id: I79f14b4e4934c88f91ca3a3155f5fc3ea2fadf6b
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10 10:44:35 -04:00
Tom Tromey
ef0f16ccf8 Remove explanatory comments from includes
I noticed a comment by an include and remembered that I think these
don't really provide much value -- sometimes they are just editorial,
and sometimes they are obsolete.  I think it's better to just remove
them.  Tested by rebuilding.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-20 11:45:16 -06:00
Simon Marchi
886176b865 gdb: introduce field::bitsize / field::set_bitsize
Add these two methods, rename the field to m_bitsize to make it pseudo
private.

Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413
Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31 13:16:13 -04:00
Tom Tromey
77c5f49648 Unify arch_float_type and init_float_type
This unifies arch_float_type and init_float_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
cc495054ad Remove arch_type
This removes arch_type, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
81b86eced2 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.
2023-02-15 08:59:53 -07:00
Simon Marchi
5a19bfd673 gdb: make target_desc_info_from_user_p a method of target_desc_info
Move the implementation over to target_desc_info.  Remove the
target_desc_info forward declaration in target-descriptions.h, it's no
longer needed.

Change-Id: Ic95060341685afe0b73af591ca6efe32f5e7e892
2023-02-03 11:06:26 -05:00
Simon Marchi
5776836631 gdb: remove copy_inferior_target_desc_info
This function is now trivial, we can just copy inferior::tdesc_info
where needed.

Change-Id: I25185e2cd4ba1ef24a822d9e0eebec6e611d54d6
2023-02-03 11:06:26 -05:00
Simon Marchi
6b0b81b9f2 gdb: remove get_tdesc_info
Remove this function, since it's now a trivial access to
inferior::tdesc_info.

Change-Id: I3e88a8214034f1a4163420b434be11f51eef462c
2023-02-03 11:06:26 -05:00
Simon Marchi
79846903c6 gdb: change inferior::tdesc_info to non-pointer
I initially made this field a unique pointer, to have automatic memory
management.  But I then thought that the field didn't really need to be
allocated separately from struct inferior.  So make it a regular
non-pointer field of inferior.

Remove target_desc_info_free, as it's no longer needed.

Change-Id: Ica2b97071226f31c40e86222a2f6922454df1229
2023-02-03 11:06:26 -05:00
Simon Marchi
650160322c gdb: move target_desc_info to inferior.h
In preparation for the following patch, where struct inferior needs to
"see" struct target_desc_info, move target_desc_info to the header file.

I initially moved the structure to target-descriptions.h, and later made
inferior.h include target-descriptions.h.  This worked, but it then
occured to me that target_desc_info is really an inferior property that
involves a target description, so I think it makes sense to have it in
inferior.h.

Change-Id: I3e81d04faafcad431e294357389f3d4c601ee83d
2023-02-03 11:06:26 -05:00
Joel Brobecker
213516ef31 Update copyright year range in header of all files managed by GDB
This commit is the result of running the gdb/copyright.py script,
which automated the update of the copyright year range for all
source files managed by the GDB project to be updated to include
year 2023.
2023-01-01 17:01:16 +04:00
Pedro Alves
f34652de0b internal_error: remove need to pass __FILE__/__LINE__
Currently, every internal_error call must be passed __FILE__/__LINE__
explicitly, like:

  internal_error (__FILE__, __LINE__, "foo %d", var);

The need to pass in explicit __FILE__/__LINE__ is there probably
because the function predates widespread and portable variadic macros
availability.  We can use variadic macros nowadays, and in fact, we
already use them in several places, including the related
gdb_assert_not_reached.

So this patch renames the internal_error function to something else,
and then reimplements internal_error as a variadic macro that expands
__FILE__/__LINE__ itself.

The result is that we now should call internal_error like so:

  internal_error ("foo %d", var);

Likewise for internal_warning.

The patch adjusts all calls sites.  99% of the adjustments were done
with a perl/sed script.

The non-mechanical changes are in gdbsupport/errors.h,
gdbsupport/gdb_assert.h, and gdb/gdbarch.py.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-10-19 15:32:36 +01:00
Keith Seitz
ac9b8c676e Constify target_desc declarations
This patch changes various global target_desc declarations to const, thereby
correcting a prominent source of ODR violations in PowerPC-related target code.
The majority of files/changes are mechanical const-ifications accomplished by
regenerating the C files in features/.

This also required manually updating mips-linux-tdep.h,  s390-linux-tdep.h,
nios2-tdep.h, s390-tdep.h, arch/ppc-linux-tdesc.h, arch/ppc-linux-common.c,
and rs6000-tdep.c.

Patch tested against the sourceware trybot, and fully regression tested against
our (Red Hat's) internal  test infrastructure on Rawhide aarch64, s390x, x86_64,
and powerpcle.

With this patch, I can finally enable LTO in our GDB package builds. [Tested
with a rawhide scratch build containing this patch.]

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24835
2022-09-29 10:00:13 -07:00
Simon Marchi
b6cdbc9a81 gdb: add type::length / type::set_length
Add the `length` and `set_length` methods on `struct type`, in order to remove
the `TYPE_LENGTH` macro.  In this patch, the macro is changed to use the
getter, so all the call sites of the macro that are used as a setter are
changed to use the setter method directly.  The next patch will remove the
macro completely.

Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
2022-09-21 10:59:51 -04:00
Andrew Burgess
b49d7aa744 gdb: Add tdesc_found_register function to tdesc API
This commit adds a new function to the target description API within
GDB.  This new function is not used in this commit, but will be used
in the next commit, I'm splitting it out into a separate patch for
easier review.

What I want to do in the next commit is check to see if a target
description supplied a particular register, however, the register in
question could appear in one of two possible features.

The new function allows me to ask the tdesc_arch_data whether a
register was found and assigned a particular GDB register number once
all of the features have been checked.  I think this is a much simpler
solution than adding code such that, while checking each feature, I
spot if the register I'm processing is the one I care about.

No tests here as the new code is not used, but this code will be
exercised in the next commit.
2022-08-31 16:07:05 +01:00
Tom Tromey
cb275538db Use registry in gdbarch
gdbarch implements its own registry-like approach.  This patch changes
it to instead use registry.h.  It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.

The main benefit of this change is that it introduces type safety to
the gdbarch registry.  It also removes a bunch of code.

One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup.  This
doesn't seem very important to me, though.
2022-08-04 13:28:04 -06:00
Andrew Burgess
af7ce09b76 gdb: move struct reggroup into reggroups.h header
Move 'struct reggroup' into the reggroups.h header.  Remove the
reggroup_name and reggroup_type accessor functions, and just use the
name/type member functions within 'struct reggroup', update all uses
of these removed functions.

There should be no user visible changes after this commit.
2022-04-07 16:01:18 +01:00
Andrew Burgess
dbf5d61bda gdb: make gdbarch_register_reggroup_p take a const reggroup *
Change gdbarch_register_reggroup_p to take a 'const struct reggroup *'
argument.  This requires a change to the gdb/gdbarch-components.py
script, regeneration of gdbarch.{c,h}, and then updates to all the
architectures that implement this method.

There should be no user visible changes after this commit.
2022-04-07 16:01:17 +01:00
Tom Tromey
6cb06a8cda Unify gdb printf functions
Now that filtered and unfiltered output can be treated identically, we
can unify the printf family of functions.  This is done under the name
"gdb_printf".  Most of this patch was written by script.
2022-03-29 12:46:24 -06:00
Tom Tromey
0426ad513f Unify gdb puts functions
Now that filtered and unfiltered output can be treated identically, we
can unify the puts family of functions.  This is done under the name
"gdb_puts".  Most of this patch was written by script.
2022-03-29 12:46:24 -06:00
Tom Tromey
19a7b8ab87 Unify vprintf functions
Now that filtered and unfiltered output can be treated identically, we
can unify the vprintf family of functions: vprintf_filtered,
vprintf_unfiltered, vfprintf_filtered and vfprintf_unfiltered.  (For
the gdb_stdout variants, recall that only printf_unfiltered gets truly
unfiltered output at this point.)  This removes one such function and
renames the remaining two to "gdb_vprintf".  All callers are updated.
Much of this patch was written by script.
2022-03-29 12:46:24 -06:00
Tom Tromey
bf31fd38f0 Move gdb obstack code to gdbsupport
This moves the gdb-specific obstack code -- both extensions like
obconcat and obstack_strdup, and things like auto_obstack -- to
gdbsupport.
2022-01-18 10:14:42 -07:00
Tom Tromey
ec2770563a Use filtered output in target-descriptions.c
target-descriptions.c uses unfiltered output.  However, if you happen
to invoke this command interactively, it's probably better for it to
use filtering.  For non-interactive use, this doesn't matter.
2022-01-05 11:08:44 -07:00
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.

For the avoidance of doubt, all changes in this commits were
performed by the script.
2022-01-01 19:13:23 +04:00
Tom Tromey
7514a66128 Consistently Use ui_file parameter to show callbacks
I happened to notice that one "show" callback was printing to
gdb_stdout rather than to the passed-in ui_file parameter.  I went
through all such callbacks and fixed them to consistently use the
ui_file.

Regression tested on x86-64 Fedora 34.
2021-12-29 11:08:04 -07:00
Simon Marchi
f54bdb6d27 gdb: add add_setshow_prefix_cmd
There's a common pattern to call add_basic_prefix_cmd and
add_show_prefix_cmd to add matching set and show commands.  Add the
add_setshow_prefix_cmd function to factor that out and use it at a few
places.

Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
2021-10-28 10:44:18 -04:00
Simon Marchi
cd3f655cc7 gdb: add accessors for field (and call site) location
Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8
2021-10-07 11:03:54 -04:00
Simon Marchi
e0700ba44c gdb: make string-like set show commands use std::string variable
String-like settings (var_string, var_filename, var_optional_filename,
var_string_noescape) currently take a pointer to a `char *` storage
variable (typically global) that holds the setting's value.  I'd like to
"mordernize" this by changing them to use an std::string for storage.

An obvious reason is that string operations on std::string are often
easier to write than with C strings.  And they avoid having to do any
manual memory management.

Another interesting reason is that, with `char *`, nullptr and an empty
string often both have the same meaning of "no value".  String settings
are initially nullptr (unless initialized otherwise).  But when doing
"set foo" (where `foo` is a string setting), the setting now points to
an empty string.  For example, solib_search_path is nullptr at startup,
but points to an empty string after doing "set solib-search-path".  This
leads to some code that needs to check for both to check for "no value".
Or some code that converts back and forth between NULL and "" when
getting or setting the value.  I find this very error-prone, because it
is very easy to forget one or the other.  With std::string, we at least
know that the variable is not "NULL".  There is only one way of
representing an empty string setting, that is with an empty string.

I was wondering whether the distinction between NULL and "" would be
important for some setting, but it doesn't seem so.  If that ever
happens, it would be more C++-y and self-descriptive to use
optional<string> anyway.

Actually, there's one spot where this distinction mattered, it's in
init_history, for the test gdb.base/gdbinit-history.exp.  init_history
sets the history filename to the default ".gdb_history" if it sees that
the setting was never set - if history_filename is nullptr.  If
history_filename is an empty string, it means the setting was explicitly
cleared, so it leaves it as-is.  With the change to std::string, this
distinction doesn't exist anymore.  This can be fixed by moving the code
that chooses a good default value for history_filename to
_initialize_top.  This is ran before -ex commands are processed, so an
-ex command can then clear that value if needed (what
gdb.base/gdbinit-history.exp tests).

Another small improvement, in my opinion is that we can now easily
give string parameters initial values, by simply initializing the global
variables, instead of xstrdup-ing it in the _initialize function.

In Python and Guile, when registering a string-like parameter, we
allocate (with new) an std::string that is owned by the param_smob (in
Guile) and the parmpy_object (in Python) objects.

This patch started by changing all relevant add_setshow_* commands to
take an `std::string *` instead of a `char **` and fixing everything
that failed to build.  That includes of course all string setting
variable and their uses.

string_option_def now uses an std::string also, because there's a
connection between options and settings (see
add_setshow_cmds_for_options).

The add_path function in source.c is really complex and twisted, I'd
rather not try to change it to work on an std::string right now.
Instead, I added an overload that copies the std:string to a `char *`
and back.  This means more copying, but this is not used in a hot path
at all, so I think it is acceptable.

Change-Id: I92c50a1bdd8307141cdbacb388248e4e4fc08c93
Co-authored-by: Lancelot SIX <lsix@lancelotsix.com>
2021-10-03 17:53:16 +01:00
Simon Marchi
b447dd03c1 gdb: remove gdbarch_info_init
While reviewing another patch, I realized that gdbarch_info_init could
easily be removed in favor of initializing gdbarch_info fields directly
in the struct declaration.  The only odd part is the union.  I don't
know if it's actually important for it to be zero-initialized, but I
presume it is.  I added a constructor to gdbarch_info to take care of
that.  A proper solution would be to use std::variant.  Or, these could
also be separate fields, the little extra space required wouldn't
matter.

gdb/ChangeLog:

	* gdbarch.sh (struct gdbarch_info): Initialize fields, add
	constructor.
	* gdbarch.h: Re-generate.
	* arch-utils.h (gdbarch_info_init): Remove, delete all usages.
	* arch-utils.c (gdbarch_info_init): Remove.

Change-Id: I7502e08fe0f278d84eef1667a072e8a97bda5ab5
2021-06-28 11:49:22 -04:00
Marco Barisione
2f822da535 gdb: generate the prefix name for prefix commands on demand
Previously, the prefixname field of struct cmd_list_element was manually
set for prefix commands.  This seems verbose and error prone as it
required every single call to functions adding prefix commands to
specify the prefix name while the same information can be easily
generated.

Historically, this was not possible as the prefix field was null for
many commands, but this was fixed in commit
3f4d92ebdf by Philippe Waroquiers, so
we can rely on the prefix field being set when generating the prefix
name.

This commit also fixes a use after free in this scenario:
* A command gets created via Python (using the gdb.Command class).
  The prefix name member is dynamically allocated.
* An alias to the new command is created. The alias's prefixname is set
  to point to the prefixname for the original command with a direct
  assignment.
* A new command with the same name as the Python command is created.
* The object for the original Python command gets freed and its
  prefixname gets freed as well.
* The alias is updated to point to the new command, but its prefixname
  is not updated so it keeps pointing to the freed one.

gdb/ChangeLog:

	* command.h (add_prefix_cmd): Remove the prefixname argument as
	it can now be generated automatically.  Update all callers.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.c (add_prefix_cmd): Ditto.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.h (struct cmd_list_element): Replace the
	prefixname member variable with a method which generates the
	prefix name at runtime.  Update all code reading the prefix
	name to use the method, and remove all code setting it.
	* python/py-cmd.c (cmdpy_destroyer): Remove code to free the
	prefixname member as it's now a method.
	(cmdpy_function): Determine if the command is a prefix by
	looking at prefixlist, not prefixname.
2021-05-12 11:19:22 +01:00
Simon Marchi
91e3c425d6 gdb: make target_desc_info::filename an std::string
To make the management of memory automatic.

As to why I chose to make this an std::string and not an
std::unique_xmalloc_ptr<char>: some parts of the code consider both a
NULL value and an empty string value to mean "no filename".
target_desc_info_from_user_p, however, doesn't check for a non-NULL but
empty string value.  So it seems like having two ways of denoting "no
filename" can lead to these kinds of inconsistencies.  Using
std::string, "no filename" is only represented by an empty value.

As a bonus, using an std::string lets us copy target_desc_info objects
using the default assignment operator.

gdb/ChangeLog:

	* target-descriptions.c (struct target_desc_info) <filename>:
	Make std::string.
	(copy_inferior_target_desc_info): Adjust.
	(target_desc_info_free): Adjust.
	(target_find_description): Adjust.
	(set_tdesc_filename_cmd): Adjust.
	(show_tdesc_filename_cmd): Adjust.
	(unset_tdesc_filename_cmd): Adjust.
	(maint_print_c_tdesc_cmd): Adjust.

Change-Id: I4e3a6ad8ccda2b88c202471d4f54249753cad127
2021-05-07 16:28:56 -04:00
Simon Marchi
0b2f7ade53 gdb: (de-)allocate target_desc_info with new/delete
In preparation for using non-POD types in the struct.

gdb/ChangeLog:

	* target-descriptions.c (struct target_desc_info): Initialize
	fields.
	(get_tdesc_info): Use new.
	(target_desc_info_free): Use delete.

Change-Id: I10fdaeeae7cdbd7930ae7adeeb13f7f363c67c7a
2021-05-07 16:28:56 -04:00
Simon Marchi
820c449092 gdb: change target_desc_info::fetched to bool
gdb/ChangeLog:

	* target-descriptions.c (struct target_desc_info) <fetched>:
	bool.
	(target_find_description): Adjust.
	(target_clear_description): Adjust.

Change-Id: Ib69e097b38cf270e674f1249105d535a312954e1
2021-05-07 16:28:56 -04:00
Simon Marchi
c2962e6ab4 gdb: remove target description macros
In my opinion, the target_desc_fetched, current_target_desc and
target_description_filename macros in target-descriptions.c are not very
useful.  I don't think it's useful to hide that they operate on the
current inferior, as everything currently works under the assumption
that the various tdesc commands operate on the current inferior, and I
don't see that changing in the foreseeable future.

This change also avoids having multiple unnecessary calls to
current_inferior and get_tdesc_info per function.

gdb/ChangeLog:

	* target-descriptions.c (struct target_desc_info) <tdesc>:
	Adjust doc.
	(target_desc_fetched): Remove.
	(current_target_desc): Remove.
	(target_description_filename): Remove.
	(target_find_description): Adjust.
	(target_clear_description): Adjust.
	(target_current_description): Adjust.
	(set_tdesc_filename_cmd): Adjust.
	(show_tdesc_filename_cmd): Adjust.
	(unset_tdesc_filename_cmd): Adjust.
	(maint_print_c_tdesc_cmd): Adjust.
	(maint_print_xml_tdesc_cmd): Adjust.

Change-Id: Ibfb581490e949c16d59924e2cac633ede5c26c5b
2021-05-07 16:28:56 -04:00
Simon Marchi
328d42d87e gdb: remove current_top_target function
The current_top_target function is a hidden dependency on the current
inferior.  Since I'd like to slowly move towards reducing our dependency
on the global current state, remove this function and make callers use

  current_inferior ()->top_target ()

There is no expected change in behavior, but this one step towards
making those callers use the inferior from their context, rather than
refer to the global current inferior.

gdb/ChangeLog:

	* target.h (current_top_target): Remove, make callers use the
	current inferior instead.
	* target.c (current_top_target): Remove.

Change-Id: Iccd457036f84466cdaa3865aa3f9339a24ea001d
2021-03-24 18:08:24 -04:00
Joel Brobecker
3666a04883 Update copyright year range in all GDB files
This commits the result of running gdb/copyright.py as per our Start
of New Year procedure...

gdb/ChangeLog

        Update copyright year range in copyright header of all GDB files.
2021-01-01 12:12:21 +04:00
Andrew Burgess
ab33b15255 gdb: add an option flag to 'maint print c-tdesc'
GDB has two approaches to generating the target descriptions found in
gdb/features/, the whole description approach, where the XML file
contains a complete target description which is then used to generate
a single C file that builds that target description.  Or, the split
feature approach, where the XML files contain a single target feature,
each feature results in a single C file to create that one feature,
and then a manually written C file is used to build a complete target
description from individual features.

There's a Makefile, gdb/features/Makefile, which is responsible for
managing the regeneration of the C files from the XML files.

However, some of the logic that selects between the whole description
approach, or the split feature approach, is actually hard-coded into
GDB, inside target-descriptions.c:maint_print_c_tdesc_cmd we check the
path to the incoming XML file and use this to choose which type of C
file we should generate.

This commit removes this hard coding from GDB, and makes the Makefile
entirely responsible for choosing the approach.  This makes sense as
the Makefile already has the XML files partitioned based on which
approach they should use.

In order to allow this change the 'maint print c-tdesc' command is
given a new command option '-single-feature', which tells GDB which
type of C file should be created.  The makefile now supplies this flag
to GDB.

This did reveal a bug in features/Makefile, the rx.xml file was in the
wrong list, this didn't matter previously as the actual choice of
which approach to use was done in GDB.  Now the Makefile decides, so
placing each XML file in the correct list is critical.

Tested this by doing 'make GDB=/path/to/gdb clean-cfiles cfiles' to
regenerate all the C files from their XML source.  There are no
changes after this commit.

gdb/ChangeLog:

	* features/Makefile (XMLTOC): Add rx.xml.
	(FEATURE_XMLFILES): Remove rx.xml.
	(FEATURE_CFILES rule): Pass '-single-feature' flag.
	* features/rx.c: Regenerate.
	* features/rx.xml: Wrap in `target` tags, and reindent.
	* target-descriptions.c (struct maint_print_c_tdesc_options): New
	structure.
	(maint_print_c_tdesc_opt_def): New typedef.
	(maint_print_c_tdesc_opt_defs): New static global.
	(make_maint_print_c_tdesc_options_def_group): New function.
	(maint_print_c_tdesc_cmd): Make use of command line flags, only
	print single feature C file for target descriptions containing a
	single feature.
	(maint_print_c_tdesc_cmd_completer): New function.
	(_initialize_target_descriptions): Update call to register command
	completer, and include command line flag in help text.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Update description of 'maint
	print c-tdesc'.
2020-11-12 09:44:00 +00:00
Andrew Burgess
51a948fdf0 gdb: Have allocate_target_description return a unique_ptr
Update allocate_target_description to return a target_desc_up, a
specialisation of unique_ptr.

This commit does not attempt to make use of the unique_ptr in the
best possible way, in almost all cases we immediately release the
pointer from within the unique_ptr and then continue as before.

There are a few places where it was easy to handle the unique_ptr, and
in these cases I've done that.

Everything under gdb/features/* is auto-regenerated.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* arch/aarch32.c (aarch32_create_target_description): Release
	unique_ptr returned from allocate_target_description.
	* arch/aarch64.c (aarch64_create_target_description): Likewise.
	* arch/amd64.c (amd64_create_target_description): Likewise.
	* arch/arc.c (arc_create_target_description): Likewise.
	* arch/arm.c (arm_create_target_description): Likewise.
	* arch/i386.c (i386_create_target_description): Likewise.
	* arch/riscv.c (riscv_create_target_description): Update return
	type.  Handle allocate_target_description returning a unique_ptr.
	(riscv_lookup_target_description): Update to handle unique_ptr.
	* arch/tic6x.c (tic6x_create_target_description): Release
	unique_ptr returned from allocate_target_description.
	* features/microblaze-with-stack-protect.c: Regenerate.
	* features/microblaze.c: Regenerate.
	* features/mips-dsp-linux.c: Regenerate.
	* features/mips-linux.c: Regenerate.
	* features/mips64-dsp-linux.c: Regenerate.
	* features/mips64-linux.c: Regenerate.
	* features/nds32.c: Regenerate.
	* features/nios2.c: Regenerate.
	* features/or1k.c: Regenerate.
	* features/rs6000/powerpc-32.c: Regenerate.
	* features/rs6000/powerpc-32l.c: Regenerate.
	* features/rs6000/powerpc-403.c: Regenerate.
	* features/rs6000/powerpc-403gc.c: Regenerate.
	* features/rs6000/powerpc-405.c: Regenerate.
	* features/rs6000/powerpc-505.c: Regenerate.
	* features/rs6000/powerpc-601.c: Regenerate.
	* features/rs6000/powerpc-602.c: Regenerate.
	* features/rs6000/powerpc-603.c: Regenerate.
	* features/rs6000/powerpc-604.c: Regenerate.
	* features/rs6000/powerpc-64.c: Regenerate.
	* features/rs6000/powerpc-64l.c: Regenerate.
	* features/rs6000/powerpc-7400.c: Regenerate.
	* features/rs6000/powerpc-750.c: Regenerate.
	* features/rs6000/powerpc-860.c: Regenerate.
	* features/rs6000/powerpc-altivec32.c: Regenerate.
	* features/rs6000/powerpc-altivec32l.c: Regenerate.
	* features/rs6000/powerpc-altivec64.c: Regenerate.
	* features/rs6000/powerpc-altivec64l.c: Regenerate.
	* features/rs6000/powerpc-e500.c: Regenerate.
	* features/rs6000/powerpc-e500l.c: Regenerate.
	* features/rs6000/powerpc-isa205-32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-altivec32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-altivec64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa207-htm-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa207-htm-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa207-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa207-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-vsx32.c: Regenerate.
	* features/rs6000/powerpc-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-vsx64.c: Regenerate.
	* features/rs6000/powerpc-vsx64l.c: Regenerate.
	* features/rs6000/rs6000.c: Regenerate.
	* features/rx.c: Regenerate.
	* features/s390-gs-linux64.c: Regenerate.
	* features/s390-linux32.c: Regenerate.
	* features/s390-linux32v1.c: Regenerate.
	* features/s390-linux32v2.c: Regenerate.
	* features/s390-linux64.c: Regenerate.
	* features/s390-linux64v1.c: Regenerate.
	* features/s390-linux64v2.c: Regenerate.
	* features/s390-te-linux64.c: Regenerate.
	* features/s390-tevx-linux64.c: Regenerate.
	* features/s390-vx-linux64.c: Regenerate.
	* features/s390x-gs-linux64.c: Regenerate.
	* features/s390x-linux64.c: Regenerate.
	* features/s390x-linux64v1.c: Regenerate.
	* features/s390x-linux64v2.c: Regenerate.
	* features/s390x-te-linux64.c: Regenerate.
	* features/s390x-tevx-linux64.c: Regenerate.
	* features/s390x-vx-linux64.c: Regenerate.
	* mips-tdep.c (_initialize_mips_tdep): Release unique_ptr returned
	from allocate_target_description.
	* target-descriptions.c (allocate_target_description): Update
	return type.
	(print_c_tdesc::visit_pre): Release unique_ptr returned from
	allocate_target_description.

gdbserver/ChangeLog:

	* linux-low.cc (linux_process_target::handle_extended_wait):
	Release the unique_ptr returned from allocate_target_description.
	* linux-riscv-low.cc (riscv_target::low_arch_setup): Likewise.
	* linux-x86-low.cc (tdesc_amd64_linux_no_xml): Change type.
	(tdesc_i386_linux_no_xml): Change type.
	(x86_linux_read_description): Borrow pointer from unique_ptr
	object.
	(x86_target::get_ipa_tdesc_idx): Likewise.
	(initialize_low_arch): Likewise.
	* tdesc.cc (allocate_target_description): Update return type.

gdbsupport/ChangeLog:

	* tdesc.h (allocate_target_description): Update return type.
2020-10-08 10:14:14 +01:00
Tom Tromey
c1e1314d00 Change management of tdesc_arch_data
While working on something else, I noticed that tdesc_data_cleanup
took a void* parameter.  Looking more into this, I found that
tdesc_use_registers expected a transfer of ownership.

I think it's better to express this sort of thing via the type system,
when possible.  This patch changes tdesc_data_alloc to return a unique
pointer, changes tdesc_use_registers to accept an rvalue reference,
and then adapts all the users.

Note that a deleter structure is introduced to avoid having to move
tdesc_arch_data to the header file.

2020-09-17  Tom Tromey  <tromey@adacore.com>

	* tic6x-tdep.c (tic6x_gdbarch_init): Update.
	* target-descriptions.h (struct tdesc_arch_data_deleter): New.
	(tdesc_arch_data_up): New typedef.
	(tdesc_use_registers, tdesc_data_alloc): Update.
	(tdesc_data_cleanup): Don't declare.
	* target-descriptions.c (tdesc_data_alloc): Return a
	tdesc_arch_data_up.
	(tdesc_arch_data_deleter::operator()): Rename from
	tdesc_data_cleanup.  Change argument type.
	(tdesc_use_registers): Change early_data to an rvalue reference.
	(tdesc_use_registers): Don't use delete.
	* sparc-tdep.c (sparc32_gdbarch_init): Update.
	* s390-tdep.c (s390_gdbarch_init): Update.
	* rx-tdep.c (rx_gdbarch_init): Update.
	* rs6000-tdep.c (rs6000_gdbarch_init): Update.
	* riscv-tdep.c (riscv_gdbarch_init): Update.
	* or1k-tdep.c (or1k_gdbarch_init): Update.
	* nios2-tdep.c (nios2_gdbarch_init): Update.
	* nds32-tdep.c (nds32_gdbarch_init): Update.
	* mips-tdep.c (mips_gdbarch_init): Update.
	* microblaze-tdep.c (microblaze_gdbarch_init): Update.
	* m68k-tdep.c (m68k_gdbarch_init): Update.
	* i386-tdep.c (i386_gdbarch_init): Update.
	* arm-tdep.c (arm_gdbarch_init): Update.
	* arc-tdep.c (arc_tdesc_init): Update.
	(arc_gdbarch_init): Update.
	* aarch64-tdep.c (aarch64_gdbarch_init): Update.
2020-09-17 14:28:06 -06:00