Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Poco/Debugger.h"
00038 #include <sstream>
00039 #include <cstdlib>
00040 #include <cstdio>
00041 #if defined(POCO_OS_FAMILY_WINDOWS)
00042 #include "Poco/UnWindows.h"
00043 #elif defined(POCO_OS_FAMILY_UNIX)
00044 #include <unistd.h>
00045 #include <signal.h>
00046 #elif defined(POCO_OS_FAMILY_VMS)
00047 #include <lib$routines.h>
00048 #include <ssdef.h>
00049 #endif
00050 #if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
00051 #include "Poco/UnicodeConverter.h"
00052 #endif
00053
00054
00055
00056
00057
00058
00059
00060 namespace Poco {
00061
00062
00063 bool Debugger::isAvailable()
00064 {
00065 #if defined(_DEBUG)
00066 #if defined(POCO_OS_FAMILY_WINDOWS)
00067 return IsDebuggerPresent() ? true : false;
00068 #elif defined(POCO_OS_FAMILY_UNIX)
00069 return std::getenv("POCO_ENABLE_DEBUGGER") ? true : false;
00070 #elif defined(POCO_OS_FAMILY_VMS)
00071 return true;
00072 #endif
00073 #else
00074 return false;
00075 #endif
00076 }
00077
00078
00079 void Debugger::message(const std::string& msg)
00080 {
00081 #if defined(_DEBUG)
00082 std::fputs("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stderr);
00083 std::fputs(msg.c_str(), stderr);
00084 std::fputs("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stderr);
00085 #if defined(POCO_OS_FAMILY_WINDOWS)
00086 if (IsDebuggerPresent())
00087 {
00088 #if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
00089 std::wstring umsg;
00090 UnicodeConverter::toUTF16(msg, umsg);
00091 umsg += '\n';
00092 OutputDebugStringW(umsg.c_str());
00093 #else
00094 OutputDebugStringA(msg.c_str());
00095 OutputDebugStringA("\n");
00096 #endif
00097 }
00098 #elif defined(POCO_OS_FAMILY_UNIX)
00099 #elif defined(POCO_OS_FAMILY_VMS)
00100 #endif
00101 #endif
00102 }
00103
00104
00105 void Debugger::message(const std::string& msg, const char* file, int line)
00106 {
00107 #if defined(_DEBUG)
00108 std::ostringstream str;
00109 str << msg << " [in file \"" << file << "\", line " << line << "]";
00110 message(str.str());
00111 #endif
00112 }
00113
00114
00115 void Debugger::enter()
00116 {
00117 #if defined(_DEBUG)
00118 #if defined(POCO_OS_FAMILY_WINDOWS)
00119 if (IsDebuggerPresent())
00120 {
00121 DebugBreak();
00122 }
00123 #elif defined(POCO_OS_FAMILY_UNIX)
00124 if (isAvailable())
00125 {
00126 kill(getpid(), SIGINT);
00127 }
00128 #elif defined(POCO_OS_FAMILY_VMS)
00129 {
00130 const char* cmd = "\012SHOW CALLS";
00131 lib$signal(SS$_DEBUG, 1, cmd);
00132 }
00133 #endif
00134 #endif
00135 }
00136
00137
00138 void Debugger::enter(const std::string& msg)
00139 {
00140 #if defined(_DEBUG)
00141 message(msg);
00142 enter();
00143 #endif
00144 }
00145
00146
00147 void Debugger::enter(const std::string& msg, const char* file, int line)
00148 {
00149 #if defined(_DEBUG)
00150 message(msg, file, line);
00151 enter();
00152 #endif
00153 }
00154
00155
00156 void Debugger::enter(const char* file, int line)
00157 {
00158 #if defined(_DEBUG)
00159 message("BREAK", file, line);
00160 enter();
00161 #endif
00162 }
00163
00164
00165 }