|
| 1 | +# Internal operation of the Debugger |
| 2 | + |
| 3 | +The debugger uses a client server model where the server is the Escargot engine. |
| 4 | +The connection between the client and server must be bi-directional and reliable. |
| 5 | + |
| 6 | +The debugger protocol uses packets, although the connection layer can split |
| 7 | +these packets into smaller ones if needed. The maximum packet length is defined by |
| 8 | +the connection layer. For example, it is 125 for the websockets layer. When a |
| 9 | +message is longer than the maximum packet size, it is split into a sequence of |
| 10 | +packets. The type of the last packet has an `_END` prefix. The following |
| 11 | +example shows the transmission of strings: |
| 12 | + |
| 13 | +Characters of a string can be 8 or 16 bit long. When a string is transmitted, |
| 14 | +it is split into a sequence of packets, and the type of these packets is either |
| 15 | +`ESCARGOT_MESSAGE_STRING_8BIT` or `ESCARGOT_MESSAGE_STRING_16BIT`, except |
| 16 | +the last one which type is either `ESCARGOT_MESSAGE_STRING_8BIT_END` |
| 17 | +or `ESCARGOT_MESSAGE_STRING_16BIT_END`. If a string fits into a single packet, |
| 18 | +only the type ending with `_END` is used. |
| 19 | + |
| 20 | +## Debugger modes |
| 21 | + |
| 22 | +The message types which can be transmitted depends on the current mode. These are |
| 23 | +the current modes: |
| 24 | + |
| 25 | +* Free running mode: Escargot executes ECMAScript code. The engine may stop at |
| 26 | +a breakpoint and notify the client. The client can also request an execution stop. |
| 27 | + |
| 28 | +* Parsing mode: when Escargot parses an ECMAScript code, it produces several |
| 29 | +messages which follows the parsing process. For example, Escargot notifies the |
| 30 | +client when it starts parsing a new nested function, or the breakpoint list is |
| 31 | +available for a function. This reduces the memory consumption, since the data |
| 32 | +is collected until the parsing ends. The debugger client sets up its internal |
| 33 | +data about the structure of the ECMAScript code based on these messages. |
| 34 | + |
| 35 | +* Breakpoint mode: when Escargot stops at a breakpoint, the client can request |
| 36 | +information about the execution status such as backtrace or lexical environment. |
| 37 | +The objects and their properties can be enumerated as well. Escargot maintains |
| 38 | +a reference to all objects which properties are enumerated until the execution |
| 39 | +resumes. Therefore the properties of temporary objects (e.g. the result of a |
| 40 | +getter) can be inspected later. These temporary objects may increase the memory |
| 41 | +consumption. |
| 42 | + |
| 43 | +* Source sending mode: the client can send multiple source files to Escargot |
| 44 | +in this mode, and the engine executes them. Escargot enters this mode when |
| 45 | +the user instructs it or it has no code to execute. |
| 46 | + |
| 47 | +## Evaluating code |
| 48 | + |
| 49 | +In breakpoint mode, the client can evaluate ECMAScript code. After the evaluation |
| 50 | +is completed, the client receives the string represenation of the result, if the |
| 51 | +evaluation is successful, or the string representation of the exception otherwise. |
| 52 | +These evaluations can have side effects, e.g. variables or properties can be created, |
| 53 | +changed, or deleted. The engine does not maintain a separate environment for |
| 54 | +executing code, the side effects remain after the execution resumes. Furthermore |
| 55 | +the engine ignores all breakpoints during the evaluation, so infinite loops |
| 56 | +will never stop. |
| 57 | + |
| 58 | +## Breakpoints |
| 59 | + |
| 60 | +The Escargot debugger emits disabled breakpoint instructions into the byte code |
| 61 | +stream. The debugger client receives the offset of these instructions with their |
| 62 | +corresponding line info. Using these offsets the client can request the server |
| 63 | +to enable or disable breakpoints by changing the opcode to enabled or disabled |
| 64 | +state. Escargot always stops when an enabled breakpoint is executed. |
0 commit comments