Ejemplo n.º 1
0
Dwarf_P_Debug
dwarf_producer_init(Dwarf_Unsigned flags,
		    Dwarf_Callback_Func func,
		    Dwarf_Handler errhand,
		    Dwarf_Ptr errarg, Dwarf_Error * error)
{

    Dwarf_P_Debug dbg;



    dbg = (Dwarf_P_Debug) _dwarf_p_get_alloc(NULL,
					     sizeof(struct
						    Dwarf_P_Debug_s));
    if (dbg == NULL) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC,
			  (Dwarf_P_Debug) DW_DLV_BADADDR);
    }
    memset((void *) dbg,0, sizeof(struct Dwarf_P_Debug_s));
    /* For the time being */
    if (func == NULL) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_NO_CALLBACK_FUNC,
			  (Dwarf_P_Debug) DW_DLV_BADADDR);
    }
    dbg->de_func = func;
    dbg->de_errhand = errhand;
    dbg->de_errarg = errarg;
    common_init(dbg, flags);
    return dbg;
}
Ejemplo n.º 2
0
/*-----------------------------------------------------------------------
        Add a directory declaration to the debug_line section. Stored
        in linked list.
------------------------------------------------------------------------*/
Dwarf_Unsigned
dwarf_add_directory_decl(Dwarf_P_Debug dbg,
                         char *name, Dwarf_Error * error)
{
    if (dbg->de_inc_dirs == NULL) {
        dbg->de_inc_dirs = (Dwarf_P_Inc_Dir)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Inc_Dir_s));
        if (dbg->de_inc_dirs == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_INCDIR_ALLOC, DW_DLV_NOCOUNT);
        }
        dbg->de_last_inc_dir = dbg->de_inc_dirs;
        dbg->de_n_inc_dirs = 1;
    } else {
        dbg->de_last_inc_dir->did_next = (Dwarf_P_Inc_Dir)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Inc_Dir_s));
        if (dbg->de_last_inc_dir->did_next == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_INCDIR_ALLOC, DW_DLV_NOCOUNT);
        }
        dbg->de_last_inc_dir = dbg->de_last_inc_dir->did_next;
        dbg->de_n_inc_dirs++;
    }
    dbg->de_last_inc_dir->did_name =
        (char *) _dwarf_p_get_alloc(dbg, strlen(name) + 1);
    if (dbg->de_last_inc_dir->did_name == NULL) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_STRING_ALLOC, DW_DLV_NOCOUNT);
    }
    strcpy(dbg->de_last_inc_dir->did_name, name);
    dbg->de_last_inc_dir->did_next = NULL;

    return dbg->de_n_inc_dirs;
}
Ejemplo n.º 3
0
/*  This function adds a cie struct to the debug pointer. Its in the
    form of a linked list.
    augmenter: string reps augmentation (implementation defined)
    code_align: alignment of code
    data_align: alignment of data
    init_bytes: byts having initial instructions
    init_n_bytes: number of bytes of initial instructions */
Dwarf_Unsigned
dwarf_add_frame_cie(Dwarf_P_Debug dbg,
    char *augmenter,
    Dwarf_Small code_align,
    Dwarf_Small data_align,
    Dwarf_Small return_reg,
    Dwarf_Ptr init_bytes,
    Dwarf_Unsigned init_n_bytes, Dwarf_Error * error)
{
    Dwarf_P_Cie curcie;
    char *tmpaug = 0;

    if (dbg->de_frame_cies == NULL) {
        dbg->de_frame_cies = (Dwarf_P_Cie)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
        if (dbg->de_frame_cies == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
        }
        curcie = dbg->de_frame_cies;
        dbg->de_n_cie = 1;
        dbg->de_last_cie = curcie;
    } else {
        curcie = dbg->de_last_cie;
        curcie->cie_next = (Dwarf_P_Cie)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
        if (curcie->cie_next == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
        }
        curcie = curcie->cie_next;
        dbg->de_n_cie++;
        dbg->de_last_cie = curcie;
    }
    curcie->cie_version = 1;
    if (dbg->de_output_version > 2) {
        curcie->cie_version = dbg->de_output_version;
    } else {
        /*  V2 dwarf has debug_frame as version 1, there
            is no 2 used in this section. */
        curcie->cie_version = 1;
    }
    tmpaug = (char *)_dwarf_p_get_alloc(dbg,strlen(augmenter)+1);
    if (!tmpaug) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
    }
    strcpy(tmpaug,augmenter);
    curcie->cie_aug = tmpaug;
    curcie->cie_code_align = code_align;
    curcie->cie_data_align = data_align;
    curcie->cie_ret_reg = return_reg;
    curcie->cie_inst = (char *) init_bytes;
    curcie->cie_inst_bytes = (long) init_n_bytes;
    curcie->cie_next = NULL;
    return dbg->de_n_cie;
}
Ejemplo n.º 4
0
/*----------------------------------------------------------------------------
	This function adds a die to dbg struct. It should be called using 
	the root of all the dies.
-----------------------------------------------------------------------------*/
Dwarf_Unsigned
dwarf_add_die_to_debug(Dwarf_P_Debug dbg,
		       Dwarf_P_Die first_die, Dwarf_Error * error)
{
    if (first_die == NULL) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT);
    }
    if (first_die->di_tag != DW_TAG_compile_unit) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_TAG, DW_DLV_NOCOUNT);
    }
    dbg->de_dies = first_die;
    return 0;
}
Ejemplo n.º 5
0
/*----------------------------------------------------------------------------
	This function creates a new die. 
	tag: tag of the new die to be created
	parent,child,left,right: specify neighbors of the new die. Only
	    one of these may be non-null
-----------------------------------------------------------------------------*/
Dwarf_P_Die
dwarf_new_die(Dwarf_P_Debug dbg,
	      Dwarf_Tag tag,
	      Dwarf_P_Die parent,
	      Dwarf_P_Die child,
	      Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error)
{
    Dwarf_P_Die new_die, ret_die;

    new_die = (Dwarf_P_Die)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Die_s));
    if (new_die == NULL) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_ALLOC,
			  (Dwarf_P_Die) DW_DLV_BADADDR);
    }
    new_die->di_parent = NULL;
    new_die->di_left = NULL;
    new_die->di_right = NULL;
    new_die->di_child = NULL;
    new_die->di_tag = tag;
    new_die->di_dbg = dbg;
    new_die->di_marker = 0;
    ret_die = 
        dwarf_die_link(new_die, parent, child, left, right, error);
    return ret_die;
}
Ejemplo n.º 6
0
int
dwarf_get_relocation_info(Dwarf_P_Debug dbg,
			  Dwarf_Signed * elf_section_index,
			  Dwarf_Signed * elf_section_index_link,
			  Dwarf_Unsigned * relocation_buffer_count,
			  Dwarf_Relocation_Data * reldata_buffer,
			  Dwarf_Error * error)
{
    int next = dbg->de_reloc_next_to_return;

    if (dbg->de_flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
	int i;

	for (i = next; i < NUM_DEBUG_SECTIONS; ++i) {
	    Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[i];

	    if (prel->pr_reloc_total_count > 0) {
		dbg->de_reloc_next_to_return = i + 1;


		/* ASSERT: prel->.pr_block_count == 1 */

		*elf_section_index = prel->pr_sect_num_of_reloc_sect;
		*elf_section_index_link = dbg->de_elf_sects[i];
		*relocation_buffer_count = prel->pr_reloc_total_count;
		*reldata_buffer = (Dwarf_Relocation_Data)
		    (prel->pr_first_block->rb_data);
		return DW_DLV_OK;
	    }
	}
	DWARF_P_DBG_ERROR(dbg, DW_DLE_REL_ALLOC, DW_DLV_ERROR);
    }
    return DW_DLV_NO_ENTRY;
}
Ejemplo n.º 7
0
/*  Add a cfe_offset instruction to the fde passed in. */
Dwarf_P_Fde
dwarf_fde_cfa_offset(Dwarf_P_Fde fde,
    Dwarf_Unsigned reg,
    Dwarf_Signed offset, Dwarf_Error * error)
{
    Dwarf_Ubyte opc, regno;
    char *ptr = 0;
    Dwarf_P_Frame_Pgm curinst;
    int nbytes = 0;
    int res = 0;
    char buff1[ENCODE_SPACE_NEEDED];
    Dwarf_P_Debug dbg = fde->fde_dbg;

    curinst = (Dwarf_P_Frame_Pgm)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Frame_Pgm_s));
    if (curinst == NULL) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_FPGM_ALLOC,
            (Dwarf_P_Fde) DW_DLV_BADADDR);
    }
    opc = DW_CFA_offset;
    regno = reg;
    if (regno & 0xc0) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_REGNO_OVFL,
            (Dwarf_P_Fde) DW_DLV_BADADDR);
    }
    opc = opc | regno;          /* lower 6 bits are register number */
    curinst->dfp_opcode = opc;
    res = _dwarf_pro_encode_leb128_nm(offset, &nbytes,
        buff1, sizeof(buff1));
    if (res != DW_DLV_OK) {
        _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }
    ptr = (char *) _dwarf_p_get_alloc(dbg, nbytes);
    if (ptr == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }
    memcpy(ptr, buff1, nbytes);

    curinst->dfp_args = ptr;
    curinst->dfp_nbytes = nbytes;
    curinst->dfp_next = NULL;

    _dwarf_pro_add_to_fde(fde, curinst);
    return fde;
}
Ejemplo n.º 8
0
/*  This function adds a cie struct to the debug pointer. Its in the
    form of a linked list.
    augmenter: string reps augmentation (implementation defined)
    code_align: alignment of code
    data_align: alignment of data
    init_bytes: byts having initial instructions
    init_n_bytes: number of bytes of initial instructions */
Dwarf_Unsigned
dwarf_add_frame_cie(Dwarf_P_Debug dbg,
    char *augmenter,
    Dwarf_Small code_align,
    Dwarf_Small data_align,
    Dwarf_Small return_reg,
    Dwarf_Ptr init_bytes,
    Dwarf_Unsigned init_n_bytes, Dwarf_Error * error)
{
    Dwarf_P_Cie curcie;
    char *tmpaug = 0;

    if (dbg->de_frame_cies == NULL) {
        dbg->de_frame_cies = (Dwarf_P_Cie)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
        if (dbg->de_frame_cies == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
        }
        curcie = dbg->de_frame_cies;
        dbg->de_n_cie = 1;
        dbg->de_last_cie = curcie;
    } else {
        curcie = dbg->de_last_cie;
        curcie->cie_next = (Dwarf_P_Cie)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Cie_s));
        if (curcie->cie_next == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
        }
        curcie = curcie->cie_next;
        dbg->de_n_cie++;
        dbg->de_last_cie = curcie;
    }
    curcie->cie_version = DW_CIE_VERSION;
    tmpaug = strdup(augmenter);
    if (!tmpaug) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_ALLOC, DW_DLV_NOCOUNT);
    }
    curcie->cie_aug = tmpaug;
    curcie->cie_code_align = code_align;
    curcie->cie_data_align = data_align;
    curcie->cie_ret_reg = return_reg;
    curcie->cie_inst = (char *) init_bytes;
    curcie->cie_inst_bytes = (long) init_n_bytes;
    curcie->cie_next = NULL;
    return dbg->de_n_cie;
}
Ejemplo n.º 9
0
/*---------------------------------------------------------------
	This routine deallocates all memory, and does some 
	finishing up
-----------------------------------------------------------------*/
 /*ARGSUSED*/ Dwarf_Unsigned
dwarf_producer_finish(Dwarf_P_Debug dbg, Dwarf_Error * error)
{
    if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, DW_DLV_NOCOUNT);
    }

    dwarf_p_dealloc((void *) dbg, 0);
    return 0;
}
Ejemplo n.º 10
0
/*  This routine deallocates all memory, and does some
    finishing up.  New September 2016. */
int
dwarf_producer_finish_a(Dwarf_P_Debug dbg, Dwarf_Error * error)
{
    if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, DW_DLV_ERROR);
    }

    /* this frees all blocks, then frees dbg. */
    _dwarf_p_dealloc_all(dbg);
    return DW_DLV_OK ;
}
Ejemplo n.º 11
0
/*  This routine deallocates all memory, and does some 
    finishing up */
/*ARGSUSED*/ Dwarf_Unsigned
dwarf_producer_finish(Dwarf_P_Debug dbg, Dwarf_Error * error)
{
    if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, DW_DLV_NOCOUNT);
    }

    /* this frees all blocks, then frees dbg. */
    _dwarf_p_dealloc_all(dbg);
    return 0;
}
Ejemplo n.º 12
0
int
_dwarf_pro_add_AT_macro_info(Dwarf_P_Debug dbg,
			     Dwarf_P_Die die,
			     Dwarf_Unsigned offset, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    int uwordb_size = dbg->de_offset_size;

    if (die == NULL) {
	DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1);
    }
    new_attr = (Dwarf_P_Attribute)
        _dwarf_p_get_alloc(dbg,sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1);
    }

    /* fill in the information */
    new_attr->ar_attribute = DW_AT_macro_info;
    new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;
    new_attr->ar_rel_type = dbg->de_offset_reloc;

    new_attr->ar_nbytes = uwordb_size;
    new_attr->ar_next = NULL;
    new_attr->ar_reloc_len = uwordb_size;
    new_attr->ar_data = (char *)
        _dwarf_p_get_alloc(dbg, uwordb_size);
    if (new_attr->ar_data == NULL) {
	DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT);
    }
    {
	Dwarf_Unsigned du = offset;

	WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data,
			(const void *) &du, sizeof(du), uwordb_size);
    }

    _dwarf_pro_add_at_to_die(die, new_attr);

    return 0;
}
Ejemplo n.º 13
0
/*-----------------------------------------------------------------------------
    Add AT_comp_dir attribute to die
------------------------------------------------------------------------------*/
Dwarf_P_Attribute
dwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie,
    char *current_working_directory,
    Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;

    if (ownerdie == NULL) {
        DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL,
            (Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    new_attr = (Dwarf_P_Attribute)
        _dwarf_p_get_alloc(ownerdie->di_dbg,
        sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
        DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC,
            (Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    /* fill in the information */
    new_attr->ar_attribute = DW_AT_comp_dir;
    /* assume that form is string, no debug_str yet */
    new_attr->ar_attribute_form = DW_FORM_string;
    new_attr->ar_nbytes = strlen(current_working_directory) + 1;
    new_attr->ar_next = NULL;
    new_attr->ar_reloc_len = 0;
    new_attr->ar_data = (char *)
        _dwarf_p_get_alloc(ownerdie->di_dbg,
        strlen(current_working_directory)+1);
    if (new_attr->ar_data == NULL) {
        DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC,
            (Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    strcpy(new_attr->ar_data, current_working_directory);

    new_attr->ar_rel_type = R_MIPS_NONE;

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Ejemplo n.º 14
0
Dwarf_Unsigned
dwarf_get_die_marker(Dwarf_P_Debug dbg,
		     Dwarf_P_Die die,
		     Dwarf_Unsigned * marker,
		     Dwarf_Error * error)
{
    if (die == NULL) {
	DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT);
    }
    *marker = die->di_marker;
    return 0;
}
Ejemplo n.º 15
0
/*----------------------------------------------------------------------------
        Add an entry in the internal list of lines mantained by producer. 
        Opc indicates if an opcode needs to be generated, rather than just
        an entry in the matrix. During opcodes generation time, these 
        opcodes will be used.
-----------------------------------------------------------------------------*/
Dwarf_Unsigned
_dwarf_pro_add_line_entry(Dwarf_P_Debug dbg,
                          Dwarf_Unsigned file_index,
                          Dwarf_Addr code_address,
                          Dwarf_Unsigned symidx,
                          Dwarf_Unsigned line_no,
                          Dwarf_Signed col_no,
                          Dwarf_Bool is_stmt_begin,
                          Dwarf_Bool is_bb_begin,
                          Dwarf_Ubyte opc, Dwarf_Error * error)
{
    if (dbg->de_lines == NULL) {
        dbg->de_lines = (Dwarf_P_Line)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Line_s));
        if (dbg->de_lines == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_LINE_ALLOC, DW_DLV_NOCOUNT);
        }
        dbg->de_last_line = dbg->de_lines;
        _dwarf_pro_reg_init(dbg->de_lines);

    } else {
        dbg->de_last_line->dpl_next = (Dwarf_P_Line)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Line_s));
        if (dbg->de_last_line->dpl_next == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_LINE_ALLOC, DW_DLV_NOCOUNT);
        }
        dbg->de_last_line = dbg->de_last_line->dpl_next;
        _dwarf_pro_reg_init(dbg->de_last_line);
    }
    dbg->de_last_line->dpl_address = code_address;
    dbg->de_last_line->dpl_file = (unsigned long) file_index;
    dbg->de_last_line->dpl_line = (unsigned long) line_no;
    dbg->de_last_line->dpl_column = (unsigned long) col_no;
    dbg->de_last_line->dpl_is_stmt = is_stmt_begin;
    dbg->de_last_line->dpl_basic_block = is_bb_begin;
    dbg->de_last_line->dpl_opc = opc;
    dbg->de_last_line->dpl_r_symidx = symidx;

    return (0);
}
Ejemplo n.º 16
0
/* Create a new fde. */
Dwarf_P_Fde
dwarf_new_fde(Dwarf_P_Debug dbg, Dwarf_Error * error)
{
    Dwarf_P_Fde fde;

    fde = (Dwarf_P_Fde)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Fde_s));
    if (fde == NULL) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_FDE_ALLOC,
            (Dwarf_P_Fde) DW_DLV_BADADDR);
    }
    fde->fde_uwordb_size = dbg->de_offset_size;
    return fde;
}
Ejemplo n.º 17
0
int
_dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg,
			    Dwarf_P_Die first_die, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    int uwordb_size = dbg->de_offset_size;

    /* Add AT_stmt_list attribute */
    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, DW_DLV_NOCOUNT);
    }

    new_attr->ar_attribute = DW_AT_stmt_list;
    new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;
    new_attr->ar_rel_type = dbg->de_offset_reloc;

    new_attr->ar_nbytes = uwordb_size;
    new_attr->ar_next = NULL;
    new_attr->ar_reloc_len = uwordb_size;
    new_attr->ar_data = (char *)
	_dwarf_p_get_alloc(dbg, uwordb_size);
    if (new_attr->ar_data == NULL) {
	DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT);
    }
    {
	Dwarf_Unsigned du = 0;

	WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data,
			(const void *) &du, sizeof(du), uwordb_size);
    }

    _dwarf_pro_add_at_to_die(first_die, new_attr);
    return 0;
}
Ejemplo n.º 18
0
/* This is an alternate to inserting frame instructions
   one instruction at a time.  But use either this
   or instruction level, not both in one fde. */
int
dwarf_insert_fde_inst_bytes(Dwarf_P_Debug dbg,
    Dwarf_P_Fde fde,Dwarf_Unsigned len, Dwarf_Ptr ibytes,
    Dwarf_Error *error)
{
    if (len == 0) {
        return DW_DLV_OK;
    }
    if (fde->fde_block || fde->fde_inst) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_DUPLICATE_INST_BLOCK,
            (int)DW_DLV_BADADDR);
    }
    fde->fde_block = (Dwarf_Ptr)_dwarf_p_get_alloc(dbg, len);
    memcpy(fde->fde_block,ibytes,len);
    fde->fde_inst_block_size = len;
    fde->fde_n_bytes += len;
    return DW_DLV_OK;
}
Ejemplo n.º 19
0
/*-----------------------------------------------------------------------
        Add a file entry declaration to the debug_line section. Stored
        in linked list. The data is immediately encodes as leb128
        and stored in Dwarf_P_F_Entry_s struct.
------------------------------------------------------------------------*/
Dwarf_Unsigned
dwarf_add_file_decl(Dwarf_P_Debug dbg,
                    char *name,
                    Dwarf_Unsigned dir_idx,
                    Dwarf_Unsigned time_mod,
                    Dwarf_Unsigned length, Dwarf_Error * error)
{
    Dwarf_P_F_Entry cur;
    char *ptr;
    int nbytes_idx, nbytes_time, nbytes_len;
    char buffidx[ENCODE_SPACE_NEEDED];
    char bufftime[ENCODE_SPACE_NEEDED];
    char bufflen[ENCODE_SPACE_NEEDED];
    int res;

    if (dbg->de_file_entries == NULL) {
        dbg->de_file_entries = (Dwarf_P_F_Entry)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_F_Entry_s));
        if (dbg->de_file_entries == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_FILE_ENTRY_ALLOC,
                              DW_DLV_NOCOUNT);
        }
        cur = dbg->de_file_entries;
        dbg->de_last_file_entry = cur;
        dbg->de_n_file_entries = 1;
    } else {
        cur = dbg->de_last_file_entry;
        cur->dfe_next = (Dwarf_P_F_Entry)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_F_Entry_s));
        if (cur->dfe_next == NULL) {
            DWARF_P_DBG_ERROR(dbg, DW_DLE_FILE_ENTRY_ALLOC,
                              DW_DLV_NOCOUNT);
        }
        cur = cur->dfe_next;
        dbg->de_last_file_entry = cur;
        dbg->de_n_file_entries++;
    }
    cur->dfe_name = (char *) _dwarf_p_get_alloc(dbg, strlen(name) + 1);
    if (cur->dfe_name == NULL) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT);
    }
    strcpy((char *) cur->dfe_name, name);
    res = _dwarf_pro_encode_leb128_nm(dir_idx, &nbytes_idx,
                                      buffidx, sizeof(buffidx));
    if (res != DW_DLV_OK) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT);
    }
    res = _dwarf_pro_encode_leb128_nm(time_mod, &nbytes_time,
                                      bufftime, sizeof(bufftime));
    if (res != DW_DLV_OK) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT);
    }
    res = _dwarf_pro_encode_leb128_nm(length, &nbytes_len,
                                      bufflen, sizeof(bufflen));
    cur->dfe_args = (char *)
        _dwarf_p_get_alloc(dbg, nbytes_idx + nbytes_time + nbytes_len);
    if (cur->dfe_args == NULL) {
        DWARF_P_DBG_ERROR(dbg, DW_DLE_ALLOC_FAIL, DW_DLV_NOCOUNT);
    }
    ptr = cur->dfe_args;
    memcpy((void *) ptr, buffidx, nbytes_idx);
    ptr += nbytes_idx;
    memcpy((void *) ptr, bufftime, nbytes_time);
    ptr += nbytes_time;
    memcpy((void *) ptr, bufflen, nbytes_len);
    ptr += nbytes_len;
    cur->dfe_nbytes = nbytes_idx + nbytes_time + nbytes_len;
    cur->dfe_next = NULL;

    return dbg->de_n_file_entries;
}
Ejemplo n.º 20
0
/*----------------------------------------------------------------------------
	This function links up a die to specified neighbors
	parent,child,left,right: specify neighbors of the new die. Only
	    one of these may be non-null
-----------------------------------------------------------------------------*/
Dwarf_P_Die
dwarf_die_link(Dwarf_P_Die new_die,
	       Dwarf_P_Die parent,
	       Dwarf_P_Die child,
	       Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error)
{
    int n_nulls;		/* to count # of non null neighbors */
    Dwarf_P_Die orig;

    n_nulls = 0;
    if (parent != NULL) {
        n_nulls++;
        if (new_die->di_parent != NULL) {
              DWARF_P_DBG_ERROR(NULL, DW_DLE_LINK_LOOP,
                    (Dwarf_P_Die) DW_DLV_BADADDR);
        }
        new_die->di_parent = parent;
        if (parent->di_child) {	/* got to traverse the child's siblings 
				 */
            Dwarf_P_Die curdie;

            curdie = parent->di_child;
            orig = curdie;
            while (curdie->di_right) {
                curdie = curdie->di_right;
                if (curdie == orig || curdie == curdie->di_right) {
                    DWARF_P_DBG_ERROR(NULL, DW_DLE_LINK_LOOP,
                       (Dwarf_P_Die) DW_DLV_BADADDR);
                }
            }
            curdie->di_right = new_die;	/* attach to sibling list */
            new_die->di_left = curdie;	/* back pointer */
	} else
	    parent->di_child = new_die;
    }
    if (child != NULL) {
        n_nulls++;
        new_die->di_child = child;
        if (child->di_parent) {
	    DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
			      (Dwarf_P_Die) DW_DLV_BADADDR);
        } else {
	    child->di_parent = new_die;
        }
    }
    if (left != NULL) {
	n_nulls++;
	new_die->di_left = left;
	if (left->di_right)	/* there's already a right sibl, lets
				   insert */
	    new_die->di_right = left->di_right;
	left->di_right = new_die;
	/* add parent pointer */
	if (new_die->di_parent) {
	    DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
			      (Dwarf_P_Die) DW_DLV_BADADDR);
	} else
	    new_die->di_parent = left->di_parent;
    }
    if (right != NULL) {
	n_nulls++;
	new_die->di_right = right;
	if (right->di_left)	/* left sibl exists, try inserting */
	    new_die->di_left = right->di_left;
	right->di_left = new_die;
	if (new_die->di_parent) {
	    DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
			      (Dwarf_P_Die) DW_DLV_BADADDR);
	} else
	    new_die->di_parent = right->di_parent;
    }
    if (n_nulls > 1) {		/* multiple neighbors, error */
	DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS,
			  (Dwarf_P_Die) DW_DLV_BADADDR);
    }
    return new_die;

}
Ejemplo n.º 21
0
/*  This function links up a die to specified neighbors
    parent,child,left,right: specify neighbors of the new die. Only
    one of these may be non-null */
Dwarf_P_Die
dwarf_die_link(Dwarf_P_Die new_die,
    Dwarf_P_Die parent,
    Dwarf_P_Die child,
    Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error)
{
    /* Count the # of non null neighbors. */
    int n_nulls = 0;

    if (parent != NULL) {
        n_nulls++;
        if (new_die->di_parent != NULL) {
            DWARF_P_DBG_ERROR(NULL, DW_DLE_LINK_LOOP,
                (Dwarf_P_Die) DW_DLV_BADADDR);
        }
        new_die->di_parent = parent;
        if (parent->di_child) {

            /*  di_last_child identifies the last sibling, the
                die we want to attach new_die to. */
            /*  ASSERT: if di_child is set so is di_last_child. */
            Dwarf_P_Die former_lastchild = parent->di_last_child;
            parent->di_last_child = new_die;
            /* Attach to  the new die to end of the sibling list. */
            former_lastchild->di_right = new_die;
            new_die->di_left = former_lastchild;
        } else {
            parent->di_child = new_die;
            parent->di_last_child = new_die;
        }
    }
    if (child != NULL) {
        n_nulls++;
        new_die->di_child = child;
        new_die->di_last_child = child;
        if (child->di_parent) {
            DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
                (Dwarf_P_Die) DW_DLV_BADADDR);
        } else {
            child->di_parent = new_die;
        }
    }
    if (left != NULL) {
        n_nulls++;
        new_die->di_left = left;
        if (left->di_right) {
            /*  There's already a right sibling of left,
                insert the new die in the list. */
            new_die->di_right = left->di_right;
            left->di_right->di_left = new_die;
        }
        left->di_right = new_die;
        if (new_die->di_parent) {
            DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
                (Dwarf_P_Die) DW_DLV_BADADDR);
        } else {
            new_die->di_parent = left->di_parent;
        }
    }
    if (right != NULL) {
        n_nulls++;
        new_die->di_right = right;
        if (right->di_left) {
            /*  There is already a left sibling of the right die,
                insert the new die in the list.  */
            new_die->di_left = right->di_left;
            right->di_left->di_right = new_die;
        }
        right->di_left = new_die;
        if (new_die->di_parent) {
            DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
                (Dwarf_P_Die) DW_DLV_BADADDR);
        } else {
            new_die->di_parent = right->di_parent;
        }
    }
    if (n_nulls > 1) {
        /* Multiple neighbors! error! */
        DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS,
            (Dwarf_P_Die) DW_DLV_BADADDR);
    }
    return new_die;

}