src/foundation/ZStackCrawl.h

00001 /*  @(#) $Id: ZStackCrawl.h,v 1.5 2006/07/23 22:00:42 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2005 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStackCrawl__
00026 #define __ZStackCrawl__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZCONFIG_API.h"
00030 #include "ZCONFIG_SPI.h"
00031 
00032 #ifndef ZCONFIG_API_Avail__StackCrawl
00033 #       if defined(linux) && ZCONFIG(Processor, x86)
00034 #               define ZCONFIG_API_Avail__StackCrawl 1
00035 #       endif
00036 #       if ZCONFIG(OS, Win32)
00037 #               define ZCONFIG_API_Avail__StackCrawl ZCONFIG_SPI_Enabled(imagehlp)
00038 #       endif
00039 #endif
00040 
00041 #ifndef ZCONFIG_API_Avail__StackCrawl
00042 #       define ZCONFIG_API_Avail__StackCrawl 0
00043 #endif
00044 
00045 #ifndef ZCONFIG_API_Desired__StackCrawl
00046 #       define ZCONFIG_API_Desired__StackCrawl 1
00047 #endif
00048 
00049 #if ZCONFIG_API_Enabled(StackCrawl)
00050 #include "ZTypes.h"
00051 
00052 #include <string>
00053 #include <vector>
00054 
00055 // =================================================================================================
00056 #pragma mark -
00057 #pragma mark * ZStackCrawl
00058 
00059 class ZStackCrawl
00060         {
00061 public:
00062         enum { kMaxCountParams = 8 };
00063 
00064         class Frame
00065                 {
00066         public:
00067                 const void* fPC;
00068                 size_t fOffset;
00069                 size_t fCountParams;
00070                 uint32 fParams[kMaxCountParams];
00071                 std::string fName;
00072                 };
00073 
00074 private:
00075         class pFrame_t
00076                 {
00077         public:
00078                 const void* fPC;
00079                 size_t fOffset;
00080                 size_t fCountParams;
00081                 uint32 fParams[kMaxCountParams];
00082                 };
00083 
00084 public:
00085 
00086         ZStackCrawl();
00087         ~ZStackCrawl();
00088 
00089         size_t Count() const;
00090         Frame At(size_t iIndex) const;
00091 
00092         #if defined(linux) && ZCONFIG(Processor, x86)
00093                 static void sPopulateStackFrames(std::vector<ZStackCrawl::pFrame_t>& oFrames);
00094         #endif
00095 
00096         #if ZCONFIG(OS, Win32)
00097                 static void sPopulateStackFrames(std::vector<ZStackCrawl::pFrame_t>& oFrames);
00098         #endif
00099 
00100 private:
00101         std::vector<pFrame_t> fFrames;
00102 
00103         #if defined(linux) && ZCONFIG(Processor, x86)
00104                 class AllSymbols;
00105                 mutable AllSymbols* fAllSymbols;
00106         #endif
00107         };
00108 
00109 #endif // ZCONFIG_API_Enabled(StackCrawl)
00110 
00111 #endif // __ZStackCrawl__

Generated on Thu Jul 26 11:21:51 2007 for ZooLib by  doxygen 1.4.7