-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug_Extension.html
300 lines (289 loc) · 15.2 KB
/
Debug_Extension.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Firm - Debug Extension</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="stylesheet" type="text/css" href="pygments.css"/>
<link rel="icon" type="image/png" href="logo-simple.png"/>
</head>
<body>
<div class="layout-header">
<a href="index.html"><img src="logo.png" alt="Firm Logo" /></a>
</div>
<div class="layout-content-wrapper">
<div class="layout-content">
<div class="layout-sidebar">
<ul>
<li><a href="index.html">About</a></li>
<li><a href="Features.html">Features</a></li>
<li><a href="Download.html">Download</a></li>
<li><a href="Documentation.html">Documentation</a></li>
<li><a href="Projects.html">Projects</a></li>
<li><a href="Development.html">Development</a></li>
<li><a href="Contact.html">Contact</a></li>
</ul>
<ul class="external">
<li><a href="http://pp.info.uni-karlsruhe.de/projects/firm_publications.php">Publications</a></li>
</ul>
<div class="layout-toc">
<h2>Contents</h2>
<ul>
<li><a href="#_commands">Commands</a></li>
<li><a href="#_usage">Usage</a>
<ul>
<li><a href="#_environment_variable">Environment Variable</a></li>
<li><a href="#_inside_a_debugger">Inside a debugger</a></li>
</ul>
</li>
<li><a href="#_debug_functions">Debug Functions</a>
<ul>
<li><a href="#_usage_in_gdb_macros">Usage in gdb macros</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="layout-document">
<h1>Debug Extension</h1>
<div class="sect1">
<h2 id="_commands">Commands</h2>
<div class="sectionbody">
<div class="tableblock">
<table rules="none"
width="100%"
frame="hsides"
cellspacing="0" cellpadding="4">
<col width="33%" />
<col width="66%" />
<thead>
<tr>
<th align="left" valign="top">Command</th>
<th align="left" valign="top"></th>
</tr>
</thead>
<tfoot>
<tr>
<td align="left" valign="top"><p class="table"><code>dumpfilter name</code></p></td>
<td align="left" valign="top"><p class="table">only dump graphs containing the given name</p></td>
</tr>
</tfoot>
<tbody>
<tr>
<td align="left" valign="top"><p class="table"><code>init</code></p></td>
<td align="left" valign="top"><p class="table">break after initialization</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>create nr</code></p></td>
<td align="left" valign="top"><p class="table">break if node nr was created</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>replace nr</code></p></td>
<td align="left" valign="top"><p class="table">break if node nr is replaced by another node</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>lower nr</code></p></td>
<td align="left" valign="top"><p class="table">break before node nr is lowered</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>remirg nr/name</code></p></td>
<td align="left" valign="top"><p class="table">break if the irg of nr or entity name is deleted</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>newent nr/name</code></p></td>
<td align="left" valign="top"><p class="table">break if the entity nr or name was created</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>newtype nr/name</code></p></td>
<td align="left" valign="top"><p class="table">break if the type nr or name was created</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>bp</code></p></td>
<td align="left" valign="top"><p class="table">show all breakpoints</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>enable nr</code></p></td>
<td align="left" valign="top"><p class="table">enable breakpoint nr</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>disable nr</code></p></td>
<td align="left" valign="top"><p class="table">disable breakpoint nr</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>showtype nr/name</code></p></td>
<td align="left" valign="top"><p class="table">show content of type nr or name</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>showent nr/name</code></p></td>
<td align="left" valign="top"><p class="table">show content of entity nr or name</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>setmask name msk</code></p></td>
<td align="left" valign="top"><p class="table">sets the debug module to mask msk</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>setlvl name lvl</code></p></td>
<td align="left" valign="top"><p class="table">sets the debug module name to level lvl</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>setoutfile name file</code></p></td>
<td align="left" valign="top"><p class="table">redirects debug output of module name to file</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>irgname name</code></p></td>
<td align="left" valign="top"><p class="table">prints address and graph number of a method given by its name</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>irgldname name</code></p></td>
<td align="left" valign="top"><p class="table">prints address and graph number of a method given by its ldname</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>help</code></p></td>
<td align="left" valign="top"><p class="table">list all commands</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_usage">Usage</h2>
<div class="sectionbody">
<div class="paragraph"><p>lib<span class="algo"><span class="algo">Firm</span></span> contains a builtin debug extension helping set breakpoints and inspecting data.</p></div>
<div class="sect2">
<h3 id="_environment_variable">Environment Variable</h3>
<div class="paragraph"><p>When firm starts up the environment variable FIRMDBG is interpreted as debug commands.
Examples:</p></div>
<div class="listingblock">
<div class="title">Break when node number 123 is created</div>
<div class="content"><div class="highlight"><pre><span></span>$<span class="w"> </span><span class="nv">FIRMDBG</span><span class="o">=</span><span class="s2">"create 123"</span><span class="w"> </span>my_firm_compiler
</pre></div></div></div>
<div class="listingblock">
<div class="title">Enable full debug logging for the firm.be.prefalloc module</div>
<div class="content"><div class="highlight"><pre><span></span>$<span class="w"> </span><span class="nv">FIRMDBG</span><span class="o">=</span><span class="s2">"setmask firm.be.prefalloc -1"</span><span class="w"> </span>my_firm_compiler
</pre></div></div></div>
</div>
<div class="sect2">
<h3 id="_inside_a_debugger">Inside a debugger</h3>
<div class="paragraph"><p>The debug extension is accessed using the builtin <code>firm_debug</code> function.</p></div>
<div class="paragraph"><p>In gdb, issue a call</p></div>
<div class="literalblock">
<div class="content">
<pre><code>call firm_debug(".help")</code></pre>
</div></div>
<div class="paragraph"><p>In the Visual Studio Debugger, simply place a call into the watch window.</p></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_debug_functions">Debug Functions</h2>
<div class="sectionbody">
<div class="paragraph"><p>Further, the following functions/expression might be useful while debugging</p></div>
<div class="tableblock">
<table rules="none"
width="100%"
frame="hsides"
cellspacing="0" cellpadding="4">
<col width="33%" />
<col width="66%" />
<thead>
<tr>
<th align="left" valign="top">Function</th>
<th align="left" valign="top"></th>
</tr>
</thead>
<tfoot>
<tr>
<td align="left" valign="top"><p class="table"><code>dump_ir_block_graph_sched(irg, suffix)</code></p></td>
<td align="left" valign="top"><p class="table">dumps graph irg</p></td>
</tr>
</tfoot>
<tbody>
<tr>
<td align="left" valign="top"><p class="table"><code>current_ir_graph</code></p></td>
<td align="left" valign="top"><p class="table">the current graph, set by most lib<span class="algo"><span class="algo">Firm</span></span> functions</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><code>dump_ir_block_graph(irg, suffix)</code></p></td>
<td align="left" valign="top"><p class="table">dumps graph irg</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_usage_in_gdb_macros">Usage in gdb macros</h3>
<div class="paragraph"><p>You can predefine gdb macros for common constructs like displaying an <code>ir_node*</code> or dumping the current graph for opening it in ycomp.
The following is a good idea:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="w"> </span>unwindonsignal<span class="w"> </span>on
<span class="c1"># FIRM</span>
<span class="c1"># The following is able to print most important firm datastructures:</span>
<span class="c1"># ir_node*, tarval*, ir_type*, ir_mode* and maybe others should work</span>
define<span class="w"> </span>irn
print<span class="w"> </span>gdb_node_helper<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
end
<span class="c1"># Hack to display the length of a firm ARR_F or ARR_D</span>
define<span class="w"> </span>arrlen
p<span class="w"> </span>array_len<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
end
define<span class="w"> </span>dumpg
<span class="k">if</span><span class="w"> </span><span class="nv">$argc</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">1</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span>is_ir_graph<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
<span class="w"> </span>call<span class="w"> </span>dump_ir_graph<span class="o">(</span><span class="nv">$arg0</span>,<span class="w"> </span><span class="s2">"XXX"</span><span class="o">)</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span>is_ir_node<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
<span class="w"> </span>call<span class="w"> </span>dump_ir_graph<span class="o">(</span>get_irn_irg<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>,<span class="w"> </span><span class="s2">"XXX"</span><span class="o">)</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s2">"Cannot determine graph of given argument\n"</span>
<span class="w"> </span>end
<span class="w"> </span>end
<span class="k">else</span>
<span class="w"> </span>call<span class="w"> </span>dump_ir_graph<span class="o">(</span>current_ir_graph,<span class="w"> </span><span class="s2">"XXX"</span><span class="o">)</span>
end
end
define<span class="w"> </span>firmd
call<span class="w"> </span>firm_debug<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
end
define<span class="w"> </span>graph
<span class="k">if</span><span class="w"> </span><span class="nv">$argc</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">1</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span>is_ir_graph<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
<span class="w"> </span>print<span class="w"> </span>gdb_node_helper<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span>is_ir_node<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
<span class="w"> </span>print<span class="w"> </span>gdb_node_helper<span class="o">(</span>get_irn_irg<span class="o">(</span><span class="nv">$arg0</span><span class="o">))</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s2">"Cannot determine graph of given argument\n"</span>
<span class="w"> </span>end
<span class="w"> </span>end
<span class="k">else</span>
<span class="w"> </span>call<span class="w"> </span>dump_ir_graph<span class="o">(</span>current_ir_graph,<span class="w"> </span><span class="s2">"XXX"</span><span class="o">)</span>
end
end
define<span class="w"> </span>keep
call<span class="w"> </span>add_End_keepalive<span class="o">(</span>get_irg_end<span class="o">(</span>get_irn_irg<span class="o">(</span><span class="nv">$arg0</span><span class="o">))</span>,<span class="w"> </span><span class="nv">$arg0</span><span class="o">)</span>
end
<span class="c1"># cparser</span>
define<span class="w"> </span>cpexpr
call<span class="w"> </span>print_expression<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>,<span class="w"> </span><span class="o">(</span>void<span class="o">)</span>putchar<span class="o">(</span><span class="s1">'\n'</span><span class="o">)</span>
end
define<span class="w"> </span>cpstmt
call<span class="w"> </span>print_statement<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>
end
define<span class="w"> </span>cptype
call<span class="w"> </span>print_type<span class="o">(</span><span class="nv">$arg0</span><span class="o">)</span>,<span class="w"> </span><span class="o">(</span>void<span class="o">)</span>putchar<span class="o">(</span><span class="s1">'\n'</span><span class="o">)</span>
end
</pre></div></div></div>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="layout-footer">
<span><a href="https://lists.ira.uni-karlsruhe.de/mailman/listinfo/firm">Mailing list</a>: <a href="mailto:[email protected]">[email protected]</a></span>
</div>
</body>
</html>