#include "debug_engine.hpp" #include #include #include namespace sleela::debugger { const char* capabilityStateName(CapabilityState s)noexcept{switch(s){case CapabilityState::Unavailable:return"unavailable";case CapabilityState::Declared:return"declared";case CapabilityState::Implemented:return"implemented";case CapabilityState::Tested:return"tested";}return"unknown";} const char* exceptionKindName(ExceptionKind k)noexcept{switch(k){case ExceptionKind::Signal:return"signal";case ExceptionKind::AccessViolation:return"access-violation";case ExceptionKind::IllegalInstruction:return"illegal-instruction";case ExceptionKind::DivideByZero:return"divide-by-zero";case ExceptionKind::Assertion:return"assertion";case ExceptionKind::Sanitizer:return"sanitizer";default:return"unknown";}} DebugEngine::DebugEngine(){const char*n[]={"breakpoints","watchpoints","threads","stack","symbols","memory","registers","exceptions","expressions","evidence"};for(auto s:n)capabilities_.push_back({s,CapabilityState::Implemented,"portable engine state","portable"});} std::uint64_t DebugEngine::addBreakpoint(BreakpointSpec s){auto id=next_breakpoint_++;breakpoints_.push_back({id,std::move(s),true,0});return id;} bool DebugEngine::removeBreakpoint(std::uint64_t id){for(auto i=breakpoints_.begin();i!=breakpoints_.end();++i)if(i->id==id){breakpoints_.erase(i);return true;}return false;} bool DebugEngine::setBreakpointEnabled(std::uint64_t id,bool e){for(auto&r:breakpoints_)if(r.id==id){r.enabled=e;return true;}return false;} bool DebugEngine::hitBreakpoint(std::uint64_t id){for(auto&r:breakpoints_)if(r.id==id&&r.enabled){++r.hit_count;if(r.spec.temporary)r.enabled=false;return r.hit_count>r.spec.ignore_count;}return false;} std::uint64_t DebugEngine::addWatchpoint(WatchpointSpec s){auto id=next_watchpoint_++;watchpoints_.push_back({id,std::move(s),true,0,{},{}});return id;} bool DebugEngine::removeWatchpoint(std::uint64_t id){for(auto i=watchpoints_.begin();i!=watchpoints_.end();++i)if(i->id==id){watchpoints_.erase(i);return true;}return false;} bool DebugEngine::updateWatchpoint(std::uint64_t id,std::string oldv,std::string newv){for(auto&r:watchpoints_)if(r.id==id&&r.enabled){r.last_value=std::move(oldv);r.new_value=std::move(newv);++r.hit_count;return r.last_value!=r.new_value;}return false;} void DebugEngine::setThreads(std::vector t){threads_=std::move(t);current_thread_=0;for(auto&r:threads_)r.current=false;} bool DebugEngine::selectThread(std::uint64_t id){for(auto&r:threads_)r.current=(r.id==id);for(const auto&r:threads_)if(r.current){current_thread_=id;return true;}return false;} void DebugEngine::setStack(std::vectors){stack_=std::move(s);} void DebugEngine::setSymbols(std::vectors){symbols_=std::move(s);} void DebugEngine::setMemoryMap(std::vectors){memory_=std::move(s);} void DebugEngine::setRegisters(RegisterSnapshot s){registers_=std::move(s);} void DebugEngine::setException(ExceptionRecord e){exception_=std::move(e);} void DebugEngine::setEvidence(EvidenceBundle e){evidence_=std::move(e);} bool DebugEngine::hasCapability(const std::string&n)const{for(const auto&c:capabilities_)if(c.name==n&&(c.state==CapabilityState::Implemented||c.state==CapabilityState::Tested))return true;return false;} std::string DebugEngine::capabilityReport()const{std::ostringstream o;for(const auto&c:capabilities_)o<4096)return false;auto i=variables_.find(e);if(i!=variables_.end()){out=i->second;return true;}std::size_t p=0;while(p