]>
Commit | Line | Data |
---|---|---|
fac0d250 | 1 | /* dwarf2dbg.c - DWARF2 debug support |
89b66cde | 2 | Copyright (C) 1999 Free Software Foundation, Inc. |
fac0d250 RH |
3 | Contributed by David Mosberger-Tang <[email protected]> |
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" | |
31 | ||
32 | #include "as.h" | |
33 | #include "dwarf2dbg.h" | |
34 | #include "subsegs.h" | |
35 | ||
d9ac5a3b | 36 | #include "elf/dwarf2.h" |
fac0d250 | 37 | |
fac0d250 RH |
38 | /* Since we can't generate the prolog until the body is complete, we |
39 | use three different subsegments for .debug_line: one holding the | |
40 | prolog, one for the directory and filename info, and one for the | |
41 | body ("statement program"). */ | |
42 | #define DL_PROLOG 0 | |
43 | #define DL_FILES 1 | |
44 | #define DL_BODY 2 | |
45 | ||
46 | /* First special line opcde - leave room for the standard opcodes. | |
47 | Note: If you want to change this, you'll have to update the | |
48 | "standard_opcode_lengths" table that is emitted below in | |
49 | dwarf2_finish(). */ | |
50 | #define DWARF2_LINE_OPCODE_BASE 10 | |
51 | ||
52 | #ifndef DWARF2_LINE_BASE | |
53 | /* Minimum line offset in a special line info. opcode. This value | |
54 | was chosen to give a reasonable range of values. */ | |
55 | # define DWARF2_LINE_BASE -5 | |
56 | #endif | |
57 | ||
58 | /* Range of line offsets in a special line info. opcode. */ | |
59 | #ifndef DWARF2_LINE_RANGE | |
60 | # define DWARF2_LINE_RANGE 14 | |
61 | #endif | |
62 | ||
63 | #ifndef DWARF2_LINE_MIN_INSN_LENGTH | |
64 | /* Define the architecture-dependent minimum instruction length (in | |
65 | bytes). This value should be rather too small than too big. */ | |
66 | # define DWARF2_LINE_MIN_INSN_LENGTH 4 | |
67 | #endif | |
68 | ||
69 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
70 | In the present implementation, we do not mark any lines as | |
71 | the beginning of a source statement, because that information | |
72 | is not made available by the GCC front-end. */ | |
73 | #define DWARF2_LINE_DEFAULT_IS_STMT 1 | |
74 | ||
75 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
76 | In the present implementation, we do not mark any lines as | |
77 | the beginning of a source statement, because that information | |
78 | is not made available by the GCC front-end. */ | |
79 | #define DWARF2_LINE_DEFAULT_IS_STMT 1 | |
80 | ||
81 | /* Given a special op, return the line skip amount: */ | |
82 | #define SPECIAL_LINE(op) \ | |
83 | (((op) - DWARF2_LINE_OPCODE_BASE)%DWARF2_LINE_RANGE + DWARF2_LINE_BASE) | |
84 | ||
85 | /* Given a special op, return the address skip amount (in units of | |
86 | DWARF2_LINE_MIN_INSN_LENGTH. */ | |
87 | #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE) | |
88 | ||
89 | /* The maximum address skip amont that can be encoded with a special op: */ | |
90 | #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255) | |
91 | ||
92 | #define INITIAL_STATE \ | |
93 | /* initialize as per DWARF2.0 standard: */ \ | |
94 | 0, /* address */ \ | |
95 | 1, /* file */ \ | |
96 | 1, /* line */ \ | |
97 | 0, /* column */ \ | |
98 | DWARF2_LINE_DEFAULT_IS_STMT, /* is_stmt */ \ | |
99 | 0, /* basic_block */ \ | |
100 | 1 /* empty_sequence */ | |
101 | ||
102 | static struct | |
103 | { | |
104 | /* state machine state as per DWARF2 manual: */ | |
105 | struct dwarf2_sm | |
106 | { | |
9e3af0e7 | 107 | addressT addr; |
fac0d250 RH |
108 | unsigned int filenum; |
109 | unsigned int line; | |
110 | unsigned int column; | |
111 | unsigned int | |
112 | is_stmt : 1, | |
113 | basic_block : 1, | |
114 | empty_sequence : 1; /* current code sequence has no DWARF2 directives? */ | |
115 | } | |
116 | sm; | |
117 | ||
118 | unsigned int | |
119 | any_dwarf2_directives : 1; /* did we emit any DWARF2 line debug directives? */ | |
120 | ||
121 | segT text_seg; /* text segment "addr" is relative to */ | |
122 | subsegT text_subseg; | |
123 | segT line_seg; /* ".debug_line" segment */ | |
124 | int last_filename; /* index of last filename that was used */ | |
125 | int num_filenames; /* index of last filename in use */ | |
126 | int filename_len; /* length of the filename array */ | |
127 | struct | |
128 | { | |
129 | int dir; /* valid after gen_dir_list() only */ | |
130 | char *name; /* full path before gen_dir_list(), filename afterwards */ | |
131 | } | |
132 | *file; | |
133 | ||
134 | struct dwarf2_line_info current; /* current source info: */ | |
135 | ||
136 | /* counters for statistical purposes: */ | |
137 | unsigned int num_line_entries; | |
138 | unsigned int opcode_hist[256]; /* histogram of opcode frequencies */ | |
139 | } | |
140 | ls = | |
141 | { | |
142 | { | |
143 | INITIAL_STATE | |
144 | }, | |
145 | }; | |
146 | ||
58b5739a RH |
147 | |
148 | /* Function prototypes: */ | |
9e3af0e7 ILT |
149 | static void out_uleb128 PARAMS ((addressT)); |
150 | static void out_sleb128 PARAMS ((offsetT)); | |
151 | static void gen_addr_line PARAMS ((int, addressT)); | |
58b5739a | 152 | static void reset_state_machine PARAMS ((void)); |
9e3af0e7 | 153 | static void out_set_addr PARAMS ((addressT)); |
58b5739a RH |
154 | static void out_end_sequence PARAMS ((void)); |
155 | static int get_filenum PARAMS ((int, char *)); | |
156 | static void gen_dir_list PARAMS ((void)); | |
157 | static void gen_file_list PARAMS ((void)); | |
158 | static void print_stats PARAMS ((unsigned long)); | |
159 | ||
160 | ||
fac0d250 RH |
161 | #define out_byte(byte) FRAG_APPEND_1_CHAR(byte) |
162 | #define out_opcode(opc) (out_byte ((opc)), ++ls.opcode_hist[(opc) & 0xff]) | |
163 | ||
164 | /* Output an unsigned "little-endian base 128" number. */ | |
165 | static void | |
58b5739a | 166 | out_uleb128 (value) |
9e3af0e7 | 167 | addressT value; |
fac0d250 RH |
168 | { |
169 | unsigned char byte, more = 0x80; | |
170 | ||
171 | do | |
172 | { | |
173 | byte = value & 0x7f; | |
174 | value >>= 7; | |
175 | if (value == 0) | |
176 | more = 0; | |
177 | out_byte (more | byte); | |
178 | } | |
179 | while (more); | |
180 | } | |
181 | ||
182 | /* Output a signed "little-endian base 128" number. */ | |
183 | static void | |
58b5739a | 184 | out_sleb128 (value) |
9e3af0e7 | 185 | offsetT value; |
fac0d250 RH |
186 | { |
187 | unsigned char byte, more = 0x80; | |
188 | ||
189 | do | |
190 | { | |
191 | byte = value & 0x7f; | |
192 | value >>= 7; | |
193 | if (((value == 0) && ((byte & 0x40) == 0)) | |
194 | || ((value == -1) && ((byte & 0x40) != 0))) | |
195 | more = 0; | |
196 | out_byte (more | byte); | |
197 | } | |
198 | while (more); | |
199 | } | |
200 | ||
201 | /* Encode a pair of line and address skips as efficiently as possible. | |
202 | Note that the line skip is signed, whereas the address skip is | |
203 | unsigned. */ | |
204 | static void | |
58b5739a RH |
205 | gen_addr_line (line_delta, addr_delta) |
206 | int line_delta; | |
9e3af0e7 | 207 | addressT addr_delta; |
fac0d250 RH |
208 | { |
209 | unsigned int tmp, opcode; | |
210 | ||
211 | tmp = line_delta - DWARF2_LINE_BASE; | |
212 | ||
213 | if (tmp >= DWARF2_LINE_RANGE) | |
214 | { | |
215 | out_opcode (DW_LNS_advance_line); | |
216 | out_sleb128 (line_delta); | |
217 | tmp = 0 - DWARF2_LINE_BASE; | |
218 | line_delta = 0; | |
219 | } | |
220 | ||
221 | tmp += DWARF2_LINE_OPCODE_BASE; | |
222 | ||
223 | /* try using a special opcode: */ | |
224 | opcode = tmp + addr_delta*DWARF2_LINE_RANGE; | |
225 | if (opcode <= 255) | |
226 | { | |
227 | out_opcode (opcode); | |
228 | return; | |
229 | } | |
230 | ||
231 | /* try using DW_LNS_const_add_pc followed by special op: */ | |
232 | opcode = tmp + (addr_delta - MAX_SPECIAL_ADDR_DELTA)*DWARF2_LINE_RANGE; | |
233 | if (opcode <= 255) | |
234 | { | |
235 | out_opcode (DW_LNS_const_add_pc); | |
236 | out_opcode (opcode); | |
237 | return; | |
238 | } | |
239 | ||
240 | out_opcode (DW_LNS_advance_pc); | |
241 | out_uleb128 (addr_delta); | |
242 | ||
243 | if (line_delta) | |
244 | out_opcode (tmp); /* output line-delta */ | |
245 | else | |
246 | out_opcode (DW_LNS_copy); /* append new row with current info */ | |
247 | } | |
248 | ||
249 | static void | |
58b5739a | 250 | reset_state_machine () |
fac0d250 RH |
251 | { |
252 | static const struct dwarf2_sm initial_state = { INITIAL_STATE }; | |
253 | ||
254 | ls.sm = initial_state; | |
255 | } | |
256 | ||
257 | /* Set an absolute address (may results in a relocation entry): */ | |
258 | static void | |
58b5739a | 259 | out_set_addr (addr) |
9e3af0e7 | 260 | addressT addr; |
fac0d250 RH |
261 | { |
262 | subsegT saved_subseg; | |
263 | segT saved_seg; | |
264 | expressionS expr; | |
265 | symbolS *sym; | |
9e3af0e7 | 266 | int bytes_per_address; |
fac0d250 RH |
267 | |
268 | saved_seg = now_seg; | |
269 | saved_subseg = now_subseg; | |
270 | ||
271 | subseg_set (ls.text_seg, ls.text_subseg); | |
272 | sym = symbol_new (".L0\001", now_seg, addr, frag_now); | |
273 | ||
274 | subseg_set (saved_seg, saved_subseg); | |
275 | ||
9e3af0e7 ILT |
276 | #ifdef BFD_ASSEMBLER |
277 | bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8; | |
278 | #else | |
279 | /* FIXME. */ | |
280 | bytes_per_address = 4; | |
281 | #endif | |
282 | ||
fac0d250 | 283 | out_opcode (DW_LNS_extended_op); |
9e3af0e7 | 284 | out_uleb128 (bytes_per_address + 1); |
fac0d250 RH |
285 | |
286 | out_opcode (DW_LNE_set_address); | |
287 | expr.X_op = O_symbol; | |
288 | expr.X_add_symbol = sym; | |
289 | expr.X_add_number = 0; | |
9e3af0e7 | 290 | emit_expr (&expr, bytes_per_address); |
fac0d250 RH |
291 | } |
292 | ||
293 | /* Emit DW_LNS_end_sequence and reset state machine. Does not | |
294 | preserve the current segment/sub-segment! */ | |
295 | static void | |
58b5739a | 296 | out_end_sequence () |
fac0d250 | 297 | { |
9e3af0e7 | 298 | addressT addr, delta; |
fac0d250 RH |
299 | |
300 | if (ls.text_seg) | |
301 | { | |
302 | subseg_set (ls.text_seg, ls.text_subseg); | |
303 | #ifdef md_current_text_addr | |
304 | addr = md_current_text_addr (); | |
305 | #else | |
306 | addr = frag_now_fix (); | |
307 | #endif | |
308 | subseg_set (ls.line_seg, DL_BODY); | |
309 | if (addr < ls.sm.addr) | |
310 | { | |
311 | out_set_addr (addr); | |
312 | ls.sm.addr = addr; | |
313 | } | |
314 | else | |
315 | { | |
316 | delta = addr - ls.sm.addr; | |
317 | if (delta > 0) | |
318 | gen_addr_line (0, delta / DWARF2_LINE_MIN_INSN_LENGTH); | |
319 | } | |
320 | } | |
321 | else | |
322 | subseg_set (ls.line_seg, DL_BODY); | |
323 | ||
324 | out_opcode (DW_LNS_extended_op); | |
325 | out_uleb128 (1); | |
326 | out_byte (DW_LNE_end_sequence); | |
327 | ||
328 | reset_state_machine (); | |
329 | } | |
330 | ||
331 | /* Look up a filenumber either by filename or by filenumber. If both | |
332 | a filenumber and a filename are specified, lookup by filename takes | |
333 | precedence. If the filename cannot be found, it is added to the | |
334 | filetable the filenumber for the new entry is returned. */ | |
335 | static int | |
58b5739a RH |
336 | get_filenum (filenum, file) |
337 | int filenum; | |
338 | char *file; | |
fac0d250 RH |
339 | { |
340 | int i, last = filenum - 1; | |
341 | char char0 = file[0]; | |
342 | ||
343 | if ((unsigned) last >= ls.num_filenames) | |
344 | last = ls.last_filename; | |
345 | ||
346 | /* do a quick check against the previously used filename: */ | |
347 | if (ls.num_filenames > 0 && ls.file[last].name[0] == char0 | |
348 | && strcmp (ls.file[last].name + 1, file + 1) == 0) | |
349 | return last + 1; | |
350 | ||
351 | /* no match, fall back to simple linear scan: */ | |
352 | for (i = 0; i < ls.num_filenames; ++i) | |
353 | { | |
354 | if (ls.file[i].name[0] == char0 | |
355 | && strcmp (ls.file[i].name + 1, file + 1) == 0) | |
356 | { | |
357 | ls.last_filename = i; | |
358 | return i + 1; | |
359 | } | |
360 | } | |
361 | ||
362 | /* no match: enter new filename */ | |
363 | if (ls.num_filenames >= ls.filename_len) | |
364 | { | |
365 | ls.filename_len += 13; | |
366 | ls.file = xrealloc (ls.file, ls.filename_len * sizeof (ls.file[0])); | |
367 | } | |
368 | ls.file[ls.num_filenames].dir = 0; | |
369 | ls.file[ls.num_filenames].name = file; | |
370 | return ++ls.num_filenames; | |
371 | } | |
372 | ||
373 | void | |
58b5739a | 374 | dwarf2_gen_line_info (addr, l) |
9e3af0e7 | 375 | addressT addr; |
58b5739a | 376 | struct dwarf2_line_info *l; |
fac0d250 RH |
377 | { |
378 | unsigned int filenum = l->filenum; | |
379 | unsigned int any_output = 0; | |
380 | subsegT saved_subseg; | |
381 | segT saved_seg; | |
fac0d250 RH |
382 | |
383 | if (flag_debug) | |
58b5739a | 384 | fprintf (stderr, "line: addr %llx file `%s' line %u col %u flags %x\n", |
fac0d250 RH |
385 | (long long) addr, l->filename, l->line, l->column, l->flags); |
386 | ||
387 | if (filenum > 0 && !l->filename) | |
388 | { | |
389 | if (filenum >= ls.num_filenames) | |
390 | { | |
391 | as_warn ("Encountered bad file number in line number debug info!"); | |
392 | return; | |
393 | } | |
394 | } | |
395 | else if (l->filename) | |
396 | filenum = get_filenum (filenum, l->filename); | |
397 | else | |
398 | return; /* no filename, no filnum => no play */ | |
399 | ||
400 | if (!ls.line_seg) | |
401 | { | |
9e3af0e7 | 402 | #ifdef BFD_ASSEMBLER |
9de8d8f1 | 403 | symbolS *secsym; |
9e3af0e7 | 404 | #endif |
9de8d8f1 | 405 | |
6576f0b5 | 406 | ls.line_seg = subseg_new (".debug_line", 0); |
9e3af0e7 ILT |
407 | |
408 | #ifdef BFD_ASSEMBLER | |
fac0d250 | 409 | bfd_set_section_flags (stdoutput, ls.line_seg, SEC_READONLY); |
6576f0b5 RH |
410 | |
411 | /* We're going to need this symbol. */ | |
9de8d8f1 RH |
412 | secsym = symbol_find (".debug_line"); |
413 | if (secsym != NULL) | |
414 | symbol_set_bfdsym (secsym, ls.line_seg->symbol); | |
415 | else | |
416 | symbol_table_insert (section_symbol (ls.line_seg)); | |
9e3af0e7 | 417 | #endif |
fac0d250 RH |
418 | } |
419 | ||
420 | saved_seg = now_seg; | |
421 | saved_subseg = now_subseg; | |
422 | subseg_set (ls.line_seg, DL_BODY); | |
423 | ||
424 | if (ls.text_seg != saved_seg || ls.text_subseg != saved_subseg) | |
425 | { | |
426 | if (!ls.sm.empty_sequence) | |
427 | { | |
428 | out_end_sequence (); /* terminate previous sequence */ | |
429 | ls.sm.empty_sequence = 1; | |
430 | } | |
431 | any_output = 1; | |
432 | ls.text_seg = saved_seg; | |
433 | ls.text_subseg = saved_subseg; | |
434 | out_set_addr (addr); | |
435 | ls.sm.addr = addr; | |
436 | } | |
437 | ||
438 | if (ls.sm.filenum != filenum) | |
439 | { | |
440 | any_output = 1; | |
441 | out_opcode (DW_LNS_set_file); | |
442 | out_uleb128 (filenum); | |
443 | ls.sm.filenum = filenum; | |
444 | } | |
445 | ||
446 | if (ls.sm.column != l->column) | |
447 | { | |
448 | any_output = 1; | |
449 | out_opcode (DW_LNS_set_column); | |
450 | out_uleb128 (l->column); | |
451 | ls.sm.column = l->column; | |
452 | } | |
453 | ||
454 | if (((l->flags & DWARF2_FLAG_BEGIN_STMT) != 0) != ls.sm.is_stmt) | |
455 | { | |
456 | any_output = 1; | |
457 | out_opcode (DW_LNS_negate_stmt); | |
458 | } | |
459 | ||
460 | if (l->flags & DWARF2_FLAG_BEGIN_BLOCK) | |
461 | { | |
462 | any_output = 1; | |
463 | out_opcode (DW_LNS_set_basic_block); | |
464 | } | |
465 | ||
466 | if (ls.sm.line != l->line) | |
467 | { | |
468 | any_output = 1; | |
469 | if (addr < ls.sm.addr) | |
470 | { | |
a340d270 RH |
471 | /* This happens when a new frag got allocated (for whatever |
472 | reason). Deal with it by generating a reference symbol. | |
473 | Note: no end_sequence needs to be generated because the | |
474 | address did not really decrease (only the reference point | |
475 | changed). | |
476 | ||
477 | ??? Perhaps we should directly check for a change of | |
478 | frag_now instead? */ | |
fac0d250 RH |
479 | out_set_addr (addr); |
480 | ls.sm.addr = addr; | |
481 | } | |
482 | gen_addr_line (l->line - ls.sm.line, | |
483 | (addr - ls.sm.addr) / DWARF2_LINE_MIN_INSN_LENGTH); | |
484 | ls.sm.basic_block = 0; | |
485 | ls.sm.line = l->line; | |
486 | ls.sm.addr = addr; | |
487 | } | |
488 | ||
489 | subseg_set (saved_seg, saved_subseg); | |
490 | ||
491 | ls.num_line_entries += any_output; | |
492 | if (any_output) | |
493 | ls.sm.empty_sequence = 0; | |
494 | } | |
495 | ||
496 | static void | |
58b5739a | 497 | gen_dir_list () |
fac0d250 RH |
498 | { |
499 | char *str, *slash, *dir_list, *dp, *cp; | |
500 | int i, j, num_dirs; | |
501 | ||
502 | dir_list = frag_more (0); | |
503 | num_dirs = 0; | |
504 | ||
505 | for (i = 0; i < ls.num_filenames; ++i) | |
506 | { | |
507 | str = ls.file[i].name; | |
508 | slash = strrchr (str, '/'); | |
509 | if (slash) | |
510 | { | |
511 | *slash = '\0'; | |
512 | for (j = 0, dp = dir_list; j < num_dirs; ++j) | |
513 | { | |
514 | if (strcmp (str, dp) == 0) | |
515 | { | |
a340d270 | 516 | ls.file[i].dir = j + 1; |
fac0d250 RH |
517 | break; |
518 | } | |
519 | dp += strlen (dp); | |
520 | } | |
521 | if (j >= num_dirs) | |
522 | { | |
523 | /* didn't find this directory: append it to the list */ | |
524 | size_t size = strlen (str) + 1; | |
525 | cp = frag_more (size); | |
526 | memcpy (cp, str, size); | |
527 | ls.file[i].dir = ++num_dirs; | |
528 | } | |
529 | *slash = '/'; | |
530 | ls.file[i].name = slash + 1; | |
531 | } | |
532 | } | |
533 | out_byte ('\0'); /* terminate directory list */ | |
534 | } | |
535 | ||
536 | static void | |
58b5739a | 537 | gen_file_list () |
fac0d250 RH |
538 | { |
539 | size_t size; | |
540 | char *cp; | |
541 | int i; | |
542 | ||
543 | for (i = 0; i < ls.num_filenames; ++i) | |
544 | { | |
545 | size = strlen (ls.file[i].name) + 1; | |
546 | cp = frag_more (size); | |
547 | memcpy (cp, ls.file[i].name, size); | |
548 | ||
549 | out_uleb128 (ls.file[i].dir); /* directory number */ | |
550 | out_uleb128 (0); /* last modification timestamp */ | |
551 | out_uleb128 (0); /* filesize */ | |
552 | } | |
553 | out_byte (0); /* terminate filename list */ | |
554 | } | |
555 | ||
58b5739a RH |
556 | static void |
557 | print_stats (total_size) | |
558 | unsigned long total_size; | |
fac0d250 RH |
559 | { |
560 | static const char *opc_name[] = | |
561 | { | |
562 | "extended", "copy", "advance_pc", "advance_line", "set_file", | |
563 | "set_column", "negate_stmt", "set_basic_block", "const_add_pc", | |
564 | "fixed_advance_pc" | |
565 | }; | |
566 | int i, j; | |
567 | ||
568 | fprintf (stderr, "Average size: %g bytes/line\n", | |
569 | total_size / (double) ls.num_line_entries); | |
570 | ||
571 | fprintf (stderr, "\nStandard opcode histogram:\n"); | |
572 | ||
573 | for (i = 0; i < sizeof (opc_name)/sizeof (opc_name[0]); ++i) | |
574 | { | |
575 | fprintf (stderr, "%s", opc_name[i]); | |
576 | for (j = strlen (opc_name[i]); j < 16; ++j) | |
577 | fprintf (stderr, " "); | |
578 | fprintf (stderr, ": %u\n", ls.opcode_hist[i]); | |
579 | } | |
580 | ||
581 | fprintf (stderr, "\nSpecial opcodes:\naddr\t\t\t\tline skip\n"); | |
582 | ||
583 | fprintf (stderr, "skip: "); | |
584 | for (j = DWARF2_LINE_BASE; j < DWARF2_LINE_BASE + DWARF2_LINE_RANGE; ++j) | |
585 | fprintf (stderr, "%3d", j); | |
586 | fprintf (stderr, "\n-----"); | |
587 | ||
588 | for (; i < 256; ++i) | |
589 | { | |
590 | j = SPECIAL_LINE (i); | |
591 | if (j == DWARF2_LINE_BASE) | |
592 | fprintf (stderr, "\n%4u: ", | |
593 | DWARF2_LINE_MIN_INSN_LENGTH*SPECIAL_ADDR (i)); | |
594 | fprintf (stderr, " %2u", ls.opcode_hist[i]); | |
595 | } | |
596 | fprintf (stderr, "\n"); | |
597 | } | |
598 | ||
599 | void | |
58b5739a | 600 | dwarf2_finish () |
fac0d250 | 601 | { |
9e3af0e7 | 602 | addressT body_size, total_size, prolog_size; |
58b5739a | 603 | subsegT saved_subseg; |
fac0d250 RH |
604 | segT saved_seg; |
605 | char *cp; | |
606 | ||
607 | if (!ls.line_seg) | |
608 | /* no .debug_line segment, no work to do... */ | |
609 | return; | |
610 | ||
611 | saved_seg = now_seg; | |
612 | saved_subseg = now_subseg; | |
613 | ||
614 | if (!ls.sm.empty_sequence) | |
615 | out_end_sequence (); | |
616 | total_size = body_size = frag_now_fix (); | |
617 | ||
618 | /* now generate the directory and file lists: */ | |
619 | subseg_set (ls.line_seg, DL_FILES); | |
620 | gen_dir_list (); | |
621 | gen_file_list (); | |
622 | total_size += frag_now_fix (); | |
623 | ||
624 | /* and now the header ("statement program prolog", in DWARF2 lingo...) */ | |
625 | subseg_set (ls.line_seg, DL_PROLOG); | |
626 | ||
627 | cp = frag_more (15 + DWARF2_LINE_OPCODE_BASE - 1); | |
628 | ||
629 | total_size += frag_now_fix (); | |
630 | prolog_size = total_size - body_size - 10; | |
631 | ||
632 | # define STUFF(val,size) md_number_to_chars (cp, val, size); cp += size; | |
633 | STUFF (total_size - 4, 4); /* length */ | |
634 | STUFF (2, 2); /* version */ | |
635 | STUFF (prolog_size, 4); /* prologue_length */ | |
636 | STUFF (DWARF2_LINE_MIN_INSN_LENGTH, 1); | |
637 | STUFF (DWARF2_LINE_DEFAULT_IS_STMT, 1); | |
638 | STUFF (DWARF2_LINE_BASE, 1); | |
639 | STUFF (DWARF2_LINE_RANGE, 1); | |
640 | STUFF (DWARF2_LINE_OPCODE_BASE, 1); | |
641 | ||
642 | /* standard_opcode_lengths: */ | |
643 | STUFF (0, 1); /* DW_LNS_copy */ | |
644 | STUFF (1, 1); /* DW_LNS_advance_pc */ | |
645 | STUFF (1, 1); /* DW_LNS_advance_line */ | |
646 | STUFF (1, 1); /* DW_LNS_set_file */ | |
647 | STUFF (1, 1); /* DW_LNS_set_column */ | |
648 | STUFF (0, 1); /* DW_LNS_negate_stmt */ | |
649 | STUFF (0, 1); /* DW_LNS_set_basic_block */ | |
650 | STUFF (0, 1); /* DW_LNS_const_add_pc */ | |
651 | STUFF (1, 1); /* DW_LNS_fixed_advance_pc */ | |
652 | ||
653 | subseg_set (saved_seg, saved_subseg); | |
654 | ||
655 | if (flag_debug) | |
656 | print_stats (total_size); | |
657 | } | |
658 | ||
659 | void | |
58b5739a RH |
660 | dwarf2_directive_file (dummy) |
661 | int dummy; | |
fac0d250 RH |
662 | { |
663 | int len; | |
664 | ||
58b5739a RH |
665 | /* Continue to accept a bare string and pass it off. */ |
666 | SKIP_WHITESPACE (); | |
667 | if (*input_line_pointer == '"') | |
668 | { | |
669 | s_app_file (0); | |
670 | return; | |
671 | } | |
672 | ||
fac0d250 RH |
673 | ls.any_dwarf2_directives = 1; |
674 | ||
675 | if (debug_type == DEBUG_NONE) | |
676 | /* Automatically turn on DWARF2 debug info unless something else | |
677 | has been selected. */ | |
678 | debug_type = DEBUG_DWARF2; | |
679 | ||
680 | ls.current.filenum = get_absolute_expression (); | |
681 | ls.current.filename = demand_copy_C_string (&len); | |
682 | ||
683 | demand_empty_rest_of_line (); | |
684 | } | |
685 | ||
686 | void | |
58b5739a RH |
687 | dwarf2_directive_loc (dummy) |
688 | int dummy; | |
fac0d250 RH |
689 | { |
690 | ls.any_dwarf2_directives = 1; | |
691 | ||
692 | ls.current.filenum = get_absolute_expression (); | |
693 | SKIP_WHITESPACE (); | |
694 | ls.current.line = get_absolute_expression (); | |
695 | SKIP_WHITESPACE (); | |
696 | ls.current.column = get_absolute_expression (); | |
697 | demand_empty_rest_of_line (); | |
698 | ||
699 | ls.current.flags = DWARF2_FLAG_BEGIN_STMT; | |
700 | ||
701 | #ifndef NO_LISTING | |
702 | if (listing) | |
703 | listing_source_line (ls.current.line); | |
704 | #endif | |
705 | } | |
706 | ||
707 | void | |
58b5739a RH |
708 | dwarf2_where (line) |
709 | struct dwarf2_line_info *line; | |
fac0d250 RH |
710 | { |
711 | if (ls.any_dwarf2_directives) | |
712 | *line = ls.current; | |
713 | else | |
714 | { | |
fac0d250 RH |
715 | as_where (&line->filename, &line->line); |
716 | line->filenum = 0; | |
717 | line->column = 0; | |
718 | line->flags = DWARF2_FLAG_BEGIN_STMT; | |
719 | } | |
720 | } |