• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef FOUNDATION_ACE_THIRD_PARTY_QUICKJS_DEBUGGER_H
24 #define FOUNDATION_ACE_THIRD_PARTY_QUICKJS_DEBUGGER_H
25 
26 #include "quickjs.h"
27 
28 #include <time.h>
29 
30 #include "hilog/log.h"
31 #include "securec.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define JS_DEBUGGER_HOST_ADDRESS "127.0.0.1"
38 #define JS_DEBUGGER_PORT_NUM 5555
39 #define STR_BUF_SIZE 64
40 #define READ_MSG_HEX_NUM 16
41 #define READ_MSG_LEN 9
42 #define WRITE_MSG_LEN 10
43 #define WRITE_MSG_ADD_NEW_LINE 2
44 #define FRAME_MOVE_TWO_STEP 2
45 #define STACK_DEPTH_MOVE_TWO_STEP 2
46 #define TYPE_OF_SCOPE_NUM 4
47 #define MAX_STR_LEN 20
48 #define FAIL_CAUSE_SOCKET_NO_CLIENT (-1003)
49 #define FAIL_CAUSE_SOCKET_COMMON_FAIL (-1004)
50 #define FAIL_CAUSE_READ_MSG_FAIL (-1005)
51 #define JS_SOCKET_SUCCESS 1
52 #define DBG_NEED_READ_MSG 1
53 #define DBG_NO_NEED_READ_MSG 0
54 #define DBG_LOC_ISEQUAL 1
55 #define DBG_LOC_ISNOTEQUAL 0
56 #define DBG_WAITING_TIME 100
57 
58 #undef LOG_DOMAIN
59 #undef LOG_TAG
60 #define LOG_DOMAIN 0xD003F01
61 #define LOG_TAG "DebuggerLogger"
62 
63 #define DEBUGGER_LOGI(...) HILOG_INFO(LOG_CORE, __VA_ARGS__)
64 #define DEBUGGER_LOGE(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__)
65 
66 enum StepOperaton {
67     NO_STEP_OPERATION = 0,
68     STEP_NEXT = 1,
69     STEP_IN = 2,
70     STEP_OUT = 3,
71     STEP_CONTINUE = 4
72 };
73 
74 enum ScopeType {
75     GLOBAL = 0,
76     LOCAL = 1,
77     CLOSURE = 2
78 };
79 
80 typedef struct LocInfo {
81     JSAtom filename;
82     int line;
83 } LocInfo;
84 
85 typedef struct DebuggerInfo {
86     JSContext *cx;
87     volatile int client;
88     int stepOperation;
89     uint32_t depth;
90     LocInfo loc;
91     JSValue breakpoints;
92     int buildConnect;
93     volatile int isConnected;
94 } DebuggerInfo;
95 
96 typedef struct DebuggerVariableState {
97     uint32_t variableReferenceCount;
98     JSValue variableReferences;
99     JSValue variablePointers;
100     const uint8_t *curPc;
101 } DebuggerVariableState;
102 
103 DebuggerInfo *JS_GetDebuggerInfo(JSContext *cx);
104 JSValue JS_BuildStackTrace(JSContext *cx, const uint8_t *curPc);
105 uint32_t JS_GetStackDepth(const JSContext *ctx);
106 LocInfo JS_GetCurrentLocation(JSContext *ctx, const uint8_t *pc);
107 JSValue JS_DebuggerEvaluate(JSContext *ctx, int stackIndex, JSValue expression);
108 void DBG_FreeSources(JSContext *cx, DebuggerInfo *debuggerInfo);
109 void DBG_CallDebugger(JSContext *cx, const uint8_t *pc);
110 uint32_t DBG_GetValueAsUint32Type(JSContext *cx, JSValue obj, const char *property);
111 void DBG_SetDebugMode(bool isAttachMode);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 #endif
117