Completed some commands.
[kdbg.git] / kdbg / debugger.h
blob8d708935cf7bbe53ba0bd6e6352f353382364520
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 <qstringlist.h>
12 #include "envvar.h"
13 #include "exprwnd.h" /* some compilers require this */
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
19 class ExprWnd;
20 class VarTree;
21 class ProgramTypeTable;
22 class KTreeViewItem;
23 class KConfig;
24 class KSimpleConfig;
25 class QListBox;
26 class RegisterInfo;
27 class ThreadInfo;
28 class DebuggerDriver;
29 class CmdQueueItem;
30 class Breakpoint;
31 struct DisassembledCode;
32 struct MemoryDump;
33 struct DbgAddr;
34 class KProcess;
37 class KDebugger : public QObject
39 Q_OBJECT
40 public:
41 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
42 ExprWnd* localVars,
43 ExprWnd* watchVars,
44 QListBox* backtrace);
45 ~KDebugger();
47 /**
48 * This function starts to debug the specified executable using the
49 * specified driver. If a program is currently being debugged, it is
50 * terminated first. Ownership of driver is taken if and only if
51 * true is returned.
53 * @return false if an error occurs.
55 bool debugProgram(const QString& executable,
56 DebuggerDriver* driver);
58 /**
59 * Uses the specified core to debug the active program.
60 * @param batch tells whether the core file was given on the
61 * command line.
63 void useCoreFile(QString corefile, bool batch);
65 /**
66 * Attaches to the specified process and debugs it.
68 void attachProgram(const QString& pid);
70 /**
71 * Returns the file name of the per-program config file for the
72 * specified program.
74 static QString getConfigForExe(const QString& exe);
76 /**
77 * The driver name entry in the per-program config file.
79 static const char DriverNameEntry[];
81 public slots:
82 /**
83 * Runs the program or continues it if it is stopped at a breakpoint.
85 void programRun();
87 /**
88 * Restarts the debuggee.
90 void programRunAgain();
92 /**
93 * Performs a single-step, possibly stepping into a function call.
94 * If byInsn is true, a step by instruction is performed.
96 void programStep();
98 /**
99 * Performs a single-step, stepping over a function call.
100 * If byInsn is true, a step by instruction is performed.
102 void programNext();
105 * Performs a single-step by instruction, possibly stepping into a
106 * function call.
108 void programStepi();
111 * Performs a single-step by instruction, stepping over a function
112 * call.
114 void programNexti();
117 * Runs the program until it returns from the current function.
119 void programFinish();
122 * Kills the program (removes it from memory).
124 void programKill();
127 * Interrupts the program if it is currently running.
129 void programBreak();
132 * Moves the program counter to the specified line.
133 * If an address is given, it is moved to the address.
135 void setProgramCounter(const QString&, int, const DbgAddr&);
137 public:
139 * Queries the user for program arguments.
141 void programArgs(QWidget* parent);
144 * Queries the user for program settings: Debugger command, terminal
145 * emulator.
147 void programSettings(QWidget* parent);
150 * Setup remote debugging device
152 void setRemoteDevice(const QString& remoteDevice) { m_remoteDevice = remoteDevice; }
155 * Run the debuggee until the specified line in the specified file is
156 * reached.
158 * @return false if the command was not executed, e.g. because the
159 * debuggee is running at the moment.
161 bool runUntil(const QString& fileName, int lineNo);
164 * Set a breakpoint.
166 * @param fileName The source file in which to set the breakpoint.
167 * @param lineNo The zero-based line number.
168 * @param address The exact address of the breakpoint.
169 * @param temporary Specifies whether this is a temporary breakpoint
170 * @return false if the command was not executed, e.g. because the
171 * debuggee is running at the moment.
173 bool setBreakpoint(QString fileName, int lineNo,
174 const DbgAddr& address, bool temporary);
177 * Enable or disable a breakpoint at the specified location.
179 * @param fileName The source file in which the breakpoint is.
180 * @param lineNo The zero-based line number.
181 * @param address The exact address of the breakpoint.
182 * @return false if the command was not executed, e.g. because the
183 * debuggee is running at the moment.
185 bool enableDisableBreakpoint(QString fileName, int lineNo,
186 const DbgAddr& address);
189 * Tells whether one of the single stepping commands can be invoked
190 * (step, next, finish, until, also run).
192 bool canSingleStep();
195 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
197 bool canChangeBreakpoints();
200 * Tells whether the debuggee can be changed.
202 bool canUseCoreFile() { return isReady() && !m_programActive; }
205 * Add a watch expression.
207 void addWatch(const QString& expr);
210 * Retrieves the current status message.
212 const QString& statusMessage() const { return m_statusMessage; }
215 * Is the debugger ready to receive another high-priority command?
217 bool isReady() const;
220 * Is the debuggee running (not just active)?
222 bool isProgramRunning() { return m_haveExecutable && m_programRunning; }
225 * Do we have an executable set?
227 bool haveExecutable() { return m_haveExecutable; }
230 * Is the debuggee active, i.e. was it started by the debugger?
232 bool isProgramActive() { return m_programActive; }
235 * Is the debugger driver idle?
237 bool isIdle() const;
239 /** The list of breakpoints. */
240 int numBreakpoints() const { return m_brkpts.size(); }
241 const Breakpoint* breakpoint(int i) const { return m_brkpts[i]; }
243 const QString& executable() const { return m_executable; }
246 * Terminal emulation level.
248 enum TTYLevel {
249 ttyNone = 0, /* ignore output, input triggers EOF */
250 ttySimpleOutputOnly = 1, /* minmal output emulation, input triggers EOF */
251 ttyFull = 7 /* program needs full emulation */
255 * Returns the level of terminal emulation requested by the inferior.
257 TTYLevel ttyLevel() const { return m_ttyLevel; }
259 /** Sets the terminal that is to be used by the debugger. */
260 void setTerminal(const QString& term) { m_inferiorTerminal = term; }
262 /** Returns the debugger driver. */
263 DebuggerDriver* driver() { return m_d; }
265 /** Returns the pid that the debugger is currently attached to. */
266 const QString& attachedPid() const { return m_attachedPid; }
269 * The memory at that the expression evaluates to is watched. Can be
270 * empty. Triggers a redisplay even if the expression did not change.
272 void setMemoryExpression(const QString& memexpr);
275 * Sets how the watched memory location is displayed.
276 * Call setMemoryExpression() to force a redisplay.
278 void setMemoryFormat(unsigned format) { m_memoryFormat = format; }
280 // settings
281 void saveSettings(KConfig*);
282 void restoreSettings(KConfig*);
284 protected:
285 QString m_inferiorTerminal;
286 QString m_debuggerCmd; /* per-program setting */
287 TTYLevel m_ttyLevel; /* level of terminal emulation */
288 bool startDriver();
289 void stopDriver();
290 void writeCommand();
292 QList<VarTree> m_watchEvalExpr; /* exprs to evaluate for watch windows */
293 QArray<Breakpoint*> m_brkpts;
294 QString m_memoryExpression; /* memory location to watch */
295 unsigned m_memoryFormat; /* how that output should look */
297 protected slots:
298 void parse(CmdQueueItem* cmd, const char* output);
299 protected:
300 VarTree* parseExpr(const char* output, bool wantErrorValue);
301 void handleRunCommands(const char* output);
302 void updateAllExprs();
303 void updateProgEnvironment(const QString& args, const QString& wd,
304 const QDict<EnvVar>& newVars,
305 const QStringList& newOptions);
306 void parseLocals(const char* output, QList<VarTree>& newVars);
307 void handleLocals(const char* output);
308 bool handlePrint(CmdQueueItem* cmd, const char* output);
309 void handleBacktrace(const char* output);
310 void handleFrameChange(const char* output);
311 void handleFindType(CmdQueueItem* cmd, const char* output);
312 void handlePrintStruct(CmdQueueItem* cmd, const char* output);
313 void handleSharedLibs(const char* output);
314 void handleRegisters(const char* output);
315 void handleMemoryDump(const char* output);
316 void handleInfoLine(CmdQueueItem* cmd, const char* output);
317 void handleDisassemble(CmdQueueItem* cmd, const char* output);
318 void handleThreadList(const char* output);
319 void handleSetPC(const char* output);
320 void evalExpressions();
321 void evalInitialStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
322 void evalStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
323 void exprExpandingHelper(ExprWnd* wnd, KTreeViewItem* item, bool& allow);
324 void dereferencePointer(ExprWnd* wnd, VarTree* var, bool immediate);
325 void determineType(ExprWnd* wnd, VarTree* var);
326 void removeExpr(ExprWnd* wnd, VarTree* var);
327 void queueMemoryDump(bool immediate);
328 CmdQueueItem* loadCoreFile();
329 void openProgramConfig(const QString& name);
331 Breakpoint* breakpointByFilePos(QString file, int lineNo,
332 const DbgAddr& address);
333 void newBreakpoint(const char* output);
334 void updateBreakList(const char* output);
335 bool stopMayChangeBreakList() const;
336 void saveBreakpoints(KSimpleConfig* config);
337 void restoreBreakpoints(KSimpleConfig* config);
339 bool m_haveExecutable; /* has an executable been specified */
340 bool m_programActive; /* is the program active (possibly halting in a brkpt)? */
341 bool m_programRunning; /* is the program executing (not stopped)? */
342 bool m_sharedLibsListed; /* do we know the shared libraries loaded by the prog? */
343 QString m_executable;
344 QString m_corefile;
345 QString m_attachedPid; /* user input of attaching to pid */
346 QString m_programArgs;
347 QString m_remoteDevice;
348 QString m_programWD; /* working directory of gdb */
349 QDict<EnvVar> m_envVars; /* environment variables set by user */
350 QStringList m_boolOptions; /* boolean options */
351 QStrList m_sharedLibs; /* shared libraries used by program */
352 ProgramTypeTable* m_typeTable; /* known types used by the program */
353 KSimpleConfig* m_programConfig; /* program-specific settings (brkpts etc) */
354 void saveProgramSettings();
355 void restoreProgramSettings();
357 // debugger process
358 DebuggerDriver* m_d;
359 bool m_explicitKill; /* whether we are killing gdb ourselves */
361 QString m_statusMessage;
363 protected slots:
364 void gdbExited(KProcess*);
365 void slotInferiorRunning();
366 void backgroundUpdate();
367 void gotoFrame(int);
368 void slotLocalsExpanding(KTreeViewItem*, bool&);
369 void slotWatchExpanding(KTreeViewItem*, bool&);
370 void slotUpdateAnimation();
371 void slotDeleteWatch();
372 void slotValuePopup(const QString&);
373 void slotDisassemble(const QString&, int);
374 public slots:
375 void setThread(int);
376 void shutdown();
378 signals:
380 * This signal is emitted before the debugger is started. The slot is
381 * supposed to set up m_inferiorTerminal.
383 void debuggerStarting();
386 * This signal is emitted whenever a part of the debugger needs to
387 * highlight the specfied source code line (e.g. when the program
388 * stops).
390 * @param file specifies the file; this is not necessarily a full path
391 * name, and if it is relative, you won't know relative to what, you
392 * can only guess.
393 * @param lineNo specifies the line number (0-based!) (this may be
394 * negative, in which case the file should be activated, but the line
395 * should NOT be changed).
396 * @param address specifies the exact address of the PC or is empty.
398 void activateFileLine(const QString& file, int lineNo, const DbgAddr& address);
401 * This signal is emitted when a line decoration item (those thingies
402 * that indicate breakpoints) must be changed.
404 void lineItemsChanged();
407 * This signal is a special case of @ref #lineItemsChanged because it
408 * indicates that only the program counter has changed.
410 * @param filename specifies the filename where the program stopped
411 * @param lineNo specifies the line number (zero-based); it can be -1
412 * if it is unknown
413 * @param address specifies the address that the instruction pointer
414 * points to.
415 * @param frameNo specifies the frame number: 0 is the innermost frame,
416 * positive numbers are frames somewhere up the stack (indicates points
417 * where a function was called); the latter cases should be indicated
418 * differently in the source window.
420 void updatePC(const QString& filename, int lineNo,
421 const DbgAddr& address, int frameNo);
424 * This signal is emitted when gdb detects that the executable has been
425 * updated, e.g. recompiled. (You usually need not handle this signal
426 * if you are the editor which changed the executable.)
428 void executableUpdated();
431 * This signal is emitted when the animated icon should advance to the
432 * next picture.
434 void animationTimeout();
437 * Indicates that a new status message is available.
439 void updateStatusMessage();
442 * Indicates that the internal state of the debugger has changed, and
443 * that this will very likely have an impact on the UI.
445 void updateUI();
448 * Indicates that the list of breakpoints has possibly changed.
450 void breakpointsChanged();
453 * Indicates that the register values have possibly changed.
455 void registersChanged(QList<RegisterInfo>&);
458 * Indicates that the list of threads has possibly changed.
460 void threadsChanged(QList<ThreadInfo>&);
463 * Indicates that the value for a value popup is ready.
465 void valuePopup(const QString&);
468 * Provides the disassembled code of the location given by file and
469 * line number (zero-based).
471 void disassembled(const QString& file, int line, const QList<DisassembledCode>& code);
474 * Indicates that the program has stopped for any reason: by a
475 * breakpoint, by a signal that the debugger driver caught, by a single
476 * step instruction.
478 void programStopped();
481 * Indicates that a new memory dump output is ready.
482 * @param msg is an error message or empty
483 * @param memdump is the memory dump
485 void memoryDumpChanged(const QString&, QList<MemoryDump>&);
488 * Gives other objects a chance to save program specific settings.
490 void saveProgramSpecific(KSimpleConfig* config);
493 * Gives other objects a chance to restore program specific settings.
495 void restoreProgramSpecific(KSimpleConfig* config);
497 protected:
498 ExprWnd& m_localVariables;
499 ExprWnd& m_watchVariables;
500 QListBox& m_btWindow;
502 // animation
503 QTimer m_animationTimer;
504 int m_animationInterval;
506 // implementation helpers
507 protected:
508 void startAnimation(bool fast);
509 void stopAnimation();
511 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
513 friend class BreakpointTable;
516 #endif // DEBUGGER_H