* Proposed Addition to GDB packets
@ 2025-08-21 21:05 Alkallas, Mouhanad
2025-08-21 23:07 ` Aaron Griffith
0 siblings, 1 reply; 3+ messages in thread
From: Alkallas, Mouhanad @ 2025-08-21 21:05 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 4241 bytes --]
[Public]
Hi,
I am looking extend the capabilities of KGDB for Linux, however in order to do this I need to define a new packet format.
See proposed Linux kernel patch below.
The proposal is to add a packet "J" for customization in privately defined KGDB IO Module.
Packet format would "J <custom data>", instead of gdbstub.c handling the packet, it would forward the call to the attached KGDB IO Module to service the packet.
This allows developers to create custom commands meeting their needs, such as but not limited to:
- Extend KGDBoE functionality to handle reading register from MMMIO physical address prior to driver load
- Extend KGDBoE functionality to perform pci re-enumeration and device reset prior to driver load
- Extend packets to work cohesively with onboard device firmware's and debuggers
This change does not require any GDB functional changes or code update, but does require documentation update and reservation of packets starting with 'J'
The questions I have are:
- Are there any reservations about this change?
- Is there a process I need to follow to get this change acknowledged across multiple open source projects, Linux & GDB?
Linux patch below
Subject: [PATCH] KGDB: Extend Serial GDB packet such that custom KGDB IO modules can extend the functionality for specific devices without having to modify the kernel. Extended functionality is meant to be proprietary to each developer and should have no impact on kernel operation.
Sample Use Case:
- Extend KGDBoE functionality to handle reading register from MMMIO physical address prior to driver load
- Extend KGDBoE functionality to perform pci re-enumeration and device reset prior to driver load
- Extend packets to work cohesively with onboard device firmwares and debuggers
Signed-off-by: Mouhanad Alkallas <malkalla@amd.com<mailto:malkalla@amd.com>>
---
include/linux/kgdb.h | 3 +++
kernel/debug/gdbstub.c | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h index 5eebbe7a3545..7f260ad3ded6 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -285,6 +285,8 @@ struct kgdb_arch {
* the I/O driver.
* @post_exception: Pointer to a function that will do any cleanup work
* for the I/O driver.
+ * @custom_packet: Pointer to a function that will handle customer packets.
+ * provided parameters are input buffer and output buffer.
* @cons: valid if the I/O device is a console; else NULL.
*/
struct kgdb_io {
@@ -296,6 +298,7 @@ struct kgdb_io {
void (*deinit) (void);
void (*pre_exception) (void);
void (*post_exception) (void);
+ int (*custom_packet) (char *, char *);
struct console *cons;
};
diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index f625172d4b67..326356f431a6 100644
--- a/kernel/debug/gdbstub.c
+++ b/kernel/debug/gdbstub.c
@@ -842,6 +842,18 @@ static void gdb_cmd_task(struct kgdb_state *ks)
}
}
+/* Handle the 'J' task query packets */ static void
+gdb_cmd_custom_packet(struct kgdb_state *ks) {
+ if (dbg_io_ops->custom_packet) {
+ if (!dbg_io_ops->custom_packet(remcom_in_buffer, remcom_out_buffer)) {
+ return;
+ } else
+ error_packet(remcom_out_buffer, -EINVAL);
+ }
+ error_packet(remcom_out_buffer, -EINVAL); }
+
/* Handle the 'T' thread query packets */ static void gdb_cmd_thread(struct kgdb_state *ks) { @@ -1029,6 +1041,9 @@ int gdb_serial_stub(struct kgdb_state *ks)
case 'H': /* task related */
gdb_cmd_task(ks);
break;
+ case 'J': /* Handle custom packet */
+ gdb_cmd_custom_packet(ks);
+ break;
case 'T': /* Query thread status */
gdb_cmd_thread(ks);
break;
--
2.43.0
[-- Attachment #2: Type: text/html, Size: 11353 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Proposed Addition to GDB packets
2025-08-21 21:05 Proposed Addition to GDB packets Alkallas, Mouhanad
@ 2025-08-21 23:07 ` Aaron Griffith
2025-08-25 14:54 ` Alkallas, Mouhanad
0 siblings, 1 reply; 3+ messages in thread
From: Aaron Griffith @ 2025-08-21 23:07 UTC (permalink / raw)
To: Alkallas, Mouhanad; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 954 bytes --]
On Thu, Aug 21, 2025 at 5:05 PM Alkallas, Mouhanad <
Mouhanad.Alkallas@amd.com> wrote:
> The proposal is to add a packet “J” for customization in privately
> defined KGDB IO Module.
>
> Packet format would “J <custom data>”, instead of gdbstub.c handling
> the packet, it would forward the call to the attached KGDB IO Module
> to service the packet.
I'm not familiar with KGDB specifically, but a common solution used by
other stubs is to use the "qRcmd" packet for custom commands. I know the
Black Magic debug probe uses this to allow the user to scan the JTAG chain
it's connected to and a few other things.
The documentation for KGDB [1] indicates it already uses this packet for
some commands. Is it possible to hook in to that existing mechanism? Or is
that unsuitable for the problem you're trying to solve?
[1]:
https://www.kernel.org/doc/html/v4.14/dev-tools/kgdb.html#running-kdb-commands-from-gdb
-Aaron
[-- Attachment #2: Type: text/html, Size: 1227 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Proposed Addition to GDB packets
2025-08-21 23:07 ` Aaron Griffith
@ 2025-08-25 14:54 ` Alkallas, Mouhanad
0 siblings, 0 replies; 3+ messages in thread
From: Alkallas, Mouhanad @ 2025-08-25 14:54 UTC (permalink / raw)
To: Aaron Griffith; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Aaron,
You are right, I didn’t know that you can use this from a serial connection.
This makes my previous proposal unnecessary.
Thanks for the feedback.
Regards,
Mouhanad Alkallas
From: Aaron Griffith <aargri@gmail.com>
Sent: Thursday, August 21, 2025 4:08 PM
To: Alkallas, Mouhanad <Mouhanad.Alkallas@amd.com>
Cc: gdb-patches@sourceware.org
Subject: Re: Proposed Addition to GDB packets
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
On Thu, Aug 21, 2025 at 5:05 PM Alkallas, Mouhanad <Mouhanad.Alkallas@amd.com<mailto:Mouhanad.Alkallas@amd.com>> wrote:
> The proposal is to add a packet “J” for customization in privately
> defined KGDB IO Module.
>
> Packet format would “J <custom data>”, instead of gdbstub.c handling
> the packet, it would forward the call to the attached KGDB IO Module
> to service the packet.
I'm not familiar with KGDB specifically, but a common solution used by other stubs is to use the "qRcmd" packet for custom commands. I know the Black Magic debug probe uses this to allow the user to scan the JTAG chain it's connected to and a few other things.
The documentation for KGDB [1] indicates it already uses this packet for some commands. Is it possible to hook in to that existing mechanism? Or is that unsuitable for the problem you're trying to solve?
[1]: https://www.kernel.org/doc/html/v4.14/dev-tools/kgdb.html#running-kdb-commands-from-gdb
-Aaron
[-- Attachment #2: Type: text/html, Size: 5216 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-25 14:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21 21:05 Proposed Addition to GDB packets Alkallas, Mouhanad
2025-08-21 23:07 ` Aaron Griffith
2025-08-25 14:54 ` Alkallas, Mouhanad
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox