2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
25 * A type representing an address.
32 DbgAddr(const QString
& aa
);
33 DbgAddr(const DbgAddr
& src
) : a(src
.a
), fnoffs(src
.fnoffs
) { }
34 void operator=(const QString
& aa
);
35 void operator=(const DbgAddr
& src
) { a
= src
.a
; fnoffs
= src
.fnoffs
; }
36 QString
asString() const;
37 bool isEmpty() const { return a
.isEmpty(); }
41 bool operator==(const DbgAddr
& a1
, const DbgAddr
& a2
);
42 bool operator>(const DbgAddr
& a1
, const DbgAddr
& a2
);
61 DCsetoption
, /* debugger options */
71 DCuntil
, /* line number is zero-based! */
75 DCbreakline
, /* line number is zero-based! */
76 DCtbreakline
, /* line number is zero-based! */
102 RDNstdin
= 0x1, /* redirect stdin to /dev/null */
103 RDNstdout
= 0x2, /* redirect stdout to /dev/null */
104 RDNstderr
= 0x4 /* redirect stderr to /dev/null */
108 * How the memory dump is formated. The lowest 4 bits define the size of
109 * the entities. The higher bits define how these are formatted. Note that
110 * not all combinations make sense.
112 enum MemoryDumpType
{
136 * Debugger commands are placed in a queue. Only one command at a time is
137 * sent down to the debugger. All other commands in the queue are retained
138 * until the sent command has been processed by gdb. The debugger tells us
139 * that it's done with the command by sending the prompt. The output of the
140 * debugger is parsed at that time. Then, if more commands are in the
141 * queue, the next one is sent to the debugger.
147 bool m_committed
; /* just a debugging aid */
148 // remember which expression when printing an expression
151 // remember file position
155 // the breakpoint info
158 // whether command was emitted due to direct user request (only set when relevant)
160 // used to store the expression to print in case of DCprintPopup is executed
163 CmdQueueItem(DbgCommand cmd
, const QString
& str
) :
177 IsEqualCmd(DbgCommand cmd
, const QString
& str
) : m_cmd(cmd
), m_str(str
) { }
178 bool operator()(CmdQueueItem
*) const;
180 const QString
& m_str
;
185 * The information about a breakpoint that is parsed from the list of
190 int id
; /* gdb's number */
192 breakpoint
, watchpoint
197 QString text
; /* text if set using DCbreaktext */
198 DbgAddr address
; /* exact address of breakpoint */
199 QString condition
; /* condition as printed by gdb */
200 int ignoreCount
; /* ignore next that may hits */
201 int hitCount
; /* as reported by gdb */
202 // the following items repeat the location, but in a better usable way
204 int lineNo
; /* zero-based line number */
206 bool isOrphaned() const { return id
< 0; }
210 * Information about a stack frame.
215 int lineNo
; /* zero-based line number */
216 DbgAddr address
; /* exact address of PC */
220 * The information about a stack frame as parsed from the backtrace.
222 struct StackFrame
: FrameInfo
225 ExprValue
* var
; /* more information if non-zero */
226 StackFrame() : var(0) { }
231 * The information about a thread as parsed from the threads list.
233 struct ThreadInfo
: FrameInfo
235 int id
; /* gdb's number */
236 QString threadName
; /* the SYSTAG */
237 QString function
; /* where thread is halted */
238 bool hasFocus
; /* the thread whose stack we are watching */
242 * Register information
248 QString cookedValue
; /* may be empty */
249 QString type
; /* of vector register if not empty */
255 struct DisassembledCode
271 * This is an abstract base class for debugger process.
273 * This class represents the debugger program. It provides the low-level
274 * interface to the commandline debugger. As such it implements the
275 * commands and parses the output.
277 class DebuggerDriver
: public QProcess
282 virtual ~DebuggerDriver() = 0;
284 virtual QString
driverName() const = 0;
286 * Returns the default command string to invoke the debugger driver.
288 virtual QString
defaultInvocation() const = 0;
291 * Returns a list of options that can be turned on and off.
293 virtual QStringList
boolOptionList() const = 0;
295 virtual bool startup(QString cmdStr
);
296 void setLogFileName(const QString
& fname
) { m_logFileName
= fname
; }
297 bool isRunning() { return state() != NotRunning
; }
303 DSidle
, /* gdb waits for input */
304 DSinterrupted
, /* a command was interrupted */
305 DSrunningLow
, /* gdb is running a low-priority command */
306 DSrunning
, /* gdb waits for program */
307 DScommandSent
, /* command has been sent, we wait for wroteStdin signal */
308 DScommandSentLow
/* low-prioritycommand has been sent */
310 DebuggerState m_state
;
313 bool isIdle() const { return m_state
== DSidle
; }
315 * Tells whether a high prority command would be executed immediately.
317 bool canExecuteImmediately() const { return m_hipriCmdQueue
.empty(); }
320 QByteArray m_output
; // normal gdb output
321 std::queue
<QByteArray
> m_delayedOutput
; // output colleced before signal bytesWritten() arrived
325 * Enqueues a high-priority command. High-priority commands are
326 * executed before any low-priority commands. No user interaction is
327 * possible as long as there is a high-priority command in the queue.
329 virtual CmdQueueItem
* executeCmd(DbgCommand
,
330 bool clearLow
= false) = 0;
331 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
,
332 bool clearLow
= false) = 0;
333 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg
,
334 bool clearLow
= false) = 0;
335 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
, int intArg
,
336 bool clearLow
= false) = 0;
337 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg1
, QString strArg2
,
338 bool clearLow
= false) = 0;
339 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg1
, int intArg2
,
340 bool clearLow
= false) = 0;
343 QMnormal
, /* queues the command last */
344 QMoverride
, /* removes an already queued command */
345 QMoverrideMoreEqual
/* ditto, also puts the command first in the queue */
349 * Enqueues a low-priority command. Low-priority commands are executed
350 * after any high-priority commands.
352 virtual CmdQueueItem
* queueCmd(DbgCommand
,
354 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
,
356 virtual CmdQueueItem
* queueCmd(DbgCommand
, int intArg
,
358 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
, int intArg
,
360 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg1
, QString strArg2
,
364 * Flushes the command queues.
365 * @param hipriOnly if true, only the high priority queue is flushed.
367 virtual void flushCommands(bool hipriOnly
= false);
370 * Terminates the debugger process.
372 virtual void terminate() = 0;
375 * Terminates the debugger process, but also detaches any program that
376 * it has been attached to.
378 virtual void detachAndTerminate() = 0;
381 * Interrupts the debuggee.
383 virtual void interruptInferior() = 0;
386 * Specifies the command that prints the QString data.
388 virtual void setPrintQStringDataCmd(const char* cmd
) = 0;
391 * Parses the output as an array of QChars.
393 virtual ExprValue
* parseQCharArray(const char* output
, bool wantErrorValue
, bool qt3like
) = 0;
396 * Parses a back-trace (the output of the DCbt command).
398 virtual void parseBackTrace(const char* output
, std::list
<StackFrame
>& stack
) = 0;
401 * Parses the output of the DCframe command;
402 * @param frameNo Returns the frame number.
403 * @param file Returns the source file name.
404 * @param lineNo The zero-based line number.
405 * @param address Returns the exact address.
406 * @return false if the frame could not be parsed successfully. The
407 * output values are undefined in this case.
409 virtual bool parseFrameChange(const char* output
, int& frameNo
,
410 QString
& file
, int& lineNo
, DbgAddr
& address
) = 0;
413 * Parses a list of breakpoints.
414 * @param output The output of the debugger.
415 * @param brks The list of new #Breakpoint objects. The list
416 * must initially be empty.
417 * @return False if there was an error before the first breakpoint
418 * was found. Even if true is returned, #brks may be empty.
420 virtual bool parseBreakList(const char* output
, std::list
<Breakpoint
>& brks
) = 0;
423 * Parses a list of threads.
424 * @param output The output of the debugger.
425 * @return The new thread list. There is no indication if there was
428 virtual std::list
<ThreadInfo
> parseThreadList(const char* output
) = 0;
431 * Parses the output when the program stops to see whether this it
432 * stopped due to a breakpoint.
433 * @param output The output of the debugger.
434 * @param id Returns the breakpoint id.
435 * @param file Returns the file name in which the breakpoint is.
436 * @param lineNo Returns the zero-based line number of the breakpoint.
437 * @param address Returns the address of the breakpoint.
438 * @return False if there was no breakpoint.
440 virtual bool parseBreakpoint(const char* output
, int& id
,
441 QString
& file
, int& lineNo
, QString
& address
) = 0;
444 * Parses the output of the DCinfolocals command.
445 * @param output The output of the debugger.
446 * @param newVars Receives the parsed variable values. The values are
447 * simply append()ed to the supplied list.
449 virtual void parseLocals(const char* output
, std::list
<ExprValue
*>& newVars
) = 0;
452 * Parses the output of a DCprint or DCprintStruct command.
453 * @param output The output of the debugger.
454 * @param wantErrorValue Specifies whether the error message should be
455 * provided as the value of a NKplain variable. If this is false,
456 * 0 is returned if the printed value is an error message.
457 * @return the parsed value. It is 0 if there was a parse error
458 * or if the output is an error message and #wantErrorValue
459 * is \c false. The returned object's text() is undefined.
461 virtual ExprValue
* parsePrintExpr(const char* output
, bool wantErrorValue
) = 0;
464 * Parses the output of the DCcd command.
465 * @return false if the message is an error message.
467 virtual bool parseChangeWD(const char* output
, QString
& message
) = 0;
470 * Parses the output of the DCexecutable command.
471 * @return false if an error occured.
473 virtual bool parseChangeExecutable(const char* output
, QString
& message
) = 0;
476 * Parses the output of the DCcorefile command.
477 * @return false if the core file was not loaded successfully.
479 virtual bool parseCoreFile(const char* output
) = 0;
482 SFrefreshSource
= 1, /* refresh of source code is needed */
483 SFrefreshBreak
= 2, /* refresh breakpoints */
484 SFrefreshThreads
= 4, /* refresh thread list */
485 SFprogramActive
= 128 /* program remains active */
488 * Parses the output of commands that execute (a piece of) the program.
489 * @return The inclusive OR of zero or more of the StopFlags.
491 virtual uint
parseProgramStopped(const char* output
, QString
& message
) = 0;
494 * Parses the output of the DCsharedlibs command.
496 virtual QStringList
parseSharedLibs(const char* output
) = 0;
499 * Parses the output of the DCfindType command.
500 * @return true if a type was found.
502 virtual bool parseFindType(const char* output
, QString
& type
) = 0;
505 * Parses the output of the DCinforegisters command.
507 virtual std::list
<RegisterInfo
> parseRegisters(const char* output
) = 0;
510 * Parses the output of the DCinfoline command. Returns false if the
511 * two addresses could not be found.
513 virtual bool parseInfoLine(const char* output
,
514 QString
& addrFrom
, QString
& addrTo
) = 0;
517 * Parses the ouput of the DCdisassemble command.
519 virtual std::list
<DisassembledCode
> parseDisassemble(const char* output
) = 0;
522 * Parses a memory dump. Returns an empty string if no error was found;
523 * otherwise it contains an error message.
525 virtual QString
parseMemoryDump(const char* output
, std::list
<MemoryDump
>& memdump
) = 0;
528 * Parses the output of the DCsetvariable command. Returns an empty
529 * string if no error was found; otherwise it contains an error
532 virtual QString
parseSetVariable(const char* output
) = 0;
535 * Returns a value that the user can edit.
537 virtual QString
editableValue(VarTree
* value
);
540 /** Removes all commands from the low-priority queue. */
541 void flushLoPriQueue();
542 /** Removes all commands from the high-priority queue. */
543 void flushHiPriQueue();
545 std::queue
<CmdQueueItem
*> m_hipriCmdQueue
;
546 std::list
<CmdQueueItem
*> m_lopriCmdQueue
;
548 * The active command is kept separately from other pending commands.
550 CmdQueueItem
* m_activeCmd
;
552 * Helper function that queues the given command string in the
553 * low-priority queue.
555 CmdQueueItem
* queueCmdString(DbgCommand cmd
, QString cmdString
,
558 * Helper function that queues the given command string in the
559 * high-priority queue.
561 CmdQueueItem
* executeCmdString(DbgCommand cmd
, QString cmdString
,
564 virtual void commandFinished(CmdQueueItem
* cmd
) = 0;
567 void processOutput(const QByteArray
& data
);
570 * Returns the start of the prompt in \a output or -1.
571 * \a len specifies the size of \a output, but in addition, the contents
572 * of \a output are NUL-terminated, i.e., \c output[len] is zero.
574 virtual int findPrompt(const QByteArray
& output
) const = 0;
577 QString m_logFileName
;
581 void dequeueCmdByVar(VarTree
* var
);
584 virtual void slotReceiveOutput();
585 virtual void slotCommandRead();
586 virtual void slotExited();
590 * This signal is emitted when the output of a command has been fully
591 * collected and is ready to be interpreted.
593 void commandReceived(CmdQueueItem
* cmd
, const char* output
);
596 * This signal is emitted when the debugger recognizes that a specific
597 * location in a file ought to be displayed.
599 * Gdb's --fullname option supports this for the step, next, frame, and
600 * run commands (and possibly others).
602 * @param file specifies the file; this is not necessarily a full path
603 * name, and if it is relative, you won't know relative to what, you
605 * @param lineNo specifies the line number (0-based!) (this may be
606 * negative, in which case the file should be activated, but the line
607 * should NOT be changed).
608 * @param address specifies the exact address of the PC or is empty.
610 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
613 * This signal is emitted when a command that starts the inferior has
614 * been submitted to the debugger.
616 void inferiorRunning();
619 * This signal is emitted when all output from the debugger has been
620 * consumed and no more commands are in the queues.
622 void enterIdleState();
625 #endif // DBGDRIVER_H