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 /* Strip path and suffix information. */
241 char *fname
, *fout
, *fptr
;
243 fptr
= bfd_get_filename (abfd
);
244 fname
= strdup (fptr
);
246 /* Strip VMS path. */
247 fout
= strrchr (fname
, ']');
249 fout
= strchr (fname
, ':');
255 /* Strip UNIX path. */
256 fptr
= strrchr (fout
, '/');
261 fptr
= strrchr (fout
, '.');
265 /* Convert to upper case and truncate at 31 characters.
266 (VMS object file format restricts module name length to 31). */
270 *fptr
= TOUPPER (*fptr
);
272 if (*fptr
== ';' || (fptr
- fout
) >= 31)
275 _bfd_vms_output_counted (abfd
, fout
);
279 _bfd_vms_output_counted (abfd
, "NONAME");
281 _bfd_vms_output_counted (abfd
, BFD_VERSION_STRING
);
282 _bfd_vms_output_dump (abfd
, get_vms_time_string (), EMH_DATE_LENGTH
);
283 _bfd_vms_output_fill (abfd
, 0, EMH_DATE_LENGTH
);
284 _bfd_vms_output_flush (abfd
);
287 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_LNM
);
288 snprintf (version
, sizeof (version
), "GAS BFD v%s", BFD_VERSION_STRING
);
289 _bfd_vms_output_dump (abfd
, (unsigned char *)version
, strlen (version
));
290 _bfd_vms_output_flush (abfd
);
293 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_SRC
);
295 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
297 symbol
= abfd
->outsymbols
[symnum
];
299 if (symbol
->flags
& BSF_FILE
)
301 if (CONST_STRNEQ ((char *)symbol
->name
, "<CASE:"))
303 PRIV (flag_hash_long_names
) = symbol
->name
[6] - '0';
304 PRIV (flag_show_after_trunc
) = symbol
->name
[7] - '0';
312 _bfd_vms_output_dump (abfd
, (unsigned char *) symbol
->name
,
313 (int) strlen (symbol
->name
));
320 if (symnum
== abfd
->symcount
)
321 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("noname"));
323 _bfd_vms_output_flush (abfd
);
326 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_TTL
);
327 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("TTL"));
328 _bfd_vms_output_flush (abfd
);
331 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_CPR
);
332 _bfd_vms_output_dump (abfd
,
333 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
335 _bfd_vms_output_flush (abfd
);
340 /* Process EOM/EEOM record
341 return 0 on success, -1 on error. */
344 _bfd_vms_slurp_eom (bfd
*abfd
, int objtype
)
346 unsigned char *vms_rec
;
349 vms_debug(2, "EOM/EEOM\n");
352 vms_rec
= PRIV (vms_rec
);
354 if ((objtype
== OBJ_S_C_EOM
)
355 || (objtype
== OBJ_S_C_EOMW
))
360 PRIV (eom_data
).eom_l_total_lps
361 = bfd_getl32 (vms_rec
+ EEOM_S_L_TOTAL_LPS
);
362 PRIV (eom_data
).eom_w_comcod
= bfd_getl16 (vms_rec
+ EEOM_S_W_COMCOD
);
363 if (PRIV (eom_data
).eom_w_comcod
> 1)
365 (*_bfd_error_handler
) (_("Object module NOT error-free !\n"));
366 bfd_set_error (bfd_error_bad_value
);
369 PRIV (eom_data
).eom_has_transfer
= FALSE
;
370 if (PRIV (rec_size
) > 10)
372 PRIV (eom_data
).eom_has_transfer
= TRUE
;
373 PRIV (eom_data
).eom_b_tfrflg
= vms_rec
[EEOM_S_B_TFRFLG
];
374 PRIV (eom_data
).eom_l_psindx
375 = bfd_getl32 (vms_rec
+ EEOM_S_L_PSINDX
);
376 PRIV (eom_data
).eom_l_tfradr
377 = bfd_getl32 (vms_rec
+ EEOM_S_L_TFRADR
);
379 abfd
->start_address
= PRIV (eom_data
).eom_l_tfradr
;
385 /* Write eom record for bfd abfd. */
388 _bfd_vms_write_eom (bfd
*abfd
, int objtype
)
391 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd
, objtype
);
394 _bfd_vms_output_begin (abfd
, objtype
, -1);
395 _bfd_vms_output_long (abfd
, (unsigned long) (PRIV (vms_linkage_index
) >> 1));
396 _bfd_vms_output_byte (abfd
, 0); /* Completion code. */
397 _bfd_vms_output_byte (abfd
, 0); /* Fill byte. */
399 if (bfd_get_start_address (abfd
) != (bfd_vma
)-1)
403 section
= bfd_get_section_by_name (abfd
, ".link");
406 bfd_set_error (bfd_error_nonrepresentable_section
);
409 _bfd_vms_output_short (abfd
, 0);
410 _bfd_vms_output_long (abfd
, (unsigned long) (section
->index
));
411 _bfd_vms_output_long (abfd
,
412 (unsigned long) bfd_get_start_address (abfd
));
413 _bfd_vms_output_long (abfd
, 0);
416 _bfd_vms_output_end (abfd
);
420 /* Read & process IHD/EIHD record.
421 Return 0 on success, -1 on error */
423 _bfd_vms_slurp_ihd (bfd
*abfd
, unsigned int *isd_offset
,
424 unsigned int *ihs_offset
)
426 unsigned int imgtype
, size
;
430 vms_debug (8, "_bfd_vms_slurp_ihd\n");
433 size
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SIZE
);
434 imgtype
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_IMGTYPE
);
436 if (imgtype
== EIHD_S_K_EXE
)
437 abfd
->flags
|= EXEC_P
;
439 symvva
= bfd_getl64 (PRIV (vms_rec
) + EIHD_S_Q_SYMVVA
);
442 PRIV (symvva
) = symvva
;
443 abfd
->flags
|= DYNAMIC
;
446 *isd_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_ISDOFF
);
447 *ihs_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SYMDBGOFF
);
450 vms_debug (4, "EIHD record size %d imgtype %d symvva 0x%llx isd %d ihs %d\n",
451 size
, imgtype
, symvva
, *isd_offset
, *ihs_offset
);
457 /* Read & process ISD/EISD record
458 return 0 on success, -1 on error */
461 _bfd_vms_slurp_isd (bfd
*abfd
, unsigned int offset
)
463 int section_count
= 0;
465 unsigned int rec_size
;
468 vms_debug (8, "_bfd_vms_slurp_isd\n");
471 for (p
= PRIV (vms_rec
) + offset
;
472 (rec_size
= bfd_getl32 (p
+ EISD_S_L_EISDSIZE
)) != 0;
475 unsigned long long vaddr
= bfd_getl64 (p
+ EISD_S_Q_VIR_ADDR
);
476 unsigned int size
= bfd_getl32 (p
+ EISD_S_L_SECSIZE
);
477 unsigned int flags
= bfd_getl32 (p
+ EISD_S_L_FLAGS
);
478 unsigned int vbn
= bfd_getl32 (p
+ EISD_S_L_VBN
);
484 vms_debug (4, "EISD record at 0x%x size 0x%x addr 0x%x bfd_flags 0x%x block %d\n",
485 p
- PRIV (vms_rec
), size
, vaddr
, flags
, vbn
);
488 /* VMS combines psects from .obj files into isects in the .exe. This
489 process doesn't preserve enough information to reliably determine
490 what's in each section without examining the data. This is
491 especially true of DWARF debug sections. */
492 bfd_flags
= SEC_ALLOC
;
494 if (flags
& EISD_S_M_EXE
)
495 bfd_flags
|= SEC_CODE
| SEC_HAS_CONTENTS
| SEC_LOAD
;
497 if (flags
& EISD_S_M_NONSHRADR
)
498 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
500 if (!(flags
& EISD_S_M_WRT
))
501 bfd_flags
|= SEC_READONLY
;
503 if (flags
& EISD_S_M_DZRO
)
504 bfd_flags
|= SEC_DATA
;
506 if (flags
& EISD_S_M_FIXUPVEC
)
507 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
509 if (flags
& EISD_S_M_CRF
)
510 bfd_flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
;
512 if (flags
& EISD_S_M_GBL
)
514 name
= _bfd_vms_save_counted_string (p
+ EISD_S_T_GBLNAM
);
515 bfd_flags
|= SEC_COFF_SHARED_LIBRARY
;
516 bfd_flags
&= ~(SEC_ALLOC
| SEC_LOAD
);
520 name
= (char*) bfd_alloc (abfd
, 32);
521 sprintf (name
, "$LOCAL_%03d$", section_count
++);
524 section
= bfd_make_section (abfd
, name
);
529 section
->filepos
= vbn
? VMS_BLOCK_SIZE
* (vbn
- 1) : (unsigned int)-1;
530 section
->size
= size
;
531 section
->vma
= vaddr
;
533 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
540 /* Read & process IHS/EIHS record
541 return 0 on success, -1 on error */
543 _bfd_vms_slurp_ihs (bfd
*abfd
, unsigned int offset
)
545 unsigned char *p
= PRIV (vms_rec
) + offset
;
546 unsigned int gstvbn
= bfd_getl32 (p
+ EIHS_S_L_GSTVBN
);
547 unsigned int gstsize ATTRIBUTE_UNUSED
= bfd_getl32 (p
+ EIHS_S_L_GSTSIZE
);
548 unsigned int dstvbn
= bfd_getl32 (p
+ EIHS_S_L_DSTVBN
);
549 unsigned int dstsize
= bfd_getl32 (p
+ EIHS_S_L_DSTSIZE
);
550 unsigned int dmtvbn
= bfd_getl32 (p
+ EIHS_S_L_DMTVBN
);
551 unsigned int dmtbytes
= bfd_getl32 (p
+ EIHS_S_L_DMTBYTES
);
555 vms_debug (8, "_bfd_vms_slurp_ihs\n");
556 vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
557 gstvbn
, gstsize
, dstvbn
, dstsize
, dmtvbn
, dmtbytes
);
562 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
564 section
= bfd_make_section (abfd
, "$DST$");
568 section
->size
= dstsize
;
569 section
->filepos
= VMS_BLOCK_SIZE
* (dstvbn
- 1);
571 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
574 PRIV (dst_section
) = section
;
575 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
580 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
582 section
= bfd_make_section (abfd
, "$DMT$");
586 section
->size
= dmtbytes
;
587 section
->filepos
= VMS_BLOCK_SIZE
* (dmtvbn
- 1);
589 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
595 flagword bfd_flags
= SEC_HAS_CONTENTS
;
597 section
= bfd_make_section (abfd
, "$GST$");
601 if (bfd_seek (abfd
, VMS_BLOCK_SIZE
* (gstvbn
- 1), SEEK_SET
))
603 bfd_set_error (bfd_error_file_truncated
);
607 if (_bfd_vms_slurp_object_records (abfd
) != 0)
610 section
->filepos
= VMS_BLOCK_SIZE
* (gstvbn
- 1);
611 section
->size
= bfd_tell (abfd
) - section
->filepos
;
613 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
616 abfd
->flags
|= HAS_SYMS
;
622 /* Build a new module for the specified BFD. */
624 static struct module
*
625 new_module (bfd
*abfd
)
627 struct module
*module
628 = (struct module
*) bfd_zalloc (abfd
, sizeof (struct module
));
629 module
->file_table_count
= 16; /* Arbitrary. */
631 = bfd_malloc (module
->file_table_count
* sizeof (struct fileinfo
));
635 /* Parse debug info for a module and internalize it. */
638 parse_module (bfd
*abfd
, struct module
*module
, unsigned char *ptr
,
641 unsigned char *maxptr
= ptr
+ length
, *src_ptr
, *pcl_ptr
;
642 unsigned int prev_linum
= 0, curr_linenum
= 0;
643 bfd_vma prev_pc
= 0, curr_pc
= 0;
644 struct srecinfo
*curr_srec
, *srec
;
645 struct lineinfo
*curr_line
, *line
;
646 struct funcinfo
*funcinfo
;
648 /* Initialize tables with zero element. */
649 curr_srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
650 module
->srec_table
= curr_srec
;
652 curr_line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
653 module
->line_table
= curr_line
;
657 /* The first byte is not counted in the recorded length. */
658 int rec_length
= bfd_getl16 (ptr
) + 1;
659 int rec_type
= bfd_getl16 (ptr
+ 2);
662 _bfd_vms_debug (2, "DST record: length %d, type %d\n",
663 rec_length
, rec_type
);
670 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_MODBEG_NAME
);
678 _bfd_vms_debug (3, "module: %s\n", module
->name
);
684 _bfd_vms_debug (3, "end module\n");
689 funcinfo
= (struct funcinfo
*)
690 bfd_zalloc (abfd
, sizeof (struct funcinfo
));
692 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_RTNBEG_NAME
);
693 funcinfo
->low
= bfd_getl32 (ptr
+ DST_S_L_RTNBEG_ADDRESS
);
694 funcinfo
->next
= module
->func_table
;
695 module
->func_table
= funcinfo
;
698 _bfd_vms_debug (3, "routine: %s at 0x%x\n",
699 funcinfo
->name
, funcinfo
->low
);
704 module
->func_table
->high
= module
->func_table
->low
705 + bfd_getl32 (ptr
+ DST_S_L_RTNEND_SIZE
) - 1;
707 if (module
->func_table
->high
> module
->high
)
708 module
->high
= module
->func_table
->high
;
711 _bfd_vms_debug (3, "end routine\n");
717 _bfd_vms_debug (3, "prologue\n");
723 _bfd_vms_debug (3, "epilog\n");
729 _bfd_vms_debug (3, "block\n");
735 _bfd_vms_debug (3, "end block\n");
740 src_ptr
= ptr
+ DST_S_C_SOURCE_HEADER_SIZE
;
743 _bfd_vms_debug (3, "source info\n");
746 while (src_ptr
< ptr
+ rec_length
)
748 int cmd
= src_ptr
[0], cmd_length
, data
;
752 case DST_S_C_SRC_DECLFILE
:
755 = bfd_getl16 (src_ptr
+ DST_S_W_SRC_DF_FILEID
);
757 = _bfd_vms_save_counted_string (src_ptr
758 + DST_S_B_SRC_DF_FILENAME
);
760 while (fileid
>= module
->file_table_count
)
762 module
->file_table_count
*= 2;
764 = bfd_realloc (module
->file_table
,
765 module
->file_table_count
766 * sizeof (struct fileinfo
));
769 module
->file_table
[fileid
].name
= filename
;
770 module
->file_table
[fileid
].srec
= 1;
771 cmd_length
= src_ptr
[DST_S_B_SRC_DF_LENGTH
] + 2;
773 _bfd_vms_debug (4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
775 module
->file_table
[fileid
].name
);
780 case DST_S_C_SRC_DEFLINES_B
:
781 /* Perform the association and set the next higher index
783 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
784 srec
= (struct srecinfo
*)
785 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
786 srec
->line
= curr_srec
->line
+ data
;
787 srec
->srec
= curr_srec
->srec
+ data
;
788 srec
->sfile
= curr_srec
->sfile
;
789 curr_srec
->next
= srec
;
793 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_B: %d\n", data
);
797 case DST_S_C_SRC_DEFLINES_W
:
798 /* Perform the association and set the next higher index
800 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
801 srec
= (struct srecinfo
*)
802 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
803 srec
->line
= curr_srec
->line
+ data
;
804 srec
->srec
= curr_srec
->srec
+ data
,
805 srec
->sfile
= curr_srec
->sfile
;
806 curr_srec
->next
= srec
;
810 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_W: %d\n", data
);
814 case DST_S_C_SRC_INCRLNUM_B
:
815 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
816 curr_srec
->line
+= data
;
819 _bfd_vms_debug (4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data
);
823 case DST_S_C_SRC_SETFILE
:
824 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
825 curr_srec
->sfile
= data
;
826 curr_srec
->srec
= module
->file_table
[data
].srec
;
829 _bfd_vms_debug (4, "DST_S_C_SRC_SETFILE: %d\n", data
);
833 case DST_S_C_SRC_SETLNUM_L
:
834 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
835 curr_srec
->line
= data
;
838 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_L: %d\n", data
);
842 case DST_S_C_SRC_SETLNUM_W
:
843 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
844 curr_srec
->line
= data
;
847 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_W: %d\n", data
);
851 case DST_S_C_SRC_SETREC_L
:
852 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
853 curr_srec
->srec
= data
;
854 module
->file_table
[curr_srec
->sfile
].srec
= data
;
857 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_L: %d\n", data
);
861 case DST_S_C_SRC_SETREC_W
:
862 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
863 curr_srec
->srec
= data
;
864 module
->file_table
[curr_srec
->sfile
].srec
= data
;
867 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_W: %d\n", data
);
871 case DST_S_C_SRC_FORMFEED
:
874 _bfd_vms_debug (4, "DST_S_C_SRC_FORMFEED\n");
879 (*_bfd_error_handler
) (_("unknown source command %d"),
885 src_ptr
+= cmd_length
;
889 case DST_S_C_LINE_NUM
:
890 pcl_ptr
= ptr
+ DST_S_C_LINE_NUM_HEADER_SIZE
;
893 _bfd_vms_debug (3, "line info\n");
896 while (pcl_ptr
< ptr
+ rec_length
)
898 /* The command byte is signed so we must sign-extend it. */
899 int cmd
= ((signed char *)pcl_ptr
)[0], cmd_length
, data
;
903 case DST_S_C_DELTA_PC_W
:
904 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
909 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_W: %d\n", data
);
913 case DST_S_C_DELTA_PC_L
:
914 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
919 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_L: %d\n", data
);
923 case DST_S_C_INCR_LINUM
:
924 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
925 curr_linenum
+= data
;
928 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM: %d\n", data
);
932 case DST_S_C_INCR_LINUM_W
:
933 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
934 curr_linenum
+= data
;
937 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_W: %d\n", data
);
941 case DST_S_C_INCR_LINUM_L
:
942 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
943 curr_linenum
+= data
;
946 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_L: %d\n", data
);
950 case DST_S_C_SET_LINUM_INCR
:
951 (*_bfd_error_handler
)
952 (_("DST_S_C_SET_LINUM_INCR not implemented"));
956 case DST_S_C_SET_LINUM_INCR_W
:
957 (*_bfd_error_handler
)
958 (_("DST_S_C_SET_LINUM_INCR_W not implemented"));
962 case DST_S_C_RESET_LINUM_INCR
:
963 (*_bfd_error_handler
)
964 (_("DST_S_C_RESET_LINUM_INCR not implemented"));
968 case DST_S_C_BEG_STMT_MODE
:
969 (*_bfd_error_handler
)
970 (_("DST_S_C_BEG_STMT_MODE not implemented"));
974 case DST_S_C_END_STMT_MODE
:
975 (*_bfd_error_handler
)
976 (_("DST_S_C_END_STMT_MODE not implemented"));
980 case DST_S_C_SET_LINUM_B
:
981 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
985 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_B: %d\n", data
);
989 case DST_S_C_SET_LINE_NUM
:
990 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
994 _bfd_vms_debug (4, "DST_S_C_SET_LINE_NUM: %d\n", data
);
998 case DST_S_C_SET_LINUM_L
:
999 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1000 curr_linenum
= data
;
1003 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_L: %d\n", data
);
1007 case DST_S_C_SET_PC
:
1008 (*_bfd_error_handler
)
1009 (_("DST_S_C_SET_PC not implemented"));
1013 case DST_S_C_SET_PC_W
:
1014 (*_bfd_error_handler
)
1015 (_("DST_S_C_SET_PC_W not implemented"));
1019 case DST_S_C_SET_PC_L
:
1020 (*_bfd_error_handler
)
1021 (_("DST_S_C_SET_PC_L not implemented"));
1025 case DST_S_C_SET_STMTNUM
:
1026 (*_bfd_error_handler
)
1027 (_("DST_S_C_SET_STMTNUM not implemented"));
1032 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
1036 _bfd_vms_debug (4, "DST_S_C_TERM: %d\n", data
);
1040 case DST_S_C_TERM_W
:
1041 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
1045 _bfd_vms_debug (4, "DST_S_C_TERM_W: %d\n", data
);
1049 case DST_S_C_TERM_L
:
1050 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1054 _bfd_vms_debug (4, "DST_S_C_TERM_L: %d\n", data
);
1058 case DST_S_C_SET_ABS_PC
:
1059 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1063 _bfd_vms_debug (4, "DST_S_C_SET_ABS_PC: 0x%x\n", data
);
1074 _bfd_vms_debug (4, "bump pc to 0x%llx and line to %d\n",
1075 curr_pc
, curr_linenum
);
1080 (*_bfd_error_handler
) (_("unknown line command %d"),
1087 if ((curr_linenum
!= prev_linum
&& curr_pc
!= prev_pc
)
1089 || cmd
== DST_S_C_DELTA_PC_L
1090 || cmd
== DST_S_C_DELTA_PC_W
)
1092 line
= (struct lineinfo
*)
1093 bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1094 line
->address
= curr_pc
;
1095 line
->line
= curr_linenum
;
1097 curr_line
->next
= line
;
1100 prev_linum
= curr_linenum
;
1103 _bfd_vms_debug (4, "-> correlate pc 0x%llx with line %d\n",
1104 curr_pc
, curr_linenum
);
1108 pcl_ptr
+= cmd_length
;
1112 case 0x17: /* Undocumented type used by DEC C to declare equates. */
1114 _bfd_vms_debug (3, "undocumented type 0x17\n");
1120 _bfd_vms_debug (3, "ignoring record\n");
1129 /* Finalize tables with EOL marker. */
1130 srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
1131 srec
->line
= (unsigned int) -1;
1132 srec
->srec
= (unsigned int) -1;
1133 curr_srec
->next
= srec
;
1135 line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1136 line
->line
= (unsigned int) -1;
1137 line
->address
= (bfd_vma
) -1;
1138 curr_line
->next
= line
;
1140 /* Advertise that this module has been parsed. This is needed
1141 because parsing can be either performed at module creation
1142 or deferred until debug info is consumed. */
1143 SET_MODULE_PARSED (module
);
1146 /* Build the list of modules for the specified BFD. */
1148 static struct module
*
1149 build_module_list (bfd
*abfd
)
1151 struct module
*module
, *list
= NULL
;
1154 if ((dmt
= bfd_get_section_by_name (abfd
, "$DMT$")))
1156 /* We have a DMT section so this must be an image. Parse the
1157 section and build the list of modules. This is sufficient
1158 since we can compute the start address and the end address
1159 of every module from the section contents. */
1160 bfd_size_type size
= bfd_get_section_size (dmt
);
1161 unsigned char *ptr
, *end
;
1163 ptr
= (unsigned char *) bfd_alloc (abfd
, size
);
1167 if (! bfd_get_section_contents (abfd
, dmt
, ptr
, 0, size
))
1171 _bfd_vms_debug (2, "DMT\n");
1178 /* Each header declares a module with its start offset and size
1179 of debug info in the DST section, as well as the count of
1180 program sections (i.e. address spans) it contains. */
1181 int modbeg
= bfd_getl32 (ptr
+ DBG_S_L_DMT_MODBEG
);
1182 int msize
= bfd_getl32 (ptr
+ DBG_S_L_DST_SIZE
);
1183 int count
= bfd_getl16 (ptr
+ DBG_S_W_DMT_PSECT_COUNT
);
1184 ptr
+= DBG_S_C_DMT_HEADER_SIZE
;
1187 _bfd_vms_debug (3, "module: modbeg = %d, size = %d, count = %d\n",
1188 modbeg
, msize
, count
);
1191 /* We create a 'module' structure for each program section since
1192 we only support contiguous addresses in a 'module' structure.
1193 As a consequence, the actual debug info in the DST section is
1194 shared and can be parsed multiple times; that doesn't seem to
1195 cause problems in practice. */
1198 int start
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_START
);
1199 int length
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_LENGTH
);
1200 module
= new_module (abfd
);
1201 module
->modbeg
= modbeg
;
1202 module
->size
= msize
;
1203 module
->low
= start
;
1204 module
->high
= start
+ length
;
1205 module
->next
= list
;
1207 ptr
+= DBG_S_C_DMT_PSECT_SIZE
;
1210 _bfd_vms_debug (4, "section: start = 0x%x, length = %d\n",
1218 /* We don't have a DMT section so this must be an object. Parse
1219 the module right now in order to compute its start address and
1221 module
= new_module (abfd
);
1222 parse_module (abfd
, module
, PRIV (dst_section
)->contents
,
1223 PRIV (dst_ptr_end
) - PRIV (dst_section
)->contents
);
1230 /* Calculate and return the name of the source file and the line nearest
1231 to the wanted location in the specified module. */
1234 module_find_nearest_line (bfd
*abfd
, struct module
*module
, bfd_vma addr
,
1235 const char **file
, const char **func
,
1238 struct funcinfo
*funcinfo
;
1239 struct lineinfo
*lineinfo
;
1240 struct srecinfo
*srecinfo
;
1241 bfd_boolean ret
= FALSE
;
1243 /* Parse this module if that was not done at module creation. */
1244 if (! IS_MODULE_PARSED (module
))
1246 unsigned int size
= module
->size
;
1247 unsigned int modbeg
= PRIV (dst_section
)->filepos
+ module
->modbeg
;
1248 unsigned char *buffer
= (unsigned char *) bfd_malloc (module
->size
);
1250 if (bfd_seek (abfd
, modbeg
, SEEK_SET
) != 0
1251 || bfd_bread (buffer
, size
, abfd
) != size
)
1253 bfd_set_error (bfd_error_no_debug_section
);
1257 parse_module (abfd
, module
, buffer
, size
);
1261 /* Find out the function (if any) that contains the address. */
1262 for (funcinfo
= module
->func_table
; funcinfo
; funcinfo
= funcinfo
->next
)
1263 if (addr
>= funcinfo
->low
&& addr
<= funcinfo
->high
)
1265 *func
= funcinfo
->name
;
1270 /* Find out the source file and the line nearest to the address. */
1271 for (lineinfo
= module
->line_table
; lineinfo
; lineinfo
= lineinfo
->next
)
1272 if (lineinfo
->next
&& addr
< lineinfo
->next
->address
)
1274 for (srecinfo
= module
->srec_table
; srecinfo
; srecinfo
= srecinfo
->next
)
1275 if (srecinfo
->next
&& lineinfo
->line
< srecinfo
->next
->line
)
1277 if (srecinfo
->sfile
> 0)
1279 *file
= module
->file_table
[srecinfo
->sfile
].name
;
1280 *line
= srecinfo
->srec
+ lineinfo
->line
- srecinfo
->line
;
1284 *file
= module
->name
;
1285 *line
= lineinfo
->line
;
1296 /* Provided a BFD, a section and an offset into the section, calculate and
1297 return the name of the source file and the line nearest to the wanted
1301 _bfd_vms_find_nearest_dst_line (bfd
*abfd
, asection
*section
,
1302 asymbol
**symbols ATTRIBUTE_UNUSED
,
1303 bfd_vma offset
, const char **file
,
1304 const char **func
, unsigned int *line
)
1306 struct module
*module
;
1308 /* What address are we looking for? */
1309 bfd_vma addr
= section
->vma
+ offset
;
1315 if (PRIV (dst_section
) == NULL
)
1318 if (PRIV (modules
) == NULL
)
1320 PRIV (modules
) = build_module_list (abfd
);
1321 if (PRIV (modules
) == NULL
)
1325 for (module
= PRIV (modules
); module
; module
= module
->next
)
1326 if (addr
>= module
->low
&& addr
<= module
->high
)
1327 return module_find_nearest_line (abfd
, module
, addr
, file
, func
, line
);
1332 /* Process EDBG/ETBT record.
1333 Return 0 on success, -1 on error */
1336 vms_slurp_debug (bfd
*abfd
)
1338 if (PRIV (dst_section
) == NULL
)
1340 /* We have no way to find out beforehand how much debug info there
1341 is in an object file, so pick an initial amount and grow it as
1343 flagword flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
| SEC_RELOC
;
1344 asection
*section
= bfd_make_section (abfd
, "$DST$");
1347 section
->size
= 1024;
1348 if (!bfd_set_section_flags (abfd
, section
, flags
))
1350 section
->contents
= ((unsigned char *)
1351 bfd_zmalloc (section
->size
));
1352 if (section
->contents
== NULL
)
1354 section
->filepos
= (unsigned int)-1;
1355 PRIV (dst_section
) = section
;
1358 PRIV (image_section
) = PRIV (dst_section
);
1359 PRIV (image_ptr
) = PRIV (dst_section
)->contents
;
1361 return _bfd_vms_slurp_tir (abfd
, EOBJ_S_C_ETIR
);
1364 /* Process DBG/EDBG record.
1365 Return 0 on success, -1 on error. */
1368 _bfd_vms_slurp_dbg (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1371 _bfd_vms_debug (2, "DBG/EDBG\n");
1374 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1376 return vms_slurp_debug (abfd
);
1379 /* Process TBT/ETBT record.
1380 Return 0 on success, -1 on error. */
1383 _bfd_vms_slurp_tbt (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1386 _bfd_vms_debug (2, "TBT/ETBT\n");
1389 abfd
->flags
|= HAS_LINENO
;
1391 return vms_slurp_debug (abfd
);
1394 /* Write DBG/EDBG record. */
1397 _bfd_vms_write_dbg (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1400 _bfd_vms_debug (2, "vms_write_dbg (%p, %d)\n", abfd
, objtype
);
1406 /* Write TBT/ETBT record. */
1409 _bfd_vms_write_tbt (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1412 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);