plcopen 0.22.0
载入中...
搜索中...
未找到
debug.h
浏览该文件的文档.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <atomic>
6#include <cstddef>
7#include <cstdint>
8#include <cstring>
9#include <limits>
10#include <new>
11#include <vector>
12
14
15namespace plcopen::core::st
16{
17
18class DebugSession final : public RuntimeDebugHooks
19{
20public:
21 ~DebugSession() { detach(); }
22
24 std::atomic<std::uint64_t> *publish_storage,
25 std::size_t publish_word_capacity,
26 DebugSnapshotEntry *publish_entries,
27 std::size_t publish_entry_capacity,
28 std::atomic<std::uint64_t> *trace_storage,
29 std::size_t trace_word_capacity,
30 const DebugSessionOptions &options = {})
31 {
32 detach();
33 last_error_ = DebugError::invalid_argument;
34 if(runtime.program_ == nullptr || target.resource == nullptr ||
35 target.task == nullptr || publish_storage == nullptr ||
36 publish_entries == nullptr ||
37 (trace_word_capacity != 0 && trace_storage == nullptr))
38 return last_error_;
39 if(runtime.debug_hooks_ != nullptr && runtime.debug_hooks_ != this)
40 return last_error_;
41 if(runtime.program_->debug_mode != DebugMode::enabled) {
43 return last_error_;
44 }
45 if(trace_word_capacity != 0 &&
46 trace_word_capacity <
47 sizeof(DebugTraceRecord) / sizeof(std::uint64_t))
48 return last_error_ = DebugError::capacity_exceeded;
49 ConfigurationRuntime::ResourceRuntime *resource =
50 runtime.find_resource(target.resource);
51 int task_index = resource == nullptr
52 ? -1
53 : runtime.find_task(*resource, target.task);
54 if(task_index < 0) return last_error_;
55 ConfigurationRuntime::TaskRuntime &task =
56 resource->tasks[static_cast<std::size_t>(task_index)];
57 if(task.info->mappings.empty()) return last_error_;
58 const std::size_t mapping_index = task.info->mappings.front();
59 if(mapping_index >= resource->mapping_count) return last_error_;
60 std::vector<std::uint32_t> breakpoint_bases(
61 resource->mapping_count, invalid_instruction);
62 std::vector<ActivePou> active_pous;
63 std::vector<SnapshotSfcStep> snapshot_sfc_steps;
64 active_pous.reserve(task.info->mappings.size());
65 std::size_t breakpoint_count = 0;
66 for(const std::uint16_t selected : task.info->mappings) {
67 if(selected >= resource->mapping_count) return last_error_;
68 ConfigurationRuntime::MappingRuntime &selected_mapping =
69 resource->mappings[selected];
70 active_pous.push_back({
71 stable_symbol_id(selected_mapping.program->program_name),
72 &selected_mapping.program->program_name,
73 static_cast<std::uint32_t>(selected)});
74 for(std::size_t network = 0;
75 network < selected_mapping.program->sfc_networks.size();
76 ++network) {
77 const SfcNetworkInfo &network_info =
78 selected_mapping.program->sfc_networks[network];
79 const SymbolId network_id =
80 stable_symbol_id(network_info.lower);
81 for(std::size_t step = 0;
82 step < network_info.steps.size(); ++step) {
83 if(snapshot_sfc_steps.size() >= kMaxDebugSfcSteps)
84 return last_error_ = DebugError::capacity_exceeded;
85 const SfcStepInfo &step_info = network_info.steps[step];
86 snapshot_sfc_steps.push_back({
87 &selected_mapping, network, step, network_id,
88 stable_symbol_id(network_info.lower + "." +
89 step_info.lower),
90 &network_info.name, &step_info.name,
91 static_cast<std::uint32_t>(selected)});
92 }
93 }
94 breakpoint_bases[selected] =
95 static_cast<std::uint32_t>(breakpoint_count);
96 breakpoint_count += resource->mappings[selected]
97 .program->source_map.entries.size();
99 std::numeric_limits<std::uint32_t>::max())
100 return last_error_ = DebugError::capacity_exceeded;
101 }
102 const std::size_t breakpoint_words =
103 (breakpoint_count + 63U) / 64U;
104 const std::size_t sfc_state_words =
105 (snapshot_sfc_steps.size() + 63U) / 64U;
106 if(breakpoint_words + header_words + sfc_state_words >
107 publish_word_capacity)
108 return last_error_ = DebugError::capacity_exceeded;
109 static_assert(sizeof(DebugTraceRecord) % sizeof(std::uint64_t) == 0,
110 "trace records use complete atomic words");
111 const std::size_t trace_words_per_record =
112 sizeof(DebugTraceRecord) / sizeof(std::uint64_t);
113 const std::size_t trace_capacity = std::min(
114 trace_word_capacity / trace_words_per_record,
115 options.trace_capacity);
116 for(std::size_t index = 0; index < publish_word_capacity; ++index)
117 publish_storage[index].store(0, std::memory_order_relaxed);
118 for(std::size_t index = 0;
119 index < trace_capacity * trace_words_per_record;
120 ++index)
121 trace_storage[index].store(0, std::memory_order_relaxed);
122
123 runtime_ = &runtime;
124 resource_ = resource;
125 task_ = &task;
126 task_index_ = static_cast<std::size_t>(task_index);
127 mapping_index_ = mapping_index;
128 mapping_ = &resource->mappings[mapping_index];
129 program_ = mapping_->program;
130 trace_resource_id_ = stable_symbol_id(resource->info->lower).value;
131 trace_task_id_ = stable_symbol_id(task.info->lower).value;
132 publish_words_ = publish_storage;
133 publish_word_capacity_ = publish_word_capacity;
134 publish_entries_ = publish_entries;
135 publish_entry_capacity_ = publish_entry_capacity;
136 trace_words_ = trace_storage;
137 trace_words_per_record_ = trace_words_per_record;
138 trace_storage_capacity_ = trace_capacity;
139 options_ = options;
140 watches_.clear();
141 watches_.reserve(options.max_watch_symbols);
142 watch_plan_state_.store(watch_plan_open,
143 std::memory_order_relaxed);
144 snapshot_ready_.store(true, std::memory_order_relaxed);
145 value_word_count_ = 0;
146 value_bytes_ = 0;
147 breakpoints_.clear();
148 breakpoints_.reserve(options.max_breakpoints);
149 mapping_breakpoint_bases_ =
150 static_cast<std::vector<std::uint32_t> &&>(breakpoint_bases);
151 active_pous_ = static_cast<std::vector<ActivePou> &&>(active_pous);
152 snapshot_sfc_steps_ =
153 static_cast<std::vector<SnapshotSfcStep> &&>(snapshot_sfc_steps);
154 sfc_state_word_count_ = sfc_state_words;
155 breakpoint_word_count_ = breakpoint_words;
156 breakpoint_words_ = publish_words_ +
157 publish_word_capacity_ - breakpoint_word_count_;
158 trace_lock_.store(0, std::memory_order_relaxed);
159 trace_begin_.store(0, std::memory_order_relaxed);
160 trace_size_.store(0, std::memory_order_relaxed);
161 trace_sequence_.store(0, std::memory_order_relaxed);
162 trace_dropped_.store(0, std::memory_order_relaxed);
163 stop_pending_.store(false, std::memory_order_relaxed);
164 command_mailbox_.store(0, std::memory_order_relaxed);
165 observed_task_state_.store(
166 static_cast<std::uint8_t>(task.storage->status.state),
167 std::memory_order_relaxed);
168 observed_release_count_.store(task.storage->status.release_count,
169 std::memory_order_relaxed);
170 current_entry_.store(nullptr, std::memory_order_relaxed);
171 current_mapping_.store(UINT32_MAX, std::memory_order_relaxed);
172 current_instruction_.store(0, std::memory_order_relaxed);
173 step_command_ = DebugCommand::continue_;
174 skip_instruction_valid_ = false;
175 runtime.debug_hooks_ = this;
176 for(const std::uint16_t index : task.info->mappings)
177 resource->mappings[index].instance.set_debug_hooks(this, index);
178 last_error_ = DebugError::ok;
179 publish_snapshot(snapshot_initial);
180 return last_error_;
181 }
182
183 DebugError last_error() const noexcept { return last_error_; }
184
186 {
187 if(program_ == nullptr) return DebugError::invalid_argument;
188 std::uint8_t expected = watch_plan_open;
189 if(!watch_plan_state_.compare_exchange_strong(
190 expected, watch_plan_editing, std::memory_order_acq_rel,
191 std::memory_order_relaxed))
192 return expected == watch_plan_frozen ||
193 expected == watch_plan_freeze_pending
196 const auto finish = [this](DebugError error) {
197 std::uint8_t editing = watch_plan_editing;
198 if(!watch_plan_state_.compare_exchange_strong(
199 editing, watch_plan_open, std::memory_order_release,
200 std::memory_order_relaxed))
201 watch_plan_state_.store(watch_plan_frozen,
202 std::memory_order_release);
203 return error;
204 };
205 for(const Watch &watch : watches_)
206 if(watch.symbol->id == id) return finish(DebugError::ok);
207 if(watches_.size() >= options_.max_watch_symbols ||
208 watches_.size() >= publish_entry_capacity_)
210 const SymbolInfo *symbol = find_symbol(id);
211 ConfigurationRuntime::MappingRuntime *watch_mapping =
212 symbol == nullptr ? nullptr : find_mapping(*symbol);
213 if(watch_mapping == nullptr)
215 const std::size_t word = value_word_count_ + header_words +
216 sfc_state_word_count_;
217 const std::size_t words = (symbol->size + 7U) / 8U;
218 if(word + words > publish_word_capacity_ - breakpoint_word_count_)
220 Watch watch;
221 watch.symbol = symbol;
222 watch.mapping = watch_mapping;
223 watch.word = word;
224 watches_.push_back(watch);
225 DebugSnapshotEntry &entry = publish_entries_[watches_.size() - 1U];
226 entry.symbol_id = id;
227 entry.type_id = symbol->type_id;
228 entry.offset = static_cast<std::uint32_t>(value_bytes_);
229 entry.size = symbol->size;
230 value_word_count_ += words;
231 value_bytes_ += symbol->size;
232 snapshot_ready_.store(false, std::memory_order_release);
233 return finish(DebugError::ok);
234 }
235
236 DebugError add_breakpoint(const char *source, std::uint32_t line,
237 std::uint32_t column, BreakpointId &id)
238 {
239 if(last_error_ == DebugError::debugging_disabled)
241 if(resource_ == nullptr || task_ == nullptr)
243 bool found = false;
244 id = invalid_instruction;
245 std::vector<std::uint32_t> keys;
246 keys.reserve(task_->info->mappings.size());
247 for(const std::uint16_t mapping : task_->info->mappings) {
248 const SourceMapEntry *entry =
249 find_source(mapping, source, line, column);
250 if(entry == nullptr) continue;
251 const std::uint32_t key = breakpoint_key(mapping, *entry);
252 bool duplicate = false;
253 for(const std::uint32_t candidate : keys)
254 duplicate = duplicate || candidate == key;
255 if(duplicate) continue;
256 keys.push_back(key);
257 if(!found) id = key;
258 found = true;
259 }
260 if(!found) return DebugError::invalid_source_location;
261 std::size_t additions = 0;
262 for(std::size_t index = 0; index < keys.size(); ++index) {
263 bool present = false;
264 for(const std::uint32_t existing : breakpoints_)
265 present = present || existing == keys[index];
266 if(!present) ++additions;
267 }
268 if(additions > options_.max_breakpoints - breakpoints_.size())
270 for(std::size_t index = 0; index < keys.size(); ++index) {
271 bool present = false;
272 for(const std::uint32_t existing : breakpoints_)
273 present = present || existing == keys[index];
274 if(present) continue;
275 breakpoints_.push_back(keys[index]);
276 set_breakpoint(keys[index]);
277 }
278 return DebugError::ok;
279 }
280
281 DebugError add_breakpoint_instruction(std::uint32_t instruction,
282 BreakpointId &id)
283 {
284 if(last_error_ == DebugError::debugging_disabled)
286 if(resource_ == nullptr || task_ == nullptr)
288 const SourceMapEntry *match = nullptr;
289 std::size_t match_mapping = 0;
290 for(const std::uint16_t mapping : task_->info->mappings) {
291 for(const SourceMapEntry &entry : resource_->mappings[mapping]
292 .program->source_map.entries) {
293 if(entry.instruction != instruction) continue;
294 if(match != nullptr) return DebugError::invalid_instruction;
295 match = &entry;
296 match_mapping = mapping;
297 }
298 }
299 return match == nullptr
301 : add_breakpoint_entry(*match, match_mapping, id);
302 }
303
304 DebugError remove_breakpoint_at(const char *source, std::uint32_t line,
305 std::uint32_t column)
306 {
307 if(last_error_ == DebugError::debugging_disabled)
309 if(resource_ == nullptr || task_ == nullptr)
311 bool removed = false;
312 for(const std::uint16_t mapping : task_->info->mappings) {
313 const SourceMapEntry *entry =
314 find_source(mapping, source, line, column);
315 if(entry == nullptr) continue;
316 const std::uint32_t key = breakpoint_key(mapping, *entry);
317 for(std::size_t index = 0; index < breakpoints_.size(); ++index) {
318 if(breakpoints_[index] == key) {
319 breakpoints_.erase(
320 breakpoints_.begin() +
321 static_cast<std::ptrdiff_t>(index));
322 clear_breakpoint(key);
323 removed = true;
324 break;
325 }
326 }
327 }
328 return removed ? DebugError::ok
330 }
331
332 std::size_t breakpoint_count() const noexcept
333 {
334 return runtime_ == nullptr ? 0 : breakpoints_.size();
335 }
336
337 DebugError poll_stop(DebugStop &stop) const noexcept
338 {
339 if(runtime_ == nullptr) return DebugError::invalid_argument;
340 if(!stop_pending_.load(std::memory_order_acquire))
342 for(std::size_t attempt = 0; attempt < 8; ++attempt) {
343 const std::uint64_t before =
344 published_stop_.sequence.load(std::memory_order_acquire);
345 if((before & 1U) != 0) continue;
346 const std::string *task =
347 published_stop_.task.load(std::memory_order_relaxed);
348 const std::string *pou =
349 published_stop_.pou.load(std::memory_order_relaxed);
350 const std::string *source =
351 published_stop_.source.load(std::memory_order_relaxed);
352 const std::string *sfc =
353 published_stop_.sfc.load(std::memory_order_relaxed);
354 DebugStop candidate{};
355 candidate.reason = static_cast<DebugStopReason>(
356 published_stop_.reason.load(std::memory_order_relaxed));
357 candidate.task = task == nullptr ? std::string_view{} : *task;
358 candidate.pou = pou == nullptr ? std::string_view{} : *pou;
359 candidate.source_name =
360 source == nullptr ? std::string_view{} : *source;
361 candidate.sfc = sfc == nullptr ? std::string_view{} : *sfc;
362 candidate.line =
363 published_stop_.line.load(std::memory_order_relaxed);
364 candidate.column =
365 published_stop_.column.load(std::memory_order_relaxed);
366 candidate.instruction =
367 published_stop_.instruction.load(std::memory_order_relaxed);
368 candidate.instruction_id.artifact =
369 published_stop_.artifact.load(std::memory_order_relaxed);
370 candidate.instruction_id.mapping =
371 published_stop_.mapping.load(std::memory_order_relaxed);
372 candidate.instruction_id.region =
373 published_stop_.region.load(std::memory_order_relaxed);
374 candidate.instruction_id.offset =
375 published_stop_.offset.load(std::memory_order_relaxed);
376 candidate.instruction_id.region_kind =
377 static_cast<DebugRegionKind>(published_stop_.region_kind.load(
378 std::memory_order_relaxed));
379 candidate.call_depth =
380 published_stop_.call_depth.load(std::memory_order_relaxed);
381 const std::uint64_t after =
382 published_stop_.sequence.load(std::memory_order_acquire);
383 if(before != after || (after & 1U) != 0) continue;
384 stop = candidate;
385 return DebugError::ok;
386 }
388 }
389
391 {
392 if(last_error_ == DebugError::debugging_disabled)
394 if(task_ == nullptr) return DebugError::invalid_argument;
395 if(static_cast<TaskState>(observed_task_state_.load(
396 std::memory_order_acquire)) == TaskState::faulted)
398 const TaskState observed = static_cast<TaskState>(
399 observed_task_state_.load(std::memory_order_acquire));
400 if(command == DebugCommand::continue_) {
401 command_mailbox_.store(static_cast<std::uint8_t>(command) + 1U,
402 std::memory_order_release);
403 return DebugError::ok;
404 }
405 if(!stop_pending_.load(std::memory_order_acquire) ||
406 observed != TaskState::paused)
408 command_mailbox_.store(static_cast<std::uint8_t>(command) + 1U,
409 std::memory_order_release);
410 return DebugError::ok;
411 }
412
414 DebugSnapshotEntry *entries,
415 std::size_t entry_capacity,
416 unsigned char *values,
417 std::size_t value_capacity,
418 std::size_t retries) const noexcept
419 {
420 snapshot = {};
421 if(runtime_ == nullptr || entries == nullptr || values == nullptr)
423 if(entry_capacity < watches_.size() || value_capacity < value_bytes_)
425 if(!snapshot_ready_.load(std::memory_order_acquire))
427 if(retries == 0) return DebugError::snapshot_busy;
428 for(std::size_t attempt = 0; attempt < retries; ++attempt) {
429 const std::uint64_t before =
430 publish_words_[0].load(std::memory_order_acquire);
431 if((before & 1U) != 0) continue;
432 const std::uint64_t state_bits =
433 publish_words_[1].load(std::memory_order_acquire);
434 const std::uint64_t fault =
435 publish_words_[2].load(std::memory_order_acquire);
436 const SourceMapEntry *active =
437 published_entry_.load(std::memory_order_relaxed);
438 const std::uint32_t active_mapping = static_cast<std::uint32_t>(
439 publish_words_[4].load(std::memory_order_acquire));
440 const std::uint32_t active_instruction =
441 static_cast<std::uint32_t>(
442 publish_words_[5].load(std::memory_order_acquire));
443 const std::uint8_t state = static_cast<std::uint8_t>(state_bits);
444 std::array<std::uint64_t,
445 (kMaxDebugSfcSteps + 63U) / 64U> sfc_bits{};
446 for(std::size_t word = 0; word < sfc_state_word_count_; ++word)
447 sfc_bits[word] = publish_words_[header_words + word].load(
448 std::memory_order_relaxed);
449 std::size_t destination = 0;
450 for(std::size_t index = 0; index < watches_.size(); ++index) {
451 entries[index] = publish_entries_[index];
452 const Watch &watch = watches_[index];
453 std::size_t remaining = watch.symbol->size;
454 std::size_t word = watch.word;
455 while(remaining != 0) {
456 const std::uint64_t bits =
457 publish_words_[word++].load(std::memory_order_relaxed);
458 const std::size_t bytes = std::min<std::size_t>(8, remaining);
459 std::memcpy(values + destination, &bits, bytes);
460 destination += bytes;
461 remaining -= bytes;
462 }
463 }
464 const std::uint64_t after =
465 publish_words_[0].load(std::memory_order_acquire);
466 if(before != after || (after & 1U) != 0) continue;
467 snapshot.version = after / 2U;
468 snapshot.value_count = watches_.size();
469 snapshot.value_bytes = value_bytes_;
470 snapshot.task_state = static_cast<TaskState>(state);
471 snapshot.fault = static_cast<TaskFault>(fault);
472 if(active != nullptr) {
473 std::string_view path = active->call_path;
474 std::size_t begin = 0;
475 while(begin < path.size() &&
476 snapshot.active_pou_count < kMaxDebugStackFrames) {
477 const std::size_t slash = path.find('/', begin);
478 const std::size_t end = slash == std::string_view::npos
479 ? path.size()
480 : slash;
481 snapshot.call_stack[snapshot.active_pou_count++].pou =
482 path.substr(begin, end - begin);
483 if(slash == std::string_view::npos) break;
484 begin = slash + 1U;
485 }
486 if(snapshot.active_pou_count == 0) {
487 snapshot.call_stack[0].pou = active->pou;
488 snapshot.active_pou_count = 1;
489 }
490 DebugStackFrame &leaf =
491 snapshot.call_stack[snapshot.active_pou_count - 1U];
492 leaf.pou_id = SymbolId{active->pou_id};
493 leaf.source_name = active->source_name;
494 leaf.sfc = active->sfc;
495 leaf.line = active->line;
496 leaf.column = active->column;
497 leaf.instruction_id = active->instruction_id;
498 leaf.instruction_id.mapping = active_mapping;
499 leaf.instruction_id.offset = active_instruction;
500 snapshot.call_depth = static_cast<std::uint16_t>(
501 snapshot.active_pou_count);
502 }
503 for(std::size_t index = 0;
504 index < snapshot_sfc_steps_.size(); ++index) {
505 const SnapshotSfcStep &published = snapshot_sfc_steps_[index];
507 snapshot.sfc_steps[snapshot.sfc_step_count++];
508 step.network_id = published.network_id;
509 step.step_id = published.step_id;
510 step.network = *published.network;
511 step.step = *published.step;
512 step.mapping = published.mapping;
513 step.active =
514 (sfc_bits[index / 64U] &
515 (std::uint64_t{1} << (index % 64U))) != 0;
516 }
517 return DebugError::ok;
518 }
520 }
521
523 std::size_t) const noexcept
524 {
526 }
527
528 DebugError queue_force(SymbolId id, TypeId type, const void *value,
529 std::size_t size, ForceReceipt &receipt)
530 {
531 if(resource_ == nullptr || task_ == nullptr)
533 const SymbolInfo *symbol = find_symbol(id);
534 if(symbol == nullptr || !symbol->located)
536 if(symbol->type_id != type || symbol->size != size)
538 const int physical_index = resource_->image.located_index(*symbol);
539 if(physical_index < 0) return DebugError::invalid_symbol;
540 const std::uint64_t target_release =
541 observed_release_count_.load(std::memory_order_acquire) +
542 (static_cast<TaskState>(observed_task_state_.load(
543 std::memory_order_acquire)) == TaskState::paused ? 0U : 1U);
544 std::uint64_t queue_version = 0;
545 const rt::ErrorCode error = resource_->image.queue_force_index(
546 static_cast<std::size_t>(physical_index), type,
547 static_cast<const unsigned char *>(value), size,
548 static_cast<std::uint32_t>(task_index_), target_release,
549 queue_version);
554 receipt.queue_version = queue_version;
555 receipt.target_release = target_release;
556 receipt.target_resource = resource_->info->lower;
557 receipt.target_task = task_->info->lower;
558 return DebugError::ok;
559 }
560
562 {
563 if(resource_ == nullptr || task_ == nullptr)
565 const SymbolInfo *symbol = find_symbol(id);
566 if(symbol == nullptr || !symbol->located)
568 const int physical_index = resource_->image.located_index(*symbol);
569 if(physical_index < 0) return DebugError::invalid_symbol;
570 const std::uint64_t target_release =
571 observed_release_count_.load(std::memory_order_acquire) +
572 (static_cast<TaskState>(observed_task_state_.load(
573 std::memory_order_acquire)) == TaskState::paused ? 0U : 1U);
574 std::uint64_t queue_version = 0;
575 if(resource_->image.queue_release_index(
576 static_cast<std::size_t>(physical_index),
577 static_cast<std::uint32_t>(task_index_), target_release,
578 queue_version) != rt::ErrorCode::ok)
580 receipt.queue_version = queue_version;
581 receipt.target_release = target_release;
582 receipt.target_resource = resource_->info->lower;
583 receipt.target_task = task_->info->lower;
584 return DebugError::ok;
585 }
586
587 DebugError read_trace(DebugTraceRecord *records, std::size_t capacity,
588 DebugTraceReport &report) const noexcept
589 {
590 report = {};
591 if(runtime_ == nullptr || records == nullptr)
593 for(std::size_t attempt = 0; attempt < 8; ++attempt) {
594 const std::uint64_t before =
595 trace_lock_.load(std::memory_order_acquire);
596 if((before & 1U) != 0) continue;
597 const std::size_t size =
598 trace_size_.load(std::memory_order_acquire);
599 const std::size_t begin =
600 trace_begin_.load(std::memory_order_acquire);
601 const std::size_t written = std::min(capacity, size);
602 const std::size_t skip = size - written;
603 for(std::size_t index = 0; index < written; ++index) {
604 const std::size_t logical = skip + index;
605 const std::size_t slot = (begin + logical) %
606 trace_storage_capacity_;
607 for(std::size_t word = 0; word < trace_words_per_record_;
608 ++word) {
609 const std::uint64_t bits = trace_words_[
610 slot * trace_words_per_record_ + word]
611 .load(std::memory_order_relaxed);
612 std::memcpy(reinterpret_cast<unsigned char *>(
613 &records[index]) +
614 word * sizeof(bits),
615 &bits, sizeof(bits));
616 }
617 }
618 const std::uint64_t dropped =
619 trace_dropped_.load(std::memory_order_acquire);
620 const std::uint64_t after =
621 trace_lock_.load(std::memory_order_acquire);
622 if(before != after || (after & 1U) != 0) continue;
623 report.version = after / 2U;
624 report.written = written;
625 report.dropped = dropped;
626 return DebugError::ok;
627 }
629 }
630
631 bool on_probe(std::size_t mapping, const SourceMapEntry &entry,
632 std::uint32_t instruction) noexcept override
633 {
634 if(!mapping_selected(mapping) || program_ == nullptr) return false;
635 current_mapping_.store(static_cast<std::uint32_t>(mapping),
636 std::memory_order_relaxed);
637 current_instruction_.store(instruction, std::memory_order_relaxed);
638 current_entry_.store(&entry, std::memory_order_release);
639 InstructionId instruction_id = entry.instruction_id;
640 instruction_id.mapping = static_cast<std::uint32_t>(mapping);
641 if(entry.sfc.empty()) {
642 push_trace(DebugEventKind::pou, instruction, &instruction_id,
643 &entry);
644 if(entry.event_kind == DebugEventKind::fb)
645 push_trace(DebugEventKind::fb, instruction, &instruction_id,
646 &entry);
647 } else {
648 push_trace(DebugEventKind::sfc, instruction, &instruction_id,
649 &entry);
650 }
651 if(skip_instruction_valid_ &&
652 instruction_id == skip_instruction_once_) {
653 skip_instruction_valid_ = false;
654 return false;
655 }
656 bool stop = breakpoint_set(breakpoint_key(mapping, entry));
658 if(step_command_ != DebugCommand::continue_) {
659 if(step_command_ == DebugCommand::step_in) {
660 stop = true;
661 } else if(step_command_ == DebugCommand::step_over) {
662 stop = entry.call_depth <= step_origin_depth_;
663 } else {
664 stop = entry.call_depth < step_origin_depth_;
665 }
666 reason = DebugStopReason::step;
667 }
668 if(!stop) return false;
669 rt_stop_entry_ = &entry;
670 rt_stop_instruction_ = instruction;
671 rt_stop_reason_ = reason;
672 rt_stop_instruction_id_ = instruction_id;
673 rt_stop_depth_ = entry.call_depth;
674 step_command_ = DebugCommand::continue_;
675 return true;
676 }
677
678 void on_task_boundary(const void *resource, std::size_t task,
679 bool faulted) noexcept override
680 {
681 if(resource != resource_ || task != task_index_) return;
682 bool publish = false;
683 for(;;) {
684 std::uint8_t state =
685 watch_plan_state_.load(std::memory_order_acquire);
686 if(state == watch_plan_frozen) {
687 publish = true;
688 break;
689 }
690 if(state == watch_plan_freeze_pending) break;
691 const std::uint8_t desired = state == watch_plan_open
692 ? watch_plan_frozen
693 : watch_plan_freeze_pending;
694 if(watch_plan_state_.compare_exchange_weak(
695 state, desired, std::memory_order_acq_rel,
696 std::memory_order_acquire)) {
697 publish = desired == watch_plan_frozen;
698 break;
699 }
700 }
701 if(!faulted) current_entry_.store(nullptr, std::memory_order_release);
702 if(publish)
703 publish_snapshot(faulted ? snapshot_fault : snapshot_committed);
704 observed_task_state_.store(
705 static_cast<std::uint8_t>(task_->storage->status.state),
706 std::memory_order_release);
707 observed_release_count_.store(task_->storage->status.release_count,
708 std::memory_order_release);
709 push_trace(DebugEventKind::task);
710 }
711
712 void on_debug_event(const void *resource, std::size_t task,
713 DebugEventKind kind,
714 std::uint32_t instruction,
715 const SourceMapEntry *entry,
716 const InstructionId *instruction_id) noexcept override
717 {
718 if(resource != resource_ || task != task_index_) return;
719 observed_task_state_.store(
720 static_cast<std::uint8_t>(task_->storage->status.state),
721 std::memory_order_release);
722 observed_release_count_.store(task_->storage->status.release_count,
723 std::memory_order_release);
724 if(kind == DebugEventKind::task &&
725 task_->storage->status.state == TaskState::paused) {
726 if(rt_stop_entry_ != nullptr) {
727 publish_stop(rt_stop_reason_, *rt_stop_entry_,
728 rt_stop_instruction_, rt_stop_instruction_id_);
729 stop_pending_.store(true, std::memory_order_release);
730 rt_stop_entry_ = nullptr;
731 }
732 publish_snapshot(snapshot_paused);
733 }
734 push_trace(kind, instruction, instruction_id, entry);
735 }
736
737 void on_scheduler_boundary() noexcept override
738 {
739 if(task_ == nullptr) return;
740 TaskStatus &status = task_->storage->status;
741 const std::uint8_t packed =
742 command_mailbox_.exchange(0, std::memory_order_acq_rel);
743 if(packed != 0 && status.state == TaskState::paused) {
744 skip_instruction_once_ = rt_stop_instruction_id_;
745 skip_instruction_valid_ = true;
746 step_command_ = static_cast<DebugCommand>(packed - 1U);
747 step_origin_depth_ = rt_stop_depth_;
748 stop_pending_.store(false, std::memory_order_release);
749 status.state = TaskState::running;
750 } else if(packed != 0 && status.state != TaskState::faulted) {
751 stop_pending_.store(false, std::memory_order_release);
752 step_command_ = DebugCommand::continue_;
753 }
754 observed_task_state_.store(static_cast<std::uint8_t>(status.state),
755 std::memory_order_release);
756 observed_release_count_.store(status.release_count,
757 std::memory_order_release);
758 }
759
760 void on_runtime_detach() noexcept override
761 {
762 runtime_ = nullptr;
763 resource_ = nullptr;
764 task_ = nullptr;
765 mapping_ = nullptr;
766 program_ = nullptr;
767 publish_words_ = nullptr;
768 publish_entries_ = nullptr;
769 trace_words_ = nullptr;
770 stop_pending_.store(false, std::memory_order_release);
771 command_mailbox_.store(0, std::memory_order_release);
772 current_entry_.store(nullptr, std::memory_order_release);
773 reset_detached_state();
774 }
775
776private:
777 static constexpr std::size_t header_words = 6;
778 static constexpr std::uint32_t invalid_instruction = UINT32_MAX;
779 static constexpr std::uint8_t watch_plan_open = 0;
780 static constexpr std::uint8_t watch_plan_editing = 1;
781 static constexpr std::uint8_t watch_plan_freeze_pending = 2;
782 static constexpr std::uint8_t watch_plan_frozen = 3;
783 static constexpr std::uint8_t snapshot_initial = 0;
784 static constexpr std::uint8_t snapshot_committed = 1;
785 static constexpr std::uint8_t snapshot_paused = 2;
786 static constexpr std::uint8_t snapshot_fault = 3;
787 struct ActivePou
788 {
789 SymbolId id{};
790 const std::string *name = nullptr;
791 std::uint32_t mapping = 0;
792 };
793 struct SnapshotSfcStep
794 {
795 ConfigurationRuntime::MappingRuntime *mapping_runtime = nullptr;
796 std::size_t network_index = 0;
797 std::size_t step_index = 0;
798 SymbolId network_id{};
799 SymbolId step_id{};
800 const std::string *network = nullptr;
801 const std::string *step = nullptr;
802 std::uint32_t mapping = 0;
803 };
804 struct Watch
805 {
806 const SymbolInfo *symbol = nullptr;
807 ConfigurationRuntime::MappingRuntime *mapping = nullptr;
808 std::size_t word = 0;
809 };
810 struct PublishedStop
811 {
812 std::atomic<std::uint64_t> sequence{0};
813 std::atomic<const std::string *> task{nullptr};
814 std::atomic<const std::string *> pou{nullptr};
815 std::atomic<const std::string *> source{nullptr};
816 std::atomic<const std::string *> sfc{nullptr};
817 std::atomic<std::uint32_t> line{0};
818 std::atomic<std::uint32_t> column{0};
819 std::atomic<std::uint32_t> instruction{0};
820 std::atomic<std::uint32_t> artifact{0};
821 std::atomic<std::uint32_t> mapping{UINT32_MAX};
822 std::atomic<std::uint32_t> region{0};
823 std::atomic<std::uint32_t> offset{0};
824 std::atomic<std::uint16_t> call_depth{0};
825 std::atomic<std::uint8_t> reason{0};
826 std::atomic<std::uint8_t> region_kind{0};
827 };
828
829 void detach() noexcept
830 {
831 if(runtime_ != nullptr && resource_ != nullptr && task_ != nullptr) {
832 for(const std::uint16_t index : task_->info->mappings)
833 resource_->mappings[index].instance.set_debug_hooks(nullptr,
834 index);
835 }
836 if(runtime_ != nullptr && runtime_->debug_hooks_ == this)
837 runtime_->debug_hooks_ = nullptr;
838 runtime_ = nullptr;
839 resource_ = nullptr;
840 task_ = nullptr;
841 mapping_ = nullptr;
842 program_ = nullptr;
843 publish_words_ = nullptr;
844 publish_entries_ = nullptr;
845 trace_words_ = nullptr;
846 stop_pending_.store(false, std::memory_order_release);
847 command_mailbox_.store(0, std::memory_order_release);
848 current_entry_.store(nullptr, std::memory_order_release);
849 reset_detached_state();
850 }
851
852 void reset_detached_state() noexcept
853 {
854 publish_word_capacity_ = 0;
855 publish_entry_capacity_ = 0;
856 trace_words_per_record_ = 0;
857 trace_storage_capacity_ = 0;
858 breakpoint_words_ = nullptr;
859 breakpoint_word_count_ = 0;
860 value_word_count_ = 0;
861 value_bytes_ = 0;
862 mapping_breakpoint_bases_.clear();
863 breakpoints_.clear();
864 watches_.clear();
865 active_pous_.clear();
866 snapshot_sfc_steps_.clear();
867 sfc_state_word_count_ = 0;
868 current_mapping_.store(UINT32_MAX, std::memory_order_release);
869 current_instruction_.store(0, std::memory_order_release);
870 }
871
872 static bool same_name(std::string_view left, const char *right) noexcept
873 {
874 if(right == nullptr || left.size() != std::strlen(right)) return false;
875 for(std::size_t index = 0; index < left.size(); ++index) {
876 char a = left[index]; char b = right[index];
877 if(a >= 'A' && a <= 'Z') a = static_cast<char>(a - 'A' + 'a');
878 if(b >= 'A' && b <= 'Z') b = static_cast<char>(b - 'A' + 'a');
879 if(a != b) return false;
880 }
881 return true;
882 }
883
884 const SymbolInfo *find_symbol(SymbolId id) const noexcept
885 {
886 if(runtime_ == nullptr || id.value == 0) return nullptr;
887 for(const SymbolInfo &symbol : runtime_->program_->symbols)
888 if(symbol.id == id) return &symbol;
889 return nullptr;
890 }
891
892 ConfigurationRuntime::MappingRuntime *find_mapping(
893 const SymbolInfo &symbol) const noexcept
894 {
895 if(resource_ == nullptr || task_ == nullptr) return nullptr;
896 for(const std::uint16_t index : task_->info->mappings) {
897 if(index < resource_->mapping_count &&
898 resource_->mappings[index].info->lower == symbol.instance)
899 return &resource_->mappings[index];
900 }
901 return nullptr;
902 }
903
904 const SourceMapEntry *find_source(std::size_t mapping,
905 const char *source, std::uint32_t line,
906 std::uint32_t column) const noexcept
907 {
908 if(!mapping_selected(mapping)) return nullptr;
909 const SourceMapEntry *first = nullptr;
910 const SourceMapEntry *best = nullptr;
911 for(const SourceMapEntry &entry :
912 resource_->mappings[mapping].program->source_map.entries) {
913 if(entry.line != line || !same_name(entry.source_name, source))
914 continue;
915 if(first == nullptr || entry.column < first->column) first = &entry;
916 if(entry.column <= column &&
917 (best == nullptr || entry.column > best->column))
918 best = &entry;
919 }
920 return best == nullptr ? first : best;
921 }
922
923 bool mapping_selected(std::size_t mapping) const noexcept
924 {
925 return mapping < mapping_breakpoint_bases_.size() &&
926 mapping_breakpoint_bases_[mapping] != invalid_instruction;
927 }
928
929 std::uint32_t breakpoint_key(
930 std::size_t mapping, const SourceMapEntry &entry) const noexcept
931 {
932 return mapping_breakpoint_bases_[mapping] + entry.breakpoint_key;
933 }
934
935 DebugError add_breakpoint_entry(const SourceMapEntry &entry,
936 std::size_t mapping,
937 BreakpointId &id)
938 {
939 const std::uint32_t key = breakpoint_key(mapping, entry);
940 for(const std::uint32_t existing : breakpoints_) {
941 if(existing == key) {
942 id = existing;
943 return DebugError::ok;
944 }
945 }
946 if(breakpoints_.size() >= options_.max_breakpoints)
948 breakpoints_.push_back(key);
949 set_breakpoint(key);
950 id = key;
951 return DebugError::ok;
952 }
953
954 void publish_stop(DebugStopReason reason, const SourceMapEntry &entry,
955 std::uint32_t instruction,
956 const InstructionId &instruction_id) noexcept
957 {
958 const std::uint64_t prior =
959 published_stop_.sequence.load(std::memory_order_relaxed);
960 published_stop_.sequence.store(prior | 1U,
961 std::memory_order_release);
962 published_stop_.task.store(&task_->info->lower,
963 std::memory_order_relaxed);
964 published_stop_.pou.store(&entry.pou, std::memory_order_relaxed);
965 published_stop_.source.store(&entry.source_name,
966 std::memory_order_relaxed);
967 published_stop_.sfc.store(&entry.sfc, std::memory_order_relaxed);
968 published_stop_.line.store(entry.line, std::memory_order_relaxed);
969 published_stop_.column.store(entry.column,
970 std::memory_order_relaxed);
971 published_stop_.instruction.store(instruction,
972 std::memory_order_relaxed);
973 published_stop_.artifact.store(instruction_id.artifact,
974 std::memory_order_relaxed);
975 published_stop_.mapping.store(instruction_id.mapping,
976 std::memory_order_relaxed);
977 published_stop_.region.store(instruction_id.region,
978 std::memory_order_relaxed);
979 published_stop_.offset.store(instruction_id.offset,
980 std::memory_order_relaxed);
981 published_stop_.call_depth.store(entry.call_depth,
982 std::memory_order_relaxed);
983 published_stop_.reason.store(static_cast<std::uint8_t>(reason),
984 std::memory_order_relaxed);
985 published_stop_.region_kind.store(
986 static_cast<std::uint8_t>(instruction_id.region_kind),
987 std::memory_order_relaxed);
988 published_stop_.sequence.store((prior | 1U) + 1U,
989 std::memory_order_release);
990 }
991
992 void publish_snapshot(std::uint8_t snapshot_kind) noexcept
993 {
994 if(publish_words_ == nullptr || publish_word_capacity_ < header_words)
995 return;
996 const std::uint64_t prior =
997 publish_words_[0].load(std::memory_order_relaxed);
998 publish_words_[0].store(prior | 1U, std::memory_order_release);
999 publish_words_[1].store(
1000 static_cast<std::uint64_t>(task_->storage->status.state) |
1001 (static_cast<std::uint64_t>(snapshot_kind) << 8U),
1002 std::memory_order_relaxed);
1003 publish_words_[2].store(
1004 static_cast<std::uint64_t>(task_->storage->status.fault),
1005 std::memory_order_relaxed);
1006 const SourceMapEntry *active =
1007 current_entry_.load(std::memory_order_acquire);
1008 published_entry_.store(active, std::memory_order_relaxed);
1009 publish_words_[4].store(
1010 current_mapping_.load(std::memory_order_relaxed),
1011 std::memory_order_relaxed);
1012 publish_words_[5].store(
1013 current_instruction_.load(std::memory_order_relaxed),
1014 std::memory_order_relaxed);
1015 for(std::size_t word = 0; word < sfc_state_word_count_; ++word) {
1016 std::uint64_t bits = 0;
1017 const std::size_t begin = word * 64U;
1018 const std::size_t end = std::min(
1019 begin + 64U, snapshot_sfc_steps_.size());
1020 for(std::size_t index = begin; index < end; ++index) {
1021 const SnapshotSfcStep &step = snapshot_sfc_steps_[index];
1022 if(step.mapping_runtime->instance
1023 .debug_sfc_committed_step_active(
1024 step.network_index, step.step_index))
1025 bits |= std::uint64_t{1} << (index - begin);
1026 }
1027 publish_words_[header_words + word].store(
1028 bits, std::memory_order_relaxed);
1029 }
1030 for(const Watch &watch : watches_) {
1031 std::size_t remaining = watch.symbol->size;
1032 std::size_t source = 0;
1033 std::size_t word = watch.word;
1034 while(remaining != 0) {
1035 std::uint64_t bits = 0;
1036 const std::size_t count = std::min<std::size_t>(8, remaining);
1037 if(!watch.mapping->instance.read_variable(
1038 watch.symbol->offset +
1039 static_cast<std::uint32_t>(source),
1040 static_cast<std::uint32_t>(count),
1041 reinterpret_cast<unsigned char *>(&bits)))
1042 break;
1043 publish_words_[word++].store(bits, std::memory_order_relaxed);
1044 source += count;
1045 remaining -= count;
1046 }
1047 }
1048 publish_words_[0].store((prior | 1U) + 1U,
1049 std::memory_order_release);
1050 snapshot_ready_.store(true, std::memory_order_release);
1051 }
1052
1053 bool breakpoint_set(std::uint32_t key) const noexcept
1054 {
1055 const std::size_t word = key / 64U;
1056 return word < breakpoint_word_count_ &&
1057 (breakpoint_words_[word].load(std::memory_order_acquire) &
1058 (std::uint64_t{1} << (key % 64U))) != 0;
1059 }
1060
1061 void set_breakpoint(std::uint32_t key) noexcept
1062 {
1063 breakpoint_words_[key / 64U].fetch_or(
1064 std::uint64_t{1} << (key % 64U), std::memory_order_release);
1065 }
1066
1067 void clear_breakpoint(std::uint32_t key) noexcept
1068 {
1069 breakpoint_words_[key / 64U].fetch_and(
1070 ~(std::uint64_t{1} << (key % 64U)),
1071 std::memory_order_release);
1072 }
1073
1074 void push_trace(DebugEventKind kind,
1075 std::uint32_t instruction = 0,
1076 const InstructionId *instruction_id = nullptr,
1077 const SourceMapEntry *entry = nullptr) noexcept
1078 {
1079 if(trace_words_ == nullptr || trace_storage_capacity_ == 0) return;
1080 const std::uint64_t prior =
1081 trace_lock_.load(std::memory_order_relaxed);
1082 trace_lock_.store(prior | 1U, std::memory_order_release);
1083 std::size_t size = trace_size_.load(std::memory_order_relaxed);
1084 std::size_t begin = trace_begin_.load(std::memory_order_relaxed);
1085 std::size_t slot = 0;
1086 if(size < trace_storage_capacity_) {
1087 slot = (begin + size) % trace_storage_capacity_;
1088 ++size;
1089 } else {
1090 slot = begin;
1091 begin = (begin + 1U) % trace_storage_capacity_;
1092 trace_dropped_.fetch_add(1, std::memory_order_relaxed);
1093 }
1094 DebugTraceRecord record{};
1095 record.sequence = trace_sequence_.fetch_add(
1096 1, std::memory_order_relaxed) + 1U;
1097 record.resource_id = trace_resource_id_;
1098 record.task_id = trace_task_id_;
1099 record.release =
1100 observed_release_count_.load(std::memory_order_relaxed);
1101 if(entry != nullptr) {
1102 record.pou_id = entry->pou_id;
1103 record.sfc_id = entry->sfc_id;
1104 }
1105 record.kind = kind;
1106 record.instruction = instruction;
1107 record.instruction_id = instruction_id == nullptr
1108 ? InstructionId{}
1109 : *instruction_id;
1110 for(std::size_t word = 0; word < trace_words_per_record_; ++word) {
1111 std::uint64_t bits = 0;
1112 std::memcpy(&bits,
1113 reinterpret_cast<const unsigned char *>(&record) +
1114 word * sizeof(bits),
1115 sizeof(bits));
1116 trace_words_[slot * trace_words_per_record_ + word].store(
1117 bits, std::memory_order_relaxed);
1118 }
1119 trace_begin_.store(begin, std::memory_order_relaxed);
1120 trace_size_.store(size, std::memory_order_relaxed);
1121 trace_lock_.store((prior | 1U) + 1U, std::memory_order_release);
1122 }
1123
1124 ConfigurationRuntime *runtime_ = nullptr;
1125 ConfigurationRuntime::ResourceRuntime *resource_ = nullptr;
1126 ConfigurationRuntime::TaskRuntime *task_ = nullptr;
1127 ConfigurationRuntime::MappingRuntime *mapping_ = nullptr;
1128 const Program *program_ = nullptr;
1129 std::size_t task_index_ = 0;
1130 std::size_t mapping_index_ = 0;
1131 std::atomic<std::uint64_t> *publish_words_ = nullptr;
1132 std::size_t publish_word_capacity_ = 0;
1133 DebugSnapshotEntry *publish_entries_ = nullptr;
1134 std::size_t publish_entry_capacity_ = 0;
1135 std::vector<Watch> watches_;
1136 std::vector<ActivePou> active_pous_;
1137 std::vector<SnapshotSfcStep> snapshot_sfc_steps_;
1138 std::size_t sfc_state_word_count_ = 0;
1139 std::atomic<std::uint8_t> watch_plan_state_{watch_plan_open};
1140 std::atomic<bool> snapshot_ready_{false};
1141 std::vector<std::uint32_t> breakpoints_;
1142 std::vector<std::uint32_t> mapping_breakpoint_bases_;
1143 std::atomic<std::uint64_t> *breakpoint_words_ = nullptr;
1144 std::size_t breakpoint_word_count_ = 0;
1145 std::size_t value_word_count_ = 0;
1146 std::size_t value_bytes_ = 0;
1147 std::atomic<std::uint64_t> *trace_words_ = nullptr;
1148 std::size_t trace_words_per_record_ = 0;
1149 std::size_t trace_storage_capacity_ = 0;
1150 mutable std::atomic<std::uint64_t> trace_lock_{0};
1151 std::atomic<std::size_t> trace_begin_{0};
1152 std::atomic<std::size_t> trace_size_{0};
1153 std::atomic<std::uint64_t> trace_sequence_{0};
1154 std::atomic<std::uint64_t> trace_dropped_{0};
1155 std::uint64_t trace_resource_id_ = 0;
1156 std::uint64_t trace_task_id_ = 0;
1157 DebugSessionOptions options_{};
1158 PublishedStop published_stop_{};
1159 std::atomic<bool> stop_pending_{false};
1160 std::atomic<std::uint8_t> command_mailbox_{0};
1161 std::atomic<std::uint8_t> observed_task_state_{
1162 static_cast<std::uint8_t>(TaskState::idle)};
1163 std::atomic<std::uint64_t> observed_release_count_{0};
1164 std::atomic<const SourceMapEntry *> published_entry_{nullptr};
1165 std::atomic<const SourceMapEntry *> current_entry_{nullptr};
1166 std::atomic<std::uint32_t> current_mapping_{UINT32_MAX};
1167 std::atomic<std::uint32_t> current_instruction_{0};
1168 DebugCommand step_command_ = DebugCommand::continue_;
1169 std::uint16_t step_origin_depth_ = 0;
1170 InstructionId rt_stop_instruction_id_{};
1171 const SourceMapEntry *rt_stop_entry_ = nullptr;
1172 std::uint32_t rt_stop_instruction_ = 0;
1174 std::uint16_t rt_stop_depth_ = 0;
1175 InstructionId skip_instruction_once_{};
1176 bool skip_instruction_valid_ = false;
1178};
1179
1180} // namespace plcopen::core::st
DebugError add_breakpoint_instruction(std::uint32_t instruction, BreakpointId &id)
bool on_probe(std::size_t mapping, const SourceMapEntry &entry, std::uint32_t instruction) noexcept override
DebugError write_symbol(SymbolId, TypeId, const void *, std::size_t) const noexcept
DebugError poll_stop(DebugStop &stop) const noexcept
DebugError remove_breakpoint_at(const char *source, std::uint32_t line, std::uint32_t column)
DebugError add_breakpoint(const char *source, std::uint32_t line, std::uint32_t column, BreakpointId &id)
DebugError queue_force(SymbolId id, TypeId type, const void *value, std::size_t size, ForceReceipt &receipt)
void on_runtime_detach() noexcept override
DebugError read_trace(DebugTraceRecord *records, std::size_t capacity, DebugTraceReport &report) const noexcept
DebugError add_watch(SymbolId id)
DebugError read_snapshot(DebugSnapshot &snapshot, DebugSnapshotEntry *entries, std::size_t entry_capacity, unsigned char *values, std::size_t value_capacity, std::size_t retries) const noexcept
DebugError last_error() const noexcept
std::size_t breakpoint_count() const noexcept
DebugError release_force(SymbolId id, ForceReceipt &receipt)
DebugError control(DebugCommand command) noexcept
void on_debug_event(const void *resource, std::size_t task, DebugEventKind kind, std::uint32_t instruction, const SourceMapEntry *entry, const InstructionId *instruction_id) noexcept override
void on_task_boundary(const void *resource, std::size_t task, bool faulted) noexcept override
void on_scheduler_boundary() noexcept override
DebugError attach(ConfigurationRuntime &runtime, DebugTarget target, std::atomic< std::uint64_t > *publish_storage, std::size_t publish_word_capacity, DebugSnapshotEntry *publish_entries, std::size_t publish_entry_capacity, std::atomic< std::uint64_t > *trace_storage, std::size_t trace_word_capacity, const DebugSessionOptions &options={})
定义 debug.h:23
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