Replace occurences of 'tolower' with 'TOLOWER'.
[deliverable/binutils-gdb.git] / gas / dwarf2dbg.c
CommitLineData
fac0d250 1/* dwarf2dbg.c - DWARF2 debug support
70658493 2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
fac0d250
RH
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
89b66cde 20 02111-1307, USA. */
fac0d250 21
89b66cde 22/* Logical line numbers can be controlled by the compiler via the
fac0d250
RH
23 following two directives:
24
25 .file FILENO "file.c"
26 .loc FILENO LINENO [COLUMN]
27
28 FILENO is the filenumber. */
29
30#include "ansidecl.h"
fac0d250 31#include "as.h"
92eb7b32 32
42dbf88c
NC
33#ifdef HAVE_LIMITS_H
34#include <limits.h>
92625c16 35#else
6717891c
NC
36#ifdef HAVE_SYS_PARAM_H
37#include <sys/param.h>
38#endif
6256f9dd 39#ifndef INT_MAX
ee515fb7 40#define INT_MAX (int) (((unsigned) (-1)) >> 1)
42dbf88c 41#endif
b8f080d6 42#endif
42dbf88c 43
70658493
AM
44#include "dwarf2dbg.h"
45
14e777e0 46#ifndef DWARF2_FORMAT
9605f328 47# define DWARF2_FORMAT() dwarf2_format_32bit
14e777e0
KB
48#endif
49
9605f328
AO
50#ifndef DWARF2_ADDR_SIZE
51# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8);
52#endif
53
54
92eb7b32
L
55#ifdef BFD_ASSEMBLER
56
fac0d250
RH
57#include "subsegs.h"
58
d9ac5a3b 59#include "elf/dwarf2.h"
fac0d250 60
fac0d250
RH
61/* Since we can't generate the prolog until the body is complete, we
62 use three different subsegments for .debug_line: one holding the
63 prolog, one for the directory and filename info, and one for the
64 body ("statement program"). */
65#define DL_PROLOG 0
66#define DL_FILES 1
67#define DL_BODY 2
68
69/* First special line opcde - leave room for the standard opcodes.
70 Note: If you want to change this, you'll have to update the
71 "standard_opcode_lengths" table that is emitted below in
72 dwarf2_finish(). */
73#define DWARF2_LINE_OPCODE_BASE 10
74
75#ifndef DWARF2_LINE_BASE
76 /* Minimum line offset in a special line info. opcode. This value
77 was chosen to give a reasonable range of values. */
78# define DWARF2_LINE_BASE -5
79#endif
80
81/* Range of line offsets in a special line info. opcode. */
82#ifndef DWARF2_LINE_RANGE
83# define DWARF2_LINE_RANGE 14
84#endif
85
86#ifndef DWARF2_LINE_MIN_INSN_LENGTH
87 /* Define the architecture-dependent minimum instruction length (in
88 bytes). This value should be rather too small than too big. */
4dc7ead9 89# define DWARF2_LINE_MIN_INSN_LENGTH 1
fac0d250
RH
90#endif
91
92/* Flag that indicates the initial value of the is_stmt_start flag.
93 In the present implementation, we do not mark any lines as
94 the beginning of a source statement, because that information
95 is not made available by the GCC front-end. */
96#define DWARF2_LINE_DEFAULT_IS_STMT 1
97
cb30237e 98/* Given a special op, return the line skip amount. */
fac0d250
RH
99#define SPECIAL_LINE(op) \
100 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
101
102/* Given a special op, return the address skip amount (in units of
103 DWARF2_LINE_MIN_INSN_LENGTH. */
104#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
105
cb30237e 106/* The maximum address skip amount that can be encoded with a special op. */
fac0d250
RH
107#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
108
ee515fb7 109struct line_entry {
220e750f
RH
110 struct line_entry *next;
111 fragS *frag;
112 addressT frag_ofs;
113 struct dwarf2_line_info loc;
e6c774b4 114};
fac0d250 115
ee515fb7 116struct line_subseg {
220e750f
RH
117 struct line_subseg *next;
118 subsegT subseg;
119 struct line_entry *head;
120 struct line_entry **ptail;
121};
353e2c69 122
ee515fb7 123struct line_seg {
220e750f
RH
124 struct line_seg *next;
125 segT seg;
126 struct line_subseg *head;
127 symbolS *text_start;
128 symbolS *text_end;
129};
130
131/* Collects data for all line table entries during assembly. */
132static struct line_seg *all_segs;
133
ee515fb7 134struct file_entry {
220e750f
RH
135 char *filename;
136 unsigned int dir;
137};
138
139/* Table of files used by .debug_line. */
140static struct file_entry *files;
141static unsigned int files_in_use;
142static unsigned int files_allocated;
143
b34976b6 144/* TRUE when we've seen a .loc directive recently. Used to avoid
220e750f 145 doing work when there's nothing to do. */
b34976b6 146static bfd_boolean loc_directive_seen;
220e750f
RH
147
148/* Current location as indicated by the most recent .loc directive. */
149static struct dwarf2_line_info current;
150
151/* Fake label name. */
152static char const fake_label_name[] = ".L0\001";
153
154/* The size of an address on the target. */
155static unsigned int sizeof_address;
156\f
157static struct line_subseg *get_line_subseg PARAMS ((segT, subsegT));
158static unsigned int get_filenum PARAMS ((const char *));
159static struct frag *first_frag_for_seg PARAMS ((segT));
160static struct frag *last_frag_for_seg PARAMS ((segT));
161static void out_byte PARAMS ((int));
162static void out_opcode PARAMS ((int));
163static void out_two PARAMS ((int));
164static void out_four PARAMS ((int));
165static void out_abbrev PARAMS ((int, int));
166static void out_uleb128 PARAMS ((addressT));
167static symbolS *symbol_new_now PARAMS ((void));
168static void set_symbol_value_now PARAMS ((symbolS *));
169static offsetT get_frag_fix PARAMS ((fragS *));
170static void out_set_addr PARAMS ((segT, fragS *, addressT));
171static int size_inc_line_addr PARAMS ((int, addressT));
172static void emit_inc_line_addr PARAMS ((int, addressT, char *, int));
173static void out_inc_line_addr PARAMS ((int, addressT));
174static void relax_inc_line_addr PARAMS ((int, segT, fragS *, addressT,
175 fragS *, addressT));
176static void process_entries PARAMS ((segT, struct line_entry *));
177static void out_file_list PARAMS ((void));
178static void out_debug_line PARAMS ((segT));
179static void out_debug_aranges PARAMS ((segT, segT));
180static void out_debug_abbrev PARAMS ((segT));
181static void out_debug_info PARAMS ((segT, segT, segT));
182\f
183/* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
184
185static struct line_subseg *
186get_line_subseg (seg, subseg)
187 segT seg;
188 subsegT subseg;
189{
190 static segT last_seg;
191 static subsegT last_subseg;
192 static struct line_subseg *last_line_subseg;
193
194 struct line_seg *s;
195 struct line_subseg **pss, *ss;
fac0d250 196
220e750f
RH
197 if (seg == last_seg && subseg == last_subseg)
198 return last_line_subseg;
199
ee515fb7 200 for (s = all_segs; s; s = s->next)
220e750f
RH
201 if (s->seg == seg)
202 goto found_seg;
203
204 s = (struct line_seg *) xmalloc (sizeof (*s));
205 s->next = all_segs;
206 s->seg = seg;
207 s->head = NULL;
208 all_segs = s;
209
210 found_seg:
211 for (pss = &s->head; (ss = *pss) != NULL ; pss = &ss->next)
fac0d250 212 {
220e750f 213 if (ss->subseg == subseg)
ee515fb7 214 goto found_subseg;
220e750f
RH
215 if (ss->subseg > subseg)
216 break;
fac0d250 217 }
220e750f
RH
218
219 ss = (struct line_subseg *) xmalloc (sizeof (*ss));
220 ss->next = *pss;
221 ss->subseg = subseg;
222 ss->head = NULL;
223 ss->ptail = &ss->head;
224 *pss = ss;
225
226 found_subseg:
227 last_seg = seg;
228 last_subseg = subseg;
229 last_line_subseg = ss;
230
231 return ss;
fac0d250
RH
232}
233
220e750f 234/* Record an entry for LOC ocurring at OFS within the current fragment. */
353e2c69 235
220e750f
RH
236void
237dwarf2_gen_line_info (ofs, loc)
238 addressT ofs;
239 struct dwarf2_line_info *loc;
fac0d250 240{
220e750f
RH
241 struct line_subseg *ss;
242 struct line_entry *e;
1ea5c325
MS
243 static unsigned int line = -1;
244 static unsigned int filenum = -1;
220e750f
RH
245
246 /* Early out for as-yet incomplete location information. */
247 if (loc->filenum == 0 || loc->line == 0)
248 return;
249
ffa554ed
GK
250 /* Don't emit sequences of line symbols for the same line when the
251 symbols apply to assembler code. It is necessary to emit
252 duplicate line symbols when a compiler asks for them, because GDB
253 uses them to determine the end of the prologue. */
d1a6c242 254 if (debug_type == DEBUG_DWARF2
ffa554ed 255 && line == loc->line && filenum == loc->filenum)
1ea5c325
MS
256 return;
257
258 line = loc->line;
259 filenum = loc->filenum;
260
220e750f
RH
261 e = (struct line_entry *) xmalloc (sizeof (*e));
262 e->next = NULL;
263 e->frag = frag_now;
264 e->frag_ofs = ofs;
265 e->loc = *loc;
266
267 ss = get_line_subseg (now_seg, now_subseg);
268 *ss->ptail = e;
269 ss->ptail = &e->next;
270}
fac0d250 271
220e750f
RH
272void
273dwarf2_where (line)
274 struct dwarf2_line_info *line;
275{
276 if (debug_type == DEBUG_DWARF2)
fac0d250 277 {
220e750f
RH
278 char *filename;
279 as_where (&filename, &line->line);
280 line->filenum = get_filenum (filename);
281 line->column = 0;
282 line->flags = DWARF2_FLAG_BEGIN_STMT;
fac0d250 283 }
220e750f
RH
284 else
285 *line = current;
fac0d250
RH
286}
287
220e750f
RH
288/* Called for each machine instruction, or relatively atomic group of
289 machine instructions (ie built-in macro). The instruction or group
290 is SIZE bytes in length. If dwarf2 line number generation is called
291 for, emit a line statement appropriately. */
353e2c69 292
220e750f
RH
293void
294dwarf2_emit_insn (size)
295 int size;
fac0d250 296{
220e750f 297 struct dwarf2_line_info loc;
fac0d250 298
b6675117 299 if (loc_directive_seen)
1080e97d
L
300 {
301 /* Use the last location established by a .loc directive, not
302 the value returned by dwarf2_where(). That calls as_where()
303 which will return either the logical input file name (foo.c)
304 or the physical input file name (foo.s) and not the file name
305 specified in the most recent .loc directive (eg foo.h). */
306 loc = current;
307
308 /* Unless we generate DWARF2 debugging information for each
309 assembler line, we only emit one line symbol for one LOC. */
310 if (debug_type != DEBUG_DWARF2)
b34976b6 311 loc_directive_seen = FALSE;
1080e97d 312 }
b6675117 313 else if (debug_type != DEBUG_DWARF2)
220e750f 314 return;
b6675117
NC
315 else
316 dwarf2_where (& loc);
317
220e750f
RH
318 dwarf2_gen_line_info (frag_now_fix () - size, &loc);
319}
fac0d250 320
220e750f
RH
321/* Get a .debug_line file number for FILENAME. */
322
323static unsigned int
324get_filenum (filename)
325 const char *filename;
326{
327 static unsigned int last_used;
328 unsigned int i;
329
330 if (last_used)
331 if (strcmp (filename, files[last_used].filename) == 0)
332 return last_used;
333
334 for (i = 1; i < files_in_use; ++i)
335 if (strcmp (filename, files[i].filename) == 0)
336 return i;
337
338 if (i >= files_allocated)
fac0d250 339 {
249e3833
RH
340 unsigned int old = files_allocated;
341
220e750f
RH
342 files_allocated = i + 32;
343 files = (struct file_entry *)
ee515fb7 344 xrealloc (files, (i + 32) * sizeof (struct file_entry));
249e3833
RH
345
346 memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
fac0d250
RH
347 }
348
ee515fb7 349 files[i].filename = xstrdup (filename);
220e750f
RH
350 files[i].dir = 0;
351 files_in_use = i + 1;
352 last_used = i;
353
354 return i;
355}
fac0d250 356
ecb4347a
DJ
357/* Handle two forms of .file directive:
358 - Pass .file "source.c" to s_app_file
359 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
220e750f 360
ecb4347a
DJ
361 If an entry is added to the file table, return a pointer to the filename. */
362
363char *
220e750f
RH
364dwarf2_directive_file (dummy)
365 int dummy ATTRIBUTE_UNUSED;
366{
367 offsetT num;
e46d99eb 368 char *filename;
220e750f
RH
369 int filename_len;
370
371 /* Continue to accept a bare string and pass it off. */
372 SKIP_WHITESPACE ();
373 if (*input_line_pointer == '"')
fac0d250 374 {
220e750f 375 s_app_file (0);
ecb4347a 376 return NULL;
fac0d250
RH
377 }
378
220e750f
RH
379 num = get_absolute_expression ();
380 filename = demand_copy_C_string (&filename_len);
381 demand_empty_rest_of_line ();
382
249e3833 383 if (num < 1)
fac0d250 384 {
0e389e77 385 as_bad (_("file number less than one"));
ecb4347a 386 return NULL;
fac0d250
RH
387 }
388
0e1a166b 389 if (num < (int) files_in_use && files[num].filename != 0)
220e750f 390 {
0e389e77 391 as_bad (_("file number %ld already allocated"), (long) num);
ecb4347a 392 return NULL;
249e3833 393 }
220e750f 394
249e3833
RH
395 if (num >= (int) files_allocated)
396 {
397 unsigned int old = files_allocated;
398
399 files_allocated = num + 16;
400 files = (struct file_entry *)
401 xrealloc (files, (num + 16) * sizeof (struct file_entry));
fac0d250 402
220e750f 403 /* Zero the new memory. */
249e3833 404 memset (files + old, 0, (num + 16 - old) * sizeof (struct file_entry));
220e750f
RH
405 }
406
249e3833
RH
407 files[num].filename = filename;
408 files[num].dir = 0;
409 files_in_use = num + 1;
ecb4347a
DJ
410
411 return filename;
fac0d250
RH
412}
413
220e750f
RH
414void
415dwarf2_directive_loc (dummy)
416 int dummy ATTRIBUTE_UNUSED;
417{
418 offsetT filenum, line, column;
419
420 filenum = get_absolute_expression ();
421 SKIP_WHITESPACE ();
422 line = get_absolute_expression ();
423 SKIP_WHITESPACE ();
424 column = get_absolute_expression ();
425 demand_empty_rest_of_line ();
426
249e3833 427 if (filenum < 1)
220e750f 428 {
0e389e77 429 as_bad (_("file number less than one"));
220e750f
RH
430 return;
431 }
249e3833 432 if (filenum >= (int) files_in_use || files[filenum].filename == 0)
220e750f 433 {
0e389e77 434 as_bad (_("unassigned file number %ld"), (long) filenum);
220e750f
RH
435 return;
436 }
437
249e3833 438 current.filenum = filenum;
220e750f
RH
439 current.line = line;
440 current.column = column;
441 current.flags = DWARF2_FLAG_BEGIN_STMT;
442
b34976b6 443 loc_directive_seen = TRUE;
220e750f
RH
444
445#ifndef NO_LISTING
446 if (listing)
9d66a1d9
L
447 {
448 listing_source_file (files[filenum].filename);
449 listing_source_line (line);
450 }
220e750f
RH
451#endif
452}
220e750f
RH
453\f
454static struct frag *
455first_frag_for_seg (seg)
456 segT seg;
457{
458 frchainS *f, *first = NULL;
459
ee515fb7 460 for (f = frchain_root; f; f = f->frch_next)
220e750f
RH
461 if (f->frch_seg == seg
462 && (! first || first->frch_subseg > f->frch_subseg))
463 first = f;
464
465 return first ? first->frch_root : NULL;
466}
467
468static struct frag *
469last_frag_for_seg (seg)
470 segT seg;
471{
472 frchainS *f, *last = NULL;
473
ee515fb7 474 for (f = frchain_root; f; f = f->frch_next)
220e750f
RH
475 if (f->frch_seg == seg
476 && (! last || last->frch_subseg < f->frch_subseg))
477 last= f;
478
479 return last ? last->frch_last : NULL;
480}
481\f
482/* Emit a single byte into the current segment. */
483
484static inline void
485out_byte (byte)
486 int byte;
487{
488 FRAG_APPEND_1_CHAR (byte);
489}
490
491/* Emit a statement program opcode into the current segment. */
492
493static inline void
494out_opcode (opc)
495 int opc;
496{
497 out_byte (opc);
498}
499
500/* Emit a two-byte word into the current segment. */
501
502static inline void
503out_two (data)
504 int data;
505{
506 md_number_to_chars (frag_more (2), data, 2);
507}
508
509/* Emit a four byte word into the current segment. */
510
511static inline void
512out_four (data)
513 int data;
514{
515 md_number_to_chars (frag_more (4), data, 4);
516}
517
518/* Emit an unsigned "little-endian base 128" number. */
519
fac0d250 520static void
220e750f
RH
521out_uleb128 (value)
522 addressT value;
523{
524 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
525}
526
527/* Emit a tuple for .debug_abbrev. */
528
529static inline void
530out_abbrev (name, form)
531 int name, form;
fac0d250 532{
220e750f
RH
533 out_uleb128 (name);
534 out_uleb128 (form);
535}
fac0d250 536
220e750f
RH
537/* Create a new fake symbol whose value is the current position. */
538
539static symbolS *
540symbol_new_now ()
541{
542 return symbol_new (fake_label_name, now_seg, frag_now_fix (), frag_now);
fac0d250
RH
543}
544
220e750f 545/* Set the value of SYM to the current position in the current segment. */
353e2c69 546
fac0d250 547static void
220e750f
RH
548set_symbol_value_now (sym)
549 symbolS *sym;
fac0d250 550{
220e750f
RH
551 S_SET_SEGMENT (sym, now_seg);
552 S_SET_VALUE (sym, frag_now_fix ());
553 symbol_set_frag (sym, frag_now);
554}
555
556/* Get the size of a fragment. */
fac0d250 557
220e750f
RH
558static offsetT
559get_frag_fix (frag)
560 fragS *frag;
561{
562 frchainS *fr;
563
564 if (frag->fr_next)
565 return frag->fr_fix;
566
567 /* If a fragment is the last in the chain, special measures must be
568 taken to find its size before relaxation, since it may be pending
569 on some subsegment chain. */
ee515fb7 570 for (fr = frchain_root; fr; fr = fr->frch_next)
220e750f
RH
571 if (fr->frch_last == frag)
572 {
7c2b59d0
AM
573 long align_mask = -1 << get_recorded_alignment (fr->frch_seg);
574 return (((char *) obstack_next_free (&fr->frch_obstack)
575 - frag->fr_literal) + ~align_mask) & align_mask;
220e750f
RH
576 }
577
578 abort ();
579}
fac0d250 580
220e750f 581/* Set an absolute address (may result in a relocation entry). */
fac0d250 582
220e750f
RH
583static void
584out_set_addr (seg, frag, ofs)
585 segT seg;
586 fragS *frag;
587 addressT ofs;
588{
589 expressionS expr;
590 symbolS *sym;
fac0d250 591
220e750f 592 sym = symbol_new (fake_label_name, seg, ofs, frag);
9e3af0e7 593
fac0d250 594 out_opcode (DW_LNS_extended_op);
220e750f 595 out_uleb128 (sizeof_address + 1);
fac0d250
RH
596
597 out_opcode (DW_LNE_set_address);
598 expr.X_op = O_symbol;
599 expr.X_add_symbol = sym;
600 expr.X_add_number = 0;
220e750f 601 emit_expr (&expr, sizeof_address);
fac0d250
RH
602}
603
a3b75434 604#if DWARF2_LINE_MIN_INSN_LENGTH > 1
c8970b4b
AM
605static void scale_addr_delta PARAMS ((addressT *));
606
a3b75434
DD
607static void
608scale_addr_delta (addr_delta)
c8970b4b 609 addressT *addr_delta;
a3b75434
DD
610{
611 static int printed_this = 0;
612 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
613 {
614 if (!printed_this)
615 as_bad("unaligned opcodes detected in executable segment");
616 printed_this = 1;
617 }
618 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
619}
620#else
621#define scale_addr_delta(A)
622#endif
623
220e750f
RH
624/* Encode a pair of line and address skips as efficiently as possible.
625 Note that the line skip is signed, whereas the address skip is unsigned.
353e2c69 626
220e750f
RH
627 The following two routines *must* be kept in sync. This is
628 enforced by making emit_inc_line_addr abort if we do not emit
629 exactly the expected number of bytes. */
630
631static int
632size_inc_line_addr (line_delta, addr_delta)
633 int line_delta;
634 addressT addr_delta;
fac0d250 635{
220e750f
RH
636 unsigned int tmp, opcode;
637 int len = 0;
fac0d250 638
220e750f 639 /* Scale the address delta by the minimum instruction length. */
a3b75434 640 scale_addr_delta (&addr_delta);
220e750f
RH
641
642 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
643 We cannot use special opcodes here, since we want the end_sequence
644 to emit the matrix entry. */
645 if (line_delta == INT_MAX)
fac0d250 646 {
220e750f
RH
647 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
648 len = 1;
fac0d250 649 else
220e750f
RH
650 len = 1 + sizeof_leb128 (addr_delta, 0);
651 return len + 3;
fac0d250 652 }
fac0d250 653
220e750f
RH
654 /* Bias the line delta by the base. */
655 tmp = line_delta - DWARF2_LINE_BASE;
fac0d250 656
220e750f
RH
657 /* If the line increment is out of range of a special opcode, we
658 must encode it with DW_LNS_advance_line. */
659 if (tmp >= DWARF2_LINE_RANGE)
660 {
661 len = 1 + sizeof_leb128 (line_delta, 1);
662 line_delta = 0;
663 tmp = 0 - DWARF2_LINE_BASE;
664 }
fac0d250 665
220e750f
RH
666 /* Bias the opcode by the special opcode base. */
667 tmp += DWARF2_LINE_OPCODE_BASE;
353e2c69 668
220e750f
RH
669 /* Avoid overflow when addr_delta is large. */
670 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
671 {
672 /* Try using a special opcode. */
673 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
674 if (opcode <= 255)
675 return len + 1;
676
677 /* Try using DW_LNS_const_add_pc followed by special op. */
678 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
679 if (opcode <= 255)
680 return len + 2;
681 }
682
683 /* Otherwise use DW_LNS_advance_pc. */
684 len += 1 + sizeof_leb128 (addr_delta, 0);
685
686 /* DW_LNS_copy or special opcode. */
687 len += 1;
688
689 return len;
690}
fac0d250 691
220e750f
RH
692static void
693emit_inc_line_addr (line_delta, addr_delta, p, len)
694 int line_delta;
695 addressT addr_delta;
696 char *p;
697 int len;
698{
699 unsigned int tmp, opcode;
700 int need_copy = 0;
701 char *end = p + len;
fac0d250 702
220e750f 703 /* Scale the address delta by the minimum instruction length. */
a3b75434
DD
704 scale_addr_delta (&addr_delta);
705
220e750f
RH
706 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
707 We cannot use special opcodes here, since we want the end_sequence
708 to emit the matrix entry. */
709 if (line_delta == INT_MAX)
fac0d250 710 {
220e750f
RH
711 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
712 *p++ = DW_LNS_const_add_pc;
713 else
fac0d250 714 {
220e750f
RH
715 *p++ = DW_LNS_advance_pc;
716 p += output_leb128 (p, addr_delta, 0);
fac0d250 717 }
220e750f
RH
718
719 *p++ = DW_LNS_extended_op;
720 *p++ = 1;
721 *p++ = DW_LNE_end_sequence;
722 goto done;
fac0d250
RH
723 }
724
220e750f
RH
725 /* Bias the line delta by the base. */
726 tmp = line_delta - DWARF2_LINE_BASE;
727
728 /* If the line increment is out of range of a special opcode, we
729 must encode it with DW_LNS_advance_line. */
730 if (tmp >= DWARF2_LINE_RANGE)
fac0d250 731 {
220e750f
RH
732 *p++ = DW_LNS_advance_line;
733 p += output_leb128 (p, line_delta, 1);
fac0d250 734
220e750f
RH
735 /* Prettier, I think, to use DW_LNS_copy instead of a
736 "line +0, addr +0" special opcode. */
737 if (addr_delta == 0)
738 {
739 *p++ = DW_LNS_copy;
740 goto done;
741 }
cb30237e 742
220e750f
RH
743 line_delta = 0;
744 tmp = 0 - DWARF2_LINE_BASE;
745 need_copy = 1;
746 }
fac0d250 747
220e750f
RH
748 /* Bias the opcode by the special opcode base. */
749 tmp += DWARF2_LINE_OPCODE_BASE;
fac0d250 750
220e750f
RH
751 /* Avoid overflow when addr_delta is large. */
752 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
fac0d250 753 {
220e750f
RH
754 /* Try using a special opcode. */
755 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
756 if (opcode <= 255)
757 {
758 *p++ = opcode;
759 goto done;
760 }
761
762 /* Try using DW_LNS_const_add_pc followed by special op. */
763 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
764 if (opcode <= 255)
fac0d250 765 {
220e750f
RH
766 *p++ = DW_LNS_const_add_pc;
767 *p++ = opcode;
768 goto done;
fac0d250
RH
769 }
770 }
220e750f
RH
771
772 /* Otherwise use DW_LNS_advance_pc. */
773 *p++ = DW_LNS_advance_pc;
774 p += output_leb128 (p, addr_delta, 0);
775
776 if (need_copy)
777 *p++ = DW_LNS_copy;
fac0d250 778 else
220e750f 779 *p++ = tmp;
fac0d250 780
220e750f
RH
781 done:
782 assert (p == end);
783}
a8316fe2 784
220e750f 785/* Handy routine to combine calls to the above two routines. */
e1c05f12 786
220e750f
RH
787static void
788out_inc_line_addr (line_delta, addr_delta)
789 int line_delta;
790 addressT addr_delta;
791{
792 int len = size_inc_line_addr (line_delta, addr_delta);
793 emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
794}
9de8d8f1 795
220e750f
RH
796/* Generate a variant frag that we can use to relax address/line
797 increments between fragments of the target segment. */
9e3af0e7 798
220e750f
RH
799static void
800relax_inc_line_addr (line_delta, seg, to_frag, to_ofs, from_frag, from_ofs)
801 int line_delta;
802 segT seg;
803 fragS *to_frag, *from_frag;
804 addressT to_ofs, from_ofs;
805{
806 symbolS *to_sym, *from_sym;
807 expressionS expr;
808 int max_chars;
6576f0b5 809
220e750f
RH
810 to_sym = symbol_new (fake_label_name, seg, to_ofs, to_frag);
811 from_sym = symbol_new (fake_label_name, seg, from_ofs, from_frag);
fac0d250 812
220e750f
RH
813 expr.X_op = O_subtract;
814 expr.X_add_symbol = to_sym;
815 expr.X_op_symbol = from_sym;
816 expr.X_add_number = 0;
fac0d250 817
220e750f
RH
818 /* The maximum size of the frag is the line delta with a maximum
819 sized address delta. */
820 max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH);
fac0d250 821
220e750f
RH
822 frag_var (rs_dwarf2dbg, max_chars, max_chars, 1,
823 make_expr_symbol (&expr), line_delta, NULL);
824}
fac0d250 825
220e750f
RH
826/* The function estimates the size of a rs_dwarf2dbg variant frag
827 based on the current values of the symbols. It is called before
828 the relaxation loop. We set fr_subtype to the expected length. */
fac0d250 829
220e750f
RH
830int
831dwarf2dbg_estimate_size_before_relax (frag)
832 fragS *frag;
833{
834 offsetT addr_delta;
835 int size;
fac0d250 836
6386f3a7 837 addr_delta = resolve_symbol_value (frag->fr_symbol);
220e750f 838 size = size_inc_line_addr (frag->fr_offset, addr_delta);
fac0d250 839
220e750f 840 frag->fr_subtype = size;
fac0d250 841
220e750f
RH
842 return size;
843}
844
845/* This function relaxes a rs_dwarf2dbg variant frag based on the
846 current values of the symbols. fr_subtype is the current length
847 of the frag. This returns the change in frag length. */
848
849int
850dwarf2dbg_relax_frag (frag)
851 fragS *frag;
852{
853 int old_size, new_size;
fac0d250 854
220e750f
RH
855 old_size = frag->fr_subtype;
856 new_size = dwarf2dbg_estimate_size_before_relax (frag);
ee515fb7 857
220e750f 858 return new_size - old_size;
fac0d250
RH
859}
860
220e750f
RH
861/* This function converts a rs_dwarf2dbg variant frag into a normal
862 fill frag. This is called after all relaxation has been done.
863 fr_subtype will be the desired length of the frag. */
864
865void
866dwarf2dbg_convert_frag (frag)
867 fragS *frag;
fac0d250 868{
220e750f
RH
869 offsetT addr_diff;
870
6386f3a7 871 addr_diff = resolve_symbol_value (frag->fr_symbol);
fac0d250 872
220e750f
RH
873 /* fr_var carries the max_chars that we created the fragment with.
874 fr_subtype carries the current expected length. We must, of
875 course, have allocated enough memory earlier. */
bccba5f0 876 assert (frag->fr_var >= (int) frag->fr_subtype);
fac0d250 877
ee515fb7 878 emit_inc_line_addr (frag->fr_offset, addr_diff,
220e750f
RH
879 frag->fr_literal + frag->fr_fix, frag->fr_subtype);
880
881 frag->fr_fix += frag->fr_subtype;
882 frag->fr_type = rs_fill;
883 frag->fr_var = 0;
884 frag->fr_offset = 0;
885}
886
887/* Generate .debug_line content for the chain of line number entries
888 beginning at E, for segment SEG. */
889
890static void
891process_entries (seg, e)
892 segT seg;
893 struct line_entry *e;
894{
895 unsigned filenum = 1;
896 unsigned line = 1;
897 unsigned column = 0;
898 unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_BEGIN_STMT : 0;
899 fragS *frag = NULL;
900 fragS *last_frag;
901 addressT frag_ofs = 0;
902 addressT last_frag_ofs;
903 struct line_entry *next;
904
905 while (e)
fac0d250 906 {
220e750f
RH
907 int changed = 0;
908
909 if (filenum != e->loc.filenum)
fac0d250 910 {
220e750f
RH
911 filenum = e->loc.filenum;
912 out_opcode (DW_LNS_set_file);
913 out_uleb128 (filenum);
914 changed = 1;
915 }
916
917 if (column != e->loc.column)
918 {
919 column = e->loc.column;
920 out_opcode (DW_LNS_set_column);
921 out_uleb128 (column);
922 changed = 1;
923 }
924
925 if ((e->loc.flags ^ flags) & DWARF2_FLAG_BEGIN_STMT)
926 {
927 flags = e->loc.flags;
928 out_opcode (DW_LNS_negate_stmt);
929 changed = 1;
930 }
931
932 if (e->loc.flags & DWARF2_FLAG_BEGIN_BLOCK)
933 {
934 out_opcode (DW_LNS_set_basic_block);
935 changed = 1;
936 }
937
fb81275c
JM
938 /* Don't try to optimize away redundant entries; gdb wants two
939 entries for a function where the code starts on the same line as
940 the {, and there's no way to identify that case here. Trust gcc
941 to optimize appropriately. */
942 if (1 /* line != e->loc.line || changed */)
220e750f
RH
943 {
944 int line_delta = e->loc.line - line;
945 if (frag == NULL)
fac0d250 946 {
220e750f
RH
947 out_set_addr (seg, e->frag, e->frag_ofs);
948 out_inc_line_addr (line_delta, 0);
fac0d250 949 }
220e750f
RH
950 else if (frag == e->frag)
951 out_inc_line_addr (line_delta, e->frag_ofs - frag_ofs);
952 else
953 relax_inc_line_addr (line_delta, seg, e->frag, e->frag_ofs,
954 frag, frag_ofs);
955
956 frag = e->frag;
957 frag_ofs = e->frag_ofs;
958 line = e->loc.line;
fac0d250 959 }
220e750f
RH
960 else if (frag == NULL)
961 {
962 out_set_addr (seg, e->frag, e->frag_ofs);
963 frag = e->frag;
964 frag_ofs = e->frag_ofs;
965 }
966
967 next = e->next;
968 free (e);
969 e = next;
fac0d250 970 }
353e2c69 971
220e750f
RH
972 /* Emit a DW_LNE_end_sequence for the end of the section. */
973 last_frag = last_frag_for_seg (seg);
974 last_frag_ofs = get_frag_fix (last_frag);
975 if (frag == last_frag)
976 out_inc_line_addr (INT_MAX, last_frag_ofs - frag_ofs);
977 else
ee515fb7 978 relax_inc_line_addr (INT_MAX, seg, last_frag, last_frag_ofs,
220e750f 979 frag, frag_ofs);
fac0d250
RH
980}
981
220e750f
RH
982/* Emit the directory and file tables for .debug_line. */
983
fac0d250 984static void
220e750f 985out_file_list ()
fac0d250
RH
986{
987 size_t size;
988 char *cp;
220e750f
RH
989 unsigned int i;
990
991 /* Terminate directory list. */
992 out_byte ('\0');
fac0d250 993
220e750f 994 for (i = 1; i < files_in_use; ++i)
fac0d250 995 {
249e3833
RH
996 if (files[i].filename == NULL)
997 {
0e389e77 998 as_bad (_("unassigned file number %ld"), (long) i);
249e3833
RH
999 continue;
1000 }
1001
220e750f 1002 size = strlen (files[i].filename) + 1;
fac0d250 1003 cp = frag_more (size);
220e750f 1004 memcpy (cp, files[i].filename, size);
fac0d250 1005
220e750f 1006 out_uleb128 (files[i].dir); /* directory number */
fac0d250
RH
1007 out_uleb128 (0); /* last modification timestamp */
1008 out_uleb128 (0); /* filesize */
1009 }
353e2c69
KH
1010
1011 /* Terminate filename list. */
1012 out_byte (0);
fac0d250
RH
1013}
1014
220e750f
RH
1015/* Emit the collected .debug_line data. */
1016
1017static void
1018out_debug_line (line_seg)
1019 segT line_seg;
1020{
1021 expressionS expr;
1022 symbolS *line_start;
1023 symbolS *prologue_end;
1024 symbolS *line_end;
1025 struct line_seg *s;
14e777e0
KB
1026 enum dwarf2_format d2f;
1027 int sizeof_offset;
220e750f
RH
1028
1029 subseg_set (line_seg, 0);
1030
1031 line_start = symbol_new_now ();
1032 prologue_end = symbol_make (fake_label_name);
1033 line_end = symbol_make (fake_label_name);
1034
1035 /* Total length of the information for this compilation unit. */
1036 expr.X_op = O_subtract;
1037 expr.X_add_symbol = line_end;
1038 expr.X_op_symbol = line_start;
14e777e0
KB
1039
1040 d2f = DWARF2_FORMAT ();
1041 if (d2f == dwarf2_format_32bit)
1042 {
1043 expr.X_add_number = -4;
1044 emit_expr (&expr, 4);
1045 sizeof_offset = 4;
1046 }
1047 else if (d2f == dwarf2_format_64bit)
1048 {
1049 expr.X_add_number = -12;
1050 out_four (-1);
1051 emit_expr (&expr, 8);
1052 sizeof_offset = 8;
1053 }
1054 else if (d2f == dwarf2_format_64bit_irix)
1055 {
1056 expr.X_add_number = -8;
1057 emit_expr (&expr, 8);
1058 sizeof_offset = 8;
1059 }
1060 else
1061 {
1062 as_fatal (_("internal error: unknown dwarf2 format"));
1063 }
220e750f
RH
1064
1065 /* Version. */
1066 out_two (2);
1067
1068 /* Length of the prologue following this length. */
1069 expr.X_op = O_subtract;
1070 expr.X_add_symbol = prologue_end;
1071 expr.X_op_symbol = line_start;
1072 expr.X_add_number = - (4 + 2 + 4);
14e777e0 1073 emit_expr (&expr, sizeof_offset);
220e750f
RH
1074
1075 /* Parameters of the state machine. */
1076 out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
1077 out_byte (DWARF2_LINE_DEFAULT_IS_STMT);
1078 out_byte (DWARF2_LINE_BASE);
1079 out_byte (DWARF2_LINE_RANGE);
1080 out_byte (DWARF2_LINE_OPCODE_BASE);
1081
1082 /* Standard opcode lengths. */
1083 out_byte (0); /* DW_LNS_copy */
1084 out_byte (1); /* DW_LNS_advance_pc */
1085 out_byte (1); /* DW_LNS_advance_line */
1086 out_byte (1); /* DW_LNS_set_file */
1087 out_byte (1); /* DW_LNS_set_column */
1088 out_byte (0); /* DW_LNS_negate_stmt */
1089 out_byte (0); /* DW_LNS_set_basic_block */
1090 out_byte (0); /* DW_LNS_const_add_pc */
1091 out_byte (1); /* DW_LNS_fixed_advance_pc */
1092
1093 out_file_list ();
1094
1095 set_symbol_value_now (prologue_end);
1096
1097 /* For each section, emit a statement program. */
ee515fb7 1098 for (s = all_segs; s; s = s->next)
220e750f
RH
1099 process_entries (s->seg, s->head->head);
1100
1101 set_symbol_value_now (line_end);
1102}
1103
1104/* Emit data for .debug_aranges. */
1105
58b5739a 1106static void
220e750f
RH
1107out_debug_aranges (aranges_seg, info_seg)
1108 segT aranges_seg;
1109 segT info_seg;
fac0d250 1110{
220e750f
RH
1111 unsigned int addr_size = sizeof_address;
1112 addressT size, skip;
1113 struct line_seg *s;
1114 expressionS expr;
1115 char *p;
fac0d250 1116
220e750f 1117 size = 4 + 2 + 4 + 1 + 1;
fac0d250 1118
ee515fb7
KH
1119 skip = 2 * addr_size - (size & (2 * addr_size - 1));
1120 if (skip == 2 * addr_size)
220e750f
RH
1121 skip = 0;
1122 size += skip;
fac0d250 1123
ee515fb7
KH
1124 for (s = all_segs; s; s = s->next)
1125 size += 2 * addr_size;
fac0d250 1126
ee515fb7 1127 size += 2 * addr_size;
fac0d250 1128
220e750f 1129 subseg_set (aranges_seg, 0);
fac0d250 1130
220e750f
RH
1131 /* Length of the compilation unit. */
1132 out_four (size - 4);
fac0d250 1133
220e750f
RH
1134 /* Version. */
1135 out_two (2);
4dc7ead9 1136
220e750f
RH
1137 /* Offset to .debug_info. */
1138 expr.X_op = O_symbol;
1139 expr.X_add_symbol = section_symbol (info_seg);
1140 expr.X_add_number = 0;
1141 emit_expr (&expr, 4);
1142
1143 /* Size of an address (offset portion). */
1144 out_byte (addr_size);
1145
1146 /* Size of a segment descriptor. */
1147 out_byte (0);
1148
1149 /* Align the header. */
1150 if (skip)
ee515fb7 1151 frag_align (ffs (2 * addr_size) - 1, 0, 0);
4dc7ead9 1152
ee515fb7 1153 for (s = all_segs; s; s = s->next)
220e750f
RH
1154 {
1155 fragS *frag;
1156 symbolS *beg, *end;
1157
1158 frag = first_frag_for_seg (s->seg);
1159 beg = symbol_new (fake_label_name, s->seg, 0, frag);
1160 s->text_start = beg;
1161
1162 frag = last_frag_for_seg (s->seg);
1163 end = symbol_new (fake_label_name, s->seg, get_frag_fix (frag), frag);
1164 s->text_end = end;
1165
1166 expr.X_op = O_symbol;
1167 expr.X_add_symbol = beg;
1168 expr.X_add_number = 0;
1169 emit_expr (&expr, addr_size);
1170
1171 expr.X_op = O_subtract;
1172 expr.X_add_symbol = end;
1173 expr.X_op_symbol = beg;
1174 expr.X_add_number = 0;
1175 emit_expr (&expr, addr_size);
1176 }
4dc7ead9 1177
220e750f
RH
1178 p = frag_more (2 * addr_size);
1179 md_number_to_chars (p, 0, addr_size);
1180 md_number_to_chars (p + addr_size, 0, addr_size);
4dc7ead9
RH
1181}
1182
220e750f
RH
1183/* Emit data for .debug_abbrev. Note that this must be kept in
1184 sync with out_debug_info below. */
fac0d250 1185
220e750f
RH
1186static void
1187out_debug_abbrev (abbrev_seg)
1188 segT abbrev_seg;
1189{
1190 subseg_set (abbrev_seg, 0);
fac0d250 1191
220e750f
RH
1192 out_uleb128 (1);
1193 out_uleb128 (DW_TAG_compile_unit);
1194 out_byte (DW_CHILDREN_no);
1195 out_abbrev (DW_AT_stmt_list, DW_FORM_data4);
1196 if (all_segs->next == NULL)
4dc7ead9 1197 {
220e750f
RH
1198 out_abbrev (DW_AT_low_pc, DW_FORM_addr);
1199 out_abbrev (DW_AT_high_pc, DW_FORM_addr);
1200 }
48b91938 1201 out_abbrev (DW_AT_name, DW_FORM_string);
220e750f
RH
1202 out_abbrev (DW_AT_comp_dir, DW_FORM_string);
1203 out_abbrev (DW_AT_producer, DW_FORM_string);
1204 out_abbrev (DW_AT_language, DW_FORM_data2);
1205 out_abbrev (0, 0);
a987bfc9
RH
1206
1207 /* Terminate the abbreviations for this compilation unit. */
1208 out_byte (0);
220e750f 1209}
4dc7ead9 1210
220e750f 1211/* Emit a description of this compilation unit for .debug_info. */
4dc7ead9 1212
220e750f
RH
1213static void
1214out_debug_info (info_seg, abbrev_seg, line_seg)
1215 segT info_seg;
1216 segT abbrev_seg;
1217 segT line_seg;
1218{
1219 char producer[128];
1220 char *comp_dir;
1221 expressionS expr;
1222 symbolS *info_start;
1223 symbolS *info_end;
1224 char *p;
1225 int len;
14e777e0
KB
1226 enum dwarf2_format d2f;
1227 int sizeof_offset;
4dc7ead9 1228
220e750f 1229 subseg_set (info_seg, 0);
4dc7ead9 1230
ee515fb7 1231 info_start = symbol_new_now ();
220e750f 1232 info_end = symbol_make (fake_label_name);
4dc7ead9 1233
220e750f
RH
1234 /* Compilation Unit length. */
1235 expr.X_op = O_subtract;
1236 expr.X_add_symbol = info_end;
1237 expr.X_op_symbol = info_start;
14e777e0
KB
1238
1239 d2f = DWARF2_FORMAT ();
1240 if (d2f == dwarf2_format_32bit)
1241 {
1242 expr.X_add_number = -4;
1243 emit_expr (&expr, 4);
1244 sizeof_offset = 4;
1245 }
1246 else if (d2f == dwarf2_format_64bit)
1247 {
1248 expr.X_add_number = -12;
1249 out_four (-1);
1250 emit_expr (&expr, 8);
1251 sizeof_offset = 8;
1252 }
1253 else if (d2f == dwarf2_format_64bit_irix)
1254 {
1255 expr.X_add_number = -8;
1256 emit_expr (&expr, 8);
1257 sizeof_offset = 8;
1258 }
1259 else
1260 {
1261 as_fatal (_("internal error: unknown dwarf2 format"));
1262 }
4dc7ead9 1263
220e750f
RH
1264 /* DWARF version. */
1265 out_two (2);
4dc7ead9 1266
220e750f
RH
1267 /* .debug_abbrev offset */
1268 expr.X_op = O_symbol;
1269 expr.X_add_symbol = section_symbol (abbrev_seg);
1270 expr.X_add_number = 0;
14e777e0 1271 emit_expr (&expr, sizeof_offset);
4dc7ead9 1272
220e750f
RH
1273 /* Target address size. */
1274 out_byte (sizeof_address);
fac0d250 1275
220e750f
RH
1276 /* DW_TAG_compile_unit DIE abbrev */
1277 out_uleb128 (1);
fac0d250 1278
220e750f
RH
1279 /* DW_AT_stmt_list */
1280 expr.X_op = O_symbol;
1281 expr.X_add_symbol = section_symbol (line_seg);
1282 expr.X_add_number = 0;
1283 emit_expr (&expr, 4);
fac0d250 1284
220e750f
RH
1285 /* These two attributes may only be emitted if all of the code is
1286 contiguous. Multiple sections are not that. */
1287 if (all_segs->next == NULL)
58b5739a 1288 {
220e750f
RH
1289 /* DW_AT_low_pc */
1290 expr.X_op = O_symbol;
1291 expr.X_add_symbol = all_segs->text_start;
1292 expr.X_add_number = 0;
1293 emit_expr (&expr, sizeof_address);
1294
1295 /* DW_AT_high_pc */
1296 expr.X_op = O_symbol;
1297 expr.X_add_symbol = all_segs->text_end;
1298 expr.X_add_number = 0;
1299 emit_expr (&expr, sizeof_address);
58b5739a
RH
1300 }
1301
48b91938
RH
1302 /* DW_AT_name. We don't have the actual file name that was present
1303 on the command line, so assume files[1] is the main input file.
1304 We're not supposed to get called unless at least one line number
1305 entry was emitted, so this should always be defined. */
1306 if (!files || files_in_use < 1)
1307 abort ();
1308 len = strlen (files[1].filename) + 1;
1309 p = frag_more (len);
1310 memcpy (p, files[1].filename, len);
1311
220e750f
RH
1312 /* DW_AT_comp_dir */
1313 comp_dir = getpwd ();
1314 len = strlen (comp_dir) + 1;
1315 p = frag_more (len);
1316 memcpy (p, comp_dir, len);
fac0d250 1317
220e750f
RH
1318 /* DW_AT_producer */
1319 sprintf (producer, "GNU AS %s", VERSION);
1320 len = strlen (producer) + 1;
1321 p = frag_more (len);
1322 memcpy (p, producer, len);
fac0d250 1323
220e750f
RH
1324 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1325 dwarf2 draft has no standard code for assembler. */
1326 out_two (DW_LANG_Mips_Assembler);
1327
1328 set_symbol_value_now (info_end);
fac0d250
RH
1329}
1330
1331void
220e750f 1332dwarf2_finish ()
fac0d250 1333{
220e750f
RH
1334 segT line_seg;
1335 struct line_seg *s;
fac0d250 1336
70ee4658
DJ
1337 /* We don't need to do anything unless:
1338 - Some debug information was recorded via .file/.loc
1339 - or, we are generating DWARF2 information ourself (--gdwarf2)
1340 - or, there is a user-provided .debug_info section which could
1341 reference the file table in the .debug_line section we generate
1342 below. */
1343 if (all_segs == NULL
1344 && debug_type != DEBUG_DWARF2
1345 && bfd_get_section_by_name (stdoutput, ".debug_info") == NULL)
220e750f 1346 return;
fac0d250 1347
220e750f 1348 /* Calculate the size of an address for the target machine. */
9605f328 1349 sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
fac0d250 1350
220e750f
RH
1351 /* Create and switch to the line number section. */
1352 line_seg = subseg_new (".debug_line", 0);
220e750f 1353 bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY);
fac0d250 1354
220e750f 1355 /* For each subsection, chain the debug entries together. */
ee515fb7 1356 for (s = all_segs; s; s = s->next)
fac0d250 1357 {
220e750f
RH
1358 struct line_subseg *ss = s->head;
1359 struct line_entry **ptail = ss->ptail;
1360
1361 while ((ss = ss->next) != NULL)
1362 {
1363 *ptail = ss->head;
1364 ptail = ss->ptail;
1365 }
fac0d250 1366 }
85a39694 1367
220e750f 1368 out_debug_line (line_seg);
85a39694 1369
220e750f
RH
1370 /* If this is assembler generated line info, we need .debug_info
1371 and .debug_abbrev sections as well. */
45c500fa 1372 if (all_segs != NULL && debug_type == DEBUG_DWARF2)
220e750f
RH
1373 {
1374 segT abbrev_seg;
1375 segT info_seg;
1376 segT aranges_seg;
4dc7ead9 1377
220e750f
RH
1378 info_seg = subseg_new (".debug_info", 0);
1379 abbrev_seg = subseg_new (".debug_abbrev", 0);
1380 aranges_seg = subseg_new (".debug_aranges", 0);
ef99799a 1381
220e750f
RH
1382 bfd_set_section_flags (stdoutput, info_seg, SEC_READONLY);
1383 bfd_set_section_flags (stdoutput, abbrev_seg, SEC_READONLY);
1384 bfd_set_section_flags (stdoutput, aranges_seg, SEC_READONLY);
ef99799a 1385
ee515fb7 1386 record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
ef99799a 1387
220e750f
RH
1388 out_debug_aranges (aranges_seg, info_seg);
1389 out_debug_abbrev (abbrev_seg);
1390 out_debug_info (info_seg, abbrev_seg, line_seg);
1391 }
85a39694 1392}
92eb7b32
L
1393
1394#else
1395void
1396dwarf2_finish ()
1397{
1398}
1399
1400int
1401dwarf2dbg_estimate_size_before_relax (frag)
1402 fragS *frag ATTRIBUTE_UNUSED;
1403{
1404 as_fatal (_("dwarf2 is not supported for this object file format"));
1405 return 0;
1406}
1407
1408int
1409dwarf2dbg_relax_frag (frag)
1410 fragS *frag ATTRIBUTE_UNUSED;
1411{
1412 as_fatal (_("dwarf2 is not supported for this object file format"));
1413 return 0;
1414}
1415
1416void
1417dwarf2dbg_convert_frag (frag)
1418 fragS *frag ATTRIBUTE_UNUSED;
1419{
1420 as_fatal (_("dwarf2 is not supported for this object file format"));
1421}
1422
1423void
1424dwarf2_emit_insn (size)
1425 int size ATTRIBUTE_UNUSED;
1426{
1427}
1428
70658493 1429char *
92eb7b32
L
1430dwarf2_directive_file (dummy)
1431 int dummy ATTRIBUTE_UNUSED;
1432{
3737d051 1433 s_app_file (0);
70658493 1434 return NULL;
92eb7b32
L
1435}
1436
1437void
1438dwarf2_directive_loc (dummy)
1439 int dummy ATTRIBUTE_UNUSED;
1440{
1441 as_fatal (_("dwarf2 is not supported for this object file format"));
1442}
1443#endif /* BFD_ASSEMBLER */
This page took 0.217907 seconds and 4 git commands to generate.