home *** CD-ROM | disk | FTP | other *** search
- /*
- dwarf_alloc.c
- $Revision: 1.21 $ $Date: 1994/06/17 02:39:01 $
- */
-
- #include <sys/types.h>
- #include <malloc.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include "dwarf_incl.h"
- #include "bstring.h"
-
- /*
- These files are included to get the sizes
- of structs to set the ah_alloc_size field
- of the Dwarf_Alloc_Hdr_s structs for each
- allocation type.
- */
- #include "dwarf_line.h"
- #include "dwarf_global.h"
- #include "dwarf_arange.h"
- #include "dwarf_abbrev.h"
- #include "dwarf_die_deliv.h"
- #include "dwarf_frame.h"
- #include "dwarf_loc.h"
- #include "dwarf_funcs.h"
- #include "dwarf_types.h"
- #include "dwarf_vars.h"
- #include "dwarf_weaks.h"
-
-
- /*
- This function is given a pointer to the header
- structure that is used to allocate 1 struct of
- the type given by alloc_type. It first checks
- if a struct is available in its free list. If
- not, it checks if 1 is available in its blob,
- which is a chunk of memory that is reserved for
- its use. If not, it malloc's a chunk. The
- initial part of it is used to store the end
- address of the chuck, and also to keep track
- of the number of free structs in that chunk.
- This information is used for freeing the chunk
- when all the structs in it are free.
-
- Assume all input arguments have been validated.
-
- This function can be used only to allocate 1
- struct of the given type.
-
- It returns a pointer to the struct that the
- user can use. It returns NULL only when it
- is out of free structs, and cannot malloc
- any more. The struct returned is zero-ed.
-
- A pointer to the chunk that the struct belongs
- to is stored in the bytes preceding the
- returned address. Since this pointer it
- never overwritten, when a struct is allocated
- from the free_list this pointer does not
- have to be written. In the 2 other cases,
- where the struct is allocated from a new
- chunk, or the blob, a pointer to the chunk
- is written.
- */
- Dwarf_Ptr
- _dwarf_find_memory (
- Dwarf_Alloc_Hdr alloc_hdr,
- Dwarf_Small alloc_type
- )
- {
- /* Pointer to the struct allocated. */
- Dwarf_Small *ret_mem;
-
- /* Pointer to info about chunks allocated. */
- Dwarf_Alloc_Area alloc_area;
-
- /* Size of chunk malloc'ed when no free structs left. */
- Dwarf_Signed mem_block_size;
-
- /* Pointer to block malloc'ed. */
- Dwarf_Small *mem_block;
-
- /* ***** BEGIN CODE ***** */
-
- /*
- If every struct in the chunks malloc'ed is busy, go
- directly to mallocing a new chunk. Otherwise, check
- the alloc_area from which the last allocation was
- made. If that is not succesful, then search the list
- of alloc_area's from alloc_header.
- */
- if (alloc_hdr->ah_struct_alloc_count > 0 &&
- alloc_hdr->ah_struct_alloc_count % alloc_hdr->ah_alloc_num == 0)
- alloc_area = NULL;
- else {
- alloc_area = alloc_hdr->ah_last_alloc_area;
- if (alloc_area == NULL || alloc_area->aa_free_count == 0)
- for (alloc_area = alloc_hdr->ah_alloc_area_head;
- alloc_area != NULL && alloc_area->aa_free_count == 0;
- alloc_area = alloc_area->aa_next);
- }
-
- if (alloc_area != NULL) {
- alloc_area->aa_free_count--;
-
- if (alloc_area->aa_free_list != NULL) {
- ret_mem = alloc_area->aa_free_list;
-
- /*
- Update the free list. The initial part of the struct
- is used to hold a pointer to the next struct on the free
- list. In this way, the free list chain is maintained at
- 0 memory cost.
- */
- alloc_area->aa_free_list =
- ((Dwarf_Free_List)alloc_area->aa_free_list)->fl_next;
- }
-
- else if (alloc_area->aa_blob_start < alloc_area->aa_blob_end) {
- ret_mem = alloc_area->aa_blob_start;
-
- /*
- Store pointer to chunk this struct belongs to in the
- first few bytes. Return pointer to bytes after this
- pointer storage.
- */
- *(Dwarf_Alloc_Area *)ret_mem = alloc_area;
- ret_mem += sizeof(void *);
-
- alloc_area->aa_blob_start += alloc_hdr->ah_alloc_size;
- }
- }
-
- /* New memory has to malloc'ed since there are no free structs. */
- else {
-
- /*
- Increment count of chunks currently malloc'ed
- for this allocation type, and update the maximum
- count if is smaller than the current count.
- */
- alloc_hdr->ah_curr_alloc++;
- if (alloc_hdr->ah_curr_alloc > alloc_hdr->ah_max_alloc)
- alloc_hdr->ah_max_alloc = alloc_hdr->ah_curr_alloc;
-
- /*
- Allocate memory to contain the required number
- of structs and the Dwarf_Alloc_Area_s to control
- it.
- */
- mem_block_size = alloc_hdr->ah_malloc_length +
- sizeof(struct Dwarf_Alloc_Area_s);
-
- mem_block = malloc(mem_block_size);
- if (mem_block == NULL) {
- return(NULL);
- }
-
- /*
- Zero out the Dwarf_Alloc_Area_s part of the
- chunk. The rest is zero-ed out as each struct
- is returned to the user.
- */
- bzero(mem_block, sizeof(struct Dwarf_Alloc_Area_s));
-
- /*
- Attach the Dwarf_Alloc_Area_s struct to
- the list of chunks malloc'ed for this
- struct type.
- */
- alloc_area = (Dwarf_Alloc_Area)mem_block;
- if (alloc_hdr->ah_alloc_area_head != NULL)
- alloc_hdr->ah_alloc_area_head->aa_prev = alloc_area;
- alloc_area->aa_next = alloc_hdr->ah_alloc_area_head;
- alloc_hdr->ah_alloc_area_head = alloc_area;
-
- alloc_area->aa_alloc_hdr = alloc_hdr;
- alloc_area->aa_free_count = alloc_hdr->ah_alloc_num - 1;
-
- /*
- The struct returned begins immediately after
- the Dwarf_Alloc_Area_s struct.
- */
- ret_mem = mem_block + sizeof(struct Dwarf_Alloc_Area_s);
- alloc_area->aa_blob_start = ret_mem + alloc_hdr->ah_alloc_size;
- alloc_area->aa_blob_end = mem_block + mem_block_size;
-
- /*
- Store pointer to chunk this struct belongs to in the
- first few bytes. Return pointer to bytes after this
- pointer storage.
- */
- *(Dwarf_Alloc_Area *)ret_mem = alloc_area;
- ret_mem += sizeof(void *);
- }
-
- alloc_hdr->ah_last_alloc_area = alloc_area;
- alloc_hdr->ah_struct_alloc_count++;
- bzero(ret_mem, alloc_hdr->ah_alloc_size - sizeof(void *));
- return(ret_mem);
- }
-
-
- /*
- This function returns a pointer to a region
- of memory. For alloc_types that are not
- strings or lists of pointers, only 1 struct
- can be requested at a time. This is indicated
- by an input count of 1. For strings, count
- equals the length of the string it will
- contain, i.e it is the length of the string
- plus 1 for the terminating null. For lists
- of pointers, count is equal to the number of
- pointers. For DW_DLA_FRAME_BLOCK, and
- DW_DLA_LOC_BLOCK allocation types also, count
- is the count of the number of structs needed.
-
- This function cannot be used to allocate a
- Dwarf_Debug_s struct.
- */
- Dwarf_Ptr
- _dwarf_get_alloc (
- Dwarf_Debug dbg,
- Dwarf_Small alloc_type,
- Dwarf_Unsigned count
- )
- {
- Dwarf_Alloc_Hdr alloc_hdr;
-
- Dwarf_Ptr ret_mem;
-
- Dwarf_Signed size = 0;
-
- if (dbg == NULL || dbg->de_alloc_hdr == NULL)
- return(NULL);
-
- if (alloc_type == DW_DLA_STRING) {
- size = count;
- }else if (alloc_type == DW_DLA_LIST) {
- size = count * sizeof(Dwarf_Ptr);
- }else if (alloc_type == DW_DLA_FRAME_BLOCK) {
- size = count * sizeof(Dwarf_Frame_Op);
-
- }else if (alloc_type == DW_DLA_LOC_BLOCK) {
- size = count * sizeof(Dwarf_Loc);
- }else if (alloc_type == DW_DLA_ADDR) {
- /* need space for either Dwarf_Off or Dwarf_Addr array */
- int lsize = sizeof(Dwarf_Addr);
- if(sizeof(Dwarf_Off) > lsize) {
- lsize = sizeof(Dwarf_Off);
- }
- size = count * lsize;
- } else if (alloc_type == DW_DLA_HASH_TABLE){
- size = ABBREV_HASH_TABLE_SIZE * 2 * sizeof(Dwarf_Abbrev_List);
-
- } else if (alloc_type > DW_DLA_STRING && alloc_type <= MAX_DW_DLA) {
- alloc_hdr = dbg->de_alloc_hdr[alloc_type];
- if (alloc_hdr != NULL)
- return(_dwarf_find_memory(alloc_hdr, alloc_type));
-
- /*
- This is for situations where there is a Dwarf Error
- even before _dwarf_setup_debug() has executed, namely
- in _dwarf_setup(). The reason _dwarf_setup_debug()
- has to execute after _dwarf_setup() is to take advantage
- of the size information that _dwarf_setup() can provide.
- In this case, a Dwarf_Error_s struct is simply malloc'ed.
- This memory will most probably leak.
- */
- if (alloc_type == DW_DLA_ERROR)
- size = sizeof(struct Dwarf_Error_s);
- else
- return(NULL);
- }
-
- ret_mem = malloc(size);
- if (ret_mem != NULL) bzero(ret_mem, size);
- return(ret_mem);
- }
-
-
- /*
- This function is used to deallocate a region of memory
- that was obtained by a call to _dwarf_get_alloc. Note
- that though dwarf_dealloc() is a public function,
- _dwarf_get_alloc() isn't.
-
- For lists, typically arrays of pointers, it is assumed
- that the space was allocated by a direct call to malloc,
- and so a straight free() is done. This is also the case
- for variable length blocks such as DW_DLA_FRAME_BLOCK
- and DW_DLA_LOC_BLOCK.
-
- For strings, the pointer might point to a string in
- .debug_info or .debug_string. After this is checked,
- and if found not to be the case, a free() is done,
- again on the assumption that a malloc was used to
- obtain the space.
-
- For other types of structs, a pointer to the chunk that
- the struct was allocated out of, is present in the bytes
- preceding the pointer passed in. For this chunk it is
- checked whether all the structs in that chunk are now free.
- If so, the entire chunk is free_ed. Otherwise, the space
- is added to the free list for that chunk, and the free count
- incremented.
-
- This function does not return anything.
- */
- void
- dwarf_dealloc (
- Dwarf_Debug dbg,
- Dwarf_Ptr space,
- Dwarf_Unsigned alloc_type
- )
- {
- Dwarf_Alloc_Hdr alloc_hdr;
- Dwarf_Alloc_Area alloc_area;
-
- if (dbg == NULL || dbg->de_alloc_hdr == NULL || space == NULL) {
- return;
- }
-
- /*
- A string pointer may point into .debug_info or
- .debug_string. Otherwise, they are directly malloc'ed.
- */
- if (alloc_type == DW_DLA_STRING) {
- if ((Dwarf_Small *)space >= dbg->de_debug_info &&
- (Dwarf_Small *)space < dbg->de_debug_info + dbg->de_debug_info_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_line &&
- (Dwarf_Small *)space < dbg->de_debug_line + dbg->de_debug_line_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_pubnames &&
- (Dwarf_Small *)space <
- dbg->de_debug_pubnames + dbg->de_debug_pubnames_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_frame &&
- (Dwarf_Small *)space <
- dbg->de_debug_frame + dbg->de_debug_frame_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_str &&
- (Dwarf_Small *)space < dbg->de_debug_str + dbg->de_debug_str_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_funcnames &&
- (Dwarf_Small *)space <
- dbg->de_debug_funcnames + dbg->de_debug_funcnames_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_typenames &&
- (Dwarf_Small *)space <
- dbg->de_debug_typenames + dbg->de_debug_typenames_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_varnames &&
- (Dwarf_Small *)space <
- dbg->de_debug_varnames + dbg->de_debug_varnames_size)
- return;
-
- if ((Dwarf_Small *)space >= dbg->de_debug_weaknames &&
- (Dwarf_Small *)space <
- dbg->de_debug_weaknames + dbg->de_debug_weaknames_size)
- return;
-
- free(space);
- return;
- }
-
- if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK ||
- alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_HASH_TABLE
- || alloc_type == DW_DLA_ADDR
- ) {
- free(space);
- return;
- }
-
-
- if (alloc_type < DW_DLA_STRING || alloc_type > MAX_DW_DLA) {
- return;
- }
-
- /* Ah_alloc_num equal 1 indicates an unused alloc type. */
- alloc_hdr = dbg->de_alloc_hdr[alloc_type];
- if (alloc_hdr->ah_alloc_num == 1) {
- return;
- }
-
- /* Get pointer to Dwarf_Alloc_Area this struct came from. */
- alloc_area = *(Dwarf_Alloc_Area *)((char *)space - sizeof(void *));
- #if 0
- if(alloc_area == 0) {
- /* ERROR! This should not be null!
- We can either abort, or let it coredump below.
- Or return, pretending all is well.
- We go on, letting program crash. Is caller error.
- */
- }
- #endif
-
- /*
- Check that the alloc_hdr field of the alloc_area we have
- is pointing to the right alloc_hdr. This is used to catch
- use of incorrect deallocation code by the user.
- */
- if (alloc_area->aa_alloc_hdr != alloc_hdr)
- return;
-
- alloc_hdr->ah_struct_alloc_count--;
- alloc_area->aa_free_count++;
-
- /*
- Give chunk back to malloc only when every struct is
- free'd, and there is more than one chunk malloc'ed
- for the type.
- */
- if (alloc_area->aa_free_count == alloc_hdr->ah_alloc_num &&
- alloc_hdr->ah_struct_alloc_count > 0) {
-
- if (alloc_area->aa_prev != NULL)
- alloc_area->aa_prev->aa_next = alloc_area->aa_next;
- else
- alloc_hdr->ah_alloc_area_head = alloc_area->aa_next;
-
- if (alloc_area->aa_next != NULL)
- alloc_area->aa_next->aa_prev = alloc_area->aa_prev;
-
- alloc_hdr->ah_curr_alloc--;
-
- if (alloc_area == alloc_hdr->ah_last_alloc_area)
- alloc_hdr->ah_last_alloc_area = NULL;
- free(alloc_area);
- }
-
- else {
- ((Dwarf_Free_List)space)->fl_next = alloc_area->aa_free_list;
- alloc_area->aa_free_list = space;
- }
- }
-
-
- /*
- Allocates space for a Dwarf_Debug_s struct,
- since one does not exist.
- */
- Dwarf_Debug
- _dwarf_get_debug (
- void
- )
- {
- Dwarf_Debug dbg;
-
- dbg = (Dwarf_Debug)malloc(sizeof(struct Dwarf_Debug_s));
- if (dbg == NULL) return(NULL);
- else bzero(dbg, sizeof(struct Dwarf_Debug_s));
-
- return(dbg);
- }
-
-
- /*
- Sets up the Dwarf_Debug_s struct for all the
- allocation types currently defined.
- Allocation types DW_DLA_STRING, DW_DLA_LIST,
- DW_DLA_FRAME_BLOCK, DW_DLA_LOC_BLOCK are
- malloc'ed directly.
-
- This routine should be called after _dwarf_setup(),
- so that information about the sizes of the Dwarf
- sections can be used to decide the number of
- structs of each type malloc'ed.
-
- Also DW_DLA_ELLIST, DW_DLA_BOUNDS, DW_DLA_TYPE,
- DW_DLA_SUBSCR, DW_DLA_LINEBUF allocation types
- are currently not used. Also, DW_DLA_DEBUG
- structs cannot be deallocated using this routine.
- The ah_alloc_size and ah_alloc_num fields for
- these types have been set to 1 for efficiency
- in dwarf_get_alloc().
-
- Ah_alloc_num should be greater than 1 for all
- types that are currently being used.
-
- Therefore, for these allocation types the
- ah_alloc_size, and ah_alloc_num fields do not
- need to be initialized.
-
- Being an internal routine, assume proper dbg.
- */
- Dwarf_Debug
- _dwarf_setup_debug (
- Dwarf_Debug dbg
- )
- {
- Dwarf_Alloc_Hdr alloc_hdr;
-
- Dwarf_Shalf i;
-
- for (i = 1; i <= MAX_DW_DLA; i++) {
-
- alloc_hdr = (Dwarf_Alloc_Hdr)malloc(sizeof(struct Dwarf_Alloc_Hdr_s));
- if (alloc_hdr == NULL) return(NULL);
- else bzero(alloc_hdr, sizeof(struct Dwarf_Alloc_Hdr_s));
-
- dbg->de_alloc_hdr[i] = alloc_hdr;
-
- switch (i) {
- case DW_DLA_STRING :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_LOC :
- alloc_hdr->ah_alloc_size = ROUND_SIZE_WITH_POINTER(Dwarf_Loc);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(Dwarf_Loc);
- break;
-
- case DW_DLA_LOCDESC :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(Dwarf_Locdesc);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(Dwarf_Locdesc);
- break;
-
- case DW_DLA_ELLIST :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_BOUNDS :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_BLOCK :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(Dwarf_Block);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(Dwarf_Block);
- break;
-
- case DW_DLA_DEBUG :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_DIE :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Die_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Die_s);
- break;
-
- case DW_DLA_LINE :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Line_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Line_s);
- break;
-
- case DW_DLA_ATTR :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Attribute_s);
- alloc_hdr->ah_alloc_num = 256;
- alloc_hdr->ah_malloc_length =
- 256 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Attribute_s);
- break;
-
- case DW_DLA_TYPE :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_SUBSCR :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_GLOBAL :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Global_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Global_s);
- break;
-
- case DW_DLA_ERROR :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Error_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Error_s);
- break;
-
- case DW_DLA_LIST :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_LINEBUF :
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_ARANGE :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Arange_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Arange_s);
- break;
-
- case DW_DLA_ABBREV :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Abbrev_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Abbrev_s);
- break;
-
- case DW_DLA_ABBREV_LIST :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Abbrev_List_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length = 128 *
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Abbrev_List_s);
- break;
-
- case DW_DLA_CHAIN :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Chain_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Chain_s);
- break;
-
- case DW_DLA_CU_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_CU_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_CU_Context_s);
- break;
-
- case DW_DLA_FRAME :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Frame_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Frame_s);
- break;
-
- case DW_DLA_FRAME_OP :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(Dwarf_Frame_Op);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(Dwarf_Frame_Op);
- break;
-
- case DW_DLA_CIE :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Cie_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Cie_s);
- break;
-
- case DW_DLA_FDE :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Fde_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Fde_s);
- break;
-
- case DW_DLA_GLOBAL_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Global_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length = 64 *
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Global_Context_s);
- break;
-
- case DW_DLA_FILE_ENTRY :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_File_Entry_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_File_Entry_s);
- break;
-
- case DW_DLA_LINE_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Line_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Line_Context_s);
- break;
-
- case DW_DLA_LOC_CHAIN :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Loc_Chain_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Loc_Chain_s);
- break;
-
- case DW_DLA_LOC_BLOCK :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_FRAME_BLOCK :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_HASH_TABLE :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_FUNC :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Func_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Func_s);
- break;
-
- case DW_DLA_FUNC_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Func_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Func_Context_s);
- break;
-
- case DW_DLA_TYPENAME :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Type_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Type_s);
- break;
-
- case DW_DLA_TYPENAME_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Type_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Type_Context_s);
- break;
-
- case DW_DLA_VAR :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Var_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Var_s);
- break;
-
- case DW_DLA_VAR_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Var_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Var_Context_s);
- break;
-
- case DW_DLA_WEAK :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Weak_s);
- alloc_hdr->ah_alloc_num = 128;
- alloc_hdr->ah_malloc_length =
- 128 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Weak_s);
- break;
-
- case DW_DLA_ADDR :
- /* not actually used */
- alloc_hdr->ah_alloc_size = 1;
- alloc_hdr->ah_alloc_num = 1;
- alloc_hdr->ah_malloc_length = 1;
- break;
-
- case DW_DLA_WEAK_CONTEXT :
- alloc_hdr->ah_alloc_size =
- ROUND_SIZE_WITH_POINTER(struct Dwarf_Weak_Context_s);
- alloc_hdr->ah_alloc_num = 64;
- alloc_hdr->ah_malloc_length =
- 64 * ROUND_SIZE_WITH_POINTER(struct Dwarf_Weak_Context_s);
- break;
- }
-
- }
- return(dbg);
- }
-
-
- /*
- This function prints out the statistics
- collected on allocation of memory chunks.
- */
- void
- dwarf_print_memory_stats (
- Dwarf_Debug dbg
- )
- {
- Dwarf_Alloc_Hdr alloc_hdr;
- Dwarf_Shalf i;
-
- /*
- Alloc types start at 1, not 0.
- Hence, the first NULL string, and
- also a size of MAX_DW_DLA + 1.
- */
- char *alloc_type_name [MAX_DW_DLA + 1] = {
- "",
- "DW_DLA_STRING",
- "DW_DLA_LOC",
- "DW_DLA_LOCDESC",
- "DW_DLA_ELLIST",
- "DW_DLA_BOUNDS",
- "DW_DLA_BLOCK",
- "DW_DLA_DEBUG",
- "DW_DLA_DIE",
- "DW_DLA_LINE",
- "DW_DLA_ATTR",
- "DW_DLA_TYPE",
- "DW_DLA_SUBSCR",
- "DW_DLA_GLOBAL",
- "DW_DLA_ERROR",
- "DW_DLA_LIST",
- "DW_DLA_LINEBUF",
- "DW_DLA_ARANGE",
- "DW_DLA_ABBREV",
- "DW_DLA_FRAME_OP",
- "DW_DLA_CIE",
- "DW_DLA_FDE",
- "DW_DLA_LOC_BLOCK",
- "DW_DLA_FRAME_BLOCK",
- "DW_DLA_FUNC",
- "DW_DLA_TYPENAME",
- "DW_DLA_VAR",
- "DW_DLA_WEAK",
- "DW_DLA_ADDR",
- "DW_DLA_ABBREV_LIST",
- "DW_DLA_CHAIN",
- "DW_DLA_CU_CONTEXT",
- "DW_DLA_FRAME",
- "DW_DLA_GLOBAL_CONTEXT",
- "DW_DLA_FILE_ENTRY",
- "DW_DLA_LINE_CONTEXT",
- "DW_DLA_LOC_CHAIN",
- "DW_DLA_HASH_TABLE",
- "DW_DLA_FUNC_CONTEXT",
- "DW_DLA_TYPENAME_CONTEXT",
- "DW_DLA_VAR_CONTEXT"
- "DW_DLA_WEAK_CONTEXT"
- };
-
- if (dbg == NULL) return;
-
- if (dbg->de_alloc_hdr == NULL) return;
-
- printf("Alloc Type Max Curr Structs\n");
- printf("---------- --- ---- -------\n");
- for (i = 1; i <= MAX_DW_DLA; i++) {
- alloc_hdr = dbg->de_alloc_hdr[i];
-
- if (alloc_hdr != NULL) {
- printf("%-25s %6d %6d %8d\n", alloc_type_name[i],
- alloc_hdr->ah_max_alloc, alloc_hdr->ah_curr_alloc,
- alloc_hdr->ah_struct_alloc_count);
- }
- }
- }
-
-
- /*
- This function is used to recursively
- free the chunks still allocated, and
- forward chained through the aa_next
- pointer.
- */
- _dwarf_recursive_free (
- Dwarf_Alloc_Area alloc_area
- )
- {
- if (alloc_area->aa_next != NULL)
- _dwarf_recursive_free(alloc_area->aa_next);
-
- free(alloc_area);
- }
-
-
- /*
- Used to free all space allocated for this Dwarf_Debug.
- The caller should assume that the Dwarf_Debug pointer
- itself is no longer valid upon return from this function.
-
- In case of difficulty, this function simply returns quietly.
- */
- int
- _dwarf_free_all_of_one_debug (
- Dwarf_Debug dbg
- )
- {
- Dwarf_Alloc_Hdr alloc_hdr;
- Dwarf_Shalf i;
-
- if (dbg == NULL) return(DW_DLV_ERROR);
-
- if (dbg->de_alloc_hdr == NULL) return(DW_DLV_ERROR);
-
- for (i = 1; i <= MAX_DW_DLA; i++) {
- alloc_hdr = dbg->de_alloc_hdr[i];
-
- if (alloc_hdr != NULL) {
-
- if (alloc_hdr->ah_alloc_area_head != NULL)
- _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head);
-
- free(alloc_hdr);
- }
- }
-
- free(dbg);
- return(DW_DLV_OK);
- }
-
-
- /*
- The application calls dwarf_transform_to_disk_form()
- and that function, when it has done its work, calls
- this function to free all it can.
-
- Leaving byte streams and other minimal support structure
- in memory.
-
- */
- void
- _dwarf_free_after_transform_to_disk (
- Dwarf_Debug dbg
- )
- {
- return;
- }
-