00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "config.h"
00043 #include "libdwarfdefs.h"
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <limits.h>
00047 #include "pro_incl.h"
00048 #include "pro_expr.h"
00049
00050 #ifndef R_MIPS_NONE
00051 #define R_MIPS_NONE 0
00052 #endif
00053
00054
00055
00056 #define NO_ELF_SYM_INDEX 0
00057
00058
00059
00060 extern void _dwarf_pro_add_at_to_die(Dwarf_P_Die die,
00061 Dwarf_P_Attribute attr);
00062
00063
00064
00065
00066
00067
00068
00069
00070 Dwarf_P_Attribute
00071 dwarf_add_AT_targ_address(Dwarf_P_Debug dbg,
00072 Dwarf_P_Die ownerdie,
00073 Dwarf_Half attr,
00074 Dwarf_Unsigned pc_value,
00075 Dwarf_Signed sym_index, Dwarf_Error * error)
00076 {
00077 return
00078 dwarf_add_AT_targ_address_b(dbg,
00079 ownerdie,
00080 attr,
00081 pc_value,
00082 (Dwarf_Unsigned) sym_index, error);
00083 }
00084
00085
00086 Dwarf_P_Attribute
00087 dwarf_add_AT_targ_address_b(Dwarf_P_Debug dbg,
00088 Dwarf_P_Die ownerdie,
00089 Dwarf_Half attr,
00090 Dwarf_Unsigned pc_value,
00091 Dwarf_Unsigned sym_index,
00092 Dwarf_Error * error)
00093 {
00094 Dwarf_P_Attribute new_attr;
00095 int upointer_size = dbg->de_pointer_size;
00096
00097 if (dbg == NULL) {
00098 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00099 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00100 }
00101
00102 if (ownerdie == NULL) {
00103 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00104 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00105 }
00106
00107 if (attr != DW_AT_low_pc && attr != DW_AT_high_pc &&
00108 attr != DW_AT_MIPS_loop_begin &&
00109 attr != DW_AT_MIPS_tail_loop_begin &&
00110 attr != DW_AT_MIPS_epilog_begin) {
00111 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00112 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00113 }
00114
00115 new_attr = (Dwarf_P_Attribute)
00116 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00117 if (new_attr == NULL) {
00118 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00119 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00120 }
00121
00122 new_attr->ar_attribute = attr;
00123 new_attr->ar_attribute_form = DW_FORM_addr;
00124 new_attr->ar_nbytes = upointer_size;
00125 new_attr->ar_rel_symidx = sym_index;
00126 new_attr->ar_reloc_len = upointer_size;
00127 new_attr->ar_next = 0;
00128 if (sym_index != NO_ELF_SYM_INDEX)
00129 new_attr->ar_rel_type = dbg->de_ptr_reloc;
00130 else
00131 new_attr->ar_rel_type = R_MIPS_NONE;
00132
00133 new_attr->ar_data = (char *)
00134 _dwarf_p_get_alloc(dbg, upointer_size);
00135 if (new_attr->ar_data == NULL) {
00136 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00137 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00138 }
00139 WRITE_UNALIGNED(dbg, new_attr->ar_data,
00140 (const void *) &pc_value,
00141 sizeof(pc_value), upointer_size);
00142
00143
00144 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00145 return new_attr;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155 Dwarf_P_Attribute
00156 dwarf_add_AT_unsigned_const(Dwarf_P_Debug dbg,
00157 Dwarf_P_Die ownerdie,
00158 Dwarf_Half attr,
00159 Dwarf_Unsigned value, Dwarf_Error * error)
00160 {
00161 Dwarf_P_Attribute new_attr;
00162 Dwarf_Half attr_form;
00163 Dwarf_Small size;
00164
00165 if (dbg == NULL) {
00166 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00167 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00168 }
00169
00170 if (ownerdie == NULL) {
00171 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00172 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00173 }
00174
00175 switch (attr) {
00176 case DW_AT_ordering:
00177 case DW_AT_byte_size:
00178 case DW_AT_bit_offset:
00179 case DW_AT_bit_size:
00180 case DW_AT_inline:
00181 case DW_AT_language:
00182 case DW_AT_visibility:
00183 case DW_AT_virtuality:
00184 case DW_AT_accessibility:
00185 case DW_AT_address_class:
00186 case DW_AT_calling_convention:
00187 case DW_AT_encoding:
00188 case DW_AT_identifier_case:
00189 case DW_AT_MIPS_loop_unroll_factor:
00190 case DW_AT_MIPS_software_pipeline_depth:
00191 break;
00192
00193 case DW_AT_decl_column:
00194 case DW_AT_decl_file:
00195 case DW_AT_decl_line:
00196 case DW_AT_const_value:
00197 case DW_AT_start_scope:
00198 case DW_AT_stride_size:
00199 case DW_AT_count:
00200 break;
00201
00202 default:{
00203 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00204 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00205 }
00206 }
00207
00208
00209
00210 if (value <= UCHAR_MAX) {
00211 attr_form = DW_FORM_data1;
00212 size = 1;
00213 } else if (value <= USHRT_MAX) {
00214 attr_form = DW_FORM_data2;
00215 size = 2;
00216 } else if (value <= UINT_MAX) {
00217 attr_form = DW_FORM_data4;
00218 size = 4;
00219 } else {
00220 attr_form = DW_FORM_data8;
00221 size = 8;
00222 }
00223
00224 new_attr = (Dwarf_P_Attribute)
00225 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00226 if (new_attr == NULL) {
00227 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00228 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00229 }
00230
00231 new_attr->ar_attribute = attr;
00232 new_attr->ar_attribute_form = attr_form;
00233 new_attr->ar_rel_type = R_MIPS_NONE;
00234 new_attr->ar_reloc_len = 0;
00235 new_attr->ar_nbytes = size;
00236 new_attr->ar_next = 0;
00237
00238 new_attr->ar_data = (char *)
00239 _dwarf_p_get_alloc(dbg, size);
00240 if (new_attr->ar_data == NULL) {
00241 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00242 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00243 }
00244 WRITE_UNALIGNED(dbg, new_attr->ar_data,
00245 (const void *) &value, sizeof(value), size);
00246
00247
00248 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00249 return new_attr;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259 Dwarf_P_Attribute
00260 dwarf_add_AT_signed_const(Dwarf_P_Debug dbg,
00261 Dwarf_P_Die ownerdie,
00262 Dwarf_Half attr,
00263 Dwarf_Signed value, Dwarf_Error * error)
00264 {
00265 Dwarf_P_Attribute new_attr;
00266 Dwarf_Half attr_form;
00267 Dwarf_Small size;
00268
00269 if (dbg == NULL) {
00270 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00271 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00272 }
00273
00274 if (ownerdie == NULL) {
00275 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00276 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00277 }
00278
00279 switch (attr) {
00280 case DW_AT_upper_bound:
00281 case DW_AT_lower_bound:
00282 break;
00283
00284 default:{
00285 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00286 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00287 }
00288 }
00289
00290
00291
00292
00293
00294 new_attr = (Dwarf_P_Attribute)
00295 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
00296 if (new_attr == NULL) {
00297 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00298 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00299 }
00300
00301 if (value < 0) {
00302 attr_form = DW_FORM_sdata;
00303 } else if (value >= SCHAR_MIN && value <= SCHAR_MAX) {
00304 attr_form = DW_FORM_data1;
00305 size = 1;
00306 } else if (value >= SHRT_MIN && value <= SHRT_MAX) {
00307 attr_form = DW_FORM_data2;
00308 size = 2;
00309 } else if (value >= INT_MIN && value <= INT_MAX) {
00310 attr_form = DW_FORM_data4;
00311 size = 4;
00312 } else {
00313 attr_form = DW_FORM_data8;
00314 size = 8;
00315 }
00316
00317 new_attr->ar_attribute = attr;
00318 new_attr->ar_attribute_form = attr_form;
00319 new_attr->ar_rel_type = R_MIPS_NONE;
00320 new_attr->ar_reloc_len = 0;
00321
00322 new_attr->ar_nbytes = size;
00323 new_attr->ar_next = 0;
00324
00325 if (attr_form == DW_FORM_sdata) {
00326 int leb_size;
00327 char encode_buffer[ENCODE_SPACE_NEEDED];
00328 int res;
00329
00330 res = _dwarf_pro_encode_signed_leb128_nm(
00331 value, &leb_size,
00332 encode_buffer,sizeof(encode_buffer));
00333 if (res != DW_DLV_OK) {
00334 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00335 return (Dwarf_P_Attribute) DW_DLV_BADADDR;
00336 }
00337 new_attr->ar_data = (char *) _dwarf_p_get_alloc(NULL, leb_size);
00338 if (new_attr->ar_data == NULL) {
00339 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00340 return (Dwarf_P_Attribute) DW_DLV_BADADDR;
00341 }
00342 memcpy(new_attr->ar_data,encode_buffer,leb_size);
00343 new_attr->ar_nbytes = leb_size;
00344 } else {
00345 new_attr->ar_data = (char *) _dwarf_p_get_alloc(dbg, size);
00346 if (new_attr->ar_data == NULL) {
00347 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00348 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00349 }
00350 WRITE_UNALIGNED(dbg, new_attr->ar_data,
00351 (const void *) &value, sizeof(value), size);
00352 }
00353
00354
00355
00356 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00357 return new_attr;
00358 }
00359
00360
00361
00362
00363
00364
00365 Dwarf_P_Attribute
00366 dwarf_add_AT_location_expr(Dwarf_P_Debug dbg,
00367 Dwarf_P_Die ownerdie,
00368 Dwarf_Half attr,
00369 Dwarf_P_Expr loc_expr, Dwarf_Error * error)
00370 {
00371 char encode_buffer[ENCODE_SPACE_NEEDED];
00372 int res;
00373 Dwarf_P_Attribute new_attr;
00374 Dwarf_Half attr_form;
00375 char *len_str;
00376 int len_size;
00377 int block_size;
00378 char *block_dest_ptr;
00379 int do_len_as_int = 0;
00380
00381 if (dbg == NULL) {
00382 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00383 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00384 }
00385
00386 if (ownerdie == NULL) {
00387 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00388 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00389 }
00390
00391 if (loc_expr == NULL) {
00392 _dwarf_p_error(dbg, error, DW_DLE_EXPR_NULL);
00393 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00394 }
00395
00396 if (loc_expr->ex_dbg != dbg) {
00397 _dwarf_p_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
00398 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00399 }
00400 block_size = loc_expr->ex_next_byte_offset;
00401
00402 switch (attr) {
00403 case DW_AT_location:
00404 case DW_AT_string_length:
00405 case DW_AT_const_value:
00406 case DW_AT_use_location:
00407 case DW_AT_return_addr:
00408 case DW_AT_data_member_location:
00409 case DW_AT_frame_base:
00410 case DW_AT_static_link:
00411 case DW_AT_vtable_elem_location:
00412 break;
00413
00414 default:{
00415 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00416 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00417 }
00418 }
00419
00420
00421
00422 if (block_size <= UCHAR_MAX) {
00423 attr_form = DW_FORM_block1;
00424 len_size = 1;
00425 do_len_as_int = 1;
00426 } else if (block_size <= USHRT_MAX) {
00427 attr_form = DW_FORM_block2;
00428 len_size = 2;
00429 do_len_as_int = 1;
00430 } else if (block_size <= UINT_MAX) {
00431 attr_form = DW_FORM_block4;
00432 len_size = 4;
00433 do_len_as_int = 1;
00434 } else {
00435 attr_form = DW_FORM_block;
00436 res = _dwarf_pro_encode_leb128_nm(block_size, &len_size,
00437 encode_buffer,
00438 sizeof(encode_buffer));
00439 if (res != DW_DLV_OK) {
00440 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00441 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00442 }
00443 len_str = (char *) encode_buffer;
00444 }
00445
00446 new_attr = (Dwarf_P_Attribute)
00447 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00448 if (new_attr == NULL) {
00449 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00450 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00451 }
00452
00453 new_attr->ar_attribute = attr;
00454 new_attr->ar_attribute_form = attr_form;
00455 new_attr->ar_reloc_len = dbg->de_pointer_size;
00456 if (loc_expr->ex_reloc_sym_index != NO_ELF_SYM_INDEX) {
00457 new_attr->ar_rel_type = dbg->de_ptr_reloc;
00458 } else {
00459 new_attr->ar_rel_type = R_MIPS_NONE;
00460 }
00461 new_attr->ar_rel_symidx = loc_expr->ex_reloc_sym_index;
00462 new_attr->ar_rel_offset =
00463 (Dwarf_Word) loc_expr->ex_reloc_offset + len_size;
00464
00465 new_attr->ar_nbytes = block_size + len_size;
00466
00467 new_attr->ar_next = 0;
00468 new_attr->ar_data = block_dest_ptr =
00469 (char *) _dwarf_p_get_alloc(dbg, block_size + len_size);
00470 if (new_attr->ar_data == NULL) {
00471 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00472 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00473 }
00474
00475 if (do_len_as_int) {
00476 WRITE_UNALIGNED(dbg, block_dest_ptr, (const void *) &block_size,
00477 sizeof(block_size), len_size);
00478 } else {
00479
00480 memcpy(block_dest_ptr, len_str, len_size);
00481 }
00482 block_dest_ptr += len_size;
00483 memcpy(block_dest_ptr, &(loc_expr->ex_byte_stream[0]), block_size);
00484
00485
00486 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00487 return new_attr;
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 Dwarf_P_Attribute
00505 dwarf_add_AT_reference(Dwarf_P_Debug dbg,
00506 Dwarf_P_Die ownerdie,
00507 Dwarf_Half attr,
00508 Dwarf_P_Die otherdie, Dwarf_Error * error)
00509 {
00510 Dwarf_P_Attribute new_attr;
00511
00512 if (dbg == NULL) {
00513 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00514 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00515 }
00516
00517 if (ownerdie == NULL) {
00518 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00519 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00520 }
00521
00522 if (otherdie == NULL) {
00523 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00524 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00525 }
00526
00527 switch (attr) {
00528 case DW_AT_specification:
00529 case DW_AT_discr:
00530 case DW_AT_common_reference:
00531 case DW_AT_import:
00532 case DW_AT_containing_type:
00533 case DW_AT_default_value:
00534 case DW_AT_abstract_origin:
00535 case DW_AT_friend:
00536 case DW_AT_priority:
00537 case DW_AT_type:
00538 case DW_AT_lower_bound:
00539 case DW_AT_upper_bound:
00540 case DW_AT_count:
00541 case DW_AT_sibling:
00542 case DW_AT_MIPS_stride:
00543 case DW_AT_MIPS_stride_byte:
00544 case DW_AT_MIPS_stride_elem:
00545 case DW_AT_MIPS_clone_origin:
00546 case DW_AT_MIPS_ptr_dopetype:
00547 case DW_AT_MIPS_allocatable_dopetype:
00548 case DW_AT_MIPS_assumed_shape_dopetype:
00549 break;
00550
00551 default:{
00552 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00553 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00554 }
00555 }
00556
00557 new_attr = (Dwarf_P_Attribute)
00558 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00559 if (new_attr == NULL) {
00560 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00561 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00562 }
00563
00564 new_attr->ar_attribute = attr;
00565 new_attr->ar_attribute_form = dbg->de_ar_ref_attr_form;
00566 new_attr->ar_nbytes = dbg->de_offset_size;
00567 new_attr->ar_reloc_len = dbg->de_offset_size;
00568 new_attr->ar_ref_die = otherdie;
00569 new_attr->ar_rel_type = R_MIPS_NONE;
00570 new_attr->ar_next = 0;
00571
00572
00573 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00574 return new_attr;
00575 }
00576
00577
00578
00579
00580
00581 Dwarf_P_Attribute
00582 dwarf_add_AT_flag(Dwarf_P_Debug dbg,
00583 Dwarf_P_Die ownerdie,
00584 Dwarf_Half attr,
00585 Dwarf_Small flag, Dwarf_Error * error)
00586 {
00587 Dwarf_P_Attribute new_attr;
00588
00589 if (dbg == NULL) {
00590 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00591 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00592 }
00593
00594 if (ownerdie == NULL) {
00595 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00596 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00597 }
00598
00599 switch (attr) {
00600 case DW_AT_is_optional:
00601 case DW_AT_artificial:
00602 case DW_AT_declaration:
00603 case DW_AT_external:
00604 case DW_AT_prototyped:
00605 case DW_AT_variable_parameter:
00606 case DW_AT_MIPS_has_inlines:
00607 case DW_AT_MIPS_assumed_size:
00608 #ifdef TARG_X8664
00609 case DW_AT_GNU_vector:
00610 #endif
00611 break;
00612
00613 default:{
00614 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00615 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00616 }
00617 }
00618
00619 new_attr = (Dwarf_P_Attribute)
00620 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00621 if (new_attr == NULL) {
00622 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00623 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00624 }
00625
00626 new_attr->ar_attribute = attr;
00627 new_attr->ar_attribute_form = DW_FORM_flag;
00628 new_attr->ar_nbytes = 1;
00629 new_attr->ar_reloc_len = 0;
00630 new_attr->ar_rel_type = R_MIPS_NONE;
00631 new_attr->ar_next = 0;
00632
00633 new_attr->ar_data = (char *)
00634 _dwarf_p_get_alloc(dbg, 1);
00635 if (new_attr->ar_data == NULL) {
00636 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00637 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00638 }
00639 memcpy(new_attr->ar_data, &flag, 1);
00640
00641
00642 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00643 return new_attr;
00644 }
00645
00646
00647
00648
00649
00650
00651 Dwarf_P_Attribute
00652 dwarf_add_AT_string(Dwarf_P_Debug dbg,
00653 Dwarf_P_Die ownerdie,
00654 Dwarf_Half attr, const char *string, Dwarf_Error * error)
00655 {
00656 Dwarf_P_Attribute new_attr;
00657
00658 if (dbg == NULL) {
00659 _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
00660 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00661 }
00662
00663 if (ownerdie == NULL) {
00664 _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
00665 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00666 }
00667
00668 new_attr = (Dwarf_P_Attribute)
00669 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
00670 if (new_attr == NULL) {
00671 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00672 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00673 }
00674
00675 switch (attr) {
00676 case DW_AT_name:
00677 case DW_AT_comp_dir:
00678 case DW_AT_const_value:
00679 case DW_AT_producer:
00680 case DW_AT_MIPS_linkage_name:
00681 case DW_AT_MIPS_abstract_name:
00682 break;
00683
00684 default:{
00685 _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
00686 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00687 }
00688 }
00689
00690 new_attr->ar_attribute = attr;
00691 new_attr->ar_attribute_form = DW_FORM_string;
00692 new_attr->ar_nbytes = strlen(string) + 1;
00693 new_attr->ar_next = 0;
00694
00695 new_attr->ar_data =
00696 (char *) _dwarf_p_get_alloc(NULL, strlen(string) + 1);
00697 if (new_attr->ar_data == NULL) {
00698 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
00699 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00700 }
00701
00702 strcpy(new_attr->ar_data, string);
00703 new_attr->ar_rel_type = R_MIPS_NONE;
00704 new_attr->ar_reloc_len = 0;
00705
00706
00707 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00708 return new_attr;
00709 }
00710
00711
00712 Dwarf_P_Attribute
00713 dwarf_add_AT_const_value_string(Dwarf_P_Die ownerdie,
00714 char *string_value, Dwarf_Error * error)
00715 {
00716 Dwarf_P_Attribute new_attr;
00717
00718 if (ownerdie == NULL) {
00719 _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
00720 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00721 }
00722
00723 new_attr = (Dwarf_P_Attribute)
00724 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
00725 if (new_attr == NULL) {
00726 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00727 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00728 }
00729
00730 new_attr->ar_attribute = DW_AT_const_value;
00731 new_attr->ar_attribute_form = DW_FORM_string;
00732 new_attr->ar_nbytes = strlen(string_value) + 1;
00733 new_attr->ar_next = 0;
00734
00735 new_attr->ar_data =
00736 (char *) _dwarf_p_get_alloc(NULL, strlen(string_value) + 1);
00737 if (new_attr->ar_data == NULL) {
00738 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00739 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00740 }
00741
00742 strcpy(new_attr->ar_data, string_value);
00743 new_attr->ar_rel_type = R_MIPS_NONE;
00744 new_attr->ar_reloc_len = 0;
00745
00746
00747 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00748 return new_attr;
00749 }
00750
00751
00752 Dwarf_P_Attribute
00753 dwarf_add_AT_producer(Dwarf_P_Die ownerdie,
00754 char *producer_string, Dwarf_Error * error)
00755 {
00756 Dwarf_P_Attribute new_attr;
00757
00758 if (ownerdie == NULL) {
00759 _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
00760 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00761 }
00762
00763 new_attr = (Dwarf_P_Attribute)
00764 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
00765 if (new_attr == NULL) {
00766 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00767 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00768 }
00769
00770 new_attr->ar_attribute = DW_AT_producer;
00771 new_attr->ar_attribute_form = DW_FORM_string;
00772 new_attr->ar_nbytes = strlen(producer_string) + 1;
00773 new_attr->ar_next = 0;
00774
00775 new_attr->ar_data =
00776 (char *) _dwarf_p_get_alloc(NULL, strlen(producer_string) + 1);
00777 if (new_attr->ar_data == NULL) {
00778 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00779 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00780 }
00781
00782 strcpy(new_attr->ar_data, producer_string);
00783 new_attr->ar_rel_type = R_MIPS_NONE;
00784 new_attr->ar_reloc_len = 0;
00785
00786
00787 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00788 return new_attr;
00789 }
00790
00791
00792 Dwarf_P_Attribute
00793 dwarf_add_AT_const_value_signedint(Dwarf_P_Die ownerdie,
00794 Dwarf_Signed signed_value,
00795 Dwarf_Error * error)
00796 {
00797 Dwarf_P_Attribute new_attr;
00798 int leb_size;
00799 char encode_buffer[ENCODE_SPACE_NEEDED];
00800 int res;
00801
00802 if (ownerdie == NULL) {
00803 _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
00804 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00805 }
00806
00807 new_attr = (Dwarf_P_Attribute)
00808 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
00809 if (new_attr == NULL) {
00810 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00811 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00812 }
00813
00814 new_attr->ar_attribute = DW_AT_const_value;
00815 new_attr->ar_attribute_form = DW_FORM_sdata;
00816 new_attr->ar_rel_type = R_MIPS_NONE;
00817 new_attr->ar_reloc_len = 0;
00818 new_attr->ar_next = 0;
00819
00820 res = _dwarf_pro_encode_signed_leb128_nm(signed_value, &leb_size,
00821 encode_buffer,
00822 sizeof(encode_buffer));
00823 if (res != DW_DLV_OK) {
00824 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00825 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00826 }
00827 new_attr->ar_data = (char *)
00828 _dwarf_p_get_alloc(NULL, leb_size);
00829 if (new_attr->ar_data == NULL) {
00830 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00831 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00832 }
00833 memcpy(new_attr->ar_data, encode_buffer, leb_size);
00834 new_attr->ar_nbytes = leb_size;
00835
00836
00837 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00838 return new_attr;
00839 }
00840
00841
00842 Dwarf_P_Attribute
00843 dwarf_add_AT_const_value_unsignedint(Dwarf_P_Die ownerdie,
00844 Dwarf_Unsigned unsigned_value,
00845 Dwarf_Error * error)
00846 {
00847 Dwarf_P_Attribute new_attr;
00848 int leb_size;
00849 char encode_buffer[ENCODE_SPACE_NEEDED];
00850 int res;
00851
00852 if (ownerdie == NULL) {
00853 _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
00854 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00855 }
00856
00857 new_attr = (Dwarf_P_Attribute)
00858 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
00859 if (new_attr == NULL) {
00860 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00861 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00862 }
00863
00864 new_attr->ar_attribute = DW_AT_const_value;
00865 new_attr->ar_attribute_form = DW_FORM_udata;
00866 new_attr->ar_rel_type = R_MIPS_NONE;
00867 new_attr->ar_reloc_len = 0;
00868 new_attr->ar_next = 0;
00869
00870 res = _dwarf_pro_encode_leb128_nm(unsigned_value, &leb_size,
00871 encode_buffer,
00872 sizeof(encode_buffer));
00873 if (res != DW_DLV_OK) {
00874 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00875 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00876 }
00877 new_attr->ar_data = (char *)
00878 _dwarf_p_get_alloc(NULL, leb_size);
00879 if (new_attr->ar_data == NULL) {
00880 _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
00881 return ((Dwarf_P_Attribute) DW_DLV_BADADDR);
00882 }
00883 memcpy(new_attr->ar_data, encode_buffer, leb_size);
00884 new_attr->ar_nbytes = leb_size;
00885
00886
00887 _dwarf_pro_add_at_to_die(ownerdie, new_attr);
00888 return new_attr;
00889 }