Changeset 212fc04 in git for omalloc/omDebug.c
- Timestamp:
- Nov 22, 1999, 7:13:00 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 6ea5825fc0e0bfabf56883aee9dac9b5bbe415fe
- Parents:
- e6908a0f43ea328a1aa0c3942e8d309db7de26d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/omDebug.c
re6908a0 r212fc04 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omDebug.c,v 1. 1.1.1 1999-11-18 17:45:53obachman Exp $6 * Version: $Id: omDebug.c,v 1.2 1999-11-22 18:12:58 obachman Exp $ 7 7 *******************************************************************/ 8 8 #include "omConfig.h" … … 12 12 #include "omDebug.h" 13 13 14 static int omdCheckBinAddrSize(void* addr, omBin bin, size_t size, 15 int level, const char* fn, const int l); 16 static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin, 17 const char* fn, const int l); 18 static const char* omdTestBinAddrSize(void* addr, omBin bin, size_t size, 19 int level); 14 static int omdCheckBinAddrSize(void* addr, size_t size, int level); 15 static int omdPrintBinError(const char* msg, void* addr, size_t size, 16 omBin bin); 17 static const char* omdTestBinAddrSize(void* addr, size_t size, int level, 18 omBin *bin); 20 19 static const char* omdTestBin(omBin bin, int level); 21 20 static const char* omdTestBinPage(omBinPage page, int level); 22 static int omdIsKnown Bin(omBin bin);21 static int omdIsKnownTopBin(omBin bin); 23 22 24 23 /******************************************************************* … … 27 26 * 28 27 *******************************************************************/ 29 int omdCheckBinAddr(void* addr, omBin bin, int level, 30 const char* fn, const int l) 31 { 32 if (! omdCheckBinAddrSize(addr, bin, bin->sizeW*SIZEOF_LONG, level, fn, l)) 28 int omdCheckBinAddr(void* addr, int level) 29 { 30 return omdCheckBinAddrSize(addr, 0, level); 31 } 32 33 int omdCheckBlockAddr(void* addr, size_t size, int level) 34 { 35 if (size == 0) 36 { 37 omError("0 size"); 33 38 return 0; 34 return omdCheckBins(level - 2, fn, l); 35 } 36 37 int omdCheckBlockAddr(void* addr, size_t size, int level, 38 const char* fn, const int l) 39 { 40 omBin bin = omSize2Bin(size); 41 if (bin != om_LargeBin && 42 ! omdCheckBinAddrSize(addr, bin, size, level, fn, l)) 43 return 0; 44 return omdCheckBins(level - 2, fn, l); 45 } 46 47 int omdCheckChunkAddr(void* addr, int level, const char* fn, const int l) 39 } 40 if (size <= OM_MAX_BLOCK_SIZE) 41 return omdCheckBinAddrSize(addr, size, level); 42 else 43 return 1; 44 } 45 46 int omdCheckChunkAddr(void* addr, int level) 48 47 { 49 48 omBinPage page; 50 49 addr = addr - SIZEOF_OM_ALIGNMENT; 51 50 page = *((omBinPage*) addr); 52 if (page != om_LargePage &&53 ! omdCheckBinAddr(addr, omBinOfPage(page), level, fn, l))54 return 0;55 return omdCheckBins(level - 2, fn, l);51 if (page != om_LargePage) 52 return omdCheckBinAddrSize(addr, -1, level); 53 else 54 return 1; 56 55 } 57 56 … … 61 60 * 62 61 *******************************************************************/ 63 static int omdIsKnown Bin(omBin bin)62 static int omdIsKnownTopBin(omBin bin) 64 63 { 65 64 int i = 0; … … 81 80 } 82 81 83 int omdCheckBin(omBin bin, int level , const char* fn, const int l)82 int omdCheckBin(omBin bin, int level) 84 83 { 85 84 const char* msg = omdTestBin(bin, level); 86 85 if (msg != NULL) 87 86 { 88 if (fn != NULL) omdPrintBinError(msg, NULL, 0, bin, fn, l);87 omdPrintBinError(msg, NULL, 0, bin); 89 88 return 0; 90 89 } … … 92 91 } 93 92 94 int omdCheckBins(int level , const char* fn, const int l)93 int omdCheckBins(int level) 95 94 { 96 95 if (level <= 0) … … 106 105 for (i=0; i<= OM_MAX_BIN_INDEX; i++) 107 106 { 108 if (! omdCheckBin(&om_StaticBin[i], level , fn, l)) return 0;107 if (! omdCheckBin(&om_StaticBin[i], level)) return 0; 109 108 } 110 109 s_bin = om_SpecBin; 111 110 while (s_bin != NULL) 112 111 { 113 if (! omdCheckBin(s_bin->bin, level , fn, l)) return 0;112 if (! omdCheckBin(s_bin->bin, level)) return 0; 114 113 s_bin = s_bin->next; 115 114 } … … 124 123 *******************************************************************/ 125 124 126 void* omdCheckAllocBin(omBin bin, const int zero, int level, 127 const char* fn, const int l) 125 void* omdCheckAllocBin(omBin bin, const int zero, int level) 128 126 { 129 127 void* res; 130 128 131 omdCheckBins(level-2 , fn, l);129 omdCheckBins(level-2); 132 130 133 131 if (zero) … … 136 134 __omTypeAllocBin(void*, res, bin); 137 135 138 omdCheckBinAddr(res, bin, level-1,fn, l);139 omdCheckBins(level-2 , fn, l);136 omdCheckBinAddr(res, level-1); 137 omdCheckBins(level-2); 140 138 141 139 return res; 142 140 } 143 141 144 void omdCheckFreeBin(void* addr, omBin bin, 145 int level, const char* fn, const int l) 146 { 147 omdCheckBins(level-2, fn, l); 148 149 if (omdCheckBinAddr(addr, bin, level, fn, l)) 142 void omdCheckFreeBin(void* addr, int level) 143 { 144 omdCheckBins(level-2); 145 146 if (omdCheckBinAddr(addr, level)) 150 147 __omFreeBin(addr); 151 148 152 omdCheckBin(bin, level - 1, fn, l); 153 omdCheckBins(level - 2, fn, l); 154 } 155 156 void* omdCheckAllocBlock(size_t size, const int zero, 157 int level, const char* fn, const int l) 149 omdCheckBins(level - 2); 150 } 151 152 void* omdCheckAllocBlock(size_t size, const int zero, int level) 158 153 { 159 154 void* res; … … 161 156 if (level > 0 && size <= 0) 162 157 { 163 if (fn != NULL)omdPrintBinError("requested AllocBlock size <= 0",164 NULL, size, NULL, fn, l);158 omdPrintBinError("requested AllocBlock size <= 0", 159 NULL, size, NULL); 165 160 size = 1; 166 161 } 167 162 168 omdCheckBins(level-2 , fn, l);163 omdCheckBins(level-2); 169 164 170 165 if (zero) … … 173 168 __omTypeAllocBlock(void*, res, size); 174 169 175 omdCheckBlockAddr(res, size, level - 1 , fn, l);176 omdCheckBins(level - 2 , fn, l);170 omdCheckBlockAddr(res, size, level - 1); 171 omdCheckBins(level - 2); 177 172 178 173 return res; 179 174 } 180 175 181 void omdCheckFreeBlock(void* addr, size_t size, 182 int level, const char* fn, const int l) 183 { 184 omdCheckBins(level - 2, fn, l); 185 if (! omdCheckBlockAddr(addr, size, level, fn, l)) return; 176 void omdCheckFreeBlock(void* addr, size_t size, int level) 177 { 178 omdCheckBins(level - 2); 179 if (! omdCheckBlockAddr(addr, size, level)) return; 186 180 187 181 __omFreeBlock(addr, size); 188 182 189 omdCheckBins(level - 2, fn, l); 190 } 191 192 193 void* omdCheckAllocChunk(size_t size, const int zero, 194 int level, const char* fn, const int l) 183 omdCheckBins(level - 2); 184 } 185 186 187 void* omdCheckAllocChunk(size_t size, const int zero, int level) 195 188 { 196 189 void* res; … … 198 191 if (level > 0 && size <= 0) 199 192 { 200 if (fn != NULL)omdPrintBinError("requested AllocBlock size <= 0",201 NULL, size, NULL, fn, l);193 omdPrintBinError("requested AllocBlock size <= 0", 194 NULL, size, NULL); 202 195 size = 1; 203 196 } 204 omdCheckBins(level - 2 , fn, l);197 omdCheckBins(level - 2); 205 198 206 199 if (zero) … … 209 202 __omTypeAllocChunk(void*, res, size); 210 203 211 omdCheckChunkAddr(res, level - 1 , fn, l);212 omdCheckBins(level - 2 , fn, l);204 omdCheckChunkAddr(res, level - 1); 205 omdCheckBins(level - 2); 213 206 214 207 return res; 215 208 } 216 209 217 void omdCheckFreeChunk(void* addr, int level , const char* fn, const int l)218 { 219 if (! omdCheckChunkAddr(addr, level , fn, l)) return;210 void omdCheckFreeChunk(void* addr, int level) 211 { 212 if (! omdCheckChunkAddr(addr, level)) return; 220 213 221 214 __omFreeChunk(addr); 222 215 223 omdCheckBins(level - 2 , fn, l);216 omdCheckBins(level - 2); 224 217 } 225 218 … … 230 223 * 231 224 *******************************************************************/ 232 static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin, 233 const char* fn, const int l) 225 static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin) 234 226 { 235 227 fprintf(stderr, 236 "***BinError: 237 %s: occured for addr:%p (%d) bin:%p (%ld:%ld) in %s:%d\n", 238 msg, addr, size, (void*) bin, 228 "for addr:%p (%d) bin:%p (%ld:%ld)\n", 229 addr, size, (void*) bin, 239 230 (bin != NULL ? bin->max_blocks : 0), 240 (bin != NULL ? bin->sizeW : 0), fn, l); 231 (bin != NULL ? bin->sizeW : 0)); 232 fflush(stderr); 241 233 return 0; 242 234 } 243 235 244 static int omdCheckBinAddrSize(void* addr, omBin bin, size_t size,245 int level, const char* fn, const int l) 246 { 247 const char* msg = omdTestBinAddrSize(addr, bin, size, level);236 static int omdCheckBinAddrSize(void* addr, size_t size, int level) 237 { 238 omBin bin = NULL; 239 const char* msg = omdTestBinAddrSize(addr, size, level, &bin); 248 240 if (msg != NULL) 249 return omdPrintBinError(msg, addr, size, bin , fn, l);241 return omdPrintBinError(msg, addr, size, bin); 250 242 else 251 243 return 1; … … 255 247 /* Check that addr is activ (used) adr of bin */ 256 248 static const char* 257 omdTestBinAddrSize(void* addr, omBin bin, size_t size, int level) 258 { 249 omdTestBinAddrSize(void* addr, size_t size, int level, omBin* r_bin) 250 { 251 omBin bin; 259 252 omBinPage page; 260 253 omBin h_bin; 261 254 const char* msg; 262 255 263 264 256 if (level <= 0) return NULL; 265 257 266 258 if (addr == NULL) return omError("NULL addr"); 259 260 if (size > OM_MAX_BLOCK_SIZE) return NULL; 261 262 bin = omGetTopBinOfAddr(addr); 263 267 264 if (bin == NULL) return omError("NULL Bin"); 268 265 269 if (! omdIsKnown Bin(bin))266 if (! omdIsKnownTopBin(bin)) 270 267 return omError("Addr not from Bin (Bin unknown)"); 268 *r_bin = bin; 271 269 272 270 if ((msg = omdTestBin(bin, level - 1)) != NULL) return msg; 273 271 274 272 // check for right bin 275 if (omIsStaticBin(bin)) 276 h_bin = omSize2Bin(size); 277 else 278 h_bin = omGetSpecBin(size); 279 if (bin != h_bin) return omError("size is wrong"); 280 if (! omIsStaticBin(bin)) omUnGetSpecBin(&h_bin); 273 if (size > 0) 274 { 275 if (omIsStaticBin(bin)) 276 h_bin = omSize2Bin(size); 277 else 278 h_bin = omGetSpecBin(size); 279 if (bin != h_bin) return omError("size is wrong"); 280 if (! omIsStaticBin(bin)) omUnGetSpecBin(&h_bin); 281 } 281 282 282 283 // check page … … 285 286 286 287 // look that page is in queue of pages of this Bin 287 h_bin = omBinOfPage(page); 288 h_bin = omGetBinOfPage(page); 289 *r_bin = h_bin; 288 290 if ( ! omIsOnGList(h_bin->last_page, prev, page)) 289 291 return omError("page of addr not from this Bin"); … … 347 349 { 348 350 void* current = page->current; 351 int i = 1; 349 352 if (current != NULL && 350 353 omListLength(current) != bin->max_blocks - page->used_blocks - 1) … … 362 365 != 0) 363 366 return omError("current has unaligned adress"); 364 current = *((void**) (current + SIZEOF_VOIDP)); 367 current = *((void**) current); 368 i++; 365 369 } 366 370 } … … 379 383 if (bin == NULL) return omError("NULL Bin"); 380 384 381 if (! omdIsKnown Bin(bin)) return omError("Bin unknown");385 if (! omdIsKnownTopBin(bin)) return omError("TopBin unknown"); 382 386 383 387 if (level > 2 && … … 440 444 return omError("Sticky of page wrong"); 441 445 442 if (om BinOfPage(page) != bin)446 if (omGetBinOfPage(page) != bin) 443 447 return omError("Bin of Page wrong"); 444 448 … … 457 461 { 458 462 if (page->current == NULL || 459 page->used_blocks ==0 ||463 page->used_blocks < 0 || 460 464 page->used_blocks == bin->max_blocks - 1) 461 465 return omError("used_blocks and current of upage out of sync");
Note: See TracChangeset
for help on using the changeset viewer.