3 // Copyright by Johannes Sixt, Keith Isdale
4 // This file is under GPL, the GNU General Public Licence
6 #include "xsldbgdriver.h"
8 #include <qstringlist.h>
9 #include <klocale.h> /* i18n */
11 #include <stdlib.h> /* strtol, atoi */
12 #include <string.h> /* strcpy */
13 #include <kmessagebox.h>
22 static VarTree
*parseVar(const char *&s
);
23 static bool parseName(const char *&s
, QString
& name
,
24 VarTree::NameKind
& kind
);
25 static bool parseValue(const char *&s
, VarTree
* variable
);
26 static bool isErrorExpr(const char *output
);
28 #define TERM_IO_ALLOWED 1
30 // TODO: make this cmd info stuff non-static to allow multiple
31 // simultaneous gdbs to run!
33 struct XsldbgCmdInfo
{
35 const char *fmt
; /* format string */
37 argNone
, argString
, argNum
,
38 argStringNum
, argNumString
,
44 * The following array of commands must be sorted by the DC* values,
45 * because they are used as indices.
47 static XsldbgCmdInfo cmds
[] = {
48 {DCinitialize
, "init\n", XsldbgCmdInfo::argNone
},
49 {DCtty
, "tty %s\n", XsldbgCmdInfo::argString
},
50 {DCexecutable
, "source %s\n", XsldbgCmdInfo::argString
}, /* force a restart */
51 {DCtargetremote
, "print 'target remote %s'\n", XsldbgCmdInfo::argString
},
52 {DCcorefile
, "data %s\n", XsldbgCmdInfo::argString
}, /* force a restart */
53 {DCattach
, "print 'attach %s'\n", XsldbgCmdInfo::argString
},
54 {DCinfolinemain
, "print 'info main line'\n", XsldbgCmdInfo::argNone
},
55 {DCinfolocals
, "locals -f\n", XsldbgCmdInfo::argNone
},
56 {DCinforegisters
, "print 'info reg'\n", XsldbgCmdInfo::argNone
},
57 {DCexamine
, "print 'x %s %s'\n", XsldbgCmdInfo::argString2
},
58 {DCinfoline
, "print 'templates %s:%d'\n", XsldbgCmdInfo::argStringNum
},
59 {DCdisassemble
, "print 'disassemble %s %s'\n", XsldbgCmdInfo::argString2
},
60 {DCsetargs
, "data %s\n", XsldbgCmdInfo::argString
},
61 {DCsetenv
, "addparam %s %s\n", XsldbgCmdInfo::argString2
},
62 {DCunsetenv
, "unset env %s\n", XsldbgCmdInfo::argString
},
63 {DCsetoption
, "setoption %s %d\n", XsldbgCmdInfo::argStringNum
},
64 {DCcd
, "chdir %s\n", XsldbgCmdInfo::argString
},
65 {DCbt
, "where\n", XsldbgCmdInfo::argNone
},
66 {DCrun
, "run\nsource\n", XsldbgCmdInfo::argNone
}, /* Ensure that at the start
67 of executing XSLT we show the XSLT file */
68 {DCcont
, "continue\n", XsldbgCmdInfo::argNone
},
69 {DCstep
, "step\n", XsldbgCmdInfo::argNone
},
70 {DCstepi
, "step\n", XsldbgCmdInfo::argNone
},
71 {DCnext
, "next\n", XsldbgCmdInfo::argNone
},
72 {DCnexti
, "next\n", XsldbgCmdInfo::argNone
},
73 {DCfinish
, "stepup\n", XsldbgCmdInfo::argNone
},
74 {DCuntil
, "continue %s:%d\n", XsldbgCmdInfo::argStringNum
},
75 {DCkill
, "quit\n", XsldbgCmdInfo::argNone
},
76 {DCbreaktext
, "break %s\n", XsldbgCmdInfo::argString
},
77 {DCbreakline
, "break -l %s %d\n", XsldbgCmdInfo::argStringNum
},
78 {DCtbreakline
, "break -l %s %d\n", XsldbgCmdInfo::argStringNum
},
79 {DCbreakaddr
, "print `break *%s`\n", XsldbgCmdInfo::argString
},
80 {DCtbreakaddr
, "print `tbreak *%s`\n", XsldbgCmdInfo::argString
},
81 {DCwatchpoint
, "print 'watch %s'\n", XsldbgCmdInfo::argString
},
82 {DCdelete
, "delete %d\n", XsldbgCmdInfo::argNum
},
83 {DCenable
, "enable %d\n", XsldbgCmdInfo::argNum
},
84 {DCdisable
, "disable %d\n", XsldbgCmdInfo::argNum
},
85 {DCprint
, "print %s\n", XsldbgCmdInfo::argString
},
86 {DCprintDeref
, "print 'print (*%s)'\n", XsldbgCmdInfo::argString
},
87 {DCprintStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
88 {DCprintQStringStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
89 {DCframe
, "frame %d\n", XsldbgCmdInfo::argNum
},
90 {DCfindType
, "print 'whatis %s'\n", XsldbgCmdInfo::argString
},
91 {DCinfosharedlib
, "stylesheets\n", XsldbgCmdInfo::argNone
},
92 {DCthread
, "print 'thread %d'\n", XsldbgCmdInfo::argNum
},
93 {DCinfothreads
, "print 'info threads'\n", XsldbgCmdInfo::argNone
},
94 {DCinfobreak
, "show\n", XsldbgCmdInfo::argNone
},
95 {DCcondition
, "print 'condition %d %s'\n", XsldbgCmdInfo::argNumString
},
96 {DCsetpc
, "print 'set variable $pc=%s'\n", XsldbgCmdInfo::argString
},
97 {DCignore
, "print 'ignore %d %d'\n", XsldbgCmdInfo::argNum2
},
98 {DCsetvariable
, "set %s %s\n", XsldbgCmdInfo::argString2
},
101 #define NUM_CMDS (int(sizeof(cmds)/sizeof(cmds[0])))
102 #define MAX_FMTLEN 200
104 XsldbgDriver::XsldbgDriver():
105 DebuggerDriver(), m_gdbMajor(2), m_gdbMinor(0)
107 m_promptRE
.setPattern("\\(xsldbg\\) .*> $");
109 m_promptLastChar
= ' ';
111 m_markerRE
.setPattern("^Breakpoint at file ");
112 m_haveDataFile
= FALSE
;
115 // check command info array
118 for (int i
= 0; i
< NUM_CMDS
; i
++) {
119 // must be indexable by DbgCommand values, i.e. sorted by DbgCommand values
120 assert(i
== cmds
[i
].cmd
);
121 // a format string must be associated
122 assert(cmds
[i
].fmt
!= 0);
123 assert(strlen(cmds
[i
].fmt
) <= MAX_FMTLEN
);
124 // format string must match arg specification
125 switch (cmds
[i
].argsNeeded
) {
126 case XsldbgCmdInfo::argNone
:
127 assert(strchr(cmds
[i
].fmt
, '%') == 0);
129 case XsldbgCmdInfo::argString
:
130 perc
= strchr(cmds
[i
].fmt
, '%');
131 assert(perc
!= 0 && perc
[1] == 's');
132 assert(strchr(perc
+ 2, '%') == 0);
134 case XsldbgCmdInfo::argNum
:
135 perc
= strchr(cmds
[i
].fmt
, '%');
136 assert(perc
!= 0 && perc
[1] == 'd');
137 assert(strchr(perc
+ 2, '%') == 0);
139 case XsldbgCmdInfo::argStringNum
:
140 perc
= strchr(cmds
[i
].fmt
, '%');
141 assert(perc
!= 0 && perc
[1] == 's');
142 perc
= strchr(perc
+ 2, '%');
143 assert(perc
!= 0 && perc
[1] == 'd');
144 assert(strchr(perc
+ 2, '%') == 0);
146 case XsldbgCmdInfo::argNumString
:
147 perc
= strchr(cmds
[i
].fmt
, '%');
148 assert(perc
!= 0 && perc
[1] == 'd');
149 perc
= strchr(perc
+ 2, '%');
150 assert(perc
!= 0 && perc
[1] == 's');
151 assert(strchr(perc
+ 2, '%') == 0);
153 case XsldbgCmdInfo::argString2
:
154 perc
= strchr(cmds
[i
].fmt
, '%');
155 assert(perc
!= 0 && perc
[1] == 's');
156 perc
= strchr(perc
+ 2, '%');
157 assert(perc
!= 0 && perc
[1] == 's');
158 assert(strchr(perc
+ 2, '%') == 0);
160 case XsldbgCmdInfo::argNum2
:
161 perc
= strchr(cmds
[i
].fmt
, '%');
162 assert(perc
!= 0 && perc
[1] == 'd');
163 perc
= strchr(perc
+ 2, '%');
164 assert(perc
!= 0 && perc
[1] == 'd');
165 assert(strchr(perc
+ 2, '%') == 0);
172 XsldbgDriver::~XsldbgDriver()
178 XsldbgDriver::driverName() const
184 XsldbgDriver::defaultXsldbg()
186 return "xsldbg --shell --gdb";
190 XsldbgDriver::defaultInvocation() const
192 return defaultXsldbg();
195 QStringList
XsldbgDriver::boolOptionList() const
197 QStringList allOptions
;
198 allOptions
.append("verbose");
199 allOptions
.append("repeat");
200 allOptions
.append("debug");
201 allOptions
.append("novalid");
202 allOptions
.append("noout");
203 allOptions
.append("html");
204 allOptions
.append("docbook");
205 allOptions
.append("nonet");
206 allOptions
.append("catalogs");
207 allOptions
.append("xinclude");
208 allOptions
.append("profile");
214 XsldbgDriver::slotReceiveOutput(KProcess
* process
, char *buffer
,
218 if (m_state
!= DSidle
) {
220 DebuggerDriver::slotReceiveOutput(process
, buffer
, buflen
);
222 if (strncmp(buffer
, "quit", 4) == 0) {
223 TRACE("Ignoring text when xsldbg is quiting");
226 ("Stray output received by XsldbgDriver::slotReceiveOutput");
233 XsldbgDriver::startup(QString cmdStr
)
235 if (!DebuggerDriver::startup(cmdStr
))
238 static const char xsldbgInitialize
[] = "pwd\n"; /* don't need to do anything else */
240 executeCmdString(DCinitialize
, xsldbgInitialize
, false);
246 XsldbgDriver::commandFinished(CmdQueueItem
* cmd
)
249 TRACE(__PRETTY_FUNCTION__
);
250 // command string must be committed
251 if (!cmd
->m_committed
) {
254 (__PRETTY_FUNCTION__
+
255 (" with uncommited command:\n\t" + cmd
->m_cmdString
)));
259 switch (cmd
->m_cmd
) {
261 // get version number from preamble
264 QRegExp
xsldbgVersion("^XSLDBG [0-9]+\\.[0-9]+\\.[0-9]+");
265 int offset
= xsldbgVersion
.match(m_output
, 0, &len
);
268 char *start
= m_output
+ offset
+ 7; // skip "^XSLDBG "
271 TRACE("Reading version");
273 m_gdbMajor
= strtol(start
, &end
, 10);
274 m_gdbMinor
= strtol(end
+ 1, 0, 10); // skip "."
276 // nothing was parsed
281 // assume some default version (what would make sense?)
285 TRACE(QString("Got version ") +
286 QString::number(m_gdbMajor
) + "." +
287 QString::number(m_gdbMinor
));
292 /* ok, the command is ready */
293 emit
commandReceived(cmd
, m_output
);
295 switch (cmd
->m_cmd
) {
303 if (!::isErrorExpr(m_output
))
306 // This only shows an error for DCinfolocals
307 // need to update KDebugger::handleRunCommand ?
308 KMessageBox::sorry(0L, m_output
);
314 if (!m_xslFile
.isEmpty())
315 emit
activateFileLine(m_xslFile
, 0, DbgAddr());
323 XsldbgDriver::parseMarker()
326 // TRACE("parseMarker : xsldbg");
328 int len
, markerStart
= -1;
331 while (markerStart
== -1) {
332 if ((p
== 0) || (*p
== '\0')) {
336 //TRACE(QString("parseMarker is looking at :") + p);
337 markerStart
= m_markerRE
.match(p
, 0, &len
);
338 if (markerStart
== -1) {
339 // try to marker on next line !
341 if ((p
!= 0) && (*p
!= '\0'))
347 // extract the marker
348 char *startMarker
= p
+ markerStart
+ len
;
350 //TRACE(QString("found marker:") + startMarker);
351 char *endMarker
= strchr(startMarker
, '\n');
358 // extract filename and line number
359 static QRegExp
MarkerRE(" : line [0-9]+");
361 int lineNoStart
= MarkerRE
.match(startMarker
, 0, &len
);
363 if (lineNoStart
>= 0) {
364 int lineNo
= atoi(startMarker
+ lineNoStart
+ 8);
368 // now show the window
369 startMarker
[lineNoStart
] = '\0'; /* split off file name */
370 TRACE("Got file and line number");
371 TRACE(QString(startMarker
) + ": " + QString::number(lineNo
));
372 emit
activateFileLine(startMarker
, lineNo
- 1, address
);
378 * Escapes characters that might lead to problems when they appear on gdb's
382 normalizeStringArg(QString
& arg
)
385 * Remove trailing backslashes. This approach is a little simplistic,
386 * but we know that there is at the moment no case where a trailing
387 * backslash would make sense.
389 while (!arg
.isEmpty() && arg
[arg
.length() - 1] == '\\') {
390 arg
= arg
.left(arg
.length() - 1);
396 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
)
398 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
399 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString
);
401 normalizeStringArg(strArg
);
404 // need the working directory when parsing the output
405 m_programWD
= strArg
;
406 } else if (cmd
== DCexecutable
) {
407 // want to display the XSL file
411 SIZED_QString(cmdString
, MAX_FMTLEN
+ strArg
.length());
412 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1());
417 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg
)
419 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
420 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum
);
422 SIZED_QString(cmdString
, MAX_FMTLEN
+ 30);
424 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
);
429 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
, int intArg
)
431 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
432 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
||
433 cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNumString
||
434 cmd
== DCexamine
|| cmd
== DCtty
);
436 normalizeStringArg(strArg
);
438 SIZED_QString(cmdString
, MAX_FMTLEN
+ 30 + strArg
.length());
442 * intArg specifies which channels should be redirected to
443 * /dev/null. It is a value or'ed together from RDNstdin,
444 * RDNstdout, RDNstderr.
446 static const char *const runRedir
[8] = {
450 " </dev/null >/dev/null",
452 " </dev/null 2>/dev/null",
454 " </dev/null >/dev/null 2>&1"
457 if (strArg
.isEmpty())
458 intArg
= 7; /* failsafe if no tty */
459 m_redirect
= runRedir
[intArg
& 7];
461 return makeCmdString(DCtty
, strArg
); /* note: no problem if strArg empty */
464 if (cmd
== DCexamine
) {
465 // make a format specifier from the intArg
466 static const char size
[16] = {
467 '\0', 'b', 'h', 'w', 'g'
469 static const char format
[16] = {
470 '\0', 'x', 'd', 'u', 'o', 't',
471 'a', 'c', 'f', 's', 'i'
474 assert(MDTsizemask
== 0xf); /* lowest 4 bits */
475 assert(MDTformatmask
== 0xf0); /* next 4 bits */
476 int count
= 16; /* number of entities to print */
477 char sizeSpec
= size
[intArg
& MDTsizemask
];
478 char formatSpec
= format
[(intArg
& MDTformatmask
) >> 4];
480 assert(sizeSpec
!= '\0');
481 assert(formatSpec
!= '\0');
482 // adjust count such that 16 lines are printed
483 switch (intArg
& MDTformatmask
) {
486 break; /* no modification needed */
488 // all cases drop through:
489 switch (intArg
& MDTsizemask
) {
502 spec
.sprintf("/%d%c%c", count
, sizeSpec
, formatSpec
);
504 return makeCmdString(DCexamine
, spec
, strArg
);
507 if (cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
) {
508 // line numbers are zero-based
509 if (cmd
== DCuntil
|| cmd
== DCbreakline
||
510 cmd
== DCtbreakline
|| cmd
== DCinfoline
) {
513 if (cmd
== DCinfoline
) {
514 // must split off file name part
515 int slash
= strArg
.findRev('/');
518 strArg
= strArg
.right(strArg
.length() - slash
- 1);
520 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1(), intArg
);
522 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
, strArg
.latin1());
528 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg1
,
531 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
532 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString2
);
534 normalizeStringArg(strArg1
);
535 normalizeStringArg(strArg2
);
537 SIZED_QString(cmdString
,
538 MAX_FMTLEN
+ strArg1
.length() + strArg2
.length());
539 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg1
.latin1(), strArg2
.latin1());
544 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg1
, int intArg2
)
546 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
547 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum2
);
549 SIZED_QString(cmdString
, MAX_FMTLEN
+ 60);
550 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg1
, intArg2
);
555 XsldbgDriver::executeCmd(DbgCommand cmd
, bool clearLow
)
557 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
558 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNone
);
561 m_haveCoreFile
= false;
564 return executeCmdString(cmd
, cmds
[cmd
].fmt
, clearLow
);
568 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, bool clearLow
)
570 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
), clearLow
);
574 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg
, bool clearLow
)
577 return executeCmdString(cmd
, makeCmdString(cmd
, intArg
), clearLow
);
581 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, int intArg
,
584 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
),
589 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
592 return executeCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
),
597 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg1
, int intArg2
,
600 return executeCmdString(cmd
, makeCmdString(cmd
, intArg1
, intArg2
),
605 XsldbgDriver::queueCmd(DbgCommand cmd
, QueueMode mode
)
607 return queueCmdString(cmd
, cmds
[cmd
].fmt
, mode
);
611 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, QueueMode mode
)
613 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
), mode
);
617 XsldbgDriver::queueCmd(DbgCommand cmd
, int intArg
, QueueMode mode
)
619 return queueCmdString(cmd
, makeCmdString(cmd
, intArg
), mode
);
623 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, int intArg
,
626 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
), mode
);
630 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
633 return queueCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
), mode
);
637 XsldbgDriver::terminate()
639 qDebug("XsldbgDriver::Terminate");
641 executeCmdString(DCinitialize
, "quit\n", true);
647 XsldbgDriver::detachAndTerminate()
649 qDebug("XsldbgDriver::detachAndTerminate");
651 executeCmdString(DCinitialize
, "quit\n", true);
656 XsldbgDriver::interruptInferior()
658 // remove accidentally queued commands
659 qDebug("interruptInferior");
665 isErrorExpr(const char *output
)
669 #define ERROR_WORD_COUNT 5
670 static const char *errorWords
[ERROR_WORD_COUNT
] = {
672 "error:", // libxslt error
675 "warning:" // libxslt warning
677 static int errorWordLength
[ERROR_WORD_COUNT
] = {
680 15, /* Unknown command*/
685 for (wordIndex
= 0; wordIndex
< ERROR_WORD_COUNT
; wordIndex
++){
687 errorWords
[wordIndex
],
688 errorWordLength
[wordIndex
]) == 0){
690 TRACE(QString("Error/Warning from xsldbg ") + output
);
699 * Returns true if the output is an error message. If wantErrorValue is
700 * true, a new VarTree object is created and filled with the error message.
703 parseErrorMessage(const char *output
,
704 VarTree
* &variable
, bool wantErrorValue
)
706 if (isErrorExpr(output
)) {
707 if (wantErrorValue
) {
708 // put the error message as value in the variable
709 variable
= new VarTree(QString(), VarTree::NKplain
);
710 const char *endMsg
= strchr(output
, '\n');
713 endMsg
= output
+ strlen(output
);
714 variable
->m_value
= FROM_LATIN1(output
, endMsg
- output
);
725 XsldbgDriver::setPrintQStringDataCmd(const char* /*cmd*/)
730 XsldbgDriver::parseQCharArray(const char */
*output*/
, bool /*wantErrorValue*/,
733 VarTree
*variable
= 0;
735 TRACE("XsldbgDriver::parseQCharArray not implmented");
740 parseVar(const char *&s
)
743 bool foundLocalVar
= false;
744 VarTree
*variable
= 0L;
747 VarTree::NameKind kind
;
749 TRACE(__PRETTY_FUNCTION__
);
752 if (parseErrorMessage(p
, variable
, false) == true) {
753 TRACE("Found error message");
757 if (strncmp(p
, " Local", 6) == 0) {
758 foundLocalVar
= true;
761 TRACE("Found local variable");
762 } else if (strncmp(p
, " Global", 7) == 0) {
765 TRACE("Found global variable");
766 } else if (strncmp(p
, "= ", 2) == 0) {
767 /* we're processing the result of a "print command" */
769 char *nextLine
= strchr(p
, '\n');
771 TRACE("Found print expr");
773 char nameBuffer
[100];
775 p
= p
+ 2; /* skip the "= " */
776 strncpy(nameBuffer
, p
, nextLine
- p
);
778 variable
= new VarTree(nameBuffer
, kind
);
779 if (variable
!= 0L) {
780 variable
->m_varKind
= VarTree::VKsimple
;
781 variable
->setDeleteChildren(true);
782 parseValue(p
, variable
);
787 return variable
; /* don't know what to do this this data abort!! */
794 // No value provided just a name
795 TRACE(QString("Parse var: name") + p
);
796 if (!parseName(p
, name
, kind
)) {
799 variable
= new VarTree(name
, kind
);
800 if (variable
!= 0L) {
801 variable
->m_varKind
= VarTree::VKsimple
;
802 variable
->setDeleteChildren(true);
809 TRACE(QString("Parse var: name") + p
);
810 if (!parseName(p
, name
, kind
)) {
813 variable
= new VarTree(name
, kind
);
814 if (variable
!= 0L) {
815 variable
->m_varKind
= VarTree::VKsimple
;
816 variable
->setDeleteChildren(true);
820 if (!parseValue(p
, variable
)) {
835 skipName(const char *&p
)
837 // allow : (for enumeration values) and $ and . (for _vtbl.)
838 while (isalnum(*p
) || *p
== '_' || *p
== ':' || *p
== '$' || *p
== '.')
843 parseName(const char *&s
, QString
& name
, VarTree::NameKind
& kind
)
845 /* qDebug(__PRETTY_FUNCTION__); */
846 kind
= VarTree::NKplain
;
851 // examples of names:
854 while ((*p
!= '\n') && (*p
!= '\0')) {
860 name
= FROM_LATIN1(s
, len
);
861 /* XSL variables will have a $ prefix to be evaluated
863 //TRACE(QString("parseName got name" ) + name);
865 // return the new position
871 parseValue(const char *&s
, VarTree
* variable
)
873 const char *start
= s
, *end
= s
;
874 VarTree
* childValue
;
875 #define VALUE_END_MARKER_INDEX 0
877 /* This mark the end of a value */
878 static const char *marker
[] = {
879 "\032\032", /* value end marker*/
881 "Breakpoint at", /* stepped to next location */
882 "Breakpoint in", /* reached a set breakpoint */
883 "Reached ", /* reached template */
890 static char valueBuffer
[2048];
891 int markerIndex
= 0, foundEnd
= 0;
895 return false; /* should never happen but .. */
897 while (start
&& (*start
!= '\0')) {
898 /* look for the next marker */
899 for (markerIndex
= 0; marker
[markerIndex
] != 0; markerIndex
++) {
901 strncmp(start
, marker
[markerIndex
],
902 strlen(marker
[markerIndex
])) == 0;
911 end
= strchr(start
, '\n');
913 copySize
= end
- start
;
915 copySize
= strlen(start
);
916 if (copySize
>= sizeof(valueBuffer
))
917 copySize
= sizeof(valueBuffer
)-1;
919 strncpy(valueBuffer
, start
, copySize
);
920 valueBuffer
[copySize
] = '\0';
921 TRACE("Got value :");
923 if ((variable
->m_varKind
== VarTree::VKsimple
)) {
924 if (!variable
->m_value
.isEmpty()){
925 variable
->m_varKind
= VarTree::VKarray
;
926 childValue
= new VarTree(variable
->m_value
, VarTree::NKplain
);
927 variable
->appendChild(childValue
);
928 childValue
= new VarTree(valueBuffer
, VarTree::NKplain
);
929 variable
->appendChild(childValue
);
930 variable
->m_value
= "";
932 variable
->m_value
= valueBuffer
;
935 childValue
= new VarTree(valueBuffer
, VarTree::NKplain
);
936 variable
->appendChild(childValue
);
948 TRACE(QString("Unable to find end on value near :") + start
);
950 // If we've got something otherthan a end of value marker then
951 // advance to the end of this buffer
952 if (markerIndex
!= VALUE_END_MARKER_INDEX
){
953 while (start
&& *start
!= '\0')
956 start
= start
+ strlen(marker
[0]);
966 * Parses a stack frame.
969 parseFrameInfo(const char *&s
, QString
& func
,
970 QString
& file
, int &lineNo
, DbgAddr
& /*address*/)
972 const char *p
= s
, *endPos
= s
+ strlen(s
);
973 QString lineNoString
;
977 /* skip 'template :\" */
979 //TRACE("parseFrameInfo");
982 while ((*p
!= '\"') && (*p
!= '\0')) {
992 /* skip mode :".*" */
993 while (p
&& *p
!= '"')
997 while (p
&& *p
!= '"')
1001 while (p
&& *p
!= '"')
1003 /* skip '" in file ' */
1007 while (!isspace(*p
) && (*p
!= '\0')) {
1011 ASSERT(p
<= endPos
);
1017 /* skip ' : line '" */
1020 ASSERT(p
<= endPos
);
1026 /* KDbg uses an offset of +1 for its line numbers */
1027 lineNo
= atoi(p
) - 1;
1028 lineNoString
= QString::number(lineNo
);
1030 /* convert func into format needed */
1031 func
.append(" at ");
1034 func
.append(lineNoString
);
1036 //TRACE(QString("Got frame : template :\"") + func + "\"file:" +
1037 // file + " line : " + lineNoString);
1039 /*advance to next line */
1040 p
= strchr(p
, '\n');
1050 * Parses a stack frame including its frame number
1053 parseFrame(const char *&s
, int &frameNo
, QString
& func
,
1054 QString
& file
, int &lineNo
, DbgAddr
& address
)
1057 // TRACE("XsldbgDriver ::parseFrame");
1058 /* skip leading 'where' or 'frame <frame_no>' */
1059 if ((strncmp(s
, "where", 5) == 0) || (strncmp(s
, "frame", 5) == 0)) {
1060 s
= strchr(s
, '\n');
1061 if ((*s
!= '\0') && (*s
!= '#'))
1067 //#1 template :"/" in file /home/keith/anon_CVS/xsldbg/docs/en/xsldoc.xsl : line 21
1068 // must start with a hash mark followed by number
1069 if (s
[0] != '#' || !isdigit(s
[1]))
1072 //TRACE("XsldbgDriver ::parseFrame got #");
1073 s
++; /* skip the hash mark */
1079 //TRACE(QString("Got frame ").append(QString::number(frameNo)));
1083 parseFrameInfo(s
, func
, file
, lineNo
, address
);
1084 // TRACE("Will next look at ");
1090 XsldbgDriver::parseBackTrace(const char *output
,
1091 QList
< StackFrame
> &stack
)
1094 int lineNo
, frameNo
;
1097 while (::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
)) {
1098 StackFrame
*frm
= new StackFrame
;
1100 frm
->frameNo
= frameNo
;
1101 frm
->fileName
= file
;
1102 frm
->lineNo
= lineNo
;
1103 frm
->address
= address
;
1104 frm
->var
= new VarTree(func
, VarTree::NKplain
);
1110 XsldbgDriver::parseFrameChange(const char *output
, int &frameNo
,
1111 QString
& file
, int &lineNo
,
1116 return::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
);
1121 XsldbgDriver::parseBreakList(const char *output
,
1122 QList
< Breakpoint
> &brks
)
1124 TRACE("parseBreakList");
1125 /* skip the first blank line */
1129 QString location
, file
, lineNo
;
1131 QString templateName
;
1134 uint ignoreCount
= 0;
1137 p
= strchr(output
, '\n');/* skip the first blank line*/
1139 while ((p
!= 0) && (*p
!= '\0')) {
1140 templateName
= QString();
1142 Breakpoint::Type bpType
= Breakpoint::breakpoint
;
1143 //qDebug("Looking at :%s", p);
1144 if (strncmp(p
, " Breakpoint", 11) != 0)
1152 long bpNum
= strtol(p
, &dummy
, 10); /* don't care about overflows */
1155 if ((p
== 0) || (p
[1] == '\0'))
1160 // Get breakpoint state ie enabled/disabled
1161 if (strncmp(p
, "enabled", 7) == 0) {
1165 if (strncmp(p
, "disabled", 8) == 0) {
1169 TRACE("Parse error in breakpoint list");
1175 //TRACE("Looking for template");
1178 /* check for ' for template :"'*/
1179 if (strncmp(p
, " for template :\"", 16) == 0){
1181 //TRACE("Looking for template name near");
1183 /* get the template name */
1184 while (p
&& (*p
!= '\0') && (*p
!= '\"')){
1185 templateName
.append(*p
);
1191 TRACE("Error missed \" near");
1196 //TRACE("Looking for mode near");
1198 if (strncmp(p
, " mode :\"", 8) == 0) {
1200 while (p
&& *p
!= '\"')
1206 if (strncmp(p
, " in file ", 9) != 0){
1207 TRACE("Parse error in breakpoint list");
1213 /* skip ' in file ' */
1217 /* grab file name */
1218 while (!isspace(*p
)) {
1225 /* skip ' : line ' */
1228 while (isdigit(*p
)) {
1234 //TRACE("Got breakpoint");
1236 Breakpoint
*bp
= new Breakpoint
;
1239 // take 1 of line number
1240 lineNo
.setNum(lineNo
.toInt() - 1);
1243 bp
->temporary
= false;
1244 bp
->enabled
= enabled
;
1245 location
.append("in ").append(templateName
).append(" at ");
1246 location
.append(file
).append(":").append(lineNo
);
1247 bp
->location
= location
;
1248 bp
->fileName
= file
;
1249 bp
->lineNo
= lineNo
.toInt();
1250 bp
->address
= address
;
1251 bp
->hitCount
= hits
;
1252 bp
->ignoreCount
= ignoreCount
;
1253 bp
->condition
= condition
;
1259 TRACE("Outof memory, breakpoint not created");
1262 p
= strchr(p
, '\n');
1269 XsldbgDriver::parseThreadList(const char */
*output*/
,
1270 QList
< ThreadInfo
> &/*threads*/)
1276 XsldbgDriver::parseBreakpoint(const char *output
, int &id
,
1277 QString
&file
, int &lineNo
, QString
&address
)
1280 if ( strncmp(output
, "Error:", 6) == 0) {
1285 if (strncmp(output
, "Breakpoint ", 11) != 0)
1289 if (!isdigit(*output
))
1293 id
= strtol(output
, &dummy
, 10); /* don't care about overflows */
1294 if (output
== dummy
)
1297 // the file name + lineNo will be filled in later from the breakpoint list
1298 file
= address
= QString();
1304 XsldbgDriver::parseLocals(const char *output
, QList
< VarTree
> &newVars
)
1307 /* keep going until error or xsldbg prompt is found */
1308 while (*output
!= '\0') {
1309 VarTree
*variable
= parseVar(output
);
1311 if (variable
== 0) {
1314 // do not add duplicates
1315 for (VarTree
* o
= newVars
.first(); o
!= 0; o
= newVars
.next()) {
1316 if (o
->getText() == variable
->getText()) {
1322 newVars
.append(variable
);
1329 XsldbgDriver::parsePrintExpr(const char *output
, bool wantErrorValue
,
1332 // check for error conditions
1333 if (parseErrorMessage(output
, var
, wantErrorValue
)) {
1336 // parse the variable
1337 var
= parseVar(output
);
1343 XsldbgDriver::parseChangeWD(const char *output
, QString
& message
)
1345 bool isGood
= false;
1347 if (strncmp(output
, "Change to directory", 20) == 0) {
1348 output
= output
+ 20; /* skip 'Change to directory' */
1349 message
= QString(output
).simplifyWhiteSpace();
1350 if (message
.isEmpty()) {
1351 message
= i18n("New working directory: ") + m_programWD
;
1359 XsldbgDriver::parseChangeExecutable(const char *output
, QString
& message
)
1362 TRACE(QString("XsldbgDriver::parseChangeExecutable :") + output
);
1363 m_haveCoreFile
= false;
1366 * The command is successful if there is no output or the single
1367 * message (no debugging symbols found)...
1369 QRegExp
exp(".*Load of source deferred use run command.*");
1370 int len
, index
= exp
.match(output
, 0, &len
);
1373 TRACE("Parsed stylesheet executable");
1376 return (output
[0] == '\0') || (index
!= -1);
1380 XsldbgDriver::parseCoreFile(const char *output
)
1382 TRACE("XsldbgDriver::parseCoreFile");
1384 QRegExp
exp(".*Load of xml data deferred use run command.*");
1385 int len
, index
= exp
.match(output
, 0, &len
);
1388 m_haveCoreFile
= true;
1389 TRACE("Parsed xml data file");
1392 return m_haveCoreFile
;
1396 XsldbgDriver::parseProgramStopped(const char *output
, QString
& message
)
1398 /* Not sure about this function leave it here for the moment */
1400 * return DebuggerDriver::SFrefreshBreak & DebuggerDriver::SFprogramActive;
1403 // go through the output, line by line, checking what we have
1404 const char *start
= output
- 1;
1405 uint flags
= SFprogramActive
;
1407 message
= QString();
1409 start
++; /* skip '\n' */
1411 if (strncmp(start
, "Finished stylesheet\n\032\032\n", 21) == 0){
1412 flags
&= ~SFprogramActive
;
1416 // next line, please
1417 start
= strchr(start
, '\n');
1418 } while (start
!= 0);
1424 XsldbgDriver::parseSharedLibs(const char */
*output*/
, QStrList
& /*shlibs*/)
1430 XsldbgDriver::parseFindType(const char */
*output*/
, QString
& /*type*/)
1436 XsldbgDriver::parseRegisters(const char */
*output*/
,
1437 QList
< RegisterInfo
> &/*regs*/)
1443 XsldbgDriver::parseInfoLine(const char */
*output*/
, QString
& /*addrFrom*/,
1444 QString
& /*addrTo*/)
1450 XsldbgDriver::parseDisassemble(const char */
*output*/
,
1451 QList
< DisassembledCode
> &/*code*/)
1457 XsldbgDriver::parseMemoryDump(const char */
*output*/
,
1458 QList
< MemoryDump
> &/*memdump*/)
1460 return i18n("No memory dump available");
1464 XsldbgDriver::parseSetVariable(const char */
*output*/
)
1471 #include "xsldbgdriver.moc"