00001 // Copyright (c) 2005, Google Inc. 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are 00006 // met: 00007 // 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above 00011 // copyright notice, this list of conditions and the following disclaimer 00012 // in the documentation and/or other materials provided with the 00013 // distribution. 00014 // * Neither the name of Google Inc. nor the names of its 00015 // contributors may be used to endorse or promote products derived from 00016 // this software without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 // --- 00031 // Author: Sanjay Ghemawat 00032 // 00033 // Routine to extract the current stack trace. 00034 00035 #ifndef _GOOGLE_STACKTRACE_H 00036 #define _GOOGLE_STACKTRACE_H 00037 00038 // Annoying stuff for windows -- makes sure clients can import these functions 00039 #ifndef PERFTOOLS_DLL_DECL 00040 # ifdef WIN32 00041 # define PERFTOOLS_DLL_DECL __declspec(dllimport) 00042 # else 00043 # define PERFTOOLS_DLL_DECL 00044 # endif 00045 #endif 00046 00047 00048 // Skips the most recent "skip_count" stack frames (also skips the 00049 // frame generated for the "GetStackTrace" routine itself), and then 00050 // records the pc values for up to the next "max_depth" frames in 00051 // "result". Returns the number of values recorded in "result". 00052 // 00053 // Example: 00054 // main() { foo(); } 00055 // foo() { bar(); } 00056 // bar() { 00057 // void* result[10]; 00058 // int depth = GetStackTrace(result, 10, 1); 00059 // } 00060 // 00061 // The GetStackTrace call will skip the frame for "bar". It will 00062 // return 2 and will produce pc values that map to the following 00063 // procedures: 00064 // result[0] foo 00065 // result[1] main 00066 // (Actually, there may be a few more entries after "main" to account for 00067 // startup procedures.) 00068 // 00069 // This routine may return fewer stack trace entries than are 00070 // available. 00071 extern PERFTOOLS_DLL_DECL int GetStackTrace(void** result, int max_depth, 00072 int skip_count); 00073 00074 #endif /* _GOOGLE_STACKTRACE_H */