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
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#ifndef STACKWALKER_H_
#define STACKWALKER_H_
#include <iostream>
#include <iomanip>
#include <string>
#include <tulip/ConsoleUtils.h>
#ifndef _MSC_VER
#ifdef HAVE_BFD
#include "BfdWrapper.h"
#endif
#else // not _MSC_VER
#include <stdint.h>
#endif
class StackWalker {
public:
virtual ~StackWalker() {}
virtual void printCallStack(std::ostream &os, unsigned int maxDepth = 50) = 0;
void printCallStackToStdErr(unsigned int maxDepth = 50);
virtual void printFrameInfos(std::ostream &os, unsigned int frameId, int64_t pcAddress, std::string moduleName, std::string funcName="", int64_t symbolOffset=0, std::string fileName="", unsigned int line=0) {
if (frameId%2 == 0)
os << setTextBackgroundColor(DARK_GRAY);
else
os << setTextBackgroundColor(LIGHT_GRAY);
os << bold;
os << lightRed << std::dec << std::setfill('0') << "#" << std::setw(2) << frameId
<< lightMagenta << " 0x" << std::hex << std::setw(16) << pcAddress << lightRed << " in ";
os << lightBlue;
if (funcName != "") {
os << funcName;
}
else {
os << "??";
}
if (symbolOffset != 0) {
os << lightMagenta << " (+0x" << std::hex << symbolOffset << ")";
}
if (fileName != "") {
os << lightRed << " at " << lightGreen << fileName << ":" << std::dec << lightYellow << line;
}
if (moduleName != "") {
os << lightRed << " from " << lightCyan << moduleName;
}
else {
os << lightRed << " from " << lightGreen << "??";
}
os << fillToEndOfLine << defaultTextColor ;
}
};
#if defined(__unix__) || defined(__APPLE__)
#include <map>
class StackWalkerGCC : public StackWalker {
public:
StackWalkerGCC();
~StackWalkerGCC();
void printCallStack(std::ostream &os, unsigned int maxDepth = 50);
void setCallerAddress(void *callerAddress) {
this->callerAddress = callerAddress;
}
private:
void *callerAddress;
#ifdef HAVE_BFD
std::map<std::string, BfdWrapper *> bfdMap;
#endif
};
#elif defined(__MINGW32__)
#include <map>
class StackWalkerMinGW : public StackWalker {
public:
StackWalkerMinGW();
~StackWalkerMinGW();
void printCallStack(std::ostream &os, unsigned int maxDepth = 50);
void setContext(LPCONTEXT context) {
this->context = context;
}
private:
LPCONTEXT context;
#ifdef HAVE_BFD
std::map<std::string, BfdWrapper *> bfdMap;
#endif
};
#elif defined(_MSC_VER)
class StackWalkerMSVC : public StackWalker {
public:
StackWalkerMSVC();
~StackWalkerMSVC();
void printCallStack(std::ostream &os, unsigned int maxDepth = 50);
void setContext(CONTEXT *context) {
this->context = context;
}
private :
CONTEXT *context;
};
#endif
#endif /* STACKWALKER_H_ */
|