microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
register_xml_printer.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
6#include "../microfmt.hpp"
7#include "dwarf_abi.hpp"
8
9namespace microfmt::gdb {
10
15public:
22 static void format_register(sink out, const register_mapping &reg) noexcept {
23 // Output format: <reg name="rax" bitsize="64" regnum="0" type="int64"/>
24 out.write("<reg name=\"");
25 out.write(reg.name);
26 out.write("\" bitsize=\"");
27 format_to(out, "{}", reg.bit_size);
28 out.write("\" regnum=\"");
29 format_to(out, "{}", reg.gdb_index);
30
31 if (!reg.gdb_type.empty()) {
32 out.write("\" type=\"");
33 out.write(reg.gdb_type);
34 }
35 out.write("\"/>");
36 }
37
46 template <typename AbiTraits>
47 static void format_target_xml(sink out, string_view gdb_arch_name,
48 string_view feature_name = "org.gnu.gdb.custom") noexcept {
49 // XML Header and DOCTYPE
50 out.write("<?xml version=\"1.0\"?>\n");
51 out.write("<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n");
52 out.write("<target>\n");
53
54 // Architecture declaration
55 out.write(" <architecture>");
56 out.write(gdb_arch_name);
57 out.write("</architecture>\n");
58
59 // Feature group block
60 out.write(" <feature name=\"");
61 out.write(feature_name);
62 out.write("\">\n");
63
64 // Iterate over the core register layout.
65 for (const auto &reg : AbiTraits::gdb_register_traits::layout()) {
66 out.write(" ");
67 format_register(out, reg);
68 out.write("\n");
69 }
70
71 out.write(" </feature>\n");
72 out.write("</target>\n");
73 }
74};
75
76} // namespace microfmt::gdb
Zero-allocation printer for generating GDB target XML descriptions.
Definition register_xml_printer.hpp:14
static void format_register(sink out, const register_mapping &reg) noexcept
Formats a single register as a GDB XML <reg> node.
Definition register_xml_printer.hpp:22
static void format_target_xml(sink out, string_view gdb_arch_name, string_view feature_name="org.gnu.gdb.custom") noexcept
Generates a complete GDB target.xml document for a specific architecture.
Definition register_xml_printer.hpp:47
#define MICROFMT_API_CLASS
Definition compat.hpp:181
Per-architecture ABI traits describing registers used during DWARF unwinding.
Definition gdb_decoders.hpp:15
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
Maps a single register between GDB and DWARF definitions.
Definition gdb_registers.hpp:15