Fix sparc testcases when building with 64-bit default.
[deliverable/binutils-gdb.git] / gas / dwarf2dbg.c
CommitLineData
fac0d250 1/* dwarf2dbg.c - DWARF2 debug support
aa820537 2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
2da5c037 3 Free Software Foundation, Inc.
fac0d250
RH
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5
6 This file is part of GAS, the GNU Assembler.
7
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
ec2655a6 10 the Free Software Foundation; either version 3, or (at your option)
fac0d250
RH
11 any later version.
12
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.
17
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
4b4da160
NC
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
fac0d250 22
89b66cde 23/* Logical line numbers can be controlled by the compiler via the
bd0eb99b 24 following directives:
fac0d250
RH
25
26 .file FILENO "file.c"
ecea7679 27 .loc FILENO LINENO [COLUMN] [basic_block] [prologue_end] \
92846e72
CC
28 [epilogue_begin] [is_stmt VALUE] [isa VALUE] \
29 [discriminator VALUE]
bd0eb99b 30*/
fac0d250 31
fac0d250 32#include "as.h"
bd0eb99b 33#include "safe-ctype.h"
92eb7b32 34
42dbf88c
NC
35#ifdef HAVE_LIMITS_H
36#include <limits.h>
92625c16 37#else
6717891c
NC
38#ifdef HAVE_SYS_PARAM_H
39#include <sys/param.h>
40#endif
6256f9dd 41#ifndef INT_MAX
ee515fb7 42#define INT_MAX (int) (((unsigned) (-1)) >> 1)
42dbf88c 43#endif
b8f080d6 44#endif
42dbf88c 45
70658493 46#include "dwarf2dbg.h"
a7ed1ca2 47#include <filenames.h>
70658493 48
56487c55
NC
49#ifdef HAVE_DOS_BASED_FILE_SYSTEM
50/* We need to decide which character to use as a directory separator.
51 Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not
52 necessarily mean that the backslash character is the one to use.
53 Some environments, eg Cygwin, can support both naming conventions.
54 So we use the heuristic that we only need to use the backslash if
55 the path is an absolute path starting with a DOS style drive
56 selector. eg C: or D: */
57# define INSERT_DIR_SEPARATOR(string, offset) \
58 do \
59 { \
60 if (offset > 1 \
7fd3924a
AM
61 && string[0] != 0 \
62 && string[1] == ':') \
56487c55
NC
63 string [offset] = '\\'; \
64 else \
65 string [offset] = '/'; \
66 } \
67 while (0)
68#else
69# define INSERT_DIR_SEPARATOR(string, offset) string[offset] = '/'
70#endif
71
14e777e0 72#ifndef DWARF2_FORMAT
413a266c 73# define DWARF2_FORMAT(SEC) dwarf2_format_32bit
14e777e0
KB
74#endif
75
9605f328 76#ifndef DWARF2_ADDR_SIZE
e4475e39 77# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
9605f328
AO
78#endif
79
01e1a5bc
NC
80#ifndef DWARF2_FILE_NAME
81#define DWARF2_FILE_NAME(FILENAME, DIRNAME) FILENAME
82#endif
83
84#ifndef DWARF2_FILE_TIME_NAME
85#define DWARF2_FILE_TIME_NAME(FILENAME,DIRNAME) 0
86#endif
87
88#ifndef DWARF2_FILE_SIZE_NAME
89#define DWARF2_FILE_SIZE_NAME(FILENAME,DIRNAME) 0
90#endif
91
fc0eebac
TG
92#ifndef DWARF2_VERSION
93#define DWARF2_VERSION 2
94#endif
95
fac0d250
RH
96#include "subsegs.h"
97
fa8f86ff 98#include "dwarf2.h"
fac0d250 99
fac0d250
RH
100/* Since we can't generate the prolog until the body is complete, we
101 use three different subsegments for .debug_line: one holding the
102 prolog, one for the directory and filename info, and one for the
103 body ("statement program"). */
104#define DL_PROLOG 0
105#define DL_FILES 1
106#define DL_BODY 2
107
1737851b
BW
108/* If linker relaxation might change offsets in the code, the DWARF special
109 opcodes and variable-length operands cannot be used. If this macro is
110 nonzero, use the DW_LNS_fixed_advance_pc opcode instead. */
111#ifndef DWARF2_USE_FIXED_ADVANCE_PC
112# define DWARF2_USE_FIXED_ADVANCE_PC 0
113#endif
114
fac0d250
RH
115/* First special line opcde - leave room for the standard opcodes.
116 Note: If you want to change this, you'll have to update the
117 "standard_opcode_lengths" table that is emitted below in
bd0eb99b
RH
118 out_debug_line(). */
119#define DWARF2_LINE_OPCODE_BASE 13
fac0d250
RH
120
121#ifndef DWARF2_LINE_BASE
122 /* Minimum line offset in a special line info. opcode. This value
123 was chosen to give a reasonable range of values. */
124# define DWARF2_LINE_BASE -5
125#endif
126
127/* Range of line offsets in a special line info. opcode. */
128#ifndef DWARF2_LINE_RANGE
129# define DWARF2_LINE_RANGE 14
130#endif
131
132#ifndef DWARF2_LINE_MIN_INSN_LENGTH
133 /* Define the architecture-dependent minimum instruction length (in
134 bytes). This value should be rather too small than too big. */
4dc7ead9 135# define DWARF2_LINE_MIN_INSN_LENGTH 1
fac0d250
RH
136#endif
137
bd0eb99b 138/* Flag that indicates the initial value of the is_stmt_start flag. */
fac0d250
RH
139#define DWARF2_LINE_DEFAULT_IS_STMT 1
140
cb30237e 141/* Given a special op, return the line skip amount. */
fac0d250
RH
142#define SPECIAL_LINE(op) \
143 (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE)
144
145/* Given a special op, return the address skip amount (in units of
146 DWARF2_LINE_MIN_INSN_LENGTH. */
147#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
148
cb30237e 149/* The maximum address skip amount that can be encoded with a special op. */
fac0d250
RH
150#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
151
ee515fb7 152struct line_entry {
220e750f 153 struct line_entry *next;
07a53e5c 154 symbolS *label;
220e750f 155 struct dwarf2_line_info loc;
e6c774b4 156};
fac0d250 157
ee515fb7 158struct line_subseg {
220e750f
RH
159 struct line_subseg *next;
160 subsegT subseg;
161 struct line_entry *head;
162 struct line_entry **ptail;
163};
353e2c69 164
ee515fb7 165struct line_seg {
220e750f
RH
166 struct line_seg *next;
167 segT seg;
168 struct line_subseg *head;
169 symbolS *text_start;
170 symbolS *text_end;
171};
172
173/* Collects data for all line table entries during assembly. */
174static struct line_seg *all_segs;
1e9cc1c2
NC
175/* Hash used to quickly lookup a segment by name, avoiding the need to search
176 through the all_segs list. */
177static struct hash_control *all_segs_hash;
178static struct line_seg **last_seg_ptr;
220e750f 179
ee515fb7 180struct file_entry {
a7ed1ca2 181 const char *filename;
220e750f
RH
182 unsigned int dir;
183};
184
185/* Table of files used by .debug_line. */
186static struct file_entry *files;
187static unsigned int files_in_use;
188static unsigned int files_allocated;
189
a7ed1ca2
NC
190/* Table of directories used by .debug_line. */
191static char **dirs;
192static unsigned int dirs_in_use;
193static unsigned int dirs_allocated;
194
b34976b6 195/* TRUE when we've seen a .loc directive recently. Used to avoid
220e750f 196 doing work when there's nothing to do. */
1eee4adc 197bfd_boolean dwarf2_loc_directive_seen;
220e750f 198
07a53e5c
RH
199/* TRUE when we're supposed to set the basic block mark whenever a
200 label is seen. */
201bfd_boolean dwarf2_loc_mark_labels;
202
220e750f 203/* Current location as indicated by the most recent .loc directive. */
bd0eb99b
RH
204static struct dwarf2_line_info current = {
205 1, 1, 0, 0,
92846e72
CC
206 DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0,
207 0
bd0eb99b 208};
220e750f 209
5045d766
RS
210/* Lines that are at the same location as CURRENT, and which are waiting
211 for a label. */
212static struct line_entry *pending_lines, **pending_lines_tail = &pending_lines;
213
220e750f
RH
214/* The size of an address on the target. */
215static unsigned int sizeof_address;
216\f
a2e22468 217static unsigned int get_filenum (const char *, unsigned int);
413a266c 218
c5c0a210 219#ifndef TC_DWARF2_EMIT_OFFSET
802f5d9e 220#define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
c5c0a210 221
6174d9c8
RH
222/* Create an offset to .dwarf2_*. */
223
224static void
a2e22468 225generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
6174d9c8 226{
91d6fa6a 227 expressionS exp;
6174d9c8 228
91d6fa6a
NC
229 exp.X_op = O_symbol;
230 exp.X_add_symbol = symbol;
231 exp.X_add_number = 0;
232 emit_expr (&exp, size);
6174d9c8 233}
c5c0a210 234#endif
6174d9c8 235
220e750f
RH
236/* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */
237
238static struct line_subseg *
a2e22468 239get_line_subseg (segT seg, subsegT subseg)
220e750f
RH
240{
241 static segT last_seg;
242 static subsegT last_subseg;
243 static struct line_subseg *last_line_subseg;
244
1e9cc1c2 245 struct line_seg *s;
91d6fa6a 246 struct line_subseg **pss, *lss;
fac0d250 247
220e750f
RH
248 if (seg == last_seg && subseg == last_subseg)
249 return last_line_subseg;
250
1e9cc1c2
NC
251 s = (struct line_seg *) hash_find (all_segs_hash, seg->name);
252 if (s == NULL)
253 {
254 s = (struct line_seg *) xmalloc (sizeof (*s));
255 s->next = NULL;
256 s->seg = seg;
257 s->head = NULL;
258 *last_seg_ptr = s;
259 last_seg_ptr = &s->next;
260 hash_insert (all_segs_hash, seg->name, s);
261 }
262 gas_assert (seg == s->seg);
220e750f 263
91d6fa6a 264 for (pss = &s->head; (lss = *pss) != NULL ; pss = &lss->next)
fac0d250 265 {
91d6fa6a 266 if (lss->subseg == subseg)
ee515fb7 267 goto found_subseg;
91d6fa6a 268 if (lss->subseg > subseg)
220e750f 269 break;
fac0d250 270 }
220e750f 271
91d6fa6a
NC
272 lss = (struct line_subseg *) xmalloc (sizeof (*lss));
273 lss->next = *pss;
274 lss->subseg = subseg;
275 lss->head = NULL;
276 lss->ptail = &lss->head;
277 *pss = lss;
220e750f
RH
278
279 found_subseg:
280 last_seg = seg;
281 last_subseg = subseg;
91d6fa6a 282 last_line_subseg = lss;
220e750f 283
91d6fa6a 284 return lss;
fac0d250
RH
285}
286
5045d766 287/* Push LOC onto the pending lines list. */
07a53e5c
RH
288
289static void
5045d766 290dwarf2_push_line (struct dwarf2_line_info *loc)
07a53e5c 291{
07a53e5c
RH
292 struct line_entry *e;
293
294 e = (struct line_entry *) xmalloc (sizeof (*e));
295 e->next = NULL;
5045d766 296 e->label = NULL;
07a53e5c
RH
297 e->loc = *loc;
298
5045d766
RS
299 *pending_lines_tail = e;
300 pending_lines_tail = &(*pending_lines_tail)->next;
301}
302
303/* Emit all pending line information. LABEL is the label with which the
304 lines should be associated, or null if they should be associated with
305 the current position. */
306
307static void
308dwarf2_flush_pending_lines (symbolS *label)
309{
310 if (pending_lines)
311 {
312 struct line_subseg *lss;
313 struct line_entry *e;
314
315 if (!label)
48b07401 316 label = symbol_temp_new_now ();
5045d766
RS
317
318 for (e = pending_lines; e; e = e->next)
319 e->label = label;
320
321 lss = get_line_subseg (now_seg, now_subseg);
322 *lss->ptail = pending_lines;
323 lss->ptail = pending_lines_tail;
324
325 pending_lines = NULL;
326 pending_lines_tail = &pending_lines;
327 }
07a53e5c
RH
328}
329
436d9e46 330/* Record an entry for LOC occurring at OFS within the current fragment. */
353e2c69 331
220e750f 332void
a2e22468 333dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
fac0d250 334{
1ea5c325
MS
335 static unsigned int line = -1;
336 static unsigned int filenum = -1;
220e750f
RH
337
338 /* Early out for as-yet incomplete location information. */
339 if (loc->filenum == 0 || loc->line == 0)
340 return;
341
ffa554ed
GK
342 /* Don't emit sequences of line symbols for the same line when the
343 symbols apply to assembler code. It is necessary to emit
344 duplicate line symbols when a compiler asks for them, because GDB
345 uses them to determine the end of the prologue. */
d1a6c242 346 if (debug_type == DEBUG_DWARF2
ffa554ed 347 && line == loc->line && filenum == loc->filenum)
1ea5c325
MS
348 return;
349
350 line = loc->line;
351 filenum = loc->filenum;
352
5045d766
RS
353 dwarf2_push_line (loc);
354 dwarf2_flush_pending_lines (symbol_temp_new (now_seg, ofs, frag_now));
220e750f 355}
fac0d250 356
ecea7679
RH
357/* Returns the current source information. If .file directives have
358 been encountered, the info for the corresponding source file is
359 returned. Otherwise, the info for the assembly source file is
360 returned. */
361
220e750f 362void
a2e22468 363dwarf2_where (struct dwarf2_line_info *line)
220e750f
RH
364{
365 if (debug_type == DEBUG_DWARF2)
fac0d250 366 {
220e750f
RH
367 char *filename;
368 as_where (&filename, &line->line);
a7ed1ca2 369 line->filenum = get_filenum (filename, 0);
220e750f 370 line->column = 0;
bd0eb99b 371 line->flags = DWARF2_FLAG_IS_STMT;
ecea7679 372 line->isa = current.isa;
92846e72 373 line->discriminator = current.discriminator;
fac0d250 374 }
220e750f
RH
375 else
376 *line = current;
fac0d250
RH
377}
378
7fd3924a 379/* A hook to allow the target backend to inform the line number state
ecea7679
RH
380 machine of isa changes when assembler debug info is enabled. */
381
382void
383dwarf2_set_isa (unsigned int isa)
384{
385 current.isa = isa;
386}
387
220e750f
RH
388/* Called for each machine instruction, or relatively atomic group of
389 machine instructions (ie built-in macro). The instruction or group
390 is SIZE bytes in length. If dwarf2 line number generation is called
391 for, emit a line statement appropriately. */
353e2c69 392
220e750f 393void
a2e22468 394dwarf2_emit_insn (int size)
fac0d250 395{
220e750f 396 struct dwarf2_line_info loc;
fac0d250 397
7fd3924a 398 if (!dwarf2_loc_directive_seen && debug_type != DEBUG_DWARF2)
220e750f 399 return;
7fd3924a
AM
400
401 dwarf2_where (&loc);
b6675117 402
220e750f 403 dwarf2_gen_line_info (frag_now_fix () - size, &loc);
661ba50f
BW
404 dwarf2_consume_line_info ();
405}
406
407/* Called after the current line information has been either used with
408 dwarf2_gen_line_info or saved with a machine instruction for later use.
409 This resets the state of the line number information to reflect that
410 it has been used. */
411
412void
413dwarf2_consume_line_info (void)
414{
5045d766
RS
415 /* If the consumer has stashed the current location away for later use,
416 assume that any earlier location information should be associated
417 with ".". */
418 dwarf2_flush_pending_lines (NULL);
419
661ba50f
BW
420 /* Unless we generate DWARF2 debugging information for each
421 assembler line, we only emit one line symbol for one LOC. */
7fd3924a 422 dwarf2_loc_directive_seen = FALSE;
bd0eb99b
RH
423
424 current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK
425 | DWARF2_FLAG_PROLOGUE_END
426 | DWARF2_FLAG_EPILOGUE_BEGIN);
92846e72 427 current.discriminator = 0;
220e750f 428}
fac0d250 429
07a53e5c
RH
430/* Called for each (preferably code) label. If dwarf2_loc_mark_labels
431 is enabled, emit a basic block marker. */
432
433void
434dwarf2_emit_label (symbolS *label)
435{
436 struct dwarf2_line_info loc;
437
438 if (!dwarf2_loc_mark_labels)
439 return;
440 if (S_GET_SEGMENT (label) != now_seg)
441 return;
442 if (!(bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE))
443 return;
7fd3924a
AM
444 if (files_in_use == 0 && debug_type != DEBUG_DWARF2)
445 return;
446
447 dwarf2_where (&loc);
07a53e5c
RH
448
449 loc.flags |= DWARF2_FLAG_BASIC_BLOCK;
450
5045d766
RS
451 dwarf2_push_line (&loc);
452 dwarf2_flush_pending_lines (label);
7fd3924a 453 dwarf2_consume_line_info ();
07a53e5c
RH
454}
455
a7ed1ca2
NC
456/* Get a .debug_line file number for FILENAME. If NUM is nonzero,
457 allocate it on that file table slot, otherwise return the first
458 empty one. */
220e750f
RH
459
460static unsigned int
a2e22468 461get_filenum (const char *filename, unsigned int num)
220e750f 462{
a7ed1ca2
NC
463 static unsigned int last_used, last_used_dir_len;
464 const char *file;
465 size_t dir_len;
466 unsigned int i, dir;
220e750f 467
a7ed1ca2
NC
468 if (num == 0 && last_used)
469 {
470 if (! files[last_used].dir
8b6efd89 471 && filename_cmp (filename, files[last_used].filename) == 0)
a7ed1ca2
NC
472 return last_used;
473 if (files[last_used].dir
8b6efd89
KT
474 && filename_ncmp (filename, dirs[files[last_used].dir],
475 last_used_dir_len) == 0
a7ed1ca2 476 && IS_DIR_SEPARATOR (filename [last_used_dir_len])
8b6efd89
KT
477 && filename_cmp (filename + last_used_dir_len + 1,
478 files[last_used].filename) == 0)
a7ed1ca2
NC
479 return last_used;
480 }
220e750f 481
a7ed1ca2
NC
482 file = lbasename (filename);
483 /* Don't make empty string from / or A: from A:/ . */
484#ifdef HAVE_DOS_BASED_FILE_SYSTEM
485 if (file <= filename + 3)
486 file = filename;
487#else
488 if (file == filename + 1)
489 file = filename;
490#endif
491 dir_len = file - filename;
492
493 dir = 0;
494 if (dir_len)
495 {
01e1a5bc 496#ifndef DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
a7ed1ca2 497 --dir_len;
01e1a5bc 498#endif
a7ed1ca2 499 for (dir = 1; dir < dirs_in_use; ++dir)
8b6efd89 500 if (filename_ncmp (filename, dirs[dir], dir_len) == 0
a7ed1ca2
NC
501 && dirs[dir][dir_len] == '\0')
502 break;
503
504 if (dir >= dirs_in_use)
505 {
506 if (dir >= dirs_allocated)
507 {
508 dirs_allocated = dir + 32;
509 dirs = (char **)
510 xrealloc (dirs, (dir + 32) * sizeof (const char *));
511 }
512
1e9cc1c2 513 dirs[dir] = (char *) xmalloc (dir_len + 1);
a7ed1ca2
NC
514 memcpy (dirs[dir], filename, dir_len);
515 dirs[dir][dir_len] = '\0';
516 dirs_in_use = dir + 1;
517 }
518 }
519
520 if (num == 0)
521 {
522 for (i = 1; i < files_in_use; ++i)
523 if (files[i].dir == dir
88b4ca40 524 && files[i].filename
8b6efd89 525 && filename_cmp (file, files[i].filename) == 0)
a7ed1ca2
NC
526 {
527 last_used = i;
528 last_used_dir_len = dir_len;
529 return i;
530 }
531 }
532 else
533 i = num;
220e750f
RH
534
535 if (i >= files_allocated)
fac0d250 536 {
249e3833
RH
537 unsigned int old = files_allocated;
538
220e750f
RH
539 files_allocated = i + 32;
540 files = (struct file_entry *)
ee515fb7 541 xrealloc (files, (i + 32) * sizeof (struct file_entry));
249e3833
RH
542
543 memset (files + old, 0, (i + 32 - old) * sizeof (struct file_entry));
fac0d250
RH
544 }
545
a7ed1ca2
NC
546 files[i].filename = num ? file : xstrdup (file);
547 files[i].dir = dir;
10cd14b4
AM
548 if (files_in_use < i + 1)
549 files_in_use = i + 1;
220e750f 550 last_used = i;
a7ed1ca2 551 last_used_dir_len = dir_len;
220e750f
RH
552
553 return i;
554}
fac0d250 555
ecb4347a
DJ
556/* Handle two forms of .file directive:
557 - Pass .file "source.c" to s_app_file
558 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table
220e750f 559
ecb4347a
DJ
560 If an entry is added to the file table, return a pointer to the filename. */
561
562char *
a2e22468 563dwarf2_directive_file (int dummy ATTRIBUTE_UNUSED)
220e750f
RH
564{
565 offsetT num;
e46d99eb 566 char *filename;
220e750f
RH
567 int filename_len;
568
569 /* Continue to accept a bare string and pass it off. */
570 SKIP_WHITESPACE ();
571 if (*input_line_pointer == '"')
fac0d250 572 {
220e750f 573 s_app_file (0);
ecb4347a 574 return NULL;
fac0d250
RH
575 }
576
220e750f
RH
577 num = get_absolute_expression ();
578 filename = demand_copy_C_string (&filename_len);
bd0eb99b
RH
579 if (filename == NULL)
580 return NULL;
220e750f
RH
581 demand_empty_rest_of_line ();
582
249e3833 583 if (num < 1)
fac0d250 584 {
0e389e77 585 as_bad (_("file number less than one"));
ecb4347a 586 return NULL;
fac0d250
RH
587 }
588
7cadeb2c
AM
589 /* A .file directive implies compiler generated debug information is
590 being supplied. Turn off gas generated debug info. */
591 debug_type = DEBUG_NONE;
592
0e1a166b 593 if (num < (int) files_in_use && files[num].filename != 0)
220e750f 594 {
0e389e77 595 as_bad (_("file number %ld already allocated"), (long) num);
ecb4347a 596 return NULL;
249e3833 597 }
220e750f 598
a7ed1ca2 599 get_filenum (filename, num);
ecb4347a
DJ
600
601 return filename;
fac0d250
RH
602}
603
220e750f 604void
a2e22468 605dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
220e750f 606{
ecea7679
RH
607 offsetT filenum, line;
608
851feff8
DJ
609 /* If we see two .loc directives in a row, force the first one to be
610 output now. */
7cadeb2c 611 if (dwarf2_loc_directive_seen)
5045d766 612 dwarf2_push_line (&current);
851feff8 613
ecea7679
RH
614 filenum = get_absolute_expression ();
615 SKIP_WHITESPACE ();
616 line = get_absolute_expression ();
617
618 if (filenum < 1)
619 {
620 as_bad (_("file number less than one"));
621 return;
622 }
623 if (filenum >= (int) files_in_use || files[filenum].filename == 0)
624 {
625 as_bad (_("unassigned file number %ld"), (long) filenum);
626 return;
627 }
628
629 current.filenum = filenum;
630 current.line = line;
92846e72 631 current.discriminator = 0;
ecea7679
RH
632
633#ifndef NO_LISTING
634 if (listing)
635 {
636 if (files[filenum].dir)
637 {
638 size_t dir_len = strlen (dirs[files[filenum].dir]);
639 size_t file_len = strlen (files[filenum].filename);
640 char *cp = (char *) alloca (dir_len + 1 + file_len + 1);
641
642 memcpy (cp, dirs[files[filenum].dir], dir_len);
56487c55 643 INSERT_DIR_SEPARATOR (cp, dir_len);
ecea7679
RH
644 memcpy (cp + dir_len + 1, files[filenum].filename, file_len);
645 cp[dir_len + file_len + 1] = '\0';
646 listing_source_file (cp);
647 }
648 else
649 listing_source_file (files[filenum].filename);
650 listing_source_line (line);
651 }
652#endif
653
220e750f 654 SKIP_WHITESPACE ();
ecea7679
RH
655 if (ISDIGIT (*input_line_pointer))
656 {
657 current.column = get_absolute_expression ();
658 SKIP_WHITESPACE ();
659 }
660
661 while (ISALPHA (*input_line_pointer))
220e750f 662 {
bd0eb99b
RH
663 char *p, c;
664 offsetT value;
665
666 p = input_line_pointer;
667 c = get_symbol_end ();
668
669 if (strcmp (p, "basic_block") == 0)
670 {
671 current.flags |= DWARF2_FLAG_BASIC_BLOCK;
672 *input_line_pointer = c;
673 }
674 else if (strcmp (p, "prologue_end") == 0)
675 {
676 current.flags |= DWARF2_FLAG_PROLOGUE_END;
677 *input_line_pointer = c;
678 }
679 else if (strcmp (p, "epilogue_begin") == 0)
680 {
681 current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
682 *input_line_pointer = c;
683 }
684 else if (strcmp (p, "is_stmt") == 0)
685 {
686 *input_line_pointer = c;
687 value = get_absolute_expression ();
688 if (value == 0)
689 current.flags &= ~DWARF2_FLAG_IS_STMT;
690 else if (value == 1)
691 current.flags |= DWARF2_FLAG_IS_STMT;
692 else
ecea7679
RH
693 {
694 as_bad (_("is_stmt value not 0 or 1"));
695 return;
696 }
bd0eb99b
RH
697 }
698 else if (strcmp (p, "isa") == 0)
699 {
7fd3924a 700 *input_line_pointer = c;
bd0eb99b 701 value = get_absolute_expression ();
ecea7679 702 if (value >= 0)
bd0eb99b 703 current.isa = value;
ecea7679
RH
704 else
705 {
706 as_bad (_("isa number less than zero"));
707 return;
708 }
bd0eb99b 709 }
92846e72
CC
710 else if (strcmp (p, "discriminator") == 0)
711 {
712 *input_line_pointer = c;
713 value = get_absolute_expression ();
714 if (value >= 0)
715 current.discriminator = value;
716 else
717 {
718 as_bad (_("discriminator less than zero"));
719 return;
720 }
721 }
bd0eb99b
RH
722 else
723 {
ecea7679 724 as_bad (_("unknown .loc sub-directive `%s'"), p);
7fd3924a 725 *input_line_pointer = c;
bd0eb99b
RH
726 return;
727 }
728
ecea7679 729 SKIP_WHITESPACE ();
bd0eb99b
RH
730 }
731
732 demand_empty_rest_of_line ();
1eee4adc 733 dwarf2_loc_directive_seen = TRUE;
7cadeb2c 734 debug_type = DEBUG_NONE;
220e750f 735}
07a53e5c
RH
736
737void
738dwarf2_directive_loc_mark_labels (int dummy ATTRIBUTE_UNUSED)
739{
740 offsetT value = get_absolute_expression ();
741
742 if (value != 0 && value != 1)
743 {
744 as_bad (_("expected 0 or 1"));
745 ignore_rest_of_line ();
746 }
747 else
748 {
749 dwarf2_loc_mark_labels = value != 0;
750 demand_empty_rest_of_line ();
751 }
752}
220e750f
RH
753\f
754static struct frag *
a2e22468 755first_frag_for_seg (segT seg)
220e750f 756{
c9049d30 757 return seg_info (seg)->frchainP->frch_root;
220e750f
RH
758}
759
760static struct frag *
a2e22468 761last_frag_for_seg (segT seg)
220e750f 762{
c9049d30 763 frchainS *f = seg_info (seg)->frchainP;
220e750f 764
c9049d30
AM
765 while (f->frch_next != NULL)
766 f = f->frch_next;
220e750f 767
c9049d30 768 return f->frch_last;
220e750f
RH
769}
770\f
771/* Emit a single byte into the current segment. */
772
773static inline void
a2e22468 774out_byte (int byte)
220e750f
RH
775{
776 FRAG_APPEND_1_CHAR (byte);
777}
778
779/* Emit a statement program opcode into the current segment. */
780
781static inline void
a2e22468 782out_opcode (int opc)
220e750f
RH
783{
784 out_byte (opc);
785}
786
787/* Emit a two-byte word into the current segment. */
788
789static inline void
a2e22468 790out_two (int data)
220e750f
RH
791{
792 md_number_to_chars (frag_more (2), data, 2);
793}
794
795/* Emit a four byte word into the current segment. */
796
797static inline void
a2e22468 798out_four (int data)
220e750f
RH
799{
800 md_number_to_chars (frag_more (4), data, 4);
801}
802
803/* Emit an unsigned "little-endian base 128" number. */
804
fac0d250 805static void
a2e22468 806out_uleb128 (addressT value)
220e750f
RH
807{
808 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
809}
810
92846e72
CC
811/* Emit a signed "little-endian base 128" number. */
812
813static void
814out_leb128 (addressT value)
815{
816 output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
817}
818
220e750f
RH
819/* Emit a tuple for .debug_abbrev. */
820
821static inline void
a2e22468 822out_abbrev (int name, int form)
fac0d250 823{
220e750f
RH
824 out_uleb128 (name);
825 out_uleb128 (form);
826}
fac0d250 827
220e750f 828/* Get the size of a fragment. */
fac0d250 829
220e750f 830static offsetT
c9049d30 831get_frag_fix (fragS *frag, segT seg)
220e750f
RH
832{
833 frchainS *fr;
834
835 if (frag->fr_next)
836 return frag->fr_fix;
837
838 /* If a fragment is the last in the chain, special measures must be
839 taken to find its size before relaxation, since it may be pending
840 on some subsegment chain. */
c9049d30 841 for (fr = seg_info (seg)->frchainP; fr; fr = fr->frch_next)
220e750f 842 if (fr->frch_last == frag)
c5c0a210 843 return (char *) obstack_next_free (&fr->frch_obstack) - frag->fr_literal;
220e750f
RH
844
845 abort ();
846}
fac0d250 847
220e750f 848/* Set an absolute address (may result in a relocation entry). */
fac0d250 849
220e750f 850static void
07a53e5c 851out_set_addr (symbolS *sym)
220e750f 852{
91d6fa6a 853 expressionS exp;
9e3af0e7 854
fac0d250 855 out_opcode (DW_LNS_extended_op);
220e750f 856 out_uleb128 (sizeof_address + 1);
fac0d250
RH
857
858 out_opcode (DW_LNE_set_address);
91d6fa6a
NC
859 exp.X_op = O_symbol;
860 exp.X_add_symbol = sym;
861 exp.X_add_number = 0;
862 emit_expr (&exp, sizeof_address);
fac0d250
RH
863}
864
a3b75434 865#if DWARF2_LINE_MIN_INSN_LENGTH > 1
a2e22468 866static void scale_addr_delta (addressT *);
c8970b4b 867
a3b75434 868static void
d7342424 869scale_addr_delta (addressT *addr_delta)
a3b75434
DD
870{
871 static int printed_this = 0;
872 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0)
873 {
874 if (!printed_this)
875 as_bad("unaligned opcodes detected in executable segment");
876 printed_this = 1;
877 }
878 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH;
879}
880#else
881#define scale_addr_delta(A)
882#endif
883
220e750f
RH
884/* Encode a pair of line and address skips as efficiently as possible.
885 Note that the line skip is signed, whereas the address skip is unsigned.
353e2c69 886
220e750f
RH
887 The following two routines *must* be kept in sync. This is
888 enforced by making emit_inc_line_addr abort if we do not emit
889 exactly the expected number of bytes. */
890
891static int
a2e22468 892size_inc_line_addr (int line_delta, addressT addr_delta)
fac0d250 893{
220e750f
RH
894 unsigned int tmp, opcode;
895 int len = 0;
fac0d250 896
220e750f 897 /* Scale the address delta by the minimum instruction length. */
a3b75434 898 scale_addr_delta (&addr_delta);
220e750f
RH
899
900 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
901 We cannot use special opcodes here, since we want the end_sequence
902 to emit the matrix entry. */
903 if (line_delta == INT_MAX)
fac0d250 904 {
220e750f
RH
905 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
906 len = 1;
fac0d250 907 else
220e750f
RH
908 len = 1 + sizeof_leb128 (addr_delta, 0);
909 return len + 3;
fac0d250 910 }
fac0d250 911
220e750f
RH
912 /* Bias the line delta by the base. */
913 tmp = line_delta - DWARF2_LINE_BASE;
fac0d250 914
220e750f
RH
915 /* If the line increment is out of range of a special opcode, we
916 must encode it with DW_LNS_advance_line. */
917 if (tmp >= DWARF2_LINE_RANGE)
918 {
919 len = 1 + sizeof_leb128 (line_delta, 1);
920 line_delta = 0;
921 tmp = 0 - DWARF2_LINE_BASE;
922 }
fac0d250 923
220e750f
RH
924 /* Bias the opcode by the special opcode base. */
925 tmp += DWARF2_LINE_OPCODE_BASE;
353e2c69 926
220e750f
RH
927 /* Avoid overflow when addr_delta is large. */
928 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
929 {
930 /* Try using a special opcode. */
931 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
932 if (opcode <= 255)
933 return len + 1;
934
935 /* Try using DW_LNS_const_add_pc followed by special op. */
936 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
937 if (opcode <= 255)
938 return len + 2;
939 }
940
941 /* Otherwise use DW_LNS_advance_pc. */
942 len += 1 + sizeof_leb128 (addr_delta, 0);
943
944 /* DW_LNS_copy or special opcode. */
945 len += 1;
946
947 return len;
948}
fac0d250 949
220e750f 950static void
a2e22468 951emit_inc_line_addr (int line_delta, addressT addr_delta, char *p, int len)
220e750f
RH
952{
953 unsigned int tmp, opcode;
954 int need_copy = 0;
955 char *end = p + len;
fac0d250 956
07a53e5c
RH
957 /* Line number sequences cannot go backward in addresses. This means
958 we've incorrectly ordered the statements in the sequence. */
9c2799c2 959 gas_assert ((offsetT) addr_delta >= 0);
07a53e5c 960
220e750f 961 /* Scale the address delta by the minimum instruction length. */
a3b75434
DD
962 scale_addr_delta (&addr_delta);
963
220e750f
RH
964 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence.
965 We cannot use special opcodes here, since we want the end_sequence
966 to emit the matrix entry. */
967 if (line_delta == INT_MAX)
fac0d250 968 {
220e750f
RH
969 if (addr_delta == MAX_SPECIAL_ADDR_DELTA)
970 *p++ = DW_LNS_const_add_pc;
971 else
fac0d250 972 {
220e750f
RH
973 *p++ = DW_LNS_advance_pc;
974 p += output_leb128 (p, addr_delta, 0);
fac0d250 975 }
220e750f
RH
976
977 *p++ = DW_LNS_extended_op;
978 *p++ = 1;
979 *p++ = DW_LNE_end_sequence;
980 goto done;
fac0d250
RH
981 }
982
220e750f
RH
983 /* Bias the line delta by the base. */
984 tmp = line_delta - DWARF2_LINE_BASE;
985
986 /* If the line increment is out of range of a special opcode, we
987 must encode it with DW_LNS_advance_line. */
988 if (tmp >= DWARF2_LINE_RANGE)
fac0d250 989 {
220e750f
RH
990 *p++ = DW_LNS_advance_line;
991 p += output_leb128 (p, line_delta, 1);
fac0d250 992
220e750f
RH
993 line_delta = 0;
994 tmp = 0 - DWARF2_LINE_BASE;
995 need_copy = 1;
996 }
fac0d250 997
bd0eb99b
RH
998 /* Prettier, I think, to use DW_LNS_copy instead of a "line +0, addr +0"
999 special opcode. */
1000 if (line_delta == 0 && addr_delta == 0)
1001 {
1002 *p++ = DW_LNS_copy;
1003 goto done;
1004 }
1005
220e750f
RH
1006 /* Bias the opcode by the special opcode base. */
1007 tmp += DWARF2_LINE_OPCODE_BASE;
fac0d250 1008
220e750f
RH
1009 /* Avoid overflow when addr_delta is large. */
1010 if (addr_delta < 256 + MAX_SPECIAL_ADDR_DELTA)
fac0d250 1011 {
220e750f
RH
1012 /* Try using a special opcode. */
1013 opcode = tmp + addr_delta * DWARF2_LINE_RANGE;
1014 if (opcode <= 255)
1015 {
1016 *p++ = opcode;
1017 goto done;
1018 }
1019
1020 /* Try using DW_LNS_const_add_pc followed by special op. */
1021 opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
1022 if (opcode <= 255)
fac0d250 1023 {
220e750f
RH
1024 *p++ = DW_LNS_const_add_pc;
1025 *p++ = opcode;
1026 goto done;
fac0d250
RH
1027 }
1028 }
220e750f
RH
1029
1030 /* Otherwise use DW_LNS_advance_pc. */
1031 *p++ = DW_LNS_advance_pc;
1032 p += output_leb128 (p, addr_delta, 0);
1033
1034 if (need_copy)
1035 *p++ = DW_LNS_copy;
fac0d250 1036 else
220e750f 1037 *p++ = tmp;
fac0d250 1038
220e750f 1039 done:
9c2799c2 1040 gas_assert (p == end);
220e750f 1041}
a8316fe2 1042
220e750f 1043/* Handy routine to combine calls to the above two routines. */
e1c05f12 1044
220e750f 1045static void
a2e22468 1046out_inc_line_addr (int line_delta, addressT addr_delta)
220e750f
RH
1047{
1048 int len = size_inc_line_addr (line_delta, addr_delta);
1049 emit_inc_line_addr (line_delta, addr_delta, frag_more (len), len);
1050}
9de8d8f1 1051
1737851b
BW
1052/* Write out an alternative form of line and address skips using
1053 DW_LNS_fixed_advance_pc opcodes. This uses more space than the default
7ddd14de
BW
1054 line and address information, but it is required if linker relaxation
1055 could change the code offsets. The following two routines *must* be
1056 kept in sync. */
1737851b 1057
7ddd14de
BW
1058static int
1059size_fixed_inc_line_addr (int line_delta, addressT addr_delta)
1737851b 1060{
7ddd14de 1061 int len = 0;
1737851b
BW
1062
1063 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
7ddd14de
BW
1064 if (line_delta != INT_MAX)
1065 len = 1 + sizeof_leb128 (line_delta, 1);
1066
1067 if (addr_delta > 50000)
1068 {
1069 /* DW_LNS_extended_op */
1070 len += 1 + sizeof_leb128 (sizeof_address + 1, 0);
1071 /* DW_LNE_set_address */
1072 len += 1 + sizeof_address;
1073 }
1074 else
1075 /* DW_LNS_fixed_advance_pc */
1076 len += 3;
1077
1737851b 1078 if (line_delta == INT_MAX)
7ddd14de
BW
1079 /* DW_LNS_extended_op + DW_LNE_end_sequence */
1080 len += 3;
1081 else
1082 /* DW_LNS_copy */
1083 len += 1;
1084
1085 return len;
1086}
1087
1088static void
1089emit_fixed_inc_line_addr (int line_delta, addressT addr_delta, fragS *frag,
1090 char *p, int len)
1091{
91d6fa6a 1092 expressionS *pexp;
7ddd14de
BW
1093 segT line_seg;
1094 char *end = p + len;
1095
1096 /* Line number sequences cannot go backward in addresses. This means
1097 we've incorrectly ordered the statements in the sequence. */
9c2799c2 1098 gas_assert ((offsetT) addr_delta >= 0);
7ddd14de
BW
1099
1100 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. */
1101 if (line_delta != INT_MAX)
1102 {
1103 *p++ = DW_LNS_advance_line;
1104 p += output_leb128 (p, line_delta, 1);
1105 }
1106
91d6fa6a 1107 pexp = symbol_get_value_expression (frag->fr_symbol);
7ddd14de
BW
1108 line_seg = subseg_get (".debug_line", 0);
1109
1110 /* The DW_LNS_fixed_advance_pc opcode has a 2-byte operand so it can
1111 advance the address by at most 64K. Linker relaxation (without
1112 which this function would not be used) could change the operand by
1113 an unknown amount. If the address increment is getting close to
1114 the limit, just reset the address. */
1115 if (addr_delta > 50000)
1737851b 1116 {
7ddd14de 1117 symbolS *to_sym;
91d6fa6a 1118 expressionS exp;
7ddd14de 1119
9f6db0d3 1120 gas_assert (pexp->X_op == O_subtract);
91d6fa6a 1121 to_sym = pexp->X_add_symbol;
7ddd14de
BW
1122
1123 *p++ = DW_LNS_extended_op;
1124 p += output_leb128 (p, sizeof_address + 1, 0);
1125 *p++ = DW_LNE_set_address;
91d6fa6a
NC
1126 exp.X_op = O_symbol;
1127 exp.X_add_symbol = to_sym;
1128 exp.X_add_number = 0;
7ddd14de 1129 subseg_change (line_seg, 0);
91d6fa6a 1130 emit_expr_fix (&exp, sizeof_address, frag, p);
7ddd14de
BW
1131 p += sizeof_address;
1132 }
1133 else
1134 {
1135 *p++ = DW_LNS_fixed_advance_pc;
1136 subseg_change (line_seg, 0);
91d6fa6a 1137 emit_expr_fix (pexp, 2, frag, p);
7ddd14de 1138 p += 2;
1737851b
BW
1139 }
1140
7ddd14de
BW
1141 if (line_delta == INT_MAX)
1142 {
1143 *p++ = DW_LNS_extended_op;
1144 *p++ = 1;
1145 *p++ = DW_LNE_end_sequence;
1146 }
1147 else
1148 *p++ = DW_LNS_copy;
1737851b 1149
9c2799c2 1150 gas_assert (p == end);
1737851b
BW
1151}
1152
220e750f
RH
1153/* Generate a variant frag that we can use to relax address/line
1154 increments between fragments of the target segment. */
9e3af0e7 1155
220e750f 1156static void
07a53e5c 1157relax_inc_line_addr (int line_delta, symbolS *to_sym, symbolS *from_sym)
220e750f 1158{
91d6fa6a 1159 expressionS exp;
220e750f 1160 int max_chars;
6576f0b5 1161
91d6fa6a
NC
1162 exp.X_op = O_subtract;
1163 exp.X_add_symbol = to_sym;
1164 exp.X_op_symbol = from_sym;
1165 exp.X_add_number = 0;
fac0d250 1166
220e750f
RH
1167 /* The maximum size of the frag is the line delta with a maximum
1168 sized address delta. */
7ddd14de
BW
1169 if (DWARF2_USE_FIXED_ADVANCE_PC)
1170 max_chars = size_fixed_inc_line_addr (line_delta,
1171 -DWARF2_LINE_MIN_INSN_LENGTH);
1172 else
1173 max_chars = size_inc_line_addr (line_delta, -DWARF2_LINE_MIN_INSN_LENGTH);
fac0d250 1174
220e750f 1175 frag_var (rs_dwarf2dbg, max_chars, max_chars, 1,
91d6fa6a 1176 make_expr_symbol (&exp), line_delta, NULL);
220e750f 1177}
fac0d250 1178
220e750f
RH
1179/* The function estimates the size of a rs_dwarf2dbg variant frag
1180 based on the current values of the symbols. It is called before
1181 the relaxation loop. We set fr_subtype to the expected length. */
fac0d250 1182
220e750f 1183int
a2e22468 1184dwarf2dbg_estimate_size_before_relax (fragS *frag)
220e750f
RH
1185{
1186 offsetT addr_delta;
1187 int size;
fac0d250 1188
6386f3a7 1189 addr_delta = resolve_symbol_value (frag->fr_symbol);
7ddd14de
BW
1190 if (DWARF2_USE_FIXED_ADVANCE_PC)
1191 size = size_fixed_inc_line_addr (frag->fr_offset, addr_delta);
1192 else
1193 size = size_inc_line_addr (frag->fr_offset, addr_delta);
fac0d250 1194
220e750f 1195 frag->fr_subtype = size;
fac0d250 1196
220e750f
RH
1197 return size;
1198}
1199
1200/* This function relaxes a rs_dwarf2dbg variant frag based on the
1201 current values of the symbols. fr_subtype is the current length
1202 of the frag. This returns the change in frag length. */
1203
1204int
a2e22468 1205dwarf2dbg_relax_frag (fragS *frag)
220e750f
RH
1206{
1207 int old_size, new_size;
fac0d250 1208
220e750f
RH
1209 old_size = frag->fr_subtype;
1210 new_size = dwarf2dbg_estimate_size_before_relax (frag);
ee515fb7 1211
220e750f 1212 return new_size - old_size;
fac0d250
RH
1213}
1214
220e750f
RH
1215/* This function converts a rs_dwarf2dbg variant frag into a normal
1216 fill frag. This is called after all relaxation has been done.
1217 fr_subtype will be the desired length of the frag. */
1218
1219void
a2e22468 1220dwarf2dbg_convert_frag (fragS *frag)
fac0d250 1221{
220e750f
RH
1222 offsetT addr_diff;
1223
6386f3a7 1224 addr_diff = resolve_symbol_value (frag->fr_symbol);
fac0d250 1225
220e750f
RH
1226 /* fr_var carries the max_chars that we created the fragment with.
1227 fr_subtype carries the current expected length. We must, of
1228 course, have allocated enough memory earlier. */
9c2799c2 1229 gas_assert (frag->fr_var >= (int) frag->fr_subtype);
fac0d250 1230
7ddd14de
BW
1231 if (DWARF2_USE_FIXED_ADVANCE_PC)
1232 emit_fixed_inc_line_addr (frag->fr_offset, addr_diff, frag,
1233 frag->fr_literal + frag->fr_fix,
1234 frag->fr_subtype);
1235 else
1236 emit_inc_line_addr (frag->fr_offset, addr_diff,
1237 frag->fr_literal + frag->fr_fix, frag->fr_subtype);
220e750f
RH
1238
1239 frag->fr_fix += frag->fr_subtype;
1240 frag->fr_type = rs_fill;
1241 frag->fr_var = 0;
1242 frag->fr_offset = 0;
1243}
1244
1245/* Generate .debug_line content for the chain of line number entries
1246 beginning at E, for segment SEG. */
1247
1248static void
a2e22468 1249process_entries (segT seg, struct line_entry *e)
220e750f
RH
1250{
1251 unsigned filenum = 1;
1252 unsigned line = 1;
1253 unsigned column = 0;
bd0eb99b
RH
1254 unsigned isa = 0;
1255 unsigned flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
07a53e5c
RH
1256 fragS *last_frag = NULL, *frag;
1257 addressT last_frag_ofs = 0, frag_ofs;
fead5cd9 1258 symbolS *last_lab = NULL, *lab;
220e750f
RH
1259 struct line_entry *next;
1260
fead5cd9 1261 do
fac0d250 1262 {
07a53e5c 1263 int line_delta;
220e750f
RH
1264
1265 if (filenum != e->loc.filenum)
fac0d250 1266 {
220e750f
RH
1267 filenum = e->loc.filenum;
1268 out_opcode (DW_LNS_set_file);
1269 out_uleb128 (filenum);
220e750f
RH
1270 }
1271
1272 if (column != e->loc.column)
1273 {
1274 column = e->loc.column;
1275 out_opcode (DW_LNS_set_column);
1276 out_uleb128 (column);
220e750f
RH
1277 }
1278
92846e72
CC
1279 if (e->loc.discriminator != 0)
1280 {
1281 out_opcode (DW_LNS_extended_op);
1282 out_leb128 (1 + sizeof_leb128 (e->loc.discriminator, 0));
1283 out_opcode (DW_LNE_set_discriminator);
1284 out_uleb128 (e->loc.discriminator);
1285 }
1286
bd0eb99b
RH
1287 if (isa != e->loc.isa)
1288 {
1289 isa = e->loc.isa;
1290 out_opcode (DW_LNS_set_isa);
1291 out_uleb128 (isa);
bd0eb99b
RH
1292 }
1293
1294 if ((e->loc.flags ^ flags) & DWARF2_FLAG_IS_STMT)
220e750f
RH
1295 {
1296 flags = e->loc.flags;
1297 out_opcode (DW_LNS_negate_stmt);
220e750f
RH
1298 }
1299
bd0eb99b 1300 if (e->loc.flags & DWARF2_FLAG_BASIC_BLOCK)
07a53e5c 1301 out_opcode (DW_LNS_set_basic_block);
220e750f 1302
bd0eb99b 1303 if (e->loc.flags & DWARF2_FLAG_PROLOGUE_END)
07a53e5c 1304 out_opcode (DW_LNS_set_prologue_end);
bd0eb99b
RH
1305
1306 if (e->loc.flags & DWARF2_FLAG_EPILOGUE_BEGIN)
07a53e5c 1307 out_opcode (DW_LNS_set_epilogue_begin);
bd0eb99b 1308
fb81275c
JM
1309 /* Don't try to optimize away redundant entries; gdb wants two
1310 entries for a function where the code starts on the same line as
1311 the {, and there's no way to identify that case here. Trust gcc
1312 to optimize appropriately. */
07a53e5c
RH
1313 line_delta = e->loc.line - line;
1314 lab = e->label;
1315 frag = symbol_get_frag (lab);
1316 frag_ofs = S_GET_VALUE (lab);
220e750f 1317
07a53e5c 1318 if (last_frag == NULL)
220e750f 1319 {
07a53e5c
RH
1320 out_set_addr (lab);
1321 out_inc_line_addr (line_delta, 0);
220e750f 1322 }
7ddd14de 1323 else if (frag == last_frag && ! DWARF2_USE_FIXED_ADVANCE_PC)
07a53e5c
RH
1324 out_inc_line_addr (line_delta, frag_ofs - last_frag_ofs);
1325 else
1326 relax_inc_line_addr (line_delta, lab, last_lab);
1327
1328 line = e->loc.line;
1329 last_lab = lab;
1330 last_frag = frag;
1331 last_frag_ofs = frag_ofs;
220e750f
RH
1332
1333 next = e->next;
1334 free (e);
1335 e = next;
fac0d250 1336 }
fead5cd9 1337 while (e);
353e2c69 1338
220e750f 1339 /* Emit a DW_LNE_end_sequence for the end of the section. */
07a53e5c 1340 frag = last_frag_for_seg (seg);
c9049d30 1341 frag_ofs = get_frag_fix (frag, seg);
7ddd14de 1342 if (frag == last_frag && ! DWARF2_USE_FIXED_ADVANCE_PC)
07a53e5c 1343 out_inc_line_addr (INT_MAX, frag_ofs - last_frag_ofs);
220e750f 1344 else
07a53e5c
RH
1345 {
1346 lab = symbol_temp_new (seg, frag_ofs, frag);
1347 relax_inc_line_addr (INT_MAX, lab, last_lab);
1348 }
fac0d250
RH
1349}
1350
220e750f
RH
1351/* Emit the directory and file tables for .debug_line. */
1352
fac0d250 1353static void
a2e22468 1354out_file_list (void)
fac0d250
RH
1355{
1356 size_t size;
3d6b762c 1357 const char *dir;
fac0d250 1358 char *cp;
220e750f
RH
1359 unsigned int i;
1360
a7ed1ca2
NC
1361 /* Emit directory list. */
1362 for (i = 1; i < dirs_in_use; ++i)
1363 {
3d6b762c
JM
1364 dir = remap_debug_filename (dirs[i]);
1365 size = strlen (dir) + 1;
a7ed1ca2 1366 cp = frag_more (size);
3d6b762c 1367 memcpy (cp, dir, size);
a7ed1ca2
NC
1368 }
1369 /* Terminate it. */
220e750f 1370 out_byte ('\0');
fac0d250 1371
220e750f 1372 for (i = 1; i < files_in_use; ++i)
fac0d250 1373 {
01e1a5bc
NC
1374 const char *fullfilename;
1375
249e3833
RH
1376 if (files[i].filename == NULL)
1377 {
0e389e77 1378 as_bad (_("unassigned file number %ld"), (long) i);
88b4ca40
RH
1379 /* Prevent a crash later, particularly for file 1. */
1380 files[i].filename = "";
249e3833
RH
1381 continue;
1382 }
1383
01e1a5bc
NC
1384 fullfilename = DWARF2_FILE_NAME (files[i].filename,
1385 files[i].dir ? dirs [files [i].dir] : "");
1386 size = strlen (fullfilename) + 1;
fac0d250 1387 cp = frag_more (size);
01e1a5bc 1388 memcpy (cp, fullfilename, size);
fac0d250 1389
220e750f 1390 out_uleb128 (files[i].dir); /* directory number */
01e1a5bc
NC
1391 /* Output the last modification timestamp. */
1392 out_uleb128 (DWARF2_FILE_TIME_NAME (files[i].filename,
1393 files[i].dir ? dirs [files [i].dir] : ""));
1394 /* Output the filesize. */
1395 out_uleb128 (DWARF2_FILE_SIZE_NAME (files[i].filename,
1396 files[i].dir ? dirs [files [i].dir] : ""));
fac0d250 1397 }
353e2c69
KH
1398
1399 /* Terminate filename list. */
1400 out_byte (0);
fac0d250
RH
1401}
1402
413a266c
AM
1403/* Switch to SEC and output a header length field. Return the size of
1404 offsets used in SEC. The caller must set EXPR->X_add_symbol value
1405 to the end of the section. */
1406
1407static int
91d6fa6a 1408out_header (asection *sec, expressionS *exp)
413a266c
AM
1409{
1410 symbolS *start_sym;
1411 symbolS *end_sym;
1412
1413 subseg_set (sec, 0);
1414 start_sym = symbol_temp_new_now ();;
1415 end_sym = symbol_temp_make ();
1416
1417 /* Total length of the information. */
91d6fa6a
NC
1418 exp->X_op = O_subtract;
1419 exp->X_add_symbol = end_sym;
1420 exp->X_op_symbol = start_sym;
413a266c
AM
1421
1422 switch (DWARF2_FORMAT (sec))
1423 {
1424 case dwarf2_format_32bit:
91d6fa6a
NC
1425 exp->X_add_number = -4;
1426 emit_expr (exp, 4);
413a266c
AM
1427 return 4;
1428
1429 case dwarf2_format_64bit:
91d6fa6a 1430 exp->X_add_number = -12;
413a266c 1431 out_four (-1);
91d6fa6a 1432 emit_expr (exp, 8);
413a266c
AM
1433 return 8;
1434
1435 case dwarf2_format_64bit_irix:
91d6fa6a
NC
1436 exp->X_add_number = -8;
1437 emit_expr (exp, 8);
413a266c
AM
1438 return 8;
1439 }
1440
1441 as_fatal (_("internal error: unknown dwarf2 format"));
1442 return 0;
1443}
1444
220e750f
RH
1445/* Emit the collected .debug_line data. */
1446
1447static void
a2e22468 1448out_debug_line (segT line_seg)
220e750f 1449{
91d6fa6a 1450 expressionS exp;
220e750f
RH
1451 symbolS *prologue_end;
1452 symbolS *line_end;
1453 struct line_seg *s;
14e777e0 1454 int sizeof_offset;
220e750f 1455
91d6fa6a
NC
1456 sizeof_offset = out_header (line_seg, &exp);
1457 line_end = exp.X_add_symbol;
220e750f
RH
1458
1459 /* Version. */
fc0eebac 1460 out_two (DWARF2_VERSION);
220e750f
RH
1461
1462 /* Length of the prologue following this length. */
413a266c 1463 prologue_end = symbol_temp_make ();
91d6fa6a
NC
1464 exp.X_add_symbol = prologue_end;
1465 exp.X_add_number = - (4 + 2 + 4);
1466 emit_expr (&exp, sizeof_offset);
220e750f
RH
1467
1468 /* Parameters of the state machine. */
1469 out_byte (DWARF2_LINE_MIN_INSN_LENGTH);
1470 out_byte (DWARF2_LINE_DEFAULT_IS_STMT);
1471 out_byte (DWARF2_LINE_BASE);
1472 out_byte (DWARF2_LINE_RANGE);
1473 out_byte (DWARF2_LINE_OPCODE_BASE);
1474
1475 /* Standard opcode lengths. */
1476 out_byte (0); /* DW_LNS_copy */
1477 out_byte (1); /* DW_LNS_advance_pc */
1478 out_byte (1); /* DW_LNS_advance_line */
1479 out_byte (1); /* DW_LNS_set_file */
1480 out_byte (1); /* DW_LNS_set_column */
1481 out_byte (0); /* DW_LNS_negate_stmt */
1482 out_byte (0); /* DW_LNS_set_basic_block */
1483 out_byte (0); /* DW_LNS_const_add_pc */
1484 out_byte (1); /* DW_LNS_fixed_advance_pc */
bd0eb99b
RH
1485 out_byte (0); /* DW_LNS_set_prologue_end */
1486 out_byte (0); /* DW_LNS_set_epilogue_begin */
1487 out_byte (1); /* DW_LNS_set_isa */
220e750f
RH
1488
1489 out_file_list ();
1490
b7d6ed97 1491 symbol_set_value_now (prologue_end);
220e750f
RH
1492
1493 /* For each section, emit a statement program. */
ee515fb7 1494 for (s = all_segs; s; s = s->next)
9aec2026
NC
1495 if (SEG_NORMAL (s->seg))
1496 process_entries (s->seg, s->head->head);
1497 else
1498 as_warn ("dwarf line number information for %s ignored",
1499 segment_name (s->seg));
220e750f 1500
b7d6ed97 1501 symbol_set_value_now (line_end);
220e750f
RH
1502}
1503
802f5d9e
NC
1504static void
1505out_debug_ranges (segT ranges_seg)
1506{
1507 unsigned int addr_size = sizeof_address;
1508 struct line_seg *s;
91d6fa6a 1509 expressionS exp;
802f5d9e
NC
1510 unsigned int i;
1511
1512 subseg_set (ranges_seg, 0);
1513
1514 /* Base Address Entry. */
7fd3924a 1515 for (i = 0; i < addr_size; i++)
802f5d9e 1516 out_byte (0xff);
7fd3924a 1517 for (i = 0; i < addr_size; i++)
802f5d9e
NC
1518 out_byte (0);
1519
1520 /* Range List Entry. */
1521 for (s = all_segs; s; s = s->next)
1522 {
1523 fragS *frag;
1524 symbolS *beg, *end;
1525
1526 frag = first_frag_for_seg (s->seg);
1527 beg = symbol_temp_new (s->seg, 0, frag);
1528 s->text_start = beg;
1529
1530 frag = last_frag_for_seg (s->seg);
1531 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
1532 s->text_end = end;
1533
91d6fa6a
NC
1534 exp.X_op = O_symbol;
1535 exp.X_add_symbol = beg;
1536 exp.X_add_number = 0;
1537 emit_expr (&exp, addr_size);
802f5d9e 1538
91d6fa6a
NC
1539 exp.X_op = O_symbol;
1540 exp.X_add_symbol = end;
1541 exp.X_add_number = 0;
1542 emit_expr (&exp, addr_size);
802f5d9e
NC
1543 }
1544
1545 /* End of Range Entry. */
7fd3924a 1546 for (i = 0; i < addr_size; i++)
802f5d9e 1547 out_byte (0);
7fd3924a 1548 for (i = 0; i < addr_size; i++)
802f5d9e
NC
1549 out_byte (0);
1550}
1551
220e750f
RH
1552/* Emit data for .debug_aranges. */
1553
58b5739a 1554static void
a2e22468 1555out_debug_aranges (segT aranges_seg, segT info_seg)
fac0d250 1556{
220e750f 1557 unsigned int addr_size = sizeof_address;
220e750f 1558 struct line_seg *s;
91d6fa6a 1559 expressionS exp;
413a266c 1560 symbolS *aranges_end;
220e750f 1561 char *p;
413a266c 1562 int sizeof_offset;
fac0d250 1563
91d6fa6a
NC
1564 sizeof_offset = out_header (aranges_seg, &exp);
1565 aranges_end = exp.X_add_symbol;
fac0d250 1566
220e750f 1567 /* Version. */
fc0eebac 1568 out_two (DWARF2_VERSION);
4dc7ead9 1569
220e750f 1570 /* Offset to .debug_info. */
413a266c 1571 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), sizeof_offset);
220e750f
RH
1572
1573 /* Size of an address (offset portion). */
1574 out_byte (addr_size);
1575
1576 /* Size of a segment descriptor. */
1577 out_byte (0);
1578
1579 /* Align the header. */
413a266c 1580 frag_align (ffs (2 * addr_size) - 1, 0, 0);
4dc7ead9 1581
ee515fb7 1582 for (s = all_segs; s; s = s->next)
220e750f
RH
1583 {
1584 fragS *frag;
1585 symbolS *beg, *end;
1586
1587 frag = first_frag_for_seg (s->seg);
b7d6ed97 1588 beg = symbol_temp_new (s->seg, 0, frag);
220e750f
RH
1589 s->text_start = beg;
1590
1591 frag = last_frag_for_seg (s->seg);
c9049d30 1592 end = symbol_temp_new (s->seg, get_frag_fix (frag, s->seg), frag);
220e750f
RH
1593 s->text_end = end;
1594
91d6fa6a
NC
1595 exp.X_op = O_symbol;
1596 exp.X_add_symbol = beg;
1597 exp.X_add_number = 0;
1598 emit_expr (&exp, addr_size);
220e750f 1599
91d6fa6a
NC
1600 exp.X_op = O_subtract;
1601 exp.X_add_symbol = end;
1602 exp.X_op_symbol = beg;
1603 exp.X_add_number = 0;
1604 emit_expr (&exp, addr_size);
220e750f 1605 }
4dc7ead9 1606
220e750f
RH
1607 p = frag_more (2 * addr_size);
1608 md_number_to_chars (p, 0, addr_size);
1609 md_number_to_chars (p + addr_size, 0, addr_size);
413a266c
AM
1610
1611 symbol_set_value_now (aranges_end);
4dc7ead9
RH
1612}
1613
220e750f
RH
1614/* Emit data for .debug_abbrev. Note that this must be kept in
1615 sync with out_debug_info below. */
fac0d250 1616
220e750f 1617static void
413a266c
AM
1618out_debug_abbrev (segT abbrev_seg,
1619 segT info_seg ATTRIBUTE_UNUSED,
1620 segT line_seg ATTRIBUTE_UNUSED)
220e750f
RH
1621{
1622 subseg_set (abbrev_seg, 0);
fac0d250 1623
220e750f
RH
1624 out_uleb128 (1);
1625 out_uleb128 (DW_TAG_compile_unit);
1626 out_byte (DW_CHILDREN_no);
413a266c
AM
1627 if (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit)
1628 out_abbrev (DW_AT_stmt_list, DW_FORM_data4);
1629 else
1630 out_abbrev (DW_AT_stmt_list, DW_FORM_data8);
220e750f 1631 if (all_segs->next == NULL)
4dc7ead9 1632 {
220e750f
RH
1633 out_abbrev (DW_AT_low_pc, DW_FORM_addr);
1634 out_abbrev (DW_AT_high_pc, DW_FORM_addr);
1635 }
802f5d9e
NC
1636 else
1637 {
413a266c 1638 if (DWARF2_FORMAT (info_seg) == dwarf2_format_32bit)
802f5d9e
NC
1639 out_abbrev (DW_AT_ranges, DW_FORM_data4);
1640 else
1641 out_abbrev (DW_AT_ranges, DW_FORM_data8);
1642 }
48b91938 1643 out_abbrev (DW_AT_name, DW_FORM_string);
220e750f
RH
1644 out_abbrev (DW_AT_comp_dir, DW_FORM_string);
1645 out_abbrev (DW_AT_producer, DW_FORM_string);
1646 out_abbrev (DW_AT_language, DW_FORM_data2);
1647 out_abbrev (0, 0);
a987bfc9
RH
1648
1649 /* Terminate the abbreviations for this compilation unit. */
1650 out_byte (0);
220e750f 1651}
4dc7ead9 1652
220e750f 1653/* Emit a description of this compilation unit for .debug_info. */
4dc7ead9 1654
220e750f 1655static void
802f5d9e 1656out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg)
220e750f
RH
1657{
1658 char producer[128];
3d6b762c
JM
1659 const char *comp_dir;
1660 const char *dirname;
91d6fa6a 1661 expressionS exp;
220e750f
RH
1662 symbolS *info_end;
1663 char *p;
1664 int len;
14e777e0 1665 int sizeof_offset;
4dc7ead9 1666
91d6fa6a
NC
1667 sizeof_offset = out_header (info_seg, &exp);
1668 info_end = exp.X_add_symbol;
4dc7ead9 1669
220e750f 1670 /* DWARF version. */
fc0eebac 1671 out_two (DWARF2_VERSION);
4dc7ead9 1672
220e750f 1673 /* .debug_abbrev offset */
6174d9c8 1674 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
4dc7ead9 1675
220e750f
RH
1676 /* Target address size. */
1677 out_byte (sizeof_address);
fac0d250 1678
220e750f
RH
1679 /* DW_TAG_compile_unit DIE abbrev */
1680 out_uleb128 (1);
fac0d250 1681
220e750f 1682 /* DW_AT_stmt_list */
413a266c
AM
1683 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg),
1684 (DWARF2_FORMAT (line_seg) == dwarf2_format_32bit
1685 ? 4 : 8));
fac0d250 1686
802f5d9e 1687 /* These two attributes are emitted if all of the code is contiguous. */
220e750f 1688 if (all_segs->next == NULL)
58b5739a 1689 {
220e750f 1690 /* DW_AT_low_pc */
91d6fa6a
NC
1691 exp.X_op = O_symbol;
1692 exp.X_add_symbol = all_segs->text_start;
1693 exp.X_add_number = 0;
1694 emit_expr (&exp, sizeof_address);
220e750f
RH
1695
1696 /* DW_AT_high_pc */
91d6fa6a
NC
1697 exp.X_op = O_symbol;
1698 exp.X_add_symbol = all_segs->text_end;
1699 exp.X_add_number = 0;
1700 emit_expr (&exp, sizeof_address);
58b5739a 1701 }
802f5d9e
NC
1702 else
1703 {
eb1fe072
NC
1704 /* This attribute is emitted if the code is disjoint. */
1705 /* DW_AT_ranges. */
1706 TC_DWARF2_EMIT_OFFSET (section_symbol (ranges_seg), sizeof_offset);
802f5d9e 1707 }
58b5739a 1708
48b91938
RH
1709 /* DW_AT_name. We don't have the actual file name that was present
1710 on the command line, so assume files[1] is the main input file.
1711 We're not supposed to get called unless at least one line number
1712 entry was emitted, so this should always be defined. */
7fd3924a 1713 if (files_in_use == 0)
48b91938 1714 abort ();
a7ed1ca2
NC
1715 if (files[1].dir)
1716 {
3d6b762c
JM
1717 dirname = remap_debug_filename (dirs[files[1].dir]);
1718 len = strlen (dirname);
198f1251
TG
1719#ifdef TE_VMS
1720 /* Already has trailing slash. */
1721 p = frag_more (len);
1722 memcpy (p, dirname, len);
1723#else
a7ed1ca2 1724 p = frag_more (len + 1);
3d6b762c 1725 memcpy (p, dirname, len);
56487c55 1726 INSERT_DIR_SEPARATOR (p, len);
198f1251 1727#endif
a7ed1ca2 1728 }
48b91938
RH
1729 len = strlen (files[1].filename) + 1;
1730 p = frag_more (len);
1731 memcpy (p, files[1].filename, len);
1732
220e750f 1733 /* DW_AT_comp_dir */
3d6b762c 1734 comp_dir = remap_debug_filename (getpwd ());
220e750f
RH
1735 len = strlen (comp_dir) + 1;
1736 p = frag_more (len);
1737 memcpy (p, comp_dir, len);
fac0d250 1738
220e750f
RH
1739 /* DW_AT_producer */
1740 sprintf (producer, "GNU AS %s", VERSION);
1741 len = strlen (producer) + 1;
1742 p = frag_more (len);
1743 memcpy (p, producer, len);
fac0d250 1744
220e750f
RH
1745 /* DW_AT_language. Yes, this is probably not really MIPS, but the
1746 dwarf2 draft has no standard code for assembler. */
1747 out_two (DW_LANG_Mips_Assembler);
1748
b7d6ed97 1749 symbol_set_value_now (info_end);
fac0d250
RH
1750}
1751
1e9cc1c2
NC
1752void
1753dwarf2_init (void)
1754{
1755 all_segs_hash = hash_new ();
1756 last_seg_ptr = &all_segs;
1757}
1758
1759
c6cb92c5
NS
1760/* Finish the dwarf2 debug sections. We emit .debug.line if there
1761 were any .file/.loc directives, or --gdwarf2 was given, or if the
df1c40a7
L
1762 file has a non-empty .debug_info section and an empty .debug_line
1763 section. If we emit .debug_line, and the .debug_info section is
1764 empty, we also emit .debug_info, .debug_aranges and .debug_abbrev.
1765 ALL_SEGS will be non-null if there were any .file/.loc directives,
1766 or --gdwarf2 was given and there were any located instructions
1767 emitted. */
c6cb92c5 1768
fac0d250 1769void
a2e22468 1770dwarf2_finish (void)
fac0d250 1771{
220e750f
RH
1772 segT line_seg;
1773 struct line_seg *s;
c6cb92c5
NS
1774 segT info_seg;
1775 int emit_other_sections = 0;
df1c40a7 1776 int empty_debug_line = 0;
c6cb92c5
NS
1777
1778 info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
1779 emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
fac0d250 1780
df1c40a7
L
1781 line_seg = bfd_get_section_by_name (stdoutput, ".debug_line");
1782 empty_debug_line = line_seg == NULL || !seg_not_empty_p (line_seg);
1783
1784 /* We can't construct a new debug_line section if we already have one.
1785 Give an error. */
1786 if (all_segs && !empty_debug_line)
1787 as_fatal ("duplicate .debug_line sections");
1788
1789 if ((!all_segs && emit_other_sections)
1790 || (!emit_other_sections && !empty_debug_line))
1791 /* If there is no line information and no non-empty .debug_info
1792 section, or if there is both a non-empty .debug_info and a non-empty
1793 .debug_line, then we do nothing. */
220e750f 1794 return;
fac0d250 1795
220e750f 1796 /* Calculate the size of an address for the target machine. */
9605f328 1797 sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
fac0d250 1798
220e750f
RH
1799 /* Create and switch to the line number section. */
1800 line_seg = subseg_new (".debug_line", 0);
8a7140c3 1801 bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
fac0d250 1802
220e750f 1803 /* For each subsection, chain the debug entries together. */
ee515fb7 1804 for (s = all_segs; s; s = s->next)
fac0d250 1805 {
91d6fa6a
NC
1806 struct line_subseg *lss = s->head;
1807 struct line_entry **ptail = lss->ptail;
220e750f 1808
91d6fa6a 1809 while ((lss = lss->next) != NULL)
220e750f 1810 {
91d6fa6a
NC
1811 *ptail = lss->head;
1812 ptail = lss->ptail;
220e750f 1813 }
fac0d250 1814 }
85a39694 1815
220e750f 1816 out_debug_line (line_seg);
85a39694 1817
c6cb92c5
NS
1818 /* If this is assembler generated line info, and there is no
1819 debug_info already, we need .debug_info and .debug_abbrev
1820 sections as well. */
1821 if (emit_other_sections)
220e750f
RH
1822 {
1823 segT abbrev_seg;
220e750f 1824 segT aranges_seg;
802f5d9e 1825 segT ranges_seg;
4dc7ead9 1826
9c2799c2 1827 gas_assert (all_segs);
7fd3924a 1828
220e750f
RH
1829 info_seg = subseg_new (".debug_info", 0);
1830 abbrev_seg = subseg_new (".debug_abbrev", 0);
1831 aranges_seg = subseg_new (".debug_aranges", 0);
ef99799a 1832
8a7140c3
NC
1833 bfd_set_section_flags (stdoutput, info_seg,
1834 SEC_READONLY | SEC_DEBUGGING);
1835 bfd_set_section_flags (stdoutput, abbrev_seg,
1836 SEC_READONLY | SEC_DEBUGGING);
1837 bfd_set_section_flags (stdoutput, aranges_seg,
1838 SEC_READONLY | SEC_DEBUGGING);
ef99799a 1839
ee515fb7 1840 record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
ef99799a 1841
802f5d9e
NC
1842 if (all_segs->next == NULL)
1843 ranges_seg = NULL;
1844 else
1845 {
1846 ranges_seg = subseg_new (".debug_ranges", 0);
7fd3924a 1847 bfd_set_section_flags (stdoutput, ranges_seg,
802f5d9e
NC
1848 SEC_READONLY | SEC_DEBUGGING);
1849 record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
1850 out_debug_ranges (ranges_seg);
1851 }
1852
220e750f 1853 out_debug_aranges (aranges_seg, info_seg);
413a266c 1854 out_debug_abbrev (abbrev_seg, info_seg, line_seg);
802f5d9e 1855 out_debug_info (info_seg, abbrev_seg, line_seg, ranges_seg);
220e750f 1856 }
85a39694 1857}
This page took 1.060452 seconds and 4 git commands to generate.