Skip to content

Commit 78c7913

Browse files
JsRT Debugging APIs
1 parent 7f3a8f6 commit 78c7913

File tree

74 files changed

+7600
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7600
-280
lines changed

bin/ChakraCore/ChakraCore.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,21 @@ LIBRARY ChakraCore
22

33
EXPORTS
44
#include "JsrtCommonExports.inc"
5+
6+
JsDiagEvaluate
7+
JsDiagGetBreakOnException
8+
JsDiagGetBreakpoints
9+
JsDiagGetFunctionPosition
10+
JsDiagGetProperties
11+
JsDiagGetScripts
12+
JsDiagGetSource
13+
JsDiagGetStackProperties
14+
JsDiagGetStackTrace
15+
JsDiagGetObjectFromHandle
16+
JsDiagRemoveBreakpoint
17+
JsDiagRequestAsyncBreak
18+
JsDiagSetBreakOnException
19+
JsDiagSetBreakpoint
20+
JsDiagSetStepType
21+
JsDiagStartDebugging
22+
JsDiagStopDebugging

bin/ch/ChakraRtInterface.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ HINSTANCE ChakraRTInterface::LoadChakraDll(ArgInfo& argInfo)
7474
m_jsApiHooks.pfJsrtDoubleToNumber = (JsAPIHooks::JsrtDoubleToNumberPtr)GetProcAddress(library, "JsDoubleToNumber");
7575
m_jsApiHooks.pfJsrtGetExternalData = (JsAPIHooks::JsrtGetExternalDataPtr)GetProcAddress(library, "JsGetExternalData");
7676
m_jsApiHooks.pfJsrtCreateArray = (JsAPIHooks::JsrtCreateArrayPtr)GetProcAddress(library, "JsCreateArray");
77+
m_jsApiHooks.pfJsrtHasException = (JsAPIHooks::JsrtHasExceptionPtr)GetProcAddress(library, "JsHasException");
7778
m_jsApiHooks.pfJsrtSetException = (JsAPIHooks::JsrtSetExceptionPtr)GetProcAddress(library, "JsSetException");
7879
m_jsApiHooks.pfJsrtGetAndClearException = (JsAPIHooks::JsrtGetAndClearExceptiopnPtr)GetProcAddress(library, "JsGetAndClearException");
7980
m_jsApiHooks.pfJsrtCreateError = (JsAPIHooks::JsrtCreateErrorPtr)GetProcAddress(library, "JsCreateError");
@@ -87,6 +88,24 @@ HINSTANCE ChakraRTInterface::LoadChakraDll(ArgInfo& argInfo)
8788
m_jsApiHooks.pfJsrtSetPromiseContinuationCallback = (JsAPIHooks::JsrtSetPromiseContinuationCallbackPtr)GetProcAddress(library, "JsSetPromiseContinuationCallback");
8889
m_jsApiHooks.pfJsrtGetContextOfObject = (JsAPIHooks::JsrtGetContextOfObject)GetProcAddress(library, "JsGetContextOfObject");
8990

91+
m_jsApiHooks.pfJsrtParseScriptWithAttributes = (JsAPIHooks::JsrtParseScriptWithAttributes)GetProcAddress(library, "JsParseScriptWithAttributes");
92+
m_jsApiHooks.pfJsrtDiagStartDebugging = (JsAPIHooks::JsrtDiagStartDebugging)GetProcAddress(library, "JsDiagStartDebugging");
93+
m_jsApiHooks.pfJsrtDiagStopDebugging = (JsAPIHooks::JsrtDiagStopDebugging)GetProcAddress(library, "JsDiagStopDebugging");
94+
m_jsApiHooks.pfJsrtDiagGetSource = (JsAPIHooks::JsrtDiagGetSource)GetProcAddress(library, "JsDiagGetSource");
95+
m_jsApiHooks.pfJsrtDiagSetBreakpoint = (JsAPIHooks::JsrtDiagSetBreakpoint)GetProcAddress(library, "JsDiagSetBreakpoint");
96+
m_jsApiHooks.pfJsrtDiagGetStackTrace = (JsAPIHooks::JsrtDiagGetStackTrace)GetProcAddress(library, "JsDiagGetStackTrace");
97+
m_jsApiHooks.pfJsrtDiagRequestAsyncBreak = (JsAPIHooks::JsrtDiagRequestAsyncBreak)GetProcAddress(library, "JsDiagRequestAsyncBreak");
98+
m_jsApiHooks.pfJsrtDiagGetBreakpoints = (JsAPIHooks::JsrtDiagGetBreakpoints)GetProcAddress(library, "JsDiagGetBreakpoints");
99+
m_jsApiHooks.pfJsrtDiagRemoveBreakpoint = (JsAPIHooks::JsrtDiagRemoveBreakpoint)GetProcAddress(library, "JsDiagRemoveBreakpoint");
100+
m_jsApiHooks.pfJsrtDiagSetBreakOnException = (JsAPIHooks::JsrtDiagSetBreakOnException)GetProcAddress(library, "JsDiagSetBreakOnException");
101+
m_jsApiHooks.pfJsrtDiagGetBreakOnException = (JsAPIHooks::JsrtDiagGetBreakOnException)GetProcAddress(library, "JsDiagGetBreakOnException");
102+
m_jsApiHooks.pfJsrtDiagSetStepType = (JsAPIHooks::JsrtDiagSetStepType)GetProcAddress(library, "JsDiagSetStepType");
103+
m_jsApiHooks.pfJsrtDiagGetScripts = (JsAPIHooks::JsrtDiagGetScripts)GetProcAddress(library, "JsDiagGetScripts");
104+
m_jsApiHooks.pfJsrtDiagGetFunctionPosition = (JsAPIHooks::JsrtDiagGetFunctionPosition)GetProcAddress(library, "JsDiagGetFunctionPosition");
105+
m_jsApiHooks.pfJsrtDiagGetStackProperties = (JsAPIHooks::JsrtDiagGetStackProperties)GetProcAddress(library, "JsDiagGetStackProperties");
106+
m_jsApiHooks.pfJsrtDiagGetProperties = (JsAPIHooks::JsrtDiagGetProperties)GetProcAddress(library, "JsDiagGetProperties");
107+
m_jsApiHooks.pfJsrtDiagGetObjectFromHandle = (JsAPIHooks::JsrtDiagGetObjectFromHandle)GetProcAddress(library, "JsDiagGetObjectFromHandle");
108+
m_jsApiHooks.pfJsrtDiagEvaluate = (JsAPIHooks::JsrtDiagEvaluate)GetProcAddress(library, "JsDiagEvaluate");
90109
return library;
91110
}
92111

bin/ch/ChakraRtInterface.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct JsAPIHooks
3636
typedef JsErrorCode (WINAPI *JsrtGetExternalDataPtr)(JsValueRef object, void **data);
3737
typedef JsErrorCode (WINAPI *JsrtCreateArrayPtr)(unsigned int length, JsValueRef *result);
3838
typedef JsErrorCode (WINAPI *JsrtCreateErrorPtr)(JsValueRef message, JsValueRef *error);
39+
typedef JsErrorCode(WINAPI *JsrtHasExceptionPtr)(bool *hasException);
3940
typedef JsErrorCode (WINAPI *JsrtSetExceptionPtr)(JsValueRef exception);
4041
typedef JsErrorCode (WINAPI *JsrtGetAndClearExceptiopnPtr)(JsValueRef* exception);
4142
typedef JsErrorCode (WINAPI *JsrtGetRuntimePtr)(JsContextRef context, JsRuntimeHandle *runtime);
@@ -48,6 +49,24 @@ struct JsAPIHooks
4849
typedef JsErrorCode (WINAPI *JsrtSetPromiseContinuationCallbackPtr)(JsPromiseContinuationCallback callback, void *callbackState);
4950
typedef JsErrorCode (WINAPI *JsrtGetContextOfObject)(JsValueRef object, JsContextRef *callbackState);
5051

52+
typedef JsErrorCode(WINAPI *JsrtParseScriptWithAttributes)(const wchar_t *script, JsSourceContext sourceContext, const wchar_t *sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result);
53+
typedef JsErrorCode(WINAPI *JsrtDiagStartDebugging)(JsRuntimeHandle runtimeHandle, JsDiagDebugEventCallback debugEventCallback, void* callbackState);
54+
typedef JsErrorCode(WINAPI *JsrtDiagStopDebugging)(JsRuntimeHandle runtimeHandle, void** callbackState);
55+
typedef JsErrorCode(WINAPI *JsrtDiagGetSource)(unsigned int scriptId, JsValueRef *source);
56+
typedef JsErrorCode(WINAPI *JsrtDiagSetBreakpoint)(unsigned int scriptId, unsigned int lineNumber, unsigned int columnNumber, JsValueRef *breakPoint);
57+
typedef JsErrorCode(WINAPI *JsrtDiagGetStackTrace)(JsValueRef *stackTrace);
58+
typedef JsErrorCode(WINAPI *JsrtDiagRequestAsyncBreak)(JsRuntimeHandle runtimeHandle);
59+
typedef JsErrorCode(WINAPI *JsrtDiagGetBreakpoints)(JsValueRef * breakpoints);
60+
typedef JsErrorCode(WINAPI *JsrtDiagRemoveBreakpoint)(unsigned int breakpointId);
61+
typedef JsErrorCode(WINAPI *JsrtDiagSetBreakOnException)(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes exceptionAttributes);
62+
typedef JsErrorCode(WINAPI *JsrtDiagGetBreakOnException)(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes * exceptionAttributes);
63+
typedef JsErrorCode(WINAPI *JsrtDiagSetStepType)(JsDiagStepType stepType);
64+
typedef JsErrorCode(WINAPI *JsrtDiagGetScripts)(JsValueRef * scriptsArray);
65+
typedef JsErrorCode(WINAPI *JsrtDiagGetFunctionPosition)(JsValueRef value, JsValueRef * functionInfo);
66+
typedef JsErrorCode(WINAPI *JsrtDiagGetStackProperties)(unsigned int stackFrameIndex, JsValueRef * properties);
67+
typedef JsErrorCode(WINAPI *JsrtDiagGetProperties)(unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject);
68+
typedef JsErrorCode(WINAPI *JsrtDiagGetObjectFromHandle)(unsigned int handle, JsValueRef * handleObject);
69+
typedef JsErrorCode(WINAPI *JsrtDiagEvaluate)(const wchar_t * expression, unsigned int stackFrameIndex, JsValueRef * evalResult);
5170
JsrtCreateRuntimePtr pfJsrtCreateRuntime;
5271
JsrtCreateContextPtr pfJsrtCreateContext;
5372
JsrtSetCurrentContextPtr pfJsrtSetCurrentContext;
@@ -80,6 +99,7 @@ struct JsAPIHooks
8099
JsrtGetExternalDataPtr pfJsrtGetExternalData;
81100
JsrtCreateArrayPtr pfJsrtCreateArray;
82101
JsrtCreateErrorPtr pfJsrtCreateError;
102+
JsrtHasExceptionPtr pfJsrtHasException;
83103
JsrtSetExceptionPtr pfJsrtSetException;
84104
JsrtGetAndClearExceptiopnPtr pfJsrtGetAndClearException;
85105
JsrtGetRuntimePtr pfJsrtGetRuntime;
@@ -91,6 +111,24 @@ struct JsAPIHooks
91111
JsrtRunSerializedScriptPtr pfJsrtRunSerializedScript;
92112
JsrtSetPromiseContinuationCallbackPtr pfJsrtSetPromiseContinuationCallback;
93113
JsrtGetContextOfObject pfJsrtGetContextOfObject;
114+
JsrtParseScriptWithAttributes pfJsrtParseScriptWithAttributes;
115+
JsrtDiagStartDebugging pfJsrtDiagStartDebugging;
116+
JsrtDiagStopDebugging pfJsrtDiagStopDebugging;
117+
JsrtDiagGetSource pfJsrtDiagGetSource;
118+
JsrtDiagSetBreakpoint pfJsrtDiagSetBreakpoint;
119+
JsrtDiagGetStackTrace pfJsrtDiagGetStackTrace;
120+
JsrtDiagRequestAsyncBreak pfJsrtDiagRequestAsyncBreak;
121+
JsrtDiagGetBreakpoints pfJsrtDiagGetBreakpoints;
122+
JsrtDiagRemoveBreakpoint pfJsrtDiagRemoveBreakpoint;
123+
JsrtDiagSetBreakOnException pfJsrtDiagSetBreakOnException;
124+
JsrtDiagGetBreakOnException pfJsrtDiagGetBreakOnException;
125+
JsrtDiagSetStepType pfJsrtDiagSetStepType;
126+
JsrtDiagGetScripts pfJsrtDiagGetScripts;
127+
JsrtDiagGetFunctionPosition pfJsrtDiagGetFunctionPosition;
128+
JsrtDiagGetStackProperties pfJsrtDiagGetStackProperties;
129+
JsrtDiagGetProperties pfJsrtDiagGetProperties;
130+
JsrtDiagGetObjectFromHandle pfJsrtDiagGetObjectFromHandle;
131+
JsrtDiagEvaluate pfJsrtDiagEvaluate;
94132
};
95133

96134
class ChakraRTInterface
@@ -189,6 +227,7 @@ class ChakraRTInterface
189227
static JsErrorCode WINAPI JsGetExternalData(JsValueRef object, void **data) { return m_jsApiHooks.pfJsrtGetExternalData(object, data); }
190228
static JsErrorCode WINAPI JsCreateArray(unsigned int length, JsValueRef *result) { return m_jsApiHooks.pfJsrtCreateArray(length, result); }
191229
static JsErrorCode WINAPI JsCreateError(JsValueRef message, JsValueRef *error) { return m_jsApiHooks.pfJsrtCreateError(message, error); }
230+
static JsErrorCode WINAPI JsHasException(bool *hasException) { return m_jsApiHooks.pfJsrtHasException(hasException); }
192231
static JsErrorCode WINAPI JsSetException(JsValueRef exception) { return m_jsApiHooks.pfJsrtSetException(exception); }
193232
static JsErrorCode WINAPI JsGetAndClearException(JsValueRef *exception) { return m_jsApiHooks.pfJsrtGetAndClearException(exception); }
194233
static JsErrorCode WINAPI JsGetRuntime(JsContextRef context, JsRuntimeHandle *runtime) { return m_jsApiHooks.pfJsrtGetRuntime(context, runtime); }
@@ -200,4 +239,61 @@ class ChakraRTInterface
200239
static JsErrorCode WINAPI JsRunSerializedScript(const char16 *script, BYTE *buffer, DWORD_PTR sourceContext, const char16 *sourceUrl, JsValueRef* result) { return m_jsApiHooks.pfJsrtRunSerializedScript(script, buffer, sourceContext, sourceUrl, result); }
201240
static JsErrorCode WINAPI JsSetPromiseContinuationCallback(JsPromiseContinuationCallback callback, void *callbackState) { return m_jsApiHooks.pfJsrtSetPromiseContinuationCallback(callback, callbackState); }
202241
static JsErrorCode WINAPI JsGetContextOfObject(JsValueRef object, JsContextRef* context) { return m_jsApiHooks.pfJsrtGetContextOfObject(object, context); }
242+
static JsErrorCode WINAPI JsParseScriptWithAttributes(const wchar_t *script, JsSourceContext sourceContext, const wchar_t *sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result) { return m_jsApiHooks.pfJsrtParseScriptWithAttributes(script, sourceContext, sourceUrl, parseAttributes, result); }
243+
static JsErrorCode WINAPI JsDiagStartDebugging(JsRuntimeHandle runtimeHandle, JsDiagDebugEventCallback debugEventCallback, void* callbackState) { return m_jsApiHooks.pfJsrtDiagStartDebugging(runtimeHandle, debugEventCallback, callbackState); }
244+
static JsErrorCode WINAPI JsDiagStopDebugging(JsRuntimeHandle runtimeHandle, void** callbackState) { return m_jsApiHooks.pfJsrtDiagStopDebugging(runtimeHandle, callbackState); }
245+
static JsErrorCode WINAPI JsDiagGetSource(unsigned int scriptId, JsValueRef *source) { return m_jsApiHooks.pfJsrtDiagGetSource(scriptId, source); }
246+
static JsErrorCode WINAPI JsDiagSetBreakpoint(unsigned int scriptId, unsigned int lineNumber, unsigned int columnNumber, JsValueRef *breakpoint) { return m_jsApiHooks.pfJsrtDiagSetBreakpoint(scriptId, lineNumber, columnNumber, breakpoint); }
247+
static JsErrorCode WINAPI JsDiagGetStackTrace(JsValueRef *stackTrace) { return m_jsApiHooks.pfJsrtDiagGetStackTrace(stackTrace); }
248+
static JsErrorCode WINAPI JsDiagRequestAsyncBreak(JsRuntimeHandle runtimeHandle) { return m_jsApiHooks.pfJsrtDiagRequestAsyncBreak(runtimeHandle); }
249+
static JsErrorCode WINAPI JsDiagGetBreakpoints(JsValueRef * breakpoints) { return m_jsApiHooks.pfJsrtDiagGetBreakpoints(breakpoints); }
250+
static JsErrorCode WINAPI JsDiagRemoveBreakpoint(unsigned int breakpointId) { return m_jsApiHooks.pfJsrtDiagRemoveBreakpoint(breakpointId); }
251+
static JsErrorCode WINAPI JsDiagSetBreakOnException(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes exceptionAttributes) { return m_jsApiHooks.pfJsrtDiagSetBreakOnException(runtimeHandle, exceptionAttributes); }
252+
static JsErrorCode WINAPI JsDiagGetBreakOnException(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes * exceptionAttributes) { return m_jsApiHooks.pfJsrtDiagGetBreakOnException(runtimeHandle, exceptionAttributes); }
253+
static JsErrorCode WINAPI JsDiagSetStepType(JsDiagStepType stepType) { return m_jsApiHooks.pfJsrtDiagSetStepType(stepType); }
254+
static JsErrorCode WINAPI JsDiagGetScripts(JsValueRef * scriptsArray) { return m_jsApiHooks.pfJsrtDiagGetScripts(scriptsArray); }
255+
static JsErrorCode WINAPI JsDiagGetFunctionPosition(JsValueRef value, JsValueRef * functionPosition) { return m_jsApiHooks.pfJsrtDiagGetFunctionPosition(value, functionPosition); }
256+
static JsErrorCode WINAPI JsDiagGetStackProperties(unsigned int stackFrameIndex, JsValueRef * properties) { return m_jsApiHooks.pfJsrtDiagGetStackProperties(stackFrameIndex, properties); }
257+
static JsErrorCode WINAPI JsDiagGetProperties(unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject) { return m_jsApiHooks.pfJsrtDiagGetProperties(objectHandle, fromCount, totalCount, propertiesObject); }
258+
static JsErrorCode WINAPI JsDiagGetObjectFromHandle(unsigned int handle, JsValueRef * handleObject) { return m_jsApiHooks.pfJsrtDiagGetObjectFromHandle(handle, handleObject); }
259+
static JsErrorCode WINAPI JsDiagEvaluate(const wchar_t * expression, unsigned int stackFrameIndex, JsValueRef * evalResult) { return m_jsApiHooks.pfJsrtDiagEvaluate(expression, stackFrameIndex, evalResult); }
260+
static JsErrorCode WINAPI JsValueToWchar(JsValueRef value, const wchar_t **stringValue, size_t *length)
261+
{
262+
JsValueRef strValue;
263+
IfJsrtErrorFailLogAndRetErrorCode(ChakraRTInterface::JsConvertValueToString(value, &strValue));
264+
IfJsrtErrorFailLogAndRetErrorCode(ChakraRTInterface::JsStringToPointer(strValue, stringValue, length));
265+
return JsNoError;
266+
}
267+
};
268+
269+
class AutoRestoreContext
270+
{
271+
public:
272+
AutoRestoreContext(JsContextRef newContext)
273+
{
274+
JsErrorCode errorCode = ChakraRTInterface::JsGetCurrentContext(&oldContext);
275+
Assert(errorCode == JsNoError);
276+
277+
if (oldContext != newContext)
278+
{
279+
errorCode = ChakraRTInterface::JsSetCurrentContext(newContext);
280+
Assert(errorCode == JsNoError);
281+
contextChanged = true;
282+
}
283+
else
284+
{
285+
contextChanged = false;
286+
}
287+
}
288+
289+
~AutoRestoreContext()
290+
{
291+
if (contextChanged && oldContext != JS_INVALID_REFERENCE)
292+
{
293+
ChakraRTInterface::JsSetCurrentContext(oldContext);
294+
}
295+
}
296+
private:
297+
JsContextRef oldContext;
298+
bool contextChanged;
203299
};

0 commit comments

Comments
 (0)