Converted the array of breakpoints to a QPtrVector.
[kdbg.git] / kdbg / debugger.h
blob33139f88dd6cd001670e2c180a7253a97e401093
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 KSimpleConfig;
26 class QListBox;
27 class RegisterInfo;
28 class ThreadInfo;
29 class DebuggerDriver;
30 class CmdQueueItem;
31 class Breakpoint;
32 struct DisassembledCode;
33 struct MemoryDump;
34 struct DbgAddr;
35 class KProcess;
38 class KDebugger : public QObject
40 Q_OBJECT
41 public:
42 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
43 ExprWnd* localVars,
44 ExprWnd* watchVars,
45 QListBox* backtrace);
46 ~KDebugger();
48 /**
49 * This function starts to debug the specified executable using the
50 * specified driver. If a program is currently being debugged, it is
51 * terminated first. Ownership of driver is taken if and only if
52 * true is returned.
54 * @return false if an error occurs.
56 bool debugProgram(const QString& executable,
57 DebuggerDriver* driver);
59 /**
60 * Uses the specified core to debug the active program.
61 * @param batch tells whether the core file was given on the
62 * command line.
64 void useCoreFile(QString corefile, bool batch);
66 /**
67 * Attaches to the specified process and debugs it.
69 void attachProgram(const QString& pid);
71 /**
72 * Returns the file name of the per-program config file for the
73 * specified program.
75 static QString getConfigForExe(const QString& exe);
77 /**
78 * The driver name entry in the per-program config file.
80 static const char DriverNameEntry[];
82 public slots:
83 /**
84 * Runs the program or continues it if it is stopped at a breakpoint.
86 void programRun();
88 /**
89 * Restarts the debuggee.
91 void programRunAgain();
93 /**
94 * Performs a single-step, possibly stepping into a function call.
95 * If byInsn is true, a step by instruction is performed.
97 void programStep();
99 /**
100 * Performs a single-step, stepping over a function call.
101 * If byInsn is true, a step by instruction is performed.
103 void programNext();
106 * Performs a single-step by instruction, possibly stepping into a
107 * function call.
109 void programStepi();
112 * Performs a single-step by instruction, stepping over a function
113 * call.
115 void programNexti();
118 * Runs the program until it returns from the current function.
120 void programFinish();
123 * Kills the program (removes it from memory).
125 void programKill();
128 * Interrupts the program if it is currently running.
130 void programBreak();
133 * Moves the program counter to the specified line.
134 * If an address is given, it is moved to the address.
136 void setProgramCounter(const QString&, int, const DbgAddr&);
138 public:
140 * Queries the user for program arguments.
142 void programArgs(QWidget* parent);
145 * Queries the user for program settings: Debugger command, terminal
146 * emulator.
148 void programSettings(QWidget* parent);
151 * Setup remote debugging device
153 void setRemoteDevice(const QString& remoteDevice) { m_remoteDevice = remoteDevice; }
156 * Run the debuggee until the specified line in the specified file is
157 * reached.
159 * @return false if the command was not executed, e.g. because the
160 * debuggee is running at the moment.
162 bool runUntil(const QString& fileName, int lineNo);
165 * Set a breakpoint.
167 * @param fileName The source file in which to set the breakpoint.
168 * @param lineNo The zero-based line number.
169 * @param address The exact address of the breakpoint.
170 * @param temporary Specifies whether this is a temporary breakpoint
171 * @return false if the command was not executed, e.g. because the
172 * debuggee is running at the moment.
174 bool setBreakpoint(QString fileName, int lineNo,
175 const DbgAddr& address, bool temporary);
178 * Enable or disable a breakpoint at the specified location.
180 * @param fileName The source file in which the breakpoint is.
181 * @param lineNo The zero-based line number.
182 * @param address The exact address of the breakpoint.
183 * @return false if the command was not executed, e.g. because the
184 * debuggee is running at the moment.
186 bool enableDisableBreakpoint(QString fileName, int lineNo,
187 const DbgAddr& address);
190 * Tells whether one of the single stepping commands can be invoked
191 * (step, next, finish, until, also run).
193 bool canSingleStep();
196 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
198 bool canChangeBreakpoints();
201 * Tells whether the debuggee can be changed.
203 bool canUseCoreFile() { return isReady() && !m_programActive; }
206 * Add a watch expression.
208 void addWatch(const QString& expr);
211 * Retrieves the current status message.
213 const QString& statusMessage() const { return m_statusMessage; }
216 * Is the debugger ready to receive another high-priority command?
218 bool isReady() const;
221 * Is the debuggee running (not just active)?
223 bool isProgramRunning() { return m_haveExecutable && m_programRunning; }
226 * Do we have an executable set?
228 bool haveExecutable() { return m_haveExecutable; }
231 * Is the debuggee active, i.e. was it started by the debugger?
233 bool isProgramActive() { return m_programActive; }
236 * Is the debugger driver idle?
238 bool isIdle() const;
240 /** The list of breakpoints. */
241 int numBreakpoints() const { return m_brkpts.count(); }
242 const Breakpoint* breakpoint(int i) const { return m_brkpts[i]; }
244 const QString& executable() const { return m_executable; }
247 * Terminal emulation level.
249 enum TTYLevel {
250 ttyNone = 0, /* ignore output, input triggers EOF */
251 ttySimpleOutputOnly = 1, /* minmal output emulation, input triggers EOF */
252 ttyFull = 7 /* program needs full emulation */
256 * Returns the level of terminal emulation requested by the inferior.
258 TTYLevel ttyLevel() const { return m_ttyLevel; }
260 /** Sets the terminal that is to be used by the debugger. */
261 void setTerminal(const QString& term) { m_inferiorTerminal = term; }
263 /** Returns the debugger driver. */
264 DebuggerDriver* driver() { return m_d; }
266 /** Returns the pid that the debugger is currently attached to. */
267 const QString& attachedPid() const { return m_attachedPid; }
270 * The memory at that the expression evaluates to is watched. Can be
271 * empty. Triggers a redisplay even if the expression did not change.
273 void setMemoryExpression(const QString& memexpr);
276 * Sets how the watched memory location is displayed.
277 * Call setMemoryExpression() to force a redisplay.
279 void setMemoryFormat(unsigned format) { m_memoryFormat = format; }
281 // settings
282 void saveSettings(KConfig*);
283 void restoreSettings(KConfig*);
285 protected:
286 QString m_inferiorTerminal;
287 QString m_debuggerCmd; /* per-program setting */
288 TTYLevel m_ttyLevel; /* level of terminal emulation */
289 bool startDriver();
290 void stopDriver();
291 void writeCommand();
293 QList<VarTree> m_watchEvalExpr; /* exprs to evaluate for watch windows */
294 QPtrVector<Breakpoint> m_brkpts;
295 QString m_memoryExpression; /* memory location to watch */
296 unsigned m_memoryFormat; /* how that output should look */
298 protected slots:
299 void parse(CmdQueueItem* cmd, const char* output);
300 protected:
301 VarTree* parseExpr(const char* output, bool wantErrorValue);
302 void handleRunCommands(const char* output);
303 void updateAllExprs();
304 void updateProgEnvironment(const QString& args, const QString& wd,
305 const QDict<EnvVar>& newVars,
306 const QStringList& newOptions);
307 void parseLocals(const char* output, QList<VarTree>& newVars);
308 void handleLocals(const char* output);
309 bool handlePrint(CmdQueueItem* cmd, const char* output);
310 void handleBacktrace(const char* output);
311 void handleFrameChange(const char* output);
312 void handleFindType(CmdQueueItem* cmd, const char* output);
313 void handlePrintStruct(CmdQueueItem* cmd, const char* output);
314 void handleSharedLibs(const char* output);
315 void handleRegisters(const char* output);
316 void handleMemoryDump(const char* output);
317 void handleInfoLine(CmdQueueItem* cmd, const char* output);
318 void handleDisassemble(CmdQueueItem* cmd, const char* output);
319 void handleThreadList(const char* output);
320 void handleSetPC(const char* output);
321 void evalExpressions();
322 void evalInitialStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
323 void evalStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
324 void exprExpandingHelper(ExprWnd* wnd, KTreeViewItem* item, bool& allow);
325 void dereferencePointer(ExprWnd* wnd, VarTree* var, bool immediate);
326 void determineType(ExprWnd* wnd, VarTree* var);
327 void removeExpr(ExprWnd* wnd, VarTree* var);
328 void queueMemoryDump(bool immediate);
329 CmdQueueItem* loadCoreFile();
330 void openProgramConfig(const QString& name);
332 Breakpoint* breakpointByFilePos(QString file, int lineNo,
333 const DbgAddr& address);
334 void newBreakpoint(CmdQueueItem* cmd, const char* output);
335 void updateBreakList(const char* output);
336 bool stopMayChangeBreakList() const;
337 void saveBreakpoints(KSimpleConfig* config);
338 void restoreBreakpoints(KSimpleConfig* config);
340 bool m_haveExecutable; /* has an executable been specified */
341 bool m_programActive; /* is the program active (possibly halting in a brkpt)? */
342 bool m_programRunning; /* is the program executing (not stopped)? */
343 bool m_sharedLibsListed; /* do we know the shared libraries loaded by the prog? */
344 QString m_executable;
345 QString m_corefile;
346 QString m_attachedPid; /* user input of attaching to pid */
347 QString m_programArgs;
348 QString m_remoteDevice;
349 QString m_programWD; /* working directory of gdb */
350 QDict<EnvVar> m_envVars; /* environment variables set by user */
351 QStringList m_boolOptions; /* boolean options */
352 QStrList m_sharedLibs; /* shared libraries used by program */
353 ProgramTypeTable* m_typeTable; /* known types used by the program */
354 KSimpleConfig* m_programConfig; /* program-specific settings (brkpts etc) */
355 void saveProgramSettings();
356 void restoreProgramSettings();
358 // debugger process
359 DebuggerDriver* m_d;
360 bool m_explicitKill; /* whether we are killing gdb ourselves */
362 QString m_statusMessage;
364 protected slots:
365 void gdbExited(KProcess*);
366 void slotInferiorRunning();
367 void backgroundUpdate();
368 void gotoFrame(int);
369 void slotLocalsExpanding(KTreeViewItem*, bool&);
370 void slotWatchExpanding(KTreeViewItem*, bool&);
371 void slotUpdateAnimation();
372 void slotDeleteWatch();
373 void slotValuePopup(const QString&);
374 void slotDisassemble(const QString&, int);
375 public slots:
376 void setThread(int);
377 void shutdown();
379 signals:
381 * This signal is emitted before the debugger is started. The slot is
382 * supposed to set up m_inferiorTerminal.
384 void debuggerStarting();
387 * This signal is emitted whenever a part of the debugger needs to
388 * highlight the specfied source code line (e.g. when the program
389 * stops).
391 * @param file specifies the file; this is not necessarily a full path
392 * name, and if it is relative, you won't know relative to what, you
393 * can only guess.
394 * @param lineNo specifies the line number (0-based!) (this may be
395 * negative, in which case the file should be activated, but the line
396 * should NOT be changed).
397 * @param address specifies the exact address of the PC or is empty.
399 void activateFileLine(const QString& file, int lineNo, const DbgAddr& address);
402 * This signal is emitted when a line decoration item (those thingies
403 * that indicate breakpoints) must be changed.
405 void lineItemsChanged();
408 * This signal is a special case of @ref #lineItemsChanged because it
409 * indicates that only the program counter has changed.
411 * @param filename specifies the filename where the program stopped
412 * @param lineNo specifies the line number (zero-based); it can be -1
413 * if it is unknown
414 * @param address specifies the address that the instruction pointer
415 * points to.
416 * @param frameNo specifies the frame number: 0 is the innermost frame,
417 * positive numbers are frames somewhere up the stack (indicates points
418 * where a function was called); the latter cases should be indicated
419 * differently in the source window.
421 void updatePC(const QString& filename, int lineNo,
422 const DbgAddr& address, int frameNo);
425 * This signal is emitted when gdb detects that the executable has been
426 * updated, e.g. recompiled. (You usually need not handle this signal
427 * if you are the editor which changed the executable.)
429 void executableUpdated();
432 * This signal is emitted when the animated icon should advance to the
433 * next picture.
435 void animationTimeout();
438 * Indicates that a new status message is available.
440 void updateStatusMessage();
443 * Indicates that the internal state of the debugger has changed, and
444 * that this will very likely have an impact on the UI.
446 void updateUI();
449 * Indicates that the list of breakpoints has possibly changed.
451 void breakpointsChanged();
454 * Indicates that the register values have possibly changed.
456 void registersChanged(QList<RegisterInfo>&);
459 * Indicates that the list of threads has possibly changed.
461 void threadsChanged(QList<ThreadInfo>&);
464 * Indicates that the value for a value popup is ready.
466 void valuePopup(const QString&);
469 * Provides the disassembled code of the location given by file and
470 * line number (zero-based).
472 void disassembled(const QString& file, int line, const QList<DisassembledCode>& code);
475 * Indicates that the program has stopped for any reason: by a
476 * breakpoint, by a signal that the debugger driver caught, by a single
477 * step instruction.
479 void programStopped();
482 * Indicates that a new memory dump output is ready.
483 * @param msg is an error message or empty
484 * @param memdump is the memory dump
486 void memoryDumpChanged(const QString&, QList<MemoryDump>&);
489 * Gives other objects a chance to save program specific settings.
491 void saveProgramSpecific(KSimpleConfig* config);
494 * Gives other objects a chance to restore program specific settings.
496 void restoreProgramSpecific(KSimpleConfig* config);
498 protected:
499 ExprWnd& m_localVariables;
500 ExprWnd& m_watchVariables;
501 QListBox& m_btWindow;
503 // animation
504 QTimer m_animationTimer;
505 int m_animationInterval;
507 // implementation helpers
508 protected:
509 void startAnimation(bool fast);
510 void stopAnimation();
512 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
514 friend class BreakpointTable;
517 #endif // DEBUGGER_H