Bug 22757

Summary: internal-error: Register "eax" has an unknown type "int32"
Product: gdb Reporter: Hannes Domani <ssbssa>
Component: win32Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: critical CC: jeremip11, pedro, qiyao, simark, ssbssa
Priority: P2    
Version: 8.1   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Hannes Domani 2018-01-28 18:07:37 UTC
When trying to open any file with the current gdb snapshot (gdb-8.0.91.20180128), I get this error:
> GNU gdb (ssbssa-1) 8.0.91.20180128-git
> Copyright (C) 2018 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-w64-mingw32".
> 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 allocer32.exe...done.
> C:/gcc/src/gdb-8.0.91.20180128/gdb/target-descriptions.c:1261: internal-error: Register "eax" has an unknown type "int32"
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.

This was the stacktrace of internal_error():
> (gdb) bt
> #0  internal_verror (
>     file=file@entry=0x8be4a0 <complete_target_initialization(target_ops*)::__PRETTY_FUNCTION__+800> "C:/gcc/src/gdb-8.0.91.20180128/gdb/target-descriptions.c",
> line=line@entry=1261,
>     fmt=fmt@entry=0x8be514 <complete_target_initialization(target_ops*)::__PRETTY_FUNCTION__+916> "Register \"%s\" has an unknown type \"%s\"",
>     ap=ap@entry=0x815f9ac "d}=\tá}=\t") at C:/gcc/src/gdb-8.0.91.20180128/gdb/utils.c:519
> #1  0x0047dbb7 in internal_error (
>     file=file@entry=0x8be4a0 <complete_target_initialization(target_ops*)::__PRETTY_FUNCTION__+800> "C:/gcc/src/gdb-8.0.91.20180128/gdb/target-descriptions.c",
> line=line@entry=1261,
>     fmt=fmt@entry=0x8be514 <complete_target_initialization(target_ops*)::__PRETTY_FUNCTION__+916> "Register \"%s\" has an unknown type \"%s\"")
>     at C:/gcc/src/gdb-8.0.91.20180128/gdb/common/errors.c:55
> #2  0x00660163 in tdesc_register_type (gdbarch=0x9f062b8, regno=0) at C:/gcc/src/gdb-8.0.91.20180128/gdb/target-descriptions.c:1261
> #3  0x005f8ea2 in init_regcache_descr (gdbarch=0x9f062b8) at C:/gcc/src/gdb-8.0.91.20180128/gdb/regcache.c:98
> #4  0x005776b0 in gdbarch_data (gdbarch=gdbarch@entry=0x9f062b8, data=0x9ee7240) at C:/gcc/src/gdb-8.0.91.20180128/gdb/gdbarch.c:5190
> #5  0x005f9090 in regcache_descr (gdbarch=0x9f062b8) at C:/gcc/src/gdb-8.0.91.20180128/gdb/regcache.c:145
> #6  register_size (gdbarch=gdbarch@entry=0x9f062b8, regnum=regnum@entry=0) at C:/gcc/src/gdb-8.0.91.20180128/gdb/regcache.c:166
> #7  0x005fd5a3 in map_regcache_remote_table (gdbarch=gdbarch@entry=0x9f062b8, regs=0x9f06710) at C:/gcc/src/gdb-8.0.91.20180128/gdb/remote.c:754
> #8  0x005fe458 in init_remote_state (gdbarch=0x9f062b8) at C:/gcc/src/gdb-8.0.91.20180128/gdb/remote.c:825
> #9  0x005776b0 in gdbarch_data (gdbarch=0x9f062b8, data=0x9ee77e8) at C:/gcc/src/gdb-8.0.91.20180128/gdb/gdbarch.c:5190
> #10 0x005ff049 in get_remote_arch_state (gdbarch=<optimized out>) at C:/gcc/src/gdb-8.0.91.20180128/gdb/remote.c:652
> #11 0x00605bdd in get_remote_state () at C:/gcc/src/gdb-8.0.91.20180128/gdb/remote.c:665
> #12 remote_new_objfile (objfile=0x0) at C:/gcc/src/gdb-8.0.91.20180128/gdb/remote.c:13849
> #13 0x005ce783 in generic_observer_notify (args=0x815fb9c, subject=<optimized out>) at C:/gcc/src/gdb-8.0.91.20180128/gdb/observer.c:167
> #14 observer_notify_new_objfile (objfile=objfile@entry=0x0) at ./observer.inc:582
> #15 0x00639ae8 in clear_symtab_users (add_flags=...) at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:2898
> #16 0x0063a0cd in finish_new_objfile (add_flags=..., objfile=0x9f19540) at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:1087
> #17 symbol_file_add_with_addrs (abfd=<optimized out>, name=name@entry=0x1e1578 "allocer32.exe", add_flags=..., add_flags@entry=..., addrs=<optimized out>,
>     addrs@entry=0x0, flags=flags@entry=..., parent=parent@entry=0x0) at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:1219
> #18 0x0063a540 in symbol_file_add_from_bfd (parent=0x0, flags=..., addrs=0x0, add_flags=..., name=0x1e1578 "allocer32.exe", abfd=<optimized out>)
>     at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:1264
> #19 symbol_file_add (name=name@entry=0x1e1578 "allocer32.exe", add_flags=add_flags@entry=..., addrs=addrs@entry=0x0, flags=...)
>     at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:1277
> #20 0x0063a5e2 in symbol_file_add_main_1 (args=0x1e1578 "allocer32.exe", add_flags=..., flags=...) at C:/gcc/src/gdb-8.0.91.20180128/gdb/symfile.c:1300
> #21 0x005b8c18 in catch_command_errors (command=command@entry=0x5b89c0 <symbol_file_add_main_adapter(char const*, int)>,
>     arg=arg@entry=0x1e1578 "allocer32.exe", from_tty=1) at C:/gcc/src/gdb-8.0.91.20180128/gdb/main.c:382
> #22 0x005b999e in captured_main_1 (context=<optimized out>) at C:/gcc/src/gdb-8.0.91.20180128/gdb/main.c:1053
> #23 captured_main (data=<optimized out>) at C:/gcc/src/gdb-8.0.91.20180128/gdb/main.c:1150
> #24 gdb_main (args=<optimized out>, args@entry=0x815feb4) at C:/gcc/src/gdb-8.0.91.20180128/gdb/main.c:1176
> #25 0x007f9b00 in main (argc=2, argv=0x1e1518) at C:/gcc/src/gdb-8.0.91.20180128/gdb/gdb.c:32
Comment 1 Yao Qi 2018-01-29 17:27:10 UTC
I tried both gdb snapshot (gdb-8.0.91.20180128) and gdb trunk on x86_linux, but can't reproduce it.

$ file ../../../native-i686-w64-mingw32/gdb/gdb.exe 
../../../native-i686-w64-mingw32/gdb/gdb.exe: PE32 executable (console) Intel 80386, for MS Windows
$ ./gdb ../../../native-i686-w64-mingw32/gdb/gdb.exe
GNU gdb (GDB) 8.1.50.20180128-git
Copyright (C) 2018 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 "--host=x86_64-pc-linux-gnu --target=i686-w64-mingw32".
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 ../../../native-i686-w64-mingw32/gdb/gdb.exe...done.

The only difference is that my host is Linux, and your host is Windows.
Comment 2 Hannes Domani 2018-01-29 19:26:20 UTC
Seems to be a problem on my side.

It looks like this variable initialization doesn't work:
> static tdesc_type_builtin tdesc_predefined_types[] =
> {
>   { "bool", TDESC_TYPE_BOOL },
>   { "int8", TDESC_TYPE_INT8 },
>   { "int16", TDESC_TYPE_INT16 },
>   { "int32", TDESC_TYPE_INT32 },
>   { "int64", TDESC_TYPE_INT64 },
>   { "int128", TDESC_TYPE_INT128 },
>   { "uint8", TDESC_TYPE_UINT8 },
>   { "uint16", TDESC_TYPE_UINT16 },
>   { "uint32", TDESC_TYPE_UINT32 },
>   { "uint64", TDESC_TYPE_UINT64 },
>   { "uint128", TDESC_TYPE_UINT128 },
>   { "code_ptr", TDESC_TYPE_CODE_PTR },
>   { "data_ptr", TDESC_TYPE_DATA_PTR },
>   { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
>   { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
>   { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
>   { "i387_ext", TDESC_TYPE_I387_EXT }
> };
It's empty in runtime:
> (gdb) p tdesc_predefined_types[0]@10
> $6 = {{<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>},
>   {<tdesc_type> = {<tdesc_element> = {_vptr.tdesc_element = 0x0}, name = {static npos = 4294967295,
>         _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}, _M_string_length = 0,
>         {_M_local_buf = '\000' <repeats 15 times>, _M_allocated_capacity = 0}}, kind = TDESC_TYPE_BOOL}, <No data fields>}}
I'm not sure how I broke this.
Comment 3 Simon Marchi 2018-01-29 20:00:04 UTC
It seems like the constructor of tdesc_type_builtin doesn't get called for the elements of this array.  Can you confirm this, maybe by gdb'ing gdb and sticking a breakpoint on the constructor, or just putting a printf in it?
Comment 4 Hannes Domani 2018-01-29 20:06:54 UTC
(In reply to Simon Marchi from comment #3)
> It seems like the constructor of tdesc_type_builtin doesn't get called for
> the elements of this array.  Can you confirm this, maybe by gdb'ing gdb and
> sticking a breakpoint on the constructor, or just putting a printf in it?

Yes, I can confirm this, the constructor is never called.
Comment 5 Simon Marchi 2018-01-29 20:52:36 UTC
Did you make a clean build?  I recall somebody on IRC a while ago that had the same problem, and it went away when they did a "make clean; make".

Otherwise, that would be either a compiler/linker problem, or us exploiting an undefined behavior.  You would need to look into the generated code to see what happens (though if the calls to the constructor are not generated, it's hard to look for something that isn't there).  But if it's indeed a compiler/linker problem, maybe you could make a small reproducer and file a bug with gcc or ld (I assume you are using gcc).

As a workaround, you could try calling the constructor by hand for each element in _initialize_target_descriptions at the bottom of the file (this function is ran at startup):

  new (&tdesc_predefined_types[0]) tdesc_type_builtin ("bool", TDESC_TYPE_BOOL);
  new (&tdesc_predefined_types[1]) tdesc_type_builtin ("int8", TDESC_TYPE_INT8);
  ...
  etc
Comment 6 Hannes Domani 2018-01-29 21:01:02 UTC
(In reply to Simon Marchi from comment #5)
> Did you make a clean build?  I recall somebody on IRC a while ago that had
> the same problem, and it went away when they did a "make clean; make".
Yes, I even started from scratch again today, same result.

> Otherwise, that would be either a compiler/linker problem, or us exploiting
> an undefined behavior.  You would need to look into the generated code to
> see what happens (though if the calls to the constructor are not generated,
> it's hard to look for something that isn't there).  But if it's indeed a
> compiler/linker problem, maybe you could make a small reproducer and file a
> bug with gcc or ld (I assume you are using gcc).
I will see if I can make a small reproducer.

> As a workaround, you could try calling the constructor by hand for each
> element in _initialize_target_descriptions at the bottom of the file (this
> function is ran at startup):
> 
>   new (&tdesc_predefined_types[0]) tdesc_type_builtin ("bool",
> TDESC_TYPE_BOOL);
>   new (&tdesc_predefined_types[1]) tdesc_type_builtin ("int8",
> TDESC_TYPE_INT8);
>   ...
>   etc
Interesting idea, I might try that (tomorrow).
Comment 7 Pedro Alves 2018-01-30 13:01:48 UTC
(In reply to Simon Marchi from comment #5)
> Did you make a clean build?  I recall somebody on IRC a while ago that had
> the same problem, and it went away when they did a "make clean; make".
> 

I think it went away by using an older linker:

 [January 12, 2018] <user>    https://paste.ubuntu.com/26373570/
 [January 12, 2018] <user>    Oh, I know what my problem is
 [January 12, 2018] <user>    I accidentally left the latest binutils as a /usr/bin/ld
 [January 12, 2018] <user>    and changing it back works :)
Comment 8 Hannes Domani 2018-01-30 17:03:03 UTC
Yes, an older binutils works.

I've opened a ld bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22762