Fixed the notice about the konsole invocation.
[kdbg.git] / kdbg / gdbdriver.cpp
blob7597643c399e8a00e991f5bc459c1a77cc4ae53f
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include "gdbdriver.h"
7 #include "exprwnd.h"
8 #include <qregexp.h>
9 #include <qstringlist.h>
10 #include <klocale.h> /* i18n */
11 #include <ctype.h>
12 #include <stdlib.h> /* strtol, atoi */
13 #include <string.h> /* strcpy */
15 #include "assert.h"
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 #include "mydebug.h"
21 static void skipString(const char*& p);
22 static void skipNested(const char*& s, char opening, char closing);
23 static VarTree* parseVar(const char*& s);
24 static bool parseName(const char*& s, QString& name, VarTree::NameKind& kind);
25 static bool parseValue(const char*& s, VarTree* variable);
26 static bool parseNested(const char*& s, VarTree* variable);
27 static bool parseVarSeq(const char*& s, VarTree* variable);
28 static bool parseValueSeq(const char*& s, VarTree* variable);
30 #define PROMPT "(kdbg)"
31 #define PROMPT_LEN 6
32 #define PROMPT_LAST_CHAR ')' /* needed when searching for prompt string */
35 // TODO: make this cmd info stuff non-static to allow multiple
36 // simultaneous gdbs to run!
38 struct GdbCmdInfo {
39 DbgCommand cmd;
40 const char* fmt; /* format string */
41 enum Args {
42 argNone, argString, argNum,
43 argStringNum, argNumString,
44 argString2, argNum2
45 } argsNeeded;
48 #if 0
49 // This is how the QString data print statement generally looks like.
50 // It is set by KDebugger via setPrintQStringDataCmd().
52 static const char printQStringStructFmt[] =
53 // if the string data is junk, fail early
54 "print ($qstrunicode=($qstrdata=(%s))->unicode)?"
55 // print an array of shorts
56 "(*(unsigned short*)$qstrunicode)@"
57 // limit the length
58 "(($qstrlen=(unsigned int)($qstrdata->len))>100?100:$qstrlen)"
59 // if unicode data is 0, report a special value
60 ":1==0\n";
61 #endif
62 static const char printQStringStructFmt[] = "print (0?\"%s\":$kdbgundef)\n";
65 * The following array of commands must be sorted by the DC* values,
66 * because they are used as indices.
68 static GdbCmdInfo cmds[] = {
69 { DCinitialize, "", GdbCmdInfo::argNone },
70 { DCtty, "tty %s\n", GdbCmdInfo::argString },
71 { DCexecutable, "file \"%s\"\n", GdbCmdInfo::argString },
72 { DCtargetremote, "target remote %s\n", GdbCmdInfo::argString },
73 { DCcorefile, "core-file %s\n", GdbCmdInfo::argString },
74 { DCattach, "attach %s\n", GdbCmdInfo::argString },
75 { DCinfolinemain, "kdbg_infolinemain\n", GdbCmdInfo::argNone },
76 { DCinfolocals, "kdbg__alllocals\n", GdbCmdInfo::argNone },
77 { DCinforegisters, "info all-registers\n", GdbCmdInfo::argNone},
78 { DCexamine, "x %s %s\n", GdbCmdInfo::argString2 },
79 { DCinfoline, "info line %s:%d\n", GdbCmdInfo::argStringNum },
80 { DCdisassemble, "disassemble %s %s\n", GdbCmdInfo::argString2 },
81 { DCsetargs, "set args %s\n", GdbCmdInfo::argString },
82 { DCsetenv, "set env %s %s\n", GdbCmdInfo::argString2 },
83 { DCunsetenv, "unset env %s\n", GdbCmdInfo::argString },
84 { DCsetoption, "setoption %s %d\n", GdbCmdInfo::argStringNum},
85 { DCcd, "cd %s\n", GdbCmdInfo::argString },
86 { DCbt, "bt\n", GdbCmdInfo::argNone },
87 { DCrun, "run\n", GdbCmdInfo::argNone },
88 { DCcont, "cont\n", GdbCmdInfo::argNone },
89 { DCstep, "step\n", GdbCmdInfo::argNone },
90 { DCstepi, "stepi\n", GdbCmdInfo::argNone },
91 { DCnext, "next\n", GdbCmdInfo::argNone },
92 { DCnexti, "nexti\n", GdbCmdInfo::argNone },
93 { DCfinish, "finish\n", GdbCmdInfo::argNone },
94 { DCuntil, "until %s:%d\n", GdbCmdInfo::argStringNum },
95 { DCkill, "kill\n", GdbCmdInfo::argNone },
96 { DCbreaktext, "break %s\n", GdbCmdInfo::argString },
97 { DCbreakline, "break %s:%d\n", GdbCmdInfo::argStringNum },
98 { DCtbreakline, "tbreak %s:%d\n", GdbCmdInfo::argStringNum },
99 { DCbreakaddr, "break *%s\n", GdbCmdInfo::argString },
100 { DCtbreakaddr, "tbreak *%s\n", GdbCmdInfo::argString },
101 { DCwatchpoint, "watch %s\n", GdbCmdInfo::argString },
102 { DCdelete, "delete %d\n", GdbCmdInfo::argNum },
103 { DCenable, "enable %d\n", GdbCmdInfo::argNum },
104 { DCdisable, "disable %d\n", GdbCmdInfo::argNum },
105 { DCprint, "print %s\n", GdbCmdInfo::argString },
106 { DCprintDeref, "print *(%s)\n", GdbCmdInfo::argString },
107 { DCprintStruct, "print %s\n", GdbCmdInfo::argString },
108 { DCprintQStringStruct, printQStringStructFmt, GdbCmdInfo::argString},
109 { DCframe, "frame %d\n", GdbCmdInfo::argNum },
110 { DCfindType, "whatis %s\n", GdbCmdInfo::argString },
111 { DCinfosharedlib, "info sharedlibrary\n", GdbCmdInfo::argNone },
112 { DCthread, "thread %d\n", GdbCmdInfo::argNum },
113 { DCinfothreads, "info threads\n", GdbCmdInfo::argNone },
114 { DCinfobreak, "info breakpoints\n", GdbCmdInfo::argNone },
115 { DCcondition, "condition %d %s\n", GdbCmdInfo::argNumString},
116 { DCsetpc, "set variable $pc=%s\n", GdbCmdInfo::argString },
117 { DCignore, "ignore %d %d\n", GdbCmdInfo::argNum2},
118 { DCsetvariable, "set variable %s=%s\n", GdbCmdInfo::argString2 },
121 #define NUM_CMDS (int(sizeof(cmds)/sizeof(cmds[0])))
122 #define MAX_FMTLEN 200
124 GdbDriver::GdbDriver() :
125 DebuggerDriver(),
126 m_gdbMajor(4), m_gdbMinor(16)
128 strcpy(m_prompt, PROMPT);
129 m_promptMinLen = PROMPT_LEN;
130 m_promptLastChar = PROMPT_LAST_CHAR;
132 #ifndef NDEBUG
133 // check command info array
134 char* perc;
135 for (int i = 0; i < NUM_CMDS; i++) {
136 // must be indexable by DbgCommand values, i.e. sorted by DbgCommand values
137 assert(i == cmds[i].cmd);
138 // a format string must be associated
139 assert(cmds[i].fmt != 0);
140 assert(strlen(cmds[i].fmt) <= MAX_FMTLEN);
141 // format string must match arg specification
142 switch (cmds[i].argsNeeded) {
143 case GdbCmdInfo::argNone:
144 assert(strchr(cmds[i].fmt, '%') == 0);
145 break;
146 case GdbCmdInfo::argString:
147 perc = strchr(cmds[i].fmt, '%');
148 assert(perc != 0 && perc[1] == 's');
149 assert(strchr(perc+2, '%') == 0);
150 break;
151 case GdbCmdInfo::argNum:
152 perc = strchr(cmds[i].fmt, '%');
153 assert(perc != 0 && perc[1] == 'd');
154 assert(strchr(perc+2, '%') == 0);
155 break;
156 case GdbCmdInfo::argStringNum:
157 perc = strchr(cmds[i].fmt, '%');
158 assert(perc != 0 && perc[1] == 's');
159 perc = strchr(perc+2, '%');
160 assert(perc != 0 && perc[1] == 'd');
161 assert(strchr(perc+2, '%') == 0);
162 break;
163 case GdbCmdInfo::argNumString:
164 perc = strchr(cmds[i].fmt, '%');
165 assert(perc != 0 && perc[1] == 'd');
166 perc = strchr(perc+2, '%');
167 assert(perc != 0 && perc[1] == 's');
168 assert(strchr(perc+2, '%') == 0);
169 break;
170 case GdbCmdInfo::argString2:
171 perc = strchr(cmds[i].fmt, '%');
172 assert(perc != 0 && perc[1] == 's');
173 perc = strchr(perc+2, '%');
174 assert(perc != 0 && perc[1] == 's');
175 assert(strchr(perc+2, '%') == 0);
176 break;
177 case GdbCmdInfo::argNum2:
178 perc = strchr(cmds[i].fmt, '%');
179 assert(perc != 0 && perc[1] == 'd');
180 perc = strchr(perc+2, '%');
181 assert(perc != 0 && perc[1] == 'd');
182 assert(strchr(perc+2, '%') == 0);
183 break;
186 assert(strlen(printQStringStructFmt) <= MAX_FMTLEN);
187 #endif
190 GdbDriver::~GdbDriver()
195 QString GdbDriver::driverName() const
197 return "GDB";
200 QString GdbDriver::defaultGdb()
202 return
203 "gdb"
204 " --fullname" /* to get standard file names each time the prog stops */
205 " --nx"; /* do not execute initialization files */
208 QString GdbDriver::defaultInvocation() const
210 if (m_defaultCmd.isEmpty()) {
211 return defaultGdb();
212 } else {
213 return m_defaultCmd;
217 QStringList GdbDriver::boolOptionList() const
219 // no options
220 return QStringList();
223 bool GdbDriver::startup(QString cmdStr)
225 if (!DebuggerDriver::startup(cmdStr))
226 return false;
228 static const char gdbInitialize[] =
230 * Work around buggy gdbs that do command line editing even if they
231 * are not on a tty. The readline library echos every command back
232 * in this case, which is confusing for us.
234 "set editing off\n"
235 "set confirm off\n"
236 "set print static-members off\n"
237 "set print asm-demangle on\n"
239 * Don't assume that program functions invoked from a watch expression
240 * always succeed.
242 "set unwindonsignal on\n"
244 * Write a short macro that prints all locals: local variables and
245 * function arguments.
247 "define kdbg__alllocals\n"
248 "info locals\n" /* local vars supersede args with same name */
249 "info args\n" /* therefore, arguments must come last */
250 "end\n"
252 * Work around a bug in gdb-6.3: "info line main" crashes gdb.
254 "define kdbg_infolinemain\n"
255 "list\n"
256 "info line\n"
257 "end\n"
258 // change prompt string and synchronize with gdb
259 "set prompt " PROMPT "\n"
262 executeCmdString(DCinitialize, gdbInitialize, false);
264 // assume that QString::null is ok
265 cmds[DCprintQStringStruct].fmt = printQStringStructFmt;
267 return true;
270 void GdbDriver::commandFinished(CmdQueueItem* cmd)
272 // command string must be committed
273 if (!cmd->m_committed) {
274 // not commited!
275 TRACE("calling " + (__PRETTY_FUNCTION__ + (" with uncommited command:\n\t" +
276 cmd->m_cmdString)));
277 return;
280 switch (cmd->m_cmd) {
281 case DCinitialize:
282 // get version number from preamble
284 int len;
285 QRegExp GDBVersion("\\nGDB [0-9]+\\.[0-9]+");
286 int offset = GDBVersion.match(m_output, 0, &len);
287 if (offset >= 0) {
288 char* start = m_output + offset + 5; // skip "\nGDB "
289 char* end;
290 m_gdbMajor = strtol(start, &end, 10);
291 m_gdbMinor = strtol(end + 1, 0, 10); // skip "."
292 if (start == end) {
293 // nothing was parsed
294 m_gdbMajor = 4;
295 m_gdbMinor = 16;
297 } else {
298 // assume some default version (what would make sense?)
299 m_gdbMajor = 4;
300 m_gdbMinor = 16;
302 // use a feasible core-file command
303 if (m_gdbMajor > 4 || (m_gdbMajor == 4 && m_gdbMinor >= 16)) {
304 cmds[DCcorefile].fmt = "target core %s\n";
305 } else {
306 cmds[DCcorefile].fmt = "core-file %s\n";
309 break;
310 default:;
313 /* ok, the command is ready */
314 emit commandReceived(cmd, m_output);
316 switch (cmd->m_cmd) {
317 case DCcorefile:
318 case DCinfolinemain:
319 case DCframe:
320 case DCattach:
321 case DCrun:
322 case DCcont:
323 case DCstep:
324 case DCstepi:
325 case DCnext:
326 case DCnexti:
327 case DCfinish:
328 case DCuntil:
329 parseMarker();
330 default:;
335 * The --fullname option makes gdb send a special normalized sequence print
336 * each time the program stops and at some other points. The sequence has
337 * the form "\032\032filename:lineno:charoffset:(beg|middle):address".
339 void GdbDriver::parseMarker()
341 char* startMarker = strstr(m_output, "\032\032");
342 if (startMarker == 0)
343 return;
345 // extract the marker
346 startMarker += 2;
347 TRACE(QString("found marker: ") + startMarker);
348 char* endMarker = strchr(startMarker, '\n');
349 if (endMarker == 0)
350 return;
352 *endMarker = '\0';
354 // extract filename and line number
355 static QRegExp MarkerRE(":[0-9]+:[0-9]+:[begmidl]+:0x");
357 int len;
358 int lineNoStart = MarkerRE.match(startMarker, 0, &len);
359 if (lineNoStart >= 0) {
360 int lineNo = atoi(startMarker + lineNoStart+1);
362 // get address
363 const char* addrStart = startMarker + lineNoStart + len - 2;
364 DbgAddr address = QString(addrStart).stripWhiteSpace();
366 // now show the window
367 startMarker[lineNoStart] = '\0'; /* split off file name */
368 emit activateFileLine(startMarker, lineNo-1, address);
374 * Escapes characters that might lead to problems when they appear on gdb's
375 * command line.
377 static void normalizeStringArg(QString& arg)
380 * Remove trailing backslashes. This approach is a little simplistic,
381 * but we know that there is at the moment no case where a trailing
382 * backslash would make sense.
384 while (!arg.isEmpty() && arg[arg.length()-1] == '\\') {
385 arg = arg.left(arg.length()-1);
390 QString GdbDriver::makeCmdString(DbgCommand cmd, QString strArg)
392 assert(cmd >= 0 && cmd < NUM_CMDS);
393 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argString);
395 normalizeStringArg(strArg);
397 if (cmd == DCcd) {
398 // need the working directory when parsing the output
399 m_programWD = strArg;
400 } else if (cmd == DCsetargs) {
401 // attach saved redirection
402 strArg += m_redirect;
405 SIZED_QString(cmdString, MAX_FMTLEN+strArg.length());
406 cmdString.sprintf(cmds[cmd].fmt, strArg.latin1());
407 return cmdString;
410 QString GdbDriver::makeCmdString(DbgCommand cmd, int intArg)
412 assert(cmd >= 0 && cmd < NUM_CMDS);
413 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argNum);
415 SIZED_QString(cmdString, MAX_FMTLEN+30);
417 cmdString.sprintf(cmds[cmd].fmt, intArg);
418 return cmdString;
421 QString GdbDriver::makeCmdString(DbgCommand cmd, QString strArg, int intArg)
423 assert(cmd >= 0 && cmd < NUM_CMDS);
424 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argStringNum ||
425 cmds[cmd].argsNeeded == GdbCmdInfo::argNumString ||
426 cmd == DCexamine ||
427 cmd == DCtty);
429 normalizeStringArg(strArg);
431 SIZED_QString(cmdString, MAX_FMTLEN+30+strArg.length());
433 if (cmd == DCtty)
436 * intArg specifies which channels should be redirected to
437 * /dev/null. It is a value or'ed together from RDNstdin,
438 * RDNstdout, RDNstderr. We store the value for a later DCsetargs
439 * command.
441 * Note: We rely on that after the DCtty a DCsetargs will follow,
442 * which will ultimately apply the redirection.
444 static const char* const runRedir[8] = {
446 " </dev/null",
447 " >/dev/null",
448 " </dev/null >/dev/null",
449 " 2>/dev/null",
450 " </dev/null 2>/dev/null",
451 " >/dev/null 2>&1",
452 " </dev/null >/dev/null 2>&1"
454 if (strArg.isEmpty())
455 intArg = 7; /* failsafe if no tty */
456 m_redirect = runRedir[intArg & 7];
458 return makeCmdString(DCtty, strArg); /* note: no problem if strArg empty */
461 if (cmd == DCexamine) {
462 // make a format specifier from the intArg
463 static const char size[16] = {
464 '\0', 'b', 'h', 'w', 'g'
466 static const char format[16] = {
467 '\0', 'x', 'd', 'u', 'o', 't',
468 'a', 'c', 'f', 's', 'i'
470 assert(MDTsizemask == 0xf); /* lowest 4 bits */
471 assert(MDTformatmask == 0xf0); /* next 4 bits */
472 int count = 16; /* number of entities to print */
473 char sizeSpec = size[intArg & MDTsizemask];
474 char formatSpec = format[(intArg & MDTformatmask) >> 4];
475 assert(sizeSpec != '\0');
476 assert(formatSpec != '\0');
477 // adjust count such that 16 lines are printed
478 switch (intArg & MDTformatmask) {
479 case MDTstring: case MDTinsn:
480 break; /* no modification needed */
481 default:
482 // all cases drop through:
483 switch (intArg & MDTsizemask) {
484 case MDTbyte:
485 case MDThalfword:
486 count *= 2;
487 case MDTword:
488 count *= 2;
489 case MDTgiantword:
490 count *= 2;
492 break;
494 QString spec;
495 spec.sprintf("/%d%c%c", count, sizeSpec, formatSpec);
497 return makeCmdString(DCexamine, spec, strArg);
500 if (cmds[cmd].argsNeeded == GdbCmdInfo::argStringNum)
502 // line numbers are zero-based
503 if (cmd == DCuntil || cmd == DCbreakline ||
504 cmd == DCtbreakline || cmd == DCinfoline)
506 intArg++;
508 if (cmd == DCinfoline)
510 // must split off file name part
511 int slash = strArg.findRev('/');
512 if (slash >= 0)
513 strArg = strArg.right(strArg.length()-slash-1);
515 cmdString.sprintf(cmds[cmd].fmt, strArg.latin1(), intArg);
517 else
519 cmdString.sprintf(cmds[cmd].fmt, intArg, strArg.latin1());
521 return cmdString;
524 QString GdbDriver::makeCmdString(DbgCommand cmd, QString strArg1, QString strArg2)
526 assert(cmd >= 0 && cmd < NUM_CMDS);
527 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argString2);
529 normalizeStringArg(strArg1);
530 normalizeStringArg(strArg2);
532 SIZED_QString(cmdString, MAX_FMTLEN+strArg1.length()+strArg2.length());
533 cmdString.sprintf(cmds[cmd].fmt, strArg1.latin1(), strArg2.latin1());
534 return cmdString;
537 QString GdbDriver::makeCmdString(DbgCommand cmd, int intArg1, int intArg2)
539 assert(cmd >= 0 && cmd < NUM_CMDS);
540 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argNum2);
542 SIZED_QString(cmdString, MAX_FMTLEN+60);
543 cmdString.sprintf(cmds[cmd].fmt, intArg1, intArg2);
544 return cmdString;
547 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, bool clearLow)
549 assert(cmd >= 0 && cmd < NUM_CMDS);
550 assert(cmds[cmd].argsNeeded == GdbCmdInfo::argNone);
552 if (cmd == DCrun) {
553 m_haveCoreFile = false;
556 return executeCmdString(cmd, cmds[cmd].fmt, clearLow);
559 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, QString strArg,
560 bool clearLow)
562 return executeCmdString(cmd, makeCmdString(cmd, strArg), clearLow);
565 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, int intArg,
566 bool clearLow)
569 return executeCmdString(cmd, makeCmdString(cmd, intArg), clearLow);
572 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, QString strArg, int intArg,
573 bool clearLow)
575 return executeCmdString(cmd, makeCmdString(cmd, strArg, intArg), clearLow);
578 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, QString strArg1, QString strArg2,
579 bool clearLow)
581 return executeCmdString(cmd, makeCmdString(cmd, strArg1, strArg2), clearLow);
584 CmdQueueItem* GdbDriver::executeCmd(DbgCommand cmd, int intArg1, int intArg2,
585 bool clearLow)
587 return executeCmdString(cmd, makeCmdString(cmd, intArg1, intArg2), clearLow);
590 CmdQueueItem* GdbDriver::queueCmd(DbgCommand cmd, QueueMode mode)
592 return queueCmdString(cmd, cmds[cmd].fmt, mode);
595 CmdQueueItem* GdbDriver::queueCmd(DbgCommand cmd, QString strArg,
596 QueueMode mode)
598 return queueCmdString(cmd, makeCmdString(cmd, strArg), mode);
601 CmdQueueItem* GdbDriver::queueCmd(DbgCommand cmd, int intArg,
602 QueueMode mode)
604 return queueCmdString(cmd, makeCmdString(cmd, intArg), mode);
607 CmdQueueItem* GdbDriver::queueCmd(DbgCommand cmd, QString strArg, int intArg,
608 QueueMode mode)
610 return queueCmdString(cmd, makeCmdString(cmd, strArg, intArg), mode);
613 CmdQueueItem* GdbDriver::queueCmd(DbgCommand cmd, QString strArg1, QString strArg2,
614 QueueMode mode)
616 return queueCmdString(cmd, makeCmdString(cmd, strArg1, strArg2), mode);
619 void GdbDriver::terminate()
621 kill(SIGTERM);
622 m_state = DSidle;
625 void GdbDriver::detachAndTerminate()
627 kill(SIGINT);
628 flushCommands();
629 executeCmdString(DCinitialize, "detach\nquit\n", true);
632 void GdbDriver::interruptInferior()
634 kill(SIGINT);
635 // remove accidentally queued commands
636 flushHiPriQueue();
639 static bool isErrorExpr(const char* output)
641 return
642 strncmp(output, "Cannot access memory at", 23) == 0 ||
643 strncmp(output, "Attempt to dereference a generic pointer", 40) == 0 ||
644 strncmp(output, "Attempt to take contents of ", 28) == 0 ||
645 strncmp(output, "Attempt to use a type name as an expression", 43) == 0 ||
646 strncmp(output, "There is no member or method named", 34) == 0 ||
647 strncmp(output, "A parse error in expression", 27) == 0 ||
648 strncmp(output, "No symbol \"", 11) == 0 ||
649 strncmp(output, "Internal error: ", 16) == 0;
653 * Returns true if the output is an error message. If wantErrorValue is
654 * true, a new VarTree object is created and filled with the error message.
656 static bool parseErrorMessage(const char* output,
657 VarTree*& variable, bool wantErrorValue)
659 if (isErrorExpr(output))
661 if (wantErrorValue) {
662 // put the error message as value in the variable
663 variable = new VarTree(QString(), VarTree::NKplain);
664 const char* endMsg = strchr(output, '\n');
665 if (endMsg == 0)
666 endMsg = output + strlen(output);
667 variable->m_value = FROM_LATIN1(output, endMsg-output);
668 } else {
669 variable = 0;
671 return true;
673 return false;
676 #if QT_VERSION >= 300
677 union Qt2QChar {
678 short s;
679 struct {
680 uchar row;
681 uchar cell;
682 } qch;
684 #endif
686 void GdbDriver::setPrintQStringDataCmd(const char* cmd)
688 // don't accept the command if it is empty
689 if (cmd == 0 || *cmd == '\0')
690 return;
691 assert(strlen(cmd) <= MAX_FMTLEN);
692 cmds[DCprintQStringStruct].fmt = cmd;
695 VarTree* GdbDriver::parseQCharArray(const char* output, bool wantErrorValue, bool qt3like)
697 VarTree* variable = 0;
700 * Parse off white space. gdb sometimes prints white space first if the
701 * printed array leaded to an error.
703 const char* p = output;
704 while (isspace(*p))
705 p++;
707 // special case: empty string (0 repetitions)
708 if (strncmp(p, "Invalid number 0 of repetitions", 31) == 0)
710 variable = new VarTree(QString(), VarTree::NKplain);
711 variable->m_value = "\"\"";
712 return variable;
715 // check for error conditions
716 if (parseErrorMessage(p, variable, wantErrorValue))
717 return variable;
719 // parse the array
721 // find '='
722 p = strchr(p, '=');
723 if (p == 0) {
724 goto error;
726 // skip white space
727 do {
728 p++;
729 } while (isspace(*p));
731 if (*p == '{')
733 // this is the real data
734 p++; /* skip '{' */
736 // parse the array
737 QString result;
738 QString repeatCount;
739 enum { wasNothing, wasChar, wasRepeat } lastThing = wasNothing;
741 * A matrix for separators between the individual "things"
742 * that are added to the string. The first index is a bool,
743 * the second index is from the enum above.
745 static const char* separator[2][3] = {
746 { "\"", 0, ", \"" }, /* normal char is added */
747 { "'", "\", '", ", '" } /* repeated char is added */
750 while (isdigit(*p)) {
751 // parse a number
752 char* end;
753 unsigned short value = (unsigned short) strtoul(p, &end, 0);
754 if (end == p)
755 goto error; /* huh? no valid digits */
756 // skip separator and search for a repeat count
757 p = end;
758 while (isspace(*p) || *p == ',')
759 p++;
760 bool repeats = strncmp(p, "<repeats ", 9) == 0;
761 if (repeats) {
762 const char* start = p;
763 p = strchr(p+9, '>'); /* search end and advance */
764 if (p == 0)
765 goto error;
766 p++; /* skip '>' */
767 repeatCount = FROM_LATIN1(start, p-start);
768 while (isspace(*p) || *p == ',')
769 p++;
771 // p is now at the next char (or the end)
773 // interpret the value as a QChar
774 // TODO: make cross-architecture compatible
775 QChar ch;
776 if (qt3like) {
777 ch = QChar(value);
778 } else {
779 #if QT_VERSION < 300
780 (unsigned short&)ch = value;
781 #else
782 Qt2QChar c;
783 c.s = value;
784 ch.setRow(c.qch.row);
785 ch.setCell(c.qch.cell);
786 #endif
789 // escape a few frequently used characters
790 char escapeCode = '\0';
791 switch (ch.latin1()) {
792 case '\n': escapeCode = 'n'; break;
793 case '\r': escapeCode = 'r'; break;
794 case '\t': escapeCode = 't'; break;
795 case '\b': escapeCode = 'b'; break;
796 case '\"': escapeCode = '\"'; break;
797 case '\\': escapeCode = '\\'; break;
798 case '\0': if (value == 0) { escapeCode = '0'; } break;
801 // add separator
802 result += separator[repeats][lastThing];
803 // add char
804 if (escapeCode != '\0') {
805 result += '\\';
806 ch = escapeCode;
808 result += ch;
810 // fixup repeat count and lastThing
811 if (repeats) {
812 result += "' ";
813 result += repeatCount;
814 lastThing = wasRepeat;
815 } else {
816 lastThing = wasChar;
819 if (*p != '}')
820 goto error;
822 // closing quote
823 if (lastThing == wasChar)
824 result += "\"";
826 // assign the value
827 variable = new VarTree(QString(), VarTree::NKplain);
828 variable->m_value = result;
830 else if (strncmp(p, "true", 4) == 0)
832 variable = new VarTree(QString(), VarTree::NKplain);
833 variable->m_value = "QString::null";
835 else if (strncmp(p, "false", 5) == 0)
837 variable = new VarTree(QString(), VarTree::NKplain);
838 variable->m_value = "(null)";
840 else
841 goto error;
842 return variable;
844 error:
845 if (wantErrorValue) {
846 variable = new VarTree(QString(), VarTree::NKplain);
847 variable->m_value = "internal parse error";
849 return variable;
852 static VarTree* parseVar(const char*& s)
854 const char* p = s;
856 // skip whitespace
857 while (isspace(*p))
858 p++;
860 QString name;
861 VarTree::NameKind kind;
862 if (!parseName(p, name, kind)) {
863 return 0;
866 // go for '='
867 while (isspace(*p))
868 p++;
869 if (*p != '=') {
870 TRACE(QString().sprintf("parse error: = not found after %s", (const char*)name));
871 return 0;
873 // skip the '=' and more whitespace
874 p++;
875 while (isspace(*p))
876 p++;
878 VarTree* variable = new VarTree(name, kind);
879 variable->setDeleteChildren(true);
881 if (!parseValue(p, variable)) {
882 delete variable;
883 return 0;
885 s = p;
886 return variable;
889 static void skipNested(const char*& s, char opening, char closing)
891 const char* p = s;
893 // parse a nested type
894 int nest = 1;
895 p++;
897 * Search for next matching `closing' char, skipping nested pairs of
898 * `opening' and `closing'.
900 while (*p && nest > 0) {
901 if (*p == opening) {
902 nest++;
903 } else if (*p == closing) {
904 nest--;
906 p++;
908 if (nest != 0) {
909 TRACE(QString().sprintf("parse error: mismatching %c%c at %-20.20s", opening, closing, s));
911 s = p;
915 * Find the end of line that is not inside braces
917 static void findEnd(const char*& s)
919 const char* p = s;
920 while (*p && *p!='\n') {
921 while (*p && *p!='\n' && *p!='{')
922 p++;
923 if (*p=='{') {
924 p++;
925 skipNested(p, '{', '}'); p--;
928 s = p;
931 static bool isNumberish(const char ch)
933 return (ch>='0' && ch<='9') || ch=='.' || ch=='x';
936 void skipString(const char*& p)
938 moreStrings:
939 // opening quote
940 char quote = *p++;
941 while (*p != quote) {
942 if (*p == '\\') {
943 // skip escaped character
944 // no special treatment for octal values necessary
945 p++;
947 // simply return if no more characters
948 if (*p == '\0')
949 return;
950 p++;
952 // closing quote
953 p++;
955 * Strings can consist of several parts, some of which contain repeated
956 * characters.
958 if (quote == '\'') {
959 // look ahaead for <repeats 123 times>
960 const char* q = p+1;
961 while (isspace(*q))
962 q++;
963 if (strncmp(q, "<repeats ", 9) == 0) {
964 p = q+9;
965 while (*p != '\0' && *p != '>')
966 p++;
967 if (*p != '\0') {
968 p++; /* skip the '>' */
972 // is the string continued?
973 if (*p == ',') {
974 // look ahead for another quote
975 const char* q = p+1;
976 while (isspace(*q))
977 q++;
978 if (*q == '"' || *q == '\'') {
979 // yes!
980 p = q;
981 goto moreStrings;
984 /* very long strings are followed by `...' */
985 if (*p == '.' && p[1] == '.' && p[2] == '.') {
986 p += 3;
990 static void skipNestedWithString(const char*& s, char opening, char closing)
992 const char* p = s;
994 // parse a nested expression
995 int nest = 1;
996 p++;
998 * Search for next matching `closing' char, skipping nested pairs of
999 * `opening' and `closing' as well as strings.
1001 while (*p && nest > 0) {
1002 if (*p == opening) {
1003 nest++;
1004 } else if (*p == closing) {
1005 nest--;
1006 } else if (*p == '\'' || *p == '\"') {
1007 skipString(p);
1008 continue;
1010 p++;
1012 if (nest > 0) {
1013 TRACE(QString().sprintf("parse error: mismatching %c%c at %-20.20s", opening, closing, s));
1015 s = p;
1018 inline void skipName(const char*& p)
1020 // allow : (for enumeration values) and $ and . (for _vtbl.)
1021 while (isalnum(*p) || *p == '_' || *p == ':' || *p == '$' || *p == '.')
1022 p++;
1025 static bool parseName(const char*& s, QString& name, VarTree::NameKind& kind)
1027 kind = VarTree::NKplain;
1029 const char* p = s;
1030 // examples of names:
1031 // name
1032 // <Object>
1033 // <string<a,b<c>,7> >
1035 if (*p == '<') {
1036 skipNested(p, '<', '>');
1037 name = FROM_LATIN1(s, p - s);
1038 kind = VarTree::NKtype;
1040 else
1042 // name, which might be "static"; allow dot for "_vtbl."
1043 skipName(p);
1044 if (p == s) {
1045 TRACE(QString().sprintf("parse error: not a name %-20.20s", s));
1046 return false;
1048 int len = p - s;
1049 if (len == 6 && strncmp(s, "static", 6) == 0) {
1050 kind = VarTree::NKstatic;
1052 // its a static variable, name comes now
1053 while (isspace(*p))
1054 p++;
1055 s = p;
1056 skipName(p);
1057 if (p == s) {
1058 TRACE(QString().sprintf("parse error: not a name after static %-20.20s", s));
1059 return false;
1061 len = p - s;
1063 name = FROM_LATIN1(s, len);
1065 // return the new position
1066 s = p;
1067 return true;
1070 static bool parseValue(const char*& s, VarTree* variable)
1072 variable->m_value = "";
1074 repeat:
1075 if (*s == '{') {
1076 // Sometimes we find the following output:
1077 // {<text variable, no debug info>} 0x40012000 <access>
1078 // {<data variable, no debug info>}
1079 // {<variable (not text or data), no debug info>}
1080 if (strncmp(s, "{<text variable, ", 17) == 0 ||
1081 strncmp(s, "{<data variable, ", 17) == 0 ||
1082 strncmp(s, "{<variable (not text or data), ", 31) == 0)
1084 const char* start = s;
1085 skipNested(s, '{', '}');
1086 variable->m_value = FROM_LATIN1(start, s-start);
1087 variable->m_value += ' '; // add only a single space
1088 while (isspace(*s))
1089 s++;
1090 goto repeat;
1092 else
1094 s++;
1095 if (!parseNested(s, variable)) {
1096 return false;
1098 // must be the closing brace
1099 if (*s != '}') {
1100 TRACE("parse error: missing } of " + variable->getText());
1101 return false;
1103 s++;
1104 // final white space
1105 while (isspace(*s))
1106 s++;
1108 } else {
1109 // examples of leaf values (cannot be the empty string):
1110 // 123
1111 // -123
1112 // 23.575e+37
1113 // 0x32a45
1114 // @0x012ab4
1115 // (DwContentType&) @0x8123456: {...}
1116 // 0x32a45 "text"
1117 // 10 '\n'
1118 // <optimized out>
1119 // 0x823abc <Array<int> virtual table>
1120 // (void (*)()) 0x8048480 <f(E *, char)>
1121 // (E *) 0xbffff450
1122 // red
1123 // &parseP (HTMLClueV *, char *)
1124 // Variable "x" is not available.
1125 // The value of variable 'x' is distributed...
1126 // -nan(0xfffff081defa0)
1128 const char*p = s;
1130 // check for type
1131 QString type;
1132 if (*p == '(') {
1133 skipNested(p, '(', ')');
1135 while (isspace(*p))
1136 p++;
1137 variable->m_value = FROM_LATIN1(s, p - s);
1140 bool reference = false;
1141 if (*p == '@') {
1142 // skip reference marker
1143 p++;
1144 reference = true;
1146 const char* start = p;
1147 if (*p == '-')
1148 p++;
1150 // some values consist of more than one token
1151 bool checkMultiPart = false;
1153 if (p[0] == '0' && p[1] == 'x') {
1154 // parse hex number
1155 p += 2;
1156 while (isxdigit(*p))
1157 p++;
1160 * Assume this is a pointer, but only if it's not a reference, since
1161 * references can't be expanded.
1163 if (!reference) {
1164 variable->m_varKind = VarTree::VKpointer;
1165 } else {
1167 * References are followed by a colon, in which case we'll
1168 * find the value following the reference address.
1170 if (*p == ':') {
1171 p++;
1172 } else {
1173 // Paranoia. (Can this happen, i.e. reference not followed by ':'?)
1174 reference = false;
1177 checkMultiPart = true;
1178 } else if (isdigit(*p)) {
1179 // parse decimal number, possibly a float
1180 while (isdigit(*p))
1181 p++;
1182 if (*p == '.') { /* TODO: obey i18n? */
1183 // In long arrays an integer may be followed by '...'.
1184 // We test for this situation and don't gobble the '...'.
1185 if (p[1] != '.' || p[0] != '.') {
1186 // fractional part
1187 p++;
1188 while (isdigit(*p))
1189 p++;
1192 if (*p == 'e' || *p == 'E') {
1193 p++;
1194 // exponent
1195 if (*p == '-' || *p == '+')
1196 p++;
1197 while (isdigit(*p))
1198 p++;
1201 // for char variables there is the char, eg. 10 '\n'
1202 checkMultiPart = true;
1203 } else if (*p == '<') {
1204 // e.g. <optimized out>
1205 skipNested(p, '<', '>');
1206 } else if (*p == '"' || *p == '\'') {
1207 // character may have multipart: '\000' <repeats 11 times>
1208 checkMultiPart = *p == '\'';
1209 // found a string
1210 skipString(p);
1211 } else if (*p == '&') {
1212 // function pointer
1213 p++;
1214 skipName(p);
1215 while (isspace(*p)) {
1216 p++;
1218 if (*p == '(') {
1219 skipNested(p, '(', ')');
1221 } else if (strncmp(p, "Variable \"", 10) == 0) {
1222 // Variable "x" is not available.
1223 p += 10; // skip to "
1224 skipName(p);
1225 if (strncmp(p, "\" is not available.", 19) == 0) {
1226 p += 19;
1228 } else if (strncmp(p, "The value of variable '", 23) == 0) {
1229 p += 23;
1230 skipName(p);
1231 const char* e = strchr(p, '.');
1232 if (e == 0) {
1233 p += strlen(p);
1234 } else {
1235 p = e+1;
1237 } else {
1238 // must be an enumeration value
1239 skipName(p);
1240 // hmm, not necessarily: nan (floating point Not a Number)
1241 // is followed by a number in ()
1242 if (*p == '(')
1243 skipNested(p, '(', ')');
1245 variable->m_value += FROM_LATIN1(start, p - start);
1247 // remove line breaks from the value; this is ok since
1248 // string values never contain a literal line break
1249 variable->m_value.replace('\n', ' ');
1251 if (checkMultiPart) {
1252 // white space
1253 while (isspace(*p))
1254 p++;
1255 // may be followed by a string or <...>
1256 start = p;
1258 if (*p == '"' || *p == '\'') {
1259 skipString(p);
1260 } else if (*p == '<') {
1261 // if this value is part of an array, it might be followed
1262 // by <repeats 15 times>, which we don't skip here
1263 if (strncmp(p, "<repeats ", 9) != 0)
1264 skipNested(p, '<', '>');
1266 if (p != start) {
1267 // there is always a blank before the string,
1268 // which we will include in the final string value
1269 variable->m_value += FROM_LATIN1(start-1, (p - start)+1);
1270 // if this was a pointer, reset that flag since we
1271 // now got the value
1272 variable->m_varKind = VarTree::VKsimple;
1276 if (variable->m_value.length() == 0) {
1277 TRACE("parse error: no value for " + variable->getText());
1278 return false;
1281 // final white space
1282 while (isspace(*p))
1283 p++;
1284 s = p;
1287 * If this was a reference, the value follows. It might even be a
1288 * composite variable!
1290 if (reference) {
1291 goto repeat;
1294 if (variable->m_varKind == VarTree::VKpointer) {
1295 variable->setDelayedExpanding(true);
1299 return true;
1302 static bool parseNested(const char*& s, VarTree* variable)
1304 // could be a structure or an array
1305 while (isspace(*s))
1306 s++;
1308 const char* p = s;
1309 bool isStruct = false;
1311 * If there is a name followed by an = or an < -- which starts a type
1312 * name -- or "static", it is a structure
1314 if (*p == '<' || *p == '}') {
1315 isStruct = true;
1316 } else if (strncmp(p, "static ", 7) == 0) {
1317 isStruct = true;
1318 } else if (isalpha(*p) || *p == '_' || *p == '$') {
1319 // look ahead for a comma after the name
1320 skipName(p);
1321 while (isspace(*p))
1322 p++;
1323 if (*p == '=') {
1324 isStruct = true;
1326 p = s; /* rescan the name */
1328 if (isStruct) {
1329 if (!parseVarSeq(p, variable)) {
1330 return false;
1332 variable->m_varKind = VarTree::VKstruct;
1333 } else {
1334 if (!parseValueSeq(p, variable)) {
1335 return false;
1337 variable->m_varKind = VarTree::VKarray;
1339 s = p;
1340 return true;
1343 static bool parseVarSeq(const char*& s, VarTree* variable)
1345 // parse a comma-separated sequence of variables
1346 VarTree* var = variable; /* var != 0 to indicate success if empty seq */
1347 for (;;) {
1348 if (*s == '}')
1349 break;
1350 if (strncmp(s, "<No data fields>}", 17) == 0)
1352 // no member variables, so break out immediately
1353 s += 16; /* go to the closing brace */
1354 break;
1356 var = parseVar(s);
1357 if (var == 0)
1358 break; /* syntax error */
1359 variable->appendChild(var);
1360 if (*s != ',')
1361 break;
1362 // skip the comma and whitespace
1363 s++;
1364 while (isspace(*s))
1365 s++;
1367 return var != 0;
1370 static bool parseValueSeq(const char*& s, VarTree* variable)
1372 // parse a comma-separated sequence of variables
1373 int index = 0;
1374 bool good;
1375 for (;;) {
1376 QString name;
1377 name.sprintf("[%d]", index);
1378 VarTree* var = new VarTree(name, VarTree::NKplain);
1379 var->setDeleteChildren(true);
1380 good = parseValue(s, var);
1381 if (!good) {
1382 delete var;
1383 return false;
1385 // a value may be followed by "<repeats 45 times>"
1386 if (strncmp(s, "<repeats ", 9) == 0) {
1387 s += 9;
1388 char* end;
1389 int l = strtol(s, &end, 10);
1390 if (end == s || strncmp(end, " times>", 7) != 0) {
1391 // should not happen
1392 delete var;
1393 return false;
1395 TRACE(QString().sprintf("found <repeats %d times> in array", l));
1396 // replace name and advance index
1397 name.sprintf("[%d .. %d]", index, index+l-1);
1398 var->setText(name);
1399 index += l;
1400 // skip " times>" and space
1401 s = end+7;
1402 // possible final space
1403 while (isspace(*s))
1404 s++;
1405 } else {
1406 index++;
1408 variable->appendChild(var);
1409 // long arrays may be terminated by '...'
1410 if (strncmp(s, "...", 3) == 0) {
1411 s += 3;
1412 VarTree* var = new VarTree("...", VarTree::NKplain);
1413 var->setDeleteChildren(true);
1414 var->m_value = i18n("<additional entries of the array suppressed>");
1415 variable->appendChild(var);
1416 break;
1418 if (*s != ',') {
1419 break;
1421 // skip the comma and whitespace
1422 s++;
1423 while (isspace(*s))
1424 s++;
1425 // sometimes there is a closing brace after a comma
1426 // if (*s == '}')
1427 // break;
1429 return true;
1433 * Parses a stack frame.
1435 static void parseFrameInfo(const char*& s, QString& func,
1436 QString& file, int& lineNo, DbgAddr& address)
1438 const char* p = s;
1440 // next may be a hexadecimal address
1441 if (*p == '0') {
1442 const char* start = p;
1443 p++;
1444 if (*p == 'x')
1445 p++;
1446 while (isxdigit(*p))
1447 p++;
1448 address = FROM_LATIN1(start, p-start);
1449 if (strncmp(p, " in ", 4) == 0)
1450 p += 4;
1451 } else {
1452 address = DbgAddr();
1454 const char* start = p;
1455 // check for special signal handler frame
1456 if (strncmp(p, "<signal handler called>", 23) == 0) {
1457 func = FROM_LATIN1(start, 23);
1458 file = QString();
1459 lineNo = -1;
1460 s = p+23;
1461 if (*s == '\n')
1462 s++;
1463 return;
1467 * Skip the function name. It is terminated by a left parenthesis
1468 * which does not delimit "(anonymous namespace)" and which is
1469 * outside the angle brackets <> of template parameter lists.
1471 while (*p != '\0')
1473 if (*p == '<') {
1474 // skip template parameter list
1475 skipNested(p, '<', '>');
1476 } else if (*p == '(') {
1477 if (strncmp(p, "(anonymous namespace)", 21) != 0)
1478 break; // parameter list found
1479 p += 21;
1480 } else {
1481 p++;
1485 if (*p == '\0') {
1486 func = start;
1487 file = QString();
1488 lineNo = -1;
1489 s = p;
1490 return;
1493 * Skip parameters. But notice that for complicated conversion
1494 * functions (eg. "operator int(**)()()", ie. convert to pointer to
1495 * pointer to function) as well as operator()(...) we have to skip
1496 * additional pairs of parentheses. Furthermore, recent gdbs write the
1497 * demangled name followed by the arguments in a pair of parentheses,
1498 * where the demangled name can end in "const".
1500 do {
1501 skipNestedWithString(p, '(', ')');
1502 while (isspace(*p))
1503 p++;
1504 // skip "const"
1505 if (strncmp(p, "const", 5) == 0) {
1506 p += 5;
1507 while (isspace(*p))
1508 p++;
1510 } while (*p == '(');
1512 // check for file position
1513 if (strncmp(p, "at ", 3) == 0) {
1514 p += 3;
1515 const char* fileStart = p;
1516 // go for the end of the line
1517 while (*p != '\0' && *p != '\n')
1518 p++;
1519 // search back for colon
1520 const char* colon = p;
1521 do {
1522 --colon;
1523 } while (*colon != ':');
1524 file = FROM_LATIN1(fileStart, colon-fileStart);
1525 lineNo = atoi(colon+1)-1;
1526 // skip new-line
1527 if (*p != '\0')
1528 p++;
1529 } else {
1530 // check for "from shared lib"
1531 if (strncmp(p, "from ", 5) == 0) {
1532 p += 5;
1533 // go for the end of the line
1534 while (*p != '\0' && *p != '\n')
1535 p++;
1536 // skip new-line
1537 if (*p != '\0')
1538 p++;
1540 file = "";
1541 lineNo = -1;
1543 // construct the function name (including file info)
1544 if (*p == '\0') {
1545 func = start;
1546 } else {
1547 func = FROM_LATIN1(start, p-start-1); /* don't include \n */
1549 s = p;
1552 * Replace \n (and whitespace around it) in func by a blank. We cannot
1553 * use QString::simplifyWhiteSpace() for this because this would also
1554 * simplify space that belongs to a string arguments that gdb sometimes
1555 * prints in the argument lists of the function.
1557 ASSERT(!isspace(func[0].latin1())); /* there must be non-white before first \n */
1558 int nl = 0;
1559 while ((nl = func.find('\n', nl)) >= 0) {
1560 // search back to the beginning of the whitespace
1561 int startWhite = nl;
1562 do {
1563 --startWhite;
1564 } while (isspace(func[startWhite].latin1()));
1565 startWhite++;
1566 // search forward to the end of the whitespace
1567 do {
1568 nl++;
1569 } while (isspace(func[nl].latin1()));
1570 // replace
1571 func.replace(startWhite, nl-startWhite, " ");
1572 /* continue searching for more \n's at this place: */
1573 nl = startWhite+1;
1579 * Parses a stack frame including its frame number
1581 static bool parseFrame(const char*& s, int& frameNo, QString& func,
1582 QString& file, int& lineNo, DbgAddr& address)
1584 // Example:
1585 // #1 0x8048881 in Dl::Dl (this=0xbffff418, r=3214) at testfile.cpp:72
1586 // Breakpoint 3, Cl::f(int) const (this=0xbffff3c0, x=17) at testfile.cpp:155
1588 // must start with a hash mark followed by number
1589 // or with "Breakpoint " followed by number and comma
1590 if (s[0] == '#') {
1591 if (!isdigit(s[1]))
1592 return false;
1593 s++; /* skip the hash mark */
1594 } else if (strncmp(s, "Breakpoint ", 11) == 0) {
1595 if (!isdigit(s[11]))
1596 return false;
1597 s += 11; /* skip "Breakpoint" */
1598 } else
1599 return false;
1601 // frame number
1602 frameNo = atoi(s);
1603 while (isdigit(*s))
1604 s++;
1605 // space and comma
1606 while (isspace(*s) || *s == ',')
1607 s++;
1608 parseFrameInfo(s, func, file, lineNo, address);
1609 return true;
1612 void GdbDriver::parseBackTrace(const char* output, QList<StackFrame>& stack)
1614 QString func, file;
1615 int lineNo, frameNo;
1616 DbgAddr address;
1618 while (::parseFrame(output, frameNo, func, file, lineNo, address)) {
1619 StackFrame* frm = new StackFrame;
1620 frm->frameNo = frameNo;
1621 frm->fileName = file;
1622 frm->lineNo = lineNo;
1623 frm->address = address;
1624 frm->var = new VarTree(func, VarTree::NKplain);
1625 stack.append(frm);
1629 bool GdbDriver::parseFrameChange(const char* output, int& frameNo,
1630 QString& file, int& lineNo, DbgAddr& address)
1632 QString func;
1633 return ::parseFrame(output, frameNo, func, file, lineNo, address);
1637 bool GdbDriver::parseBreakList(const char* output, QList<Breakpoint>& brks)
1639 // skip first line, which is the headline
1640 const char* p = strchr(output, '\n');
1641 if (p == 0)
1642 return false;
1643 p++;
1644 if (*p == '\0')
1645 return false;
1647 // split up a line
1648 QString location;
1649 QString address;
1650 int hits = 0;
1651 uint ignoreCount = 0;
1652 QString condition;
1653 const char* end;
1654 char* dummy;
1655 while (*p != '\0') {
1656 // get Num
1657 long bpNum = strtol(p, &dummy, 10); /* don't care about overflows */
1658 p = dummy;
1659 // get Type
1660 while (isspace(*p))
1661 p++;
1662 Breakpoint::Type bpType = Breakpoint::breakpoint;
1663 if (strncmp(p, "breakpoint", 10) == 0) {
1664 p += 10;
1665 } else if (strncmp(p, "hw watchpoint", 13) == 0) {
1666 bpType = Breakpoint::watchpoint;
1667 p += 13;
1668 } else if (strncmp(p, "watchpoint", 10) == 0) {
1669 bpType = Breakpoint::watchpoint;
1670 p += 10;
1672 while (isspace(*p))
1673 p++;
1674 if (*p == '\0')
1675 break;
1676 // get Disp
1677 char disp = *p++;
1678 while (*p != '\0' && !isspace(*p)) /* "keep" or "del" */
1679 p++;
1680 while (isspace(*p))
1681 p++;
1682 if (*p == '\0')
1683 break;
1684 // get Enb
1685 char enable = *p++;
1686 while (*p != '\0' && !isspace(*p)) /* "y" or "n" */
1687 p++;
1688 while (isspace(*p))
1689 p++;
1690 if (*p == '\0')
1691 break;
1692 // the address, if present
1693 if (bpType == Breakpoint::breakpoint &&
1694 strncmp(p, "0x", 2) == 0)
1696 const char* start = p;
1697 while (*p != '\0' && !isspace(*p))
1698 p++;
1699 address = FROM_LATIN1(start, p-start);
1700 while (isspace(*p) && *p != '\n')
1701 p++;
1702 if (*p == '\0')
1703 break;
1704 } else {
1705 address = QString();
1707 // remainder is location, hit and ignore count, condition
1708 hits = 0;
1709 ignoreCount = 0;
1710 condition = QString();
1711 end = strchr(p, '\n');
1712 if (end == 0) {
1713 location = p;
1714 p += location.length();
1715 } else {
1716 location = FROM_LATIN1(p, end-p).stripWhiteSpace();
1717 p = end+1; /* skip over \n */
1720 // may be continued in next line
1721 while (isspace(*p)) { /* p points to beginning of line */
1722 // skip white space at beginning of line
1723 while (isspace(*p))
1724 p++;
1726 // seek end of line
1727 end = strchr(p, '\n');
1728 if (end == 0)
1729 end = p+strlen(p);
1731 if (strncmp(p, "breakpoint already hit", 22) == 0) {
1732 // extract the hit count
1733 p += 22;
1734 hits = strtol(p, &dummy, 10);
1735 TRACE(QString().sprintf("hit count %d", hits));
1736 } else if (strncmp(p, "stop only if ", 13) == 0) {
1737 // extract condition
1738 p += 13;
1739 condition = FROM_LATIN1(p, end-p).stripWhiteSpace();
1740 TRACE("condition: "+condition);
1741 } else if (strncmp(p, "ignore next ", 12) == 0) {
1742 // extract ignore count
1743 p += 12;
1744 ignoreCount = strtol(p, &dummy, 10);
1745 TRACE(QString().sprintf("ignore count %d", ignoreCount));
1746 } else {
1747 // indeed a continuation
1748 location += " " + FROM_LATIN1(p, end-p).stripWhiteSpace();
1750 p = end;
1751 if (*p != '\0')
1752 p++; /* skip '\n' */
1754 Breakpoint* bp = new Breakpoint;
1755 bp->id = bpNum;
1756 bp->type = bpType;
1757 bp->temporary = disp == 'd';
1758 bp->enabled = enable == 'y';
1759 bp->location = location;
1760 bp->address = address;
1761 bp->hitCount = hits;
1762 bp->ignoreCount = ignoreCount;
1763 bp->condition = condition;
1764 brks.append(bp);
1766 return true;
1769 bool GdbDriver::parseThreadList(const char* output, QList<ThreadInfo>& threads)
1771 if (strcmp(output, "\n") == 0 || strncmp(output, "No stack.", 9) == 0) {
1772 // no threads
1773 return true;
1776 int id;
1777 QString systag;
1778 QString func, file;
1779 int lineNo;
1780 DbgAddr address;
1782 const char* p = output;
1783 while (*p != '\0') {
1784 // seach look for thread id, watching out for the focus indicator
1785 bool hasFocus = false;
1786 while (isspace(*p)) /* may be \n from prev line: see "No stack" below */
1787 p++;
1788 if (*p == '*') {
1789 hasFocus = true;
1790 p++;
1791 // there follows only whitespace
1793 char* end;
1794 id = strtol(p, &end, 10);
1795 if (p == end) {
1796 // syntax error: no number found; bail out
1797 return true;
1799 p = end;
1801 // skip space
1802 while (isspace(*p))
1803 p++;
1806 * Now follows the thread's SYSTAG. It is terminated by two blanks.
1808 end = strstr(p, " ");
1809 if (end == 0) {
1810 // syntax error; bail out
1811 return true;
1813 systag = FROM_LATIN1(p, end-p);
1814 p = end+2;
1817 * Now follows a standard stack frame. Sometimes, however, gdb
1818 * catches a thread at an instant where it doesn't have a stack.
1820 if (strncmp(p, "[No stack.]", 11) != 0) {
1821 ::parseFrameInfo(p, func, file, lineNo, address);
1822 } else {
1823 func = "[No stack]";
1824 file = QString();
1825 lineNo = -1;
1826 address = QString();
1827 p += 11; /* \n is skipped above */
1830 ThreadInfo* thr = new ThreadInfo;
1831 thr->id = id;
1832 thr->threadName = systag;
1833 thr->hasFocus = hasFocus;
1834 thr->function = func;
1835 thr->fileName = file;
1836 thr->lineNo = lineNo;
1837 thr->address = address;
1838 threads.append(thr);
1840 return true;
1843 static bool parseNewBreakpoint(const char* o, int& id,
1844 QString& file, int& lineNo, QString& address);
1845 static bool parseNewWatchpoint(const char* o, int& id,
1846 QString& expr);
1848 bool GdbDriver::parseBreakpoint(const char* output, int& id,
1849 QString& file, int& lineNo, QString& address)
1851 const char* o = output;
1852 // skip lines of that begin with "(Cannot find"
1853 while (strncmp(o, "(Cannot find", 12) == 0) {
1854 o = strchr(o, '\n');
1855 if (o == 0)
1856 return false;
1857 o++; /* skip newline */
1860 if (strncmp(o, "Breakpoint ", 11) == 0) {
1861 output += 11; /* skip "Breakpoint " */
1862 return ::parseNewBreakpoint(output, id, file, lineNo, address);
1863 } else if (strncmp(o, "Hardware watchpoint ", 20) == 0) {
1864 output += 20;
1865 return ::parseNewWatchpoint(output, id, address);
1866 } else if (strncmp(o, "Watchpoint ", 11) == 0) {
1867 output += 11;
1868 return ::parseNewWatchpoint(output, id, address);
1870 return false;
1873 static bool parseNewBreakpoint(const char* o, int& id,
1874 QString& file, int& lineNo, QString& address)
1876 // breakpoint id
1877 char* p;
1878 id = strtoul(o, &p, 10);
1879 if (p == o)
1880 return false;
1882 // check for the address
1883 if (strncmp(p, " at 0x", 6) == 0) {
1884 char* start = p+4; /* skip " at ", but not 0x */
1885 p += 6;
1886 while (isxdigit(*p))
1887 ++p;
1888 address = FROM_LATIN1(start, p-start);
1891 // file name
1892 char* fileStart = strstr(p, "file ");
1893 if (fileStart == 0)
1894 return !address.isEmpty(); /* parse error only if there's no address */
1895 fileStart += 5;
1897 // line number
1898 char* numStart = strstr(fileStart, ", line ");
1899 QString fileName = FROM_LATIN1(fileStart, numStart-fileStart);
1900 numStart += 7;
1901 int line = strtoul(numStart, &p, 10);
1902 if (numStart == p)
1903 return false;
1905 file = fileName;
1906 lineNo = line-1; /* zero-based! */
1907 return true;
1910 static bool parseNewWatchpoint(const char* o, int& id,
1911 QString& expr)
1913 // watchpoint id
1914 char* p;
1915 id = strtoul(o, &p, 10);
1916 if (p == o)
1917 return false;
1919 if (strncmp(p, ": ", 2) != 0)
1920 return false;
1921 p += 2;
1923 // all the rest on the line is the expression
1924 expr = FROM_LATIN1(p, strlen(p)).stripWhiteSpace();
1925 return true;
1928 void GdbDriver::parseLocals(const char* output, QList<VarTree>& newVars)
1930 // check for possible error conditions
1931 if (strncmp(output, "No symbol table", 15) == 0)
1933 return;
1936 while (*output != '\0') {
1937 while (isspace(*output))
1938 output++;
1939 if (*output == '\0')
1940 break;
1941 // skip occurrences of "No locals" and "No args"
1942 if (strncmp(output, "No locals", 9) == 0 ||
1943 strncmp(output, "No arguments", 12) == 0)
1945 output = strchr(output, '\n');
1946 if (output == 0) {
1947 break;
1949 continue;
1952 VarTree* variable = parseVar(output);
1953 if (variable == 0) {
1954 break;
1956 // do not add duplicates
1957 for (VarTree* o = newVars.first(); o != 0; o = newVars.next()) {
1958 if (o->getText() == variable->getText()) {
1959 delete variable;
1960 goto skipDuplicate;
1963 newVars.append(variable);
1964 skipDuplicate:;
1968 bool GdbDriver::parsePrintExpr(const char* output, bool wantErrorValue, VarTree*& var)
1970 // check for error conditions
1971 if (parseErrorMessage(output, var, wantErrorValue))
1973 return false;
1974 } else {
1975 // parse the variable
1976 var = parseVar(output);
1977 return true;
1981 bool GdbDriver::parseChangeWD(const char* output, QString& message)
1983 bool isGood = false;
1984 message = QString(output).simplifyWhiteSpace();
1985 if (message.isEmpty()) {
1986 message = i18n("New working directory: ") + m_programWD;
1987 isGood = true;
1989 return isGood;
1992 bool GdbDriver::parseChangeExecutable(const char* output, QString& message)
1994 message = output;
1996 m_haveCoreFile = false;
1999 * Lines starting with the following do not indicate errors:
2000 * Using host libthread_db
2001 * (no debugging symbols found)
2003 while (strncmp(output, "Using host libthread_db", 23) == 0 ||
2004 strncmp(output, "(no debugging symbols found)", 28) == 0)
2006 // this line is good, go to the next one
2007 const char* end = strchr(output, '\n');
2008 if (end == 0)
2009 output += strlen(output);
2010 else
2011 output = end+1;
2015 * If we've parsed all lines, there was no error.
2017 return output[0] == '\0';
2020 bool GdbDriver::parseCoreFile(const char* output)
2022 // if command succeeded, gdb emits a line starting with "#0 "
2023 m_haveCoreFile = strstr(output, "\n#0 ") != 0;
2024 return m_haveCoreFile;
2027 uint GdbDriver::parseProgramStopped(const char* output, QString& message)
2029 // optionally: "program changed, rereading symbols",
2030 // followed by:
2031 // "Program exited normally"
2032 // "Program terminated with wignal SIGSEGV"
2033 // "Program received signal SIGINT" or other signal
2034 // "Breakpoint..."
2036 // go through the output, line by line, checking what we have
2037 const char* start = output - 1;
2038 uint flags = SFprogramActive;
2039 message = QString();
2040 do {
2041 start++; /* skip '\n' */
2043 if (strncmp(start, "Program ", 8) == 0 ||
2044 strncmp(start, "ptrace: ", 8) == 0) {
2046 * When we receive a signal, the program remains active.
2048 * Special: If we "stopped" in a corefile, the string "Program
2049 * terminated with signal"... is displayed. (Normally, we see
2050 * "Program received signal"... when a signal happens.)
2052 if (strncmp(start, "Program exited", 14) == 0 ||
2053 (strncmp(start, "Program terminated", 18) == 0 && !m_haveCoreFile) ||
2054 strncmp(start, "ptrace: ", 8) == 0)
2056 flags &= ~SFprogramActive;
2059 // set message
2060 const char* endOfMessage = strchr(start, '\n');
2061 if (endOfMessage == 0)
2062 endOfMessage = start + strlen(start);
2063 message = FROM_LATIN1(start, endOfMessage-start);
2064 } else if (strncmp(start, "Breakpoint ", 11) == 0) {
2066 * We stopped at a (permanent) breakpoint (gdb doesn't tell us
2067 * that it stopped at a temporary breakpoint).
2069 flags |= SFrefreshBreak;
2070 } else if (strstr(start, "re-reading symbols.") != 0) {
2071 flags |= SFrefreshSource;
2074 // next line, please
2075 start = strchr(start, '\n');
2076 } while (start != 0);
2079 * Gdb only notices when new threads have appeared, but not when a
2080 * thread finishes. So we always have to assume that the list of
2081 * threads has changed.
2083 flags |= SFrefreshThreads;
2085 return flags;
2088 void GdbDriver::parseSharedLibs(const char* output, QStrList& shlibs)
2090 if (strncmp(output, "No shared libraries loaded", 26) == 0)
2091 return;
2093 // parse the table of shared libraries
2095 // strip off head line
2096 output = strchr(output, '\n');
2097 if (output == 0)
2098 return;
2099 output++; /* skip '\n' */
2100 QString shlibName;
2101 while (*output != '\0') {
2102 // format of a line is
2103 // 0x404c5000 0x40580d90 Yes /lib/libc.so.5
2104 // 3 blocks of non-space followed by space
2105 for (int i = 0; *output != '\0' && i < 3; i++) {
2106 while (*output != '\0' && !isspace(*output)) { /* non-space */
2107 output++;
2109 while (isspace(*output)) { /* space */
2110 output++;
2113 if (*output == '\0')
2114 return;
2115 const char* start = output;
2116 output = strchr(output, '\n');
2117 if (output == 0)
2118 output = start + strlen(start);
2119 shlibName = FROM_LATIN1(start, output-start);
2120 if (*output != '\0')
2121 output++;
2122 shlibs.append(shlibName);
2123 TRACE("found shared lib " + shlibName);
2127 bool GdbDriver::parseFindType(const char* output, QString& type)
2129 if (strncmp(output, "type = ", 7) != 0)
2130 return false;
2133 * Everything else is the type. We strip off any leading "const" and any
2134 * trailing "&" on the grounds that neither affects the decoding of the
2135 * object. We also strip off all white-space from the type.
2137 output += 7;
2138 if (strncmp(output, "const ", 6) == 0)
2139 output += 6;
2140 type = output;
2141 type.replace(QRegExp("\\s+"), "");
2142 if (type.endsWith("&"))
2143 type.truncate(type.length() - 1);
2144 return true;
2147 void GdbDriver::parseRegisters(const char* output, QList<RegisterInfo>& regs)
2149 if (strncmp(output, "The program has no registers now", 32) == 0) {
2150 return;
2153 QString regName;
2154 QString value;
2156 // parse register values
2157 while (*output != '\0')
2159 // skip space at the start of the line
2160 while (isspace(*output))
2161 output++;
2163 // register name
2164 const char* start = output;
2165 while (*output != '\0' && !isspace(*output))
2166 output++;
2167 if (*output == '\0')
2168 break;
2169 regName = FROM_LATIN1(start, output-start);
2171 // skip space
2172 while (isspace(*output))
2173 output++;
2175 RegisterInfo* reg = new RegisterInfo;
2176 reg->regName = regName;
2179 * If we find a brace now, this is a vector register. We look for
2180 * the closing brace and treat the result as cooked value.
2182 if (*output == '{')
2184 start = output;
2185 skipNested(output, '{', '}');
2186 value = FROM_LATIN1(start, output-start).simplifyWhiteSpace();
2187 // skip space, but not the end of line
2188 while (isspace(*output) && *output != '\n')
2189 output++;
2190 // get rid of the braces at the begining and the end
2191 value.remove(0, 1);
2192 if (value[value.length()-1] == '}') {
2193 value = value.left(value.length()-1);
2195 // gdb 5.3 doesn't print a separate set of raw values
2196 if (*output == '{') {
2197 // another set of vector follows
2198 // what we have so far is the raw value
2199 reg->rawValue = value;
2201 start = output;
2202 skipNested(output, '{', '}');
2203 value = FROM_LATIN1(start, output-start).simplifyWhiteSpace();
2204 } else {
2205 // for gdb 5.3
2206 // find first type that does not have an array, this is the RAW value
2207 const char* end=start;
2208 findEnd(end);
2209 const char* cur=start;
2210 while (cur<end) {
2211 while (*cur != '=' && cur<end)
2212 cur++;
2213 cur++;
2214 while (isspace(*cur) && cur<end)
2215 cur++;
2216 if (isNumberish(*cur)) {
2217 end=cur;
2218 while (*end && (*end!='}') && (*end!=',') && (*end!='\n'))
2219 end++;
2220 QString rawValue = FROM_LATIN1(cur, end-cur).simplifyWhiteSpace();
2221 reg->rawValue = rawValue;
2223 if (rawValue.left(2)=="0x") {
2224 // ok we have a raw value, now get it's type
2225 end=cur-1;
2226 while (isspace(*end) || *end=='=') end--;
2227 end++;
2228 cur=end-1;
2229 while (*cur!='{' && *cur!=' ')
2230 cur--;
2231 cur++;
2232 reg->type=FROM_LATIN1(cur, end-cur);
2235 // end while loop
2236 cur=end;
2239 // skip to the end of line
2240 while (*output != '\0' && *output != '\n')
2241 output++;
2242 // get rid of the braces at the begining and the end
2243 value.remove(0, 1);
2244 if (value[value.length()-1] == '}') {
2245 value = value.left(value.length()-1);
2248 reg->cookedValue = value;
2250 else
2252 // the rest of the line is the register value
2253 start = output;
2254 output = strchr(output,'\n');
2255 if (output == 0)
2256 output = start + strlen(start);
2257 value = FROM_LATIN1(start, output-start).simplifyWhiteSpace();
2260 * We split the raw from the cooked values.
2261 * Some modern gdbs explicitly say: "0.1234 (raw 0x3e4567...)".
2262 * Here, the cooked value comes first, and the raw value is in
2263 * the second part.
2265 int pos = value.find(" (raw ");
2266 if (pos >= 0)
2268 reg->cookedValue = value.left(pos);
2269 reg->rawValue = value.mid(pos+6);
2270 if (reg->rawValue.right(1) == ")") // remove closing bracket
2271 reg->rawValue.truncate(reg->rawValue.length()-1);
2273 else
2276 * In other cases we split off the first token (separated by
2277 * whitespace). It is the raw value. The remainder of the line
2278 * is the cooked value.
2280 int pos = value.find(' ');
2281 if (pos < 0) {
2282 reg->rawValue = value;
2283 reg->cookedValue = QString();
2284 } else {
2285 reg->rawValue = value.left(pos);
2286 reg->cookedValue = value.mid(pos+1);
2290 if (*output != '\0')
2291 output++; /* skip '\n' */
2293 regs.append(reg);
2297 bool GdbDriver::parseInfoLine(const char* output, QString& addrFrom, QString& addrTo)
2299 // "is at address" or "starts at address"
2300 const char* start = strstr(output, "s at address ");
2301 if (start == 0)
2302 return false;
2304 start += 13;
2305 const char* p = start;
2306 while (*p != '\0' && !isspace(*p))
2307 p++;
2308 addrFrom = FROM_LATIN1(start, p-start);
2310 start = strstr(p, "and ends at ");
2311 if (start == 0) {
2312 addrTo = addrFrom;
2313 return true;
2316 start += 12;
2317 p = start;
2318 while (*p != '\0' && !isspace(*p))
2319 p++;
2320 addrTo = FROM_LATIN1(start, p-start);
2322 return true;
2325 void GdbDriver::parseDisassemble(const char* output, QList<DisassembledCode>& code)
2327 code.clear();
2329 if (strncmp(output, "Dump of assembler", 17) != 0) {
2330 // error message?
2331 DisassembledCode c;
2332 c.code = output;
2333 code.append(new DisassembledCode(c));
2334 return;
2337 // remove first line
2338 const char* p = strchr(output, '\n');
2339 if (p == 0)
2340 return; /* not a regular output */
2342 p++;
2344 // remove last line
2345 const char* end = strstr(output, "End of assembler");
2346 if (end == 0)
2347 end = p + strlen(p);
2349 DbgAddr address;
2351 // remove function offsets from the lines
2352 while (p != end)
2354 const char* start = p;
2355 // address
2356 while (p != end && !isspace(*p))
2357 p++;
2358 address = FROM_LATIN1(start, p-start);
2360 // function name (enclosed in '<>', followed by ':')
2361 while (p != end && *p != '<')
2362 p++;
2363 if (*p == '<')
2364 skipNested(p, '<', '>');
2365 if (*p == ':')
2366 p++;
2368 // space until code
2369 while (p != end && isspace(*p))
2370 p++;
2372 // code until end of line
2373 start = p;
2374 while (p != end && *p != '\n')
2375 p++;
2376 if (p != end) /* include '\n' */
2377 p++;
2379 DisassembledCode* c = new DisassembledCode;
2380 c->address = address;
2381 c->code = FROM_LATIN1(start, p-start);
2382 code.append(c);
2386 QString GdbDriver::parseMemoryDump(const char* output, QList<MemoryDump>& memdump)
2388 if (isErrorExpr(output)) {
2389 // error; strip space
2390 QString msg = output;
2391 return msg.stripWhiteSpace();
2394 const char* p = output; /* save typing */
2395 DbgAddr addr;
2396 QString dump;
2398 // the address
2399 while (*p != 0) {
2400 const char* start = p;
2401 while (*p != '\0' && *p != ':' && !isspace(*p))
2402 p++;
2403 addr = FROM_LATIN1(start, p-start);
2404 if (*p != ':') {
2405 // parse function offset
2406 while (isspace(*p))
2407 p++;
2408 start = p;
2409 while (*p != '\0' && !(*p == ':' && isspace(p[1])))
2410 p++;
2411 addr.fnoffs = FROM_LATIN1(start, p-start);
2413 if (*p == ':')
2414 p++;
2415 // skip space; this may skip a new-line char!
2416 while (isspace(*p))
2417 p++;
2418 // everything to the end of the line is the memory dump
2419 const char* end = strchr(p, '\n');
2420 if (end != 0) {
2421 dump = FROM_LATIN1(p, end-p);
2422 p = end+1;
2423 } else {
2424 dump = FROM_LATIN1(p, strlen(p));
2425 p += strlen(p);
2427 MemoryDump* md = new MemoryDump;
2428 md->address = addr;
2429 md->dump = dump;
2430 memdump.append(md);
2433 return QString();
2436 QString GdbDriver::editableValue(VarTree* value)
2438 const char* s = value->m_value.latin1();
2440 // if the variable is a pointer value that contains a cast,
2441 // remove the cast
2442 if (*s == '(') {
2443 skipNested(s, '(', ')');
2444 // skip space
2445 while (isspace(*s))
2446 ++s;
2449 repeat:
2450 const char* start = s;
2452 if (strncmp(s, "0x", 2) == 0)
2454 s += 2;
2455 while (isxdigit(*s))
2456 ++s;
2459 * What we saw so far might have been a reference. If so, edit the
2460 * referenced value. Otherwise, edit the pointer.
2462 if (*s == ':') {
2463 // a reference
2464 ++s;
2465 goto repeat;
2467 // a pointer
2468 // if it's a pointer to a string, remove the string
2469 const char* end = s;
2470 while (isspace(*s))
2471 ++s;
2472 if (*s == '"') {
2473 // a string
2474 return FROM_LATIN1(start, end-start);
2475 } else {
2476 // other pointer
2477 return FROM_LATIN1(start, strlen(start));
2481 // else leave it unchanged (or stripped of the reference preamble)
2482 return s;
2485 QString GdbDriver::parseSetVariable(const char* output)
2487 // if there is any output, it is an error message
2488 QString msg = output;
2489 return msg.stripWhiteSpace();
2493 #include "gdbdriver.moc"