Changeset 609 for branches/GNU/src/binutils/gas/dwarf2dbg.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/gas/dwarf2dbg.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* dwarf2dbg.c - DWARF2 debug support 2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.2 Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 3 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 4 … … 42 42 #endif 43 43 44 #include "dwarf2dbg.h" 45 #include <filenames.h> 46 47 #ifndef DWARF2_FORMAT 48 # define DWARF2_FORMAT() dwarf2_format_32bit 49 #endif 50 51 #ifndef DWARF2_ADDR_SIZE 52 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8); 53 #endif 54 55 #ifndef TC_DWARF2_EMIT_OFFSET 56 # define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset 57 #endif 58 44 59 #ifdef BFD_ASSEMBLER 45 60 46 #include "dwarf2dbg.h"47 61 #include "subsegs.h" 48 62 … … 123 137 124 138 struct file_entry { 125 c har *filename;139 const char *filename; 126 140 unsigned int dir; 127 141 }; … … 132 146 static unsigned int files_allocated; 133 147 134 /* True when we've seen a .loc directive recently. Used to avoid 148 /* Table of directories used by .debug_line. */ 149 static char **dirs; 150 static unsigned int dirs_in_use; 151 static unsigned int dirs_allocated; 152 153 /* TRUE when we've seen a .loc directive recently. Used to avoid 135 154 doing work when there's nothing to do. */ 136 static b oolean loc_directive_seen;155 static bfd_boolean loc_directive_seen; 137 156 138 157 /* Current location as indicated by the most recent .loc directive. */ … … 146 165 147 166 167 static void generic_dwarf2_emit_offset PARAMS((symbolS *, unsigned int)); 148 168 static struct line_subseg *get_line_subseg PARAMS ((segT, subsegT)); 149 static unsigned int get_filenum PARAMS ((const char * ));169 static unsigned int get_filenum PARAMS ((const char *, unsigned int)); 150 170 static struct frag *first_frag_for_seg PARAMS ((segT)); 151 171 static struct frag *last_frag_for_seg PARAMS ((segT)); … … 173 193 174 194 195 /* Create an offset to .dwarf2_*. */ 196 197 static void 198 generic_dwarf2_emit_offset (symbol, size) 199 symbolS *symbol; 200 unsigned int size; 201 { 202 expressionS expr; 203 204 expr.X_op = O_symbol; 205 expr.X_add_symbol = symbol; 206 expr.X_add_number = 0; 207 emit_expr (&expr, size); 208 } 209 175 210 /* Find or create an entry for SEG+SUBSEG in ALL_SEGS. */ 176 211 … … 233 268 struct line_subseg *ss; 234 269 struct line_entry *e; 270 static unsigned int line = -1; 271 static unsigned int filenum = -1; 235 272 236 273 /* Early out for as-yet incomplete location information. */ 237 274 if (loc->filenum == 0 || loc->line == 0) 238 275 return; 276 277 /* Don't emit sequences of line symbols for the same line when the 278 symbols apply to assembler code. It is necessary to emit 279 duplicate line symbols when a compiler asks for them, because GDB 280 uses them to determine the end of the prologue. */ 281 if (debug_type == DEBUG_DWARF2 282 && line == loc->line && filenum == loc->filenum) 283 return; 284 285 line = loc->line; 286 filenum = loc->filenum; 239 287 240 288 e = (struct line_entry *) xmalloc (sizeof (*e)); … … 257 305 char *filename; 258 306 as_where (&filename, &line->line); 259 line->filenum = get_filenum (filename );307 line->filenum = get_filenum (filename, 0); 260 308 line->column = 0; 261 309 line->flags = DWARF2_FLAG_BEGIN_STMT; … … 276 324 struct dwarf2_line_info loc; 277 325 278 if (debug_type != DEBUG_DWARF2 && ! loc_directive_seen) 326 if (loc_directive_seen) 327 { 328 /* Use the last location established by a .loc directive, not 329 the value returned by dwarf2_where(). That calls as_where() 330 which will return either the logical input file name (foo.c) 331 or the physical input file name (foo.s) and not the file name 332 specified in the most recent .loc directive (eg foo.h). */ 333 loc = current; 334 335 /* Unless we generate DWARF2 debugging information for each 336 assembler line, we only emit one line symbol for one LOC. */ 337 if (debug_type != DEBUG_DWARF2) 338 loc_directive_seen = FALSE; 339 } 340 else if (debug_type != DEBUG_DWARF2) 279 341 return; 280 loc_directive_seen = false;281 282 dwarf2_where (&loc); 342 else 343 dwarf2_where (& loc); 344 283 345 dwarf2_gen_line_info (frag_now_fix () - size, &loc); 284 346 } 285 347 286 /* Get a .debug_line file number for FILENAME. */ 348 /* Get a .debug_line file number for FILENAME. If NUM is nonzero, 349 allocate it on that file table slot, otherwise return the first 350 empty one. */ 287 351 288 352 static unsigned int 289 get_filenum (filename )353 get_filenum (filename, num) 290 354 const char *filename; 291 { 292 static unsigned int last_used; 293 unsigned int i; 294 295 if (last_used) 296 if (strcmp (filename, files[last_used].filename) == 0) 297 return last_used; 298 299 for (i = 1; i < files_in_use; ++i) 300 if (strcmp (filename, files[i].filename) == 0) 301 return i; 355 unsigned int num; 356 { 357 static unsigned int last_used, last_used_dir_len; 358 const char *file; 359 size_t dir_len; 360 unsigned int i, dir; 361 362 if (num == 0 && last_used) 363 { 364 if (! files[last_used].dir 365 && strcmp (filename, files[last_used].filename) == 0) 366 return last_used; 367 if (files[last_used].dir 368 && strncmp (filename, dirs[files[last_used].dir], 369 last_used_dir_len) == 0 370 && IS_DIR_SEPARATOR (filename [last_used_dir_len]) 371 && strcmp (filename + last_used_dir_len + 1, 372 files[last_used].filename) == 0) 373 return last_used; 374 } 375 376 file = lbasename (filename); 377 /* Don't make empty string from / or A: from A:/ . */ 378 #ifdef HAVE_DOS_BASED_FILE_SYSTEM 379 if (file <= filename + 3) 380 file = filename; 381 #else 382 if (file == filename + 1) 383 file = filename; 384 #endif 385 dir_len = file - filename; 386 387 dir = 0; 388 if (dir_len) 389 { 390 --dir_len; 391 for (dir = 1; dir < dirs_in_use; ++dir) 392 if (memcmp (filename, dirs[dir], dir_len) == 0 393 && dirs[dir][dir_len] == '\0') 394 break; 395 396 if (dir >= dirs_in_use) 397 { 398 if (dir >= dirs_allocated) 399 { 400 dirs_allocated = dir + 32; 401 dirs = (char **) 402 xrealloc (dirs, (dir + 32) * sizeof (const char *)); 403 } 404 405 dirs[dir] = xmalloc (dir_len + 1); 406 memcpy (dirs[dir], filename, dir_len); 407 dirs[dir][dir_len] = '\0'; 408 dirs_in_use = dir + 1; 409 } 410 } 411 412 if (num == 0) 413 { 414 for (i = 1; i < files_in_use; ++i) 415 if (files[i].dir == dir 416 && files[i].filename 417 && strcmp (file, files[i].filename) == 0) 418 { 419 last_used = i; 420 last_used_dir_len = dir_len; 421 return i; 422 } 423 } 424 else 425 i = num; 302 426 303 427 if (i >= files_allocated) … … 312 436 } 313 437 314 files[i].filename = xstrdup (filename);315 files[i].dir = 0;438 files[i].filename = num ? file : xstrdup (file); 439 files[i].dir = dir; 316 440 files_in_use = i + 1; 317 441 last_used = i; 442 last_used_dir_len = dir_len; 318 443 319 444 return i; 320 445 } 321 446 322 /* Handle the .file directive. */ 323 324 void 447 /* Handle two forms of .file directive: 448 - Pass .file "source.c" to s_app_file 449 - Handle .file 1 "source.c" by adding an entry to the DWARF-2 file table 450 451 If an entry is added to the file table, return a pointer to the filename. */ 452 453 char * 325 454 dwarf2_directive_file (dummy) 326 455 int dummy ATTRIBUTE_UNUSED; … … 335 464 { 336 465 s_app_file (0); 337 return ;466 return NULL; 338 467 } 339 468 … … 344 473 if (num < 1) 345 474 { 346 as_bad (_("File number less than one")); 347 return; 348 } 349 350 if (num < files_in_use && files[num].filename != 0) 351 { 352 as_bad (_("File number %ld already allocated"), (long) num); 353 return; 354 } 355 356 if (num >= (int) files_allocated) 357 { 358 unsigned int old = files_allocated; 359 360 files_allocated = num + 16; 361 files = (struct file_entry *) 362 xrealloc (files, (num + 16) * sizeof (struct file_entry)); 363 364 /* Zero the new memory. */ 365 memset (files + old, 0, (num + 16 - old) * sizeof (struct file_entry)); 366 } 367 368 files[num].filename = filename; 369 files[num].dir = 0; 370 files_in_use = num + 1; 475 as_bad (_("file number less than one")); 476 return NULL; 477 } 478 479 if (num < (int) files_in_use && files[num].filename != 0) 480 { 481 as_bad (_("file number %ld already allocated"), (long) num); 482 return NULL; 483 } 484 485 get_filenum (filename, num); 486 487 return filename; 371 488 } 372 489 … … 386 503 if (filenum < 1) 387 504 { 388 as_bad (_(" File number less than one"));505 as_bad (_("file number less than one")); 389 506 return; 390 507 } 391 508 if (filenum >= (int) files_in_use || files[filenum].filename == 0) 392 509 { 393 as_bad (_(" Unassigned file number %ld"), (long) filenum);510 as_bad (_("unassigned file number %ld"), (long) filenum); 394 511 return; 395 512 } … … 400 517 current.flags = DWARF2_FLAG_BEGIN_STMT; 401 518 402 loc_directive_seen = true;519 loc_directive_seen = TRUE; 403 520 404 521 #ifndef NO_LISTING 405 522 if (listing) 406 listing_source_line (line); 523 { 524 if (files[filenum].dir) 525 { 526 size_t dir_len = strlen (dirs[files[filenum].dir]); 527 size_t file_len = strlen (files[filenum].filename); 528 char *cp = (char *) alloca (dir_len + 1 + file_len + 1); 529 530 memcpy (cp, dirs[files[filenum].dir], dir_len); 531 cp[dir_len] = '/'; 532 memcpy (cp + dir_len + 1, files[filenum].filename, file_len); 533 cp[dir_len + file_len + 1] = '\0'; 534 listing_source_file (cp); 535 } 536 else 537 listing_source_file (files[filenum].filename); 538 listing_source_line (line); 539 } 407 540 #endif 408 541 } … … 529 662 if (fr->frch_last == frag) 530 663 { 531 return ((char *) obstack_next_free (&fr->frch_obstack) 532 - frag->fr_literal); 664 long align_mask = -1 << get_recorded_alignment (fr->frch_seg); 665 return (((char *) obstack_next_free (&fr->frch_obstack) 666 - frag->fr_literal) + ~align_mask) & align_mask; 533 667 } 534 668 … … 559 693 } 560 694 695 #if DWARF2_LINE_MIN_INSN_LENGTH > 1 696 static void scale_addr_delta PARAMS ((addressT *)); 697 698 static void 699 scale_addr_delta (addr_delta) 700 addressT *addr_delta; 701 { 702 static int printed_this = 0; 703 if (*addr_delta % DWARF2_LINE_MIN_INSN_LENGTH != 0) 704 { 705 if (!printed_this) 706 as_bad("unaligned opcodes detected in executable segment"); 707 printed_this = 1; 708 } 709 *addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH; 710 } 711 #else 712 #define scale_addr_delta(A) 713 #endif 714 561 715 /* Encode a pair of line and address skips as efficiently as possible. 562 716 Note that the line skip is signed, whereas the address skip is unsigned. … … 575 729 576 730 /* Scale the address delta by the minimum instruction length. */ 577 #if DWARF2_LINE_MIN_INSN_LENGTH > 1 578 assert (addr_delta % DWARF2_LINE_MIN_INSN_LENGTH == 0); 579 addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH; 580 #endif 731 scale_addr_delta (&addr_delta); 581 732 582 733 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. … … 641 792 char *end = p + len; 642 793 643 #if DWARF2_LINE_MIN_INSN_LENGTH > 1644 794 /* Scale the address delta by the minimum instruction length. */ 645 assert (addr_delta % DWARF2_LINE_MIN_INSN_LENGTH == 0); 646 addr_delta /= DWARF2_LINE_MIN_INSN_LENGTH; 647 #endif 795 scale_addr_delta (&addr_delta); 796 648 797 /* INT_MAX is a signal that this is actually a DW_LNE_end_sequence. 649 798 We cannot use special opcodes here, since we want the end_sequence … … 777 926 int size; 778 927 779 addr_delta = resolve_symbol_value (frag->fr_symbol , 0);928 addr_delta = resolve_symbol_value (frag->fr_symbol); 780 929 size = size_inc_line_addr (frag->fr_offset, addr_delta); 781 930 … … 811 960 offsetT addr_diff; 812 961 813 addr_diff = resolve_symbol_value (frag->fr_symbol , 1);962 addr_diff = resolve_symbol_value (frag->fr_symbol); 814 963 815 964 /* fr_var carries the max_chars that we created the fragment with. … … 931 1080 unsigned int i; 932 1081 933 /* Terminate directory list. */ 1082 /* Emit directory list. */ 1083 for (i = 1; i < dirs_in_use; ++i) 1084 { 1085 size = strlen (dirs[i]) + 1; 1086 cp = frag_more (size); 1087 memcpy (cp, dirs[i], size); 1088 } 1089 /* Terminate it. */ 934 1090 out_byte ('\0'); 935 1091 … … 938 1094 if (files[i].filename == NULL) 939 1095 { 940 as_bad (_("Unassigned file number %u"), i); 1096 as_bad (_("unassigned file number %ld"), (long) i); 1097 /* Prevent a crash later, particularly for file 1. */ 1098 files[i].filename = ""; 941 1099 continue; 942 1100 } … … 966 1124 symbolS *line_end; 967 1125 struct line_seg *s; 1126 enum dwarf2_format d2f; 1127 int sizeof_offset; 968 1128 969 1129 subseg_set (line_seg, 0); … … 977 1137 expr.X_add_symbol = line_end; 978 1138 expr.X_op_symbol = line_start; 979 expr.X_add_number = -4; 980 emit_expr (&expr, 4); 1139 1140 d2f = DWARF2_FORMAT (); 1141 if (d2f == dwarf2_format_32bit) 1142 { 1143 expr.X_add_number = -4; 1144 emit_expr (&expr, 4); 1145 sizeof_offset = 4; 1146 } 1147 else if (d2f == dwarf2_format_64bit) 1148 { 1149 expr.X_add_number = -12; 1150 out_four (-1); 1151 emit_expr (&expr, 8); 1152 sizeof_offset = 8; 1153 } 1154 else if (d2f == dwarf2_format_64bit_irix) 1155 { 1156 expr.X_add_number = -8; 1157 emit_expr (&expr, 8); 1158 sizeof_offset = 8; 1159 } 1160 else 1161 { 1162 as_fatal (_("internal error: unknown dwarf2 format")); 1163 } 981 1164 982 1165 /* Version. */ … … 988 1171 expr.X_op_symbol = line_start; 989 1172 expr.X_add_number = - (4 + 2 + 4); 990 emit_expr (&expr, 4);1173 emit_expr (&expr, sizeof_offset); 991 1174 992 1175 /* Parameters of the state machine. */ … … 1053 1236 1054 1237 /* Offset to .debug_info. */ 1055 expr.X_op = O_symbol; 1056 expr.X_add_symbol = section_symbol (info_seg); 1057 expr.X_add_number = 0; 1058 emit_expr (&expr, 4); 1238 /* ??? sizeof_offset */ 1239 TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), 4); 1059 1240 1060 1241 /* Size of an address (offset portion). */ … … 1116 1297 out_abbrev (DW_AT_high_pc, DW_FORM_addr); 1117 1298 } 1299 out_abbrev (DW_AT_name, DW_FORM_string); 1118 1300 out_abbrev (DW_AT_comp_dir, DW_FORM_string); 1119 1301 out_abbrev (DW_AT_producer, DW_FORM_string); … … 1140 1322 char *p; 1141 1323 int len; 1324 enum dwarf2_format d2f; 1325 int sizeof_offset; 1142 1326 1143 1327 subseg_set (info_seg, 0); … … 1150 1334 expr.X_add_symbol = info_end; 1151 1335 expr.X_op_symbol = info_start; 1152 expr.X_add_number = -4; 1153 emit_expr (&expr, 4); 1336 1337 d2f = DWARF2_FORMAT (); 1338 if (d2f == dwarf2_format_32bit) 1339 { 1340 expr.X_add_number = -4; 1341 emit_expr (&expr, 4); 1342 sizeof_offset = 4; 1343 } 1344 else if (d2f == dwarf2_format_64bit) 1345 { 1346 expr.X_add_number = -12; 1347 out_four (-1); 1348 emit_expr (&expr, 8); 1349 sizeof_offset = 8; 1350 } 1351 else if (d2f == dwarf2_format_64bit_irix) 1352 { 1353 expr.X_add_number = -8; 1354 emit_expr (&expr, 8); 1355 sizeof_offset = 8; 1356 } 1357 else 1358 { 1359 as_fatal (_("internal error: unknown dwarf2 format")); 1360 } 1154 1361 1155 1362 /* DWARF version. */ … … 1157 1364 1158 1365 /* .debug_abbrev offset */ 1159 expr.X_op = O_symbol; 1160 expr.X_add_symbol = section_symbol (abbrev_seg); 1161 expr.X_add_number = 0; 1162 emit_expr (&expr, 4); 1366 TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset); 1163 1367 1164 1368 /* Target address size. */ … … 1169 1373 1170 1374 /* DW_AT_stmt_list */ 1171 expr.X_op = O_symbol; 1172 expr.X_add_symbol = section_symbol (line_seg); 1173 expr.X_add_number = 0; 1174 emit_expr (&expr, 4); 1375 /* ??? sizeof_offset */ 1376 TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg), 4); 1175 1377 1176 1378 /* These two attributes may only be emitted if all of the code is … … 1191 1393 } 1192 1394 1395 /* DW_AT_name. We don't have the actual file name that was present 1396 on the command line, so assume files[1] is the main input file. 1397 We're not supposed to get called unless at least one line number 1398 entry was emitted, so this should always be defined. */ 1399 if (!files || files_in_use < 1) 1400 abort (); 1401 if (files[1].dir) 1402 { 1403 len = strlen (dirs[files[1].dir]); 1404 p = frag_more (len + 1); 1405 memcpy (p, dirs[files[1].dir], len); 1406 p[len] = '/'; 1407 } 1408 len = strlen (files[1].filename) + 1; 1409 p = frag_more (len); 1410 memcpy (p, files[1].filename, len); 1411 1193 1412 /* DW_AT_comp_dir */ 1194 1413 comp_dir = getpwd (); … … 1216 1435 struct line_seg *s; 1217 1436 1218 /* If no debug information was recorded, nothing to do. */ 1219 if (all_segs == NULL) 1437 /* We don't need to do anything unless: 1438 - Some debug information was recorded via .file/.loc 1439 - or, we are generating DWARF2 information ourself (--gdwarf2) 1440 - or, there is a user-provided .debug_info section which could 1441 reference the file table in the .debug_line section we generate 1442 below. */ 1443 if (all_segs == NULL 1444 && debug_type != DEBUG_DWARF2 1445 && bfd_get_section_by_name (stdoutput, ".debug_info") == NULL) 1220 1446 return; 1221 1447 1222 1448 /* Calculate the size of an address for the target machine. */ 1223 sizeof_address = bfd_arch_bits_per_address (stdoutput) / 8;1449 sizeof_address = DWARF2_ADDR_SIZE (stdoutput); 1224 1450 1225 1451 /* Create and switch to the line number section. */ … … 1244 1470 /* If this is assembler generated line info, we need .debug_info 1245 1471 and .debug_abbrev sections as well. */ 1246 if ( debug_type == DEBUG_DWARF2)1472 if (all_segs != NULL && debug_type == DEBUG_DWARF2) 1247 1473 { 1248 1474 segT abbrev_seg; … … 1301 1527 } 1302 1528 1303 void 1529 char * 1304 1530 dwarf2_directive_file (dummy) 1305 1531 int dummy ATTRIBUTE_UNUSED; 1306 1532 { 1307 1533 s_app_file (0); 1534 return NULL; 1308 1535 } 1309 1536 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.