3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
12 #include "exprwnd.h" /* some compilers require this */
20 class ProgramTypeTable
;
29 class DisassembledCode
;
34 class KDebugger
: public QObject
38 KDebugger(QWidget
* parent
, /* will be used as the parent for dialogs */
42 DebuggerDriver
* driver
47 * This function starts to debug the specified executable. If a program
48 * is currently being debugged, it is terminated first.
50 * @return false if an error occurs.
52 bool debugProgram(const QString
& executable
);
55 * Uses the specified core to debug the active program.
56 * @param batch tells whether the core file was given on the
59 void useCoreFile(QString corefile
, bool batch
);
62 * Runs the program or continues it if it is stopped at a breakpoint.
67 * Attaches to the specified process and debugs it.
69 void attachProgram(const QString
& pid
);
72 * Restarts the debuggee.
74 void programRunAgain();
77 * Performs a single-step, possibly stepping into a function call.
82 * Performs a single-step, stepping over a function call.
87 * Runs the program until it returns from the current function.
92 * Kills the program (removes it from memory).
97 * Interrupts the program if it is currently running.
102 * Queries the user for program arguments.
104 void programArgs(QWidget
* parent
);
107 * Queries the user for program settings: Debugger command, terminal
110 void programSettings(QWidget
* parent
);
113 * Setup remote debugging device
115 void setRemoteDevice(const QString
& remoteDevice
) { m_remoteDevice
= remoteDevice
; }
118 * Run the debuggee until the specified line in the specified file is
121 * @return false if the command was not executed, e.g. because the
122 * debuggee is running at the moment.
124 bool runUntil(const QString
& fileName
, int lineNo
);
129 * @param fileName The source file in which to set the breakpoint.
130 * @param lineNo The zero-based line number.
131 * @param address The exact address of the breakpoint.
132 * @param temporary Specifies whether this is a temporary breakpoint
133 * @return false if the command was not executed, e.g. because the
134 * debuggee is running at the moment.
136 bool setBreakpoint(QString fileName
, int lineNo
,
137 const DbgAddr
& address
, bool temporary
);
140 * Enable or disable a breakpoint at the specified location.
142 * @param fileName The source file in which the breakpoint is.
143 * @param lineNo The zero-based line number.
144 * @param address The exact address of the breakpoint.
145 * @return false if the command was not executed, e.g. because the
146 * debuggee is running at the moment.
148 bool enableDisableBreakpoint(QString fileName
, int lineNo
,
149 const DbgAddr
& address
);
152 * Tells whether one of the single stepping commands can be invoked
153 * (step, next, finish, until, also run).
155 bool canSingleStep();
158 * Tells whether a breakpoints can be set, deleted, enabled, or disabled.
160 bool canChangeBreakpoints();
163 * Tells whether the debuggee can be changed.
165 bool canUseCoreFile() { return isReady() && !m_programActive
; }
168 * Add a watch expression.
170 void addWatch(const QString
& expr
);
173 * Retrieves the current status message.
175 const QString
& statusMessage() const { return m_statusMessage
; }
178 * Is the debugger ready to receive another high-priority command?
180 bool isReady() const;
183 * Is the debuggee running (not just active)?
185 bool isProgramRunning() { return m_haveExecutable
&& m_programRunning
; }
188 * Do we have an executable set?
190 bool haveExecutable() { return m_haveExecutable
; }
193 * Is the debuggee active, i.e. was it started by the debugger?
195 bool isProgramActive() { return m_programActive
; }
198 * Is the debugger driver idle?
202 /** The list of breakpoints. */
203 int numBreakpoints() const { return m_brkpts
.size(); }
204 const Breakpoint
* breakpoint(int i
) const { return m_brkpts
[i
]; }
206 const QString
& executable() const { return m_executable
; }
209 * Sets the command to invoke gdb. If cmd is the empty string, the
210 * default is substituted.
212 void setDebuggerCmd(const QString
& cmd
)
213 { m_generalDebuggerCmd
= cmd
; }
216 * Terminal emulation level.
219 ttyNone
= 0, /* ignore output, input triggers EOF */
220 ttySimpleOutputOnly
= 1, /* minmal output emulation, input triggers EOF */
221 ttyFull
= 7 /* program needs full emulation */
225 * Returns the level of terminal emulation requested by the inferior.
227 TTYLevel
ttyLevel() const { return m_ttyLevel
; }
229 /** Sets the terminal that is to be used by the debugger. */
230 void setTerminal(const QString
& term
) { m_inferiorTerminal
= term
; }
232 /** Returns the debugger driver. */
233 DebuggerDriver
* driver() { return m_d
; }
235 /** Returns the pid that the debugger is currently attached to. */
236 const QString
& attachedPid() const { return m_attachedPid
; }
239 void saveSettings(KConfig
*);
240 void restoreSettings(KConfig
*);
243 QString m_inferiorTerminal
;
244 QString m_debuggerCmd
; /* per-program setting */
245 QString m_generalDebuggerCmd
; /* global setting */
246 TTYLevel m_ttyLevel
; /* level of terminal emulation */
251 QList
<VarTree
> m_watchEvalExpr
; /* exprs to evaluate for watch windows */
252 QArray
<Breakpoint
*> m_brkpts
;
255 void parse(CmdQueueItem
* cmd
, const char* output
);
257 VarTree
* parseExpr(const char* output
, bool wantErrorValue
);
258 void handleRunCommands(const char* output
);
259 void updateAllExprs();
260 void updateProgEnvironment(const QString
& args
, const QString
& wd
,
261 const QDict
<EnvVar
>& newVars
);
262 void parseLocals(const char* output
, QList
<VarTree
>& newVars
);
263 void handleLocals(const char* output
);
264 bool handlePrint(CmdQueueItem
* cmd
, const char* output
);
265 void handleBacktrace(const char* output
);
266 void handleFrameChange(const char* output
);
267 void handleFindType(CmdQueueItem
* cmd
, const char* output
);
268 void handlePrintStruct(CmdQueueItem
* cmd
, const char* output
);
269 void handleSharedLibs(const char* output
);
270 void handleRegisters(const char* output
);
271 void handleInfoLine(CmdQueueItem
* cmd
, const char* output
);
272 void handleDisassemble(CmdQueueItem
* cmd
, const char* output
);
273 void evalExpressions();
274 void evalInitialStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
275 void evalStructExpression(VarTree
* var
, ExprWnd
* wnd
, bool immediate
);
276 void exprExpandingHelper(ExprWnd
* wnd
, KTreeViewItem
* item
, bool& allow
);
277 void dereferencePointer(ExprWnd
* wnd
, VarTree
* var
, bool immediate
);
278 void determineType(ExprWnd
* wnd
, VarTree
* var
);
279 void removeExpr(ExprWnd
* wnd
, VarTree
* var
);
280 CmdQueueItem
* loadCoreFile();
281 void openProgramConfig(const QString
& name
);
283 Breakpoint
* breakpointByFilePos(QString file
, int lineNo
,
284 const DbgAddr
& address
);
285 void newBreakpoint(const char* output
);
286 void updateBreakList(const char* output
);
287 bool haveTemporaryBP() const;
288 void saveBreakpoints(KSimpleConfig
* config
);
289 void restoreBreakpoints(KSimpleConfig
* config
);
291 bool m_haveExecutable
; /* has an executable been specified */
292 bool m_programActive
; /* is the program active (possibly halting in a brkpt)? */
293 bool m_programRunning
; /* is the program executing (not stopped)? */
294 bool m_sharedLibsListed
; /* do we know the shared libraries loaded by the prog? */
295 QString m_executable
;
297 QString m_attachedPid
; /* user input of attaching to pid */
298 QString m_programArgs
;
299 QString m_remoteDevice
;
300 QString m_programWD
; /* working directory of gdb */
301 QDict
<EnvVar
> m_envVars
; /* environment variables set by user */
302 QStrList m_sharedLibs
; /* shared libraries used by program */
303 ProgramTypeTable
* m_typeTable
; /* known types used by the program */
304 KSimpleConfig
* m_programConfig
; /* program-specific settings (brkpts etc) */
305 void saveProgramSettings();
306 void restoreProgramSettings();
310 bool m_explicitKill
; /* whether we are killing gdb ourselves */
312 QString m_statusMessage
;
315 void gdbExited(KProcess
*);
316 void slotInferiorRunning();
317 void backgroundUpdate();
319 void slotLocalsExpanding(KTreeViewItem
*, bool&);
320 void slotWatchExpanding(KTreeViewItem
*, bool&);
321 void slotUpdateAnimation();
322 void slotDeleteWatch();
323 void slotValuePopup(const QString
&);
324 void slotDisassemble(const QString
&, int);
328 * This signal is emitted before the debugger is started. The slot is
329 * supposed to set up m_inferiorTerminal.
331 void debuggerStarting();
334 * This signal is emitted whenever a part of the debugger needs to
335 * highlight the specfied source code line (e.g. when the program
338 * @param file specifies the file; this is not necessarily a full path
339 * name, and if it is relative, you won't know relative to what, you
341 * @param lineNo specifies the line number (0-based!) (this may be
342 * negative, in which case the file should be activated, but the line
343 * should NOT be changed).
344 * @param address specifies the exact address of the PC or is empty.
346 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
349 * This signal is emitted when a line decoration item (those thingies
350 * that indicate breakpoints) must be changed.
352 void lineItemsChanged();
355 * This signal is a special case of @ref #lineItemsChanged because it
356 * indicates that only the program counter has changed.
358 * @param filename specifies the filename where the program stopped
359 * @param lineNo specifies the line number (zero-based); it can be -1
361 * @param address specifies the address that the instruction pointer
363 * @param frameNo specifies the frame number: 0 is the innermost frame,
364 * positive numbers are frames somewhere up the stack (indicates points
365 * where a function was called); the latter cases should be indicated
366 * differently in the source window.
368 void updatePC(const QString
& filename
, int lineNo
,
369 const DbgAddr
& address
, int frameNo
);
372 * This signal is emitted when gdb detects that the executable has been
373 * updated, e.g. recompiled. (You usually need not handle this signal
374 * if you are the editor which changed the executable.)
376 void executableUpdated();
379 * This signal is emitted when the animated icon should advance to the
382 void animationTimeout();
385 * Indicates that a new status message is available.
387 void updateStatusMessage();
390 * Indicates that the internal state of the debugger has changed, and
391 * that this will very likely have an impact on the UI.
396 * Indicates that the list of breakpoints has possibly changed.
398 void breakpointsChanged();
401 * Indicates that the register values have possibly changed.
403 void registersChanged(QList
<RegisterInfo
>&);
406 * Indicates that the value for a value popup is ready.
408 void valuePopup(const QString
&);
411 * Provides the disassembled code of the location given by file and
412 * line number (zero-based).
414 void disassembled(const QString
& file
, int line
, const QList
<DisassembledCode
>& code
);
417 ExprWnd
& m_localVariables
;
418 ExprWnd
& m_watchVariables
;
419 QListBox
& m_btWindow
;
422 QTimer m_animationTimer
;
423 int m_animationInterval
;
425 // implementation helpers
427 void startAnimation(bool fast
);
428 void stopAnimation();
430 QWidget
* parentWidget() { return static_cast<QWidget
*>(parent()); }
432 friend class BreakpointTable
;