From a499f6e7a7d97490abd9033c33c55c94d289671e Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 24 Apr 2024 09:15:43 +0900 Subject: [PATCH] Reallocate shadow callstack in krk-callgrind --- tools/callgrind.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/callgrind.c b/tools/callgrind.c index b94936f..882059b 100644 --- a/tools/callgrind.c +++ b/tools/callgrind.c @@ -86,12 +86,17 @@ struct FrameMetadata { struct timespec in_time; /* Time of frame entry */ }; -static struct FrameMetadata frameMetadata[KRK_CALL_FRAMES_MAX]; +static size_t maxFrameCount = KRK_CALL_FRAMES_MAX; +static struct FrameMetadata * frameMetadata; int krk_callgrind_debuggerHook(KrkCallFrame * frame) { instrCounter++; if (krk_currentThread.frameCount != lastFrameCount) { + if (maxFrameCount != krk_currentThread.maximumCallDepth) { + frameMetadata = realloc(frameMetadata, sizeof(*frameMetadata) * krk_currentThread.maximumCallDepth); + maxFrameCount = krk_currentThread.maximumCallDepth; + } if (krk_currentThread.frameCount > lastFrameCount) { /* When we detect function entry, record details of the function being called * and what called in, and record the current time. */ @@ -262,6 +267,7 @@ int main(int argc, char *argv[]) { findInterpreter(argv); krk_initVM(KRK_THREAD_SINGLE_STEP); + frameMetadata = malloc(sizeof(*frameMetadata) * krk_currentThread.maximumCallDepth); krk_debug_registerCallback(krk_callgrind_debuggerHook); KrkValue argList = addArgs(argc,argv);