Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: david carlton <carlton@math.stanford.edu>
To: gdb-patches@sources.redhat.com
Cc: carlton@math.stanford.edu
Subject: dwarf2_build_psymtabs should check that .debug_line exists
Date: Wed, 07 Aug 2002 16:53:00 -0000	[thread overview]
Message-ID: <15697.45810.578860.108712@jackfruit.Stanford.EDU> (raw)

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


             reply	other threads:[~2002-08-07 23:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07 16:53 david carlton [this message]
2002-08-13 13:50 ` Jim Blandy
2002-08-13 14:54   ` David Carlton
2002-08-14 16:47     ` Jim Blandy
2002-08-19 16:43       ` David Carlton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15697.45810.578860.108712@jackfruit.Stanford.EDU \
    --to=carlton@math.stanford.edu \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox