summaryrefslogtreecommitdiffstats
path: root/parts/valgrind/valgrinditem.cpp
blob: 0ae6f1e0c4c2d5c114470711cff633cf7edea70f (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 <tqregexp.h>
#include <tqstringlist.h>

#include <kdebug.h>

ValgrindBacktraceItem::ValgrindBacktraceItem( const TQString& rawOutput ): _rawOutput( rawOutput ), _highlight( false )
{
  TQRegExp re1( "^==(\\d+)==\\s+(by|at) (0x[\\dABCDEF]+): (.*) \\((.*):(\\d+)\\)$" );
  TQRegExp re2( "^==(\\d+)==\\s+(by|at) (0x[\\dABCDEF]+): (.*) \\(in (.*)\\)$" );
  TQRegExp 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 TQString& message ): _pid(-1)
{
  TQRegExp valRe( "==(\\d+)== (.*)" );
  TQStringList lines = TQStringList::split( "\n", message );
  TQString curMsg;
  
  for ( TQStringList::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()
{
}