Bug 16201 - internal error on a cygwin program linked against a DLL with no .data section
Summary: internal error on a cygwin program linked against a DLL with no .data section
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.6
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-21 19:29 UTC by Stas Maximov
Modified: 2023-12-09 12:46 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
a DLL with no .data section (5.47 MB, application/octet-stream)
2013-11-21 20:37 UTC, Stas Maximov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stas Maximov 2013-11-21 19:29:22 UTC
An internal error in gdb prevents debugging any Cygwin program linked against a DLL without a .data section:

/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

Environment:

$ uname -a
CYGWIN_NT-6.1-WOW64 my-PC 1.7.25(0.270/5/3) 2013-08-31 20:39 i686 Cygwin


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-pc-cygwin/4.8.2/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.2-1/src/gcc-4.8.2/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.2-1/src/gcc-4.8.2 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libjava --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib
Thread model: posix
gcc version 4.8.2 (GCC)



How-To-Repeat:

$ cat test1.c
int icudt49_dat(int);
int main()
{
    icudt49_dat(0);
    return 0;
}


$ gcc -g -L. -o test1 test1.c -licudt49


$ gdb --args test1
GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
..
Reading symbols from /home/user/test/test1...done.
(gdb) ru
Starting program: /home/user/test/test1
[New Thread 12768.0x1ce4]
/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n


$ ldd test1.exe
        ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x77320000)
        kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x76950000)
        KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll (0x753d0000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
        icudt49.dll => /home/user/test/icudt49.dll (0x62c40000)


$ objdump -h test1.exe

test1.exe:     file format pei-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000768  00401000  00401000  00000400  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
  1 .data         000000d8  00402000  00402000  00000c00  2**5
                  CONTENTS, ALLOC, LOAD, DATA
  2 .rdata        00000018  00403000  00403000  00000e00  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .eh_frame     0000036c  00404000  00404000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .bss          00000110  00405000  00405000  00000000  2**5
                  ALLOC
  5 .idata        00000248  00406000  00406000  00001400  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .debug_aranges 00000198  00407000  00407000  00001800  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_info   00006366  00408000  00408000  00001a00  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_abbrev 00000c33  0040f000  0040f000  00007e00  2**0
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_line   00000cb5  00410000  00410000  00008c00  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_str    00000043  00411000  00411000  00009a00  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_loc    0000027f  00412000  00412000  00009c00  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_ranges 00000018  00413000  00413000  0000a000  2**0
                  CONTENTS, READONLY, DEBUGGING


$ objdump -h icudt49.dll

icudt49.dll:     file format pei-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .rdata        0111f4fa  10001000  10001000  00000400  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .rsrc         00000458  11121000  11121000  0111fa00  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
Comment 1 Stas Maximov 2013-11-21 20:37:56 UTC
Created attachment 7289 [details]
a DLL with no .data section

This is a DLL without .data section used to reproduce the bug
Comment 2 Tom Tromey 2013-11-21 21:30:20 UTC
I tried it with "gdb icudt49.dll" using git master gdb,
and it worked fine for me.
Does this test cause your gdb to fail?
Given the location of the error, I would expect so.

If your gdb fails but mine does not, then the bug has been fixed.

If your gdb does not fail then I'd like a self-contained
test case.  I don't have a cygwin box on which to try this;
but it ought to be host-independent anyhow, since it occurs
in symbol reading...
Comment 3 Stas Maximov 2013-11-21 21:36:10 UTC
Tom, thanks for the quick response.

"gdb icudt49.dll" is not the test case. 

Here is the test case:

$ cat test1.c
int icudt49_dat(int);
int main()
{
    icudt49_dat(0);
    return 0;
}
$ gcc -g -L. -o test1 test1.c -licudt49
$ $ gdb --args test1
(gdb) run
...
/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
...

Stas.
Comment 4 Tom Tromey 2013-11-21 21:39:04 UTC
(In reply to Stas Maximov from comment #3)
> Tom, thanks for the quick response.
> 
> "gdb icudt49.dll" is not the test case. 
> 
> Here is the test case:
> 
> $ cat test1.c
> int icudt49_dat(int);
> int main()
> {
>     icudt49_dat(0);
>     return 0;
> }
> $ gcc -g -L. -o test1 test1.c -licudt49
> $ $ gdb --args test1
> (gdb) run

I can't do this step.

> /netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data
> not initialized
> ...

Can you debug gdb and see what objfile is being read when this assertion hits?
Or just try "gdb icudt49.dll"?
Comment 5 Stas Maximov 2013-11-21 21:54:35 UTC
This appears to be COFF-PE specific. It is not likely to be repeatable on a platform other than 32-bit Cygwin.

If it helps, here is the result of coff-pe-read trace:

...
$ gdb test1
(gdb) set debug coff-pe-read 1
(gdb) run
Starting program: /home/user/test/test1.exe 
[New Thread 8076.0x29e8]
Export RVA for dll "/cygdrive/c/Windows/system32/ntdll.dll" is in section ".text"
DLL "ntdll" has 2025 export entries, base=1
Finished reading "ntdll", exports 2025, forwards 0, total 2025/2025.
Export RVA for dll "/cygdrive/c/Windows/syswow64/kernel32.dll" is in section ".text"
DLL "KERNEL32" has 1364 export entries, base=1
Unable to find function "AddDllDirectory" in dll "api-ms-win-core-libraryloader-l1-1-0", forward of "AddDllDirectory" in dll "KERNEL32"
Unable to find function "CreateRemoteThreadEx" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "CreateRemoteThreadEx" in dll "KERNEL32"
Unable to find function "DeleteProcThreadAttributeList" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "DeleteProcThreadAttributeList" in dll "KERNEL32"
Unable to find function "GetLogicalProcessorInformationEx" in dll "api-ms-win-core-sysinfo-l1-1-0", forward of "GetLogicalProcessorInformationEx" in dll "KERNEL32"
Unable to find function "InitializeProcThreadAttributeList" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "InitializeProcThreadAttributeList" in dll "KERNEL32"
Unable to find function "OpenProcessToken" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "OpenProcessToken" in dll "KERNEL32"
Unable to find function "OpenThreadToken" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "OpenThreadToken" in dll "KERNEL32"
Unable to find function "RemoveDllDirectory" in dll "api-ms-win-core-libraryloader-l1-1-0", forward of "RemoveDllDirectory" in dll "KERNEL32"
Unable to find function "SetDefaultDllDirectories" in dll "api-ms-win-core-libraryloader-l1-1-0", forward of "SetDefaultDllDirectories" in dll "KERNEL32"
Unable to find function "SetThreadToken" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "SetThreadToken" in dll "KERNEL32"
Unable to find function "SetWaitableTimerEx" in dll "api-ms-win-core-threadpool-l1-1-0", forward of "SetWaitableTimerEx" in dll "KERNEL32"
Unable to find function "SystemTimeToTzSpecificLocalTimeEx" in dll "kernelbase", forward of "SystemTimeToTzSpecificLocalTimeEx" in dll "KERNEL32"
Unable to find function "TzSpecificLocalTimeToSystemTimeEx" in dll "kernelbase", forward of "TzSpecificLocalTimeToSystemTimeEx" in dll "KERNEL32"
Unable to find function "UpdateProcThreadAttribute" in dll "api-ms-win-core-processthreads-l1-1-0", forward of "UpdateProcThreadAttribute" in dll "KERNEL32"
Finished reading "KERNEL32", exports 1282, forwards 68, total 1350/1364.
Export RVA for dll "/cygdrive/c/Windows/syswow64/KERNELBASE.dll" is in section ".text"
DLL "KERNELBASE" has 633 export entries, base=1
Finished reading "KERNELBASE", exports 576, forwards 57, total 633/633.
Export RVA for dll "/home/user/test/icudt49.dll" is in section ".rdata"
DLL "icudt49" has 1 export entries, base=1
/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

/netrel/src/gdb-7.6.50-4/gdb/minsyms.c:885: internal-error: sect_index_data not initialized
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Comment 6 Tom Tromey 2013-11-21 22:01:05 UTC
(In reply to Stas Maximov from comment #5)
> This appears to be COFF-PE specific. It is not likely to be repeatable on a
> platform other than 32-bit Cygwin.

Except the crash occurs in the symbol reader, which is not host-dependent.
So it is likely to be reproducible if we knew which objfile was causing it.

> If it helps, here is the result of coff-pe-read trace:

It would help if you did one of the two things I asked for in comment #4.
Thanks.
Comment 7 Stas Maximov 2013-11-21 22:04:16 UTC
>> If it helps, here is the result of coff-pe-read trace:
> It would help if you did one of the two things I asked for in comment #4.

Sorry, here we go:

$ gdb icudt49.dll 
GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
..
Reading symbols from /home/user/test/icudt49.dll...(no debugging symbols found)...done.
(gdb)
Comment 8 Tom Tromey 2013-11-22 15:58:18 UTC
(In reply to Stas Maximov from comment #7)
> >> If it helps, here is the result of coff-pe-read trace:
> > It would help if you did one of the two things I asked for in comment #4.
> 
> Sorry, here we go:
> 
> $ gdb icudt49.dll 

Ok, that's too bad :)

The next thing that would be good is a backtrace of gdb at the failure.
And, if possible, find the objfile causing the crash.
Comment 9 Stas Maximov 2013-11-22 23:48:45 UTC
Tom,

I am sorry, I can not configure/build debug version of gdb on Cygwin. The last hurdle looks like this:

...
checking for Tcl configuration... found /usr/lib/tclConfig.sh
checking for Tk configuration... found /usr/lib/tkConfig.sh
checking for existence of /usr/lib/tclConfig.sh... loading
checking for Tcl private headers... configure: error: could not find private Tcl headers
...

Any other way to get backtrace using Cygwin pre-built gdb?

Stas.
Comment 10 Keith Seitz 2013-11-23 17:23:00 UTC
(In reply to Stas Maximov from comment #9)
> ...
> checking for Tcl configuration... found /usr/lib/tclConfig.sh
> checking for Tk configuration... found /usr/lib/tkConfig.sh
> checking for existence of /usr/lib/tclConfig.sh... loading
> checking for Tcl private headers... configure: error: could not find private
> Tcl headers
> ...

It looks like your build is trying to build Insight using system-supplied Tcl, Tk, Itcl, and Iwidgets. This is not supported on Windows (Cygwin/MinGW).

Pass "--disable-gdbtk" to configure to disable this.
Comment 11 Stas Maximov 2013-11-25 18:30:46 UTC
Hi Tom, thanks to Keith's suggestion, here is the backtrace for the point of failure:

$ gdb --args /usr/local/bin/gdb test1.exe 
GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
..
Reading symbols from /usr/local/bin/gdb...done.
(gdb) b internal_error
Breakpoint 1 at 0x5cb530: file ../../gdb-7.6.50-4/gdb/utils.c, line 839.
(gdb) ru
Starting program: /usr/local/bin/gdb test1.exe
[New Thread 14808.0x1d60]
[New Thread 14808.0x3b6c]
GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
..
Reading symbols from /home/user/test/test1.exe...done.
(gdb) [New Thread 14808.0xb44]
[New Thread 14808.0x3514]
run
run
Starting program: /home/user/test/test1.exe 
[New Thread 14704.0x2bcc]

Breakpoint 1, internal_error (file=file@entry=0x729c38 <__PRETTY_FUNCTION__.21996+1640> "../../gdb-7.6.50-4/gdb/minsyms.c", 
    line=line@entry=885, string=0x729dd8 <__PRETTY_FUNCTION__.21996+2056> "sect_index_data not initialized")
    at ../../gdb-7.6.50-4/gdb/utils.c:839
839     {
(gdb) bt
#0  internal_error (file=file@entry=0x729c38 <__PRETTY_FUNCTION__.21996+1640> "../../gdb-7.6.50-4/gdb/minsyms.c", 
    line=line@entry=885, string=0x729dd8 <__PRETTY_FUNCTION__.21996+2056> "sect_index_data not initialized")
    at ../../gdb-7.6.50-4/gdb/utils.c:839
#1  0x00545c86 in prim_record_minimal_symbol (name=name@entry=0x801a7f38 "icudt49!icudt49_dat", 
    address=address@entry=1645875200, ms_type=mst_data, objfile=objfile@entry=0x803e8c60)
    at ../../gdb-7.6.50-4/gdb/minsyms.c:885
#2  0x005501ce in add_pe_exported_sym (sym_name=0x8019f156 "icudt49_dat", func_rva=<optimized out>, ordinal=<optimized out>, 
    section_data=0x801a7e8c, dll_name=dll_name@entry=0x8019f14a "icudt49", objfile=0x803e8c60)
    at ../../gdb-7.6.50-4/gdb/coff-pe-read.c:178
#3  0x00550ad5 in read_pe_exported_syms (objfile=objfile@entry=0x803e8c60) at ../../gdb-7.6.50-4/gdb/coff-pe-read.c:585
#4  0x0054fbf2 in coff_symtab_read (objfile=0x803e8c60, nsyms=0, symtab_offset=<optimized out>)
    at ../../gdb-7.6.50-4/gdb/coffread.c:1187
#5  coff_symfile_read (objfile=0x803e8c60, symfile_flags=8) at ../../gdb-7.6.50-4/gdb/coffread.c:646
#6  0x004e8c9b in read_symbols (objfile=objfile@entry=0x803e8c60, add_flags=add_flags@entry=8)
    at ../../gdb-7.6.50-4/gdb/symfile.c:830
#7  0x004e8879 in syms_from_objfile_1 (add_flags=8, addrs=0x80166a40, objfile=0x803e8c60)
    at ../../gdb-7.6.50-4/gdb/symfile.c:998
#8  syms_from_objfile (add_flags=8, addrs=0x80166a40, objfile=0x803e8c60) at ../../gdb-7.6.50-4/gdb/symfile.c:1014
#9  symbol_file_add_with_addrs (abfd=<optimized out>, add_flags=8, addrs=addrs@entry=0x80166a40, flags=2, parent=0x0)
    at ../../gdb-7.6.50-4/gdb/symfile.c:1109
#10 0x004e8d31 in symbol_file_add_from_bfd (abfd=<optimized out>, add_flags=<optimized out>, add_flags@entry=8, 
    addrs=addrs@entry=0x80166a40, flags=flags@entry=2, parent=parent@entry=0x0) at ../../gdb-7.6.50-4/gdb/symfile.c:1196
#11 0x005dd5fe in solib_read_symbols (so=so@entry=0x80199200, flags=flags@entry=8) at ../../gdb-7.6.50-4/gdb/solib.c:611
#12 0x005dda91 in solib_add (pattern=pattern@entry=0x0, from_tty=from_tty@entry=0, 
    target=target@entry=0x877cc0 <current_target>, readsyms=1) at ../../gdb-7.6.50-4/gdb/solib.c:922
#13 0x004f636b in post_create_inferior (target=0x877cc0 <current_target>, from_tty=from_tty@entry=0)
    at ../../gdb-7.6.50-4/gdb/infcmd.c:451
#14 0x004f69c7 in run_command_1 (args=0x0, from_tty=<optimized out>, tbreak_at_main=<optimized out>)
    at ../../gdb-7.6.50-4/gdb/infcmd.c:603
#15 0x005c773e in execute_command (p=<optimized out>, p@entry=0x8003acf8 "", from_tty=1) at ../../gdb-7.6.50-4/gdb/top.c:478
#16 0x00516238 in command_handler (command=0x8003acf8 "") at ../../gdb-7.6.50-4/gdb/event-top.c:433
#17 0x005165c1 in command_line_handler (rl=0x80161e60 "") at ../../gdb-7.6.50-4/gdb/event-top.c:631
#18 0x0060987e in rl_callback_read_char () at ../../gdb-7.6.50-4/readline/callback.c:220
#19 0x005162a8 in rl_callback_read_char_wrapper (client_data=0x0) at ../../gdb-7.6.50-4/gdb/event-top.c:164
#20 0x0051484e in handle_file_event (data=data@entry=...) at ../../gdb-7.6.50-4/gdb/event-loop.c:768
#21 0x00514fa4 in process_event () at ../../gdb-7.6.50-4/gdb/event-loop.c:342
#22 0x005152a7 in gdb_do_one_event () at ../../gdb-7.6.50-4/gdb/event-loop.c:394
#23 0x005154ee in start_event_loop () at ../../gdb-7.6.50-4/gdb/event-loop.c:431
#24 0x0050f282 in captured_command_loop (data=0x0) at ../../gdb-7.6.50-4/gdb/main.c:260
#25 0x0050d959 in catch_errors (func=func@entry=0x50f270 <captured_command_loop>, func_args=func_args@entry=0x0, 
    errstring=errstring@entry=0x70e766 <__PRETTY_FUNCTION__.13081+203> "", mask=mask@entry=6)
    at ../../gdb-7.6.50-4/gdb/exceptions.c:546
#26 0x00510089 in captured_main (data=0x2dbabe0) at ../../gdb-7.6.50-4/gdb/main.c:1057
#27 0x0050d959 in catch_errors (func=func@entry=0x50f540 <captured_main>, func_args=func_args@entry=0x2dbabe0, 
    errstring=errstring@entry=0x70e766 <__PRETTY_FUNCTION__.13081+203> "", mask=mask@entry=6)
    at ../../gdb-7.6.50-4/gdb/exceptions.c:546
#28 0x005105b0 in gdb_main (args=args@entry=0x2dbabe0) at ../../gdb-7.6.50-4/gdb/main.c:1066
#29 0x006a4bc8 in main (argc=2, argv=0x2dbac1c) at ../../gdb-7.6.50-4/gdb/gdb.c:34
(gdb)
Comment 12 Tom Tromey 2013-11-25 21:33:30 UTC
Thanks for the update.

Looking at your stack trace and mine, one difference is that
mine passes 0 for "addrs" to syms_from_objfile.
This makes me wonder what code path avoids default_symfile_offsets
and thus the "cleanup" code in init_objfile_sect_indices.

Two thoughts - one, try git master, in case changes in this area
helped; two, step through syms_from_objfile.

Unfortunately it seems you were correct that a windows box is
needed to easily reproduce.  Sorry about that.
Comment 13 Tom Tromey 2013-11-25 21:56:05 UTC
Ok, maybe I see.  I was able to reproduce it with

add-symbol-file icudt49.dll 0x0 -s .rdata 0x10000 -s rsrc 0x20000

This avoids the cleanup code in the obvious way (duh!) - 
at the end of init_objfile_sect_indices there is a non-zero
offset, so this code is never used.

Also, I tried with git master and it still fails there.
Comment 14 Stas Maximov 2013-11-26 00:21:37 UTC
Confirmed the problem on 7.6.50.20131125-cvs snapshot:

$ gdb --args /usr/local/bin/gdb test1.exe 
GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
..
Reading symbols from /usr/local/bin/gdb...done.
(gdb) b internal_error
Breakpoint 1 at 0x5d2ec0: file ../../gdb-7.6.50.20131125/gdb/utils.c, line 826.
(gdb) ru
Starting program: /usr/local/bin/gdb test1.exe
[New Thread 11624.0x1978]
[New Thread 11624.0x48c]
GNU gdb (GDB) 7.6.50.20131125-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test1.exe...done.
(gdb) [New Thread 11624.0x3990]
[New Thread 11624.0x2aa0]
ru
ru
Starting program: /home/user/test/test1.exe 
[New Thread 7868.0x2664]

Breakpoint 1, internal_error (
    file=file@entry=0x734958 <__PRETTY_FUNCTION__.22235+1649> "../../gdb-7.6.50.20131125/gdb/minsyms.c", line=line@entry=890, 
    string=0x734ad8 <__PRETTY_FUNCTION__.22235+2033> "sect_index_data not initialized")
    at ../../gdb-7.6.50.20131125/gdb/utils.c:826
826     {
(gdb) bt
#0  internal_error (file=file@entry=0x734958 <__PRETTY_FUNCTION__.22235+1649> "../../gdb-7.6.50.20131125/gdb/minsyms.c", 
    line=line@entry=890, string=0x734ad8 <__PRETTY_FUNCTION__.22235+2033> "sect_index_data not initialized")
    at ../../gdb-7.6.50.20131125/gdb/utils.c:826
#1  0x0054ae16 in prim_record_minimal_symbol (name=name@entry=0x8019db78 "icudt49!icudt49_dat", 
    address=address@entry=1585713152, ms_type=mst_data, objfile=objfile@entry=0x8027a9c8)
    at ../../gdb-7.6.50.20131125/gdb/minsyms.c:890
#2  0x0055538e in add_pe_exported_sym (sym_name=0x8019dcde "icudt49_dat", func_rva=<optimized out>, ordinal=<optimized out>, 
    section_data=0x8019dab4, dll_name=dll_name@entry=0x8019dcd2 "icudt49", objfile=0x8027a9c8)
    at ../../gdb-7.6.50.20131125/gdb/coff-pe-read.c:178
#3  0x00555c95 in read_pe_exported_syms (objfile=objfile@entry=0x8027a9c8) at ../../gdb-7.6.50.20131125/gdb/coff-pe-read.c:585
#4  0x00554da6 in coff_symtab_read (objfile=0x8027a9c8, nsyms=0, symtab_offset=<optimized out>)
    at ../../gdb-7.6.50.20131125/gdb/coffread.c:1200
#5  coff_symfile_read (objfile=0x8027a9c8, symfile_flags=8) at ../../gdb-7.6.50.20131125/gdb/coffread.c:659
#6  0x004eb05b in read_symbols (objfile=objfile@entry=0x8027a9c8, add_flags=add_flags@entry=8)
    at ../../gdb-7.6.50.20131125/gdb/symfile.c:839
#7  0x004eac49 in syms_from_objfile_1 (add_flags=8, addrs=0x8017bc40, objfile=0x8027a9c8)
    at ../../gdb-7.6.50.20131125/gdb/symfile.c:1014
#8  syms_from_objfile (add_flags=8, addrs=<optimized out>, objfile=0x8027a9c8) at ../../gdb-7.6.50.20131125/gdb/symfile.c:1030
#9  symbol_file_add_with_addrs (abfd=<optimized out>, name=<optimized out>, add_flags=8, addrs=0x8017bc40, flags=2, 
    parent=0x0) at ../../gdb-7.6.50.20131125/gdb/symfile.c:1127
#10 0x004eb10b in symbol_file_add_from_bfd (abfd=<optimized out>, name=<optimized out>, 
    name@entry=0x80199a10 "/home/user/test/icudt49.dll", add_flags=<optimized out>, add_flags@entry=8, 
    addrs=addrs@entry=0x8017bc40, flags=flags@entry=2, parent=parent@entry=0x0)
    at ../../gdb-7.6.50.20131125/gdb/symfile.c:1216
#11 0x005e51d7 in solib_read_symbols (so=so@entry=0x80199808, flags=flags@entry=8)
    at ../../gdb-7.6.50.20131125/gdb/solib.c:630
#12 0x005e5671 in solib_add (pattern=pattern@entry=0x0, from_tty=from_tty@entry=0, 
    target=target@entry=0x8856a0 <current_target>, readsyms=1) at ../../gdb-7.6.50.20131125/gdb/solib.c:941
#13 0x004f9fbb in post_create_inferior (target=0x8856a0 <current_target>, from_tty=from_tty@entry=0)
    at ../../gdb-7.6.50.20131125/gdb/infcmd.c:455
#14 0x004fa617 in run_command_1 (args=0x0, from_tty=<optimized out>, tbreak_at_main=<optimized out>)
    at ../../gdb-7.6.50.20131125/gdb/infcmd.c:607
#15 0x005cf0ee in execute_command (p=<optimized out>, p@entry=0x8003acf8 "", from_tty=1)
    at ../../gdb-7.6.50.20131125/gdb/top.c:468
#16 0x00519f88 in command_handler (command=0x8003acf8 "") at ../../gdb-7.6.50.20131125/gdb/event-top.c:435
#17 0x0051a3e0 in command_line_handler (rl=0x80039878 "") at ../../gdb-7.6.50.20131125/gdb/event-top.c:632
#18 0x0061165e in rl_callback_read_char () at ../../gdb-7.6.50.20131125/readline/callback.c:220
#19 0x00519ff8 in rl_callback_read_char_wrapper (client_data=0x0) at ../../gdb-7.6.50.20131125/gdb/event-top.c:164
#20 0x0051859e in handle_file_event (data=data@entry=...) at ../../gdb-7.6.50.20131125/gdb/event-loop.c:768
#21 0x00518cf4 in process_event () at ../../gdb-7.6.50.20131125/gdb/event-loop.c:342
#22 0x00518ff7 in gdb_do_one_event () at ../../gdb-7.6.50.20131125/gdb/event-loop.c:394
#23 0x0051923e in start_event_loop () at ../../gdb-7.6.50.20131125/gdb/event-loop.c:431
#24 0x005128e8 in current_interp_command_loop () at ../../gdb-7.6.50.20131125/gdb/interps.c:327
#25 0x00512fb2 in captured_command_loop (data=0x0) at ../../gdb-7.6.50.20131125/gdb/main.c:267
#26 0x00511619 in catch_errors (func=func@entry=0x512fa0 <captured_command_loop>, func_args=func_args@entry=0x0, 
    errstring=errstring@entry=0x71801c <__PRETTY_FUNCTION__.13085+214> "", mask=mask@entry=RETURN_MASK_ALL)
    at ../../gdb-7.6.50.20131125/gdb/exceptions.c:524
#27 0x00513da4 in captured_main (data=0x2e4abe0) at ../../gdb-7.6.50.20131125/gdb/main.c:1067
#28 0x00511619 in catch_errors (func=func@entry=0x513280 <captured_main>, func_args=func_args@entry=0x2e4abe0, 
    errstring=errstring@entry=0x71801c <__PRETTY_FUNCTION__.13085+214> "", mask=mask@entry=RETURN_MASK_ALL)
    at ../../gdb-7.6.50.20131125/gdb/exceptions.c:524
#29 0x005142d0 in gdb_main (args=args@entry=0x2e4abe0) at ../../gdb-7.6.50.20131125/gdb/main.c:1076
#30 0x006ac8c8 in main (argc=2, argv=0x2e4ac1c) at ../../gdb-7.6.50.20131125/gdb/gdb.c:34
(gdb)
Comment 15 Pierre Muller 2013-11-26 02:20:11 UTC
  This problem might indeed have been introduced by
my patch to improve reading of export sections in DLLs.

  The problem is that minimal symbols only recognizes
three symbol types in enum ms_type:
  mst_text, mst_data and mst_unknown
but objfile header
itself has four special sections:
sect_index_text, sect_index_data, sect_index_bss and sect_index_rodata

See:
https://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/coff-pe-read.c?rev=1.19&content-type=text/x-cvsweb-markup&cvsroot=src

The following patch seems to work for me,
but I am not sure it is correct...

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 91ee3f6..954c457 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -466,6 +466,13 @@ read_pe_exported_syms (struct objfile *objfile)
        {
          section_data[sectix].rva_start = vaddr;
          section_data[sectix].rva_end = vaddr + vsize;
+         /* Force sect_index, even if it was already set before.  */
+         if (sectix == PE_SECTION_INDEX_TEXT)
+           objfile->sect_index_text = sectix;
+         if (sectix == PE_SECTION_INDEX_DATA)
+           objfile->sect_index_data = sectix;
+         if (sectix == PE_SECTION_INDEX_BSS)
+           objfile->sect_index_bss = sectix;
        }
       else
        {
@@ -480,11 +487,23 @@ read_pe_exported_syms (struct objfile *objfile)
          section_data[otherix].rva_end = vaddr + vsize;
          section_data[otherix].vma_offset = 0;
          if (characteristics & IMAGE_SCN_CNT_CODE)
-           section_data[otherix].ms_type = mst_text;
+           {
+             section_data[otherix].ms_type = mst_text;
+             if (objfile->sect_index_text == -1)
+               objfile->sect_index_text = otherix;
+           }
          else if (characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
-           section_data[otherix].ms_type = mst_data;
+           {
+             section_data[otherix].ms_type = mst_data;
+             if (objfile->sect_index_data == -1)
+             objfile->sect_index_data = otherix;
+           }
          else if (characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-           section_data[otherix].ms_type = mst_bss;
+           {
+             section_data[otherix].ms_type = mst_bss;
+             if (objfile->sect_index_bss == -1)
+               objfile->sect_index_bss = otherix;
+           }
          else
            section_data[otherix].ms_type = mst_unknown;
          otherix++;


In the hope this helps,

Pierre Muller

PS: Is it "normal" that the program generates
a SIGSEGV?
Comment 16 Stas Maximov 2013-11-26 03:13:36 UTC
Pierre, thank you for the patch. It works for me.

> PS: Is it "normal" that the program generates a SIGSEGV?
Yes. The test case was minimized to the point of SIGSEGV. The original "bigger brother" of the test does not do SIGSEGV, but also works well with the patch.
Comment 17 Stas Maximov 2013-11-27 00:04:09 UTC
Could anyone estimate if/when this change makes it to the nearest release, please?
Comment 18 Stas Maximov 2013-12-21 00:49:11 UTC
Can anyone get the proposed patch into the next release?
What can I do to facilitate that?
Comment 19 asmwarrior 2013-12-21 01:02:05 UTC
Hi, Stas Maximov. There are many discussions in the gdb patches maillist, you can read them, see: https://sourceware.org/ml/gdb-patches/2013-12/msg00851.html

Yuanhui Zhang
Comment 20 Hannes Domani 2023-12-09 12:46:37 UTC
Wasn't this bug fixed by this commit?:
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=f93ba80c9848d3cf4bd2a3d05d9c1f86239b60ef