00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "config.h"
00043 #include "dwarf_incl.h"
00044 #include <sys/types.h>
00045
00046 #include <stdlib.h>
00047 #include <stdio.h>
00048 #if ! defined(BUILD_OS_DARWIN)
00049 #include <malloc.h>
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058 #include "dwarf_line.h"
00059 #include "dwarf_global.h"
00060 #include "dwarf_arange.h"
00061 #include "dwarf_abbrev.h"
00062 #include "dwarf_die_deliv.h"
00063 #include "dwarf_frame.h"
00064 #include "dwarf_loc.h"
00065 #include "dwarf_funcs.h"
00066 #include "dwarf_types.h"
00067 #include "dwarf_vars.h"
00068 #include "dwarf_weaks.h"
00069
00070 static void _dwarf_free_special_error(Dwarf_Ptr space);
00071 #ifdef DWARF_SIMPLE_MALLOC
00072 static void _dwarf_simple_malloc_add_to_list(Dwarf_Debug dbg,
00073 Dwarf_Ptr addr,
00074 unsigned long size,
00075 short alloc_type);
00076 static void _dwarf_simple_malloc_delete_from_list(Dwarf_Debug dbg,
00077 Dwarf_Ptr space,
00078 short alloc_type);
00079 void _dwarf_simple_malloc_botch(int err);
00080
00081 #endif
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #if _MIPS_SIM == _MIPS_SIM_NABI32
00108 #define _DW_FAC 2
00109 #define _DW_PS sizeof(void *)
00110 #else
00111 #define _DW_FAC 1
00112 #define _DW_PS sizeof(void *)
00113 #endif
00114 #define _DW_RESERVE (_DW_FAC * _DW_PS)
00115
00116
00117
00118 #define ROUND_SIZE(inputsize) \
00119 (((inputsize) % (_DW_RESERVE)) == 0 ? \
00120 (inputsize): \
00121 ((inputsize) + \
00122 (_DW_RESERVE) - ((inputsize) % (_DW_RESERVE)) ))
00123
00124 #define ROUND_SIZE_WITH_POINTER(i_size) (ROUND_SIZE(i_size) + _DW_RESERVE)
00125 #define BASE_ALLOC 64
00126 #define BIG_ALLOC 128
00127
00128
00129
00130
00131
00132
00133
00134 struct ial_s {
00135 int ia_al_num;
00136
00137
00138
00139
00140
00141 int ia_struct_size;
00142
00143
00144
00145 int ia_base_count;
00146 };
00147
00148 static const
00149 struct ial_s index_into_allocated[ALLOC_AREA_INDEX_TABLE_MAX] = {
00150 {0, 1, 1},
00151 {0, 1, 1,},
00152 {1, sizeof(Dwarf_Loc), BASE_ALLOC}
00153 ,
00154 {2, sizeof(Dwarf_Locdesc), BASE_ALLOC}
00155 ,
00156 {0, 1, 1}
00157 ,
00158 {0, 1, 1}
00159 ,
00160 {3, sizeof(Dwarf_Block), BASE_ALLOC}
00161 ,
00162 {0, 1, 1}
00163 ,
00164 {4, sizeof(struct Dwarf_Die_s), BIG_ALLOC},
00165 {5, sizeof(struct Dwarf_Line_s), BIG_ALLOC},
00166
00167 {6, sizeof(struct Dwarf_Attribute_s), BIG_ALLOC * 2},
00168
00169 {0, 1, 1},
00170 {0, 1, 1},
00171 {7, sizeof(struct Dwarf_Global_s), BIG_ALLOC},
00172
00173
00174 {8, sizeof(struct Dwarf_Error_s), BASE_ALLOC},
00175
00176
00177 {0, 1, 1},
00178 {0, 1, 1},
00179 {9, sizeof(struct Dwarf_Arange_s), BASE_ALLOC},
00180
00181
00182 {10, sizeof(struct Dwarf_Abbrev_s), BIG_ALLOC},
00183
00184
00185 {11, sizeof(Dwarf_Frame_Op), BIG_ALLOC}
00186 ,
00187 {12, sizeof(struct Dwarf_Cie_s), BASE_ALLOC},
00188
00189 {13, sizeof(struct Dwarf_Fde_s), BASE_ALLOC},
00190
00191 {0, 1, 1},
00192 {0, 1, 1},
00193 {14, sizeof(struct Dwarf_Global_s), BIG_ALLOC},
00194
00195 {15, sizeof(struct Dwarf_Global_s), BIG_ALLOC},
00196
00197
00198 {16, sizeof(struct Dwarf_Global_s), BIG_ALLOC},
00199
00200 {17, sizeof(struct Dwarf_Global_s), BASE_ALLOC},
00201
00202 {0, 1, 1},
00203 {18, sizeof(struct Dwarf_Abbrev_List_s), BIG_ALLOC},
00204
00205 {19, sizeof(struct Dwarf_Chain_s), BIG_ALLOC},
00206
00207
00208 {20, sizeof(struct Dwarf_CU_Context_s), BASE_ALLOC},
00209
00210 {21, sizeof(struct Dwarf_Frame_s), BASE_ALLOC},
00211
00212
00213 {22, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC},
00214
00215 {23, sizeof(struct Dwarf_File_Entry_s), BASE_ALLOC},
00216
00217 {24, sizeof(struct Dwarf_Line_Context_s), BASE_ALLOC},
00218
00219 {25, sizeof(struct Dwarf_Loc_Chain_s), BASE_ALLOC},
00220
00221 {26, ABBREV_HASH_TABLE_SIZE * 2 * sizeof(Dwarf_Abbrev_List),
00222 BASE_ALLOC}
00223 ,
00224
00225
00226
00227
00228
00229
00230
00231 {27, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC},
00232
00233 {28, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC},
00234
00235 {29, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC},
00236
00237 {30, sizeof(struct Dwarf_Global_Context_s), BASE_ALLOC},
00238
00239 };
00240
00241 #ifndef DWARF_SIMPLE_MALLOC
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 static Dwarf_Ptr
00278 _dwarf_find_memory(Dwarf_Alloc_Hdr alloc_hdr)
00279 {
00280
00281 Dwarf_Small *ret_mem = 0;
00282
00283
00284 Dwarf_Alloc_Area alloc_area;
00285
00286
00287 Dwarf_Signed mem_block_size;
00288
00289
00290 Dwarf_Small *mem_block;
00291
00292
00293
00294
00295
00296 alloc_area = alloc_hdr->ah_last_alloc_area;
00297 if (alloc_area == NULL || alloc_area->aa_free_structs_in_chunk == 0)
00298 for (alloc_area = alloc_hdr->ah_alloc_area_head;
00299 alloc_area != NULL; alloc_area = alloc_area->aa_next) {
00300
00301 if (alloc_area->aa_free_structs_in_chunk > 0) {
00302 break;
00303 }
00304
00305 }
00306
00307 if (alloc_area != NULL) {
00308 alloc_area->aa_free_structs_in_chunk--;
00309
00310 if (alloc_area->aa_free_list != NULL) {
00311 ret_mem = alloc_area->aa_free_list;
00312
00313
00314
00315
00316
00317
00318 alloc_area->aa_free_list =
00319 ((Dwarf_Free_List) ret_mem)->fl_next;
00320 } else if (alloc_area->aa_blob_start < alloc_area->aa_blob_end) {
00321 ret_mem = alloc_area->aa_blob_start;
00322
00323
00324
00325
00326
00327 *(Dwarf_Alloc_Area *) ret_mem = alloc_area;
00328 ret_mem += _DW_RESERVE;
00329
00330 alloc_area->aa_blob_start += alloc_hdr->ah_bytes_one_struct;
00331 } else {
00332
00333
00334
00335 #ifdef DEBUG
00336 fprintf(stderr, "libdwarf Internal error start %x end %x\n",
00337 (int) alloc_area->aa_blob_start,
00338 (int) alloc_area->aa_blob_end);
00339 #endif
00340 }
00341 }
00342
00343
00344 if (ret_mem == 0) {
00345 Dwarf_Word rounded_area_hdr_size;
00346
00347 alloc_hdr->ah_chunks_allocated++;
00348
00349 {
00350
00351 unsigned long v = sizeof(struct Dwarf_Alloc_Area_s);
00352
00353 rounded_area_hdr_size = ROUND_SIZE(v);
00354 }
00355
00356
00357
00358
00359 mem_block_size = alloc_hdr->ah_bytes_malloc_per_chunk +
00360 rounded_area_hdr_size;
00361
00362 mem_block = malloc(mem_block_size);
00363 if (mem_block == NULL) {
00364 return (NULL);
00365 }
00366
00367
00368
00369
00370
00371
00372 alloc_area = (Dwarf_Alloc_Area) mem_block;
00373 alloc_area->aa_prev = 0;
00374 if (alloc_hdr->ah_alloc_area_head != NULL) {
00375 alloc_hdr->ah_alloc_area_head->aa_prev = alloc_area;
00376 }
00377 alloc_area->aa_free_list = 0;
00378 alloc_area->aa_next = alloc_hdr->ah_alloc_area_head;
00379 alloc_hdr->ah_alloc_area_head = alloc_area;
00380
00381 alloc_area->aa_alloc_hdr = alloc_hdr;
00382 alloc_area->aa_free_structs_in_chunk =
00383 (Dwarf_Sword) alloc_hdr->ah_structs_per_chunk - 1;
00384 if (alloc_area->aa_free_structs_in_chunk < 1) {
00385
00386
00387 #ifdef DEBUG
00388 fprintf(stderr,
00389 "libdwarf Internal error: free structs in chunk %d\n",
00390 (int) alloc_area->aa_free_structs_in_chunk);
00391 #endif
00392 return NULL;
00393 }
00394
00395
00396
00397
00398 ret_mem = mem_block + rounded_area_hdr_size;
00399 alloc_area->aa_blob_start =
00400 ret_mem + alloc_hdr->ah_bytes_one_struct;
00401 alloc_area->aa_blob_end = mem_block + mem_block_size;
00402
00403
00404
00405
00406
00407 *(Dwarf_Alloc_Area *) ret_mem = alloc_area;
00408 ret_mem += _DW_RESERVE;
00409 }
00410
00411 alloc_hdr->ah_last_alloc_area = alloc_area;
00412 alloc_hdr->ah_struct_user_holds++;
00413 memset(ret_mem,0, alloc_hdr->ah_bytes_one_struct - _DW_RESERVE);
00414 return (ret_mem);
00415 }
00416
00417 #endif
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 Dwarf_Ptr
00437 _dwarf_get_alloc(Dwarf_Debug dbg,
00438 Dwarf_Small alloc_type, Dwarf_Unsigned count)
00439 {
00440 Dwarf_Alloc_Hdr alloc_hdr;
00441
00442 Dwarf_Ptr ret_mem;
00443
00444 Dwarf_Signed size = 0;
00445 unsigned int index;
00446 unsigned int type = alloc_type;
00447
00448 if (dbg == NULL) {
00449 return (NULL);
00450 }
00451
00452 if (type >= ALLOC_AREA_INDEX_TABLE_MAX) {
00453
00454 return NULL;
00455 }
00456 index = index_into_allocated[type].ia_al_num;
00457
00458
00459
00460
00461
00462
00463
00464 if (index == 0) {
00465 if (alloc_type == DW_DLA_STRING) {
00466 size = count;
00467 } else if (alloc_type == DW_DLA_LIST) {
00468 size = count * sizeof(Dwarf_Ptr);
00469 } else if (alloc_type == DW_DLA_FRAME_BLOCK) {
00470 size = count * sizeof(Dwarf_Frame_Op);
00471 } else if (alloc_type == DW_DLA_LOC_BLOCK) {
00472 size = count * sizeof(Dwarf_Loc);
00473 } else if (alloc_type == DW_DLA_ADDR) {
00474 size = count *
00475 (sizeof(Dwarf_Addr) > sizeof(Dwarf_Off) ?
00476 sizeof(Dwarf_Addr) : sizeof(Dwarf_Off));
00477 } else if (alloc_type == DW_DLA_ERROR) {
00478 return _dwarf_special_no_dbg_error_malloc();
00479 } else {
00480
00481
00482 #ifdef DEBUG
00483 fprintf(stderr,
00484 "libdwarf Internal error: type %d unexpected\n",
00485 (int) type);
00486 #endif
00487 }
00488 } else {
00489 alloc_hdr = &dbg->de_alloc_hdr[index];
00490 if (alloc_hdr->ah_bytes_one_struct > 0) {
00491 #ifdef DWARF_SIMPLE_MALLOC
00492 size = alloc_hdr->ah_bytes_one_struct;
00493 #else
00494 return (_dwarf_find_memory(alloc_hdr));
00495 #endif
00496
00497 } else {
00498
00499 if (type == DW_DLA_ERROR) {
00500
00501
00502 return _dwarf_special_no_dbg_error_malloc();
00503 } else {
00504
00505
00506 #ifdef DWARF_SIMPLE_MALLOC
00507 _dwarf_simple_malloc_botch(3);
00508 #endif
00509 #ifdef DEBUG
00510 fprintf(stderr,
00511 "libdwarf Internal error: Type %d unexpected\n",
00512 (int) type);
00513 #endif
00514 }
00515 }
00516 }
00517
00518 ret_mem = malloc(size);
00519 #ifdef DWARF_SIMPLE_MALLOC
00520 _dwarf_simple_malloc_add_to_list(dbg,ret_mem,(unsigned long)size,
00521 alloc_type);
00522 #endif
00523 if (ret_mem != NULL)
00524 memset(ret_mem,0, size);
00525
00526 return (ret_mem);
00527 }
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 void
00559 dwarf_dealloc(Dwarf_Debug dbg,
00560 Dwarf_Ptr space, Dwarf_Unsigned alloc_type)
00561 {
00562 Dwarf_Alloc_Hdr alloc_hdr;
00563 Dwarf_Alloc_Area alloc_area;
00564 unsigned int type = alloc_type;
00565 unsigned int index;
00566
00567 if (space == NULL) {
00568 return;
00569 }
00570 if (alloc_type == DW_DLA_ERROR) {
00571
00572
00573 alloc_area =
00574 *(Dwarf_Alloc_Area *) ((char *) space - _DW_RESERVE);
00575 if (alloc_area == 0) {
00576
00577
00578
00579
00580
00581 _dwarf_free_special_error(space);
00582 return;
00583 }
00584
00585 }
00586 if (dbg == NULL) {
00587
00588
00589 return;
00590 }
00591 if (type >= ALLOC_AREA_INDEX_TABLE_MAX) {
00592
00593 return;
00594 }
00595
00596 index = index_into_allocated[alloc_type].ia_al_num;
00597
00598
00599
00600 if (index == 0) {
00601 if (alloc_type == DW_DLA_STRING) {
00602 if ((Dwarf_Small *) space >= dbg->de_debug_info &&
00603 (Dwarf_Small *) space <
00604 dbg->de_debug_info + dbg->de_debug_info_size)
00605 return;
00606
00607 if (dbg->de_debug_line != NULL &&
00608 (Dwarf_Small *) space >= dbg->de_debug_line &&
00609 (Dwarf_Small *) space <
00610 dbg->de_debug_line + dbg->de_debug_line_size)
00611 return;
00612
00613 if (dbg->de_debug_pubnames != NULL &&
00614 (Dwarf_Small *) space >= dbg->de_debug_pubnames &&
00615 (Dwarf_Small *) space <
00616 dbg->de_debug_pubnames + dbg->de_debug_pubnames_size)
00617 return;
00618
00619 if (dbg->de_debug_frame != NULL &&
00620 (Dwarf_Small *) space >= dbg->de_debug_frame &&
00621 (Dwarf_Small *) space <
00622 dbg->de_debug_frame + dbg->de_debug_frame_size)
00623 return;
00624
00625 if (dbg->de_debug_str != NULL &&
00626 (Dwarf_Small *) space >= dbg->de_debug_str &&
00627 (Dwarf_Small *) space <
00628 dbg->de_debug_str + dbg->de_debug_str_size)
00629 return;
00630
00631 if (dbg->de_debug_funcnames != NULL &&
00632 (Dwarf_Small *) space >= dbg->de_debug_funcnames &&
00633 (Dwarf_Small *) space <
00634 dbg->de_debug_funcnames + dbg->de_debug_funcnames_size)
00635 return;
00636
00637 if (dbg->de_debug_typenames != NULL &&
00638 (Dwarf_Small *) space >= dbg->de_debug_typenames &&
00639 (Dwarf_Small *) space <
00640 dbg->de_debug_typenames + dbg->de_debug_typenames_size)
00641 return;
00642
00643 if (dbg->de_debug_varnames != NULL &&
00644 (Dwarf_Small *) space >= dbg->de_debug_varnames &&
00645 (Dwarf_Small *) space <
00646 dbg->de_debug_varnames + dbg->de_debug_varnames_size)
00647 return;
00648
00649 if (dbg->de_debug_weaknames != NULL &&
00650 (Dwarf_Small *) space >= dbg->de_debug_weaknames &&
00651 (Dwarf_Small *) space <
00652 dbg->de_debug_weaknames + dbg->de_debug_weaknames_size)
00653 return;
00654
00655 free(space);
00656 return;
00657 }
00658
00659 if (alloc_type == DW_DLA_LIST ||
00660 alloc_type == DW_DLA_FRAME_BLOCK ||
00661 alloc_type == DW_DLA_LOC_BLOCK ||
00662 alloc_type == DW_DLA_ADDR) {
00663
00664 free(space);
00665 return;
00666 }
00667
00668
00669 #ifdef DWARF_SIMPLE_MALLOC
00670 _dwarf_simple_malloc_botch(4);
00671 #endif
00672 return;
00673
00674 }
00675
00676 #ifdef DWARF_SIMPLE_MALLOC
00677 _dwarf_simple_malloc_delete_from_list(dbg, space, alloc_type);
00678 free(space);
00679 #else
00680 alloc_hdr = &dbg->de_alloc_hdr[index];
00681
00682
00683
00684 alloc_area = *(Dwarf_Alloc_Area *) ((char *) space - _DW_RESERVE);
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695 if (alloc_area->aa_alloc_hdr != alloc_hdr) {
00696
00697
00698
00699 #ifdef DEBUG
00700 fprintf(stderr,
00701 "libdwarf Internal error: type %d hdr mismatch %x %x area ptr %x\n",
00702 (int) alloc_type,
00703 (int) alloc_area->aa_alloc_hdr,
00704 (int) alloc_hdr, (int) alloc_area);
00705 #endif
00706 return;
00707 }
00708
00709 alloc_hdr->ah_struct_user_holds--;
00710 alloc_area->aa_free_structs_in_chunk++;
00711
00712
00713
00714 if (alloc_area->aa_free_structs_in_chunk ==
00715 alloc_hdr->ah_structs_per_chunk) {
00716 if (alloc_area->aa_prev != NULL) {
00717 alloc_area->aa_prev->aa_next = alloc_area->aa_next;
00718 } else {
00719 alloc_hdr->ah_alloc_area_head = alloc_area->aa_next;
00720 }
00721
00722 if (alloc_area->aa_next != NULL) {
00723 alloc_area->aa_next->aa_prev = alloc_area->aa_prev;
00724 }
00725
00726 alloc_hdr->ah_chunks_allocated--;
00727
00728 if (alloc_area == alloc_hdr->ah_last_alloc_area) {
00729 alloc_hdr->ah_last_alloc_area = NULL;
00730 }
00731 memset(alloc_area,0, sizeof(*alloc_area));
00732 free(alloc_area);
00733 }
00734
00735 else {
00736 ((Dwarf_Free_List) space)->fl_next = alloc_area->aa_free_list;
00737 alloc_area->aa_free_list = space;
00738 }
00739 #endif
00740 }
00741
00742
00743
00744
00745
00746
00747 Dwarf_Debug
00748 _dwarf_get_debug(void
00749 )
00750 {
00751 Dwarf_Debug dbg;
00752
00753 dbg = (Dwarf_Debug) malloc(sizeof(struct Dwarf_Debug_s));
00754 if (dbg == NULL)
00755 return (NULL);
00756 else
00757 memset(dbg,0, sizeof(struct Dwarf_Debug_s));
00758
00759 return (dbg);
00760 }
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 Dwarf_Debug
00800 _dwarf_setup_debug(Dwarf_Debug dbg)
00801 {
00802 int i;
00803
00804 for (i = 1; i <= MAX_DW_DLA; i++) {
00805 const struct ial_s *ialp = &index_into_allocated[i];
00806 unsigned int hdr_index = ialp->ia_al_num;
00807 Dwarf_Word str_size = ialp->ia_struct_size;
00808 Dwarf_Word str_count = ialp->ia_base_count;
00809 Dwarf_Word rnded_size = ROUND_SIZE_WITH_POINTER(str_size);
00810
00811 Dwarf_Alloc_Hdr alloc_hdr = &dbg->de_alloc_hdr[hdr_index];
00812
00813 alloc_hdr->ah_bytes_one_struct = (Dwarf_Half) rnded_size;
00814
00815
00816 alloc_hdr->ah_structs_per_chunk = str_count;
00817 alloc_hdr->ah_bytes_malloc_per_chunk = rnded_size * str_count;
00818 }
00819 return (dbg);
00820 }
00821
00822
00823
00824
00825
00826 void
00827 dwarf_print_memory_stats(Dwarf_Debug dbg)
00828 {
00829 Dwarf_Alloc_Hdr alloc_hdr;
00830 Dwarf_Shalf i;
00831
00832
00833
00834
00835 char *alloc_type_name[MAX_DW_DLA + 1] = {
00836 "",
00837 "DW_DLA_STRING",
00838 "DW_DLA_LOC",
00839 "DW_DLA_LOCDESC",
00840 "DW_DLA_ELLIST",
00841 "DW_DLA_BOUNDS",
00842 "DW_DLA_BLOCK",
00843 "DW_DLA_DEBUG",
00844 "DW_DLA_DIE",
00845 "DW_DLA_LINE",
00846 "DW_DLA_ATTR",
00847 "DW_DLA_TYPE",
00848 "DW_DLA_SUBSCR",
00849 "DW_DLA_GLOBAL",
00850 "DW_DLA_ERROR",
00851 "DW_DLA_LIST",
00852 "DW_DLA_LINEBUF",
00853 "DW_DLA_ARANGE",
00854 "DW_DLA_ABBREV",
00855 "DW_DLA_FRAME_OP",
00856 "DW_DLA_CIE",
00857 "DW_DLA_FDE",
00858 "DW_DLA_LOC_BLOCK",
00859 "DW_DLA_FRAME_BLOCK",
00860 "DW_DLA_FUNC",
00861 "DW_DLA_TYPENAME",
00862 "DW_DLA_VAR",
00863 "DW_DLA_WEAK",
00864 "DW_DLA_ADDR",
00865 "DW_DLA_ABBREV_LIST",
00866 "DW_DLA_CHAIN",
00867 "DW_DLA_CU_CONTEXT",
00868 "DW_DLA_FRAME",
00869 "DW_DLA_GLOBAL_CONTEXT",
00870 "DW_DLA_FILE_ENTRY",
00871 "DW_DLA_LINE_CONTEXT",
00872 "DW_DLA_LOC_CHAIN",
00873 "DW_DLA_HASH_TABLE",
00874 "DW_DLA_FUNC_CONTEXT",
00875 "DW_DLA_TYPENAME_CONTEXT",
00876 "DW_DLA_VAR_CONTEXT",
00877 "DW_DLA_WEAK_CONTEXT"
00878 };
00879
00880 if (dbg == NULL)
00881 return;
00882
00883 printf("Size of Dwarf_Debug %4ld bytes\n",
00884 (long) sizeof(*dbg));
00885 printf("Size of Dwarf_Alloc_Hdr_s %4ld bytes\n",
00886 (long) sizeof(struct Dwarf_Alloc_Hdr_s));
00887 printf("size of Dwarf_Alloc_Area_s %4ld bytes\n",
00888 (long) sizeof(struct Dwarf_Alloc_Area_s));
00889
00890 printf(" Alloc Type Curr Structs byt str\n");
00891 printf(" ---------- ---- ------- per per\n");
00892 for (i = 1; i <= MAX_DW_DLA; i++) {
00893 int indx = index_into_allocated[i].ia_al_num;
00894
00895 alloc_hdr = &dbg->de_alloc_hdr[indx];
00896 if (alloc_hdr->ah_bytes_one_struct != 1) {
00897 printf("%2d %-25s %6d %8d %6d %6d\n",
00898 (int) i,
00899 alloc_type_name[i],
00900 (int) alloc_hdr->ah_chunks_allocated,
00901 (int) alloc_hdr->ah_struct_user_holds,
00902 (int) alloc_hdr->ah_bytes_malloc_per_chunk,
00903 (int) alloc_hdr->ah_structs_per_chunk);
00904 }
00905 }
00906 }
00907
00908
00909 #ifndef DWARF_SIMPLE_MALLOC
00910
00911
00912
00913
00914
00915
00916 static void
00917 _dwarf_recursive_free(Dwarf_Alloc_Area alloc_area)
00918 {
00919 if (alloc_area->aa_next != NULL) {
00920 _dwarf_recursive_free(alloc_area->aa_next);
00921 }
00922
00923 alloc_area->aa_next = 0;
00924 alloc_area->aa_prev = 0;
00925 free(alloc_area);
00926 }
00927 #endif
00928
00929
00930
00931
00932
00933
00934
00935
00936 int
00937 _dwarf_free_all_of_one_debug(Dwarf_Debug dbg)
00938 {
00939 Dwarf_Alloc_Hdr alloc_hdr;
00940 Dwarf_Shalf i;
00941
00942 if (dbg == NULL)
00943 return (DW_DLV_ERROR);
00944
00945 #ifdef DWARF_SIMPLE_MALLOC
00946 if(dbg->de_simple_malloc_base) {
00947 struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base;
00948 while( smp)
00949 {
00950 int i;
00951 struct simple_malloc_record_s *prev_smp = 0;
00952
00953 for(i = 0; i < smp->sr_used; ++i) {
00954 struct simple_malloc_entry_s *cur;
00955 cur = &smp->sr_entry[i];
00956 if(cur->se_addr != 0) {
00957 free(cur->se_addr);
00958 cur->se_addr = 0;
00959 }
00960 }
00961 prev_smp = smp;
00962 smp = smp->sr_next;
00963 free(prev_smp);
00964 }
00965 dbg->de_simple_malloc_base = 0;
00966 dbg->de_simple_malloc_current = 0;
00967 }
00968 #else
00969 for (i = 1; i < ALLOC_AREA_REAL_TABLE_MAX; i++) {
00970 int indx = i;
00971
00972 alloc_hdr = &dbg->de_alloc_hdr[indx];
00973 if (alloc_hdr->ah_alloc_area_head != NULL) {
00974 _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head);
00975 }
00976 }
00977
00978 #endif
00979
00980 memset(dbg,0, sizeof(*dbg));
00981 free(dbg);
00982 return (DW_DLV_OK);
00983 }
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993 struct Dwarf_Error_s *
00994 _dwarf_special_no_dbg_error_malloc(void)
00995 {
00996
00997 union u {
00998 Dwarf_Alloc_Area ptr_not_used;
00999 struct Dwarf_Error_s base_not_used;
01000 char data_space[sizeof(struct Dwarf_Error_s) +
01001 (_DW_RESERVE * 2)];
01002 };
01003 char *mem;
01004
01005 mem = malloc(sizeof(union u));
01006
01007 if (mem == 0) {
01008 return 0;
01009
01010 }
01011 memset(mem,0, sizeof(union u));
01012 mem += _DW_RESERVE;
01013 return (struct Dwarf_Error_s *) mem;
01014 }
01015
01016
01017
01018 static void
01019 _dwarf_free_special_error(Dwarf_Ptr space)
01020 {
01021 char *mem = (char *) space;
01022
01023 mem -= _DW_RESERVE;
01024 free(mem);
01025 }
01026
01027
01028 #ifdef DWARF_SIMPLE_MALLOC
01029
01030
01031 void
01032 _dwarf_simple_malloc_botch(int err)
01033 {
01034 }
01035 static void
01036 _dwarf_simple_malloc_add_to_list(Dwarf_Debug dbg,
01037 Dwarf_Ptr addr,
01038 unsigned long size,
01039 short alloc_type)
01040 {
01041 struct simple_malloc_record_s *cur;
01042 struct simple_malloc_entry_s *newentry;
01043 if (!dbg->de_simple_malloc_current) {
01044
01045 dbg->de_simple_malloc_current =
01046 malloc(sizeof(struct simple_malloc_record_s));
01047 if(!dbg->de_simple_malloc_current) {
01048 return;
01049 }
01050 memset(dbg->de_simple_malloc_current,
01051 0,
01052 sizeof(struct simple_malloc_record_s));
01053 dbg->de_simple_malloc_base = dbg->de_simple_malloc_current;
01054 }
01055 cur = dbg->de_simple_malloc_current;
01056
01057 if(cur->sr_used >= DSM_BLOCK_COUNT) {
01058
01059
01060
01061
01062 struct simple_malloc_record_s *newblock =
01063 malloc(sizeof(struct simple_malloc_record_s));
01064 if(!newblock) {
01065 return;
01066 }
01067 memset(newblock,0, sizeof(struct simple_malloc_record_s));
01068
01069
01070
01071 dbg->de_simple_malloc_current = newblock;
01072 newblock->sr_next = cur;
01073 cur = newblock;
01074 }
01075 newentry = &cur->sr_entry[cur->sr_used];
01076 newentry->se_addr = addr;
01077 newentry->se_size = size;
01078 newentry->se_type = alloc_type;
01079 ++cur->sr_used;
01080 }
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094 static void
01095 _dwarf_simple_malloc_delete_from_list(Dwarf_Debug dbg,
01096 Dwarf_Ptr space,
01097 short alloc_type)
01098 {
01099 if(space == 0) {
01100 _dwarf_simple_malloc_botch(6);
01101 }
01102 if(dbg->de_simple_malloc_base) {
01103 struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base;
01104 while( smp)
01105 {
01106 int i;
01107
01108 for(i = 0; i < smp->sr_used; ++i) {
01109 struct simple_malloc_entry_s *cur;
01110 cur = &smp->sr_entry[i];
01111 if(cur->se_addr == space) {
01112 if(cur->se_type != alloc_type ) {
01113 _dwarf_simple_malloc_botch(0);
01114 }
01115 cur->se_addr = 0;
01116 return;
01117 }
01118 }
01119 smp = smp->sr_next;
01120 }
01121 }
01122
01123 _dwarf_simple_malloc_botch(1);
01124 return;
01125
01126 }
01127 #endif
01128