3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
11 #include <qptrvector.h>
12 #include <qstringlist.h>
14 #include "exprwnd.h" /* some compilers require this */
22 class ProgramTypeTable
;
33 struct DisassembledCode
;
39 class KDebugger
: public QObject
43 KDebugger(QWidget
* parent
, /* will be used as the parent for dialogs */
50 * This function starts to debug the specified executable using the
51 * specified driver. If a program is currently being debugged, it is
52 * terminated first. Ownership of driver is taken if and only if
55 * @return false if an error occurs.
57 bool debugProgram(const QString
& executable
,
58 DebuggerDriver
* driver
);
61 * Uses the specified core to debug the active program.
62 * @param batch tells whether the core file was given on the
65 void useCoreFile(QString corefile
, bool batch
);
68 * Attaches to the specified process and debugs it.
70 void attachProgram(const QString
& pid
);
73 * Returns the file name of the per-program config file for the
76 static QString
getConfigForExe(const QString
& exe
);
79 * The driver name entry in the per-program config file.
81 static const char DriverNameEntry
[];
85 * Runs the program or continues it if it is stopped at a breakpoint.
90 * Restarts the debuggee.
92 void programRunAgain();
95 * Performs a single-step, possibly stepping into a function call.
96 * If byInsn is true, a step by instruction is performed.
101 * Performs a single-step, stepping over a function call.
102 * If byInsn is true, a step by instruction is performed.
107 * Performs a single-step by instruction, possibly stepping into a
113 * Performs a single-step by instruction, stepping over a function
119 * Runs the program until it returns from the current function.
121 void programFinish();
124 * Kills the program (removes it from memory).
129 * Interrupts the program if it is currently running.
134 * Moves the program counter to the specified line.
135 * If an address is given, it is moved to the address.
137 void setProgramCounter(const QString
&, int, const DbgAddr
&);
141 * Queries the user for program arguments.
143 void programArgs(QWidget
* parent
);
146 * Queries the user for program settings: Debugger command, terminal
149 void programSettings(QWidget
* parent
);
152 * Setup remote debugging device
154 void setRemoteDevice(const QString
& remoteDevice
) { m_remoteDevice
= remoteDevice
; }
157 * Run the debuggee until the specified line in the specified file is
160 * @return false if the command was not executed, e.g. because the
161 * debuggee is running at the moment.
163 bool runUntil(const QString
& fileName
, int lineNo
);
168 * @param fileName The source file in which to set the breakpoint.
169 * @param lineNo The zero-based line number.
170 * @param address The exact address of the breakpoint.
171 * @param temporary Specifies whether this is a temporary breakpoint
172 * @return false if the command was not executed, e.g. because the
173 * debuggee is running at the moment.
175 bool setBreakpoint(QString fileName
, int lineNo
,
176 const DbgAddr
& address
, bool temporary
);
181 * @param bp Describes the breakpoint.
182 * @param queueOnly If false, the breakpoint is set using a high-priority command.
184 void setBreakpoint(Breakpoint
* bp
, bool queueOnly
);
187 * Enable or disable a breakpoint at the specified location.
189 * @param fileName The source file in which the breakpoint is.
190 * @param lineNo The zero-based line number.
191 * @param address The exact address of the breakpoint.
192 * @return false if the command was not executed, e.g. because the
193 * debuggee is running at the moment.
195 bool enableDisableBreakpoint(QString fileName
, int lineNo
,
196 const DbgAddr
& address
);
199 * Enables or disables the specified breakpoint.
201 * @return false if the command was not executed, e.g. because the
202 * debuggee is running at the moment.
204 bool enableDisableBreakpoint(Breakpoint
* bp
);
207 * Removes the specified breakpoint. Note that if bp is an orphaned
208 * breakpoint, then bp is an invalid pointer if (and only if) this
209 * function returns true.
211 * @return false if the command was not executed, e.g. because the
212 * debuggee is running at the moment.
214 bool deleteBreakpoint(Breakpoint
* bp
);
217 * Changes the specified breakpoint's condition and ignore count.
219 * @return false if the command was not executed, e.g. because the
220 * debuggee is running at the moment.
222 bool conditionalBreakpoint(Breakpoint
* bp
,
223 const QString
& condition
,
227 * Tells whether one of the single stepping commands can be invoked
228 * (step, next, finish, until, also run).
230 bool canSingleStep();
233 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
235 bool canChangeBreakpoints();
238 * Tells whether the debuggee can be changed.
240 bool canUseCoreFile() { return isReady() && !m_programActive
; }
243 * Add a watch expression.
245 void addWatch(const QString
& expr
);
248 * Retrieves the current status message.
250 const QString
& statusMessage() const { return m_statusMessage
; }
253 * Is the debugger ready to receive another high-priority command?
255 bool isReady() const;
258 * Is the debuggee running (not just active)?
260 bool isProgramRunning() { return m_haveExecutable
&& m_programRunning
; }
263 * Do we have an executable set?
265 bool haveExecutable() { return m_haveExecutable
; }
268 * Is the debuggee active, i.e. was it started by the debugger?
270 bool isProgramActive() { return m_programActive
; }
273 * Is the debugger driver idle?
277 /** The list of breakpoints. */
278 int numBreakpoints() const { return m_brkpts
.size(); }
279 const Breakpoint
* breakpoint(int i
) const { return m_brkpts
[i
]; }
282 * Returns the breakpoint with the specified \a id.
284 Breakpoint
* breakpointById(int id
);
286 const QString
& executable() const { return m_executable
; }
289 * Terminal emulation level.
292 ttyNone
= 0, /* ignore output, input triggers EOF */
293 ttySimpleOutputOnly
= 1, /* minmal output emulation, input triggers EOF */
294 ttyFull
= 7 /* program needs full emulation */
298 * Returns the level of terminal emulation requested by the inferior.
300 TTYLevel
ttyLevel() const { return m_ttyLevel
; }
302 /** Sets the terminal that is to be used by the debugger. */
303 void setTerminal(const QString
& term
) { m_inferiorTerminal
= term
; }
305 /** Returns the debugger driver. */
306 DebuggerDriver
* driver() { return m_d
; }
308 /** Returns the pid that the debugger is currently attached to. */
309 const QString
& attachedPid() const { return m_attachedPid
; }
312 void editLocalValue(int row
);
315 * The memory at that the expression evaluates to is watched. Can be
316 * empty. Triggers a redisplay even if the expression did not change.
318 void setMemoryExpression(const QString
& memexpr
);
321 * Sets how the watched memory location is displayed.
322 * Call setMemoryExpression() to force a redisplay.
324 void setMemoryFormat(unsigned format
) { m_memoryFormat
= format
; }
327 void saveSettings(KConfig
*);
328 void restoreSettings(KConfig
*);
331 QString m_inferiorTerminal
;
332 QString m_debuggerCmd
; /* per-program setting */
333 TTYLevel m_ttyLevel
; /* level of terminal emulation */
338 QList
<VarTree
> m_watchEvalExpr
; /* exprs to evaluate for watch windows */
339 QPtrVector
<Breakpoint
> m_brkpts
;
340 QString m_memoryExpression
; /* memory location to watch */
341 unsigned m_memoryFormat
; /* how that output should look */
344 void parse(CmdQueueItem
* cmd
, const char* output
);
346 VarTree
* parseExpr(const char* output
, bool wantErrorValue
);
347 void handleRunCommands(const char* output
);
348 void updateAllExprs();
349 void updateProgEnvironment(const QString
& args
, const QString
& wd
,
350 const QDict
<EnvVar
>& newVars
,
351 const QStringList
& newOptions
);
352 void parseLocals(const char* output
, QList
<VarTree
>& newVars
);
353 void handleLocals(const char* output
);
354 bool handlePrint(CmdQueueItem
* cmd
, const char* output
);
355 void handleBacktrace(const char* output
);
356 void handleFrameChange(const char* output
);
357 void handleFindType(CmdQueueItem
* cmd
, const char* output
);
358 void handlePrintStruct(CmdQueueItem
* cmd
, const char* output
);
359 void handleSharedLibs(const char* output
);
360 void handleRegisters(const char* output
);
361 void handleMemoryDump(const char* output
);
362 void handleInfoLine(CmdQueueItem
* cmd
, const char* output
);
363 void handleDisassemble(CmdQueueItem
* cmd
, const char* output
);
364 void handleThreadList(const char* output
);
365 void handleSetPC(const char* output
);
366 void evalExpressions();
367 void evalInitialStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
368 void evalStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
369 void exprExpandingHelper(ExprWnd
* wnd
, KTreeViewItem
* item
, bool& allow
);
370 void dereferencePointer(ExprWnd
* wnd
, VarTree
* var
, bool immediate
);
371 void determineType(ExprWnd
* wnd
, VarTree
* var
);
372 void removeExpr(ExprWnd
* wnd
, VarTree
* var
);
373 void queueMemoryDump(bool immediate
);
374 CmdQueueItem
* loadCoreFile();
375 void openProgramConfig(const QString
& name
);
377 Breakpoint
* breakpointByFilePos(QString file
, int lineNo
,
378 const DbgAddr
& address
);
379 void newBreakpoint(CmdQueueItem
* cmd
, const char* output
);
380 void updateBreakList(const char* output
);
381 bool stopMayChangeBreakList() const;
382 void saveBreakpoints(ProgramConfig
* config
);
383 void restoreBreakpoints(ProgramConfig
* config
);
385 bool m_haveExecutable
; /* has an executable been specified */
386 bool m_programActive
; /* is the program active (possibly halting in a brkpt)? */
387 bool m_programRunning
; /* is the program executing (not stopped)? */
388 bool m_sharedLibsListed
; /* do we know the shared libraries loaded by the prog? */
389 QString m_executable
;
391 QString m_attachedPid
; /* user input of attaching to pid */
392 QString m_programArgs
;
393 QString m_remoteDevice
;
394 QString m_programWD
; /* working directory of gdb */
395 QDict
<EnvVar
> m_envVars
; /* environment variables set by user */
396 QStringList m_boolOptions
; /* boolean options */
397 QStrList m_sharedLibs
; /* shared libraries used by program */
398 ProgramTypeTable
* m_typeTable
; /* known types used by the program */
399 ProgramConfig
* m_programConfig
; /* program-specific settings (brkpts etc) */
400 void saveProgramSettings();
401 void restoreProgramSettings();
402 QString
readDebuggerCmd();
406 bool m_explicitKill
; /* whether we are killing gdb ourselves */
408 QString m_statusMessage
;
411 void gdbExited(KProcess
*);
412 void slotInferiorRunning();
413 void backgroundUpdate();
415 void slotLocalsExpanding(KTreeViewItem
*, bool&);
416 void slotWatchExpanding(KTreeViewItem
*, bool&);
417 void slotUpdateAnimation();
418 void slotDeleteWatch();
419 void slotValuePopup(const QString
&);
420 void slotDisassemble(const QString
&, int);
421 void slotLocalsValueEdited(int, const QString
&);
428 * This signal is emitted before the debugger is started. The slot is
429 * supposed to set up m_inferiorTerminal.
431 void debuggerStarting();
434 * This signal is emitted whenever a part of the debugger needs to
435 * highlight the specfied source code line (e.g. when the program
438 * @param file specifies the file; this is not necessarily a full path
439 * name, and if it is relative, you won't know relative to what, you
441 * @param lineNo specifies the line number (0-based!) (this may be
442 * negative, in which case the file should be activated, but the line
443 * should NOT be changed).
444 * @param address specifies the exact address of the PC or is empty.
446 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
449 * This signal indicates that the program counter has changed.
451 * @param filename specifies the filename where the program stopped
452 * @param lineNo specifies the line number (zero-based); it can be -1
454 * @param address specifies the address that the instruction pointer
456 * @param frameNo specifies the frame number: 0 is the innermost frame,
457 * positive numbers are frames somewhere up the stack (indicates points
458 * where a function was called); the latter cases should be indicated
459 * differently in the source window.
461 void updatePC(const QString
& filename
, int lineNo
,
462 const DbgAddr
& address
, int frameNo
);
465 * This signal is emitted when gdb detects that the executable has been
466 * updated, e.g. recompiled. (You usually need not handle this signal
467 * if you are the editor which changed the executable.)
469 void executableUpdated();
472 * This signal is emitted when the animated icon should advance to the
475 void animationTimeout();
478 * Indicates that a new status message is available.
480 void updateStatusMessage();
483 * Indicates that the internal state of the debugger has changed, and
484 * that this will very likely have an impact on the UI.
489 * Indicates that the list of breakpoints has possibly changed.
491 void breakpointsChanged();
494 * Indicates that the register values have possibly changed.
496 void registersChanged(QList
<RegisterInfo
>&);
499 * Indicates that the list of threads has possibly changed.
501 void threadsChanged(QList
<ThreadInfo
>&);
504 * Indicates that the value for a value popup is ready.
506 void valuePopup(const QString
&);
509 * Provides the disassembled code of the location given by file and
510 * line number (zero-based).
512 void disassembled(const QString
& file
, int line
, const QList
<DisassembledCode
>& code
);
515 * Indicates that the program has stopped for any reason: by a
516 * breakpoint, by a signal that the debugger driver caught, by a single
519 void programStopped();
522 * Indicates that a new memory dump output is ready.
523 * @param msg is an error message or empty
524 * @param memdump is the memory dump
526 void memoryDumpChanged(const QString
&, QList
<MemoryDump
>&);
529 * Gives other objects a chance to save program specific settings.
531 void saveProgramSpecific(KConfigBase
* config
);
534 * Gives other objects a chance to restore program specific settings.
536 void restoreProgramSpecific(KConfigBase
* config
);
539 ExprWnd
& m_localVariables
;
540 ExprWnd
& m_watchVariables
;
541 QListBox
& m_btWindow
;
544 QTimer m_animationTimer
;
545 int m_animationInterval
;
547 // implementation helpers
549 void startAnimation(bool fast
);
550 void stopAnimation();
552 QWidget
* parentWidget() { return static_cast<QWidget
*>(parent()); }
554 friend class BreakpointTable
;