Debugging method and device
By injecting a debugger module and single-step debugging functionality into the JavaScript engine of an embedded device, and combining this with the DevTools communication protocol, the issues of convenience and real-time performance in debugging JavaScript code on embedded devices are resolved, enabling JavaScript code debugging and program status viewing on embedded devices.
Patent Information
- Application Number
- CN202210286721.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-22
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2042-03-22
AI Technical Summary
Existing technologies cannot conveniently and effectively debug JavaScript code on embedded devices, nor can they monitor the program's running status in real time.
Inject a debugger module and single-step debugging functionality into the JavaScript engine of the embedded device, and configure a communication protocol with the debugging tool DevTools. Through the communication protocol, single-step debugging on a real device can be performed without modifying the JavaScript code, and breakpoints can be inserted and stack frame information can be captured.
It enables convenient and effective JavaScript code debugging and real-time monitoring of program running status on embedded devices, improving debugging efficiency.
Smart Images

Figure CN114625660B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and more particularly to a debugging method and device. Background Art
[0002] On embedded devices, the use of JavaScript language for development is becoming more and more popular. The industry also has some JavaScript engines for the embedded field (that is, a virtual machine that specializes in processing JavaScript scripts), such as: Internet of Things JavaScript engine (such as JerryScript), streamlined embedded JavaScript engine (such as Duktape), lightweight and embeddable JavaScript engine (such as QuickJS), etc.
[0003] Currently, the common method is to use console.log to view the log output during program operation in the console to determine the running status of the JavaScript program. This method requires modifying the code, adding log printing, and updating it to run on the device, and it is impossible to view the stack frame status when the program runs to a certain point.
[0004] Therefore, the debugging method of the prior art cannot conveniently and effectively debug JavaScript code on embedded devices, and cannot view the program running status in real time. Summary of the invention
[0005] The embodiments of the present application provide a debugging method and device to solve the problem in the prior art that JavaScript code cannot be debugged conveniently and effectively on an embedded device, and the program running status cannot be viewed in real time.
[0006] In a first aspect, an embodiment of the present application provides a debugging method, which is applied to a JavaScript engine on an embedded device, wherein the JavaScript engine is configured with a debugger module, and the debugger module encapsulates a communication protocol for communicating with a debugging tool DevTools; wherein a single-step debugging function is injected into the JavaScript engine; the method comprises:
[0007] Obtaining a JavaScript script, and compiling JavaScript code in the JavaScript script to obtain at least one bytecode;
[0008] Determining, according to the at least one bytecode, through the communication protocol, whether debugging information for indicating debugging of the bytecode currently to be run is detected, wherein the debugging information is determined through the DevTools;
[0009] If it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function.
[0010] Optionally, the determining, according to the at least one bytecode, through the communication protocol, whether debugging information for indicating debugging of a bytecode currently to be run is detected includes:
[0011] Determining respective operation codes according to the at least one bytecode;
[0012] Determine the target operation code to be executed currently from each of the operation codes, and execute the following steps:
[0013] Determine a target bytecode corresponding to the target operation code from the at least one bytecode, and use the target bytecode as the current bytecode to be executed;
[0014] Determining whether the debugging information is detected according to the target bytecode through the communication protocol;
[0015] Wherein, the target operation code is any one of the operation codes.
[0016] Optionally, determining whether the debugging information is detected according to the target bytecode through the communication protocol includes:
[0017] According to the target bytecode, determining, through the communication protocol, a code statement referred to by a current running step in the JavaScript code, wherein the code statement includes the target bytecode;
[0018] According to the communication protocol, detecting whether there is a breakpoint in the code statement in the DevTools or whether there is a click operation for indicating a pause in the DevTools;
[0019] If there is a breakpoint or a click operation for indicating a pause, it is determined that the debugging information is detected.
[0020] Optionally, the breakpoint is generated by a user clicking a code statement in the DevTools;
[0021] The detecting, according to the communication protocol, whether there is a breakpoint in the code statement in the DevTools includes:
[0022] Through the communication protocol, if there is an operation of clicking a code statement in the DevTools, it is determined that a breakpoint is detected in the code statement in the DevTools.
[0023] Optionally, after running the current bytecode, the method further includes:
[0024] Generate stack frame information corresponding to the current bytecode;
[0025] According to the communication protocol, the stack frame information is sent to the DevTools, so that the DevTools displays the current running status corresponding to the bytecode on the interface corresponding to the DevTools according to the stack frame information.
[0026] Optionally, the method further includes:
[0027] After running the current bytecode, if a click operation for indicating a next step or a continuation is detected in the DevTools according to the communication protocol, a next target opcode is determined from each of the opcodes;
[0028] The next target opcode is used as the current target opcode to be executed.
[0029] Optionally, if it is determined that the debugging information is detected, running the current bytecode according to the single-step debugging function includes:
[0030] If a breakpoint or a click operation indicating a pause is detected in the DevTools, the JavaScript script is stopped from running, and the current bytecode is executed step by step according to the single-step debugging function.
[0031] Optionally, the method further includes:
[0032] If the debugging information is detected, an event notification is sent to the DevTools through the communication protocol.
[0033] Optionally, obtaining the JavaScript script includes:
[0034] Check whether there is the JavaScript script to be executed, and if so, obtain the JavaScript script.
[0035] In a second aspect, an embodiment of the present application provides a debugging device, which is applied to a JavaScript engine on an embedded device, wherein the JavaScript engine is configured with a debugger module, and the debugger module encapsulates a communication protocol for communicating with a debugging tool DevTools; wherein a single-step debugging function is injected into the JavaScript engine; the device comprises:
[0036] Obtaining a JavaScript script, and compiling JavaScript code in the JavaScript script to obtain at least one bytecode;
[0037] Determining, according to the at least one bytecode, through the communication protocol, whether the debugger module detects debugging information for indicating debugging of the bytecode currently to be run, wherein the debugging information is determined through the DevTools;
[0038] If it is determined that the debugger module detects the debugging information, the current bytecode is run according to the single-step debugging function.
[0039] The debugging method and device provided by the embodiment of the present application are applied to the JavaScript engine on the embedded device, wherein the JavaScript engine is configured with a debugger module, wherein the debugger module encapsulates a communication protocol for communicating with the debugging tool DevTools; wherein the JavaScript engine is injected with a single-step debugging function. By obtaining a JavaScript script and compiling the JavaScript code in the JavaScript script, at least one bytecode is obtained, and then according to the at least one bytecode, through the communication protocol, it is determined whether debugging information for indicating debugging of the bytecode currently to be run is detected, and the debugging information is determined by the DevTools, by injecting a debugger module into the JavaScript engine on the embedded device, and configuring the communication protocol in the debugger module to communicate with DevTools, so that the JavaScript engine on the embedded device has a debugging function; if it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function. Therefore, by using the debugging function of DevTools, without modifying the JavaScript code, developers can be allowed to perform real machine single-step debugging on embedded devices, conveniently and effectively implementing the debugging of the JavaScript code of the JavaScript engine on the embedded device, and based on the characteristics of DevTools and the single-step debugging function, the program running status can be viewed in real time. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0041] Figure 1 A flowchart of a debugging method provided in an embodiment of the present application;
[0042] Figure 2 A flowchart of a debugging method provided in another embodiment of the present application;
[0043] Figure 3 A schematic diagram of the structure of the debugging device provided in the embodiment of the present application;
[0044] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0045] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0046] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can also include other sequential instances in addition to those illustrated or described. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0047] At present, the commonly used method is to use console.log to view the log output during program operation in the console to determine the running status of the JavaScript program. This method requires modifying the code, adding log printing, and updating it to run on the device, and it is impossible to view the stack frame status when the program runs to a certain point. Therefore, the debugging method of the prior art cannot debug JavaScript code conveniently and effectively on embedded devices, and it is also impossible to view the program running status in real time.
[0048] In order to solve the above problems, the inventive concept of the present application is: inject a debugger module and a single-step debugging function into the JavaScript engine of an embedded device, and inject a communication protocol for communicating with the debugging tool DevTools into the debugger module, and then through the communication protocol, based on the debugging tool DevTools, without modifying the JavaScript code, real-machine single-step debugging can be allowed on the embedded device, breakpoints can be inserted, stack frame information can be captured, and the program running status can be viewed in real time.
[0049] The technical solution of the present application is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0050] The debugging method provided in the embodiment of the present application can be applied to an embedded device, and different development languages can be used on the embedded device for development and convenient and effective code debugging of the development language can be achieved, while the program running status can be viewed in real time. Among them, the debugging method is applied to a target engine on an embedded device, and the target engine can be any engine running in a development language, and the target engine is configured with a debugger module, and the debugger module encapsulates a communication protocol (such as a WebSocket protocol) for communicating with the debugging tool DevTools; wherein the target engine is injected with a single-step debugging function.
[0051] Specifically, a script corresponding to a development language is obtained, and the code in the script is compiled to obtain at least one bytecode; according to the at least one bytecode, it is determined through the communication protocol whether debugging information for indicating debugging of the bytecode currently to be run is detected, and the debugging information is determined through the DevTools; if it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function. The following takes JavaScript as an example to explain the debugging method in detail.
[0052] Figure 1 The flowchart of the debugging method provided in the embodiment of the present application is as follows. The method of the present embodiment can be executed by a JavaScript engine on an embedded device. The method of the present embodiment is applied to the scenario of debugging embedded JavaScript code. Specifically, the debugging method is applied to a JavaScript engine on an embedded device. The JavaScript engine is configured with a debugger module, and the debugger module encapsulates a communication protocol for communicating with the debugging tool DevTools. DevTools is a set of Web development and debugging tools built into the browser. Figure 1 As shown, the method of this embodiment may include:
[0053] S101. Obtain a JavaScript script, and compile the JavaScript code in the JavaScript script to obtain at least one bytecode.
[0054] In this embodiment, the JavaScript engine is first started and initialized to execute a JavaScript script obtained. In actual applications, the JavaScript script is not executed as a text in the JavaScript engine. The JavaScript engine parses the JavaScript script into bytecodes to form a bytecode set.
[0055] Optionally, obtain the JavaScript script by following these steps:
[0056] Check whether there is the JavaScript script to be executed, and if so, obtain the JavaScript script.
[0057] In this embodiment, after the JavaScript engine is initialized, it is first necessary to check whether there is an executable JavaScript script. If so, the JavaScript script is executed.
[0058] S102: Determine, based on the at least one bytecode and through the communication protocol, whether debugging information for indicating debugging of a bytecode currently to be run is detected, wherein the debugging information is determined through the DevTools.
[0059] The communication protocol here may be the WebSocket protocol, which is a new network protocol based on the Transmission Control Protocol (TCP) (a full-duplex communication protocol based on TCP).
[0060] In this embodiment, the parsed bytecode may have many operations, that is, the corresponding operation code can be obtained from the bytecode, and the operation code is at least one. Among them, the bytecode is the code logic, and the operation code is the bytecode type. For example, the bytecode is a+b, and the operation code is +. Among them, the JavaScript code traverses these operation codes during the execution of the JavaScript engine.
[0061] Specifically, through the communication protocol, it is detected from DevTools whether there is debugging information, such as whether there is a breakpoint or a pause operation. If there is a breakpoint or a pause operation, the breakpoint or pause operation will be used as debugging information, indicating that DevTools has actively initiated a debugging request, and the JavaScript code can be paused from running in the JavaScript engine.
[0062] S103: If it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function.
[0063] In this embodiment, if the debugging information is detected, the code logic is executed step by step through the single-step debugging function, which is a debugging method used in program development to track the program execution process step by step and find the cause of the error according to the value of the stack frame variable.
[0064] The debugging method provided by the present application is applied to the JavaScript engine on the embedded device, wherein the JavaScript engine is configured with a debugger module, wherein the debugger module encapsulates a communication protocol for communicating with the debugging tool DevTools; wherein the JavaScript engine is injected with a single-step debugging function. By obtaining a JavaScript script and compiling the JavaScript code in the JavaScript script, at least one bytecode is obtained, and then according to the at least one bytecode, through the communication protocol, it is determined whether debugging information for indicating debugging of the bytecode currently to be run is detected, and the debugging information is determined by the DevTools, by injecting a debugger module into the JavaScript engine on the embedded device, and configuring the communication protocol in the debugger module to communicate with DevTools, so that the JavaScript engine on the embedded device has a debugging function; if it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function. Therefore, by using the debugging function of DevTools, developers can be allowed to perform real machine single-step debugging on embedded devices without modifying the JavaScript code, conveniently and effectively realizing the debugging of the JavaScript code of the JavaScript engine on the embedded device, and based on the characteristics of DevTools and the single-step debugging function, the program running status can be viewed in real time.
[0065] Optionally, determining whether debugging information for indicating debugging of a bytecode currently to be run is detected through the communication protocol according to the at least one bytecode may be implemented by the following steps:
[0066] Step a1: Determine each operation code according to the at least one byte code.
[0067] Step a2: Determine the target operation code to be executed currently from each of the operation codes, and execute the following steps:
[0068] Step a21, determining a target bytecode corresponding to the target operation code from the at least one bytecode, and using the target bytecode as the bytecode currently to be executed;
[0069] Step a22, determining whether the debugging information is detected according to the target bytecode through the communication protocol;
[0070] Wherein, the target operation code is any one of the operation codes.
[0071] In this embodiment, after being parsed into bytecodes, these bytecodes may involve multiple opcodes, and these opcodes are traversed during the operation of the JavaScript engine. First, select the opcode to determine what operation the opcode corresponds to, that is, the bytecode corresponding to the selected opcode, such as an addition operation, a subtraction operation, or a multiplication operation. Different bytecodes will correspond to different execution functions in the JavaScript engine. Then, each time a bytecode is executed, the communication protocol is used to detect whether there is a breakpoint or a pause operation in DevTools. The breakpoint or pause operation here can be used as debugging information.
[0072] Optionally, this embodiment describes in detail how to determine whether the debugging information is detected based on the above embodiment. According to the target bytecode, through the communication protocol, determining whether the debugging information is detected can be achieved by the following steps:
[0073] Step b1: According to the target bytecode, through the communication protocol, determine the code statement pointed to by the current running step in the JavaScript code, wherein the code statement contains the target bytecode.
[0074] Step b2: According to the communication protocol, detecting whether there is a breakpoint in the code statement in the DevTools or whether there is a click operation for indicating a pause in the DevTools.
[0075] Step b3: If there is a breakpoint or a click operation for indicating a pause, it is determined that the debugging information is detected.
[0076] In this embodiment, during the operation of the JavaScript engine, a code statement containing bytecode is displayed on the DevTools interface, and the code statement may contain at least one bytecode. If the JavaScript engine detects through the communication protocol that the code statement containing the target bytecode displayed in DevTools contains a breakpoint at the location, or detects that the user clicks the pause button in DevTools, it means that the JavaScript engine detects a debugging request initiated by DevTools. The user here can be a debugger, which is not specifically limited here.
[0077] Optionally, according to the communication protocol, detecting whether there is a breakpoint in the code statement in the DevTools can be achieved by the following steps:
[0078] Through the communication protocol, if there is an operation of clicking a code statement in the DevTools, it is determined that a breakpoint is detected in the code statement in the DevTools.
[0079] The breakpoint is generated by a user clicking a code statement in the DevTools.
[0080] Optionally, if it is determined that the debugging information is detected, running the current bytecode according to the single-step debugging function may include the following steps:
[0081] If a breakpoint or a click operation indicating a pause is detected in the DevTools, the JavaScript script is stopped from running, and the current bytecode is executed step by step according to the single-step debugging function.
[0082] In this embodiment, based on the characteristics of DevTools, when marking a breakpoint, you only need to click on the location of the code statement displayed in DevTools. When the program reaches the breakpoint or clicks the pause button at a certain location, the program will be paused. Specifically, when the code is executed to the breakpoint, or the debugger actively clicks the pause button on the DevTools interface, the program will stop; then you can start to execute step by step. You can view the program running status in real time, insert breakpoints, and capture stack frame information.
[0083] Optionally, after running the current bytecode, the method may also be implemented by the following steps:
[0084] Step c1, generating stack frame information corresponding to the current bytecode.
[0085] Step c2: sending the stack frame information to the DevTools according to the communication protocol, so that the DevTools displays the current running status corresponding to the bytecode on the interface corresponding to the DevTools according to the stack frame information.
[0086] In this embodiment, taking the scenario of stopping at a breakpoint as an example, DevTools will automatically initiate a request to obtain stack frame information, and then display it on the DevTools interface, so that the debugger can see the program running status. Among them, the process status generated when running the bytecode is provided to DevTools as stack frame information. Running the bytecode is executed in the JS engine, and the program running status based on the stack frame information is displayed on the DevTools interface for the debugger to view.
[0087] Optionally, the method may further include the following steps:
[0088] Step d1, after running the current bytecode, if according to the communication protocol, a click operation for indicating the next step or continuing is detected in the DevTools, then determining the next target opcode from each of the opcodes;
[0089] Step d2: Use the next target operation code as the current target operation code to be executed.
[0090] In this embodiment, if after running the bytecode, it is necessary to wait for the debugger module to return an instruction on whether to continue execution, such as clicking a next or continue button on DevTools, DevTools initiates a next or continue request to the JavaScript engine, and after receiving the request based on the communication protocol, the JavaScript engine executes the next or continue operation, such as continuing to select the next opcode, to implement the above-mentioned loop operation for the opcode. For example, a target bytecode corresponding to the opcode is determined from the at least one bytecode, and the target bytecode is used as the bytecode to be currently run, and according to the target bytecode, it is determined through the communication protocol whether the debugging information is detected.
[0091] Optionally, the method may further include the following steps:
[0092] If the debugging information is detected, an event notification is sent to the DevTools through the communication protocol.
[0093] In this embodiment, an event notification is sent to the DevTools through a communication protocol, so that the DevTools performs the operation corresponding to the debugging information. For example, when JavaScript runs to a breakpoint, DevTools will be notified. DevTools performs the single-step debugging operation. Flexible control is achieved, allowing developers to perform real-machine single-step debugging on embedded devices.
[0094] Combination Figure 2 As shown, Figure 2A flowchart of a debugging method provided for another embodiment of the present application. On an embedded device, a debugger is extended on the JS engine to communicate with the debugging tool DevTools of the Chrome browser. Specifically, first start and initialize the JS engine (i.e., JavaScript engine), execute the JS script (i.e., JavaScript script), compile JS into bytecode, select the opcode, and then determine whether to debug through the debugger (module), and wait for the debugger to return a result indicating whether to debug. Among them, the debugger is a functional module injected into the JS engine. In DevTools, when the code executes to the breakpoint position, or the debugger actively clicks Pause on the DevTools interface (here it can refer to the JS code test interface), it will stop; then you can start to step down single-step (you can use the single-step debugging function). When it stops at a breakpoint, it will automatically initiate a request to get the stack frame information, and then display it on the DevTools interface, so that the debugger can see the program running status. Among them, DevTools has multiple functions (refer to Figure 2 Functional areas in the program), such as pause, continue, single-step debugging, set breakpoints, etc.
[0095] Among them, step means single-step debugging, and step includes step into (entering a function), step out (jumping out of the current function stack), and step over (skipping the current statement). Specifically, step into: single-step execution, entering and continuing single-step execution when encountering a sub-function (that is, entering the sub-function). step over: during single-step execution, when encountering a sub-function in a function, it will not enter the sub-function for single-step execution, but will execute the entire sub-function before stopping, that is, the entire sub-function is regarded as a step; among them, after our simple debugging, when there is no sub-function, it has the same effect as step into (that is, skipping the sub-function, but the sub-function will be executed). step out: when single-stepping into a sub-function, use step out to execute the rest of the sub-function and return to the previous function.
[0096] In this application, during the configuration of the JavaScript engine, the Web debugging tool DevTools is used to debug the JavaScript code on the embedded device. It is necessary to implement the protocol for the JavaScript debugger in DevTools on the embedded device, based on WebSocket communication; it is necessary to inject the single-step debugging function into the embedded JavaScript engine (including JerryScript, Duktape, QuickJS, etc.), and it is necessary to determine whether to pause JavaScript before running the bytecode, and capture the stack frame information as required by the protocol. Therefore, based on the debugging tool DevTools, without modifying the JavaScript code, developers can perform real-machine single-step debugging on embedded devices, which conveniently and effectively implements the JavaScript code for debugging the JavaScript engine on the embedded device, and can insert breakpoints, capture stack frame information, and view the program running status in real time.
[0097] Based on the same idea, the present application also provides a device corresponding to the above method, such as Figure 3 As shown, Figure 3 A schematic diagram of the structure of a debugging device provided in an embodiment of the present application. The debugging device is applied to a JavaScript engine on an embedded device, wherein the JavaScript engine is configured with a debugger module, wherein the debugger module encapsulates a communication protocol for communicating with the debugging tool DevTools; wherein a single-step debugging function is injected into the JavaScript engine. The debugging device may include:
[0098] The processing module 301 is used to obtain a JavaScript script and compile the JavaScript code in the JavaScript script to obtain at least one bytecode;
[0099] A first debugging module 302 is used to determine whether debugging information for indicating debugging of a bytecode currently to be run is detected through the communication protocol according to the at least one bytecode, wherein the debugging information is determined through the DevTools;
[0100] The second debugging module 303 is used to run the current bytecode according to the single-step debugging function when it is determined that the debugging information is detected.
[0101] In this embodiment, by obtaining a JavaScript script and compiling the JavaScript code in the JavaScript script through the processing module 301, the first debugging module 302, and the second debugging module 303, at least one bytecode is obtained, and then according to the at least one bytecode, through the communication protocol, it is determined whether debugging information for indicating debugging of the bytecode currently to be run is detected, and the debugging information is determined by the DevTools, by injecting a debugger module into the JavaScript engine on the embedded device, and configuring the communication protocol in the debugger module to communicate with DevTools, so that the JavaScript engine on the embedded device has a debugging function; if it is determined that the debugging information is detected, the current bytecode is run according to the single-step debugging function. Therefore, by using the debugging function of DevTools, without modifying the JavaScript code, developers can be allowed to perform real machine single-step debugging on embedded devices, which conveniently and effectively realizes the debugging of the JavaScript code of the JavaScript engine on the embedded device, and based on the characteristics of DevTools and the single-step debugging function, the program running status can be viewed in real time.
[0102] Optionally, the first debugging module 302 includes a first debugging unit and a second debugging unit;
[0103] A first debugging unit, configured to determine each operation code according to the at least one byte code;
[0104] The second debugging unit is used to determine the target operation code to be executed currently from each of the operation codes, and execute the following steps:
[0105] Determining a target bytecode corresponding to the target operation code from the at least one bytecode, and using the target bytecode as the bytecode to be currently executed; determining whether the debugging information is detected according to the target bytecode through the communication protocol;
[0106] Wherein, the target operation code is any one of the operation codes.
[0107] Optionally, the second debugging unit is specifically used for:
[0108] According to the target bytecode, determining, through the communication protocol, a code statement referred to by a current running step in the JavaScript code, wherein the code statement includes the target bytecode;
[0109] According to the communication protocol, detecting whether there is a breakpoint in the code statement in the DevTools or whether there is a click operation for indicating a pause in the DevTools;
[0110] If there is a breakpoint or a click operation for indicating a pause, it is determined that the debugging information is detected.
[0111] Optionally, the breakpoint is generated by a user clicking a code statement in the DevTools; the second debugging unit is specifically configured to:
[0112] Through the communication protocol, if there is an operation of clicking a code statement in the DevTools, it is determined that a breakpoint is detected in the code statement in the DevTools.
[0113] Optionally, the debugging device also includes a third debugging module; the third debugging module is used to send the stack frame information to the DevTools according to the communication protocol after running the current bytecode, so that the DevTools displays the running status corresponding to the current bytecode on the interface corresponding to the DevTools according to the stack frame information.
[0114] Optionally, the third debugging module is also used to:
[0115] After running the current bytecode, if a click operation for indicating a next step or a continuation is detected in the DevTools according to the communication protocol, a next target opcode is determined from each of the opcodes;
[0116] The next target opcode is used as the current target opcode to be executed.
[0117] Optionally, the second debugging module is specifically used to:
[0118] When a breakpoint or a click operation for indicating a pause is detected in the DevTools, the running of the JavaScript script is stopped, and the current bytecode is executed step by step according to a single-step debugging function.
[0119] Optionally, the debugging device further includes a fourth debugging module; the fourth debugging module is used to:
[0120] If the debugging information is detected, an event notification is sent to the DevTools through the communication protocol.
[0121] Optional, processing module, specifically used for:
[0122] Check whether there is the JavaScript script to be executed, and if so, obtain the JavaScript script.
[0123] This embodiment, based on the debugging tool DevTools, allows developers to perform real-machine single-step debugging on embedded devices without modifying the JavaScript code, conveniently and effectively debugs the JavaScript code of the JavaScript engine on the embedded device, and can insert breakpoints, capture stack frame information, and view the program running status in real time.
[0124] The device provided in the embodiment of the present application can realize the above-mentioned Figure 1-2 The implementation principle and technical effect of the method in the embodiment shown are similar and will not be described in detail here.
[0125] Figure 4 The hardware structure diagram of the electronic device provided in the embodiment of the present application is shown in FIG. Figure 4 As shown, the electronic device 400 provided in this embodiment includes: a processor 401 and a memory connected to the processor in communication. The processor 401 and the memory 402 are connected via a bus 403 .
[0126] In a specific implementation process, the processor 401 executes the computer-executable instructions stored in the memory 402, so that the processor 401 executes the method in the above method embodiment.
[0127] The specific implementation process of the processor 401 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0128] In the above Figure 4 In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0129] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage.
[0130] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0131] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the debugging method of the above method embodiment is implemented.
[0132] An embodiment of the present application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the debugging method as described above is implemented.
[0133] The computer-readable storage medium mentioned above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0134] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0135] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0136] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A debugging method, It is characterized in that A JavaScript engine applied to an embedded device, wherein the JavaScript engine is configured with a debugger module, wherein the debugger module encapsulates a communication protocol for communicating with a debugging tool DevTools; wherein a single-step debugging function is injected into the JavaScript engine; and the method comprises: Obtaining a JavaScript script, and compiling JavaScript code in the JavaScript script to obtain at least one bytecode; Determining, according to the at least one bytecode, through the communication protocol, whether debugging information for indicating debugging of the bytecode currently to be run is detected, wherein the debugging information is determined through the DevTools; If it is determined that the debugging information is detected, running the current bytecode according to the single-step debugging function; Generate stack frame information corresponding to the current bytecode; According to the communication protocol, the stack frame information is sent to the DevTools, so that the DevTools displays the current running status corresponding to the bytecode on an interface corresponding to the DevTools according to the stack frame information; The determining, based on the at least one bytecode and through the communication protocol, whether debugging information for indicating debugging of the bytecode currently to be run is detected comprises: Determining respective operation codes according to the at least one bytecode; Determine the target operation code to be executed currently from each of the operation codes, and execute the following steps: Determine a target bytecode corresponding to the target operation code from the at least one bytecode, and use the target bytecode as the current bytecode to be executed; Determining whether the debugging information is detected according to the target bytecode through the communication protocol; Wherein, the target operation code is any one of the operation codes.
2. The method according to claim 1, It is characterized in that The step of determining whether the debugging information is detected according to the target bytecode through the communication protocol includes: According to the target bytecode, determining, through the communication protocol, a code statement referred to by a current running step in the JavaScript code, wherein the code statement includes the target bytecode; According to the communication protocol, detecting whether there is a breakpoint in the code statement in the DevTools or whether there is a click operation for indicating a pause in the DevTools; If there is a breakpoint or a click operation for indicating a pause, it is determined that the debugging information is detected.
3. The method according to claim 2, It is characterized in that The breakpoint is generated by a user clicking a code statement in the DevTools; The detecting, according to the communication protocol, whether there is a breakpoint in the code statement in the DevTools includes: Through the communication protocol, if there is an operation of clicking a code statement in the DevTools, it is determined that a breakpoint is detected in the code statement in the DevTools.
4. The method according to claim 1, It is characterized in that The method further comprises: After running the current bytecode, if a click operation for indicating a next step or a continuation is detected in the DevTools according to the communication protocol, a next target opcode is determined from each of the opcodes; The next target opcode is used as the current target opcode to be executed.
5. The method according to claim 1 or 2, It is characterized in that If it is determined that the debugging information is detected, running the current bytecode according to the single-step debugging function includes: If a breakpoint or a click operation indicating a pause is detected in the DevTools, the JavaScript script is stopped from running, and the current bytecode is executed step by step according to the single-step debugging function.
6. The method according to claim 1 or 2, It is characterized in that The method further comprises: If the debugging information is detected, an event notification is sent to the DevTools through the communication protocol.
7. The method according to claim 1 or 2, It is characterized in that The obtaining of the JavaScript script includes: Check whether there is the JavaScript script to be executed, and if so, obtain the JavaScript script.
8. A debugging device, It is characterized in that A JavaScript engine applied to an embedded device, wherein the JavaScript engine is configured with a debugger module, wherein the debugger module encapsulates a communication protocol for communicating with a debugging tool DevTools; wherein a single-step debugging function is injected into the JavaScript engine; and the device comprises: A processing module, used for obtaining a JavaScript script and compiling the JavaScript code in the JavaScript script to obtain at least one bytecode; A first debugging module is used to determine whether debugging information for indicating debugging of a bytecode currently to be run is detected through the communication protocol according to the at least one bytecode, wherein the debugging information is determined through the DevTools; A second debugging module is used to run the current bytecode according to the single-step debugging function when it is determined that the debugging information is detected; The first debugging module includes a first debugging unit and a second debugging unit; The first debugging unit is used to determine each operation code according to the at least one byte code; The second debugging unit is used to determine the target operation code to be executed currently from each of the operation codes, and perform the following steps: Determine a target bytecode corresponding to the target opcode from the at least one bytecode, and use the target bytecode as the bytecode to be currently executed; determine whether the debugging information is detected according to the target bytecode through the communication protocol; wherein the target opcode is any one of the opcodes; The debugging device also includes a third debugging module; the third debugging module is used to generate stack frame information corresponding to the current bytecode after running the current bytecode; according to the communication protocol, the stack frame information is sent to the DevTools, so that the DevTools displays the running status corresponding to the current bytecode on the interface corresponding to the DevTools according to the stack frame information.
