1
/* ---------------------------------------------------------------------
2
* vglogreader: reads xml log into a VgLog vglogreader.h
3
* ---------------------------------------------------------------------
4
* This file is part of Valkyrie, a front-end for Valgrind
5
* Copyright (C) 2000-2008, OpenWorks LLP <info@open-works.co.uk>
6
* This program is released under the terms of the GNU GPL v.2
7
* See the file COPYING for the full license details.
10
#include "vglogreader.h"
15
/**********************************************************************/
17
VgLogReader::VgLogReader( VgLog* vglog )
18
: vghandler(0), source(0)
20
vghandler = new VgLogHandler( vglog );
21
setContentHandler( vghandler );
22
setErrorHandler( vghandler );
23
// setLexicalHandler( vghandler );
24
// setDeclHandler( vghandler );
25
// setDTDHandler( vghandler );
28
VgLogReader::~VgLogReader()
30
if ( vghandler != 0 ) {
42
bool VgLogReader::parse( QString filepath, bool incremental/*=false*/ )
48
file.setName( filepath );
49
source = new QXmlInputSource( file );
50
return QXmlSimpleReader::parse( source, incremental );
53
bool VgLogReader::parseContinue()
57
return QXmlSimpleReader::parseContinue();
61
/**********************************************************************/
63
VgLogHandler::VgLogHandler( VgLog* alog )
70
VgLogHandler::~VgLogHandler()
73
/* gets <?xml...> element */
74
bool VgLogHandler::processingInstruction( const QString& target, const QString& data )
76
// vkPrintErr("VgLogHandler::processingInstruction: %s, %s", target.latin1(), data.latin1());
77
doc.appendChild( doc.createProcessingInstruction( target, data ) );
82
bool VgLogHandler::startElement( const QString&, const QString&,
84
const QXmlAttributes& )
86
// vkPrintErr("VgLogHandler::startElement: '%s'", tag.latin1());
87
QDomNode n = doc.createElement( tag );
88
node.appendChild( n );
91
if (node == doc.documentElement()) {
92
QDomProcessingInstruction xml_insn =
93
doc.firstChild().toProcessingInstruction();
94
if ( ! vglog->init( xml_insn, tag ) ) {
95
//VK_DEBUG("Error: Failed log initialisation");
103
bool VgLogHandler::endElement( const QString&, const QString&,
104
const QString& /*tag*/ )
106
// vkPrintErr("VgLogHandler::endElement: %s", tag.latin1());
107
// Should never have end element at doc level
109
//VK_DEBUG("VgLogHandler::endElement(): Error: node == doc");
113
QDomNode prnt = node.parentNode();
115
/* if closing a top-level tag, append to vglog */
116
if (prnt == doc.documentElement()) {
117
if ( ! vglog->appendNode( node ) ) {
118
//VK_DEBUG("Failed to append node");
125
/* In case we get bad xml after the closing tag, mark as 'finished'
126
This may happed, for example, as a result of doing fork() but
127
not exec() under valgrind. When the process forks, you wind up
128
with 2 V's attached to the same logfile, which doesn't get
129
sorted out until the child does exec().
137
bool VgLogHandler::characters( const QString& ch )
139
// vkPrintErr("characters: '%s'", ch.latin1());
140
// No text as child of some document
144
/* ignore text as child of doc_elem
145
=> valgrind non-xml output (shouldn't happen), or client output */
146
if ( node == doc.documentElement() )
149
QString chars = ch.simplifyWhiteSpace();
150
if ( !chars.isEmpty() ) {
151
node.appendChild( doc.createTextNode( chars ) );
152
// vkPrintErr("chars: '%s'", chars.latin1());
158
/* Called by xml reader at start of parsing */
159
bool VgLogHandler::startDocument()
161
// vkPrintErr("VgLogHandler::startDocument()\n");
164
doc = QDomDocument();
166
m_fatalMsg = QString();
171
/* Called by xml reader after it has finished parsing
172
Checks we have a complete document,
173
i.e. endElement() has returned node ptr to root
175
bool VgLogHandler::endDocument()
177
// vkPrintErr("VgLogHandler::endDocument()\n");
184
/* non-fatal error: just report it */
185
bool VgLogHandler::error( const QXmlParseException& exception )
187
// vkPrintErr("VgLogHandler::error");
188
QString err = exception.message() +
189
" (line: " + QString::number(exception.lineNumber()) +
190
", col: " + QString::number(exception.columnNumber()) + ")";
192
// printf("VgLogHandler::non-fatal error: %s", err.latin1());
194
return true; /* try to continue. */
197
bool VgLogHandler::fatalError( const QXmlParseException& exception )
199
// vkPrintErr("fatalError");
200
m_fatalMsg = exception.message() +
201
" (line: " + QString::number(exception.lineNumber()) +
202
", col: " + QString::number(exception.columnNumber()) + ")";
205
/* If we finished before we got the error, this is probably the
206
result of Valgrind's fork-no-exec problem. */
208
+= "\nError after document closing tag.\nThis may be "
209
"caused by the Valgrinded application doing fork() but "
210
"not exec(). If so, ensure each fork() has a matching "
214
return false; /* don't continue parsing */