Commit Graph

364 Commits

Author SHA1 Message Date
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
Tom Tromey
beadf91284 Add extension_language_ops::shutdown
Right now, Python is shut down via a final cleanup.  However, it seems
to me that it is better for extension languages to be shut down
explicitly, after all the ordinary final cleanups are run.  The main
reason for this is that a subsequent patch adds another case like
finalize_values; and rather than add a series of workarounds for
Python shutdown, it seemed better to let these be done via final
cleanups, and then have Python shutdown itself be the special case.
2024-02-27 10:30:29 -07:00
Lancelot SIX
878e894801 gdb: Use SYM_DOMAIN instead of DOMAIN when calling sym-domains.def
Since commit 6771fc6f1d "Use a .def file for domain_enum", the
sym-domains.def file has been introduced, and requires the user to
define the DOMAIN(x) macro.

On older systems (centos-7 with glibc-2.17 for example), this DOMAIN
macro conflicts with another macro defined in /usr/include/math.h.

Fix this conflict by changing sym-domains.def to use a macro named
SYM_DOMAIN instead of DOMAIN.

Change-Id: I679df30e2bd2f4333343f16bbd2a3511a37550a3
Approved-By: Tom Tromey <tom@tromey.com>
2024-01-29 20:20:30 +00:00
Tom Tromey
ccf41c2487 Use domain_search_flags in lookup_symbol et al
This changes lookup_symbol and associated APIs to accept
domain_search_flags rather than a domain_enum.

Note that this introduces some new constants to Python and Guile.  I
chose to break out the documentation patch for this, because the
internals here do not change until a later patch, and it seemed
simpler to patch the docs just once, rather than twice.
2024-01-28 10:58:16 -07:00
Tom Tromey
6771fc6f1d Use a .def file for domain_enum
Future patches will change and reuse the names from domain_enum.  This
patch makes this less error-prone by having a single point to define
these names, using the typical gdb ".def" file.
2024-01-28 10:58:16 -07: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
a7952927db gdb: change value_of_register and value_of_register_lazy to take the next frame
Some functions related to the handling of registers in frames accept
"this frame", for which we want to read or write the register values,
while other functions accept "the next frame", which is the frame next
to that.  The later is needed because we sometimes need to read register
values for a frame that does not exist yet (usually when trying to
unwind that frame-to-be).

value_of_register and value_of_register_lazy both take "this frame",
even if what they ultimately want internally is "the next frame".  This
is annoying if you are in a spot that currently has "the next frame" and
need to call one of these functions (which happens later in this
series).  You need to get the previous frame only for those functions to
get the next frame again.  This is more manipulations, more chances of
mistake.

I propose to change these functions (and a few more functions in the
subsequent patches) to operate on "the next frame".  Things become a bit
less awkward when all these functions agree on which frame they take.

So, in this patch, change value_of_register_lazy and value_of_register
to take "the next frame" instead of "this frame".  This adds a lot of
get_next_frame_sentinel_okay, but if we convert the user registers API
to also use "the next frame" instead of "this frame", it will get simple
again.

Change-Id: Iaa24815e648fbe5ae3c214c738758890a91819cd
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
2023-12-14 16:04:49 +00:00
Lancelot Six
6b09f1342c gdb: Replace gdb::optional with std::optional
Since GDB now requires C++17, we don't need the internally maintained
gdb::optional implementation.  This patch does the following replacing:
  - gdb::optional -> std::optional
  - gdb::in_place -> std::in_place
  - #include "gdbsupport/gdb_optional.h" -> #include <optional>

This change has mostly been done automatically.  One exception is
gdbsupport/thread-pool.* which did not use the gdb:: prefix as it
already lives in the gdb namespace.

Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21 11:52:35 +00:00
Simon Marchi
74ce4f8ecf gdb: add program_space parameters to some auto-load functions
Make the current_program_space references bubble up a bit.

Change-Id: Id047a48cc8d8a45504cdbb5960bafe3e7735d652
Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05 13:20:50 -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
Tom Tromey
bcafd1c19e Use gdb::checked_static_cast for watchpoints
This replaces some casts to 'watchpoint *' with checked_static_cast.
In one spot, an unnecessary block is also removed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-09-19 08:14:00 -06:00
Simon Marchi
6c0f749351 gdb: remove FIELD_ARTIFICIAL
Replace uses with field::is_artificial.

Change-Id: I599616fdd9f4b6d044de492e8151aa6130725cd1
Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31 13:16:12 -04:00
Andrew Burgess
b080fe54fb gdb: add inferior-specific breakpoints
This commit extends the breakpoint mechanism to allow for inferior
specific breakpoints (but not watchpoints in this commit).

As GDB gains better support for multiple connections, and so for
running multiple (possibly unrelated) inferiors, then it is not hard
to imagine that a user might wish to create breakpoints that apply to
any thread in a single inferior.  To achieve this currently, the user
would need to create a condition possibly making use of the $_inferior
convenience variable, which, though functional, isn't the most user
friendly.

This commit adds a new 'inferior' keyword that allows for the creation
of inferior specific breakpoints.

Inferior specific breakpoints are automatically deleted when the
associated inferior is removed from GDB, this is similar to how
thread-specific breakpoints are deleted when the associated thread is
deleted.

Watchpoints are already per-program-space, which in most cases mean
watchpoints are already inferior specific.  There is a small window
where inferior-specific watchpoints might make sense, which is after a
vfork, when two processes are sharing the same address space.
However, I'm leaving that as an exercise for another day.  For now,
attempting to use the inferior keyword with a watchpoint will give an
error, like this:

  (gdb) watch a8 inferior 1
  Cannot use 'inferior' keyword with watchpoints

A final note on the implementation: currently, inferior specific
breakpoints, like thread-specific breakpoints, are inserted into every
inferior, GDB then checks once the inferior stops if we are in the
correct thread or inferior, and resumes automatically if we stopped in
the wrong thread/inferior.

An obvious optimisation here is to only insert breakpoint locations
into the specific program space (which mostly means inferior) that
contains either the inferior or thread we are interested in.  This
would reduce the number times GDB has to stop and then resume again in
a multi-inferior setup.

I have a series on the mailing list[1] that implements this
optimisation for thread-specific breakpoints.  Once this series has
landed I'll update that series to also handle inferior specific
breakpoints in the same way.  For now, inferior specific breakpoints
are just slightly less optimal, but this is no different to
thread-specific breakpoints in a multi-inferior debug session, so I
don't see this as a huge problem.

[1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
2023-08-17 16:42:39 +01:00
Tom de Vries
6a93ab8af4 [gdb/build] Fix enum param_types odr violation
When building gdb with -O2 -flto, I run into:
...
gdb/guile/scm-param.c:121:6: warning: type 'param_types' violates the C++ \
  One Definition Rule [-Wodr]
 enum param_types
      ^
gdb/python/py-param.c:33:6: note: an enum with different value name is \
  defined in another translation unit
 enum param_types
      ^
...

Fix this by renaming to enum scm_param_types and py_param_types.

Tested on x86_64-linux.

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

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14 18:32:29 +02:00
Andrew Burgess
baab375361 gdb: building inferior strings from within GDB
History Of This Patch
=====================

This commit aims to address PR gdb/21699.  There have now been a
couple of attempts to fix this issue.  Simon originally posted two
patches back in 2021:

  https://sourceware.org/pipermail/gdb-patches/2021-July/180894.html
  https://sourceware.org/pipermail/gdb-patches/2021-July/180896.html

Before Pedro then posted a version of his own:

  https://sourceware.org/pipermail/gdb-patches/2021-July/180970.html

After this the conversation halted.  Then in 2023 I (Andrew) also took
a look at this bug and posted two versions:

  https://sourceware.org/pipermail/gdb-patches/2023-April/198570.html
  https://sourceware.org/pipermail/gdb-patches/2023-April/198680.html

The approach taken in my first patch was pretty similar to what Simon
originally posted back in 2021.  My second attempt was only a slight
variation on the first.

Pedro then pointed out his older patch, and so we arrive at this
patch.  The GDB changes here are mostly Pedro's work, but updated by
me (Andrew), any mistakes are mine.

The tests here are a combinations of everyone's work, and the commit
message is new, but copies bits from everyone's earlier work.

Problem Description
===================

Bug PR gdb/21699 makes the observation that using $_as_string with
GDB's printf can cause GDB to print unexpected data from the
inferior.  The reproducer is pretty simple:

  #include <stddef.h>
  static char arena[100];

  /* Override malloc() so value_coerce_to_target() gets a known
     pointer, and we know we"ll see an error if $_as_string() gives
     a string that isn't null terminated. */
  void
  *malloc (size_t size)
  {
      memset (arena, 'x', sizeof (arena));
      if (size > sizeof (arena))
          return NULL;
      return arena;
  }

  int
  main ()
  {
    return 0;
  }

And then in a GDB session:

  $ gdb -q test
  Reading symbols from /tmp/test...
  (gdb) start
  Temporary breakpoint 1 at 0x4004c8: file test.c, line 17.
  Starting program: /tmp/test

  Temporary breakpoint 1, main () at test.c:17
  17        return 0;
  (gdb) printf "%s\n", $_as_string("hello")
  "hello"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  (gdb) quit

The problem above is caused by how value_cstring is used within
py-value.c, but once we understand the issue then it turns out that
value_cstring is used in an unexpected way in many places within GDB.

Within py-value.c we have a null-terminated C-style string.  We then
pass a pointer to this string, along with the length of this
string (so not including the null-character) to value_cstring.

In value_cstring GDB allocates an array value of the given character
type, and copies in requested number of characters.  However
value_cstring does not add a null-character of its own.  This means
that the value created by calling value_cstring is only
null-terminated if the null-character is included in the passed in
length.  In py-value.c this is not the case, and indeed, in most uses
of value_cstring, this is not the case.

When GDB tries to print one of these strings the value contents are
pushed to the inferior, and then read back as a C-style string, that
is, GDB reads inferior memory until it finds a null-terminator.  For
the py-value.c case, no null-terminator is pushed into the inferior,
so GDB will continue reading inferior memory until a null-terminator
is found, with unpredictable results.

Patch Description
=================

The first thing this patch does is better define what the arguments
for the two function value_cstring and value_string should represent.
The comments in the header file are updated to describe whether the
length argument should, or should not, include a null-character.
Also, the data argument is changed to type gdb_byte.  The functions as
they currently exist will handle wide-characters, in which case more
than one 'char' would be needed for each character.  As such using
gdb_byte seems to make more sense.

To avoid adding casts throughout GDB, I've also added an overload that
still takes a 'char *', but asserts that the character type being used
is of size '1'.

The value_cstring function is now responsible for adding a null
character at the end of the string value it creates.

However, once we start looking at how value_cstring is used, we
realise there's another, related, problem.  Not every language's
strings are null terminated.  Fortran and Ada strings, for example,
are just an array of characters, GDB already has the function
value_string which can be used to create such values.

Consider this example using current GDB:

  (gdb) set language ada
  (gdb) p $_gdb_setting("arch")
  $1 = (97, 117, 116, 111)
  (gdb) ptype $
  type = array (1 .. 4) of char
  (gdb) p $_gdb_maint_setting("test-settings string")
  $2 = (0)
  (gdb) ptype $
  type = array (1 .. 1) of char

This shows two problems, first, the $_gdb_setting and
$_gdb_maint_setting functions are calling value_cstring using the
builtin_char character, rather than a language appropriate type.  In
the first call, the 'arch' case, the value_cstring call doesn't
include the null character, so the returned array only contains the
expected characters.  But, in the $_gdb_maint_setting example we do
end up including the null-character, even though this is not expected
for Ada strings.

This commit adds a new language method language_defn::value_string,
this function takes a pointer and length and creates a language
appropriate value that represents the string.  For C, C++, etc this
will be a null-terminated string (by calling value_cstring), and for
Fortran and Ada this can be a bounded array of characters with no null
terminator.  Additionally, this new language_defn::value_string
function is responsible for selecting a language appropriate character
type.

After this commit the only calls to value_cstring are from the C
expression evaluator and from the default language_defn::value_string.

And the only calls to value_string are from Fortan, Ada, and ObjectC
related code.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21699

Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-06-05 13:25:08 +01:00
Tom de Vries
33b5899fc0 [gdb] Fix typos
Fix a few typos:
- implemention -> implementation
- convertion(s) -> conversion(s)
- backlashes -> backslashes
- signoring -> ignoring
- (un)ambigious -> (un)ambiguous
- occured -> occurred
- hidding -> hiding
- temporarilly -> temporarily
- immediatelly -> immediately
- sillyness -> silliness
- similiar -> similar
- porkuser -> pokeuser
- thats -> that
- alway -> always
- supercede -> supersede
- accomodate -> accommodate
- aquire -> acquire
- priveleged -> privileged
- priviliged -> privileged
- priviledges -> privileges
- privilige -> privilege
- recieve -> receive
- (p)refered -> (p)referred
- succesfully -> successfully
- successfuly -> successfully
- responsability -> responsibility
- wether -> whether
- wich -> which
- disasbleable -> disableable
- descriminant -> discriminant
- construcstor -> constructor
- underlaying -> underlying
- underyling -> underlying
- structureal -> structural
- appearences -> appearances
- terciarily -> tertiarily
- resgisters -> registers
- reacheable -> reachable
- likelyhood -> likelihood
- intepreter -> interpreter
- disassemly -> disassembly
- covnersion -> conversion
- conviently -> conveniently
- atttribute -> attribute
- struction -> struct
- resonable -> reasonable
- popupated -> populated
- namespaxe -> namespace
- intialize -> initialize
- identifer(s) -> identifier(s)
- expection -> exception
- exectuted -> executed
- dungerous -> dangerous
- dissapear -> disappear
- completly -> completely
- (inter)changable -> (inter)changeable
- beakpoint -> breakpoint
- automativ -> automatic
- alocating -> allocating
- agressive -> aggressive
- writting -> writing
- reguires -> requires
- registed -> registered
- recuding -> reducing
- opeartor -> operator
- ommitted -> omitted
- modifing -> modifying
- intances -> instances
- imbedded -> embedded
- gdbaarch -> gdbarch
- exection -> execution
- direcive -> directive
- demanged -> demangled
- decidely -> decidedly
- argments -> arguments
- agrument -> argument
- amespace -> namespace
- targtet -> target
- supress(ed) -> suppress(ed)
- startum -> stratum
- squence -> sequence
- prompty -> prompt
- overlow -> overflow
- memember -> member
- languge -> language
- geneate -> generate
- funcion -> function
- exising -> existing
- dinking -> syncing
- destroh -> destroy
- clenaed -> cleaned
- changep -> changedp (name of variable)
- arround -> around
- aproach -> approach
- whould -> would
- symobl -> symbol
- recuse -> recurse
- outter -> outer
- freeds -> frees
- contex -> context

Tested on x86_64-linux.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-03 22:43:57 +02:00
Tom de Vries
26236df340 [gdb/guile] Fix doc string for value-optimized-out?
In gdb/guile/scm-value.c, I noticed in the value_functions array initializer:
...
  { "value-optimized-out?", 1, 0, 0,
    as_a_scm_t_subr (gdbscm_value_optimized_out_p),
    "\
Return #t if the value has been optimizd out." },
...
There's a typo in the doc string.

Fix this by using "optimized".

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-03 22:43:57 +02:00
Simon Marchi
a1decfc1df gdb: remove breakpoint_pointer_iterator
Remove the breakpoint_pointer_iterator layer.  Adjust all users of
all_breakpoints and all_tracepoints to use references instead of
pointers.

Change-Id: I376826f812117cee1e6b199c384a10376973af5d
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:52:22 -04:00
Tom Tromey
9c0fb73485 Add dynamic_prop::is_constant
I noticed many spots checking whether a dynamic property's kind is
PROP_CONST.  Some spots, I think, are doing a slightly incorrect check
-- checking for != PROP_UNDEFINED where == PROP_CONST is actually
required, the key thing being that const_val may only be called for
PROP_CONST properties.

This patch adds dynamic::is_constant and then updates these checks to
use it.

Regression tested on x86-64 Fedora 36.
2023-05-12 12:30:28 -06:00
Simon Marchi
13d03262f2 gdb: move struct ui and related things to ui.{c,h}
I'd like to move some things so they become methods on struct ui.  But
first, I think that struct ui and the related things are big enough to
deserve their own file, instead of being scattered through top.{c,h} and
event-top.c.

Change-Id: I15594269ace61fd76ef80a7b58f51ff3ab6979bc
2023-05-01 15:40:54 -04:00
Simon Marchi
287de65625 gdb, gdbserver, gdbsupport: fix whitespace issues
Replace spaces with tabs in a bunch of places.

Change-Id: If0f87180f1d13028dc178e5a8af7882a067868b0
2023-03-09 16:32:00 -05:00
Kevin Buettner
53f1f3d4aa Guile QUIT processing updates
This commit contains QUIT processing updates for GDB's Guile support.
As with the Python updates, we don't want to permit this code to
swallow the exception, gdb_exception_forced_quit, which is associated
with GDB receiving a SIGTERM.

I've adopted the same solution that I used for Python; whereever
a gdb_exception is caught in try/catch code in the Guile extension
language support, a catch for gdb_exception_forced_quit has been
added; this catch block will simply call quit_force(), which will
cause the necessary cleanups to occur followed by GDB exiting.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761
Tested-by: Tom de Vries <tdevries@suse.de>
Approved-By: Pedro Alves <pedro@palves.net>
2023-02-27 16:20:39 -07:00
Tom Tromey
1c49bb455c Convert explicit iterator uses to foreach
This converts most existing explicit uses of block_iterator to use
foreach with the range iterator instead.
2023-02-19 12:51:06 -07:00
Tom Tromey
d24e14a0c6 Convert block_static_block and block_global_block to methods
This converts block_static_block and block_global_block to be methods.
This was mostly written by script.  It was simpler to convert them at
the same time because they're often used near each other.
2023-02-19 12:51:06 -07:00
Tom Tromey
0d0f488e1d 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>
2023-02-13 15:22:17 -07:00
Tom Tromey
e3fb3c4772 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>
2023-02-13 15:22:17 -07:00
Tom Tromey
d00664dbba 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>
2023-02-13 15:22:17 -07:00
Tom Tromey
cda0334434 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>
2023-02-13 15:22:16 -07:00
Tom Tromey
efaf1ae025 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>
2023-02-13 15:22:16 -07:00
Tom Tromey
cdf3de175d 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>
2023-02-13 15:22:16 -07:00
Tom Tromey
78259c365f 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>
2023-02-13 15:22:04 -07:00
Tom Tromey
ee7bb2944b Turn value_zero into static "constructor"
This turns value_zero into a static "constructor" of value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13 15:21:08 -07:00
Tom Tromey
9feb2d07de 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>
2023-02-13 15:21:07 -07:00
Tom Tromey
3ee3b2700d 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>
2023-02-13 15:21:07 -07:00
Tom Tromey
d0c9791728 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>
2023-02-13 15:21:06 -07:00
Andrew Burgess
2ecee23675 gdb: use -1 for breakpoint::task default value
Within the breakpoint struct we have two fields ::thread and ::task
which are used for thread or task specific breakpoints.  When a
breakpoint doesn't have a specific thread or task then these fields
have the values -1 and 0 respectively.

There's no particular reason (as far as I can tell) why these two
"default" values are different, and I find the difference a little
confusing.  Long term I'd like to potentially fold these two fields
into a single field, but that isn't what this commit does.

What this commit does is switch to using -1 as the "default" value for
both fields, this means that the default for breakpoint::task has
changed from 0 to -1.   I've updated all the code I can find that
relied on the value of 0, and I see no test regressions, especially in
gdb.ada/tasks.exp, which still fully passes.

There should be no user visible changes after this commit.

Approved-By: Pedro Alves <pedro@palves.net>
2023-02-12 05:46:44 +00:00
Andrew Burgess
0a9ccb9dd7 gdb: only allow one of thread or task on breakpoints or watchpoints
After this mailing list posting:

  https://sourceware.org/pipermail/gdb-patches/2023-February/196607.html

it seems to me that in practice an Ada task maps 1:1 with a GDB
thread, and so it doesn't really make sense to allow uses to give both
a thread and a task within a single breakpoint or watchpoint
condition.

This commit updates GDB so that the user will get an error if both
are specified.

I've added new tests to cover the CLI as well as the Python and Guile
APIs.  For the Python and Guile testing, as far as I can tell, this
was the first testing for this corner of the APIs, so I ended up
adding more than just a single test.

For documentation I've added a NEWS entry, but I've not added anything
to the docs themselves.  Currently we document the commands with a
thread-id or task-id as distinct command, e.g.:

  'break LOCSPEC task TASKNO'
  'break LOCSPEC task TASKNO if ...'
  'break LOCSPEC thread THREAD-ID'
  'break LOCSPEC thread THREAD-ID if ...'

As such, I don't believe there is any indication that combining 'task'
and 'thread' would be expected to work; it seems clear to me in the
above that those four options are all distinct commands.

I think the NEWS entry is enough that if someone is combining these
keywords (it's not clear what the expected behaviour would be in this
case) then they can figure out that this was a deliberate change in
GDB, but for a new user, the manual doesn't suggest combining them is
OK, and any future attempt to combine them will give an error.

Approved-By: Pedro Alves <pedro@palves.net>
2023-02-12 05:46:44 +00:00
Maciej W. Rozycki
7aeb03e2d4 GDB: Allow arbitrary keywords in integer set commands
Rather than just `unlimited' allow the integer set commands (or command
options) to define arbitrary keywords for the user to use, removing
hardcoded arrangements for the `unlimited' keyword.

Remove the confusingly named `var_zinteger', `var_zuinteger' and
`var_zuinteger_unlimited' `set'/`show' command variable types redefining
them in terms of `var_uinteger', `var_integer' and `var_pinteger', which
have the range of [0;UINT_MAX], [INT_MIN;INT_MAX], and [0;INT_MAX] each.

Following existing practice `var_pinteger' allows extra negative values
to be used, however unlike `var_zuinteger_unlimited' any number of such
values can be defined rather than just `-1'.

The "p" in `var_pinteger' stands for "positive", for the lack of a more
appropriate unambiguous letter, even though 0 obviously is not positive;
"n" would be confusing as to whether it stands for "non-negative" or
"negative".

Add a new structure, `literal_def', the entries of which define extra
keywords allowed for a command and numerical values they correspond to.
Those values are not verified against the basic range supported by the
underlying variable type, allowing extra values to be allowed outside
that range, which may or may not be individually made visible to the
user.  An optional value translation is possible with the structure to
follow the existing practice for some commands where user-entered 0 is
internally translated to UINT_MAX or INT_MAX.  Such translation can now
be arbitrary.  Literals defined by this structure are automatically used
for completion as necessary.

So for example:

const literal_def integer_unlimited_literals[] =
  {
    { "unlimited", INT_MAX, 0 },
    { nullptr }
  };

defines an extra `unlimited' keyword and a user-visible 0 value, both of
which get translated to INT_MAX for the setting to be used with.

Similarly:

const literal_def zuinteger_unlimited_literals[] =
  {
    { "unlimited", -1, -1 },
    { nullptr }
  };

defines the same keyword and a corresponding user-visible -1 value that
is used for the requested setting.  If the last member were omitted (or
set to `{}') here, then only the keyword would be allowed for the user
to enter and while -1 would still be used internally trying to enter it
as a part of a command would result in an "integer -1 out of range"
error.

Use said error message in all cases (citing the invalid value requested)
replacing "only -1 is allowed to set as unlimited" previously used for
`var_zuinteger_unlimited' settings only rather than propagating it to
`var_pinteger' type.  It could only be used for the specific case where
a single extra `unlimited' keyword was defined standing for -1 and the
use of numeric equivalents is discouraged anyway as it is for historical
reasons only that they expose GDB internals, confusingly different
across variable types.  Similarly update the "must be >= -1" Guile error
message.

Redefine Guile and Python parameter types in terms of the new variable
types and interpret extra keywords as Scheme keywords and Python strings
used to communicate corresponding parameter values.  Do not add a new
PARAM_INTEGER Guile parameter type, however do handle the `var_integer'
variable type now, permitting existing parameters defined by GDB proper,
such as `listsize', to be accessed from Scheme code.

With these changes in place it should be trivial for a Scheme or Python
programmer to expand the syntax of the `make-parameter' command and the
`gdb.Parameter' class initializer to have arbitrary extra literals along
with their internal representation supplied.

Update the testsuite accordingly.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-01-19 21:15:56 +00: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
Tom Tromey
dad6b350f9 Use bool constants for value_print_options
This changes the uses of value_print_options to use 'true' and 'false'
rather than integers.
2022-12-19 08:18:59 -07:00
Andrew Burgess
8eb7d135e3 gdb/disasm: mark functions passed to the disassembler noexcept
While working on another patch, Simon pointed out that GDB could be
improved by marking the functions passed to the disassembler as
noexcept.

  https://sourceware.org/pipermail/gdb-patches/2022-October/193084.html

The reason this is important is the on some hosts, libopcodes, being C
code, will not be compiled with support for handling exceptions.  As
such, an attempt to throw an exception over libopcodes code will cause
GDB to terminate.

See bug gdb/29712 for an example of when this happened.

In this commit all the functions that are passed to the disassembler,
and which might be used as callbacks by libopcodes are marked
noexcept.

Ideally, I would have liked to change these typedefs:

  using read_memory_ftype = decltype (disassemble_info::read_memory_func);
  using memory_error_ftype = decltype (disassemble_info::memory_error_func);
  using print_address_ftype = decltype (disassemble_info::print_address_func);
  using fprintf_ftype = decltype (disassemble_info::fprintf_func);
  using fprintf_styled_ftype = decltype (disassemble_info::fprintf_styled_func);

which are declared in disasm.h, as including the noexcept keyword.
However, when I tried this, I ran into this warning/error:

  In file included from ../../src/gdb/disasm.c:25:
  ../../src/gdb/disasm.h: In constructor ‘gdb_printing_disassembler::gdb_printing_disassembler(gdbarch*, ui_file*, gdb_disassemble_info::read_memory_ftype, gdb_disassemble_info::memory_error_ftype, gdb_disassemble_info::print_address_ftype)’:
  ../../src/gdb/disasm.h:116:3: error: mangled name for ‘gdb_printing_disassembler::gdb_printing_disassembler(gdbarch*, ui_file*, gdb_disassemble_info::read_memory_ftype, gdb_disassemble_info::memory_error_ftype, gdb_disassemble_info::print_address_ftype)’ will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type]
    116 |   gdb_printing_disassembler (struct gdbarch *gdbarch,
        |   ^~~~~~~~~~~~~~~~~~~~~~~~~

So I've left that change out.  This does mean that if somebody adds a
new use of the disassembler classes in the future, and forgets to mark
the callbacks as noexcept, this will compile fine.  We'll just have to
manually check for that during review.
2022-11-28 19:23:30 +00:00
Tom Tromey
4881fcd7c1 Add missing TYPE_CODE_* constants to Python
A user noticed that TYPE_CODE_FIXED_POINT was not exported by the gdb
Python layer.  This patch fixes the bug, and prevents future
occurences of this type of bug.
2022-10-31 12:47:36 -06:00
Maciej W. Rozycki
90319cefe3 GDB/Guile: Don't assert that an integer value is boolean
Do not assert that a value intended for an integer parameter, of either
the PARAM_UINTEGER or the PARAM_ZUINTEGER_UNLIMITED type, is boolean,
causing error messages such as:

ERROR: In procedure make-parameter:
ERROR: In procedure gdbscm_make_parameter: Wrong type argument in position 15 (expecting integer or #:unlimited): 3
Error while executing Scheme code.

when initialization with a number is attempted.  Instead assert that it
is integer.  Keep matching `#:unlimited' keyword as an alternative.  Add
suitable test cases.

Approved-By: Simon Marchi <simon.marchi@polymtl.ca>
2022-10-21 08:54:18 +01:00
Tom Tromey
79aafec96b Fix the guile build
The frame_info_ptr patches broke the build with Guile.  This patch
fixes the problem.  In mos cases I chose to preserve the use of
frame_info_ptr, at least where I could be sure that the object
lifetime did not interact with Guile's longjmp-based exception scheme.

Tested on x86-64 Fedora 34.
2022-10-10 09:34:09 -06:00
Tom Tromey
bd2b40ac12 Change GDB to use frame_info_ptr
This changes GDB to use frame_info_ptr instead of frame_info *
The substitution was done with multiple sequential `sed` commands:

sed 's/^struct frame_info;/class frame_info_ptr;/'
sed 's/struct frame_info \*/frame_info_ptr /g' - which left some
    issues in a few files, that were manually fixed.
sed 's/\<frame_info \*/frame_info_ptr /g'
sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace
    problems.

The changed files were then manually checked and some 'sed' changes
undone, some constructors and some gets were added, according to what
made sense, and what Tromey originally did

Co-Authored-By: Bruno Larsen <blarsen@redhat.com>
Approved-by: Tom Tomey <tom@tromey.com>
2022-10-10 11:57:10 +02:00
Tom Tromey
a0cbd6505e Remove frame_id_eq
This replaces frame_id_eq with operator== and operator!=.  I wrote
this for a version of this series that I later abandoned; but since it
simplifies the code, I left this patch in.

Approved-by: Tom Tomey <tom@tromey.com>
2022-10-10 11:57:10 +02:00
Simon Marchi
df86565b31 gdb: remove TYPE_LENGTH
Remove the macro, replace all uses with calls to type::length.

Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
2022-09-21 11:05:21 -04:00
Simon Marchi
27710edb4e gdb: remove TYPE_TARGET_TYPE
Remove the macro, replace all uses by calls to type::target_type.

Change-Id: Ie51d3e1e22f94130176d6abd723255282bb6d1ed
2022-09-21 10:59:49 -04:00
Tom Tromey
992aeed80b Use ui_out_redirect_pop in more places
This changes ui_out_redirect_pop to also perform the redirection, and
then updates several sites to use this, rather than explicit
redirects.
2022-08-31 11:03:39 -06:00