Support debugger drivers that use a regular expression to search for the prompt.
[kdbg.git] / kdbg / debugger.h
blob929e639eed079a4cf7ecfba90c29bd20d349e2d6
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 "envvar.h"
12 #include "exprwnd.h" /* some compilers require this */
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
18 class ExprWnd;
19 class VarTree;
20 class ProgramTypeTable;
21 class KTreeViewItem;
22 class KConfig;
23 class KSimpleConfig;
24 class QListBox;
25 class RegisterInfo;
26 class ThreadInfo;
27 class DebuggerDriver;
28 class CmdQueueItem;
29 class Breakpoint;
30 struct DisassembledCode;
31 struct MemoryDump;
32 struct DbgAddr;
33 class KProcess;
36 class KDebugger : public QObject
38 Q_OBJECT
39 public:
40 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
41 ExprWnd* localVars,
42 ExprWnd* watchVars,
43 QListBox* backtrace,
44 DebuggerDriver* driver
46 ~KDebugger();
48 /**
49 * This function starts to debug the specified executable. If a program
50 * is currently being debugged, it is terminated first.
52 * @return false if an error occurs.
54 bool debugProgram(const QString& executable);
56 /**
57 * Uses the specified core to debug the active program.
58 * @param batch tells whether the core file was given on the
59 * command line.
61 void useCoreFile(QString corefile, bool batch);
63 /**
64 * Attaches to the specified process and debugs it.
66 void attachProgram(const QString& pid);
68 public slots:
69 /**
70 * Runs the program or continues it if it is stopped at a breakpoint.
72 void programRun();
74 /**
75 * Restarts the debuggee.
77 void programRunAgain();
79 /**
80 * Performs a single-step, possibly stepping into a function call.
81 * If byInsn is true, a step by instruction is performed.
83 void programStep();
85 /**
86 * Performs a single-step, stepping over a function call.
87 * If byInsn is true, a step by instruction is performed.
89 void programNext();
91 /**
92 * Performs a single-step by instruction, possibly stepping into a
93 * function call.
95 void programStepi();
97 /**
98 * Performs a single-step by instruction, stepping over a function
99 * call.
101 void programNexti();
104 * Runs the program until it returns from the current function.
106 void programFinish();
109 * Kills the program (removes it from memory).
111 void programKill();
114 * Interrupts the program if it is currently running.
116 void programBreak();
118 public:
120 * Queries the user for program arguments.
122 void programArgs(QWidget* parent);
125 * Queries the user for program settings: Debugger command, terminal
126 * emulator.
128 void programSettings(QWidget* parent);
131 * Setup remote debugging device
133 void setRemoteDevice(const QString& remoteDevice) { m_remoteDevice = remoteDevice; }
136 * Run the debuggee until the specified line in the specified file is
137 * reached.
139 * @return false if the command was not executed, e.g. because the
140 * debuggee is running at the moment.
142 bool runUntil(const QString& fileName, int lineNo);
145 * Set a breakpoint.
147 * @param fileName The source file in which to set the breakpoint.
148 * @param lineNo The zero-based line number.
149 * @param address The exact address of the breakpoint.
150 * @param temporary Specifies whether this is a temporary breakpoint
151 * @return false if the command was not executed, e.g. because the
152 * debuggee is running at the moment.
154 bool setBreakpoint(QString fileName, int lineNo,
155 const DbgAddr& address, bool temporary);
158 * Enable or disable a breakpoint at the specified location.
160 * @param fileName The source file in which the breakpoint is.
161 * @param lineNo The zero-based line number.
162 * @param address The exact address of the breakpoint.
163 * @return false if the command was not executed, e.g. because the
164 * debuggee is running at the moment.
166 bool enableDisableBreakpoint(QString fileName, int lineNo,
167 const DbgAddr& address);
170 * Tells whether one of the single stepping commands can be invoked
171 * (step, next, finish, until, also run).
173 bool canSingleStep();
176 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
178 bool canChangeBreakpoints();
181 * Tells whether the debuggee can be changed.
183 bool canUseCoreFile() { return isReady() && !m_programActive; }
186 * Add a watch expression.
188 void addWatch(const QString& expr);
191 * Retrieves the current status message.
193 const QString& statusMessage() const { return m_statusMessage; }
196 * Is the debugger ready to receive another high-priority command?
198 bool isReady() const;
201 * Is the debuggee running (not just active)?
203 bool isProgramRunning() { return m_haveExecutable && m_programRunning; }
206 * Do we have an executable set?
208 bool haveExecutable() { return m_haveExecutable; }
211 * Is the debuggee active, i.e. was it started by the debugger?
213 bool isProgramActive() { return m_programActive; }
216 * Is the debugger driver idle?
218 bool isIdle() const;
220 /** The list of breakpoints. */
221 int numBreakpoints() const { return m_brkpts.size(); }
222 const Breakpoint* breakpoint(int i) const { return m_brkpts[i]; }
224 const QString& executable() const { return m_executable; }
227 * Sets the command to invoke gdb. If cmd is the empty string, the
228 * default is substituted.
230 void setDebuggerCmd(const QString& cmd)
231 { m_generalDebuggerCmd = cmd; }
234 * Terminal emulation level.
236 enum TTYLevel {
237 ttyNone = 0, /* ignore output, input triggers EOF */
238 ttySimpleOutputOnly = 1, /* minmal output emulation, input triggers EOF */
239 ttyFull = 7 /* program needs full emulation */
243 * Returns the level of terminal emulation requested by the inferior.
245 TTYLevel ttyLevel() const { return m_ttyLevel; }
247 /** Sets the terminal that is to be used by the debugger. */
248 void setTerminal(const QString& term) { m_inferiorTerminal = term; }
250 /** Returns the debugger driver. */
251 DebuggerDriver* driver() { return m_d; }
253 /** Returns the pid that the debugger is currently attached to. */
254 const QString& attachedPid() const { return m_attachedPid; }
257 * The memory at that the expression evaluates to is watched. Can be
258 * empty. Triggers a redisplay even if the expression did not change.
260 void setMemoryExpression(const QString& memexpr);
263 * Sets how the watched memory location is displayed.
264 * Call setMemoryExpression() to force a redisplay.
266 void setMemoryFormat(unsigned format) { m_memoryFormat = format; }
268 // settings
269 void saveSettings(KConfig*);
270 void restoreSettings(KConfig*);
272 protected:
273 QString m_inferiorTerminal;
274 QString m_debuggerCmd; /* per-program setting */
275 QString m_generalDebuggerCmd; /* global setting */
276 TTYLevel m_ttyLevel; /* level of terminal emulation */
277 bool startDriver();
278 void stopDriver();
279 void writeCommand();
281 QList<VarTree> m_watchEvalExpr; /* exprs to evaluate for watch windows */
282 QArray<Breakpoint*> m_brkpts;
283 QString m_memoryExpression; /* memory location to watch */
284 unsigned m_memoryFormat; /* how that output should look */
286 protected slots:
287 void parse(CmdQueueItem* cmd, const char* output);
288 protected:
289 VarTree* parseExpr(const char* output, bool wantErrorValue);
290 void handleRunCommands(const char* output);
291 void updateAllExprs();
292 void updateProgEnvironment(const QString& args, const QString& wd,
293 const QDict<EnvVar>& newVars);
294 void parseLocals(const char* output, QList<VarTree>& newVars);
295 void handleLocals(const char* output);
296 bool handlePrint(CmdQueueItem* cmd, const char* output);
297 void handleBacktrace(const char* output);
298 void handleFrameChange(const char* output);
299 void handleFindType(CmdQueueItem* cmd, const char* output);
300 void handlePrintStruct(CmdQueueItem* cmd, const char* output);
301 void handleSharedLibs(const char* output);
302 void handleRegisters(const char* output);
303 void handleMemoryDump(const char* output);
304 void handleInfoLine(CmdQueueItem* cmd, const char* output);
305 void handleDisassemble(CmdQueueItem* cmd, const char* output);
306 void handleThreadList(const char* output);
307 void evalExpressions();
308 void evalInitialStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
309 void evalStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
310 void exprExpandingHelper(ExprWnd* wnd, KTreeViewItem* item, bool& allow);
311 void dereferencePointer(ExprWnd* wnd, VarTree* var, bool immediate);
312 void determineType(ExprWnd* wnd, VarTree* var);
313 void removeExpr(ExprWnd* wnd, VarTree* var);
314 void queueMemoryDump(bool immediate);
315 CmdQueueItem* loadCoreFile();
316 void openProgramConfig(const QString& name);
318 Breakpoint* breakpointByFilePos(QString file, int lineNo,
319 const DbgAddr& address);
320 void newBreakpoint(const char* output);
321 void updateBreakList(const char* output);
322 bool stopMayChangeBreakList() const;
323 void saveBreakpoints(KSimpleConfig* config);
324 void restoreBreakpoints(KSimpleConfig* config);
326 bool m_haveExecutable; /* has an executable been specified */
327 bool m_programActive; /* is the program active (possibly halting in a brkpt)? */
328 bool m_programRunning; /* is the program executing (not stopped)? */
329 bool m_sharedLibsListed; /* do we know the shared libraries loaded by the prog? */
330 QString m_executable;
331 QString m_corefile;
332 QString m_attachedPid; /* user input of attaching to pid */
333 QString m_programArgs;
334 QString m_remoteDevice;
335 QString m_programWD; /* working directory of gdb */
336 QDict<EnvVar> m_envVars; /* environment variables set by user */
337 QStrList m_sharedLibs; /* shared libraries used by program */
338 ProgramTypeTable* m_typeTable; /* known types used by the program */
339 KSimpleConfig* m_programConfig; /* program-specific settings (brkpts etc) */
340 void saveProgramSettings();
341 void restoreProgramSettings();
343 // debugger process
344 DebuggerDriver* m_d;
345 bool m_explicitKill; /* whether we are killing gdb ourselves */
347 QString m_statusMessage;
349 protected slots:
350 void gdbExited(KProcess*);
351 void slotInferiorRunning();
352 void backgroundUpdate();
353 void gotoFrame(int);
354 void slotLocalsExpanding(KTreeViewItem*, bool&);
355 void slotWatchExpanding(KTreeViewItem*, bool&);
356 void slotUpdateAnimation();
357 void slotDeleteWatch();
358 void slotValuePopup(const QString&);
359 void slotDisassemble(const QString&, int);
360 public slots:
361 void setThread(int);
362 void shutdown();
364 signals:
366 * This signal is emitted before the debugger is started. The slot is
367 * supposed to set up m_inferiorTerminal.
369 void debuggerStarting();
372 * This signal is emitted whenever a part of the debugger needs to
373 * highlight the specfied source code line (e.g. when the program
374 * stops).
376 * @param file specifies the file; this is not necessarily a full path
377 * name, and if it is relative, you won't know relative to what, you
378 * can only guess.
379 * @param lineNo specifies the line number (0-based!) (this may be
380 * negative, in which case the file should be activated, but the line
381 * should NOT be changed).
382 * @param address specifies the exact address of the PC or is empty.
384 void activateFileLine(const QString& file, int lineNo, const DbgAddr& address);
387 * This signal is emitted when a line decoration item (those thingies
388 * that indicate breakpoints) must be changed.
390 void lineItemsChanged();
393 * This signal is a special case of @ref #lineItemsChanged because it
394 * indicates that only the program counter has changed.
396 * @param filename specifies the filename where the program stopped
397 * @param lineNo specifies the line number (zero-based); it can be -1
398 * if it is unknown
399 * @param address specifies the address that the instruction pointer
400 * points to.
401 * @param frameNo specifies the frame number: 0 is the innermost frame,
402 * positive numbers are frames somewhere up the stack (indicates points
403 * where a function was called); the latter cases should be indicated
404 * differently in the source window.
406 void updatePC(const QString& filename, int lineNo,
407 const DbgAddr& address, int frameNo);
410 * This signal is emitted when gdb detects that the executable has been
411 * updated, e.g. recompiled. (You usually need not handle this signal
412 * if you are the editor which changed the executable.)
414 void executableUpdated();
417 * This signal is emitted when the animated icon should advance to the
418 * next picture.
420 void animationTimeout();
423 * Indicates that a new status message is available.
425 void updateStatusMessage();
428 * Indicates that the internal state of the debugger has changed, and
429 * that this will very likely have an impact on the UI.
431 void updateUI();
434 * Indicates that the list of breakpoints has possibly changed.
436 void breakpointsChanged();
439 * Indicates that the register values have possibly changed.
441 void registersChanged(QList<RegisterInfo>&);
444 * Indicates that the list of threads has possibly changed.
446 void threadsChanged(QList<ThreadInfo>&);
449 * Indicates that the value for a value popup is ready.
451 void valuePopup(const QString&);
454 * Provides the disassembled code of the location given by file and
455 * line number (zero-based).
457 void disassembled(const QString& file, int line, const QList<DisassembledCode>& code);
460 * Indicates that the program has stopped for any reason: by a
461 * breakpoint, by a signal that the debugger driver caught, by a single
462 * step instruction.
464 void programStopped();
467 * Indicates that a new memory dump output is ready.
468 * @param msg is an error message or empty
469 * @param memdump is the memory dump
471 void memoryDumpChanged(const QString&, QList<MemoryDump>&);
474 * Gives other objects a chance to save program specific settings.
476 void saveProgramSpecific(KSimpleConfig* config);
479 * Gives other objects a chance to restore program specific settings.
481 void restoreProgramSpecific(KSimpleConfig* config);
483 protected:
484 ExprWnd& m_localVariables;
485 ExprWnd& m_watchVariables;
486 QListBox& m_btWindow;
488 // animation
489 QTimer m_animationTimer;
490 int m_animationInterval;
492 // implementation helpers
493 protected:
494 void startAnimation(bool fast);
495 void stopAnimation();
497 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
499 friend class BreakpointTable;
502 #endif // DEBUGGER_H