3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
24 * A type representing an address.
31 DbgAddr(const QString
& aa
);
32 DbgAddr(const DbgAddr
& src
) : a(src
.a
), fnoffs(src
.fnoffs
) { }
33 void operator=(const QString
& aa
);
34 void operator=(const DbgAddr
& src
) { a
= src
.a
; fnoffs
= src
.fnoffs
; }
35 QString
asString() const;
36 bool isEmpty() const { return a
.isEmpty(); }
40 bool operator==(const DbgAddr
& a1
, const DbgAddr
& a2
);
41 bool operator>(const DbgAddr
& a1
, const DbgAddr
& a2
);
60 DCsetoption
, /* debugger options */
70 DCuntil
, /* line number is zero-based! */
73 DCbreakline
, /* line number is zero-based! */
74 DCtbreakline
, /* line number is zero-based! */
96 RDNstdin
= 0x1, /* redirect stdin to /dev/null */
97 RDNstdout
= 0x2, /* redirect stdout to /dev/null */
98 RDNstderr
= 0x4 /* redirect stderr to /dev/null */
102 * How the memory dump is formated. The lowest 4 bits define the size of
103 * the entities. The higher bits define how these are formatted. Note that
104 * not all combinations make sense.
106 enum MemoryDumpType
{
130 * Debugger commands are placed in a queue. Only one command at a time is
131 * sent down to the debugger. All other commands in the queue are retained
132 * until the sent command has been processed by gdb. The debugger tells us
133 * that it's done with the command by sending the prompt. The output of the
134 * debugger is parsed at that time. Then, if more commands are in the
135 * queue, the next one is sent to the debugger.
141 bool m_committed
; /* just a debugging aid */
142 // remember which expression when printing an expression
145 // remember file position
148 // the breakpoint info
150 // whether command was emitted due to direct user request (only set when relevant)
153 CmdQueueItem(DbgCommand cmd
, const QString
& str
) :
166 * The information about a breakpoint that is parsed from the list of
171 int id
; /* gdb's number */
173 breakpoint
, watchpoint
178 DbgAddr address
; /* exact address of breakpoint */
179 QString condition
; /* condition as printed by gdb */
180 int ignoreCount
; /* ignore next that may hits */
181 int hitCount
; /* as reported by gdb */
182 // the following items repeat the location, but in a better usable way
184 int lineNo
; /* zero-based line number */
188 * Information about a stack frame.
193 int lineNo
; /* zero-based line number */
194 DbgAddr address
; /* exact address of PC */
198 * The information about a stack frame as parsed from the backtrace.
200 struct StackFrame
: FrameInfo
203 VarTree
* var
; /* more information if non-zero */
204 StackFrame() : var(0) { }
209 * The information about a thread as parsed from the threads list.
211 struct ThreadInfo
: FrameInfo
213 int id
; /* gdb's number */
214 QString threadName
; /* the SYSTAG */
215 QString function
; /* where thread is halted */
216 bool hasFocus
; /* the thread whose stack we are watching */
220 * Register information
226 QString cookedValue
; /* may be empty */
227 QString type
; /* of vector register if not empty */
233 struct DisassembledCode
249 * This is an abstract base class for debugger process.
251 * This class represents the debugger program. It provides the low-level
252 * interface to the commandline debugger. As such it implements the
253 * commands and parses the output.
255 class DebuggerDriver
: public KProcess
260 virtual ~DebuggerDriver() = 0;
262 virtual QString
driverName() const = 0;
264 * Returns the default command string to invoke the debugger driver.
266 virtual QString
defaultInvocation() const = 0;
269 * Returns a list of options that can be turned on and off.
271 virtual QStringList
boolOptionList() const = 0;
273 virtual bool startup(QString cmdStr
);
274 void dequeueCmdByVar(VarTree
* var
);
275 void setLogFileName(const QString
& fname
) { m_logFileName
= fname
; }
281 DSidle
, /* gdb waits for input */
282 DSinterrupted
, /* a command was interrupted */
283 DSrunningLow
, /* gdb is running a low-priority command */
284 DSrunning
, /* gdb waits for program */
285 DScommandSent
, /* command has been sent, we wait for wroteStdin signal */
286 DScommandSentLow
/* low-prioritycommand has been sent */
288 DebuggerState m_state
;
291 bool isIdle() const { return m_state
== DSidle
; }
293 * Tells whether a high prority command would be executed immediately.
295 bool canExecuteImmediately() const { return m_hipriCmdQueue
.isEmpty(); }
298 char* m_output
; /* normal gdb output */
299 size_t m_outputLen
; /* amount of data so far accumulated in m_output */
300 size_t m_outputAlloc
; /* space available in m_output */
301 typedef QCString DelayedStr
;
302 QQueue
<DelayedStr
> m_delayedOutput
; /* output colleced while we have receivedOutput */
303 /* but before signal wroteStdin arrived */
307 * Enqueues a high-priority command. High-priority commands are
308 * executed before any low-priority commands. No user interaction is
309 * possible as long as there is a high-priority command in the queue.
311 virtual CmdQueueItem
* executeCmd(DbgCommand
,
312 bool clearLow
= false) = 0;
313 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
,
314 bool clearLow
= false) = 0;
315 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg
,
316 bool clearLow
= false) = 0;
317 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
, int intArg
,
318 bool clearLow
= false) = 0;
319 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg1
, QString strArg2
,
320 bool clearLow
= false) = 0;
321 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg1
, int intArg2
,
322 bool clearLow
= false) = 0;
325 QMnormal
, /* queues the command last */
326 QMoverride
, /* removes an already queued command */
327 QMoverrideMoreEqual
/* ditto, also puts the command first in the queue */
331 * Enqueues a low-priority command. Low-priority commands are executed
332 * after any high-priority commands.
334 virtual CmdQueueItem
* queueCmd(DbgCommand
,
336 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
,
338 virtual CmdQueueItem
* queueCmd(DbgCommand
, int intArg
,
340 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
, int intArg
,
342 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg1
, QString strArg2
,
346 * Flushes the command queues.
347 * @param hipriOnly if true, only the high priority queue is flushed.
349 virtual void flushCommands(bool hipriOnly
= false);
352 * Terminates the debugger process.
354 virtual void terminate() = 0;
357 * Terminates the debugger process, but also detaches any program that
358 * it has been attached to.
360 virtual void detachAndTerminate() = 0;
363 * Interrupts the debuggee.
365 virtual void interruptInferior() = 0;
368 * Parses the output as an array of QChars.
370 virtual VarTree
* parseQCharArray(const char* output
, bool wantErrorValue
, bool qt3like
) = 0;
373 * Parses a back-trace (the output of the DCbt command).
375 virtual void parseBackTrace(const char* output
, QList
<StackFrame
>& stack
) = 0;
378 * Parses the output of the DCframe command;
379 * @param frameNo Returns the frame number.
380 * @param file Returns the source file name.
381 * @param lineNo The zero-based line number.
382 * @param address Returns the exact address.
383 * @return false if the frame could not be parsed successfully. The
384 * output values are undefined in this case.
386 virtual bool parseFrameChange(const char* output
, int& frameNo
,
387 QString
& file
, int& lineNo
, DbgAddr
& address
) = 0;
390 * Parses a list of breakpoints.
391 * @param output The output of the debugger.
392 * @param brks The list of new #Breakpoint objects. The list
393 * must initially be empty.
394 * @return False if there was an error before the first breakpoint
395 * was found. Even if true is returned, #brks may be empty.
397 virtual bool parseBreakList(const char* output
, QList
<Breakpoint
>& brks
) = 0;
400 * Parses a list of threads.
401 * @param output The output of the debugger.
402 * @param threads The list of new #ThreadInfo objects. The list
403 * must initially be empty.
404 * @return False if there was an error before the first thread entry
405 * was found. Even if true is returned, #threads may be empty.
407 virtual bool parseThreadList(const char* output
, QList
<ThreadInfo
>& threads
) = 0;
410 * Parses the output when the program stops to see whether this it
411 * stopped due to a breakpoint.
412 * @param output The output of the debugger.
413 * @param id Returns the breakpoint id.
414 * @param file Returns the file name in which the breakpoint is.
415 * @param lineNo Returns the zero-based line number of the breakpoint.
416 * @param address Returns the address of the breakpoint.
417 * @return False if there was no breakpoint.
419 virtual bool parseBreakpoint(const char* output
, int& id
,
420 QString
& file
, int& lineNo
, QString
& address
) = 0;
423 * Parses the output of the DCinfolocals command.
424 * @param output The output of the debugger.
425 * @param newVars Receives the parsed variable values. The values are
426 * simply append()ed to the supplied list.
428 virtual void parseLocals(const char* output
, QList
<VarTree
>& newVars
) = 0;
431 * Parses the output of a DCprint or DCprintStruct command.
432 * @param output The output of the debugger.
433 * @param wantErrorValue Specifies whether the error message should be
434 * provided as the value of a NKplain variable. If this is false,
435 * #var will be 0 if the printed value is an error message.
436 * @param var Returns the variable value. It is set to 0 if there was
437 * a parse error or if the output is an error message and wantErrorValue
438 * is false. If it is not 0, #var->text() will return junk and must be
439 * set using #var->setText().
440 * @return false if the output is an error message. Even if true is
441 * returned, #var might still be 0 (due to a parse error).
443 virtual bool parsePrintExpr(const char* output
, bool wantErrorValue
,
447 * Parses the output of the DCcd command.
448 * @return false if the message is an error message.
450 virtual bool parseChangeWD(const char* output
, QString
& message
) = 0;
453 * Parses the output of the DCexecutable command.
454 * @return false if an error occured.
456 virtual bool parseChangeExecutable(const char* output
, QString
& message
) = 0;
459 * Parses the output of the DCcorefile command.
460 * @return false if the core file was not loaded successfully.
462 virtual bool parseCoreFile(const char* output
) = 0;
465 SFrefreshSource
= 1, /* refresh of source code is needed */
466 SFrefreshBreak
= 2, /* refresh breakpoints */
467 SFrefreshThreads
= 4, /* refresh thread list */
468 SFprogramActive
= 128 /* program remains active */
471 * Parses the output of commands that execute (a piece of) the program.
472 * @return The inclusive OR of zero or more of the StopFlags.
474 virtual uint
parseProgramStopped(const char* output
, QString
& message
) = 0;
477 * Parses the output of the DCsharedlibs command.
479 virtual void parseSharedLibs(const char* output
, QStrList
& shlibs
) = 0;
482 * Parses the output of the DCfindType command.
483 * @return true if a type was found.
485 virtual bool parseFindType(const char* output
, QString
& type
) = 0;
488 * Parses the output of the DCinforegisters command.
490 virtual void parseRegisters(const char* output
, QList
<RegisterInfo
>& regs
) = 0;
493 * Parses the output of the DCinfoline command. Returns false if the
494 * two addresses could not be found.
496 virtual bool parseInfoLine(const char* output
,
497 QString
& addrFrom
, QString
& addrTo
) = 0;
500 * Parses the ouput of the DCdisassemble command.
502 virtual void parseDisassemble(const char* output
, QList
<DisassembledCode
>& code
) = 0;
505 * Parses a memory dump. Returns an empty string if no error was found;
506 * otherwise it contains an error message.
508 virtual QString
parseMemoryDump(const char* output
, QList
<MemoryDump
>& memdump
) = 0;
511 /** Removes all commands from the low-priority queue. */
512 void flushLoPriQueue();
513 /** Removes all commands from the high-priority queue. */
514 void flushHiPriQueue();
516 QQueue
<CmdQueueItem
> m_hipriCmdQueue
;
517 QList
<CmdQueueItem
> m_lopriCmdQueue
;
519 * The active command is kept separately from other pending commands.
521 CmdQueueItem
* m_activeCmd
;
523 * Helper function that queues the given command string in the
524 * low-priority queue.
526 CmdQueueItem
* queueCmdString(DbgCommand cmd
, QString cmdString
,
529 * Helper function that queues the given command string in the
530 * high-priority queue.
532 CmdQueueItem
* executeCmdString(DbgCommand cmd
, QString cmdString
,
535 virtual void commandFinished(CmdQueueItem
* cmd
) = 0;
539 virtual int commSetupDoneC();
542 size_t m_promptMinLen
;
543 char m_promptLastChar
;
547 QString m_logFileName
;
551 virtual void slotReceiveOutput(KProcess
*, char* buffer
, int buflen
);
552 virtual void slotCommandRead(KProcess
*);
553 virtual void slotExited(KProcess
*);
557 * This signal is emitted when the output of a command has been fully
558 * collected and is ready to be interpreted.
560 void commandReceived(CmdQueueItem
* cmd
, const char* output
);
563 * This signal is emitted when the debugger recognizes that a specific
564 * location in a file ought to be displayed.
566 * Gdb's --fullname option supports this for the step, next, frame, and
567 * run commands (and possibly others).
569 * @param file specifies the file; this is not necessarily a full path
570 * name, and if it is relative, you won't know relative to what, you
572 * @param lineNo specifies the line number (0-based!) (this may be
573 * negative, in which case the file should be activated, but the line
574 * should NOT be changed).
575 * @param address specifies the exact address of the PC or is empty.
577 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
580 * This signal is emitted when a command that starts the inferior has
581 * been submitted to the debugger.
583 void inferiorRunning();
586 * This signal is emitted when all output from the debugger has been
587 * consumed and no more commands are in the queues.
589 void enterIdleState();
592 #endif // DBGDRIVER_H