Change ValueEdit widget to remember the item instead of the row number.
[kdbg.git] / kdbg / debugger.h
blob513ca418cdfc8bfda4ce596fb312251a01ed048b
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 struct ExprValue;
23 class ProgramTypeTable;
24 class KTreeViewItem;
25 class KConfig;
26 class KConfigBase;
27 class ProgramConfig;
28 class QListBox;
29 class RegisterInfo;
30 class ThreadInfo;
31 class DebuggerDriver;
32 class CmdQueueItem;
33 class Breakpoint;
34 struct DisassembledCode;
35 struct MemoryDump;
36 struct DbgAddr;
37 class KProcess;
40 class KDebugger : public QObject
42 Q_OBJECT
43 public:
44 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
45 ExprWnd* localVars,
46 ExprWnd* watchVars,
47 QListBox* backtrace);
48 ~KDebugger();
50 /**
51 * This function starts to debug the specified executable using the
52 * specified driver. If a program is currently being debugged, it is
53 * terminated first. Ownership of driver is taken if and only if
54 * true is returned.
56 * @return false if an error occurs.
58 bool debugProgram(const QString& executable,
59 DebuggerDriver* driver);
61 /**
62 * Uses the specified core to debug the active program.
63 * @param batch tells whether the core file was given on the
64 * command line.
66 void useCoreFile(QString corefile, bool batch);
68 /**
69 * Uses the specified pid to attach to the active program.
71 void setAttachPid(const QString& pid);
73 /**
74 * Attaches to the specified process and debugs it.
76 void attachProgram(const QString& pid);
78 /**
79 * Returns the file name of the per-program config file for the
80 * specified program.
82 static QString getConfigForExe(const QString& exe);
84 /**
85 * The driver name entry in the per-program config file.
87 static const char DriverNameEntry[];
89 public slots:
90 /**
91 * Runs the program or continues it if it is stopped at a breakpoint.
93 void programRun();
95 /**
96 * Restarts the debuggee.
98 void programRunAgain();
101 * Performs a single-step, possibly stepping into a function call.
102 * If byInsn is true, a step by instruction is performed.
104 void programStep();
107 * Performs a single-step, stepping over a function call.
108 * If byInsn is true, a step by instruction is performed.
110 void programNext();
113 * Performs a single-step by instruction, possibly stepping into a
114 * function call.
116 void programStepi();
119 * Performs a single-step by instruction, stepping over a function
120 * call.
122 void programNexti();
125 * Runs the program until it returns from the current function.
127 void programFinish();
130 * Kills the program (removes it from memory).
132 void programKill();
135 * Interrupts the program if it is currently running.
137 void programBreak();
140 * Moves the program counter to the specified line.
141 * If an address is given, it is moved to the address.
143 void setProgramCounter(const QString&, int, const DbgAddr&);
145 public:
147 * Queries the user for program arguments.
149 void programArgs(QWidget* parent);
152 * Queries the user for program settings: Debugger command, terminal
153 * emulator.
155 void programSettings(QWidget* parent);
158 * Setup remote debugging device
160 void setRemoteDevice(const QString& remoteDevice) { m_remoteDevice = remoteDevice; }
163 * Run the debuggee until the specified line in the specified file is
164 * reached.
166 * @return false if the command was not executed, e.g. because the
167 * debuggee is running at the moment.
169 bool runUntil(const QString& fileName, int lineNo);
172 * Set a breakpoint.
174 * @param fileName The source file in which to set the breakpoint.
175 * @param lineNo The zero-based line number.
176 * @param address The exact address of the breakpoint.
177 * @param temporary Specifies whether this is a temporary breakpoint
178 * @return false if the command was not executed, e.g. because the
179 * debuggee is running at the moment.
181 bool setBreakpoint(QString fileName, int lineNo,
182 const DbgAddr& address, bool temporary);
185 * Set a breakpoint.
187 * @param bp Describes the breakpoint.
188 * @param queueOnly If false, the breakpoint is set using a high-priority command.
190 void setBreakpoint(Breakpoint* bp, bool queueOnly);
193 * Enable or disable a breakpoint at the specified location.
195 * @param fileName The source file in which the breakpoint is.
196 * @param lineNo The zero-based line number.
197 * @param address The exact address of the breakpoint.
198 * @return false if the command was not executed, e.g. because the
199 * debuggee is running at the moment.
201 bool enableDisableBreakpoint(QString fileName, int lineNo,
202 const DbgAddr& address);
205 * Enables or disables the specified breakpoint.
207 * @return false if the command was not executed, e.g. because the
208 * debuggee is running at the moment.
210 bool enableDisableBreakpoint(Breakpoint* bp);
213 * Removes the specified breakpoint. Note that if bp is an orphaned
214 * breakpoint, then bp is an invalid pointer if (and only if) this
215 * function returns true.
217 * @return false if the command was not executed, e.g. because the
218 * debuggee is running at the moment.
220 bool deleteBreakpoint(Breakpoint* bp);
223 * Changes the specified breakpoint's condition and ignore count.
225 * @return false if the command was not executed, e.g. because the
226 * debuggee is running at the moment.
228 bool conditionalBreakpoint(Breakpoint* bp,
229 const QString& condition,
230 int ignoreCount);
233 * Tells whether one of the single stepping commands can be invoked
234 * (step, next, finish, until, also run).
236 bool canSingleStep();
239 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
241 bool canChangeBreakpoints();
244 * Tells whether a the program is loaded, but not active.
246 bool canStart();
249 * Add a watch expression.
251 void addWatch(const QString& expr);
254 * Retrieves the current status message.
256 const QString& statusMessage() const { return m_statusMessage; }
259 * Is the debugger ready to receive another high-priority command?
261 bool isReady() const;
264 * Is the debuggee running (not just active)?
266 bool isProgramRunning() { return m_haveExecutable && m_programRunning; }
269 * Do we have an executable set?
271 bool haveExecutable() { return m_haveExecutable; }
274 * Is the debuggee active, i.e. was it started by the debugger?
276 bool isProgramActive() { return m_programActive; }
279 * Is the debugger driver idle?
281 bool isIdle() const;
283 /** The list of breakpoints. */
284 int numBreakpoints() const { return m_brkpts.size(); }
285 const Breakpoint* breakpoint(int i) const { return m_brkpts[i]; }
288 * Returns the breakpoint with the specified \a id.
290 Breakpoint* breakpointById(int id);
292 const QString& executable() const { return m_executable; }
295 * Terminal emulation level.
297 enum TTYLevel {
298 ttyNone = 0, /* ignore output, input triggers EOF */
299 ttySimpleOutputOnly = 1, /* minmal output emulation, input triggers EOF */
300 ttyFull = 7 /* program needs full emulation */
304 * Returns the level of terminal emulation requested by the inferior.
306 TTYLevel ttyLevel() const { return m_ttyLevel; }
308 /** Sets the terminal that is to be used by the debugger. */
309 void setTerminal(const QString& term) { m_inferiorTerminal = term; }
311 /** Returns the debugger driver. */
312 DebuggerDriver* driver() { return m_d; }
314 /** Returns the pid that the debugger is currently attached to. */
315 const QString& attachedPid() const { return m_attachedPid; }
318 * The memory at that the expression evaluates to is watched. Can be
319 * empty. Triggers a redisplay even if the expression did not change.
321 void setMemoryExpression(const QString& memexpr);
324 * Sets how the watched memory location is displayed.
325 * Call setMemoryExpression() to force a redisplay.
327 void setMemoryFormat(unsigned format) { m_memoryFormat = format; }
329 // settings
330 void saveSettings(KConfig*);
331 void restoreSettings(KConfig*);
333 protected:
334 QString m_inferiorTerminal;
335 QString m_debuggerCmd; /* per-program setting */
336 TTYLevel m_ttyLevel; /* level of terminal emulation */
337 bool startDriver();
338 void stopDriver();
339 void writeCommand();
341 QStringList m_watchEvalExpr; /* exprs to evaluate for watch window */
342 QPtrVector<Breakpoint> m_brkpts;
343 QString m_memoryExpression; /* memory location to watch */
344 unsigned m_memoryFormat; /* how that output should look */
346 protected slots:
347 void parse(CmdQueueItem* cmd, const char* output);
348 protected:
349 void handleRunCommands(const char* output);
350 void updateAllExprs();
351 void updateProgEnvironment(const QString& args, const QString& wd,
352 const QDict<EnvVar>& newVars,
353 const QStringList& newOptions);
354 void parseLocals(const char* output, QList<ExprValue>& newVars);
355 void handleLocals(const char* output);
356 bool handlePrint(CmdQueueItem* cmd, const char* output);
357 bool handlePrintDeref(CmdQueueItem* cmd, const char* output);
358 void handleBacktrace(const char* output);
359 void handleFrameChange(const char* output);
360 void handleFindType(CmdQueueItem* cmd, const char* output);
361 void handlePrintStruct(CmdQueueItem* cmd, const char* output);
362 void handleSharedLibs(const char* output);
363 void handleRegisters(const char* output);
364 void handleMemoryDump(const char* output);
365 void handleInfoLine(CmdQueueItem* cmd, const char* output);
366 void handleDisassemble(CmdQueueItem* cmd, const char* output);
367 void handleThreadList(const char* output);
368 void handleSetPC(const char* output);
369 void handleSetVariable(CmdQueueItem* cmd, const char* output);
370 void evalExpressions();
371 void evalInitialStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
372 void evalStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
373 void exprExpandingHelper(ExprWnd* wnd, KTreeViewItem* item, bool& allow);
374 void dereferencePointer(ExprWnd* wnd, VarTree* var, bool immediate);
375 void determineType(ExprWnd* wnd, VarTree* var);
376 void queueMemoryDump(bool immediate);
377 CmdQueueItem* loadCoreFile();
378 void openProgramConfig(const QString& name);
380 Breakpoint* breakpointByFilePos(QString file, int lineNo,
381 const DbgAddr& address);
382 void newBreakpoint(CmdQueueItem* cmd, const char* output);
383 void updateBreakList(const char* output);
384 bool stopMayChangeBreakList() const;
385 void saveBreakpoints(ProgramConfig* config);
386 void restoreBreakpoints(ProgramConfig* config);
388 bool m_haveExecutable; /* has an executable been specified */
389 bool m_programActive; /* is the program active (possibly halting in a brkpt)? */
390 bool m_programRunning; /* is the program executing (not stopped)? */
391 bool m_sharedLibsListed; /* do we know the shared libraries loaded by the prog? */
392 QString m_executable;
393 QString m_corefile;
394 QString m_attachedPid; /* user input of attaching to pid */
395 QString m_programArgs;
396 QString m_remoteDevice;
397 QString m_programWD; /* working directory of gdb */
398 QDict<EnvVar> m_envVars; /* environment variables set by user */
399 QStringList m_boolOptions; /* boolean options */
400 QStrList m_sharedLibs; /* shared libraries used by program */
401 ProgramTypeTable* m_typeTable; /* known types used by the program */
402 ProgramConfig* m_programConfig; /* program-specific settings (brkpts etc) */
403 void saveProgramSettings();
404 void restoreProgramSettings();
405 QString readDebuggerCmd();
407 // debugger process
408 DebuggerDriver* m_d;
409 bool m_explicitKill; /* whether we are killing gdb ourselves */
411 QString m_statusMessage;
413 protected slots:
414 void gdbExited(KProcess*);
415 void slotInferiorRunning();
416 void backgroundUpdate();
417 void gotoFrame(int);
418 void slotLocalsExpanding(KTreeViewItem*, bool&);
419 void slotWatchExpanding(KTreeViewItem*, bool&);
420 void slotDeleteWatch();
421 void slotValuePopup(const QString&);
422 void slotDisassemble(const QString&, int);
423 void slotValueEdited(VarTree*, const QString&);
424 public slots:
425 void setThread(int);
426 void shutdown();
428 signals:
430 * This signal is emitted before the debugger is started. The slot is
431 * supposed to set up m_inferiorTerminal.
433 void debuggerStarting();
436 * This signal is emitted whenever a part of the debugger needs to
437 * highlight the specfied source code line (e.g. when the program
438 * stops).
440 * @param file specifies the file; this is not necessarily a full path
441 * name, and if it is relative, you won't know relative to what, you
442 * can only guess.
443 * @param lineNo specifies the line number (0-based!) (this may be
444 * negative, in which case the file should be activated, but the line
445 * should NOT be changed).
446 * @param address specifies the exact address of the PC or is empty.
448 void activateFileLine(const QString& file, int lineNo, const DbgAddr& address);
451 * This signal indicates that the program counter has changed.
453 * @param filename specifies the filename where the program stopped
454 * @param lineNo specifies the line number (zero-based); it can be -1
455 * if it is unknown
456 * @param address specifies the address that the instruction pointer
457 * points to.
458 * @param frameNo specifies the frame number: 0 is the innermost frame,
459 * positive numbers are frames somewhere up the stack (indicates points
460 * where a function was called); the latter cases should be indicated
461 * differently in the source window.
463 void updatePC(const QString& filename, int lineNo,
464 const DbgAddr& address, int frameNo);
467 * This signal is emitted when gdb detects that the executable has been
468 * updated, e.g. recompiled. (You usually need not handle this signal
469 * if you are the editor which changed the executable.)
471 void executableUpdated();
474 * Indicates that a new status message is available.
476 void updateStatusMessage();
479 * Indicates that the internal state of the debugger has changed, and
480 * that this will very likely have an impact on the UI.
482 void updateUI();
485 * Indicates that the list of breakpoints has possibly changed.
487 void breakpointsChanged();
490 * Indicates that the register values have possibly changed.
492 void registersChanged(QList<RegisterInfo>&);
495 * Indicates that the list of threads has possibly changed.
497 void threadsChanged(QList<ThreadInfo>&);
500 * Indicates that the value for a value popup is ready.
502 void valuePopup(const QString&);
505 * Provides the disassembled code of the location given by file and
506 * line number (zero-based).
508 void disassembled(const QString& file, int line, const QList<DisassembledCode>& code);
511 * Indicates that the program has stopped for any reason: by a
512 * breakpoint, by a signal that the debugger driver caught, by a single
513 * step instruction.
515 void programStopped();
518 * Indicates that a new memory dump output is ready.
519 * @param msg is an error message or empty
520 * @param memdump is the memory dump
522 void memoryDumpChanged(const QString&, QList<MemoryDump>&);
525 * Gives other objects a chance to save program specific settings.
527 void saveProgramSpecific(KConfigBase* config);
530 * Gives other objects a chance to restore program specific settings.
532 void restoreProgramSpecific(KConfigBase* config);
534 protected:
535 ExprWnd& m_localVariables;
536 ExprWnd& m_watchVariables;
537 QListBox& m_btWindow;
539 // implementation helpers
540 protected:
541 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
543 friend class BreakpointTable;
546 #endif // DEBUGGER_H