Discussion:
[Bug breakpoints/23366] New: segfault during info prog at exec catchpoint with follow-exec-mode new
vries at gcc dot gnu.org
2018-07-03 19:07:27 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

Bug ID: 23366
Summary: segfault during info prog at exec catchpoint with
follow-exec-mode new
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: breakpoints
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---

Consider this test-case:
...
$ cat t.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int
main (void)
{
char *exec_args[] = { "/bin/ls", "ppp", NULL };
execve (exec_args[0], exec_args, NULL);
}
...

compiled for debug:
...
$ gcc -g t.c -o t
...

we run into a segfault with trunk gdb:
...
$ ./install/bin/gdb t \
-batch \
-ex "catch exec" \
-ex "set follow-exec-mode new" \
-ex "run" \
-ex "info prog"
Catchpoint 1 (exec)
process 22490 is executing new program: /usr/bin/ls
[New inferior 2 (process 0)]
[New process 22490]

Thread 2.1 "ls" hit Catchpoint 1 (exec'd /usr/bin/ls), 0x00007ffff7dd7ea0 in
_start () from /lib64/ld-linux-x86-64.so.2
Segmentation fault (core dumped)
...

Runnig with gdb, we see:
...
Program received signal SIGSEGV, Segmentation fault.
info_program_command (args=<optimized out>, from_tty=0)
at src/gdb/infcmd.c:2099
2099 if (tp->state == THREAD_EXITED)
(gdb) p tp
$1 = (thread_info *) 0x0
...

and tp is NULL, because find_thread_ptid (ptid) can't find a thread pointer for
ptid 'minus_one_ptid':
...
(gdb) p ptid
$2 = {m_pid = -1, m_lwp = 0, m_tid = 0}
...
--
You are receiving this mail because:
You are on the CC list for the bug.
vries at gcc dot gnu.org
2018-07-03 19:12:46 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
With patch:
...
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 821bcc6544..74d5956765 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2091,7 +2091,7 @@ info_program_command (const char *args, int from_tty)
get_last_target_status (&ptid, &ws);
}

- if (ptid == null_ptid)
+ if (ptid == null_ptid || ptid == minus_one_ptid)
error (_("No selected thread."));

thread_info *tp = find_thread_ptid (ptid);
...

we have instead:
...
$ ./install/bin/gdb t -batch -ex "catch exec" -ex "set follow-exec-mode new"
-ex "run" -ex "info prog"
Catchpoint 1 (exec)
process 25728 is executing new program: /usr/bin/ls
[New inferior 2 (process 0)]
[New process 25728]

Thread 2.1 "ls" hit Catchpoint 1 (exec'd /usr/bin/ls), 0x00007ffff7dd7ea0 in
_start () from /lib64/ld-linux-x86-64.so.2

[1]+ Stopped ./install/bin/gdb t -batch -ex "catch exec" -ex
"set follow-exec-mode new" -ex "run" -ex "info prog"
$ fg
./install/bin/gdb t -batch -ex "catch exec" -ex "set follow-exec-mode new" -ex
"run" -ex "info prog"
No selected thread.
$
...
--
You are receiving this mail because:
You are on the CC list for the bug.
vries at gcc dot gnu.org
2018-07-04 10:22:07 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
Post by vries at gcc dot gnu.org
Thread 2.1 "ls" hit Catchpoint 1 (exec'd /usr/bin/ls), 0x00007ffff7dd7ea0 in
_start () from /lib64/ld-linux-x86-64.so.2
[1]+ Stopped ./install/bin/gdb t -batch -ex "catch exec"
-ex "set follow-exec-mode new" -ex "run" -ex "info prog"
Filed as PR23368 - "gdb goes to into background when hitting exec catchpoint
with follow-exec-mode new"
--
You are receiving this mail because:
You are on the CC list for the bug.
zrlw at sina dot com
2018-07-04 18:29:48 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

Lao Wei <zrlw at sina dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |zrlw at sina dot com

--- Comment #3 from Lao Wei <zrlw at sina dot com> ---
Patch for gdb 7.11.1 of SUSE Linux Enterprise 12, maybe suitable for other
7.11.1:

# gdb -v
GNU gdb (GDB; SUSE Linux Enterprise 12) 7.11.1

# cat /usr/src/packages/SOURCES/gdb-7.11.1-follow-exec-mode-new.patch
--- gdb.orig/infcmd.c 2016-06-01 08:36:15.000000000 +0800
+++ gdb/infcmd.c 2018-07-05 01:11:52.476253718 +0800
@@ -2062,7 +2062,9 @@ program_info (char *args, int from_tty)
get_last_target_status (&ptid, &ws);
}

- if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
+ if (ptid_equal (ptid, minus_one_ptid))
+ error (_("No selected thread."));
+ else if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
error (_("Invalid selected thread."));
else if (is_running (ptid))
error (_("Selected thread is running."));
--
You are receiving this mail because:
You are on the CC list for the bug.
vries at gcc dot gnu.org
2018-07-20 14:15:22 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Patch submitted: https://sourceware.org/ml/gdb-patches/2018-07/msg00618.html
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-07-25 22:58:25 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9e7f3bbbbf5a13e879a4cc3cfa958412ffac0d9d

commit 9e7f3bbbbf5a13e879a4cc3cfa958412ffac0d9d
Author: Tom de Vries <***@suse.de>
Date: Tue Jul 3 17:08:42 2018 +0200

[gdb/breakpoints] Fix sigsegv in info prog at exec catchpoint

With the test-case contained in this patch and compiled for debug we run
into
a segfault with trunk gdb:
...
$ gdb catch-follow-exec -batch -ex "catch exec" \
-ex "set follow-exec-mode new" -ex "run" -ex "info prog"
Catchpoint 1 (exec)
process xxx is executing new program: /usr/bin/ls
[New inferior 2 (process 0)]
[New process xxx]

Thread 2.1 "ls" hit Catchpoint 1 (exec'd /usr/bin/ls), in _start () from
/lib64/ld-linux-x86-64.so.2
Segmentation fault (core dumped)
...

The patch fixes the segfault by returning an error in info_program_command
if get_last_target_status returns minus_one_ptid.

The test-case is non-standard, because the standard approach runs into
PR23368, a problem with gdb going to the background.

Build and reg-tested on x86_64-linux.

2018-07-26 Tom de Vries <***@suse.de>

PR breakpoints/23366
* infcmd.c (info_program_command): Handle ptid == minus_one_ptid.

* gdb.base/catch-follow-exec.c: New test.
* gdb.base/catch-follow-exec.exp: New file.
--
You are receiving this mail because:
You are on the CC list for the bug.
vries at gcc dot gnu.org
2018-07-26 09:21:15 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23366

Tom de Vries <vries at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
Patch with test-case committed, marking resolved-fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...