Skip to content

Commit

Permalink
Reallocate shadow callstack in krk-callgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Apr 24, 2024
1 parent 40bfcfe commit a499f6e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools/callgrind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a499f6e

Please sign in to comment.