Re: [PATCH 1/4] Add sniffer for Cygwin x86_64 core dumps

Jon Turney
2020-08-21T15:25:05Z

On 20/08/2020 23:20, Simon Marchi wrote:
> On 2020-08-12 3:18 p.m., Jon Turney wrote:
>> Similarly to existing i386_cygwin_core_osabi_sniffer()
>>
>> gdb/ChangeLog:
>>
>> 2020-07-01 Jon Turney <jon.turney@dronecode.org.uk>
>>
>> * amd64-windows-tdep.c (amd64_cygwin_core_osabi_sniffer): New.
>> (_initialize_amd64_windows_tdep): Register amd64_cygwin_core_osabi_sniffer.
>
> Hi Jon,
>
> I am trying to test this using these steps:

Wow. Thanks for testing.

> 1. Write a dummy C program that just sleeps in Cygwin, compile it (gcc test.c -g3 -O0) and run it
> 2. Run "dumper" on it

The "dumper" currently shipping in x86_64 Cygwin is utterly broken. (See
[1] et seq.).

If you use "dumper" from the latest snapshot [2], you may have more success

[1]
https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=7dd1b08836e8a7bb37d330995096540afce152a0;hp=38f88601469f4a6ab7cf42e1f076775c99eb17f2
[2] https://cygwin.com/snapshots/

> 3. Load it in GDB (back on my amd64 Linux host)
>
> I get this in step 3:
>
> $ ./gdb --data-directory=data-directory -nx -q ~/a.exe
> Reading symbols from /home/simark/a.exe...
> (gdb) core ~/core.core
> BFD: BFD (GNU Binutils) 2.35.50.20200820 internal error, aborting at /home/simark/src/binutils-gdb/bfd/bfd.c:1311 in _bfd_doprnt_scan
>
> BFD: Please report this bug.
>
> This happens while BFD encounters an error and tries to print this format string:
>
> "%pB: win32pstatus NOTE_INFO_MODULE of size %lu is too small to contain a name of size %zu"
>
> _bfd_doprnt_scan aborts because it doesn't like the z length modifier:
>
> (top-gdb) p ptr[-1]
> $2 = 122 'z'
>
> So there are two issues here:
>
> 1. The actual error, the note being too small for the name. If I go up in
> elfcore_grok_win32pstatus, the name_size doesn't make sense:
>
> (top-gdb) p name_size
> $9 = 4194304
>
> whereas the note size makes sense:
>
> (top-gdb) p note->descsz
> $10 = 1276

This should be resolved by using a fixed "dumper".

> 2. The internal error from trying to print that error message

Clearly, I shouldn't be using '%zu' here, so I'll make a patch to fix
that (once I work out what I should be using :) )