ChakraDebug.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. /// \mainpage Chakra Hosting Debugging API Reference
  6. ///
  7. /// Chakra is Microsoft's JavaScript engine. It is an integral part of Internet Explorer but can
  8. /// also be hosted independently by other applications. This reference describes the APIs available
  9. /// to applications to debug JavaScript.
  10. /// \file
  11. /// \brief The Chakra hosting debugging API.
  12. ///
  13. /// This file contains a flat C API layer. This is the API exported by ChakraCore.dll.
  14. #ifdef _MSC_VER
  15. #pragma once
  16. #endif // _MSC_VER
  17. #ifndef _CHAKRADEBUG_H_
  18. #define _CHAKRADEBUG_H_
  19. #include "ChakraCommon.h"
  20. #ifdef _WIN32
  21. //Other platforms already include <stdint.h> and have this defined automatically
  22. typedef __int64 int64_t;
  23. typedef unsigned __int32 uint32_t;
  24. #endif
  25. /// <summary>
  26. /// Debug events reported from ChakraCore engine.
  27. /// </summary>
  28. typedef enum _JsDiagDebugEvent
  29. {
  30. /// <summary>
  31. /// Indicates a new script being compiled, this includes script, eval, new function.
  32. /// </summary>
  33. JsDiagDebugEventSourceCompile = 0,
  34. /// <summary>
  35. /// Indicates compile error for a script.
  36. /// </summary>
  37. JsDiagDebugEventCompileError = 1,
  38. /// <summary>
  39. /// Indicates a break due to a breakpoint.
  40. /// </summary>
  41. JsDiagDebugEventBreakpoint = 2,
  42. /// <summary>
  43. /// Indicates a break after completion of step action.
  44. /// </summary>
  45. JsDiagDebugEventStepComplete = 3,
  46. /// <summary>
  47. /// Indicates a break due to debugger statement.
  48. /// </summary>
  49. JsDiagDebugEventDebuggerStatement = 4,
  50. /// <summary>
  51. /// Indicates a break due to async break.
  52. /// </summary>
  53. JsDiagDebugEventAsyncBreak = 5,
  54. /// <summary>
  55. /// Indicates a break due to a runtime script exception.
  56. /// </summary>
  57. JsDiagDebugEventRuntimeException = 6
  58. } JsDiagDebugEvent;
  59. /// <summary>
  60. /// Break on Exception attributes.
  61. /// </summary>
  62. typedef enum _JsDiagBreakOnExceptionAttributes
  63. {
  64. /// <summary>
  65. /// Don't break on any exception.
  66. /// </summary>
  67. JsDiagBreakOnExceptionAttributeNone = 0x0,
  68. /// <summary>
  69. /// Break on uncaught exception.
  70. /// </summary>
  71. JsDiagBreakOnExceptionAttributeUncaught = 0x1,
  72. /// <summary>
  73. /// Break on first chance exception.
  74. /// </summary>
  75. JsDiagBreakOnExceptionAttributeFirstChance = 0x2
  76. } JsDiagBreakOnExceptionAttributes;
  77. /// <summary>
  78. /// Stepping types.
  79. /// </summary>
  80. typedef enum _JsDiagStepType
  81. {
  82. /// <summary>
  83. /// Perform a step operation to next statement.
  84. /// </summary>
  85. JsDiagStepTypeStepIn = 0,
  86. /// <summary>
  87. /// Perform a step out from the current function.
  88. /// </summary>
  89. JsDiagStepTypeStepOut = 1,
  90. /// <summary>
  91. /// Perform a single step over after a debug break if the next statement is a function call, else behaves as a stepin.
  92. /// </summary>
  93. JsDiagStepTypeStepOver = 2,
  94. /// <summary>
  95. /// Perform a single step back to the previous statement (only applicable in TTD mode).
  96. /// </summary>
  97. JsDiagStepTypeStepBack = 3,
  98. /// <summary>
  99. /// Perform a reverse continue operation (only applicable in TTD mode).
  100. /// </summary>
  101. JsDiagStepTypeReverseContinue = 4,
  102. /// <summary>
  103. /// Perform a forward continue operation. Clears any existing step value.
  104. /// </summary>
  105. JsDiagStepTypeContinue = 5
  106. } JsDiagStepType;
  107. /// <summary>
  108. /// User implemented callback routine for debug events.
  109. /// </summary>
  110. /// <remarks>
  111. /// Use <c>JsDiagStartDebugging</c> to register the callback.
  112. /// </remarks>
  113. /// <param name="debugEvent">The type of JsDiagDebugEvent event.</param>
  114. /// <param name="eventData">Additional data related to the debug event.</param>
  115. /// <param name="callbackState">The state passed to <c>JsDiagStartDebugging</c>.</param>
  116. typedef void (CHAKRA_CALLBACK * JsDiagDebugEventCallback)(_In_ JsDiagDebugEvent debugEvent, _In_ JsValueRef eventData, _In_opt_ void* callbackState);
  117. /// <summary>
  118. /// Starts debugging in the given runtime.
  119. /// </summary>
  120. /// <param name="runtimeHandle">Runtime to put into debug mode.</param>
  121. /// <param name="debugEventCallback">Registers a callback to be called on every JsDiagDebugEvent.</param>
  122. /// <param name="callbackState">User provided state that will be passed back to the callback.</param>
  123. /// <returns>
  124. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  125. /// </returns>
  126. /// <remarks>
  127. /// The runtime should be active on the current thread and should not be in debug state.
  128. /// </remarks>
  129. CHAKRA_API
  130. JsDiagStartDebugging(
  131. _In_ JsRuntimeHandle runtimeHandle,
  132. _In_ JsDiagDebugEventCallback debugEventCallback,
  133. _In_opt_ void* callbackState);
  134. /// <summary>
  135. /// Stops debugging in the given runtime.
  136. /// </summary>
  137. /// <param name="runtimeHandle">Runtime to stop debugging.</param>
  138. /// <param name="callbackState">User provided state that was passed in JsDiagStartDebugging.</param>
  139. /// <returns>
  140. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  141. /// </returns>
  142. /// <remarks>
  143. /// The runtime should be active on the current thread and in debug state.
  144. /// </remarks>
  145. CHAKRA_API
  146. JsDiagStopDebugging(
  147. _In_ JsRuntimeHandle runtimeHandle,
  148. _Out_ void** callbackState);
  149. /// <summary>
  150. /// Request the runtime to break on next JavaScript statement.
  151. /// </summary>
  152. /// <param name="runtimeHandle">Runtime to request break.</param>
  153. /// <returns>
  154. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  155. /// </returns>
  156. /// <remarks>
  157. /// The runtime should be in debug state. This API can be called from another runtime.
  158. /// </remarks>
  159. CHAKRA_API
  160. JsDiagRequestAsyncBreak(
  161. _In_ JsRuntimeHandle runtimeHandle);
  162. /// <summary>
  163. /// List all breakpoints in the current runtime.
  164. /// </summary>
  165. /// <param name="breakpoints">Array of breakpoints.</param>
  166. /// <remarks>
  167. /// <para>
  168. /// [{
  169. /// "breakpointId" : 1,
  170. /// "scriptId" : 1,
  171. /// "line" : 0,
  172. /// "column" : 62
  173. /// }]
  174. /// </para>
  175. /// </remarks>
  176. /// <returns>
  177. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  178. /// </returns>
  179. /// <remarks>
  180. /// The current runtime should be in debug state. This API can be called when runtime is at a break or running.
  181. /// </remarks>
  182. CHAKRA_API
  183. JsDiagGetBreakpoints(
  184. _Out_ JsValueRef *breakpoints);
  185. /// <summary>
  186. /// Sets breakpoint in the specified script at give location.
  187. /// </summary>
  188. /// <param name="scriptId">Id of script from JsDiagGetScripts or JsDiagGetSource to put breakpoint.</param>
  189. /// <param name="lineNumber">0 based line number to put breakpoint.</param>
  190. /// <param name="columnNumber">0 based column number to put breakpoint.</param>
  191. /// <param name="breakpoint">Breakpoint object with id, line and column if success.</param>
  192. /// <remarks>
  193. /// <para>
  194. /// {
  195. /// "breakpointId" : 1,
  196. /// "line" : 2,
  197. /// "column" : 4
  198. /// }
  199. /// </para>
  200. /// </remarks>
  201. /// <returns>
  202. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  203. /// </returns>
  204. /// <remarks>
  205. /// The current runtime should be in debug state. This API can be called when runtime is at a break or running.
  206. /// </remarks>
  207. CHAKRA_API
  208. JsDiagSetBreakpoint(
  209. _In_ unsigned int scriptId,
  210. _In_ unsigned int lineNumber,
  211. _In_ unsigned int columnNumber,
  212. _Out_ JsValueRef *breakpoint);
  213. /// <summary>
  214. /// Remove a breakpoint.
  215. /// </summary>
  216. /// <param name="breakpointId">Breakpoint id returned from JsDiagSetBreakpoint.</param>
  217. /// <returns>
  218. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  219. /// </returns>
  220. /// <remarks>
  221. /// The current runtime should be in debug state. This API can be called when runtime is at a break or running.
  222. /// </remarks>
  223. CHAKRA_API
  224. JsDiagRemoveBreakpoint(
  225. _In_ unsigned int breakpointId);
  226. /// <summary>
  227. /// Sets break on exception handling.
  228. /// </summary>
  229. /// <param name="runtimeHandle">Runtime to set break on exception attributes.</param>
  230. /// <param name="exceptionAttributes">Mask of JsDiagBreakOnExceptionAttributes to set.</param>
  231. /// <remarks>
  232. /// <para>
  233. /// If this API is not called the default value is set to JsDiagBreakOnExceptionAttributeUncaught in the runtime.
  234. /// </para>
  235. /// </remarks>
  236. /// <returns>
  237. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  238. /// </returns>
  239. /// <remarks>
  240. /// The runtime should be in debug state. This API can be called from another runtime.
  241. /// </remarks>
  242. CHAKRA_API
  243. JsDiagSetBreakOnException(
  244. _In_ JsRuntimeHandle runtimeHandle,
  245. _In_ JsDiagBreakOnExceptionAttributes exceptionAttributes);
  246. /// <summary>
  247. /// Gets break on exception setting.
  248. /// </summary>
  249. /// <param name="runtimeHandle">Runtime from which to get break on exception attributes, should be in debug mode.</param>
  250. /// <param name="exceptionAttributes">Mask of JsDiagBreakOnExceptionAttributes.</param>
  251. /// <returns>
  252. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  253. /// </returns>
  254. /// <remarks>
  255. /// The runtime should be in debug state. This API can be called from another runtime.
  256. /// </remarks>
  257. CHAKRA_API
  258. JsDiagGetBreakOnException(
  259. _In_ JsRuntimeHandle runtimeHandle,
  260. _Out_ JsDiagBreakOnExceptionAttributes* exceptionAttributes);
  261. /// <summary>
  262. /// Sets the step type in the runtime after a debug break.
  263. /// </summary>
  264. /// <remarks>
  265. /// Requires to be at a debug break.
  266. /// </remarks>
  267. /// <param name="resumeType">Type of JsDiagStepType.</param>
  268. /// <returns>
  269. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  270. /// </returns>
  271. /// <remarks>
  272. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  273. /// </remarks>
  274. CHAKRA_API
  275. JsDiagSetStepType(
  276. _In_ JsDiagStepType stepType);
  277. /// <summary>
  278. /// Gets list of scripts.
  279. /// </summary>
  280. /// <param name="scriptsArray">Array of script objects.</param>
  281. /// <remarks>
  282. /// <para>
  283. /// [{
  284. /// "scriptId" : 2,
  285. /// "fileName" : "c:\\Test\\Test.js",
  286. /// "lineCount" : 4,
  287. /// "sourceLength" : 111
  288. /// }, {
  289. /// "scriptId" : 3,
  290. /// "parentScriptId" : 2,
  291. /// "scriptType" : "eval code",
  292. /// "lineCount" : 1,
  293. /// "sourceLength" : 12
  294. /// }]
  295. /// </para>
  296. /// </remarks>
  297. /// <returns>
  298. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  299. /// </returns>
  300. /// <remarks>
  301. /// The current runtime should be in debug state. This API can be called when runtime is at a break or running.
  302. /// </remarks>
  303. CHAKRA_API
  304. JsDiagGetScripts(
  305. _Out_ JsValueRef *scriptsArray);
  306. /// <summary>
  307. /// Gets source for a specific script identified by scriptId from JsDiagGetScripts.
  308. /// </summary>
  309. /// <param name="scriptId">Id of the script.</param>
  310. /// <param name="source">Source object.</param>
  311. /// <remarks>
  312. /// <para>
  313. /// {
  314. /// "scriptId" : 1,
  315. /// "fileName" : "c:\\Test\\Test.js",
  316. /// "lineCount" : 12,
  317. /// "sourceLength" : 15154,
  318. /// "source" : "var x = 1;"
  319. /// }
  320. /// </para>
  321. /// </remarks>
  322. /// <returns>
  323. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  324. /// </returns>
  325. /// <remarks>
  326. /// The current runtime should be in debug state. This API can be called when runtime is at a break or running.
  327. /// </remarks>
  328. CHAKRA_API
  329. JsDiagGetSource(
  330. _In_ unsigned int scriptId,
  331. _Out_ JsValueRef *source);
  332. /// <summary>
  333. /// Gets the source information for a function object.
  334. /// </summary>
  335. /// <param name="function">JavaScript function.</param>
  336. /// <param name="functionPosition">Function position - scriptId, start line, start column, line number of first statement, column number of first statement.</param>
  337. /// <remarks>
  338. /// <para>
  339. /// {
  340. /// "scriptId" : 1,
  341. /// "fileName" : "c:\\Test\\Test.js",
  342. /// "line" : 1,
  343. /// "column" : 2,
  344. /// "firstStatementLine" : 6,
  345. /// "firstStatementColumn" : 0
  346. /// }
  347. /// </para>
  348. /// </remarks>
  349. /// <returns>
  350. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  351. /// </returns>
  352. /// <remarks>
  353. /// This API can be called when runtime is at a break or running.
  354. /// </remarks>
  355. CHAKRA_API
  356. JsDiagGetFunctionPosition(
  357. _In_ JsValueRef function,
  358. _Out_ JsValueRef *functionPosition);
  359. /// <summary>
  360. /// Gets the stack trace information.
  361. /// </summary>
  362. /// <param name="stackTrace">Stack trace information.</param>
  363. /// <remarks>
  364. /// <para>
  365. /// [{
  366. /// "index" : 0,
  367. /// "scriptId" : 2,
  368. /// "line" : 3,
  369. /// "column" : 0,
  370. /// "sourceLength" : 9,
  371. /// "sourceText" : "var x = 1",
  372. /// "functionHandle" : 1
  373. /// }]
  374. /// </para>
  375. /// </remarks>
  376. /// <returns>
  377. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  378. /// </returns>
  379. /// <remarks>
  380. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  381. /// </remarks>
  382. CHAKRA_API
  383. JsDiagGetStackTrace(
  384. _Out_ JsValueRef *stackTrace);
  385. /// <summary>
  386. /// Gets the list of properties corresponding to the frame.
  387. /// </summary>
  388. /// <param name="stackFrameIndex">Index of stack frame from JsDiagGetStackTrace.</param>
  389. /// <param name="properties">Object of properties array (properties, scopes and globals).</param>
  390. /// <remarks>
  391. /// <para>
  392. /// propertyAttributes is a bit mask of
  393. /// NONE = 0x1,
  394. /// HAVE_CHILDRENS = 0x2,
  395. /// READ_ONLY_VALUE = 0x4,
  396. /// </para>
  397. /// <para>
  398. /// {
  399. /// "thisObject": {
  400. /// "name": "this",
  401. /// "type" : "object",
  402. /// "className" : "Object",
  403. /// "display" : "{...}",
  404. /// "propertyAttributes" : 1,
  405. /// "handle" : 306
  406. /// },
  407. /// "exception" : {
  408. /// "name" : "{exception}",
  409. /// "type" : "object",
  410. /// "display" : "'a' is undefined",
  411. /// "className" : "Error",
  412. /// "propertyAttributes" : 1,
  413. /// "handle" : 307
  414. /// }
  415. /// "arguments" : {
  416. /// "name" : "arguments",
  417. /// "type" : "object",
  418. /// "display" : "{...}",
  419. /// "className" : "Object",
  420. /// "propertyAttributes" : 1,
  421. /// "handle" : 190
  422. /// },
  423. /// "returnValue" : {
  424. /// "name" : "[Return value]",
  425. /// "type" : "undefined",
  426. /// "propertyAttributes" : 0,
  427. /// "handle" : 192
  428. /// },
  429. /// "functionCallsReturn" : [{
  430. /// "name" : "[foo1 returned]",
  431. /// "type" : "number",
  432. /// "value" : 1,
  433. /// "propertyAttributes" : 2,
  434. /// "handle" : 191
  435. /// }
  436. /// ],
  437. /// "locals" : [],
  438. /// "scopes" : [{
  439. /// "index" : 0,
  440. /// "handle" : 193
  441. /// }
  442. /// ],
  443. /// "globals" : {
  444. /// "handle" : 194
  445. /// }
  446. /// }
  447. /// </para>
  448. /// </remarks>
  449. /// <returns>
  450. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  451. /// </returns>
  452. /// <remarks>
  453. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  454. /// </remarks>
  455. CHAKRA_API
  456. JsDiagGetStackProperties(
  457. _In_ unsigned int stackFrameIndex,
  458. _Out_ JsValueRef *properties);
  459. /// <summary>
  460. /// Gets the list of children of a handle.
  461. /// </summary>
  462. /// <param name="objectHandle">Handle of object.</param>
  463. /// <param name="fromCount">0-based from count of properties, usually 0.</param>
  464. /// <param name="totalCount">Number of properties to return.</param>
  465. /// <param name="propertiesObject">Array of properties.</param>
  466. /// <remarks>Handle should be from objects returned from call to JsDiagGetStackProperties.</remarks>
  467. /// <remarks>For scenarios where object have large number of properties totalCount can be used to control how many properties are given.</remarks>
  468. /// <remarks>
  469. /// <para>
  470. /// {
  471. /// "totalPropertiesOfObject": 10,
  472. /// "properties" : [{
  473. /// "name" : "__proto__",
  474. /// "type" : "object",
  475. /// "display" : "{...}",
  476. /// "className" : "Object",
  477. /// "propertyAttributes" : 1,
  478. /// "handle" : 156
  479. /// }
  480. /// ],
  481. /// "debuggerOnlyProperties" : [{
  482. /// "name" : "[Map]",
  483. /// "type" : "string",
  484. /// "value" : "size = 0",
  485. /// "propertyAttributes" : 2,
  486. /// "handle" : 157
  487. /// }
  488. /// ]
  489. /// }
  490. /// </para>
  491. /// </remarks>
  492. /// <returns>
  493. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  494. /// </returns>
  495. /// <remarks>
  496. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  497. /// </remarks>
  498. CHAKRA_API
  499. JsDiagGetProperties(
  500. _In_ unsigned int objectHandle,
  501. _In_ unsigned int fromCount,
  502. _In_ unsigned int totalCount,
  503. _Out_ JsValueRef *propertiesObject);
  504. /// <summary>
  505. /// Gets the object corresponding to handle.
  506. /// </summary>
  507. /// <param name="objectHandle">Handle of object.</param>
  508. /// <param name="handleObject">Object corresponding to the handle.</param>
  509. /// <remarks>
  510. /// <para>
  511. /// {
  512. /// "scriptId" : 24,
  513. /// "line" : 1,
  514. /// "column" : 63,
  515. /// "name" : "foo",
  516. /// "type" : "function",
  517. /// "handle" : 2
  518. /// }
  519. /// </para>
  520. /// </remarks>
  521. /// <returns>
  522. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  523. /// </returns>
  524. /// <remarks>
  525. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  526. /// </remarks>
  527. CHAKRA_API
  528. JsDiagGetObjectFromHandle(
  529. _In_ unsigned int objectHandle,
  530. _Out_ JsValueRef *handleObject);
  531. /// <summary>
  532. /// Evaluates an expression on given frame.
  533. /// </summary>
  534. /// <param name="expression">
  535. /// Javascript String or ArrayBuffer (incl. ExternalArrayBuffer).
  536. /// </param>
  537. /// <param name="stackFrameIndex">Index of stack frame on which to evaluate the expression.</param>
  538. /// <param name="parseAttributes">
  539. /// Defines how `expression` (JsValueRef) should be parsed.
  540. /// - `JsParseScriptAttributeNone` when `expression` is a Utf8 encoded ArrayBuffer and/or a Javascript String (encoding independent)
  541. /// - `JsParseScriptAttributeArrayBufferIsUtf16Encoded` when `expression` is Utf16 Encoded ArrayBuffer
  542. /// - `JsParseScriptAttributeLibraryCode` has no use for this function and has similar effect with `JsParseScriptAttributeNone`
  543. /// </param>
  544. /// <param name="forceSetValueProp">Forces the result to contain the raw value of the expression result.</param>
  545. /// <param name="evalResult">Result of evaluation.</param>
  546. /// <remarks>
  547. /// <para>
  548. /// evalResult when evaluating 'this' and return is JsNoError
  549. /// {
  550. /// "name" : "this",
  551. /// "type" : "object",
  552. /// "className" : "Object",
  553. /// "display" : "{...}",
  554. /// "propertyAttributes" : 1,
  555. /// "handle" : 18
  556. /// }
  557. ///
  558. /// evalResult when evaluating a script which throws JavaScript error and return is JsErrorScriptException
  559. /// {
  560. /// "name" : "a.b.c",
  561. /// "type" : "object",
  562. /// "className" : "Error",
  563. /// "display" : "'a' is undefined",
  564. /// "propertyAttributes" : 1,
  565. /// "handle" : 18
  566. /// }
  567. /// </para>
  568. /// </remarks>
  569. /// <returns>
  570. /// The code <c>JsNoError</c> if the operation succeeded, evalResult will contain the result
  571. /// The code <c>JsErrorScriptException</c> if evaluate generated a JavaScript exception, evalResult will contain the error details
  572. /// Other error code for invalid parameters or API was not called at break
  573. /// </returns>
  574. /// <remarks>
  575. /// The current runtime should be in debug state. This API can only be called when runtime is at a break.
  576. /// </remarks>
  577. CHAKRA_API
  578. JsDiagEvaluate(
  579. _In_ JsValueRef expression,
  580. _In_ unsigned int stackFrameIndex,
  581. _In_ JsParseScriptAttributes parseAttributes,
  582. _In_ bool forceSetValueProp,
  583. _Out_ JsValueRef *evalResult);
  584. /////////////////////
  585. /// <summary>
  586. /// TimeTravel move options as bit flag enum.
  587. /// </summary>
  588. typedef enum _JsTTDMoveModes
  589. {
  590. /// <summary>
  591. /// Indicates no special actions needed for move.
  592. /// </summary>
  593. JsTTDMoveNone = 0x0,
  594. /// <summary>
  595. /// Indicates that we want to move to the first event.
  596. /// </summary>
  597. JsTTDMoveFirstEvent = 0x1,
  598. /// <summary>
  599. /// Indicates that we want to move to the last event.
  600. /// </summary>
  601. JsTTDMoveLastEvent = 0x2,
  602. /// <summary>
  603. /// Indicates that we want to move to the kth event -- top 32 bits are event count.
  604. /// </summary>
  605. JsTTDMoveKthEvent = 0x4,
  606. /// <summary>
  607. /// Indicates if we are doing the scan for a continue operation
  608. /// </summary>
  609. JsTTDMoveScanIntervalForContinue = 0x10,
  610. /// <summary>
  611. /// Indicates if we are doing the scan for a continue operation and are in the time-segment where the active breakpoint was
  612. /// </summary>
  613. JsTTDMoveScanIntervalForContinueInActiveBreakpointSegment = 0x20,
  614. /// <summary>
  615. /// Indicates if we want to set break on entry or just run and let something else trigger breakpoints.
  616. /// </summary>
  617. JsTTDMoveBreakOnEntry = 0x100
  618. } JsTTDMoveMode;
  619. /// <summary>
  620. /// A handle for URI's that TTD information is written to/read from.
  621. /// </summary>
  622. typedef void* JsTTDStreamHandle;
  623. /// <summary>
  624. /// TTD API -- may change in future versions:
  625. /// Construct a JsTTDStreamHandle that will be used to read/write the event log portion of the TTD data based on the uri
  626. /// provided by JsTTDInitializeUriCallback.
  627. /// </summary>
  628. /// <remarks>
  629. /// <para>Exactly one of read or write will be set to true.</para>
  630. /// </remarks>
  631. /// <param name="uriLength">The length of the uri array that the host passed in for storing log info.</param>
  632. /// <param name="uri">The URI that the host passed in for storing log info.</param>
  633. /// <param name="asciiNameLength">The length of the ascii name array that the host passed in for storing log info.</param>
  634. /// <param name="asciiResourceName">An optional ascii string giving a unique name to the resource that the JsTTDStreamHandle will be created for.</param>
  635. /// <param name="read">If the handle should be opened for reading.</param>
  636. /// <param name="write">If the handle should be opened for writing.</param>
  637. /// <returns>A JsTTDStreamHandle opened in read/write mode as specified.</returns>
  638. typedef JsTTDStreamHandle (CHAKRA_CALLBACK *TTDOpenResourceStreamCallback)(_In_ size_t uriLength, _In_reads_(uriLength) const char* uri, _In_ size_t asciiNameLength, _In_reads_(asciiNameLength) const char* asciiResourceName, _In_ bool read, _In_ bool write);
  639. /// <summary>
  640. /// TTD API -- may change in future versions:
  641. /// A callback for reading data from a handle.
  642. /// </summary>
  643. /// <param name="handle">The JsTTDStreamHandle to read the data from.</param>
  644. /// <param name="buff">The buffer to place the data into.</param>
  645. /// <param name="size">The max number of bytes that should be read.</param>
  646. /// <param name="readCount">The actual number of bytes read and placed in the buffer.</param>
  647. /// <returns>true if the read was successful false otherwise.</returns>
  648. typedef bool (CHAKRA_CALLBACK *JsTTDReadBytesFromStreamCallback)(_In_ JsTTDStreamHandle handle, _Out_writes_(size) byte* buff, _In_ size_t size, _Out_ size_t* readCount);
  649. /// <summary>
  650. /// TTD API -- may change in future versions:
  651. /// A callback for writing data to a handle.
  652. /// </summary>
  653. /// <param name="handle">The JsTTDStreamHandle to write the data to.</param>
  654. /// <param name="buff">The buffer to copy the data from.</param>
  655. /// <param name="size">The max number of bytes that should be written.</param>
  656. /// <param name="readCount">The actual number of bytes written to the HANDLE.</param>
  657. /// <returns>true if the write was successful false otherwise.</returns>
  658. typedef bool (CHAKRA_CALLBACK *JsTTDWriteBytesToStreamCallback)(_In_ JsTTDStreamHandle handle, _In_reads_(size) const byte* buff, _In_ size_t size, _Out_ size_t* writtenCount);
  659. /// <summary>
  660. /// TTD API -- may change in future versions:
  661. /// Flush and close the stream represented by the HANDLE as needed.
  662. /// </summary>
  663. /// <remarks>
  664. /// <para>Exactly one of read or write will be set to true.</para>
  665. /// </remarks>
  666. /// <param name="handle">The JsTTDStreamHandle to close.</param>
  667. /// <param name="read">If the handle was opened for reading.</param>
  668. /// <param name="write">If the handle was opened for writing.</param>
  669. typedef void (CHAKRA_CALLBACK *JsTTDFlushAndCloseStreamCallback)(_In_ JsTTDStreamHandle handle, _In_ bool read, _In_ bool write);
  670. /// <summary>
  671. /// TTD API -- may change in future versions:
  672. /// Creates a new runtime in Record Mode.
  673. /// </summary>
  674. /// <param name="attributes">The attributes of the runtime to be created.</param>
  675. /// <param name="snapInterval">The interval to wait between snapshots (measured in millis).</param>
  676. /// <param name="snapHistoryLength">The amount of history to maintain before discarding -- measured in number of snapshots and controls how far back in time a trace can be reversed.</param>
  677. /// <param name="openResourceStream">The <c>TTDOpenResourceStreamCallback</c> function for generating a JsTTDStreamHandle to read/write serialized data.</param>
  678. /// <param name="writeBytesToStream">The <c>JsTTDWriteBytesToStreamCallback</c> function for writing bytes to a JsTTDStreamHandle.</param>
  679. /// <param name="flushAndCloseStream">The <c>JsTTDFlushAndCloseStreamCallback</c> function for flushing and closing a JsTTDStreamHandle as needed.</param>
  680. /// <param name="threadService">The thread service for the runtime. Can be null.</param>
  681. /// <param name="runtime">The runtime created.</param>
  682. /// <remarks>
  683. /// <para>See <c>JsCreateRuntime</c> for additional information.</para>
  684. /// </remarks>
  685. /// <returns>
  686. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  687. /// </returns>
  688. CHAKRA_API
  689. JsTTDCreateRecordRuntime(
  690. _In_ JsRuntimeAttributes attributes,
  691. _In_ size_t snapInterval,
  692. _In_ size_t snapHistoryLength,
  693. _In_ TTDOpenResourceStreamCallback openResourceStream,
  694. _In_ JsTTDWriteBytesToStreamCallback writeBytesToStream,
  695. _In_ JsTTDFlushAndCloseStreamCallback flushAndCloseStream,
  696. _In_opt_ JsThreadServiceCallback threadService,
  697. _Out_ JsRuntimeHandle *runtime);
  698. /// <summary>
  699. /// TTD API -- may change in future versions:
  700. /// Creates a new runtime in Debug Mode.
  701. /// </summary>
  702. /// <param name="attributes">The attributes of the runtime to be created.</param>
  703. /// <param name="infoUri">The uri where the recorded Time-Travel data should be loaded from.</param>
  704. /// <param name="enableDebugging">A flag to enable addtional debugging operation support during replay.</param>
  705. /// <param name="openResourceStream">The <c>TTDOpenResourceStreamCallback</c> function for generating a JsTTDStreamHandle to read/write serialized data.</param>
  706. /// <param name="readBytesFromStream">The <c>JsTTDReadBytesFromStreamCallback</c> function for reading bytes from a JsTTDStreamHandle.</param>
  707. /// <param name="flushAndCloseStream">The <c>JsTTDFlushAndCloseStreamCallback</c> function for flushing and closing a JsTTDStreamHandle as needed.</param>
  708. /// <param name="threadService">The thread service for the runtime. Can be null.</param>
  709. /// <param name="runtime">The runtime created.</param>
  710. /// <remarks>
  711. /// <para>See <c>JsCreateRuntime</c> for additional information.</para>
  712. /// </remarks>
  713. /// <returns>
  714. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  715. /// </returns>
  716. CHAKRA_API
  717. JsTTDCreateReplayRuntime(
  718. _In_ JsRuntimeAttributes attributes,
  719. _In_reads_(infoUriCount) const char* infoUri,
  720. _In_ size_t infoUriCount,
  721. _In_ bool enableDebugging,
  722. _In_ TTDOpenResourceStreamCallback openResourceStream,
  723. _In_ JsTTDReadBytesFromStreamCallback readBytesFromStream,
  724. _In_ JsTTDFlushAndCloseStreamCallback flushAndCloseStream,
  725. _In_opt_ JsThreadServiceCallback threadService,
  726. _Out_ JsRuntimeHandle *runtime);
  727. /// <summary>
  728. /// TTD API -- may change in future versions:
  729. /// Creates a script context that takes the TTD mode from the log or explicitly is not in TTD mode (regular takes mode from currently active script).
  730. /// </summary>
  731. /// <param name="runtime">The runtime the script context is being created in.</param>
  732. /// <param name="useRuntimeTTDMode">Set to true to use runtime TTD mode false to explicitly be non-TTD context.</param>
  733. /// <param name="newContext">The created script context.</param>
  734. /// <returns>
  735. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  736. /// </returns>
  737. CHAKRA_API JsTTDCreateContext(
  738. _In_ JsRuntimeHandle runtimeHandle,
  739. _In_ bool useRuntimeTTDMode,
  740. _Out_ JsContextRef *newContext);
  741. /// <summary>
  742. /// TTD API -- may change in future versions:
  743. /// Notify the time-travel system that a context has been identified as dead by the gc (and is being de-allocated).
  744. /// </summary>
  745. /// <param name="context">The script context that is now dead.</param>
  746. /// <returns>
  747. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  748. /// </returns>
  749. CHAKRA_API JsTTDNotifyContextDestroy(
  750. _In_ JsContextRef context);
  751. /// <summary>
  752. /// TTD API -- may change in future versions:
  753. /// Start Time-Travel record or replay at next turn of event loop.
  754. /// </summary>
  755. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  756. CHAKRA_API
  757. JsTTDStart();
  758. /// <summary>
  759. /// TTD API -- may change in future versions:
  760. /// Stop Time-Travel record or replay.
  761. /// </summary>
  762. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  763. CHAKRA_API
  764. JsTTDStop();
  765. /// <summary>
  766. /// TTD API -- may change in future versions:
  767. /// Pause Time-Travel recording before executing code on behalf of debugger or other diagnostic/telemetry.
  768. /// </summary>
  769. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  770. CHAKRA_API
  771. JsTTDPauseTimeTravelBeforeRuntimeOperation();
  772. /// <summary>
  773. /// TTD API -- may change in future versions:
  774. /// ReStart Time-Travel recording after executing code on behalf of debugger or other diagnostic/telemetry.
  775. /// </summary>
  776. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  777. CHAKRA_API
  778. JsTTDReStartTimeTravelAfterRuntimeOperation();
  779. /// <summary>
  780. /// TTD API -- may change in future versions:
  781. /// Notify the Js runtime we are at a safe yield point in the event loop (i.e. no locals on the stack and we can proccess as desired).
  782. /// </summary>
  783. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  784. CHAKRA_API
  785. JsTTDNotifyYield();
  786. /// <summary>
  787. /// TTD API -- may change in future versions:
  788. /// Notify the TTD runtime that we are doing a weak add on a reference (we may use this in external API calls and the release will happen in a GC callback).
  789. /// </summary>
  790. /// <param name="value">The value we are adding the ref to.</param>
  791. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  792. CHAKRA_API
  793. JsTTDNotifyLongLivedReferenceAdd(_In_ JsValueRef value);
  794. /// <summary>
  795. /// TTD API -- may change in future versions:
  796. /// Notify the Js runtime the host is aborting the process and what the status code is.
  797. /// </summary>
  798. /// <param name="statusCode">The exit status code.</param>
  799. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  800. CHAKRA_API
  801. JsTTDHostExit(_In_ int statusCode);
  802. /// <summary>
  803. /// TTD API -- may change in future versions:
  804. /// Notify the event log that the contents of one buffer have been copied to a second buffer.
  805. /// </summary>
  806. /// <param name="dst">The buffer that was written into.</param>
  807. /// <param name="dstIndex">The first index modified.</param>
  808. /// <param name="src">The buffer that was copied from.</param>
  809. /// <param name="srcIndex">The first index copied.</param>
  810. /// <param name="count">The number of bytes copied.</param>
  811. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  812. CHAKRA_API
  813. JsTTDRawBufferCopySyncIndirect(
  814. _In_ JsValueRef dst,
  815. _In_ size_t dstIndex,
  816. _In_ JsValueRef src,
  817. _In_ size_t srcIndex,
  818. _In_ size_t count);
  819. /// <summary>
  820. /// TTD API -- may change in future versions:
  821. /// Notify the event log that the contents of a naked byte* buffer passed to the host have been modified synchronously.
  822. /// </summary>
  823. /// <param name="buffer">The buffer that was modified.</param>
  824. /// <param name="index">The first index modified.</param>
  825. /// <param name="count">The number of bytes written.</param>
  826. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  827. CHAKRA_API
  828. JsTTDRawBufferModifySyncIndirect(
  829. _In_ JsValueRef buffer,
  830. _In_ size_t index,
  831. _In_ size_t count);
  832. /// <summary>
  833. /// TTD API -- may change in future versions:
  834. /// Get info for notifying the TTD system that a raw buffer it shares with the host has been modified.
  835. /// </summary>
  836. /// <param name="instance">The array buffer we want to monitor for contents modification.</param>
  837. /// <param name="initialModPos">The first position in the buffer that may be modified.</param>
  838. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  839. CHAKRA_API
  840. JsTTDRawBufferAsyncModificationRegister(
  841. _In_ JsValueRef instance,
  842. _In_ byte* initialModPos);
  843. /// <summary>
  844. /// TTD API -- may change in future versions:
  845. /// Notify the event log that the contents of a naked byte* buffer passed to the host have been modified asynchronously.
  846. /// </summary>
  847. /// <param name="finalModPos">One past the last modified position in the buffer.</param>
  848. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  849. CHAKRA_API
  850. JsTTDRawBufferAsyncModifyComplete(
  851. _In_ byte* finalModPos);
  852. /// <summary>
  853. /// TTD API -- may change in future versions:
  854. /// A check for unimplmented TTD actions in the host.
  855. /// This API is a TEMPORARY API while we complete the implementation of TTD support in the Node host and will be deleted once that is complete.
  856. /// </summary>
  857. /// <param name="msg">The message to print if we should be catching this as a TTD operation.</param>
  858. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  859. CHAKRA_API
  860. JsTTDCheckAndAssertIfTTDRunning(
  861. _In_ const char* msg);
  862. /// <summary>
  863. /// TTD API -- may change in future versions:
  864. /// Before calling JsTTDMoveToTopLevelEvent (which inflates a snapshot and replays) check to see if we want to reset the script context.
  865. /// We reset the script context if the move will require inflating from a different snapshot that the last one.
  866. /// </summary>
  867. /// <param name="runtimeHandle">The runtime handle that the script is executing in.</param>
  868. /// <param name="moveMode">Flags controlling the way the move it performed and how other parameters are interpreted.</param>
  869. /// <param name="kthEvent">When <c>moveMode == JsTTDMoveKthEvent</c> indicates which event, otherwise this parameter is ignored.</param>
  870. /// <param name="targetEventTime">The event time we want to move to or -1 if not relevant.</param>
  871. /// <param name="targetStartSnapTime">Out parameter with the event time of the snapshot that we should inflate from.</param>
  872. /// <param name="targetEndSnapTime">Optional Out parameter with the snapshot time following the event.</param>
  873. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  874. CHAKRA_API JsTTDGetSnapTimeTopLevelEventMove(
  875. _In_ JsRuntimeHandle runtimeHandle,
  876. _In_ JsTTDMoveMode moveMode,
  877. _In_opt_ uint32_t kthEvent,
  878. _Inout_ int64_t* targetEventTime,
  879. _Out_ int64_t* targetStartSnapTime,
  880. _Out_opt_ int64_t* targetEndSnapTime);
  881. /// <summary>
  882. /// TTD API -- may change in future versions:
  883. /// Get the snapshot interval that bounds the target event time.
  884. /// </summary>
  885. /// <param name="runtimeHandle">The runtime handle that the script is executing in.</param>
  886. /// <param name="targetEventTime">The event time we want to get the interval for.</param>
  887. /// <param name="startSnapTime">The snapshot time that comes before the desired event.</param>
  888. /// <param name="endSnapTime">The snapshot time that comes after the desired event (-1 if the leg ends before a snapshot appears).</param>
  889. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  890. CHAKRA_API JsTTDGetSnapShotBoundInterval(
  891. _In_ JsRuntimeHandle runtimeHandle,
  892. _In_ int64_t targetEventTime,
  893. _Out_ int64_t* startSnapTime,
  894. _Out_ int64_t* endSnapTime);
  895. /// <summary>
  896. /// TTD API -- may change in future versions:
  897. /// Get the snapshot interval that precedes the one given by currentSnapStartTime (or -1 if there is no such interval).
  898. /// </summary>
  899. /// <param name="runtimeHandle">The runtime handle that the script is executing in.</param>
  900. /// <param name="currentSnapStartTime">The current snapshot interval start time.</param>
  901. /// <param name="previousSnapTime">The resulting previous snapshot interval start time or -1 if no such time.</param>
  902. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  903. CHAKRA_API JsTTDGetPreviousSnapshotInterval(
  904. _In_ JsRuntimeHandle runtimeHandle,
  905. _In_ int64_t currentSnapStartTime,
  906. _Out_ int64_t* previousSnapTime);
  907. /// <summary>
  908. /// TTD API -- may change in future versions:
  909. /// During debug operations some additional information is populated during replay. This runs the code between the given
  910. /// snapshots to poulate this information which may be needed by the debugger to determine time-travel jump targets.
  911. /// </summary>
  912. /// <param name="runtimeHandle">The runtime handle that the script is executing in.</param>
  913. ///<param name = "startSnapTime">The snapshot time that we will start executing from.< / param>
  914. ///<param name = "endSnapTime">The snapshot time that we will stop at (or -1 if we want to run to the end).< / param>
  915. /// <param name="moveMode">Additional flags for controling how the move is done.</param>
  916. /// <param name="newTargetEventTime">The updated target event time set according to the moveMode (-1 if not found).</param>
  917. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  918. CHAKRA_API JsTTDPreExecuteSnapShotInterval(
  919. _In_ JsRuntimeHandle runtimeHandle,
  920. _In_ int64_t startSnapTime,
  921. _In_ int64_t endSnapTime,
  922. _In_ JsTTDMoveMode moveMode,
  923. _Out_ int64_t* newTargetEventTime);
  924. /// <summary>
  925. /// TTD API -- may change in future versions:
  926. /// Move to the given top-level call event time (assuming JsTTDPrepContextsForTopLevelEventMove) was called previously to reset any script contexts.
  927. /// This also computes the ready-to-run snapshot if needed.
  928. /// </summary>
  929. /// <param name="runtimeHandle">The runtime handle that the script is executing in.</param>
  930. /// <param name="moveMode">Additional flags for controling how the move is done.</param>
  931. /// <param name="snapshotTime">The event time that we will start executing from to move to the given target time.</param>
  932. /// <param name="eventTime">The event that we want to move to.</param>
  933. /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
  934. CHAKRA_API
  935. JsTTDMoveToTopLevelEvent(
  936. _In_ JsRuntimeHandle runtimeHandle,
  937. _In_ JsTTDMoveMode moveMode,
  938. _In_ int64_t snapshotTime,
  939. _In_ int64_t eventTime);
  940. /// <summary>
  941. /// TTD API -- may change in future versions:
  942. /// Execute from the current point in the log to the end returning the error code.
  943. /// </summary>
  944. /// <param name="moveMode">Additional flags for controling how the move is done.</param>
  945. /// <param name="rootEventTime">The event time that we should move to next or notification (-1) that replay has ended.</param>
  946. /// <returns>
  947. /// If the debugger requested an abort the code is JsNoError -- rootEventTime is the target event time we need to move to and re - execute from.
  948. /// If we aborted at the end of the replay log the code is JsNoError -- rootEventTime is -1.
  949. /// If there was an unhandled script exception the code is JsErrorCategoryScript.
  950. /// </returns>
  951. CHAKRA_API
  952. JsTTDReplayExecution(
  953. _Inout_ JsTTDMoveMode* moveMode,
  954. _Out_ int64_t* rootEventTime);
  955. #endif // _CHAKRADEBUG_H_