public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Vladimir Simonov <sv@sw.ru>
Cc: gdb-patches@sourceware.org
Subject: Re: gdb: Incorrect stack unwinding if compressed debug info is used
Date: Fri, 04 Feb 2011 20:31:00 -0000	[thread overview]
Message-ID: <m3tygj7d90.fsf@fleche.redhat.com> (raw)
In-Reply-To: <4D4C4576.2020709@sw.ru> (Vladimir Simonov's message of "Fri, 04	Feb 2011 21:29:10 +0300")

>>>>> "Vladimir" == Vladimir Simonov <sv@sw.ru> writes:

Vladimir> The only I can mention - the name
Vladimir> dwarf2_section_size a bit misleading, it hides
Vladimir> the fact that it will read section if it is not done.
Vladimir> May be just change dwarf2_read_section to return
Vladimir> size?

I think the name is ok, but I extended the comment to try to clear up
the semantics.

I am going to check in the appended patch.  If you still think the name
is not good, pick a better one and I will rename it.

Vladimir> Also I'm not sure that call functions inside "if"
Vladimir> are encouraged in gdb coding style. I mean
Vladimir> +  if (header->abbrev_offset
Vladimir> +      >= dwarf2_section_size (dwarf2_per_objfile->objfile,
Vladimir> +			      &dwarf2_per_objfile->abbrev))

This is ok, what is prohibited is assignments in a condition.

Tom

2011-02-04  Tom Tromey  <tromey@redhat.com>

	* dwarf2read.c (dwarf2_section_empty_p): New function.
	(dwarf2_read_section): Use dwarf2_section_empty_p.
	(dwarf2_section_size): New function.
	(dwarf2_get_section_info): Unconditionally read section.
	(dwarf2_read_index): Use dwarf2_section_empty_p.
	(partial_read_comp_unit_head): Use dwarf2_section_size.
	(dwarf2_symbol_mark_computed): Likewise.

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6a98d57..f443ba3 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1509,6 +1509,14 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
 #endif
 }
 
+/* A helper function that decides whether a section is empty.  */
+
+static int
+dwarf2_section_empty_p (struct dwarf2_section_info *info)
+{
+  return info->asection == NULL || info->size == 0;
+}
+
 /* Read the contents of the section SECTP from object file specified by
    OBJFILE, store info about the section into INFO.
    If the section is compressed, uncompress it before returning.  */
@@ -1527,7 +1535,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
   info->was_mmapped = 0;
   info->readin = 1;
 
-  if (info->asection == NULL || info->size == 0)
+  if (dwarf2_section_empty_p (info))
     return;
 
   /* Check if the file has a 4-byte header indicating compression.  */
@@ -1592,6 +1600,22 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
 	   bfd_get_filename (abfd));
 }
 
+/* A helper function that returns the size of a section in a safe way.
+   If you are positive that the section has been read before using the
+   size, then it is safe to refer to the dwarf2_section_info object's
+   "size" field directly.  In other cases, you must call this
+   function, because for compressed sections the size field is not set
+   correctly until the section has been read.  */
+
+static bfd_size_type
+dwarf2_section_size (struct objfile *objfile,
+		     struct dwarf2_section_info *info)
+{
+  if (!info->readin)
+    dwarf2_read_section (objfile, info);
+  return info->size;
+}
+
 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
    SECTION_NAME.  */
 
@@ -1620,9 +1644,7 @@ dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
   else
     gdb_assert_not_reached ("unexpected section");
 
-  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
-    /* We haven't read this section in yet.  Do it now.  */
-    dwarf2_read_section (objfile, info);
+  dwarf2_read_section (objfile, info);
 
   *sectp = info->asection;
   *bufp = info->buffer;
@@ -2008,8 +2030,7 @@ dwarf2_read_index (struct objfile *objfile)
   offset_type types_list_elements = 0;
   int i;
 
-  if (dwarf2_per_objfile->gdb_index.asection == NULL
-      || dwarf2_per_objfile->gdb_index.size == 0)
+  if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
     return 0;
 
   /* Older elfutils strip versions could keep the section in the main
@@ -2823,7 +2844,9 @@ partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
 	   "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
 	   bfd_get_filename (abfd));
 
-  if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
+  if (header->abbrev_offset
+      >= dwarf2_section_size (dwarf2_per_objfile->objfile,
+			      &dwarf2_per_objfile->abbrev))
     error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
 	   "(offset 0x%lx + 6) [in module %s]"),
 	   (long) header->abbrev_offset,
@@ -14365,7 +14388,8 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
       /* ".debug_loc" may not exist at all, or the offset may be outside
 	 the section.  If so, fall through to the complaint in the
 	 other branch.  */
-      && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
+      && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
+						&dwarf2_per_objfile->loc))
     {
       struct dwarf2_loclist_baton *baton;
 

  reply	other threads:[~2011-02-04 20:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1296238472.3009.ezmlm@sourceware.org>
2011-01-31 16:57 ` Vladimir Simonov
2011-02-02 19:55   ` Paul Pluzhnikov
2011-02-03 16:51     ` Vladimir Simonov
2011-02-04 16:35     ` Tom Tromey
2011-02-04 16:34   ` Tom Tromey
2011-02-04 17:47     ` Vladimir Simonov
2011-02-04 17:56       ` Tom Tromey
2011-02-04 18:43         ` Vladimir Simonov
2011-02-04 20:31           ` Tom Tromey [this message]
2011-02-05 13:53             ` Vladimir Simonov
2011-02-07 15:00               ` Tom Tromey
2011-02-01  7:34 ` gdb: Incorrect stack unwinding if debug info is compressed Vladimir Simonov

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=m3tygj7d90.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sv@sw.ru \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).