public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] m32c: Print warning instead of error in address->pointer  function
@ 2010-04-06  4:23 Kevin Buettner
  2010-04-13 15:39 ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2010-04-06  4:23 UTC (permalink / raw)
  To: gdb-patches

The patch below fixes a number of failures for m32c-elf, around 40 in
gdb.cp/cplusfuncs.exp, and a handful in a few other places as well.

It changes the m32c address to pointer function so that it returns
a result which may be used to, most likely, obtain the original address
when passed to the m32c pointer to address function.  It does not,
however, return a correct pointer value because it does not refer a PLT
entry which may be called.  I.e. if a non-PLT pointer result produced
by m32c_m16c_address_to_pointer() were stuffed into a function pointer
variable in the inferior, and then called by the inferior, the result
would, almost certainly, not be correct.

The result can be useful though because there are more than a few
occassions where the address->pointer result is later passed to the
pointer->address function in order to obtain an address.  When used in
this manner, the results are usually pretty good.

The patch changes what used to be an error into a warning, thus
allowing the user to decide whether the actual results obtained are
useful or not.  If left as an error, the user has no chance to make
this determination even if the result might have been useful.

Comments?

	* m32c-tdep.c (m32c_m16c_address_to_pointer): Print warning
	instead of an error if no PLT entry is found.  Return a
	potentially useful result.
	(m32c_m16c_pointer_to_address): Add code to search for function
	address when no .plt entry is found.


Index: m32c-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m32c-tdep.c,v
retrieving revision 1.36
diff -u -p -r1.36 m32c-tdep.c
--- m32c-tdep.c	6 Apr 2010 00:14:43 -0000	1.36
+++ m32c-tdep.c	6 Apr 2010 04:12:39 -0000
@@ -2448,12 +2448,39 @@ m32c_m16c_address_to_pointer (struct gdb
       xfree (tramp_name);
 
       if (! tramp_msym)
-        error ("Cannot convert code address %s to function pointer:\n"
-               "couldn't find trampoline named '%s.plt'.",
-               paddress (gdbarch, addr), func_name);
+	{
+	  CORE_ADDR ptrval;
 
-      /* The trampoline's address is our pointer.  */
-      addr = SYMBOL_VALUE_ADDRESS (tramp_msym);
+	  /* No PLT entry found.  Mask off the upper bits of the address
+	     to make a pointer.  As noted in the warning to the user
+	     below, this value might be useful if converted back into
+	     an address by GDB, but will otherwise, almost certainly,
+	     be garbage.
+	     
+	     Using this masked result does seem to be useful
+	     in gdb.cp/cplusfuncs.exp in which ~40 FAILs turn into
+	     PASSes.  These results appear to be correct as well.
+	     
+	     We print a warning here so that the user can make a
+	     determination about whether the result is useful or not.  */
+	  ptrval = addr & 0xffff;
+
+	  warning ("Cannot convert code address %s to function pointer:\n"
+		   "couldn't find trampoline named '%s.plt'.\n"
+		   "Returning pointer value %s instead; this may produce\n"
+		   "a useful result if converted back into an address by GDB,\n"
+		   "but will most likely not be useful otherwise.\n",
+		   paddress (gdbarch, addr), func_name,
+		   paddress (gdbarch, ptrval));
+
+	  addr = ptrval;
+
+	}
+      else
+	{
+	  /* The trampoline's address is our pointer.  */
+	  addr = SYMBOL_VALUE_ADDRESS (tramp_msym);
+	}
     }
 
   store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr);
@@ -2508,6 +2535,18 @@ m32c_m16c_pointer_to_address (struct gdb
                 ptr = SYMBOL_VALUE_ADDRESS (func_msym);
             }
         }
+      else
+	{
+	  int aspace;
+
+	  for (aspace = 1; aspace <= 15; aspace++)
+	    {
+	      ptr_msym = lookup_minimal_symbol_by_pc ((aspace << 16) | ptr);
+	      
+	      if (ptr_msym)
+		ptr |= aspace << 16;
+	    }
+	}
     }
 
   return ptr;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] m32c: Print warning instead of error in address->pointer   function
  2010-04-06  4:23 [RFC] m32c: Print warning instead of error in address->pointer function Kevin Buettner
@ 2010-04-13 15:39 ` Joel Brobecker
  2010-04-16 22:48   ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2010-04-13 15:39 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

> 	* m32c-tdep.c (m32c_m16c_address_to_pointer): Print warning
> 	instead of an error if no PLT entry is found.  Return a
> 	potentially useful result.
> 	(m32c_m16c_pointer_to_address): Add code to search for function
> 	address when no .plt entry is found.

No objection on my end. Don't know if there is any better alternative
anyway, and an improvement is an improvement ;-).

I just noticed that you forgot to bracket the warning text with _()...

> +	  warning ("Cannot convert code address %s to function pointer:\n"
> +		   "couldn't find trampoline named '%s.plt'.\n"
> +		   "Returning pointer value %s instead; this may produce\n"
> +		   "a useful result if converted back into an address by GDB,\n"
> +		   "but will most likely not be useful otherwise.\n",
> +		   paddress (gdbarch, addr), func_name,
> +		   paddress (gdbarch, ptrval));

-- 
Joel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] m32c: Print warning instead of error in address->pointer    function
  2010-04-13 15:39 ` Joel Brobecker
@ 2010-04-16 22:48   ` Kevin Buettner
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Buettner @ 2010-04-16 22:48 UTC (permalink / raw)
  To: gdb-patches

On Tue, 13 Apr 2010 08:38:55 -0700
Joel Brobecker <brobecker@adacore.com> wrote:

> > 	* m32c-tdep.c (m32c_m16c_address_to_pointer): Print warning
> > 	instead of an error if no PLT entry is found.  Return a
> > 	potentially useful result.
> > 	(m32c_m16c_pointer_to_address): Add code to search for function
> > 	address when no .plt entry is found.
> 
> No objection on my end. Don't know if there is any better alternative
> anyway, and an improvement is an improvement ;-).
> 
> I just noticed that you forgot to bracket the warning text with _()...
> 
> > +	  warning ("Cannot convert code address %s to function pointer:\n"
> > +		   "couldn't find trampoline named '%s.plt'.\n"
> > +		   "Returning pointer value %s instead; this may produce\n"
> > +		   "a useful result if converted back into an address by GDB,\n"
> > +		   "but will most likely not be useful otherwise.\n",
> > +		   paddress (gdbarch, addr), func_name,
> > +		   paddress (gdbarch, ptrval));

Thanks for looking it over.  I ended up committing the patch below.

I bracketed the warning message with _().  I added the _() bracketing
to an error message im m32c_m16c_address_to_pointer() too.

	* m32c-tdep.c (m32c_m16c_address_to_pointer): Print warning
	instead of an error if no PLT entry is found.  Return a
	potentially useful result.
	(m32c_m16c_pointer_to_address): Add code to search for function
	address when no .plt entry is found.

Index: m32c-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m32c-tdep.c,v
retrieving revision 1.36
diff -u -p -r1.36 m32c-tdep.c
--- m32c-tdep.c	6 Apr 2010 00:14:43 -0000	1.36
+++ m32c-tdep.c	16 Apr 2010 22:43:40 -0000
@@ -2431,8 +2431,8 @@ m32c_m16c_address_to_pointer (struct gdb
       struct minimal_symbol *func_msym = lookup_minimal_symbol_by_pc (addr);
 
       if (! func_msym)
-        error ("Cannot convert code address %s to function pointer:\n"
-               "couldn't find a symbol at that address, to find trampoline.",
+        error (_("Cannot convert code address %s to function pointer:\n"
+               "couldn't find a symbol at that address, to find trampoline."),
                paddress (gdbarch, addr));
 
       func_name = SYMBOL_LINKAGE_NAME (func_msym);
@@ -2448,12 +2448,39 @@ m32c_m16c_address_to_pointer (struct gdb
       xfree (tramp_name);
 
       if (! tramp_msym)
-        error ("Cannot convert code address %s to function pointer:\n"
-               "couldn't find trampoline named '%s.plt'.",
-               paddress (gdbarch, addr), func_name);
+	{
+	  CORE_ADDR ptrval;
 
-      /* The trampoline's address is our pointer.  */
-      addr = SYMBOL_VALUE_ADDRESS (tramp_msym);
+	  /* No PLT entry found.  Mask off the upper bits of the address
+	     to make a pointer.  As noted in the warning to the user
+	     below, this value might be useful if converted back into
+	     an address by GDB, but will otherwise, almost certainly,
+	     be garbage.
+	     
+	     Using this masked result does seem to be useful
+	     in gdb.cp/cplusfuncs.exp in which ~40 FAILs turn into
+	     PASSes.  These results appear to be correct as well.
+	     
+	     We print a warning here so that the user can make a
+	     determination about whether the result is useful or not.  */
+	  ptrval = addr & 0xffff;
+
+	  warning (_("Cannot convert code address %s to function pointer:\n"
+		   "couldn't find trampoline named '%s.plt'.\n"
+		   "Returning pointer value %s instead; this may produce\n"
+		   "a useful result if converted back into an address by GDB,\n"
+		   "but will most likely not be useful otherwise.\n"),
+		   paddress (gdbarch, addr), func_name,
+		   paddress (gdbarch, ptrval));
+
+	  addr = ptrval;
+
+	}
+      else
+	{
+	  /* The trampoline's address is our pointer.  */
+	  addr = SYMBOL_VALUE_ADDRESS (tramp_msym);
+	}
     }
 
   store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr);
@@ -2508,6 +2535,18 @@ m32c_m16c_pointer_to_address (struct gdb
                 ptr = SYMBOL_VALUE_ADDRESS (func_msym);
             }
         }
+      else
+	{
+	  int aspace;
+
+	  for (aspace = 1; aspace <= 15; aspace++)
+	    {
+	      ptr_msym = lookup_minimal_symbol_by_pc ((aspace << 16) | ptr);
+	      
+	      if (ptr_msym)
+		ptr |= aspace << 16;
+	    }
+	}
     }
 
   return ptr;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-16 22:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-06  4:23 [RFC] m32c: Print warning instead of error in address->pointer function Kevin Buettner
2010-04-13 15:39 ` Joel Brobecker
2010-04-16 22:48   ` Kevin Buettner

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).