00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021 #include "dwarf_stuff.h"
00022 #include "libdwarfdefs.h"
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <limits.h>
00026 #include "pro_incl.h"
00027 #include "pro_expr.h"
00028
00029
00030 extern void _dwarf_pro_add_at_to_die(Dwarf_P_Die die,
00031 Dwarf_P_Attribute attr);
00032
00033
00034
00035
00036
00037
00038
00039
00040 Dwarf_P_Attribute
00041 dwf_add_AT_unsigned_const_ext(Dwarf_P_Debug dbg,
00042 Dwarf_P_Die ownerdie,
00043 Dwarf_Half attr,
00044 Dwarf_Unsigned value,
00045 Dwarf_Error *error,
00046 Dwarf_Unsigned intype)
00047 {
00048 Dwarf_P_Attribute new_attr;
00049 Dwarf_Half attr_form;
00050 Dwarf_Small size;
00051
00052 if (dbg == NULL) {
00053 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00054 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00055 }
00056
00057 if (ownerdie == NULL) {
00058 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00059 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00060 }
00061
00062 if (attr != DW_AT_const_value ||
00063 (intype != 1 && intype != 2 && intype != 4 && intype != 8)) {
00064 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00065 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00066 }
00067
00068
00069
00070
00071
00072 switch (intype) {
00073 case 1: attr_form = DW_FORM_data1; size = 1; break;
00074 case 2: attr_form = DW_FORM_data2; size = 2; break;
00075 case 4: attr_form = DW_FORM_data4; size = 4; break;
00076 case 8: attr_form = DW_FORM_data8; size = 8; break;
00077 }
00078
00079 new_attr = (Dwarf_P_Attribute)
00080 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00081 if (new_attr == NULL) {
00082 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00083 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00084 }
00085
00086 new_attr->ar_attribute = attr;
00087 new_attr->ar_attribute_form = attr_form;
00088 #if defined(BUILD_OS_DARWIN)
00089 #define NO_RELOCATION (~0)
00090 new_attr->ar_rel_type = NO_RELOCATION;
00091 #else
00092 new_attr->ar_rel_type = R_MIPS_NONE;
00093 #endif
00094 new_attr->ar_reloc_len = 0 ;
00095 new_attr->ar_nbytes = size;
00096 new_attr->ar_next = 0;
00097
00098 new_attr->ar_data = (char *)
00099 _dwarf_p_get_alloc(dbg, size);
00100 if (new_attr->ar_data == NULL) {
00101 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00102 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00103 }
00104 WRITE_UNALIGNED(dbg,new_attr->ar_data,
00105 (const void *)&value,
00106 sizeof(value),
00107 size);
00108
00109
00110 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00111 return new_attr;
00112 }
00113
00114
00115
00116
00117
00118 Dwarf_P_Attribute
00119 dwf_add_AT_complex_const(Dwarf_P_Debug dbg,
00120 Dwarf_P_Die ownerdie,
00121 Dwarf_Half attr,
00122 Dwarf_Unsigned value1,
00123 Dwarf_Unsigned value2,
00124 Dwarf_Error *error,
00125 Dwarf_Unsigned intype)
00126 {
00127 char encode_buffer[ENCODE_SPACE_NEEDED];
00128 Dwarf_P_Attribute new_attr;
00129 Dwarf_Small size;
00130 char value[17];
00131 int index, shift;
00132 char *block_dest_ptr;
00133
00134 if (dbg == NULL) {
00135 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00136 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00137 }
00138
00139 if (ownerdie == NULL) {
00140 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00141 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00142 }
00143
00144 if (attr != DW_AT_const_value ||
00145 (intype != 4 && intype != 8)) {
00146 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00147 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00148 }
00149
00150
00151
00152
00153
00154 switch (intype) {
00155 case 4: size = 8; break;
00156 case 8: size = 16; break;
00157 }
00158
00159 value[0] = size;
00160 for (index = 0; index < size/2; index ++)
00161 value[index+1] = (value1 >> (index * 8)) & 0xff;
00162 for (index = 0; index < size/2; index ++)
00163 value[index+size/2+1] = (value2 >> (index * 8)) & 0xff;
00164
00165 new_attr = (Dwarf_P_Attribute)
00166 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00167 if (new_attr == NULL) {
00168 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00169 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00170 }
00171
00172 new_attr->ar_attribute = attr;
00173 new_attr->ar_attribute_form = DW_FORM_block;
00174 #if defined(BUILD_OS_DARWIN)
00175 new_attr->ar_rel_type = NO_RELOCATION;
00176 #else
00177 new_attr->ar_rel_type = R_MIPS_NONE;
00178 #endif
00179 new_attr->ar_reloc_len = 0 ;
00180 new_attr->ar_nbytes = size+1;
00181 new_attr->ar_next = 0;
00182
00183 new_attr->ar_data = block_dest_ptr = (char *)
00184 _dwarf_p_get_alloc(dbg, size+1);
00185 if (new_attr->ar_data == NULL) {
00186 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00187 return((Dwarf_P_Attribute)DW_DLV_BADADDR);
00188 }
00189
00190 memcpy(block_dest_ptr, &value[0], size+1);
00191
00192
00193 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00194 return new_attr;
00195 }