L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
utrace
Go to the documentation of this file.
1// vim:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * Copyright (C) 2026 Kernkonzept GmbH.
4 * Author(s): Martin Decky <martin.decky@kernkonzept.com>
5 *
6 * License: see LICENSE.spdx (in this directory or the directories above)
7 */
8
17
18#pragma once
19
20#include <version>
21#include <bit>
22#include <string>
23#include <optional>
24#include <l4/sys/ktrace_events.h>
25#include <l4/sys/consts.h>
26#include <l4/sys/capability>
27#include <l4/sys/debugger>
28#include <l4/utrace/ring_buffer>
29
30#if defined(__cpp_lib_generator)
31#include <generator>
32#else
33#include <vector>
34#endif
35
36namespace utrace {
37
39static constexpr size_t log_name_buffer_size = 64U;
40
42static constexpr size_t object_name_buffer_size = 16U;
43
50class Tracebuffer
51{
52public:
53 using Sequence = L4_ktrace_t__Mword;
54 using Item = l4_tracebuffer_entry_t;
55
57 using Drop_policy = Buffer::Drop_policy;
58 using Status = Buffer::Status;
59 using Slot = Buffer::Slot;
60
61 using Id = unsigned long;
62
63 static_assert(sizeof(Status) <= L4_PAGESIZE);
64
67 {
68 unsigned index;
69 std::string name;
70 std::string shortname;
71 };
72
82 static void validate();
83
85 static unsigned version();
86
88 static std::endian endianness();
89
98 static std::optional<Index_desc> index(unsigned idx);
99
106#if defined(__cpp_lib_generator)
107 static std::generator<Index_desc> indexes();
108#else
109 static std::vector<Index_desc> indexes();
110#endif
111
113 static Tracebuffer &instance();
114
116 size_t items() const;
117
137 size_t dequeue(Item *items, size_t capacity, size_t burst, Drop_policy policy,
138 Sequence *drops = nullptr);
139
151 static std::optional<Id> ptr_to_id(void *const ptr);
152
164 static std::optional<std::string> id_to_name(Id const id);
165
166private:
167 static constexpr unsigned tracebuffer_version = 0;
168 static constexpr size_t yield_cycles = 100;
169
174 class Factory
175 {
176 public:
178 static Factory &instance();
179
181 Status &status();
182
184 Slot *slots();
185
186 private:
197 Factory();
198
205 ~Factory();
206
220 static l4_fpage_t reserve(size_t size);
221
232 static Status *map_status(l4_fpage_t fpage);
233
245 static Slot *map_slots(l4_fpage_t fpage, size_t items);
246
247 l4_fpage_t _fpage_status;
248 l4_fpage_t _fpage_slots;
249
250 Status *_status;
251 Slot *_slots;
252 };
253
254 Tracebuffer() = delete;
255
261 Tracebuffer(Factory &factory);
262
263 static L4::Cap<L4::Debugger> _jdb;
264 Buffer _buffer;
265};
266
267}; // namespace utrace
L4::Cap related definitions.
C++ interface for capabilities.
Definition capability.h:249
Blocking ring buffer consumer.
Definition ring_buffer:509
Tracebuffer abstraction.
Definition utrace:51
static std::endian endianness()
Get the endianness supported by this class.
static std::optional< Id > ptr_to_id(void *const ptr)
Convert kernel object pointer to global kernel object ID.
static void validate()
Check that the base debugger (JDB) capability is valid and accessible.
static std::optional< Index_desc > index(unsigned idx)
Map a dynamic tracebuffer log index to names.
static std::vector< Index_desc > indexes()
Get all mappings of dynamic tracebuffer log indexes to names.
static Tracebuffer & instance()
Get the singleton instance of this class.
size_t dequeue(Item *items, size_t capacity, size_t burst, Drop_policy policy, Sequence *drops=nullptr)
Dequeue items from the tracebuffer.
static std::optional< std::string > id_to_name(Id const id)
Convert global kernel object ID to object name.
static unsigned version()
Get the tracebuffer format version supported by this class.
size_t items() const
Get the capacity (in items) of the tracebuffer ring buffer.
The debugger interface specifies common debugging related definitions.
#define L4_PAGESIZE
Minimal page size (in bytes).
Definition consts.h:402
Common constants.
Shared-memory multiple-producer multiple-consumer head-drop ring buffer implementation.
Data buffer used to transfer packets.
Mapping of the dynamic tracebuffer log indexes to names.
Definition utrace:67
L4 flexpage type.
Definition __l4_fpage.h:76