blarsen / rpms / gdb

Forked from rpms/gdb 2 years ago
Clone
ee681d3
--- ./gdb/doc/gdb.texinfo	2010-05-24 19:37:01.000000000 +0200
ee681d3
+++ ./gdb/doc/gdb.texinfo	2010-05-24 19:38:56.000000000 +0200
ee681d3
@@ -14768,33 +14768,21 @@ and @code{show architecture}.
ee681d3
 @cindex active targets
ee681d3
 @cindex multiple targets
ee681d3
 
ee681d3
-There are three classes of targets: processes, core files, and
ee681d3
-executable files.  @value{GDBN} can work concurrently on up to three
ee681d3
-active targets, one in each class.  This allows you to (for example)
ee681d3
-start a process and inspect its activity without abandoning your work on
ee681d3
-a core file.
ee681d3
-
ee681d3
-For example, if you execute @samp{gdb a.out}, then the executable file
ee681d3
-@code{a.out} is the only active target.  If you designate a core file as
ee681d3
-well---presumably from a prior run that crashed and coredumped---then
ee681d3
-@value{GDBN} has two active targets and uses them in tandem, looking
ee681d3
-first in the corefile target, then in the executable file, to satisfy
ee681d3
-requests for memory addresses.  (Typically, these two classes of target
ee681d3
-are complementary, since core files contain only a program's
ee681d3
-read-write memory---variables and so on---plus machine status, while
ee681d3
-executable files contain only the program text and initialized data.)
ee681d3
-
ee681d3
-When you type @code{run}, your executable file becomes an active process
ee681d3
-target as well.  When a process target is active, all @value{GDBN}
ee681d3
-commands requesting memory addresses refer to that target; addresses in
ee681d3
-an active core file or executable file target are obscured while the
ee681d3
-process target is active.
ee681d3
-
ee681d3
-Use the @code{core-file} and @code{exec-file} commands to select a new
ee681d3
-core file or executable target (@pxref{Files, ,Commands to Specify
ee681d3
-Files}).  To specify as a target a process that is already running, use
ee681d3
-the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
ee681d3
-Process}).
ee681d3
+There are multiple classes of targets such as: processes, executable files or
ee681d3
+recording sessions.  Core files belong to the process class, there can be
ee681d3
+active only one of a core or a running process.  Otherwise @value{GDBN} can
ee681d3
+work concurrently on multiple active targets, one in each class.  This allows
ee681d3
+you to (for example) start a process and inspect its activity while still
ee681d3
+having access to the executable file after the process finishes.  Or if you
ee681d3
+start process recording (@pxref{Reverse Execution}) and @code{reverse-step}
ee681d3
+there you are presented a virtual layer of the recording target while the
ee681d3
+process target remains stopped at the chronologically last point of the process
ee681d3
+execution.
ee681d3
+
ee681d3
+Use the @code{core-file} and @code{exec-file} commands to select a new core
ee681d3
+file or executable target (@pxref{Files, ,Commands to Specify Files}).  To
ee681d3
+specify as a target a process that is already running, use the @code{attach}
ee681d3
+command (@pxref{Attach, ,Debugging an Already-running Process}).
ee681d3
 
ee681d3
 @node Target Commands
ee681d3
 @section Commands for Managing Targets
ee681d3
--- ./gdb/infcmd.c	2010-05-24 19:37:01.000000000 +0200
ee681d3
+++ ./gdb/infcmd.c	2010-05-24 19:41:21.000000000 +0200
ee681d3
@@ -483,6 +483,13 @@ run_command_1 (char *args, int from_tty,
ee681d3
 
ee681d3
   dont_repeat ();
ee681d3
 
ee681d3
+  if (core_bfd)
ee681d3
+    {
ee681d3
+      core_file_command (NULL, from_tty);
ee681d3
+      if (core_bfd)
ee681d3
+	warning (_("Core file not unloaded."));
ee681d3
+    }
ee681d3
+
ee681d3
   kill_if_already_running (from_tty);
ee681d3
 
ee681d3
   init_wait_for_inferior ();
ee681d3
@@ -2373,6 +2380,13 @@ attach_command (char *args, int from_tty
ee681d3
 	error (_("Not killed."));
ee681d3
     }
ee681d3
 
ee681d3
+  if (core_bfd)
ee681d3
+    {
ee681d3
+      core_file_command (NULL, from_tty);
ee681d3
+      if (core_bfd)
ee681d3
+	warning (_("Core file not unloaded."));
ee681d3
+    }
ee681d3
+
ee681d3
   /* Clean up any leftovers from other runs.  Some other things from
ee681d3
      this function should probably be moved into target_pre_inferior.  */
ee681d3
   target_pre_inferior (from_tty);
ee681d3
--- ./gdb/testsuite/gdb.base/corefile.exp	2010-01-09 01:14:11.000000000 +0100
ee681d3
+++ ./gdb/testsuite/gdb.base/corefile.exp	2010-05-24 19:38:56.000000000 +0200
ee681d3
@@ -182,3 +182,62 @@ gdb_load ${binfile}
ee681d3
 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
ee681d3
 
ee681d3
 gdb_test "core" "No core file now."
ee681d3
+
ee681d3
+
ee681d3
+# Test a run (start) command will clear any loaded core file.
ee681d3
+
ee681d3
+gdb_test "core-file $corefile" "Core was generated by .*" "run: load core again"
ee681d3
+gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file"
ee681d3
+
ee681d3
+set test "run: with core"
ee681d3
+if [runto_main] {
ee681d3
+    pass $test
ee681d3
+} else {
ee681d3
+    fail $test
ee681d3
+}
ee681d3
+
ee681d3
+set test "run: core file is cleared"
ee681d3
+gdb_test_multiple "info files" $test {
ee681d3
+    "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
ee681d3
+	fail $test
ee681d3
+    }
ee681d3
+    "\r\n$gdb_prompt $" {
ee681d3
+	pass $test
ee681d3
+    }
ee681d3
+}
ee681d3
+
ee681d3
+gdb_exit
ee681d3
+
ee681d3
+
ee681d3
+# Test an attach command will clear any loaded core file.
ee681d3
+
ee681d3
+if ![is_remote target] {
ee681d3
+    set test "attach: spawn sleep"
ee681d3
+    set res [remote_spawn host "$binfile sleep"];
ee681d3
+    if { $res < 0 || $res == "" } {
ee681d3
+	perror "$test failed."
ee681d3
+	fail $test
ee681d3
+	return
ee681d3
+    }
ee681d3
+    set pid [exp_pid -i $res]
ee681d3
+    # We do not care of the startup phase where it will be caught.
ee681d3
+
ee681d3
+    gdb_start
ee681d3
+
ee681d3
+    gdb_test "core-file $corefile" "Core was generated by .*" "attach: load core again"
ee681d3
+    gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "attach: sanity check we see the core file"
ee681d3
+
ee681d3
+    gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core"
ee681d3
+
ee681d3
+    set test "attach: core file is cleared"
ee681d3
+    gdb_test_multiple "info files" $test {
ee681d3
+	"\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
ee681d3
+	    fail $test
ee681d3
+	}
ee681d3
+	"\r\n$gdb_prompt $" {
ee681d3
+	    pass $test
ee681d3
+	}
ee681d3
+    }
ee681d3
+
ee681d3
+    gdb_exit
ee681d3
+}
ee681d3
--- ./gdb/testsuite/gdb.base/coremaker.c	2010-01-01 08:32:00.000000000 +0100
ee681d3
+++ ./gdb/testsuite/gdb.base/coremaker.c	2010-05-24 19:38:56.000000000 +0200
ee681d3
@@ -133,8 +133,14 @@ func1 ()
ee681d3
   func2 ();
ee681d3
 }
ee681d3
 
ee681d3
-int main ()
ee681d3
+int
ee681d3
+main (int argc, char **argv)
ee681d3
 {
ee681d3
+  if (argc == 2 && strcmp (argv[1], "sleep") == 0)
ee681d3
+    {
ee681d3
+      sleep (60);
ee681d3
+      return 0;
ee681d3
+    }
ee681d3
   mmapdata ();
ee681d3
   func1 ();
ee681d3
   return 0;