summaryrefslogtreecommitdiffstats
path: root/parts/valgrind/valgrinditem.cpp
blob: 318254d3a66ece3b68e469e7f9f345248641fc2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "valgrinditem.h"

#include <qregexp.h>
#include <qstringlist.h>

#include <kdebug.h>

ValgrindBacktraceItem::ValgrindBacktraceItem( const QString& rawOutput ): _rawOutput( rawOutput ), _highlight( false )
{
  QRegExp re1( "^==(\\d+)==\\s+(by|at) (0x[\\dABCDEF]+): (.*) \\((.*):(\\d+)\\)$" );
  QRegExp re2( "^==(\\d+)==\\s+(by|at) (0x[\\dABCDEF]+): (.*) \\(in (.*)\\)$" );
  QRegExp valRe( "==(\\d+)== (.*)" );
  if ( valRe.search( _rawOutput ) >= 0 )
    _message = valRe.cap( 2 );
  if ( re1.search( _rawOutput ) >= 0 ) {
    _type = SourceCode;
    _pid = re1.cap( 1 ).toInt();
    _address = re1.cap( 3 );
    _function = re1.cap( 4 );
    _url = re1.cap( 5 );
    _line = re1.cap( 6 ).toInt();
  } else if ( re2.search( _rawOutput ) >= 0 ) {
    _type = Library;
    _pid = re2.cap( 1 ).toInt();
    _address = re2.cap( 3 );
    _function = re2.cap( 4 );
    _url = re2.cap( 5 );
    _line = -1;
  } else {
    _type = Unknown;
    _line = -1;
    _pid = -1;
  }
}

ValgrindBacktraceItem::~ValgrindBacktraceItem()
{
}


ValgrindItem::ValgrindItem( const QString& message ): _pid(-1)
{
  QRegExp valRe( "==(\\d+)== (.*)" );
  QStringList lines = QStringList::split( "\n", message );
  QString curMsg;
  
  for ( QStringList::ConstIterator it = lines.begin(); it != lines.end(); ++it ) {
    if ( valRe.search( *it ) < 0 ) {
      kdDebug() << "ValgrindItem: got unrecognizable line '" << *it << "'" << endl;
      continue; // not of interest
    }
    if ( _pid == -1 )
      _pid = valRe.cap( 1 ).toInt();
    curMsg = valRe.cap( 2 );

    if ( curMsg.startsWith( " " ) ) {
      _backtrace.append( ValgrindBacktraceItem( *it ) );
    } else {
      if ( !_message.isEmpty() )
        _message += "\n";
      _message += curMsg;
    }
  }
//  static int i = 0;
//  kdDebug() << "got: " << ++i << ": " << _message << endl << message << endl;
}


ValgrindItem::~ValgrindItem()
{
}