From 152c16aea97da9149c41b477720f308a40d3916a Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 4 Oct 2023 12:52:17 -0700 Subject: [PATCH] Debug dump improvements --- dev/TODO.txt | 5 +++++ dev/src/lobster/vmdata.h | 3 ++- dev/src/lobsterreader.cpp | 2 +- dev/src/vm.cpp | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dev/TODO.txt b/dev/TODO.txt index 406fed755..57f7a8543 100644 --- a/dev/TODO.txt +++ b/dev/TODO.txt @@ -8,6 +8,11 @@ it make things harder to recognize without its namespace in front. Really, don't put things in a namespace if you don't effectively want to make it part of the name. +- Debug dump improvements: + - automatically zip these files, can be 5x smaller. + - Turn C++ crashes into Lobster errors so they can be saved with a lot of context. + - For cycle objects, instead save object ids so a viewer can still find the original objects? + - auto binding generated C++ headers from a Lobster decl - allow let inside if/guard as syntactic sugar diff --git a/dev/src/lobster/vmdata.h b/dev/src/lobster/vmdata.h index 3055cd1fd..ad84d8a3c 100644 --- a/dev/src/lobster/vmdata.h +++ b/dev/src/lobster/vmdata.h @@ -387,7 +387,8 @@ struct ToFlexBufferContext { string cycle_hit; flexbuffers::Builder::Value cycle_hit_value; - ToFlexBufferContext(VM &vm) : vm(vm) {} + ToFlexBufferContext(VM &vm, size_t initial_size, flexbuffers::BuilderFlag flags) + : vm(vm), builder(initial_size, flags) {} }; struct Value { diff --git a/dev/src/lobsterreader.cpp b/dev/src/lobsterreader.cpp index 88b3d88c1..8153d7f71 100644 --- a/dev/src/lobsterreader.cpp +++ b/dev/src/lobsterreader.cpp @@ -395,7 +395,7 @@ nfr("flexbuffers_value_to_binary", "val,max_nesting,cycle_detection", "AI?B?", " "turns any reference value into a flexbuffer. max_nesting defaults to 100. " "cycle_detection is by default off (expensive)", [](StackPtr &, VM &vm, Value &val, Value &maxnest, Value &cycle_detect) { - ToFlexBufferContext fbc(vm); + ToFlexBufferContext fbc(vm, 1024, flexbuffers::BUILDER_FLAG_SHARE_KEYS); auto mn = maxnest.ival(); if (mn > 0) fbc.max_depth = mn; fbc.cycle_detect = cycle_detect.True(); diff --git a/dev/src/vm.cpp b/dev/src/vm.cpp index 38d49ae3e..9e0921b17 100644 --- a/dev/src/vm.cpp +++ b/dev/src/vm.cpp @@ -480,7 +480,7 @@ void VM::DumpStackTraceMemory(const string &err) { // We're going to be dumping as much as possible of the memory of the program along with // the stack trace. To this end we're using the FlexBuffers dumper which already can deal with // cycles etc, so it will output max 1 copy of each data structure. - ToFlexBufferContext fbc(*this); + ToFlexBufferContext fbc(*this, 1024 * 1024, flexbuffers::BUILDER_FLAG_SHARE_KEYS_AND_STRINGS); fbc.cycle_detect = true; fbc.max_depth = 64; fbc.ignore_unsupported_types = true;