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 {DCprintStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
87 {DCprintQStringStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
88 {DCframe
, "frame %d\n", XsldbgCmdInfo::argNum
},
89 {DCfindType
, "print 'whatis %s'\n", XsldbgCmdInfo::argString
},
90 {DCinfosharedlib
, "stylesheets\n", XsldbgCmdInfo::argNone
},
91 {DCthread
, "print 'thread %d'\n", XsldbgCmdInfo::argNum
},
92 {DCinfothreads
, "print 'info threads'\n", XsldbgCmdInfo::argNone
},
93 {DCinfobreak
, "show\n", XsldbgCmdInfo::argNone
},
94 {DCcondition
, "print 'condition %d %s'\n", XsldbgCmdInfo::argNumString
},
95 {DCsetpc
, "print 'set variable $pc=%s'\n", XsldbgCmdInfo::argString
},
96 {DCignore
, "print 'ignore %d %d'\n", XsldbgCmdInfo::argNum2
},
99 #define NUM_CMDS (int(sizeof(cmds)/sizeof(cmds[0])))
100 #define MAX_FMTLEN 200
102 XsldbgDriver::XsldbgDriver():
103 DebuggerDriver(), m_gdbMajor(2), m_gdbMinor(0)
105 m_promptRE
.setPattern("\\(xsldbg\\) .*> $");
107 m_promptLastChar
= ' ';
109 m_markerRE
.setPattern("^Breakpoint at file ");
110 m_haveDataFile
= FALSE
;
113 // check command info array
116 for (int i
= 0; i
< NUM_CMDS
; i
++) {
117 // must be indexable by DbgCommand values, i.e. sorted by DbgCommand values
118 assert(i
== cmds
[i
].cmd
);
119 // a format string must be associated
120 assert(cmds
[i
].fmt
!= 0);
121 assert(strlen(cmds
[i
].fmt
) <= MAX_FMTLEN
);
122 // format string must match arg specification
123 switch (cmds
[i
].argsNeeded
) {
124 case XsldbgCmdInfo::argNone
:
125 assert(strchr(cmds
[i
].fmt
, '%') == 0);
127 case XsldbgCmdInfo::argString
:
128 perc
= strchr(cmds
[i
].fmt
, '%');
129 assert(perc
!= 0 && perc
[1] == 's');
130 assert(strchr(perc
+ 2, '%') == 0);
132 case XsldbgCmdInfo::argNum
:
133 perc
= strchr(cmds
[i
].fmt
, '%');
134 assert(perc
!= 0 && perc
[1] == 'd');
135 assert(strchr(perc
+ 2, '%') == 0);
137 case XsldbgCmdInfo::argStringNum
:
138 perc
= strchr(cmds
[i
].fmt
, '%');
139 assert(perc
!= 0 && perc
[1] == 's');
140 perc
= strchr(perc
+ 2, '%');
141 assert(perc
!= 0 && perc
[1] == 'd');
142 assert(strchr(perc
+ 2, '%') == 0);
144 case XsldbgCmdInfo::argNumString
:
145 perc
= strchr(cmds
[i
].fmt
, '%');
146 assert(perc
!= 0 && perc
[1] == 'd');
147 perc
= strchr(perc
+ 2, '%');
148 assert(perc
!= 0 && perc
[1] == 's');
149 assert(strchr(perc
+ 2, '%') == 0);
151 case XsldbgCmdInfo::argString2
:
152 perc
= strchr(cmds
[i
].fmt
, '%');
153 assert(perc
!= 0 && perc
[1] == 's');
154 perc
= strchr(perc
+ 2, '%');
155 assert(perc
!= 0 && perc
[1] == 's');
156 assert(strchr(perc
+ 2, '%') == 0);
158 case XsldbgCmdInfo::argNum2
:
159 perc
= strchr(cmds
[i
].fmt
, '%');
160 assert(perc
!= 0 && perc
[1] == 'd');
161 perc
= strchr(perc
+ 2, '%');
162 assert(perc
!= 0 && perc
[1] == 'd');
163 assert(strchr(perc
+ 2, '%') == 0);
170 XsldbgDriver::~XsldbgDriver()
176 XsldbgDriver::driverName() const
182 XsldbgDriver::defaultXsldbg()
184 return "xsldbg --shell --gdb";
188 XsldbgDriver::defaultInvocation() const
190 return defaultXsldbg();
193 QStringList
XsldbgDriver::boolOptionList() const
195 QStringList allOptions
;
196 allOptions
.append("verbose");
197 allOptions
.append("repeat");
198 allOptions
.append("debug");
199 allOptions
.append("novalid");
200 allOptions
.append("noout");
201 allOptions
.append("html");
202 allOptions
.append("docbook");
203 allOptions
.append("nonet");
204 allOptions
.append("catalogs");
205 allOptions
.append("xinclude");
206 allOptions
.append("profile");
212 XsldbgDriver::slotReceiveOutput(KProcess
* process
, char *buffer
,
216 if (m_state
!= DSidle
) {
218 DebuggerDriver::slotReceiveOutput(process
, buffer
, buflen
);
220 if (strncmp(buffer
, "quit", 4) == 0) {
221 TRACE("Ignoring text when xsldbg is quiting");
224 ("Stray output received by XsldbgDriver::slotReceiveOutput");
231 XsldbgDriver::startup(QString cmdStr
)
233 if (!DebuggerDriver::startup(cmdStr
))
236 static const char xsldbgInitialize
[] = "pwd\n"; /* don't need to do anything else */
238 executeCmdString(DCinitialize
, xsldbgInitialize
, false);
244 XsldbgDriver::commandFinished(CmdQueueItem
* cmd
)
247 TRACE(__PRETTY_FUNCTION__
);
248 // command string must be committed
249 if (!cmd
->m_committed
) {
252 (__PRETTY_FUNCTION__
+
253 (" with uncommited command:\n\t" + cmd
->m_cmdString
)));
257 switch (cmd
->m_cmd
) {
259 // get version number from preamble
262 QRegExp
xsldbgVersion("^XSLDBG [0-9]+\\.[0-9]+\\.[0-9]+");
263 int offset
= xsldbgVersion
.match(m_output
, 0, &len
);
266 char *start
= m_output
+ offset
+ 7; // skip "^XSLDBG "
269 TRACE("Reading version");
271 m_gdbMajor
= strtol(start
, &end
, 10);
272 m_gdbMinor
= strtol(end
+ 1, 0, 10); // skip "."
274 // nothing was parsed
279 // assume some default version (what would make sense?)
283 TRACE(QString("Got version ") +
284 QString::number(m_gdbMajor
) + "." +
285 QString::number(m_gdbMinor
));
290 /* ok, the command is ready */
291 emit
commandReceived(cmd
, m_output
);
293 switch (cmd
->m_cmd
) {
301 if (!::isErrorExpr(m_output
))
304 // This only shows an error for DCinfolocals
305 // need to update KDebugger::handleRunCommand ?
306 KMessageBox::sorry(0L, m_output
);
312 if (!m_xslFile
.isEmpty())
313 emit
activateFileLine(m_xslFile
, 0, DbgAddr());
321 XsldbgDriver::parseMarker()
324 // TRACE("parseMarker : xsldbg");
326 int len
, markerStart
= -1;
329 while (markerStart
== -1) {
330 if ((p
== 0) || (*p
== '\0')) {
334 //TRACE(QString("parseMarker is looking at :") + p);
335 markerStart
= m_markerRE
.match(p
, 0, &len
);
336 if (markerStart
== -1) {
337 // try to marker on next line !
339 if ((p
!= 0) && (*p
!= '\0'))
345 // extract the marker
346 char *startMarker
= p
+ markerStart
+ len
;
348 //TRACE(QString("found marker:") + startMarker);
349 char *endMarker
= strchr(startMarker
, '\n');
356 // extract filename and line number
357 static QRegExp
MarkerRE(" : line [0-9]+");
359 int lineNoStart
= MarkerRE
.match(startMarker
, 0, &len
);
361 if (lineNoStart
>= 0) {
362 int lineNo
= atoi(startMarker
+ lineNoStart
+ 8);
366 // now show the window
367 startMarker
[lineNoStart
] = '\0'; /* split off file name */
368 TRACE("Got file and line number");
369 TRACE(QString(startMarker
) + ": " + QString::number(lineNo
));
370 emit
activateFileLine(startMarker
, lineNo
- 1, address
);
376 * Escapes characters that might lead to problems when they appear on gdb's
380 normalizeStringArg(QString
& arg
)
383 * Remove trailing backslashes. This approach is a little simplistic,
384 * but we know that there is at the moment no case where a trailing
385 * backslash would make sense.
387 while (!arg
.isEmpty() && arg
[arg
.length() - 1] == '\\') {
388 arg
= arg
.left(arg
.length() - 1);
394 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
)
396 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
397 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString
);
399 normalizeStringArg(strArg
);
402 // need the working directory when parsing the output
403 m_programWD
= strArg
;
404 } else if (cmd
== DCexecutable
) {
405 // want to display the XSL file
409 SIZED_QString(cmdString
, MAX_FMTLEN
+ strArg
.length());
410 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1());
415 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg
)
417 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
418 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum
);
420 SIZED_QString(cmdString
, MAX_FMTLEN
+ 30);
422 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
);
427 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
, int intArg
)
429 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
430 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
||
431 cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNumString
||
432 cmd
== DCexamine
|| cmd
== DCtty
);
434 normalizeStringArg(strArg
);
436 SIZED_QString(cmdString
, MAX_FMTLEN
+ 30 + strArg
.length());
440 * intArg specifies which channels should be redirected to
441 * /dev/null. It is a value or'ed together from RDNstdin,
442 * RDNstdout, RDNstderr.
444 static const char *const runRedir
[8] = {
448 " </dev/null >/dev/null",
450 " </dev/null 2>/dev/null",
452 " </dev/null >/dev/null 2>&1"
455 if (strArg
.isEmpty())
456 intArg
= 7; /* failsafe if no tty */
457 m_redirect
= runRedir
[intArg
& 7];
459 return makeCmdString(DCtty
, strArg
); /* note: no problem if strArg empty */
462 if (cmd
== DCexamine
) {
463 // make a format specifier from the intArg
464 static const char size
[16] = {
465 '\0', 'b', 'h', 'w', 'g'
467 static const char format
[16] = {
468 '\0', 'x', 'd', 'u', 'o', 't',
469 'a', 'c', 'f', 's', 'i'
472 assert(MDTsizemask
== 0xf); /* lowest 4 bits */
473 assert(MDTformatmask
== 0xf0); /* next 4 bits */
474 int count
= 16; /* number of entities to print */
475 char sizeSpec
= size
[intArg
& MDTsizemask
];
476 char formatSpec
= format
[(intArg
& MDTformatmask
) >> 4];
478 assert(sizeSpec
!= '\0');
479 assert(formatSpec
!= '\0');
480 // adjust count such that 16 lines are printed
481 switch (intArg
& MDTformatmask
) {
484 break; /* no modification needed */
486 // all cases drop through:
487 switch (intArg
& MDTsizemask
) {
500 spec
.sprintf("/%d%c%c", count
, sizeSpec
, formatSpec
);
502 return makeCmdString(DCexamine
, spec
, strArg
);
505 if (cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
) {
506 // line numbers are zero-based
507 if (cmd
== DCuntil
|| cmd
== DCbreakline
||
508 cmd
== DCtbreakline
|| cmd
== DCinfoline
) {
511 if (cmd
== DCinfoline
) {
512 // must split off file name part
513 int slash
= strArg
.findRev('/');
516 strArg
= strArg
.right(strArg
.length() - slash
- 1);
518 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1(), intArg
);
520 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
, strArg
.latin1());
526 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg1
,
529 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
530 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString2
);
532 normalizeStringArg(strArg1
);
533 normalizeStringArg(strArg2
);
535 SIZED_QString(cmdString
,
536 MAX_FMTLEN
+ strArg1
.length() + strArg2
.length());
537 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg1
.latin1(), strArg2
.latin1());
542 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg1
, int intArg2
)
544 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
545 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum2
);
547 SIZED_QString(cmdString
, MAX_FMTLEN
+ 60);
548 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg1
, intArg2
);
553 XsldbgDriver::executeCmd(DbgCommand cmd
, bool clearLow
)
555 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
556 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNone
);
559 m_haveCoreFile
= false;
562 return executeCmdString(cmd
, cmds
[cmd
].fmt
, clearLow
);
566 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, bool clearLow
)
568 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
), clearLow
);
572 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg
, bool clearLow
)
575 return executeCmdString(cmd
, makeCmdString(cmd
, intArg
), clearLow
);
579 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, int intArg
,
582 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
),
587 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
590 return executeCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
),
595 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg1
, int intArg2
,
598 return executeCmdString(cmd
, makeCmdString(cmd
, intArg1
, intArg2
),
603 XsldbgDriver::queueCmd(DbgCommand cmd
, QueueMode mode
)
605 return queueCmdString(cmd
, cmds
[cmd
].fmt
, mode
);
609 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, QueueMode mode
)
611 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
), mode
);
615 XsldbgDriver::queueCmd(DbgCommand cmd
, int intArg
, QueueMode mode
)
617 return queueCmdString(cmd
, makeCmdString(cmd
, intArg
), mode
);
621 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, int intArg
,
624 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
), mode
);
628 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
631 return queueCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
), mode
);
635 XsldbgDriver::terminate()
637 qDebug("XsldbgDriver::Terminate");
639 executeCmdString(DCinitialize
, "quit\n", true);
645 XsldbgDriver::detachAndTerminate()
647 qDebug("XsldbgDriver::detachAndTerminate");
649 executeCmdString(DCinitialize
, "quit\n", true);
654 XsldbgDriver::interruptInferior()
656 // remove accidentally queued commands
657 qDebug("interruptInferior");
663 isErrorExpr(const char *output
)
667 #define ERROR_WORD_COUNT 5
668 static const char *errorWords
[ERROR_WORD_COUNT
] = {
670 "error:", // libxslt error
673 "warning:" // libxslt warning
675 static int errorWordLength
[ERROR_WORD_COUNT
] = {
678 15, /* Unknown command*/
683 for (wordIndex
= 0; wordIndex
< ERROR_WORD_COUNT
; wordIndex
++){
685 errorWords
[wordIndex
],
686 errorWordLength
[wordIndex
]) == 0){
688 TRACE(QString("Error/Warning from xsldbg ") + output
);
697 * Returns true if the output is an error message. If wantErrorValue is
698 * true, a new VarTree object is created and filled with the error message.
701 parseErrorMessage(const char *output
,
702 VarTree
* &variable
, bool wantErrorValue
)
704 if (isErrorExpr(output
)) {
705 if (wantErrorValue
) {
706 // put the error message as value in the variable
707 variable
= new VarTree(QString(), VarTree::NKplain
);
708 const char *endMsg
= strchr(output
, '\n');
711 endMsg
= output
+ strlen(output
);
712 variable
->m_value
= FROM_LATIN1(output
, endMsg
- output
);
723 XsldbgDriver::parseQCharArray(const char */
*output*/
, bool /*wantErrorValue*/,
726 VarTree
*variable
= 0;
728 TRACE("XsldbgDriver::parseQCharArray not implmented");
733 parseVar(const char *&s
)
736 bool foundLocalVar
= false;
737 VarTree
*variable
= 0L;
740 VarTree::NameKind kind
;
742 TRACE(__PRETTY_FUNCTION__
);
745 if (parseErrorMessage(p
, variable
, false) == true) {
746 TRACE("Found error message");
750 if (strncmp(p
, " Local", 6) == 0) {
751 foundLocalVar
= true;
754 TRACE("Found local variable");
755 } else if (strncmp(p
, " Global", 7) == 0) {
758 TRACE("Found global variable");
759 } else if (strncmp(p
, "= ", 2) == 0) {
760 /* we're processing the result of a "print command" */
762 char *nextLine
= strchr(p
, '\n');
764 TRACE("Found print expr");
766 char nameBuffer
[100];
768 p
= p
+ 2; /* skip the "= " */
769 strncpy(nameBuffer
, p
, nextLine
- p
);
771 variable
= new VarTree(nameBuffer
, kind
);
772 if (variable
!= 0L) {
773 variable
->setDeleteChildren(true);
774 parseValue(p
, variable
);
779 return variable
; /* don't know what to do this this data abort!! */
786 // No value provided just a name
787 TRACE(QString("Parse var: name") + p
);
788 if (!parseName(p
, name
, kind
)) {
791 variable
= new VarTree(name
, kind
);
792 if (variable
!= 0L) {
793 variable
->setDeleteChildren(true);
800 TRACE(QString("Parse var: name") + p
);
801 if (!parseName(p
, name
, kind
)) {
804 variable
= new VarTree(name
, kind
);
805 if (variable
!= 0L) {
806 variable
->setDeleteChildren(true);
810 if (!parseValue(p
, variable
)) {
825 skipName(const char *&p
)
827 // allow : (for enumeration values) and $ and . (for _vtbl.)
828 while (isalnum(*p
) || *p
== '_' || *p
== ':' || *p
== '$' || *p
== '.')
833 parseName(const char *&s
, QString
& name
, VarTree::NameKind
& kind
)
835 /* qDebug(__PRETTY_FUNCTION__); */
836 kind
= VarTree::NKplain
;
841 // examples of names:
844 while ((*p
!= '\n') && (*p
!= '\0')) {
850 name
= FROM_LATIN1(s
, len
);
851 /* XSL variables will have a $ prefix to be evaluated
853 //TRACE(QString("parseName got name" ) + name);
855 // return the new position
861 parseValue(const char *&s
, VarTree
* variable
)
863 const char *start
= s
, *end
= s
;
864 VarTree
* childValue
;
865 #define VALUE_END_MARKER_INDEX 0
867 /* This mark the end of a value */
868 static const char *marker
[] = {
869 "\032\032", /* value end marker*/
871 "Breakpoint at", /* stepped to next location */
872 "Breakpoint in", /* reached a set breakpoint */
873 "Reached ", /* reached template */
880 static char valueBuffer
[255];
881 int markerIndex
= 0, foundEnd
= 0;
885 return false; /* should never happen but .. */
887 variable
->m_value
= "";
888 while (start
&& (*start
!= '\0')) {
889 /* look for the next marker */
890 for (markerIndex
= 0; marker
[markerIndex
] != 0; markerIndex
++) {
892 strncmp(start
, marker
[markerIndex
],
893 strlen(marker
[markerIndex
])) == 0;
902 end
= strchr(start
, '\n');
906 copySize
= end
- start
- 1;
907 if (copySize
> sizeof(valueBuffer
))
908 copySize
= sizeof(valueBuffer
);
910 strncpy(valueBuffer
, start
, copySize
);
911 valueBuffer
[copySize
] = '\0';
912 TRACE("Got value :");
914 childValue
= new VarTree(valueBuffer
, VarTree::NKplain
);
915 variable
->appendChild(childValue
);
919 childValue
= new VarTree(start
, VarTree::NKplain
);
920 variable
->appendChild(childValue
);
926 TRACE(QString("Unable to find end on value near :") + start
);
928 // If we've got something otherthan a end of value marker then
929 // advance to the end of this buffer
930 if (markerIndex
!= VALUE_END_MARKER_INDEX
){
931 while (start
&& *start
!= '\0')
934 start
= start
+ strlen(marker
[0]);
944 * Parses a stack frame.
947 parseFrameInfo(const char *&s
, QString
& func
,
948 QString
& file
, int &lineNo
, DbgAddr
& /*address*/)
950 const char *p
= s
, *endPos
= s
+ strlen(s
);
951 QString lineNoString
;
955 /* skip 'template :\" */
957 //TRACE("parseFrameInfo");
960 while ((*p
!= '\"') && (*p
!= '\0')) {
970 /* skip mode :".*" */
971 while (p
&& *p
!= '"')
975 while (p
&& *p
!= '"')
979 while (p
&& *p
!= '"')
981 /* skip '" in file ' */
985 while (!isspace(*p
) && (*p
!= '\0')) {
995 /* skip ' : line '" */
1004 /* KDbg uses an offset of +1 for its line numbers */
1005 lineNo
= atoi(p
) - 1;
1006 lineNoString
= QString::number(lineNo
);
1008 /* convert func into format needed */
1009 func
.append(" at ");
1012 func
.append(lineNoString
);
1014 //TRACE(QString("Got frame : template :\"") + func + "\"file:" +
1015 // file + " line : " + lineNoString);
1017 /*advance to next line */
1018 p
= strchr(p
, '\n');
1028 * Parses a stack frame including its frame number
1031 parseFrame(const char *&s
, int &frameNo
, QString
& func
,
1032 QString
& file
, int &lineNo
, DbgAddr
& address
)
1035 // TRACE("XsldbgDriver ::parseFrame");
1036 /* skip leading 'where' or 'frame <frame_no>' */
1037 if ((strncmp(s
, "where", 5) == 0) || (strncmp(s
, "frame", 5) == 0)) {
1038 s
= strchr(s
, '\n');
1039 if ((*s
!= '\0') && (*s
!= '#'))
1045 //#1 template :"/" in file /home/keith/anon_CVS/xsldbg/docs/en/xsldoc.xsl : line 21
1046 // must start with a hash mark followed by number
1047 if (s
[0] != '#' || !isdigit(s
[1]))
1050 //TRACE("XsldbgDriver ::parseFrame got #");
1051 s
++; /* skip the hash mark */
1057 //TRACE(QString("Got frame ").append(QString::number(frameNo)));
1061 parseFrameInfo(s
, func
, file
, lineNo
, address
);
1062 // TRACE("Will next look at ");
1068 XsldbgDriver::parseBackTrace(const char *output
,
1069 QList
< StackFrame
> &stack
)
1072 int lineNo
, frameNo
;
1075 while (::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
)) {
1076 StackFrame
*frm
= new StackFrame
;
1078 frm
->frameNo
= frameNo
;
1079 frm
->fileName
= file
;
1080 frm
->lineNo
= lineNo
;
1081 frm
->address
= address
;
1082 frm
->var
= new VarTree(func
, VarTree::NKplain
);
1088 XsldbgDriver::parseFrameChange(const char *output
, int &frameNo
,
1089 QString
& file
, int &lineNo
,
1094 return::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
);
1099 XsldbgDriver::parseBreakList(const char *output
,
1100 QList
< Breakpoint
> &brks
)
1102 TRACE("parseBreakList");
1103 /* skip the first blank line */
1107 QString location
, file
, lineNo
;
1109 QString templateName
;
1112 uint ignoreCount
= 0;
1115 p
= strchr(output
, '\n');/* skip the first blank line*/
1117 while ((p
!= 0) && (*p
!= '\0')) {
1118 templateName
= QString();
1120 Breakpoint::Type bpType
= Breakpoint::breakpoint
;
1121 //qDebug("Looking at :%s", p);
1122 if (strncmp(p
, " Breakpoint", 11) != 0)
1130 long bpNum
= strtol(p
, &dummy
, 10); /* don't care about overflows */
1133 if ((p
== 0) || (p
[1] == '\0'))
1138 // Get breakpoint state ie enabled/disabled
1139 if (strncmp(p
, "enabled", 7) == 0) {
1143 if (strncmp(p
, "disabled", 8) == 0) {
1147 TRACE("Parse error in breakpoint list");
1153 //TRACE("Looking for template");
1156 /* check for ' for template :"'*/
1157 if (strncmp(p
, " for template :\"", 16) == 0){
1159 //TRACE("Looking for template name near");
1161 /* get the template name */
1162 while (p
&& (*p
!= '\0') && (*p
!= '\"')){
1163 templateName
.append(*p
);
1169 TRACE("Error missed \" near");
1174 //TRACE("Looking for mode near");
1176 if (strncmp(p
, " mode :\"", 8) == 0) {
1178 while (p
&& *p
!= '\"')
1184 if (strncmp(p
, " in file ", 9) != 0){
1185 TRACE("Parse error in breakpoint list");
1191 /* skip ' in file ' */
1195 /* grab file name */
1196 while (!isspace(*p
)) {
1203 /* skip ' : line ' */
1206 while (isdigit(*p
)) {
1212 //TRACE("Got breakpoint");
1214 Breakpoint
*bp
= new Breakpoint
;
1217 // take 1 of line number
1218 lineNo
.setNum(lineNo
.toInt() - 1);
1221 bp
->temporary
= false;
1222 bp
->enabled
= enabled
;
1223 location
.append("in ").append(templateName
).append(" at ");
1224 location
.append(file
).append(":").append(lineNo
);
1225 bp
->location
= location
;
1226 bp
->fileName
= file
;
1227 bp
->lineNo
= lineNo
.toInt();
1228 bp
->address
= address
;
1229 bp
->hitCount
= hits
;
1230 bp
->ignoreCount
= ignoreCount
;
1231 bp
->condition
= condition
;
1237 TRACE("Outof memory, breakpoint not created");
1240 p
= strchr(p
, '\n');
1247 XsldbgDriver::parseThreadList(const char */
*output*/
,
1248 QList
< ThreadInfo
> &/*threads*/)
1254 XsldbgDriver::parseBreakpoint(const char *output
, int &id
,
1255 QString
&file
, int &lineNo
, QString
&address
)
1258 if ( strncmp(output
, "Error:", 6) == 0) {
1263 if (strncmp(output
, "Breakpoint ", 11) != 0)
1267 if (!isdigit(*output
))
1271 id
= strtol(output
, &dummy
, 10); /* don't care about overflows */
1272 if (output
== dummy
)
1275 // the file name + lineNo will be filled in later from the breakpoint list
1276 file
= address
= QString();
1282 XsldbgDriver::parseLocals(const char *output
, QList
< VarTree
> &newVars
)
1285 /* keep going until error or xsldbg prompt is found */
1286 while (*output
!= '\0') {
1287 VarTree
*variable
= parseVar(output
);
1289 if (variable
== 0) {
1292 // do not add duplicates
1293 for (VarTree
* o
= newVars
.first(); o
!= 0; o
= newVars
.next()) {
1294 if (o
->getText() == variable
->getText()) {
1300 newVars
.append(variable
);
1307 XsldbgDriver::parsePrintExpr(const char *output
, bool wantErrorValue
,
1310 // check for error conditions
1311 if (parseErrorMessage(output
, var
, wantErrorValue
)) {
1314 // parse the variable
1315 var
= parseVar(output
);
1321 XsldbgDriver::parseChangeWD(const char *output
, QString
& message
)
1323 bool isGood
= false;
1325 if (strncmp(output
, "Change to directory", 20) == 0) {
1326 output
= output
+ 20; /* skip 'Change to directory' */
1327 message
= QString(output
).simplifyWhiteSpace();
1328 if (message
.isEmpty()) {
1329 message
= i18n("New working directory: ") + m_programWD
;
1337 XsldbgDriver::parseChangeExecutable(const char *output
, QString
& message
)
1340 TRACE(QString("XsldbgDriver::parseChangeExecutable :") + output
);
1341 m_haveCoreFile
= false;
1344 * The command is successful if there is no output or the single
1345 * message (no debugging symbols found)...
1347 QRegExp
exp(".*Load of source deferred use run command.*");
1348 int len
, index
= exp
.match(output
, 0, &len
);
1351 TRACE("Parsed stylesheet executable");
1354 return (output
[0] == '\0') || (index
!= -1);
1358 XsldbgDriver::parseCoreFile(const char *output
)
1360 TRACE("XsldbgDriver::parseCoreFile");
1362 QRegExp
exp(".*Load of xml data deferred use run command.*");
1363 int len
, index
= exp
.match(output
, 0, &len
);
1366 m_haveCoreFile
= true;
1367 TRACE("Parsed xml data file");
1370 return m_haveCoreFile
;
1374 XsldbgDriver::parseProgramStopped(const char *output
, QString
& message
)
1376 /* Not sure about this function leave it here for the moment */
1378 * return DebuggerDriver::SFrefreshBreak & DebuggerDriver::SFprogramActive;
1381 // go through the output, line by line, checking what we have
1382 const char *start
= output
- 1;
1383 uint flags
= SFprogramActive
;
1385 message
= QString();
1387 start
++; /* skip '\n' */
1389 if (strncmp(start
, "Finished stylesheet\n\032\032\n", 21) == 0){
1390 flags
&= ~SFprogramActive
;
1394 // next line, please
1395 start
= strchr(start
, '\n');
1396 } while (start
!= 0);
1402 XsldbgDriver::parseSharedLibs(const char */
*output*/
, QStrList
& /*shlibs*/)
1408 XsldbgDriver::parseFindType(const char */
*output*/
, QString
& /*type*/)
1414 XsldbgDriver::parseRegisters(const char */
*output*/
,
1415 QList
< RegisterInfo
> &/*regs*/)
1421 XsldbgDriver::parseInfoLine(const char */
*output*/
, QString
& /*addrFrom*/,
1422 QString
& /*addrTo*/)
1428 XsldbgDriver::parseDisassemble(const char */
*output*/
,
1429 QList
< DisassembledCode
> &/*code*/)
1435 XsldbgDriver::parseMemoryDump(const char */
*output*/
,
1436 QList
< MemoryDump
> &/*memdump*/)
1438 return i18n("No memory dump available");
1442 #include "xsldbgdriver.moc"