![]() |
ArkScript
A small, lisp-inspired, functional scripting language
|
#include <Debugger.hpp>
Classes | |
| struct | Command |
| struct | CommandArgs |
| struct | StartsWith |
Public Member Functions | |
| Debugger (const ExecutionContext &context, const std::vector< std::filesystem::path > &libenv, const std::vector< std::string > &symbols, const std::vector< Value > &constants) | |
| Create a new Debugger object. | |
| Debugger (const std::vector< std::filesystem::path > &libenv, const std::string &path_to_prompt_file, std::ostream &os, const std::vector< std::string > &symbols, const std::vector< Value > &constants) | |
| Create a new Debugger object that will use lines from a file as prompts, instead of waiting for user inputs. | |
| void | saveState (const ExecutionContext &context) |
| Save the current VM state, to get back to it once the debugger is done running. | |
| void | resetContextToSavedState (ExecutionContext &context) |
| Reset a VM context to the last state saved by the debugger. | |
| void | run (VM &vm, ExecutionContext &context, bool from_breakpoint) |
| Start the debugger shell. | |
| void | registerInstruction (uint8_t inst, uint8_t padding, uint16_t arg, std::size_t ip, std::size_t pp) noexcept |
| ARK_ALWAYS_INLINE bool | isRunning () const noexcept |
| ARK_ALWAYS_INLINE bool | shouldQuitVM () const noexcept |
Private Member Functions | |
| void | initCommands () |
| std::optional< Command > | matchCommand (const std::string &line) const |
| void | showContext (const VM &vm, const ExecutionContext &context) const |
| void | showStack (VM &vm, const ExecutionContext &context, std::size_t count) const |
| void | showLocals (VM &vm, ExecutionContext &context, std::size_t count) const |
| void | showScopes (VM &vm, ExecutionContext &context, std::size_t count) const |
| void | showPreviousInstructions (const VM &vm, std::size_t count) const |
| void | showLocals (const ScopeView &scope, VM &vm, std::optional< std::size_t > limit=std::nullopt) const |
| std::optional< std::string > | prompt (std::size_t ip, std::size_t pp, VM &vm, ExecutionContext &context) |
| std::optional< CompiledPrompt > | compile (const std::string &code, std::size_t start_page_at_offset) const |
| Take care of compiling new code using the existing data tables. | |
Private Attributes | |
| std::vector< Command > | m_commands |
| std::vector< std::unique_ptr< SavedState > > | m_states |
| std::vector< std::filesystem::path > | m_libenv |
| std::vector< std::string > | m_symbols |
| std::vector< Value > | m_constants |
| bool | m_running { false } |
| bool | m_quit_vm { false } |
| std::deque< TracedInstruction > | m_previous_insts |
| std::ostream & | m_os |
| bool | m_colorize |
| std::unique_ptr< std::istream > | m_prompt_stream |
| std::string | m_code |
| Code added while inside the debugger. | |
| std::size_t | m_line_count { 0 } |
Definition at line 60 of file Debugger.hpp.
| Ark::internal::Debugger::Debugger | ( | const ExecutionContext & | context, |
| const std::vector< std::filesystem::path > & | libenv, | ||
| const std::vector< std::string > & | symbols, | ||
| const std::vector< Value > & | constants ) |
Create a new Debugger object.
| context | context from the VM before displaying a backtrace |
| libenv | |
| symbols | symbols table of the VM |
| constants | constants table of the VM |
Definition at line 20 of file Debugger.cpp.
References initCommands(), and saveState().
| Ark::internal::Debugger::Debugger | ( | const std::vector< std::filesystem::path > & | libenv, |
| const std::string & | path_to_prompt_file, | ||
| std::ostream & | os, | ||
| const std::vector< std::string > & | symbols, | ||
| const std::vector< Value > & | constants ) |
Create a new Debugger object that will use lines from a file as prompts, instead of waiting for user inputs.
| libenv | |
| path_to_prompt_file | |
| os | output stream |
| symbols | symbols table of the VM |
| constants | constants table of the VM |
Definition at line 31 of file Debugger.cpp.
References initCommands().
|
nodiscardprivate |
Take care of compiling new code using the existing data tables.
| code | |
| start_page_at_offset | offset to start the new pages at |
Definition at line 492 of file Debugger.cpp.
References Ark::Welder::bytecode(), Ark::BytecodeReader::code(), Ark::Welder::computeASTFromStringWithKnownSymbols(), Ark::DefaultFeatures, Ark::BytecodeReader::feed(), Ark::BytecodeReader::filenames(), Ark::Welder::generateBytecodeUsingTables(), Ark::BytecodeReader::instLocations(), m_constants, m_libenv, m_symbols, Ark::BytecodeReader::symbols(), and Ark::BytecodeReader::values().
Referenced by run().
|
private |
Definition at line 185 of file Debugger.cpp.
References Ark::internal::Debugger::Command::argAsCount(), Ark::internal::Debugger::CommandArgs::ctx_ptr, Ark::internal::Debugger::CommandArgs::ip, m_colorize, m_commands, m_os, m_quit_vm, Ark::internal::Debugger::CommandArgs::me, Ark::internal::Debugger::CommandArgs::pp, showLocals(), showPreviousInstructions(), showScopes(), showStack(), Ark::internal::ExecutionContext::sp, and Ark::internal::Debugger::CommandArgs::vm_ptr.
Referenced by Debugger(), and Debugger().
|
inlinenodiscardnoexcept |
Definition at line 109 of file Debugger.hpp.
References m_running.
|
nodiscardprivate |
|
private |
Definition at line 436 of file Debugger.cpp.
References Ark::internal::Debugger::Command::action, Ark::Utils::countOpenEnclosures(), m_colorize, m_line_count, m_os, m_prompt_stream, matchCommand(), and Ark::Utils::trimWhitespace().
Referenced by run().
|
noexcept |
Definition at line 135 of file Debugger.cpp.
| void Ark::internal::Debugger::resetContextToSavedState | ( | ExecutionContext & | context | ) |
Reset a VM context to the last state saved by the debugger.
| context | context to reset |
Definition at line 54 of file Debugger.cpp.
References Ark::internal::ExecutionContext::fc, Ark::internal::ExecutionContext::ip, Ark::internal::ExecutionContext::locals, m_states, Ark::internal::ExecutionContext::pp, Ark::internal::ExecutionContext::sp, and Ark::internal::ExecutionContext::stacked_closure_scopes.
| void Ark::internal::Debugger::run | ( | VM & | vm, |
| ExecutionContext & | context, | ||
| bool | from_breakpoint ) |
Start the debugger shell.
| vm | |
| context | |
| from_breakpoint | true if the debugger is being invoked from a breakpoint |
Definition at line 67 of file Debugger.cpp.
References compile(), Ark::State::extendBytecode(), Ark::Garbage, Ark::InstPtr, Ark::internal::ExecutionContext::ip, Ark::internal::ExecutionContext::locals, m_code, m_colorize, m_line_count, m_os, Ark::State::m_pages, m_running, Ark::VM::m_running, Ark::VM::m_state, Ark::VM::peekAndResolveAsPtr(), Ark::internal::ExecutionContext::pp, prompt(), Ark::VM::safeRun(), Ark::internal::ExecutionContext::scopes_storage, showContext(), Ark::Value::toString(), Ark::Undefined, and Ark::Value::valueType().
| void Ark::internal::Debugger::saveState | ( | const ExecutionContext & | context | ) |
Save the current VM state, to get back to it once the debugger is done running.
| context |
Definition at line 42 of file Debugger.cpp.
References Ark::internal::ExecutionContext::fc, Ark::internal::ExecutionContext::ip, Ark::internal::ExecutionContext::locals, m_states, Ark::internal::ExecutionContext::pp, Ark::internal::ExecutionContext::sp, and Ark::internal::ExecutionContext::stacked_closure_scopes.
Referenced by Debugger().
|
inlinenodiscardnoexcept |
Definition at line 114 of file Debugger.hpp.
References m_quit_vm.
|
private |
Definition at line 294 of file Debugger.cpp.
References Ark::Utils::fileExists(), Ark::VM::findSourceLocation(), Ark::internal::ExecutionContext::ip, m_colorize, Ark::State::m_filenames, m_os, Ark::VM::m_state, Ark::Diagnostics::makeContext(), and Ark::internal::ExecutionContext::pp.
Referenced by run().
|
private |
Definition at line 389 of file Debugger.cpp.
References Ark::internal::ScopeView::atPosReverse(), m_colorize, m_os, Ark::VM::m_state, Ark::State::m_symbols, Ark::internal::ScopeView::size(), and std::to_string().
|
private |
Definition at line 342 of file Debugger.cpp.
References Ark::internal::ExecutionContext::locals, m_os, and showLocals().
Referenced by initCommands(), showLocals(), and showScopes().
|
private |
Definition at line 414 of file Debugger.cpp.
References Ark::VM::bytecode(), Ark::BytecodeReader::feed(), m_colorize, m_os, m_previous_insts, Ark::BytecodeReader::printInstruction(), Ark::BytecodeReader::symbols(), and Ark::BytecodeReader::values().
Referenced by initCommands().
|
private |
Definition at line 357 of file Debugger.cpp.
References Ark::internal::ExecutionContext::locals, m_os, and showLocals().
Referenced by initCommands().
|
private |
Definition at line 319 of file Debugger.cpp.
References m_colorize, m_os, Ark::internal::ExecutionContext::sp, and Ark::internal::ExecutionContext::stack.
Referenced by initCommands().
|
private |
Code added while inside the debugger.
Definition at line 176 of file Debugger.hpp.
Referenced by run().
|
private |
Definition at line 174 of file Debugger.hpp.
Referenced by initCommands(), prompt(), run(), showContext(), showLocals(), showPreviousInstructions(), and showStack().
|
private |
Definition at line 162 of file Debugger.hpp.
Referenced by initCommands(), and matchCommand().
|
private |
Definition at line 167 of file Debugger.hpp.
Referenced by compile().
|
private |
Definition at line 165 of file Debugger.hpp.
Referenced by compile().
|
private |
Definition at line 177 of file Debugger.hpp.
|
private |
Definition at line 173 of file Debugger.hpp.
Referenced by initCommands(), prompt(), run(), showContext(), showLocals(), showLocals(), showPreviousInstructions(), showScopes(), and showStack().
|
private |
Definition at line 171 of file Debugger.hpp.
Referenced by showPreviousInstructions().
|
private |
Definition at line 175 of file Debugger.hpp.
Referenced by prompt().
|
private |
Definition at line 169 of file Debugger.hpp.
Referenced by initCommands(), and shouldQuitVM().
|
private |
Definition at line 168 of file Debugger.hpp.
Referenced by isRunning(), and run().
|
private |
Definition at line 164 of file Debugger.hpp.
Referenced by resetContextToSavedState(), and saveState().
|
private |
Definition at line 166 of file Debugger.hpp.
Referenced by compile().