OLD | NEW |
| (Empty) |
1 # ARM debugging with the simulator | |
2 | |
3 The simulator and debugger can be very helpful when working with v8 code generat
ion. | |
4 | |
5 * It is convenient as it allows you to test code generation without access to
actual hardware. | |
6 * No cross or native compilation is needed. | |
7 * The simulator fully supports the debugging of generated code. | |
8 | |
9 Please note that this simulator is designed for v8 purposes. Only the features u
sed by v8 are implemented, and you might encounter unimplemented features or ins
tructions. In this case, feel free to implement them and submit the code! | |
10 | |
11 | |
12 ## Details on the ARM Debugger | |
13 | |
14 Compile the ARM simulator shell with: | |
15 ``` | |
16 make arm.debug | |
17 ``` | |
18 on an x86 host using your regular compiler. | |
19 | |
20 ### Starting the Debugger | |
21 There are different ways of starting the debugger: | |
22 | |
23 ``` | |
24 $ out/arm.debug/d8 --stop_sim_at <n> | |
25 ``` | |
26 The simulator will start the debugger after executing n instructions. | |
27 | |
28 ``` | |
29 $ out/arm.debug/d8 --stop_at <function name> | |
30 ``` | |
31 | |
32 The simulator will stop at the given JavaScript function. | |
33 | |
34 Also you can directly generate 'stop' instructions in the ARM code. Stops are ge
nerated with | |
35 | |
36 ``` | |
37 Assembler::stop(const char* msg, Condition cond, int32_t code) | |
38 ``` | |
39 | |
40 When the Simulator hits a stop, it will print msg and start the debugger. | |
41 | |
42 | |
43 ### Debugging commands. | |
44 | |
45 **Usual commands:** | |
46 | |
47 Enter `help` in the debugger prompt to get details on available commands. These
include usual gdb-like commands, such as stepi, cont, disasm, etc. If the Simula
tor is run under gdb, the “gdb” debugger command will give control to gdb. You c
an then use cont from gdb to go back to the debugger. | |
48 | |
49 | |
50 **Debugger specific commands:** | |
51 | |
52 Here's a list of the ARM debugger specific commands, along with examples. | |
53 The JavaScript file “func.js” used below contains: | |
54 | |
55 ``` | |
56 function test() { | |
57 print(“In function test.”); | |
58 } | |
59 test(); | |
60 ``` | |
61 | |
62 * **printobject** `<`register`>` (alias po), will describe an object held in
a register. | |
63 | |
64 ``` | |
65 $ out/arm.debug/d8 func.js --stop_at test | |
66 | |
67 Simulator hit stop-at | |
68 0xb544d6a8 e92d4902 stmdb sp!, {r1, r8, fp, lr} | |
69 sim> print r0 | |
70 r0: 0xb547ec15 -1253577707 | |
71 sim> printobject r0 | |
72 r0: | |
73 0xb547ec15: [Function] | |
74 - map = 0x0xb540ff01 | |
75 - initial_map = | |
76 - shared_info = 0xb547eb2d <SharedFunctionInfo> | |
77 - name = #test | |
78 - context = 0xb60083f1 <FixedArray[52]> | |
79 - code = 0xb544d681 <Code> | |
80 #arguments: 0xb545a15d <Proxy> (callback) | |
81 #length: 0xb545a14d <Proxy> (callback) | |
82 #name: 0xb545a155 <Proxy> (callback) | |
83 #prototype: 0xb545a145 <Proxy> (callback) | |
84 #caller: 0xb545a165 <Proxy> (callback) | |
85 ``` | |
86 | |
87 * **break** `<`address`>`, will insert a breakpoint at the specified address. | |
88 | |
89 * **del**, will delete the current breakpoint. | |
90 | |
91 You can have only one such breakpoint. This is useful if you want to insert a br
eakpoint at runtime. | |
92 ``` | |
93 $ out/arm.debug/d8 func.js --stop_at test | |
94 | |
95 Simulator hit stop-at | |
96 0xb53a1ee8 e92d4902 stmdb sp!, {r1, r8, fp, lr} | |
97 sim> disasm 5 | |
98 0xb53a1ee8 e92d4902 stmdb sp!, {r1, r8, fp, lr} | |
99 0xb53a1eec e28db008 add fp, sp, #8 | |
100 0xb53a1ef0 e59a200c ldr r2, [r10, #+12] | |
101 0xb53a1ef4 e28fe004 add lr, pc, #4 | |
102 0xb53a1ef8 e15d0002 cmp sp, r2 | |
103 sim> break 0xb53a1ef8 | |
104 sim> cont | |
105 0xb53a1ef8 e15d0002 cmp sp, r2 | |
106 sim> disasm 5 | |
107 0xb53a1ef8 e15d0002 cmp sp, r2 | |
108 0xb53a1efc 359ff034 ldrcc pc, [pc, #+52] | |
109 0xb53a1f00 e5980017 ldr r0, [r8, #+23] | |
110 0xb53a1f04 e59f1030 ldr r1, [pc, #+48] | |
111 0xb53a1f08 e52d0004 str r0, [sp, #-4]! | |
112 sim> break 0xb53a1f08 | |
113 setting breakpoint failed | |
114 sim> del | |
115 sim> break 0xb53a1f08 | |
116 sim> cont | |
117 0xb53a1f08 e52d0004 str r0, [sp, #-4]! | |
118 sim> del | |
119 sim> cont | |
120 In function test. | |
121 ``` | |
122 | |
123 * Generated `stop` instuctions, will work as breakpoints with a few additional
features. | |
124 | |
125 The first argument is a help message, the second is the condition, and the third
is the stop code. If a code is specified, and is less than 256, the stop is sai
d to be “watched”, and can be disabled/enabled; a counter also keeps track of ho
w many times the Simulator hits this code. | |
126 | |
127 If we are working on this v8 C++ code, which is reached when running our JavaScr
ipt file. | |
128 | |
129 ``` | |
130 __ stop("My stop.", al, 123); | |
131 __ mov(r0, r0); | |
132 __ mov(r0, r0); | |
133 __ mov(r0, r0); | |
134 __ mov(r0, r0); | |
135 __ mov(r0, r0); | |
136 __ stop("My second stop.", al, 0x1); | |
137 __ mov(r1, r1); | |
138 __ mov(r1, r1); | |
139 __ mov(r1, r1); | |
140 __ mov(r1, r1); | |
141 __ mov(r1, r1); | |
142 ``` | |
143 | |
144 Here's a sample debugging session: | |
145 | |
146 We hit the first stop. | |
147 | |
148 ``` | |
149 Simulator hit My stop. | |
150 0xb53559e8 e1a00000 mov r0, r0 | |
151 ``` | |
152 | |
153 We can see the following stop using disasm. The address of the message string is
inlined in the code after the svc stop instruction. | |
154 | |
155 ``` | |
156 sim> disasm | |
157 0xb53559e8 e1a00000 mov r0, r0 | |
158 0xb53559ec e1a00000 mov r0, r0 | |
159 0xb53559f0 e1a00000 mov r0, r0 | |
160 0xb53559f4 e1a00000 mov r0, r0 | |
161 0xb53559f8 e1a00000 mov r0, r0 | |
162 0xb53559fc ef800001 stop 1 - 0x1 | |
163 0xb5355a00 08338a97 stop message: My second stop | |
164 0xb5355a04 e1a00000 mov r1, r1 | |
165 0xb5355a08 e1a00000 mov r1, r1 | |
166 0xb5355a0c e1a00000 mov r1, r1 | |
167 ``` | |
168 | |
169 Information can be printed for all (watched) stops which were hit at least once. | |
170 | |
171 ``` | |
172 sim> stop info all | |
173 Stop information: | |
174 stop 123 - 0x7b: Enabled, counter = 1, My stop. | |
175 sim> cont | |
176 Simulator hit My second stop | |
177 0xb5355a04 e1a00000 mov r1, r1 | |
178 sim> stop info all | |
179 Stop information: | |
180 stop 1 - 0x1: Enabled, counter = 1, My second stop | |
181 stop 123 - 0x7b: Enabled, counter = 1, My stop. | |
182 ``` | |
183 | |
184 Stops can be disabled or enabled. (Only available for watched stops.) | |
185 | |
186 ``` | |
187 sim> stop disable 1 | |
188 sim> cont | |
189 Simulator hit My stop. | |
190 0xb5356808 e1a00000 mov r0, r0 | |
191 sim> cont | |
192 Simulator hit My stop. | |
193 0xb5356c28 e1a00000 mov r0, r0 | |
194 sim> stop info all | |
195 Stop information: | |
196 stop 1 - 0x1: Disabled, counter = 2, My second stop | |
197 stop 123 - 0x7b: Enabled, counter = 3, My stop. | |
198 sim> stop enable 1 | |
199 sim> cont | |
200 Simulator hit My second stop | |
201 0xb5356c44 e1a00000 mov r1, r1 | |
202 sim> stop disable all | |
203 sim> con | |
204 In function test. | |
205 ``` | |
OLD | NEW |