Max OS 0.3
Loading...
Searching...
No Matches
gdbstub.h
Go to the documentation of this file.
1
14#ifndef MAXOS_RUNTIME_GDBSTUB_H
15#define MAXOS_RUNTIME_GDBSTUB_H
16
17#include <libcommon/string.h>
18
19#include <console/serial.h>
20#include <processes/process.h>
22
23namespace MaxOS::runtime {
24
26 constexpr bool DO_DEBUGGING = false;
27
29 constexpr char* DEBUG_TARGET = "DriverManager.elf";
30
31 class GDBServer;
32
38
39 private:
40 GDBServer* m_gdb_handler;
41
42 public:
45
47
48 };
49
55
56 private:
57 GDBServer* m_gdb_handler;
58
59 public:
62
64
65 };
66
72
73 private:
74
75 processes::Thread* m_attached_thread;
76
77 console::SerialConsole* m_serial;
78 void handle_interrupt() override;
79
80 string current_command_buffer;
81 void try_handle_command();
82 void delegate_command(const string& command);
83
84 string format_register(uint64_t value, int num_bytes);
85
86 TrapFlagExcpetion m_trap_flag_handler;
87 BreakPointException m_break_point_handler;
88
89 common::Map<void*, uint8_t> m_breakpoints;
90
91 public:
93 ~GDBServer();
94
95 void attach(processes::Thread* thread);
96
97 string get_checksum(const string& payload);
98 bool check_checksum(const string& payload, const string& checksum);
99
100 string build_message(const string& payload);
101 void send_message(const string& payload);
102
103 void send_empty();
104 void send_supported(const string& peer_supported);
105 void send_registers();
106 void send_memory(const string& message);
107 void send_memory(void* address, size_t length);
108 void send_breakpoint_reached();
109
111 void handle_set_breakpoint(const string& message);
112 void handle_set_breakpoint(void* address);
113 void handle_remove_breakpoint(const string& message);
114 void handle_remove_breakpoint(void* address);
115 void handle_continue();
116 void handle_detach();
117
119 system::cpu_status_t thread_regs;
120
121 };
122
123}
124
125#endif //MAXOS_RUNTIME_GDBSTUB_H
A driver for the serial output.
Definition serial.h:25
Base class for handing CPU expection interrupts.
Definition interrupts.h:61
Handles a certain interrupt number.
Definition interrupts.h:44
virtual void handle_interrupt()
Handles an interrupt.
The execution context of a sub-process thread.
Definition process.h:50
Exception handler for a hardware breakpoint.
Definition gdbstub.h:54
Handler for running a GDB server over serial.
Definition gdbstub.h:71
processes::Thread * attached_thread()
Get the attached thread.
Definition gdbstub.cpp:536
void handle_step_instruction()
Set the trap flag and allow the thread to run.
Definition gdbstub.cpp:383
string build_message(const string &payload)
Converts a message into the form GDB expects, including and ACK package.
Definition gdbstub.cpp:258
void send_message(const string &payload)
Converts a message to the required form and sends it over serial.
Definition gdbstub.cpp:267
void handle_set_breakpoint(const string &message)
Set a software break point by replacing the instruction with a INT3.
Definition gdbstub.cpp:405
string get_checksum(const string &payload)
Calculates the GDB checksum of a command.
Definition gdbstub.cpp:222
bool check_checksum(const string &payload, const string &checksum)
Validates the checksum of a commnad.
Definition gdbstub.cpp:248
void send_supported(const string &peer_supported)
Sends the features that this GDB stub supports to the GDB server.
Definition gdbstub.cpp:284
void send_memory(const string &message)
Send a chunk of memory to the GDB server.
Definition gdbstub.cpp:343
void handle_remove_breakpoint(const string &message)
Remove a software break point, and replace the original opcode.
Definition gdbstub.cpp:457
void handle_continue()
Continues the exeuction of the thread, acknowledges the request and allows the thread to run.
Definition gdbstub.cpp:508
void send_empty()
Send an empty message to the GDB server.
Definition gdbstub.cpp:275
void send_registers()
Sends the registers of the thread to the GDB server.
Definition gdbstub.cpp:300
void attach(processes::Thread *thread)
Begin debugging a thread, will start paused.
Definition gdbstub.cpp:43
void handle_detach()
Detaches the thread from the GDB, removing all breakpoints and allowing it to be scheduled as usual.
Definition gdbstub.cpp:520
Exception handler for a hardware mem watch.
Definition gdbstub.h:37
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
constexpr bool DO_DEBUGGING
Whether to use the serial for GDB communcation or for logging.
Definition gdbstub.h:26
constexpr char * DEBUG_TARGET
The userspace process to attach to.
Definition gdbstub.h:29
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
Defines Process and Thread classes for managing processes and their execution contexts.
Defines a SerialConsole driver for serial output.