ArkScript
A small, lisp-inspired, functional scripting language
Ark::internal::Debugger Class Reference

#include <Debugger.hpp>

Collaboration diagram for Ark::internal::Debugger:
[legend]

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< CommandmatchCommand (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< CompiledPromptcompile (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< Commandm_commands
 
std::vector< std::unique_ptr< SavedState > > m_states
 
std::vector< std::filesystem::path > m_libenv
 
std::vector< std::string > m_symbols
 
std::vector< Valuem_constants
 
bool m_running { false }
 
bool m_quit_vm { false }
 
std::deque< TracedInstructionm_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 }
 

Detailed Description

Definition at line 60 of file Debugger.hpp.

Constructor & Destructor Documentation

◆ Debugger() [1/2]

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.

Parameters
contextcontext from the VM before displaying a backtrace
libenv
symbolssymbols table of the VM
constantsconstants table of the VM

Definition at line 20 of file Debugger.cpp.

References initCommands(), and saveState().

◆ Debugger() [2/2]

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.

Parameters
libenv
path_to_prompt_file
osoutput stream
symbolssymbols table of the VM
constantsconstants table of the VM

Definition at line 31 of file Debugger.cpp.

References initCommands().

Member Function Documentation

◆ compile()

std::optional< CompiledPrompt > Ark::internal::Debugger::compile ( const std::string & code,
std::size_t start_page_at_offset ) const
nodiscardprivate

Take care of compiling new code using the existing data tables.

Parameters
code
start_page_at_offsetoffset to start the new pages at
Returns
std::optional<CompiledPrompt> optional set of bytecode pages, symbols and constants if compilation succeeded

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().

◆ initCommands()

◆ isRunning()

ARK_ALWAYS_INLINE bool Ark::internal::Debugger::isRunning ( ) const
inlinenodiscardnoexcept

Definition at line 109 of file Debugger.hpp.

References m_running.

◆ matchCommand()

std::optional< Debugger::Command > Ark::internal::Debugger::matchCommand ( const std::string & line) const
nodiscardprivate

Definition at line 273 of file Debugger.cpp.

References m_commands.

Referenced by prompt().

◆ prompt()

std::optional< std::string > Ark::internal::Debugger::prompt ( std::size_t ip,
std::size_t pp,
VM & vm,
ExecutionContext & context )
private

◆ registerInstruction()

void Ark::internal::Debugger::registerInstruction ( uint8_t inst,
uint8_t padding,
uint16_t arg,
std::size_t ip,
std::size_t pp )
noexcept

Definition at line 135 of file Debugger.cpp.

◆ resetContextToSavedState()

void Ark::internal::Debugger::resetContextToSavedState ( ExecutionContext & context)

◆ run()

◆ saveState()

void Ark::internal::Debugger::saveState ( const ExecutionContext & context)

◆ shouldQuitVM()

ARK_ALWAYS_INLINE bool Ark::internal::Debugger::shouldQuitVM ( ) const
inlinenodiscardnoexcept

Definition at line 114 of file Debugger.hpp.

References m_quit_vm.

◆ showContext()

void Ark::internal::Debugger::showContext ( const VM & vm,
const ExecutionContext & context ) const
private

◆ showLocals() [1/2]

void Ark::internal::Debugger::showLocals ( const ScopeView & scope,
VM & vm,
std::optional< std::size_t > limit = std::nullopt ) const
private

◆ showLocals() [2/2]

void Ark::internal::Debugger::showLocals ( VM & vm,
ExecutionContext & context,
std::size_t count ) const
private

Definition at line 342 of file Debugger.cpp.

References Ark::internal::ExecutionContext::locals, m_os, and showLocals().

Referenced by initCommands(), showLocals(), and showScopes().

◆ showPreviousInstructions()

void Ark::internal::Debugger::showPreviousInstructions ( const VM & vm,
std::size_t count ) const
private

◆ showScopes()

void Ark::internal::Debugger::showScopes ( VM & vm,
ExecutionContext & context,
std::size_t count ) const
private

Definition at line 357 of file Debugger.cpp.

References Ark::internal::ExecutionContext::locals, m_os, and showLocals().

Referenced by initCommands().

◆ showStack()

void Ark::internal::Debugger::showStack ( VM & vm,
const ExecutionContext & context,
std::size_t count ) const
private

Member Data Documentation

◆ m_code

std::string Ark::internal::Debugger::m_code
private

Code added while inside the debugger.

Definition at line 176 of file Debugger.hpp.

Referenced by run().

◆ m_colorize

bool Ark::internal::Debugger::m_colorize
private

◆ m_commands

std::vector<Command> Ark::internal::Debugger::m_commands
private

Definition at line 162 of file Debugger.hpp.

Referenced by initCommands(), and matchCommand().

◆ m_constants

std::vector<Value> Ark::internal::Debugger::m_constants
private

Definition at line 167 of file Debugger.hpp.

Referenced by compile().

◆ m_libenv

std::vector<std::filesystem::path> Ark::internal::Debugger::m_libenv
private

Definition at line 165 of file Debugger.hpp.

Referenced by compile().

◆ m_line_count

std::size_t Ark::internal::Debugger::m_line_count { 0 }
private

Definition at line 177 of file Debugger.hpp.

Referenced by prompt(), and run().

◆ m_os

std::ostream& Ark::internal::Debugger::m_os
private

◆ m_previous_insts

std::deque<TracedInstruction> Ark::internal::Debugger::m_previous_insts
private

Definition at line 171 of file Debugger.hpp.

Referenced by showPreviousInstructions().

◆ m_prompt_stream

std::unique_ptr<std::istream> Ark::internal::Debugger::m_prompt_stream
private

Definition at line 175 of file Debugger.hpp.

Referenced by prompt().

◆ m_quit_vm

bool Ark::internal::Debugger::m_quit_vm { false }
private

Definition at line 169 of file Debugger.hpp.

Referenced by initCommands(), and shouldQuitVM().

◆ m_running

bool Ark::internal::Debugger::m_running { false }
private

Definition at line 168 of file Debugger.hpp.

Referenced by isRunning(), and run().

◆ m_states

std::vector<std::unique_ptr<SavedState> > Ark::internal::Debugger::m_states
private

Definition at line 164 of file Debugger.hpp.

Referenced by resetContextToSavedState(), and saveState().

◆ m_symbols

std::vector<std::string> Ark::internal::Debugger::m_symbols
private

Definition at line 166 of file Debugger.hpp.

Referenced by compile().


The documentation for this class was generated from the following files: