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]

Re: gdb under solaris7


On 10-Nov-2000, Andrew Cagney wrote:

>Assuming that bfd_get_section_name() returns a ``const char *'' (I'm
>very much relying on memory here)

Ah, right you are.

>I'm just suggesting is that the proposed changes be re-examined to
>determine if the casts being added/tweeked are even needed.

Okay, here's an alternative to the "scan = (char *) ref" patch that
removes 8 typecasts.  I haven't tested it.

Nick

Index: gdb/remote.c
===================================================================
diff -up gdb/remote.c gdb/remote.c
--- gdb/remote.c	Fri Nov 10 10:54:28 2000
+++ gdb/remote.c	Fri Nov 10 10:53:28 2000
@@ -924,7 +924,10 @@ remote_thread_alive (int tid)
 #define OPAQUETHREADBYTES 8
 
 /* a 64 bit opaque identifier */
-typedef unsigned char threadref[OPAQUETHREADBYTES];
+struct threadref
+  {
+    unsigned char bytes[OPAQUETHREADBYTES];
+  };
 
 /* WARNING: This threadref data structure comes from the remote O.S., libstub
    protocol encoding, and remote.c. it is not particularly changable */
@@ -940,7 +943,7 @@ typedef int gdb_threadref;	/* internal G
 
 struct gdb_ext_thread_info
   {
-    threadref threadid;		/* External form of thread reference */
+    struct threadref threadid;	/* External form of thread reference */
     int active;			/* Has state interesting to GDB? , regs, stack */
     char display[256];		/* Brief state display, name, blocked/syspended */
     char shortname[32];		/* To be used to name threads */
@@ -977,27 +980,27 @@ static char *unpack_int (char *buf, int 
 
 static char *unpack_string (char *src, char *dest, int length);
 
-static char *pack_threadid (char *pkt, threadref * id);
+static char *pack_threadid (char *pkt, struct threadref * id);
 
-static char *unpack_threadid (char *inbuf, threadref * id);
+static char *unpack_threadid (char *inbuf, struct threadref * id);
 
-void int_to_threadref (threadref * id, int value);
+void int_to_threadref (struct threadref * id, int value);
 
-static int threadref_to_int (threadref * ref);
+static int threadref_to_int (struct threadref * ref);
 
-static void copy_threadref (threadref * dest, threadref * src);
+static void copy_threadref (struct threadref * dest, struct threadref * src);
 
-static int threadmatch (threadref * dest, threadref * src);
+static int threadmatch (struct threadref * dest, struct threadref * src);
 
-static char *pack_threadinfo_request (char *pkt, int mode, threadref * id);
+static char *pack_threadinfo_request (char *pkt, int mode, struct threadref * id);
 
 static int remote_unpack_thread_info_response (char *pkt,
-					       threadref * expectedref,
+					       struct threadref * expectedref,
 					       struct gdb_ext_thread_info
 					       *info);
 
 
-static int remote_get_threadinfo (threadref * threadid, int fieldset,	/*TAG mask */
+static int remote_get_threadinfo (struct threadref * threadid, int fieldset,	/*TAG mask */
 				  struct gdb_ext_thread_info *info);
 
 static int adapt_remote_get_threadinfo (gdb_threadref * ref,
@@ -1006,25 +1009,25 @@ static int adapt_remote_get_threadinfo (
 
 static char *pack_threadlist_request (char *pkt, int startflag,
 				      int threadcount,
-				      threadref * nextthread);
+				      struct threadref * nextthread);
 
 static int parse_threadlist_response (char *pkt,
 				      int result_limit,
-				      threadref * original_echo,
-				      threadref * resultlist, int *doneflag);
+				      struct threadref * original_echo,
+				      struct threadref * resultlist, int *doneflag);
 
 static int remote_get_threadlist (int startflag,
-				  threadref * nextthread,
+				  struct threadref * nextthread,
 				  int result_limit,
 				  int *done,
-				  int *result_count, threadref * threadlist);
+				  int *result_count, struct threadref * threadlist);
 
-typedef int (*rmt_thread_action) (threadref * ref, void *context);
+typedef int (*rmt_thread_action) (struct threadref * ref, void *context);
 
 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
 				       void *context, int looplimit);
 
-static int remote_newthread_step (threadref * ref, void *context);
+static int remote_newthread_step (struct threadref * ref, void *context);
 
 /* encode 64 bits in 16 chars of hex */
 
@@ -1177,12 +1180,12 @@ unpack_string (char *src, char *dest, in
 }
 
 static char *
-pack_threadid (char *pkt, threadref *id)
+pack_threadid (char *pkt, struct threadref *id)
 {
   char *limit;
   unsigned char *altid;
 
-  altid = (unsigned char *) id;
+  altid = id->bytes;
   limit = pkt + BUF_THREAD_ID_SIZE;
   while (pkt < limit)
     pkt = pack_hex_byte (pkt, *altid++);
@@ -1191,13 +1194,13 @@ pack_threadid (char *pkt, threadref *id)
 
 
 static char *
-unpack_threadid (char *inbuf, threadref *id)
+unpack_threadid (char *inbuf, struct threadref *id)
 {
-  char *altref;
+  unsigned char *altref;
   char *limit = inbuf + BUF_THREAD_ID_SIZE;
   int x, y;
 
-  altref = (char *) id;
+  altref = id->bytes;
 
   while (inbuf < limit)
     {
@@ -1214,11 +1217,11 @@ unpack_threadid (char *inbuf, threadref 
    function.  */
 
 void
-int_to_threadref (threadref *id, int value)
+int_to_threadref (struct threadref *id, int value)
 {
   unsigned char *scan;
 
-  scan = (unsigned char *) id;
+  scan = id->bytes;
   {
     int i = 4;
     while (i--)
@@ -1231,12 +1234,12 @@ int_to_threadref (threadref *id, int val
 }
 
 static int
-threadref_to_int (threadref *ref)
+threadref_to_int (struct threadref *ref)
 {
   int i, value = 0;
   unsigned char *scan;
 
-  scan = (char *) ref;
+  scan = ref->bytes;
   scan += 4;
   i = 4;
   while (i-- > 0)
@@ -1245,27 +1248,27 @@ threadref_to_int (threadref *ref)
 }
 
 static void
-copy_threadref (threadref *dest, threadref *src)
+copy_threadref (struct threadref *dest, struct threadref *src)
 {
   int i;
   unsigned char *csrc, *cdest;
 
-  csrc = (unsigned char *) src;
-  cdest = (unsigned char *) dest;
+  csrc = src->bytes;
+  cdest = dest->bytes;
   i = 8;
   while (i--)
     *cdest++ = *csrc++;
 }
 
 static int
-threadmatch (threadref *dest, threadref *src)
+threadmatch (struct threadref *dest, struct threadref *src)
 {
   /* things are broken right now, so just assume we got a match */
 #if 0
   unsigned char *srcp, *destp;
   int i, result;
-  srcp = (char *) src;
-  destp = (char *) dest;
+  srcp = src->bytes;
+  destp = dest->bytes;
 
   result = 1;
   while (i-- > 0)
@@ -1286,7 +1289,7 @@ threadmatch (threadref *dest, threadref 
 /* Encoding:  'Q':8,'P':8,mask:32,threadid:64 */
 
 static char *
-pack_threadinfo_request (char *pkt, int mode, threadref *id)
+pack_threadinfo_request (char *pkt, int mode, struct threadref *id)
 {
   *pkt++ = 'q';			/* Info Query */
   *pkt++ = 'P';			/* process or thread info */
@@ -1309,11 +1312,10 @@ pack_threadinfo_request (char *pkt, int 
 				   the process */
 
 static int
-remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
+remote_unpack_thread_info_response (char *pkt, struct threadref *expectedref,
 				    struct gdb_ext_thread_info *info)
 {
-  int mask, length;
-  unsigned int tag;
+  int mask, length, tag;
   threadref ref;
   char *limit = pkt + PBUFSIZ;	/* plausable parsing limit */
   int retval = 1;
@@ -1341,7 +1343,7 @@ remote_unpack_thread_info_response (char
 
   while ((pkt < limit) && mask && *pkt)		/* packets are terminated with nulls */
     {
-      pkt = unpack_int (pkt, &tag);	/* tag */
+      pkt = unpack_int (pkt, &tag);		/* tag */
       pkt = unpack_byte (pkt, &length);		/* length */
       if (!(tag & mask))	/* tags out of synch with mask */
 	{
@@ -1399,7 +1401,7 @@ remote_unpack_thread_info_response (char
 }
 
 static int
-remote_get_threadinfo (threadref *threadid, int fieldset,	/* TAG mask */
+remote_get_threadinfo (struct threadref *threadid, int fieldset,	/* TAG mask */
 		       struct gdb_ext_thread_info *info)
 {
   int result;
@@ -1420,7 +1422,7 @@ static int
 adapt_remote_get_threadinfo (gdb_threadref *ref, int selection,
 			     struct gdb_ext_thread_info *info)
 {
-  threadref lclref;
+  struct threadref lclref;
 
   int_to_threadref (&lclref, *ref);
   return remote_get_threadinfo (&lclref, selection, info);
@@ -1430,7 +1432,7 @@ adapt_remote_get_threadinfo (gdb_threadr
 
 static char *
 pack_threadlist_request (char *pkt, int startflag, int threadcount,
-			 threadref *nextthread)
+			 struct threadref *nextthread)
 {
   *pkt++ = 'q';			/* info query packet */
   *pkt++ = 'L';			/* Process LIST or threadLIST request */
@@ -1445,8 +1447,8 @@ pack_threadlist_request (char *pkt, int 
 
 static int
 parse_threadlist_response (char *pkt, int result_limit,
-			   threadref *original_echo, threadref *resultlist,
-			   int *doneflag)
+			   struct threadref *original_echo,
+			   struct threadref *resultlist, int *doneflag)
 {
   char *limit;
   int count, resultcount, done;
@@ -1470,8 +1472,9 @@ parse_threadlist_response (char *pkt, in
 }
 
 static int
-remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
-		       int *done, int *result_count, threadref *threadlist)
+remote_get_threadlist (int startflag, struct threadref *nextthread,
+		       int result_limit, int *done, int *result_count,
+		       struct threadref *threadlist)
 {
   static threadref echo_nextthread;
   char *threadlist_packet = alloca (PBUFSIZ);
@@ -1543,8 +1546,8 @@ remote_threadlist_iterator (rmt_thread_a
   int startflag = 1;
   int result = 1;
   int loopcount = 0;
-  static threadref nextthread;
-  static threadref resultthreadlist[MAXTHREADLISTRESULTS];
+  static struct threadref nextthread;
+  static struct threadref resultthreadlist[MAXTHREADLISTRESULTS];
 
   done = 0;
   while (!done)
@@ -1575,7 +1578,7 @@ remote_threadlist_iterator (rmt_thread_a
 }
 
 static int
-remote_newthread_step (threadref *ref, void *context)
+remote_newthread_step (struct threadref *ref, void *context)
 {
   int pid;
 
@@ -1674,7 +1677,7 @@ remote_threads_extra_info (struct thread
 {
   int result;
   int set;
-  threadref id;
+  struct threadref id;
   struct gdb_ext_thread_info threadinfo;
   static char display_buf[100];	/* arbitrary... */
   char *bufp = alloca (PBUFSIZ);
@@ -1890,7 +1893,7 @@ remote_cisco_section_offsets (bfd_vma te
        sect != 0;
        sect = sect->next)
     {
-      p = (unsigned char *) bfd_get_section_name (abfd, sect);
+      const unsigned char *p = bfd_get_section_name (abfd, sect);
       len = strlen (p);
       if (strcmp (p + len - 4, "data") == 0)	/* ends in "data" */
 	if (data_base == 0 ||
@@ -2604,7 +2607,7 @@ remote_wait (int pid, struct target_wait
 	  {
 	    int i;
 	    long regno;
-	    char regs[MAX_REGISTER_RAW_SIZE];
+	    char *regs = alloca(MAX_REGISTER_RAW_SIZE);
 
 	    /* Expedited reply, containing Signal, {regno, reg} repeat */
 	    /*  format is:  'Tssn...:r...;n...:r...;n...:r...;#cc', where
@@ -2825,7 +2828,7 @@ remote_async_wait (int pid, struct targe
 	  {
 	    int i;
 	    long regno;
-	    char regs[MAX_REGISTER_RAW_SIZE];
+	    char *regs = alloca(MAX_REGISTER_RAW_SIZE);
 
 	    /* Expedited reply, containing Signal, {regno, reg} repeat */
 	    /*  format is:  'Tssn...:r...;n...:r...;n...:r...;#cc', where
@@ -3025,7 +3028,7 @@ remote_fetch_registers (int regno)
   char *buf = alloca (PBUFSIZ);
   int i;
   char *p;
-  char regs[REGISTER_BYTES];
+  char *regs = alloca(REGISTER_BYTES);
 
   set_thread (inferior_pid, 1);
 
@@ -4784,11 +4787,11 @@ static void threadalive_test (char *cmd,
 
 static void threadlist_test_cmd (char *cmd, int tty);
 
-int get_and_display_threadinfo (threadref * ref);
+int get_and_display_threadinfo (struct threadref * ref);
 
 static void threadinfo_test_cmd (char *cmd, int tty);
 
-static int thread_display_step (threadref * ref, void *context);
+static int thread_display_step (struct threadref * ref, void *context);
 
 static void threadlist_update_test_cmd (char *cmd, int tty);
 
@@ -4817,10 +4820,10 @@ threadalive_test (char *cmd, int tty)
     printf_filtered ("FAIL: Thread alive test\n");
 }
 
-void output_threadid (char *title, threadref * ref);
+void output_threadid (char *title, struct threadref * ref);
 
 void
-output_threadid (char *title, threadref *ref)
+output_threadid (char *title, struct threadref *ref)
 {
   char hexid[20];
 
@@ -4833,9 +4836,9 @@ static void
 threadlist_test_cmd (char *cmd, int tty)
 {
   int startflag = 1;
-  threadref nextthread;
+  struct threadref nextthread;
   int done, result_count;
-  threadref threadlist[3];
+  struct threadref threadlist[3];
 
   printf_filtered ("Remote Threadlist test\n");
   if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
@@ -4843,8 +4846,8 @@ threadlist_test_cmd (char *cmd, int tty)
     printf_filtered ("FAIL: threadlist test\n");
   else
     {
-      threadref *scan = threadlist;
-      threadref *limit = scan + result_count;
+      struct threadref *scan = threadlist;
+      struct threadref *limit = scan + result_count;
 
       while (scan < limit)
 	output_threadid (" thread ", scan++);
@@ -4861,7 +4864,7 @@ display_thread_info (struct gdb_ext_thre
 }
 
 int
-get_and_display_threadinfo (threadref *ref)
+get_and_display_threadinfo (struct threadref *ref)
 {
   int result;
   int set;
@@ -4878,7 +4881,7 @@ static void
 threadinfo_test_cmd (char *cmd, int tty)
 {
   int athread = SAMPLE_THREAD;
-  threadref thread;
+  struct threadref thread;
   int set;
 
   int_to_threadref (&thread, athread);
@@ -4888,7 +4891,7 @@ threadinfo_test_cmd (char *cmd, int tty)
 }
 
 static int
-thread_display_step (threadref *ref, void *context)
+thread_display_step (struct threadref *ref, void *context)
 {
   /* output_threadid(" threadstep ",ref); *//* simple test */
   return get_and_display_threadinfo (ref);

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