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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright : (C) 2015 Eran Ifrah
// File name : memcheckerror.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* @file
* @author pavel.iqx
* @date 2014
* @copyright GNU General Public License v2
*
* ErrorList implements of list of parsed errors. Basically Error have label and trace log - list of Locations.
* LocationList represents stack trace.
*/
#ifndef _MEMCHECKERROR_H_
#define _MEMCHECKERROR_H_
#include <wx/wx.h>
#include <wx/tokenzr.h>
#include <list>
#include "memcheckdefs.h"
class MemCheckErrorLocation;
class MemCheckError;
typedef std::list<MemCheckErrorLocation> LocationList;
typedef std::list<MemCheckError> ErrorList;
typedef MemCheckError* MemCheckErrorPtr;
/**
* @class MemCheckErrorReferrer
* @brief wrapper pointer to MemCheckError
*
* wxDVC needs reference to MemCheckError, the only way to achieve this is to set its wxClientData. But the problem is that whenever wxDVC is cleared it is made by wxCrafters wxDVCModel and this model frees all the client data. With this hack model clears only this wrapper class and leavs MemCheckErrorList intact.
*/
class MemCheckErrorReferrer: public wxClientData
{
MemCheckError & m_error;
public:
MemCheckErrorReferrer(MemCheckError & error) : wxClientData(), m_error(error) {};
MemCheckError & Get() {
return m_error;
};
};
/**
* @class MemCheckErrorLocationReferrer
* @brief wrapper pointer to MemCheckErrorLocation
*
* wxDVC needs reference to MemCheckErrorLocation, the only way to achieve this is to set its wxClientData. But the problem is that whenever wxDVC is cleared it is made by wxCrafters wxDVCModel and this model frees all the client data. With this hack model clears only this wrapper class and leavs MemCheckErrorList intact.
*/
class MemCheckErrorLocationReferrer: public wxClientData
{
MemCheckErrorLocation & m_location;
public:
MemCheckErrorLocationReferrer(MemCheckErrorLocation & location) : m_location(location) {};
MemCheckErrorLocation & Get() {
return m_location;
};
};
/**
* @class MemCheckErrorLocation
* @brief Represents on record from error stacktrace.
*/
struct MemCheckErrorLocation {
bool operator==(const MemCheckErrorLocation & other) const;
bool operator!=(const MemCheckErrorLocation & other) const;
/**
* @brief Returns all atributed concatenated to tab separated string.
* @return string
*
* this function is used in searching function
*/
const wxString toString() const;
/**
* @brief Is used in tooltip.
* @param workspacePath
* @return string
*/
const wxString toText(const wxString & workspacePath = wxEmptyString) const;
/**
* @brief If file is in workspace path, that path is trimmed
* @param workspacePath
* @return file name
*/
const wxString getFile(const wxString & workspacePath = wxEmptyString) const;
/**
* @brief If object file is in workspace path, that path is trimmed
* @param workspacePath
* @return obj file name
*/
const wxString getObj(const wxString & workspacePath = wxEmptyString) const;
/**
* @brief test if is NOT in workspace
* @return true if location points to file not in workspace scope
*/
const bool isOutOfWorkspace(const wxString & workspacePath) const;
wxString func;
wxString file;
int line;
wxString obj;
};
/**
* @class MemCheckError
* @brief Represents one error with label, stack trace (location list), and some additional record.
*
* Aditional records have also stacttrace, so they are implemented same as errors. Auxiliary record implemented as list of error. Some tool have more than one auxiliary section. Type is used to distinguish between them.
*/
struct MemCheckError {
enum Type { TYPE_ERROR, TYPE_AUXILIARY };
MemCheckError();
/**
* @brief Returns all atributed and atributes of all locations and all atributes from nested errors concatenated to tab separated string.
* @return string
*
* TODO: It cloud be buffered to improve speed, but it would cost more memory.
*/
const wxString toString() const;
/**
* @brief Is used in tooltip.
* @param indent number of spaces
* @return string
*/
const wxString toText(unsigned int indent = 1) const;
/**
* @brief creates uniq name for suppresion
* @return suppression rule as string
*
* FIXME This method must be moved to Valgrind procesor, it is Valgrind specfic.
*/
const wxString getSuppression();
/**
* @brief Test if error has file on specified path.
* @param path
* @return True if at least one file is in path, otherwise false.
*/
const bool hasPath(const wxString & path) const;
Type type;
bool suppressed;
wxString label;
wxString suppression;
LocationList locations;
ErrorList nestedErrors;
};
/**
* @brief flags to use with MemCheckIterTools
*/
enum {
MC_IT_OMIT_NONWORKSPACE = 1 << 1,
MC_IT_OMIT_DUPLICATIONS = 1 << 2,
MC_IT_OMIT_SUPPRESSED = 1 << 3,
};
/**
* @class MemCheckIterTools
* @brief Iterator for iterating trought ErrorList and LocationList.
*
* There are three options in setting
* + omitNonWorkspace: Hide all other location than the ones with path from current workspace. In other words, shown are only locations from current workspace.
* + omitDuplications: Some errors cause that Valgrind prints almost identical error more than one time. So this reduces succeed errors which looks same.
* + omitSuppressed: If error is suppressed (in supp notebook) it disappears from list. It is the same efect as creating supp and rerunning test.
*
* This class holds context of these setting for whole ErrorList and ErrorLocationList.
* In python for example it would be question of ene predicate passed as argument to iterator function, in C I had to do it by hand :(
* The reason id I need iterator that can hold some atritubes and pass them to subiterators.
*
* This functionality could be part of ErrorList
*/
class MemCheckIterTools
{
struct IterTool {
bool omitNonWorkspace;
bool omitDuplications;
bool omitSuppressed;
wxString workspacePath;
bool isEqual(MemCheckError & lhs, MemCheckError & rhs) const;
} m_iterTool ;
public:
class LocationListIterator : public std::iterator<std::input_iterator_tag, MemCheckErrorLocation>
{
LocationList::iterator p;
LocationList::iterator m_end;
IterTool m_iterTool;
public:
LocationListIterator(LocationList & l, const IterTool &iterTool);
~LocationListIterator();
LocationList::iterator& operator++();
LocationList::iterator operator++(int);
bool operator==(const LocationList::iterator& rhs);
bool operator!=(const LocationList::iterator& rhs);
MemCheckErrorLocation & operator*();
};
class ErrorListIterator : public std::iterator<std::input_iterator_tag, MemCheckError>
{
ErrorList::iterator p;
ErrorList::iterator m_end;
IterTool m_iterTool;
public:
ErrorListIterator(ErrorList & l, const IterTool & iterTool);
~ErrorListIterator();
ErrorList::iterator& operator++();
ErrorList::iterator operator++(int);
bool operator==(const ErrorList::iterator& rhs);
bool operator!=(const ErrorList::iterator& rhs);
MemCheckError & operator*();
};
protected:
/**
* @brief ctor creates object which hold shared atributes and provides all functionality for iterration over ErrorLists and LocationLists
* @param workspacePath
* @param flags
*/
MemCheckIterTools(const wxString & workspacePath, unsigned int flags);
ErrorListIterator GetIterator(ErrorList & l);
LocationListIterator GetIterator(LocationList & l);
public:
/**
* @brief Creates iterator with holds settings and does iteration.
* @param l list to iterate over
* @param workspacePath
* @param flags MC_IT_OMIT_NONWORKSPACE | MC_IT_OMIT_DUPLICATIONS | MC_IT_OMIT_SUPPRESSED
* @return iterator over ErrorList
*
* This method calls MemCheckIterTools constructor and then GetIterator method.
*/
static ErrorListIterator Factory(ErrorList & l, const wxString & workspacePath, unsigned int flags);
/**
* @brief Creates iterator with holds settings and does iteration.
* @param l list to iterate over
* @param workspacePath
* @param flags MC_IT_OMIT_NONWORKSPACE | MC_IT_OMIT_DUPLICATIONS | MC_IT_OMIT_SUPPRESSED
* @return iterator over LocationList
*
* This method calls MemCheckIterTools constructor and then GetIterator method.
*/
static LocationListIterator Factory(LocationList & l, const wxString & workspacePath, unsigned int flags);
};
#endif //_MEMCHECKERROR_H_
|