Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
@ 2003-01-31 22:58 Andrew Cagney
  2003-01-31 23:20 ` Andreas Schwab
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Andrew Cagney @ 2003-01-31 22:58 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

Hello,

Since MAX_REGISTER_RAW_SIZE is implemented using a function the declaration:

	  char buf[MAX_REGISTER_RAW_SIZE];

is illegal.  (GCC does allow it which is why no one notices :-/).

The attached patch updates all obvious (as in found by a grep) 
occurances of this and changes them to:

	char *buf = alloca (max_register_raw_size (current_gdbarch));

I'll look to commiting this in a few days,

enjoy,
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 16239 bytes --]

2003-01-31  Andrew Cagney  <ac131313@redhat.com>

	* mips-nat.c (zerobuf): Delete.
	(fetch_inferior_registers): Alloc local zerobuf.
	(fetch_core_registers): Alloc local zerobuf.
	* d10v-tdep.c (show_regs): Don't allocate a dynamic array using
	MAX_REGISTER_RAW_SIZE or MAX_REGISTER_VIRTUAL_SIZE.
	* thread-db.c (thread_db_store_registers): Ditto.
	* sh-tdep.c (sh_do_register): Ditto.
	* rom68k-rom.c (rom68k_supply_one_register): Ditto.
	* remote-sim.c (gdbsim_store_register): Ditto.
	* remote-mips.c (mips_wait, mips_fetch_registers): Ditto.
	* remote-e7000.c (fetch_regs_from_dump): Ditto.
	* monitor.c (monitor_supply_register): Ditto.
	* mipsv4-nat.c (supply_gregset, supply_fpregset): Ditto.
	* mips-nat.c (fetch_inferior_registers): Ditto.
	* m68klinux-nat.c (fetch_register): Ditto.
	* lynx-nat.c (fetch_inferior_registers): Ditto.
	(fetch_inferior_registers): Ditto.
	* irix4-nat.c (supply_gregset, supply_fpregset): Ditto.
	* hpux-thread.c (hpux_thread_fetch_registers): Ditto.
	(hpux_thread_store_registers): Ditto.
	* hppah-nat.c (fetch_register): Ditto.
	* hppab-nat.c (fetch_register): Ditto.
	* hppa-tdep.c (pa_register_look_aside): Ditto.
	(pa_print_fp_reg, pa_strcat_fp_reg): Ditto.
	* dve3900-rom.c (fetch_bitmapped_register): Ditto.

Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.73
diff -u -r1.73 d10v-tdep.c
--- d10v-tdep.c	30 Jan 2003 15:11:20 -0000	1.73
+++ d10v-tdep.c	31 Jan 2003 22:19:41 -0000
@@ -864,17 +864,19 @@
       printf_filtered ("\n");
     }
   printf_filtered ("A0-A%d", NR_A_REGS - 1);
-  for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++)
-    {
-      char num[MAX_REGISTER_RAW_SIZE];
-      int i;
-      printf_filtered ("  ");
-      deprecated_read_register_gen (a, (char *) &num);
-      for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
-	{
-	  printf_filtered ("%02x", (num[i] & 0xff));
-	}
-    }
+  {
+    char *num = alloca (max_register_size (current_gdbarch));
+    for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++)
+      {
+	int i;
+	printf_filtered ("  ");
+	deprecated_read_register_gen (a, (char *) &num);
+	for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
+	  {
+	    printf_filtered ("%02x", (num[i] & 0xff));
+	  }
+      }
+  }
   printf_filtered ("\n");
 }
 
Index: dve3900-rom.c
===================================================================
RCS file: /cvs/src/src/gdb/dve3900-rom.c,v
retrieving revision 1.10
diff -u -r1.10 dve3900-rom.c
--- dve3900-rom.c	18 Jan 2003 15:55:51 -0000	1.10
+++ dve3900-rom.c	31 Jan 2003 22:19:41 -0000
@@ -455,7 +455,7 @@
 fetch_bitmapped_register (int regno, struct bit_field *bf)
 {
   unsigned long val;
-  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
+  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
   char *regname = NULL;
 
   if (regno >= sizeof (r3900_regnames) / sizeof (r3900_regnames[0]))
Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.47
diff -u -r1.47 hppa-tdep.c
--- hppa-tdep.c	18 Jan 2003 15:55:52 -0000	1.47
+++ hppa-tdep.c	31 Jan 2003 22:19:42 -0000
@@ -2636,7 +2636,7 @@
   int start;
 
 
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
   long long reg_val;
 
   if (!know_which)
@@ -2833,8 +2833,8 @@
 static void
 pa_print_fp_reg (int i)
 {
-  char raw_buffer[MAX_REGISTER_RAW_SIZE];
-  char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
+  char *raw_buffer = alloca (max_register_size (current_gdbarch));
+  char *virtual_buffer = alloca (max_register_size (current_gdbarch));
 
   /* Get 32bits of data.  */
   frame_register_read (deprecated_selected_frame, i, raw_buffer);
@@ -2876,8 +2876,8 @@
 static void
 pa_strcat_fp_reg (int i, struct ui_file *stream, enum precision_type precision)
 {
-  char raw_buffer[MAX_REGISTER_RAW_SIZE];
-  char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
+  char *raw_buffer = alloca (max_register_size (current_gdbarch));
+  char *virtual_buffer = alloca (max_register_size (current_gdbarch));
 
   fputs_filtered (REGISTER_NAME (i), stream);
   print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), stream);
@@ -2891,7 +2891,7 @@
   if (precision == double_precision && (i % 2) == 0)
     {
 
-      char raw_buf[MAX_REGISTER_RAW_SIZE];
+      char *raw_buf = alloca (max_register_size (current_gdbarch));
 
       /* Get the data in raw format for the 2nd half.  */
       frame_register_read (deprecated_selected_frame, i + 1, raw_buf);
Index: hppab-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/hppab-nat.c,v
retrieving revision 1.7
diff -u -r1.7 hppab-nat.c
--- hppab-nat.c	14 Nov 2002 20:37:28 -0000	1.7
+++ hppab-nat.c	31 Jan 2003 22:19:42 -0000
@@ -55,7 +55,7 @@
 fetch_register (int regno)
 {
   register unsigned int regaddr;
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
   register int i;
 
   /* Offset of registers within the u area.  */
Index: hppah-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/hppah-nat.c,v
retrieving revision 1.21
diff -u -r1.21 hppah-nat.c
--- hppah-nat.c	29 Jan 2003 15:56:11 -0000	1.21
+++ hppah-nat.c	31 Jan 2003 22:19:42 -0000
@@ -189,7 +189,7 @@
 static void
 fetch_register (int regno)
 {
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
   unsigned int addr, len, offset;
   int i;
 
Index: hpux-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/hpux-thread.c,v
retrieving revision 1.13
diff -u -r1.13 hpux-thread.c
--- hpux-thread.c	14 Nov 2002 20:37:28 -0000	1.13
+++ hpux-thread.c	31 Jan 2003 22:19:42 -0000
@@ -285,7 +285,7 @@
 	child_ops.to_fetch_registers (regno);
       else
 	{
-	  unsigned char buf[MAX_REGISTER_RAW_SIZE];
+	  unsigned char *buf = alloca (max_register_size (current_gdbarch));
 	  CORE_ADDR sp;
 
 	  sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
@@ -347,7 +347,7 @@
 	child_ops.to_store_registers (regno);
       else
 	{
-	  unsigned char buf[MAX_REGISTER_RAW_SIZE];
+	  unsigned char *buf = alloca (max_register_size (current_gdbarch));
 	  CORE_ADDR sp;
 
 	  sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
Index: irix4-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/irix4-nat.c,v
retrieving revision 1.9
diff -u -r1.9 irix4-nat.c
--- irix4-nat.c	14 Nov 2002 20:37:28 -0000	1.9
+++ irix4-nat.c	31 Jan 2003 22:19:42 -0000
@@ -51,8 +51,8 @@
 {
   register int regi;
   register greg_t *regp = (greg_t *) (gregsetp->gp_regs);
-  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
-  {0};
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
 
   /* FIXME: somewhere, there should be a #define for the meaning
      of this magic number 32; we should use that. */
@@ -104,8 +104,8 @@
 supply_fpregset (fpregset_t *fpregsetp)
 {
   register int regi;
-  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
-  {0};
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
 
   for (regi = 0; regi < 32; regi++)
     supply_register (FP0_REGNUM + regi,
Index: lynx-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/lynx-nat.c,v
retrieving revision 1.11
diff -u -r1.11 lynx-nat.c
--- lynx-nat.c	14 Nov 2002 20:37:28 -0000	1.11
+++ lynx-nat.c	31 Jan 2003 22:19:42 -0000
@@ -282,7 +282,7 @@
   if (whatregs & WHATREGS_GEN)
     {
       struct econtext ec;	/* general regs */
-      char buf[MAX_REGISTER_RAW_SIZE];
+      char *buf = alloca (max_register_size (current_gdbarch));
       int retval;
       int i;
 
@@ -510,29 +510,31 @@
 
   ecp = registers_addr (PIDGET (inferior_ptid));
 
-  for (regno = reglo; regno <= reghi; regno++)
-    {
-      char buf[MAX_REGISTER_RAW_SIZE];
-      int ptrace_fun = PTRACE_PEEKTHREAD;
-
+  {
+    char *buf = alloca (max_register_size (current_gdbarch));
+    for (regno = reglo; regno <= reghi; regno++)
+      {
+	int ptrace_fun = PTRACE_PEEKTHREAD;
+	
 #ifdef M68K
-      ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD;
+	ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD;
 #endif
-
-      for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
-	{
-	  unsigned int reg;
-
-	  errno = 0;
-	  reg = ptrace (ptrace_fun, PIDGET (inferior_ptid),
-			(PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), 0);
-	  if (errno)
-	    perror_with_name ("ptrace(PTRACE_PEEKUSP)");
-
-	  *(int *) &buf[i] = reg;
-	}
-      supply_register (regno, buf);
-    }
+	
+	for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
+	  {
+	    unsigned int reg;
+	    
+	    errno = 0;
+	    reg = ptrace (ptrace_fun, PIDGET (inferior_ptid),
+			  (PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), 0);
+	    if (errno)
+	      perror_with_name ("ptrace(PTRACE_PEEKUSP)");
+	    
+	    *(int *) &buf[i] = reg;
+	  }
+	supply_register (regno, buf);
+      }
+  }
 }
 
 /* Store our register values back into the inferior.
Index: m68klinux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
retrieving revision 1.15
diff -u -r1.15 m68klinux-nat.c
--- m68klinux-nat.c	23 Nov 2002 19:45:11 -0000	1.15
+++ m68klinux-nat.c	31 Jan 2003 22:19:42 -0000
@@ -135,7 +135,7 @@
   char mess[128];		/* For messages */
   register int i;
   unsigned int offset;		/* Offset of registers within the u area.  */
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
   int tid;
 
   if (CANNOT_FETCH_REGISTER (regno))
Index: mips-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/mips-nat.c,v
retrieving revision 1.8
diff -u -r1.8 mips-nat.c
--- mips-nat.c	7 Nov 2002 15:31:31 -0000	1.8
+++ mips-nat.c	31 Jan 2003 22:19:42 -0000
@@ -62,9 +62,6 @@
   : regno >= FP0_REGNUM ?	FPR_BASE + (regno - FP0_REGNUM) \
   : 0)
 
-static char zerobuf[MAX_REGISTER_RAW_SIZE] =
-{0};
-
 static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
 
 /* Get all registers from the inferior */
@@ -73,8 +70,10 @@
 fetch_inferior_registers (int regno)
 {
   register unsigned int regaddr;
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
   register int i;
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
 
   deprecated_registers_fetched ();
 
@@ -174,6 +173,10 @@
   register unsigned int addr;
   int bad_reg = -1;
   register reg_ptr = -reg_addr;	/* Original u.u_ar0 is -reg_addr. */
+
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
+
 
   /* If u.u_ar0 was an absolute address in the core file, relativize it now,
      so we can use it as an offset into core_reg_sect.  When we're done,
Index: mipsv4-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/mipsv4-nat.c,v
retrieving revision 1.7
diff -u -r1.7 mipsv4-nat.c
--- mipsv4-nat.c	14 Nov 2002 20:37:28 -0000	1.7
+++ mipsv4-nat.c	31 Jan 2003 22:19:42 -0000
@@ -47,8 +47,8 @@
 {
   register int regi;
   register greg_t *regp = &(*gregsetp)[0];
-  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
-  {0};
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
 
   for (regi = 0; regi <= CXT_RA; regi++)
     supply_register (regi, (char *) (regp + regi));
@@ -102,8 +102,8 @@
 supply_fpregset (fpregset_t *fpregsetp)
 {
   register int regi;
-  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
-  {0};
+  char *zerobuf = alloca (max_register_size (current_gdbarch));
+  memset (zerobuf, 0, max_register_size (current_gdbarch));
 
   for (regi = 0; regi < 32; regi++)
     supply_register (FP0_REGNUM + regi,
Index: monitor.c
===================================================================
RCS file: /cvs/src/src/gdb/monitor.c,v
retrieving revision 1.36
diff -u -r1.36 monitor.c
--- monitor.c	12 Nov 2002 21:43:55 -0000	1.36
+++ monitor.c	31 Jan 2003 22:19:42 -0000
@@ -894,7 +894,7 @@
 monitor_supply_register (int regno, char *valstr)
 {
   ULONGEST val;
-  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
+  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
   char *p;
 
   val = 0;
Index: remote-e7000.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-e7000.c,v
retrieving revision 1.31
diff -u -r1.31 remote-e7000.c
--- remote-e7000.c	29 Nov 2002 19:40:30 -0000	1.31
+++ remote-e7000.c	31 Jan 2003 22:19:42 -0000
@@ -785,7 +785,7 @@
 fetch_regs_from_dump (int (*nextchar) (), char *want)
 {
   int regno;
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char *buf = alloca (max_register_size (current_gdbarch));
 
   int thischar = nextchar ();
 
Index: remote-mips.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-mips.c,v
retrieving revision 1.31
diff -u -r1.31 remote-mips.c
--- remote-mips.c	18 Jan 2003 15:55:52 -0000	1.31
+++ remote-mips.c	31 Jan 2003 22:19:43 -0000
@@ -1791,7 +1791,7 @@
 		    &rpc, &rfp, &rsp, flags);
   if (nfields >= 3)
     {
-      char buf[MAX_REGISTER_RAW_SIZE];
+      char *buf = alloca (max_register_size (current_gdbarch));
 
       store_unsigned_integer (buf, REGISTER_RAW_SIZE (PC_REGNUM), rpc);
       supply_register (PC_REGNUM, buf);
@@ -1972,7 +1972,7 @@
     }
 
   {
-    char buf[MAX_REGISTER_RAW_SIZE];
+    char *buf = alloca (max_register_size (current_gdbarch));
 
     /* We got the number the register holds, but gdb expects to see a
        value in the target byte ordering.  */
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.26
diff -u -r1.26 remote-sim.c
--- remote-sim.c	12 Nov 2002 21:43:55 -0000	1.26
+++ remote-sim.c	31 Jan 2003 22:19:43 -0000
@@ -359,7 +359,7 @@
     }
   else if (REGISTER_SIM_REGNO (regno) >= 0)
     {
-      char tmp[MAX_REGISTER_RAW_SIZE];
+      char *tmp = alloca (max_register_size (current_gdbarch));
       int nr_bytes;
       deprecated_read_register_gen (regno, tmp);
       nr_bytes = sim_store_register (gdbsim_desc,
Index: rom68k-rom.c
===================================================================
RCS file: /cvs/src/src/gdb/rom68k-rom.c,v
retrieving revision 1.9
diff -u -r1.9 rom68k-rom.c
--- rom68k-rom.c	23 Nov 2002 19:45:11 -0000	1.9
+++ rom68k-rom.c	31 Jan 2003 22:19:43 -0000
@@ -88,7 +88,7 @@
 rom68k_supply_one_register (int regno, unsigned char *hex)
 {
   ULONGEST value;
-  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
+  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
 
   value = 0;
   while (*hex != '\0')
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.94
diff -u -r1.94 sh-tdep.c
--- sh-tdep.c	21 Jan 2003 19:43:47 -0000	1.94
+++ sh-tdep.c	31 Jan 2003 22:19:45 -0000
@@ -4009,7 +4009,7 @@
 static void
 sh_do_register (int regnum)
 {
-  char raw_buffer[MAX_REGISTER_RAW_SIZE];
+  char *raw_buffer = alloca (max_register_size (current_gdbarch));
 
   fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
   print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), gdb_stdout);
Index: thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/thread-db.c,v
retrieving revision 1.28
diff -u -r1.28 thread-db.c
--- thread-db.c	14 Jan 2003 00:49:04 -0000	1.28
+++ thread-db.c	31 Jan 2003 22:19:45 -0000
@@ -941,7 +941,7 @@
 
   if (regno != -1)
     {
-      char raw[MAX_REGISTER_RAW_SIZE];
+      char *raw = alloca (max_register_size (current_gdbarch));
 
       deprecated_read_register_gen (regno, raw);
       thread_db_fetch_registers (-1);

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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-01-31 22:58 [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE] Andrew Cagney
@ 2003-01-31 23:20 ` Andreas Schwab
  2003-01-31 23:26   ` Andrew Cagney
  2003-02-01  1:36 ` Michael Snyder
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2003-01-31 23:20 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

Andrew Cagney <ac131313@redhat.com> writes:

|> Hello,
|> 
|> Since MAX_REGISTER_RAW_SIZE is implemented using a function the declaration:
|> 
|> 	  char buf[MAX_REGISTER_RAW_SIZE];
|> 
|> is illegal.  (GCC does allow it which is why no one notices :-/).
|> 
|> The attached patch updates all obvious (as in found by a grep) occurances
|> of this and changes them to:
|> 
|> 	char *buf = alloca (max_register_raw_size (current_gdbarch));

You have used max_register_size in the patch.  Which of the two is
correct?

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-01-31 23:20 ` Andreas Schwab
@ 2003-01-31 23:26   ` Andrew Cagney
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Cagney @ 2003-01-31 23:26 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

> Andrew Cagney <ac131313@redhat.com> writes:
> 
> |> Hello,
> |> 
> |> Since MAX_REGISTER_RAW_SIZE is implemented using a function the declaration:
> |> 
> |> 	  char buf[MAX_REGISTER_RAW_SIZE];
> |> 
> |> is illegal.  (GCC does allow it which is why no one notices :-/).
> |> 
> |> The attached patch updates all obvious (as in found by a grep) occurances
> |> of this and changes them to:
> |> 
> |> 	char *buf = alloca (max_register_raw_size (current_gdbarch));
> 
> You have used max_register_size in the patch.  Which of the two is
> correct?

Oops, max_register_size() is correct.  (I've built all the cross targets).

Hmm, I also forgot to mention that it hit both MAX_REGISTER_RAW_SIZE and 
MAX_REGISTER_VIRTUAL_SIZE.

Andrew



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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-01-31 22:58 [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE] Andrew Cagney
  2003-01-31 23:20 ` Andreas Schwab
@ 2003-02-01  1:36 ` Michael Snyder
  2003-02-01  6:17   ` Andrew Cagney
  2003-02-01  6:13 ` Joel Brobecker
  2003-02-02  5:36 ` Andrew Cagney
  3 siblings, 1 reply; 9+ messages in thread
From: Michael Snyder @ 2003-02-01  1:36 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

Andrew Cagney wrote:
> 
> Hello,
> 
> Since MAX_REGISTER_RAW_SIZE is implemented using a function the declaration:
> 
>           char buf[MAX_REGISTER_RAW_SIZE];
> 
> is illegal.  (GCC does allow it which is why no one notices :-/).
> 
> The attached patch updates all obvious (as in found by a grep)
> occurances of this and changes them to:
> 
>         char *buf = alloca (max_register_raw_size (current_gdbarch));
> 
> I'll look to commiting this in a few days,

I'm not sure, but I think you need to go even further:

	char *buf;
	buf = alloca (...);

Some compilers will not allow a function call in an auto initializer.

> 
> enjoy,
> Andrew
> 
>   -------------------------------------------------------------------------------
> 2003-01-31  Andrew Cagney  <ac131313@redhat.com>
> 
>         * mips-nat.c (zerobuf): Delete.
>         (fetch_inferior_registers): Alloc local zerobuf.
>         (fetch_core_registers): Alloc local zerobuf.
>         * d10v-tdep.c (show_regs): Don't allocate a dynamic array using
>         MAX_REGISTER_RAW_SIZE or MAX_REGISTER_VIRTUAL_SIZE.
>         * thread-db.c (thread_db_store_registers): Ditto.
>         * sh-tdep.c (sh_do_register): Ditto.
>         * rom68k-rom.c (rom68k_supply_one_register): Ditto.
>         * remote-sim.c (gdbsim_store_register): Ditto.
>         * remote-mips.c (mips_wait, mips_fetch_registers): Ditto.
>         * remote-e7000.c (fetch_regs_from_dump): Ditto.
>         * monitor.c (monitor_supply_register): Ditto.
>         * mipsv4-nat.c (supply_gregset, supply_fpregset): Ditto.
>         * mips-nat.c (fetch_inferior_registers): Ditto.
>         * m68klinux-nat.c (fetch_register): Ditto.
>         * lynx-nat.c (fetch_inferior_registers): Ditto.
>         (fetch_inferior_registers): Ditto.
>         * irix4-nat.c (supply_gregset, supply_fpregset): Ditto.
>         * hpux-thread.c (hpux_thread_fetch_registers): Ditto.
>         (hpux_thread_store_registers): Ditto.
>         * hppah-nat.c (fetch_register): Ditto.
>         * hppab-nat.c (fetch_register): Ditto.
>         * hppa-tdep.c (pa_register_look_aside): Ditto.
>         (pa_print_fp_reg, pa_strcat_fp_reg): Ditto.
>         * dve3900-rom.c (fetch_bitmapped_register): Ditto.
> 
> Index: d10v-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
> retrieving revision 1.73
> diff -u -r1.73 d10v-tdep.c
> --- d10v-tdep.c 30 Jan 2003 15:11:20 -0000      1.73
> +++ d10v-tdep.c 31 Jan 2003 22:19:41 -0000
> @@ -864,17 +864,19 @@
>        printf_filtered ("\n");
>      }
>    printf_filtered ("A0-A%d", NR_A_REGS - 1);
> -  for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++)
> -    {
> -      char num[MAX_REGISTER_RAW_SIZE];
> -      int i;
> -      printf_filtered ("  ");
> -      deprecated_read_register_gen (a, (char *) &num);
> -      for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
> -       {
> -         printf_filtered ("%02x", (num[i] & 0xff));
> -       }
> -    }
> +  {
> +    char *num = alloca (max_register_size (current_gdbarch));
> +    for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++)
> +      {
> +       int i;
> +       printf_filtered ("  ");
> +       deprecated_read_register_gen (a, (char *) &num);
> +       for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
> +         {
> +           printf_filtered ("%02x", (num[i] & 0xff));
> +         }
> +      }
> +  }
>    printf_filtered ("\n");
>  }
> 
> Index: dve3900-rom.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/dve3900-rom.c,v
> retrieving revision 1.10
> diff -u -r1.10 dve3900-rom.c
> --- dve3900-rom.c       18 Jan 2003 15:55:51 -0000      1.10
> +++ dve3900-rom.c       31 Jan 2003 22:19:41 -0000
> @@ -455,7 +455,7 @@
>  fetch_bitmapped_register (int regno, struct bit_field *bf)
>  {
>    unsigned long val;
> -  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
> +  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
>    char *regname = NULL;
> 
>    if (regno >= sizeof (r3900_regnames) / sizeof (r3900_regnames[0]))
> Index: hppa-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
> retrieving revision 1.47
> diff -u -r1.47 hppa-tdep.c
> --- hppa-tdep.c 18 Jan 2003 15:55:52 -0000      1.47
> +++ hppa-tdep.c 31 Jan 2003 22:19:42 -0000
> @@ -2636,7 +2636,7 @@
>    int start;
> 
> 
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
>    long long reg_val;
> 
>    if (!know_which)
> @@ -2833,8 +2833,8 @@
>  static void
>  pa_print_fp_reg (int i)
>  {
> -  char raw_buffer[MAX_REGISTER_RAW_SIZE];
> -  char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
> +  char *raw_buffer = alloca (max_register_size (current_gdbarch));
> +  char *virtual_buffer = alloca (max_register_size (current_gdbarch));
> 
>    /* Get 32bits of data.  */
>    frame_register_read (deprecated_selected_frame, i, raw_buffer);
> @@ -2876,8 +2876,8 @@
>  static void
>  pa_strcat_fp_reg (int i, struct ui_file *stream, enum precision_type precision)
>  {
> -  char raw_buffer[MAX_REGISTER_RAW_SIZE];
> -  char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
> +  char *raw_buffer = alloca (max_register_size (current_gdbarch));
> +  char *virtual_buffer = alloca (max_register_size (current_gdbarch));
> 
>    fputs_filtered (REGISTER_NAME (i), stream);
>    print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), stream);
> @@ -2891,7 +2891,7 @@
>    if (precision == double_precision && (i % 2) == 0)
>      {
> 
> -      char raw_buf[MAX_REGISTER_RAW_SIZE];
> +      char *raw_buf = alloca (max_register_size (current_gdbarch));
> 
>        /* Get the data in raw format for the 2nd half.  */
>        frame_register_read (deprecated_selected_frame, i + 1, raw_buf);
> Index: hppab-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/hppab-nat.c,v
> retrieving revision 1.7
> diff -u -r1.7 hppab-nat.c
> --- hppab-nat.c 14 Nov 2002 20:37:28 -0000      1.7
> +++ hppab-nat.c 31 Jan 2003 22:19:42 -0000
> @@ -55,7 +55,7 @@
>  fetch_register (int regno)
>  {
>    register unsigned int regaddr;
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
>    register int i;
> 
>    /* Offset of registers within the u area.  */
> Index: hppah-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/hppah-nat.c,v
> retrieving revision 1.21
> diff -u -r1.21 hppah-nat.c
> --- hppah-nat.c 29 Jan 2003 15:56:11 -0000      1.21
> +++ hppah-nat.c 31 Jan 2003 22:19:42 -0000
> @@ -189,7 +189,7 @@
>  static void
>  fetch_register (int regno)
>  {
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
>    unsigned int addr, len, offset;
>    int i;
> 
> Index: hpux-thread.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/hpux-thread.c,v
> retrieving revision 1.13
> diff -u -r1.13 hpux-thread.c
> --- hpux-thread.c       14 Nov 2002 20:37:28 -0000      1.13
> +++ hpux-thread.c       31 Jan 2003 22:19:42 -0000
> @@ -285,7 +285,7 @@
>         child_ops.to_fetch_registers (regno);
>        else
>         {
> -         unsigned char buf[MAX_REGISTER_RAW_SIZE];
> +         unsigned char *buf = alloca (max_register_size (current_gdbarch));
>           CORE_ADDR sp;
> 
>           sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
> @@ -347,7 +347,7 @@
>         child_ops.to_store_registers (regno);
>        else
>         {
> -         unsigned char buf[MAX_REGISTER_RAW_SIZE];
> +         unsigned char *buf = alloca (max_register_size (current_gdbarch));
>           CORE_ADDR sp;
> 
>           sp = (CORE_ADDR) tcb_ptr->static_ctx.sp - 160;
> Index: irix4-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/irix4-nat.c,v
> retrieving revision 1.9
> diff -u -r1.9 irix4-nat.c
> --- irix4-nat.c 14 Nov 2002 20:37:28 -0000      1.9
> +++ irix4-nat.c 31 Jan 2003 22:19:42 -0000
> @@ -51,8 +51,8 @@
>  {
>    register int regi;
>    register greg_t *regp = (greg_t *) (gregsetp->gp_regs);
> -  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
> -  {0};
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> 
>    /* FIXME: somewhere, there should be a #define for the meaning
>       of this magic number 32; we should use that. */
> @@ -104,8 +104,8 @@
>  supply_fpregset (fpregset_t *fpregsetp)
>  {
>    register int regi;
> -  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
> -  {0};
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> 
>    for (regi = 0; regi < 32; regi++)
>      supply_register (FP0_REGNUM + regi,
> Index: lynx-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/lynx-nat.c,v
> retrieving revision 1.11
> diff -u -r1.11 lynx-nat.c
> --- lynx-nat.c  14 Nov 2002 20:37:28 -0000      1.11
> +++ lynx-nat.c  31 Jan 2003 22:19:42 -0000
> @@ -282,7 +282,7 @@
>    if (whatregs & WHATREGS_GEN)
>      {
>        struct econtext ec;      /* general regs */
> -      char buf[MAX_REGISTER_RAW_SIZE];
> +      char *buf = alloca (max_register_size (current_gdbarch));
>        int retval;
>        int i;
> 
> @@ -510,29 +510,31 @@
> 
>    ecp = registers_addr (PIDGET (inferior_ptid));
> 
> -  for (regno = reglo; regno <= reghi; regno++)
> -    {
> -      char buf[MAX_REGISTER_RAW_SIZE];
> -      int ptrace_fun = PTRACE_PEEKTHREAD;
> -
> +  {
> +    char *buf = alloca (max_register_size (current_gdbarch));
> +    for (regno = reglo; regno <= reghi; regno++)
> +      {
> +       int ptrace_fun = PTRACE_PEEKTHREAD;
> +
>  #ifdef M68K
> -      ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD;
> +       ptrace_fun = regno == SP_REGNUM ? PTRACE_PEEKUSP : PTRACE_PEEKTHREAD;
>  #endif
> -
> -      for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
> -       {
> -         unsigned int reg;
> -
> -         errno = 0;
> -         reg = ptrace (ptrace_fun, PIDGET (inferior_ptid),
> -                       (PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), 0);
> -         if (errno)
> -           perror_with_name ("ptrace(PTRACE_PEEKUSP)");
> -
> -         *(int *) &buf[i] = reg;
> -       }
> -      supply_register (regno, buf);
> -    }
> +
> +       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
> +         {
> +           unsigned int reg;
> +
> +           errno = 0;
> +           reg = ptrace (ptrace_fun, PIDGET (inferior_ptid),
> +                         (PTRACE_ARG3_TYPE) (ecp + regmap[regno] + i), 0);
> +           if (errno)
> +             perror_with_name ("ptrace(PTRACE_PEEKUSP)");
> +
> +           *(int *) &buf[i] = reg;
> +         }
> +       supply_register (regno, buf);
> +      }
> +  }
>  }
> 
>  /* Store our register values back into the inferior.
> Index: m68klinux-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/m68klinux-nat.c,v
> retrieving revision 1.15
> diff -u -r1.15 m68klinux-nat.c
> --- m68klinux-nat.c     23 Nov 2002 19:45:11 -0000      1.15
> +++ m68klinux-nat.c     31 Jan 2003 22:19:42 -0000
> @@ -135,7 +135,7 @@
>    char mess[128];              /* For messages */
>    register int i;
>    unsigned int offset;         /* Offset of registers within the u area.  */
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
>    int tid;
> 
>    if (CANNOT_FETCH_REGISTER (regno))
> Index: mips-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/mips-nat.c,v
> retrieving revision 1.8
> diff -u -r1.8 mips-nat.c
> --- mips-nat.c  7 Nov 2002 15:31:31 -0000       1.8
> +++ mips-nat.c  31 Jan 2003 22:19:42 -0000
> @@ -62,9 +62,6 @@
>    : regno >= FP0_REGNUM ?      FPR_BASE + (regno - FP0_REGNUM) \
>    : 0)
> 
> -static char zerobuf[MAX_REGISTER_RAW_SIZE] =
> -{0};
> -
>  static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
> 
>  /* Get all registers from the inferior */
> @@ -73,8 +70,10 @@
>  fetch_inferior_registers (int regno)
>  {
>    register unsigned int regaddr;
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
>    register int i;
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> 
>    deprecated_registers_fetched ();
> 
> @@ -174,6 +173,10 @@
>    register unsigned int addr;
>    int bad_reg = -1;
>    register reg_ptr = -reg_addr;        /* Original u.u_ar0 is -reg_addr. */
> +
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> +
> 
>    /* If u.u_ar0 was an absolute address in the core file, relativize it now,
>       so we can use it as an offset into core_reg_sect.  When we're done,
> Index: mipsv4-nat.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/mipsv4-nat.c,v
> retrieving revision 1.7
> diff -u -r1.7 mipsv4-nat.c
> --- mipsv4-nat.c        14 Nov 2002 20:37:28 -0000      1.7
> +++ mipsv4-nat.c        31 Jan 2003 22:19:42 -0000
> @@ -47,8 +47,8 @@
>  {
>    register int regi;
>    register greg_t *regp = &(*gregsetp)[0];
> -  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
> -  {0};
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> 
>    for (regi = 0; regi <= CXT_RA; regi++)
>      supply_register (regi, (char *) (regp + regi));
> @@ -102,8 +102,8 @@
>  supply_fpregset (fpregset_t *fpregsetp)
>  {
>    register int regi;
> -  static char zerobuf[MAX_REGISTER_RAW_SIZE] =
> -  {0};
> +  char *zerobuf = alloca (max_register_size (current_gdbarch));
> +  memset (zerobuf, 0, max_register_size (current_gdbarch));
> 
>    for (regi = 0; regi < 32; regi++)
>      supply_register (FP0_REGNUM + regi,
> Index: monitor.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/monitor.c,v
> retrieving revision 1.36
> diff -u -r1.36 monitor.c
> --- monitor.c   12 Nov 2002 21:43:55 -0000      1.36
> +++ monitor.c   31 Jan 2003 22:19:42 -0000
> @@ -894,7 +894,7 @@
>  monitor_supply_register (int regno, char *valstr)
>  {
>    ULONGEST val;
> -  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
> +  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
>    char *p;
> 
>    val = 0;
> Index: remote-e7000.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/remote-e7000.c,v
> retrieving revision 1.31
> diff -u -r1.31 remote-e7000.c
> --- remote-e7000.c      29 Nov 2002 19:40:30 -0000      1.31
> +++ remote-e7000.c      31 Jan 2003 22:19:42 -0000
> @@ -785,7 +785,7 @@
>  fetch_regs_from_dump (int (*nextchar) (), char *want)
>  {
>    int regno;
> -  char buf[MAX_REGISTER_RAW_SIZE];
> +  char *buf = alloca (max_register_size (current_gdbarch));
> 
>    int thischar = nextchar ();
> 
> Index: remote-mips.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/remote-mips.c,v
> retrieving revision 1.31
> diff -u -r1.31 remote-mips.c
> --- remote-mips.c       18 Jan 2003 15:55:52 -0000      1.31
> +++ remote-mips.c       31 Jan 2003 22:19:43 -0000
> @@ -1791,7 +1791,7 @@
>                     &rpc, &rfp, &rsp, flags);
>    if (nfields >= 3)
>      {
> -      char buf[MAX_REGISTER_RAW_SIZE];
> +      char *buf = alloca (max_register_size (current_gdbarch));
> 
>        store_unsigned_integer (buf, REGISTER_RAW_SIZE (PC_REGNUM), rpc);
>        supply_register (PC_REGNUM, buf);
> @@ -1972,7 +1972,7 @@
>      }
> 
>    {
> -    char buf[MAX_REGISTER_RAW_SIZE];
> +    char *buf = alloca (max_register_size (current_gdbarch));
> 
>      /* We got the number the register holds, but gdb expects to see a
>         value in the target byte ordering.  */
> Index: remote-sim.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/remote-sim.c,v
> retrieving revision 1.26
> diff -u -r1.26 remote-sim.c
> --- remote-sim.c        12 Nov 2002 21:43:55 -0000      1.26
> +++ remote-sim.c        31 Jan 2003 22:19:43 -0000
> @@ -359,7 +359,7 @@
>      }
>    else if (REGISTER_SIM_REGNO (regno) >= 0)
>      {
> -      char tmp[MAX_REGISTER_RAW_SIZE];
> +      char *tmp = alloca (max_register_size (current_gdbarch));
>        int nr_bytes;
>        deprecated_read_register_gen (regno, tmp);
>        nr_bytes = sim_store_register (gdbsim_desc,
> Index: rom68k-rom.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/rom68k-rom.c,v
> retrieving revision 1.9
> diff -u -r1.9 rom68k-rom.c
> --- rom68k-rom.c        23 Nov 2002 19:45:11 -0000      1.9
> +++ rom68k-rom.c        31 Jan 2003 22:19:43 -0000
> @@ -88,7 +88,7 @@
>  rom68k_supply_one_register (int regno, unsigned char *hex)
>  {
>    ULONGEST value;
> -  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
> +  unsigned char *regbuf = alloca (max_register_size (current_gdbarch));
> 
>    value = 0;
>    while (*hex != '\0')
> Index: sh-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/sh-tdep.c,v
> retrieving revision 1.94
> diff -u -r1.94 sh-tdep.c
> --- sh-tdep.c   21 Jan 2003 19:43:47 -0000      1.94
> +++ sh-tdep.c   31 Jan 2003 22:19:45 -0000
> @@ -4009,7 +4009,7 @@
>  static void
>  sh_do_register (int regnum)
>  {
> -  char raw_buffer[MAX_REGISTER_RAW_SIZE];
> +  char *raw_buffer = alloca (max_register_size (current_gdbarch));
> 
>    fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
>    print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), gdb_stdout);
> Index: thread-db.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/thread-db.c,v
> retrieving revision 1.28
> diff -u -r1.28 thread-db.c
> --- thread-db.c 14 Jan 2003 00:49:04 -0000      1.28
> +++ thread-db.c 31 Jan 2003 22:19:45 -0000
> @@ -941,7 +941,7 @@
> 
>    if (regno != -1)
>      {
> -      char raw[MAX_REGISTER_RAW_SIZE];
> +      char *raw = alloca (max_register_size (current_gdbarch));
> 
>        deprecated_read_register_gen (regno, raw);
>        thread_db_fetch_registers (-1);


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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-01-31 22:58 [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE] Andrew Cagney
  2003-01-31 23:20 ` Andreas Schwab
  2003-02-01  1:36 ` Michael Snyder
@ 2003-02-01  6:13 ` Joel Brobecker
  2003-02-01  6:40   ` Andrew Cagney
  2003-02-02  5:36 ` Andrew Cagney
  3 siblings, 1 reply; 9+ messages in thread
From: Joel Brobecker @ 2003-02-01  6:13 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

> Since MAX_REGISTER_RAW_SIZE is implemented using a function the declaration:
> 
> 	  char buf[MAX_REGISTER_RAW_SIZE];
> 
> is illegal.  (GCC does allow it which is why no one notices :-/).
> 
> The attached patch updates all obvious (as in found by a grep) 
> occurances of this and changes them to:
> 
> 	char *buf = alloca (max_register_raw_size (current_gdbarch));

I have a simple (stupid?) question: Generaly speaking, is there a
prefered form between the following two?

     max_register_raw_size (current_gdbarch)

or

     MAX_REGISTER_RAW_SIZE
     
These two forms are exactly equivalent, but in most occurences I've seen
in the code, we used the macro... But maybe you used the non-macro form
to show that we do an alloca because the size of the buffer is not known
at compile-time?

-- 
Joel


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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-02-01  1:36 ` Michael Snyder
@ 2003-02-01  6:17   ` Andrew Cagney
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Cagney @ 2003-02-01  6:17 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

> 
> I'm not sure, but I think you need to go even further:
> 
> 	char *buf;
> 	buf = alloca (...);
> 
> Some compilers will not allow a function call in an auto initializer.

That isn't a problem.  GDB's been using alloca() in auto declarations 
for ages.

Andrew



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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-02-01  6:13 ` Joel Brobecker
@ 2003-02-01  6:40   ` Andrew Cagney
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Cagney @ 2003-02-01  6:40 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches


> I have a simple (stupid?) question: Generaly speaking, is there a
> prefered form between the following two?
> 
>      max_register_raw_size (current_gdbarch)
> 
> or
> 
>      MAX_REGISTER_RAW_SIZE
>      
> These two forms are exactly equivalent, but in most occurences I've seen
> in the code, we used the macro... But maybe you used the non-macro form
> to show that we do an alloca because the size of the buffer is not known
> at compile-time?

Old == MAX_REGISTER_RAW_SIZE, MAX_REGISTER_VIRTUAL_SIZE.
New == max_register_size (current_gdbarch)

The old macro's will eventually go away.

Andrew



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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
  2003-01-31 22:58 [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE] Andrew Cagney
                   ` (2 preceding siblings ...)
  2003-02-01  6:13 ` Joel Brobecker
@ 2003-02-02  5:36 ` Andrew Cagney
  3 siblings, 0 replies; 9+ messages in thread
From: Andrew Cagney @ 2003-02-02  5:36 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

> 2003-01-31  Andrew Cagney  <ac131313@redhat.com>
> 
> 	* mips-nat.c (zerobuf): Delete.
> 	(fetch_inferior_registers): Alloc local zerobuf.
> 	(fetch_core_registers): Alloc local zerobuf.
> 	* d10v-tdep.c (show_regs): Don't allocate a dynamic array using
> 	MAX_REGISTER_RAW_SIZE or MAX_REGISTER_VIRTUAL_SIZE.
> 	* thread-db.c (thread_db_store_registers): Ditto.
> 	* sh-tdep.c (sh_do_register): Ditto.
> 	* rom68k-rom.c (rom68k_supply_one_register): Ditto.
> 	* remote-sim.c (gdbsim_store_register): Ditto.
> 	* remote-mips.c (mips_wait, mips_fetch_registers): Ditto.
> 	* remote-e7000.c (fetch_regs_from_dump): Ditto.
> 	* monitor.c (monitor_supply_register): Ditto.
> 	* mipsv4-nat.c (supply_gregset, supply_fpregset): Ditto.
> 	* mips-nat.c (fetch_inferior_registers): Ditto.
> 	* m68klinux-nat.c (fetch_register): Ditto.
> 	* lynx-nat.c (fetch_inferior_registers): Ditto.
> 	(fetch_inferior_registers): Ditto.
> 	* irix4-nat.c (supply_gregset, supply_fpregset): Ditto.
> 	* hpux-thread.c (hpux_thread_fetch_registers): Ditto.
> 	(hpux_thread_store_registers): Ditto.
> 	* hppah-nat.c (fetch_register): Ditto.
> 	* hppab-nat.c (fetch_register): Ditto.
> 	* hppa-tdep.c (pa_register_look_aside): Ditto.
> 	(pa_print_fp_reg, pa_strcat_fp_reg): Ditto.
> 	* dve3900-rom.c (fetch_bitmapped_register): Ditto.
> 
I've checked this in.

Andrew



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

* Re: [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]
@ 2003-02-01 17:33 Michael Elizabeth Chastain
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Elizabeth Chastain @ 2003-02-01 17:33 UTC (permalink / raw)
  To: ac131313, msnyder; +Cc: gdb-patches

Michael Snyder writes:

> Some compilers will not allow a function call in an auto initializer.

I think you are thinking of

  static int i = foo ();  /* not legal in any C standard that I know */

Rather than

  auto int i = foo ();  /* been legal since K&R C */

Static and global initializers have to be resolved by link time so they
have to be constants or nearly constant (address expressions like
'&array' or '&function).  Auto initializers can be any expression
including function calls.  It's been that way since K&R C.

It would take a really deficient compiler to screw that up.  I
acknowledge that there is no limit to how messed up a vendor C compiler
can actually be.  So I took a quick look at utils.c (at random) to see
if gdb uses this construct anywhere else.  And it does:

  /* gdb 5.2.1 utils.c */
  struct cleanup *
  make_cleanup_close (int fd)
  {
    int *saved_fd = xmalloc (sizeof (fd));
    ...
  }

  void
  quit (void)
  {
    struct serial *gdb_stdout_serial = serial_fdopen (1);
    ...
  }

So we are safe on this point.

Michael C


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

end of thread, other threads:[~2003-02-02  5:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-31 22:58 [patch/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE] Andrew Cagney
2003-01-31 23:20 ` Andreas Schwab
2003-01-31 23:26   ` Andrew Cagney
2003-02-01  1:36 ` Michael Snyder
2003-02-01  6:17   ` Andrew Cagney
2003-02-01  6:13 ` Joel Brobecker
2003-02-01  6:40   ` Andrew Cagney
2003-02-02  5:36 ` Andrew Cagney
2003-02-01 17:33 Michael Elizabeth Chastain

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