1 /* vms-hdr.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
4 2007, 2008, 2009 Free Software Foundation, Inc.
6 HDR record handling functions
7 EMH record handling functions
9 EOM record handling functions
10 EEOM record handling functions
12 IHD record handling functions
13 EIHD record handling functions
15 ISD record handling functions
16 EISD record handling functions
18 IHS record handling functions
19 EIHS record handling functions
21 DBG record handling functions
22 EDBG record handling functions
24 TBT record handling functions
25 ETBT record handling functions
27 DST/DMT section handling functions
29 Written by Klaus K"ampf (kkaempf@rmi.de)
31 This program is free software; you can redistribute it and/or modify
32 it under the terms of the GNU General Public License as published by
33 the Free Software Foundation; either version 3 of the License, or
34 (at your option) any later version.
36 This program is distributed in the hope that it will be useful,
37 but WITHOUT ANY WARRANTY; without even the implied warranty of
38 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 GNU General Public License for more details.
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
44 MA 02110-1301, USA. */
50 #include "safe-ctype.h"
55 static struct module
*new_module (bfd
*);
56 static void parse_module
57 (bfd
*, struct module
*, unsigned char *, unsigned int);
58 static struct module
*build_module_list (bfd
*);
59 static bfd_boolean module_find_nearest_line
60 (bfd
*, struct module
*, bfd_vma
, const char **, const char **,
62 static int vms_slurp_debug (bfd
*);
64 #define SET_MODULE_PARSED(m) \
65 do { if ((m)->name == NULL) (m)->name = ""; } while (0)
66 #define IS_MODULE_PARSED(m) ((m)->name != NULL)
69 /* Read & process emh record
70 return 0 on success, -1 on error. */
73 _bfd_vms_slurp_hdr (bfd
*abfd
, int objtype
)
76 unsigned char *vms_rec
;
79 vms_rec
= PRIV(vms_rec
);
82 vms_debug(2, "HDR/EMH\n");
91 subtype
= bfd_getl16 (vms_rec
+ 4) + EVAX_OFFSET
;
98 vms_debug(3, "subtype %d\n", subtype
);
105 PRIV (hdr_data
).hdr_b_strlvl
= vms_rec
[2];
106 PRIV (hdr_data
).hdr_l_recsiz
= bfd_getl16 (vms_rec
+ 3);
107 PRIV (hdr_data
).hdr_t_name
= _bfd_vms_save_counted_string (vms_rec
+ 5);
108 ptr
= vms_rec
+ 5 + vms_rec
[5] + 1;
109 PRIV (hdr_data
).hdr_t_version
= _bfd_vms_save_counted_string (ptr
);
111 PRIV (hdr_data
).hdr_t_date
= _bfd_vms_save_sized_string (ptr
, 17);
115 PRIV (hdr_data
).hdr_c_lnm
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 2));
119 PRIV (hdr_data
).hdr_c_src
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 2));
123 PRIV (hdr_data
).hdr_c_ttl
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 2));
126 case EMH_S_C_MHD
+ EVAX_OFFSET
:
128 PRIV (hdr_data
).hdr_b_strlvl
= vms_rec
[6];
129 PRIV (hdr_data
).hdr_l_arch1
= bfd_getl32 (vms_rec
+ 8);
130 PRIV (hdr_data
).hdr_l_arch2
= bfd_getl32 (vms_rec
+ 12);
131 PRIV (hdr_data
).hdr_l_recsiz
= bfd_getl32 (vms_rec
+ 16);
132 PRIV (hdr_data
).hdr_t_name
= _bfd_vms_save_counted_string (vms_rec
+ 20);
133 ptr
= vms_rec
+ 20 + vms_rec
[20] + 1;
134 PRIV (hdr_data
).hdr_t_version
=_bfd_vms_save_counted_string (ptr
);
136 PRIV (hdr_data
).hdr_t_date
= _bfd_vms_save_sized_string (ptr
, 17);
139 case EMH_S_C_LNM
+ EVAX_OFFSET
:
140 PRIV (hdr_data
).hdr_c_lnm
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 6));
143 case EMH_S_C_SRC
+ EVAX_OFFSET
:
144 PRIV (hdr_data
).hdr_c_src
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 6));
147 case EMH_S_C_TTL
+ EVAX_OFFSET
:
148 PRIV (hdr_data
).hdr_c_ttl
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_size
- 6));
154 case EMH_S_C_CPR
+ EVAX_OFFSET
:
155 case EMH_S_C_MTC
+ EVAX_OFFSET
:
156 case EMH_S_C_GTX
+ EVAX_OFFSET
:
160 bfd_set_error (bfd_error_wrong_format
);
167 /* Output routines. */
169 /* Manufacture a VMS like time on a unix based system.
170 stolen from obj-vms.c. */
172 static unsigned char *
173 get_vms_time_string (void)
175 static unsigned char tbuf
[18];
183 pnt
= ctime (&timeb
);
189 sprintf ((char *) tbuf
, "%2s-%3s-%s %s",
190 pnt
+ 8, pnt
+ 4, pnt
+ 20, pnt
+ 11);
198 Descriptor
.Size
= 17;
199 Descriptor
.Ptr
= tbuf
;
200 SYS$
ASCTIM (0, &Descriptor
, 0, 0);
204 vms_debug (6, "vmstimestring:'%s'\n", tbuf
);
210 /* Write object header for bfd abfd. */
213 _bfd_vms_write_hdr (bfd
*abfd
, int objtype
)
222 vms_debug (2, "vms_write_hdr (%p)\n", abfd
);
225 _bfd_vms_output_alignment (abfd
, 2);
228 if (objtype
!= OBJ_S_C_HDR
)
230 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_MHD
);
231 _bfd_vms_output_short (abfd
, EOBJ_S_C_STRLVL
);
232 _bfd_vms_output_long (abfd
, 0);
233 _bfd_vms_output_long (abfd
, 0);
234 _bfd_vms_output_long (abfd
, MAX_OUTREC_SIZE
);
237 /* Create module name from filename. */
238 if (bfd_get_filename (abfd
) != 0)
240 char *module
= vms_get_module_name (bfd_get_filename (abfd
), TRUE
);
241 _bfd_vms_output_counted (abfd
, module
);
245 _bfd_vms_output_counted (abfd
, "NONAME");
247 _bfd_vms_output_counted (abfd
, BFD_VERSION_STRING
);
248 _bfd_vms_output_dump (abfd
, get_vms_time_string (), EMH_DATE_LENGTH
);
249 _bfd_vms_output_fill (abfd
, 0, EMH_DATE_LENGTH
);
250 _bfd_vms_output_flush (abfd
);
253 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_LNM
);
254 snprintf (version
, sizeof (version
), "GAS BFD v%s", BFD_VERSION_STRING
);
255 _bfd_vms_output_dump (abfd
, (unsigned char *)version
, strlen (version
));
256 _bfd_vms_output_flush (abfd
);
259 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_SRC
);
261 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
263 symbol
= abfd
->outsymbols
[symnum
];
265 if (symbol
->flags
& BSF_FILE
)
267 if (CONST_STRNEQ ((char *)symbol
->name
, "<CASE:"))
269 PRIV (flag_hash_long_names
) = symbol
->name
[6] - '0';
270 PRIV (flag_show_after_trunc
) = symbol
->name
[7] - '0';
278 _bfd_vms_output_dump (abfd
, (unsigned char *) symbol
->name
,
279 (int) strlen (symbol
->name
));
286 if (symnum
== abfd
->symcount
)
287 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("noname"));
289 _bfd_vms_output_flush (abfd
);
292 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_TTL
);
293 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("TTL"));
294 _bfd_vms_output_flush (abfd
);
297 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_CPR
);
298 _bfd_vms_output_dump (abfd
,
299 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
301 _bfd_vms_output_flush (abfd
);
306 /* Process EOM/EEOM record
307 return 0 on success, -1 on error. */
310 _bfd_vms_slurp_eom (bfd
*abfd
, int objtype
)
312 unsigned char *vms_rec
;
315 vms_debug(2, "EOM/EEOM\n");
318 vms_rec
= PRIV (vms_rec
);
320 if ((objtype
== OBJ_S_C_EOM
)
321 || (objtype
== OBJ_S_C_EOMW
))
326 PRIV (eom_data
).eom_l_total_lps
327 = bfd_getl32 (vms_rec
+ EEOM_S_L_TOTAL_LPS
);
328 PRIV (eom_data
).eom_w_comcod
= bfd_getl16 (vms_rec
+ EEOM_S_W_COMCOD
);
329 if (PRIV (eom_data
).eom_w_comcod
> 1)
331 (*_bfd_error_handler
) (_("Object module NOT error-free !\n"));
332 bfd_set_error (bfd_error_bad_value
);
335 PRIV (eom_data
).eom_has_transfer
= FALSE
;
336 if (PRIV (rec_size
) > 10)
338 PRIV (eom_data
).eom_has_transfer
= TRUE
;
339 PRIV (eom_data
).eom_b_tfrflg
= vms_rec
[EEOM_S_B_TFRFLG
];
340 PRIV (eom_data
).eom_l_psindx
341 = bfd_getl32 (vms_rec
+ EEOM_S_L_PSINDX
);
342 PRIV (eom_data
).eom_l_tfradr
343 = bfd_getl32 (vms_rec
+ EEOM_S_L_TFRADR
);
345 abfd
->start_address
= PRIV (eom_data
).eom_l_tfradr
;
351 /* Write eom record for bfd abfd. */
354 _bfd_vms_write_eom (bfd
*abfd
, int objtype
)
357 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd
, objtype
);
360 _bfd_vms_output_begin (abfd
, objtype
, -1);
361 _bfd_vms_output_long (abfd
, (unsigned long) (PRIV (vms_linkage_index
) >> 1));
362 _bfd_vms_output_byte (abfd
, 0); /* Completion code. */
363 _bfd_vms_output_byte (abfd
, 0); /* Fill byte. */
365 if (bfd_get_start_address (abfd
) != (bfd_vma
)-1)
369 section
= bfd_get_section_by_name (abfd
, ".link");
372 bfd_set_error (bfd_error_nonrepresentable_section
);
375 _bfd_vms_output_short (abfd
, 0);
376 _bfd_vms_output_long (abfd
, (unsigned long) (section
->index
));
377 _bfd_vms_output_long (abfd
,
378 (unsigned long) bfd_get_start_address (abfd
));
379 _bfd_vms_output_long (abfd
, 0);
382 _bfd_vms_output_end (abfd
);
386 /* Read & process IHD/EIHD record.
387 Return 0 on success, -1 on error */
389 _bfd_vms_slurp_ihd (bfd
*abfd
, unsigned int *isd_offset
,
390 unsigned int *ihs_offset
)
392 unsigned int imgtype
, size
;
396 vms_debug (8, "_bfd_vms_slurp_ihd\n");
399 size
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SIZE
);
400 imgtype
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_IMGTYPE
);
402 if (imgtype
== EIHD_S_K_EXE
)
403 abfd
->flags
|= EXEC_P
;
405 symvva
= bfd_getl64 (PRIV (vms_rec
) + EIHD_S_Q_SYMVVA
);
408 PRIV (symvva
) = symvva
;
409 abfd
->flags
|= DYNAMIC
;
412 *isd_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_ISDOFF
);
413 *ihs_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SYMDBGOFF
);
416 vms_debug (4, "EIHD record size %d imgtype %d symvva 0x%llx isd %d ihs %d\n",
417 size
, imgtype
, symvva
, *isd_offset
, *ihs_offset
);
423 /* Read & process ISD/EISD record
424 return 0 on success, -1 on error */
427 _bfd_vms_slurp_isd (bfd
*abfd
, unsigned int offset
)
429 int section_count
= 0;
431 unsigned int rec_size
;
434 vms_debug (8, "_bfd_vms_slurp_isd\n");
437 for (p
= PRIV (vms_rec
) + offset
;
438 (rec_size
= bfd_getl32 (p
+ EISD_S_L_EISDSIZE
)) != 0;
441 unsigned long long vaddr
= bfd_getl64 (p
+ EISD_S_Q_VIR_ADDR
);
442 unsigned int size
= bfd_getl32 (p
+ EISD_S_L_SECSIZE
);
443 unsigned int flags
= bfd_getl32 (p
+ EISD_S_L_FLAGS
);
444 unsigned int vbn
= bfd_getl32 (p
+ EISD_S_L_VBN
);
450 vms_debug (4, "EISD record at 0x%x size 0x%x addr 0x%x bfd_flags 0x%x block %d\n",
451 p
- PRIV (vms_rec
), size
, vaddr
, flags
, vbn
);
454 /* VMS combines psects from .obj files into isects in the .exe. This
455 process doesn't preserve enough information to reliably determine
456 what's in each section without examining the data. This is
457 especially true of DWARF debug sections. */
458 bfd_flags
= SEC_ALLOC
;
460 if (flags
& EISD_S_M_EXE
)
461 bfd_flags
|= SEC_CODE
| SEC_HAS_CONTENTS
| SEC_LOAD
;
463 if (flags
& EISD_S_M_NONSHRADR
)
464 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
466 if (!(flags
& EISD_S_M_WRT
))
467 bfd_flags
|= SEC_READONLY
;
469 if (flags
& EISD_S_M_DZRO
)
470 bfd_flags
|= SEC_DATA
;
472 if (flags
& EISD_S_M_FIXUPVEC
)
473 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
475 if (flags
& EISD_S_M_CRF
)
476 bfd_flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
;
478 if (flags
& EISD_S_M_GBL
)
480 name
= _bfd_vms_save_counted_string (p
+ EISD_S_T_GBLNAM
);
481 bfd_flags
|= SEC_COFF_SHARED_LIBRARY
;
482 bfd_flags
&= ~(SEC_ALLOC
| SEC_LOAD
);
486 name
= (char*) bfd_alloc (abfd
, 32);
487 sprintf (name
, "$LOCAL_%03d$", section_count
++);
490 section
= bfd_make_section (abfd
, name
);
495 section
->filepos
= vbn
? VMS_BLOCK_SIZE
* (vbn
- 1) : (unsigned int)-1;
496 section
->size
= size
;
497 section
->vma
= vaddr
;
499 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
506 /* Read & process IHS/EIHS record
507 return 0 on success, -1 on error */
509 _bfd_vms_slurp_ihs (bfd
*abfd
, unsigned int offset
)
511 unsigned char *p
= PRIV (vms_rec
) + offset
;
512 unsigned int gstvbn
= bfd_getl32 (p
+ EIHS_S_L_GSTVBN
);
513 unsigned int gstsize ATTRIBUTE_UNUSED
= bfd_getl32 (p
+ EIHS_S_L_GSTSIZE
);
514 unsigned int dstvbn
= bfd_getl32 (p
+ EIHS_S_L_DSTVBN
);
515 unsigned int dstsize
= bfd_getl32 (p
+ EIHS_S_L_DSTSIZE
);
516 unsigned int dmtvbn
= bfd_getl32 (p
+ EIHS_S_L_DMTVBN
);
517 unsigned int dmtbytes
= bfd_getl32 (p
+ EIHS_S_L_DMTBYTES
);
521 vms_debug (8, "_bfd_vms_slurp_ihs\n");
522 vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
523 gstvbn
, gstsize
, dstvbn
, dstsize
, dmtvbn
, dmtbytes
);
528 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
530 section
= bfd_make_section (abfd
, "$DST$");
534 section
->size
= dstsize
;
535 section
->filepos
= VMS_BLOCK_SIZE
* (dstvbn
- 1);
537 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
540 PRIV (dst_section
) = section
;
541 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
546 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
548 section
= bfd_make_section (abfd
, "$DMT$");
552 section
->size
= dmtbytes
;
553 section
->filepos
= VMS_BLOCK_SIZE
* (dmtvbn
- 1);
555 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
561 flagword bfd_flags
= SEC_HAS_CONTENTS
;
563 section
= bfd_make_section (abfd
, "$GST$");
567 if (bfd_seek (abfd
, VMS_BLOCK_SIZE
* (gstvbn
- 1), SEEK_SET
))
569 bfd_set_error (bfd_error_file_truncated
);
573 if (_bfd_vms_slurp_object_records (abfd
) != 0)
576 section
->filepos
= VMS_BLOCK_SIZE
* (gstvbn
- 1);
577 section
->size
= bfd_tell (abfd
) - section
->filepos
;
579 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
582 abfd
->flags
|= HAS_SYMS
;
588 /* Build a new module for the specified BFD. */
590 static struct module
*
591 new_module (bfd
*abfd
)
593 struct module
*module
594 = (struct module
*) bfd_zalloc (abfd
, sizeof (struct module
));
595 module
->file_table_count
= 16; /* Arbitrary. */
597 = bfd_malloc (module
->file_table_count
* sizeof (struct fileinfo
));
601 /* Parse debug info for a module and internalize it. */
604 parse_module (bfd
*abfd
, struct module
*module
, unsigned char *ptr
,
607 unsigned char *maxptr
= ptr
+ length
, *src_ptr
, *pcl_ptr
;
608 unsigned int prev_linum
= 0, curr_linenum
= 0;
609 bfd_vma prev_pc
= 0, curr_pc
= 0;
610 struct srecinfo
*curr_srec
, *srec
;
611 struct lineinfo
*curr_line
, *line
;
612 struct funcinfo
*funcinfo
;
614 /* Initialize tables with zero element. */
615 curr_srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
616 module
->srec_table
= curr_srec
;
618 curr_line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
619 module
->line_table
= curr_line
;
623 /* The first byte is not counted in the recorded length. */
624 int rec_length
= bfd_getl16 (ptr
) + 1;
625 int rec_type
= bfd_getl16 (ptr
+ 2);
628 _bfd_vms_debug (2, "DST record: length %d, type %d\n",
629 rec_length
, rec_type
);
636 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_MODBEG_NAME
);
644 _bfd_vms_debug (3, "module: %s\n", module
->name
);
650 _bfd_vms_debug (3, "end module\n");
655 funcinfo
= (struct funcinfo
*)
656 bfd_zalloc (abfd
, sizeof (struct funcinfo
));
658 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_RTNBEG_NAME
);
659 funcinfo
->low
= bfd_getl32 (ptr
+ DST_S_L_RTNBEG_ADDRESS
);
660 funcinfo
->next
= module
->func_table
;
661 module
->func_table
= funcinfo
;
664 _bfd_vms_debug (3, "routine: %s at 0x%x\n",
665 funcinfo
->name
, funcinfo
->low
);
670 module
->func_table
->high
= module
->func_table
->low
671 + bfd_getl32 (ptr
+ DST_S_L_RTNEND_SIZE
) - 1;
673 if (module
->func_table
->high
> module
->high
)
674 module
->high
= module
->func_table
->high
;
677 _bfd_vms_debug (3, "end routine\n");
683 _bfd_vms_debug (3, "prologue\n");
689 _bfd_vms_debug (3, "epilog\n");
695 _bfd_vms_debug (3, "block\n");
701 _bfd_vms_debug (3, "end block\n");
706 src_ptr
= ptr
+ DST_S_C_SOURCE_HEADER_SIZE
;
709 _bfd_vms_debug (3, "source info\n");
712 while (src_ptr
< ptr
+ rec_length
)
714 int cmd
= src_ptr
[0], cmd_length
, data
;
718 case DST_S_C_SRC_DECLFILE
:
721 = bfd_getl16 (src_ptr
+ DST_S_W_SRC_DF_FILEID
);
723 = _bfd_vms_save_counted_string (src_ptr
724 + DST_S_B_SRC_DF_FILENAME
);
726 while (fileid
>= module
->file_table_count
)
728 module
->file_table_count
*= 2;
730 = bfd_realloc (module
->file_table
,
731 module
->file_table_count
732 * sizeof (struct fileinfo
));
735 module
->file_table
[fileid
].name
= filename
;
736 module
->file_table
[fileid
].srec
= 1;
737 cmd_length
= src_ptr
[DST_S_B_SRC_DF_LENGTH
] + 2;
739 _bfd_vms_debug (4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
741 module
->file_table
[fileid
].name
);
746 case DST_S_C_SRC_DEFLINES_B
:
747 /* Perform the association and set the next higher index
749 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
750 srec
= (struct srecinfo
*)
751 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
752 srec
->line
= curr_srec
->line
+ data
;
753 srec
->srec
= curr_srec
->srec
+ data
;
754 srec
->sfile
= curr_srec
->sfile
;
755 curr_srec
->next
= srec
;
759 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_B: %d\n", data
);
763 case DST_S_C_SRC_DEFLINES_W
:
764 /* Perform the association and set the next higher index
766 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
767 srec
= (struct srecinfo
*)
768 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
769 srec
->line
= curr_srec
->line
+ data
;
770 srec
->srec
= curr_srec
->srec
+ data
,
771 srec
->sfile
= curr_srec
->sfile
;
772 curr_srec
->next
= srec
;
776 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_W: %d\n", data
);
780 case DST_S_C_SRC_INCRLNUM_B
:
781 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
782 curr_srec
->line
+= data
;
785 _bfd_vms_debug (4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data
);
789 case DST_S_C_SRC_SETFILE
:
790 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
791 curr_srec
->sfile
= data
;
792 curr_srec
->srec
= module
->file_table
[data
].srec
;
795 _bfd_vms_debug (4, "DST_S_C_SRC_SETFILE: %d\n", data
);
799 case DST_S_C_SRC_SETLNUM_L
:
800 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
801 curr_srec
->line
= data
;
804 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_L: %d\n", data
);
808 case DST_S_C_SRC_SETLNUM_W
:
809 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
810 curr_srec
->line
= data
;
813 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_W: %d\n", data
);
817 case DST_S_C_SRC_SETREC_L
:
818 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
819 curr_srec
->srec
= data
;
820 module
->file_table
[curr_srec
->sfile
].srec
= data
;
823 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_L: %d\n", data
);
827 case DST_S_C_SRC_SETREC_W
:
828 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
829 curr_srec
->srec
= data
;
830 module
->file_table
[curr_srec
->sfile
].srec
= data
;
833 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_W: %d\n", data
);
837 case DST_S_C_SRC_FORMFEED
:
840 _bfd_vms_debug (4, "DST_S_C_SRC_FORMFEED\n");
845 (*_bfd_error_handler
) (_("unknown source command %d"),
851 src_ptr
+= cmd_length
;
855 case DST_S_C_LINE_NUM
:
856 pcl_ptr
= ptr
+ DST_S_C_LINE_NUM_HEADER_SIZE
;
859 _bfd_vms_debug (3, "line info\n");
862 while (pcl_ptr
< ptr
+ rec_length
)
864 /* The command byte is signed so we must sign-extend it. */
865 int cmd
= ((signed char *)pcl_ptr
)[0], cmd_length
, data
;
869 case DST_S_C_DELTA_PC_W
:
870 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
875 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_W: %d\n", data
);
879 case DST_S_C_DELTA_PC_L
:
880 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
885 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_L: %d\n", data
);
889 case DST_S_C_INCR_LINUM
:
890 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
891 curr_linenum
+= data
;
894 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM: %d\n", data
);
898 case DST_S_C_INCR_LINUM_W
:
899 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
900 curr_linenum
+= data
;
903 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_W: %d\n", data
);
907 case DST_S_C_INCR_LINUM_L
:
908 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
909 curr_linenum
+= data
;
912 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_L: %d\n", data
);
916 case DST_S_C_SET_LINUM_INCR
:
917 (*_bfd_error_handler
)
918 (_("DST_S_C_SET_LINUM_INCR not implemented"));
922 case DST_S_C_SET_LINUM_INCR_W
:
923 (*_bfd_error_handler
)
924 (_("DST_S_C_SET_LINUM_INCR_W not implemented"));
928 case DST_S_C_RESET_LINUM_INCR
:
929 (*_bfd_error_handler
)
930 (_("DST_S_C_RESET_LINUM_INCR not implemented"));
934 case DST_S_C_BEG_STMT_MODE
:
935 (*_bfd_error_handler
)
936 (_("DST_S_C_BEG_STMT_MODE not implemented"));
940 case DST_S_C_END_STMT_MODE
:
941 (*_bfd_error_handler
)
942 (_("DST_S_C_END_STMT_MODE not implemented"));
946 case DST_S_C_SET_LINUM_B
:
947 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
951 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_B: %d\n", data
);
955 case DST_S_C_SET_LINE_NUM
:
956 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
960 _bfd_vms_debug (4, "DST_S_C_SET_LINE_NUM: %d\n", data
);
964 case DST_S_C_SET_LINUM_L
:
965 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
969 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_L: %d\n", data
);
974 (*_bfd_error_handler
)
975 (_("DST_S_C_SET_PC not implemented"));
979 case DST_S_C_SET_PC_W
:
980 (*_bfd_error_handler
)
981 (_("DST_S_C_SET_PC_W not implemented"));
985 case DST_S_C_SET_PC_L
:
986 (*_bfd_error_handler
)
987 (_("DST_S_C_SET_PC_L not implemented"));
991 case DST_S_C_SET_STMTNUM
:
992 (*_bfd_error_handler
)
993 (_("DST_S_C_SET_STMTNUM not implemented"));
998 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
1002 _bfd_vms_debug (4, "DST_S_C_TERM: %d\n", data
);
1006 case DST_S_C_TERM_W
:
1007 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
1011 _bfd_vms_debug (4, "DST_S_C_TERM_W: %d\n", data
);
1015 case DST_S_C_TERM_L
:
1016 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1020 _bfd_vms_debug (4, "DST_S_C_TERM_L: %d\n", data
);
1024 case DST_S_C_SET_ABS_PC
:
1025 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1029 _bfd_vms_debug (4, "DST_S_C_SET_ABS_PC: 0x%x\n", data
);
1040 _bfd_vms_debug (4, "bump pc to 0x%llx and line to %d\n",
1041 curr_pc
, curr_linenum
);
1046 (*_bfd_error_handler
) (_("unknown line command %d"),
1053 if ((curr_linenum
!= prev_linum
&& curr_pc
!= prev_pc
)
1055 || cmd
== DST_S_C_DELTA_PC_L
1056 || cmd
== DST_S_C_DELTA_PC_W
)
1058 line
= (struct lineinfo
*)
1059 bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1060 line
->address
= curr_pc
;
1061 line
->line
= curr_linenum
;
1063 curr_line
->next
= line
;
1066 prev_linum
= curr_linenum
;
1069 _bfd_vms_debug (4, "-> correlate pc 0x%llx with line %d\n",
1070 curr_pc
, curr_linenum
);
1074 pcl_ptr
+= cmd_length
;
1078 case 0x17: /* Undocumented type used by DEC C to declare equates. */
1080 _bfd_vms_debug (3, "undocumented type 0x17\n");
1086 _bfd_vms_debug (3, "ignoring record\n");
1095 /* Finalize tables with EOL marker. */
1096 srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
1097 srec
->line
= (unsigned int) -1;
1098 srec
->srec
= (unsigned int) -1;
1099 curr_srec
->next
= srec
;
1101 line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1102 line
->line
= (unsigned int) -1;
1103 line
->address
= (bfd_vma
) -1;
1104 curr_line
->next
= line
;
1106 /* Advertise that this module has been parsed. This is needed
1107 because parsing can be either performed at module creation
1108 or deferred until debug info is consumed. */
1109 SET_MODULE_PARSED (module
);
1112 /* Build the list of modules for the specified BFD. */
1114 static struct module
*
1115 build_module_list (bfd
*abfd
)
1117 struct module
*module
, *list
= NULL
;
1120 if ((dmt
= bfd_get_section_by_name (abfd
, "$DMT$")))
1122 /* We have a DMT section so this must be an image. Parse the
1123 section and build the list of modules. This is sufficient
1124 since we can compute the start address and the end address
1125 of every module from the section contents. */
1126 bfd_size_type size
= bfd_get_section_size (dmt
);
1127 unsigned char *ptr
, *end
;
1129 ptr
= (unsigned char *) bfd_alloc (abfd
, size
);
1133 if (! bfd_get_section_contents (abfd
, dmt
, ptr
, 0, size
))
1137 _bfd_vms_debug (2, "DMT\n");
1144 /* Each header declares a module with its start offset and size
1145 of debug info in the DST section, as well as the count of
1146 program sections (i.e. address spans) it contains. */
1147 int modbeg
= bfd_getl32 (ptr
+ DBG_S_L_DMT_MODBEG
);
1148 int msize
= bfd_getl32 (ptr
+ DBG_S_L_DST_SIZE
);
1149 int count
= bfd_getl16 (ptr
+ DBG_S_W_DMT_PSECT_COUNT
);
1150 ptr
+= DBG_S_C_DMT_HEADER_SIZE
;
1153 _bfd_vms_debug (3, "module: modbeg = %d, size = %d, count = %d\n",
1154 modbeg
, msize
, count
);
1157 /* We create a 'module' structure for each program section since
1158 we only support contiguous addresses in a 'module' structure.
1159 As a consequence, the actual debug info in the DST section is
1160 shared and can be parsed multiple times; that doesn't seem to
1161 cause problems in practice. */
1164 int start
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_START
);
1165 int length
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_LENGTH
);
1166 module
= new_module (abfd
);
1167 module
->modbeg
= modbeg
;
1168 module
->size
= msize
;
1169 module
->low
= start
;
1170 module
->high
= start
+ length
;
1171 module
->next
= list
;
1173 ptr
+= DBG_S_C_DMT_PSECT_SIZE
;
1176 _bfd_vms_debug (4, "section: start = 0x%x, length = %d\n",
1184 /* We don't have a DMT section so this must be an object. Parse
1185 the module right now in order to compute its start address and
1187 module
= new_module (abfd
);
1188 parse_module (abfd
, module
, PRIV (dst_section
)->contents
,
1189 PRIV (dst_ptr_end
) - PRIV (dst_section
)->contents
);
1196 /* Calculate and return the name of the source file and the line nearest
1197 to the wanted location in the specified module. */
1200 module_find_nearest_line (bfd
*abfd
, struct module
*module
, bfd_vma addr
,
1201 const char **file
, const char **func
,
1204 struct funcinfo
*funcinfo
;
1205 struct lineinfo
*lineinfo
;
1206 struct srecinfo
*srecinfo
;
1207 bfd_boolean ret
= FALSE
;
1209 /* Parse this module if that was not done at module creation. */
1210 if (! IS_MODULE_PARSED (module
))
1212 unsigned int size
= module
->size
;
1213 unsigned int modbeg
= PRIV (dst_section
)->filepos
+ module
->modbeg
;
1214 unsigned char *buffer
= (unsigned char *) bfd_malloc (module
->size
);
1216 if (bfd_seek (abfd
, modbeg
, SEEK_SET
) != 0
1217 || bfd_bread (buffer
, size
, abfd
) != size
)
1219 bfd_set_error (bfd_error_no_debug_section
);
1223 parse_module (abfd
, module
, buffer
, size
);
1227 /* Find out the function (if any) that contains the address. */
1228 for (funcinfo
= module
->func_table
; funcinfo
; funcinfo
= funcinfo
->next
)
1229 if (addr
>= funcinfo
->low
&& addr
<= funcinfo
->high
)
1231 *func
= funcinfo
->name
;
1236 /* Find out the source file and the line nearest to the address. */
1237 for (lineinfo
= module
->line_table
; lineinfo
; lineinfo
= lineinfo
->next
)
1238 if (lineinfo
->next
&& addr
< lineinfo
->next
->address
)
1240 for (srecinfo
= module
->srec_table
; srecinfo
; srecinfo
= srecinfo
->next
)
1241 if (srecinfo
->next
&& lineinfo
->line
< srecinfo
->next
->line
)
1243 if (srecinfo
->sfile
> 0)
1245 *file
= module
->file_table
[srecinfo
->sfile
].name
;
1246 *line
= srecinfo
->srec
+ lineinfo
->line
- srecinfo
->line
;
1250 *file
= module
->name
;
1251 *line
= lineinfo
->line
;
1262 /* Provided a BFD, a section and an offset into the section, calculate and
1263 return the name of the source file and the line nearest to the wanted
1267 _bfd_vms_find_nearest_dst_line (bfd
*abfd
, asection
*section
,
1268 asymbol
**symbols ATTRIBUTE_UNUSED
,
1269 bfd_vma offset
, const char **file
,
1270 const char **func
, unsigned int *line
)
1272 struct module
*module
;
1274 /* What address are we looking for? */
1275 bfd_vma addr
= section
->vma
+ offset
;
1281 if (PRIV (dst_section
) == NULL
)
1284 if (PRIV (modules
) == NULL
)
1286 PRIV (modules
) = build_module_list (abfd
);
1287 if (PRIV (modules
) == NULL
)
1291 for (module
= PRIV (modules
); module
; module
= module
->next
)
1292 if (addr
>= module
->low
&& addr
<= module
->high
)
1293 return module_find_nearest_line (abfd
, module
, addr
, file
, func
, line
);
1298 /* Process EDBG/ETBT record.
1299 Return 0 on success, -1 on error */
1302 vms_slurp_debug (bfd
*abfd
)
1304 if (PRIV (dst_section
) == NULL
)
1306 /* We have no way to find out beforehand how much debug info there
1307 is in an object file, so pick an initial amount and grow it as
1309 flagword flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
| SEC_RELOC
;
1310 asection
*section
= bfd_make_section (abfd
, "$DST$");
1313 section
->size
= 1024;
1314 if (!bfd_set_section_flags (abfd
, section
, flags
))
1316 section
->contents
= ((unsigned char *)
1317 bfd_zmalloc (section
->size
));
1318 if (section
->contents
== NULL
)
1320 section
->filepos
= (unsigned int)-1;
1321 PRIV (dst_section
) = section
;
1324 PRIV (image_section
) = PRIV (dst_section
);
1325 PRIV (image_ptr
) = PRIV (dst_section
)->contents
;
1327 return _bfd_vms_slurp_tir (abfd
, EOBJ_S_C_ETIR
);
1330 /* Process DBG/EDBG record.
1331 Return 0 on success, -1 on error. */
1334 _bfd_vms_slurp_dbg (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1337 _bfd_vms_debug (2, "DBG/EDBG\n");
1340 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1342 return vms_slurp_debug (abfd
);
1345 /* Process TBT/ETBT record.
1346 Return 0 on success, -1 on error. */
1349 _bfd_vms_slurp_tbt (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1352 _bfd_vms_debug (2, "TBT/ETBT\n");
1355 abfd
->flags
|= HAS_LINENO
;
1357 return vms_slurp_debug (abfd
);
1360 /* Write DBG/EDBG record. */
1363 _bfd_vms_write_dbg (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1366 _bfd_vms_debug (2, "vms_write_dbg (%p, %d)\n", abfd
, objtype
);
1372 /* Write TBT/ETBT record. */
1375 _bfd_vms_write_tbt (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1378 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);