Commit graph

2990 commits

Author SHA1 Message Date
Andrew Burgess
2988a36005 gdb/python: Use tp_init instead of tp_new to setup gdb.Value
The documentation suggests that we implement gdb.Value.__init__,
however, this is not currently true, we really implement
gdb.Value.__new__.  This will cause confusion if a user tries to
sub-class gdb.Value.  They might write:

  class MyVal (gdb.Value):
      def __init__ (self, val):
          gdb.Value.__init__(self, val)

  obj = MyVal(123)
  print ("Got: %s" % obj)

But, when they source this code they'll see:

  (gdb) source ~/tmp/value-test.py
  Traceback (most recent call last):
    File "/home/andrew/tmp/value-test.py", line 7, in <module>
      obj = MyVal(123)
    File "/home/andrew/tmp/value-test.py", line 5, in __init__
      gdb.Value.__init__(self, val)
  TypeError: object.__init__() takes exactly one argument (the instance to initialize)
  (gdb)

The reason for this is that, as we don't implement __init__ for
gdb.Value, Python ends up calling object.__init__ instead, which
doesn't expect any arguments.

The Python docs suggest that the reason why we might take this
approach is because we want gdb.Value to be immutable:

   https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_new

But I don't see any reason why we should require gdb.Value to be
immutable when other types defined in GDB are not.  This current
immutability can be seen in this code:

  obj = gdb.Value(1234)
  print("Got: %s" % obj)
  obj.__init__ (5678)
  print("Got: %s" % obj)

Which currently runs without error, but prints:

  Got: 1234
  Got: 1234

In this commit I propose that we switch to using __init__ to
initialize gdb.Value objects.

This does introduce some additional complexity, during the __init__
call a gdb.Value might already be associated with a gdb value object,
in which case we need to cleanly break that association before
installing the new gdb value object.  However, the cost of doing this
is not great, and the benefit - being able to easily sub-class
gdb.Value seems worth it.

After this commit the first example above works without error, while
the second example now prints:

  Got: 1234
  Got: 5678

In order to make it easier to override the gdb.Value.__init__ method,
I have tweaked the definition of gdb.Value.__init__.  The second,
optional argument to __init__ is a gdb.Type, if this argument is not
present then GDB figures out a suitable type.

However, if we want to override the __init__ method in a sub-class,
and still support the default argument, it is easier to write:

  class MyVal (gdb.Value):
      def __init__ (self, val, type=None):
          gdb.Value.__init__(self, val, type)

Currently, passing None for the Type will result in an error:

  TypeError: type argument must be a gdb.Type.

After this commit I now allow the type argument to be None, in which
case GDB figures out a suitable type just as if the type had not been
passed at all.

Unless a user is trying to reinitialize a value, or create sub-classes
of gdb.Value, there should be no user visible changes after this
commit.
2021-12-08 13:38:11 +00:00
Tom Tromey
bc75fb44c5 Implement 'task apply'
This adds a 'task apply' command, which is the Ada tasking analogue of
'thread apply'.  Unlike 'thread apply', it doesn't offer the
'ascending' flag; but otherwise it's essentially the same.
2021-12-02 08:58:22 -07:00
Tom Tromey
8a18382f94 Add "task" keyword to the "watch" command
Breakpoints in gdb can be made specific to an Ada task using the
"task" qualifier.  This patch applies this same idea to watchpoints.
2021-12-02 08:58:22 -07:00
Andrew Burgess
24b2de7b77 gdb/python: add gdb.RemoteTargetConnection.send_packet
This commits adds a new sub-class of gdb.TargetConnection,
gdb.RemoteTargetConnection.  This sub-class is created for all
'remote' and 'extended-remote' targets.

This new sub-class has one additional method over its base class,
'send_packet'.  This new method is equivalent to the 'maint
packet' CLI command, it allows a custom packet to be sent to a remote
target.

The outgoing packet can either be a bytes object, or a Unicode string,
so long as the Unicode string contains only ASCII characters.

The result of calling RemoteTargetConnection.send_packet is a bytes
object containing the reply that came from the remote.
2021-11-30 12:10:40 +00:00
Andrew Burgess
e5b176f25f gdb: make packet_command function available outside remote.c
In a later commit I will add a Python API to access the 'maint packet'
functionality, that is, sending a user specified packet to the target.

To make implementing this easier, this commit refactors how this
command is currently implemented so that the packet_command function
is now global.

The new global send_remote_packet function takes an object that is an
implementation of an abstract interface.  Two functions within this
interface are then called, one just before a packet is sent to the
remote target, and one when the reply has been received from the
remote target.  Using an interface object in this way allows (1) for
the error checking to be done before the first callback is made, this
means we only print out what packet it being sent once we know we are
going to actually send it, and (2) we don't need to make a copy of the
reply if all we want to do is print it.

One user visible changes after this commit are the error
messages, which I've changed to be less 'maint packet' command
focused, this will make them (I hope) better for when
send_remote_packet can be called from Python code.

So:      "command can only be used with remote target"
Becomes: "packets can only be sent to a remote target"

And:     "remote-packet command requires packet text as argument"
Becomes: "a remote packet must not be empty"

Additionally, in this commit, I've added support for packet replies
that contain binary data.  Before this commit, the code that printed
the reply treated the reply as a C string, it assumed that the string
only contained printable characters, and had a null character only at
the end.

One way to show the problem with this is if we try to read the auxv
data from a remote target, the auxv data is binary, so, before this
commit:

  (gdb) target remote :54321
  ...
  (gdb) maint packet qXfer:auxv:read::0,1000
  sending: "qXfer:auxv:read::0,1000"
  received: "l!"
  (gdb)

And after this commit:

  (gdb) target remote :54321
  ...
  (gdb) maint packet qXfer:auxv:read::0,1000
  sending: "qXfer:auxv:read::0,1000"
  received: "l!\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfc\xf7\xff\x7f\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\xff\xf>
  (gdb)

The binary contents of the reply are now printed as escaped hex.
2021-11-30 12:10:40 +00:00
Andrew Burgess
0e3b7c25ee gdb/python: introduce gdb.TargetConnection object type
This commit adds a new object type gdb.TargetConnection.  This new
type represents a connection within GDB (a connection as displayed by
'info connections').

There's three ways to find a gdb.TargetConnection, there's a new
'gdb.connections()' function, which returns a list of all currently
active connections.

Or you can read the new 'connection' property on the gdb.Inferior
object type, this contains the connection for that inferior (or None
if the inferior has no connection, for example, it is exited).

Finally, there's a new gdb.events.connection_removed event registry,
this emits a new gdb.ConnectionEvent whenever a connection is removed
from GDB (this can happen when all inferiors using a connection exit,
though this is not always the case, depending on the connection type).
The gdb.ConnectionEvent has a 'connection' property, which is the
gdb.TargetConnection being removed from GDB.

The gdb.TargetConnection has an 'is_valid()' method.  A connection
object becomes invalid when the underlying connection is removed from
GDB (as discussed above, this might be when all inferiors using a
connection exit, or it might be when the user explicitly replaces a
connection in GDB by issuing another 'target' command).

The gdb.TargetConnection has the following read-only properties:

  'num': The number for this connection,

  'type': e.g. 'native', 'remote', 'sim', etc

  'description': The longer description as seen in the 'info
                 connections' command output.

  'details': A string or None.  Extra details for the connection, for
             example, a remote connection's details might be
             'hostname:port'.
2021-11-30 12:10:33 +00:00
Tom de Vries
6ff9675421 [gdb/cli] Add "set logging enabled", deprecate "set logging on/off"
Before commit 3b6acaee89 "Update more calls to add_prefix_cmd" we had the
following output for "show logging file":
...
$ gdb -q -batch -ex "set trace-commands on" \
    -ex "set logging off" \
    -ex "show logging file" \
    -ex "set logging on" \
    -ex "show logging file"
+set logging off
+show logging file
Future logs will be written to gdb.txt.
+set logging on
+show logging file
Currently logging to "gdb.txt".
...

After that commit we have instead:
...
+set logging off
+show logging file
The current logfile is "gdb.txt".
+set logging on
+show logging file
The current logfile is "gdb.txt".
...

Before the commit, whether logging is enabled or not can be deduced from the
output of the command.  After the commit, the message is unified and it's no
longer clear whether logging is enabled or not.

Fix this by:
- adding a new command "show logging enabled"
- adding a corresponding new command "set logging enabled on/off"
- making the commands "set logging on/off" deprecated aliases of the
  "set logging enabled on/off" command.

Update the docs and testsuite to use "set logging enabled".  Mention the new
and deprecated commands in NEWS.

Tested on x86_64-linux.
2021-11-25 07:49:16 +01:00
Tom de Vries
8ba97c1904 [gdb/doc] Fix negative repeat count examining memory example
The documentation for the examining memory command x contains an example:
...
You can also specify a negative repeat count to examine memory backward from
the given address.  For example, 'x/-3uh 0x54320' prints three halfwords (h)
at 0x54314, 0x54328, and 0x5431c.
...

The 0x54328 looks like a typo, which was intended to be 0x54318.

But the series uses a 4-byte distance, while the halfword size used in the
command means a 2-byte distance, so the series should be:
...
0x5431a, 0x5431c, and 0x5431e.
...

Fix this by updating the addresses in the example accordingly.

Reported here ( https://sourceware.org/pipermail/gdb/2021-November/049784.html
).
2021-11-18 19:22:51 +01:00
Simon Marchi
333f35b631 gdb: rework "set debuginfod" commands
As discussed here [1], do some re-work in the "set debuginfod commands".

First, use "set debuginfod enabled on/off/ask" instead of "set
debuginfod on/off/ask".  This is more MI-friendly, and it gives an
output that makes more sense in "info set", for example.

Then, make the show commands not call "error" when debuginfod support is
not compiled in.  This makes the commands "show" and "show debuginfod"
stop early, breaking gdb.base/default.exp:

    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/default.exp ...
    FAIL: gdb.base/default.exp: info set
    FAIL: gdb.base/default.exp: show

 - Make the "debuginfod enabled" setting default to "off" when debuginfod
   support is not compiled in, and "ask" otherwise.
 - Make the setter of "debuginfod enabled" error out when debuginfod
   support is not compiled in, so that "debuginfod enabled" will always
   remain "off" in that case.
 - Make the setter of "debuginfod verbose" work in any case.  I don't
   see the harm in letting the user change that setting, since the user will
   hit an error if they try to enable the use of debuginfod.
 - I would do the same for the "debuginfod urls" setter, but because
   this one needs to see the DEBUGINFOD_URLS_ENV_VAR macro, provided by
   libdebuginfod, I made that one error out as well if debuginfod
   support is not compiled it (otherwise, I would have left it like
   "debuginfod verbose".  Alternatively, we could hard-code
   "DEBUGINFOD_URLS" in the code (in fact, it was prior to this patch,
   but I think it was an oversight, as other spots use
   DEBUGINFOD_URLS_ENV_VAR), or use a dummy string to store the setting,
   but I don't really see the value in that.

Rename debuginfod_enable to debuginfod_enabled, just so it matches the
setting name.

[1] https://sourceware.org/pipermail/gdb-patches/2021-October/182937.html

Change-Id: I45fdb2993f668226a5639228951362b7800f09d5
Co-Authored-By: Aaron Merey <amerey@redhat.com>
2021-11-15 21:47:27 -05:00
Simon Marchi
7bc5c369fa gdb: introduce "set index-cache enabled", deprecate "set index-cache on/off"
The "set index-cache" command is used at the same time as a prefix
command (prefix for "set index-cache directory", for example), and a
boolean setting for turning the index-cache on and off.  Even though I
did introduce that, I now don't think it's a good idea to do something
non-standard like this.

First, there's no dedicated CLI command to show whether the index-cache
is enabled, so it has to be custom output in the "show index-cache
handler".  Also, it means there's no good way a MI frontend can find out
if the index-cache is enabled.  "-gdb-show index-cache" doesn't show it
in the MI output record:

    (gdb) interpreter-exec mi "-gdb-show index-cache"
    ~"\n"
    ~"The index cache is currently disabled.\n"
    ^done,showlist={option={name="directory",value="/home/simark/.cache/gdb"}}

Fix this by introducing "set/show index-cache enabled on/off", regular
boolean setting commands.  Keep commands "set index-cache on" and "set
index-cache off" as deprecated aliases of "set index-cache enabled",
with respectively the default arguments "on" and "off".

Update tests using "set index-cache on/off" to use the new command.
Update the regexps in gdb.base/maint.exp to figure out whether the
index-cache is enabled or not.  Update the doc to mention the new
commands.

Change-Id: I7d5aaaf7fd22bf47bd03e0023ef4fbb4023b37b3
2021-11-04 15:48:59 -04:00
Bruno Larsen
2047d95b89 [gdb/doc]: Updated manpages to be consistent with help
Updated manpages to be consistent with help information provided by the
binary. The main changes are:

* Making all long-form options have '--', instead of a single '-';
* added most of the missing options to the manpage;
* removed the information about using '+' instead of '-', since it
  doesn't seem to be supported anymore.

This also fixes 2 upstream bugs:
* https://sourceware.org/bugzilla/show_bug.cgi?id=23965; by adding
--args to the manpage
* https://sourceware.org/bugzilla/show_bug.cgi?id=10619; by adding the
double dashes
2021-11-01 10:47:19 -03:00
Aaron Merey
3ea44f2129 gdb.texinfo: Expand documentation for debuginfod
Add section describing GDB's usage of debuginfod.

Refer to this new section in the description of the '--with-debuginfod'
configure option.

Mention debuginfod in the 'Separate Debug Files' section.
2021-10-29 20:58:21 -04:00
Tom Tromey
d3771fe234 Add gdb.Architecture.integer_type Python function
This adds a new Python function, gdb.Architecture.integer_type, which
can be used to look up an integer type of a given size and
signed-ness.  This is useful to avoid dependency on debuginfo when a
particular integer type would be useful.

v2 moves this to be a method on gdb.Architecture and addresses other
review comments.
2021-10-29 07:52:31 -06:00
Enze Li
91b7c7e522 Document "memory-tag-violations".
* gdb/doc/gdb.texinfo: (Data): Document	'-memory-tag-violations'.
 (Command Options): Update the example.
2021-10-29 13:31:37 +03:00
Simon Marchi
a1ff87d77c gdb: add "maint set/show selftest verbose" commands and use process_options
I saw the new -verbose switch to "maint selftests" and thought it would
be nice for it to use the option framework.  For example, that makes
having completion easy.  It's not that high value, given this is a
maintenance command, but I had never used the framework myself, so it
was a good way to practice.

This patch also adds the "maint set/show selftest verbose" setting.  It
would be possible to use option framework without adding the setting,
but using the framework makes adding the option almost trivial, so I
thought why not.

Change-Id: I6687faa0713ff3da60b398253211777100094144
2021-10-28 10:48:16 -04:00
Tom de Vries
a4b0231e17 [gdb/doc] Fix print inferior-events default
In the docs about print inferior-events we read:
...
By default, these messages will not be printed.
...

That used to be the case, but is no longer so since commit f67c0c9171 "Enable
'set print inferior-events' and improve detach/fork/kill/exit messages".

Fix this by updating the docs.
2021-10-26 10:45:08 +02:00
Andrew Burgess
8b87fbe6bb gdb/python: new gdb.architecture_names function
Add a new function to the Python API, gdb.architecture_names().  This
function returns a list containing all of the supported architecture
names within the current build of GDB.

The values returned in this list are all of the possible values that
can be returned from gdb.Architecture.name().
2021-10-22 13:42:49 +01:00
Srinath Parvathaneni
ae66a8f19e [ARM] Add support for M-profile MVE extension
This patch adds support for the M-profile MVE extension, which includes the
following:

- New M-profile XML feature m-profile-mve
- MVE vector predication status and control register (VPR)
- p0 pseudo register (contained in the VPR)
- q0 ~ q7 pseudo vector registers
- New feature bits
- Documentation update

Pseudo register p0 is the least significant bits of vpr and can be accessed
as $p0 or displayed through $vpr.  For more information about the register
layout, please refer to [1].

The q0 ~ q7 registers map back to the d0 ~ d15 registers, two d registers
per q register.

The register dump looks like this:

(gdb) info reg all
r0             0x0                 0
r1             0x0                 0
r2             0x0                 0
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
sp             0x0                 0x0 <__Vectors>
lr             0xffffffff          -1
pc             0xd0c               0xd0c <Reset_Handler>
xpsr           0x1000000           16777216
d0             0                   (raw 0x0000000000000000)
d1             0                   (raw 0x0000000000000000)
d2             0                   (raw 0x0000000000000000)
d3             0                   (raw 0x0000000000000000)
d4             0                   (raw 0x0000000000000000)
d5             0                   (raw 0x0000000000000000)
d6             0                   (raw 0x0000000000000000)
d7             0                   (raw 0x0000000000000000)
d8             0                   (raw 0x0000000000000000)
d9             0                   (raw 0x0000000000000000)
d10            0                   (raw 0x0000000000000000)
d11            0                   (raw 0x0000000000000000)
d12            0                   (raw 0x0000000000000000)
d13            0                   (raw 0x0000000000000000)
d14            0                   (raw 0x0000000000000000)
d15            0                   (raw 0x0000000000000000)
fpscr          0x0                 0
vpr            0x0                 [ P0=0 MASK01=0 MASK23=0 ]
s0             0                   (raw 0x00000000)
s1             0                   (raw 0x00000000)
s2             0                   (raw 0x00000000)
s3             0                   (raw 0x00000000)
s4             0                   (raw 0x00000000)
s5             0                   (raw 0x00000000)
s6             0                   (raw 0x00000000)
s7             0                   (raw 0x00000000)
s8             0                   (raw 0x00000000)
s9             0                   (raw 0x00000000)
s10            0                   (raw 0x00000000)
s11            0                   (raw 0x00000000)
s12            0                   (raw 0x00000000)
s13            0                   (raw 0x00000000)
s14            0                   (raw 0x00000000)
s15            0                   (raw 0x00000000)
s16            0                   (raw 0x00000000)
s17            0                   (raw 0x00000000)
s18            0                   (raw 0x00000000)
s19            0                   (raw 0x00000000)
s20            0                   (raw 0x00000000)
s21            0                   (raw 0x00000000)
s22            0                   (raw 0x00000000)
s23            0                   (raw 0x00000000)
s24            0                   (raw 0x00000000)
s25            0                   (raw 0x00000000)
s26            0                   (raw 0x00000000)
s27            0                   (raw 0x00000000)
s28            0                   (raw 0x00000000)
s29            0                   (raw 0x00000000)
s30            0                   (raw 0x00000000)
s31            0                   (raw 0x00000000)
q0             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q1             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q2             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q3             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q4             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q5             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q6             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q7             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
p0             0x0                 0

Built and regtested with a simulator.

[1] https://developer.arm.com/documentation/ddi0553/bn

Co-Authored-By: Luis Machado <luis.machado@linaro.org>
2021-10-11 16:03:56 -03:00
Andrew Burgess
24616c1995 gdb/doc: improve 'show print elements' description
The documentation for 'show print elements' contains the line:

  If the number is 0, then the printing is unlimited.

However, this line is now out of date as can be seen by this GDB
session:

  (gdb) set print elements 0
  (gdb) show print elements
  Limit on string chars or array elements to print is unlimited.

The value 0 does indeed mean unlimited, and this is described in the
'set print elements' section, however, for 'show print elements' the
user will never see the value 0, so lets just remove that bit from the
docs.
2021-10-06 14:36:23 +01:00
Andrew Burgess
b1f0f28418 gdb/python: add a new gdb_exiting event
Add a new event, gdb.events.gdb_exiting, which is called once GDB
decides it is going to exit.

This event is not triggered in the case that GDB performs a hard
abort, for example, when handling an internal error and the user
decides to quit the debug session, or if GDB hits an unexpected,
fatal, signal.

This event is triggered if the user just types 'quit' at the command
prompt, or if GDB is run with '-batch' and has processed all of the
required commands.

The new event type is gdb.GdbExitingEvent, and it has a single
attribute exit_code, which is the value that GDB is about to exit
with.

The event is triggered before GDB starts dismantling any of its own
internal state, so, my expectation is that most Python calls should
work just fine at this point.

When considering this functionality I wondered about using the
'atexit' Python module.  However, this is triggered when the Python
environment is shut down, which is done from a final cleanup.  At
this point we don't know for sure what other GDB state has already
been cleaned up.
2021-10-05 10:05:40 +01:00
Andrew Burgess
1cb56ad3f3 gdb/python: update events test to handle missing exit_code
The test gdb.python/py-events.exp sets up a handler for the gdb.exited
event.  Unfortunately the handler is slightly broken, it assumes that
the exit_code attribute will always be present.  This is not always
the case.

In a later commit I am going to add more tests to py-events.exp test
script, and in so doing I expose the bug in our handling of gdb.exited
events.

Just to be clear, GDB itself is fine, it is the test that is not
written correctly according to the Python Events API.

So, in this commit I fix the Python code in the test, and extend the
test case to exercise more paths through the Python code.

Additionally, I noticed that the gdb.exited event is used as an
example in the documentation for how to write an event handler.
Unfortunately the same bug that we had in our test was also present in
the example code in the manual.

So I've fixed that too.

After this commit there is no functional change to GDB.
2021-10-05 10:05:40 +01:00
Andrew Burgess
4180173142 gdb/doc: use 'standard error stream' instead of 'stderr' in some places
With this commit:

  commit 91f2597bd2
  Date:   Thu Aug 12 18:24:59 2021 +0100

      gdb: print backtrace for internal error/warning

I included some references to 'stderr', which, it was pointed out,
would be better written as 'standard error stream'.  See:

  https://sourceware.org/pipermail/gdb-patches/2021-September/182225.html

This commit replaces the two instances of 'stderr' that I introduced.
2021-09-29 09:25:03 +01:00
Andrew Burgess
91f2597bd2 gdb: print backtrace for internal error/warning
This commit builds on previous work to allow GDB to print a backtrace
of itself when GDB encounters an internal-error or internal-warning.
This fixes PR gdb/26377.

There's not many places where we call internal_warning, and I guess in
most cases the user would probably continue their debug session.  And
so, in order to avoid cluttering up the output, by default, printing
of a backtrace is off for internal-warnings.

In contrast, printing of a backtrace is on by default for
internal-errors, as I figure that in most cases hitting an
internal-error is going to be the end of the debug session.

Whether a backtrace is printed or not can be controlled with the new
settings:

  maintenance set internal-error backtrace on|off
  maintenance show internal-error backtrace

  maintenance set internal-warning backtrace on|off
  maintenance show internal-warning backtrace

Here is an example of what an internal-error now looks like with the
backtrace included:

  (gdb) maintenance internal-error blah
  ../../src.dev-3/gdb/maint.c:82: internal-error: blah
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  ----- Backtrace -----
  0x5c61ca gdb_internal_backtrace_1
  	../../src.dev-3/gdb/bt-utils.c:123
  0x5c626d _Z22gdb_internal_backtracev
  	../../src.dev-3/gdb/bt-utils.c:165
  0xe33237 internal_vproblem
  	../../src.dev-3/gdb/utils.c:393
  0xe33539 _Z15internal_verrorPKciS0_P13__va_list_tag
  	../../src.dev-3/gdb/utils.c:470
  0x1549652 _Z14internal_errorPKciS0_z
  	../../src.dev-3/gdbsupport/errors.cc:55
  0x9c7982 maintenance_internal_error
  	../../src.dev-3/gdb/maint.c:82
  0x636f57 do_simple_func
  	../../src.dev-3/gdb/cli/cli-decode.c:97
   .... snip, lots more backtrace lines ....
  ---------------------
  ../../src.dev-3/gdb/maint.c:82: internal-error: blah
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) y

  This is a bug, please report it.  For instructions, see:
  <https://www.gnu.org/software/gdb/bugs/>.

  ../../src.dev-3/gdb/maint.c:82: internal-error: blah
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Create a core file of GDB? (y or n) n

My hope is that this backtrace might make it slightly easier to
diagnose GDB issues if all that is provided is the console output, I
find that we frequently get reports of an assert being hit that is
located in pretty generic code (frame.c, value.c, etc) and it is not
always obvious how we might have arrived at the assert.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26377
2021-09-28 12:21:22 +01:00
Andrew Burgess
fde1a9a3ee gdb: add setting to disable reading source code files
In some situations it is possible that a user might not want GDB to
try and access source code files, for example, the source code might
be stored on a slow to access network file system.

It is almost certainly possible that using some combination of 'set
directories' and/or 'set substitute-path' a user can trick GDB into
being unable to find the source files, but this feels like a rather
crude way to solve the problem.

In this commit a new option is add that stops GDB from opening and
reading the source files.  A user can run with source code reading
disabled if this is required, then re-enable later if they decide
that they now want to view the source code.
2021-09-27 11:31:35 +01:00
Tom de Vries
479209dd4f [gdb] Add maint selftest -verbose option
The print_one_insn selftest in gdb/disasm-selftests.c contains:
...
  /* If you want to see the disassembled instruction printed to gdb_stdout,
     set verbose to true.  */
  static const bool verbose = false;
...

Make this parameter available in the maint selftest command using a new option
-verbose, such that we can do:
...
(gdb) maint selftest -verbose print_one_insn
...

Tested on x86_64-linux.
2021-09-22 11:47:50 +02:00
Felix Willgerodt
be24dba6f1 gdb, doc: Add ieee_half and bfloat16 to list of predefined target types.
For some reason these two weren't added to the list when they were orginally
added to GDB.

gdb/doc/ChangeLog:
2021-09-21  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (Predefined Target Types): Mention ieee_half and bfloat16.
2021-09-21 10:14:36 +02:00
Mike Frysinger
034ce7b42a gdb: manual: update @inforef to @xref
The @inforef command is deprecated, and @xref does the samething.
Also had to update the text capitalization to match current manual.
Verified that info & HTML links work.
2021-09-19 02:20:34 -04:00
Mike Frysinger
0ffd31f044 gdb: manual: fix werrors typo 2021-09-16 03:27:56 -04:00
Tom de Vries
3d53d4603e [gdb/doc] Fix typo in maint selftest entry
Fix typo "will by" -> "will be".
2021-09-15 11:46:57 +02:00
Andrew Burgess
540bf37b25 gdb/python: new function to add values into GDB's history
The guile API has (history-append! <value>) to add values into GDB's
history list.  There is currently no equivalent in the Python API.

This commit adds gdb.add_history(<value>) to the Python API, this
function takes <value> a gdb.Value (or anything that can be passed to
the constructor of gdb.Value), and adds the value it represents to
GDB's history list.  The index of the newly added value is returned.
2021-09-07 10:54:07 +01:00
Tom Tromey
6a33fa0efe Update documentation to mention Pygments
Philippe Blain pointed out that the gdb documentation does not mention
that Pygments may be used for source highlighting.  This patch updates
the docs to reflect how highlighting is actually done.
2021-08-12 14:06:20 -06:00
Andrew Burgess
6aa4f97c2b gdb: print backtrace on fatal SIGSEGV
This commit adds a new maintenance feature, the ability to print
a (limited) backtrace if GDB dies due to a fatal signal.

The backtrace is produced using the backtrace and backtrace_symbols_fd
functions which are declared in the execinfo.h header, and both of
which are async signal safe.  A configure check has been added to
check for these features, if they are not available then the new code
is not compiled into GDB and the backtrace will not be printed.

The motivation for this new feature is to aid in debugging GDB in
situations where GDB has crashed at a users site, but the user is
reluctant to share core files, possibly due to concerns about what
might be in the memory image within the core file.  Such a user might
be happy to share a simple backtrace that was written to stderr.

The production of the backtrace is on by default, but can switched off
using the new commands:

  maintenance set backtrace-on-fatal-signal on|off
  maintenance show backtrace-on-fatal-signal

Right now, I have hooked this feature in to GDB's existing handling of
SIGSEGV only, but this will be extended to more signals in a later
commit.

One additional change I have made in this commit is that, when we
decide GDB should terminate due to the fatal signal, we now
raise the same fatal signal rather than raising SIGABRT.

Currently, this is only effecting our handling of SIGSEGV.  So,
previously, if GDB hit a SEGV then we would terminate GDB with a
SIGABRT.  After this commit we will terminate GDB with a SIGSEGV.

This feels like an improvement to me, we should still get a core dump,
but in many shells, the user will see a more specific message once GDB
exits, in bash for example "Segmentation fault" rather than "Aborted".

Finally then, here is an example of the output a user would see if GDB
should hit an internal SIGSEGV:

  Fatal signal: Segmentation fault
  ----- Backtrace -----
  ./gdb/gdb[0x8078e6]
  ./gdb/gdb[0x807b20]
  /lib64/libpthread.so.0(+0x14b20)[0x7f6648c92b20]
  /lib64/libc.so.6(__poll+0x4f)[0x7f66484d3a5f]
  ./gdb/gdb[0x1540f4c]
  ./gdb/gdb[0x154034a]
  ./gdb/gdb[0x9b002d]
  ./gdb/gdb[0x9b014d]
  ./gdb/gdb[0x9b1aa6]
  ./gdb/gdb[0x9b1b0c]
  ./gdb/gdb[0x41756d]
  /lib64/libc.so.6(__libc_start_main+0xf3)[0x7f66484041a3]
  ./gdb/gdb[0x41746e]
  ---------------------
  A fatal error internal to GDB has been detected, further
  debugging is not possible.  GDB will now terminate.

  This is a bug, please report it.  For instructions, see:
  <https://www.gnu.org/software/gdb/bugs/>.

  Segmentation fault (core dumped)

It is disappointing that backtrace_symbols_fd does not actually map
the addresses back to symbols, this appears, in part, to be due to GDB
not being built with -rdynamic as the manual page for
backtrace_symbols_fd suggests, however, even when I do add -rdynamic
to the build of GDB I only see symbols for some addresses.

We could potentially look at alternative libraries to provide the
backtrace (e.g. libunwind) however, the solution presented here, which
is available as part of glibc is probably a good baseline from which
we might improve things in future.
2021-08-11 12:35:14 +01:00
George Barrett
ad42014be2 Guile: temporary breakpoints
Adds API to the Guile bindings for creating temporary breakpoints and
querying whether an existing breakpoint object is temporary. This is
effectively a transliteration of the Python implementation.

It's worth noting that the added `is_temporary' flag is ignored in the
watchpoint registration path. This replicates the behaviour of the
Python implementation, but might be a bit surprising for users.

gdb/ChangeLog:

2021-06-09  George Barrett  <bob@bob131.so>

	* guile/scm-breakpoint.c (gdbscm_breakpoint_object::spec): Add
	is_temporary field.
	(temporary_keyword): Add keyword object for make-breakpoint
	argument parsing.
	(gdbscm_make_breakpoint): Accept #:temporary keyword argument
	and store the value in the allocated object's
	spec.is_temporary.
	(gdbscm_register_breakpoint_x): Pass the breakpoint's
	spec.is_temporary value to create_breakpoint.
	(gdbscm_breakpoint_temporary): Add breakpoint-temporary?
	procedure implementation.
	(breakpoint_functions::make-breakpoint): Update documentation
	string and fix a typo.
	(breakpoint_functions::breakpoint-temporary?): Add
	breakpoint-temporary? procedure.
	(gdbscm_initialize_breakpoints): Initialise temporary_keyword
	variable.
	NEWS (Guile API): Mention new temporary breakpoints API.

gdb/doc/ChangeLog:

2021-06-09  George Barrett  <bob@bob131.so>

	* guile.texi (Breakpoints In Guile): Update make-breakpoint
	documentation to reflect new #:temporary argument.
	Add documentation for new breakpoint-temporary? procedure.

gdb/testsuite/ChangeLog:

2021-06-09  George Barrett  <bob@bob131.so>

	* gdb.guile/scm-breakpoint.exp: Add additional tests for
	temporary breakpoints.

Change-Id: I2de332ee7c256f5591d7141ab3ad50d31b871d17
2021-07-28 20:30:24 -04:00
Andrew Burgess
730afdd139 gdb: move remaining ChangeLogs to legacy files
In commit:

  commit f069ea46a0
  Date:   Sat Jul 3 16:29:08 2021 -0700

      Rename gdb/ChangeLog to gdb/ChangeLog-2021

The gdb/ChangeLog file was renamed, but all of the other ChangeLog
files relating to gdb were left in place.

As I understand things, the no ChangeLogs policy applies to all the
GDB related directories, so this commit renames all of the remaining
GDB related ChangeLog files.

As with the original commit, the intention behind this commit is to
hopefully stop people merging ChangeLog entries by mistake.

The renames carried out in this commit are:

    gdb/doc/ChangeLog -> gdb/doc/ChangeLog-1991-2021
    gdb/stubs/ChangeLog -> gdb/stubs/ChangeLog-2012-2020
    gdb/testsuite/ChangeLog -> gdb/testsuite/ChangeLog-2014-2021
    gdbserver/ChangeLog -> gdbserver/ChangeLog-2002-2021
    gdbsupport/ChangeLog -> gdbsupport/ChangeLog-2020-2021
2021-07-26 12:20:33 +01:00
Tankut Baris Aktemur
b6c4205149 gdb/mi: handle no condition argument case for -break-condition
As reported in PR gdb/28076 [1], passing no condition argument to the
-break-condition command (e.g.: "-break-condition 2") should clear the
condition for breakpoint 2, just like CLI's "condition 2", but instead
an error message is returned:

  ^error,msg="-break-condition: Missing the <number> and/or <expr> argument"

The current implementation of the -break-condition command's argument
handling (79aabb7308 "gdb/mi: add a '--force' flag to the
'-break-condition' command") was done according to the documentation,
where the condition argument seemed mandatory.  However, the
-break-condition command originally (i.e. before the 79aabb7308
patch) used the CLI's "cond" command, and back then not passing a
condition argument was clearing out the condition.  So, this is a
regression in terms of the behavior.

Fix the argument handling of the -break-condition command to allow not
having a condition argument, and also update the document to make the
behavior clear.  Also add test cases to test the scenarios which were
previously not covered.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=28076
2021-07-26 08:46:02 +02:00
Simon Marchi
ff77083572 gdb: call post_create_inferior at end of follow_fork_inferior
GDB doesn't handle well the case of an inferior using the JIT interface
to register JIT-ed objfiles and forking.  If an inferior registers a
code object using the JIT interface and then forks, the child process
conceptually has the same code object loaded, so GDB should look it up
and learn about it (it currently doesn't).

To achieve this, I think it would make sense to have the
inferior_created observable called when an inferior is created due to a
fork in follow_fork_inferior.  The inferior_created observable is
currently called both after starting a new inferior and after attaching
to an inferior, allowing various sub-components to learn about that new
executing inferior.  We can see handling a fork child just like
attaching to it, so any work done when attaching should also be done in
the case of a fork child.

Instead of just calling the inferior_created observable, this patch
makes follow_fork_inferior call the whole post_create_inferior function.
This way, the attach and follow-fork code code paths are more alike.

Given that post_create_inferior calls solib_create_inferior_hook,
follow_fork_inferior doesn't need to do it itself, so those calls to
solib_create_inferior_hook are removed.

One question you may have: why not just call post_create_inferior at the
places where solib_create_inferior_hook is currently called, instead of
after target_follow_fork?

 - there's something fishy for the second solib_create_inferior_hook
   call site: at this point we have switched the current program space
   to the child's, but not the current inferior nor the current thread.
   So solib_create_inferior_hook (and everything under, including
   check_for_thread_db, for example) is called with inferior 1 as the
   current inferior and inferior 2's program space as the current
   program space.  I think that's wrong, because at this point we are
   setting up inferior 2, and all that code relies on the current
   inferior.  We could just add a switch_to_thread call before it to
   make inferior 2 the current one, but there are other problems (see
   below).

 - solib_create_inferior_hook is currently not called on the
   `follow_child && detach_fork` path.  I think we need to call it,
   because we still get a new inferior in that case (even though we
   detach the parent).  If we only call post_create_inferior where
   solib_create_inferior_hook used to be called, then the JIT
   subcomponent doesn't get informed about the new inferior, and that
   introduces a failure in the new gdb.base/jit-elf-fork.exp test.

 - if we try to put the post_create_inferior just after the
   switch_to_thread that was originally at line 662, or just before the
   call to target_follow_fork, we introduce a subtle failure in
   gdb.threads/fork-thread-pending.exp.  What happens then is that
   libthread_db gets loaded (somewhere under post_create_inferior)
   before the linux-nat target learns about the LWPs (which happens in
   linux_nat_target::follow_fork).  As a result, the ALL_LWPS loop in
   try_thread_db_load_1 doesn't see the child LWP, and the thread-db
   target doesn't have the chance to fill in thread_info::priv.  A bit
   later, when the test does "info threads", and
   thread_db_target::pid_to_str is called, the thread-db target doesn't
   recognize the thread as one of its own, and delegates the request to
   the target below.  Because the pid_to_str output is not the expected
   one, the test fails.

   This tells me that we need to call the process target's follow_fork
   first, to make the process target create the necessary LWP and thread
   structures.  Then, we can call post_create_inferior to let the other
   components of GDB do their thing.

   But then you may ask: check_for_thread_db is already called today,
   somewhere under solib_create_inferior_hook, and that is before
   target_follow_fork, why don't we see this ordering problem!?  Well,
   because of the first bullet point: when check_for_thread_db /
   thread_db_load are called, the current inferior is (erroneously)
   inferior 1, the parent.  Because libthread_db is already loaded for
   the parent, thread_db_load early returns.  check_for_thread_db later
   gets called by linux_nat_target::follow_fork.  At this point, the
   current inferior is the correct one and the child's LWP exists, so
   all is well.

Since we now call post_create_inferior after target_follow_fork, which
calls the inferior_created observable, which calls check_for_thread_db,
I don't think linux_nat_target needs to explicitly call
check_for_thread_db itself, so that is removed.

In terms of testing, this patch adds a new gdb.base/jit-elf-fork.exp
test.  It makes an inferior register a JIT code object and then fork.
It then verifies that whatever the detach-on-fork and follow-fork-child
parameters are, GDB knows about the JIT code object in all the inferiors
that survive the fork.  It verifies that the inferiors can unload that
code object.

There isn't currently a way to get visibility into GDB's idea of the JIT
code objects for each inferior.  For the purpose of this test, add the
"maintenance info jit" command.  There isn't much we can print about the
JIT code objects except their load address.  So the output looks a bit
bare, but it's good enough for the test.

gdb/ChangeLog:

	* NEWS: Mention "maint info jit" command.
	* infrun.c (follow_fork_inferior): Don't call
	solib_create_inferior_hook, call post_create_inferior if a new
	inferior was created.
	* jit.c (maint_info_jit_cmd): New.
	(_initialize_jit): Register new command.
	* linux-nat.c (linux_nat_target::follow_fork): Don't call
	check_for_thread_db.
	* linux-nat.h (check_for_thread_db): Remove declaration.
	* linux-thread-db.c (check_thread_signals): Make static.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Mention "maint info jit".

gdb/testsuite/ChangeLog:

	* gdb.base/jit-elf-fork-main.c: New test.
	* gdb.base/jit-elf-fork-solib.c: New test.
	* gdb.base/jit-elf-fork.exp: New test.

Change-Id: I9a192e55b8a451c00e88100669283fc9ca60de5c
2021-07-14 23:18:24 -04:00
Pedro Alves
90b044ef10 Document TUI improvements in the manual & NEWS
gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>
	    Hannes Domani  <ssbssa@yahoo.de>

	* NEWS: Add new "TUI Improvements" section and mention mouse
	support and that unrecognized special keys are now passed to
	GDB.  Mention Python Window.click in the Python improvements
	section.

gdb/doc/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* gdb.texinfo (TUI): <TUI Mouse Support>: New node/section.

Co-Authored-By: Hannes Domani <ssbssa@yahoo.de>

Change-Id: I0d79a795d8ac561fd28cdc5184bff029ba28bc64
2021-07-02 16:31:20 +01:00
Andrew Burgess
bd742128ba gdb: change info sources to group results by objfile
Currently the 'info sources' command lists all of the known source
files together, regardless of their source, e.g. here is a session
debugging a test application that makes use of a shared library:

  (gdb) info sources
  Source files for which symbols have been read in:

  /tmp/info-sources/test.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h, /tmp/info-sources/helper.c

  Source files for which symbols will be read in on demand:

  (gdb)

In this commit I change the format of the 'info sources' results so
that the results are grouped by the object file that uses that source
file.  Here's the same session with the new output format:

  (gdb) info sources
  /tmp/info-sources/test.x:

  /tmp/info-sources/test.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h

  /lib64/ld-linux-x86-64.so.2:
  (Objfile has no debug information.)

  system-supplied DSO at 0x7ffff7fcf000:
  (Objfile has no debug information.)

  /tmp/info-sources/libhelper.so:

  /tmp/info-sources/helper.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h

  /lib64/libc.so.6:
  (Objfile has no debug information.)

  (gdb)

Notice that in the new output some source files are repeated,
e.g. /tmp/info-sources/header.h, as multiple objfiles use this source
file.

Further, some object files are tagged with the message '(Objfile has
no debug information.)', it is also possible to see the message '(Full
debug information has not yet been read for this file.)', which is
printed when some symtabs within an objfile have not yet been
expanded.

All of the existing regular expression based filtering still works.

An original version of this patch added the new format as an option to
'info sources', however, it was felt that the new layout was so much
better than the old style that GDB should just switch to the new
result format completely.

gdb/ChangeLog:

	* NEWS: Mention changes to 'info sources'.
	* symtab.c (info_sources_filter::print): Delete.
	(struct output_source_filename_data) <print_header>: Delete
	declaration.  <printed_filename_p>: New member function.
	(output_source_filename_data::print_header): Delete.
	(info_sources_worker): Update group-by-objfile style output to
	make it CLI suitable, simplify non-group-by-objfile now this is
	only used from the MI.
	(info_sources_command): Make group-by-objfile be the default for
	CLI info sources command.
	* symtab.h (struct info_sources_filter) <print>: Delete.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new output format for 'info
	sources'.

gdb/testsuite/ChangeLog:

	* gdb.base/info_sources_2-header.h: New file.
	* gdb.base/info_sources_2-lib.c: New file.
	* gdb.base/info_sources_2-test.c: New file.
	* gdb.base/info_sources_2.exp: New file.
2021-06-25 20:54:29 +01:00
Andrew Burgess
1fb1ce02fc gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
This commit adds a new option '--group-by-objfile' to the MI command
-file-list-exec-source-files.  With this option the output format is
changed; instead of a single list of source files the results are now
a list of objfiles.  For each objfile all of the source files
associated with that objfile are listed.

Here is an example of the new output format taken from the
documentation (the newlines are added just for readability):

  -file-list-exec-source-files --group-by-objfile
  ^done,files=[{filename="/tmp/info-sources/test.x",
                debug-info="fully-read",
                sources=[{file="test.c",
                          fullname="/tmp/info-sources/test.c",
                          debug-fully-read="true"},
                         {file="/usr/include/stdc-predef.h",
                          fullname="/usr/include/stdc-predef.h",
                          debug-fully-read="true"},
                         {file="header.h",
                          fullname="/tmp/info-sources/header.h",
                          debug-fully-read="true"}]},
               {filename="/lib64/ld-linux-x86-64.so.2",
                debug-info="none",
                sources=[]},
               {filename="system-supplied DSO at 0x7ffff7fcf000",
                debug-info="none",
                sources=[]},
               {filename="/tmp/info-sources/libhelper.so",
                debug-info="fully-read",
                sources=[{file="helper.c",
                          fullname="/tmp/info-sources/helper.c",
                          debug-fully-read="true"},
                         {file="/usr/include/stdc-predef.h",
                          fullname="/usr/include/stdc-predef.h",
                          debug-fully-read="true"},
                         {file="header.h",
                          fullname="/tmp/info-sources/header.h",
                          debug-fully-read="true"}]},
               {filename="/lib64/libc.so.6",
                debug-info="none",
                sources=[]}]

In the above output the 'debug-info' field associated with each
objfile will have one of the values 'none', 'partially-read', or
'fully-read'.  For example, /lib64/libc.so.6 has the value 'none',
this indicates that this object file has no debug information
associated with it, unsurprisingly then, the sources list of this
object file is empty.

An object file that was compiled with debug, for example
/tmp/info-sources/libhelper.so, has the value 'fully-read' above
indicating that this object file does have debug information, and the
information is fully read into GDB.  At different times this field
might have the value 'partially-read' indicating that that the object
file has debug information, but it has not been fully read into GDB
yet.

Source files can appear at most once for any single objfile, but can
appear multiple times in total, if the same source file is part of
multiple objfiles, for example /tmp/info-sources/header.h in the above
output.

The new output format is hidden behind a command option to ensure that
the default output is unchanged, this ensures backward compatibility.

The behaviour of the CLI "info sources" command is unchanged after
this commit.

gdb/ChangeLog:

	* NEWS: Mention additions to -file-list-exec-source-files.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Add
	--group-by-objfile option.
	* symtab.c (isrc_flag_option_def): Rename to...
	(isrc_match_flag_option_def): ...this.
	(info_sources_option_defs): Rename to...
	(info_sources_match_option_defs): ...this, and update to rename of
	isrc_flag_option_def.
	(struct filename_grouping_opts): New struct.
	(isrc_grouping_flag_option_def): New type.
	(info_sources_grouping_option_defs): New static global.
	(make_info_sources_options_def_group): Update to return two option
	groups.
	(info_sources_command_completer): Update for changes to
	make_info_sources_options_def_group.
	(info_sources_worker): Add extra parameter, use this to display
	alternative output format.
	(info_sources_command): Pass extra parameter to
	info_sources_worker.
	(_initialize_symtab): Update for changes to
	make_info_sources_options_def_group.
	* symtab.h (info_sources_worker): Add extra parameter.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI File Commands): Document --group-by-objfile
	extension for -file-list-exec-source-files.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-info-sources.exp: Add additional tests.
2021-06-25 20:54:29 +01:00
Andrew Burgess
0e350a054b gdb/mi: add regexp filtering to -file-list-exec-source-files
This commit extends the existing MI command
-file-list-exec-source-files to provide the same regular expression
based filtering that the equivalent CLI command "info sources"
provides.

The new command syntax is:

  -file-list-exec-source-files [--basename | --dirname] [--] [REGEXP]

All options are optional, which ensures the command is backward
compatible.

As part of this work I have unified the CLI and MI code.

As a result of the unified code I now provide additional information
in the MI command output, there is now a new field 'debug-fully-read'
included with each source file.  This field which has the values
'true' or 'false', indicates if the source file is from a compilation
unit that has had its debug information fully read.  However, as this
is additional information, a well written front-end should just ignore
this field if it doesn't understand it, so things should still be
backward compatible.

gdb/ChangeLog:

	* NEWS: Mention additions to -file-list-exec-source-files.
	* mi/mi-cmd-file.c (print_partial_file_name): Delete.
	(mi_cmd_file_list_exec_source_files): Rewrite to handle command
	options, and make use of info_sources_worker.
	* symtab.c (struct info_sources_filter): Moved to symtab.h.
	(info_sources_filter::print): Take uiout argument, produce output
	through uiout.
	(struct output_source_filename_data)
	<output_source_filename_data>: Take uiout argument, store into
	m_uiout.  <output>: Rewrite comment, add additional arguments to
	declaration.  <operator()>: Send more arguments to
	output. <m_uiout>: New member variable.
	(output_source_filename_data::output): Take extra arguments,
	produce output through m_uiout, and structure for MI.
	(output_source_filename_data::print_header): Produce output
	through m_uiout.
	(info_sources_worker): New function, the implementation is taken
	from info_sources_command, but modified so produce output through
	a ui_out.
	(info_sources_command): The second half of this function has gone
	to become info_sources_worker.
	* symtab.h (struct info_sources_filter): Moved from symtab.c, add
	extra parameter to print member function.
	(info_sources_worker): Declare.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI File Commands): Document extensions to
	-file-list-exec-source-files.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-filename.exp: Update expected results.
	* gdb.mi/mi-file.exp: Likewise.
	* gdb.mi/mi-info-sources-base.c: New file.
	* gdb.mi/mi-info-sources.c: New file.
	* gdb.mi/mi-info-sources.exp: New file.
2021-06-25 20:54:29 +01:00
Andrew Burgess
6b95f5ad96 gdb/python: allow for catchpoint type breakpoints in python
This commit adds initial support for catchpoints to the python
breakpoint API.

This commit adds a BP_CATCHPOINT constant which corresponds to
GDB's internal bp_catchpoint.  The new constant is documented in the
manual.

The user can't create breakpoints with type BP_CATCHPOINT after this
commit, but breakpoints that already exist, obtained with the
`gdb.breakpoints` function, can now have this type.  Additionally,
when a stop event is reported for hitting a catchpoint, GDB will now
report a BreakpointEvent with the attached breakpoint being of type
BP_CATCHPOINT - previously GDB would report a generic StopEvent in
this situation.

gdb/ChangeLog:

	* NEWS: Mention Python BP_CATCHPOINT feature.
	* python/py-breakpoint.c (pybp_codes): Add bp_catchpoint support.
	(bppy_init): Likewise.
	(gdbpy_breakpoint_created): Likewise.

gdb/doc/ChangeLog:

	* python.texinfo (Breakpoints In Python): Add BP_CATCHPOINT
	description.

gdb/testsuite/ChangeLog:

	* gdb.python/py-breakpoint.c (do_throw): New function.
	(main): Call do_throw.
	* gdb.python/py-breakpoint.exp (test_catchpoints): New proc.
2021-06-25 18:22:07 +01:00
Andrew Burgess
08080f9744 gdb/guile: allow for catchpoint type breakpoints in guile
This commit adds initial support for catchpoints to the guile
breakpoint API.

This commit adds a BP_CATCHPOINT constant which corresponds to
GDB's internal bp_catchpoint.  The new constant is documented in the
manual.

The user can't create breakpoints with type BP_CATCHPOINT after this
commit, but breakpoints that already exist, obtained with
the (breakpoints) function, can now have this type.

gdb/ChangeLog:

	* guile/scm-breakpoint.c (bpscm_type_to_string): Handle
	bp_catchpoint.
	(bpscm_want_scm_wrapper_p): Likewise.
	(gdbscm_make_breakpoint): Likewise.
	(breakpoint_integer_constants): Likewise.

gdb/doc/ChangeLog:

	* guile.texinfo (Breakpoints In Guile): Add BP_CATCHPOINT
	description.

gdb/testsuite/ChangeLog:

	* gdb.guile/scm-breakpoint.exp (test_catchpoints): New proc.
2021-06-25 18:22:05 +01:00
Andrew Burgess
96f842cbdb gdb/riscv: add support for vector registers in target descriptions
This commit adds support to RISC-V GDB for vector registers in the
incoming target description.

The vector registers should be described in a feature called
"org.gnu.gdb.riscv.vector", and should contain the register v0 to
v31.  There's no restriction on the size or type of these registers,
so the target description can set these up as it requires.

However, if the target feature is present then all of the registers
must be present, and they must all be the same size, these
requirements are, I believe, inline with the RISC-V vector extension.

The DWARF register numbers for the vector registers have been added,
and the code to map between GDB's internal numbering and the DWARF
numbering has been updated.

I have not yet added a feature/riscv/*.xml file for the vector
extension, the consequence of this is that we can't, right now, detect
vector registers on a native target, this patch is all about
supporting vectors on a remote target.

It is worth noting that I don't actually have access to a RISC-V
target with vectors, so the only testing that this patch has had has
been done using 'set tdesc filename ....' to load a target description
to which I have manually added the vector feature.  This has shown
that the vector register feature can be successfully parsed, and that
the registers show up in the expected register groups.

Additionally, the RISC-V vector extension is currently at v0.10, which
is also the v1.0 draft release.  However, this extension is not yet
finalised.  It is possible (but unlikely I think) that the register
set could change between now and the final release of the vector
extension.  If this were to happen then we would potentially end up
changing the requirements for the new org.gnu.gdb.riscv.vector
feature.  I really don't think it is likely that the register set will
change this late in the process, and even if it did, changing the
feature requirements will not be a problem as far as I am
concerned (when the alternative is GDB just continues without this
feature for now).

gdb/ChangeLog:

	* NEWS: Mention new target feature name.
	* arch/riscv.c (riscv_create_target_description): GDB doesn't
	currently create target descriptions containing vector registers.
	* arch/riscv.h (struct riscv_gdbarch_features) <vlen>: New member
	variable.
	<operator==>: Also compare vlen.
	<hash>: Also include vlen.
	* riscv-tdep.c (riscv_feature_name_vector): New static global.
	(struct riscv_vector_feature): New struct.
	(riscv_vector_feature): New static global.
	(riscv_register_reggroup_p): Ensure vector registers are part of
	the 'all' group, and part of the 'vector' group.
	(riscv_dwarf_reg_to_regnum): Handle vector registers.
	(riscv_gdbarch_init): Check vector register feature.
	* riscv-tdep.h: Add vector registers to GDB's internal register
	numbers, and to the DWARF register numbers.

gdb/doc/ChangeLog:

	* gdb.texinfo (RISC-V Features): Mention vector register feature.
2021-06-21 20:47:13 +01:00
Andrew Burgess
d52b800721 gdb/python: add PendingFrame.level and Frame.level methods
Add new methods to the PendingFrame and Frame classes to obtain the
stack frame level for each object.

The use of 'level' as the method name is consistent with the existing
attribute RecordFunctionSegment.level (though this is an attribute
rather than a method).

For Frame/PendingFrame I went with methods as these classes currently
only use methods, including for simple data like architecture, so I
want to be consistent with this interface.

gdb/ChangeLog:

	* NEWS: Mention the two new methods.
	* python/py-frame.c (frapy_level): New function.
	(frame_object_methods): Register 'level' method.
	* python/py-unwind.c (pending_framepy_level): New function.
	(pending_frame_object_methods): Register 'level' method.

gdb/doc/ChangeLog:

	* python.texi (Unwinding Frames in Python): Mention
	PendingFrame.level.
	(Frames In Python): Mention Frame.level.

gdb/testsuite/ChangeLog:

	* gdb.python/py-frame.exp: Add Frame.level tests.
	* gdb.python/py-pending-frame-level.c: New file.
	* gdb.python/py-pending-frame-level.exp: New file.
	* gdb.python/py-pending-frame-level.py: New file.
2021-06-21 16:20:08 +01:00
Felix Willgerodt
3aabdfe15b gdb, doc: Fix missed ChangeLog entry.
My previous commit "btrace, doc: Clarify record function-call-history
documentation." didn't add this to the actual ChangeLog file. Fix that.
2021-06-16 15:31:23 +02:00
Felix Willgerodt
cdb2186c9f btrace, doc: Clarify record function-call-history documentation.
The documentation for 'record function-call-history' mentions lines instead
of functions when talking about the number of functions printed, as currently
there is only one line printed per function.  Yet the code actually handles
this on function granularity not on line basis.  Future patches will
extend the number of lines printed per function.  This also makes it
consistent with the 'record instruction-history' command, where multiple
lines can be printed per instruction.

gdb/doc/ChangeLog:
2021-06-16  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (Process Record and Replay): Stop mentioning lines
	for "record function-call-history" and
	"set record function-call-history-size".
2021-06-16 13:55:25 +02:00
Lancelot SIX
f9e59d060f Use is/is not to check for None in python code.
While reviewing a patch sent to the mailing list, I noticed there are few
places where python code checks if a variable is 'None' or not by using the
comparison operators '==' and '!='.  PEP8[1], which is used as coding standard
in GDB coding standards, recommends using 'is' / 'is not' when comparing to a
singleton such as 'None'.

This patch proposes to change the instances of '== None' by 'is None' and
'!= None' by 'is not None'.

[1] https://www.python.org/dev/peps/pep-0008/

gdb/doc/ChangeLog:

	* python.texi (Writing a Pretty-Printer): Use 'is None' instead of
	'== None'.

gdb/ChangeLog:

	* python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None' instead of
	'== None'.
	(FrameVars): Use 'is not None' instead of '!= None'.
	* python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority): Use 'is None'
	instead of '== None' and 'is not None' instead of '!= None'.

gdb/testsuite/ChangeLog:

	* gdb.base/premature-dummy-frame-removal.py (TestUnwinder): Use
	'is None' instead of '== None' and 'is not None' instead of
	'!= None'.
	* gdb.python/py-frame-args.py (lookup_function): Same.
	* gdb.python/py-framefilter-invalidarg.py (Reverse_Function): Same.
	* gdb.python/py-framefilter.py (Reverse_Function): Same.
	* gdb.python/py-nested-maps.py (lookup_function): Same.
	* gdb.python/py-objfile-script-gdb.py (lookup_function): Same.
	* gdb.python/py-prettyprint.py (lookup_function): Same.
	* gdb.python/py-section-script.py (lookup_function): Same.
	* gdb.python/py-unwind-inline.py (dummy_unwinder): Same.
	* gdb.python/python.exp: Same.
	* gdb.rust/pp.py (lookup_function): Same.
2021-06-08 23:49:05 +01:00
Shahab Vahedi
ae61ef2c56 arc: Add 'set disassembler-options' support
Implement ARC target support for passing options to the disassembler
through the command interface. e.g.:

gdb> set disassembler-options cpu=hs38_linux ...

gdb/ChangeLog:

	* NEWS: Document 'set disassembler-options' support for the ARC
	target.
	* arc-tdep.c (arc_gdbarch_init): Set
	'gdbarch_valid_disassembler_options'.

gdb/doc/ChangeLog:

	* gdb.texinfo (Source and Machine Code): Document 'set
	disassembler-options' support for the ARC target.

gdb/testsuite/ChangeLog:

	* gdb.arch/arc-disassembler-options.exp: New test.
	* gdb.arch/arc-disassembler-options.s: New test source.
2021-06-05 11:43:07 +02:00
Hannes Domani
a53755664f Forward mouse click to python TUI window
If the TUI window object implements the click method, it is called for each
mouse click event in this window.

gdb/ChangeLog:

2021-06-04  Hannes Domani  <ssbssa@yahoo.de>

	* python/py-tui.c (class tui_py_window): Add click function.
	(tui_py_window::click): Likewise.

gdb/doc/ChangeLog:

2021-06-04  Hannes Domani  <ssbssa@yahoo.de>

	* python.texi (TUI Windows In Python): Document Window.click.
2021-06-04 16:18:10 +02:00
Hannes Domani
3067d0b1be Fix InlinedFrameDecorator example
Argument fobj was only available in the constructor.

gdb/doc/ChangeLog:

2021-05-29  Hannes Domani  <ssbssa@yahoo.de>

	* python.texi (Writing a Frame Filter): Fix example.
2021-05-29 13:39:18 +02:00