1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \page qtscriptdebugger-manual.html
|
---|
44 | \title Qt Script Debugger Manual
|
---|
45 | \ingroup scripting
|
---|
46 | \brief A manual describing how to use the Qt Script debugger.
|
---|
47 |
|
---|
48 | The Qt Script debugger is a tool for debugging script execution in
|
---|
49 | Qt applications that use Qt Script. Application developers can embed
|
---|
50 | the debugger into their application through the
|
---|
51 | QScriptEngineDebugger class. This manual describes how to use the
|
---|
52 | debugger. We assume that the reader is somewhat familiar with
|
---|
53 | general debugging concepts and existing debugging tools.
|
---|
54 |
|
---|
55 | We assume that the debugger has been integrated into the application
|
---|
56 | through the QScriptEngineDebugger::standardWindow()
|
---|
57 | function, which provides the standard debugger configuration.
|
---|
58 |
|
---|
59 | \tableofcontents
|
---|
60 |
|
---|
61 | \section1 Getting Started
|
---|
62 |
|
---|
63 | The following image shows the debugger as created with
|
---|
64 | \l{QScriptEngineDebugger::}{standardWindow()}:
|
---|
65 |
|
---|
66 | \image qtscript-debugger.png Running a script under the Qt Script debugger.
|
---|
67 |
|
---|
68 | The debugger will start, i.e., take control over the script's
|
---|
69 | execution when any of these conditions are met:
|
---|
70 |
|
---|
71 | \list
|
---|
72 | \o The \c{debugger} statement is encountered in the script.
|
---|
73 | \o Clicking the \gui Interrupt menu item from the \gui Debug
|
---|
74 | menu in the main window.
|
---|
75 | \o A breakpoint is reached.
|
---|
76 | \o An uncaught script exception is thrown.
|
---|
77 | \endlist
|
---|
78 |
|
---|
79 | Once the debugger is started, the execution state can be inspected,
|
---|
80 | e.g., the value of variables can be queried and the current program
|
---|
81 | stack shown. New breakpoints can be set.
|
---|
82 |
|
---|
83 | The debugger will resume, i.e., give the control back to the script
|
---|
84 | engine, when the user clicks \gui Continue menu item from the \gui
|
---|
85 | Debug menu. It will be invoked again if one of the conditions
|
---|
86 | described in the list above is met.
|
---|
87 |
|
---|
88 | \section1 Overview of Debugger Components
|
---|
89 |
|
---|
90 | The debugger's functionality is divided into a series of components,
|
---|
91 | each being a widget that can be shown in the main window of the
|
---|
92 | debugger. The following table describes each component and how they
|
---|
93 | relate to each other.
|
---|
94 |
|
---|
95 | \table
|
---|
96 | \header
|
---|
97 | \o Component
|
---|
98 | \o Description
|
---|
99 | \row
|
---|
100 | \o Console Widget
|
---|
101 | \o The console widget provides a command-line interface to the
|
---|
102 | debugger's functionality, and also serves as an interactive script
|
---|
103 | interpreter. The set of commands and their syntax is inspired by
|
---|
104 | GDB, the GNU Debugger. Commands and script variables are
|
---|
105 | auto-completed through the TAB key.
|
---|
106 |
|
---|
107 | Any console command that causes a change in the debugger or debugger
|
---|
108 | target's state will immediately be reflected in the other debugger
|
---|
109 | components (e.g. breakpoints or local variables changed).
|
---|
110 |
|
---|
111 | The console provides a simple and powerful way of manipulating the
|
---|
112 | script environment. For example, typing "x" and hitting enter will
|
---|
113 | evaluate "x" in the current stack frame and display the result.
|
---|
114 | Typing "x = 123" will assign the value 123 to the variable \c{x} in
|
---|
115 | the current scope (or create a global variable \c{x} if there isn't
|
---|
116 | one -- scripts evaluated through the console can have arbitrary side
|
---|
117 | effects, so be careful).
|
---|
118 |
|
---|
119 | \row
|
---|
120 | \o Stack Widget
|
---|
121 | \o The stack widget shows a backtrace of the script execution state.
|
---|
122 | Each row represents one frame in the stack. A row contains the
|
---|
123 | frame index (0 being the inner-most frame), the name of the script function,
|
---|
124 | and the location (file name and line number). To select a particular
|
---|
125 | stack frame to inspect, click on its row.
|
---|
126 |
|
---|
127 | \row
|
---|
128 | \o Locals Widget
|
---|
129 | \o The locals widget shows the variables that are local to the
|
---|
130 | currently selected stack frame; that is, the properties of the
|
---|
131 | objects in the scope chain and the \c{this}-object. Objects can be
|
---|
132 | expanded, so that their properties can be examined, recursively.
|
---|
133 | Properties whose value has changed are shown in bold font.
|
---|
134 |
|
---|
135 | Properties that are not read-only can be edited. Double-click on the
|
---|
136 | value and type in the new value; the value can be an arbitrary
|
---|
137 | expression. The expression will be evaluated in the associated stack
|
---|
138 | frame. While typing, you can press the TAB key to get possible
|
---|
139 | completions for the expression.
|
---|
140 |
|
---|
141 | \row
|
---|
142 | \o Code Widget
|
---|
143 | \o The code widget shows the code of the currently selected script.
|
---|
144 | The widget displays an arrow in the left margin, marking the
|
---|
145 | code line that is being executed.
|
---|
146 | Clicking in the margin of a line will cause a breakpoint to be
|
---|
147 | toggled at that line. A breakpoint has to be set on a line that
|
---|
148 | contains an actual statement in order to be useful.When an uncaught script exception occurs, the
|
---|
149 | offending line will be shown with a red background.
|
---|
150 |
|
---|
151 | The code widget is read-only; it cannot currently be used to edit
|
---|
152 | and (re)evaluate scripts. This is however possible from the
|
---|
153 | command-line interface, see \l{Console Command Reference}.
|
---|
154 |
|
---|
155 | \row
|
---|
156 | \o Scripts Widget
|
---|
157 |
|
---|
158 | \o The scripts widget shows the scripts that are currently loaded in
|
---|
159 | the script engine. Clicking on a script will cause its code to be
|
---|
160 | shown in the code widget. When a script is no longer referenced by
|
---|
161 | the debugger target it is removed from the scripts widget. Code
|
---|
162 | evaluated through QScriptEngine::evaluate() without a name specified, will be
|
---|
163 | displayed in the widget as Anonymous.
|
---|
164 |
|
---|
165 | \row
|
---|
166 | \o Breakpoints Widget
|
---|
167 |
|
---|
168 | \o The breakpoints widget shows all the breakpoints that are set. A
|
---|
169 | breakpoint can be disabled or enabled by clicking the checkbox next
|
---|
170 | to the breakpoint's ID (the ID is provided so that the breakpoint
|
---|
171 | can be manipulated through the console widget as well).
|
---|
172 |
|
---|
173 | A condition can be associated with the breakpoint; the condition can
|
---|
174 | be an arbitrary expression that should evaluate to true or
|
---|
175 | false. The breakpoint will only be triggered when its location is
|
---|
176 | reached \bold{and} the condition evaluates to true.
|
---|
177 |
|
---|
178 | Similarly, if the breakpoint's ignore-count is set to N, the
|
---|
179 | breakpoint will be ignored the next N times it is hit.
|
---|
180 |
|
---|
181 | A new breakpoint can be set by clicking the New Breakpoint button
|
---|
182 | and typing in a location of the form <filename>\bold{:}<linenumber>.
|
---|
183 | The breakpoint location can refer to an already loaded script, or
|
---|
184 | one that has not been loaded yet.
|
---|
185 |
|
---|
186 | \row
|
---|
187 | \o Debug Output Widget
|
---|
188 | \o The debug output widget shows messages generated by the print()
|
---|
189 | script function. Scripts can use the special variables \c{__FILE__}
|
---|
190 | and \c{__LINE__} to include the current location information in the
|
---|
191 | messages.
|
---|
192 |
|
---|
193 | \row
|
---|
194 | \o Error Log Widget
|
---|
195 | \o The error log widget shows error messages that have been generated.
|
---|
196 | All uncaught exceptions that occur in the engine will appear here.
|
---|
197 |
|
---|
198 | \endtable
|
---|
199 |
|
---|
200 | \section2 Resuming Script Evaluation
|
---|
201 |
|
---|
202 | Script evaluation can be resumed in one of the following ways:
|
---|
203 |
|
---|
204 | \list
|
---|
205 | \o \bold{Continue}: Evaluation will resume normally.
|
---|
206 | \o \bold{Step Into}: Evaluation will resume until the next statement is reached.
|
---|
207 | \o \bold{Step Over}: Evaluation will resume until the next statement is reached;
|
---|
208 | but if the current statement is a function call, the debugger
|
---|
209 | will treat it as a single statement.
|
---|
210 | \o \bold{Step Out}: Evaluation will resume until the current function exits and
|
---|
211 | the next statement is reached.
|
---|
212 | \o \bold{Run to Cursor}: Run until the statement at the cursor is reached.
|
---|
213 | \o \bold{Run to New Script}: Run until the first statement of a new script is reached.
|
---|
214 | \endlist
|
---|
215 |
|
---|
216 | In any case, script evaluation can also be stopped due to either of the
|
---|
217 | following reasons:
|
---|
218 |
|
---|
219 | \list
|
---|
220 | \o A \c{debugger} statement is encountered.
|
---|
221 | \o A breakpoint is hit.
|
---|
222 | \o An uncaught script exception occurs.
|
---|
223 | \endlist
|
---|
224 |
|
---|
225 | \section2 Resuming After an Uncaught Exception
|
---|
226 |
|
---|
227 | When an uncaught script exception occurs, it is not possible to
|
---|
228 | continue evaluating the current function normally. However, you can
|
---|
229 | use the console command \bold{return} to catch the exception and
|
---|
230 | return a value to the calling function.
|
---|
231 |
|
---|
232 | \section1 Console Command Reference
|
---|
233 |
|
---|
234 | Note that you can also get help on the available commands by typing
|
---|
235 | ".help" in the console.
|
---|
236 |
|
---|
237 | \section2 Breakpoint-related Commands
|
---|
238 |
|
---|
239 | Break points is set
|
---|
240 |
|
---|
241 | \section3 break <location>
|
---|
242 |
|
---|
243 | Sets a breakpoint at a given code line.
|
---|
244 |
|
---|
245 | \code
|
---|
246 | .break foo.qs:123
|
---|
247 | \endcode
|
---|
248 |
|
---|
249 | This command sets a breakpoint at \c{foo.qs}, line 123.
|
---|
250 |
|
---|
251 | \code
|
---|
252 | .break 123
|
---|
253 | \endcode
|
---|
254 |
|
---|
255 | This command sets a breakpoint at line 123 in the current script; the current script
|
---|
256 | is the script associated with the current stack frame.
|
---|
257 |
|
---|
258 | Each breakpoint has a unique identifier (an integer) associated with it.
|
---|
259 | This identifier is needed by other breakpoint-related commands.
|
---|
260 |
|
---|
261 | \section3 clear <location>
|
---|
262 |
|
---|
263 | \code
|
---|
264 | .clear foo.qs:123
|
---|
265 | \endcode
|
---|
266 |
|
---|
267 | clears (deletes) the breakpoint at \c{foo.qs}, line 123.
|
---|
268 |
|
---|
269 | \code
|
---|
270 | clear 123
|
---|
271 | \endcode
|
---|
272 |
|
---|
273 | clears (deletes) the breakpoint at line 123 in the current script;
|
---|
274 | the current script is the script associated with the current stack
|
---|
275 | frame.
|
---|
276 |
|
---|
277 | \section3 condition <breakpoint-id> <expression>
|
---|
278 |
|
---|
279 | Sets a condition for a breakpoint.
|
---|
280 |
|
---|
281 | \code
|
---|
282 | .condition 1 i > 42
|
---|
283 | \endcode
|
---|
284 |
|
---|
285 | specifies that breakpoint 1 should only be triggered if the variable \c{i}
|
---|
286 | is greater than 42.
|
---|
287 |
|
---|
288 | The expression can be an arbitrary one, i.e. it can have
|
---|
289 | side-effects. It can be any valid QScript conditional
|
---|
290 | expression.
|
---|
291 |
|
---|
292 | \section3 delete <breakpoint-id>
|
---|
293 |
|
---|
294 | Deletes a breakpoint, i.e., removes it from the current debugging
|
---|
295 | session.
|
---|
296 |
|
---|
297 | \section3 disable <breakpoint-id>
|
---|
298 |
|
---|
299 | Disables a breakpoint. The breakpoint will continue to exist, but
|
---|
300 | will not stop program execution.
|
---|
301 |
|
---|
302 | \section3 enable <breakpoint-id>
|
---|
303 |
|
---|
304 | Enables a breakpoint. Breakpoints are enabled by default, so you
|
---|
305 | only need to use this command if you have disabled to breakpoint
|
---|
306 | previously.
|
---|
307 |
|
---|
308 | \section3 ignore <breakpoint-id> <count>
|
---|
309 |
|
---|
310 | Sets the ignore-count of a breakpoint, i.e., the breakpoint will not
|
---|
311 | stop the program execution unless it have been reached \c count
|
---|
312 | times. This can, for instance, be useful in loops to stop at a
|
---|
313 | specific iteration.
|
---|
314 |
|
---|
315 | \code
|
---|
316 | .ignore 1 5
|
---|
317 | \endcode
|
---|
318 |
|
---|
319 | Specifies that breakpoint 1 should be ignored the next 5 times it is
|
---|
320 | hit.
|
---|
321 |
|
---|
322 | \section3 info breakpoints
|
---|
323 |
|
---|
324 | Lists the breakpoints that are set.
|
---|
325 |
|
---|
326 | \code
|
---|
327 | .info breakpoints
|
---|
328 | \endcode
|
---|
329 |
|
---|
330 | \section3 tbreak <location>
|
---|
331 |
|
---|
332 | Sets a temporary breakpoint. This command is identical to the
|
---|
333 | \c{break} command, only the breakpoint will be automatically deleted
|
---|
334 | the first time it is hit.
|
---|
335 |
|
---|
336 | \section2 File-related Commands
|
---|
337 |
|
---|
338 | \section3 list <location>
|
---|
339 |
|
---|
340 | Lists the contents of a script around a given location, where the
|
---|
341 | location is given as a line number and, optionally, the name of the
|
---|
342 | file from which you will print. If only a line number is given, \c
|
---|
343 | {.list} will use the file of the current stack frame.
|
---|
344 |
|
---|
345 | \code
|
---|
346 | .list foo.qs:125
|
---|
347 | \endcode
|
---|
348 |
|
---|
349 | When no arguments are given, \c{list} will incrementally list
|
---|
350 | sections of the current script.
|
---|
351 |
|
---|
352 | \section3 info scripts
|
---|
353 |
|
---|
354 | Lists the scripts that are currently loaded.
|
---|
355 |
|
---|
356 | \section2 Execution-related Commands
|
---|
357 |
|
---|
358 | \section3 advance <location>
|
---|
359 |
|
---|
360 | Advances execution to a given location. The syntax of the location
|
---|
361 | is the same as for setting breakpoints. For example:
|
---|
362 |
|
---|
363 | \code
|
---|
364 | .advance foo.qs:125
|
---|
365 | \endcode
|
---|
366 |
|
---|
367 | \section3 continue
|
---|
368 |
|
---|
369 | Continues execution normally, i.e, gives the execution control over
|
---|
370 | the script back the the QScriptEngine.
|
---|
371 |
|
---|
372 | \section3 eval <program>
|
---|
373 |
|
---|
374 | Evaluates a program.
|
---|
375 |
|
---|
376 | \section3 finish
|
---|
377 |
|
---|
378 | Continues execution until the current function exits and the next
|
---|
379 | statement is reached (i.e., the statement after the call to the
|
---|
380 | function).
|
---|
381 |
|
---|
382 | \section3 interrupt
|
---|
383 |
|
---|
384 | Requests that execution should be interrupted. Interruption will
|
---|
385 | occur as soon as a new script statement is reached.
|
---|
386 |
|
---|
387 | \section3 next <count = 1>
|
---|
388 |
|
---|
389 | Continues execution until a new statement is reached; but if the
|
---|
390 | current statement is a function call, the function call will be
|
---|
391 | treated as a single statement. This will be done \c count times
|
---|
392 | before execution is stopped; the default is one.
|
---|
393 |
|
---|
394 | \section3 return <expression>
|
---|
395 |
|
---|
396 | Makes the current frame return to its caller. If \c expression is
|
---|
397 | given, it will sent as the result of the function (i.e., replacing
|
---|
398 | the functions return value). \c expression can be any valid QScript
|
---|
399 | expression.
|
---|
400 |
|
---|
401 | \section3 step <count = 1>
|
---|
402 |
|
---|
403 | Continues execution until a new statement is reached. If the number
|
---|
404 | \c count is given as argument, this will be done \c count times
|
---|
405 | before execution is stopped. As opposed to \l{next <count = 1>}, \c
|
---|
406 | step will enter functions when encountering a function call
|
---|
407 | statement.
|
---|
408 |
|
---|
409 | \section2 Stack-related Commands
|
---|
410 |
|
---|
411 | \section3 backtrace
|
---|
412 |
|
---|
413 | Shows a backtrace of the current execution. The trace will list the
|
---|
414 | function name and its position in the script for each stack frame.
|
---|
415 |
|
---|
416 | \section3 down
|
---|
417 |
|
---|
418 | Selects the previous (inner) stack frame. The execution will not
|
---|
419 | return to this frame, but you will get access to its local
|
---|
420 | variables.
|
---|
421 |
|
---|
422 | \section3 frame <index>
|
---|
423 |
|
---|
424 | This command moves to the stack frame with the given \c index. The
|
---|
425 | index of the frame on the top of the stack is 0. Previous frames are
|
---|
426 | numbered from 1 and upwards (the bottom frame in the stack has the
|
---|
427 | largest index).
|
---|
428 |
|
---|
429 | \section3 info locals
|
---|
430 |
|
---|
431 | Lists the variables that are in the scope of the current frame.
|
---|
432 |
|
---|
433 | \section3 up
|
---|
434 |
|
---|
435 | Selects the next (outer) stack frame.
|
---|
436 |
|
---|
437 | */
|
---|