[rfa/utils] preg -> phex + monitor.c fix

Andrew Cagney ac131313@cygnus.com
Sun May 14 20:47:00 GMT 2000


Hello,

The attached replaces preg() with the more useful/correct phex() and
uses it to fix a trace bug in monitor.c.
It also eliminates the bogus ``typedef t_reg''.

	Andrew
Mon May 15 12:30:57 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* defs.h (t_reg): Delete typedef.
	(preg, preg_nz): Delete function. Replaced by phex and phex_nz.
	* utils.c (phex, phex_nz): New functions.
	(paddr, paddr_nz): Use.

	* monitor.c (monitor_store_register): Replace preg with phex.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.17
diff -p -r1.17 defs.h
*** defs.h	2000/05/02 08:57:21	1.17
--- defs.h	2000/05/15 03:30:53
*************** extern char *paddr_nz (CORE_ADDR addr);
*** 484,492 ****
  extern char *paddr_u (CORE_ADDR addr);
  extern char *paddr_d (LONGEST addr);
  
! typedef bfd_vma t_reg;
! extern char *preg (t_reg reg);
! extern char *preg_nz (t_reg reg);
  
  extern void fprintf_symbol_filtered (struct ui_file *, char *,
  				     enum language, int);
--- 484,491 ----
  extern char *paddr_u (CORE_ADDR addr);
  extern char *paddr_d (LONGEST addr);
  
! extern char *phex (ULONGEST l, int sizeof_l);
! extern char *phex_nz (ULONGEST l, int sizeof_l);
  
  extern void fprintf_symbol_filtered (struct ui_file *, char *,
  				     enum language, int);
Index: monitor.c
===================================================================
RCS file: /cvs/src/src/gdb/monitor.c,v
retrieving revision 1.5
diff -p -r1.5 monitor.c
*** monitor.c	2000/05/03 18:21:52	1.5
--- monitor.c	2000/05/15 03:30:58
*************** monitor_store_register (regno)
*** 1377,1383 ****
      }
  
    val = read_register (regno);
!   monitor_debug ("MON storeg %d %s\n", regno, preg (val));
  
    /* send the register deposit command */
  
--- 1377,1384 ----
      }
  
    val = read_register (regno);
!   monitor_debug ("MON storeg %d %s\n", regno,
! 		 phex (val, REGISTER_RAW_SIZE (regno)));
  
    /* send the register deposit command */
  
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.8
diff -p -r1.8 utils.c
*** utils.c	2000/04/27 00:15:14	1.8
--- utils.c	2000/05/15 03:31:05
*************** floatformat_from_doublest (fmt, from, to
*** 2819,2824 ****
--- 2819,2826 ----
      }
  }
  
+ /* print routines to handle variable size regs, etc. */
+ 
  /* temporary storage using circular buffer */
  #define NUMCELLS 16
  #define CELLSIZE 32
*************** get_cell ()
*** 2832,2910 ****
    return buf[cell];
  }
  
- /* print routines to handle variable size regs, etc.
- 
-    FIXME: Note that t_addr is a bfd_vma, which is currently either an
-    unsigned long or unsigned long long, determined at configure time.
-    If t_addr is an unsigned long long and sizeof (unsigned long long)
-    is greater than sizeof (unsigned long), then I believe this code will
-    probably lose, at least for little endian machines.  I believe that
-    it would also be better to eliminate the switch on the absolute size
-    of t_addr and replace it with a sequence of if statements that compare
-    sizeof t_addr with sizeof the various types and do the right thing,
-    which includes knowing whether or not the host supports long long.
-    -fnf
- 
-  */
- 
  int
  strlen_paddr (void)
  {
    return (TARGET_PTR_BIT / 8 * 2);
  }
  
- 
- /* eliminate warning from compiler on 32-bit systems */
- static int thirty_two = 32;
- 
  char *
  paddr (CORE_ADDR addr)
  {
!   char *paddr_str = get_cell ();
!   switch (TARGET_PTR_BIT / 8)
!     {
!     case 8:
!       sprintf (paddr_str, "%08lx%08lx",
! 	       (unsigned long) (addr >> thirty_two), (unsigned long) (addr & 0xffffffff));
!       break;
!     case 4:
!       sprintf (paddr_str, "%08lx", (unsigned long) addr);
!       break;
!     case 2:
!       sprintf (paddr_str, "%04x", (unsigned short) (addr & 0xffff));
!       break;
!     default:
!       sprintf (paddr_str, "%lx", (unsigned long) addr);
!     }
!   return paddr_str;
  }
  
  char *
  paddr_nz (CORE_ADDR addr)
  {
!   char *paddr_str = get_cell ();
!   switch (TARGET_PTR_BIT / 8)
!     {
!     case 8:
!       {
! 	unsigned long high = (unsigned long) (addr >> thirty_two);
! 	if (high == 0)
! 	  sprintf (paddr_str, "%lx", (unsigned long) (addr & 0xffffffff));
! 	else
! 	  sprintf (paddr_str, "%lx%08lx",
! 		   high, (unsigned long) (addr & 0xffffffff));
! 	break;
!       }
!     case 4:
!       sprintf (paddr_str, "%lx", (unsigned long) addr);
!       break;
!     case 2:
!       sprintf (paddr_str, "%x", (unsigned short) (addr & 0xffff));
!       break;
!     default:
!       sprintf (paddr_str, "%lx", (unsigned long) addr);
!     }
!   return paddr_str;
  }
  
  static void
--- 2834,2855 ----
    return buf[cell];
  }
  
  int
  strlen_paddr (void)
  {
    return (TARGET_PTR_BIT / 8 * 2);
  }
  
  char *
  paddr (CORE_ADDR addr)
  {
!   return phex (addr, TARGET_PTR_BIT / 8);
  }
  
  char *
  paddr_nz (CORE_ADDR addr)
  {
!   return phex_nz (addr, TARGET_PTR_BIT / 8);
  }
  
  static void
*************** paddr_d (LONGEST addr)
*** 2959,3014 ****
    return paddr_str;
  }
  
  char *
! preg (reg)
!      t_reg reg;
  {
!   char *preg_str = get_cell ();
!   switch (sizeof (t_reg))
      {
      case 8:
!       sprintf (preg_str, "%08lx%08lx",
! 	       (unsigned long) (reg >> thirty_two), (unsigned long) (reg & 0xffffffff));
        break;
      case 4:
!       sprintf (preg_str, "%08lx", (unsigned long) reg);
        break;
      case 2:
!       sprintf (preg_str, "%04x", (unsigned short) (reg & 0xffff));
        break;
      default:
!       sprintf (preg_str, "%lx", (unsigned long) reg);
      }
!   return preg_str;
  }
  
  char *
! preg_nz (reg)
!      t_reg reg;
  {
!   char *preg_str = get_cell ();
!   switch (sizeof (t_reg))
      {
      case 8:
        {
! 	unsigned long high = (unsigned long) (reg >> thirty_two);
  	if (high == 0)
! 	  sprintf (preg_str, "%lx", (unsigned long) (reg & 0xffffffff));
  	else
! 	  sprintf (preg_str, "%lx%08lx",
! 		   high, (unsigned long) (reg & 0xffffffff));
  	break;
        }
      case 4:
!       sprintf (preg_str, "%lx", (unsigned long) reg);
        break;
      case 2:
!       sprintf (preg_str, "%x", (unsigned short) (reg & 0xffff));
        break;
      default:
!       sprintf (preg_str, "%lx", (unsigned long) reg);
      }
!   return preg_str;
  }
  
  /* Helper functions for INNER_THAN */
--- 2904,2963 ----
    return paddr_str;
  }
  
+ /* eliminate warning from compiler on 32-bit systems */
+ static int thirty_two = 32;
+ 
  char *
! phex (ULONGEST l, int sizeof_l)
  {
!   char *str = get_cell ();
!   switch (sizeof_l)
      {
      case 8:
!       sprintf (str, "%08lx%08lx",
! 	       (unsigned long) (l >> thirty_two),
! 	       (unsigned long) (l & 0xffffffff));
        break;
      case 4:
!       sprintf (str, "%08lx", (unsigned long) l);
        break;
      case 2:
!       sprintf (str, "%04x", (unsigned short) (l & 0xffff));
        break;
      default:
!       phex (l, sizeof (l));
!       break;
      }
!   return str;
  }
  
  char *
! phex_nz (ULONGEST l, int sizeof_l)
  {
!   char *str = get_cell ();
!   switch (sizeof_l)
      {
      case 8:
        {
! 	unsigned long high = (unsigned long) (l >> thirty_two);
  	if (high == 0)
! 	  sprintf (str, "%lx", (unsigned long) (l & 0xffffffff));
  	else
! 	  sprintf (str, "%lx%08lx",
! 		   high, (unsigned long) (l & 0xffffffff));
  	break;
        }
      case 4:
!       sprintf (str, "%lx", (unsigned long) l);
        break;
      case 2:
!       sprintf (str, "%x", (unsigned short) (l & 0xffff));
        break;
      default:
!       phex_nz (l, sizeof (l));
!       break;
      }
!   return str;
  }
  
  /* Helper functions for INNER_THAN */


More information about the Gdb-patches mailing list