plcopen 0.22.0
载入中...
搜索中...
未找到
debug_types.h
浏览该文件的文档.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <string>
7#include <string_view>
8#include <vector>
9
10#include "st/types.h"
11#include "st/tasking.h"
12
13namespace plcopen::core::st
14{
15
16enum class DebugMode : std::uint8_t
17{
20};
21
37
39{
40 std::uint64_t value = 0;
41};
42
43constexpr bool operator==(SymbolId left, SymbolId right) noexcept
44{
45 return left.value == right.value;
46}
47
48constexpr bool operator!=(SymbolId left, SymbolId right) noexcept
49{
50 return !(left == right);
51}
52
53inline SymbolId stable_symbol_id(std::string_view qualified_name) noexcept
54{
55 std::uint64_t hash = 1469598103934665603ULL;
56 for(unsigned char byte : qualified_name) {
57 if(byte >= 'A' && byte <= 'Z')
58 byte = static_cast<unsigned char>(byte - 'A' + 'a');
59 hash ^= byte;
60 hash *= 1099511628211ULL;
61 }
62 return SymbolId{hash};
63}
64
66{
68 std::string qualified_name;
69 std::string configuration;
70 std::string resource;
71 std::string instance;
72 std::string program;
73 std::string variable;
75 std::uint32_t offset = 0;
76 std::uint32_t size = 0;
77 bool located = false;
78 std::uint8_t physical_area = 0;
79 std::uint32_t physical_byte_offset = 0;
80 std::uint8_t physical_bit = 0;
81 std::uint8_t physical_width = 0;
83};
84
85enum class DebugEventKind : std::uint8_t
86{
87 scan = 0,
93};
94
95enum class DebugRegionKind : std::uint8_t
96{
97 base = 0,
100};
101
103{
104 std::uint32_t artifact = 0;
105 std::uint32_t mapping = UINT32_MAX;
106 std::uint32_t region = 0;
107 std::uint32_t offset = 0;
109};
110
111constexpr bool operator==(const InstructionId &left,
112 const InstructionId &right) noexcept
113{
114 return left.artifact == right.artifact &&
115 left.mapping == right.mapping && left.region == right.region &&
116 left.offset == right.offset &&
117 left.region_kind == right.region_kind;
118}
119
120constexpr bool operator!=(const InstructionId &left,
121 const InstructionId &right) noexcept
122{
123 return !(left == right);
124}
125
127{
128 std::string source_name;
129 std::string pou;
130 std::string call_path;
131 std::string sfc;
132 std::uint64_t pou_id = 0;
133 std::uint64_t sfc_id = 0;
134 std::uint32_t line = 0;
135 std::uint32_t column = 0;
136 std::uint32_t instruction = 0;
137 std::uint32_t probe_index = 0;
138 std::uint32_t breakpoint_key = 0;
140 std::uint16_t call_depth = 1;
142};
143
145{
146 std::vector<SourceMapEntry> entries;
147
148 std::uint32_t first_instruction_at(const char *source,
149 std::uint32_t line) const noexcept
150 {
151 if(source == nullptr) return UINT32_MAX;
152 for(const SourceMapEntry &entry : entries) {
153 if(entry.line != line) continue;
154 std::string_view left(entry.source_name);
155 std::string_view right(source);
156 if(left.size() != right.size()) continue;
157 bool same = true;
158 for(std::size_t index = 0; index < left.size(); ++index) {
159 char a = left[index];
160 char b = right[index];
161 if(a >= 'A' && a <= 'Z') a = static_cast<char>(a - 'A' + 'a');
162 if(b >= 'A' && b <= 'Z') b = static_cast<char>(b - 'A' + 'a');
163 if(a != b) { same = false; break; }
164 }
165 if(same) return entry.instruction;
166 }
167 return UINT32_MAX;
168 }
169};
170
172{
173 std::string source_name;
174 std::string caller;
175 std::string callee;
176 std::uint32_t call_line = 0;
177 std::uint32_t callee_line = 0;
178 std::uint32_t return_line = 0;
179 std::uint16_t callee_depth = 2;
180};
181
183{
184 std::uint64_t sequence = 0;
185 std::uint64_t resource_id = 0;
186 std::uint64_t task_id = 0;
187 std::uint64_t release = 0;
188 std::uint64_t pou_id = 0;
189 std::uint64_t sfc_id = 0;
191 std::uint32_t instruction = 0;
193};
194
196{
197 std::uint64_t version = 0;
198 std::size_t written = 0;
199 std::uint64_t dropped = 0;
200};
201
202using BreakpointId = std::uint32_t;
203
204enum class DebugStopReason : std::uint8_t
205{
206 none = 0,
210};
211
213{
215 std::string_view task;
216 std::string_view pou;
217 std::string_view source_name;
218 std::string_view sfc;
219 std::uint32_t line = 0;
220 std::uint32_t column = 0;
221 std::uint32_t instruction = 0;
223 std::uint16_t call_depth = 0;
224};
225
226enum class DebugCommand : std::uint8_t
227{
232};
233
235{
238 std::uint32_t offset = 0;
239 std::uint32_t size = 0;
240};
241
243{
245 std::string_view pou;
246 std::string_view source_name;
247 std::string_view sfc;
248 std::uint32_t line = 0;
249 std::uint32_t column = 0;
251};
252
253inline constexpr std::size_t kMaxDebugStackFrames = 64;
254inline constexpr std::size_t kMaxDebugSfcSteps = 256;
255
257{
260 std::string_view network;
261 std::string_view step;
262 std::uint32_t mapping = 0;
263 bool active = false;
264};
265
267{
268 std::uint64_t version = 0;
269 std::size_t value_count = 0;
270 std::size_t value_bytes = 0;
271 std::size_t active_pou_count = 0;
272 std::uint16_t call_depth = 0;
273 std::array<DebugStackFrame, kMaxDebugStackFrames> call_stack{};
274 std::size_t sfc_step_count = 0;
275 std::array<DebugSfcStepState, kMaxDebugSfcSteps> sfc_steps{};
278};
279
281{
282 std::size_t max_breakpoints = 4096;
283 std::size_t max_watch_symbols = 8192;
284 std::size_t trace_capacity = 256;
285};
286
288{
289 const char *resource = nullptr;
290 const char *task = nullptr;
291};
292
294{
295 std::uint64_t queue_version = 0;
296 std::uint64_t target_release = 0;
297 std::string_view target_resource;
298 std::string_view target_task;
299};
300
302{
303public:
304 virtual ~RuntimeDebugHooks() = default;
305 virtual bool on_probe(std::size_t mapping, const SourceMapEntry &entry,
306 std::uint32_t instruction) noexcept = 0;
307 virtual void on_task_boundary(const void *resource,
308 std::size_t task,
309 bool faulted) noexcept = 0;
310 virtual void on_debug_event(const void *resource, std::size_t task,
311 DebugEventKind kind,
312 std::uint32_t instruction = 0,
313 const SourceMapEntry *entry = nullptr,
314 const InstructionId *instruction_id =
315 nullptr) noexcept = 0;
316 virtual void on_scheduler_boundary() noexcept = 0;
317 virtual void on_runtime_detach() noexcept = 0;
318};
319
320} // namespace plcopen::core::st
virtual void on_debug_event(const void *resource, std::size_t task, DebugEventKind kind, std::uint32_t instruction=0, const SourceMapEntry *entry=nullptr, const InstructionId *instruction_id=nullptr) noexcept=0
virtual void on_runtime_detach() noexcept=0
virtual void on_scheduler_boundary() noexcept=0
virtual void on_task_boundary(const void *resource, std::size_t task, bool faulted) noexcept=0
virtual bool on_probe(std::size_t mapping, const SourceMapEntry &entry, std::uint32_t instruction) noexcept=0
constexpr std::size_t kMaxDebugSfcSteps
std::uint32_t TypeId
std::uint32_t BreakpointId
constexpr std::size_t kMaxDebugStackFrames
SymbolId stable_symbol_id(std::string_view qualified_name) noexcept
constexpr bool operator!=(SymbolId left, SymbolId right) noexcept
constexpr bool operator==(SymbolId left, SymbolId right) noexcept
std::array< DebugStackFrame, kMaxDebugStackFrames > call_stack
std::array< DebugSfcStepState, kMaxDebugSfcSteps > sfc_steps
std::uint32_t first_instruction_at(const char *source, std::uint32_t line) const noexcept
std::vector< SourceMapEntry > entries