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

#include <Debugger.hpp>

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

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.
 
bool isRunning () const noexcept
 
bool shouldQuitVM () const noexcept
 

Private Member Functions

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
 
std::optional< std::size_t > getArgAndParseOrError (const std::string &command, const std::string &line, std::size_t default_value) 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.
 

Static Private Member Functions

static std::optional< std::string > getCommandArg (const std::string &command, const std::string &line)
 
static std::optional< std::size_t > parseStringAsInt (const std::string &str)
 

Private Attributes

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::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 48 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 19 of file Debugger.cpp.

References 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 29 of file Debugger.cpp.

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

◆ getArgAndParseOrError()

std::optional< std::size_t > Ark::internal::Debugger::getArgAndParseOrError ( const std::string & command,
const std::string & line,
std::size_t default_value ) const
nodiscardprivate

Definition at line 233 of file Debugger.cpp.

References getCommandArg(), m_os, and parseStringAsInt().

Referenced by prompt().

◆ getCommandArg()

std::optional< std::string > Ark::internal::Debugger::getCommandArg ( const std::string & command,
const std::string & line )
staticprivate

Definition at line 213 of file Debugger.cpp.

References Ark::Utils::trimWhitespace().

Referenced by getArgAndParseOrError().

◆ isRunning()

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

Definition at line 95 of file Debugger.hpp.

References m_running.

◆ parseStringAsInt()

std::optional< std::size_t > Ark::internal::Debugger::parseStringAsInt ( const std::string & str)
staticprivate

Definition at line 223 of file Debugger.cpp.

Referenced by getArgAndParseOrError().

◆ prompt()

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

◆ resetContextToSavedState()

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

◆ run()

◆ saveState()

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

◆ shouldQuitVM()

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

Definition at line 100 of file Debugger.hpp.

References m_quit_vm.

◆ showContext()

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

◆ showLocals()

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

◆ 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 116 of file Debugger.hpp.

Referenced by run().

◆ m_colorize

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

Definition at line 114 of file Debugger.hpp.

Referenced by prompt(), run(), showContext(), showLocals(), and showStack().

◆ m_constants

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

Definition at line 109 of file Debugger.hpp.

Referenced by compile().

◆ m_libenv

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

Definition at line 107 of file Debugger.hpp.

Referenced by compile().

◆ m_line_count

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

Definition at line 117 of file Debugger.hpp.

Referenced by prompt(), and run().

◆ m_os

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

Definition at line 113 of file Debugger.hpp.

Referenced by getArgAndParseOrError(), prompt(), run(), showContext(), showLocals(), and showStack().

◆ m_prompt_stream

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

Definition at line 115 of file Debugger.hpp.

Referenced by prompt().

◆ m_quit_vm

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

Definition at line 111 of file Debugger.hpp.

Referenced by prompt(), and shouldQuitVM().

◆ m_running

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

Definition at line 110 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 106 of file Debugger.hpp.

Referenced by resetContextToSavedState(), and saveState().

◆ m_symbols

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

Definition at line 108 of file Debugger.hpp.

Referenced by compile().


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