Add `set print array-indexes' tests for C/C++ arrays
[binutils-gdb.git] / gdb / inferior.c
index 74b1c65fa3dab9401b67bf2a576f168f0647c1db..bebddb44173cb4280a774d18250f591b19e2bf4d 100644 (file)
@@ -1,6 +1,6 @@
 /* Multi-process control for GDB, the GNU debugger.
 
-   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Copyright (C) 2008-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,6 +35,7 @@
 #include "target-descriptions.h"
 #include "readline/tilde.h"
 #include "progspace-and-thread.h"
+#include "gdbsupport/buildargv.h"
 
 /* Keep a registry of per-inferior data-pointers required by other GDB
    modules.  */
@@ -111,18 +112,15 @@ inferior::unpush_target (struct target_ops *t)
 }
 
 void
-inferior::set_tty (const char *terminal_name)
+inferior::set_tty (std::string terminal_name)
 {
-  if (terminal_name != nullptr && *terminal_name != '\0')
-    m_terminal = make_unique_xstrdup (terminal_name);
-  else
-    m_terminal = NULL;
+  m_terminal = std::move (terminal_name);
 }
 
-const char *
+const std::string &
 inferior::tty ()
 {
-  return m_terminal.get ();
+  return m_terminal;
 }
 
 void
@@ -182,6 +180,8 @@ inferior::clear_thread_list (bool silent)
 {
   thread_list.clear_and_dispose ([=] (thread_info *thr)
     {
+      threads_debug_printf ("deleting thread %s, silent = %d",
+                           thr->ptid.to_string ().c_str (), silent);
       set_thread_exited (thr, silent);
       if (thr->deletable ())
        delete thr;
@@ -935,6 +935,23 @@ clone_inferior_command (const char *args, int from_tty)
        copy_inferior_target_desc_info (inf, orginf);
 
       clone_program_space (pspace, orginf->pspace);
+
+      /* Copy properties from the original inferior to the new one.  */
+      inf->set_args (orginf->args ());
+      inf->set_cwd (orginf->cwd ());
+      inf->set_tty (orginf->tty ());
+      for (const std::string &set_var : orginf->environment.user_set_env ())
+       {
+         /* set_var has the form NAME=value.  Split on the first '='.  */
+         const std::string::size_type pos = set_var.find ('=');
+         gdb_assert (pos != std::string::npos);
+         const std::string varname = set_var.substr (0, pos);
+         inf->environment.set
+           (varname.c_str (), orginf->environment.get (varname.c_str ()));
+       }
+      for (const std::string &unset_var
+          : orginf->environment.user_unset_env ())
+       inf->environment.unset (unset_var.c_str ());
     }
 }