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/rfc] Eliminate char buf[MAX_REGISTER_RAW_SIZE]


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


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