Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Fawzi Mohamed <fawzi.mohamed@nokia.com>
To: gdb-patches@sourceware.org
Cc: "ext Tristan Gingold" <gingold@adacore.com>,
	"André Pönitz" <andre.poenitz@nokia.com>,
	"ext Jan Kratochvil" <jan.kratochvil@redhat.com>
Subject: Re: [PATCH,gdb,Update5]: ensures that cie ptr of an fda is a cie
Date: Thu, 07 Jul 2011 18:48:00 -0000	[thread overview]
Message-ID: <C29D3D87-52FA-4E67-929E-13A3B885E28E@nokia.com> (raw)
In-Reply-To: <20110706170323.GA28535@host1.jankratochvil.net>

Clearly as soon as I sent it away I realized that I did not check if the arguments of
printf were null. Here a new patch reviewed by Andre, hopefully close to ok :)

master is still a bit buggy on mac, and I have found that 10.7 lion uses some more load commands
in mach-o that are not even defined in the mach-o/loader.h, but that is something for another time
(I will switch back to the 7.2 branch for now).

Fawzi

2011-07-07  Fawzi Mohamed  <fawzi.mohamed@nokia.com>

	* dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): Ensure
	that CIE pointer of an FDE really points to a CIE .

diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index b68a773..dcc3682 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1801,17 +1801,30 @@ add_fde (struct dwarf2_fde_table *fde_table, struct dwarf2_fde *fde)
 #define DW64_CIE_ID ~0
 #endif
 
+/* Defines the type of eh_frames that are expected to be decoded: CIE, FDE
+   or any of them.  */
+
+enum eh_frame_type
+{
+  EH_CIE_TYPE_ID = 1 << 0,
+  EH_FDE_TYPE_ID = 1 << 1,
+  EH_CIE_OR_FDE_TYPE_ID = EH_CIE_TYPE_ID | EH_FDE_TYPE_ID
+};
+
 static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *start,
 				     int eh_frame_p,
                                      struct dwarf2_cie_table *cie_table,
-                                     struct dwarf2_fde_table *fde_table);
+                                     struct dwarf2_fde_table *fde_table,
+                                     enum eh_frame_type entry_type);
+
+/* Decode the next CIE or FDE, entry_type specifies the expected type.
+   Return NULL if invalid input, otherwise the next byte to be processed.  */
 
-/* Decode the next CIE or FDE.  Return NULL if invalid input, otherwise
-   the next byte to be processed.  */
 static gdb_byte *
 decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
                       struct dwarf2_cie_table *cie_table,
-                      struct dwarf2_fde_table *fde_table)
+                      struct dwarf2_fde_table *fde_table,
+                      enum eh_frame_type entry_type)
 {
   struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
   gdb_byte *buf, *end;
@@ -1862,6 +1875,10 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
       char *augmentation;
       unsigned int cie_version;
 
+      /* Check that a CIE was expected.  */
+      if ((entry_type & EH_CIE_TYPE_ID) == 0)
+	error (_("Found a CIE when not expecting it, broken eh_info"));
+
       /* Record the offset into the .debug_frame section of this CIE.  */
       cie_pointer = start - unit->dwarf_frame_buffer;
 
@@ -2027,6 +2044,10 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
       /* This is a FDE.  */
       struct dwarf2_fde *fde;
 
+      /* Check that an FDE was expected.  */
+      if ((entry_type & EH_FDE_TYPE_ID) == 0)
+	error (_("Found an FDE when not expecting it, broken eh_info."));
+
       /* In an .eh_frame section, the CIE pointer is the delta between the
 	 address within the FDE where the CIE pointer is stored and the
 	 address of the CIE.  Convert it to an offset into the .eh_frame
@@ -2048,7 +2069,8 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
       if (fde->cie == NULL)
 	{
 	  decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
-			      eh_frame_p, cie_table, fde_table);
+			      eh_frame_p, cie_table, fde_table,
+			      EH_CIE_TYPE_ID);
 	  fde->cie = find_cie (cie_table, cie_pointer);
 	}
 
@@ -2089,11 +2111,14 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
   return end;
 }
 
-/* Read a CIE or FDE in BUF and decode it.  */
+/* Read a CIE or FDE in BUF and decode it. Entry_type specifies whether we
+   expect an FDE or a CIE.  */
+
 static gdb_byte *
 decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
                     struct dwarf2_cie_table *cie_table,
-                    struct dwarf2_fde_table *fde_table)
+                    struct dwarf2_fde_table *fde_table,
+                    enum eh_frame_type entry_type)
 {
   enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
   gdb_byte *ret;
@@ -2102,7 +2127,7 @@ decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
   while (1)
     {
       ret = decode_frame_entry_1 (unit, start, eh_frame_p,
-                                  cie_table, fde_table);
+				  cie_table, fde_table, entry_type);
       if (ret != NULL)
 	break;
 
@@ -2212,6 +2237,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
   struct dwarf2_cie_table cie_table;
   struct dwarf2_fde_table fde_table;
   struct dwarf2_fde_table *fde_table2;
+  volatile struct gdb_exception e;
 
   cie_table.num_entries = 0;
   cie_table.entries = NULL;
@@ -2253,10 +2279,29 @@ dwarf2_build_frame_info (struct objfile *objfile)
           if (txt)
             unit->tbase = txt->vma;
 
-          frame_ptr = unit->dwarf_frame_buffer;
-          while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
-            frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
-                                            &cie_table, &fde_table);
+	  TRY_CATCH (e, RETURN_MASK_ERROR)
+	    {
+	      frame_ptr = unit->dwarf_frame_buffer;
+	      while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
+		frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
+						&cie_table, &fde_table,
+						EH_CIE_OR_FDE_TYPE_ID);
+	    }
+
+	  if (e.reason < 0)
+	    {
+	      warning (_("skipping .eh_frame info of %s: %s"),
+		       (objfile->name ? objfile->name : "*unknown*"),
+		       (e.message ? e.message : ""));
+
+	      if (fde_table.num_entries != 0)
+		{
+		  xfree(fde_table.entries);
+		  fde_table.entries = NULL;
+		  fde_table.num_entries = 0;
+		}
+	      /* The cie_table is discarded by the next if.  */
+	    }
 
           if (cie_table.num_entries != 0)
             {
@@ -2274,10 +2319,39 @@ dwarf2_build_frame_info (struct objfile *objfile)
                            &unit->dwarf_frame_size);
   if (unit->dwarf_frame_size)
     {
-      frame_ptr = unit->dwarf_frame_buffer;
-      while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
-	frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
-                                        &cie_table, &fde_table);
+      int num_old_fde_entries = fde_table.num_entries;
+
+      TRY_CATCH (e, RETURN_MASK_ERROR)
+	{
+	  frame_ptr = unit->dwarf_frame_buffer;
+	  while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
+	    frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
+					    &cie_table, &fde_table,
+					    EH_CIE_OR_FDE_TYPE_ID);
+	}
+      if (e.reason < 0)
+	{
+	  warning (_("skipping .debug_frame info of %s: %s"),
+		   (objfile->name ? objfile->name : "*unknown*"),
+		   (e.message ? e.message : ""));
+
+	  if (fde_table.num_entries != 0)
+	    {
+	      fde_table.num_entries = num_old_fde_entries;
+	      if (num_old_fde_entries == 0)
+		{
+		  xfree(fde_table.entries);
+		  fde_table.entries = NULL;
+		}
+	      else
+		{
+		    xrealloc (fde_table.entries,
+			      fde_table.num_entries * sizeof (fde_table.entries[0]));
+		}
+	    }
+	  fde_table.num_entries = num_old_fde_entries;
+	  /* The cie_table is discarded by the next if.  */
+	}
     }
 
   /* Discard the cie_table, it is no longer needed.  */


  parent reply	other threads:[~2011-07-07 18:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-04 18:19 [PATCH,gdb]: " Fawzi Mohamed
2011-07-04 18:52 ` Joel Brobecker
2011-07-05 10:44   ` [PATCH,gdb, Update1]: " Fawzi Mohamed
2011-07-05 15:17     ` Joel Brobecker
2011-07-05 16:57       ` [PATCH,gdb, Update2]: " Fawzi Mohamed
2011-07-05 16:26 ` [PATCH,gdb]: " Tom Tromey
2011-07-06 14:45   ` [PATCH,gdb,Update3]: " Fawzi Mohamed
2011-07-06 18:16     ` Jan Kratochvil
2011-07-07 17:17       ` [PATCH,gdb,Update4]: " Fawzi Mohamed
2011-07-07 23:37         ` Tom Tromey
2011-07-11 17:19           ` [PATCH,gdb,Update6]: " Fawzi Mohamed
2011-07-11 21:52             ` Tom Tromey
2011-07-12 11:15               ` [PATCH,gdb,Update7]: " Fawzi Mohamed
2011-07-12 20:01                 ` Tom Tromey
2011-07-15 15:34                   ` FYI " Fawzi Mohamed
2011-07-07 18:48       ` Fawzi Mohamed [this message]
2011-07-07 19:38         ` [PATCH,gdb,Update5]: " Tom Tromey

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=C29D3D87-52FA-4E67-929E-13A3B885E28E@nokia.com \
    --to=fawzi.mohamed@nokia.com \
    --cc=andre.poenitz@nokia.com \
    --cc=gdb-patches@sourceware.org \
    --cc=gingold@adacore.com \
    --cc=jan.kratochvil@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