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.
26 * A type representing an address.
33 DbgAddr(const QString
& aa
);
34 DbgAddr(const DbgAddr
& src
) : a(src
.a
), fnoffs(src
.fnoffs
) { }
35 void operator=(const QString
& aa
);
36 void operator=(const DbgAddr
& src
) { a
= src
.a
; fnoffs
= src
.fnoffs
; }
37 QString
asString() const;
38 bool isEmpty() const { return a
.isEmpty(); }
42 bool operator==(const DbgAddr
& a1
, const DbgAddr
& a2
);
43 bool operator>(const DbgAddr
& a1
, const DbgAddr
& a2
);
62 DCsetoption
, /* debugger options */
72 DCuntil
, /* line number is zero-based! */
75 DCbreakline
, /* line number is zero-based! */
76 DCtbreakline
, /* line number is zero-based! */
101 RDNstdin
= 0x1, /* redirect stdin to /dev/null */
102 RDNstdout
= 0x2, /* redirect stdout to /dev/null */
103 RDNstderr
= 0x4 /* redirect stderr to /dev/null */
107 * How the memory dump is formated. The lowest 4 bits define the size of
108 * the entities. The higher bits define how these are formatted. Note that
109 * not all combinations make sense.
111 enum MemoryDumpType
{
135 * Debugger commands are placed in a queue. Only one command at a time is
136 * sent down to the debugger. All other commands in the queue are retained
137 * until the sent command has been processed by gdb. The debugger tells us
138 * that it's done with the command by sending the prompt. The output of the
139 * debugger is parsed at that time. Then, if more commands are in the
140 * queue, the next one is sent to the debugger.
146 bool m_committed
; /* just a debugging aid */
147 // remember which expression when printing an expression
150 // remember file position
154 // the breakpoint info
157 // whether command was emitted due to direct user request (only set when relevant)
160 CmdQueueItem(DbgCommand cmd
, const QString
& str
) :
174 IsEqualCmd(DbgCommand cmd
, const QString
& str
) : m_cmd(cmd
), m_str(str
) { }
175 bool operator()(CmdQueueItem
*) const;
177 const QString
& m_str
;
182 * The information about a breakpoint that is parsed from the list of
187 int id
; /* gdb's number */
189 breakpoint
, watchpoint
194 QString text
; /* text if set using DCbreaktext */
195 DbgAddr address
; /* exact address of breakpoint */
196 QString condition
; /* condition as printed by gdb */
197 int ignoreCount
; /* ignore next that may hits */
198 int hitCount
; /* as reported by gdb */
199 // the following items repeat the location, but in a better usable way
201 int lineNo
; /* zero-based line number */
203 bool isOrphaned() const { return id
< 0; }
207 * Information about a stack frame.
212 int lineNo
; /* zero-based line number */
213 DbgAddr address
; /* exact address of PC */
217 * The information about a stack frame as parsed from the backtrace.
219 struct StackFrame
: FrameInfo
222 ExprValue
* var
; /* more information if non-zero */
223 StackFrame() : var(0) { }
228 * The information about a thread as parsed from the threads list.
230 struct ThreadInfo
: FrameInfo
232 int id
; /* gdb's number */
233 QString threadName
; /* the SYSTAG */
234 QString function
; /* where thread is halted */
235 bool hasFocus
; /* the thread whose stack we are watching */
239 * Register information
245 QString cookedValue
; /* may be empty */
246 QString type
; /* of vector register if not empty */
252 struct DisassembledCode
268 * This is an abstract base class for debugger process.
270 * This class represents the debugger program. It provides the low-level
271 * interface to the commandline debugger. As such it implements the
272 * commands and parses the output.
274 class DebuggerDriver
: public KProcess
279 virtual ~DebuggerDriver() = 0;
281 virtual QString
driverName() const = 0;
283 * Returns the default command string to invoke the debugger driver.
285 virtual QString
defaultInvocation() const = 0;
288 * Returns a list of options that can be turned on and off.
290 virtual QStringList
boolOptionList() const = 0;
292 virtual bool startup(QString cmdStr
);
293 void setLogFileName(const QString
& fname
) { m_logFileName
= fname
; }
299 DSidle
, /* gdb waits for input */
300 DSinterrupted
, /* a command was interrupted */
301 DSrunningLow
, /* gdb is running a low-priority command */
302 DSrunning
, /* gdb waits for program */
303 DScommandSent
, /* command has been sent, we wait for wroteStdin signal */
304 DScommandSentLow
/* low-prioritycommand has been sent */
306 DebuggerState m_state
;
309 bool isIdle() const { return m_state
== DSidle
; }
311 * Tells whether a high prority command would be executed immediately.
313 bool canExecuteImmediately() const { return m_hipriCmdQueue
.empty(); }
316 char* m_output
; /* normal gdb output */
317 size_t m_outputLen
; /* amount of data so far accumulated in m_output */
318 size_t m_outputAlloc
; /* space available in m_output */
319 std::queue
<QByteArray
> m_delayedOutput
; /* output colleced while we have receivedOutput */
320 /* but before signal wroteStdin arrived */
324 * Enqueues a high-priority command. High-priority commands are
325 * executed before any low-priority commands. No user interaction is
326 * possible as long as there is a high-priority command in the queue.
328 virtual CmdQueueItem
* executeCmd(DbgCommand
,
329 bool clearLow
= false) = 0;
330 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
,
331 bool clearLow
= false) = 0;
332 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg
,
333 bool clearLow
= false) = 0;
334 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg
, int intArg
,
335 bool clearLow
= false) = 0;
336 virtual CmdQueueItem
* executeCmd(DbgCommand
, QString strArg1
, QString strArg2
,
337 bool clearLow
= false) = 0;
338 virtual CmdQueueItem
* executeCmd(DbgCommand
, int intArg1
, int intArg2
,
339 bool clearLow
= false) = 0;
342 QMnormal
, /* queues the command last */
343 QMoverride
, /* removes an already queued command */
344 QMoverrideMoreEqual
/* ditto, also puts the command first in the queue */
348 * Enqueues a low-priority command. Low-priority commands are executed
349 * after any high-priority commands.
351 virtual CmdQueueItem
* queueCmd(DbgCommand
,
353 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
,
355 virtual CmdQueueItem
* queueCmd(DbgCommand
, int intArg
,
357 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg
, int intArg
,
359 virtual CmdQueueItem
* queueCmd(DbgCommand
, QString strArg1
, QString strArg2
,
363 * Flushes the command queues.
364 * @param hipriOnly if true, only the high priority queue is flushed.
366 virtual void flushCommands(bool hipriOnly
= false);
369 * Terminates the debugger process.
371 virtual void terminate() = 0;
374 * Terminates the debugger process, but also detaches any program that
375 * it has been attached to.
377 virtual void detachAndTerminate() = 0;
380 * Interrupts the debuggee.
382 virtual void interruptInferior() = 0;
385 * Specifies the command that prints the QString data.
387 virtual void setPrintQStringDataCmd(const char* cmd
) = 0;
390 * Parses the output as an array of QChars.
392 virtual ExprValue
* parseQCharArray(const char* output
, bool wantErrorValue
, bool qt3like
) = 0;
395 * Parses a back-trace (the output of the DCbt command).
397 virtual void parseBackTrace(const char* output
, std::list
<StackFrame
>& stack
) = 0;
400 * Parses the output of the DCframe command;
401 * @param frameNo Returns the frame number.
402 * @param file Returns the source file name.
403 * @param lineNo The zero-based line number.
404 * @param address Returns the exact address.
405 * @return false if the frame could not be parsed successfully. The
406 * output values are undefined in this case.
408 virtual bool parseFrameChange(const char* output
, int& frameNo
,
409 QString
& file
, int& lineNo
, DbgAddr
& address
) = 0;
412 * Parses a list of breakpoints.
413 * @param output The output of the debugger.
414 * @param brks The list of new #Breakpoint objects. The list
415 * must initially be empty.
416 * @return False if there was an error before the first breakpoint
417 * was found. Even if true is returned, #brks may be empty.
419 virtual bool parseBreakList(const char* output
, std::list
<Breakpoint
>& brks
) = 0;
422 * Parses a list of threads.
423 * @param output The output of the debugger.
424 * @return The new thread list. There is no indication if there was
427 virtual std::list
<ThreadInfo
> parseThreadList(const char* output
) = 0;
430 * Parses the output when the program stops to see whether this it
431 * stopped due to a breakpoint.
432 * @param output The output of the debugger.
433 * @param id Returns the breakpoint id.
434 * @param file Returns the file name in which the breakpoint is.
435 * @param lineNo Returns the zero-based line number of the breakpoint.
436 * @param address Returns the address of the breakpoint.
437 * @return False if there was no breakpoint.
439 virtual bool parseBreakpoint(const char* output
, int& id
,
440 QString
& file
, int& lineNo
, QString
& address
) = 0;
443 * Parses the output of the DCinfolocals command.
444 * @param output The output of the debugger.
445 * @param newVars Receives the parsed variable values. The values are
446 * simply append()ed to the supplied list.
448 virtual void parseLocals(const char* output
, std::list
<ExprValue
*>& newVars
) = 0;
451 * Parses the output of a DCprint or DCprintStruct command.
452 * @param output The output of the debugger.
453 * @param wantErrorValue Specifies whether the error message should be
454 * provided as the value of a NKplain variable. If this is false,
455 * 0 is returned if the printed value is an error message.
456 * @return the parsed value. It is 0 if there was a parse error
457 * or if the output is an error message and #wantErrorValue
458 * is \c false. The returned object's text() is undefined.
460 virtual ExprValue
* parsePrintExpr(const char* output
, bool wantErrorValue
) = 0;
463 * Parses the output of the DCcd command.
464 * @return false if the message is an error message.
466 virtual bool parseChangeWD(const char* output
, QString
& message
) = 0;
469 * Parses the output of the DCexecutable command.
470 * @return false if an error occured.
472 virtual bool parseChangeExecutable(const char* output
, QString
& message
) = 0;
475 * Parses the output of the DCcorefile command.
476 * @return false if the core file was not loaded successfully.
478 virtual bool parseCoreFile(const char* output
) = 0;
481 SFrefreshSource
= 1, /* refresh of source code is needed */
482 SFrefreshBreak
= 2, /* refresh breakpoints */
483 SFrefreshThreads
= 4, /* refresh thread list */
484 SFprogramActive
= 128 /* program remains active */
487 * Parses the output of commands that execute (a piece of) the program.
488 * @return The inclusive OR of zero or more of the StopFlags.
490 virtual uint
parseProgramStopped(const char* output
, QString
& message
) = 0;
493 * Parses the output of the DCsharedlibs command.
495 virtual QStringList
parseSharedLibs(const char* output
) = 0;
498 * Parses the output of the DCfindType command.
499 * @return true if a type was found.
501 virtual bool parseFindType(const char* output
, QString
& type
) = 0;
504 * Parses the output of the DCinforegisters command.
506 virtual std::list
<RegisterInfo
> parseRegisters(const char* output
) = 0;
509 * Parses the output of the DCinfoline command. Returns false if the
510 * two addresses could not be found.
512 virtual bool parseInfoLine(const char* output
,
513 QString
& addrFrom
, QString
& addrTo
) = 0;
516 * Parses the ouput of the DCdisassemble command.
518 virtual std::list
<DisassembledCode
> parseDisassemble(const char* output
) = 0;
521 * Parses a memory dump. Returns an empty string if no error was found;
522 * otherwise it contains an error message.
524 virtual QString
parseMemoryDump(const char* output
, std::list
<MemoryDump
>& memdump
) = 0;
527 * Parses the output of the DCsetvariable command. Returns an empty
528 * string if no error was found; otherwise it contains an error
531 virtual QString
parseSetVariable(const char* output
) = 0;
534 * Returns a value that the user can edit.
536 virtual QString
editableValue(VarTree
* value
);
539 /** Removes all commands from the low-priority queue. */
540 void flushLoPriQueue();
541 /** Removes all commands from the high-priority queue. */
542 void flushHiPriQueue();
544 std::queue
<CmdQueueItem
*> m_hipriCmdQueue
;
545 std::list
<CmdQueueItem
*> m_lopriCmdQueue
;
547 * The active command is kept separately from other pending commands.
549 CmdQueueItem
* m_activeCmd
;
551 * Helper function that queues the given command string in the
552 * low-priority queue.
554 CmdQueueItem
* queueCmdString(DbgCommand cmd
, QString cmdString
,
557 * Helper function that queues the given command string in the
558 * high-priority queue.
560 CmdQueueItem
* executeCmdString(DbgCommand cmd
, QString cmdString
,
563 virtual void commandFinished(CmdQueueItem
* cmd
) = 0;
567 virtual int commSetupDoneC();
570 size_t m_promptMinLen
;
571 char m_promptLastChar
;
575 QString m_logFileName
;
579 void dequeueCmdByVar(VarTree
* var
);
582 virtual void slotReceiveOutput(KProcess
*, char* buffer
, int buflen
);
583 virtual void slotCommandRead(KProcess
*);
584 virtual void slotExited(KProcess
*);
588 * This signal is emitted when the output of a command has been fully
589 * collected and is ready to be interpreted.
591 void commandReceived(CmdQueueItem
* cmd
, const char* output
);
594 * This signal is emitted when the debugger recognizes that a specific
595 * location in a file ought to be displayed.
597 * Gdb's --fullname option supports this for the step, next, frame, and
598 * run commands (and possibly others).
600 * @param file specifies the file; this is not necessarily a full path
601 * name, and if it is relative, you won't know relative to what, you
603 * @param lineNo specifies the line number (0-based!) (this may be
604 * negative, in which case the file should be activated, but the line
605 * should NOT be changed).
606 * @param address specifies the exact address of the PC or is empty.
608 void activateFileLine(const QString
& file
, int lineNo
, const DbgAddr
& address
);
611 * This signal is emitted when a command that starts the inferior has
612 * been submitted to the debugger.
614 void inferiorRunning();
617 * This signal is emitted when all output from the debugger has been
618 * consumed and no more commands are in the queues.
620 void enterIdleState();
623 #endif // DBGDRIVER_H