This is the mail archive of the gdb-patches@sources.redhat.com 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]

dwarf2_build_psymtabs should check that .debug_line exists


I was reading through dwarf2read.c when I noticed that
dwarf2_build_psymtabs() doesn't check to see if the file that you're
debugging has a .debug_line section before initializing
dwarf_line_buffer.  This is potentially unfortunate:
dwarf2_build_psymtabs() is called when dwarf2_has_info() returns 1,
but dwarf2_has_info() only checks to see if the file that you're
debugging has .debug_info and .debug_abbrev sections.

It is, of course, quite rare for a file to have .debug_info and
.debug_abbrev sections but not to have a .debug_line section; so,
obviously this isn't a serious problem.  And, even if you produce such
a file (using objcopy -R .debug_line, say), it's still pretty hard to
cause GDB to signal an error, but with some effort I did manage to do
so.  (I can submit a PR with details, if anybody wants.)  Given that
dwarf2_build_psymtabs() is careful to make sure all the other
.debug_XXX sections exist, it should certainly also check to make sure
that .debug_line exists.

By the way, I checked to see where the contents of the .debug_line
section are used; as far as I can tell, it's only used in
dwarf2read.c(dwarf_decode_line_header), and that function does have a
check in it to make sure that dwarf_line_buffer is non-NULL.  So this
fix is probably better than the other obvious fix, namely to have
dwarf2_has_info() ensure that the file has a .debug_line section.

Here's a patch; no new regressions.

2002-08-07  David Carlton  <carlton@math.stanford.edu>

	* dwarf2read.c (dwarf2_build_psymtabs): Check that
	dwarf_line_offset is nonzero before creating dwarf_line_buffer.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.64
diff -u -p -r1.64 dwarf2read.c
--- dwarf2read.c	31 Jul 2002 22:35:30 -0000	1.64
+++ dwarf2read.c	7 Aug 2002 22:55:49 -0000
@@ -1009,9 +1009,13 @@ dwarf2_build_psymtabs (struct objfile *o
   dwarf_abbrev_buffer = dwarf2_read_section (objfile,
 					     dwarf_abbrev_offset,
 					     dwarf_abbrev_size);
-  dwarf_line_buffer = dwarf2_read_section (objfile,
-					   dwarf_line_offset,
-					   dwarf_line_size);
+
+  if (dwarf_line_offset)
+    dwarf_line_buffer = dwarf2_read_section (objfile,
+					     dwarf_line_offset,
+					     dwarf_line_size);
+  else
+    dwarf_line_buffer = NULL;
 
   if (dwarf_str_offset)
     dwarf_str_buffer = dwarf2_read_section (objfile,


David Carlton
carlton@math.stanford.edu


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