[D] Fix crash when debug expression enabled.
[binutils-gdb.git] / gdb / target.c
index bca25bd9dba4eef43057ba11af78d4f46de2727a..be7367c4c940e0ee5889cd00193ecb9e9de01b6b 100644 (file)
@@ -1,6 +1,6 @@
 /* Select target systems and architectures at runtime for GDB.
 
-   Copyright (C) 1990-2016 Free Software Foundation, Inc.
+   Copyright (C) 1990-2017 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -45,6 +45,7 @@
 #include "target-debug.h"
 #include "top.h"
 #include "event-top.h"
+#include <algorithm>
 
 static void target_info (char *, int);
 
@@ -1292,7 +1293,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
         shadow handling even though we only end up writing a small
         subset of it.  Cap writes to a limit specified by the target
         to mitigate this.  */
-      len = min (ops->to_get_memory_xfer_limit (ops), len);
+      len = std::min (ops->to_get_memory_xfer_limit (ops), len);
 
       buf = (gdb_byte *) xmalloc (len);
       old_chain = make_cleanup (xfree, buf);
@@ -1858,7 +1859,7 @@ read_memory_robust (struct target_ops *ops,
        }
       else
        {
-         LONGEST to_read = min (len - xfered_total, region_len);
+         LONGEST to_read = std::min (len - xfered_total, region_len);
          gdb_byte *buffer = (gdb_byte *) xmalloc (to_read * unit_size);
          struct cleanup *inner_cleanup = make_cleanup (xfree, buffer);
 
@@ -2328,6 +2329,34 @@ target_resume (ptid_t ptid, int step, enum gdb_signal signal)
   clear_inline_frame_state (ptid);
 }
 
+/* If true, target_commit_resume is a nop.  */
+static int defer_target_commit_resume;
+
+/* See target.h.  */
+
+void
+target_commit_resume (void)
+{
+  struct target_ops *t;
+
+  if (defer_target_commit_resume)
+    return;
+
+  current_target.to_commit_resume (&current_target);
+}
+
+/* See target.h.  */
+
+struct cleanup *
+make_cleanup_defer_target_commit_resume (void)
+{
+  struct cleanup *old_chain;
+
+  old_chain = make_cleanup_restore_integer (&defer_target_commit_resume);
+  defer_target_commit_resume = 1;
+  return old_chain;
+}
+
 void
 target_pass_signals (int numsigs, unsigned char *pass_signals)
 {
@@ -2376,8 +2405,9 @@ default_mourn_inferior (struct target_ops *self)
 }
 
 void
-target_mourn_inferior (void)
+target_mourn_inferior (ptid_t ptid)
 {
+  gdb_assert (ptid_equal (ptid, inferior_ptid));
   current_target.to_mourn_inferior (&current_target);
 
   /* We no longer need to keep handles on any of the object files.
@@ -2445,7 +2475,8 @@ simple_search_memory (struct target_ops *ops,
   while (search_space_len >= pattern_len)
     {
       gdb_byte *found_ptr;
-      unsigned nr_search_bytes = min (search_space_len, search_buf_size);
+      unsigned nr_search_bytes
+       = std::min (search_space_len, (ULONGEST) search_buf_size);
 
       found_ptr = (gdb_byte *) memmem (search_buf, nr_search_bytes,
                                       pattern, pattern_len);
@@ -2478,7 +2509,8 @@ simple_search_memory (struct target_ops *ops,
          gdb_assert (keep_len == pattern_len - 1);
          memcpy (search_buf, search_buf + chunk_size, keep_len);
 
-         nr_to_read = min (search_space_len - keep_len, chunk_size);
+         nr_to_read = std::min (search_space_len - keep_len,
+                                (ULONGEST) chunk_size);
 
          if (target_read (ops, TARGET_OBJECT_MEMORY, NULL,
                           search_buf + keep_len, read_addr,
@@ -2723,6 +2755,14 @@ target_supports_disable_randomization (void)
   return 0;
 }
 
+/* See target/target.h.  */
+
+int
+target_supports_multi_process (void)
+{
+  return (*current_target.to_supports_multi_process) (&current_target);
+}
+
 char *
 target_get_osdata (const char *type)
 {
@@ -2850,7 +2890,7 @@ static void
 release_fileio_fd (int fd, fileio_fh_t *fh)
 {
   fh->fd = -1;
-  lowest_closed_fd = min (lowest_closed_fd, fd);
+  lowest_closed_fd = std::min (lowest_closed_fd, fd);
 }
 
 /* Return a pointer to the fileio_fhandle_t corresponding to FD.  */
@@ -3582,7 +3622,7 @@ simple_verify_memory (struct target_ops *ops,
       ULONGEST xfered_len;
       enum target_xfer_status status;
       gdb_byte buf[1024];
-      ULONGEST howmuch = min (sizeof (buf), size - total_xfered);
+      ULONGEST howmuch = std::min<ULONGEST> (sizeof (buf), size - total_xfered);
 
       status = target_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
                                    buf, NULL, lma + total_xfered, howmuch,