11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef INCLUDE_V8_DEBUG_H_ 61cb0ef41Sopenharmony_ci#define INCLUDE_V8_DEBUG_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <stdint.h> 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "v8-script.h" // NOLINT(build/include_directory) 111cb0ef41Sopenharmony_ci#include "v8config.h" // NOLINT(build/include_directory) 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinamespace v8 { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciclass Isolate; 161cb0ef41Sopenharmony_ciclass String; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci/** 191cb0ef41Sopenharmony_ci * A single JavaScript stack frame. 201cb0ef41Sopenharmony_ci */ 211cb0ef41Sopenharmony_ciclass V8_EXPORT StackFrame { 221cb0ef41Sopenharmony_ci public: 231cb0ef41Sopenharmony_ci /** 241cb0ef41Sopenharmony_ci * Returns the source location, 0-based, for the associated function call. 251cb0ef41Sopenharmony_ci */ 261cb0ef41Sopenharmony_ci Location GetLocation() const; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci /** 291cb0ef41Sopenharmony_ci * Returns the number, 1-based, of the line for the associate function call. 301cb0ef41Sopenharmony_ci * This method will return Message::kNoLineNumberInfo if it is unable to 311cb0ef41Sopenharmony_ci * retrieve the line number, or if kLineNumber was not passed as an option 321cb0ef41Sopenharmony_ci * when capturing the StackTrace. 331cb0ef41Sopenharmony_ci */ 341cb0ef41Sopenharmony_ci int GetLineNumber() const { return GetLocation().GetLineNumber() + 1; } 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci /** 371cb0ef41Sopenharmony_ci * Returns the 1-based column offset on the line for the associated function 381cb0ef41Sopenharmony_ci * call. 391cb0ef41Sopenharmony_ci * This method will return Message::kNoColumnInfo if it is unable to retrieve 401cb0ef41Sopenharmony_ci * the column number, or if kColumnOffset was not passed as an option when 411cb0ef41Sopenharmony_ci * capturing the StackTrace. 421cb0ef41Sopenharmony_ci */ 431cb0ef41Sopenharmony_ci int GetColumn() const { return GetLocation().GetColumnNumber() + 1; } 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci /** 461cb0ef41Sopenharmony_ci * Returns the id of the script for the function for this StackFrame. 471cb0ef41Sopenharmony_ci * This method will return Message::kNoScriptIdInfo if it is unable to 481cb0ef41Sopenharmony_ci * retrieve the script id, or if kScriptId was not passed as an option when 491cb0ef41Sopenharmony_ci * capturing the StackTrace. 501cb0ef41Sopenharmony_ci */ 511cb0ef41Sopenharmony_ci int GetScriptId() const; 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci /** 541cb0ef41Sopenharmony_ci * Returns the name of the resource that contains the script for the 551cb0ef41Sopenharmony_ci * function for this StackFrame. 561cb0ef41Sopenharmony_ci */ 571cb0ef41Sopenharmony_ci Local<String> GetScriptName() const; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci /** 601cb0ef41Sopenharmony_ci * Returns the name of the resource that contains the script for the 611cb0ef41Sopenharmony_ci * function for this StackFrame or sourceURL value if the script name 621cb0ef41Sopenharmony_ci * is undefined and its source ends with //# sourceURL=... string or 631cb0ef41Sopenharmony_ci * deprecated //@ sourceURL=... string. 641cb0ef41Sopenharmony_ci */ 651cb0ef41Sopenharmony_ci Local<String> GetScriptNameOrSourceURL() const; 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci /** 681cb0ef41Sopenharmony_ci * Returns the source of the script for the function for this StackFrame. 691cb0ef41Sopenharmony_ci */ 701cb0ef41Sopenharmony_ci Local<String> GetScriptSource() const; 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci /** 731cb0ef41Sopenharmony_ci * Returns the source mapping URL (if one is present) of the script for 741cb0ef41Sopenharmony_ci * the function for this StackFrame. 751cb0ef41Sopenharmony_ci */ 761cb0ef41Sopenharmony_ci Local<String> GetScriptSourceMappingURL() const; 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci /** 791cb0ef41Sopenharmony_ci * Returns the name of the function associated with this stack frame. 801cb0ef41Sopenharmony_ci */ 811cb0ef41Sopenharmony_ci Local<String> GetFunctionName() const; 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci /** 841cb0ef41Sopenharmony_ci * Returns whether or not the associated function is compiled via a call to 851cb0ef41Sopenharmony_ci * eval(). 861cb0ef41Sopenharmony_ci */ 871cb0ef41Sopenharmony_ci bool IsEval() const; 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci /** 901cb0ef41Sopenharmony_ci * Returns whether or not the associated function is called as a 911cb0ef41Sopenharmony_ci * constructor via "new". 921cb0ef41Sopenharmony_ci */ 931cb0ef41Sopenharmony_ci bool IsConstructor() const; 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci /** 961cb0ef41Sopenharmony_ci * Returns whether or not the associated functions is defined in wasm. 971cb0ef41Sopenharmony_ci */ 981cb0ef41Sopenharmony_ci bool IsWasm() const; 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci /** 1011cb0ef41Sopenharmony_ci * Returns whether or not the associated function is defined by the user. 1021cb0ef41Sopenharmony_ci */ 1031cb0ef41Sopenharmony_ci bool IsUserJavaScript() const; 1041cb0ef41Sopenharmony_ci}; 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci/** 1071cb0ef41Sopenharmony_ci * Representation of a JavaScript stack trace. The information collected is a 1081cb0ef41Sopenharmony_ci * snapshot of the execution stack and the information remains valid after 1091cb0ef41Sopenharmony_ci * execution continues. 1101cb0ef41Sopenharmony_ci */ 1111cb0ef41Sopenharmony_ciclass V8_EXPORT StackTrace { 1121cb0ef41Sopenharmony_ci public: 1131cb0ef41Sopenharmony_ci /** 1141cb0ef41Sopenharmony_ci * Flags that determine what information is placed captured for each 1151cb0ef41Sopenharmony_ci * StackFrame when grabbing the current stack trace. 1161cb0ef41Sopenharmony_ci * Note: these options are deprecated and we always collect all available 1171cb0ef41Sopenharmony_ci * information (kDetailed). 1181cb0ef41Sopenharmony_ci */ 1191cb0ef41Sopenharmony_ci enum StackTraceOptions { 1201cb0ef41Sopenharmony_ci kLineNumber = 1, 1211cb0ef41Sopenharmony_ci kColumnOffset = 1 << 1 | kLineNumber, 1221cb0ef41Sopenharmony_ci kScriptName = 1 << 2, 1231cb0ef41Sopenharmony_ci kFunctionName = 1 << 3, 1241cb0ef41Sopenharmony_ci kIsEval = 1 << 4, 1251cb0ef41Sopenharmony_ci kIsConstructor = 1 << 5, 1261cb0ef41Sopenharmony_ci kScriptNameOrSourceURL = 1 << 6, 1271cb0ef41Sopenharmony_ci kScriptId = 1 << 7, 1281cb0ef41Sopenharmony_ci kExposeFramesAcrossSecurityOrigins = 1 << 8, 1291cb0ef41Sopenharmony_ci kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, 1301cb0ef41Sopenharmony_ci kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL 1311cb0ef41Sopenharmony_ci }; 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci /** 1341cb0ef41Sopenharmony_ci * Returns a StackFrame at a particular index. 1351cb0ef41Sopenharmony_ci */ 1361cb0ef41Sopenharmony_ci Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const; 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci /** 1391cb0ef41Sopenharmony_ci * Returns the number of StackFrames. 1401cb0ef41Sopenharmony_ci */ 1411cb0ef41Sopenharmony_ci int GetFrameCount() const; 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci /** 1441cb0ef41Sopenharmony_ci * Grab a snapshot of the current JavaScript execution stack. 1451cb0ef41Sopenharmony_ci * 1461cb0ef41Sopenharmony_ci * \param frame_limit The maximum number of stack frames we want to capture. 1471cb0ef41Sopenharmony_ci * \param options Enumerates the set of things we will capture for each 1481cb0ef41Sopenharmony_ci * StackFrame. 1491cb0ef41Sopenharmony_ci */ 1501cb0ef41Sopenharmony_ci static Local<StackTrace> CurrentStackTrace( 1511cb0ef41Sopenharmony_ci Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed); 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ci /** 1541cb0ef41Sopenharmony_ci * Returns the first valid script name or source URL starting at the top of 1551cb0ef41Sopenharmony_ci * the JS stack. The returned string is either an empty handle if no script 1561cb0ef41Sopenharmony_ci * name/url was found or a non-zero-length string. 1571cb0ef41Sopenharmony_ci * 1581cb0ef41Sopenharmony_ci * This method is equivalent to calling StackTrace::CurrentStackTrace and 1591cb0ef41Sopenharmony_ci * walking the resulting frames from the beginning until a non-empty script 1601cb0ef41Sopenharmony_ci * name/url is found. The difference is that this method won't allocate 1611cb0ef41Sopenharmony_ci * a stack trace. 1621cb0ef41Sopenharmony_ci */ 1631cb0ef41Sopenharmony_ci static Local<String> CurrentScriptNameOrSourceURL(Isolate* isolate); 1641cb0ef41Sopenharmony_ci}; 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci} // namespace v8 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci#endif // INCLUDE_V8_DEBUG_H_ 169