debug.h
Go to the documentation of this file.
1 #pragma once
18 #include <stdio.h>
19 #include "vm.h"
20 #include "chunk.h"
21 #include "object.h"
22 
23 #ifndef KRK_DISABLE_DEBUG
24 
35 extern void krk_disassembleCodeObject(FILE * f, KrkCodeObject * func, const char * name);
36 
49 extern size_t krk_disassembleInstruction(FILE * f, KrkCodeObject * func, size_t offset);
50 
56 extern int krk_debugBreakpointHandler(void);
57 
67 extern int krk_debuggerHook(KrkCallFrame * frame);
68 
73 typedef int (*KrkDebugCallback)(KrkCallFrame *frame);
74 
95 
111 extern int krk_debug_addBreakpointFileLine(KrkString * filename, size_t line, int flags);
112 
129 extern int krk_debug_addBreakpointCodeOffset(KrkCodeObject * codeObject, size_t offset, int flags);
130 
141 extern int krk_debug_removeBreakpoint(int breakpointId);
142 
152 extern int krk_debug_enableBreakpoint(int breakpointId);
153 
165 extern int krk_debug_disableBreakpoint(int breakpointId);
166 
170 extern void krk_debug_enableSingleStep(void);
171 
175 extern void krk_debug_disableSingleStep(void);
176 
183 extern void krk_debug_dumpTraceback(void);
184 
198 extern int krk_debug_examineBreakpoint(int breakIndex, KrkCodeObject ** funcOut, size_t * offsetOut, int * flagsOut, int *enabledOut);
199 
207 extern void krk_debug_dumpStack(FILE * f, KrkCallFrame * frame);
208 
212 extern void krk_debug_init(void);
213 
231 #define KRK_BREAKPOINT_NORMAL 0
232 #define KRK_BREAKPOINT_ONCE 1
233 #define KRK_BREAKPOINT_REPEAT 2
234 
235 #define KRK_DEBUGGER_CONTINUE 0
236 #define KRK_DEBUGGER_ABORT 1
237 #define KRK_DEBUGGER_STEP 2
238 #define KRK_DEBUGGER_RAISE 3
239 #define KRK_DEBUGGER_QUIT 4
240 
255 extern void krk_debug_addExpression(KrkCodeObject * codeobject, uint8_t start, uint8_t midStart, uint8_t midEnd, uint8_t end);
256 
272 extern int krk_debug_expressionUnderline(const KrkCodeObject * codeobject, uint8_t * start, uint8_t * midStart, uint8_t * endStart, uint8_t * end, size_t instruction);
273 
290 extern void krk_printValueSafe(FILE * f, KrkValue value);
291 
292 #endif
Structures and enums for bytecode chunks.
int krk_debug_addBreakpointCodeOffset(KrkCodeObject *codeObject, size_t offset, int flags)
Add a breakpoint to the given code object.
Definition: debug.c:403
void krk_debug_disableSingleStep(void)
Disable single stepping in the current thread.
Definition: debug.c:527
int krk_debuggerHook(KrkCallFrame *frame)
Called by the VM on single step.
Definition: debug.c:531
int krk_debug_examineBreakpoint(int breakIndex, KrkCodeObject **funcOut, size_t *offsetOut, int *flagsOut, int *enabledOut)
Retreive information on a breakpoint.
Definition: debug.c:583
void krk_debug_init(void)
Initialize debugger state. Call exactly once per VM.
Definition: debug.c:633
int(* KrkDebugCallback)(KrkCallFrame *frame)
Function pointer for a debugger hook. krk_debug_registerCallback()
Definition: debug.h:73
int krk_debug_enableBreakpoint(int breakpointId)
Enable a breakpoint.
Definition: debug.c:469
int krk_debugBreakpointHandler(void)
Called by the VM when a breakpoint is encountered.
Definition: debug.c:597
void krk_debug_dumpTraceback(void)
Safely dump a traceback to stderr.
Definition: debug.c:511
void krk_debug_enableSingleStep(void)
Enable single stepping in the current thread.
Definition: debug.c:523
int krk_debug_removeBreakpoint(int breakpointId)
Remove a breakpoint from the breakpoint table.
Definition: debug.c:487
int krk_debug_registerCallback(KrkDebugCallback hook)
Register a debugger callback.
Definition: debug.c:577
int krk_debug_disableBreakpoint(int breakpointId)
Disable a breakpoint.
Definition: debug.c:476
size_t krk_disassembleInstruction(FILE *f, KrkCodeObject *func, size_t offset)
Print a disassembly of a single opcode instruction.
Definition: debug.c:351
int krk_debug_addBreakpointFileLine(KrkString *filename, size_t line, int flags)
Add a breakpoint to the given line of a file.
Definition: debug.c:429
void krk_disassembleCodeObject(FILE *f, KrkCodeObject *func, const char *name)
Print a disassembly of 'func' to the stream 'f'.
Definition: debug.c:163
void krk_debug_dumpStack(FILE *f, KrkCallFrame *frame)
Print the elements on the stack.
Definition: debug.c:125
Struct definitions for core object types.
Represents a managed call state in a VM thread.
Definition: vm.h:45
Code object.
Definition: object.h:157
void krk_debug_addExpression(KrkCodeObject *codeobject, uint8_t start, uint8_t midStart, uint8_t midEnd, uint8_t end)
Add an expression mapping to the bytecode chunk.
Definition: debug.c:639
int krk_debug_expressionUnderline(const KrkCodeObject *codeobject, uint8_t *start, uint8_t *midStart, uint8_t *endStart, uint8_t *end, size_t instruction)
Extract expression mapping from chunk.
Definition: debug.c:660
Immutable sequence of Unicode codepoints.
Definition: object.h:93
Stack reference or primative value.
void krk_printValueSafe(FILE *f, KrkValue value)
Print a value without calling the VM.
Definition: debug.c:21
Core API for the bytecode virtual machine.