#include "debugger.hpp" #include #include namespace sleela::debugger { static const char* name(EventType t) { switch(t) { case EventType::Info:return "info"; case EventType::Breakpoint:return "breakpoint"; case EventType::Watchpoint:return "watchpoint"; case EventType::Exception:return "exception"; case EventType::Assertion:return "assertion"; case EventType::Thread:return "thread"; case EventType::Log:return "log"; case EventType::Coverage:return "coverage"; case EventType::Sanitizer:return "sanitizer"; case EventType::Test:return "test"; case EventType::Regression:return "regression"; case EventType::Crash:return "crash"; } return "unknown"; } const char* stopReasonName(StopReason r) noexcept { switch(r) { case StopReason::None:return "none"; case StopReason::Breakpoint:return "breakpoint"; case StopReason::Watchpoint:return "watchpoint"; case StopReason::Exception:return "exception"; case StopReason::Signal:return "signal"; case StopReason::Assertion:return "assertion"; case StopReason::Sanitizer:return "sanitizer"; case StopReason::Crash:return "crash"; case StopReason::UserPause:return "user-pause"; case StopReason::TestFailure:return "test-failure"; } return "unknown"; } std::uint64_t DebugSession::addBreakpoint(Breakpoint b) { b.id = next_id_++; breakpoints_.push_back(std::move(b)); return breakpoints_.back().id; } std::uint64_t DebugSession::addWatchpoint(Watchpoint w) { w.id = next_id_++; watchpoints_.push_back(std::move(w)); return watchpoints_.back().id; } bool DebugSession::removeBreakpoint(std::uint64_t id) { auto n=breakpoints_.size(); breakpoints_.erase(std::remove_if(breakpoints_.begin(),breakpoints_.end(), [&](const Breakpoint& b){return b.id==id;}),breakpoints_.end()); return n!=breakpoints_.size(); } bool DebugSession::removeWatchpoint(std::uint64_t id) { auto n=watchpoints_.size(); watchpoints_.erase(std::remove_if(watchpoints_.begin(),watchpoints_.end(), [&](const Watchpoint& w){return w.id==id;}),watchpoints_.end()); return n!=watchpoints_.size(); } void DebugSession::emit(DebugEvent e) { if (e.type==EventType::Breakpoint || e.type==EventType::Watchpoint || e.type==EventType::Exception || e.type==EventType::Assertion || e.type==EventType::Sanitizer || e.type==EventType::Crash) { StopRecord record; record.reason = e.type==EventType::Breakpoint ? StopReason::Breakpoint : e.type==EventType::Watchpoint ? StopReason::Watchpoint : e.type==EventType::Exception ? StopReason::Exception : e.type==EventType::Assertion ? StopReason::Assertion : e.type==EventType::Sanitizer ? StopReason::Sanitizer : StopReason::Crash; record.thread=e.thread; record.location=e.location; record.detail=e.message; record.event_index=events_.size(); auto bp=e.fields.find("breakpoint_id"); if(bp!=e.fields.end()) try { record.breakpoint_id=std::stoull(bp->second); } catch(...) {} auto wp=e.fields.find("watchpoint_id"); if(wp!=e.fields.end()) try { record.watchpoint_id=std::stoull(wp->second); } catch(...) {} stop_=std::move(record); } events_.push_back(std::move(e)); } std::uint64_t DebugSession::addEvidence(EvidenceRecord record) { record.sequence=next_evidence_++; evidence_.push_back(std::move(record)); return evidence_.back().sequence; } void DiagnosticReport::write(std::ostream& out,const std::vector& es){ out<<"SLeeLa Debugger Diagnostic Report\n"<<"events="<& es) { out<<"SLeeLa Debug Evidence\nrecords="<