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 if (bfd_get_filename (abfd
) != 0)
239 /* Strip path and suffix information. */
240 char *fname
, *fout
, *fptr
;
242 fptr
= bfd_get_filename (abfd
);
243 fname
= strdup (fptr
);
245 /* Strip VMS path. */
246 fout
= strrchr (fname
, ']');
248 fout
= strchr (fname
, ':');
254 /* Strip UNIX path. */
255 fptr
= strrchr (fout
, '/');
259 /* Strip .obj suffix. */
260 fptr
= strrchr (fout
, '.');
261 if (fptr
!= 0 && strcasecmp (fptr
, ".OBJ") == 0)
264 /* Convert to upper case and truncate at 31 characters.
265 (VMS object file format restricts module name length to 31). */
269 *fptr
= TOUPPER (*fptr
);
271 if (*fptr
== ';' || (fptr
- fout
) >= 31)
274 _bfd_vms_output_counted (abfd
, fout
);
278 _bfd_vms_output_counted (abfd
, "NONAME");
280 _bfd_vms_output_counted (abfd
, BFD_VERSION_STRING
);
281 _bfd_vms_output_dump (abfd
, get_vms_time_string (), EMH_DATE_LENGTH
);
282 _bfd_vms_output_fill (abfd
, 0, EMH_DATE_LENGTH
);
283 _bfd_vms_output_flush (abfd
);
286 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_LNM
);
287 snprintf (version
, sizeof (version
), "GAS BFD v%s", BFD_VERSION_STRING
);
288 _bfd_vms_output_dump (abfd
, (unsigned char *)version
, strlen (version
));
289 _bfd_vms_output_flush (abfd
);
292 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_SRC
);
294 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
296 symbol
= abfd
->outsymbols
[symnum
];
298 if (symbol
->flags
& BSF_FILE
)
300 if (CONST_STRNEQ ((char *)symbol
->name
, "<CASE:"))
302 PRIV (flag_hash_long_names
) = symbol
->name
[6] - '0';
303 PRIV (flag_show_after_trunc
) = symbol
->name
[7] - '0';
311 _bfd_vms_output_dump (abfd
, (unsigned char *) symbol
->name
,
312 (int) strlen (symbol
->name
));
319 if (symnum
== abfd
->symcount
)
320 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("noname"));
322 _bfd_vms_output_flush (abfd
);
325 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_TTL
);
326 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("TTL"));
327 _bfd_vms_output_flush (abfd
);
330 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_CPR
);
331 _bfd_vms_output_dump (abfd
,
332 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
334 _bfd_vms_output_flush (abfd
);
339 /* Process EOM/EEOM record
340 return 0 on success, -1 on error. */
343 _bfd_vms_slurp_eom (bfd
*abfd
, int objtype
)
345 unsigned char *vms_rec
;
348 vms_debug(2, "EOM/EEOM\n");
351 vms_rec
= PRIV (vms_rec
);
353 if ((objtype
== OBJ_S_C_EOM
)
354 || (objtype
== OBJ_S_C_EOMW
))
359 PRIV (eom_data
).eom_l_total_lps
360 = bfd_getl32 (vms_rec
+ EEOM_S_L_TOTAL_LPS
);
361 PRIV (eom_data
).eom_w_comcod
= bfd_getl16 (vms_rec
+ EEOM_S_W_COMCOD
);
362 if (PRIV (eom_data
).eom_w_comcod
> 1)
364 (*_bfd_error_handler
) (_("Object module NOT error-free !\n"));
365 bfd_set_error (bfd_error_bad_value
);
368 PRIV (eom_data
).eom_has_transfer
= FALSE
;
369 if (PRIV (rec_size
) > 10)
371 PRIV (eom_data
).eom_has_transfer
= TRUE
;
372 PRIV (eom_data
).eom_b_tfrflg
= vms_rec
[EEOM_S_B_TFRFLG
];
373 PRIV (eom_data
).eom_l_psindx
374 = bfd_getl32 (vms_rec
+ EEOM_S_L_PSINDX
);
375 PRIV (eom_data
).eom_l_tfradr
376 = bfd_getl32 (vms_rec
+ EEOM_S_L_TFRADR
);
378 abfd
->start_address
= PRIV (eom_data
).eom_l_tfradr
;
384 /* Write eom record for bfd abfd. */
387 _bfd_vms_write_eom (bfd
*abfd
, int objtype
)
390 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd
, objtype
);
393 _bfd_vms_output_begin (abfd
, objtype
, -1);
394 _bfd_vms_output_long (abfd
, (unsigned long) (PRIV (vms_linkage_index
) >> 1));
395 _bfd_vms_output_byte (abfd
, 0); /* Completion code. */
396 _bfd_vms_output_byte (abfd
, 0); /* Fill byte. */
398 if (bfd_get_start_address (abfd
) != (bfd_vma
)-1)
402 section
= bfd_get_section_by_name (abfd
, ".link");
405 bfd_set_error (bfd_error_nonrepresentable_section
);
408 _bfd_vms_output_short (abfd
, 0);
409 _bfd_vms_output_long (abfd
, (unsigned long) (section
->index
));
410 _bfd_vms_output_long (abfd
,
411 (unsigned long) bfd_get_start_address (abfd
));
412 _bfd_vms_output_long (abfd
, 0);
415 _bfd_vms_output_end (abfd
);
419 /* Read & process IHD/EIHD record.
420 Return 0 on success, -1 on error */
422 _bfd_vms_slurp_ihd (bfd
*abfd
, unsigned int *isd_offset
,
423 unsigned int *ihs_offset
)
425 unsigned int imgtype
, size
;
429 vms_debug (8, "_bfd_vms_slurp_ihd\n");
432 size
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SIZE
);
433 imgtype
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_IMGTYPE
);
435 if (imgtype
== EIHD_S_K_EXE
)
436 abfd
->flags
|= EXEC_P
;
438 symvva
= bfd_getl64 (PRIV (vms_rec
) + EIHD_S_Q_SYMVVA
);
441 PRIV (symvva
) = symvva
;
442 abfd
->flags
|= DYNAMIC
;
445 *isd_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_ISDOFF
);
446 *ihs_offset
= bfd_getl32 (PRIV (vms_rec
) + EIHD_S_L_SYMDBGOFF
);
449 vms_debug (4, "EIHD record size %d imgtype %d symvva 0x%llx isd %d ihs %d\n",
450 size
, imgtype
, symvva
, *isd_offset
, *ihs_offset
);
456 /* Read & process ISD/EISD record
457 return 0 on success, -1 on error */
460 _bfd_vms_slurp_isd (bfd
*abfd
, unsigned int offset
)
462 int section_count
= 0;
464 unsigned int rec_size
;
467 vms_debug (8, "_bfd_vms_slurp_isd\n");
470 for (p
= PRIV (vms_rec
) + offset
;
471 (rec_size
= bfd_getl32 (p
+ EISD_S_L_EISDSIZE
)) != 0;
474 unsigned long long vaddr
= bfd_getl64 (p
+ EISD_S_Q_VIR_ADDR
);
475 unsigned int size
= bfd_getl32 (p
+ EISD_S_L_SECSIZE
);
476 unsigned int flags
= bfd_getl32 (p
+ EISD_S_L_FLAGS
);
477 unsigned int vbn
= bfd_getl32 (p
+ EISD_S_L_VBN
);
483 vms_debug (4, "EISD record at 0x%x size 0x%x addr 0x%x bfd_flags 0x%x block %d\n",
484 p
- PRIV (vms_rec
), size
, vaddr
, flags
, vbn
);
487 /* VMS combines psects from .obj files into isects in the .exe. This
488 process doesn't preserve enough information to reliably determine
489 what's in each section without examining the data. This is
490 especially true of DWARF debug sections. */
491 bfd_flags
= SEC_ALLOC
;
493 if (flags
& EISD_S_M_EXE
)
494 bfd_flags
|= SEC_CODE
| SEC_HAS_CONTENTS
| SEC_LOAD
;
496 if (flags
& EISD_S_M_NONSHRADR
)
497 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
499 if (!(flags
& EISD_S_M_WRT
))
500 bfd_flags
|= SEC_READONLY
;
502 if (flags
& EISD_S_M_DZRO
)
503 bfd_flags
|= SEC_DATA
;
505 if (flags
& EISD_S_M_FIXUPVEC
)
506 bfd_flags
|= SEC_DATA
| SEC_HAS_CONTENTS
| SEC_LOAD
;
508 if (flags
& EISD_S_M_CRF
)
509 bfd_flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
;
511 if (flags
& EISD_S_M_GBL
)
513 name
= _bfd_vms_save_counted_string (p
+ EISD_S_T_GBLNAM
);
514 bfd_flags
|= SEC_COFF_SHARED_LIBRARY
;
515 bfd_flags
&= ~(SEC_ALLOC
| SEC_LOAD
);
519 name
= (char*) bfd_alloc (abfd
, 32);
520 sprintf (name
, "$LOCAL_%03d$", section_count
++);
523 section
= bfd_make_section (abfd
, name
);
528 section
->filepos
= vbn
? VMS_BLOCK_SIZE
* (vbn
- 1) : (unsigned int)-1;
529 section
->size
= size
;
530 section
->vma
= vaddr
;
532 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
539 /* Read & process IHS/EIHS record
540 return 0 on success, -1 on error */
542 _bfd_vms_slurp_ihs (bfd
*abfd
, unsigned int offset
)
544 unsigned char *p
= PRIV (vms_rec
) + offset
;
545 unsigned int gstvbn
= bfd_getl32 (p
+ EIHS_S_L_GSTVBN
);
546 unsigned int gstsize ATTRIBUTE_UNUSED
= bfd_getl32 (p
+ EIHS_S_L_GSTSIZE
);
547 unsigned int dstvbn
= bfd_getl32 (p
+ EIHS_S_L_DSTVBN
);
548 unsigned int dstsize
= bfd_getl32 (p
+ EIHS_S_L_DSTSIZE
);
549 unsigned int dmtvbn
= bfd_getl32 (p
+ EIHS_S_L_DMTVBN
);
550 unsigned int dmtbytes
= bfd_getl32 (p
+ EIHS_S_L_DMTBYTES
);
554 vms_debug (8, "_bfd_vms_slurp_ihs\n");
555 vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
556 gstvbn
, gstsize
, dstvbn
, dstsize
, dmtvbn
, dmtbytes
);
561 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
563 section
= bfd_make_section (abfd
, "$DST$");
567 section
->size
= dstsize
;
568 section
->filepos
= VMS_BLOCK_SIZE
* (dstvbn
- 1);
570 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
573 PRIV (dst_section
) = section
;
574 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
579 flagword bfd_flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
;
581 section
= bfd_make_section (abfd
, "$DMT$");
585 section
->size
= dmtbytes
;
586 section
->filepos
= VMS_BLOCK_SIZE
* (dmtvbn
- 1);
588 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
594 flagword bfd_flags
= SEC_HAS_CONTENTS
;
596 section
= bfd_make_section (abfd
, "$GST$");
600 if (bfd_seek (abfd
, VMS_BLOCK_SIZE
* (gstvbn
- 1), SEEK_SET
))
602 bfd_set_error (bfd_error_file_truncated
);
606 if (_bfd_vms_slurp_object_records (abfd
) != 0)
609 section
->filepos
= VMS_BLOCK_SIZE
* (gstvbn
- 1);
610 section
->size
= bfd_tell (abfd
) - section
->filepos
;
612 if (!bfd_set_section_flags (abfd
, section
, bfd_flags
))
615 abfd
->flags
|= HAS_SYMS
;
621 /* Build a new module for the specified BFD. */
623 static struct module
*
624 new_module (bfd
*abfd
)
626 struct module
*module
627 = (struct module
*) bfd_zalloc (abfd
, sizeof (struct module
));
628 module
->file_table_count
= 16; /* Arbitrary. */
630 = bfd_malloc (module
->file_table_count
* sizeof (struct fileinfo
));
634 /* Parse debug info for a module and internalize it. */
637 parse_module (bfd
*abfd
, struct module
*module
, unsigned char *ptr
,
640 unsigned char *maxptr
= ptr
+ length
, *src_ptr
, *pcl_ptr
;
641 unsigned int prev_linum
= 0, curr_linenum
= 0;
642 bfd_vma prev_pc
= 0, curr_pc
= 0;
643 struct srecinfo
*curr_srec
, *srec
;
644 struct lineinfo
*curr_line
, *line
;
645 struct funcinfo
*funcinfo
;
647 /* Initialize tables with zero element. */
648 curr_srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
649 module
->srec_table
= curr_srec
;
651 curr_line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
652 module
->line_table
= curr_line
;
656 /* The first byte is not counted in the recorded length. */
657 int rec_length
= bfd_getl16 (ptr
) + 1;
658 int rec_type
= bfd_getl16 (ptr
+ 2);
661 _bfd_vms_debug (2, "DST record: length %d, type %d\n",
662 rec_length
, rec_type
);
669 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_MODBEG_NAME
);
677 _bfd_vms_debug (3, "module: %s\n", module
->name
);
683 _bfd_vms_debug (3, "end module\n");
688 funcinfo
= (struct funcinfo
*)
689 bfd_zalloc (abfd
, sizeof (struct funcinfo
));
691 = _bfd_vms_save_counted_string (ptr
+ DST_S_B_RTNBEG_NAME
);
692 funcinfo
->low
= bfd_getl32 (ptr
+ DST_S_L_RTNBEG_ADDRESS
);
693 funcinfo
->next
= module
->func_table
;
694 module
->func_table
= funcinfo
;
697 _bfd_vms_debug (3, "routine: %s at 0x%x\n",
698 funcinfo
->name
, funcinfo
->low
);
703 module
->func_table
->high
= module
->func_table
->low
704 + bfd_getl32 (ptr
+ DST_S_L_RTNEND_SIZE
) - 1;
706 if (module
->func_table
->high
> module
->high
)
707 module
->high
= module
->func_table
->high
;
710 _bfd_vms_debug (3, "end routine\n");
716 _bfd_vms_debug (3, "prologue\n");
722 _bfd_vms_debug (3, "epilog\n");
728 _bfd_vms_debug (3, "block\n");
734 _bfd_vms_debug (3, "end block\n");
739 src_ptr
= ptr
+ DST_S_C_SOURCE_HEADER_SIZE
;
742 _bfd_vms_debug (3, "source info\n");
745 while (src_ptr
< ptr
+ rec_length
)
747 int cmd
= src_ptr
[0], cmd_length
, data
;
751 case DST_S_C_SRC_DECLFILE
:
754 = bfd_getl16 (src_ptr
+ DST_S_W_SRC_DF_FILEID
);
756 = _bfd_vms_save_counted_string (src_ptr
757 + DST_S_B_SRC_DF_FILENAME
);
759 while (fileid
>= module
->file_table_count
)
761 module
->file_table_count
*= 2;
763 = bfd_realloc (module
->file_table
,
764 module
->file_table_count
765 * sizeof (struct fileinfo
));
768 module
->file_table
[fileid
].name
= filename
;
769 module
->file_table
[fileid
].srec
= 1;
770 cmd_length
= src_ptr
[DST_S_B_SRC_DF_LENGTH
] + 2;
772 _bfd_vms_debug (4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
774 module
->file_table
[fileid
].name
);
779 case DST_S_C_SRC_DEFLINES_B
:
780 /* Perform the association and set the next higher index
782 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
783 srec
= (struct srecinfo
*)
784 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
785 srec
->line
= curr_srec
->line
+ data
;
786 srec
->srec
= curr_srec
->srec
+ data
;
787 srec
->sfile
= curr_srec
->sfile
;
788 curr_srec
->next
= srec
;
792 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_B: %d\n", data
);
796 case DST_S_C_SRC_DEFLINES_W
:
797 /* Perform the association and set the next higher index
799 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
800 srec
= (struct srecinfo
*)
801 bfd_zalloc (abfd
, sizeof (struct srecinfo
));
802 srec
->line
= curr_srec
->line
+ data
;
803 srec
->srec
= curr_srec
->srec
+ data
,
804 srec
->sfile
= curr_srec
->sfile
;
805 curr_srec
->next
= srec
;
809 _bfd_vms_debug (4, "DST_S_C_SRC_DEFLINES_W: %d\n", data
);
813 case DST_S_C_SRC_INCRLNUM_B
:
814 data
= src_ptr
[DST_S_B_SRC_UNSBYTE
];
815 curr_srec
->line
+= data
;
818 _bfd_vms_debug (4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data
);
822 case DST_S_C_SRC_SETFILE
:
823 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
824 curr_srec
->sfile
= data
;
825 curr_srec
->srec
= module
->file_table
[data
].srec
;
828 _bfd_vms_debug (4, "DST_S_C_SRC_SETFILE: %d\n", data
);
832 case DST_S_C_SRC_SETLNUM_L
:
833 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
834 curr_srec
->line
= data
;
837 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_L: %d\n", data
);
841 case DST_S_C_SRC_SETLNUM_W
:
842 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
843 curr_srec
->line
= data
;
846 _bfd_vms_debug (4, "DST_S_C_SRC_SETLNUM_W: %d\n", data
);
850 case DST_S_C_SRC_SETREC_L
:
851 data
= bfd_getl32 (src_ptr
+ DST_S_L_SRC_UNSLONG
);
852 curr_srec
->srec
= data
;
853 module
->file_table
[curr_srec
->sfile
].srec
= data
;
856 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_L: %d\n", data
);
860 case DST_S_C_SRC_SETREC_W
:
861 data
= bfd_getl16 (src_ptr
+ DST_S_W_SRC_UNSWORD
);
862 curr_srec
->srec
= data
;
863 module
->file_table
[curr_srec
->sfile
].srec
= data
;
866 _bfd_vms_debug (4, "DST_S_C_SRC_SETREC_W: %d\n", data
);
870 case DST_S_C_SRC_FORMFEED
:
873 _bfd_vms_debug (4, "DST_S_C_SRC_FORMFEED\n");
878 (*_bfd_error_handler
) (_("unknown source command %d"),
884 src_ptr
+= cmd_length
;
888 case DST_S_C_LINE_NUM
:
889 pcl_ptr
= ptr
+ DST_S_C_LINE_NUM_HEADER_SIZE
;
892 _bfd_vms_debug (3, "line info\n");
895 while (pcl_ptr
< ptr
+ rec_length
)
897 /* The command byte is signed so we must sign-extend it. */
898 int cmd
= ((signed char *)pcl_ptr
)[0], cmd_length
, data
;
902 case DST_S_C_DELTA_PC_W
:
903 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
908 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_W: %d\n", data
);
912 case DST_S_C_DELTA_PC_L
:
913 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
918 _bfd_vms_debug (4, "DST_S_C_DELTA_PC_L: %d\n", data
);
922 case DST_S_C_INCR_LINUM
:
923 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
924 curr_linenum
+= data
;
927 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM: %d\n", data
);
931 case DST_S_C_INCR_LINUM_W
:
932 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
933 curr_linenum
+= data
;
936 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_W: %d\n", data
);
940 case DST_S_C_INCR_LINUM_L
:
941 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
942 curr_linenum
+= data
;
945 _bfd_vms_debug (4, "DST_S_C_INCR_LINUM_L: %d\n", data
);
949 case DST_S_C_SET_LINUM_INCR
:
950 (*_bfd_error_handler
)
951 (_("DST_S_C_SET_LINUM_INCR not implemented"));
955 case DST_S_C_SET_LINUM_INCR_W
:
956 (*_bfd_error_handler
)
957 (_("DST_S_C_SET_LINUM_INCR_W not implemented"));
961 case DST_S_C_RESET_LINUM_INCR
:
962 (*_bfd_error_handler
)
963 (_("DST_S_C_RESET_LINUM_INCR not implemented"));
967 case DST_S_C_BEG_STMT_MODE
:
968 (*_bfd_error_handler
)
969 (_("DST_S_C_BEG_STMT_MODE not implemented"));
973 case DST_S_C_END_STMT_MODE
:
974 (*_bfd_error_handler
)
975 (_("DST_S_C_END_STMT_MODE not implemented"));
979 case DST_S_C_SET_LINUM_B
:
980 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
984 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_B: %d\n", data
);
988 case DST_S_C_SET_LINE_NUM
:
989 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
993 _bfd_vms_debug (4, "DST_S_C_SET_LINE_NUM: %d\n", data
);
997 case DST_S_C_SET_LINUM_L
:
998 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1002 _bfd_vms_debug (4, "DST_S_C_SET_LINUM_L: %d\n", data
);
1006 case DST_S_C_SET_PC
:
1007 (*_bfd_error_handler
)
1008 (_("DST_S_C_SET_PC not implemented"));
1012 case DST_S_C_SET_PC_W
:
1013 (*_bfd_error_handler
)
1014 (_("DST_S_C_SET_PC_W not implemented"));
1018 case DST_S_C_SET_PC_L
:
1019 (*_bfd_error_handler
)
1020 (_("DST_S_C_SET_PC_L not implemented"));
1024 case DST_S_C_SET_STMTNUM
:
1025 (*_bfd_error_handler
)
1026 (_("DST_S_C_SET_STMTNUM not implemented"));
1031 data
= pcl_ptr
[DST_S_B_PCLINE_UNSBYTE
];
1035 _bfd_vms_debug (4, "DST_S_C_TERM: %d\n", data
);
1039 case DST_S_C_TERM_W
:
1040 data
= bfd_getl16 (pcl_ptr
+ DST_S_W_PCLINE_UNSWORD
);
1044 _bfd_vms_debug (4, "DST_S_C_TERM_W: %d\n", data
);
1048 case DST_S_C_TERM_L
:
1049 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1053 _bfd_vms_debug (4, "DST_S_C_TERM_L: %d\n", data
);
1057 case DST_S_C_SET_ABS_PC
:
1058 data
= bfd_getl32 (pcl_ptr
+ DST_S_L_PCLINE_UNSLONG
);
1062 _bfd_vms_debug (4, "DST_S_C_SET_ABS_PC: 0x%x\n", data
);
1073 _bfd_vms_debug (4, "bump pc to 0x%llx and line to %d\n",
1074 curr_pc
, curr_linenum
);
1079 (*_bfd_error_handler
) (_("unknown line command %d"),
1086 if ((curr_linenum
!= prev_linum
&& curr_pc
!= prev_pc
)
1088 || cmd
== DST_S_C_DELTA_PC_L
1089 || cmd
== DST_S_C_DELTA_PC_W
)
1091 line
= (struct lineinfo
*)
1092 bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1093 line
->address
= curr_pc
;
1094 line
->line
= curr_linenum
;
1096 curr_line
->next
= line
;
1099 prev_linum
= curr_linenum
;
1102 _bfd_vms_debug (4, "-> correlate pc 0x%llx with line %d\n",
1103 curr_pc
, curr_linenum
);
1107 pcl_ptr
+= cmd_length
;
1111 case 0x17: /* Undocumented type used by DEC C to declare equates. */
1113 _bfd_vms_debug (3, "undocumented type 0x17\n");
1119 _bfd_vms_debug (3, "ignoring record\n");
1128 /* Finalize tables with EOL marker. */
1129 srec
= (struct srecinfo
*) bfd_zalloc (abfd
, sizeof (struct srecinfo
));
1130 srec
->line
= (unsigned int) -1;
1131 srec
->srec
= (unsigned int) -1;
1132 curr_srec
->next
= srec
;
1134 line
= (struct lineinfo
*) bfd_zalloc (abfd
, sizeof (struct lineinfo
));
1135 line
->line
= (unsigned int) -1;
1136 line
->address
= (bfd_vma
) -1;
1137 curr_line
->next
= line
;
1139 /* Advertise that this module has been parsed. This is needed
1140 because parsing can be either performed at module creation
1141 or deferred until debug info is consumed. */
1142 SET_MODULE_PARSED (module
);
1145 /* Build the list of modules for the specified BFD. */
1147 static struct module
*
1148 build_module_list (bfd
*abfd
)
1150 struct module
*module
, *list
= NULL
;
1153 if ((dmt
= bfd_get_section_by_name (abfd
, "$DMT$")))
1155 /* We have a DMT section so this must be an image. Parse the
1156 section and build the list of modules. This is sufficient
1157 since we can compute the start address and the end address
1158 of every module from the section contents. */
1159 bfd_size_type size
= bfd_get_section_size (dmt
);
1160 unsigned char *ptr
, *end
;
1162 ptr
= (unsigned char *) bfd_alloc (abfd
, size
);
1166 if (! bfd_get_section_contents (abfd
, dmt
, ptr
, 0, size
))
1170 _bfd_vms_debug (2, "DMT\n");
1177 /* Each header declares a module with its start offset and size
1178 of debug info in the DST section, as well as the count of
1179 program sections (i.e. address spans) it contains. */
1180 int modbeg
= bfd_getl32 (ptr
+ DBG_S_L_DMT_MODBEG
);
1181 int size
= bfd_getl32 (ptr
+ DBG_S_L_DST_SIZE
);
1182 int count
= bfd_getl16 (ptr
+ DBG_S_W_DMT_PSECT_COUNT
);
1183 ptr
+= DBG_S_C_DMT_HEADER_SIZE
;
1186 _bfd_vms_debug (3, "module: modbeg = %d, size = %d, count = %d\n",
1187 modbeg
, size
, count
);
1190 /* We create a 'module' structure for each program section since
1191 we only support contiguous addresses in a 'module' structure.
1192 As a consequence, the actual debug info in the DST section is
1193 shared and can be parsed multiple times; that doesn't seem to
1194 cause problems in practice. */
1197 int start
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_START
);
1198 int length
= bfd_getl32 (ptr
+ DBG_S_L_DMT_PSECT_LENGTH
);
1199 module
= new_module (abfd
);
1200 module
->modbeg
= modbeg
;
1201 module
->size
= size
;
1202 module
->low
= start
;
1203 module
->high
= start
+ length
;
1204 module
->next
= list
;
1206 ptr
+= DBG_S_C_DMT_PSECT_SIZE
;
1209 _bfd_vms_debug (4, "section: start = 0x%x, length = %d\n",
1217 /* We don't have a DMT section so this must be an object. Parse
1218 the module right now in order to compute its start address and
1220 module
= new_module (abfd
);
1221 parse_module (abfd
, module
, PRIV (dst_section
)->contents
,
1222 PRIV (dst_ptr_end
) - PRIV (dst_section
)->contents
);
1229 /* Calculate and return the name of the source file and the line nearest
1230 to the wanted location in the specified module. */
1233 module_find_nearest_line (bfd
*abfd
, struct module
*module
, bfd_vma addr
,
1234 const char **file
, const char **func
,
1237 struct funcinfo
*funcinfo
;
1238 struct lineinfo
*lineinfo
;
1239 struct srecinfo
*srecinfo
;
1240 bfd_boolean ret
= FALSE
;
1242 /* Parse this module if that was not done at module creation. */
1243 if (! IS_MODULE_PARSED (module
))
1245 unsigned int size
= module
->size
;
1246 unsigned int modbeg
= PRIV (dst_section
)->filepos
+ module
->modbeg
;
1247 unsigned char *buffer
= (unsigned char *) bfd_malloc (module
->size
);
1249 if (bfd_seek (abfd
, modbeg
, SEEK_SET
) != 0
1250 || bfd_bread (buffer
, size
, abfd
) != size
)
1252 bfd_set_error (bfd_error_no_debug_section
);
1256 parse_module (abfd
, module
, buffer
, size
);
1260 /* Find out the function (if any) that contains the address. */
1261 for (funcinfo
= module
->func_table
; funcinfo
; funcinfo
= funcinfo
->next
)
1262 if (addr
>= funcinfo
->low
&& addr
<= funcinfo
->high
)
1264 *func
= funcinfo
->name
;
1269 /* Find out the source file and the line nearest to the address. */
1270 for (lineinfo
= module
->line_table
; lineinfo
; lineinfo
= lineinfo
->next
)
1271 if (lineinfo
->next
&& addr
< lineinfo
->next
->address
)
1273 for (srecinfo
= module
->srec_table
; srecinfo
; srecinfo
= srecinfo
->next
)
1274 if (srecinfo
->next
&& lineinfo
->line
< srecinfo
->next
->line
)
1276 if (srecinfo
->sfile
> 0)
1278 *file
= module
->file_table
[srecinfo
->sfile
].name
;
1279 *line
= srecinfo
->srec
+ lineinfo
->line
- srecinfo
->line
;
1283 *file
= module
->name
;
1284 *line
= lineinfo
->line
;
1295 /* Provided a BFD, a section and an offset into the section, calculate and
1296 return the name of the source file and the line nearest to the wanted
1300 _bfd_vms_find_nearest_dst_line (bfd
*abfd
, asection
*section
,
1301 asymbol
**symbols ATTRIBUTE_UNUSED
,
1302 bfd_vma offset
, const char **file
,
1303 const char **func
, unsigned int *line
)
1305 struct module
*module
;
1307 /* What address are we looking for? */
1308 bfd_vma addr
= section
->vma
+ offset
;
1314 if (PRIV (dst_section
) == NULL
)
1317 if (PRIV (modules
) == NULL
)
1319 PRIV (modules
) = build_module_list (abfd
);
1320 if (PRIV (modules
) == NULL
)
1324 for (module
= PRIV (modules
); module
; module
= module
->next
)
1325 if (addr
>= module
->low
&& addr
<= module
->high
)
1326 return module_find_nearest_line (abfd
, module
, addr
, file
, func
, line
);
1331 /* Process EDBG/ETBT record.
1332 Return 0 on success, -1 on error */
1335 vms_slurp_debug (bfd
*abfd
)
1337 if (PRIV (dst_section
) == NULL
)
1339 /* We have no way to find out beforehand how much debug info there
1340 is in an object file, so pick an initial amount and grow it as
1342 flagword flags
= SEC_HAS_CONTENTS
| SEC_DEBUGGING
| SEC_RELOC
;
1343 asection
*section
= bfd_make_section (abfd
, "$DST$");
1346 section
->size
= 1024;
1347 if (!bfd_set_section_flags (abfd
, section
, flags
))
1349 section
->contents
= ((unsigned char *)
1350 bfd_zmalloc (section
->size
));
1351 if (section
->contents
== NULL
)
1353 section
->filepos
= (unsigned int)-1;
1354 PRIV (dst_section
) = section
;
1357 PRIV (image_section
) = PRIV (dst_section
);
1358 PRIV (image_ptr
) = PRIV (dst_section
)->contents
;
1360 return _bfd_vms_slurp_tir (abfd
, EOBJ_S_C_ETIR
);
1363 /* Process DBG/EDBG record.
1364 Return 0 on success, -1 on error. */
1367 _bfd_vms_slurp_dbg (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1370 _bfd_vms_debug (2, "DBG/EDBG\n");
1373 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1375 return vms_slurp_debug (abfd
);
1378 /* Process TBT/ETBT record.
1379 Return 0 on success, -1 on error. */
1382 _bfd_vms_slurp_tbt (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
1385 _bfd_vms_debug (2, "TBT/ETBT\n");
1388 abfd
->flags
|= HAS_LINENO
;
1390 return vms_slurp_debug (abfd
);
1393 /* Write DBG/EDBG record. */
1396 _bfd_vms_write_dbg (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1399 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);
1405 /* Write TBT/ETBT record. */
1408 _bfd_vms_write_tbt (bfd
*abfd ATTRIBUTE_UNUSED
, int objtype ATTRIBUTE_UNUSED
)
1411 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);