This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] Handle dwarf2 line numbers for code in header files better


This is something I've had in a local tree for a year or two; thanks
to Kazu Hirata for updating it for mainline.

We use "record_line (last_subfile, 0, address)" to mark end records in
the line table.  This is useful because the line table only has start
addresses; otherwise, the last line table entry will seem to stretch
out into infinity.  So if the range of text addresses is wrong for a
psymtab, and we select it for some code not actually associated, then
we may decide that code is on a particular line.

And then adjust breakpoints at that code address to the start of the
line, far away from where they were supposed to be.  Oops.

The solution is to mark end of line whenever we switch away from a
subfile.

An easy way to reproduce this is to have a file with some code in
".text", and some code in "__libc_freeres", some code in a header file
in the .text section, and a linker script that puts the latter section
explicitly after the former.  Then stick a file with .text and no debug
symbols in the middle.  I tried to write a test that didn't require a
linker script, but I failed :-(

Tested on x86_64-pc-linux-gnu and checked in.

-- 
Daniel Jacobowitz
CodeSourcery

2006-10-11  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (dwarf_decode_lines): Call record_line upon
	encountering a different subfile.

Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.203
diff -u -d -p -r1.203 dwarf2read.c
--- gdb/dwarf2read.c	18 Aug 2006 13:26:31 -0000	1.203
+++ gdb/dwarf2read.c	6 Oct 2006 02:24:44 -0000
@@ -6621,6 +6621,7 @@ dwarf_decode_lines (struct line_header *
   CORE_ADDR baseaddr;
   struct objfile *objfile = cu->objfile;
   const int decode_for_pst_p = (pst != NULL);
+  struct subfile *last_subfile = NULL;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
@@ -6670,6 +6671,12 @@ dwarf_decode_lines (struct line_header *
               lh->file_names[file - 1].included_p = 1;
               if (!decode_for_pst_p)
                 {
+		  if (last_subfile != current_subfile)
+		    {
+		      if (last_subfile)
+			record_line (last_subfile, 0, address);
+		      last_subfile = current_subfile;
+		    }
 	          /* Append row to matrix using current values.  */
 	          record_line (current_subfile, line, 
 	                       check_cu_functions (address, cu));
@@ -6724,8 +6731,16 @@ dwarf_decode_lines (struct line_header *
 	    case DW_LNS_copy:
               lh->file_names[file - 1].included_p = 1;
               if (!decode_for_pst_p)
-	        record_line (current_subfile, line, 
-	                     check_cu_functions (address, cu));
+		{
+		  if (last_subfile != current_subfile)
+		    {
+		      if (last_subfile)
+			record_line (last_subfile, 0, address);
+		      last_subfile = current_subfile;
+		    }
+		  record_line (current_subfile, line, 
+			       check_cu_functions (address, cu));
+		}
 	      basic_block = 0;
 	      break;
 	    case DW_LNS_advance_pc:
@@ -6752,7 +6767,10 @@ dwarf_decode_lines (struct line_header *
                   dir = lh->include_dirs[fe->dir_index - 1];
 
                 if (!decode_for_pst_p)
-                  dwarf2_start_subfile (fe->name, dir, comp_dir);
+		  {
+		    last_subfile = current_subfile;
+		    dwarf2_start_subfile (fe->name, dir, comp_dir);
+		  }
               }
 	      break;
 	    case DW_LNS_set_column:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]