~ubuntu-branches/ubuntu/oneiric/valkyrie/oneiric

« back to all changes in this revision

Viewing changes to src/utils/vglogreader.cpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-09-02 22:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110902220834-kigsixteppj9epp5
Tags: 2.0.0-0ubuntu1
* New upstream release. (LP: #635129, LP: #832886, LP: #721298)
* Standards bumped to 3.9.2, no changes required.
* d/control, d/rules: cdbs removed, dh minimal rule instead.
* d/control: build system is qmake not autotools
* d/control: bump required qt to qt4
* d/valkyrie.install: installing html docs manually as make install
  no longer does so.
* d/patches/valkyrie-2.0.0-fix-doc.dir.patch: Fix doc path to match
  policy. Also corrects LP: #588074 since the documentation link now
  works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** VgLogReader implementation
 
3
**  - reads valgrind xml log into a VgLog
 
4
** --------------------------------------------------------------------------
 
5
**
 
6
** Copyright (C) 2000-2010, OpenWorks LLP. All rights reserved.
 
7
** <info@open-works.co.uk>
 
8
**
 
9
** This file is part of Valkyrie, a front-end for Valgrind.
 
10
**
 
11
** This file may be used under the terms of the GNU General Public
 
12
** License version 2.0 as published by the Free Software Foundation
 
13
** and appearing in the file COPYING included in the packaging of
 
14
** this file.
 
15
**
 
16
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
17
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include "utils/vglogreader.h"
 
22
#include "utils/vk_utils.h"
 
23
 
 
24
 
 
25
/**********************************************************************/
 
26
/*!
 
27
  VgLogReader
 
28
*/
 
29
VgLogReader::VgLogReader( VgLogView* lv )
 
30
   : vghandler( 0 ), source( 0 )
 
31
{
 
32
   vghandler = new VgLogHandler( lv );
 
33
   setContentHandler( vghandler );
 
34
   setErrorHandler( vghandler );
 
35
   //  setLexicalHandler( vghandler );
 
36
   //  setDeclHandler( vghandler );
 
37
   //  setDTDHandler( vghandler );
 
38
}
 
39
 
 
40
VgLogReader::~VgLogReader()
 
41
{
 
42
   if ( vghandler != 0 ) {
 
43
      delete vghandler;
 
44
      vghandler = 0;
 
45
   }
 
46
   
 
47
   if ( source ) {
 
48
      delete source;
 
49
      source = 0;
 
50
   }
 
51
   
 
52
   if ( file.isOpen() ) {
 
53
      file.close();
 
54
   }
 
55
}
 
56
 
 
57
bool VgLogReader::parse( QString filepath, bool incremental/*=false*/ )
 
58
{
 
59
   if ( source ) {
 
60
      delete source;
 
61
   }
 
62
   
 
63
   if ( file.isOpen() ) {
 
64
      file.close();
 
65
   }
 
66
   
 
67
   file.setFileName( filepath );
 
68
   source = new QXmlInputSource( &file );
 
69
   return QXmlSimpleReader::parse( source, incremental );
 
70
}
 
71
 
 
72
bool VgLogReader::parseContinue()
 
73
{
 
74
   if ( source ) {
 
75
      source->fetchData();
 
76
   }
 
77
   
 
78
   return QXmlSimpleReader::parseContinue();
 
79
}
 
80
 
 
81
 
 
82
/**********************************************************************/
 
83
/* VgLogHandler */
 
84
VgLogHandler::VgLogHandler( VgLogView* lv )
 
85
{
 
86
   logview = lv;
 
87
   node = doc;
 
88
   m_finished = false;
 
89
   m_started = false;
 
90
}
 
91
 
 
92
VgLogHandler::~VgLogHandler()
 
93
{ }
 
94
 
 
95
/* gets <?xml...> element */
 
96
bool VgLogHandler::processingInstruction( const QString& target, const QString& data )
 
97
{
 
98
   //  vkPrintErr("VgLogHandler::processingInstruction: %s, %s", target.latin1(), data.latin1());
 
99
   doc.appendChild( doc.createProcessingInstruction( target, data ) );
 
100
   node = doc;
 
101
   return true;
 
102
}
 
103
 
 
104
bool VgLogHandler::startElement( const QString&, const QString&,
 
105
                                 const QString& tag,
 
106
                                 const QXmlAttributes& )
 
107
{
 
108
   //  vkPrintErr("VgLogHandler::startElement: '%s'", tag.latin1());
 
109
   QDomNode n = doc.createElement( tag );
 
110
   node.appendChild( n );
 
111
   node = n;
 
112
   
 
113
   if ( node == doc.documentElement() ) {
 
114
      QDomProcessingInstruction xml_insn =
 
115
         doc.firstChild().toProcessingInstruction();
 
116
      if ( ! logview->init( xml_insn, tag ) ) {
 
117
         //VK_DEBUG("Error: Failed log initialisation");
 
118
         return false;
 
119
      }
 
120
   }
 
121
   
 
122
   return true;
 
123
}
 
124
 
 
125
bool VgLogHandler::endElement( const QString&, const QString&,
 
126
                               const QString& /*tag*/ )
 
127
{
 
128
   // vkPrintErr("VgLogHandler::endElement: %s", qPrintable( tag ));
 
129
   // Should never have end element at doc level
 
130
   if ( node == doc ) {
 
131
      //VK_DEBUG("VgLogHandler::endElement(): Error: node == doc");
 
132
      return false;
 
133
   }
 
134
   
 
135
   QDomNode prnt = node.parentNode();
 
136
   
 
137
   /* if closing a top-level tag, append to vglog */
 
138
   if ( prnt == doc.documentElement() ) {
 
139
      QString errMsg;
 
140
      if ( ! logview->appendNode( node, errMsg ) ) {
 
141
         //VK_DEBUG("Failed to append node");
 
142
         m_fatalMsg = errMsg;
 
143
         return false;
 
144
      }
 
145
   }
 
146
   
 
147
   node = prnt;
 
148
   
 
149
   if ( node == doc ) {
 
150
      /* In case we get bad xml after the closing tag, mark as 'finished'
 
151
         This may happed, for example, as a result of doing fork() but
 
152
         not exec() under valgrind.  When the process forks, you wind up
 
153
         with 2 V's attached to the same logfile, which doesn't get
 
154
         sorted out until the child does exec().
 
155
      */
 
156
      m_finished = true;
 
157
   }
 
158
   
 
159
   return true;
 
160
}
 
161
 
 
162
bool VgLogHandler::characters( const QString&  ch )
 
163
{
 
164
   //  vkPrintErr("characters: '%s'", ch.latin1());
 
165
   // No text as child of some document
 
166
   if ( node == doc ) {
 
167
      return false;
 
168
   }
 
169
   
 
170
   /* ignore text as child of doc_elem
 
171
      => valgrind non-xml output (shouldn't happen), or client output */
 
172
   if ( node == doc.documentElement() ) {
 
173
      return true;
 
174
   }
 
175
   
 
176
   QString chars = ch.simplified();
 
177
   
 
178
   if ( !chars.isEmpty() ) {
 
179
      node.appendChild( doc.createTextNode( chars ) );
 
180
      //    vkPrintErr("chars: '%s'", chars.latin1());
 
181
   }
 
182
   
 
183
   return true;
 
184
}
 
185
 
 
186
/* Called by xml reader at start of parsing */
 
187
bool VgLogHandler::startDocument()
 
188
{
 
189
   //   vkPrintErr("VgLogHandler::startDocument()\n");
 
190
   vk_assert( logview != 0 );
 
191
   
 
192
   doc = QDomDocument();
 
193
   node = doc;
 
194
   m_fatalMsg = QString();
 
195
   m_finished = false;
 
196
   m_started = true;
 
197
   return true;
 
198
}
 
199
 
 
200
/* Called by xml reader after it has finished parsing
 
201
   Checks we have a complete document,
 
202
   i.e. endElement() has returned node ptr to root
 
203
*/
 
204
bool VgLogHandler::endDocument()
 
205
{
 
206
   //   vkPrintErr("VgLogHandler::endDocument()\n");
 
207
   m_finished = true;
 
208
   
 
209
   if ( node != doc ) {
 
210
      return false;
 
211
   }
 
212
   
 
213
   return true;
 
214
}
 
215
 
 
216
/* non-fatal error: just report it */
 
217
bool VgLogHandler::error( const QXmlParseException& exception )
 
218
{
 
219
   //   vkPrintErr("VgLogHandler::error");
 
220
   QString err = exception.message() +
 
221
                 " (line: " + QString::number( exception.lineNumber() ) +
 
222
                 ", col: " + QString::number( exception.columnNumber() ) + ")";
 
223
                 
 
224
   // printf("VgLogHandler::non-fatal error: %s", err.latin1());
 
225
   
 
226
   return true; /* try to continue. */
 
227
}
 
228
 
 
229
bool VgLogHandler::fatalError( const QXmlParseException& exception )
 
230
{
 
231
   //  vkPrintErr("fatalError");
 
232
 
 
233
   // msg previously set by logview: print everything.
 
234
   m_fatalMsg = exception.message() +
 
235
                " (line: " + QString::number( exception.lineNumber() ) +
 
236
                ", col: " + QString::number( exception.columnNumber() ) + ")" +
 
237
                "\n\n" + m_fatalMsg;
 
238
                
 
239
   if ( m_finished ) {
 
240
      /* If we finished before we got the error, this is probably the
 
241
         result of Valgrind's fork-no-exec problem. */
 
242
      m_fatalMsg
 
243
      += "\nError after document closing tag.\nThis may be "
 
244
         "caused by the Valgrinded application doing fork() but "
 
245
         "not exec().  If so, ensure each fork() has a matching "
 
246
         "exec() call.";
 
247
   }
 
248
   
 
249
   return false; /* don't continue parsing */
 
250
}