chakra-core / chakra-core/ChakraCore

JsDiagGetStackTrace returns empty array when stack is not empty

Open
#4,944 6 comments 0 reactions 0 assignees View on GitHub
APIs Bug Severity: 3
Dominant language
JavaScript
Stars
9.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I'm having a bizarre issue where `JsDiagGetStackTrace()` returns an empty trace even when there's something on the stack. This only seems to happen on Linux and what's very strange is that it appears to depend on optimization settings; I can't reproduce it in an unoptimized build at all (this being strange because ChakraCore itself is a fully optimized shared-library build in all cases, so the optimization settings of the host shouldn't matter).

To verify there was indeed something on the stack, I gave my debugger the following code:
```js
function doStuff()
{
print("Checkpoint 1");
debugger;
print("Checkpoint 2");
}
doStuff();
```

Running this code, execution pauses at the debugger statement but the backtrace is completely empty--and remains empty even as I step through the remainder of the code.

To rule out that this isn't a bug in one of my abstractions, I added some instrumentation at the point I actually retrieve the stack:
```
if (JsDiagGetStackTrace(&backtrace) != JsNoError)
return false;
JsPropertyIdRef propId;
JsValueRef propValue;
int length;
JsCreatePropertyId("length", 6, &propId);
JsGetProperty(backtrace, propId, &propValue);
JsGetValueType(propValue, &type);
JsNumberToInt(propValue, &length);
printf("%d: %d\n", type, length);
```

The output was `2: 0` (`2` being JsNumber); so it seems that I've indeed been handed back a zero-length array. If I recompile the host with `-g` instead of an optimization flag, this same code prints `2: 2` upon hitting the debugger statement. It's very, very strange.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.