PR binutils/2768
[binutils.git] / gas / dwarf2dbg.c
blob22dde6a0194dd56f9025a1cbda7072baa39b906e
1 /* dwarf2dbg.c - DWARF2 debug support
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 /* Logical line numbers can be controlled by the compiler via the
24 following directives:
26 .file FILENO "file.c"
27 .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \
28 [epilogue_begin] [is_stmt VALUE] [isa VALUE]
31 #include "as.h"
32 #include "safe-ctype.h"
34 #ifdef HAVE_LIMITS_H
35 #include <limits.h>
36 #else
37 #ifdef HAVE_SYS_PARAM_H
38 #include <sys/param.h>
39 #endif
40 #ifndef INT_MAX
41 #define INT_MAX (int) (((unsigned) (-1)) >> 1)
42 #endif
43 #endif
45 #include "dwarf2dbg.h"
46 #include <filenames.h>
48 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
49 /* We need to decide which character to use as a directory separator.
50 Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not
51 necessarily mean that the backslash character is the one to use.
52 Some environments, eg Cygwin, can support both naming conventions.
53 So we use the heuristic that we only need to use the backslash if
54 the path is an absolute path starting with a DOS style drive
55 selector. eg C: or D: */
56 # define INSERT_DIR_SEPARATOR(string, offset) \
57 do \
58 { \
59 if (offset > 1 \
60 && string[0] != 0 \
61 && string[1] == ':') \
62 string [offset] = '\\'; \
63 else \
64 string [offset] = '/'; \
65 } \
66 while (0)
67 #else
68 # define INSERT_DIR_SEPARATOR(string, offset) string[offset] = '/'
69 #endif
71 #ifndef DWARF2_FORMAT
72 # define DWARF2_FORMAT() dwarf2_format_32bit
73 #endif
75 #ifndef DWARF2_ADDR_SIZE
76 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
77 #endif
79 #include "subsegs.h"
81 #include "elf/dwarf2.h"
83 /* Since we can't generate the prolog until the body is complete, we
84 use three different subsegments for .debug_line: one holding the
85 prolog, one for the directory and filename info, and one for the
86 body ("statement program"). */
87 #define DL_PROLOG 0
88 #define DL_FILES 1
89 #define DL_BODY 2
91 /* First special line opcde - leave room for the standard opcodes.
92 Note: If you want to change this, you'll have to update the
93 "standard_opcode_lengths" table that is emitted below in
94 out_debug_line(). */
95 #define DWARF2_LINE_OPCODE_BASE 13
97 #ifndef DWARF2_LINE_BASE
98 /* Minimum line offset in a special line info. opcode. This value
99 was chosen to give a reasonable range of values. */
100 # define DWARF2_LINE_BASE -5
101 #endif
103 /* Range of line offsets in a special line info. opcode. */
104 #ifndef DWARF2_LINE_RANGE
105 # define DWARF2_LINE_RANGE 14
106 #endif
108 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
109 /* Define the architecture-dependent minimum instruction length (in
110 bytes). This value should be rather too small than too big. */
111 # define DWARF2_LINE_MIN_INSN_LENGTH 1
112 #endif
114 /* Flag that indicates the initial value of the is_stmt_start flag. */
115 #define DWARF2_LINE_DEFAULT_IS_STMT 1
117 /* Given a special op, return the line skip amount. */
118 #define SPECIAL_LINE(op) \
119 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
121 /* Given a special op, return the address skip amount (in units of
122 DWARF2_LINE_MIN_INSN_LENGTH. */
123 #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
125 /* The maximum address skip amount that can be encoded with a special op. */
126 #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
128 struct line_entry {
129 struct line_entry *next;
130 symbolS *label;
131 struct dwarf2_line_info loc;
134 struct line_subseg {
135 struct line_subseg *next;
136 subsegT subseg;
137 struct line_entry *head;
138 struct line_entry **ptail;
141 struct line_seg {
142 struct line_seg *next;
143 segT seg;
144 struct line_subseg *head;
145 symbolS *text_start;
146 symbolS *text_end;
149 /* Collects data for all line table entries during assembly. */
150 static struct line_seg *all_segs;
152 struct file_entry {
153 const char *filename;
154 unsigned int dir;
157 /* Table of files used by .debug_line. */
158 static struct file_entry *files;
159 static unsigned int files_in_use;
160 static unsigned int files_allocated;
162 /* Table of directories used by .debug_line. */
163 static char **dirs;
164 static unsigned int dirs_in_use;
165 static unsigned int dirs_allocated;
167 /* TRUE when we've seen a .loc directive recently. Used to avoid
168 doing work when there's nothing to do. */
169 static bfd_boolean loc_directive_seen;
171 /* TRUE when we're supposed to set the basic block mark whenever a
172 label is seen. */
173 bfd_boolean dwarf2_loc_mark_labels;
175 /* Current location as indicated by the most recent .loc directive. */
176 static struct dwarf2_line_info current = {
177 1, 1, 0, 0,
178 DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0
181 /* The size of an address on the target. */
182 static unsigned int sizeof_address;
184 static struct line_subseg *get_line_subseg (segT, subsegT);
185 static unsigned int get_filenum (const char *, unsigned int);
186 static struct frag *first_frag_for_seg (segT);
187 static struct frag *last_frag_for_seg (segT);
188 static void out_byte (int);
189 static void out_opcode (int);
190 static void out_two (int);
191 static void out_four (int);
192 static void out_abbrev (int, int);
193 static void out_uleb128 (addressT);
194 static offsetT get_frag_fix (fragS *, segT);
195 static void out_set_addr (symbolS *);
196 static int size_inc_line_addr (int, addressT);
197 static void emit_inc_line_addr (int, addressT, char *, int);
198 static void out_inc_line_addr (int, addressT);
199 static void relax_inc_line_addr (int, symbolS *, symbolS *);
200 static void process_entries (segT, struct line_entry *);
201 static void out_file_list (void);
202 static void out_debug_line (segT);
203 static void out_debug_aranges (segT, segT);
204 static void out_debug_abbrev (segT);
206 #ifndef TC_DWARF2_EMIT_OFFSET
207 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
209 /* Create an offset to .dwarf2_*. */
211 static void
212 generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
214 expressionS expr;
216 expr.X_op = O_symbol;
217 expr.X_add_symbol = symbol;
218 expr.X_add_number = 0;
219 emit_expr (&expr, size);
221 #endif
223 /* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
225 static struct line_subseg *
226 get_line_subseg (segT seg, subsegT subseg)
228 static segT last_seg;
229 static subsegT last_subseg;
230 static struct line_subseg *last_line_subseg;
232 struct line_seg **ps, *s;
233 struct line_subseg **pss, *ss;
235 if (seg == last_seg && subseg == last_subseg)
236 return last_line_subseg;
238 for (ps = &all_segs; (s = *ps) != NULL; ps = &s->next)
239 if (s->seg == seg)
240 goto found_seg;
242 s = (struct line_seg *) xmalloc (sizeof (*s));
243 s->next = NULL;
244 s->seg = seg;
245 s->head = NULL;
246 *ps = s;
248 found_seg:
249 for (pss = &s->head; (ss = *pss) != NULL ; pss = &ss->next)
251 if (ss->subseg == subseg)
252 goto found_subseg;
253 if (ss->subseg > subseg)
254 break;
257 ss = (struct line_subseg *) xmalloc (sizeof (*ss));
258 ss->next = *pss;
259 ss->subseg = subseg;
260 ss->head = NULL;
261 ss->ptail = &ss->head;
262 *pss = ss;
264 found_subseg:
265 last_seg = seg;
266 last_subseg = subseg;
267 last_line_subseg = ss;
269 return ss;
272 /* Record an entry for LOC occurring at LABEL. */
274 static void
275 dwarf2_gen_line_info_1 (symbolS *label, struct dwarf2_line_info *loc)
277 struct line_subseg *ss;
278 struct line_entry *e;
280 e = (struct line_entry *) xmalloc (sizeof (*e));
281 e->next = NULL;
282 e->label = label;
283 e->loc = *loc;
285 ss = get_line_subseg (now_seg, now_subseg);
286 *ss->ptail = e;
287 ss->ptail = &e->next;
290 /* Record an entry for LOC occurring at OFS within the current fragment. */
292 void
293 dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
295 static unsigned int line = -1;
296 static unsigned int filenum = -1;
298 symbolS *sym;
300 /* Early out for as-yet incomplete location information. */
301 if (loc->filenum == 0 || loc->line == 0)
302 return;
304 /* Don't emit sequences of line symbols for the same line when the
305 symbols apply to assembler code. It is necessary to emit
306 duplicate line symbols when a compiler asks for them, because GDB
307 uses them to determine the end of the prologue. */
308 if (debug_type == DEBUG_DWARF2
309 && line == loc->line && filenum == loc->filenum)
310 return;
312 line = loc->line;
313 filenum = loc->filenum;
315 sym = symbol_temp_new (now_seg, ofs, frag_now);
316 dwarf2_gen_line_info_1 (sym, loc);
319 /* Returns the current source information. If .file directives have
320 been encountered, the info for the corresponding source file is
321 returned. Otherwise, the info for the assembly source file is
322 returned. */
324 void
325 dwarf2_where (struct dwarf2_line_info *line)
327 if (debug_type == DEBUG_DWARF2)
329 char *filename;
330 as_where (&filename, &line->line);
331 line->filenum = get_filenum (filename, 0);
332 line->column = 0;
333 line->flags = DWARF2_FLAG_IS_STMT;
334 line->isa = current.isa;
336 else
337 *line = current;
340 /* A hook to allow the target backend to inform the line number state
341 machine of isa changes when assembler debug info is enabled. */
343 void
344 dwarf2_set_isa (unsigned int isa)
346 current.isa = isa;
349 /* Called for each machine instruction, or relatively atomic group of
350 machine instructions (ie built-in macro). The instruction or group
351 is SIZE bytes in length. If dwarf2 line number generation is called
352 for, emit a line statement appropriately. */
354 void
355 dwarf2_emit_insn (int size)
357 struct dwarf2_line_info loc;
359 if (loc_directive_seen)
361 /* Use the last location established by a .loc directive, not
362 the value returned by dwarf2_where(). That calls as_where()
363 which will return either the logical input file name (foo.c)
364 or the physical input file name (foo.s) and not the file name
365 specified in the most recent .loc directive (eg foo.h). */
366 loc = current;
368 /* Unless we generate DWARF2 debugging information for each
369 assembler line, we only emit one line symbol for one LOC. */
370 if (debug_type != DEBUG_DWARF2)
371 loc_directive_seen = FALSE;
373 else if (debug_type != DEBUG_DWARF2)
374 return;
375 else
376 dwarf2_where (&loc);
378 dwarf2_gen_line_info (frag_now_fix () - size, &loc);
380 current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK
381 | DWARF2_FLAG_PROLOGUE_END
382 | DWARF2_FLAG_EPILOGUE_BEGIN);
385 /* Called for each (preferably code) label. If dwarf2_loc_mark_labels
386 is enabled, emit a basic block marker. */
388 void
389 dwarf2_emit_label (symbolS *label)
391 struct dwarf2_line_info loc;
393 if (!dwarf2_loc_mark_labels)
394 return;
395 if (S_GET_SEGMENT (label) != now_seg)
396 return;
397 if (!(bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE))
398 return;
400 if (debug_type == DEBUG_DWARF2)
401 dwarf2_where (&loc);
402 else
404 loc = current;
405 loc_directive_seen = FALSE;
408 loc.flags |= DWARF2_FLAG_BASIC_BLOCK;
410 current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK
411 | DWARF2_FLAG_PROLOGUE_END
412 | DWARF2_FLAG_EPILOGUE_BEGIN);
414 dwarf2_gen_line_info_1 (label, &loc);
417 /* Get a .debug_line file number for FILENAME. If NUM is nonzero,
418 allocate it on that file table slot, otherwise return the first
419 empty one. */
421 static unsigned int
422 get_filenum (const char *filename, unsigned int num)
424 static unsigned int last_used, last_used_dir_len;
425 const char *file;
426 size_t dir_len;
427 unsigned int i, dir;
429 if (num == 0 && last_used)
431 if (! files[last_used].dir
432 && strcmp (filename, files[last_used].filename) == 0)
433 return last_used;
434 if (files[last_used].dir
435 && strncmp (filename, dirs[files[last_used].dir],
436 last_used_dir_len) == 0
437 && IS_DIR_SEPARATOR (filename [last_used_dir_len])
438 && strcmp (filename + last_used_dir_len + 1,
439 files[last_used].filename) == 0)
440 return last_used;
443 file = lbasename (filename);
444 /* Don't make empty string from / or A: from A:/ . */
445 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
446 if (file <= filename + 3)
447 file = filename;
448 #else
449 if (file == filename + 1)
450 file = filename;
451 #endif
452 dir_len = file - filename;
454 dir = 0;
455 if (dir_len)
457 --dir_len;
458 for (dir = 1; dir < dirs_in_use; ++dir)
459 if (strncmp (filename, dirs[dir], dir_len) == 0
460 && dirs[dir][dir_len] == '\0')
461 break;
463 if (dir >= dirs_in_use)
465 if (dir >= dirs_allocated)
467 dirs_allocated = dir + 32;
468 dirs = (char **)
469 xrealloc (dirs, (dir + 32) * sizeof (const char *));
472 dirs[dir] = xmalloc (dir_len + 1);
473 memcpy (dirs[dir], filename, dir_len);
474 dirs[dir][dir_len] = '\0';
475 dirs_in_use = dir + 1;
479 if (num == 0)
481 for (i = 1; i < files_in_use; ++i)
482 if (files[i].dir == dir
483 && files[i].filename
484 && strcmp (file, files[i].filename) == 0)
486 last_used = i;
487 last_used_dir_len = dir_len;
488 return i;
491 else
492 i = num;
494 if (i >= files_allocated)
496 unsigned int old = files_allocated;
498 files_allocated = i + 32;
499 files = (struct file_entry *)
500 xrealloc (files, (i + 32) * sizeof (struct file_entry));
502 memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
505 files[i].filename = num ? file : xstrdup (file);
506 files[i].dir = dir;
507 if (files_in_use < i + 1)
508 files_in_use = i + 1;
509 last_used = i;
510 last_used_dir_len = dir_len;
512 return i;
515 /* Handle two forms of .file directive:
516 - Pass .file "source.c" to s_app_file
517 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
519 If an entry is added to the file table, return a pointer to the filename. */
521 char *
522 dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED)
524 offsetT num;
525 char *filename;
526 int filename_len;
528 /* Continue to accept a bare string and pass it off. */
529 SKIP_WHITESPACE ();
530 if (*input_line_pointer == '"')
532 s_app_file (0);
533 return NULL;
536 num = get_absolute_expression ();
537 filename = demand_copy_C_string (&filename_len);
538 if (filename == NULL)
539 return NULL;
540 demand_empty_rest_of_line ();
542 if (num < 1)
544 as_bad (_("file number less than one"));
545 return NULL;
548 if (num < (int) files_in_use && files[num].filename != 0)
550 as_bad (_("file number %ld already allocated"), (long) num);
551 return NULL;
554 get_filenum (filename, num);
556 return filename;
559 void
560 dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
562 offsetT filenum, line;
564 filenum = get_absolute_expression ();
565 SKIP_WHITESPACE ();
566 line = get_absolute_expression ();
568 if (filenum < 1)
570 as_bad (_("file number less than one"));
571 return;
573 if (filenum >= (int) files_in_use || files[filenum].filename == 0)
575 as_bad (_("unassigned file number %ld"), (long) filenum);
576 return;
579 current.filenum = filenum;
580 current.line = line;
582 #ifndef NO_LISTING
583 if (listing)
585 if (files[filenum].dir)
587 size_t dir_len = strlen (dirs[files[filenum].dir]);
588 size_t file_len = strlen (files[filenum].filename);
589 char *cp = (char *) alloca (dir_len + 1 + file_len + 1);
591 memcpy (cp, dirs[files[filenum].dir], dir_len);
592 INSERT_DIR_SEPARATOR (cp, dir_len);
593 memcpy (cp + dir_len + 1, files[filenum].filename, file_len);
594 cp[dir_len + file_len + 1] = '\0';
595 listing_source_file (cp);
597 else
598 listing_source_file (files[filenum].filename);
599 listing_source_line (line);
601 #endif
603 SKIP_WHITESPACE ();
604 if (ISDIGIT (*input_line_pointer))
606 current.column = get_absolute_expression ();
607 SKIP_WHITESPACE ();
610 while (ISALPHA (*input_line_pointer))
612 char *p, c;
613 offsetT value;
615 p = input_line_pointer;
616 c = get_symbol_end ();
618 if (strcmp (p, "basic_block") == 0)
620 current.flags |= DWARF2_FLAG_BASIC_BLOCK;
621 *input_line_pointer = c;
623 else if (strcmp (p, "prologue_end") == 0)
625 current.flags |= DWARF2_FLAG_PROLOGUE_END;
626 *input_line_pointer = c;
628 else if (strcmp (p, "epilogue_begin") == 0)
630 current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
631 *input_line_pointer = c;
633 else if (strcmp (p, "is_stmt") == 0)
635 *input_line_pointer = c;
636 value = get_absolute_expression ();
637 if (value == 0)
638 current.flags &= ~DWARF2_FLAG_IS_STMT;
639 else if (value == 1)
640 current.flags |= DWARF2_FLAG_IS_STMT;
641 else
643 as_bad (_("is_stmt value not 0 or 1"));
644 return;
647 else if (strcmp (p, "isa") == 0)
649 *input_line_pointer = c;
650 value = get_absolute_expression ();
651 if (value >= 0)
652 current.isa = value;
653 else
655 as_bad (_("isa number less than zero"));
656 return;
659 else
661 as_bad (_("unknown .loc sub-directive `%s'"), p);
662 *input_line_pointer = c;
663 return;
666 SKIP_WHITESPACE ();
669 demand_empty_rest_of_line ();
670 loc_directive_seen = TRUE;
673 void
674 dwarf2_directive_loc_mark_labels (int dummy ATTRIBUTE_UNUSED)
676 offsetT value = get_absolute_expression ();
678 if (value != 0 && value != 1)
680 as_bad (_("expected 0 or 1"));
681 ignore_rest_of_line ();
683 else
685 dwarf2_loc_mark_labels = value != 0;
686 demand_empty_rest_of_line ();
690 static struct frag *
691 first_frag_for_seg (segT seg)
693 return seg_info (seg)->frchainP->frch_root;
696 static struct frag *
697 last_frag_for_seg (segT seg)
699 frchainS *f = seg_info (seg)->frchainP;
701 while (f->frch_next != NULL)
702 f = f->frch_next;
704 return f->frch_last;
707 /* Emit a single byte into the current segment. */
709 static inline void
710 out_byte (int byte)
712 FRAG_APPEND_1_CHAR (byte);
715 /* Emit a statement program opcode into the current segment. */
717 static inline void
718 out_opcode (int opc)
720 out_byte (opc);
723 /* Emit a two-byte word into the current segment. */
725 static inline void
726 out_two (int data)
728 md_number_to_chars (frag_more (2), data, 2);
731 /* Emit a four byte word into the current segment. */
733 static inline void
734 out_four (int data)
736 md_number_to_chars (frag_more (4), data, 4);
739 /* Emit an unsigned "little-endian base 128" number. */
741 static void
742 out_uleb128 (addressT value)
744 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
747 /* Emit a tuple for .debug_abbrev. */
749 static inline void
750 out_abbrev (int name, int form)
752 out_uleb128 (name);
753 out_uleb128 (form);
756 /* Get the size of a fragment. */
758 static offsetT
759 get_frag_fix (fragS *frag, segT seg)
761 frchainS *fr;
763 if (frag->fr_next)
764 return frag->fr_fix;
766 /* If a fragment is the last in the chain, special measures must be
767 taken to find its size before relaxation, since it may be pending
768 on some subsegment chain. */
769 for (fr = seg_info (seg)->frchainP; fr; fr = fr->frch_next)
770 if (fr->frch_last == frag)
771 return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal;
773 abort ();
776 /* Set an absolute address (may result in a relocation entry). */
778 static void
779 out_set_addr (symbolS *sym)
781 expressionS expr;
783 out_opcode (DW_LNS_extended_op);
784 out_uleb128 (sizeof_address + 1);
786 out_opcode (DW_LNE_set_address);
787 expr.X_op = O_symbol;
788 expr.X_add_symbol = sym;
789 expr.X_add_number = 0;
790 emit_expr (&expr, sizeof_address);
793 #if DWARF2_LINE_MIN_INSN_LENGTH > 1
794 static void scale_addr_delta (addressT *);
796 static void
797 scale_addr_delta (addressT *addr_delta)
799 static int printed_this = 0;
800 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
802 if (!printed_this)
803 as_bad("unaligned opcodes detected in executable segment");
804 printed_this = 1;
806 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
808 #else
809 #define scale_addr_delta(A)
810 #endif
812 /* Encode a pair of line and address skips as efficiently as possible.
813 Note that the line skip is signed, whereas the address skip is unsigned.
815 The following two routines *must* be kept in sync. This is
816 enforced by making emit_inc_line_addr abort if we do not emit
817 exactly the expected number of bytes. */
819 static int
820 size_inc_line_addr (int line_delta, addressT addr_delta)
822 unsigned int tmp, opcode;
823 int len = 0;
825 /* Scale the address delta by the minimum instruction length. */
826 scale_addr_delta (&addr_delta);
828 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
829 We cannot use special opcodes here, since we want the end_sequence
830 to emit the matrix entry. */
831 if (line_delta == INT_MAX)
833 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
834 len = 1;
835 else
836 len = 1 + sizeof_leb128 (addr_delta, 0);
837 return len + 3;
840 /* Bias the line delta by the base. */
841 tmp = line_delta - DWARF2_LINE_BASE;
843 /* If the line increment is out of range of a special opcode, we
844 must encode it with DW_LNS_advance_line. */
845 if (tmp >= DWARF2_LINE_RANGE)
847 len = 1 + sizeof_leb128 (line_delta, 1);
848 line_delta = 0;
849 tmp = 0 - DWARF2_LINE_BASE;
852 /* Bias the opcode by the special opcode base. */
853 tmp += DWARF2_LINE_OPCODE_BASE;
855 /* Avoid overflow when addr_delta is large. */
856 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
858 /* Try using a special opcode. */
859 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
860 if (opcode <= 255)
861 return len + 1;
863 /* Try using DW_LNS_const_add_pc followed by special op. */
864 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
865 if (opcode <= 255)
866 return len + 2;
869 /* Otherwise use DW_LNS_advance_pc. */
870 len += 1 + sizeof_leb128 (addr_delta, 0);
872 /* DW_LNS_copy or special opcode. */
873 len += 1;
875 return len;
878 static void
879 emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len)
881 unsigned int tmp, opcode;
882 int need_copy = 0;
883 char *end = p + len;
885 /* Line number sequences cannot go backward in addresses. This means
886 we've incorrectly ordered the statements in the sequence. */
887 assert ((offsetT) addr_delta >= 0);
889 /* Scale the address delta by the minimum instruction length. */
890 scale_addr_delta (&addr_delta);
892 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
893 We cannot use special opcodes here, since we want the end_sequence
894 to emit the matrix entry. */
895 if (line_delta == INT_MAX)
897 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
898 *p++ = DW_LNS_const_add_pc;
899 else
901 *p++ = DW_LNS_advance_pc;
902 p += output_leb128 (p, addr_delta, 0);
905 *p++ = DW_LNS_extended_op;
906 *p++ = 1;
907 *p++ = DW_LNE_end_sequence;
908 goto done;
911 /* Bias the line delta by the base. */
912 tmp = line_delta - DWARF2_LINE_BASE;
914 /* If the line increment is out of range of a special opcode, we
915 must encode it with DW_LNS_advance_line. */
916 if (tmp >= DWARF2_LINE_RANGE)
918 *p++ = DW_LNS_advance_line;
919 p += output_leb128 (p, line_delta, 1);
921 line_delta = 0;
922 tmp = 0 - DWARF2_LINE_BASE;
923 need_copy = 1;
926 /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0"
927 special opcode. */
928 if (line_delta == 0 && addr_delta == 0)
930 *p++ = DW_LNS_copy;
931 goto done;
934 /* Bias the opcode by the special opcode base. */
935 tmp += DWARF2_LINE_OPCODE_BASE;
937 /* Avoid overflow when addr_delta is large. */
938 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
940 /* Try using a special opcode. */
941 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
942 if (opcode <= 255)
944 *p++ = opcode;
945 goto done;
948 /* Try using DW_LNS_const_add_pc followed by special op. */
949 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
950 if (opcode <= 255)
952 *p++ = DW_LNS_const_add_pc;
953 *p++ = opcode;
954 goto done;
958 /* Otherwise use DW_LNS_advance_pc. */
959 *p++ = DW_LNS_advance_pc;
960 p += output_leb128 (p, addr_delta, 0);
962 if (need_copy)
963 *p++ = DW_LNS_copy;
964 else
965 *p++ = tmp;
967 done:
968 assert (p == end);
971 /* Handy routine to combine calls to the above two routines. */
973 static void
974 out_inc_line_addr (int line_delta, addressT addr_delta)
976 int len = size_inc_line_addr (line_delta, addr_delta);
977 emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
980 /* Generate a variant frag that we can use to relax address/line
981 increments between fragments of the target segment. */
983 static void
984 relax_inc_line_addr (int line_delta, symbolS *to_sym, symbolS *from_sym)
986 expressionS expr;
987 int max_chars;
989 expr.X_op = O_subtract;
990 expr.X_add_symbol = to_sym;
991 expr.X_op_symbol = from_sym;
992 expr.X_add_number = 0;
994 /* The maximum size of the frag is the line delta with a maximum
995 sized address delta. */
996 max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH);
998 frag_var (rs_dwarf2dbg, max_chars, max_chars, 1,
999 make_expr_symbol (&expr), line_delta, NULL);
1002 /* The function estimates the size of a rs_dwarf2dbg variant frag
1003 based on the current values of the symbols. It is called before
1004 the relaxation loop. We set fr_subtype to the expected length. */
1007 dwarf2dbg_estimate_size_before_relax (fragS *frag)
1009 offsetT addr_delta;
1010 int size;
1012 addr_delta = resolve_symbol_value (frag->fr_symbol);
1013 size = size_inc_line_addr (frag->fr_offset, addr_delta);
1015 frag->fr_subtype = size;
1017 return size;
1020 /* This function relaxes a rs_dwarf2dbg variant frag based on the
1021 current values of the symbols. fr_subtype is the current length
1022 of the frag. This returns the change in frag length. */
1025 dwarf2dbg_relax_frag (fragS *frag)
1027 int old_size, new_size;
1029 old_size = frag->fr_subtype;
1030 new_size = dwarf2dbg_estimate_size_before_relax (frag);
1032 return new_size - old_size;
1035 /* This function converts a rs_dwarf2dbg variant frag into a normal
1036 fill frag. This is called after all relaxation has been done.
1037 fr_subtype will be the desired length of the frag. */
1039 void
1040 dwarf2dbg_convert_frag (fragS *frag)
1042 offsetT addr_diff;
1044 addr_diff = resolve_symbol_value (frag->fr_symbol);
1046 /* fr_var carries the max_chars that we created the fragment with.
1047 fr_subtype carries the current expected length. We must, of
1048 course, have allocated enough memory earlier. */
1049 assert (frag->fr_var >= (int) frag->fr_subtype);
1051 emit_inc_line_addr (frag->fr_offset, addr_diff,
1052 frag->fr_literal + frag->fr_fix, frag->fr_subtype);
1054 frag->fr_fix += frag->fr_subtype;
1055 frag->fr_type = rs_fill;
1056 frag->fr_var = 0;
1057 frag->fr_offset = 0;
1060 /* Generate .debug_line content for the chain of line number entries
1061 beginning at E, for segment SEG. */
1063 static void
1064 process_entries (segT seg, struct line_entry *e)
1066 unsigned filenum = 1;
1067 unsigned line = 1;
1068 unsigned column = 0;
1069 unsigned isa = 0;
1070 unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
1071 fragS *last_frag = NULL, *frag;
1072 addressT last_frag_ofs = 0, frag_ofs;
1073 symbolS *last_lab = NULL, *lab;
1074 struct line_entry *next;
1078 int line_delta;
1080 if (filenum != e->loc.filenum)
1082 filenum = e->loc.filenum;
1083 out_opcode (DW_LNS_set_file);
1084 out_uleb128 (filenum);
1087 if (column != e->loc.column)
1089 column = e->loc.column;
1090 out_opcode (DW_LNS_set_column);
1091 out_uleb128 (column);
1094 if (isa != e->loc.isa)
1096 isa = e->loc.isa;
1097 out_opcode (DW_LNS_set_isa);
1098 out_uleb128 (isa);
1101 if ((e->loc.flags ^ flags) & DWARF2_FLAG_IS_STMT)
1103 flags = e->loc.flags;
1104 out_opcode (DW_LNS_negate_stmt);
1107 if (e->loc.flags & DWARF2_FLAG_BASIC_BLOCK)
1108 out_opcode (DW_LNS_set_basic_block);
1110 if (e->loc.flags & DWARF2_FLAG_PROLOGUE_END)
1111 out_opcode (DW_LNS_set_prologue_end);
1113 if (e->loc.flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1114 out_opcode (DW_LNS_set_epilogue_begin);
1116 /* Don't try to optimize away redundant entries; gdb wants two
1117 entries for a function where the code starts on the same line as
1118 the {, and there's no way to identify that case here. Trust gcc
1119 to optimize appropriately. */
1120 line_delta = e->loc.line - line;
1121 lab = e->label;
1122 frag = symbol_get_frag (lab);
1123 frag_ofs = S_GET_VALUE (lab);
1125 if (last_frag == NULL)
1127 out_set_addr (lab);
1128 out_inc_line_addr (line_delta, 0);
1130 else if (frag == last_frag)
1131 out_inc_line_addr (line_delta, frag_ofs - last_frag_ofs);
1132 else
1133 relax_inc_line_addr (line_delta, lab, last_lab);
1135 line = e->loc.line;
1136 last_lab = lab;
1137 last_frag = frag;
1138 last_frag_ofs = frag_ofs;
1140 next = e->next;
1141 free (e);
1142 e = next;
1144 while (e);
1146 /* Emit a DW_LNE_end_sequence for the end of the section. */
1147 frag = last_frag_for_seg (seg);
1148 frag_ofs = get_frag_fix (frag, seg);
1149 if (frag == last_frag)
1150 out_inc_line_addr (INT_MAX, frag_ofs - last_frag_ofs);
1151 else
1153 lab = symbol_temp_new (seg, frag_ofs, frag);
1154 relax_inc_line_addr (INT_MAX, lab, last_lab);
1158 /* Emit the directory and file tables for .debug_line. */
1160 static void
1161 out_file_list (void)
1163 size_t size;
1164 char *cp;
1165 unsigned int i;
1167 /* Emit directory list. */
1168 for (i = 1; i < dirs_in_use; ++i)
1170 size = strlen (dirs[i]) + 1;
1171 cp = frag_more (size);
1172 memcpy (cp, dirs[i], size);
1174 /* Terminate it. */
1175 out_byte ('\0');
1177 for (i = 1; i < files_in_use; ++i)
1179 if (files[i].filename == NULL)
1181 as_bad (_("unassigned file number %ld"), (long) i);
1182 /* Prevent a crash later, particularly for file 1. */
1183 files[i].filename = "";
1184 continue;
1187 size = strlen (files[i].filename) + 1;
1188 cp = frag_more (size);
1189 memcpy (cp, files[i].filename, size);
1191 out_uleb128 (files[i].dir); /* directory number */
1192 out_uleb128 (0); /* last modification timestamp */
1193 out_uleb128 (0); /* filesize */
1196 /* Terminate filename list. */
1197 out_byte (0);
1200 /* Emit the collected .debug_line data. */
1202 static void
1203 out_debug_line (segT line_seg)
1205 expressionS expr;
1206 symbolS *line_start;
1207 symbolS *prologue_end;
1208 symbolS *line_end;
1209 struct line_seg *s;
1210 enum dwarf2_format d2f;
1211 int sizeof_offset;
1213 subseg_set (line_seg, 0);
1215 line_start = symbol_temp_new_now ();
1216 prologue_end = symbol_temp_make ();
1217 line_end = symbol_temp_make ();
1219 /* Total length of the information for this compilation unit. */
1220 expr.X_op = O_subtract;
1221 expr.X_add_symbol = line_end;
1222 expr.X_op_symbol = line_start;
1224 d2f = DWARF2_FORMAT ();
1225 if (d2f == dwarf2_format_32bit)
1227 expr.X_add_number = -4;
1228 emit_expr (&expr, 4);
1229 sizeof_offset = 4;
1231 else if (d2f == dwarf2_format_64bit)
1233 expr.X_add_number = -12;
1234 out_four (-1);
1235 emit_expr (&expr, 8);
1236 sizeof_offset = 8;
1238 else if (d2f == dwarf2_format_64bit_irix)
1240 expr.X_add_number = -8;
1241 emit_expr (&expr, 8);
1242 sizeof_offset = 8;
1244 else
1246 as_fatal (_("internal error: unknown dwarf2 format"));
1249 /* Version. */
1250 out_two (2);
1252 /* Length of the prologue following this length. */
1253 expr.X_op = O_subtract;
1254 expr.X_add_symbol = prologue_end;
1255 expr.X_op_symbol = line_start;
1256 expr.X_add_number = - (4 + 2 + 4);
1257 emit_expr (&expr, sizeof_offset);
1259 /* Parameters of the state machine. */
1260 out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
1261 out_byte (DWARF2_LINE_DEFAULT_IS_STMT);
1262 out_byte (DWARF2_LINE_BASE);
1263 out_byte (DWARF2_LINE_RANGE);
1264 out_byte (DWARF2_LINE_OPCODE_BASE);
1266 /* Standard opcode lengths. */
1267 out_byte (0); /* DW_LNS_copy */
1268 out_byte (1); /* DW_LNS_advance_pc */
1269 out_byte (1); /* DW_LNS_advance_line */
1270 out_byte (1); /* DW_LNS_set_file */
1271 out_byte (1); /* DW_LNS_set_column */
1272 out_byte (0); /* DW_LNS_negate_stmt */
1273 out_byte (0); /* DW_LNS_set_basic_block */
1274 out_byte (0); /* DW_LNS_const_add_pc */
1275 out_byte (1); /* DW_LNS_fixed_advance_pc */
1276 out_byte (0); /* DW_LNS_set_prologue_end */
1277 out_byte (0); /* DW_LNS_set_epilogue_begin */
1278 out_byte (1); /* DW_LNS_set_isa */
1280 out_file_list ();
1282 symbol_set_value_now (prologue_end);
1284 /* For each section, emit a statement program. */
1285 for (s = all_segs; s; s = s->next)
1286 process_entries (s->seg, s->head->head);
1288 symbol_set_value_now (line_end);
1291 static void
1292 out_debug_ranges (segT ranges_seg)
1294 unsigned int addr_size = sizeof_address;
1295 struct line_seg *s;
1296 expressionS expr;
1297 unsigned int i;
1299 subseg_set (ranges_seg, 0);
1301 /* Base Address Entry. */
1302 for (i = 0; i < addr_size; i++)
1303 out_byte (0xff);
1304 for (i = 0; i < addr_size; i++)
1305 out_byte (0);
1307 /* Range List Entry. */
1308 for (s = all_segs; s; s = s->next)
1310 fragS *frag;
1311 symbolS *beg, *end;
1313 frag = first_frag_for_seg (s->seg);
1314 beg = symbol_temp_new (s->seg, 0, frag);
1315 s->text_start = beg;
1317 frag = last_frag_for_seg (s->seg);
1318 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
1319 s->text_end = end;
1321 expr.X_op = O_symbol;
1322 expr.X_add_symbol = beg;
1323 expr.X_add_number = 0;
1324 emit_expr (&expr, addr_size);
1326 expr.X_op = O_symbol;
1327 expr.X_add_symbol = end;
1328 expr.X_add_number = 0;
1329 emit_expr (&expr, addr_size);
1332 /* End of Range Entry. */
1333 for (i = 0; i < addr_size; i++)
1334 out_byte (0);
1335 for (i = 0; i < addr_size; i++)
1336 out_byte (0);
1339 /* Emit data for .debug_aranges. */
1341 static void
1342 out_debug_aranges (segT aranges_seg, segT info_seg)
1344 unsigned int addr_size = sizeof_address;
1345 addressT size, skip;
1346 struct line_seg *s;
1347 expressionS expr;
1348 char *p;
1350 size = 4 + 2 + 4 + 1 + 1;
1352 skip = 2 * addr_size - (size & (2 * addr_size - 1));
1353 if (skip == 2 * addr_size)
1354 skip = 0;
1355 size += skip;
1357 for (s = all_segs; s; s = s->next)
1358 size += 2 * addr_size;
1360 size += 2 * addr_size;
1362 subseg_set (aranges_seg, 0);
1364 /* Length of the compilation unit. */
1365 out_four (size - 4);
1367 /* Version. */
1368 out_two (2);
1370 /* Offset to .debug_info. */
1371 /* ??? sizeof_offset */
1372 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), 4);
1374 /* Size of an address (offset portion). */
1375 out_byte (addr_size);
1377 /* Size of a segment descriptor. */
1378 out_byte (0);
1380 /* Align the header. */
1381 if (skip)
1382 frag_align (ffs (2 * addr_size) - 1, 0, 0);
1384 for (s = all_segs; s; s = s->next)
1386 fragS *frag;
1387 symbolS *beg, *end;
1389 frag = first_frag_for_seg (s->seg);
1390 beg = symbol_temp_new (s->seg, 0, frag);
1391 s->text_start = beg;
1393 frag = last_frag_for_seg (s->seg);
1394 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
1395 s->text_end = end;
1397 expr.X_op = O_symbol;
1398 expr.X_add_symbol = beg;
1399 expr.X_add_number = 0;
1400 emit_expr (&expr, addr_size);
1402 expr.X_op = O_subtract;
1403 expr.X_add_symbol = end;
1404 expr.X_op_symbol = beg;
1405 expr.X_add_number = 0;
1406 emit_expr (&expr, addr_size);
1409 p = frag_more (2 * addr_size);
1410 md_number_to_chars (p, 0, addr_size);
1411 md_number_to_chars (p + addr_size, 0, addr_size);
1414 /* Emit data for .debug_abbrev. Note that this must be kept in
1415 sync with out_debug_info below. */
1417 static void
1418 out_debug_abbrev (segT abbrev_seg)
1420 subseg_set (abbrev_seg, 0);
1422 out_uleb128 (1);
1423 out_uleb128 (DW_TAG_compile_unit);
1424 out_byte (DW_CHILDREN_no);
1425 out_abbrev (DW_AT_stmt_list, DW_FORM_data4);
1426 if (all_segs->next == NULL)
1428 out_abbrev (DW_AT_low_pc, DW_FORM_addr);
1429 out_abbrev (DW_AT_high_pc, DW_FORM_addr);
1431 else
1433 if (DWARF2_FORMAT () == dwarf2_format_32bit)
1434 out_abbrev (DW_AT_ranges, DW_FORM_data4);
1435 else
1436 out_abbrev (DW_AT_ranges, DW_FORM_data8);
1438 out_abbrev (DW_AT_name, DW_FORM_string);
1439 out_abbrev (DW_AT_comp_dir, DW_FORM_string);
1440 out_abbrev (DW_AT_producer, DW_FORM_string);
1441 out_abbrev (DW_AT_language, DW_FORM_data2);
1442 out_abbrev (0, 0);
1444 /* Terminate the abbreviations for this compilation unit. */
1445 out_byte (0);
1448 /* Emit a description of this compilation unit for .debug_info. */
1450 static void
1451 out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
1453 char producer[128];
1454 char *comp_dir;
1455 expressionS expr;
1456 symbolS *info_start;
1457 symbolS *info_end;
1458 char *p;
1459 int len;
1460 enum dwarf2_format d2f;
1461 int sizeof_offset;
1463 subseg_set (info_seg, 0);
1465 info_start = symbol_temp_new_now ();
1466 info_end = symbol_temp_make ();
1468 /* Compilation Unit length. */
1469 expr.X_op = O_subtract;
1470 expr.X_add_symbol = info_end;
1471 expr.X_op_symbol = info_start;
1473 d2f = DWARF2_FORMAT ();
1474 if (d2f == dwarf2_format_32bit)
1476 expr.X_add_number = -4;
1477 emit_expr (&expr, 4);
1478 sizeof_offset = 4;
1480 else if (d2f == dwarf2_format_64bit)
1482 expr.X_add_number = -12;
1483 out_four (-1);
1484 emit_expr (&expr, 8);
1485 sizeof_offset = 8;
1487 else if (d2f == dwarf2_format_64bit_irix)
1489 expr.X_add_number = -8;
1490 emit_expr (&expr, 8);
1491 sizeof_offset = 8;
1493 else
1495 as_fatal (_("internal error: unknown dwarf2 format"));
1498 /* DWARF version. */
1499 out_two (2);
1501 /* .debug_abbrev offset */
1502 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
1504 /* Target address size. */
1505 out_byte (sizeof_address);
1507 /* DW_TAG_compile_unit DIE abbrev */
1508 out_uleb128 (1);
1510 /* DW_AT_stmt_list */
1511 /* ??? sizeof_offset */
1512 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg), 4);
1514 /* These two attributes are emitted if all of the code is contiguous. */
1515 if (all_segs->next == NULL)
1517 /* DW_AT_low_pc */
1518 expr.X_op = O_symbol;
1519 expr.X_add_symbol = all_segs->text_start;
1520 expr.X_add_number = 0;
1521 emit_expr (&expr, sizeof_address);
1523 /* DW_AT_high_pc */
1524 expr.X_op = O_symbol;
1525 expr.X_add_symbol = all_segs->text_end;
1526 expr.X_add_number = 0;
1527 emit_expr (&expr, sizeof_address);
1529 else
1531 /* This attributes is emitted if the code is disjoint. */
1533 /* DW_AT_ranges */
1534 expr.X_op = O_symbol;
1535 expr.X_add_symbol = section_symbol (ranges_seg);
1536 expr.X_add_number = 0;
1537 emit_expr (&expr, sizeof_address);
1540 /* DW_AT_name. We don't have the actual file name that was present
1541 on the command line, so assume files[1] is the main input file.
1542 We're not supposed to get called unless at least one line number
1543 entry was emitted, so this should always be defined. */
1544 if (!files || files_in_use < 1)
1545 abort ();
1546 if (files[1].dir)
1548 len = strlen (dirs[files[1].dir]);
1549 p = frag_more (len + 1);
1550 memcpy (p, dirs[files[1].dir], len);
1551 INSERT_DIR_SEPARATOR (p, len);
1553 len = strlen (files[1].filename) + 1;
1554 p = frag_more (len);
1555 memcpy (p, files[1].filename, len);
1557 /* DW_AT_comp_dir */
1558 comp_dir = getpwd ();
1559 len = strlen (comp_dir) + 1;
1560 p = frag_more (len);
1561 memcpy (p, comp_dir, len);
1563 /* DW_AT_producer */
1564 sprintf (producer, "GNU AS %s", VERSION);
1565 len = strlen (producer) + 1;
1566 p = frag_more (len);
1567 memcpy (p, producer, len);
1569 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1570 dwarf2 draft has no standard code for assembler. */
1571 out_two (DW_LANG_Mips_Assembler);
1573 symbol_set_value_now (info_end);
1576 /* Finish the dwarf2 debug sections. We emit .debug.line if there
1577 were any .file/.loc directives, or --gdwarf2 was given, or if the
1578 file has a non-empty .debug_info section. If we emit .debug_line,
1579 and the .debug_info section is empty, we also emit .debug_info,
1580 .debug_aranges and .debug_abbrev. ALL_SEGS will be non-null if
1581 there were any .file/.loc directives, or --gdwarf2 was given and
1582 there were any located instructions emitted. */
1584 void
1585 dwarf2_finish (void)
1587 segT line_seg;
1588 struct line_seg *s;
1589 segT info_seg;
1590 int emit_other_sections = 0;
1592 info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
1593 emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
1595 if (!all_segs && emit_other_sections)
1596 /* There is no line information and no non-empty .debug_info
1597 section. */
1598 return;
1600 /* Calculate the size of an address for the target machine. */
1601 sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
1603 /* Create and switch to the line number section. */
1604 line_seg = subseg_new (".debug_line", 0);
1605 bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
1607 /* For each subsection, chain the debug entries together. */
1608 for (s = all_segs; s; s = s->next)
1610 struct line_subseg *ss = s->head;
1611 struct line_entry **ptail = ss->ptail;
1613 while ((ss = ss->next) != NULL)
1615 *ptail = ss->head;
1616 ptail = ss->ptail;
1620 out_debug_line (line_seg);
1622 /* If this is assembler generated line info, and there is no
1623 debug_info already, we need .debug_info and .debug_abbrev
1624 sections as well. */
1625 if (emit_other_sections)
1627 segT abbrev_seg;
1628 segT aranges_seg;
1629 segT ranges_seg;
1631 assert (all_segs);
1633 info_seg = subseg_new (".debug_info", 0);
1634 abbrev_seg = subseg_new (".debug_abbrev", 0);
1635 aranges_seg = subseg_new (".debug_aranges", 0);
1637 bfd_set_section_flags (stdoutput, info_seg,
1638 SEC_READONLY | SEC_DEBUGGING);
1639 bfd_set_section_flags (stdoutput, abbrev_seg,
1640 SEC_READONLY | SEC_DEBUGGING);
1641 bfd_set_section_flags (stdoutput, aranges_seg,
1642 SEC_READONLY | SEC_DEBUGGING);
1644 record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
1646 if (all_segs->next == NULL)
1647 ranges_seg = NULL;
1648 else
1650 ranges_seg = subseg_new (".debug_ranges", 0);
1651 bfd_set_section_flags (stdoutput, ranges_seg,
1652 SEC_READONLY | SEC_DEBUGGING);
1653 record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
1654 out_debug_ranges (ranges_seg);
1657 out_debug_aranges (aranges_seg, info_seg);
1658 out_debug_abbrev (abbrev_seg);
1659 out_debug_info (info_seg, abbrev_seg, line_seg, ranges_seg);