When an item having the current item is taken out from the tree,
[kdbg.git] / kdbg / debugger.h
blob6ccd731b943fd309c4610db4c11ba083e082b9c0
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 class DisassembledCode;
31 struct DbgAddr;
32 class KProcess;
35 class KDebugger : public QObject
37 Q_OBJECT
38 public:
39 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
40 ExprWnd* localVars,
41 ExprWnd* watchVars,
42 QListBox* backtrace,
43 DebuggerDriver* driver
45 ~KDebugger();
47 /**
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);
55 /**
56 * Uses the specified core to debug the active program.
57 * @param batch tells whether the core file was given on the
58 * command line.
60 void useCoreFile(QString corefile, bool batch);
62 /**
63 * Runs the program or continues it if it is stopped at a breakpoint.
65 void programRun();
67 /**
68 * Attaches to the specified process and debugs it.
70 void attachProgram(const QString& pid);
72 /**
73 * Restarts the debuggee.
75 void programRunAgain();
77 /**
78 * Performs a single-step, possibly stepping into a function call.
80 void programStep();
82 /**
83 * Performs a single-step, stepping over a function call.
85 void programNext();
87 /**
88 * Runs the program until it returns from the current function.
90 void programFinish();
92 /**
93 * Kills the program (removes it from memory).
95 void programKill();
97 /**
98 * Interrupts the program if it is currently running.
100 void programBreak();
103 * Queries the user for program arguments.
105 void programArgs(QWidget* parent);
108 * Queries the user for program settings: Debugger command, terminal
109 * emulator.
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
120 * reached.
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);
128 * Set a breakpoint.
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?
201 bool isIdle() const;
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.
219 enum TTYLevel {
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; }
239 // settings
240 void saveSettings(KConfig*);
241 void restoreSettings(KConfig*);
243 protected:
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 */
248 bool startDriver();
249 void stopDriver();
250 void writeCommand();
252 QList<VarTree> m_watchEvalExpr; /* exprs to evaluate for watch windows */
253 QArray<Breakpoint*> m_brkpts;
255 protected slots:
256 void parse(CmdQueueItem* cmd, const char* output);
257 protected:
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;
298 QString m_corefile;
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();
310 // debugger process
311 DebuggerDriver* m_d;
312 bool m_explicitKill; /* whether we are killing gdb ourselves */
314 QString m_statusMessage;
316 protected slots:
317 void gdbExited(KProcess*);
318 void slotInferiorRunning();
319 void backgroundUpdate();
320 void gotoFrame(int);
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);
327 public slots:
328 void setThread(int);
329 void shutdown();
331 signals:
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
341 * stops).
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
345 * can only guess.
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
365 * if it is unknown
366 * @param address specifies the address that the instruction pointer
367 * points to.
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
385 * next picture.
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.
398 void updateUI();
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
429 * step instruction.
431 void programStopped();
433 protected:
434 ExprWnd& m_localVariables;
435 ExprWnd& m_watchVariables;
436 QListBox& m_btWindow;
438 // animation
439 QTimer m_animationTimer;
440 int m_animationInterval;
442 // implementation helpers
443 protected:
444 void startAnimation(bool fast);
445 void stopAnimation();
447 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
449 friend class BreakpointTable;
452 #endif // DEBUGGER_H