This is the mail archive of the gdb-patches@sourceware.org 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]

[RFC] remote.c: Define interface for inheriting remote.c's target operations


The patch below defines an interface by which other targets may
inherit the target operations defined in remote.c.  I based the
interface on that defined by monitor.h and monitor.c which also allow
inheritance of the target operations defined therein.

I used this interface in the implementation of the remote-rx and
extended-remote-rx targets, the patch for which I've posted
separately.

Comments?

	* remote.c (init_remote_ops, init_extended_remote_ops): Rename
	to init_base_remote_ops and init_base_extended_remote_ops,
	respectively.  Fix all callers.
	(remote_open_1): Rename to remote_open_target.  Make non-static.
	Fix all callers.
	(init_remote_ops, init_extended_remote_ops): New functions.
	* remote.h (init_remote_ops, init_extended_remote_ops)
	(remote_open_target): Declare.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.402
diff -u -p -r1.402 remote.c
--- remote.c	16 Apr 2010 07:49:35 -0000	1.402
+++ remote.c	30 Apr 2010 19:55:43 -0000
@@ -107,8 +107,6 @@ static void remote_open (char *name, int
 
 static void extended_remote_open (char *name, int from_tty);
 
-static void remote_open_1 (char *, int, struct target_ops *, int extended_p);
-
 static void remote_close (int quitting);
 
 static void remote_mourn (struct target_ops *ops);
@@ -155,9 +153,9 @@ static long read_frame (char **buf_p, lo
 
 static int hexnumlen (ULONGEST num);
 
-static void init_remote_ops (void);
+static void init_base_remote_ops (void);
 
-static void init_extended_remote_ops (void);
+static void init_base_extended_remote_ops (void);
 
 static void remote_stop (ptid_t);
 
@@ -3198,7 +3196,7 @@ remote_start_remote (struct ui_out *uiou
 static void
 remote_open (char *name, int from_tty)
 {
-  remote_open_1 (name, from_tty, &remote_ops, 0);
+  remote_open_target (name, from_tty, &remote_ops, 0);
 }
 
 /* Open a connection to a remote debugger using the extended
@@ -3207,7 +3205,8 @@ remote_open (char *name, int from_tty)
 static void
 extended_remote_open (char *name, int from_tty)
 {
-  remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */);
+  remote_open_target (name, from_tty, &extended_remote_ops,
+                      1 /*extended_p */);
 }
 
 /* Generic code for opening a connection to a remote target.  */
@@ -3658,9 +3657,14 @@ remote_query_supported (void)
       }
 }
 
+/* Open the remote target associated with NAME using the target operations
+   specified by TARGET.  The flag EXTENDED_P should be set to 1 to indicate
+   use of the extended remote serial protocol, or set to 0 to in order to
+   use the standard remote serial protocol.  */
 
-static void
-remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended_p)
+void
+remote_open_target (char *name, int from_tty, struct target_ops *target,
+                    int extended_p)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -9867,7 +9871,7 @@ remote_set_circular_trace_buffer (int va
 }
 
 static void
-init_remote_ops (void)
+init_base_remote_ops (void)
 {
   remote_ops.to_shortname = "remote";
   remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
@@ -9954,7 +9958,7 @@ Specify the serial device it is connecte
    remote vector and adding to it.  */
 
 static void
-init_extended_remote_ops (void)
+init_base_extended_remote_ops (void)
 {
   extended_remote_ops = remote_ops;
 
@@ -9972,6 +9976,30 @@ Specify the serial device it is connecte
   extended_remote_ops.to_kill = extended_remote_kill;
 }
 
+/* Initialize the target vector OPS to the target operations associated
+   with GDB's remote serial protocol.  */
+
+void
+init_remote_ops (struct target_ops *ops)
+{
+  if (remote_ops.to_magic != OPS_MAGIC)
+    init_base_remote_ops ();
+
+  memcpy (ops, &remote_ops, sizeof remote_ops);
+}
+
+/* Initialize the target vector OPS to the target operations associated
+   with GDB's extended remote serial protocol.  */
+
+void
+init_extended_remote_ops (struct target_ops *ops)
+{
+  if (extended_remote_ops.to_magic != OPS_MAGIC)
+    init_base_extended_remote_ops ();
+
+  memcpy (ops, &extended_remote_ops, sizeof extended_remote_ops);
+}
+
 static int
 remote_can_async_p (void)
 {
@@ -10166,10 +10194,10 @@ _initialize_remote (void)
   rs->buf_size = 400;
   rs->buf = xmalloc (rs->buf_size);
 
-  init_remote_ops ();
+  init_base_remote_ops ();
   add_target (&remote_ops);
 
-  init_extended_remote_ops ();
+  init_base_extended_remote_ops ();
   add_target (&extended_remote_ops);
 
   /* Hook into new objfile notification.  */
Index: remote.h
===================================================================
RCS file: /cvs/src/src/gdb/remote.h,v
retrieving revision 1.19
diff -u -p -r1.19 remote.h
--- remote.h	30 Mar 2010 15:45:14 -0000	1.19
+++ remote.h	30 Apr 2010 19:55:43 -0000
@@ -78,4 +78,24 @@ bfd *remote_bfd_open (const char *remote
 
 int remote_filename_p (const char *filename);
 
+/* Initialize the target vector OPS to the target operations associated
+   with GDB's remote serial protocol.  It is expected that callers of this
+   function will override one or more operations.  */
+
+void init_remote_ops (struct target_ops *ops);
+
+/* Initialize the target vector OPS to the target operations associated
+   with GDB's extended remote serial protocol.  Again, it is expected that
+   callers of this function will override one or more operations.  */
+
+void init_extended_remote_ops (struct target_ops *ops);
+
+/* Open the remote target associated with NAME using the target operations
+   specified by TARGET.  The flag EXTENDED_P should be set to 1 to indicate
+   use of the extended remote serial protocol, or set to 0 to in order to
+   use the standard remote serial protocol.  */
+
+void remote_open_target (char *name, int from_tty, struct target_ops *target,
+                         int extended_p);
+
 #endif


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