microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
gdb_packet_metadata.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Jarosław Pelczar <jarek@jpelczar.com>
2// SPDX-License-Identifier: BSD-2-Clause
3
4#pragma once
5
8#include "../microfmt.hpp"
10#include <cstdint>
11
12namespace microfmt::gdb {
13
17struct MICROFMT_API_CLASS RELOCO_POINTER packet_metadata {
19 string_view name; // Human-readable identifier for logging/diagnostics
20 string_view prefix; // The GDB RSP protocol prefix string (e.g., "qSupported", "m", "Z")
21};
22
27// NOLINTNEXTLINE(reloco-no-c-array): fixed-size buffer/table for span APIs
29 {packet_type::unknown, "unknown", ""},
30 {packet_type::halt_reason, "halt_reason", "?"},
31 {packet_type::continue_exec, "continue_exec", "c"},
32 {packet_type::continue_with_signal, "continue_with_signal", "C"},
33 {packet_type::step_exec, "step_exec", "s"},
34 {packet_type::step_with_signal, "step_with_signal", "S"},
35 {packet_type::kill, "kill", "k"},
36 {packet_type::detach, "detach", "D"},
37 {packet_type::restart, "restart", "R"},
38 {packet_type::enable_extended_mode, "enable_extended_mode", "!"},
39 {packet_type::read_general_registers, "read_general_registers", "g"},
40 {packet_type::write_general_registers, "write_general_registers", "G"},
41 {packet_type::read_single_register, "read_single_register", "p"},
42 {packet_type::write_single_register, "write_single_register", "P"},
43 {packet_type::read_memory, "read_memory", "m"},
44 {packet_type::write_memory_hex, "write_memory_hex", "M"},
45 {packet_type::write_memory_binary, "write_memory_binary", "X"},
46 {packet_type::search_memory, "search_memory", "qSearch:memory"},
47 {packet_type::insert_break_watch, "insert_break_watch", "Z"},
48 {packet_type::remove_break_watch, "remove_break_watch", "z"},
49 {packet_type::set_thread, "set_thread", "H"},
50 {packet_type::thread_is_alive, "thread_is_alive", "T"},
51 {packet_type::query_supported, "query_supported", "qSupported"},
52 {packet_type::query_first_thread_info, "query_first_thread_info", "qfThreadInfo"},
53 {packet_type::query_subsequent_thread, "query_subsequent_thread", "qsThreadInfo"},
54 {packet_type::query_current_thread, "query_current_thread", "qC"},
55 {packet_type::query_thread_extra_info, "query_thread_extra_info", "qThreadExtraInfo"},
56 {packet_type::query_attached, "query_attached", "qAttached"},
57 {packet_type::query_offsets, "query_offsets", "qOffsets"},
58 {packet_type::query_crc, "query_crc", "qCRC"},
59 {packet_type::query_symbol, "query_symbol", "qSymbol"},
60 {packet_type::query_trace_status, "query_trace_status", "qTStatus"},
61 {packet_type::set_start_noack_mode, "set_start_noack_mode", "QStartNoAckMode"},
62 {packet_type::set_pass_signals, "set_pass_signals", "QPassSignals"},
63 {packet_type::set_program_signals, "set_program_signals", "QProgramSignals"},
64 {packet_type::set_non_stop, "set_non_stop", "QNonStop"},
65 {packet_type::set_thread_events, "set_thread_events", "QThreadEvents"},
66 {packet_type::v_cont, "v_cont", "vCont"},
67 {packet_type::v_cont_supported, "v_cont_supported", "vCont?"},
68 {packet_type::v_attach, "v_attach", "vAttach"},
69 {packet_type::v_run, "v_run", "vRun"},
70 {packet_type::v_kill, "v_kill", "vKill"},
71 {packet_type::v_stopped, "v_stopped", "vStopped"},
72 {packet_type::v_must_reply_empty, "v_must_reply_empty", "vMustReplyEmpty"},
73 {packet_type::file_io_request, "file_io_request", "F"}};
74
75// Guarantee the table matches the enum exactly at compile time
76static_assert((sizeof(packet_metadata_table) / sizeof(packet_metadata_table[0])) ==
77 static_cast<size_t>(packet_type::_count),
78 "GDB Packet metadata table is missing entries or out of sync with packet_type enum.");
79
86[[nodiscard]] constexpr const packet_metadata &get_packet_metadata(packet_type type) noexcept {
87 const auto index = static_cast<size_t>(type);
88 if (index >= static_cast<size_t>(packet_type::_count)) {
89 return packet_metadata_table[static_cast<size_t>(packet_type::unknown)];
90 }
91 RELOCO_BEGIN_UNSAFE_BUFFER_USAGE;
92 return packet_metadata_table[index];
93 RELOCO_END_UNSAFE_BUFFER_USAGE;
94}
95
96} // namespace microfmt::gdb
#define MICROFMT_API_CLASS
Definition compat.hpp:181
Comprehensive enumeration of GDB RSP packet types.
Definition gdb_decoders.hpp:15
packet_type
High-level classification of GDB Remote Serial Protocol commands.
Definition gdb_packet_types.hpp:64
constexpr const packet_metadata & get_packet_metadata(packet_type type) noexcept
Retrieves metadata for a specific packet type with strict bounds checking.
Definition gdb_packet_metadata.hpp:86
constexpr packet_metadata packet_metadata_table[]
Compile-time lookup table mapping packet_type to its metadata. Initialized strictly with C++17 positi...
Definition gdb_packet_metadata.hpp:28
Metadata descriptor for a GDB RSP packet.
Definition gdb_packet_metadata.hpp:17
string_view name
Definition gdb_packet_metadata.hpp:19
string_view prefix
Definition gdb_packet_metadata.hpp:20