public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Quit after debugging corefiles
@ 2010-06-22 13:18 Edjunior Barbosa Machado
  2010-06-22 13:22 ` Pedro Alves
  2010-06-22 17:42 ` Michael Snyder
  0 siblings, 2 replies; 5+ messages in thread
From: Edjunior Barbosa Machado @ 2010-06-22 13:18 UTC (permalink / raw)
  To: gdb-patches

Hello,

when quitting after a successful debug using a corefile, gdb returns the following internal error:

...
(gdb) cont
Continuing.

Program exited normally.
(gdb) quit
../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

Please consider the following patch containing a fix and a new test for the gcore.exp testcase. It also proposes a change in the function called by gdb_test_multiple that deals with internal error (proc gdb_internal_error_resync{}, in gdb.exp) in order to recognize that gdb is finished.

Comments/suggestions are welcome.

Thanks,
-- 
Edjunior Barbosa Machado
IBM Linux Technology Center

2010-06-22  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>

	* gdb/corelow.c (core_close): check if 'ptid' is still valid.
	* gdb/testsuite/gdb.base/gcore.exp: check if gdb quits successfully.
	* gdb/testsuite/lib/gbd.exp: add pattern 'eof', in order to allow
	gdb_test_multiple to detect that gdb is finished.

diff --git a/gdb/corelow.c b/gdb/corelow.c
index 9523f32..4ec2416 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -208,9 +208,11 @@ core_close (int quitting)
 
   if (core_bfd)
     {
-      int pid = ptid_get_pid (inferior_ptid);
+      ptid_t ptid = inferior_ptid;
       inferior_ptid = null_ptid;	/* Avoid confusion from thread stuff */
-      exit_inferior_silent (pid);
+
+      if (!ptid_equal (ptid, null_ptid))
+	  exit_inferior_silent (ptid_get_pid (ptid));
 
       /* Clear out solib state while the bfd is still open. See
          comments in clear_solib in solib.c. */
diff --git a/gdb/testsuite/gdb.base/gcore.exp b/gdb/testsuite/gdb.base/gcore.exp
index 0da0c75..e0e5243 100644
--- a/gdb/testsuite/gdb.base/gcore.exp
+++ b/gdb/testsuite/gdb.base/gcore.exp
@@ -211,3 +211,11 @@ if ![string compare $pre_corefile_backtrace $post_corefile_backtrace]  {
 } else {
     fail "corefile restored backtrace"
 }
+
+# checking if gdb quits successfully
+gdb_test "run" ".*Starting program.*"
+gdb_test_multiple "quit" "quitting gdb" {
+    eof {
+	pass "gdb quit sucessfully"
+    }
+}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 833fbf2..6292610 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -526,6 +526,10 @@ proc gdb_internal_error_resync {} {
 		# We're resynchronized.
 		return 1
 	    }
+	    eof {
+		# gdb is finished.
+		return 1
+	    }
 	    timeout {
 		perror "Could not resync from internal error (timeout)"
 		return 0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Quit after debugging corefiles
  2010-06-22 13:18 [PATCH] Quit after debugging corefiles Edjunior Barbosa Machado
@ 2010-06-22 13:22 ` Pedro Alves
  2010-06-22 17:42 ` Michael Snyder
  1 sibling, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2010-06-22 13:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: Edjunior Barbosa Machado

On Tuesday 22 June 2010 14:18:28, Edjunior Barbosa Machado wrote:
> Hello,
> 
> when quitting after a successful debug using a corefile, gdb returns the following internal error:
> 
> ...
> (gdb) cont
> Continuing.

Please refer to last month's "Forbid run with a core file loaded" thread.

> 
> Program exited normally.
> (gdb) quit
> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Quit this debugging session? (y or n) n
> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Create a core file of GDB? (y or n) n
> 
> Please consider the following patch containing a fix and a new test for the gcore.exp testcase. It also proposes a change in the function called by gdb_test_multiple that deals with internal error (proc gdb_internal_error_resync{}, in gdb.exp) in order to recognize that gdb is finished.
> 
> Comments/suggestions are welcome.
> 
> Thanks,
> 


-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Quit after debugging corefiles
  2010-06-22 13:18 [PATCH] Quit after debugging corefiles Edjunior Barbosa Machado
  2010-06-22 13:22 ` Pedro Alves
@ 2010-06-22 17:42 ` Michael Snyder
  2010-06-22 20:03   ` Edjunior Barbosa Machado
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Snyder @ 2010-06-22 17:42 UTC (permalink / raw)
  To: Edjunior Barbosa Machado; +Cc: gdb-patches

Edjunior Barbosa Machado wrote:
> Hello,
> 
> when quitting after a successful debug using a corefile, gdb returns the following internal error:
> 
> ...
> (gdb) cont
> Continuing.
> 
> Program exited normally.
> (gdb) quit

Hmm, I don't think you're supposed to "continue" when debugging a core 
file...

> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Quit this debugging session? (y or n) n
> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Create a core file of GDB? (y or n) n
> 
> Please consider the following patch containing a fix and a new test for the gcore.exp testcase. It also proposes a change in the function called by gdb_test_multiple that deals with internal error (proc gdb_internal_error_resync{}, in gdb.exp) in order to recognize that gdb is finished.
> 
> Comments/suggestions are welcome.
> 
> Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Quit after debugging corefiles
  2010-06-22 17:42 ` Michael Snyder
@ 2010-06-22 20:03   ` Edjunior Barbosa Machado
  2010-06-23  2:53     ` Hui Zhu
  0 siblings, 1 reply; 5+ messages in thread
From: Edjunior Barbosa Machado @ 2010-06-22 20:03 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches



On 06/22/2010 02:42 PM, Michael Snyder wrote:
> Hmm, I don't think you're supposed to "continue" when debugging a core
> file...

I meant I had already started debugging (with breakpoints and 'run') before, which is permitted in the current version (although I noticed this behavior has been discussed in the thread that Pedro previously mentioned).

You can see the full output below. Sorry if it was unclear in the beginning.

Using the following faulty code:

$ cat -n corefile-quit.c
      1	#include <stdio.h>
      2	
      3	static void
      4	fault_func (char *arg)
      5	{
      6	  *arg = 0; /* segfault */
      7	}
      8	
      9	int main (int argc, char *argv[])
     10	{
     11	  char *ptr = NULL;
     12	
     13	  printf("hello world\n");
     14	
     15	  fault_func (ptr);
     16	
     17	  return 0;
     18	}

$ ./gdb -q ./corefile-quit core
Reading symbols from /home/emachado/work/gdb/community/build/gdb/corefile-quit...done.
[New Thread 17524]

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/i686/cmov/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./corefile-quit'.
Program terminated with signal 11, Segmentation fault.
#0  0x080483ca in fault_func (arg=0x0) at corefile-quit.c:6
6	  *arg = 0; /* segfault */
Setting up the environment for debugging gdb.
Function "internal_error" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
Function "info_command" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
.gdbinit:8: Error in sourced command file:
Argument required (one or more breakpoint numbers).
(gdb) b 14
Breakpoint 1 at 0x80483ec: file corefile-quit.c, line 14.
(gdb) r
Starting program: /home/emachado/work/gdb/community/build/gdb/corefile-quit
hello world

Breakpoint 1, main (argc=
During symbol reading, incomplete CFI data; unspecified registers (e.g., eax) at 0x80483d2.
1, argv=0xbffff544) at corefile-quit.c:15
15	  fault_func (ptr);
(gdb) set ptr="new"
(gdb) cont
Continuing.

Program exited normally.
(gdb) quit
../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

-- 
Edjunior Barbosa Machado
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Quit after debugging corefiles
  2010-06-22 20:03   ` Edjunior Barbosa Machado
@ 2010-06-23  2:53     ` Hui Zhu
  0 siblings, 0 replies; 5+ messages in thread
From: Hui Zhu @ 2010-06-23  2:53 UTC (permalink / raw)
  To: Edjunior Barbosa Machado; +Cc: Michael Snyder, gdb-patches

I reproduce this issue too.

Thanks,
Hui

On Wed, Jun 23, 2010 at 04:03, Edjunior Barbosa Machado
<emachado@linux.vnet.ibm.com> wrote:
>
>
> On 06/22/2010 02:42 PM, Michael Snyder wrote:
>>
>> Hmm, I don't think you're supposed to "continue" when debugging a core
>> file...
>
> I meant I had already started debugging (with breakpoints and 'run') before,
> which is permitted in the current version (although I noticed this behavior
> has been discussed in the thread that Pedro previously mentioned).
>
> You can see the full output below. Sorry if it was unclear in the beginning.
>
> Using the following faulty code:
>
> $ cat -n corefile-quit.c
>     1  #include <stdio.h>
>     2
>     3  static void
>     4  fault_func (char *arg)
>     5  {
>     6    *arg = 0; /* segfault */
>     7  }
>     8
>     9  int main (int argc, char *argv[])
>    10  {
>    11    char *ptr = NULL;
>    12
>    13    printf("hello world\n");
>    14
>    15    fault_func (ptr);
>    16
>    17    return 0;
>    18  }
>
> $ ./gdb -q ./corefile-quit core
> Reading symbols from
> /home/emachado/work/gdb/community/build/gdb/corefile-quit...done.
> [New Thread 17524]
>
> warning: Can't read pathname for load map: Input/output error.
> Reading symbols from /lib/i686/cmov/libc.so.6...(no debugging symbols
> found)...done.
> Loaded symbols for /lib/i686/cmov/libc.so.6
> Reading symbols from /lib/ld-linux.so.2...(no debugging symbols
> found)...done.
> Loaded symbols for /lib/ld-linux.so.2
> Core was generated by `./corefile-quit'.
> Program terminated with signal 11, Segmentation fault.
> #0  0x080483ca in fault_func (arg=0x0) at corefile-quit.c:6
> 6         *arg = 0; /* segfault */
> Setting up the environment for debugging gdb.
> Function "internal_error" not defined.
> Make breakpoint pending on future shared library load? (y or [n]) [answered
> N; input not from terminal]
> Function "info_command" not defined.
> Make breakpoint pending on future shared library load? (y or [n]) [answered
> N; input not from terminal]
> .gdbinit:8: Error in sourced command file:
> Argument required (one or more breakpoint numbers).
> (gdb) b 14
> Breakpoint 1 at 0x80483ec: file corefile-quit.c, line 14.
> (gdb) r
> Starting program: /home/emachado/work/gdb/community/build/gdb/corefile-quit
> hello world
>
> Breakpoint 1, main (argc=
> During symbol reading, incomplete CFI data; unspecified registers (e.g.,
> eax) at 0x80483d2.
> 1, argv=0xbffff544) at corefile-quit.c:15
> 15        fault_func (ptr);
> (gdb) set ptr="new"
> (gdb) cont
> Continuing.
>
> Program exited normally.
> (gdb) quit
> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion
> `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Quit this debugging session? (y or n) n
> ../../git/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion
> `pid != 0' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Create a core file of GDB? (y or n) n
>
> --
> Edjunior Barbosa Machado
> IBM Linux Technology Center
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-06-23  2:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-22 13:18 [PATCH] Quit after debugging corefiles Edjunior Barbosa Machado
2010-06-22 13:22 ` Pedro Alves
2010-06-22 17:42 ` Michael Snyder
2010-06-22 20:03   ` Edjunior Barbosa Machado
2010-06-23  2:53     ` Hui Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).