This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Remote.c uses alloca (PBUFSIZ).
- To: gdb-patches@sourceware.cygnus.com
- Subject: Remote.c uses alloca (PBUFSIZ).
- From: Andrew Cagney <ac131313@cygnus.com>
- Date: Wed, 23 Jun 1999 15:39:21 +1000
- DJ-Gateway: from newsgroup cygnus.patches.gdb
- Newsgroups: cygnus.patches.gdb
- Organization: Cygnus Solutions
FYI,
I've made the attached change to remote.c. The change is required
because, in a multi-arch configuration, PBUFSIZ is not constant. I know
that there are other cases of this in the code and they will be fixed as
they are found.
This problem occures when compiling a multi-arch target with a non GCC
compiler.
If your remote target suddenly breaks then you've a good idea who to
blame.
enjoy,
Andrew
Wed Jun 23 15:30:46 1999 Andrew Cagney <cagney@b1.cygnus.com>
* remote.c (set_thread, remote_get_threadinfo,
remote_threads_info, remote_current_thread,
remote_get_threadlist,
extended_remote_restart, get_offsets, remote_open_1,
remote_detach, remote_resume, remote_wait,
remote_fetch_registers,
remote_store_registers, check_binary_download,
remote_write_bytes,
remote_read_bytes, remote_search, putpkt_binary, putpkt_binary,
read_frame, compare_sections_command, remote_query,
packet_command, remote_info_process): Use alloca to create space
for arrays of size PBUFSIZ.
Index: remote.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote.c,v
retrieving revision 1.195
diff -c -r1.195 remote.c
*** remote.c 1999/06/13 01:37:01 1.195
--- remote.c 1999/06/23 05:27:21
***************
*** 485,491 ****
int th;
int gen;
{
! char buf[PBUFSIZ];
int state = gen ? general_thread : continue_thread;
if (state == th)
--- 485,491 ----
int th;
int gen;
{
! char *buf = alloca (PBUFSIZ);
int state = gen ? general_thread : continue_thread;
if (state == th)
***************
*** 1059,1065 ****
struct gdb_ext_thread_info *info;
{
int result;
! char threadinfo_pkt[PBUFSIZ];
pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
putpkt (threadinfo_pkt);
--- 1059,1065 ----
struct gdb_ext_thread_info *info;
{
int result;
! char *threadinfo_pkt = alloca (PBUFSIZ);
pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
putpkt (threadinfo_pkt);
***************
*** 1146,1153 ****
{
static threadref echo_nextthread;
! char threadlist_packet[PBUFSIZ];
! char t_response[PBUFSIZ];
int result = 1;
/* Trancate result limit to be smaller than the packet size */
--- 1146,1153 ----
{
static threadref echo_nextthread;
! char *threadlist_packet = alloca (PBUFSIZ);
! char *t_response = alloca (PBUFSIZ);
int result = 1;
/* Trancate result limit to be smaller than the packet size */
***************
*** 1267,1273 ****
remote_current_thread (oldpid)
int oldpid;
{
! char buf[PBUFSIZ];
putpkt ("qC");
getpkt (buf, 0);
--- 1267,1273 ----
remote_current_thread (oldpid)
int oldpid;
{
! char *buf = alloca (PBUFSIZ);
putpkt ("qC");
getpkt (buf, 0);
***************
*** 1291,1297 ****
static void
remote_threads_info (void)
{
! char buf[PBUFSIZ], *bufp;
int tid;
if (remote_desc == 0) /* paranoia */
--- 1291,1298 ----
static void
remote_threads_info (void)
{
! char *buf = alloca (PBUFSIZ);
! char *bufp;
int tid;
if (remote_desc == 0) /* paranoia */
***************
*** 1323,1329 ****
static void
extended_remote_restart ()
{
! char buf[PBUFSIZ];
/* Send the restart command; for reasons I don't understand the
remote side really expects a number after the "R". */
--- 1324,1330 ----
static void
extended_remote_restart ()
{
! char *buf = alloca (PBUFSIZ);
/* Send the restart command; for reasons I don't understand the
remote side really expects a number after the "R". */
***************
*** 1354,1360 ****
static void
get_offsets ()
{
! char buf[PBUFSIZ], *ptr;
int lose;
CORE_ADDR text_addr, data_addr, bss_addr;
struct section_offsets *offs;
--- 1355,1362 ----
static void
get_offsets ()
{
! char *buf = alloca (PBUFSIZ);
! char *ptr;
int lose;
CORE_ADDR text_addr, data_addr, bss_addr;
struct section_offsets *offs;
***************
*** 1414,1420 ****
if (symfile_objfile == NULL)
return;
! offs = (struct section_offsets *) alloca (sizeof (struct section_offsets)
+ symfile_objfile->num_sections
* sizeof (offs->offsets));
memcpy (offs, symfile_objfile->section_offsets,
--- 1416,1422 ----
if (symfile_objfile == NULL)
return;
! offs = alloca (sizeof (struct section_offsets)
+ symfile_objfile->num_sections
* sizeof (offs->offsets));
memcpy (offs, symfile_objfile->section_offsets,
***************
*** 1697,1703 ****
if (extended_p)
{
/* tell the remote that we're using the extended protocol. */
! char buf[PBUFSIZ];
putpkt ("!");
getpkt (buf, 0);
}
--- 1699,1705 ----
if (extended_p)
{
/* tell the remote that we're using the extended protocol. */
! char *buf = alloca (PBUFSIZ);
putpkt ("!");
getpkt (buf, 0);
}
***************
*** 1713,1719 ****
char *args;
int from_tty;
{
! char buf[PBUFSIZ];
if (args)
error ("Argument given to \"detach\" when remotely debugging.");
--- 1715,1721 ----
char *args;
int from_tty;
{
! char *buf = alloca (PBUFSIZ);
if (args)
error ("Argument given to \"detach\" when remotely debugging.");
***************
*** 1766,1772 ****
int pid, step;
enum target_signal siggnal;
{
! char buf[PBUFSIZ];
if (pid == -1)
set_thread (0, 0); /* run any thread */
--- 1768,1774 ----
int pid, step;
enum target_signal siggnal;
{
! char *buf = alloca (PBUFSIZ);
if (pid == -1)
set_thread (0, 0); /* run any thread */
***************
*** 1896,1902 ****
int pid;
struct target_waitstatus *status;
{
! unsigned char buf[PBUFSIZ];
int thread_num = -1;
status->kind = TARGET_WAITKIND_EXITED;
--- 1898,1904 ----
int pid;
struct target_waitstatus *status;
{
! unsigned char *buf = alloca (PBUFSIZ);
int thread_num = -1;
status->kind = TARGET_WAITKIND_EXITED;
***************
*** 2119,2125 ****
remote_fetch_registers (regno)
int regno;
{
! char buf[PBUFSIZ];
int i;
char *p;
char regs[REGISTER_BYTES];
--- 2121,2127 ----
remote_fetch_registers (regno)
int regno;
{
! char *buf = alloca (PBUFSIZ);
int i;
char *p;
char regs[REGISTER_BYTES];
***************
*** 2207,2213 ****
remote_store_registers (regno)
int regno;
{
! char buf[PBUFSIZ];
int i;
char *p;
--- 2209,2215 ----
remote_store_registers (regno)
int regno;
{
! char *buf = alloca (PBUFSIZ);
int i;
char *p;
***************
*** 2360,2366 ****
{
if (remote_binary_download && !remote_binary_checked)
{
! char buf[PBUFSIZ], *p;
remote_binary_checked = 1;
p = buf;
--- 2362,2369 ----
{
if (remote_binary_download && !remote_binary_checked)
{
! char *buf = alloca (PBUFSIZ);
! char *p;
remote_binary_checked = 1;
p = buf;
***************
*** 2403,2408 ****
--- 2406,2412 ----
char *myaddr;
int len;
{
+ unsigned char *buf = alloca (PBUFSIZ);
int max_buf_size; /* Max size of packet output buffer */
int origlen;
***************
*** 2421,2427 ****
origlen = len;
while (len > 0)
{
- unsigned char buf[PBUFSIZ];
unsigned char *p, *plen;
int todo;
int i;
--- 2425,2430 ----
***************
*** 2534,2539 ****
--- 2537,2543 ----
char *myaddr;
int len;
{
+ char *buf = alloca (PBUFSIZ);
int max_buf_size; /* Max size of packet output buffer */
int origlen;
***************
*** 2546,2552 ****
origlen = len;
while (len > 0)
{
- char buf[PBUFSIZ];
char *p;
int todo;
int i;
--- 2550,2555 ----
***************
*** 2647,2653 ****
long mask_long, data_long;
long data_found_long;
CORE_ADDR addr_we_found;
! char buf[PBUFSIZ];
long returned_long[2];
char *p;
--- 2650,2656 ----
long mask_long, data_long;
long data_found_long;
CORE_ADDR addr_we_found;
! char *buf = alloca (PBUFSIZ);
long returned_long[2];
char *p;
***************
*** 2779,2785 ****
{
int i;
unsigned char csum = 0;
! char buf2[PBUFSIZ];
int ch;
int tcount = 0;
char *p;
--- 2782,2790 ----
{
int i;
unsigned char csum = 0;
! char *buf2 = alloca (PBUFSIZ);
! char *junkbuf = alloca (PBUFSIZ);
!
int ch;
int tcount = 0;
char *p;
***************
*** 2850,2857 ****
break; /* Retransmit buffer */
case '$':
{
- char junkbuf[PBUFSIZ];
-
/* It's probably an old response, and we're out of sync.
Just gobble up the packet and ignore it. */
getpkt (junkbuf, 0);
--- 2855,2860 ----
***************
*** 2956,2962 ****
{
if (remote_cisco_mode) /* variant run-length-encoding */
{
! char tmp_buf[PBUFSIZ];
remote_cisco_expand (buf, tmp_buf);
strcpy (buf, tmp_buf);
--- 2959,2965 ----
{
if (remote_cisco_mode) /* variant run-length-encoding */
{
! char *tmp_buf = alloca (PBUFSIZ);
remote_cisco_expand (buf, tmp_buf);
strcpy (buf, tmp_buf);
***************
*** 3329,3335 ****
unsigned long host_crc, target_crc;
extern bfd *exec_bfd;
struct cleanup *old_chain;
! char *tmp, *sectdata, *sectname, buf[PBUFSIZ];
bfd_size_type size;
bfd_vma lma;
int matched = 0;
--- 3332,3341 ----
unsigned long host_crc, target_crc;
extern bfd *exec_bfd;
struct cleanup *old_chain;
! char *tmp;
! char *sectdata;
! char *sectname;
! char *buf = alloca (PBUFSIZ);
bfd_size_type size;
bfd_vma lma;
int matched = 0;
***************
*** 3403,3409 ****
int *bufsiz;
{
int i;
! char buf2[PBUFSIZ];
char *p2 = &buf2[0];
char *p = buf;
--- 3409,3415 ----
int *bufsiz;
{
int i;
! char *buf2 = alloca (PBUFSIZ);
char *p2 = &buf2[0];
char *p = buf;
***************
*** 3470,3476 ****
char *args;
int from_tty;
{
! char buf[PBUFSIZ];
if (! remote_desc)
error ("command can only be used with remote target");
--- 3476,3482 ----
char *args;
int from_tty;
{
! char *buf = alloca (PBUFSIZ);
if (! remote_desc)
error ("command can only be used with remote target");
***************
*** 3726,3732 ****
char *args;
int from_tty;
{
! char buf[PBUFSIZ];
if (remote_desc == 0)
error ("Command can only be used when connected to the remote target.");
--- 3732,3738 ----
char *args;
int from_tty;
{
! char *buf = alloca (PBUFSIZ);
if (remote_desc == 0)
error ("Command can only be used when connected to the remote target.");