3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
12 #include "exprwnd.h" /* some compilers require this */
20 class ProgramTypeTable
;
30 class DisassembledCode
;
35 class KDebugger
: public QObject
39 KDebugger(QWidget
* parent
, /* will be used as the parent for dialogs */
43 DebuggerDriver
* driver
48 * This function starts to debug the specified executable. If a program
49 * is currently being debugged, it is terminated first.
51 * @return false if an error occurs.
53 bool debugProgram(const QString
& executable
);
56 * Uses the specified core to debug the active program.
57 * @param batch tells whether the core file was given on the
60 void useCoreFile(QString corefile
, bool batch
);
63 * Runs the program or continues it if it is stopped at a breakpoint.
68 * Attaches to the specified process and debugs it.
70 void attachProgram(const QString
& pid
);
73 * Restarts the debuggee.
75 void programRunAgain();
78 * Performs a single-step, possibly stepping into a function call.
83 * Performs a single-step, stepping over a function call.
88 * Runs the program until it returns from the current function.
93 * Kills the program (removes it from memory).
98 * Interrupts the program if it is currently running.
103 * Queries the user for program arguments.
105 void programArgs(QWidget
* parent
);
108 * Queries the user for program settings: Debugger command, terminal
111 void programSettings(QWidget
* parent
);
114 * Setup remote debugging device
116 void setRemoteDevice(const QString
& remoteDevice
) { m_remoteDevice
= remoteDevice
; }
119 * Run the debuggee until the specified line in the specified file is
122 * @return false if the command was not executed, e.g. because the
123 * debuggee is running at the moment.
125 bool runUntil(const QString
& fileName
, int lineNo
);
130 * @param fileName The source file in which to set the breakpoint.
131 * @param lineNo The zero-based line number.
132 * @param address The exact address of the breakpoint.
133 * @param temporary Specifies whether this is a temporary breakpoint
134 * @return false if the command was not executed, e.g. because the
135 * debuggee is running at the moment.
137 bool setBreakpoint(QString fileName
, int lineNo
,
138 const DbgAddr
& address
, bool temporary
);
141 * Enable or disable a breakpoint at the specified location.
143 * @param fileName The source file in which the breakpoint is.
144 * @param lineNo The zero-based line number.
145 * @param address The exact address of the breakpoint.
146 * @return false if the command was not executed, e.g. because the
147 * debuggee is running at the moment.
149 bool enableDisableBreakpoint(QString fileName
, int lineNo
,
150 const DbgAddr
& address
);
153 * Tells whether one of the single stepping commands can be invoked
154 * (step, next, finish, until, also run).
156 bool canSingleStep();
159 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
161 bool canChangeBreakpoints();
164 * Tells whether the debuggee can be changed.
166 bool canUseCoreFile() { return isReady() && !m_programActive
; }
169 * Add a watch expression.
171 void addWatch(const QString
& expr
);
174 * Retrieves the current status message.
176 const QString
& statusMessage() const { return m_statusMessage
; }
179 * Is the debugger ready to receive another high-priority command?
181 bool isReady() const;
184 * Is the debuggee running (not just active)?
186 bool isProgramRunning() { return m_haveExecutable
&& m_programRunning
; }
189 * Do we have an executable set?
191 bool haveExecutable() { return m_haveExecutable
; }
194 * Is the debuggee active, i.e. was it started by the debugger?
196 bool isProgramActive() { return m_programActive
; }
199 * Is the debugger driver idle?
203 /** The list of breakpoints. */
204 int numBreakpoints() const { return m_brkpts
.size(); }
205 const Breakpoint
* breakpoint(int i
) const { return m_brkpts
[i
]; }
207 const QString
& executable() const { return m_executable
; }
210 * Sets the command to invoke gdb. If cmd is the empty string, the
211 * default is substituted.
213 void setDebuggerCmd(const QString
& cmd
)
214 { m_generalDebuggerCmd
= cmd
; }
217 * Terminal emulation level.
220 ttyNone
= 0, /* ignore output, input triggers EOF */
221 ttySimpleOutputOnly
= 1, /* minmal output emulation, input triggers EOF */
222 ttyFull
= 7 /* program needs full emulation */
226 * Returns the level of terminal emulation requested by the inferior.
228 TTYLevel
ttyLevel() const { return m_ttyLevel
; }
230 /** Sets the terminal that is to be used by the debugger. */
231 void setTerminal(const QString
& term
) { m_inferiorTerminal
= term
; }
233 /** Returns the debugger driver. */
234 DebuggerDriver
* driver() { return m_d
; }
236 /** Returns the pid that the debugger is currently attached to. */
237 const QString
& attachedPid() const { return m_attachedPid
; }
240 void saveSettings(KConfig
*);
241 void restoreSettings(KConfig
*);
244 QString m_inferiorTerminal
;
245 QString m_debuggerCmd
; /* per-program setting */
246 QString m_generalDebuggerCmd
; /* global setting */
247 TTYLevel m_ttyLevel
; /* level of terminal emulation */
252 QList
<VarTree
> m_watchEvalExpr
; /* exprs to evaluate for watch windows */
253 QArray
<Breakpoint
*> m_brkpts
;
256 void parse(CmdQueueItem
* cmd
, const char* output
);
258 VarTree
* parseExpr(const char* output
, bool wantErrorValue
);
259 void handleRunCommands(const char* output
);
260 void updateAllExprs();
261 void updateProgEnvironment(const QString
& args
, const QString
& wd
,
262 const QDict
<EnvVar
>& newVars
);
263 void parseLocals(const char* output
, QList
<VarTree
>& newVars
);
264 void handleLocals(const char* output
);
265 bool handlePrint(CmdQueueItem
* cmd
, const char* output
);
266 void handleBacktrace(const char* output
);
267 void handleFrameChange(const char* output
);
268 void handleFindType(CmdQueueItem
* cmd
, const char* output
);
269 void handlePrintStruct(CmdQueueItem
* cmd
, const char* output
);
270 void handleSharedLibs(const char* output
);
271 void handleRegisters(const char* output
);
272 void handleInfoLine(CmdQueueItem
* cmd
, const char* output
);
273 void handleDisassemble(CmdQueueItem
* cmd
, const char* output
);
274 void handleThreadList(const char* output
);
275 void evalExpressions();
276 void evalInitialStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
277 void evalStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
278 void exprExpandingHelper(ExprWnd
* wnd
, KTreeViewItem
* item
, bool& allow
);
279 void dereferencePointer(ExprWnd
* wnd
, VarTree
* var
, bool immediate
);
280 void determineType(ExprWnd
* wnd
, VarTree
* var
);
281 void removeExpr(ExprWnd
* wnd
, VarTree
* var
);
282 CmdQueueItem
* loadCoreFile();
283 void openProgramConfig(const QString
& name
);
285 Breakpoint
* breakpointByFilePos(QString file
, int lineNo
,
286 const DbgAddr
& address
);
287 void newBreakpoint(const char* output
);
288 void updateBreakList(const char* output
);
289 bool haveTemporaryBP() const;
290 void saveBreakpoints(KSimpleConfig
* config
);
291 void restoreBreakpoints(KSimpleConfig
* config
);
293 bool m_haveExecutable
; /* has an executable been specified */
294 bool m_programActive
; /* is the program active (possibly halting in a brkpt)? */
295 bool m_programRunning
; /* is the program executing (not stopped)? */
296 bool m_sharedLibsListed
; /* do we know the shared libraries loaded by the prog? */
297 QString m_executable
;
299 QString m_attachedPid
; /* user input of attaching to pid */
300 QString m_programArgs
;
301 QString m_remoteDevice
;
302 QString m_programWD
; /* working directory of gdb */
303 QDict
<EnvVar
> m_envVars
; /* environment variables set by user */
304 QStrList m_sharedLibs
; /* shared libraries used by program */
305 ProgramTypeTable
* m_typeTable
; /* known types used by the program */
306 KSimpleConfig
* m_programConfig
; /* program-specific settings (brkpts etc) */
307 void saveProgramSettings();
308 void restoreProgramSettings();
312 bool m_explicitKill
; /* whether we are killing gdb ourselves */
314 QString m_statusMessage
;
317 void gdbExited(KProcess
*);
318 void slotInferiorRunning();
319 void backgroundUpdate();
321 void slotLocalsExpanding(KTreeViewItem
*, bool&);
322 void slotWatchExpanding(KTreeViewItem
*, bool&);
323 void slotUpdateAnimation();
324 void slotDeleteWatch();
325 void slotValuePopup(const QString
&);
326 void slotDisassemble(const QString
&, int);
333 * This signal is emitted before the debugger is started. The slot is
334 * supposed to set up m_inferiorTerminal.
336 void debuggerStarting();
339 * This signal is emitted whenever a part of the debugger needs to
340 * highlight the specfied source code line (e.g. when the program
343 * @param file specifies the file; this is not necessarily a full path
344 * name, and if it is relative, you won't know relative to what, you
346 * @param lineNo specifies the line number (0-based!) (this may be
347 * negative, in which case the file should be activated, but the line
348 * should NOT be changed).
349 * @param address specifies the exact address of the PC or is empty.
351 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
354 * This signal is emitted when a line decoration item (those thingies
355 * that indicate breakpoints) must be changed.
357 void lineItemsChanged();
360 * This signal is a special case of @ref #lineItemsChanged because it
361 * indicates that only the program counter has changed.
363 * @param filename specifies the filename where the program stopped
364 * @param lineNo specifies the line number (zero-based); it can be -1
366 * @param address specifies the address that the instruction pointer
368 * @param frameNo specifies the frame number: 0 is the innermost frame,
369 * positive numbers are frames somewhere up the stack (indicates points
370 * where a function was called); the latter cases should be indicated
371 * differently in the source window.
373 void updatePC(const QString
& filename
, int lineNo
,
374 const DbgAddr
& address
, int frameNo
);
377 * This signal is emitted when gdb detects that the executable has been
378 * updated, e.g. recompiled. (You usually need not handle this signal
379 * if you are the editor which changed the executable.)
381 void executableUpdated();
384 * This signal is emitted when the animated icon should advance to the
387 void animationTimeout();
390 * Indicates that a new status message is available.
392 void updateStatusMessage();
395 * Indicates that the internal state of the debugger has changed, and
396 * that this will very likely have an impact on the UI.
401 * Indicates that the list of breakpoints has possibly changed.
403 void breakpointsChanged();
406 * Indicates that the register values have possibly changed.
408 void registersChanged(QList
<RegisterInfo
>&);
411 * Indicates that the list of threads has possibly changed.
413 void threadsChanged(QList
<ThreadInfo
>&);
416 * Indicates that the value for a value popup is ready.
418 void valuePopup(const QString
&);
421 * Provides the disassembled code of the location given by file and
422 * line number (zero-based).
424 void disassembled(const QString
& file
, int line
, const QList
<DisassembledCode
>& code
);
427 * Indicates that the program has stopped for any reason: by a
428 * breakpoint, by a signal that the debugger driver caught, by a single
431 void programStopped();
434 ExprWnd
& m_localVariables
;
435 ExprWnd
& m_watchVariables
;
436 QListBox
& m_btWindow
;
439 QTimer m_animationTimer
;
440 int m_animationInterval
;
442 // implementation helpers
444 void startAnimation(bool fast
);
445 void stopAnimation();
447 QWidget
* parentWidget() { return static_cast<QWidget
*>(parent()); }
449 friend class BreakpointTable
;