NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/49662: gdb has trouble with threaded programs



>Number:         49662
>Category:       bin
>Synopsis:       gdb has trouble with threaded programs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 13 12:20:00 +0000 2015
>Originator:     Patrick Welche
>Release:        NetBSD-7.99.4/amd64 (9 Feb 2015)
>Organization:
>Environment:
>Description:
gdb looses track debugging the following "simple" test case.
>How-To-Repeat:
Find a trivial program with a bug, ioctltest.c:

#include <sys/ioctl.h>

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
        int fd, owner;

        fd = open("/dev/zero", O_RDONLY);

        /* should set ENOTTY */
        if (ioctl(fd, FIOGETOWN, &owner) == -1)
                err(1, NULL);

        printf("/dev/zero is owned by uid %d.\n", owner);

        close(fd);

        return 0;
}

Aim to find out what is up with the ioctl() call, so fire up a rump server:

  rump_allserver unix:///tmp/sock

e.g. for /bin/sh, set

export RUMP_SERVER=unix:///tmp/sock
export LD_PRELOAD=/usr/lib/librumphijack.so
export RUMPHIJACK_RETRYCONNECT=inftime
export RUMPHIJACK=path=/rump,blanket=/dev/zero

$ gdb ioctltest
GNU gdb (GDB) 7.7.1
...
(gdb) break ioctl
Breakpoint 1 at 0x400800
(gdb) run
Starting program: /home/prlw1/NetBSD/thread/ioctltest 
[Switching to LWP 1]

Breakpoint 1, ioctl (fd=131, cmd=1074030203)
    at /usr/src/lib/librumphijack/hijack.c:1326
1326            if (fd_isrump(fd)) {
(gdb) n
1327                    fd = fd_host2rump(fd);
(gdb) 
1328                    op_ioctl = GETSYSCALL(rump, IOCTL);
(gdb) 
1333            va_start(ap, cmd);
(gdb) 
1334            rv = op_ioctl(fd, cmd, va_arg(ap, void *));
(gdb) s
rump___sysimpl_ioctl (fd=3, com=1074030203, data=0x7f7fffffda68)
    at /usr/src/lib/librumpclient/../../sys/rump/librump/rumpkern/rump_syscalls.c:970
970             int error = 0;
(gdb) n
971             int rv = -1;
(gdb) 
974             memset(&callarg, 0, sizeof(callarg));
(gdb) 
975             SPARG(&callarg, fd) = fd;
(gdb) 
976             SPARG(&callarg, com) = com;
(gdb) 
977             SPARG(&callarg, data) = data;
(gdb) 
979             error = rsys_syscall(SYS_ioctl, &callarg, sizeof(callarg), retval);
(gdb) s
rumpclient_syscall (sysnum=54, data=0x7f7fffffd910, dlen=24, 
    retval=0x7f7fffffd930) at /usr/src/lib/librumpclient/rumpclient.c:583
583             pthread_sigmask(SIG_SETMASK, &fullset, &omask);
(gdb) 


Now watch the debugged program chew 100% CPU, and ctl-C in gdb fails.

Sending a STOP to the debugged program gives:

Program received signal SIGSTOP, Stopped (signal).
0x00007f7ff680daf1 in syscall_req (spc=0x7f7ff6a13580, omask=0x7f7fffffd8c0, 
    sysnum=54, data=0x7f7fffffd910, dlen=24, resp=0xffffd8b8)
    at /usr/src/lib/librumpclient/rumpclient.c:382
382             *resp = rw.rw_data;
(gdb) c
Continuing.

goes back to 100% CPU usage, rather than the expected:
ioctltest: Operation not supported by device

>Fix:



Home | Main Index | Thread Index | Old Index