Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] utils.c: Revise a couple of internal_error() messages
@ 2002-07-27 23:26 Kevin Buettner
  2002-07-29  8:56 ` Andrew Cagney
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2002-07-27 23:26 UTC (permalink / raw)
  To: gdb-patches

I've just committed the patch below.

In some work that I've been doing recently, I was seeing one of these
internal errors.  Unfortunately, the message string was identical for
both host_pointer_to_address() and address_to_host_pointer(), making
it difficult to tell which function was responsible.  I've changed the
messages to indicate the actual function responsible for the internal
error.  (I suspect that one of these functions was originally named
core_addr_to_void_ptr, but got renamed somewhere along the way without
a change to the error message.)

	* utils.c (host_pointer_to_address, address_to_host_pointer):
	Change internal_error() message to indicate function responsible
	for the error.
 
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.73
diff -u -p -r1.73 utils.c
--- utils.c	24 Jul 2002 17:58:46 -0000	1.73
+++ utils.c	27 Jul 2002 01:59:47 -0000
@@ -2464,7 +2464,7 @@ host_pointer_to_address (void *ptr)
 {
   if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
     internal_error (__FILE__, __LINE__,
-		    "core_addr_to_void_ptr: bad cast");
+		    "host_pointer_to_address: bad cast");
   return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
 }
 
@@ -2474,7 +2474,7 @@ address_to_host_pointer (CORE_ADDR addr)
   void *ptr;
   if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
     internal_error (__FILE__, __LINE__,
-		    "core_addr_to_void_ptr: bad cast");
+		    "address_to_host_pointer: bad cast");
   ADDRESS_TO_POINTER (builtin_type_void_data_ptr, &ptr, addr);
   return ptr;
 }


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

* Re: [PATCH] utils.c: Revise a couple of internal_error() messages
  2002-07-27 23:26 [PATCH] utils.c: Revise a couple of internal_error() messages Kevin Buettner
@ 2002-07-29  8:56 ` Andrew Cagney
  2002-07-31 10:25   ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2002-07-29  8:56 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

>  {
>    if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
>      internal_error (__FILE__, __LINE__,
> -		    "core_addr_to_void_ptr: bad cast");
> +		    "host_pointer_to_address: bad cast");
>    return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
>  }

BTW, another (easier/better?) way of resolving this is to convert the 
above into gdb_assert().  That way you pick up the function name for 
free (and in a maintainable way).

enjoy,
Andrew



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

* Re: [PATCH] utils.c: Revise a couple of internal_error() messages
  2002-07-29  8:56 ` Andrew Cagney
@ 2002-07-31 10:25   ` Kevin Buettner
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Buettner @ 2002-07-31 10:25 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

On Jul 29, 11:51am, Andrew Cagney wrote:

> >  {
> >    if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
> >      internal_error (__FILE__, __LINE__,
> > -		    "core_addr_to_void_ptr: bad cast");
> > +		    "host_pointer_to_address: bad cast");
> >    return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
> >  }
> 
> BTW, another (easier/better?) way of resolving this is to convert the 
> above into gdb_assert().  That way you pick up the function name for 
> free (and in a maintainable way).

I agree.  I've just committed the patch below.

	* utils.c (host_pointer_to_address, address_to_host_pointer):
	Use gdb_assert() instead of explicit call to internal_error().

Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.74
diff -u -p -r1.74 utils.c
--- utils.c	27 Jul 2002 02:03:45 -0000	1.74
+++ utils.c	31 Jul 2002 16:58:15 -0000
@@ -2462,9 +2462,7 @@ phex_nz (ULONGEST l, int sizeof_l)
 CORE_ADDR
 host_pointer_to_address (void *ptr)
 {
-  if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
-    internal_error (__FILE__, __LINE__,
-		    "host_pointer_to_address: bad cast");
+  gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
   return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
 }
 
@@ -2472,9 +2470,8 @@ void *
 address_to_host_pointer (CORE_ADDR addr)
 {
   void *ptr;
-  if (sizeof (ptr) != TYPE_LENGTH (builtin_type_void_data_ptr))
-    internal_error (__FILE__, __LINE__,
-		    "address_to_host_pointer: bad cast");
+
+  gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
   ADDRESS_TO_POINTER (builtin_type_void_data_ptr, &ptr, addr);
   return ptr;
 }


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

end of thread, other threads:[~2002-07-31 17:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-27 23:26 [PATCH] utils.c: Revise a couple of internal_error() messages Kevin Buettner
2002-07-29  8:56 ` Andrew Cagney
2002-07-31 10:25   ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox