Skip to content

Commit f327398

Browse files
committed
Fix #354: segmentation fault in debugger
1 parent 82a8afd commit f327398

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/Debug/debugger.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ void Debugger::dumpFunctions(Module *m) const {
558558
void Debugger::dumpCallstack(Module *m) const {
559559
auto toVA = [m](uint8_t *addr) { return toVirtualAddress(addr, m); };
560560
this->channel->write("\"callstack\":[");
561+
562+
if (m->csp < 0) {
563+
this->channel->write("]");
564+
return;
565+
}
566+
561567
for (int i = 0; i <= m->csp; i++) {
562568
const Frame *f = &m->callstack[i];
563569
int callsite_retaddr = -1;
@@ -582,6 +588,12 @@ void Debugger::dumpCallstack(Module *m) const {
582588
void Debugger::dumpLocals(const Module *m) const {
583589
// fflush(stdout);
584590
int firstFunFramePtr = m->csp;
591+
592+
if (firstFunFramePtr < 0) {
593+
this->channel->write("[]");
594+
return;
595+
}
596+
585597
while (m->callstack[firstFunFramePtr].block->block_type != 0) {
586598
firstFunFramePtr--;
587599
if (firstFunFramePtr < 0) {

0 commit comments

Comments
 (0)