1 #ifndef MP_STACK_H 2 #define MP_STACK_H 3 4 5 /* 6 * mpatrol 7 * A library for controlling and tracing dynamic memory allocations. 8 * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Library General Public 12 * License as published by the Free Software Foundation; either 13 * version 2 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Library General Public License for more details. 19 * 20 * You should have received a copy of the GNU Library General Public 21 * License along with this library; if not, write to the Free 22 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 23 * MA 02111-1307, USA. 24 */ 25 26 27 /* 28 * Call stacks. This module attempts to provide a common interface for 29 * traversing the function call stack at a specific point during execution. 30 */ 31 32 33 /* 34 * $Id: stack.h,v 1.15 2002/01/08 20:13:59 graeme Exp $ 35 */ 36 37 38 #include "config.h" 39 #include <stddef.h> 40 #include <signal.h> 41 #if !MP_BUILTINSTACK_SUPPORT 42 #if MP_LIBRARYSTACK_SUPPORT && TARGET == TARGET_WINDOWS 43 #include <windows.h> 44 #include <imagehlp.h> 45 #endif /* MP_LIBRARYSTACK_SUPPORT && TARGET */ 46 #endif /* MP_BUILTINSTACK_SUPPORT */ 47 48 49 #if !MP_BUILTINSTACK_SUPPORT 50 #if MP_LIBRARYSTACK_SUPPORT 51 #if SYSTEM == SYSTEM_HPUX 52 /* HP/UX provides functions to traverse the PA/RISC stack frames. This 53 * structure only makes visible the stack frame entries that we need to 54 * use - all the rest are simply reserved. 55 */ 56 57 typedef struct frameinfo 58 { 59 unsigned int size; /* frame size */ 60 unsigned int sp; /* stack pointer */ 61 unsigned int ps; /* program counter space */ 62 unsigned int pc; /* program counter */ 63 unsigned int dp; /* data pointer */ 64 unsigned int res[6]; /* reserved entries */ 65 } 66 frameinfo; 67 #endif /* SYSTEM */ 68 #else /* MP_LIBRARYSTACK_SUPPORT */ 69 #if TARGET == TARGET_UNIX && ARCH == ARCH_MIPS 70 /* The MIPS architecture does not save and restore a frame pointer on the 71 * stack so the stack pointer and program counter must be used to obtain 72 * this information. 73 */ 74 75 typedef struct frameinfo 76 { 77 unsigned int sp; /* stack pointer */ 78 unsigned int ra; /* return address */ 79 } 80 frameinfo; 81 #endif /* TARGET && ARCH */ 82 #endif /* MP_LIBRARYSTACK_SUPPORT */ 83 #endif /* MP_BUILTINSTACK_SUPPORT */ 84 85 86 /* A stackinfo structure provides information about the currently selected 87 * stack frame. 88 */ 89 90 typedef struct stackinfo 91 { 92 void *frame; /* current frame handle */ 93 void *addr; /* current return address */ 94 #if MP_BUILTINSTACK_SUPPORT 95 void *frames[MP_MAXSTACK]; /* array of frame pointers */ 96 void *addrs[MP_MAXSTACK]; /* array of return addresses */ 97 size_t index; /* current stack index */ 98 #elif MP_LIBRARYSTACK_SUPPORT 99 #if TARGET == TARGET_UNIX 100 #if SYSTEM == SYSTEM_HPUX 101 struct frameinfo next; /* next frame handle */ 102 #elif SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_TRU64 103 struct sigcontext next; /* next frame handle */ 104 #endif /* SYSTEM */ 105 #elif TARGET == TARGET_WINDOWS 106 STACKFRAME next; /* next frame handle */ 107 #endif /* TARGET */ 108 #else /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT */ 109 #if TARGET == TARGET_UNIX && ARCH == ARCH_MIPS 110 struct frameinfo next; /* next frame handle */ 111 #else /* TARGET && ARCH */ 112 void *next; /* next frame handle */ 113 #endif /* TARGET && ARCH */ 114 #endif /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT */ 115 void *first; /* first frame information */ 116 } 117 stackinfo; 118 119 120 #ifdef __cplusplus 121 extern "C" 122 { 123 #endif /* __cplusplus */ 124 125 126 MP_EXPORT void __mp_newframe(stackinfo *, void *); 127 MP_EXPORT int __mp_getframe(stackinfo *); 128 129 130 #ifdef __cplusplus 131 } 132 #endif /* __cplusplus */ 133 134 135 #endif /* MP_STACK_H */ 136