2002-06-11 Daniel Jacobowitz <drow@mvista.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / target.c
index 53a4c1ef55a4c4c35c5fcb805c90e166b012f662..1c2860a11e97213cccb48a1f6eb3ac919a5048cb 100644 (file)
 
 struct target_ops *the_target;
 
+void
+set_desired_inferior (int use_general)
+{
+  struct thread_info *found;
+
+  if (use_general == 1)
+    {
+      found = (struct thread_info *) find_inferior_id (&all_threads,
+                                                      general_thread);
+    }
+  else
+    {
+      found = NULL;
+
+      /* If we are continuing any (all) thread(s), use step_thread
+        to decide which thread to step and/or send the specified
+        signal to.  */
+      if (step_thread > 0 && (cont_thread == 0 || cont_thread == -1))
+       found = (struct thread_info *) find_inferior_id (&all_threads,
+                                                        step_thread);
+
+      if (found == NULL)
+       found = (struct thread_info *) find_inferior_id (&all_threads,
+                                                        cont_thread);
+    }
+
+  if (found == NULL)
+    current_inferior = (struct thread_info *) all_threads.head;
+  else
+    current_inferior = found;
+}
+
 void
 read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
 {
@@ -33,10 +65,41 @@ read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
 }
 
 int
-write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
+write_inferior_memory (CORE_ADDR memaddr, const char *myaddr, int len)
+{
+  /* Lacking cleanups, there is some potential for a memory leak if the
+     write fails and we go through error().  Make sure that no more than
+     one buffer is ever pending by making BUFFER static.  */
+  static char *buffer = 0;
+  int res;
+
+  if (buffer != NULL)
+    free (buffer);
+
+  buffer = malloc (len);
+  memcpy (buffer, myaddr, len);
+  check_mem_write (memaddr, buffer, len);
+  res = (*the_target->write_memory) (memaddr, buffer, len);
+  free (buffer);
+  buffer = NULL;
+
+  return res;
+}
+
+unsigned char
+mywait (char *statusp, int connected_wait)
 {
-  check_mem_write (memaddr, myaddr, len);
-  return (*the_target->write_memory) (memaddr, myaddr, len);
+  unsigned char ret;
+
+  if (connected_wait)
+    server_waiting = 1;
+
+  ret = (*the_target->wait) (statusp);
+
+  if (connected_wait)
+    server_waiting = 0;
+
+  return ret;
 }
 
 void
This page took 0.02374 seconds and 4 git commands to generate.