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
00043
00044
00045
00046 #include "config.h"
00047 #include "dwarf_stuff.h"
00048 #include "libdwarfdefs.h"
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #ifdef HAVE_ELFACCESS_H
00053 #include <elfaccess.h>
00054 #endif
00055 #include "pro_incl.h"
00056 #include "pro_section.h"
00057 #include "pro_line.h"
00058 #include "pro_frame.h"
00059 #include "pro_die.h"
00060 #include "pro_macinfo.h"
00061 #include "pro_types.h"
00062
00063 #ifndef SHF_MIPS_NOSTRIP
00064
00065 #define SHF_MIPS_NOSTRIP 0
00066 #endif
00067 #ifndef R_MIPS_NONE
00068 #define R_MIPS_NONE 0
00069 #endif
00070
00071 #ifndef TRUE
00072 #define TRUE 1
00073 #endif
00074 #ifndef FALSE
00075 #define FALSE 0
00076 #endif
00077
00078
00079
00080
00081 char *_dwarf_rel_section_names[] = {
00082 ".rel.debug_info",
00083 ".rel.debug_line",
00084 ".rel.debug_abbrev",
00085 ".rel.debug_frame",
00086 ".rel.debug_aranges",
00087 ".rel.debug_pubnames",
00088 ".rel.debug_str",
00089 ".rel.debug_funcnames",
00090 ".rel.debug_typenames",
00091 ".rel.debug_varnames",
00092 ".rel.debug_weaknames",
00093 ".rel.debug_macinfo",
00094 ".rel.debug_loc",
00095 ".rel.eh_frame",
00096 };
00097
00098
00099
00100
00101
00102 char *_dwarf_sectnames[] = {
00103 #ifdef KEY
00104 DEBUG_INFO_SECTNAME,
00105 DEBUG_LINE_SECTNAME,
00106 DEBUG_ABBREV_SECTNAME,
00107 DEBUG_FRAME_SECTNAME,
00108 DEBUG_ARANGES_SECTNAME,
00109 DEBUG_PUBNAMES_SECTNAME,
00110 DEBUG_STR_SECTNAME,
00111 DEBUG_FUNCNAMES_SECTNAME,
00112 DEBUG_TYPENAMES_SECTNAME,
00113 DEBUG_VARNAMES_SECTNAME,
00114 DEBUG_WEAKNAMES_SECTNAME,
00115 DEBUG_MACINFO_SECTNAME,
00116 DEBUG_LOC_SECTNAME,
00117 EH_FRAME_SECTNAME
00118 #else
00119 ".debug_info",
00120 ".debug_line",
00121 ".debug_abbrev",
00122 ".debug_frame",
00123 ".debug_aranges",
00124 ".debug_pubnames",
00125 ".debug_str",
00126 ".debug_funcnames",
00127 ".debug_typenames",
00128 ".debug_varnames",
00129 ".debug_weaknames",
00130 ".debug_macinfo",
00131 ".debug_loc",
00132 ".eh_frame"
00133 #endif
00134 };
00135
00136
00137
00138
00139 static Dwarf_Ubyte std_opcode_len[] = { 0,
00140 1,
00141 1,
00142 1,
00143 1,
00144 0,
00145 0,
00146 0,
00147 1,
00148 };
00149
00150
00151
00152
00153
00154
00155
00156 typedef struct Dwarf_P_Rel_s *Dwarf_P_Rel;
00157 struct Dwarf_P_Rel_s {
00158 Dwarf_P_Rel dr_next;
00159 void *dr_rel_datap;
00160 };
00161 typedef struct Dwarf_P_Rel_Head_s *Dwarf_P_Rel_Head;
00162 struct Dwarf_P_Rel_Head_s {
00163 struct Dwarf_P_Rel_s *drh_head;
00164 struct Dwarf_P_Rel_s *drh_tail;
00165 };
00166
00167 int _dwf_pro_generate_ehframe(Dwarf_P_Debug dbg, Dwarf_Error * error);
00168 static int _dwarf_pro_generate_debugline(Dwarf_P_Debug dbg,
00169 Dwarf_Error * error);
00170 static int _dwarf_pro_generate_debugframe(Dwarf_P_Debug dbg,
00171 Dwarf_Error * error);
00172 static int _dwarf_pro_generate_debuginfo(Dwarf_P_Debug dbg,
00173 Dwarf_Error * error);
00174 static Dwarf_P_Abbrev _dwarf_pro_getabbrev(Dwarf_P_Die, Dwarf_P_Abbrev);
00175 static int _dwarf_pro_match_attr
00176 (Dwarf_P_Attribute, Dwarf_P_Abbrev, int no_attr);
00177
00178
00179 #define OPC_INCS_ZERO -1
00180 #define OPC_OUT_OF_RANGE -2
00181 #define LINE_OUT_OF_RANGE -3
00182 static int _dwarf_pro_get_opc(Dwarf_Unsigned addr_adv, int line_adv);
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 static int
00195 dwarf_need_debug_line_section(Dwarf_P_Debug dbg)
00196 {
00197 if (dbg->de_lines == NULL && dbg->de_file_entries == NULL
00198 && dbg->de_inc_dirs == NULL) {
00199 return FALSE;
00200 }
00201 return TRUE;
00202 }
00203
00204
00205
00206
00207
00208
00209 Dwarf_Signed
00210 dwarf_transform_to_disk_form(Dwarf_P_Debug dbg, Dwarf_Error * error)
00211 {
00212
00213
00214
00215
00216
00217 int nbufs;
00218 int sect;
00219 int name_idx;
00220 int err;
00221 Dwarf_Unsigned du;
00222
00223 if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
00224 DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, DW_DLV_NOCOUNT);
00225 }
00226
00227
00228 for (sect = 0; sect < NUM_DEBUG_SECTIONS; sect++) {
00229 long flags = 0;
00230
00231 switch (sect) {
00232
00233 case DEBUG_INFO:
00234 if (dbg->de_dies == NULL)
00235 continue;
00236 break;
00237
00238 case DEBUG_LINE:
00239 if (dwarf_need_debug_line_section(dbg) == FALSE) {
00240 continue;
00241 }
00242 break;
00243
00244 case DEBUG_ABBREV:
00245 if (dbg->de_dies == NULL)
00246 continue;
00247 break;
00248
00249 case DEBUG_FRAME:
00250 if (dbg->de_frame_cies == NULL)
00251 continue;
00252 flags = SHF_MIPS_NOSTRIP;
00253 break;
00254
00255 case DEBUG_ARANGES:
00256 if (dbg->de_arange == NULL)
00257 continue;
00258 break;
00259
00260 case DEBUG_PUBNAMES:
00261 if (dbg->de_simple_name_headers[dwarf_snk_pubname].
00262 sn_head == NULL)
00263 continue;
00264 break;
00265
00266 case DEBUG_STR:
00267 if (dbg->de_strings == NULL)
00268 continue;
00269 break;
00270
00271 case DEBUG_FUNCNAMES:
00272 if (dbg->de_simple_name_headers[dwarf_snk_funcname].
00273 sn_head == NULL)
00274 continue;
00275 break;
00276
00277 case DEBUG_TYPENAMES:
00278 if (dbg->de_simple_name_headers[dwarf_snk_typename].
00279 sn_head == NULL)
00280 continue;
00281 break;
00282
00283 case DEBUG_VARNAMES:
00284 if (dbg->de_simple_name_headers[dwarf_snk_varname].
00285 sn_head == NULL)
00286 continue;
00287 break;
00288
00289 case DEBUG_WEAKNAMES:
00290 if (dbg->de_simple_name_headers[dwarf_snk_weakname].
00291 sn_head == NULL)
00292 continue;
00293 break;
00294
00295 case DEBUG_MACINFO:
00296 if (dbg->de_first_macinfo == NULL)
00297 continue;
00298 break;
00299 case DEBUG_LOC:
00300
00301 continue;
00302 case EH_FRAME:
00303 if (dbg->de_eh_frame_cies == NULL)
00304 continue;
00305 #ifdef KEY
00306 flags = SHF_MIPS_NOSTRIP | SHF_ALLOC;
00307 #else
00308 flags = SHF_MIPS_NOSTRIP;
00309 #endif
00310 break;
00311 default:
00312
00313 DWARF_P_DBG_ERROR(dbg, DW_DLE_ELF_SECT_ERR, DW_DLV_NOCOUNT);
00314 }
00315 {
00316 int new_base_elf_sect;
00317
00318 if (dbg->de_func_b) {
00319 new_base_elf_sect =
00320 dbg->de_func_b(_dwarf_sectnames[sect],
00321 1,
00322 SECTION_TYPE,
00323 flags, SHN_UNDEF, 0, &du, &err);
00324
00325 } else {
00326 new_base_elf_sect = dbg->de_func(_dwarf_sectnames[sect],
00327 dbg->
00328 de_relocation_record_size,
00329 SECTION_TYPE, flags,
00330 SHN_UNDEF, 0,
00331 &name_idx, &err);
00332 du = name_idx;
00333 }
00334 if (new_base_elf_sect == -1) {
00335 DWARF_P_DBG_ERROR(dbg, DW_DLE_ELF_SECT_ERR,
00336 DW_DLV_NOCOUNT);
00337 }
00338 dbg->de_elf_sects[sect] = new_base_elf_sect;
00339
00340 dbg->de_sect_name_idx[sect] = du;
00341 }
00342 }
00343
00344 nbufs = 0;
00345
00346
00347
00348
00349
00350 if (dwarf_need_debug_line_section(dbg) == TRUE) {
00351 nbufs = _dwarf_pro_generate_debugline(dbg, error);
00352 if (nbufs < 0) {
00353 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGLINE_ERROR,
00354 DW_DLV_NOCOUNT);
00355 }
00356 }
00357
00358 if (dbg->de_frame_cies) {
00359 nbufs = _dwarf_pro_generate_debugframe(dbg, error);
00360 if (nbufs < 0) {
00361 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGFRAME_ERROR,
00362 DW_DLV_NOCOUNT);
00363 }
00364 }
00365 if (dbg->de_first_macinfo) {
00366 nbufs = _dwarf_pro_transform_macro_info_to_disk(dbg, error);
00367 if (nbufs < 0) {
00368 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGMACINFO_ERROR,
00369 DW_DLV_NOCOUNT);
00370 }
00371 }
00372
00373 if (dbg->de_dies) {
00374 nbufs = _dwarf_pro_generate_debuginfo(dbg, error);
00375 if (nbufs < 0) {
00376 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00377 DW_DLV_NOCOUNT);
00378 }
00379 }
00380
00381 if (dbg->de_arange) {
00382 nbufs = _dwarf_transform_arange_to_disk(dbg, error);
00383 if (nbufs < 0) {
00384 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00385 DW_DLV_NOCOUNT);
00386 }
00387 }
00388
00389 if (dbg->de_simple_name_headers[dwarf_snk_pubname].sn_head) {
00390 nbufs = _dwarf_transform_simplename_to_disk(dbg,
00391 dwarf_snk_pubname,
00392 DEBUG_PUBNAMES,
00393 error);
00394
00395
00396 if (nbufs < 0) {
00397 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00398 DW_DLV_NOCOUNT);
00399 }
00400 }
00401
00402 if (dbg->de_simple_name_headers[dwarf_snk_funcname].sn_head) {
00403 nbufs = _dwarf_transform_simplename_to_disk(dbg,
00404 dwarf_snk_funcname,
00405 DEBUG_FUNCNAMES,
00406 error);
00407 if (nbufs < 0) {
00408 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00409 DW_DLV_NOCOUNT);
00410 }
00411 }
00412
00413 if (dbg->de_simple_name_headers[dwarf_snk_typename].sn_head) {
00414 nbufs = _dwarf_transform_simplename_to_disk(dbg,
00415 dwarf_snk_typename,
00416 DEBUG_TYPENAMES,
00417 error);
00418 if (nbufs < 0) {
00419 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00420 DW_DLV_NOCOUNT);
00421 }
00422 }
00423
00424 if (dbg->de_simple_name_headers[dwarf_snk_varname].sn_head) {
00425 nbufs = _dwarf_transform_simplename_to_disk(dbg,
00426 dwarf_snk_varname,
00427 DEBUG_VARNAMES,
00428 error);
00429
00430 if (nbufs < 0) {
00431 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00432 DW_DLV_NOCOUNT);
00433 }
00434 }
00435
00436 if (dbg->de_simple_name_headers[dwarf_snk_weakname].sn_head) {
00437 nbufs = _dwarf_transform_simplename_to_disk(dbg,
00438 dwarf_snk_weakname,
00439 DEBUG_WEAKNAMES,
00440 error);
00441
00442 if (nbufs < 0) {
00443 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00444 DW_DLV_NOCOUNT);
00445 }
00446 }
00447
00448 if (dbg->de_eh_frame_cies) {
00449 nbufs = _dwf_pro_generate_ehframe(dbg,error);
00450 if (nbufs < 0) {
00451 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGFRAME_ERROR, DW_DLV_NOCOUNT);
00452 }
00453 }
00454
00455 {
00456 Dwarf_Signed new_secs;
00457 int res;
00458
00459 res = dbg->de_transform_relocs_to_disk(dbg, &new_secs);
00460 if (res != DW_DLV_OK) {
00461 DWARF_P_DBG_ERROR(dbg, DW_DLE_DEBUGINFO_ERROR,
00462 DW_DLV_NOCOUNT);
00463 }
00464 nbufs += new_secs;
00465 }
00466 return nbufs;
00467 }
00468
00469
00470
00471
00472
00473 static int
00474 _dwarf_pro_generate_debugline(Dwarf_P_Debug dbg, Dwarf_Error * error)
00475 {
00476 Dwarf_P_Inc_Dir curdir;
00477 Dwarf_P_F_Entry curentry;
00478 Dwarf_P_Line curline, prevline;
00479
00480
00481
00482 int sum_bytes;
00483 int prolog_size;
00484 unsigned char *data;
00485 int elfsectno;
00486 unsigned char *start_line_sec;
00487
00488
00489 Dwarf_Unsigned du;
00490 Dwarf_Ubyte db;
00491 Dwarf_Half dh;
00492 int res;
00493 int uwordb_size = dbg->de_offset_size;
00494 int extension_size = dbg->de_64bit_extension ? 4 : 0;
00495 int upointer_size = dbg->de_pointer_size;
00496 char buff1[ENCODE_SPACE_NEEDED];
00497
00498
00499 sum_bytes = 0;
00500
00501 elfsectno = dbg->de_elf_sects[DEBUG_LINE];
00502
00503
00504 prolog_size = 0;
00505
00506 curdir = dbg->de_inc_dirs;
00507 while (curdir) {
00508 prolog_size += strlen(curdir->did_name) + 1;
00509 curdir = curdir->did_next;
00510 }
00511 prolog_size++;
00512
00513
00514
00515 curentry = dbg->de_file_entries;
00516 while (curentry) {
00517 prolog_size +=
00518 strlen(curentry->dfe_name) + 1 + curentry->dfe_nbytes;
00519 curentry = curentry->dfe_next;
00520 }
00521 prolog_size++;
00522
00523
00524 prolog_size += extension_size +
00525 sizeof_uhalf(dbg) +
00526 uwordb_size +
00527 sizeof_ubyte(dbg) +
00528 sizeof_ubyte(dbg) +
00529 sizeof_ubyte(dbg) +
00530 sizeof_ubyte(dbg) +
00531 sizeof_ubyte(dbg);
00532
00533
00534 prolog_size += sizeof(std_opcode_len);
00535 prolog_size += uwordb_size;
00536
00537 GET_CHUNK(dbg, elfsectno, data, prolog_size, error);
00538 start_line_sec = data;
00539
00540
00541
00542 du = 0;
00543 if (extension_size) {
00544 Dwarf_Word x = DISTINGUISHED_VALUE;
00545
00546 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &x,
00547 sizeof(x), extension_size);
00548 data += extension_size;
00549 }
00550
00551 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &du,
00552 sizeof(du), uwordb_size);
00553 data += uwordb_size;
00554
00555 dh = VERSION;
00556 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &dh,
00557 sizeof(dh), sizeof(Dwarf_Half));
00558 data += sizeof(Dwarf_Half);
00559
00560
00561 du = prolog_size - (uwordb_size + sizeof(Dwarf_Half) + uwordb_size);
00562 {
00563 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &du,
00564 sizeof(du), uwordb_size);
00565 data += uwordb_size;
00566 }
00567 db = MIN_INST_LENGTH;
00568 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00569 sizeof(db), sizeof(Dwarf_Ubyte));
00570 data += sizeof(Dwarf_Ubyte);
00571 db = DEFAULT_IS_STMT;
00572 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00573 sizeof(db), sizeof(Dwarf_Ubyte));
00574 data += sizeof(Dwarf_Ubyte);
00575 db = (Dwarf_Ubyte) LINE_BASE;
00576 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00577 sizeof(db), sizeof(Dwarf_Ubyte));
00578 data += sizeof(Dwarf_Ubyte);
00579 db = LINE_RANGE;
00580 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00581 sizeof(db), sizeof(Dwarf_Ubyte));
00582 data += sizeof(Dwarf_Ubyte);
00583 db = OPCODE_BASE;
00584 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00585 sizeof(db), sizeof(Dwarf_Ubyte));
00586 data += sizeof(Dwarf_Ubyte);
00587 WRITE_UNALIGNED(dbg, (void *) data, (const void *) std_opcode_len,
00588 sizeof(std_opcode_len), sizeof(std_opcode_len));
00589 data += sizeof(std_opcode_len);
00590
00591
00592 curdir = dbg->de_inc_dirs;
00593 while (curdir) {
00594 strcpy((char *) data, curdir->did_name);
00595 data += strlen(curdir->did_name) + 1;
00596 curdir = curdir->did_next;
00597 }
00598 *data = '\0';
00599 data++;
00600
00601
00602 curentry = dbg->de_file_entries;
00603 while (curentry) {
00604 strcpy((char *) data, curentry->dfe_name);
00605 data += strlen(curentry->dfe_name) + 1;
00606
00607 memcpy((void *) data,
00608 (const void *) curentry->dfe_args, curentry->dfe_nbytes);
00609 data += curentry->dfe_nbytes;
00610 curentry = curentry->dfe_next;
00611 }
00612 *data = '\0';
00613 data++;
00614
00615 sum_bytes += prolog_size;
00616
00617 curline = dbg->de_lines;
00618 prevline = (Dwarf_P_Line)
00619 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Line_s));
00620 if (prevline == NULL) {
00621 DWARF_P_DBG_ERROR(dbg, DW_DLE_LINE_ALLOC, -1);
00622 }
00623 _dwarf_pro_reg_init(prevline);
00624
00625 while (curline) {
00626 int nbytes;
00627 char *arg;
00628 int opc;
00629 int no_lns_copy;
00630
00631
00632 Dwarf_Unsigned addr_adv;
00633 int line_adv;
00634
00635
00636
00637 no_lns_copy = 0;
00638 if (curline->dpl_opc != 0) {
00639 int inst_bytes;
00640 char *str;
00641 int str_nbytes;
00642
00643 switch (curline->dpl_opc) {
00644 case DW_LNE_end_sequence:
00645
00646
00647 addr_adv = curline->dpl_address - prevline->dpl_address;
00648 if (addr_adv > 0) {
00649 db = DW_LNS_advance_pc;
00650 res =
00651 _dwarf_pro_encode_leb128_nm(addr_adv /
00652 MIN_INST_LENGTH,
00653 &nbytes, buff1,
00654 sizeof(buff1));
00655 if (res != DW_DLV_OK) {
00656 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00657 }
00658 GET_CHUNK(dbg, elfsectno, data,
00659 nbytes + sizeof(Dwarf_Ubyte), error);
00660 WRITE_UNALIGNED(dbg, (void *) data,
00661 (const void *) &db, sizeof(db),
00662 sizeof(Dwarf_Ubyte));
00663 data += sizeof(Dwarf_Ubyte);
00664
00665 memcpy((void *) data, (const void *) buff1, nbytes);
00666 data += nbytes + sizeof(Dwarf_Ubyte);
00667 sum_bytes += nbytes + sizeof(Dwarf_Ubyte);
00668 prevline->dpl_address = curline->dpl_address;
00669 }
00670
00671
00672 db = 0;
00673 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00674 error);
00675 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00676 sizeof(db), sizeof(Dwarf_Ubyte));
00677 data += sizeof(Dwarf_Ubyte);
00678 sum_bytes += sizeof(Dwarf_Ubyte);
00679
00680
00681 inst_bytes = sizeof(Dwarf_Ubyte);
00682 res =
00683 _dwarf_pro_encode_leb128_nm(inst_bytes, &str_nbytes,
00684 buff1, sizeof(buff1));
00685 if (res != DW_DLV_OK) {
00686 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00687 }
00688 GET_CHUNK(dbg, elfsectno, data, str_nbytes, error);
00689 memcpy((void *) data, (const void *) buff1, str_nbytes);
00690 data += str_nbytes;
00691 sum_bytes += str_nbytes;
00692
00693
00694 db = DW_LNE_end_sequence;
00695 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00696 error);
00697 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00698 sizeof(db), sizeof(Dwarf_Ubyte));
00699 data += sizeof(Dwarf_Ubyte);
00700 sum_bytes += sizeof(Dwarf_Ubyte);
00701
00702 _dwarf_pro_reg_init(prevline);
00703 no_lns_copy = 1;
00704
00705
00706 break;
00707
00708 case DW_LNE_set_address:
00709
00710
00711 db = 0;
00712 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00713 error);
00714 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00715 sizeof(db), sizeof(Dwarf_Ubyte));
00716 data += sizeof(Dwarf_Ubyte);
00717 sum_bytes += sizeof(Dwarf_Ubyte);
00718
00719
00720 inst_bytes = sizeof(Dwarf_Ubyte) + upointer_size;
00721 res =
00722 _dwarf_pro_encode_leb128_nm(inst_bytes, &str_nbytes,
00723 buff1, sizeof(buff1));
00724 if (res != DW_DLV_OK) {
00725 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00726 }
00727 GET_CHUNK(dbg, elfsectno, data, str_nbytes, error);
00728 str = buff1;
00729
00730 memcpy((void *) data, (const void *) str, str_nbytes);
00731 data += str_nbytes;
00732 sum_bytes += str_nbytes;
00733
00734
00735 db = DW_LNE_set_address;
00736 GET_CHUNK(dbg, elfsectno, data, upointer_size +
00737 sizeof(Dwarf_Ubyte), error);
00738 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00739 sizeof(db), sizeof(Dwarf_Ubyte));
00740 data += sizeof(Dwarf_Ubyte);
00741 sum_bytes += sizeof(Dwarf_Ubyte);
00742
00743
00744 res = dbg->de_reloc_name(dbg, DEBUG_LINE, sum_bytes,
00745
00746 curline->dpl_r_symidx,
00747 dwarf_drt_data_reloc,
00748 uwordb_size);
00749 if (res != DW_DLV_OK) {
00750 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00751 }
00752
00753
00754 du = curline->dpl_address;
00755 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &du,
00756 sizeof(du), upointer_size);
00757 data += upointer_size;
00758 sum_bytes += upointer_size;
00759 prevline->dpl_address = curline->dpl_address;
00760 no_lns_copy = 1;
00761 break;
00762 }
00763 } else {
00764 if (curline->dpl_file != prevline->dpl_file) {
00765 db = DW_LNS_set_file;
00766 res =
00767 _dwarf_pro_encode_leb128_nm(curline->dpl_file,
00768 &nbytes, buff1,
00769 sizeof(buff1));
00770 if (res != DW_DLV_OK) {
00771 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00772 }
00773 arg = buff1;
00774 GET_CHUNK(dbg, elfsectno, data,
00775 nbytes + sizeof(Dwarf_Ubyte), error);
00776 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00777 sizeof(db), sizeof(Dwarf_Ubyte));
00778 data += sizeof(Dwarf_Ubyte);
00779 memcpy((void *) data, (const void *) arg, nbytes);
00780 data += nbytes;
00781 sum_bytes += nbytes + sizeof(Dwarf_Ubyte);
00782 prevline->dpl_file = curline->dpl_file;
00783 }
00784 if (curline->dpl_column != prevline->dpl_column) {
00785 db = DW_LNS_set_column;
00786 res = _dwarf_pro_encode_leb128_nm(curline->dpl_column,
00787 &nbytes,
00788 buff1, sizeof(buff1));
00789 if (res != DW_DLV_OK) {
00790 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00791 }
00792
00793 arg = buff1;
00794 GET_CHUNK(dbg, elfsectno, data,
00795 nbytes + sizeof(Dwarf_Ubyte), error);
00796 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00797 sizeof(db), sizeof(Dwarf_Ubyte));
00798 data += sizeof(Dwarf_Ubyte);
00799 memcpy((void *) data, (const void *) arg, nbytes);
00800 data += nbytes;
00801 sum_bytes += nbytes + sizeof(Dwarf_Ubyte);
00802 prevline->dpl_column = curline->dpl_column;
00803 }
00804 if (curline->dpl_is_stmt != prevline->dpl_is_stmt) {
00805 db = DW_LNS_negate_stmt;
00806 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00807 error);
00808 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00809 sizeof(db), sizeof(Dwarf_Ubyte));
00810 data += sizeof(Dwarf_Ubyte);
00811 sum_bytes += sizeof(Dwarf_Ubyte);
00812 prevline->dpl_is_stmt = curline->dpl_is_stmt;
00813 }
00814 if (curline->dpl_basic_block == true &&
00815 prevline->dpl_basic_block == false) {
00816 db = DW_LNS_set_basic_block;
00817 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00818 error);
00819 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00820 sizeof(db), sizeof(Dwarf_Ubyte));
00821 data += sizeof(Dwarf_Ubyte);
00822 sum_bytes += sizeof(Dwarf_Ubyte);
00823 prevline->dpl_basic_block = curline->dpl_basic_block;
00824 }
00825 addr_adv = curline->dpl_address - prevline->dpl_address;
00826
00827 line_adv = (int) (curline->dpl_line - prevline->dpl_line);
00828 if ((addr_adv % MIN_INST_LENGTH) != 0) {
00829 DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_ADDRESS, -1);
00830 }
00831 if ((opc = _dwarf_pro_get_opc(addr_adv, line_adv)) > 0) {
00832 no_lns_copy = 1;
00833 db = opc;
00834 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte),
00835 error);
00836 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
00837 sizeof(db), sizeof(Dwarf_Ubyte));
00838 data += sizeof(Dwarf_Ubyte);
00839 sum_bytes += sizeof(Dwarf_Ubyte);
00840 prevline->dpl_basic_block = false;
00841 prevline->dpl_address = curline->dpl_address;
00842 prevline->dpl_line = curline->dpl_line;
00843 } else {
00844 if (addr_adv > 0) {
00845 db = DW_LNS_advance_pc;
00846 res =
00847 _dwarf_pro_encode_leb128_nm(addr_adv /
00848 MIN_INST_LENGTH,
00849 &nbytes, buff1,
00850 sizeof(buff1));
00851 if (res != DW_DLV_OK) {
00852 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00853 }
00854
00855 arg = buff1;
00856 GET_CHUNK(dbg, elfsectno, data,
00857 nbytes + sizeof(Dwarf_Ubyte), error);
00858 WRITE_UNALIGNED(dbg, (void *) data,
00859 (const void *) &db,
00860 sizeof(db), sizeof(Dwarf_Ubyte));
00861 data += sizeof(Dwarf_Ubyte);
00862 memcpy((void *) data, (const void *) arg, nbytes);
00863 data += nbytes + sizeof(Dwarf_Ubyte);
00864 sum_bytes += nbytes + sizeof(Dwarf_Ubyte);
00865 prevline->dpl_basic_block = false;
00866 prevline->dpl_address = curline->dpl_address;
00867 }
00868 if (line_adv != 0) {
00869 db = DW_LNS_advance_line;
00870 res = _dwarf_pro_encode_signed_leb128_nm(line_adv,
00871 &nbytes,
00872 buff1,
00873 sizeof
00874 (buff1));
00875 if (res != DW_DLV_OK) {
00876 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
00877 }
00878
00879 arg = buff1;
00880 GET_CHUNK(dbg, elfsectno, data,
00881 nbytes + sizeof(Dwarf_Ubyte), error);
00882 WRITE_UNALIGNED(dbg, (void *) data,
00883 (const void *) &db, sizeof(db),
00884 sizeof(Dwarf_Ubyte));
00885 data += sizeof(Dwarf_Ubyte);
00886 memcpy((void *) data, (const void *) arg, nbytes);
00887 data += nbytes + sizeof(Dwarf_Ubyte);
00888 sum_bytes += nbytes + sizeof(Dwarf_Ubyte);
00889 prevline->dpl_basic_block = false;
00890 prevline->dpl_line = curline->dpl_line;
00891 }
00892 }
00893 }
00894 if (no_lns_copy == 0) {
00895
00896 db = DW_LNS_copy;
00897 GET_CHUNK(dbg, elfsectno, data, sizeof(Dwarf_Ubyte), error);
00898 WRITE_UNALIGNED(dbg, (void *) data,
00899 (const void *) &db,
00900 sizeof(db), sizeof(Dwarf_Ubyte));
00901 data += sizeof(Dwarf_Ubyte);
00902 sum_bytes += sizeof(Dwarf_Ubyte);
00903 prevline->dpl_basic_block = false;
00904 }
00905 curline = curline->dpl_next;
00906 }
00907
00908
00909 du = sum_bytes - uwordb_size - extension_size;
00910
00911
00912 {
00913 start_line_sec += extension_size;
00914 WRITE_UNALIGNED(dbg, (void *) start_line_sec,
00915 (const void *) &du, sizeof(du), uwordb_size);
00916 }
00917
00918 return (int) dbg->de_n_debug_sect;
00919 }
00920
00921
00922
00923
00924 static int
00925 _dwarf_pro_generate_debugframe(Dwarf_P_Debug dbg, Dwarf_Error * error)
00926 {
00927 int elfsectno;
00928 int i;
00929 int firsttime = 1;
00930 int pad;
00931
00932 Dwarf_P_Cie curcie;
00933 Dwarf_P_Fde curfde;
00934 unsigned char *data;
00935 #ifdef TARG_X8664
00936 Dwarf_Signed dsw;
00937 #else
00938 Dwarf_sfixed dsw;
00939 #endif
00940 Dwarf_Unsigned du;
00941 Dwarf_Ubyte db;
00942 long *cie_offs;
00943
00944 unsigned long cie_length;
00945 int cie_no;
00946 int uwordb_size = dbg->de_offset_size;
00947 int extension_size = dbg->de_64bit_extension ? 4 : 0;
00948 int upointer_size = dbg->de_pointer_size;
00949 Dwarf_Unsigned cur_off;
00950
00951
00952 #ifdef TARG_X8664
00953 if (generate_fpic_dwarf) {
00954 upointer_size = 4;
00955 }
00956 #endif
00957
00958 elfsectno = dbg->de_elf_sects[DEBUG_FRAME];
00959
00960 curcie = dbg->de_frame_cies;
00961 cie_length = 0;
00962 cur_off = 0;
00963 cie_offs = (long *)
00964 _dwarf_p_get_alloc(dbg, sizeof(long) * dbg->de_n_cie);
00965 if (cie_offs == NULL) {
00966 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_OFFS_ALLOC, -1);
00967 }
00968
00969 cie_no = 1;
00970 while (curcie) {
00971 char *code_al;
00972 int c_bytes;
00973 char *data_al;
00974 int d_bytes;
00975 int res;
00976 char buff1[ENCODE_SPACE_NEEDED];
00977 char buff2[ENCODE_SPACE_NEEDED];
00978 char buff3[ENCODE_SPACE_NEEDED];
00979 const char *augmentation;
00980 char *augmented_al;
00981 long augmented_fields_length;
00982 int a_bytes;
00983
00984 if (cie_no != 1) {
00985 fprintf (stderr, "Implement CIE %d", cie_no);
00986 abort();
00987 }
00988
00989 res = dbg->de_reloc_name(dbg, DEBUG_FRAME,
00990 extension_size,
00991 0,
00992 dwarf_drt_none,
00993 uwordb_size);
00994 if (res != DW_DLV_OK) {
00995 DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,-1);
00996 }
00997
00998 res = dbg->de_reloc_name(dbg, DEBUG_FRAME,
00999 extension_size+uwordb_size,
01000 0,
01001 dwarf_drt_none,
01002 uwordb_size);
01003 if (res != DW_DLV_OK) {
01004 DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,-1);
01005 }
01006
01007 res = _dwarf_pro_encode_leb128_nm(curcie->cie_code_align,
01008 &c_bytes,
01009 buff1, sizeof(buff1));
01010 if (res != DW_DLV_OK) {
01011 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_OFFS_ALLOC, -1);
01012 }
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027 res = _dwarf_pro_encode_signed_leb128_nm(curcie->cie_data_align,
01028 &d_bytes,
01029 buff2, sizeof(buff2));
01030 if (res != DW_DLV_OK) {
01031 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_OFFS_ALLOC, -1);
01032 }
01033 code_al = buff1;
01034 data_al = buff2;
01035
01036
01037 if (firsttime) {
01038 cie_offs[cie_no - 1] = 0;
01039 firsttime = 0;
01040 } else {
01041 cie_offs[cie_no - 1] = cie_offs[cie_no - 2] +
01042 (long) cie_length + uwordb_size + extension_size;
01043 }
01044 cie_no++;
01045 augmentation = curcie->cie_aug;
01046 if (strcmp(augmentation, DW_CIE_AUGMENTER_STRING_V0) == 0 ||
01047 strcmp(augmentation, PIC_DW_CIE_AUGMENTER_STRING_V0) == 0) {
01048 if (generate_fpic_dwarf)
01049 augmented_fields_length = 7;
01050 else
01051 augmented_fields_length = generate_m64_dwarf ? 10 : 6;
01052 res = _dwarf_pro_encode_leb128_nm(augmented_fields_length,
01053 &a_bytes, buff3,
01054 sizeof(buff3));
01055 augmented_al = buff3;
01056 if (res != DW_DLV_OK) {
01057 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_OFFS_ALLOC, -1);
01058 }
01059 cie_length = uwordb_size +
01060 sizeof(Dwarf_Ubyte) +
01061 strlen(curcie->cie_aug) + 1 +
01062 c_bytes +
01063 d_bytes +
01064 sizeof(Dwarf_Ubyte) +
01065 a_bytes +
01066 sizeof(Dwarf_Ubyte) +
01067 (generate_fpic_dwarf ? sizeof(Dwarf_Ubyte) : 0) +
01068 curcie->cie_inst_bytes;
01069 } else {
01070 cie_length = uwordb_size +
01071 sizeof(Dwarf_Ubyte) +
01072 strlen(curcie->cie_aug) + 1 +
01073 c_bytes + d_bytes + sizeof(Dwarf_Ubyte) +
01074
01075
01076
01077 curcie->cie_inst_bytes;
01078 }
01079 pad = (int) PADDING(cie_length, upointer_size);
01080 cie_length += pad;
01081 GET_CHUNK(dbg, elfsectno, data, cie_length + uwordb_size
01082 + extension_size, error);
01083 if (extension_size) {
01084 Dwarf_Unsigned x = DISTINGUISHED_VALUE;
01085
01086 WRITE_UNALIGNED(dbg, (void *) data,
01087 (const void *) &x,
01088 sizeof(x), extension_size);
01089 data += extension_size;
01090
01091 }
01092 du = cie_length;
01093
01094 WRITE_UNALIGNED(dbg, (void *) data,
01095 (const void *) &du, sizeof(du), uwordb_size);
01096 data += uwordb_size;
01097
01098
01099 du = DW_CIE_ID;
01100 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &du,
01101 sizeof(du), uwordb_size);
01102 data += uwordb_size;
01103
01104 db = curcie->cie_version;
01105 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
01106 sizeof(db), sizeof(Dwarf_Ubyte));
01107 data += sizeof(Dwarf_Ubyte);
01108 strcpy((char *) data, curcie->cie_aug);
01109 data += strlen(curcie->cie_aug) + 1;
01110 memcpy((void *) data, (const void *) code_al, c_bytes);
01111 data += c_bytes;
01112 memcpy((void *) data, (const void *) data_al, d_bytes);
01113 data += d_bytes;
01114 db = curcie->cie_ret_reg;
01115 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
01116 sizeof(db), sizeof(Dwarf_Ubyte));
01117 data += sizeof(Dwarf_Ubyte);
01118
01119 if (strcmp(augmentation, DW_CIE_AUGMENTER_STRING_V0) == 0 ||
01120 strcmp(augmentation, PIC_DW_CIE_AUGMENTER_STRING_V0) == 0) {
01121 memcpy((void *) data, (const void *) augmented_al, a_bytes);
01122 data += a_bytes;
01123 }
01124 memcpy((void *) data, (const void *) curcie->cie_inst,
01125 curcie->cie_inst_bytes);
01126 data += curcie->cie_inst_bytes;
01127 for (i = 0; i < pad; i++) {
01128 *data = DW_CFA_nop;
01129 data++;
01130 }
01131 curcie = curcie->cie_next;
01132 }
01133
01134 cur_off = cie_offs[cie_no - 2] + cie_length + uwordb_size
01135 + extension_size;
01136
01137
01138 curfde = dbg->de_frame_fdes;
01139 while (curfde) {
01140 Dwarf_P_Frame_Pgm curinst;
01141 long fde_length;
01142 int pad;
01143 Dwarf_P_Cie cie_ptr;
01144 Dwarf_Word cie_index, index;
01145 int oet_length, afl_length, res;
01146 int v0_augmentation = 0;
01147 unsigned char *fde_start_point;
01148
01149 char afl_buff[ENCODE_SPACE_NEEDED];
01150
01151
01152 cie_ptr = dbg->de_frame_cies;
01153 cie_index = curfde->fde_cie;
01154 index = 1;
01155
01156 while (cie_ptr && index < cie_index) {
01157 cie_ptr = cie_ptr->cie_next;
01158 index++;
01159 }
01160 if (cie_ptr == NULL) {
01161 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_NULL, -1);
01162 }
01163
01164 if (strcmp(cie_ptr->cie_aug, DW_CIE_AUGMENTER_STRING_V0) == 0 ||
01165 strcmp(cie_ptr->cie_aug, PIC_DW_CIE_AUGMENTER_STRING_V0) == 0) {
01166 v0_augmentation = 1;
01167 #ifdef TARG_X8664
01168 if (generate_fpic_dwarf || !generate_m64_dwarf)
01169 oet_length = 4;
01170 else
01171 oet_length = 8;
01172 #else
01173 oet_length = sizeof(Dwarf_sfixed);
01174 #endif
01175
01176 res = _dwarf_pro_encode_leb128_nm(oet_length,
01177 &afl_length, afl_buff,
01178 sizeof(afl_buff));
01179 if (res != DW_DLV_OK) {
01180 DWARF_P_DBG_ERROR(dbg, DW_DLE_CIE_OFFS_ALLOC, -1);
01181 }
01182
01183 fde_length = curfde->fde_n_bytes + uwordb_size +
01184
01185
01186 upointer_size +
01187 upointer_size +
01188 afl_length +
01189 oet_length;
01190 } else {
01191 fde_length = curfde->fde_n_bytes + uwordb_size +
01192
01193
01194 upointer_size +
01195 upointer_size;
01196 }
01197
01198 #ifndef TARG_X8664
01199
01200
01201 if (_dwarf_pro_add_AT_fde(dbg, curfde->fde_die, cur_off, error)
01202 < 0)
01203 return -1;
01204 #endif
01205
01206 res = dbg->de_reloc_name(dbg, DEBUG_FRAME,
01207 cur_off+extension_size,
01208 0,
01209 dwarf_drt_none,
01210 uwordb_size);
01211 if (res != DW_DLV_OK) {
01212 DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,-1);
01213 }
01214
01215 res = dbg->de_reloc_pair(dbg, DEBUG_FRAME,
01216 cur_off+extension_size+uwordb_size,
01217 dbg->de_sect_name_idx[DEBUG_FRAME],
01218 0,
01219 dwarf_drt_cie_label,
01220 uwordb_size);
01221 if (res != DW_DLV_OK) {
01222 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
01223 }
01224
01225
01226 res = dbg->de_reloc_name(dbg, DEBUG_FRAME,
01227 cur_off + extension_size + 2 * uwordb_size,
01228 curfde->fde_r_symidx,
01229 dwarf_drt_data_reloc, upointer_size);
01230 if (res != DW_DLV_OK) {
01231 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
01232 }
01233 res = dbg->de_reloc_pair(dbg,
01234
01235 DEBUG_FRAME,
01236 cur_off+extension_size+2*uwordb_size +
01237 upointer_size,
01238 curfde->fde_r_symidx,
01239 curfde->fde_end_symbol,
01240 dwarf_drt_first_of_length_pair,
01241 upointer_size);
01242 if (res != DW_DLV_OK) {
01243 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
01244 return 0;
01245 }
01246
01247
01248
01249 if (v0_augmentation &&
01250 curfde->fde_offset_into_exception_tables >= 0) {
01251
01252 int size;
01253 #ifdef TARG_X8664
01254 size = upointer_size;
01255 #else
01256 size = sizeof(Dwarf_sfixed);
01257 #endif
01258 res = dbg->de_reloc_name(dbg, DEBUG_FRAME,
01259
01260
01261 cur_off + 2 * uwordb_size +
01262 extension_size + 2 * upointer_size + afl_length,
01263 curfde->fde_exception_table_symbol,
01264 dwarf_drt_segment_rel,
01265 size);
01266 if (res != DW_DLV_OK) {
01267 DWARF_P_DBG_ERROR(dbg, DW_DLE_CHUNK_ALLOC, -1);
01268 }
01269 }
01270
01271
01272 pad = (int) PADDING(fde_length, upointer_size);
01273 fde_length += pad;
01274
01275
01276
01277 GET_CHUNK(dbg, elfsectno, data, fde_length + uwordb_size +
01278 extension_size, error);
01279 fde_start_point = data;
01280 du = fde_length;
01281 {
01282 if (extension_size) {
01283 Dwarf_Word x = DISTINGUISHED_VALUE;
01284
01285 WRITE_UNALIGNED(dbg, (void *) data,
01286 (const void *) &x,
01287 sizeof(x), extension_size);
01288 data += extension_size;
01289 }
01290
01291 WRITE_UNALIGNED(dbg, (void *) data,
01292 (const void *) &du,
01293 sizeof(du), uwordb_size);
01294 data += uwordb_size;
01295
01296
01297 du = cie_offs[curfde->fde_cie - 1];
01298 WRITE_UNALIGNED(dbg, (void *) data,
01299 (const void *) &du,
01300 sizeof(du), uwordb_size);
01301 data += uwordb_size;
01302
01303 du = curfde->fde_initloc;
01304 WRITE_UNALIGNED(dbg, (void *) data,
01305 (const void *) &du,
01306 sizeof(du), upointer_size);
01307 data += upointer_size;
01308
01309 if (dbg->de_reloc_pair &&
01310 curfde->fde_end_symbol != 0 &&
01311 curfde->fde_addr_range == 0) {
01312
01313
01314
01315 Dwarf_Unsigned val;
01316
01317
01318
01319 val = curfde->fde_end_symbol_offset -
01320 curfde->fde_initloc;
01321 WRITE_UNALIGNED(dbg, data,
01322 (const void *) &val,
01323 sizeof(val), upointer_size);
01324 data += upointer_size;
01325 } else {
01326
01327 du = curfde->fde_addr_range;
01328 WRITE_UNALIGNED(dbg, (void *) data,
01329 (const void *) &du,
01330 sizeof(du), upointer_size);
01331 data += upointer_size;
01332 }
01333 }
01334
01335 if (v0_augmentation) {
01336 int size;
01337 #ifdef TARG_X8664
01338 size = upointer_size;
01339 #else
01340 size = sizeof(Dwarf_sfixed);
01341 #endif
01342
01343 memcpy((void *) data, (const void *) afl_buff, afl_length);
01344 data += afl_length;
01345
01346 dsw =
01347 (Dwarf_sfixed) curfde->fde_offset_into_exception_tables;
01348 if (dsw == -1)
01349 dsw = 0;
01350 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &dsw,
01351 sizeof(dsw), size);
01352 data += size;
01353 }
01354
01355 curinst = curfde->fde_inst;
01356 while (curinst) {
01357 db = curinst->dfp_opcode;
01358 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
01359 sizeof(db), sizeof(Dwarf_Ubyte));
01360 data += sizeof(Dwarf_Ubyte);
01361 if (DW_CFA_advance_loc4 == db) {
01362 res = dbg->de_reloc_pair(dbg,
01363 DEBUG_FRAME,
01364 (data-fde_start_point) +
01365 cur_off,
01366 #ifdef TARG_IA64
01367 *(unsigned short *)(&curinst->dfp_args[0]),
01368 *(unsigned short *)(&curinst->dfp_args[2]),
01369 #else
01370 *(Dwarf_Unsigned *)(curinst->dfp_args),
01371 *(Dwarf_Unsigned *)(curinst->dfp_args
01372 + sizeof(Dwarf_Unsigned)),
01373 #endif
01374 dwarf_drt_first_of_length_pair,
01375 uwordb_size);
01376 if (res != DW_DLV_OK) {
01377 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
01378 return 0;
01379 }
01380 }
01381 #if 0
01382 if (curinst->dfp_sym_index) {
01383 int res;
01384
01385 res = dbg->de_reloc_name(dbg,
01386 DEBUG_FRAME,
01387 (data - fde_start_point)
01388 + cur_off + uwordb_size,
01389
01390 curinst->dfp_sym_index,
01391 dwarf_drt_data_reloc,
01392 upointer_size);
01393 if (res != DW_DLV_OK) {
01394 {
01395 _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
01396 return (0);
01397 }
01398 }
01399 }
01400 #endif
01401 if (DW_CFA_advance_loc4 == db) {
01402 data[0] = 0;
01403 data[1] = 0;
01404 data[2] = 0;
01405 data[3] = 0;
01406 } else {
01407 memcpy((void *) data,
01408 (const void *) curinst->dfp_args,
01409 curinst->dfp_nbytes);
01410 }
01411 data += curinst->dfp_nbytes;
01412 curinst = curinst->dfp_next;
01413 }
01414
01415 for (i = 0; i < pad; i++) {
01416 *data = DW_CFA_nop;
01417 data++;
01418 }
01419 cur_off += fde_length + uwordb_size;
01420 curfde = curfde->fde_next;
01421 }
01422
01423
01424 return (int) dbg->de_n_debug_sect;
01425 }
01426
01427
01428
01429
01430
01431
01432 static int
01433 _dwarf_pro_generate_debuginfo(Dwarf_P_Debug dbg, Dwarf_Error * error)
01434 {
01435 int elfsectno_of_debug_info;
01436 int abbrevsectno;
01437 unsigned char *data;
01438 #ifdef KEY
01439 int upointer_size = dbg->de_pointer_size;
01440 char *module_name;
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453 unsigned count_imported_decls = 0;
01454 # define ADJUSTED_DIE_OFF (die_off - count_imported_decls * upointer_size)
01455 #endif
01456 int cu_header_size;
01457 Dwarf_P_Abbrev curabbrev, abbrev_head, abbrev_tail;
01458 Dwarf_P_Die curdie;
01459 Dwarf_P_Die first_child;
01460 Dwarf_Word dw;
01461 Dwarf_Unsigned du;
01462 Dwarf_Half dh;
01463 Dwarf_Ubyte db;
01464 Dwarf_Half version;
01465 Dwarf_Unsigned die_off;
01466 int n_abbrevs;
01467 int res;
01468
01469 Dwarf_Small *start_info_sec;
01470
01471 int uword_size = dbg->de_offset_size;
01472 int extension_size = dbg->de_64bit_extension ? 4 : 0;
01473
01474 abbrev_head = abbrev_tail = NULL;
01475 elfsectno_of_debug_info = dbg->de_elf_sects[DEBUG_INFO];
01476
01477
01478 cu_header_size = extension_size + uword_size +
01479
01480
01481 sizeof(Dwarf_Half) +
01482 uword_size +
01483 sizeof(Dwarf_Ubyte);
01484 GET_CHUNK(dbg, elfsectno_of_debug_info, data, cu_header_size,
01485 error);
01486 start_info_sec = data;
01487 if (extension_size) {
01488 du = DISTINGUISHED_VALUE;
01489 WRITE_UNALIGNED(dbg, (void *) data,
01490 (const void *) &du, sizeof(du), extension_size);
01491 data += extension_size;
01492 }
01493 du = 0;
01494
01495
01496 WRITE_UNALIGNED(dbg, (void *) data,
01497 (const void *) &du, sizeof(du), uword_size);
01498 data += uword_size;
01499
01500 version = CURRENT_VERSION_STAMP;
01501
01502 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &version,
01503 sizeof(version), sizeof(Dwarf_Half));
01504 data += sizeof(Dwarf_Half);
01505
01506 du = 0;
01507
01508 WRITE_UNALIGNED(dbg, (void *) data,
01509 (const void *) &du, sizeof(du), uword_size);
01510 data += uword_size;
01511
01512
01513 db = dbg->de_pointer_size;
01514
01515 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
01516 sizeof(db), 1);
01517
01518
01519
01520
01521
01522
01523 curdie = dbg->de_dies;
01524
01525
01526 if (dbg->de_first_macinfo != NULL) {
01527 if (_dwarf_pro_add_AT_macro_info(dbg, curdie, 0, error) < 0)
01528 return -1;
01529 }
01530
01531
01532 if (dwarf_need_debug_line_section(dbg) == TRUE)
01533 if (_dwarf_pro_add_AT_stmt_list(dbg, curdie, error) < 0)
01534 return -1;
01535
01536 die_off = cu_header_size;
01537
01538 #if defined(BUILD_OS_DARWIN)
01539
01540 #else
01541
01542
01543
01544 res = dbg->de_reloc_name(dbg, DEBUG_INFO, extension_size + uword_size + sizeof(Dwarf_Half),
01545
01546 dbg->de_sect_name_idx[DEBUG_ABBREV],
01547 dwarf_drt_data_reloc, uword_size);
01548 if (res != DW_DLV_OK) {
01549 DWARF_P_DBG_ERROR(dbg, DW_DLE_REL_ALLOC, -1);
01550 }
01551 #endif
01552
01553
01554
01555 first_child = curdie->di_child;
01556 while (first_child && first_child->di_right) {
01557 if (first_child->di_child)
01558 dwarf_add_AT_reference(dbg,
01559 first_child,
01560 DW_AT_sibling,
01561 first_child->di_right, error);
01562 first_child = first_child->di_right;
01563 }
01564
01565
01566 while (curdie != NULL) {
01567 int nbytes;
01568 Dwarf_P_Attribute curattr;
01569 char *space;
01570 int res;
01571 char buff1[ENCODE_SPACE_NEEDED];
01572
01573 curdie->di_offset = die_off;
01574 curabbrev = _dwarf_pro_getabbrev(curdie, abbrev_head);
01575 if (curabbrev == NULL) {
01576 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01577 }
01578 if (abbrev_head == NULL) {
01579 n_abbrevs = 1;
01580 curabbrev->abb_idx = n_abbrevs;
01581 abbrev_tail = abbrev_head = curabbrev;
01582 } else {
01583
01584 if (curabbrev->abb_idx == 0) {
01585 n_abbrevs++;
01586 curabbrev->abb_idx = n_abbrevs;
01587 abbrev_tail->abb_next = curabbrev;
01588 abbrev_tail = curabbrev;
01589 }
01590 }
01591 #ifdef KEY
01592 if (curabbrev->abb_tag == DW_TAG_module) {
01593 res = dbg->de_reloc_pair(dbg,
01594 DEBUG_INFO,
01595 ADJUSTED_DIE_OFF,
01596 dbg->de_sect_name_idx[DEBUG_INFO],
01597 0,
01598 dwarf_drt_module,
01599 uword_size);
01600 if (res != DW_DLV_OK) {
01601 DWARF_P_DBG_ERROR(dbg,DW_DLE_REL_ALLOC, -1);
01602 }
01603 }
01604 #endif
01605 res = _dwarf_pro_encode_leb128_nm(curabbrev->abb_idx,
01606 &nbytes,
01607 buff1, sizeof(buff1));
01608 if (res != DW_DLV_OK) {
01609 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01610 }
01611 space = _dwarf_p_get_alloc(dbg, nbytes);
01612 if (space == NULL) {
01613 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01614 }
01615 memcpy(space, buff1, nbytes);
01616 curdie->di_abbrev = space;
01617 curdie->di_abbrev_nbytes = nbytes;
01618 die_off += nbytes;
01619 curattr = curdie->di_attrs;
01620 #ifdef KEY
01621
01622 if (curabbrev->abb_tag == DW_TAG_imported_declaration)
01623 module_name = curattr->ar_data;
01624 #endif
01625 #if defined(BUILD_OS_DARWIN)
01626 int skip_stmt_list = 0;
01627 #endif
01628 while (curattr) {
01629 if (curattr->ar_rel_type != R_MIPS_NONE) {
01630 switch (curattr->ar_attribute) {
01631 case DW_AT_stmt_list:
01632 #if defined(BUILD_OS_DARWIN)
01633 skip_stmt_list = 1;
01634 #else
01635 curattr->ar_rel_symidx =
01636 dbg->de_sect_name_idx[DEBUG_LINE];
01637 #endif
01638 break;
01639 case DW_AT_MIPS_fde:
01640 curattr->ar_rel_symidx =
01641 dbg->de_sect_name_idx[DEBUG_FRAME];
01642 break;
01643 case DW_AT_macro_info:
01644 curattr->ar_rel_symidx =
01645 dbg->de_sect_name_idx[DEBUG_MACINFO];
01646 break;
01647 default:
01648 break;
01649 }
01650 #if defined(BUILD_OS_DARWIN)
01651 if (!skip_stmt_list) {
01652 #endif
01653 res = dbg->de_reloc_name(dbg, DEBUG_INFO,
01654 #ifdef KEY
01655 ADJUSTED_DIE_OFF + curattr->ar_rel_offset,
01656 #else
01657 die_off + curattr->ar_rel_offset,
01658 #endif
01659 curattr->ar_rel_symidx,
01660 dwarf_drt_data_reloc,
01661 curattr->ar_reloc_len);
01662
01663 if (res != DW_DLV_OK) {
01664 DWARF_P_DBG_ERROR(dbg, DW_DLE_REL_ALLOC, -1);
01665 }
01666 #if defined(BUILD_OS_DARWIN)
01667 }
01668 #endif
01669
01670 }
01671 die_off += curattr->ar_nbytes;
01672 curattr = curattr->ar_next;
01673 }
01674 #ifdef KEY
01675 if (curabbrev->abb_tag == DW_TAG_imported_declaration) {
01676
01677
01678
01679
01680
01681
01682 res = dbg->de_reloc_pair(dbg,
01683 DEBUG_INFO,
01684 ADJUSTED_DIE_OFF,
01685 dbg->de_sect_name_idx[DEBUG_INFO],
01686 0,
01687 dwarf_drt_imported_declaration,
01688 strlen(module_name));
01689 if (res != DW_DLV_OK) {
01690 DWARF_P_DBG_ERROR(dbg,DW_DLE_REL_ALLOC, -1);
01691 }
01692
01693
01694
01695 die_off += upointer_size;
01696 count_imported_decls += 1;
01697 }
01698 #endif
01699
01700 if (curdie->di_child)
01701 curdie = curdie->di_child;
01702 else {
01703 while (curdie != NULL && curdie->di_right == NULL) {
01704 curdie = curdie->di_parent;
01705 die_off++;
01706
01707 }
01708 if (curdie != NULL)
01709 curdie = curdie->di_right;
01710 }
01711 }
01712
01713
01714
01715 curdie = dbg->de_dies;
01716 while (curdie != NULL) {
01717 Dwarf_P_Attribute curattr;
01718
01719
01720 GET_CHUNK(dbg, elfsectno_of_debug_info,
01721 data, curdie->di_abbrev_nbytes, error);
01722
01723 memcpy((void *) data,
01724 (const void *) curdie->di_abbrev,
01725 curdie->di_abbrev_nbytes);
01726
01727
01728 curattr = curdie->di_attrs;
01729 while (curattr) {
01730 GET_CHUNK(dbg, elfsectno_of_debug_info, data,
01731 (unsigned long) curattr->ar_nbytes, error);
01732 switch (curattr->ar_attribute_form) {
01733 case DW_FORM_ref1:
01734 {
01735 if (curattr->ar_ref_die->di_offset >
01736 (unsigned) 0xff) {
01737 DWARF_P_DBG_ERROR(dbg, DW_DLE_OFFSET_UFLW, -1);
01738 }
01739 db = curattr->ar_ref_die->di_offset;
01740 WRITE_UNALIGNED(dbg, (void *) data,
01741 (const void *) &db,
01742 sizeof(db), sizeof(Dwarf_Ubyte));
01743 break;
01744 }
01745 case DW_FORM_ref2:
01746 {
01747 if (curattr->ar_ref_die->di_offset >
01748 (unsigned) 0xffff) {
01749 DWARF_P_DBG_ERROR(dbg, DW_DLE_OFFSET_UFLW, -1);
01750 }
01751 dh = curattr->ar_ref_die->di_offset;
01752 WRITE_UNALIGNED(dbg, (void *) data,
01753 (const void *) &dh,
01754 sizeof(dh), sizeof(Dwarf_Half));
01755 break;
01756 }
01757 case DW_FORM_ref_addr:
01758 {
01759 du = curattr->ar_ref_die->di_offset;
01760 {
01761
01762 WRITE_UNALIGNED(dbg, (void *) data,
01763 (const void *) &du,
01764 sizeof(du), uword_size);
01765 }
01766 break;
01767
01768 }
01769 case DW_FORM_ref4:
01770 {
01771 if (curattr->ar_ref_die->di_offset >
01772 (unsigned) 0xffffffff) {
01773 DWARF_P_DBG_ERROR(dbg, DW_DLE_OFFSET_UFLW, -1);
01774 }
01775 dw = (Dwarf_Word) curattr->ar_ref_die->di_offset;
01776 WRITE_UNALIGNED(dbg, (void *) data,
01777 (const void *) &dw,
01778 sizeof(dw), sizeof(Dwarf_ufixed));
01779 break;
01780 }
01781 case DW_FORM_ref8:
01782 du = curattr->ar_ref_die->di_offset;
01783 WRITE_UNALIGNED(dbg, (void *) data,
01784 (const void *) &du,
01785 sizeof(du), sizeof(Dwarf_Unsigned));
01786 break;
01787 case DW_FORM_ref_udata:
01788 {
01789
01790 int nbytes;
01791 char buff1[ENCODE_SPACE_NEEDED];
01792
01793 res =
01794 _dwarf_pro_encode_leb128_nm(curattr->
01795 ar_ref_die->
01796 di_offset, &nbytes,
01797 buff1,
01798 sizeof(buff1));
01799 if (res != DW_DLV_OK) {
01800 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01801 }
01802
01803 memcpy(data, buff1, nbytes);
01804 break;
01805 }
01806 default:
01807 memcpy((void *) data,
01808 (const void *) curattr->ar_data,
01809 curattr->ar_nbytes);
01810 break;
01811 }
01812 curattr = curattr->ar_next;
01813 }
01814
01815
01816 if (curdie->di_child)
01817 curdie = curdie->di_child;
01818 else {
01819 while (curdie != NULL && curdie->di_right == NULL) {
01820 GET_CHUNK(dbg, elfsectno_of_debug_info, data, 1, error);
01821 *data = '\0';
01822 curdie = curdie->di_parent;
01823 }
01824 if (curdie != NULL)
01825 curdie = curdie->di_right;
01826 }
01827 }
01828
01829
01830
01831 du = die_off - uword_size - extension_size;
01832 WRITE_UNALIGNED(dbg, (void *) (start_info_sec + extension_size),
01833 (const void *) &du, sizeof(du), uword_size);
01834
01835
01836 data = 0;
01837
01838
01839 abbrevsectno = dbg->de_elf_sects[DEBUG_ABBREV];
01840
01841 curabbrev = abbrev_head;
01842 while (curabbrev) {
01843 char *val;
01844 int nbytes;
01845 int idx;
01846 int res;
01847 char buff1[ENCODE_SPACE_NEEDED];
01848
01849 res = _dwarf_pro_encode_leb128_nm(curabbrev->abb_idx, &nbytes,
01850 buff1, sizeof(buff1));
01851 if (res != DW_DLV_OK) {
01852 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01853 }
01854
01855 GET_CHUNK(dbg, abbrevsectno, data, nbytes, error);
01856 val = buff1;
01857 memcpy((void *) data, (const void *) val, nbytes);
01858 res = _dwarf_pro_encode_leb128_nm(curabbrev->abb_tag, &nbytes,
01859 buff1, sizeof(buff1));
01860 if (res != DW_DLV_OK) {
01861 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01862 }
01863 val = buff1;
01864 GET_CHUNK(dbg, abbrevsectno, data, nbytes, error);
01865 memcpy((void *) data, (const void *) val, nbytes);
01866 db = curabbrev->abb_children;
01867 GET_CHUNK(dbg, abbrevsectno, data, sizeof(Dwarf_Ubyte), error);
01868 WRITE_UNALIGNED(dbg, (void *) data, (const void *) &db,
01869 sizeof(db), sizeof(Dwarf_Ubyte));
01870
01871
01872 for (idx = 0; idx < curabbrev->abb_n_attr; idx++) {
01873 res = _dwarf_pro_encode_leb128_nm(curabbrev->abb_attrs[idx],
01874 &nbytes,
01875 buff1, sizeof(buff1));
01876 if (res != DW_DLV_OK) {
01877 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01878 }
01879 val = buff1;
01880 GET_CHUNK(dbg, abbrevsectno, data, nbytes, error);
01881 memcpy((void *) data, (const void *) val, nbytes);
01882 res = _dwarf_pro_encode_leb128_nm(curabbrev->abb_forms[idx],
01883 &nbytes,
01884 buff1, sizeof(buff1));
01885 if (res != DW_DLV_OK) {
01886 DWARF_P_DBG_ERROR(dbg, DW_DLE_ABBREV_ALLOC, -1);
01887 }
01888 val = buff1;
01889 GET_CHUNK(dbg, abbrevsectno, data, nbytes, error);
01890 memcpy((void *) data, (const void *) val, nbytes);
01891 }
01892 #ifndef KEY
01893 GET_CHUNK(dbg,abbrevsectno,data,2,error);
01894
01895 *data = 0;
01896 data++;
01897 *data = 0;
01898 #else
01899
01900 if (curabbrev->abb_tag == DW_TAG_imported_declaration) {
01901 res = _dwarf_pro_encode_leb128_nm(DW_AT_import,
01902 &nbytes,
01903 buff1,sizeof(buff1));
01904 if (res != DW_DLV_OK) {
01905 DWARF_P_DBG_ERROR(dbg,DW_DLE_ABBREV_ALLOC, -1);
01906 }
01907 val = buff1;
01908 GET_CHUNK(dbg,abbrevsectno,data,nbytes,error);
01909 memcpy((void *)data,(const void *)val, nbytes);
01910 res = _dwarf_pro_encode_leb128_nm(DW_FORM_ref_addr,
01911 &nbytes,
01912 buff1,sizeof(buff1));
01913 if (res != DW_DLV_OK) {
01914 DWARF_P_DBG_ERROR(dbg,DW_DLE_ABBREV_ALLOC, -1);
01915 }
01916 val = buff1;
01917 GET_CHUNK(dbg,abbrevsectno,data,nbytes,error);
01918 memcpy((void *)data,(const void *)val, nbytes);
01919 }
01920
01921
01922
01923
01924
01925
01926
01927 if (curabbrev->abb_next) {
01928 GET_CHUNK(dbg,abbrevsectno,data,2,error);
01929
01930 *data = 0;
01931 data++;
01932 *data = 0;
01933 } else {
01934 GET_CHUNK(dbg,abbrevsectno,data,3,error);
01935
01936
01937 *data = 0;
01938 data++;
01939 *data = 0;
01940 data++;
01941 *data = 0;
01942 }
01943 #endif
01944
01945 curabbrev = curabbrev->abb_next;
01946 }
01947
01948 GET_CHUNK(dbg,abbrevsectno,data,1,error);
01949
01950 *data = 0;
01951
01952
01953 return (int) dbg->de_n_debug_sect;
01954 }
01955
01956
01957
01958
01959
01960
01961
01962
01963 Dwarf_Ptr
01964 dwarf_get_section_bytes(Dwarf_P_Debug dbg,
01965 Dwarf_Signed dwarf_section,
01966 Dwarf_Signed * section_idx,
01967 Dwarf_Unsigned * length, Dwarf_Error * error)
01968 {
01969 Dwarf_Ptr buf;
01970
01971 if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
01972 DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, NULL);
01973 }
01974
01975 if (dbg->de_debug_sects == 0) {
01976
01977 return NULL;
01978 }
01979 if (dbg->de_debug_sects->ds_elf_sect_no == MAGIC_SECT_NO) {
01980
01981 return NULL;
01982 }
01983 *section_idx = dbg->de_debug_sects->ds_elf_sect_no;
01984 *length = dbg->de_debug_sects->ds_nbytes;
01985
01986 buf = (Dwarf_Ptr *) dbg->de_debug_sects->ds_data;
01987
01988 dbg->de_debug_sects = dbg->de_debug_sects->ds_next;
01989
01990
01991
01992
01993 return buf;
01994 }
01995
01996
01997
01998
01999 void
02000 dwarf_reset_section_bytes(Dwarf_P_Debug dbg)
02001 {
02002 dbg->de_debug_sects = dbg->de_first_debug_sect;
02003
02004
02005 dbg->de_reloc_next_to_return = 0;
02006 }
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021 Dwarf_Small *
02022 _dwarf_pro_buffer(Dwarf_P_Debug dbg,
02023 int elfsectno, unsigned long nbytes)
02024 {
02025 Dwarf_P_Section_Data cursect;
02026
02027
02028 cursect = dbg->de_current_active_section;
02029
02030
02031
02032 if ((cursect->ds_elf_sect_no != elfsectno) ||
02033 ((cursect->ds_nbytes + nbytes) > cursect->ds_orig_alloc)
02034 ) {
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044 unsigned long space = nbytes;
02045
02046 if (nbytes < CHUNK_SIZE)
02047 space = CHUNK_SIZE;
02048
02049 cursect = (Dwarf_P_Section_Data)
02050 _dwarf_p_get_alloc(dbg,
02051 sizeof(struct Dwarf_P_Section_Data_s)
02052 + space);
02053
02054
02055 if (cursect == NULL)
02056 return (NULL);
02057
02058
02059
02060 cursect->ds_data = (char *) cursect +
02061 sizeof(struct Dwarf_P_Section_Data_s);
02062 cursect->ds_orig_alloc = space;
02063 cursect->ds_elf_sect_no = elfsectno;
02064 cursect->ds_nbytes = nbytes;
02065
02066
02067
02068
02069
02070
02071 if (dbg->de_debug_sects->ds_elf_sect_no == MAGIC_SECT_NO) {
02072
02073
02074
02075 dbg->de_debug_sects = cursect;
02076 dbg->de_current_active_section = cursect;
02077 dbg->de_first_debug_sect = cursect;
02078 } else {
02079 dbg->de_current_active_section->ds_next = cursect;
02080 dbg->de_current_active_section = cursect;
02081 }
02082 dbg->de_n_debug_sect++;
02083
02084 return ((Dwarf_Small *) cursect->ds_data);
02085 }
02086
02087
02088 {
02089 Dwarf_Small *space_for_caller = (Dwarf_Small *)
02090 (cursect->ds_data + cursect->ds_nbytes);
02091
02092 cursect->ds_nbytes += nbytes;
02093 return space_for_caller;
02094 }
02095 }
02096
02097
02098
02099
02100
02101
02102 static int
02103 _dwarf_pro_get_opc(Dwarf_Unsigned addr_adv, int line_adv)
02104 {
02105 int opc;
02106
02107 addr_adv = addr_adv / MIN_INST_LENGTH;
02108 if (line_adv == 0 && addr_adv == 0)
02109 return OPC_INCS_ZERO;
02110 if (line_adv >= LINE_BASE && line_adv < LINE_BASE + LINE_RANGE) {
02111 opc =
02112 (line_adv - LINE_BASE) + (addr_adv * LINE_RANGE) +
02113 OPCODE_BASE;
02114 if (opc > 255)
02115 return OPC_OUT_OF_RANGE;
02116 return opc;
02117 } else
02118 return LINE_OUT_OF_RANGE;
02119 }
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129 static Dwarf_P_Abbrev
02130 _dwarf_pro_getabbrev(Dwarf_P_Die die, Dwarf_P_Abbrev head)
02131 {
02132 Dwarf_P_Abbrev curabbrev;
02133 Dwarf_P_Attribute curattr;
02134 int res1;
02135 int nattrs;
02136 int match;
02137 Dwarf_ufixed *forms = 0;
02138 Dwarf_ufixed *attrs = 0;
02139
02140 curabbrev = head;
02141 while (curabbrev) {
02142 if ((die->di_tag == curabbrev->abb_tag) &&
02143 ((die->di_child != NULL &&
02144 curabbrev->abb_children == DW_CHILDREN_yes) ||
02145 (die->di_child == NULL &&
02146 curabbrev->abb_children == DW_CHILDREN_no)) &&
02147 (die->di_n_attr == curabbrev->abb_n_attr)) {
02148
02149
02150 curattr = die->di_attrs;
02151 match = 1;
02152 while (match && curattr) {
02153 res1 = _dwarf_pro_match_attr(curattr,
02154 curabbrev,
02155 (int) curabbrev->
02156 abb_n_attr);
02157 if (res1 == 0)
02158 match = 0;
02159 curattr = curattr->ar_next;
02160 }
02161 if (match == 1)
02162 return curabbrev;
02163 }
02164 curabbrev = curabbrev->abb_next;
02165 }
02166
02167
02168 if (die->di_n_attr != 0) {
02169 forms = (Dwarf_ufixed *)
02170 _dwarf_p_get_alloc(NULL,
02171 sizeof(Dwarf_ufixed) * die->di_n_attr);
02172 if (forms == NULL)
02173 return NULL;
02174 attrs = (Dwarf_ufixed *)
02175 _dwarf_p_get_alloc(NULL,
02176 sizeof(Dwarf_ufixed) * die->di_n_attr);
02177 if (attrs == NULL)
02178 return NULL;
02179 }
02180 nattrs = 0;
02181 curattr = die->di_attrs;
02182 while (curattr) {
02183 attrs[nattrs] = curattr->ar_attribute;
02184 forms[nattrs] = curattr->ar_attribute_form;
02185 nattrs++;
02186 curattr = curattr->ar_next;
02187 }
02188
02189 curabbrev = (Dwarf_P_Abbrev)
02190 _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Abbrev_s));
02191 if (curabbrev == NULL)
02192 return NULL;
02193
02194 if (die->di_child == NULL)
02195 curabbrev->abb_children = DW_CHILDREN_no;
02196 else
02197 curabbrev->abb_children = DW_CHILDREN_yes;
02198 curabbrev->abb_tag = die->di_tag;
02199 curabbrev->abb_attrs = attrs;
02200 curabbrev->abb_forms = forms;
02201 curabbrev->abb_n_attr = die->di_n_attr;
02202 curabbrev->abb_idx = 0;
02203 curabbrev->abb_next = NULL;
02204
02205 return curabbrev;
02206 }
02207
02208
02209
02210
02211
02212 static int
02213 _dwarf_pro_match_attr(Dwarf_P_Attribute attr,
02214 Dwarf_P_Abbrev abbrev, int no_attr)
02215 {
02216 int i;
02217 int found = 0;
02218
02219 for (i = 0; i < no_attr; i++) {
02220 if (attr->ar_attribute == abbrev->abb_attrs[i] &&
02221 attr->ar_attribute_form == abbrev->abb_forms[i]) {
02222 found = 1;
02223 break;
02224 }
02225 }
02226 return found;
02227 }