public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Can't debug bash with gdb 8.2.1-1
@ 2019-07-22 14:59 Ken Brown
  2019-07-23 13:52 ` Jon Turney
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2019-07-22 14:59 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 703 bytes --]

With the test version of gdb, attempting to debug bash fails as follows:

$ gdb bash
GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
[...]
Reading symbols from bash...Reading symbols from 
/usr/lib/debug//usr/bin/bash.exe.dbg...done.
done.
(gdb) r -c ls
Starting program: /usr/bin/bash -c ls
[...]
/usr/bin/bash: initialize_job_control: getpgrp failed: No error
[...]
[Inferior 1 (process 31876) exited with code 01]

This problem doesn't occur with gdb-8.1.1-1.

Ken
\0ТÒÐÐ¥\a&ö&ÆVÒ\a&W\x06÷'G3¢\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒ÷\a&ö&ÆV×2æ‡FÖÀФd\x15\x13¢\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöf\x17\x12ðФFö7VÖVçF\x17F–öã¢\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöFö72æ‡FÖÀÐ¥Vç7V'67&–&R\x06–æfó¢\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöÖÂò7Vç7V'67&–&R×6–×\x06ÆPРÐ

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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-22 14:59 Can't debug bash with gdb 8.2.1-1 Ken Brown
@ 2019-07-23 13:52 ` Jon Turney
  2019-07-23 15:42   ` Ken Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Turney @ 2019-07-23 13:52 UTC (permalink / raw)
  To: The Cygwin Mailing List; +Cc: Ken Brown

On 22/07/2019 15:59, Ken Brown wrote:
> With the test version of gdb, attempting to debug bash fails as follows:
> 
> $ gdb bash
> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
> [...]
> Reading symbols from bash...Reading symbols from
> /usr/lib/debug//usr/bin/bash.exe.dbg...done.
> done.
> (gdb) r -c ls
> Starting program: /usr/bin/bash -c ls
> [...]
> /usr/bin/bash: initialize_job_control: getpgrp failed: No error
> [...]
> [Inferior 1 (process 31876) exited with code 01]
> 
> This problem doesn't occur with gdb-8.1.1-1.
Thanks for reporting this.

I had also tripped over this problem recently: It seems that changes in 
gdb (bisection lands on [1]) mean that any call to getpgrp() in the 
inferior fails (this can be demonstrated with a test program that just 
calls that).

I believe this is behaviour is caused by some kind of defect in the 
cygwin DLL, but I haven't made much progress in investigating it. (I 
don't really understand how the inferior gets into a state where 
getpgrp() fails, which isn't really supposed to happen...)

[1] 
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=e671cd59d74cec9f53e110ce887128d1eeadb7f2


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-23 13:52 ` Jon Turney
@ 2019-07-23 15:42   ` Ken Brown
  2019-07-23 18:02     ` Jon Turney
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2019-07-23 15:42 UTC (permalink / raw)
  To: Jon Turney, The Cygwin Mailing List; +Cc: Eric Blake

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2260 bytes --]

On 7/23/2019 9:51 AM, Jon Turney wrote:
> On 22/07/2019 15:59, Ken Brown wrote:
>> With the test version of gdb, attempting to debug bash fails as follows:
>>
>> $ gdb bash
>> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
>> [...]
>> Reading symbols from bash...Reading symbols from
>> /usr/lib/debug//usr/bin/bash.exe.dbg...done.
>> done.
>> (gdb) r -c ls
>> Starting program: /usr/bin/bash -c ls
>> [...]
>> /usr/bin/bash: initialize_job_control: getpgrp failed: No error
>> [...]
>> [Inferior 1 (process 31876) exited with code 01]
>>
>> This problem doesn't occur with gdb-8.1.1-1.
> Thanks for reporting this.
> 
> I had also tripped over this problem recently: It seems that changes in gdb 
> (bisection lands on [1]) mean that any call to getpgrp() in the inferior fails 
> (this can be demonstrated with a test program that just calls that).

I can't reproduce that with the following test program:

$ cat getpgrp_test.c
#include <unistd.h>
int
main ()
{
   pid_t t = getpgrp ();
}

> I believe this is behaviour is caused by some kind of defect in the cygwin DLL, 
> but I haven't made much progress in investigating it. (I don't really understand 
> how the inferior gets into a state where getpgrp() fails, which isn't really 
> supposed to happen...)

POSIX says that getpgrp() never fails, but Cygwin's getpgrp() can in fact fail. 
I'm about to send a proposed fix to cygwin-patches.  I've just checked that the 
bash example succeeds with my patch installed.

BTW, I think there's also a bash bug here.  The bash-4.4.12 source code has the 
following in jobs.c:

   shell_pgrp = getpgid (0);

   if (shell_pgrp == -1)
     {
       sys_error (_("initialize_job_control: getpgrp failed"));
       exit (1);
     }

At first glance this might seem OK, since getpgid() is allowed to fail.  But a 
macro earlier in the code redefines getpgid() in terms of getpgrp(), which is 
not supposed to fail.

I've added Eric to the CC in case he wants to follow up on this.

Ken
\0ТÒÐÐ¥\a&ö&ÆVÒ\a&W\x06÷'G3¢\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒ÷\a&ö&ÆV×2æ‡FÖÀФd\x15\x13¢\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöf\x17\x12ðФFö7VÖVçF\x17F–öã¢\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöFö72æ‡FÖÀÐ¥Vç7V'67&–&R\x06–æfó¢\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöÖÂò7Vç7V'67&–&R×6–×\x06ÆPРÐ

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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-23 15:42   ` Ken Brown
@ 2019-07-23 18:02     ` Jon Turney
  2019-07-24 12:33       ` Ken Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Turney @ 2019-07-23 18:02 UTC (permalink / raw)
  To: Ken Brown, The Cygwin Mailing List

On 23/07/2019 16:42, Ken Brown wrote:
> On 7/23/2019 9:51 AM, Jon Turney wrote:
>> On 22/07/2019 15:59, Ken Brown wrote:
>>> With the test version of gdb, attempting to debug bash fails as follows:
>>>
>>> $ gdb bash
>>> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
>>> [...]
>>> Reading symbols from bash...Reading symbols from
>>> /usr/lib/debug//usr/bin/bash.exe.dbg...done.
>>> done.
>>> (gdb) r -c ls
>>> Starting program: /usr/bin/bash -c ls
>>> [...]
>>> /usr/bin/bash: initialize_job_control: getpgrp failed: No error
>>> [...]
>>> [Inferior 1 (process 31876) exited with code 01]
>>>
>>> This problem doesn't occur with gdb-8.1.1-1.
>> Thanks for reporting this.
>>
>> I had also tripped over this problem recently: It seems that changes in gdb
>> (bisection lands on [1]) mean that any call to getpgrp() in the inferior fails
>> (this can be demonstrated with a test program that just calls that).
> 
> I can't reproduce that with the following test program:
> 
> $ cat getpgrp_test.c
> #include <unistd.h>
> int
> main ()
> {
>     pid_t t = getpgrp ();
> }

Hmm.... let me clarify what I mean:

$ cat getpgrp_test.c
#include <unistd.h>
#include <stdio.h>

int main() {
   printf("getpgrp() = %d\n", getpgrp());
}

$ gcc getpgrp_test.c -o getpgrp_test.exe

$ ./getpgrp_test
getpgrp() = 1241


$ gdb ./getpgrp_test
GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
[...]
Reading symbols from ./getpgrp_test...done.
(gdb) r
Starting program: /work/getpgrp_test
getpgrp() = -1
[Inferior 1 (process 11428) exited normally]

>> I believe this is behaviour is caused by some kind of defect in the cygwin DLL,
>> but I haven't made much progress in investigating it. (I don't really understand
>> how the inferior gets into a state where getpgrp() fails, which isn't really
>> supposed to happen...)
> 
> POSIX says that getpgrp() never fails, but Cygwin's getpgrp() can in fact fail.
> I'm about to send a proposed fix to cygwin-patches.  I've just checked that the
> bash example succeeds with my patch installed.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-23 18:02     ` Jon Turney
@ 2019-07-24 12:33       ` Ken Brown
  2019-07-24 14:32         ` Ken Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2019-07-24 12:33 UTC (permalink / raw)
  To: Jon Turney, The Cygwin Mailing List

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1640 bytes --]

On 7/23/2019 2:02 PM, Jon Turney wrote:
> Hmm.... let me clarify what I mean:
> 
> $ cat getpgrp_test.c
> #include <unistd.h>
> #include <stdio.h>
> 
> int main() {
>    printf("getpgrp() = %d\n", getpgrp());
> }
> 
> $ gcc getpgrp_test.c -o getpgrp_test.exe
> 
> $ ./getpgrp_test
> getpgrp() = 1241
> 
> 
> $ gdb ./getpgrp_test
> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
> [...]
> Reading symbols from ./getpgrp_test...done.
> (gdb) r
> Starting program: /work/getpgrp_test
> getpgrp() = -1
> [Inferior 1 (process 11428) exited normally]

Thanks, I was being dense.  But look at this one:

$ cat getpgrp_test.c
#include <unistd.h>
#include <stdio.h>
#include <errno.h>

int
main ()
{
   pid_t pid = getpid ();
   pid_t pgid = getpgid (0);
   printf ("getpid () = %d, getpgid (0) = %d, errno = %d\n", pid, pgid, errno);
}

$ gcc -o getpgrp_test -Wall -g -O0 getpgrp_test.c

$ ./getpgrp_test.exe
getpid () = 1424, getpgid (0) = 1424, errno = 0

$ gdb ./getpgrp_test.exe
GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
[...]
(gdb) r
Starting program: /home/kbrown/Documents/programming/misc_examples/getpgrp_test.exe
[...]
getpid () = 1427, getpgid (0) = -1, errno = 0
[...]
[Inferior 1 (process 23872) exited normally]

So getpgid (0) returns -1 without setting errno.  I think this means that 
pinfo::init() didn't fail, but for some reason myself->pgid == -1.

Ken
\x03B‹KCB”\x1c›Ø›\x19[H\x1c™\^[ܝ\x1cΈ\b\b\b\b\b\b\x1a\x1d\x1d\x1c\x0e‹ËØÞYÝÚ[‹˜ÛÛKÜ\x1c›Ø›\x19[\Ëš\x1d^[[\x03B‘TNˆ\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\x1a\x1d\x1d\x1c\x0e‹ËØÞYÝÚ[‹˜ÛÛKÙ˜\KÃB‘^[ØÝ[Y[\x18]\x1a[ÛŽˆ\b\b\b\b\b\b\b\b\x1a\x1d\x1d\x1c\x0e‹ËØÞYÝÚ[‹˜ÛÛKÙ^[ØÜËš\x1d^[[\x03B•[œÝXœØÜšX™H\x1a[™›Îˆ\b\b\b\b\b\x1a\x1d\x1d\x1c\x0e‹ËØÞYÝÚ[‹˜ÛÛKÛ[\vÈÝ[œÝXœØÜšX™K\Ú[\^[\x19CBƒB

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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-24 12:33       ` Ken Brown
@ 2019-07-24 14:32         ` Ken Brown
  2019-07-24 14:42           ` Ken Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2019-07-24 14:32 UTC (permalink / raw)
  To: cygwin

On 7/24/2019 8:33 AM, Ken Brown wrote:
> $ cat getpgrp_test.c
> #include <unistd.h>
> #include <stdio.h>
> #include <errno.h>
> 
> int
> main ()
> {
>     pid_t pid = getpid ();
>     pid_t pgid = getpgid (0);
>     printf ("getpid () = %d, getpgid (0) = %d, errno = %d\n", pid, pgid, errno);
> }
> 
> $ gcc -o getpgrp_test -Wall -g -O0 getpgrp_test.c
> 
> $ ./getpgrp_test.exe
> getpid () = 1424, getpgid (0) = 1424, errno = 0
> 
> $ gdb ./getpgrp_test.exe
> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
> [...]
> (gdb) r
> Starting program: /home/kbrown/Documents/programming/misc_examples/getpgrp_test.exe
> [...]
> getpid () = 1427, getpgid (0) = -1, errno = 0
> [...]
> [Inferior 1 (process 23872) exited normally]
> 
> So getpgid (0) returns -1 without setting errno.  I think this means that
> pinfo::init() didn't fail, but for some reason myself->pgid == -1.

I just ran the above gdb session under strace and found several lines like this:

    25 32828861 [main] gdb 1799 tcsetpgrp: 0 = tcsetpgrp(0, -1)

I haven't looked at the gdb code, but doesn't this mean that gdb is trying to 
set pgrp to -1?  If so, why?  And shouldn't tcsetpgrp return -1 with EINVAL?

Ken

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-24 14:32         ` Ken Brown
@ 2019-07-24 14:42           ` Ken Brown
  2019-07-25 12:12             ` Jon Turney
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2019-07-24 14:42 UTC (permalink / raw)
  To: cygwin

On 7/24/2019 10:32 AM, Ken Brown wrote:
> On 7/24/2019 8:33 AM, Ken Brown wrote:
>> $ cat getpgrp_test.c
>> #include <unistd.h>
>> #include <stdio.h>
>> #include <errno.h>
>>
>> int
>> main ()
>> {
>>      pid_t pid = getpid ();
>>      pid_t pgid = getpgid (0);
>>      printf ("getpid () = %d, getpgid (0) = %d, errno = %d\n", pid, pgid, errno);
>> }
>>
>> $ gcc -o getpgrp_test -Wall -g -O0 getpgrp_test.c
>>
>> $ ./getpgrp_test.exe
>> getpid () = 1424, getpgid (0) = 1424, errno = 0
>>
>> $ gdb ./getpgrp_test.exe
>> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
>> [...]
>> (gdb) r
>> Starting program: /home/kbrown/Documents/programming/misc_examples/getpgrp_test.exe
>> [...]
>> getpid () = 1427, getpgid (0) = -1, errno = 0
>> [...]
>> [Inferior 1 (process 23872) exited normally]
>>
>> So getpgid (0) returns -1 without setting errno.  I think this means that
>> pinfo::init() didn't fail, but for some reason myself->pgid == -1.
> 
> I just ran the above gdb session under strace and found several lines like this:
> 
>      25 32828861 [main] gdb 1799 tcsetpgrp: 0 = tcsetpgrp(0, -1)
> 
> I haven't looked at the gdb code, but doesn't this mean that gdb is trying to
> set pgrp to -1?  If so, why?  And shouldn't tcsetpgrp return -1 with EINVAL?

I just looked at the gdb commit that Jon pointed to earlier in the thread.  It 
adds calls like this:

   result = tcsetpgrp (0, getpgid (inf->pid));

It then checks for errors and takes appropriate action.  But tcsetpgrp returns 
success.

So this all seems to boil down to the fact that Cygwin's tcsetpgrp() doesn't 
check the validity of its second argument.

Ken

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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

* Re: Can't debug bash with gdb 8.2.1-1
  2019-07-24 14:42           ` Ken Brown
@ 2019-07-25 12:12             ` Jon Turney
  0 siblings, 0 replies; 8+ messages in thread
From: Jon Turney @ 2019-07-25 12:12 UTC (permalink / raw)
  To: The Cygwin Mailing List

On 24/07/2019 15:42, Ken Brown wrote:
> On 7/24/2019 10:32 AM, Ken Brown wrote:
>> On 7/24/2019 8:33 AM, Ken Brown wrote:
>>> $ cat getpgrp_test.c
>>> #include <unistd.h>
>>> #include <stdio.h>
>>> #include <errno.h>
>>>
>>> int
>>> main ()
>>> {
>>>       pid_t pid = getpid ();
>>>       pid_t pgid = getpgid (0);
>>>       printf ("getpid () = %d, getpgid (0) = %d, errno = %d\n", pid, pgid, errno);
>>> }
>>>
>>> $ gcc -o getpgrp_test -Wall -g -O0 getpgrp_test.c
>>>
>>> $ ./getpgrp_test.exe
>>> getpid () = 1424, getpgid (0) = 1424, errno = 0
>>>
>>> $ gdb ./getpgrp_test.exe
>>> GNU gdb (GDB) (Cygwin 8.2.1-1) 8.2.1
>>> [...]
>>> (gdb) r
>>> Starting program: /home/kbrown/Documents/programming/misc_examples/getpgrp_test.exe
>>> [...]
>>> getpid () = 1427, getpgid (0) = -1, errno = 0
>>> [...]
>>> [Inferior 1 (process 23872) exited normally]
>>>
>>> So getpgid (0) returns -1 without setting errno.  I think this means that
>>> pinfo::init() didn't fail, but for some reason myself->pgid == -1.
>>
>> I just ran the above gdb session under strace and found several lines like this:
>>
>>       25 32828861 [main] gdb 1799 tcsetpgrp: 0 = tcsetpgrp(0, -1)
>>
>> I haven't looked at the gdb code, but doesn't this mean that gdb is trying to
>> set pgrp to -1?  If so, why?  And shouldn't tcsetpgrp return -1 with EINVAL?

Well spotted.

> I just looked at the gdb commit that Jon pointed to earlier in the thread.  It
> adds calls like this:
> 
>     result = tcsetpgrp (0, getpgid (inf->pid));
> 
> It then checks for errors and takes appropriate action.  But tcsetpgrp returns
> success.
> 
> So this all seems to boil down to the fact that Cygwin's tcsetpgrp() doesn't
> check the validity of its second argument.

Great.  Thanks very much for looking into this.

I guess I need to look into gdb to see if it's trying to use -1 due to 
some other problem, or just expects that to be ignored.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2019-07-25 12:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 14:59 Can't debug bash with gdb 8.2.1-1 Ken Brown
2019-07-23 13:52 ` Jon Turney
2019-07-23 15:42   ` Ken Brown
2019-07-23 18:02     ` Jon Turney
2019-07-24 12:33       ` Ken Brown
2019-07-24 14:32         ` Ken Brown
2019-07-24 14:42           ` Ken Brown
2019-07-25 12:12             ` Jon Turney

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).