| 1 |
/* |
| 2 |
Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. |
| 3 |
Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved. |
| 4 |
Portions Copyright 2007-2020 David Anderson. All rights reserved. |
| 5 |
Portions Copyright 2012 SN Systems Ltd. All rights reserved. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of version 2.1 of the |
| 9 |
GNU Lesser General Public License as published by the Free |
| 10 |
Software Foundation. |
| 11 |
|
| 12 |
This program is distributed in the hope that it would be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 14 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 |
PURPOSE. |
| 16 |
|
| 17 |
Further, this software is distributed without any warranty |
| 18 |
that it is free of the rightful claim of any third person |
| 19 |
regarding infringement or the like. Any license provided |
| 20 |
herein, whether implied or otherwise, applies only to this |
| 21 |
software file. Patent licenses, if any, provided herein |
| 22 |
do not apply to combinations of this program with other |
| 23 |
software, or any other product whatsoever. |
| 24 |
|
| 25 |
You should have received a copy of the GNU Lesser General |
| 26 |
Public License along with this program; if not, write the |
| 27 |
Free Software Foundation, Inc., 51 Franklin Street - Fifth |
| 28 |
Floor, Boston MA 02110-1301, USA. |
| 29 |
|
| 30 |
*/ |
| 31 |
|
| 32 |
#include <config.h> |
| 33 |
|
| 34 |
#include <limits.h> /* INT_MAX and al. */ |
| 35 |
#include <stddef.h> /* NULL */ |
| 36 |
#include <string.h> /* memcpy() */ |
| 37 |
|
| 38 |
#include "dwarf.h" |
| 39 |
#include "libdwarf.h" |
| 40 |
#include "dwarf_base_types.h" |
| 41 |
#include "libdwarfp.h" |
| 42 |
#include "dwarf_pro_incl.h" |
| 43 |
#include "dwarf_pro_opaque.h" |
| 44 |
#include "dwarf_pro_error.h" |
| 45 |
#include "dwarf_pro_alloc.h" |
| 46 |
#include "dwarf_pro_die.h" |
| 47 |
#include "dwarf_pro_expr.h" |
| 48 |
|
| 49 |
#ifdef WORDS_BIGENDIAN |
| 50 |
#define ASNARD(t,s,l) \ |
| 51 |
do { \ |
| 52 |
unsigned tbyte = sizeof(t) - l; \ |
| 53 |
t = 0; \ |
| 54 |
dbg->de_copy_word(((char *)&t)+tbyte ,&s[0],l);\ |
| 55 |
} while (0) |
| 56 |
#else /* LITTLE ENDIAN */ |
| 57 |
#define ASNARD(t,s,l) \ |
| 58 |
do { \ |
| 59 |
t = 0; \ |
| 60 |
dbg->de_copy_word(&t,&s[0],l); \ |
| 61 |
} while (0) |
| 62 |
#endif /* end LITTLE- BIG-ENDIAN */ |
| 63 |
|
| 64 |
/* This function adds an attribute whose value is |
| 65 |
a target address to the given die. The attribute |
| 66 |
is given the name provided by attr. The address |
| 67 |
is given in pc_value. */ |
| 68 |
|
| 69 |
static int |
| 70 |
local_add_AT_address_a(Dwarf_P_Debug dbg, |
| 71 |
Dwarf_P_Die ownerdie, |
| 72 |
Dwarf_Half attr, |
| 73 |
Dwarf_Signed form, |
| 74 |
Dwarf_Unsigned pc_value, |
| 75 |
Dwarf_Unsigned sym_index, |
| 76 |
Dwarf_P_Attribute *attr_out, |
| 77 |
Dwarf_Error * error); |
| 78 |
|
| 79 |
int |
| 80 |
dwarf_add_AT_targ_address_c(Dwarf_P_Debug dbg, |
| 81 |
Dwarf_P_Die ownerdie, |
| 82 |
Dwarf_Half attr, |
| 83 |
Dwarf_Unsigned pc_value, |
| 84 |
Dwarf_Unsigned sym_index, |
| 85 |
Dwarf_P_Attribute *attr_out, |
| 86 |
Dwarf_Error * error) |
| 87 |
{ |
| 88 |
int res = 0; |
| 89 |
|
| 90 |
switch (attr) { |
| 91 |
case DW_AT_low_pc: |
| 92 |
case DW_AT_high_pc: |
| 93 |
|
| 94 |
/* added to support location lists */ |
| 95 |
/* no way to check that this is a loclist-style address though */ |
| 96 |
case DW_AT_location: |
| 97 |
case DW_AT_string_length: |
| 98 |
case DW_AT_return_addr: |
| 99 |
case DW_AT_frame_base: |
| 100 |
case DW_AT_segment: |
| 101 |
case DW_AT_static_link: |
| 102 |
case DW_AT_use_location: |
| 103 |
case DW_AT_vtable_elem_location: |
| 104 |
case DW_AT_const_value: /* Gcc can generate this as address. */ |
| 105 |
case DW_AT_entry_pc: |
| 106 |
break; |
| 107 |
default: |
| 108 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 109 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 110 |
return DW_DLV_ERROR; |
| 111 |
} |
| 112 |
break; |
| 113 |
} |
| 114 |
|
| 115 |
res = local_add_AT_address_a(dbg, ownerdie, attr, DW_FORM_addr, |
| 116 |
pc_value, sym_index,attr_out, error); |
| 117 |
return res; |
| 118 |
} |
| 119 |
|
| 120 |
int |
| 121 |
dwarf_add_AT_ref_address_a(Dwarf_P_Debug dbg, |
| 122 |
Dwarf_P_Die ownerdie, |
| 123 |
Dwarf_Half attr, |
| 124 |
Dwarf_Unsigned pc_value, |
| 125 |
Dwarf_Unsigned sym_index, |
| 126 |
Dwarf_P_Attribute *attr_out, |
| 127 |
Dwarf_Error * error) |
| 128 |
{ |
| 129 |
int res = 0; |
| 130 |
|
| 131 |
switch (attr) { |
| 132 |
case DW_AT_type: |
| 133 |
case DW_AT_import: |
| 134 |
break; |
| 135 |
|
| 136 |
default: |
| 137 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 138 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 139 |
return DW_DLV_ERROR; |
| 140 |
} |
| 141 |
break; |
| 142 |
} |
| 143 |
|
| 144 |
/* FIXME: For DWARF3 and later this call is problematic as |
| 145 |
DW_FORM_ref_addr is really an offset in |
| 146 |
.debug_info , not an address. */ |
| 147 |
res = local_add_AT_address_a(dbg, ownerdie, |
| 148 |
attr, DW_FORM_ref_addr, |
| 149 |
pc_value, sym_index,attr_out, error); |
| 150 |
return res; |
| 151 |
} |
| 152 |
|
| 153 |
/* Make sure attribute types are checked before entering here. */ |
| 154 |
static int |
| 155 |
local_add_AT_address_a(Dwarf_P_Debug dbg, |
| 156 |
Dwarf_P_Die ownerdie, |
| 157 |
Dwarf_Half attr, |
| 158 |
Dwarf_Signed form, |
| 159 |
Dwarf_Unsigned pc_value, |
| 160 |
Dwarf_Unsigned sym_index, |
| 161 |
Dwarf_P_Attribute *attr_out, |
| 162 |
Dwarf_Error * error) |
| 163 |
{ |
| 164 |
Dwarf_P_Attribute new_attr; |
| 165 |
int upointer_size = 0; |
| 166 |
|
| 167 |
if (dbg == NULL) { |
| 168 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 169 |
return DW_DLV_ERROR; |
| 170 |
} |
| 171 |
upointer_size = dbg->de_pointer_size; |
| 172 |
|
| 173 |
if (ownerdie == NULL) { |
| 174 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 175 |
return DW_DLV_ERROR; |
| 176 |
} |
| 177 |
|
| 178 |
/* attribute types have already been checked */ |
| 179 |
/* switch (attr) { ... } */ |
| 180 |
|
| 181 |
new_attr = (Dwarf_P_Attribute) |
| 182 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 183 |
if (new_attr == NULL) { |
| 184 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 185 |
return DW_DLV_ERROR; |
| 186 |
} |
| 187 |
|
| 188 |
new_attr->ar_attribute = attr; |
| 189 |
new_attr->ar_attribute_form = form; |
| 190 |
new_attr->ar_nbytes = upointer_size; |
| 191 |
new_attr->ar_rel_symidx = sym_index; |
| 192 |
new_attr->ar_reloc_len = upointer_size; |
| 193 |
new_attr->ar_next = 0; |
| 194 |
if (sym_index != NO_ELF_SYM_INDEX) { |
| 195 |
new_attr->ar_rel_type = dbg->de_ptr_reloc; |
| 196 |
} else { |
| 197 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 198 |
} |
| 199 |
|
| 200 |
new_attr->ar_data = (char *) |
| 201 |
_dwarf_p_get_alloc(dbg, upointer_size); |
| 202 |
if (new_attr->ar_data == NULL) { |
| 203 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 204 |
return DW_DLV_ERROR; |
| 205 |
} |
| 206 |
WRITE_UNALIGNED(dbg, new_attr->ar_data, |
| 207 |
(const void *) &pc_value, |
| 208 |
sizeof(pc_value), upointer_size); |
| 209 |
|
| 210 |
/* add attribute to the die */ |
| 211 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 212 |
*attr_out = new_attr; |
| 213 |
return DW_DLV_OK; |
| 214 |
} |
| 215 |
|
| 216 |
/* Pass in array (ie a pointer to) of Dwarf_Signed |
| 217 |
with input_array_length elements. |
| 218 |
|
| 219 |
A block of bytes is created |
| 220 |
with the sleb data in it. |
| 221 |
|
| 222 |
A pointer to the glob of bytes is returned |
| 223 |
through the output_block pointer and its length |
| 224 |
through output_block_len pointer. */ |
| 225 |
int |
| 226 |
dwarf_compress_integer_block_a( |
| 227 |
Dwarf_P_Debug dbg, |
| 228 |
Dwarf_Unsigned input_array_length, |
| 229 |
Dwarf_Signed * input_array, |
| 230 |
Dwarf_Unsigned *output_block_len, |
| 231 |
void ** output_block_returned, |
| 232 |
Dwarf_Error* error |
| 233 |
) |
| 234 |
{ |
| 235 |
Dwarf_Unsigned output_length_in_bytes = 0; |
| 236 |
char * output_block = 0; |
| 237 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 238 |
unsigned u = 0; |
| 239 |
char * ptr = 0; |
| 240 |
int remain = 0; |
| 241 |
int result = 0; |
| 242 |
|
| 243 |
if (dbg == NULL) { |
| 244 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 245 |
return DW_DLV_ERROR; |
| 246 |
} |
| 247 |
/* First compress everything to find the total size. */ |
| 248 |
|
| 249 |
output_length_in_bytes = 0; |
| 250 |
for (u=0; u<input_array_length; u++) { |
| 251 |
int unit_encoded_size; |
| 252 |
Dwarf_Signed unit = 0; |
| 253 |
|
| 254 |
unit = input_array[u]; |
| 255 |
result = dwarf_encode_signed_leb128( |
| 256 |
unit, &unit_encoded_size, |
| 257 |
encode_buffer,sizeof(encode_buffer)); |
| 258 |
if (result != DW_DLV_OK) { |
| 259 |
_dwarf_p_error(NULL, error, DW_DLE_LEB_IMPROPER); |
| 260 |
return DW_DLV_ERROR; |
| 261 |
} |
| 262 |
output_length_in_bytes += unit_encoded_size; |
| 263 |
} |
| 264 |
output_block = (void *) |
| 265 |
_dwarf_p_get_alloc(dbg, output_length_in_bytes); |
| 266 |
if (output_block == NULL) { |
| 267 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 268 |
return DW_DLV_ERROR; |
| 269 |
} |
| 270 |
|
| 271 |
/* Then compress again and copy into new buffer */ |
| 272 |
ptr = output_block; |
| 273 |
remain = output_length_in_bytes; |
| 274 |
for (u=0; u<input_array_length; u++) { |
| 275 |
int unit_encoded_size; |
| 276 |
Dwarf_Signed unit = 0; |
| 277 |
|
| 278 |
unit = input_array[u]; |
| 279 |
result = dwarf_encode_signed_leb128(unit, |
| 280 |
&unit_encoded_size, |
| 281 |
ptr, remain); |
| 282 |
if (result != DW_DLV_OK) { |
| 283 |
_dwarf_p_error(NULL, error, DW_DLE_LEB_IMPROPER); |
| 284 |
return DW_DLV_ERROR; |
| 285 |
} |
| 286 |
remain -= unit_encoded_size; |
| 287 |
ptr += unit_encoded_size; |
| 288 |
} |
| 289 |
|
| 290 |
*output_block_len = output_length_in_bytes; |
| 291 |
*output_block_returned = output_block; |
| 292 |
return DW_DLV_OK; |
| 293 |
} |
| 294 |
/* This is very similar to targ_address but results |
| 295 |
in a different FORM */ |
| 296 |
/* dbg->de_ar_data_attribute_form is data4 or data8 |
| 297 |
and dwarf4 changes the definition for such on DW_AT_high_pc. |
| 298 |
DWARF 3: the FORM here has no defined meaning for dwarf3. |
| 299 |
DWARF 4: the FORM here means that for DW_AT_high_pc the value |
| 300 |
is not a high address but is instead an offset |
| 301 |
from a (separate) DW_AT_low_pc. |
| 302 |
The intent for DWARF4 is that this is not a relocated |
| 303 |
address at all. Instead a simple offset. |
| 304 |
But this should NOT be called for a simple non-relocated offset. |
| 305 |
So do not call this with an attr of DW_AT_high_pc. |
| 306 |
Use dwarf_add_AT_unsigned_const_a() (for example) instead of |
| 307 |
dwarf_add_AT_dataref_a when the value is a simple offset . */ |
| 308 |
|
| 309 |
int |
| 310 |
dwarf_add_AT_dataref_a( |
| 311 |
Dwarf_P_Debug dbg, |
| 312 |
Dwarf_P_Die ownerdie, |
| 313 |
Dwarf_Half attr, |
| 314 |
Dwarf_Unsigned pc_value, |
| 315 |
Dwarf_Unsigned sym_index, |
| 316 |
Dwarf_P_Attribute *attr_out, |
| 317 |
Dwarf_Error * error) |
| 318 |
{ |
| 319 |
int res = 0; |
| 320 |
|
| 321 |
/* TODO: Add checking here */ |
| 322 |
res = local_add_AT_address_a(dbg, ownerdie, attr, |
| 323 |
dbg->de_ar_data_attribute_form, |
| 324 |
pc_value, |
| 325 |
sym_index, |
| 326 |
attr_out, |
| 327 |
error); |
| 328 |
return res; |
| 329 |
} |
| 330 |
|
| 331 |
/* For DW_FORM_block* or DW_FORM_exprloc */ |
| 332 |
int |
| 333 |
dwarf_add_AT_block_a( |
| 334 |
Dwarf_P_Debug dbg, |
| 335 |
Dwarf_P_Die ownerdie, |
| 336 |
Dwarf_Half attr, |
| 337 |
Dwarf_Small *block_data, |
| 338 |
Dwarf_Unsigned block_size, |
| 339 |
Dwarf_P_Attribute* attr_out, |
| 340 |
Dwarf_Error *error) |
| 341 |
{ |
| 342 |
Dwarf_P_Attribute new_attr = 0; |
| 343 |
int result = 0; |
| 344 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 345 |
int len_size = 0; |
| 346 |
char * attrdata = 0; |
| 347 |
Dwarf_Bool is_exprloc_related = FALSE; |
| 348 |
Dwarf_Half out_version = 0; |
| 349 |
if (dbg == NULL) { |
| 350 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 351 |
return DW_DLV_ERROR; |
| 352 |
} |
| 353 |
out_version = dbg->de_output_version; |
| 354 |
|
| 355 |
switch (attr) { |
| 356 |
case DW_AT_location: |
| 357 |
case DW_AT_use_location: |
| 358 |
case DW_AT_return_addr: |
| 359 |
case DW_AT_data_member_location: |
| 360 |
case DW_AT_frame_base: |
| 361 |
case DW_AT_static_link: |
| 362 |
case DW_AT_vtable_elem_location: |
| 363 |
case DW_AT_lower_bound: |
| 364 |
case DW_AT_upper_bound: |
| 365 |
case DW_AT_data_location: |
| 366 |
is_exprloc_related = TRUE; |
| 367 |
} |
| 368 |
if (ownerdie == NULL) { |
| 369 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 370 |
return DW_DLV_ERROR; |
| 371 |
} |
| 372 |
|
| 373 |
/* I don't mess with block1, block2, block4, |
| 374 |
not worth the effort, and block would be wrong |
| 375 |
to use block for DW_FORM_exprloc */ |
| 376 |
/* So, encode the length into LEB128 */ |
| 377 |
result = dwarf_encode_leb128(block_size, &len_size, |
| 378 |
encode_buffer,sizeof(encode_buffer)); |
| 379 |
if (result != DW_DLV_OK) { |
| 380 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 381 |
return DW_DLV_ERROR; |
| 382 |
} |
| 383 |
|
| 384 |
/* Allocate the new attribute */ |
| 385 |
new_attr = (Dwarf_P_Attribute) |
| 386 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 387 |
if (new_attr == NULL) { |
| 388 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 389 |
return DW_DLV_ERROR; |
| 390 |
} |
| 391 |
|
| 392 |
/* Fill in the attribute */ |
| 393 |
new_attr->ar_attribute = attr; |
| 394 |
if (is_exprloc_related && out_version == 5) { |
| 395 |
new_attr->ar_attribute_form = DW_FORM_exprloc; |
| 396 |
} else { |
| 397 |
new_attr->ar_attribute_form = DW_FORM_block; |
| 398 |
} |
| 399 |
new_attr->ar_nbytes = len_size + block_size; |
| 400 |
new_attr->ar_next = 0; |
| 401 |
|
| 402 |
new_attr->ar_data = attrdata = (char *) |
| 403 |
_dwarf_p_get_alloc(dbg, len_size + block_size); |
| 404 |
if (new_attr->ar_data == NULL) { |
| 405 |
/* free the block we got earlier */ |
| 406 |
_dwarf_p_dealloc((unsigned char *) new_attr); |
| 407 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 408 |
return DW_DLV_ERROR; |
| 409 |
} |
| 410 |
|
| 411 |
/* write length and data to attribute data buffer */ |
| 412 |
memcpy(attrdata, encode_buffer, len_size); |
| 413 |
attrdata += len_size; |
| 414 |
memcpy(attrdata, block_data, block_size); |
| 415 |
|
| 416 |
/* add attribute to the die */ |
| 417 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 418 |
*attr_out = new_attr; |
| 419 |
return DW_DLV_OK; |
| 420 |
} |
| 421 |
|
| 422 |
/* |
| 423 |
This function adds attributes whose value |
| 424 |
is an unsigned constant. It determines the |
| 425 |
size of the value field from the value of |
| 426 |
the constant. |
| 427 |
*/ |
| 428 |
int |
| 429 |
dwarf_add_AT_unsigned_const_a(Dwarf_P_Debug dbg, |
| 430 |
Dwarf_P_Die ownerdie, |
| 431 |
Dwarf_Half attr, |
| 432 |
Dwarf_Unsigned value, |
| 433 |
Dwarf_P_Attribute *attr_out, |
| 434 |
Dwarf_Error * error) |
| 435 |
{ |
| 436 |
Dwarf_P_Attribute new_attr = 0; |
| 437 |
Dwarf_Half attr_form = 0; |
| 438 |
Dwarf_Small size = 0; |
| 439 |
|
| 440 |
if (dbg == NULL) { |
| 441 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 442 |
return DW_DLV_ERROR; |
| 443 |
} |
| 444 |
|
| 445 |
if (ownerdie == NULL) { |
| 446 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 447 |
return DW_DLV_ERROR; |
| 448 |
} |
| 449 |
|
| 450 |
switch (attr) { |
| 451 |
case DW_AT_ordering: |
| 452 |
case DW_AT_byte_size: |
| 453 |
case DW_AT_bit_offset: |
| 454 |
case DW_AT_bit_size: |
| 455 |
case DW_AT_inline: |
| 456 |
case DW_AT_language: |
| 457 |
case DW_AT_visibility: |
| 458 |
case DW_AT_virtuality: |
| 459 |
case DW_AT_accessibility: |
| 460 |
case DW_AT_address_class: |
| 461 |
case DW_AT_calling_convention: |
| 462 |
case DW_AT_encoding: |
| 463 |
case DW_AT_identifier_case: |
| 464 |
case DW_AT_MIPS_loop_unroll_factor: |
| 465 |
case DW_AT_MIPS_software_pipeline_depth: |
| 466 |
break; |
| 467 |
|
| 468 |
case DW_AT_decl_column: |
| 469 |
case DW_AT_decl_file: |
| 470 |
case DW_AT_decl_line: |
| 471 |
case DW_AT_const_value: |
| 472 |
case DW_AT_start_scope: |
| 473 |
case DW_AT_stride_size: /* DW_AT_bit_stride is DWARF3 name */ |
| 474 |
case DW_AT_count: |
| 475 |
case DW_AT_high_pc: /* DWARF5: allowing const udata high_pc */ |
| 476 |
case DW_AT_associated: |
| 477 |
case DW_AT_allocated: |
| 478 |
case DW_AT_upper_bound: |
| 479 |
case DW_AT_lower_bound: |
| 480 |
case DW_AT_call_file: |
| 481 |
case DW_AT_call_line: |
| 482 |
case DW_AT_data_member_location: |
| 483 |
case DW_AT_trampoline: |
| 484 |
break; |
| 485 |
|
| 486 |
default: |
| 487 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 488 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 489 |
return DW_DLV_ERROR; |
| 490 |
} |
| 491 |
break; |
| 492 |
} |
| 493 |
|
| 494 |
/* Compute the number of bytes needed to hold constant. */ |
| 495 |
if (value <= UCHAR_MAX) { |
| 496 |
attr_form = DW_FORM_data1; |
| 497 |
size = 1; |
| 498 |
} else if (value <= USHRT_MAX) { |
| 499 |
attr_form = DW_FORM_data2; |
| 500 |
size = 2; |
| 501 |
} else if (value <= UINT_MAX) { |
| 502 |
attr_form = DW_FORM_data4; |
| 503 |
size = 4; |
| 504 |
} else { |
| 505 |
attr_form = DW_FORM_data8; |
| 506 |
size = 8; |
| 507 |
} |
| 508 |
|
| 509 |
new_attr = (Dwarf_P_Attribute) |
| 510 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 511 |
if (new_attr == NULL) { |
| 512 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 513 |
return DW_DLV_ERROR; |
| 514 |
} |
| 515 |
|
| 516 |
new_attr->ar_attribute = attr; |
| 517 |
new_attr->ar_attribute_form = attr_form; |
| 518 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 519 |
|
| 520 |
/* irrelevant: unused with R_MIPS_NONE */ |
| 521 |
new_attr->ar_reloc_len = 0; |
| 522 |
|
| 523 |
new_attr->ar_nbytes = size; |
| 524 |
new_attr->ar_next = 0; |
| 525 |
|
| 526 |
new_attr->ar_data = (char *) |
| 527 |
_dwarf_p_get_alloc(dbg, size); |
| 528 |
if (new_attr->ar_data == NULL) { |
| 529 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 530 |
return DW_DLV_ERROR; |
| 531 |
} |
| 532 |
WRITE_UNALIGNED(dbg, new_attr->ar_data, |
| 533 |
(const void *) &value, sizeof(value), size); |
| 534 |
|
| 535 |
/* add attribute to the die */ |
| 536 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 537 |
*attr_out = new_attr; |
| 538 |
return DW_DLV_OK; |
| 539 |
} |
| 540 |
|
| 541 |
int |
| 542 |
dwarf_add_AT_signed_const_a(Dwarf_P_Debug dbg, |
| 543 |
Dwarf_P_Die ownerdie, |
| 544 |
Dwarf_Half attr, |
| 545 |
Dwarf_Signed value, |
| 546 |
Dwarf_P_Attribute *attr_out, |
| 547 |
Dwarf_Error * error) |
| 548 |
{ |
| 549 |
Dwarf_P_Attribute new_attr = 0; |
| 550 |
Dwarf_Half attr_form = 0; |
| 551 |
Dwarf_Small size = 0; |
| 552 |
|
| 553 |
if (dbg == NULL) { |
| 554 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 555 |
return DW_DLV_ERROR; |
| 556 |
} |
| 557 |
|
| 558 |
if (ownerdie == NULL) { |
| 559 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 560 |
return DW_DLV_ERROR; |
| 561 |
} |
| 562 |
|
| 563 |
switch (attr) { |
| 564 |
case DW_AT_lower_bound: |
| 565 |
case DW_AT_upper_bound: |
| 566 |
case DW_AT_const_value: |
| 567 |
case DW_AT_bit_offset: |
| 568 |
case DW_AT_bit_size: |
| 569 |
case DW_AT_byte_size: |
| 570 |
case DW_AT_count: |
| 571 |
case DW_AT_byte_stride: |
| 572 |
case DW_AT_bit_stride: |
| 573 |
case DW_AT_allocated: |
| 574 |
case DW_AT_associated: |
| 575 |
break; |
| 576 |
|
| 577 |
default: |
| 578 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 579 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 580 |
return DW_DLV_ERROR; |
| 581 |
} |
| 582 |
break; |
| 583 |
} |
| 584 |
|
| 585 |
/* Compute the number of bytes needed to hold constant. */ |
| 586 |
if (value >= SCHAR_MIN && value <= SCHAR_MAX) { |
| 587 |
attr_form = DW_FORM_data1; |
| 588 |
size = 1; |
| 589 |
} else if (value >= SHRT_MIN && value <= SHRT_MAX) { |
| 590 |
attr_form = DW_FORM_data2; |
| 591 |
size = 2; |
| 592 |
} else if (value >= INT_MIN && value <= INT_MAX) { |
| 593 |
attr_form = DW_FORM_data4; |
| 594 |
size = 4; |
| 595 |
} else { |
| 596 |
attr_form = DW_FORM_data8; |
| 597 |
size = 8; |
| 598 |
} |
| 599 |
|
| 600 |
new_attr = (Dwarf_P_Attribute) |
| 601 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 602 |
if (new_attr == NULL) { |
| 603 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 604 |
return DW_DLV_ERROR; |
| 605 |
} |
| 606 |
|
| 607 |
new_attr->ar_attribute = attr; |
| 608 |
new_attr->ar_attribute_form = attr_form; |
| 609 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 610 |
|
| 611 |
/* irrelevant: unused with R_MIPS_NONE */ |
| 612 |
new_attr->ar_reloc_len = 0; |
| 613 |
|
| 614 |
new_attr->ar_nbytes = size; |
| 615 |
new_attr->ar_next = 0; |
| 616 |
|
| 617 |
new_attr->ar_data = (char *) |
| 618 |
_dwarf_p_get_alloc(dbg, size); |
| 619 |
if (new_attr->ar_data == NULL) { |
| 620 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 621 |
return DW_DLV_ERROR; |
| 622 |
} |
| 623 |
WRITE_UNALIGNED(dbg, new_attr->ar_data, |
| 624 |
(const void *) &value, sizeof(value), size); |
| 625 |
|
| 626 |
/* add attribute to the die */ |
| 627 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 628 |
*attr_out = new_attr; |
| 629 |
return DW_DLV_OK; |
| 630 |
} |
| 631 |
|
| 632 |
/* Preferred interface as of December 2018 */ |
| 633 |
int |
| 634 |
dwarf_add_AT_location_expr_a(Dwarf_P_Debug dbg, |
| 635 |
Dwarf_P_Die ownerdie, |
| 636 |
Dwarf_Half attr, |
| 637 |
Dwarf_P_Expr loc_expr, |
| 638 |
Dwarf_P_Attribute *attr_out, |
| 639 |
Dwarf_Error * error) |
| 640 |
{ |
| 641 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 642 |
int res = 0; |
| 643 |
Dwarf_P_Attribute new_attr = 0; |
| 644 |
Dwarf_Half attr_form = 0; |
| 645 |
char *len_str = 0; |
| 646 |
int len_size = 0; |
| 647 |
Dwarf_Unsigned block_size = 0; |
| 648 |
char *block_dest_ptr = 0; |
| 649 |
int do_len_as_int = 0; |
| 650 |
int dwarf_version = 0; |
| 651 |
Dwarf_Bool is_exprloc_related = FALSE; |
| 652 |
if (dbg == NULL) { |
| 653 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 654 |
return DW_DLV_ERROR; |
| 655 |
} |
| 656 |
dwarf_version = dbg->de_output_version; |
| 657 |
if (ownerdie == NULL) { |
| 658 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 659 |
return DW_DLV_ERROR; |
| 660 |
} |
| 661 |
if (loc_expr == NULL) { |
| 662 |
_dwarf_p_error(dbg, error, DW_DLE_EXPR_NULL); |
| 663 |
return DW_DLV_ERROR; |
| 664 |
} |
| 665 |
if (loc_expr->ex_dbg != dbg) { |
| 666 |
_dwarf_p_error(dbg, error, DW_DLE_LOC_EXPR_BAD); |
| 667 |
return DW_DLV_ERROR; |
| 668 |
} |
| 669 |
block_size = loc_expr->ex_next_byte_offset; |
| 670 |
switch (attr) { |
| 671 |
case DW_AT_location: |
| 672 |
case DW_AT_use_location: |
| 673 |
case DW_AT_return_addr: |
| 674 |
case DW_AT_data_member_location: |
| 675 |
case DW_AT_frame_base: |
| 676 |
case DW_AT_static_link: |
| 677 |
case DW_AT_vtable_elem_location: |
| 678 |
case DW_AT_lower_bound: |
| 679 |
case DW_AT_upper_bound: |
| 680 |
case DW_AT_data_location: |
| 681 |
is_exprloc_related = TRUE; |
| 682 |
break; |
| 683 |
|
| 684 |
case DW_AT_string_length: |
| 685 |
case DW_AT_const_value: |
| 686 |
case DW_AT_count: |
| 687 |
case DW_AT_associated: |
| 688 |
case DW_AT_allocated: |
| 689 |
case DW_AT_byte_stride: |
| 690 |
case DW_AT_bit_stride: |
| 691 |
case DW_AT_byte_size: |
| 692 |
case DW_AT_bit_size: |
| 693 |
break; |
| 694 |
|
| 695 |
default: |
| 696 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 697 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 698 |
return DW_DLV_ERROR; |
| 699 |
} |
| 700 |
break; |
| 701 |
} |
| 702 |
|
| 703 |
/* Compute the number of bytes needed to hold constant. |
| 704 |
This is a bit fake in that the size will never |
| 705 |
be particularly large and always < UINT_MAX. */ |
| 706 |
if (is_exprloc_related && dwarf_version == DW_CU_VERSION5) { |
| 707 |
attr_form = DW_FORM_exprloc; |
| 708 |
res = dwarf_encode_leb128(block_size, &len_size, |
| 709 |
encode_buffer, |
| 710 |
sizeof(encode_buffer)); |
| 711 |
if (res != DW_DLV_OK) { |
| 712 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 713 |
return DW_DLV_ERROR; |
| 714 |
} |
| 715 |
len_str = (char *) encode_buffer; |
| 716 |
} else if (block_size <= UCHAR_MAX) { |
| 717 |
attr_form = DW_FORM_block1; |
| 718 |
len_size = 1; |
| 719 |
do_len_as_int = 1; |
| 720 |
} else if (block_size <= USHRT_MAX) { |
| 721 |
attr_form = DW_FORM_block2; |
| 722 |
len_size = 2; |
| 723 |
do_len_as_int = 1; |
| 724 |
} else if (block_size <= UINT_MAX) { |
| 725 |
attr_form = DW_FORM_block4; |
| 726 |
len_size = 4; |
| 727 |
do_len_as_int = 1; |
| 728 |
} else { |
| 729 |
attr_form = DW_FORM_block; |
| 730 |
res = dwarf_encode_leb128(block_size, &len_size, |
| 731 |
encode_buffer, |
| 732 |
sizeof(encode_buffer)); |
| 733 |
if (res != DW_DLV_OK) { |
| 734 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 735 |
return DW_DLV_ERROR; |
| 736 |
} |
| 737 |
len_str = (char *) encode_buffer; |
| 738 |
} |
| 739 |
|
| 740 |
new_attr = (Dwarf_P_Attribute) |
| 741 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 742 |
if (new_attr == NULL) { |
| 743 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 744 |
return DW_DLV_ERROR; |
| 745 |
} |
| 746 |
|
| 747 |
new_attr->ar_attribute = attr; |
| 748 |
new_attr->ar_attribute_form = attr_form; |
| 749 |
new_attr->ar_reloc_len = dbg->de_pointer_size; |
| 750 |
if (loc_expr->ex_reloc_sym_index != NO_ELF_SYM_INDEX) { |
| 751 |
new_attr->ar_rel_type = dbg->de_ptr_reloc; |
| 752 |
} else { |
| 753 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 754 |
} |
| 755 |
new_attr->ar_rel_symidx = loc_expr->ex_reloc_sym_index; |
| 756 |
/* If there is a relocation the code assumes |
| 757 |
that relocation on a DW_OP_addr and |
| 758 |
the addr is the initial expression in the block */ |
| 759 |
new_attr->ar_rel_offset = loc_expr->ex_reloc_offset + len_size; |
| 760 |
|
| 761 |
new_attr->ar_nbytes = block_size + len_size; |
| 762 |
|
| 763 |
new_attr->ar_next = 0; |
| 764 |
new_attr->ar_data = block_dest_ptr = |
| 765 |
(char *) _dwarf_p_get_alloc(dbg, block_size + len_size); |
| 766 |
if (new_attr->ar_data == NULL) { |
| 767 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 768 |
return DW_DLV_ERROR; |
| 769 |
} |
| 770 |
|
| 771 |
if (do_len_as_int) { |
| 772 |
WRITE_UNALIGNED(dbg, block_dest_ptr, |
| 773 |
(const void *) &block_size, |
| 774 |
sizeof(block_size), len_size); |
| 775 |
} else { |
| 776 |
/* Is uleb number form, DW_FORM_block or |
| 777 |
DW_FORM_exprloc. See above. */ |
| 778 |
memcpy(block_dest_ptr, len_str, len_size); |
| 779 |
} |
| 780 |
block_dest_ptr += len_size; |
| 781 |
if (block_size > sizeof(loc_expr->ex_byte_stream)) { |
| 782 |
/* ex_byte_stream has a fixed max value. */ |
| 783 |
_dwarf_p_error(dbg, error, DW_DLE_EXPR_LENGTH_BAD); |
| 784 |
return DW_DLV_ERROR; |
| 785 |
} |
| 786 |
memcpy(block_dest_ptr, &(loc_expr->ex_byte_stream[0]), |
| 787 |
block_size); |
| 788 |
|
| 789 |
/* add attribute to the die */ |
| 790 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 791 |
*attr_out = new_attr; |
| 792 |
return DW_DLV_OK; |
| 793 |
} |
| 794 |
#if 0 |
| 795 |
/* New for DWARF5 DW_FORM_exprloc */ |
| 796 |
int |
| 797 |
dwarf_add_AT_exprloc(Dwarf_P_Debug dbg, |
| 798 |
Dwarf_P_Die ownerdie, |
| 799 |
Dwarf_Half attr, |
| 800 |
Dwarf_Block *b, |
| 801 |
Dwarf_P_Attribute *attr_out, |
| 802 |
Dwarf_Error * error) |
| 803 |
{ |
| 804 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 805 |
int res = 0; |
| 806 |
Dwarf_P_Attribute new_attr = 0; |
| 807 |
char *len_str = 0; |
| 808 |
int len_size = 0; |
| 809 |
Dwarf_Unsigned block_size = 0; |
| 810 |
char *block_dest_ptr = 0; |
| 811 |
|
| 812 |
Dwarf_Half attr_form = DW_FORM_exprloc; |
| 813 |
#if 0 |
| 814 |
if (attr_form != DW_FORM_exprloc) { |
| 815 |
/* This is just for a single FORM! */ |
| 816 |
_dwarf_p_error(dbg, error, DW_DLE_ATTR_FORM_BAD); |
| 817 |
return DW_DLV_ERROR; |
| 818 |
} |
| 819 |
#endif |
| 820 |
block_size = b.dl_len; |
| 821 |
res = dwarf_encode_leb128(block_size, &len_size, |
| 822 |
encode_buffer, |
| 823 |
sizeof(encode_buffer)); |
| 824 |
if (res != DW_DLV_OK) { |
| 825 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 826 |
return DW_DLV_ERROR; |
| 827 |
} |
| 828 |
len_str = (char *) encode_buffer; |
| 829 |
new_attr = (Dwarf_P_Attribute) |
| 830 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 831 |
if (new_attr == NULL) { |
| 832 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 833 |
return DW_DLV_ERROR; |
| 834 |
} |
| 835 |
new_attr->ar_attribute = attr; |
| 836 |
new_attr->ar_attribute_form = attr_form; |
| 837 |
new_attr->ar_reloc_len = dbg->de_pointer_size; |
| 838 |
if (loc_expr->ex_reloc_sym_index != NO_ELF_SYM_INDEX) { |
| 839 |
new_attr->ar_rel_type = dbg->de_ptr_reloc; |
| 840 |
} else { |
| 841 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 842 |
} |
| 843 |
new_attr->ar_rel_symidx = loc_expr->ex_reloc_sym_index; |
| 844 |
/* If there is a relocation the code assumes |
| 845 |
that relocation on a DW_OP_addr and |
| 846 |
the addr is the initial expression in the block */ |
| 847 |
|
| 848 |
new_attr->ar_nbytes = block_size + len_size; |
| 849 |
new_attr->ar_next = 0; |
| 850 |
new_attr->ar_data = block_dest_ptr = |
| 851 |
(char *) _dwarf_p_get_alloc(dbg, block_size + len_size); |
| 852 |
if (new_attr->ar_data == NULL) { |
| 853 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 854 |
return DW_DLV_ERROR; |
| 855 |
} |
| 856 |
/* Is uleb number form */ |
| 857 |
memcpy(block_dest_ptr, len_str, len_size); |
| 858 |
block_dest_ptr += len_size; |
| 859 |
if (block_size > sizeof(loc_expr->ex_byte_stream)) { |
| 860 |
/* ex_byte_stream has a fixed max value. */ |
| 861 |
_dwarf_p_error(dbg, error, DW_DLE_EXPR_LENGTH_BAD); |
| 862 |
return DW_DLV_ERROR; |
| 863 |
} |
| 864 |
memcpy(block_dest_ptr, &(loc_expr->ex_byte_stream[0]), |
| 865 |
block_size); |
| 866 |
/* add attribute to the die */ |
| 867 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 868 |
*attr_out = new_attr; |
| 869 |
return DW_DLV_OK; |
| 870 |
} |
| 871 |
#endif /* 0 */ |
| 872 |
|
| 873 |
/* This function adds attributes of reference class. |
| 874 |
The references here are local CU references, |
| 875 |
not DW_FORM_ref_addr. |
| 876 |
The offset field is 4 bytes for 32-bit objects, |
| 877 |
and 8-bytes for 64-bit objects. Otherdie is the |
| 878 |
that is referenced by ownerdie. |
| 879 |
|
| 880 |
For reference attributes, the ar_data and ar_nbytes |
| 881 |
are not needed. Instead, the ar_ref_die points to |
| 882 |
the other die, and its di_offset value is used as |
| 883 |
the reference value. */ |
| 884 |
|
| 885 |
static int |
| 886 |
_dwarf_add_AT_reference_internal_a(Dwarf_P_Debug dbg, |
| 887 |
Dwarf_P_Die ownerdie, |
| 888 |
Dwarf_Half attr, |
| 889 |
Dwarf_P_Die otherdie, |
| 890 |
int check_otherdie, |
| 891 |
Dwarf_P_Attribute *attr_out, |
| 892 |
Dwarf_Error * error) |
| 893 |
{ |
| 894 |
Dwarf_P_Attribute new_attr = 0; |
| 895 |
|
| 896 |
if (dbg == NULL) { |
| 897 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 898 |
return DW_DLV_ERROR; |
| 899 |
} |
| 900 |
|
| 901 |
if (ownerdie == NULL) { |
| 902 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 903 |
return DW_DLV_ERROR; |
| 904 |
} |
| 905 |
|
| 906 |
if (check_otherdie && (otherdie == NULL)) { |
| 907 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 908 |
return DW_DLV_ERROR; |
| 909 |
} |
| 910 |
|
| 911 |
switch (attr) { |
| 912 |
case DW_AT_count: |
| 913 |
case DW_AT_sibling: |
| 914 |
case DW_AT_byte_size: |
| 915 |
case DW_AT_bit_offset: |
| 916 |
case DW_AT_bit_size: |
| 917 |
case DW_AT_discr: |
| 918 |
case DW_AT_import: |
| 919 |
case DW_AT_common_reference: |
| 920 |
case DW_AT_containing_type: |
| 921 |
case DW_AT_default_value: |
| 922 |
case DW_AT_lower_bound: |
| 923 |
case DW_AT_bit_stride: /* Early name is DW_AT_stride_size */ |
| 924 |
case DW_AT_upper_bound: |
| 925 |
case DW_AT_abstract_origin: |
| 926 |
case DW_AT_base_types: |
| 927 |
case DW_AT_friend: |
| 928 |
case DW_AT_namelist_item: |
| 929 |
case DW_AT_priority: |
| 930 |
case DW_AT_specification: |
| 931 |
case DW_AT_type: |
| 932 |
case DW_AT_allocated: |
| 933 |
case DW_AT_associated: |
| 934 |
case DW_AT_byte_stride: |
| 935 |
case DW_AT_extension: |
| 936 |
case DW_AT_trampoline: |
| 937 |
case DW_AT_small: |
| 938 |
case DW_AT_object_pointer: |
| 939 |
case DW_AT_signature: |
| 940 |
break; |
| 941 |
|
| 942 |
default: |
| 943 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 944 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 945 |
return DW_DLV_ERROR; |
| 946 |
} |
| 947 |
break; |
| 948 |
} |
| 949 |
|
| 950 |
new_attr = (Dwarf_P_Attribute) |
| 951 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 952 |
if (new_attr == NULL) { |
| 953 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 954 |
return DW_DLV_ERROR; |
| 955 |
} |
| 956 |
|
| 957 |
new_attr->ar_attribute = attr; |
| 958 |
new_attr->ar_attribute_form = dbg->de_ar_ref_attr_form; |
| 959 |
new_attr->ar_nbytes = dbg->de_dwarf_offset_size; |
| 960 |
new_attr->ar_reloc_len = dbg->de_dwarf_offset_size; |
| 961 |
new_attr->ar_ref_die = otherdie; |
| 962 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 963 |
new_attr->ar_next = 0; |
| 964 |
|
| 965 |
/* Add attribute to the die */ |
| 966 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 967 |
*attr_out = new_attr; |
| 968 |
return DW_DLV_OK; |
| 969 |
} |
| 970 |
|
| 971 |
/* Allowing the target die to be identified later. |
| 972 |
*/ |
| 973 |
int |
| 974 |
dwarf_add_AT_reference_c(Dwarf_P_Debug dbg, |
| 975 |
Dwarf_P_Die ownerdie, |
| 976 |
Dwarf_Half attr, |
| 977 |
Dwarf_P_Die otherdie, |
| 978 |
Dwarf_P_Attribute *attr_out, |
| 979 |
Dwarf_Error * error) |
| 980 |
{ |
| 981 |
int res = 0; |
| 982 |
|
| 983 |
res = _dwarf_add_AT_reference_internal_a(dbg, |
| 984 |
ownerdie, |
| 985 |
attr, |
| 986 |
otherdie, |
| 987 |
/* check otherdie */ 0, |
| 988 |
attr_out, |
| 989 |
error); |
| 990 |
return res; |
| 991 |
} |
| 992 |
|
| 993 |
int |
| 994 |
dwarf_fixup_AT_reference_die(Dwarf_P_Debug dbg, |
| 995 |
Dwarf_Half attrnum, |
| 996 |
Dwarf_P_Die sourcedie, |
| 997 |
Dwarf_P_Die targetdie, |
| 998 |
Dwarf_Error *error) |
| 999 |
{ |
| 1000 |
Dwarf_P_Attribute a = 0; |
| 1001 |
Dwarf_P_Attribute cur = 0; |
| 1002 |
if (dbg == NULL) { |
| 1003 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 1004 |
return DW_DLV_ERROR; |
| 1005 |
} |
| 1006 |
for (cur = sourcedie->di_attrs; cur; cur = cur->ar_next) { |
| 1007 |
if (attrnum == cur->ar_attribute) { |
| 1008 |
a = cur; |
| 1009 |
break; |
| 1010 |
} |
| 1011 |
} |
| 1012 |
if (!a) { |
| 1013 |
_dwarf_p_error(dbg, error, DW_DLE_AT_FIXUP_NULL); |
| 1014 |
return DW_DLV_ERROR; |
| 1015 |
} |
| 1016 |
if (a->ar_ref_die) { |
| 1017 |
_dwarf_p_error(dbg, error, DW_DLE_AT_FIXUP_DUP); |
| 1018 |
return DW_DLV_ERROR; |
| 1019 |
} |
| 1020 |
a->ar_ref_die = targetdie; |
| 1021 |
return DW_DLV_OK; |
| 1022 |
} |
| 1023 |
|
| 1024 |
int |
| 1025 |
dwarf_add_AT_flag_a(Dwarf_P_Debug dbg, |
| 1026 |
Dwarf_P_Die ownerdie, |
| 1027 |
Dwarf_Half attr, |
| 1028 |
Dwarf_Small flag, |
| 1029 |
Dwarf_P_Attribute * attr_out, |
| 1030 |
Dwarf_Error * error) |
| 1031 |
{ |
| 1032 |
Dwarf_P_Attribute new_attr = 0; |
| 1033 |
|
| 1034 |
if (dbg == NULL) { |
| 1035 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 1036 |
return DW_DLV_ERROR; |
| 1037 |
} |
| 1038 |
if (ownerdie == NULL) { |
| 1039 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1040 |
return DW_DLV_ERROR; |
| 1041 |
} |
| 1042 |
|
| 1043 |
new_attr = (Dwarf_P_Attribute) |
| 1044 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1045 |
if (new_attr == NULL) { |
| 1046 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1047 |
return DW_DLV_ERROR; |
| 1048 |
} |
| 1049 |
|
| 1050 |
new_attr->ar_attribute = attr; |
| 1051 |
new_attr->ar_attribute_form = DW_FORM_flag; |
| 1052 |
new_attr->ar_nbytes = 1; |
| 1053 |
new_attr->ar_reloc_len = 0; /* not used */ |
| 1054 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1055 |
new_attr->ar_next = 0; |
| 1056 |
|
| 1057 |
new_attr->ar_data = (char *) |
| 1058 |
_dwarf_p_get_alloc(dbg, 1); |
| 1059 |
if (new_attr->ar_data == NULL) { |
| 1060 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1061 |
return DW_DLV_ERROR; |
| 1062 |
} |
| 1063 |
memcpy(new_attr->ar_data, &flag, 1); |
| 1064 |
|
| 1065 |
/* Add attribute to the die */ |
| 1066 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1067 |
*attr_out = new_attr; |
| 1068 |
return DW_DLV_OK; |
| 1069 |
} |
| 1070 |
|
| 1071 |
int |
| 1072 |
dwarf_add_AT_string_a(Dwarf_P_Debug dbg, |
| 1073 |
Dwarf_P_Die ownerdie, |
| 1074 |
Dwarf_Half attr, |
| 1075 |
char *string, |
| 1076 |
Dwarf_P_Attribute *attr_out, |
| 1077 |
Dwarf_Error * error) |
| 1078 |
{ |
| 1079 |
Dwarf_P_Attribute new_attr = 0; |
| 1080 |
int res = 0; |
| 1081 |
|
| 1082 |
if (dbg == NULL) { |
| 1083 |
_dwarf_p_error(NULL, error, DW_DLE_DBG_NULL); |
| 1084 |
return DW_DLV_ERROR; |
| 1085 |
} |
| 1086 |
|
| 1087 |
if (ownerdie == NULL) { |
| 1088 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1089 |
return DW_DLV_ERROR; |
| 1090 |
} |
| 1091 |
|
| 1092 |
new_attr = (Dwarf_P_Attribute) |
| 1093 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1094 |
if (new_attr == NULL) { |
| 1095 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1096 |
return DW_DLV_ERROR; |
| 1097 |
} |
| 1098 |
|
| 1099 |
switch (attr) { |
| 1100 |
/* See also: pro_section.c for same strings attribute list. */ |
| 1101 |
case DW_AT_comp_dir: |
| 1102 |
case DW_AT_const_value: |
| 1103 |
|
| 1104 |
/* DWARF5, but ok for any version really.*/ |
| 1105 |
case DW_AT_linkage_name: |
| 1106 |
|
| 1107 |
case DW_AT_MIPS_abstract_name: |
| 1108 |
case DW_AT_MIPS_linkage_name: |
| 1109 |
case DW_AT_name: |
| 1110 |
case DW_AT_producer: |
| 1111 |
break; |
| 1112 |
|
| 1113 |
default: |
| 1114 |
if (attr < DW_AT_lo_user || attr > DW_AT_hi_user ) { |
| 1115 |
_dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD); |
| 1116 |
return DW_DLV_ERROR; |
| 1117 |
} |
| 1118 |
break; |
| 1119 |
} |
| 1120 |
new_attr->ar_attribute = attr; |
| 1121 |
res = _dwarf_pro_set_string_attr(new_attr,ownerdie->di_dbg, |
| 1122 |
string,error); |
| 1123 |
if (res != DW_DLV_OK) { |
| 1124 |
return res; |
| 1125 |
} |
| 1126 |
|
| 1127 |
/* add attribute to the die */ |
| 1128 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1129 |
*attr_out = new_attr; |
| 1130 |
return DW_DLV_OK; |
| 1131 |
} |
| 1132 |
|
| 1133 |
int |
| 1134 |
dwarf_add_AT_const_value_string_a(Dwarf_P_Die ownerdie, |
| 1135 |
char *string_value, |
| 1136 |
Dwarf_P_Attribute *attr_out, |
| 1137 |
Dwarf_Error * error) |
| 1138 |
{ |
| 1139 |
Dwarf_P_Attribute new_attr = 0; |
| 1140 |
Dwarf_P_Debug dbg = 0; |
| 1141 |
int res = 0; |
| 1142 |
|
| 1143 |
if (ownerdie == NULL) { |
| 1144 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1145 |
return DW_DLV_ERROR; |
| 1146 |
} |
| 1147 |
dbg = ownerdie->di_dbg; |
| 1148 |
|
| 1149 |
new_attr = (Dwarf_P_Attribute) |
| 1150 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1151 |
if (new_attr == NULL) { |
| 1152 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1153 |
return DW_DLV_ERROR; |
| 1154 |
} |
| 1155 |
|
| 1156 |
new_attr->ar_attribute = DW_AT_const_value; |
| 1157 |
res = _dwarf_pro_set_string_attr(new_attr,dbg, |
| 1158 |
string_value,error); |
| 1159 |
if (res != DW_DLV_OK) { |
| 1160 |
return res; |
| 1161 |
} |
| 1162 |
|
| 1163 |
/* add attribute to the die */ |
| 1164 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1165 |
*attr_out = new_attr; |
| 1166 |
return DW_DLV_OK; |
| 1167 |
} |
| 1168 |
|
| 1169 |
int |
| 1170 |
dwarf_add_AT_with_ref_sig8_a(Dwarf_P_Die ownerdie, |
| 1171 |
Dwarf_Half attrnum, |
| 1172 |
const Dwarf_Sig8 *sig8_in, |
| 1173 |
Dwarf_P_Attribute * attr_out, |
| 1174 |
Dwarf_Error * error) |
| 1175 |
{ |
| 1176 |
Dwarf_P_Attribute new_attr = 0; |
| 1177 |
Dwarf_P_Debug dbg = 0; |
| 1178 |
|
| 1179 |
if (ownerdie == NULL) { |
| 1180 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1181 |
return DW_DLV_ERROR; |
| 1182 |
} |
| 1183 |
dbg = ownerdie->di_dbg; |
| 1184 |
|
| 1185 |
new_attr = (Dwarf_P_Attribute) |
| 1186 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1187 |
if (new_attr == NULL) { |
| 1188 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1189 |
return DW_DLV_ERROR; |
| 1190 |
} |
| 1191 |
new_attr->ar_attribute = attrnum; |
| 1192 |
new_attr->ar_attribute_form = DW_FORM_ref_sig8; |
| 1193 |
new_attr->ar_nbytes = sizeof (Dwarf_Sig8); |
| 1194 |
new_attr->ar_next = 0; |
| 1195 |
|
| 1196 |
new_attr->ar_data = |
| 1197 |
(char *) _dwarf_p_get_alloc(dbg, sizeof(Dwarf_Sig8)); |
| 1198 |
if (new_attr->ar_data == NULL) { |
| 1199 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1200 |
return DW_DLV_ERROR; |
| 1201 |
} |
| 1202 |
memcpy(new_attr->ar_data,sig8_in,sizeof(Dwarf_Sig8)); |
| 1203 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1204 |
new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */ |
| 1205 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1206 |
*attr_out = new_attr; |
| 1207 |
return DW_DLV_OK; |
| 1208 |
} |
| 1209 |
|
| 1210 |
int |
| 1211 |
dwarf_add_AT_producer_a(Dwarf_P_Die ownerdie, |
| 1212 |
char *producer_string, |
| 1213 |
Dwarf_P_Attribute *attr_out, |
| 1214 |
Dwarf_Error * error) |
| 1215 |
{ |
| 1216 |
Dwarf_P_Attribute new_attr = 0; |
| 1217 |
Dwarf_P_Debug dbg = 0; |
| 1218 |
int res = 0; |
| 1219 |
|
| 1220 |
if (ownerdie == NULL) { |
| 1221 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1222 |
return DW_DLV_ERROR; |
| 1223 |
} |
| 1224 |
dbg = ownerdie->di_dbg; |
| 1225 |
new_attr = (Dwarf_P_Attribute) |
| 1226 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1227 |
if (new_attr == NULL) { |
| 1228 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1229 |
return DW_DLV_ERROR; |
| 1230 |
} |
| 1231 |
|
| 1232 |
new_attr->ar_attribute = DW_AT_producer; |
| 1233 |
res = _dwarf_pro_set_string_attr(new_attr,dbg, |
| 1234 |
producer_string,error); |
| 1235 |
if (res != DW_DLV_OK) { |
| 1236 |
return res; |
| 1237 |
} |
| 1238 |
|
| 1239 |
/* add attribute to the die */ |
| 1240 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1241 |
*attr_out = new_attr; |
| 1242 |
return DW_DLV_OK; |
| 1243 |
} |
| 1244 |
|
| 1245 |
int |
| 1246 |
dwarf_add_AT_const_value_signedint_a(Dwarf_P_Die ownerdie, |
| 1247 |
Dwarf_Signed signed_value, |
| 1248 |
Dwarf_P_Attribute *attr_out, |
| 1249 |
Dwarf_Error * error) |
| 1250 |
{ |
| 1251 |
int res = 0; |
| 1252 |
|
| 1253 |
res = dwarf_add_AT_any_value_sleb_a( |
| 1254 |
ownerdie,DW_AT_const_value, |
| 1255 |
signed_value, |
| 1256 |
attr_out, error); |
| 1257 |
return res; |
| 1258 |
} |
| 1259 |
|
| 1260 |
int |
| 1261 |
dwarf_add_AT_implicit_const(Dwarf_P_Die ownerdie, |
| 1262 |
Dwarf_Half attrnum, |
| 1263 |
Dwarf_Signed signed_value, |
| 1264 |
Dwarf_P_Attribute *outattr, |
| 1265 |
Dwarf_Error * error) |
| 1266 |
{ |
| 1267 |
Dwarf_P_Attribute new_attr = 0; |
| 1268 |
Dwarf_P_Debug dbg = 0; |
| 1269 |
|
| 1270 |
if (ownerdie == NULL) { |
| 1271 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1272 |
return DW_DLV_ERROR; |
| 1273 |
} |
| 1274 |
dbg = ownerdie->di_dbg; |
| 1275 |
|
| 1276 |
new_attr = (Dwarf_P_Attribute) |
| 1277 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1278 |
if (new_attr == NULL) { |
| 1279 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1280 |
return DW_DLV_ERROR; |
| 1281 |
} |
| 1282 |
|
| 1283 |
new_attr->ar_attribute = attrnum; |
| 1284 |
new_attr->ar_attribute_form = DW_FORM_implicit_const; |
| 1285 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1286 |
new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */ |
| 1287 |
new_attr->ar_next = 0; |
| 1288 |
|
| 1289 |
/* The value will go in the abbrev section. |
| 1290 |
Not the DIE. Encoding done with abbrev generation. */ |
| 1291 |
new_attr->ar_data = 0; |
| 1292 |
new_attr->ar_nbytes = 0; |
| 1293 |
new_attr->ar_implicit_const = signed_value; |
| 1294 |
|
| 1295 |
/* add attribute to the die */ |
| 1296 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1297 |
*outattr = new_attr; |
| 1298 |
return DW_DLV_OK; |
| 1299 |
} |
| 1300 |
|
| 1301 |
int |
| 1302 |
dwarf_add_AT_any_value_sleb_a(Dwarf_P_Die ownerdie, |
| 1303 |
Dwarf_Half attrnum, |
| 1304 |
Dwarf_Signed signed_value, |
| 1305 |
Dwarf_P_Attribute *attr_out, |
| 1306 |
Dwarf_Error * error) |
| 1307 |
{ |
| 1308 |
Dwarf_P_Attribute new_attr = 0; |
| 1309 |
int leb_size = 0; |
| 1310 |
Dwarf_P_Debug dbg = 0; |
| 1311 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 1312 |
int res = 0; |
| 1313 |
|
| 1314 |
if (ownerdie == NULL) { |
| 1315 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1316 |
return DW_DLV_ERROR; |
| 1317 |
} |
| 1318 |
dbg = ownerdie->di_dbg; |
| 1319 |
|
| 1320 |
new_attr = (Dwarf_P_Attribute) |
| 1321 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1322 |
if (new_attr == NULL) { |
| 1323 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1324 |
return DW_DLV_ERROR; |
| 1325 |
} |
| 1326 |
|
| 1327 |
new_attr->ar_attribute = attrnum; |
| 1328 |
new_attr->ar_attribute_form = DW_FORM_sdata; |
| 1329 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1330 |
new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */ |
| 1331 |
new_attr->ar_next = 0; |
| 1332 |
|
| 1333 |
res = dwarf_encode_signed_leb128(signed_value, &leb_size, |
| 1334 |
encode_buffer, |
| 1335 |
sizeof(encode_buffer)); |
| 1336 |
if (res != DW_DLV_OK) { |
| 1337 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1338 |
return DW_DLV_ERROR; |
| 1339 |
} |
| 1340 |
new_attr->ar_data = (char *) |
| 1341 |
_dwarf_p_get_alloc(dbg, leb_size); |
| 1342 |
if (new_attr->ar_data == NULL) { |
| 1343 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1344 |
return DW_DLV_ERROR; |
| 1345 |
} |
| 1346 |
memcpy(new_attr->ar_data, encode_buffer, leb_size); |
| 1347 |
new_attr->ar_nbytes = leb_size; |
| 1348 |
|
| 1349 |
/* add attribute to the die */ |
| 1350 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1351 |
*attr_out = new_attr; |
| 1352 |
return DW_DLV_OK; |
| 1353 |
} |
| 1354 |
|
| 1355 |
int |
| 1356 |
dwarf_add_AT_const_value_unsignedint_a(Dwarf_P_Die ownerdie, |
| 1357 |
Dwarf_Unsigned unsigned_value, |
| 1358 |
Dwarf_P_Attribute *attr_out, |
| 1359 |
Dwarf_Error * error) |
| 1360 |
{ |
| 1361 |
|
| 1362 |
return dwarf_add_AT_any_value_uleb_a( |
| 1363 |
ownerdie,DW_AT_const_value, |
| 1364 |
unsigned_value, |
| 1365 |
attr_out, |
| 1366 |
error); |
| 1367 |
} |
| 1368 |
|
| 1369 |
int |
| 1370 |
dwarf_add_AT_data16(Dwarf_P_Die ownerdie, |
| 1371 |
Dwarf_Half attrnum, |
| 1372 |
Dwarf_Form_Data16 * ptr_to_val, |
| 1373 |
Dwarf_P_Attribute * attr_return, |
| 1374 |
Dwarf_Error * error) |
| 1375 |
{ |
| 1376 |
Dwarf_P_Attribute new_attr; |
| 1377 |
int val_size = sizeof(Dwarf_Form_Data16); |
| 1378 |
Dwarf_P_Debug dbg = 0; |
| 1379 |
|
| 1380 |
if (ownerdie == NULL) { |
| 1381 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1382 |
return DW_DLV_ERROR; |
| 1383 |
} |
| 1384 |
dbg = ownerdie->di_dbg; |
| 1385 |
new_attr = (Dwarf_P_Attribute) |
| 1386 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1387 |
if (new_attr == NULL) { |
| 1388 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1389 |
return DW_DLV_ERROR; |
| 1390 |
} |
| 1391 |
new_attr->ar_attribute = attrnum; |
| 1392 |
new_attr->ar_attribute_form = DW_FORM_data16; |
| 1393 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1394 |
new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */ |
| 1395 |
new_attr->ar_next = 0; |
| 1396 |
new_attr->ar_data = (char *) |
| 1397 |
_dwarf_p_get_alloc(dbg, val_size); |
| 1398 |
if (new_attr->ar_data == NULL) { |
| 1399 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1400 |
return DW_DLV_ERROR; |
| 1401 |
} |
| 1402 |
memcpy(new_attr->ar_data, ptr_to_val->fd_data, val_size); |
| 1403 |
new_attr->ar_nbytes = val_size; |
| 1404 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1405 |
*attr_return = new_attr; |
| 1406 |
return DW_DLV_OK; |
| 1407 |
} |
| 1408 |
|
| 1409 |
int |
| 1410 |
dwarf_add_AT_any_value_uleb_a(Dwarf_P_Die ownerdie, |
| 1411 |
Dwarf_Half attrnum, |
| 1412 |
Dwarf_Unsigned unsigned_value, |
| 1413 |
Dwarf_P_Attribute * attr_out, |
| 1414 |
Dwarf_Error * error) |
| 1415 |
{ |
| 1416 |
Dwarf_P_Attribute new_attr; |
| 1417 |
int leb_size; |
| 1418 |
Dwarf_P_Debug dbg = 0; |
| 1419 |
char encode_buffer[ENCODE_SPACE_NEEDED]; |
| 1420 |
int res; |
| 1421 |
|
| 1422 |
if (ownerdie == NULL) { |
| 1423 |
_dwarf_p_error(dbg, error, DW_DLE_DIE_NULL); |
| 1424 |
return DW_DLV_ERROR; |
| 1425 |
} |
| 1426 |
dbg = ownerdie->di_dbg; |
| 1427 |
new_attr = (Dwarf_P_Attribute) |
| 1428 |
_dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); |
| 1429 |
if (new_attr == NULL) { |
| 1430 |
_dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL); |
| 1431 |
return DW_DLV_ERROR; |
| 1432 |
} |
| 1433 |
|
| 1434 |
new_attr->ar_attribute = attrnum; |
| 1435 |
new_attr->ar_attribute_form = DW_FORM_udata; |
| 1436 |
new_attr->ar_rel_type = R_MIPS_NONE; |
| 1437 |
new_attr->ar_reloc_len = 0; /* unused for R_MIPS_NONE */ |
| 1438 |
new_attr->ar_next = 0; |
| 1439 |
|
| 1440 |
res = dwarf_encode_leb128(unsigned_value, &leb_size, |
| 1441 |
encode_buffer, |
| 1442 |
sizeof(encode_buffer)); |
| 1443 |
if (res != DW_DLV_OK) { |
| 1444 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1445 |
return DW_DLV_ERROR; |
| 1446 |
} |
| 1447 |
new_attr->ar_data = (char *) |
| 1448 |
_dwarf_p_get_alloc(dbg, leb_size); |
| 1449 |
if (new_attr->ar_data == NULL) { |
| 1450 |
_dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 1451 |
return DW_DLV_ERROR; |
| 1452 |
} |
| 1453 |
memcpy(new_attr->ar_data, encode_buffer, leb_size); |
| 1454 |
new_attr->ar_nbytes = leb_size; |
| 1455 |
|
| 1456 |
/* add attribute to the die */ |
| 1457 |
_dwarf_pro_add_at_to_die(ownerdie, new_attr); |
| 1458 |
*attr_out = new_attr; |
| 1459 |
return DW_DLV_OK; |
| 1460 |
} |