History log of /freebsd-current/sys/gdb/gdb_main.c
Revision Date Author Comments
# 0adc959a 14-Mar-2024 Andrew Turner <andrew@FreeBSD.org>

sys/gdb: Support hardware breakpoints

Support the use of hardware breakpoints in the kernel gdb stub.

Reviewed by: jhb (earlier version)
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D44354


# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 7446b088 08-Mar-2021 Mitchell Horne <mhorne@FreeBSD.org>

gdb: report specific stop reason for watchpoints

The remote protocol allows for implementations to report more specific
reasons for the break in execution back to the client [1]. This is
entirely optional, so it is only implemented for amd64, arm64, and i386
at the moment.

[1] https://sourceware.org/gdb/current/onlinedocs/gdb/Stop-Reply-Packets.html

Reviewed by: jhb
MFC after: 3 weeks
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
NetApp PR: 51
Differential Revision: https://reviews.freebsd.org/D29174


# 4beb3858 08-Mar-2021 Mitchell Horne <mhorne@FreeBSD.org>

gdb: allow setting/removing hardware watchpoints

Handle the 'z' and 'Z' remote packets for manipulating hardware
watchpoints.

This could be expanded quite easily to support hardware or software
breakpoints as well.

https://sourceware.org/gdb/onlinedocs/gdb/Packets.html

Reviewed by: cem, markj
MFC after: 3 weeks
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
NetApp PR: 51
Differential Revision: https://reviews.freebsd.org/D29173


# fa2528ac 18-Feb-2021 Alex Richardson <arichardson@FreeBSD.org>

Use atomic loads/stores when updating td->td_state

KCSAN complains about racy accesses in the locking code. Those races are
fine since they are inside a TD_SET_RUNNING() loop that expects the value
to be changed by another CPU.

Use relaxed atomic stores/loads to indicate that this variable can be
written/read by multiple CPUs at the same time. This will also prevent
the compiler from doing unexpected re-ordering.

Reported by: GENERIC-KCSAN
Test Plan: KCSAN no longer complains, kernel still runs fine.
Reviewed By: markj, mjg (earlier version)
Differential Revision: https://reviews.freebsd.org/D28569


# 3f3cc995 23-Dec-2020 Mitchell Horne <mhorne@FreeBSD.org>

gdb(4): allow bulk write of registers

Add support for the remote 'G' packet. This is not widely used by gdb
when 'P' is supported, but is technically required by any remote gdb
stub implementation [1].

[1] https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html

Reviewed by: cem
MFC after: 1 week
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
NetApp PR: 44
Differential Revision: https://reviews.freebsd.org/D27644


# fd29833d 23-Dec-2020 Mitchell Horne <mhorne@FreeBSD.org>

gdb(4): handle single register read packets

We support bulk reads of the register set, but not reading specific
registers via the 'p' packet. This is useful at least for the 'call'
command in gdb.

Reviewed by: cem
MFC after: 1 week
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
NetApp PR: 44
Differential Revision: https://reviews.freebsd.org/D27644


# a91812f6 30-Sep-2020 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Don't escape GDB special characters at application layer

In r351368, we introduced this XML- and GDB-encoded data. The protocol
'offset' should reflex the logical XML data offset, but unfortunately we
counted the GDB escapes as well.

In fact, we cannot safely do GDB character escaping at this layer at
all, because we don't know what will be flushed in a packet. It is
bogus to send only the first character of a two-character escape
sequence.

This patch "corrects" the problem by squashing these characters in the
transmitted XML document. It would be nice to transmit the characters
faithfully, but that is a more complicated change. Thread names are a
nice convenience feature for the GDB client, but one can always inspect
td_name or p_comm directly to find the true name.

Reported by: Ka Ho Ng <khng300 AT gmail.com>
Tested by: Ka Ho Ng
Reviewed by: emaste, markj, rlibby
Differential Revision: https://reviews.freebsd.org/D26599


# 5af88677 18-Aug-2020 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Support empty qSupported queries

Technically a client may send a qSupported query without specifying any
client features. We should respond with our supported list in that case
instead of bailing with error.

Reported by: rlibby
Reviewed by: emaste, rlibby, vangyzen
Sponsored by: Isilon
Differential Revision: https://reviews.freebsd.org/D26115


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# fa76c6f9 16-Dec-2019 Leandro Lupori <luporl@FreeBSD.org>

[PPC] Handle qOffsets packet

On PowerPC, this is needed in order for the debugger to find out
the memory offset where the kernel image was loaded on the remote
target.

This fixes symbol resolution when remote debugging a PowerPC kernel.

Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D22767


# 6310546d 17-Oct-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Implement support for NoAckMode

When the underlying debugport transport is reliable, GDB's additional
checksums and acknowledgements are redundant. NoAckMode eliminates the
the acks and allows us to skip checking RX checksums. The GDB packet
framing does not change, so unfortunately (valid) checksums are still
included as message trailers.

The gdb(4) stub in FreeBSD advertises support for the feature in response to
the client's 'qSupported' request IFF the current debugport has the
gdb_dbfeatures flag GDB_DBGP_FEAT_RELIABLE set. Currently, only netgdb(4)
supports this feature.

If the remote GDB client supports the feature and does not have it disabled
via a GDB configuration knob, it may instruct our gdb(4) stub to enter
NoAckMode. Unless and until it issues that command, we must continue to
transmit acks as usual (and for now, we continue to wait until we receive
them as well, even if we know the debugport is on a reliable transport).

In the kernel sources, the sense of the flag representing the state of the
feature is reversed from that of the GDB command. (I.e., it is
'gdb_ackmode', not 'gdb_noackmode.') This is to avoid confusing double-
negative conditions.

For reference, see:
* https://sourceware.org/gdb/onlinedocs/gdb/Packet-Acknowledgment.html
* https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#QStartNoAckMode

Reviewed by: jhb, markj (both earlier version)
Differential Revision: https://reviews.freebsd.org/D21761


# dda17b36 17-Oct-2019 Conrad Meyer <cem@FreeBSD.org>

Implement NetGDB(4)

NetGDB(4) is a component of a system using a panic-time network stack to
remotely debug crashed FreeBSD kernels over the network, instead of
traditional serial interfaces.

There are three pieces in the complete NetGDB system.

First, a dedicated proxy server must be running to accept connections from
both NetGDB and gdb(1), and pass bidirectional traffic between the two
protocols.

Second, the NetGDB client is activated much like ordinary 'gdb' and
similarly to 'netdump' in ddb(4) after a panic. Like other debugnet(4)
clients (netdump(4)), the network interface on the route to the proxy server
must be online and support debugnet(4).

Finally, the remote (k)gdb(1) uses 'target remote <proxy>:<port>' (like any
other TCP remote) to connect to the proxy server.

The NetGDB v1 protocol speaks the literal GDB remote serial protocol, and
uses a 1:1 relationship between GDB packets and sequences of debugnet
packets (fragmented by MTU). There is no encryption utilized to keep
debugging sessions private, so this is only appropriate for local
segments or trusted networks.

Submitted by: John Reimer <john.reimer AT emc.com> (earlier version)
Discussed some with: emaste, markj
Relnotes: sure
Differential Revision: https://reviews.freebsd.org/D21568


# 10f6c05c 08-Sep-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Root a sysctl tree at 'debug.gdb.'

Like debug.ddb and debug.kdb. Rename 'debug.gdbcons' to 'debug.gdb.cons,'
but leave the old name as a compatibility alias.


# acef7371 21-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

Fix i386 build after r351368

Reported by: cy
Submitted by: cy


# 5df6fa43 21-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Style

No functional change.

I was surprised to find that no sys/ header already defines the -1 EOF
convention anywhere, so defined one locally.


# 5555afa1 21-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Implement qXfer:threads:read

This streams out an XML document over several GDB packets describing all
threads in the system; their ids, name, and any loosely defined "extra info"
we feel like including. For now, I have included a string version of the run
state, similar to some of the DDB logic to stringify thread state.

The benefit of supporting this in addition to the qfThreadInfo/qsThreadInfo
packing is that in this mode, the host gdb does not ask for every thread's
"qThreadExtraInfo," saving per-thread round-trips on "info threads."

To use this feature, (k)gdb needs to be built with the --with-expat option.
I would encourage enabling this option by default in our GDB port, if it is
not already.

Finally, there is another optional attribute you can specify per-thread
called a "handle." Handles are arbitrarily long sequences of bytes,
represented in the XML as hexadecimal. It is unclear to me how or if GDB
actually uses handles for anything. So I have left them out.


# c4fbbfaa 21-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Add basic 'qSupported' support

This is where the host GDB tells us what features it supports, and we
respond with the list we support. For now, just report PacketSize.


# 76c8c090 21-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Include thread in Target Halt Reason

This saves a round trip of the gdb remote inferior attempting to find
the thread id of the halted thread.

Sponsored by: Dell EMC Isilon


# 54a210d4 19-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

Fix stylistic nit in r351239

Meant to fix this before committing, but forgot.


# 3bbe6e64 19-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Support "qC" query

Sometimes GDB gets confused about what the current thread is. When it does,
it asks the remote: "Who am I?"

Answer it.


# 130ef1ad 19-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

gdb(4): Pack 'info threads' responses into fewer packets

We suffer at least one round trip ACK latency every command / packet that
GDB has to send and receive, and the response format for 'info threads'
supports packing many threads IDs into a single packet, so do so.

Adds and uses a new API, gdb_txbuf_has_capacity(), which checks for a
certain number of bytes available in the outgoing txbuf.

On an example amd64 VM, the number of RTTs to transmit this list is reduced
by a factor of 110x. This is especially beneficial with recent GDB, which
seems to request the list at least twice during attach.


# 497b6b2a 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/gdb: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 8a7a6571 16-Oct-2017 Ryan Libby <rlibby@FreeBSD.org>

gdb kernel server: fixup Search:memory style

This is a NFC patch to move around the Search:memory implementation so
that it doesn't exceed the standard column width and doesn't take so
much vertical space in gdb_trap.

Submitted by: Daniel O'Connor <darius@dons.net.au>
Reviewed by: cem, jhb
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D12684


# 27ecc2ad 05-Sep-2014 Benno Rice <benno@FreeBSD.org>

Add support for gdb's memory searching capabilities to our in-kernel gdb
server.

Submitted by: Daniel O'Connor <daniel.oconnor@isilon.com>
Reviewed by: jhb
Sponsored by: EMC Isilon Storage Division


# 28926c57 12-Apr-2012 John Baldwin <jhb@FreeBSD.org>

Update the ddb and gdb backends for the new 'trace_thread' hook.
It is implemented via db_trace_thread() for DDB and not implemented
for GDB. This should have been part of r234190.

Pointy hat to: jhb
Reported by: jkim
MFC after: 1 week


# 3a5d3671 18-Feb-2011 Matthew D Fleming <mdf@FreeBSD.org>

Modify kdb_trap() so that it re-calls the dbbe_trap function as long as
the debugger back-end has changed. This means that switching from ddb
to gdb no longer requires a "step" which can be dangerous on an
already-crashed kernel.

Also add a capability to get from the gdb back-end back to ddb, by
typing ^C in the console window.

While here, simplify kdb_sysctl_available() by using
sbuf_new_for_sysctl(), and use strlcpy() instead of strncpy() since the
strlcpy semantic is desired.

MFC after: 1 month


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d412b2de 28-Feb-2008 Peter Grehan <grehan@FreeBSD.org>

Add support for kgdb's 'detach' command.

Reviewed by: marcel
Sponsored by: Network Appliance


# e8d86c0e 26-May-2006 Poul-Henning Kamp <phk@FreeBSD.org>

Don't use GDB_DBGPORT() macro to fill in dummy element in gdb_dbgport_set.


# 7d0c6c9f 23-Mar-2006 Sam Leffler <sam@FreeBSD.org>

add support for copying console messages to a remote gdb

Reviewed by: kan


# 4af77ece 28-Mar-2005 Sam Leffler <sam@FreeBSD.org>

check return value of gdb_rx_varhex

Noticed by: Coverity Prevent analysis tool
Reviewed by: kan


# fa521b03 06-Jan-2005 Warner Losh <imp@FreeBSD.org>

/* -> /*- for copyright notices, minor format tweaks as necessary


# bcc5241c 30-Nov-2004 Marcel Moolenaar <marcel@FreeBSD.org>

Change gdb_cpu_setreg() to not take the value to which to set the
specified register, but a pointer to the in-memory representation of
that value. The reason for this is twofold:
1. Not all registers can be represented by a register_t. In particular
FP registers fall in that category. Passing the new register value
by reference instead of by value makes this point moot.
2. When we receive a G or P packet, both are for writing a register,
the packet will have the register value in target-byte order and
in the memory representation (modulo the fact that bytes are sent
as 2 printable hexadecimal numbers of course). We only need to
decode the packet to have a pointer to the register value.

This change fixes the bug of extracting the register value of the P
packet as a hexadecimal number instead of as a bit array. The quick
(and dirty) fix to bswap the register value in gdb_cpu_setreg() as
it has been added on i386 and amd64 can therefore be removed and has
in fact been that.

Tested on: alpha, amd64, i386, ia64, sparc64


# 03e62bf3 10-Aug-2004 Marcel Moolenaar <marcel@FreeBSD.org>

Comment-out the debugging printf I left in in case there were some
packet related problems. No problems have been reported.


# 72d44f31 10-Jul-2004 Marcel Moolenaar <marcel@FreeBSD.org>

Introduce the GDB debugger backend for the new KDB framework. The
backend improves over the old GDB support in the following ways:
o Unified implementation with minimal MD code.
o A simple interface for devices to register themselves as debug
ports, ala consoles.
o Compression by using run-length encoding.
o Implements GDB threading support.