Introduced a separate DCprintDeref to separate the handlePrintDeref() from
[kdbg.git] / kdbg / debugger.h
blob81e8cbd4ac8fe962d5cf0d1e05cae6bd6073ebe3
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 KConfigBase;
26 class ProgramConfig;
27 class QListBox;
28 class RegisterInfo;
29 class ThreadInfo;
30 class DebuggerDriver;
31 class CmdQueueItem;
32 class Breakpoint;
33 struct DisassembledCode;
34 struct MemoryDump;
35 struct DbgAddr;
36 class KProcess;
39 class KDebugger : public QObject
41 Q_OBJECT
42 public:
43 KDebugger(QWidget* parent, /* will be used as the parent for dialogs */
44 ExprWnd* localVars,
45 ExprWnd* watchVars,
46 QListBox* backtrace);
47 ~KDebugger();
49 /**
50 * This function starts to debug the specified executable using the
51 * specified driver. If a program is currently being debugged, it is
52 * terminated first. Ownership of driver is taken if and only if
53 * true is returned.
55 * @return false if an error occurs.
57 bool debugProgram(const QString& executable,
58 DebuggerDriver* driver);
60 /**
61 * Uses the specified core to debug the active program.
62 * @param batch tells whether the core file was given on the
63 * command line.
65 void useCoreFile(QString corefile, bool batch);
67 /**
68 * Attaches to the specified process and debugs it.
70 void attachProgram(const QString& pid);
72 /**
73 * Returns the file name of the per-program config file for the
74 * specified program.
76 static QString getConfigForExe(const QString& exe);
78 /**
79 * The driver name entry in the per-program config file.
81 static const char DriverNameEntry[];
83 public slots:
84 /**
85 * Runs the program or continues it if it is stopped at a breakpoint.
87 void programRun();
89 /**
90 * Restarts the debuggee.
92 void programRunAgain();
94 /**
95 * Performs a single-step, possibly stepping into a function call.
96 * If byInsn is true, a step by instruction is performed.
98 void programStep();
101 * Performs a single-step, stepping over a function call.
102 * If byInsn is true, a step by instruction is performed.
104 void programNext();
107 * Performs a single-step by instruction, possibly stepping into a
108 * function call.
110 void programStepi();
113 * Performs a single-step by instruction, stepping over a function
114 * call.
116 void programNexti();
119 * Runs the program until it returns from the current function.
121 void programFinish();
124 * Kills the program (removes it from memory).
126 void programKill();
129 * Interrupts the program if it is currently running.
131 void programBreak();
134 * Moves the program counter to the specified line.
135 * If an address is given, it is moved to the address.
137 void setProgramCounter(const QString&, int, const DbgAddr&);
139 public:
141 * Queries the user for program arguments.
143 void programArgs(QWidget* parent);
146 * Queries the user for program settings: Debugger command, terminal
147 * emulator.
149 void programSettings(QWidget* parent);
152 * Setup remote debugging device
154 void setRemoteDevice(const QString& remoteDevice) { m_remoteDevice = remoteDevice; }
157 * Run the debuggee until the specified line in the specified file is
158 * reached.
160 * @return false if the command was not executed, e.g. because the
161 * debuggee is running at the moment.
163 bool runUntil(const QString& fileName, int lineNo);
166 * Set a breakpoint.
168 * @param fileName The source file in which to set the breakpoint.
169 * @param lineNo The zero-based line number.
170 * @param address The exact address of the breakpoint.
171 * @param temporary Specifies whether this is a temporary breakpoint
172 * @return false if the command was not executed, e.g. because the
173 * debuggee is running at the moment.
175 bool setBreakpoint(QString fileName, int lineNo,
176 const DbgAddr& address, bool temporary);
179 * Set a breakpoint.
181 * @param bp Describes the breakpoint.
182 * @param queueOnly If false, the breakpoint is set using a high-priority command.
184 void setBreakpoint(Breakpoint* bp, bool queueOnly);
187 * Enable or disable a breakpoint at the specified location.
189 * @param fileName The source file in which the breakpoint is.
190 * @param lineNo The zero-based line number.
191 * @param address The exact address of the breakpoint.
192 * @return false if the command was not executed, e.g. because the
193 * debuggee is running at the moment.
195 bool enableDisableBreakpoint(QString fileName, int lineNo,
196 const DbgAddr& address);
199 * Enables or disables the specified breakpoint.
201 * @return false if the command was not executed, e.g. because the
202 * debuggee is running at the moment.
204 bool enableDisableBreakpoint(Breakpoint* bp);
207 * Removes the specified breakpoint. Note that if bp is an orphaned
208 * breakpoint, then bp is an invalid pointer if (and only if) this
209 * function returns true.
211 * @return false if the command was not executed, e.g. because the
212 * debuggee is running at the moment.
214 bool deleteBreakpoint(Breakpoint* bp);
217 * Changes the specified breakpoint's condition and ignore count.
219 * @return false if the command was not executed, e.g. because the
220 * debuggee is running at the moment.
222 bool conditionalBreakpoint(Breakpoint* bp,
223 const QString& condition,
224 int ignoreCount);
227 * Tells whether one of the single stepping commands can be invoked
228 * (step, next, finish, until, also run).
230 bool canSingleStep();
233 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
235 bool canChangeBreakpoints();
238 * Tells whether the debuggee can be changed.
240 bool canUseCoreFile() { return isReady() && !m_programActive; }
243 * Add a watch expression.
245 void addWatch(const QString& expr);
248 * Retrieves the current status message.
250 const QString& statusMessage() const { return m_statusMessage; }
253 * Is the debugger ready to receive another high-priority command?
255 bool isReady() const;
258 * Is the debuggee running (not just active)?
260 bool isProgramRunning() { return m_haveExecutable && m_programRunning; }
263 * Do we have an executable set?
265 bool haveExecutable() { return m_haveExecutable; }
268 * Is the debuggee active, i.e. was it started by the debugger?
270 bool isProgramActive() { return m_programActive; }
273 * Is the debugger driver idle?
275 bool isIdle() const;
277 /** The list of breakpoints. */
278 int numBreakpoints() const { return m_brkpts.size(); }
279 const Breakpoint* breakpoint(int i) const { return m_brkpts[i]; }
282 * Returns the breakpoint with the specified \a id.
284 Breakpoint* breakpointById(int id);
286 const QString& executable() const { return m_executable; }
289 * Terminal emulation level.
291 enum TTYLevel {
292 ttyNone = 0, /* ignore output, input triggers EOF */
293 ttySimpleOutputOnly = 1, /* minmal output emulation, input triggers EOF */
294 ttyFull = 7 /* program needs full emulation */
298 * Returns the level of terminal emulation requested by the inferior.
300 TTYLevel ttyLevel() const { return m_ttyLevel; }
302 /** Sets the terminal that is to be used by the debugger. */
303 void setTerminal(const QString& term) { m_inferiorTerminal = term; }
305 /** Returns the debugger driver. */
306 DebuggerDriver* driver() { return m_d; }
308 /** Returns the pid that the debugger is currently attached to. */
309 const QString& attachedPid() const { return m_attachedPid; }
311 /** Edit a value */
312 void editLocalValue(int row);
315 * The memory at that the expression evaluates to is watched. Can be
316 * empty. Triggers a redisplay even if the expression did not change.
318 void setMemoryExpression(const QString& memexpr);
321 * Sets how the watched memory location is displayed.
322 * Call setMemoryExpression() to force a redisplay.
324 void setMemoryFormat(unsigned format) { m_memoryFormat = format; }
326 // settings
327 void saveSettings(KConfig*);
328 void restoreSettings(KConfig*);
330 protected:
331 QString m_inferiorTerminal;
332 QString m_debuggerCmd; /* per-program setting */
333 TTYLevel m_ttyLevel; /* level of terminal emulation */
334 bool startDriver();
335 void stopDriver();
336 void writeCommand();
338 QList<VarTree> m_watchEvalExpr; /* exprs to evaluate for watch windows */
339 QPtrVector<Breakpoint> m_brkpts;
340 QString m_memoryExpression; /* memory location to watch */
341 unsigned m_memoryFormat; /* how that output should look */
343 protected slots:
344 void parse(CmdQueueItem* cmd, const char* output);
345 protected:
346 VarTree* parseExpr(const char* output, bool wantErrorValue);
347 void handleRunCommands(const char* output);
348 void updateAllExprs();
349 void updateProgEnvironment(const QString& args, const QString& wd,
350 const QDict<EnvVar>& newVars,
351 const QStringList& newOptions);
352 void parseLocals(const char* output, QList<VarTree>& newVars);
353 void handleLocals(const char* output);
354 bool handlePrint(CmdQueueItem* cmd, const char* output);
355 bool handlePrintDeref(CmdQueueItem* cmd, const char* output);
356 void handleBacktrace(const char* output);
357 void handleFrameChange(const char* output);
358 void handleFindType(CmdQueueItem* cmd, const char* output);
359 void handlePrintStruct(CmdQueueItem* cmd, const char* output);
360 void handleSharedLibs(const char* output);
361 void handleRegisters(const char* output);
362 void handleMemoryDump(const char* output);
363 void handleInfoLine(CmdQueueItem* cmd, const char* output);
364 void handleDisassemble(CmdQueueItem* cmd, const char* output);
365 void handleThreadList(const char* output);
366 void handleSetPC(const char* output);
367 void handleSetVariable(CmdQueueItem* cmd, const char* output);
368 void evalExpressions();
369 void evalInitialStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
370 void evalStructExpression(VarTree* var, ExprWnd* wnd, bool immediate);
371 void exprExpandingHelper(ExprWnd* wnd, KTreeViewItem* item, bool& allow);
372 void dereferencePointer(ExprWnd* wnd, VarTree* var, bool immediate);
373 void determineType(ExprWnd* wnd, VarTree* var);
374 void removeExpr(ExprWnd* wnd, VarTree* var);
375 void queueMemoryDump(bool immediate);
376 CmdQueueItem* loadCoreFile();
377 void openProgramConfig(const QString& name);
379 Breakpoint* breakpointByFilePos(QString file, int lineNo,
380 const DbgAddr& address);
381 void newBreakpoint(CmdQueueItem* cmd, const char* output);
382 void updateBreakList(const char* output);
383 bool stopMayChangeBreakList() const;
384 void saveBreakpoints(ProgramConfig* config);
385 void restoreBreakpoints(ProgramConfig* config);
387 bool m_haveExecutable; /* has an executable been specified */
388 bool m_programActive; /* is the program active (possibly halting in a brkpt)? */
389 bool m_programRunning; /* is the program executing (not stopped)? */
390 bool m_sharedLibsListed; /* do we know the shared libraries loaded by the prog? */
391 QString m_executable;
392 QString m_corefile;
393 QString m_attachedPid; /* user input of attaching to pid */
394 QString m_programArgs;
395 QString m_remoteDevice;
396 QString m_programWD; /* working directory of gdb */
397 QDict<EnvVar> m_envVars; /* environment variables set by user */
398 QStringList m_boolOptions; /* boolean options */
399 QStrList m_sharedLibs; /* shared libraries used by program */
400 ProgramTypeTable* m_typeTable; /* known types used by the program */
401 ProgramConfig* m_programConfig; /* program-specific settings (brkpts etc) */
402 void saveProgramSettings();
403 void restoreProgramSettings();
404 QString readDebuggerCmd();
406 // debugger process
407 DebuggerDriver* m_d;
408 bool m_explicitKill; /* whether we are killing gdb ourselves */
410 QString m_statusMessage;
412 protected slots:
413 void gdbExited(KProcess*);
414 void slotInferiorRunning();
415 void backgroundUpdate();
416 void gotoFrame(int);
417 void slotLocalsExpanding(KTreeViewItem*, bool&);
418 void slotWatchExpanding(KTreeViewItem*, bool&);
419 void slotUpdateAnimation();
420 void slotDeleteWatch();
421 void slotValuePopup(const QString&);
422 void slotDisassemble(const QString&, int);
423 void slotLocalsValueEdited(int, 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 * This signal is emitted when the animated icon should advance to the
475 * next picture.
477 void animationTimeout();
480 * Indicates that a new status message is available.
482 void updateStatusMessage();
485 * Indicates that the internal state of the debugger has changed, and
486 * that this will very likely have an impact on the UI.
488 void updateUI();
491 * Indicates that the list of breakpoints has possibly changed.
493 void breakpointsChanged();
496 * Indicates that the register values have possibly changed.
498 void registersChanged(QList<RegisterInfo>&);
501 * Indicates that the list of threads has possibly changed.
503 void threadsChanged(QList<ThreadInfo>&);
506 * Indicates that the value for a value popup is ready.
508 void valuePopup(const QString&);
511 * Provides the disassembled code of the location given by file and
512 * line number (zero-based).
514 void disassembled(const QString& file, int line, const QList<DisassembledCode>& code);
517 * Indicates that the program has stopped for any reason: by a
518 * breakpoint, by a signal that the debugger driver caught, by a single
519 * step instruction.
521 void programStopped();
524 * Indicates that a new memory dump output is ready.
525 * @param msg is an error message or empty
526 * @param memdump is the memory dump
528 void memoryDumpChanged(const QString&, QList<MemoryDump>&);
531 * Gives other objects a chance to save program specific settings.
533 void saveProgramSpecific(KConfigBase* config);
536 * Gives other objects a chance to restore program specific settings.
538 void restoreProgramSpecific(KConfigBase* config);
540 protected:
541 ExprWnd& m_localVariables;
542 ExprWnd& m_watchVariables;
543 QListBox& m_btWindow;
545 // animation
546 QTimer m_animationTimer;
547 int m_animationInterval;
549 // implementation helpers
550 protected:
551 void startAnimation(bool fast);
552 void stopAnimation();
554 QWidget* parentWidget() { return static_cast<QWidget*>(parent()); }
556 friend class BreakpointTable;
559 #endif // DEBUGGER_H