Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/util/SignalHandler.cc @ 7452

Last change on this file since 7452 was 7452, checked in by landauf, 14 years ago

changed to non-deprecated functions (xxxx64)
fixed a few errors that were copy-pasted from other sources
demangling function names on mingw

  • Property svn:eol-style set to native
File size: 23.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Christoph Renner
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of the SignalHandler class.
32*/
33
34#include "SignalHandler.h"
35
36#include <iostream>
37#include <cstdlib>
38#include <cstring>
39#include "Debug.h"
40
41namespace orxonox
42{
43    SignalHandler* SignalHandler::singletonPtr_s = NULL;
44}
45
46#if defined(ORXONOX_PLATFORM_LINUX)
47
48#include <wait.h>
49#include <X11/Xlib.h>
50#include <X11/Xutil.h>
51#include <X11/keysym.h>
52
53namespace orxonox
54{
55    /**
56     * register signal handlers for SIGSEGV and SIGABRT
57     * @param appName path to executable eg argv[0]
58     * @param filename filename to append backtrace to
59     */
60    void SignalHandler::doCatch( const std::string & appName, const std::string & filename )
61    {
62      this->appName = appName;
63      this->filename = filename;
64
65      // make sure doCatch is only called once without calling dontCatch
66      assert( sigRecList.size() == 0 );
67
68      catchSignal( SIGSEGV );
69      catchSignal( SIGABRT );
70      catchSignal( SIGILL );
71    }
72
73    /**
74     * restore previous signal handlers
75     */
76    void SignalHandler::dontCatch()
77    {
78      for ( SignalRecList::iterator it = sigRecList.begin(); it != sigRecList.end(); it++ )
79      {
80        signal( it->signal, it->handler );
81      }
82
83      sigRecList.clear();
84    }
85
86    /**
87     * catch signal sig
88     * @param sig signal to catch
89     */
90    void SignalHandler::catchSignal( int sig )
91    {
92      sig_t handler = signal( sig, SignalHandler::sigHandler );
93
94      assert( handler != SIG_ERR );
95
96      SignalRec rec;
97      rec.signal = sig;
98      rec.handler = handler;
99
100      sigRecList.push_front( rec );
101    }
102
103    /**
104     * sigHandler is called when receiving signals
105     * @param sig
106     */
107    void SignalHandler::sigHandler( int sig )
108    {
109      std::string sigName = "UNKNOWN";
110
111      switch ( sig )
112      {
113        case SIGSEGV:
114          sigName = "SIGSEGV";
115          break;
116        case SIGABRT:
117          sigName = "SIGABRT";
118          break;
119        case SIGILL:
120          sigName = "SIGILL";
121          break;
122      }
123      // if the signalhandler has already been destroyed then don't do anything
124      if( SignalHandler::singletonPtr_s == 0 )
125      {
126        COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
127        exit(EXIT_FAILURE);
128      }
129
130      for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++  )
131      {
132        (*(it->cb))( it->someData );
133      }
134
135
136      COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
137
138      int sigPipe[2];
139      if ( pipe(sigPipe) == -1 )
140      {
141        perror("pipe failed!\n");
142        exit(EXIT_FAILURE);
143      }
144
145      int sigPid = fork();
146
147      if ( sigPid == -1 )
148      {
149        perror("fork failed!\n");
150        exit(EXIT_FAILURE);
151      }
152
153      // gdb will be attached to this process
154      if ( sigPid == 0 )
155      {
156        getInstance().dontCatch();
157        // wait for message from parent when it has attached gdb
158        int someData;
159
160        read( sigPipe[0], &someData, sizeof(someData) );
161
162        if ( someData != 0x12345678 )
163        {
164          COUT(0) << "something went wrong :(" << std::endl;
165        }
166
167        return;
168      }
169
170      int gdbIn[2];
171      int gdbOut[2];
172      int gdbErr[2];
173
174      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
175      {
176        perror("pipe failed!\n");
177        kill( sigPid, SIGTERM );
178        waitpid( sigPid, NULL, 0 );
179        exit(EXIT_FAILURE);
180      }
181
182      int gdbPid = fork();
183      // this process will run gdb
184
185      if ( gdbPid == -1 )
186      {
187        perror("fork failed\n");
188        kill( sigPid, SIGTERM );
189        waitpid( sigPid, NULL, 0 );
190        exit(EXIT_FAILURE);
191      }
192
193      if ( gdbPid == 0 )
194      {
195        // start gdb
196
197        close(gdbIn[1]);
198        close(gdbOut[0]);
199        close(gdbErr[0]);
200
201        dup2( gdbIn[0], STDIN_FILENO );
202        dup2( gdbOut[1], STDOUT_FILENO );
203        dup2( gdbErr[1], STDERR_FILENO );
204
205        execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL));
206      }
207
208      char cmd[256];
209      snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
210      write( gdbIn[1], cmd, strlen(cmd) );
211
212      int charsFound = 0;
213      int promptFound = 0;
214      char byte;
215      while ( read( gdbOut[0], &byte, 1 ) == 1 )
216      {
217        if (
218          (charsFound == 0 && byte == '(') ||
219          (charsFound == 1 && byte == 'g') ||
220          (charsFound == 2 && byte == 'd') ||
221          (charsFound == 3 && byte == 'b') ||
222          (charsFound == 4 && byte == ')') ||
223          (charsFound == 5 && byte == ' ')
224            )
225              charsFound++;
226        else
227          charsFound = 0;
228
229        if ( charsFound == 6 )
230        {
231          promptFound++;
232          charsFound = 0;
233        }
234
235        if ( promptFound == 3 )
236        {
237          break;
238        }
239      }
240
241      int someData = 0x12345678;
242      write( sigPipe[1], &someData, sizeof(someData) );
243
244      write( gdbIn[1], "bt\nk\nq\n", 7 );
245
246
247      charsFound = 0;
248      promptFound = 0;
249      std::string bt;
250      while ( read( gdbOut[0], &byte, 1 ) == 1 )
251      {
252        bt += std::string( &byte, 1 );
253
254        if (
255          (charsFound == 0 && byte == '(') ||
256          (charsFound == 1 && byte == 'g') ||
257          (charsFound == 2 && byte == 'd') ||
258          (charsFound == 3 && byte == 'b') ||
259          (charsFound == 4 && byte == ')') ||
260          (charsFound == 5 && byte == ' ')
261            )
262              charsFound++;
263        else
264          charsFound = 0;
265
266        if ( charsFound == 6 )
267        {
268          promptFound++;
269          charsFound = 0;
270          bt += "\n";
271        }
272
273        if ( promptFound == 3 )
274        {
275          break;
276        }
277      }
278
279
280      waitpid( sigPid, NULL, 0 );
281      waitpid( gdbPid, NULL, 0 );
282
283      int wsRemoved = 0;
284
285      while ( wsRemoved < 2 && bt.length() > 0 )
286      {
287        if ( bt[1] == '\n' )
288          wsRemoved++;
289        bt.erase(0, 1);
290      }
291
292      if ( bt.length() > 0 )
293        bt.erase(0, 1);
294
295      time_t now = time(NULL);
296
297      std::string timeString =
298                         "=======================================================\n"
299                         "= time: " + std::string(ctime(&now)) +
300                         "=======================================================\n";
301      bt.insert(0, timeString);
302
303      FILE * f = fopen( getInstance().filename.c_str(), "w" );
304
305      if ( !f )
306      {
307        perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() );
308        exit(EXIT_FAILURE);
309      }
310
311      if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
312      {
313        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
314        exit(EXIT_FAILURE);
315      }
316
317      exit(EXIT_FAILURE);
318    }
319
320    void SignalHandler::registerCallback( SignalCallback cb, void * someData )
321    {
322      SignalCallbackRec rec;
323      rec.cb = cb;
324      rec.someData = someData;
325
326      callbackList.push_back(rec);
327    }
328}
329
330#elif defined(ORXONOX_PLATFORM_WINDOWS) && defined(DBGHELP_FOUND)
331
332#include <iostream>
333#include <iomanip>
334#include <fstream>
335#include <dbghelp.h>
336
337#ifdef ORXONOX_COMPILER_GCC
338#   include <cxxabi.h>
339#endif
340
341namespace orxonox
342{
343    /// Constructor: Initializes the values, but doesn't register the exception handler.
344    SignalHandler::SignalHandler()
345    {
346        this->prevExceptionFilter_ = NULL;
347    }
348
349    /// Destructor: Removes the exception handler.
350    SignalHandler::~SignalHandler()
351    {
352        if (this->prevExceptionFilter_ != NULL)
353        {
354            // Remove the unhandled exception filter function
355            SetUnhandledExceptionFilter(this->prevExceptionFilter_);
356            this->prevExceptionFilter_ = NULL;
357        }
358    }
359
360    /// Registers an exception handler and initializes the filename of the crash log.
361    void SignalHandler::doCatch(const std::string&, const std::string& filename)
362    {
363        this->filename_ = filename;
364
365        // don't register twice
366        assert(this->prevExceptionFilter_ == NULL);
367
368        if (this->prevExceptionFilter_ == NULL)
369        {
370            // Install the unhandled exception filter function
371            this->prevExceptionFilter_ = SetUnhandledExceptionFilter(&SignalHandler::exceptionFilter);
372        }
373    }
374
375    /// Exception handler: Will be called by Windows if an unhandled exceptions occurs.
376    /* static */ LONG WINAPI SignalHandler::exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
377    {
378        // avoid loops
379        static bool bExecuting = false;
380
381        if (!bExecuting)
382        {
383            bExecuting = true;
384
385
386            // if the signalhandler has already been destroyed then don't do anything
387            if (SignalHandler::singletonPtr_s == 0)
388            {
389                COUT(1) << "Caught an unhandled exception" << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
390                exit(EXIT_FAILURE);
391            }
392
393            COUT(1) << "Caught an unhandled exception" << std::endl << "Try to write backtrace to orxonox_crash.log..." << std::endl;
394
395            // write the crash log
396            std::ofstream crashlog(SignalHandler::getInstance().filename_.c_str());
397
398            time_t now = time(NULL);
399
400            crashlog << "=======================================================" << std::endl;
401            crashlog << "= Time: " << std::string(ctime(&now));
402            crashlog << "=======================================================" << std::endl;
403            crashlog << std::endl;
404
405            const std::string& error = SignalHandler::getExceptionType(pExceptionInfo);
406
407            crashlog << error << std::endl;
408            crashlog << std::endl;
409
410            const std::string& callstack = SignalHandler::getStackTrace(pExceptionInfo);
411
412            crashlog << "Call stack:" << std::endl;
413            crashlog << callstack << std::endl;
414
415            crashlog.close();
416
417            // print the same information also to the console
418            COUT(1) << std::endl;
419            COUT(1) << error << std::endl;
420            COUT(1) << std::endl;
421            COUT(1) << "Call stack:" << std::endl;
422            COUT(1) << callstack << std::endl;
423
424            bExecuting = false;
425        }
426        else
427        {
428            COUT(1) << "An error occurred while writing the backtrace" << std::endl;
429        }
430
431        if (SignalHandler::getInstance().prevExceptionFilter_)
432            return SignalHandler::getInstance().prevExceptionFilter_(pExceptionInfo);
433        else
434            return EXCEPTION_CONTINUE_SEARCH;
435    }
436
437    /// Returns the stack trace for either the current function, or, if @a pExceptionInfo is not NULL, for the given exception context.
438    /* static */ std::string SignalHandler::getStackTrace(PEXCEPTION_POINTERS pExceptionInfo)
439    {
440        // Initialise the symbol table to get function names:
441        SymSetOptions
442        (
443            SYMOPT_DEFERRED_LOADS
444#ifndef ORXONOX_COMPILER_GCC
445            | SYMOPT_UNDNAME
446#endif
447        );
448        SymInitialize(GetCurrentProcess(), 0, true);
449
450        // Store the current stack frame here:
451        STACKFRAME64 frame;
452        memset(&frame, 0, sizeof(STACKFRAME64));
453
454        // Get processor information for the current thread:
455        CONTEXT context;
456        memset(&context, 0, sizeof(CONTEXT));
457
458        if (pExceptionInfo)
459        {
460            // get the context of the exception
461            context = *pExceptionInfo->ContextRecord;
462        }
463        else
464        {
465            context.ContextFlags = CONTEXT_FULL;
466
467            // Load the RTLCapture context function:
468            HINSTANCE kernel32 = LoadLibrary("Kernel32.dll");
469            typedef void (*RtlCaptureContextFunc) (CONTEXT* ContextRecord);
470            RtlCaptureContextFunc rtlCaptureContext = (RtlCaptureContextFunc) GetProcAddress(kernel32, "RtlCaptureContext");
471
472            // Capture the thread context
473            rtlCaptureContext(&context);
474        }
475
476        DWORD type;
477
478        // set the flags and initialize the stackframe struct
479#ifdef _M_IX86
480        type = IMAGE_FILE_MACHINE_I386;
481
482        frame.AddrPC.Offset         = context.Eip;              // program counter
483        frame.AddrPC.Mode           = AddrModeFlat;
484        frame.AddrFrame.Offset      = context.Ebp;              // frame pointer (for function arguments)
485        frame.AddrFrame.Mode        = AddrModeFlat;
486        frame.AddrStack.Offset      = context.Esp;              // stack pointer
487        frame.AddrStack.Mode        = AddrModeFlat;
488#elif _M_X64
489        type = IMAGE_FILE_MACHINE_AMD64;
490
491        frame.AddrPC.Offset         = context.Rip;              // program counter
492        frame.AddrPC.Mode           = AddrModeFlat;
493        frame.AddrFrame.Offset      = context.Rbp; // (or Rdi)  // frame pointer (for function arguments)
494        frame.AddrFrame.Mode        = AddrModeFlat;
495        frame.AddrStack.Offset      = context.Rsp;              // stack pointer
496        frame.AddrStack.Mode        = AddrModeFlat;
497#elif _M_IA64
498        type = IMAGE_FILE_MACHINE_IA64;
499
500        frame.AddrPC.Offset         = context.StIIP;            // program counter
501        frame.AddrPC.Mode           = AddrModeFlat;
502        frame.AddrFrame.Offset      = context.RsBSP;            // frame pointer (for function arguments) // <-- unneeded on Intel IPF, may be removed
503        frame.AddrFrame.Mode        = AddrModeFlat;
504        frame.AddrStack.Offset      = context.IntSp;            // stack pointer
505        frame.AddrStack.Mode        = AddrModeFlat;
506        frame.AddrBStore.Offset     = context.RsBSP;            // backing store
507        frame.AddrBStore.Mode       = AddrModeFlat;
508#else
509        return
510#endif
511
512        std::string output;
513
514        // Keep getting stack frames from windows till there are no more left:
515        for (int i = 0;
516            StackWalk64
517            (
518                type                      ,      // MachineType
519                GetCurrentProcess()       ,      // Process to get stack trace for
520                GetCurrentThread()        ,      // Thread to get stack trace for
521                &frame                    ,      // Where to store next stack frame
522                &context                  ,      // Pointer to processor context record
523                0                         ,      // Routine to read process memory: use the default ReadProcessMemory
524                &SymFunctionTableAccess64 ,      // Routine to access the modules symbol table
525                &SymGetModuleBase64       ,      // Routine to access the modules base address
526                0                                // Something to do with 16-bit code. Not needed.
527            );
528            ++i
529        )
530        {
531            //------------------------------------------------------------------
532            // Declare an image help symbol structure to hold symbol info and
533            // name up to 256 chars This struct is of variable lenght though so
534            // it must be declared as a raw byte buffer.
535            //------------------------------------------------------------------
536            static char symbolBuffer[sizeof(SYMBOL_INFO) + 255];
537            memset(symbolBuffer, 0, sizeof(symbolBuffer));
538
539            // Cast it to a symbol struct:
540            SYMBOL_INFO* symbol = (SYMBOL_INFO*)symbolBuffer;
541
542            // Need to set two fields of this symbol before obtaining name info:
543            symbol->SizeOfStruct    = sizeof(SYMBOL_INFO);
544            symbol->MaxNameLen      = 255;
545
546            // The displacement from the beginning of the symbol is stored here: pretty useless
547            long long unsigned int displacement = 0;
548
549            if (i < 10)
550                output += " ";
551            output += multi_cast<std::string>(i) + ": ";
552
553            // Print the function's address:
554            output += SignalHandler::pointerToString(frame.AddrPC.Offset);
555
556            // Get the symbol information from the address of the instruction pointer register:
557            if
558            (
559                SymFromAddr
560                (
561                    GetCurrentProcess() ,   // Process to get symbol information for
562                    frame.AddrPC.Offset ,   // Address to get symbol for: instruction pointer register
563                    &displacement       ,   // Displacement from the beginning of the symbol
564                    symbol                  // Where to save the symbol
565                )
566            )
567            {
568                // Add the name of the function to the function list:
569                output += " ";
570
571#ifdef ORXONOX_COMPILER_GCC
572                int status;
573                char* demangled = __cxxabiv1::__cxa_demangle(symbol->Name, NULL, NULL, &status);
574                if (demangled)
575                {
576                    output += demangled;
577                    free(demangled);
578                }
579                else
580#endif
581                {
582                    output += symbol->Name;
583                }
584            }
585
586//            output += " (+" + SignalHandler::pointerToString(displacement) + ")";
587
588            output += "\n";
589        }
590
591        // Cleanup the symbol table:
592        SymCleanup(GetCurrentProcess());
593
594        return output;
595    }
596
597    /// Returns a description of the given exception.
598    // Based on code from Dr. Mingw by José Fonseca
599    /* static */ std::string SignalHandler::getExceptionType(PEXCEPTION_POINTERS pExceptionInfo)
600    {
601        PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
602        TCHAR szModule[MAX_PATH];
603        HMODULE hModule;
604
605        std::string output = (GetModuleFileName(NULL, szModule, MAX_PATH) ? SignalHandler::getModuleName(szModule) : "Application");
606        output += " caused ";
607
608        switch(pExceptionRecord->ExceptionCode)
609        {
610            case EXCEPTION_ACCESS_VIOLATION:            output += "an Access Violation";        break;
611            case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:       output += "an Array Bound Exceeded";    break;
612            case EXCEPTION_BREAKPOINT:                  output += "a Breakpoint";               break;
613            case EXCEPTION_DATATYPE_MISALIGNMENT:       output += "a Datatype Misalignment";    break;
614            case EXCEPTION_FLT_DENORMAL_OPERAND:        output += "a Float Denormal Operand";   break;
615            case EXCEPTION_FLT_DIVIDE_BY_ZERO:          output += "a Float Divide By Zero";     break;
616            case EXCEPTION_FLT_INEXACT_RESULT:          output += "a Float Inexact Result";     break;
617            case EXCEPTION_FLT_INVALID_OPERATION:       output += "a Float Invalid Operation";  break;
618            case EXCEPTION_FLT_OVERFLOW:                output += "a Float Overflow";           break;
619            case EXCEPTION_FLT_STACK_CHECK:             output += "a Float Stack Check";        break;
620            case EXCEPTION_FLT_UNDERFLOW:               output += "a Float Underflow";          break;
621            case EXCEPTION_GUARD_PAGE:                  output += "a Guard Page";               break;
622            case EXCEPTION_ILLEGAL_INSTRUCTION:         output += "an Illegal Instruction";     break;
623            case EXCEPTION_IN_PAGE_ERROR:               output += "an In Page Error";           break;
624            case EXCEPTION_INT_DIVIDE_BY_ZERO:          output += "an Integer Divide By Zero";  break;
625            case EXCEPTION_INT_OVERFLOW:                output += "an Integer Overflow";        break;
626            case EXCEPTION_INVALID_DISPOSITION:         output += "an Invalid Disposition";     break;
627            case EXCEPTION_INVALID_HANDLE:              output += "an Invalid Handle";          break;
628            case EXCEPTION_NONCONTINUABLE_EXCEPTION:    output += "a Noncontinuable Exception"; break;
629            case EXCEPTION_PRIV_INSTRUCTION:            output += "a Privileged Instruction";   break;
630            case EXCEPTION_SINGLE_STEP:                 output += "a Single Step";              break;
631            case EXCEPTION_STACK_OVERFLOW:              output += "a Stack Overflow";           break;
632            case DBG_CONTROL_C:                         output += "a Control+C";                break;
633            case DBG_CONTROL_BREAK:                     output += "a Control+Break";            break;
634            case DBG_TERMINATE_THREAD:                  output += "a Terminate Thread";         break;
635            case DBG_TERMINATE_PROCESS:                 output += "a Terminate Process";        break;
636            case RPC_S_UNKNOWN_IF:                      output += "an Unknown Interface";       break;
637            case RPC_S_SERVER_UNAVAILABLE:              output += "a Server Unavailable";       break;
638            default:                                    output += "an Unknown Exception (" + SignalHandler::pointerToString(pExceptionRecord->ExceptionCode) + ")"; break;
639        }
640
641        // Now print information about where the fault occured
642        output += " at location " + SignalHandler::pointerToString(pExceptionRecord->ExceptionAddress);
643        if ((hModule = (HMODULE) SignalHandler::getModuleBase((DWORD) pExceptionRecord->ExceptionAddress)) && GetModuleFileName(hModule, szModule, MAX_PATH))
644        {
645            output += " in module ";
646            output += SignalHandler::getModuleName(szModule);
647        }
648
649        // If the exception was an access violation, print out some additional information, to the error log and the debugger.
650        if(pExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && pExceptionRecord->NumberParameters >= 2)
651        {
652            output += " ";
653            output += pExceptionRecord->ExceptionInformation[0] ? "writing to" : "reading from";
654            output += " location ";
655            output += SignalHandler::pointerToString(pExceptionRecord->ExceptionInformation[1]);
656        }
657
658        return output;
659    }
660
661    /// Strips the directories from the path to the module and returns the module's name only.
662    /* static */ std::string SignalHandler::getModuleName(const std::string& path)
663    {
664        return path.substr(path.find_last_of('\\') + 1);
665    }
666
667    /// Retrieves the base address of the module that contains the specified address.
668    // Code from Dr. Mingw by José Fonseca
669    /* static */ DWORD SignalHandler::getModuleBase(DWORD dwAddress)
670    {
671        MEMORY_BASIC_INFORMATION Buffer;
672
673        return VirtualQuery((LPCVOID) dwAddress, &Buffer, sizeof(Buffer)) ? (DWORD) Buffer.AllocationBase : 0;
674    }
675
676    /// Converts a value to string, formatted as pointer.
677    template <typename T>
678    /* static */ std::string SignalHandler::pointerToString(T pointer)
679    {
680        std::ostringstream oss;
681
682        oss << std::setw(8) << std::setfill('0') << std::hex << pointer;
683
684        return std::string("0x") + oss.str();
685    }
686
687    /// Converts a pointer to string.
688    template <typename T>
689    /* static */ std::string SignalHandler::pointerToString(T* pointer)
690    {
691        std::ostringstream oss;
692
693        oss << pointer;
694
695        return oss.str();
696    }
697}
698
699#endif
Note: See TracBrowser for help on using the repository browser.