This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] utils.c: Revise a couple of internal_error() messages


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;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]