2 * Copyright Johannes Sixt, Keith Isdale
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
7 #include "xsldbgdriver.h"
9 #include <qstringlist.h>
10 #include <klocale.h> /* i18n */
12 #include <stdlib.h> /* strtol, atoi */
13 #include <string.h> /* strcpy */
14 #include <kmessagebox.h>
23 static ExprValue
*parseVar(const char *&s
);
24 static bool parseName(const char *&s
, QString
& name
,
25 VarTree::NameKind
& kind
);
26 static bool parseValue(const char *&s
, ExprValue
* variable
);
27 static bool isErrorExpr(const char *output
);
29 #define TERM_IO_ALLOWED 1
31 // TODO: make this cmd info stuff non-static to allow multiple
32 // simultaneous gdbs to run!
34 struct XsldbgCmdInfo
{
36 const char *fmt
; /* format string */
38 argNone
, argString
, argNum
,
39 argStringNum
, argNumString
,
45 * The following array of commands must be sorted by the DC* values,
46 * because they are used as indices.
48 static XsldbgCmdInfo cmds
[] = {
49 {DCinitialize
, "init\n", XsldbgCmdInfo::argNone
},
50 {DCtty
, "tty %s\n", XsldbgCmdInfo::argString
},
51 {DCexecutable
, "source %s\n", XsldbgCmdInfo::argString
}, /* force a restart */
52 {DCtargetremote
, "print 'target remote %s'\n", XsldbgCmdInfo::argString
},
53 {DCcorefile
, "data %s\n", XsldbgCmdInfo::argString
}, /* force a restart */
54 {DCattach
, "print 'attach %s'\n", XsldbgCmdInfo::argString
},
55 {DCinfolinemain
, "print 'info main line'\n", XsldbgCmdInfo::argNone
},
56 {DCinfolocals
, "locals -f\n", XsldbgCmdInfo::argNone
},
57 {DCinforegisters
, "print 'info reg'\n", XsldbgCmdInfo::argNone
},
58 {DCexamine
, "print 'x %s %s'\n", XsldbgCmdInfo::argString2
},
59 {DCinfoline
, "print 'templates %s:%d'\n", XsldbgCmdInfo::argStringNum
},
60 {DCdisassemble
, "print 'disassemble %s %s'\n", XsldbgCmdInfo::argString2
},
61 {DCsetargs
, "data %s\n", XsldbgCmdInfo::argString
},
62 {DCsetenv
, "addparam %s %s\n", XsldbgCmdInfo::argString2
},
63 {DCunsetenv
, "unset env %s\n", XsldbgCmdInfo::argString
},
64 {DCsetoption
, "setoption %s %d\n", XsldbgCmdInfo::argStringNum
},
65 {DCcd
, "chdir %s\n", XsldbgCmdInfo::argString
},
66 {DCbt
, "where\n", XsldbgCmdInfo::argNone
},
67 {DCrun
, "run\nsource\n", XsldbgCmdInfo::argNone
}, /* Ensure that at the start
68 of executing XSLT we show the XSLT file */
69 {DCcont
, "continue\n", XsldbgCmdInfo::argNone
},
70 {DCstep
, "step\n", XsldbgCmdInfo::argNone
},
71 {DCstepi
, "step\n", XsldbgCmdInfo::argNone
},
72 {DCnext
, "next\n", XsldbgCmdInfo::argNone
},
73 {DCnexti
, "next\n", XsldbgCmdInfo::argNone
},
74 {DCfinish
, "stepup\n", XsldbgCmdInfo::argNone
},
75 {DCuntil
, "continue %s:%d\n", XsldbgCmdInfo::argStringNum
},
76 {DCkill
, "quit\n", XsldbgCmdInfo::argNone
},
77 {DCbreaktext
, "break %s\n", XsldbgCmdInfo::argString
},
78 {DCbreakline
, "break -l %s %d\n", XsldbgCmdInfo::argStringNum
},
79 {DCtbreakline
, "break -l %s %d\n", XsldbgCmdInfo::argStringNum
},
80 {DCbreakaddr
, "print `break *%s`\n", XsldbgCmdInfo::argString
},
81 {DCtbreakaddr
, "print `tbreak *%s`\n", XsldbgCmdInfo::argString
},
82 {DCwatchpoint
, "print 'watch %s'\n", XsldbgCmdInfo::argString
},
83 {DCdelete
, "delete %d\n", XsldbgCmdInfo::argNum
},
84 {DCenable
, "enable %d\n", XsldbgCmdInfo::argNum
},
85 {DCdisable
, "disable %d\n", XsldbgCmdInfo::argNum
},
86 {DCprint
, "print %s\n", XsldbgCmdInfo::argString
},
87 {DCprintDeref
, "print 'print (*%s)'\n", XsldbgCmdInfo::argString
},
88 {DCprintStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
89 {DCprintQStringStruct
, "print 'print %s'\n", XsldbgCmdInfo::argString
},
90 {DCframe
, "frame %d\n", XsldbgCmdInfo::argNum
},
91 {DCfindType
, "print 'whatis %s'\n", XsldbgCmdInfo::argString
},
92 {DCinfosharedlib
, "stylesheets\n", XsldbgCmdInfo::argNone
},
93 {DCthread
, "print 'thread %d'\n", XsldbgCmdInfo::argNum
},
94 {DCinfothreads
, "print 'info threads'\n", XsldbgCmdInfo::argNone
},
95 {DCinfobreak
, "show\n", XsldbgCmdInfo::argNone
},
96 {DCcondition
, "print 'condition %d %s'\n", XsldbgCmdInfo::argNumString
},
97 {DCsetpc
, "print 'set variable $pc=%s'\n", XsldbgCmdInfo::argString
},
98 {DCignore
, "print 'ignore %d %d'\n", XsldbgCmdInfo::argNum2
},
99 {DCprintWChar
, "print 'ignore %s'\n", XsldbgCmdInfo::argString
},
100 {DCsetvariable
, "set %s %s\n", XsldbgCmdInfo::argString2
},
103 #define NUM_CMDS (int(sizeof(cmds)/sizeof(cmds[0])))
104 #define MAX_FMTLEN 200
106 XsldbgDriver::XsldbgDriver():
107 DebuggerDriver(), m_gdbMajor(2), m_gdbMinor(0)
109 m_promptRE
.setPattern("\\(xsldbg\\) .*> ");
111 m_promptLastChar
= ' ';
113 m_markerRE
.setPattern("^Breakpoint for file ");
114 m_haveDataFile
= FALSE
;
117 // check command info array
120 for (int i
= 0; i
< NUM_CMDS
; i
++) {
121 // must be indexable by DbgCommand values, i.e. sorted by DbgCommand values
122 assert(i
== cmds
[i
].cmd
);
123 // a format string must be associated
124 assert(cmds
[i
].fmt
!= 0);
125 assert(strlen(cmds
[i
].fmt
) <= MAX_FMTLEN
);
126 // format string must match arg specification
127 switch (cmds
[i
].argsNeeded
) {
128 case XsldbgCmdInfo::argNone
:
129 assert(strchr(cmds
[i
].fmt
, '%') == 0);
131 case XsldbgCmdInfo::argString
:
132 perc
= strchr(cmds
[i
].fmt
, '%');
133 assert(perc
!= 0 && perc
[1] == 's');
134 assert(strchr(perc
+ 2, '%') == 0);
136 case XsldbgCmdInfo::argNum
:
137 perc
= strchr(cmds
[i
].fmt
, '%');
138 assert(perc
!= 0 && perc
[1] == 'd');
139 assert(strchr(perc
+ 2, '%') == 0);
141 case XsldbgCmdInfo::argStringNum
:
142 perc
= strchr(cmds
[i
].fmt
, '%');
143 assert(perc
!= 0 && perc
[1] == 's');
144 perc
= strchr(perc
+ 2, '%');
145 assert(perc
!= 0 && perc
[1] == 'd');
146 assert(strchr(perc
+ 2, '%') == 0);
148 case XsldbgCmdInfo::argNumString
:
149 perc
= strchr(cmds
[i
].fmt
, '%');
150 assert(perc
!= 0 && perc
[1] == 'd');
151 perc
= strchr(perc
+ 2, '%');
152 assert(perc
!= 0 && perc
[1] == 's');
153 assert(strchr(perc
+ 2, '%') == 0);
155 case XsldbgCmdInfo::argString2
:
156 perc
= strchr(cmds
[i
].fmt
, '%');
157 assert(perc
!= 0 && perc
[1] == 's');
158 perc
= strchr(perc
+ 2, '%');
159 assert(perc
!= 0 && perc
[1] == 's');
160 assert(strchr(perc
+ 2, '%') == 0);
162 case XsldbgCmdInfo::argNum2
:
163 perc
= strchr(cmds
[i
].fmt
, '%');
164 assert(perc
!= 0 && perc
[1] == 'd');
165 perc
= strchr(perc
+ 2, '%');
166 assert(perc
!= 0 && perc
[1] == 'd');
167 assert(strchr(perc
+ 2, '%') == 0);
174 XsldbgDriver::~XsldbgDriver()
180 XsldbgDriver::driverName() const
186 XsldbgDriver::defaultXsldbg()
188 return "xsldbg --lang en --shell --gdb";
192 XsldbgDriver::defaultInvocation() const
194 return defaultXsldbg();
197 QStringList
XsldbgDriver::boolOptionList() const
199 QStringList allOptions
;
200 allOptions
.append("verbose");
201 allOptions
.append("repeat");
202 allOptions
.append("debug");
203 allOptions
.append("novalid");
204 allOptions
.append("noout");
205 allOptions
.append("html");
206 allOptions
.append("docbook");
207 allOptions
.append("nonet");
208 allOptions
.append("catalogs");
209 allOptions
.append("xinclude");
210 allOptions
.append("profile");
216 XsldbgDriver::slotReceiveOutput(KProcess
* process
, char *buffer
,
220 if (m_state
!= DSidle
) {
222 DebuggerDriver::slotReceiveOutput(process
, buffer
, buflen
);
224 if (strncmp(buffer
, "quit", 4) == 0) {
225 TRACE("Ignoring text when xsldbg is quiting");
228 ("Stray output received by XsldbgDriver::slotReceiveOutput");
235 XsldbgDriver::startup(QString cmdStr
)
237 if (!DebuggerDriver::startup(cmdStr
))
240 static const char xsldbgInitialize
[] = "pwd\nsetoption gdb 2\n"; /* don't need to do anything else */
242 executeCmdString(DCinitialize
, xsldbgInitialize
, false);
248 XsldbgDriver::commandFinished(CmdQueueItem
* cmd
)
251 TRACE(__PRETTY_FUNCTION__
);
252 // command string must be committed
253 if (!cmd
->m_committed
) {
256 (__PRETTY_FUNCTION__
+
257 (" with uncommited command:\n\t" + cmd
->m_cmdString
)));
261 switch (cmd
->m_cmd
) {
263 // get version number from preamble
266 QRegExp
xsldbgVersion("^XSLDBG [0-9]+\\.[0-9]+\\.[0-9]+");
267 int offset
= xsldbgVersion
.match(m_output
, 0, &len
);
270 char *start
= m_output
+ offset
+ 7; // skip "^XSLDBG "
273 TRACE("Reading version");
275 m_gdbMajor
= strtol(start
, &end
, 10);
276 m_gdbMinor
= strtol(end
+ 1, 0, 10); // skip "."
278 // nothing was parsed
283 // assume some default version (what would make sense?)
287 TRACE(QString("Got version ") +
288 QString::number(m_gdbMajor
) + "." +
289 QString::number(m_gdbMinor
));
294 /* ok, the command is ready */
295 emit
commandReceived(cmd
, m_output
);
297 switch (cmd
->m_cmd
) {
305 if (!::isErrorExpr(m_output
))
308 // This only shows an error for DCinfolocals
309 // need to update KDebugger::handleRunCommand ?
310 KMessageBox::sorry(0L, m_output
);
316 if (!m_xslFile
.isEmpty())
317 emit
activateFileLine(m_xslFile
, 0, DbgAddr());
325 XsldbgDriver::parseMarker()
328 // TRACE("parseMarker : xsldbg");
330 int len
, markerStart
= -1;
333 while (markerStart
== -1) {
334 if ((p
== 0) || (*p
== '\0')) {
338 //TRACE(QString("parseMarker is looking at :") + p);
339 markerStart
= m_markerRE
.match(p
, 0, &len
);
340 if (markerStart
== -1) {
341 // try to marker on next line !
343 if ((p
!= 0) && (*p
!= '\0'))
349 // extract the marker
350 char *startMarker
= p
+ markerStart
+ len
;
352 //TRACE(QString("found marker:") + startMarker);
353 char *endMarker
= strchr(startMarker
, '\n');
360 // extract filename and line number
361 static QRegExp
MarkerRE(" at line [0-9]+");
363 int lineNoStart
= MarkerRE
.match(startMarker
, 0, &len
);
365 if (lineNoStart
>= 0) {
366 int lineNo
= atoi(startMarker
+ lineNoStart
+ 8);
370 // now show the window
371 startMarker
[lineNoStart
-1] = '\0'; /* split off file name */
372 TRACE("Got file and line number");
374 TRACE(QString(startMarker
) + ": " + QString::number(lineNo
));
375 emit
activateFileLine(startMarker
, lineNo
- 1, address
);
381 * Escapes characters that might lead to problems when they appear on gdb's
385 normalizeStringArg(QString
& arg
)
388 * Remove trailing backslashes. This approach is a little simplistic,
389 * but we know that there is at the moment no case where a trailing
390 * backslash would make sense.
392 while (!arg
.isEmpty() && arg
[arg
.length() - 1] == '\\') {
393 arg
= arg
.left(arg
.length() - 1);
399 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
)
401 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
402 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString
);
404 normalizeStringArg(strArg
);
407 // need the working directory when parsing the output
408 m_programWD
= strArg
;
409 } else if (cmd
== DCexecutable
) {
410 // want to display the XSL file
415 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1());
420 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg
)
422 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
423 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum
);
426 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
);
431 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg
, int intArg
)
433 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
434 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
||
435 cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNumString
||
436 cmd
== DCexamine
|| cmd
== DCtty
);
438 normalizeStringArg(strArg
);
444 * intArg specifies which channels should be redirected to
445 * /dev/null. It is a value or'ed together from RDNstdin,
446 * RDNstdout, RDNstderr.
448 static const char *const runRedir
[8] = {
452 " </dev/null >/dev/null",
454 " </dev/null 2>/dev/null",
456 " </dev/null >/dev/null 2>&1"
459 if (strArg
.isEmpty())
460 intArg
= 7; /* failsafe if no tty */
461 m_redirect
= runRedir
[intArg
& 7];
463 return makeCmdString(DCtty
, strArg
); /* note: no problem if strArg empty */
466 if (cmd
== DCexamine
) {
467 // make a format specifier from the intArg
468 static const char size
[16] = {
469 '\0', 'b', 'h', 'w', 'g'
471 static const char format
[16] = {
472 '\0', 'x', 'd', 'u', 'o', 't',
473 'a', 'c', 'f', 's', 'i'
476 assert(MDTsizemask
== 0xf); /* lowest 4 bits */
477 assert(MDTformatmask
== 0xf0); /* next 4 bits */
478 int count
= 16; /* number of entities to print */
479 char sizeSpec
= size
[intArg
& MDTsizemask
];
480 char formatSpec
= format
[(intArg
& MDTformatmask
) >> 4];
482 assert(sizeSpec
!= '\0');
483 assert(formatSpec
!= '\0');
484 // adjust count such that 16 lines are printed
485 switch (intArg
& MDTformatmask
) {
488 break; /* no modification needed */
490 // all cases drop through:
491 switch (intArg
& MDTsizemask
) {
504 spec
.sprintf("/%d%c%c", count
, sizeSpec
, formatSpec
);
506 return makeCmdString(DCexamine
, spec
, strArg
);
509 if (cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argStringNum
) {
510 // line numbers are zero-based
511 if (cmd
== DCuntil
|| cmd
== DCbreakline
||
512 cmd
== DCtbreakline
|| cmd
== DCinfoline
) {
515 if (cmd
== DCinfoline
) {
516 // must split off file name part
517 int slash
= strArg
.findRev('/');
520 strArg
= strArg
.right(strArg
.length() - slash
- 1);
522 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg
.latin1(), intArg
);
524 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg
, strArg
.latin1());
530 XsldbgDriver::makeCmdString(DbgCommand cmd
, QString strArg1
,
533 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
534 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argString2
);
536 normalizeStringArg(strArg1
);
537 normalizeStringArg(strArg2
);
540 cmdString
.sprintf(cmds
[cmd
].fmt
, strArg1
.latin1(), strArg2
.latin1());
545 XsldbgDriver::makeCmdString(DbgCommand cmd
, int intArg1
, int intArg2
)
547 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
548 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNum2
);
551 cmdString
.sprintf(cmds
[cmd
].fmt
, intArg1
, intArg2
);
556 XsldbgDriver::executeCmd(DbgCommand cmd
, bool clearLow
)
558 assert(cmd
>= 0 && cmd
< NUM_CMDS
);
559 assert(cmds
[cmd
].argsNeeded
== XsldbgCmdInfo::argNone
);
562 m_haveCoreFile
= false;
565 return executeCmdString(cmd
, cmds
[cmd
].fmt
, clearLow
);
569 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, bool clearLow
)
571 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
), clearLow
);
575 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg
, bool clearLow
)
578 return executeCmdString(cmd
, makeCmdString(cmd
, intArg
), clearLow
);
582 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg
, int intArg
,
585 return executeCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
),
590 XsldbgDriver::executeCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
593 return executeCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
),
598 XsldbgDriver::executeCmd(DbgCommand cmd
, int intArg1
, int intArg2
,
601 return executeCmdString(cmd
, makeCmdString(cmd
, intArg1
, intArg2
),
606 XsldbgDriver::queueCmd(DbgCommand cmd
, QueueMode mode
)
608 return queueCmdString(cmd
, cmds
[cmd
].fmt
, mode
);
612 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, QueueMode mode
)
614 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
), mode
);
618 XsldbgDriver::queueCmd(DbgCommand cmd
, int intArg
, QueueMode mode
)
620 return queueCmdString(cmd
, makeCmdString(cmd
, intArg
), mode
);
624 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg
, int intArg
,
627 return queueCmdString(cmd
, makeCmdString(cmd
, strArg
, intArg
), mode
);
631 XsldbgDriver::queueCmd(DbgCommand cmd
, QString strArg1
, QString strArg2
,
634 return queueCmdString(cmd
, makeCmdString(cmd
, strArg1
, strArg2
), mode
);
638 XsldbgDriver::terminate()
640 qDebug("XsldbgDriver::Terminate");
642 executeCmdString(DCinitialize
, "quit\n", true);
648 XsldbgDriver::detachAndTerminate()
650 qDebug("XsldbgDriver::detachAndTerminate");
652 executeCmdString(DCinitialize
, "quit\n", true);
657 XsldbgDriver::interruptInferior()
659 // remove accidentally queued commands
660 qDebug("interruptInferior");
666 isErrorExpr(const char *output
)
670 #define ERROR_WORD_COUNT 6
671 static const char *errorWords
[ERROR_WORD_COUNT
] = {
673 "error:", // libxslt error
676 "warning:", // libxslt warning
677 "Information:" // xsldbg information
679 static int errorWordLength
[ERROR_WORD_COUNT
] = {
682 15, /* Unknown command*/
688 for (wordIndex
= 0; wordIndex
< ERROR_WORD_COUNT
; wordIndex
++){
689 // ignore any warnings relating to local variables not being available
691 errorWords
[wordIndex
],
692 errorWordLength
[wordIndex
]) == 0 &&
693 (wordIndex
== 0 && strstr(output
, "try stepping past the xsl:param") == 0) ) {
695 TRACE(QString("Error/Warning/Information from xsldbg ") + output
);
704 * Returns true if the output is an error message. If wantErrorValue is
705 * true, a new ExprValue object is created and filled with the error message.
708 parseErrorMessage(const char *output
,
709 ExprValue
* &variable
, bool wantErrorValue
)
711 if (isErrorExpr(output
)) {
712 if (wantErrorValue
) {
713 // put the error message as value in the variable
714 variable
= new ExprValue(QString(), VarTree::NKplain
);
715 const char *endMsg
= strchr(output
, '\n');
718 endMsg
= output
+ strlen(output
);
719 variable
->m_value
= QString::fromLatin1(output
, endMsg
- output
);
730 XsldbgDriver::setPrintQStringDataCmd(const char* /*cmd*/)
735 XsldbgDriver::parseQCharArray(const char */
*output*/
, bool /*wantErrorValue*/,
738 ExprValue
*variable
= 0;
740 TRACE("XsldbgDriver::parseQCharArray not implmented");
745 parseVar(const char *&s
)
748 bool foundLocalVar
= false;
749 ExprValue
*variable
= 0L;
752 VarTree::NameKind kind
;
754 TRACE(__PRETTY_FUNCTION__
);
757 if (parseErrorMessage(p
, variable
, false) == true) {
758 TRACE("Found error message");
762 if (strncmp(p
, " Local", 6) == 0) {
763 foundLocalVar
= true;
766 TRACE("Found local variable");
767 } else if (strncmp(p
, " Global", 7) == 0) {
770 TRACE("Found global variable");
771 } else if (strncmp(p
, "= ", 2) == 0) {
772 /* we're processing the result of a "print command" */
774 char *nextLine
= strchr(p
, '\n');
776 TRACE("Found print expr");
778 p
= p
+ 2; /* skip the "= " */
779 name
= QString::fromLatin1(p
, nextLine
- p
);
780 kind
= VarTree::NKplain
;
782 variable
= new ExprValue(name
, kind
);
783 variable
->m_varKind
= VarTree::VKsimple
;
784 parseValue(p
, variable
);
788 return variable
; /* don't know what to do this this data abort!! */
795 // No value provided just a name
796 TRACE(QString("Parse var: name") + p
);
797 if (!parseName(p
, name
, kind
)) {
800 variable
= new ExprValue(name
, kind
);
801 if (variable
!= 0L) {
802 variable
->m_varKind
= VarTree::VKsimple
;
809 TRACE(QString("Parse var: name") + p
);
810 if (!parseName(p
, name
, kind
)) {
813 variable
= new ExprValue(name
, kind
);
814 if (variable
!= 0L) {
815 variable
->m_varKind
= VarTree::VKsimple
;
819 if (!parseValue(p
, variable
)) {
834 skipName(const char *&p
)
836 // allow : (for enumeration values) and $ and . (for _vtbl.)
837 while (isalnum(*p
) || *p
== '_' || *p
== ':' || *p
== '$' || *p
== '.')
842 parseName(const char *&s
, QString
& name
, VarTree::NameKind
& kind
)
844 /* qDebug(__PRETTY_FUNCTION__); */
845 kind
= VarTree::NKplain
;
850 // examples of names:
853 while ((*p
!= '\n') && (*p
!= '\0')) {
859 name
= QString::fromLatin1(s
, len
);
860 /* XSL variables will have a $ prefix to be evaluated
862 //TRACE(QString("parseName got name" ) + name);
864 // return the new position
870 parseValue(const char *&s
, ExprValue
* variable
)
872 const char *start
= s
, *end
= s
;
873 ExprValue
* childValue
;
874 #define VALUE_END_MARKER_INDEX 0
876 /* This mark the end of a value */
877 static const char *marker
[] = {
878 "\032\032", /* value end marker*/
880 "Breakpoint at", /* stepped to next location */
881 "Breakpoint in", /* reached a set breakpoint */
882 "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 ExprValue(variable
->m_value
, VarTree::NKplain
);
927 variable
->appendChild(childValue
);
928 childValue
= new ExprValue(valueBuffer
, VarTree::NKplain
);
929 variable
->appendChild(childValue
);
930 variable
->m_value
= "";
932 variable
->m_value
= valueBuffer
;
935 childValue
= new ExprValue(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
;
975 TRACE("parseFrameInfo");
979 /* skip 'template :\" */
983 while ((*p
!= '\"') && (*p
!= '\0')) {
987 while ((*p
!= '\0') && *p
!= '"')
997 /* skip mode :".*" */
998 while ((*p
!= '\0') && *p
!= '"')
1002 while ((*p
!= '\0') && *p
!= '"')
1005 /* skip '" in file ' */
1011 while (!isspace(*p
) && (*p
!= '\"') && (*p
!= '\0')) {
1017 ASSERT(p
<= endPos
);
1024 /* skip ' : line '" */
1027 ASSERT(p
<= endPos
);
1034 /* KDbg uses an offset of +1 for its line numbers */
1035 lineNo
= atoi(p
) - 1;
1036 lineNoString
= QString::number(lineNo
);
1038 /* convert func into format needed */
1039 func
.append(" at ");
1042 func
.append(lineNoString
);
1044 /*advance to next line */
1045 p
= strchr(p
, '\n');
1055 * Parses a stack frame including its frame number
1058 parseFrame(const char *&s
, int &frameNo
, QString
& func
,
1059 QString
& file
, int &lineNo
, DbgAddr
& address
)
1062 // TRACE("XsldbgDriver ::parseFrame");
1063 /* skip leading 'where' or 'frame <frame_no>' */
1064 if ((strncmp(s
, "where", 5) == 0) || (strncmp(s
, "frame", 5) == 0)) {
1065 s
= strchr(s
, '\n');
1066 if ((*s
!= '\0') && (*s
!= '#'))
1072 //#1 template :"/" in file /home/keith/anon_CVS/xsldbg/docs/en/xsldoc.xsl : line 21
1073 // must start with a hash mark followed by number
1074 if (s
[0] != '#' || !isdigit(s
[1]))
1077 //TRACE("XsldbgDriver ::parseFrame got #");
1078 s
++; /* skip the hash mark */
1084 //TRACE(QString("Got frame ").append(QString::number(frameNo)));
1088 parseFrameInfo(s
, func
, file
, lineNo
, address
);
1089 // TRACE("Will next look at ");
1095 XsldbgDriver::parseBackTrace(const char *output
,
1096 std::list
< StackFrame
> &stack
)
1099 int lineNo
, frameNo
;
1102 while (::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
)) {
1103 stack
.push_back(StackFrame());
1104 StackFrame
* frm
= &stack
.back();
1106 frm
->frameNo
= frameNo
;
1107 frm
->fileName
= file
;
1108 frm
->lineNo
= lineNo
;
1109 frm
->address
= address
;
1110 frm
->var
= new ExprValue(func
, VarTree::NKplain
);
1115 XsldbgDriver::parseFrameChange(const char *output
, int &frameNo
,
1116 QString
& file
, int &lineNo
,
1121 return::parseFrame(output
, frameNo
, func
, file
, lineNo
, address
);
1126 XsldbgDriver::parseBreakList(const char *output
,
1127 std::list
< Breakpoint
> &brks
)
1129 TRACE("parseBreakList");
1130 /* skip the first blank line */
1136 p
= strchr(output
, '\n');/* skip the first blank line*/
1138 while ((p
!= 0) && (*p
!= '\0')) {
1141 QString templateName
;
1142 //qDebug("Looking at :%s", p);
1143 if (strncmp(p
, " Breakpoint", 11) != 0)
1151 bp
.id
= strtol(p
, &dummy
, 10); /* don't care about overflows */
1154 if ((p
== 0) || (p
[1] == '\0'))
1159 // Get breakpoint state ie enabled/disabled
1160 if (strncmp(p
, "enabled", 7) == 0) {
1164 if (strncmp(p
, "disabled", 8) == 0) {
1168 TRACE("Parse error in breakpoint list");
1174 //TRACE("Looking for template");
1176 if (strncmp(p
, " for template: \"", 16) == 0){
1178 //TRACE("Looking for template name near");
1180 /* get the template name */
1181 while (p
&& (*p
!= '\0') && (*p
!= '\"')){
1182 templateName
.append(*p
);
1188 TRACE("Error missed \" near");
1193 //TRACE("Looking for mode near");
1195 if (strncmp(p
, " mode: \"", 8) == 0){
1197 while (p
&& *p
!= '\"')
1203 if (strncmp(p
, " in file ", 9) != 0){
1204 TRACE("Parse error in breakpoint list");
1210 /* skip ' in file ' */
1216 /* grab file name */
1218 while ((*p
!= '\"') && !isspace(*p
)) {
1227 /* skip ' : line ' */
1229 while (isspace(*p
)) {
1234 while (isdigit(*p
)) {
1239 // bp.lineNo is zero-based
1240 bp
.lineNo
= lineNo
.toInt() - 1;
1241 bp
.location
= QString("in %1 at %2:%3").arg(templateName
, file
, lineNo
);
1246 p
= strchr(p
, '\n');
1254 std::list
<ThreadInfo
>
1255 XsldbgDriver::parseThreadList(const char */
*output*/
)
1257 return std::list
<ThreadInfo
>();
1261 XsldbgDriver::parseBreakpoint(const char *output
, int &id
,
1262 QString
&file
, int &lineNo
, QString
&address
)
1265 if ( strncmp(output
, "Error:", 6) == 0) {
1270 if (strncmp(output
, "Breakpoint ", 11) != 0)
1274 if (!isdigit(*output
))
1278 id
= strtol(output
, &dummy
, 10); /* don't care about overflows */
1279 if (output
== dummy
)
1282 // the file name + lineNo will be filled in later from the breakpoint list
1283 file
= address
= QString();
1289 XsldbgDriver::parseLocals(const char *output
, std::list
< ExprValue
* > &newVars
)
1292 /* keep going until error or xsldbg prompt is found */
1293 while (*output
!= '\0') {
1294 ExprValue
*variable
= parseVar(output
);
1296 if (variable
== 0) {
1299 // do not add duplicates
1300 for (std::list
<ExprValue
*>::iterator o
= newVars
.begin(); o
!= newVars
.end(); ++o
) {
1301 if ((*o
)->m_name
== variable
->m_name
) {
1307 newVars
.push_back(variable
);
1314 XsldbgDriver::parsePrintExpr(const char *output
, bool wantErrorValue
)
1317 // check for error conditions
1318 if (!parseErrorMessage(output
, var
, wantErrorValue
)) {
1319 // parse the variable
1320 var
= parseVar(output
);
1326 XsldbgDriver::parseChangeWD(const char *output
, QString
& message
)
1328 bool isGood
= false;
1330 if (strncmp(output
, "Change to directory", 20) == 0) {
1331 output
= output
+ 20; /* skip 'Change to directory' */
1332 message
= QString(output
).simplifyWhiteSpace();
1333 if (message
.isEmpty()) {
1334 message
= i18n("New working directory: ") + m_programWD
;
1342 XsldbgDriver::parseChangeExecutable(const char *output
, QString
& message
)
1345 TRACE(QString("XsldbgDriver::parseChangeExecutable :") + output
);
1346 m_haveCoreFile
= false;
1349 * The command is successful if there is no output or the single
1350 * message (no debugging symbols found)...
1352 QRegExp
exp(".*Load of source deferred. Use the run command.*");
1353 int len
, index
= exp
.match(output
, 0, &len
);
1356 TRACE("Parsed stylesheet executable");
1359 return (output
[0] == '\0') || (index
!= -1);
1363 XsldbgDriver::parseCoreFile(const char *output
)
1365 TRACE("XsldbgDriver::parseCoreFile");
1367 QRegExp
exp(".*Load of data file deferred. Use the run command.*");
1368 int len
, index
= exp
.match(output
, 0, &len
);
1371 m_haveCoreFile
= true;
1372 TRACE("Parsed data file name");
1375 return m_haveCoreFile
;
1379 XsldbgDriver::parseProgramStopped(const char *output
, QString
& message
)
1381 /* Not sure about this function leave it here for the moment */
1383 * return DebuggerDriver::SFrefreshBreak & DebuggerDriver::SFprogramActive;
1386 // go through the output, line by line, checking what we have
1387 const char *start
= output
- 1;
1388 uint flags
= SFprogramActive
;
1390 message
= QString();
1392 start
++; /* skip '\n' */
1394 if (strncmp(start
, "Finished stylesheet\n\032\032\n", 21) == 0){
1395 // flags &= ~SFprogramActive;
1399 // next line, please
1400 start
= strchr(start
, '\n');
1401 } while (start
!= 0);
1407 XsldbgDriver::parseSharedLibs(const char */
*output*/
)
1409 return QStringList();
1413 XsldbgDriver::parseFindType(const char */
*output*/
, QString
& /*type*/)
1418 std::list
<RegisterInfo
>
1419 XsldbgDriver::parseRegisters(const char */
*output*/
)
1421 return std::list
<RegisterInfo
>();
1425 XsldbgDriver::parseInfoLine(const char */
*output*/
, QString
& /*addrFrom*/,
1426 QString
& /*addrTo*/)
1431 std::list
<DisassembledCode
>
1432 XsldbgDriver::parseDisassemble(const char */
*output*/
)
1434 return std::list
<DisassembledCode
>();
1438 XsldbgDriver::parseMemoryDump(const char */
*output*/
,
1439 std::list
< MemoryDump
> &/*memdump*/)
1441 return i18n("No memory dump available");
1445 XsldbgDriver::parseSetVariable(const char */
*output*/
)
1452 #include "xsldbgdriver.moc"