StuBS
|
Remote stub for GNU Debugger (GDB) More...
#include <debug/gdb/stub.h>
Public Member Functions | |
GDB_Stub (bool wait=false, bool debug_output=false, ComPort port=COM1, BaudRate baud_rate=BAUD_9600) | |
constructor More... | |
![]() | |
Serial (ComPort port=COM1, BaudRate baud_rate=BAUD_115200, DataBits data_bits=DATA_8BIT, StopBits stop_bits=STOP_1BIT, Parity parity=PARITY_NONE) | |
Constructor. More... | |
int | read (bool blocking=true) |
Read one byte from the serial interface. More... | |
int | write (char out, bool blocking=true) |
Write one byte to the serial interface. More... | |
bool | receiveInterrupt (bool enable) |
Activate or deactivate interrupts on data reception. More... | |
Static Public Attributes | |
static int | signal = 0 |
Last trap/interrupt vector handled in GDB. More... | |
Protected Member Functions | |
void | handle () |
Handling traps. More... | |
int | writeString (const char *buf, size_t len) |
Send a string via the serial connection. More... | |
int | readString (char *buf, size_t buf_len, size_t len) |
Receive a string via the serial connection. More... | |
int | sendPacket (const char *pkt_data, size_t pkt_len) |
Transmits a packet of data. More... | |
int | receivePacket (char *pkt_buf, size_t pkt_buf_len, size_t *pkt_len) |
Receives a packet of data assuming a 7-bit clean connection. More... | |
int | receiveAck (void) |
Receive acknowledgment for a packet. More... | |
int | sendOkPacket () |
Create and send an OK packet (OK ) More... | |
int | sendSignalPacket (char *buf, size_t buf_len, char signal) |
Create and send a signal packet (S [int] ) More... | |
int | sendErrorPacket (char *buf, size_t buf_len, char error) |
Create and send an error packet (E [code] ) More... | |
Static Protected Member Functions | |
static int | checksum (const char *buf, size_t len) |
Calculate 8-bit checksum of a buffer. More... | |
static int | memRead (char *buf, size_t buf_len, uintptr_t addr, size_t len, bool hex) |
Read contents of system memory area into the buffer. More... | |
static int | memWrite (const char *buf, size_t buf_len, uintptr_t addr, size_t len, bool hex) |
Write buffer contents to system memory area. More... | |
static void | sysContinue () |
Continue program execution (at current instruction pointer) | |
static void | sysStep () |
Single step the next instruction. | |
Friends | |
void | gdb_interrupt_handler (DebugContext *context) |
Allow the generic GDB interrupt handler to access the protected methods of this class. More... | |
Additional Inherited Members | |
![]() | |
enum | ComPort { COM1 = 0x3f8 , COM2 = 0x2f8 , COM3 = 0x3e8 , COM4 = 0x2e8 } |
COM-Port. More... | |
enum | BaudRate { BAUD_300 = 384 , BAUD_600 = 192 , BAUD_1200 = 96 , BAUD_2400 = 48 , BAUD_4800 = 24 , BAUD_9600 = 12 , BAUD_19200 = 6 , BAUD_38400 = 3 , BAUD_57600 = 2 , BAUD_115200 = 1 } |
Transmission speed. More... | |
enum | DataBits { DATA_5BIT = 0 , DATA_6BIT = 1 , DATA_7BIT = 2 , DATA_8BIT = 3 } |
Number of data bits per character. | |
enum | StopBits { STOP_1BIT = 0 , STOP_1_5BIT = 4 , STOP_2BIT = 4 } |
Number of stop bits per character. | |
enum | Parity { PARITY_NONE = 0 , PARITY_ODD = 8 , PARITY_EVEN = 24 , PARITY_MARK = 40 , PARITY_SPACE = 56 } |
parity bit | |
![]() | |
const ComPort | port |
Selected COM port. | |
Remote stub for GNU Debugger (GDB)
Allows remote debugging of the operating system with GDB on real (bare metal) hardware (but also in the emulator) by implementing the main part of the GDB Remote Serial Protocols (RSP), installing own interrupt handler routines for traps and communicating with the GDB host over the serial port.
To use this feature, GDB must be started on the host with the identical kernel binary file as the operating system on the target hardware runs with – ideally in the kernels source code directory, because then the source code can be embedded in the debug output of the GDB host.
In addition, the settings for serial transmission must be identical on both hardware and GDB.
print GDB_Stub::signal
.
|
explicit |
constructor
configures interrupt handler and serial interface (as 8N1
)
NUM_HANDLERS
in debug/gdb/handler.asm
) is big enough to create an entry routine for the serial vector and make a corresponding call to IDT::handle.wait | Wait for a GDB connection after configuration |
debug_output | Debug the stub by printing the communication on the DBG output (could be useful while extending the RSP) |
port | COM port for the serial connection |
baud_rate | Baud Rate, default for GDB is 9600 (can be a bottleneck) |
|
protected |
Handling traps.
Called by the generic debug interrupt handler after the current core state has been stored.
This contains the heart functionality of the GDB_Stub, including the communication with the GDB host.
|
protected |
Send a string via the serial connection.
buf | Pointer to buffer |
len | Size of buffer (or characters to transmit) |
0 | on success |
-1 | if no or not all bytes have been sent |
|
protected |
Receive a string via the serial connection.
buf | Pointer to buffer |
buf_len | Size of buffer |
len | Size of received characters |
0 | on success |
-1 | if no or not all bytes have been received |
|
protected |
Transmits a packet of data.
Packets are of the form:
pkt_data | Pointer to packet buffer |
pkt_len | Size of packet buffer |
0 | if the packet was transmitted and acknowledged |
1 | if the packet was transmitted but not acknowledged |
-1 | otherwise |
|
protected |
Receives a packet of data assuming a 7-bit clean connection.
pkt_buf | Pointer to packet buffer |
pkt_buf_len | Size of packet buffer |
pkt_len | Size of packet to receive |
0 | if the packet was received |
-1 | otherwise |
|
staticprotected |
Calculate 8-bit checksum of a buffer.
buf | Pointer to buffer |
len | Size of buffer |
|
protected |
Receive acknowledgment for a packet.
3
(not ASCII, also no valid packet). Our operating system is usually in this function when receiving this value. We can simply ignore the receipt of the value and wait for the next character – the actual acknowledgement.\3
0 | received [positive] acknowledgment (ACK, + ) |
1 | received negative acknowledgment (NACK, - ) |
-1 | otherwise (invalid character) |
|
protected |
Create and send an OK packet (OK
)
|
protected |
Create and send a signal packet (S [int]
)
buf | Pointer to buffer |
buf_len | Size of buffer |
signal | Interrupt vector |
|
protected |
Create and send an error packet (E [code]
)
buf | Pointer to buffer |
buf_len | Size of buffer |
error | Error code |
|
staticprotected |
Read contents of system memory area into the buffer.
buf | Pointer to buffer |
buf_len | Size of buffer |
addr | Base address of system memory to read from |
len | Size of memory area to read from |
hex | Buffer content has hexadecimal (true ) or binary (false ) encoding |
-1
on error (buffer to small)
|
staticprotected |
Write buffer contents to system memory area.
buf | Pointer to buffer |
buf_len | Size of buffer |
addr | Base address of system memory to write at |
len | Size of memory area to write at |
hex | Buffer content has hexadecimal (true ) or binary (false ) encoding |
-1
on error (buffer to big)
|
friend |
Allow the generic GDB interrupt handler to access the protected methods of this class.
Similar to the default interrupt_handler. Called by the entry function written in assembly (see debug/gbd/handler.asm
) – these routines are installed in the constructor.
After preparing the data this function calls GDB_Stub::handle, which handles the communication with the host via the serial interface.
context | contains a pointer to the stack, which can be used to access the debug interrupt context. |
|
static |
Last trap/interrupt vector handled in GDB.
store signal to simplify debugging