Пример #1
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;
}
Пример #2
0
/* Similar to dwarf_add_fde_inst, except that the offset denoted by VAL2
   is signed.
*/
Dwarf_P_Fde
dwarf_add_fde_inst_with_signed_offset(Dwarf_P_Fde fde,
                                      Dwarf_Small op,
                                      Dwarf_Unsigned val1,
                                      Dwarf_Signed val2, Dwarf_Error * error)
{
    Dwarf_P_Frame_Pgm curinst;
    int nbytes, nbytes1, nbytes2;
    char *ptr;
    int res;
    char buff1[ENCODE_SPACE_NEEDED];
    char buff2[ENCODE_SPACE_NEEDED];


    nbytes = 0;
    ptr = NULL;
    curinst = (Dwarf_P_Frame_Pgm)
        _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Frame_Pgm_s));
    if (curinst == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_FPGM_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }

    if (op == DW_CFA_offset_extended_sf)
    {
      res = _dwarf_pro_encode_leb128_nm(val1, &nbytes1,
                                        buff1, sizeof(buff1));
      if (res != DW_DLV_OK) {
        _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
      }
      res = _dwarf_pro_encode_signed_leb128_nm(val2, &nbytes2,
                                               buff2, sizeof(buff2));
      if (res != DW_DLV_OK) {
        _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
      }
      ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes1 + nbytes2);
      if (ptr == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
      }
      memcpy(ptr, buff1, nbytes1);
      memcpy(ptr + nbytes1, buff2, nbytes2);
      nbytes = nbytes1 + nbytes2;
    }
    curinst->dfp_opcode = op;
    curinst->dfp_args = ptr;
    curinst->dfp_nbytes = nbytes;
    curinst->dfp_next = NULL;

    _dwarf_pro_add_to_fde(fde, curinst);
    return fde;
}
Пример #3
0
Dwarf_P_Attribute
dwarf_add_AT_any_value_uleb(Dwarf_P_Die ownerdie,
    Dwarf_Half attrnum,
    Dwarf_Unsigned unsigned_value,
    Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    int leb_size;
    char encode_buffer[ENCODE_SPACE_NEEDED];
    int res;

    if (ownerdie == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
        return ((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_error(NULL, error, DW_DLE_ALLOC_FAIL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attrnum;
    new_attr->ar_attribute_form = DW_FORM_udata;
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */
    new_attr->ar_next = 0;

    res = _dwarf_pro_encode_leb128_nm(unsigned_value, &leb_size,
        encode_buffer,
        sizeof(encode_buffer));
    if (res != DW_DLV_OK) {
        _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    new_attr->ar_data = (char *)
        _dwarf_p_get_alloc(ownerdie->di_dbg, leb_size);
    if (new_attr->ar_data == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    memcpy(new_attr->ar_data, encode_buffer, leb_size);
    new_attr->ar_nbytes = leb_size;

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #4
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;
}
Пример #5
0
int
dwarf_force_debug_names(Dwarf_P_Debug dbg,
    Dwarf_Error * error)
{

    Dwarf_P_Dnames dn;

    if (dbg == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
        return DW_DLV_ERROR;
    }

    dn = (Dwarf_P_Dnames)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Dnames_s));
    if (dn == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return DW_DLV_ERROR;
    }
    if (!dbg->de_dnames) {
        dbg->de_dnames = dn;
    }
    dn->dn_create_section = TRUE;

    return DW_DLV_OK;
}
Пример #6
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;
}
Пример #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;
}
Пример #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;
}
Пример #9
0
/* This function adds attributes of the flag class.  */
Dwarf_P_Attribute
dwarf_add_AT_flag(Dwarf_P_Debug dbg,
    Dwarf_P_Die ownerdie,
    Dwarf_Half attr,
    Dwarf_Small flag, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr = 0;

    if (dbg == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr = (Dwarf_P_Attribute)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = DW_FORM_flag;
    new_attr->ar_nbytes = 1;
    new_attr->ar_reloc_len = 0; /* not used */
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_next = 0;

    new_attr->ar_data = (char *)
        _dwarf_p_get_alloc(dbg, 1);
    if (new_attr->ar_data == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    memcpy(new_attr->ar_data, &flag, 1);

    /* Add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #10
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;
}
Пример #11
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;
}
Пример #12
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);
}
Пример #13
0
/* 
    This function performs error handling as described in the 
    libdwarf consumer document section 3.  Dbg is the Dwarf_P_debug
    structure being processed.  Error is a pointer to the pointer
    to the error descriptor that will be returned.  Errval is an
    error code listed in dwarf_error.h.
*/
void
_dwarf_p_error(Dwarf_P_Debug dbg,
	       Dwarf_Error * error, Dwarf_Word errval)
{
    Dwarf_Error errptr;

    /* Allow NULL dbg on entry, since sometimes that can happen and we
       want to report the upper-level error, not this one. */
    if ((Dwarf_Sword) errval < 0)
	printf("ERROR VALUE: %ld - %s\n",
	       (long) errval, _dwarf_errmsgs[-errval - 1]);
    if (error != NULL) {
	errptr = (Dwarf_Error)
	    _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
	if (errptr == NULL) {
	    fprintf(stderr,
		    "Could not allocate Dwarf_Error structure\n");
	    abort();
	}
	errptr->er_errval = (Dwarf_Sword) errval;
	*error = errptr;
	return;
    }

    if (dbg != NULL && dbg->de_errhand != NULL) {
	errptr = (Dwarf_Error)
	    _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
	if (errptr == NULL) {
	    fprintf(stderr,
		    "Could not allocate Dwarf_Error structure\n");
	    abort();
	}
	errptr->er_errval = (Dwarf_Sword) errval;
	dbg->de_errhand(errptr, dbg->de_errarg);
	return;
    }

    abort();
}
Пример #14
0
Dwarf_P_Attribute
dwarf_add_AT_producer(Dwarf_P_Die ownerdie,
		      char *producer_string, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;

    if (ownerdie == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = DW_AT_producer;
    new_attr->ar_attribute_form = DW_FORM_string;
    new_attr->ar_nbytes = strlen(producer_string) + 1;
    new_attr->ar_next = 0;

    new_attr->ar_data =
	(char *) _dwarf_p_get_alloc(NULL, strlen(producer_string) + 1);
    if (new_attr->ar_data == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    strcpy(new_attr->ar_data, producer_string);
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_reloc_len = 0;	/* unused for R_MIPS_NONE */

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #15
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;
}
Пример #16
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;
}
Пример #17
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;
}
Пример #18
0
/*Do initial alloc of newslots slots.
  Fails only if malloc fails.

  Supposed to be called before any relocs allocated.
  Ignored if after any allocated.

  Part of an optimization, so that for a known 'newslots' 
  relocations count we can preallocate the right size block.
  Called from just 2 places.

  returns DW_DLV_OK or  DW_DLV_ERROR
*/
int
_dwarf_pro_pre_alloc_n_reloc_slots(Dwarf_P_Debug dbg,
				   int rel_sec_index,
				   Dwarf_Unsigned newslots)
{
    unsigned long len;
    struct Dwarf_P_Relocation_Block_s *data;
    Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[rel_sec_index];
    unsigned long slots_in_blk = (unsigned long) newslots;
    unsigned long rel_rec_size = dbg->de_relocation_record_size;

    if (prel->pr_first_block)
	return DW_DLV_OK;	/* do nothing */

    len = sizeof(struct Dwarf_P_Relocation_Block_s) +
	slots_in_blk * rel_rec_size;


    data = (struct Dwarf_P_Relocation_Block_s *)
	_dwarf_p_get_alloc(dbg, len);
    if (!data) {
	return DW_DLV_ERROR;
    }
    data->rb_slots_in_block = slots_in_blk;	/* could use default
						   here, as fallback in 
						   case our origininal
						   estimate wrong.
						   When we call this we 
						   presumably know what 
						   we are doing, so
						   keep this count for
						   now */
    data->rb_next_slot_to_use = 0;
    data->rb_where_to_add_next =
	((char *) data) + sizeof(struct Dwarf_P_Relocation_Block_s);
    data->rb_data = data->rb_where_to_add_next;

    prel->pr_first_block = data;
    prel->pr_last_block = data;
    prel->pr_block_count = 1;


    return DW_DLV_OK;
}
Пример #19
0
/*Do alloc of slots.
  Fails only if malloc fails.

  Only allocator used.

  returns DW_DLV_OK or  DW_DLV_ERROR
*/
int
_dwarf_pro_alloc_reloc_slots(
	Dwarf_P_Debug  dbg,
	int            rel_sec_index)
{
	unsigned long len;
	struct Dwarf_P_Relocation_Block_s * data;
	Dwarf_P_Per_Reloc_Sect  prel =
		&dbg->de_reloc_sect[rel_sec_index];
	unsigned long slots_in_blk = prel->pr_slots_per_block_to_alloc;
	unsigned long rel_rec_size = dbg->de_relocation_record_size;

	len = sizeof (struct Dwarf_P_Relocation_Block_s) +
		slots_in_blk *rel_rec_size;
	
	data = (struct Dwarf_P_Relocation_Block_s *)
		_dwarf_p_get_alloc(dbg, len);
	if(!data) {
		return DW_DLV_ERROR;
	}

	if(prel->pr_first_block) {
		prel->pr_last_block->rb_next = data;
		prel->pr_last_block = data;
		prel->pr_block_count += 1;
		
	} else {
		
		prel->pr_first_block = data;
		prel->pr_last_block = data;
		prel->pr_block_count = 1;
	}

	data->rb_slots_in_block = slots_in_blk;
	data->rb_next_slot_to_use = 0;
	data->rb_where_to_add_next =
		((char *)data) + sizeof(struct Dwarf_P_Relocation_Block_s);
	data->rb_data = data->rb_where_to_add_next;
	
	return DW_DLV_OK;
	
}
Пример #20
0
/*
    This function creates a new expression 
    struct that can be used to build up a
    location expression.
*/
Dwarf_P_Expr
dwarf_new_expr(Dwarf_P_Debug dbg, Dwarf_Error * error)
{
    Dwarf_P_Expr ret_expr;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return (NULL);
    }

    ret_expr = (Dwarf_P_Expr)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Expr_s));
    if (ret_expr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return (NULL);
    }

    ret_expr->ex_dbg = dbg;

    return (ret_expr);
}
Пример #21
0
/*  This function adds another address range
    to the list of address ranges for the
    given Dwarf_P_Debug.  It returns 0 on error,
    and 1 otherwise.  */
Dwarf_Unsigned
dwarf_add_arange_b(Dwarf_P_Debug dbg,
    Dwarf_Addr begin_address,
    Dwarf_Unsigned length,
    Dwarf_Unsigned symbol_index,
    Dwarf_Unsigned end_symbol_index,
    Dwarf_Addr offset_from_end_sym, Dwarf_Error * error)
{
    Dwarf_P_Arange arange;

    if (dbg == NULL) {
        _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
        return (0);
    }

    arange = (Dwarf_P_Arange)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Arange_s));
    if (arange == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return (0);
    }

    arange->ag_begin_address = begin_address;
    arange->ag_length = length;
    arange->ag_symbol_index = symbol_index;
    arange->ag_end_symbol_index = end_symbol_index;
    arange->ag_end_symbol_offset = offset_from_end_sym;

    if (dbg->de_arange == NULL)
        dbg->de_arange = dbg->de_last_arange = arange;
    else {
        dbg->de_last_arange->ag_next = arange;
        dbg->de_last_arange = arange;
    }
    dbg->de_arange_count++;

    return (1);
}
Пример #22
0
/*  Generic routine to add opcode to fde instructions. val1 and
    val2 are parameters whose interpretation depends on the 'op'.

    This does not work properly for  DW_DLC_SYMBOLIC_RELOCATIONS
    for DW_CFA_set_loc or DW_DVA_advance_loc* 'op', as
    these ops normally are addresses or (DW_CFA_set_loc)
    or code lengths (DW_DVA_advance_loc*) and such must be
    represented with relocations and symbol indices for
    DW_DLC_SYMBOLIC_RELOCATIONS.

    This does not treat all DW_CFA instructions yet.

    For certain operations a val? value must be
    signed (though passed in as unsigned here).

    Currently this does not check that the frame
    version is 3(for dwarf3) or 4 (for dwarf4)
    when applying operations that are only valid for
    dwarf3 or dwarf4. */
Dwarf_P_Fde
dwarf_add_fde_inst(Dwarf_P_Fde fde,
    Dwarf_Small op,
    Dwarf_Unsigned val1,
    Dwarf_Unsigned val2, Dwarf_Error * error)
{
    Dwarf_P_Frame_Pgm curinst;
    int nbytes, nbytes1, nbytes2;
    Dwarf_Ubyte db;
    Dwarf_Half dh;
    Dwarf_Word dw;
    Dwarf_Unsigned du;
    char *ptr;
    int res;
    char buff1[ENCODE_SPACE_NEEDED];
    char buff2[ENCODE_SPACE_NEEDED];
    Dwarf_P_Debug dbg = fde->fde_dbg;
    /*  This is a hack telling the code when to transform
        a value to a signed leb number. */
    int signed_second = 0;
    int signed_first = 0;


    nbytes = 0;
    ptr = NULL;
    curinst = (Dwarf_P_Frame_Pgm)
        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Frame_Pgm_s));
    if (curinst == NULL) {
        _dwarf_p_error(dbg, error, DW_DLE_FPGM_ALLOC);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }

    switch (op) {

    case DW_CFA_advance_loc:
        if (val1 <= 0x3f) {
            db = val1;
            op |= db;
        }
        /* test not portable FIX */
        else if (val1 <= UCHAR_MAX) {
            op = DW_CFA_advance_loc1;
            db = val1;
            ptr = (char *) _dwarf_p_get_alloc(dbg, 1);
            if (ptr == NULL) {
                _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
                return ((Dwarf_P_Fde) DW_DLV_BADADDR);
            }
            memcpy((void *) ptr, (const void *) &db, 1);
            nbytes = 1;
        }
        /* test not portable FIX */
        else if (val1 <= USHRT_MAX) {
            op = DW_CFA_advance_loc2;
            dh = val1;
            ptr = (char *) _dwarf_p_get_alloc(dbg, 2);
            if (ptr == NULL) {
                _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
                return ((Dwarf_P_Fde) DW_DLV_BADADDR);
            }
            memcpy((void *) ptr, (const void *) &dh, 2);
            nbytes = 2;
        }
        /* test not portable FIX */
        else if (val1 <= ULONG_MAX) {
            op = DW_CFA_advance_loc4;
            dw = (Dwarf_Word) val1;
            ptr = (char *) _dwarf_p_get_alloc(dbg, 4);
            if (ptr == NULL) {
                _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
                return ((Dwarf_P_Fde) DW_DLV_BADADDR);
            }
            memcpy((void *) ptr, (const void *) &dw, 4);
            nbytes = 4;
        } else {
            op = DW_CFA_MIPS_advance_loc8;
            du = val1;
            ptr =
                (char *) _dwarf_p_get_alloc(dbg,
                    sizeof(Dwarf_Unsigned));
            if (ptr == NULL) {
                _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
                return ((Dwarf_P_Fde) DW_DLV_BADADDR);
            }
            memcpy((void *) ptr, (const void *) &du, 8);
            nbytes = 8;
        }
        break;

    case DW_CFA_offset:
        if (val1 <= MAX_6_BIT_VALUE) {
            db = val1;
            op |= db;
            res = _dwarf_pro_encode_leb128_nm(val2, &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);

        } else {
            op = DW_CFA_offset_extended;
            goto two_leb;
        }
        break;
    case DW_CFA_offset_extended_sf: /* DWARF3 */
        signed_second = 1;
        goto two_leb;
    case DW_CFA_offset_extended:
        goto two_leb;

    case DW_CFA_undefined:
    case DW_CFA_same_value:
        goto one_leb;

    case DW_CFA_val_offset:
        goto two_leb;
    case DW_CFA_val_offset_sf:
        signed_second = 1;
        goto two_leb;
    case DW_CFA_def_cfa_sf:
        signed_second = 1;
        goto two_leb;
    case DW_CFA_register:
    case DW_CFA_def_cfa:
    two_leb:
        res = _dwarf_pro_encode_leb128_nm(val1, &nbytes1,
            buff1, sizeof(buff1));
        if (res != DW_DLV_OK) {
            _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
            return ((Dwarf_P_Fde) DW_DLV_BADADDR);
        }
        if (!signed_second) {
            res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
                buff2, sizeof(buff2));
        } else {
            Dwarf_Signed val2s = val2;
            res = _dwarf_pro_encode_signed_leb128_nm(val2s, &nbytes2,
                buff2, sizeof(buff2));
        }

        res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
            buff2, sizeof(buff2));
        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, nbytes1 + nbytes2);
        if (ptr == NULL) {
            _dwarf_p_error(dbg, error, DW_DLE_STRING_ALLOC);
            return ((Dwarf_P_Fde) DW_DLV_BADADDR);
        }
        memcpy(ptr, buff1, nbytes1);
        memcpy(ptr + nbytes1, buff2, nbytes2);
        nbytes = nbytes1 + nbytes2;
        break;

    case DW_CFA_def_cfa_offset_sf: /* DWARF3 */
        signed_first = 1;
        goto one_leb;
    case DW_CFA_def_cfa_register:
    case DW_CFA_def_cfa_offset:
    one_leb:
        if (!signed_first) {
            res = _dwarf_pro_encode_leb128_nm(val1, &nbytes,
                buff1, sizeof(buff1));
        } else {
            Dwarf_Signed val1s = val1;
            res = _dwarf_pro_encode_signed_leb128_nm(val1s, &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);
        break;
    case DW_CFA_def_cfa_expression: /* DWARF3 */
        /*  FIXME: argument is dwarf expr, not handled yet. */
    case DW_CFA_expression: /* DWARF3 */
        /*  First arg: ULEB reg num. 2nd arg dwarf expr in form block.
            FIXME: not handled yet. */
    case DW_CFA_val_expression: /* DWARF3f */
        /*  First arg: ULEB reg num. 2nd arg dwarf expr in form block.
            FIXME: not handled yet. */
    default:
        _dwarf_p_error(dbg, error, DW_DLE_DEBUGFRAME_ERROR);
        return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }

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

    _dwarf_pro_add_to_fde(fde, curinst);
    return fde;
}
Пример #23
0
/*
    This function adds attributes whose value
    is a location expression.
*/
Dwarf_P_Attribute
dwarf_add_AT_location_expr(Dwarf_P_Debug dbg,
			   Dwarf_P_Die ownerdie,
			   Dwarf_Half attr,
			   Dwarf_P_Expr loc_expr, Dwarf_Error * error)
{
    char encode_buffer[ENCODE_SPACE_NEEDED];
    int res;
    Dwarf_P_Attribute new_attr;
    Dwarf_Half attr_form;
    char *len_str;
    int len_size;
    int block_size;
    char *block_dest_ptr;
    int do_len_as_int = 0;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (loc_expr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_EXPR_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (loc_expr->ex_dbg != dbg) {
	_dwarf_p_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    block_size = loc_expr->ex_next_byte_offset;

    switch (attr) {
    case DW_AT_location:
    case DW_AT_string_length:
    case DW_AT_const_value:
    case DW_AT_use_location:
    case DW_AT_return_addr:
    case DW_AT_data_member_location:
    case DW_AT_frame_base:
    case DW_AT_static_link:
    case DW_AT_vtable_elem_location:
	break;

    default:{
	    _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
    }

    /* 
       Compute the number of bytes needed to hold constant. */
    if (block_size <= UCHAR_MAX) {
	attr_form = DW_FORM_block1;
	len_size = 1;
	do_len_as_int = 1;
    } else if (block_size <= USHRT_MAX) {
	attr_form = DW_FORM_block2;
	len_size = 2;
	do_len_as_int = 1;
    } else if (block_size <= UINT_MAX) {
	attr_form = DW_FORM_block4;
	len_size = 4;
	do_len_as_int = 1;
    } else {
	attr_form = DW_FORM_block;
	res = _dwarf_pro_encode_leb128_nm(block_size, &len_size,
					  encode_buffer,
					  sizeof(encode_buffer));
	if (res != DW_DLV_OK) {
	    _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
	len_str = (char *) encode_buffer;
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = attr_form;
    new_attr->ar_reloc_len = dbg->de_pointer_size;
    if (loc_expr->ex_reloc_sym_index != NO_ELF_SYM_INDEX) {
	new_attr->ar_rel_type = dbg->de_ptr_reloc;
    } else {
	new_attr->ar_rel_type = R_MIPS_NONE;
    }
    new_attr->ar_rel_symidx = loc_expr->ex_reloc_sym_index;
    new_attr->ar_rel_offset =
	(Dwarf_Word) loc_expr->ex_reloc_offset + len_size;

    new_attr->ar_nbytes = block_size + len_size;

    new_attr->ar_next = 0;
    new_attr->ar_data = block_dest_ptr =
	(char *) _dwarf_p_get_alloc(dbg, block_size + len_size);
    if (new_attr->ar_data == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (do_len_as_int) {
	WRITE_UNALIGNED(dbg, block_dest_ptr, (const void *) &block_size,
			sizeof(block_size), len_size);
    } else {
	/* is uleb number form */
	memcpy(block_dest_ptr, len_str, len_size);
    }
    block_dest_ptr += len_size;
    memcpy(block_dest_ptr, &(loc_expr->ex_byte_stream[0]), block_size);

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #24
0
/*
    This function adds attributes whose value
    is an signed constant.  It determines the 
    size of the value field from the value of 
    the constant.
*/
Dwarf_P_Attribute
dwarf_add_AT_signed_const(Dwarf_P_Debug dbg,
			  Dwarf_P_Die ownerdie,
			  Dwarf_Half attr,
			  Dwarf_Signed value, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    Dwarf_Half attr_form;
    Dwarf_Small size;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    switch (attr) {
    case DW_AT_upper_bound:
    case DW_AT_lower_bound:
	break;

    default:{
	    _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
    }

    /* Compute the number of bytes needed to hold constant.
       gdb seems to treat all the DW_FORM_data forms as unsigned, so
       if we have a negative number we need to encode it as signed
       data. */
    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (value < 0) {
	attr_form = DW_FORM_sdata;
    } else if (value >= SCHAR_MIN && value <= SCHAR_MAX) {
	attr_form = DW_FORM_data1;
	size = 1;
    } else if (value >= SHRT_MIN && value <= SHRT_MAX) {
	attr_form = DW_FORM_data2;
	size = 2;
    } else if (value >= INT_MIN && value <= INT_MAX) {
	attr_form = DW_FORM_data4;
	size = 4;
    } else {
	attr_form = DW_FORM_data8;
	size = 8;
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = attr_form;
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_reloc_len = 0;	/* irrelevant: unused with R_MIPS_NONE 
				 */
    new_attr->ar_nbytes = size;
    new_attr->ar_next = 0;

    if (attr_form == DW_FORM_sdata) {
        int leb_size;
        char encode_buffer[ENCODE_SPACE_NEEDED];
        int res;

        res = _dwarf_pro_encode_signed_leb128_nm(
	    value, &leb_size,
	    encode_buffer,sizeof(encode_buffer));
        if (res != DW_DLV_OK) {
            _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
            return (Dwarf_P_Attribute) DW_DLV_BADADDR;
        }
        new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, leb_size);
        if (new_attr->ar_data == NULL) {
            _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
            return (Dwarf_P_Attribute) DW_DLV_BADADDR;
        }
        memcpy(new_attr->ar_data,encode_buffer,leb_size);
        new_attr->ar_nbytes = leb_size;
    } else {
	new_attr->ar_data = (char *) _dwarf_p_get_alloc(dbg, size);
	if (new_attr->ar_data == NULL) {
	    _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
	WRITE_UNALIGNED(dbg, new_attr->ar_data,
			(const void *) &value, sizeof(value), size);
    }


    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #25
0
/*
    This function adds attributes whose value
    is an unsigned constant.  It determines the 
    size of the value field from the value of 
    the constant.
*/
Dwarf_P_Attribute
dwarf_add_AT_unsigned_const(Dwarf_P_Debug dbg,
			    Dwarf_P_Die ownerdie,
			    Dwarf_Half attr,
			    Dwarf_Unsigned value, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    Dwarf_Half attr_form;
    Dwarf_Small size;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    switch (attr) {
    case DW_AT_ordering:
    case DW_AT_byte_size:
    case DW_AT_bit_offset:
    case DW_AT_bit_size:
    case DW_AT_inline:
    case DW_AT_language:
    case DW_AT_visibility:
    case DW_AT_virtuality:
    case DW_AT_accessibility:
    case DW_AT_address_class:
    case DW_AT_calling_convention:
    case DW_AT_encoding:
    case DW_AT_identifier_case:
    case DW_AT_MIPS_loop_unroll_factor:
    case DW_AT_MIPS_software_pipeline_depth:
	break;

    case DW_AT_decl_column:
    case DW_AT_decl_file:
    case DW_AT_decl_line:
    case DW_AT_const_value:
    case DW_AT_start_scope:
    case DW_AT_stride_size:
    case DW_AT_count:
	break;

    default:{
	    _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
    }

    /* 
       Compute the number of bytes needed to hold constant. */
    if (value <= UCHAR_MAX) {
	attr_form = DW_FORM_data1;
	size = 1;
    } else if (value <= USHRT_MAX) {
	attr_form = DW_FORM_data2;
	size = 2;
    } else if (value <= UINT_MAX) {
	attr_form = DW_FORM_data4;
	size = 4;
    } else {
	attr_form = DW_FORM_data8;
	size = 8;
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = attr_form;
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_reloc_len = 0;	/* irrelevant: unused with R_MIPS_NONE */
    new_attr->ar_nbytes = size;
    new_attr->ar_next = 0;

    new_attr->ar_data = (char *)
	_dwarf_p_get_alloc(dbg, size);
    if (new_attr->ar_data == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    WRITE_UNALIGNED(dbg, new_attr->ar_data,
		    (const void *) &value, sizeof(value), size);

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #26
0
/*
    Generic routine to add opcode to fde instructions. val1 and
    val2 are parameters whose interpretation depends on the 'op'.

    This does not work properly for  DW_DLC_SYMBOLIC_RELOCATIONS
    for DW_CFA_set_loc or DW_DVA_advance_loc* 'op', as
    these ops normally are addresses or (DW_CFA_set_loc) 
    or code lengths (DW_DVA_advance_loc*) and such must be
    represented with relocations and symbol indices for
    DW_DLC_SYMBOLIC_RELOCATIONS.

*/
Dwarf_P_Fde
dwarf_add_fde_inst(Dwarf_P_Fde fde,
		   Dwarf_Small op,
		   Dwarf_Unsigned val1,
		   Dwarf_Unsigned val2, Dwarf_Error * error)
{
    Dwarf_P_Frame_Pgm curinst;
    int nbytes, nbytes1, nbytes2;
    Dwarf_Ubyte db;
    Dwarf_Half dh;
    Dwarf_Word dw;
    Dwarf_Unsigned du;
    char *ptr;
    int res;
    char buff1[ENCODE_SPACE_NEEDED];
    char buff2[ENCODE_SPACE_NEEDED];


    nbytes = 0;
    ptr = NULL;
    curinst = (Dwarf_P_Frame_Pgm)
	_dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Frame_Pgm_s));
    if (curinst == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_FPGM_ALLOC);
	return ((Dwarf_P_Fde) DW_DLV_BADADDR);
    }

    switch (op) {

#ifdef TARG_X8664
	case DW_CFA_advance_loc4:
	    // We will use 2 half-words to copy the labels; cg will later
	    // fix the relocatable symbols.
	    dh = val1;
	    ptr = (char *) _dwarf_p_get_alloc(NULL, 4);
	    if (ptr == NULL) {
	      _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	      return((Dwarf_P_Fde)DW_DLV_BADADDR);
	    }
	    memcpy((void *)ptr, (const void *)&dh,2);
	    dh = val2;
	    memcpy((void *)ptr+2, (const void *)&dh,2);
	    nbytes = 4;
	    break;
#endif // TARG_X8664
    case DW_CFA_advance_loc:
	if (val1 <= 0x3f) {
	    db = val1;
	    op |= db;
	}
	/* test not portable FIX */
	else if (val1 <= UCHAR_MAX) {
	    op = DW_CFA_advance_loc1;
	    db = val1;
	    ptr = (char *) _dwarf_p_get_alloc(NULL, 1);
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy((void *) ptr, (const void *) &db, 1);
	    nbytes = 1;
	}
	/* test not portable FIX */
	else if (val1 <= USHRT_MAX) {
	    op = DW_CFA_advance_loc2;
	    dh = val1;
	    ptr = (char *) _dwarf_p_get_alloc(NULL, 2);
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy((void *) ptr, (const void *) &dh, 2);
	    nbytes = 2;
	}
	/* test not portable FIX */
	else if (val1 <= ULONG_MAX) {
	    op = DW_CFA_advance_loc4;
	    dw = (Dwarf_Word) val1;
	    ptr = (char *) _dwarf_p_get_alloc(NULL, 4);
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy((void *) ptr, (const void *) &dw, 4);
	    nbytes = 4;
	} else {
	    op = DW_CFA_MIPS_advance_loc8;
	    du = val1;
	    ptr =
		(char *) _dwarf_p_get_alloc(NULL,
					    sizeof(Dwarf_Unsigned));
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy((void *) ptr, (const void *) &du, 8);
	    nbytes = 8;
	}
	break;

    case DW_CFA_offset:
	if (val1 <= MAX_6_BIT_VALUE) {
	    db = val1;
	    op |= db;
	    res = _dwarf_pro_encode_leb128_nm(val2, &nbytes,
					      buff1, sizeof(buff1));
	    if (res != DW_DLV_OK) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes);
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy(ptr, buff1, nbytes);

	} else {
	    op = DW_CFA_offset_extended;

	    res = _dwarf_pro_encode_leb128_nm(val1, &nbytes1,
					      buff1, sizeof(buff1));
	    if (res != DW_DLV_OK) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
					      buff2, sizeof(buff2));
	    if (res != DW_DLV_OK) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes1 + nbytes2);
	    if (ptr == NULL) {
		_dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
		return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	    }
	    memcpy(ptr, buff1, nbytes1);
	    memcpy(ptr + nbytes1, buff2, nbytes2);
	    nbytes = nbytes1 + nbytes2;
	}
	break;

    case DW_CFA_undefined:
    case DW_CFA_same_value:
	res = _dwarf_pro_encode_leb128_nm(val1, &nbytes,
					  buff1, sizeof(buff1));
	if (res != DW_DLV_OK) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}
	ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes);
	if (ptr == NULL) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}
	memcpy(ptr, buff1, nbytes);
	break;

    case DW_CFA_register:
    case DW_CFA_def_cfa:
	res = _dwarf_pro_encode_leb128_nm(val1, &nbytes1,
					  buff1, sizeof(buff1));
	if (res != DW_DLV_OK) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}

	res = _dwarf_pro_encode_leb128_nm(val2, &nbytes2,
					  buff2, sizeof(buff2));
	if (res != DW_DLV_OK) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}

	ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes1 + nbytes2);
	if (ptr == NULL) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}
	memcpy(ptr, buff1, nbytes1);
	memcpy(ptr + nbytes1, buff2, nbytes2);
	nbytes = nbytes1 + nbytes2;
	break;

    case DW_CFA_def_cfa_register:
    case DW_CFA_def_cfa_offset:
	res = _dwarf_pro_encode_leb128_nm(val1, &nbytes,
					  buff1, sizeof(buff1));
	if (res != DW_DLV_OK) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}
	ptr = (char *) _dwarf_p_get_alloc(NULL, nbytes);
	if (ptr == NULL) {
	    _dwarf_p_error(NULL, error, DW_DLE_STRING_ALLOC);
	    return ((Dwarf_P_Fde) DW_DLV_BADADDR);
	}
	memcpy(ptr, buff1, nbytes);
	break;

    default:
	break;
    }

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

    _dwarf_pro_add_to_fde(fde, curinst);
    return fde;
}
Пример #27
0
/*
    This function adds attributes of reference class.
    The references here are local CU references, 
    not DW_FORM_ref_addr.
    The offset field is 4 bytes for 32-bit objects,
    and 8-bytes for 64-bit objects.  Otherdie is the
    that is referenced by ownerdie.

    For reference attributes, the ar_data and ar_nbytes
    are not needed.  Instead, the ar_ref_die points to
    the other die, and its di_offset value is used as
    the reference value.
*/
Dwarf_P_Attribute
dwarf_add_AT_reference(Dwarf_P_Debug dbg,
		       Dwarf_P_Die ownerdie,
		       Dwarf_Half attr,
		       Dwarf_P_Die otherdie, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (otherdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    switch (attr) {
    case DW_AT_specification:
    case DW_AT_discr:
    case DW_AT_common_reference:
    case DW_AT_import:
    case DW_AT_containing_type:
    case DW_AT_default_value:
    case DW_AT_abstract_origin:
    case DW_AT_friend:
    case DW_AT_priority:
    case DW_AT_type:
    case DW_AT_lower_bound:
    case DW_AT_upper_bound:
    case DW_AT_count:
    case DW_AT_sibling:
    case DW_AT_MIPS_stride:
    case DW_AT_MIPS_stride_byte:
    case DW_AT_MIPS_stride_elem:
    case DW_AT_MIPS_clone_origin:
    case DW_AT_MIPS_ptr_dopetype:
    case DW_AT_MIPS_allocatable_dopetype:
    case DW_AT_MIPS_assumed_shape_dopetype:
	break;

    default:{
	    _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = dbg->de_ar_ref_attr_form;
    new_attr->ar_nbytes = dbg->de_offset_size;
    new_attr->ar_reloc_len = dbg->de_offset_size;
    new_attr->ar_ref_die = otherdie;
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_next = 0;

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #28
0
/*
    This function adds attributes of the flag class.
*/
Dwarf_P_Attribute
dwarf_add_AT_flag(Dwarf_P_Debug dbg,
		  Dwarf_P_Die ownerdie,
		  Dwarf_Half attr,
		  Dwarf_Small flag, Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    switch (attr) {
    case DW_AT_is_optional:
    case DW_AT_artificial:
    case DW_AT_declaration:
    case DW_AT_external:
    case DW_AT_prototyped:
    case DW_AT_variable_parameter:
    case DW_AT_MIPS_has_inlines:
    case DW_AT_MIPS_assumed_size:
	break;

    default:{
	    _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	    return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
	}
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = DW_FORM_flag;
    new_attr->ar_nbytes = 1;
    new_attr->ar_reloc_len = 0;	/* not used */
    new_attr->ar_rel_type = R_MIPS_NONE;
    new_attr->ar_next = 0;

    new_attr->ar_data = (char *)
	_dwarf_p_get_alloc(dbg, 1);
    if (new_attr->ar_data == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    memcpy(new_attr->ar_data, &flag, 1);

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #29
0
/* new interface */
Dwarf_P_Attribute
dwarf_add_AT_targ_address_b(Dwarf_P_Debug dbg,
			    Dwarf_P_Die ownerdie,
			    Dwarf_Half attr,
			    Dwarf_Unsigned pc_value,
			    Dwarf_Unsigned sym_index,
			    Dwarf_Error * error)
{
    Dwarf_P_Attribute new_attr;
    int upointer_size = dbg->de_pointer_size;

    if (dbg == NULL) {
	_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (ownerdie == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    if (attr != DW_AT_low_pc && attr != DW_AT_high_pc &&
	attr != DW_AT_MIPS_loop_begin &&
	attr != DW_AT_MIPS_tail_loop_begin &&
	attr != DW_AT_MIPS_epilog_begin) {
	_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr = (Dwarf_P_Attribute)
	_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
    if (new_attr == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }

    new_attr->ar_attribute = attr;
    new_attr->ar_attribute_form = DW_FORM_addr;
    new_attr->ar_nbytes = upointer_size;
    new_attr->ar_rel_symidx = sym_index;
    new_attr->ar_reloc_len = upointer_size;
    new_attr->ar_next = 0;
    if (sym_index != NO_ELF_SYM_INDEX)
	new_attr->ar_rel_type = dbg->de_ptr_reloc;
    else
	new_attr->ar_rel_type = R_MIPS_NONE;

    new_attr->ar_data = (char *)
	_dwarf_p_get_alloc(dbg, upointer_size);
    if (new_attr->ar_data == NULL) {
	_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
    }
    WRITE_UNALIGNED(dbg, new_attr->ar_data,
		    (const void *) &pc_value,
		    sizeof(pc_value), upointer_size);

    /* add attribute to the die */
    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
    return new_attr;
}
Пример #30
0
static int
libdwarf_compose_begin(Dwarf_P_Debug dbg, int code,
		       size_t maxlen, int *compose_error_type)
{
    unsigned char *nextchar;
    struct dw_macinfo_block_s *curblk = dbg->de_current_macinfo;

    if (curblk == 0) {
	struct dw_macinfo_block_s *newb;
	size_t len;

	/* initial allocation */
	size_t blen = BASE_MACINFO_MALLOC_LEN;

	if (blen < maxlen) {
	    blen = 2 * maxlen;
	}
	len = sizeof(struct dw_macinfo_block_s) + blen;
	newb =
	    (struct dw_macinfo_block_s *) _dwarf_p_get_alloc(dbg, len);
	if (!newb) {
	    *compose_error_type = DW_DLE_MACINFO_MALLOC_FAIL;
	    return DW_DLV_ERROR;
	}
	newb->mb_data =
	    (char *) newb + sizeof(struct dw_macinfo_block_s);
	newb->mb_avail_len = blen;
	newb->mb_used_len = 0;
	newb->mb_macinfo_data_space_len = blen;
	dbg->de_first_macinfo = newb;
	dbg->de_current_macinfo = newb;
	curblk = newb;
    } else if (curblk->mb_avail_len < maxlen) {
	struct dw_macinfo_block_s *newb;
	size_t len;

	/* no space left in block: allocate a new block */
	size_t blen =
	    dbg->de_current_macinfo->mb_macinfo_data_space_len * 2;
	if (blen < maxlen) {
	    blen = 2 * maxlen;
	}
	len = sizeof(struct dw_macinfo_block_s) + blen;
	newb =
	    (struct dw_macinfo_block_s *) _dwarf_p_get_alloc(dbg, len);
	if (!newb) {
	    *compose_error_type = DW_DLE_MACINFO_MALLOC_FAIL;
	    return DW_DLV_ERROR;
	}
	newb->mb_data =
	    (char *) newb + sizeof(struct dw_macinfo_block_s);
	newb->mb_avail_len = blen;
	newb->mb_used_len = 0;
	newb->mb_macinfo_data_space_len = blen;
	dbg->de_first_macinfo->mb_next = newb;
	dbg->de_current_macinfo = newb;
	curblk = newb;
    }
    /* now curblk has enough room */
    dbg->de_compose_avail = curblk->mb_avail_len;
    dbg->de_compose_used_len = curblk->mb_used_len;
    nextchar =
	(unsigned char *) (curblk->mb_data + dbg->de_compose_used_len);
    *nextchar = code;
    dbg->de_compose_avail--;
    ++dbg->de_compose_used_len;
    return DW_DLV_OK;
}