Bumped version number.
[kdbg.git] / kdbg / debugger.h
blob42cb3e3f213079960cfabcee75e2cd10c974441e
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #ifndef DEBUGGER_H
7 #define DEBUGGER_H
9 #include <qtimer.h>
10 #include <qdict.h>
11 #include <qptrvector.h>
12 #include <qstringlist.h>
13 #include "envvar.h"
14 #include "exprwnd.h" /* some compilers require this */
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
20 class ExprWnd;
21 class VarTree;
22 class ProgramTypeTable;
23 class KTreeViewItem;
24 class KConfig;
25 class KConfigBase;
26 class ProgramConfig;
27 class QListBox;
28 class RegisterInfo;
29 class ThreadInfo;
30 class DebuggerDriver;
31 class CmdQueueItem;
32 class Breakpoint;
33 struct DisassembledCode;
34 struct MemoryDump;
35 struct DbgAddr;
36 class KProcess;
39 class KDebugger : public QObject
41 Q_OBJECT
42 public:
43 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
44 ExprWnd* localVars,
45 ExprWnd* watchVars,
46 QListBox* backtrace);
47 ~KDebugger();
49 /**
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
53 * true is returned.
55 * @return false if an error occurs.
57 bool debugProgram(const QString& executable,
58 DebuggerDriver* driver);
60 /**
61 * Uses the specified core to debug the active program.
62 * @param batch tells whether the core file was given on the
63 * command line.
65 void useCoreFile(QString corefile, bool batch);
67 /**
68 * Attaches to the specified process and debugs it.
70 void attachProgram(const QString& pid);
72 /**
73 * Returns the file name of the per-program config file for the
74 * specified program.
76 static QString getConfigForExe(const QString& exe);
78 /**
79 * The driver name entry in the per-program config file.
81 static const char DriverNameEntry[];
83 public slots:
84 /**
85 * Runs the program or continues it if it is stopped at a breakpoint.
87 void programRun();
89 /**
90 * Restarts the debuggee.
92 void programRunAgain();
94 /**
95 * Performs a single-step, possibly stepping into a function call.
96 * If byInsn is true, a step by instruction is performed.
98 void programStep();
101 * Performs a single-step, stepping over a function call.
102 * If byInsn is true, a step by instruction is performed.
104 void programNext();
107 * Performs a single-step by instruction, possibly stepping into a
108 * function call.
110 void programStepi();
113 * Performs a single-step by instruction, stepping over a function
114 * call.
116 void programNexti();
119 * Runs the program until it returns from the current function.
121 void programFinish();
124 * Kills the program (removes it from memory).
126 void programKill();
129 * Interrupts the program if it is currently running.
131 void programBreak();
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&);
139 public:
141 * Queries the user for program arguments.
143 void programArgs(QWidget* parent);
146 * Queries the user for program settings: Debugger command, terminal
147 * emulator.
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
158 * reached.
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);
166 * Set a breakpoint.
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);
179 * Set a breakpoint.
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,
224 int ignoreCount);
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?
275 bool isIdle() const;
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.
291 enum TTYLevel {
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; }
311 /** Edit a value */
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; }
326 // settings
327 void saveSettings(KConfig*);
328 void restoreSettings(KConfig*);
330 protected:
331 QString m_inferiorTerminal;
332 QString m_debuggerCmd; /* per-program setting */
333 TTYLevel m_ttyLevel; /* level of terminal emulation */
334 bool startDriver();
335 void stopDriver();
336 void writeCommand();
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 */
343 protected slots:
344 void parse(CmdQueueItem* cmd, const char* output);
345 protected:
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;
390 QString m_corefile;
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();
404 // debugger process
405 DebuggerDriver* m_d;
406 bool m_explicitKill; /* whether we are killing gdb ourselves */
408 QString m_statusMessage;
410 protected slots:
411 void gdbExited(KProcess*);
412 void slotInferiorRunning();
413 void backgroundUpdate();
414 void gotoFrame(int);
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&);
422 public slots:
423 void setThread(int);
424 void shutdown();
426 signals:
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
436 * stops).
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
440 * can only guess.
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
453 * if it is unknown
454 * @param address specifies the address that the instruction pointer
455 * points to.
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
473 * next picture.
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.
486 void updateUI();
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
517 * step instruction.
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);
538 protected:
539 ExprWnd& m_localVariables;
540 ExprWnd& m_watchVariables;
541 QListBox& m_btWindow;
543 // animation
544 QTimer m_animationTimer;
545 int m_animationInterval;
547 // implementation helpers
548 protected:
549 void startAnimation(bool fast);
550 void stopAnimation();
552 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
554 friend class BreakpointTable;
557 #endif // DEBUGGER_H