2011-05-26 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / target.c
index 59841258554a0a39b800bd2f829de7c777c759c1..ed2da34744cc534c74afede90930ca9a0dfb7986 100644 (file)
@@ -1,7 +1,7 @@
 /* Select target systems and architectures at runtime for GDB.
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
@@ -54,8 +54,6 @@ static int default_watchpoint_addr_within_range (struct target_ops *,
 
 static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int);
 
-static int nosymbol (char *, CORE_ADDR *);
-
 static void tcomplain (void) ATTRIBUTE_NORETURN;
 
 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
@@ -149,20 +147,10 @@ static void debug_to_terminal_info (char *, int);
 
 static void debug_to_load (char *, int);
 
-static int debug_to_lookup_symbol (char *, CORE_ADDR *);
-
 static int debug_to_can_run (void);
 
-static void debug_to_notice_signals (ptid_t);
-
 static void debug_to_stop (ptid_t);
 
-/* NOTE: cagney/2004-09-29: Many targets reference this variable in
-   wierd and mysterious ways.  Putting the variable here lets those
-   wierd and mysterious ways keep building while they are being
-   converted to the inferior inheritance structure.  */
-struct target_ops deprecated_child_ops;
-
 /* Pointer to array of target architecture structures; the size of the
    array; the current index into the array; the allocated size of the
    array.  */
@@ -320,11 +308,11 @@ default_child_has_registers (struct target_ops *ops)
 }
 
 int
-default_child_has_execution (struct target_ops *ops)
+default_child_has_execution (struct target_ops *ops, ptid_t the_ptid)
 {
   /* If there's no thread selected, then we can't make it run through
      hoops.  */
-  if (ptid_equal (inferior_ptid, null_ptid))
+  if (ptid_equal (the_ptid, null_ptid))
     return 0;
 
   return 1;
@@ -380,17 +368,23 @@ target_has_registers_1 (void)
 }
 
 int
-target_has_execution_1 (void)
+target_has_execution_1 (ptid_t the_ptid)
 {
   struct target_ops *t;
 
   for (t = current_target.beneath; t != NULL; t = t->beneath)
-    if (t->to_has_execution (t))
+    if (t->to_has_execution (t, the_ptid))
       return 1;
 
   return 0;
 }
 
+int
+target_has_execution_current (void)
+{
+  return target_has_execution_1 (inferior_ptid);
+}
+
 /* Add a possible target architecture to the list.  */
 
 void
@@ -413,7 +407,7 @@ add_target (struct target_ops *t)
     t->to_has_registers = (int (*) (struct target_ops *)) return_zero;
 
   if (t->to_has_execution == NULL)
-    t->to_has_execution = (int (*) (struct target_ops *)) return_zero;
+    t->to_has_execution = (int (*) (struct target_ops *, ptid_t)) return_zero;
 
   if (!target_structs)
     {
@@ -493,14 +487,14 @@ target_create_inferior (char *exec_file, char *args,
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to create inferior");
+                 _("could not find a target to create inferior"));
 }
 
 void
 target_terminal_inferior (void)
 {
   /* A background resume (``run&'') should leave GDB in control of the
-     terminal. Use target_can_async_p, not target_is_async_p, since at
+     terminal.  Use target_can_async_p, not target_is_async_p, since at
      this point the target is not async yet.  However, if sync_execution
      is not set, we know it will become async prior to resume.  */
   if (target_can_async_p () && !sync_execution)
@@ -515,8 +509,8 @@ static int
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
          struct target_ops *t)
 {
-  errno = EIO;                 /* Can't read/write this location */
-  return 0;                    /* No bytes handled */
+  errno = EIO;                 /* Can't read/write this location */
+  return 0;                    /* No bytes handled */
 }
 
 static void
@@ -532,12 +526,6 @@ noprocess (void)
   error (_("You can't do that without a process to debug."));
 }
 
-static int
-nosymbol (char *name, CORE_ADDR *addrp)
-{
-  return 1;                    /* Symbol does not exist in target env */
-}
-
 static void
 default_terminal_info (char *args, int from_tty)
 {
@@ -604,8 +592,11 @@ update_current_target (void)
       INHERIT (to_can_use_hw_breakpoint, t);
       INHERIT (to_insert_hw_breakpoint, t);
       INHERIT (to_remove_hw_breakpoint, t);
+      /* Do not inherit to_ranged_break_num_registers.  */
       INHERIT (to_insert_watchpoint, t);
       INHERIT (to_remove_watchpoint, t);
+      /* Do not inherit to_insert_mask_watchpoint.  */
+      /* Do not inherit to_remove_mask_watchpoint.  */
       INHERIT (to_stopped_data_address, t);
       INHERIT (to_have_steppable_watchpoint, t);
       INHERIT (to_have_continuable_watchpoint, t);
@@ -613,6 +604,7 @@ update_current_target (void)
       INHERIT (to_watchpoint_addr_within_range, t);
       INHERIT (to_region_ok_for_hw_watchpoint, t);
       INHERIT (to_can_accel_watchpoint_condition, t);
+      /* Do not inherit to_masked_watch_num_registers.  */
       INHERIT (to_terminal_init, t);
       INHERIT (to_terminal_inferior, t);
       INHERIT (to_terminal_ours_for_output, t);
@@ -621,10 +613,8 @@ update_current_target (void)
       INHERIT (to_terminal_info, t);
       /* Do not inherit to_kill.  */
       INHERIT (to_load, t);
-      INHERIT (to_lookup_symbol, t);
       /* Do no inherit to_create_inferior.  */
       INHERIT (to_post_startup_inferior, t);
-      INHERIT (to_acknowledge_created_inferior, t);
       INHERIT (to_insert_fork_catchpoint, t);
       INHERIT (to_remove_fork_catchpoint, t);
       INHERIT (to_insert_vfork_catchpoint, t);
@@ -636,22 +626,23 @@ update_current_target (void)
       INHERIT (to_has_exited, t);
       /* Do not inherit to_mourn_inferior.  */
       INHERIT (to_can_run, t);
-      INHERIT (to_notice_signals, t);
+      /* Do not inherit to_pass_signals.  */
       /* Do not inherit to_thread_alive.  */
       /* Do not inherit to_find_new_threads.  */
       /* Do not inherit to_pid_to_str.  */
       INHERIT (to_extra_thread_info, t);
+      INHERIT (to_thread_name, t);
       INHERIT (to_stop, t);
       /* Do not inherit to_xfer_partial.  */
       INHERIT (to_rcmd, t);
       INHERIT (to_pid_to_exec_file, t);
       INHERIT (to_log_command, t);
       INHERIT (to_stratum, t);
-      /* Do not inherit to_has_all_memory */
-      /* Do not inherit to_has_memory */
-      /* Do not inherit to_has_stack */
-      /* Do not inherit to_has_registers */
-      /* Do not inherit to_has_execution */
+      /* Do not inherit to_has_all_memory */
+      /* Do not inherit to_has_memory */
+      /* Do not inherit to_has_stack */
+      /* Do not inherit to_has_registers */
+      /* Do not inherit to_has_execution */
       INHERIT (to_has_thread_control, t);
       INHERIT (to_can_async_p, t);
       INHERIT (to_is_async_p, t);
@@ -668,9 +659,12 @@ update_current_target (void)
       INHERIT (to_get_ada_task_ptid, t);
       /* Do not inherit to_search_memory.  */
       INHERIT (to_supports_multi_process, t);
+      INHERIT (to_supports_enable_disable_tracepoint, t);
       INHERIT (to_trace_init, t);
       INHERIT (to_download_tracepoint, t);
       INHERIT (to_download_trace_state_variable, t);
+      INHERIT (to_enable_tracepoint, t);
+      INHERIT (to_disable_tracepoint, t);
       INHERIT (to_trace_set_readonly_regions, t);
       INHERIT (to_trace_start, t);
       INHERIT (to_get_trace_status, t);
@@ -687,6 +681,7 @@ update_current_target (void)
       INHERIT (to_set_permissions, t);
       INHERIT (to_static_tracepoint_marker_at, t);
       INHERIT (to_static_tracepoint_markers_by_strid, t);
+      INHERIT (to_traceframe_info, t);
       INHERIT (to_magic, t);
       /* Do not inherit to_memory_map.  */
       /* Do not inherit to_flash_erase.  */
@@ -715,7 +710,8 @@ update_current_target (void)
            (void (*) (struct regcache *))
            noprocess);
   de_fault (deprecated_xfer_memory,
-           (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *))
+           (int (*) (CORE_ADDR, gdb_byte *, int, int,
+                     struct mem_attrib *, struct target_ops *))
            nomemory);
   de_fault (to_files_info,
            (void (*) (struct target_ops *))
@@ -772,47 +768,41 @@ update_current_target (void)
   de_fault (to_load,
            (void (*) (char *, int))
            tcomplain);
-  de_fault (to_lookup_symbol,
-           (int (*) (char *, CORE_ADDR *))
-           nosymbol);
   de_fault (to_post_startup_inferior,
            (void (*) (ptid_t))
            target_ignore);
-  de_fault (to_acknowledge_created_inferior,
-           (void (*) (int))
-           target_ignore);
   de_fault (to_insert_fork_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_fork_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_insert_vfork_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_vfork_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_insert_exec_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_exec_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_set_syscall_catchpoint,
            (int (*) (int, int, int, int, int *))
-           tcomplain);
+           return_one);
   de_fault (to_has_exited,
            (int (*) (int, int, int *))
            return_zero);
   de_fault (to_can_run,
            return_zero);
-  de_fault (to_notice_signals,
-           (void (*) (ptid_t))
-           target_ignore);
   de_fault (to_extra_thread_info,
            (char *(*) (struct thread_info *))
            return_zero);
+  de_fault (to_thread_name,
+           (char *(*) (struct thread_info *))
+           return_zero);
   de_fault (to_stop,
            (void (*) (ptid_t))
            target_ignore);
@@ -838,6 +828,9 @@ update_current_target (void)
   de_fault (to_supports_multi_process,
            (int (*) (void))
            return_zero);
+  de_fault (to_supports_enable_disable_tracepoint,
+           (int (*) (void))
+           return_zero);
   de_fault (to_trace_init,
            (void (*) (void))
            tcomplain);
@@ -847,6 +840,12 @@ update_current_target (void)
   de_fault (to_download_trace_state_variable,
            (void (*) (struct trace_state_variable *))
            tcomplain);
+  de_fault (to_enable_tracepoint,
+           (void (*) (struct bp_location *))
+           tcomplain);
+  de_fault (to_disable_tracepoint,
+           (void (*) (struct bp_location *))
+           tcomplain);
   de_fault (to_trace_set_readonly_regions,
            (void (*) (void))
            tcomplain);
@@ -895,6 +894,9 @@ update_current_target (void)
   de_fault (to_static_tracepoint_markers_by_strid,
            (VEC(static_tracepoint_marker_p) * (*) (const char *))
            tcomplain);
+  de_fault (to_traceframe_info,
+           (struct traceframe_info * (*) (void))
+           tcomplain);
 #undef de_fault
 
   /* Finally, position the target-stack beneath the squashed
@@ -925,7 +927,8 @@ push_target (struct target_ops *t)
       fprintf_unfiltered (gdb_stderr,
                          "Magic number of %s target struct wrong\n",
                          t->to_shortname);
-      internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
+      internal_error (__FILE__, __LINE__,
+                     _("failed internal consistency check"));
     }
 
   /* Find the proper stratum to install this target in.  */
@@ -967,10 +970,10 @@ unpush_target (struct target_ops *t)
 
   if (t->to_stratum == dummy_stratum)
     internal_error (__FILE__, __LINE__,
-                   "Attempt to unpush the dummy target");
+                   _("Attempt to unpush the dummy target"));
 
   /* Look for the specified target.  Note that we assume that a target
-     can only occur once in the target stack. */
+     can only occur once in the target stack.  */
 
   for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
     {
@@ -979,7 +982,7 @@ unpush_target (struct target_ops *t)
     }
 
   if ((*cur) == NULL)
-    return 0;                  /* Didn't find target_ops, quit now */
+    return 0;                  /* Didn't find target_ops, quit now */
 
   /* NOTE: cagney/2003-12-06: In '94 the close call was made
      unconditional by moving it to before the above check that the
@@ -989,7 +992,7 @@ unpush_target (struct target_ops *t)
      targets should be closed.  */
   target_close (t, 0);
 
-  /* Unchain the target */
+  /* Unchain the target */
   tmp = (*cur);
   (*cur) = (*cur)->beneath;
   tmp->beneath = NULL;
@@ -1002,7 +1005,7 @@ unpush_target (struct target_ops *t)
 void
 pop_target (void)
 {
-  target_close (target_stack, 0);      /* Let it clean up */
+  target_close (target_stack, 0);      /* Let it clean up */
   if (unpush_target (target_stack) == 1)
     return;
 
@@ -1051,7 +1054,8 @@ target_is_pushed (struct target_ops *t)
       fprintf_unfiltered (gdb_stderr,
                          "Magic number of %s target struct wrong\n",
                          t->to_shortname);
-      internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
+      internal_error (__FILE__, __LINE__,
+                     _("failed internal consistency check"));
     }
 
   for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
@@ -1095,7 +1099,8 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
            throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
                         _("TLS load module not found"));
 
-         addr = target->to_get_thread_local_address (target, ptid, lm_addr, offset);
+         addr = target->to_get_thread_local_address (target, ptid,
+                                                     lm_addr, offset);
        }
       /* If an error occurred, print TLS related messages here.  Otherwise,
          throw the error to some higher catcher.  */
@@ -1106,7 +1111,8 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
          switch (ex.error)
            {
            case TLS_NO_LIBRARY_SUPPORT_ERROR:
-             error (_("Cannot find thread-local variables in this thread library."));
+             error (_("Cannot find thread-local variables "
+                      "in this thread library."));
              break;
            case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
              if (objfile_is_library)
@@ -1194,7 +1200,7 @@ target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
       if (errcode != 0)
        {
          /* The transfer request might have crossed the boundary to an
-            unallocated region of memory. Retry the transfer, requesting
+            unallocated region of memory.  Retry the transfer, requesting
             a single byte.  */
          tlen = 1;
          offset = 0;
@@ -1268,6 +1274,85 @@ target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
   return NULL;
 }
 
+/* Read memory from the live target, even if currently inspecting a
+   traceframe.  The return is the same as that of target_read.  */
+
+static LONGEST
+target_read_live_memory (enum target_object object,
+                        ULONGEST memaddr, gdb_byte *myaddr, LONGEST len)
+{
+  int ret;
+  struct cleanup *cleanup;
+
+  /* Switch momentarily out of tfind mode so to access live memory.
+     Note that this must not clear global state, such as the frame
+     cache, which must still remain valid for the previous traceframe.
+     We may be _building_ the frame cache at this point.  */
+  cleanup = make_cleanup_restore_traceframe_number ();
+  set_traceframe_number (-1);
+
+  ret = target_read (current_target.beneath, object, NULL,
+                    myaddr, memaddr, len);
+
+  do_cleanups (cleanup);
+  return ret;
+}
+
+/* Using the set of read-only target sections of OPS, read live
+   read-only memory.  Note that the actual reads start from the
+   top-most target again.
+
+   For interface/parameters/return description see target.h,
+   to_xfer_partial.  */
+
+static LONGEST
+memory_xfer_live_readonly_partial (struct target_ops *ops,
+                                  enum target_object object,
+                                  gdb_byte *readbuf, ULONGEST memaddr,
+                                  LONGEST len)
+{
+  struct target_section *secp;
+  struct target_section_table *table;
+
+  secp = target_section_by_addr (ops, memaddr);
+  if (secp != NULL
+      && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
+         & SEC_READONLY))
+    {
+      struct target_section *p;
+      ULONGEST memend = memaddr + len;
+
+      table = target_get_section_table (ops);
+
+      for (p = table->sections; p < table->sections_end; p++)
+       {
+         if (memaddr >= p->addr)
+           {
+             if (memend <= p->endaddr)
+               {
+                 /* Entire transfer is within this section.  */
+                 return target_read_live_memory (object, memaddr,
+                                                 readbuf, len);
+               }
+             else if (memaddr >= p->endaddr)
+               {
+                 /* This section ends before the transfer starts.  */
+                 continue;
+               }
+             else
+               {
+                 /* This section overlaps the transfer.  Just do half.  */
+                 len = p->endaddr - memaddr;
+                 return target_read_live_memory (object, memaddr,
+                                                 readbuf, len);
+               }
+           }
+       }
+    }
+
+  return 0;
+}
+
 /* Perform a partial memory transfer.
    For docs see target.h, to_xfer_partial.  */
 
@@ -1326,6 +1411,59 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
        }
     }
 
+  /* If reading unavailable memory in the context of traceframes, and
+     this address falls within a read-only section, fallback to
+     reading from live memory.  */
+  if (readbuf != NULL && get_traceframe_number () != -1)
+    {
+      VEC(mem_range_s) *available;
+
+      /* If we fail to get the set of available memory, then the
+        target does not support querying traceframe info, and so we
+        attempt reading from the traceframe anyway (assuming the
+        target implements the old QTro packet then).  */
+      if (traceframe_available_memory (&available, memaddr, len))
+       {
+         struct cleanup *old_chain;
+
+         old_chain = make_cleanup (VEC_cleanup(mem_range_s), &available);
+
+         if (VEC_empty (mem_range_s, available)
+             || VEC_index (mem_range_s, available, 0)->start != memaddr)
+           {
+             /* Don't read into the traceframe's available
+                memory.  */
+             if (!VEC_empty (mem_range_s, available))
+               {
+                 LONGEST oldlen = len;
+
+                 len = VEC_index (mem_range_s, available, 0)->start - memaddr;
+                 gdb_assert (len <= oldlen);
+               }
+
+             do_cleanups (old_chain);
+
+             /* This goes through the topmost target again.  */
+             res = memory_xfer_live_readonly_partial (ops, object,
+                                                      readbuf, memaddr, len);
+             if (res > 0)
+               return res;
+
+             /* No use trying further, we know some memory starting
+                at MEMADDR isn't available.  */
+             return -1;
+           }
+
+         /* Don't try to read more than how much is available, in
+            case the target implements the deprecated QTro packet to
+            cater for older GDBs (the target's knowledge of read-only
+            sections may be outdated by now).  */
+         len = VEC_index (mem_range_s, available, 0)->length;
+
+         do_cleanups (old_chain);
+       }
+    }
+
   /* Try GDB's internal data cache.  */
   region = lookup_mem_region (memaddr);
   /* region->hi == 0 means there's no upper bound.  */
@@ -1415,7 +1553,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
     }
   while (ops != NULL);
 
-  if (readbuf && !show_memory_breakpoints)
+  if (res > 0 && readbuf != NULL && !show_memory_breakpoints)
     breakpoint_restore_shadows (readbuf, memaddr, reg_len);
 
   /* Make sure the cache gets updated no matter what - if we are writing
@@ -1493,7 +1631,8 @@ target_xfer_partial (struct target_ops *ops,
       const unsigned char *myaddr = NULL;
 
       fprintf_unfiltered (gdb_stdlog,
-                         "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
+                         "%s:target_xfer_partial "
+                         "(%d, %s, %s, %s, %s, %s) = %s",
                          ops->to_shortname,
                          (int) object,
                          (annex ? annex : "(null)"),
@@ -1541,7 +1680,7 @@ target_xfer_partial (struct target_ops *ops,
    filling the buffer with good data.  There is no way for the caller to know
    how much good data might have been transfered anyway.  Callers that can
    deal with partial reads should call target_read (which will retry until
-   it makes no progress, and then return how much was transferred). */
+   it makes no progress, and then return how much was transferred).  */
 
 int
 target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
@@ -1678,8 +1817,8 @@ static void
 show_trust_readonly (struct ui_file *file, int from_tty,
                     struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Mode for reading from readonly sections is %s.\n"),
+  fprintf_filtered (file,
+                   _("Mode for reading from readonly sections is %s.\n"),
                    value);
 }
 
@@ -1792,31 +1931,33 @@ target_read (struct target_ops *ops,
   return len;
 }
 
-/** Assuming that the entire [begin, end) range of memory cannot be read,
-    try to read whatever subrange is possible to read.
+/* Assuming that the entire [begin, end) range of memory cannot be
+   read, try to read whatever subrange is possible to read.
 
-    The function results, in RESULT, either zero or one memory block.
-    If there's a readable subrange at the beginning, it is completely
-    read and returned. Any further readable subrange will not be read.
-    Otherwise, if there's a readable subrange at the end, it will be
-    completely read and returned.  Any readable subranges before it (obviously,
-    not starting at the beginning), will be ignored. In other cases --
-    either no readable subrange, or readable subrange (s) that is neither
-    at the beginning, or end, nothing is returned.
+   The function returns, in RESULT, either zero or one memory block.
+   If there's a readable subrange at the beginning, it is completely
+   read and returned.  Any further readable subrange will not be read.
+   Otherwise, if there's a readable subrange at the end, it will be
+   completely read and returned.  Any readable subranges before it
+   (obviously, not starting at the beginning), will be ignored.  In
+   other cases -- either no readable subrange, or readable subrange(s)
+   that is neither at the beginning, or end, nothing is returned.
 
-    The purpose of this function is to handle a read across a boundary of
-    accessible memory in a case when memory map is not available. The above
-    restrictions are fine for this case, but will give incorrect results if
-    the memory is 'patchy'. However, supporting 'patchy' memory would require
-    trying to read every single byte, and it seems unacceptable solution.
-    Explicit memory map is recommended for this case -- and
-    target_read_memory_robust will take care of reading multiple ranges then.  */
+   The purpose of this function is to handle a read across a boundary
+   of accessible memory in a case when memory map is not available.
+   The above restrictions are fine for this case, but will give
+   incorrect results if the memory is 'patchy'.  However, supporting
+   'patchy' memory would require trying to read every single byte,
+   and it seems unacceptable solution.  Explicit memory map is
+   recommended for this case -- and target_read_memory_robust will
+   take care of reading multiple ranges then.  */
 
 static void
-read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
+read_whatever_is_readable (struct target_ops *ops,
+                          ULONGEST begin, ULONGEST end,
                           VEC(memory_read_result_s) **result)
 {
-  gdb_byte *buf = xmalloc (end-begin);
+  gdb_byte *buf = xmalloc (end - begin);
   ULONGEST current_begin = begin;
   ULONGEST current_end = end;
   int forward;
@@ -1824,10 +1965,13 @@ read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
 
   /* If we previously failed to read 1 byte, nothing can be done here.  */
   if (end - begin <= 1)
-    return;
+    {
+      xfree (buf);
+      return;
+    }
 
   /* Check that either first or the last byte is readable, and give up
-     if not. This heuristic is meant to permit reading accessible memory
+     if not.  This heuristic is meant to permit reading accessible memory
      at the boundary of accessible region.  */
   if (target_read_partial (ops, TARGET_OBJECT_MEMORY, NULL,
                           buf, begin, 1) == 1)
@@ -1843,6 +1987,7 @@ read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
     }
   else
     {
+      xfree (buf);
       return;
     }
 
@@ -1856,8 +2001,8 @@ read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
       ULONGEST first_half_begin, first_half_end;
       ULONGEST second_half_begin, second_half_end;
       LONGEST xfer;
-
       ULONGEST middle = current_begin + (current_end - current_begin)/2;
+
       if (forward)
        {
          first_half_begin = current_begin;
@@ -1880,14 +2025,15 @@ read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
 
       if (xfer == first_half_end - first_half_begin)
        {
-         /* This half reads up fine. So, the error must be in the other half.  */
+         /* This half reads up fine.  So, the error must be in the
+            other half.  */
          current_begin = second_half_begin;
          current_end = second_half_end;
        }
       else
        {
-         /* This half is not readable. Because we've tried one byte, we
-            know some part of this half if actually redable. Go to the next
+         /* This half is not readable.  Because we've tried one byte, we
+            know some part of this half if actually redable.  Go to the next
             iteration to divide again and try to read.
 
             We don't handle the other half, because this function only tries
@@ -1908,6 +2054,7 @@ read_whatever_is_readable (struct target_ops *ops, ULONGEST begin, ULONGEST end,
     {
       /* The [current_end, end) range has been read.  */
       LONGEST rlen = end - current_end;
+
       r.data = xmalloc (rlen);
       memcpy (r.data, buf + current_end - begin, rlen);
       r.begin = current_end;
@@ -1952,7 +2099,7 @@ read_memory_robust (struct target_ops *ops, ULONGEST offset, LONGEST len)
 
       if (region->attrib.mode == MEM_NONE || region->attrib.mode == MEM_WO)
        {
-         /* Cannot read this region. Note that we can end up here only
+         /* Cannot read this region.  Note that we can end up here only
             if the region is explicitly marked inaccessible, or
             'inaccessible-by-default' is in effect.  */
          xfered += rlen;
@@ -1968,10 +2115,11 @@ read_memory_robust (struct target_ops *ops, ULONGEST offset, LONGEST len)
          /* Call an observer, notifying them of the xfer progress?  */
          if (xfer <= 0)
            {
-             /* Got an error reading full chunk. See if maybe we can read
+             /* Got an error reading full chunk.  See if maybe we can read
                 some subrange.  */
              xfree (buffer);
-             read_whatever_is_readable (ops, offset + xfered, offset + xfered + to_read, &result);
+             read_whatever_is_readable (ops, offset + xfered,
+                                        offset + xfered + to_read, &result);
              xfered += to_read;
            }
          else
@@ -2210,7 +2358,8 @@ target_info (char *args, int from_tty)
       if ((int) (t->to_stratum) <= (int) dummy_stratum)
        continue;
       if (has_all_mem)
-       printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
+       printf_unfiltered (_("\tWhile running this, "
+                            "GDB does not access memory from...\n"));
       printf_unfiltered ("%s:\n", t->to_longname);
       (t->to_files_info) (t);
       has_all_mem = (*t->to_has_all_memory) (t);
@@ -2226,9 +2375,9 @@ target_info (char *args, int from_tty)
 void
 target_pre_inferior (int from_tty)
 {
-  /* Clear out solib state. Otherwise the solib state of the previous
+  /* Clear out solib state.  Otherwise the solib state of the previous
      inferior might have survived and is entirely wrong for the new
-     target.  This has been observed on GNU/Linux using glibc 2.3. How
+     target.  This has been observed on GNU/Linux using glibc 2.3.  How
      to reproduce:
 
      bash$ ./foo&
@@ -2336,7 +2485,7 @@ target_detach (char *args, int from_tty)
        }
     }
 
-  internal_error (__FILE__, __LINE__, "could not find a target to detach");
+  internal_error (__FILE__, __LINE__, _("could not find a target to detach"));
 }
 
 void
@@ -2406,6 +2555,20 @@ target_pid_to_str (ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
+char *
+target_thread_name (struct thread_info *info)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_thread_name != NULL)
+       return (*t->to_thread_name) (info);
+    }
+
+  return NULL;
+}
+
 void
 target_resume (ptid_t ptid, int step, enum target_signal signal)
 {
@@ -2434,6 +2597,37 @@ target_resume (ptid_t ptid, int step, enum target_signal signal)
 
   noprocess ();
 }
+
+void
+target_pass_signals (int numsigs, unsigned char *pass_signals)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_pass_signals != NULL)
+       {
+         if (targetdebug)
+           {
+             int i;
+
+             fprintf_unfiltered (gdb_stdlog, "target_pass_signals (%d, {",
+                                 numsigs);
+
+             for (i = 0; i < numsigs; i++)
+               if (pass_signals[i])
+                 fprintf_unfiltered (gdb_stdlog, " %s",
+                                     target_signal_to_name (i));
+
+             fprintf_unfiltered (gdb_stdlog, " })\n");
+           }
+
+         (*t->to_pass_signals) (numsigs, pass_signals);
+         return;
+       }
+    }
+}
+
 /* Look through the list of possible targets for a target that can
    follow forks.  */
 
@@ -2457,7 +2651,7 @@ target_follow_fork (int follow_child)
 
   /* Some target returned a fork event, but did not know how to follow it.  */
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to follow fork");
+                 _("could not find a target to follow fork"));
 }
 
 void
@@ -2483,7 +2677,7 @@ target_mourn_inferior (void)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to follow mourn inferior");
+                 _("could not find a target to follow mourn inferior"));
 }
 
 /* Look for a target which can describe architectural features, starting
@@ -2596,7 +2790,8 @@ simple_search_memory (struct target_ops *ops,
                           search_buf + keep_len, read_addr,
                           nr_to_read) != nr_to_read)
            {
-             warning (_("Unable to access target memory at %s, halting search."),
+             warning (_("Unable to access target "
+                        "memory at %s, halting search."),
                       hex_string (read_addr));
              do_cleanups (old_cleanups);
              return -1;
@@ -2684,15 +2879,15 @@ target_require_runnable (void)
          || t->to_stratum == arch_stratum)
        continue;
 
-      error (_("\
-The \"%s\" target does not support \"run\".  Try \"help target\" or \"continue\"."),
+      error (_("The \"%s\" target does not support \"run\".  "
+              "Try \"help target\" or \"continue\"."),
             t->to_shortname);
     }
 
   /* This function is only called if the target is running.  In that
      case there should have been a process_stratum target and it
-     should either know how to create inferiors, or not... */
-  internal_error (__FILE__, __LINE__, "No targets found");
+     should either know how to create inferiors, or not...  */
+  internal_error (__FILE__, __LINE__, _("No targets found"));
 }
 
 /* Look through the list of possible targets for a target that can
@@ -2856,8 +3051,9 @@ target_thread_address_space (ptid_t ptid)
   inf = find_inferior_pid (ptid_get_pid (ptid));
 
   if (inf == NULL || inf->aspace == NULL)
-    internal_error (__FILE__, __LINE__, "\
-Can't determine the current address space of thread %s\n",
+    internal_error (__FILE__, __LINE__,
+                   _("Can't determine the current "
+                     "address space of thread %s\n"),
                    target_pid_to_str (ptid));
 
   return inf->aspace;
@@ -3061,7 +3257,8 @@ init_dummy_target (void)
   dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero;
-  dummy_target.to_has_execution = (int (*) (struct target_ops *)) return_zero;
+  dummy_target.to_has_execution
+    = (int (*) (struct target_ops *, ptid_t)) return_zero;
   dummy_target.to_stopped_by_watchpoint = return_zero;
   dummy_target.to_stopped_data_address =
     (int (*) (struct target_ops *, CORE_ADDR *)) return_zero;
@@ -3106,7 +3303,7 @@ target_attach (char *args, int from_tty)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to attach");
+                 _("could not find a target to attach"));
 }
 
 int
@@ -3302,7 +3499,8 @@ target_core_of_thread (ptid_t ptid)
          int retval = t->to_core_of_thread (t, ptid);
 
          if (targetdebug)
-           fprintf_unfiltered (gdb_stdlog, "target_core_of_thread (%d) = %d\n",
+           fprintf_unfiltered (gdb_stdlog,
+                               "target_core_of_thread (%d) = %d\n",
                                PIDGET (ptid), retval);
          return retval;
        }
@@ -3323,7 +3521,8 @@ target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
          int retval = t->to_verify_memory (t, data, memaddr, size);
 
          if (targetdebug)
-           fprintf_unfiltered (gdb_stdlog, "target_verify_memory (%s, %s) = %d\n",
+           fprintf_unfiltered (gdb_stdlog,
+                               "target_verify_memory (%s, %s) = %d\n",
                                paddress (target_gdbarch, memaddr),
                                pulongest (size),
                                retval);
@@ -3334,6 +3533,90 @@ target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
   tcomplain ();
 }
 
+/* The documentation for this function is in its prototype declaration in
+   target.h.  */
+
+int
+target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_insert_mask_watchpoint != NULL)
+      {
+       int ret;
+
+       ret = t->to_insert_mask_watchpoint (t, addr, mask, rw);
+
+       if (targetdebug)
+         fprintf_unfiltered (gdb_stdlog, "\
+target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
+                             core_addr_to_string (addr),
+                             core_addr_to_string (mask), rw, ret);
+
+       return ret;
+      }
+
+  return 1;
+}
+
+/* The documentation for this function is in its prototype declaration in
+   target.h.  */
+
+int
+target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_remove_mask_watchpoint != NULL)
+      {
+       int ret;
+
+       ret = t->to_remove_mask_watchpoint (t, addr, mask, rw);
+
+       if (targetdebug)
+         fprintf_unfiltered (gdb_stdlog, "\
+target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
+                             core_addr_to_string (addr),
+                             core_addr_to_string (mask), rw, ret);
+
+       return ret;
+      }
+
+  return 1;
+}
+
+/* The documentation for this function is in its prototype declaration
+   in target.h.  */
+
+int
+target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_masked_watch_num_registers != NULL)
+      return t->to_masked_watch_num_registers (t, addr, mask);
+
+  return -1;
+}
+
+/* The documentation for this function is in its prototype declaration
+   in target.h.  */
+
+int
+target_ranged_break_num_registers (void)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_ranged_break_num_registers != NULL)
+      return t->to_ranged_break_num_registers (t);
+
+  return -1;
+}
+
 static void
 debug_to_prepare_to_store (struct regcache *regcache)
 {
@@ -3457,10 +3740,12 @@ debug_to_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int rw,
 {
   int retval;
 
-  retval = debug_target.to_can_accel_watchpoint_condition (addr, len, rw, cond);
+  retval = debug_target.to_can_accel_watchpoint_condition (addr, len,
+                                                          rw, cond);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_can_accel_watchpoint_condition (%s, %d, %d, %s) = %ld\n",
+                     "target_can_accel_watchpoint_condition "
+                     "(%s, %d, %d, %s) = %ld\n",
                      core_addr_to_string (addr), len, rw,
                      host_address_to_string (cond), (unsigned long) retval);
   return retval;
@@ -3627,18 +3912,6 @@ debug_to_load (char *args, int from_tty)
   fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
 }
 
-static int
-debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
-{
-  int retval;
-
-  retval = debug_target.to_lookup_symbol (name, addrp);
-
-  fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
-
-  return retval;
-}
-
 static void
 debug_to_post_startup_inferior (ptid_t ptid)
 {
@@ -3648,22 +3921,17 @@ debug_to_post_startup_inferior (ptid_t ptid)
                      PIDGET (ptid));
 }
 
-static void
-debug_to_acknowledge_created_inferior (int pid)
+static int
+debug_to_insert_fork_catchpoint (int pid)
 {
-  debug_target.to_acknowledge_created_inferior (pid);
+  int retval;
 
-  fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
-                     pid);
-}
+  retval = debug_target.to_insert_fork_catchpoint (pid);
 
-static void
-debug_to_insert_fork_catchpoint (int pid)
-{
-  debug_target.to_insert_fork_catchpoint (pid);
+  fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3679,13 +3947,17 @@ debug_to_remove_fork_catchpoint (int pid)
   return retval;
 }
 
-static void
+static int
 debug_to_insert_vfork_catchpoint (int pid)
 {
-  debug_target.to_insert_vfork_catchpoint (pid);
+  int retval;
+
+  retval = debug_target.to_insert_vfork_catchpoint (pid);
+
+  fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3701,13 +3973,17 @@ debug_to_remove_vfork_catchpoint (int pid)
   return retval;
 }
 
-static void
+static int
 debug_to_insert_exec_catchpoint (int pid)
 {
-  debug_target.to_insert_exec_catchpoint (pid);
+  int retval;
+
+  retval = debug_target.to_insert_exec_catchpoint (pid);
+
+  fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3748,15 +4024,6 @@ debug_to_can_run (void)
   return retval;
 }
 
-static void
-debug_to_notice_signals (ptid_t ptid)
-{
-  debug_target.to_notice_signals (ptid);
-
-  fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
-                      PIDGET (ptid));
-}
-
 static struct gdbarch *
 debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
 {
@@ -3764,8 +4031,10 @@ debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
 
   retval = debug_target.to_thread_architecture (ops, ptid);
 
-  fprintf_unfiltered (gdb_stdlog, "target_thread_architecture (%s) = %s [%s]\n",
-                     target_pid_to_str (ptid), host_address_to_string (retval),
+  fprintf_unfiltered (gdb_stdlog, 
+                     "target_thread_architecture (%s) = %s [%s]\n",
+                     target_pid_to_str (ptid),
+                     host_address_to_string (retval),
                      gdbarch_bfd_arch_info (retval)->printable_name);
   return retval;
 }
@@ -3819,19 +4088,21 @@ setup_target_debug (void)
   current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
   current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
   current_target.to_stopped_data_address = debug_to_stopped_data_address;
-  current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
-  current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint;
-  current_target.to_can_accel_watchpoint_condition = debug_to_can_accel_watchpoint_condition;
+  current_target.to_watchpoint_addr_within_range
+    = debug_to_watchpoint_addr_within_range;
+  current_target.to_region_ok_for_hw_watchpoint
+    = debug_to_region_ok_for_hw_watchpoint;
+  current_target.to_can_accel_watchpoint_condition
+    = debug_to_can_accel_watchpoint_condition;
   current_target.to_terminal_init = debug_to_terminal_init;
   current_target.to_terminal_inferior = debug_to_terminal_inferior;
-  current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
+  current_target.to_terminal_ours_for_output
+    = debug_to_terminal_ours_for_output;
   current_target.to_terminal_ours = debug_to_terminal_ours;
   current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
   current_target.to_terminal_info = debug_to_terminal_info;
   current_target.to_load = debug_to_load;
-  current_target.to_lookup_symbol = debug_to_lookup_symbol;
   current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
-  current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
   current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
   current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
   current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
@@ -3840,7 +4111,6 @@ setup_target_debug (void)
   current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
   current_target.to_has_exited = debug_to_has_exited;
   current_target.to_can_run = debug_to_can_run;
-  current_target.to_notice_signals = debug_to_notice_signals;
   current_target.to_stop = debug_to_stop;
   current_target.to_rcmd = debug_to_rcmd;
   current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
@@ -3849,8 +4119,8 @@ setup_target_debug (void)
 \f
 
 static char targ_desc[] =
-"Names of targets and files being debugged.\n\
-Shows the entire stack of targets currently in use (including the exec-file,\n\
+"Names of targets and files being debugged.\nShows the entire \
+stack of targets currently in use (including the exec-file,\n\
 core-file, and process, if any), as well as the symbol file name.";
 
 static void
@@ -3906,8 +4176,9 @@ show_maintenance_target_async_permitted (struct ui_file *file, int from_tty,
                                         struct cmd_list_element *c,
                                         const char *value)
 {
-  fprintf_filtered (file, _("\
-Controlling the inferior in asynchronous mode is %s.\n"), value);
+  fprintf_filtered (file,
+                   _("Controlling the inferior in "
+                     "asynchronous mode is %s.\n"), value);
 }
 
 /* Temporary copies of permission settings.  */
This page took 0.039039 seconds and 4 git commands to generate.