Bug 18624 - GDB on windows with golang: buildsym_init Assertion `free_pendings == NULL` failed.
Summary: GDB on windows with golang: buildsym_init Assertion `free_pendings == NULL` f...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.9
: P1 critical
Target Milestone: 8.2
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-05 15:13 UTC by damtur
Modified: 2018-07-31 16:40 UTC (History)
8 users (show)

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


Attachments
Go binary generated with go 1.10 on win10 (719.17 KB, application/octet-stream)
2018-06-29 20:43 UTC, Krzysztof Kowalczyk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description damtur 2015-07-05 15:13:04 UTC
Hey, when I'm trying to debug golang program on Windows using git bash console I'm getting assertion failed. Below console output:

 ~/Documents/tmp
$ go build -gcflags "-N -l" hello.go

 ~/Documents/tmp
$ gdb hello.exe
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 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 "x86_64-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 hello.exe...done.
(gdb) list
../../../../src/gdb-7.9.1/gdb/buildsym.c:1759: internal-error: buildsym_init: Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

../../../../src/gdb-7.9.1/gdb/buildsym.c:1759: internal-error: buildsym_init: Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) y
Command aborted.
(gdb)
Comment 1 joshua.vijay 2015-09-08 15:06:48 UTC
I face the same issue.
Comment 2 xiucai 2016-08-31 09:23:02 UTC
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 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 "x86_64-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".
../../../../src/gdb-7.10.1/gdb/buildsym.c:1759: internal-error: buildsym_init: Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) [answered Y; input not from terminal]
../../../../src/gdb-7.10.1/gdb/buildsym.c:1759: internal-error: buildsym_init: Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) [answered Y; input not from terminal]

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Comment 3 xiucai 2016-08-31 09:24:36 UTC
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\bin\gdborig.exe'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\lpk.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\usp10.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\nsi.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\bin\libpython2.7.dll'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\Windows\System32\psapi.dll'. Cannot find or open the PDB file.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\lib\python2.7\lib-dynload\_codecs_cn.pyd'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\lib\python2.7\lib-dynload\_multibytecodec.pyd'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\lib\python2.7\lib-dynload\itertools.pyd'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\lib\python2.7\lib-dynload\_collections.pyd'. Module was built without symbols.
'gdborig.exe' (Win32): Loaded 'C:\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev0\mingw64\opt\lib\python2.7\lib-dynload\_heapq.pyd'. Module was built without symbols.
The thread 0xda4 has exited with code 0 (0x0).
The thread 0x1d6c has exited with code 3 (0x3).
The thread 0x5d48 has exited with code 3 (0x3).
The program '[8468] gdborig.exe' has exited with code 3 (0x3).
Comment 4 Paul C Brown 2016-11-22 22:03:03 UTC
I have the same problem in goclipse:

GNU gdb (GDB) 7.12
Copyright (C) 2016 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 "x86_64-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".
Loading Go Runtime support.
../../gdb-7.12/gdb/buildsym.c:1773: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) [answered Y; input not from terminal]

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

../../gdb-7.12/gdb/buildsym.c:1773: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? 
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
(y or n) [answered Y; input not from terminal]
Comment 5 Paul C Brown 2016-11-22 22:10:10 UTC
Actually, not a bug - just missing a command line argument (at least for me). The missing argument is "-d $GOROOT" (I am actually debugging Go).
Comment 6 tree1891 2017-06-03 12:58:01 UTC
(In reply to Paul C Brown from comment #5)
> Actually, not a bug - just missing a command line argument (at least for
> me). The missing argument is "-d $GOROOT" (I am actually debugging Go).

what argument is it?
Comment 7 shirley.ji 2018-01-27 15:52:06 UTC
I hit the same problem in eclipse(neno3) and goclipse on windows(7) with gdb version 8.0.1, but if I just used the command line in gdb, it works fine. 

command line in gdb, successful scenario:
D:\GoWork\src>go build -gcflags "-N -l" HelloWorld/src/main/main.go

D:\GoWork\src>gdb main.exe
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 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 "x86_64-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 main.exe...done.
Loading Go Runtime support.

eclipse + go , failed scenario:
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 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 "x86_64-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".
Loading Go Runtime support.
../../../../src/gdb-8.0.1/gdb/buildsym.c:1773: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) [answered Y; input not from terminal]

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
../../../../src/gdb-8.0.1/gdb/buildsym.c:1773: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) [answered Y; input not from terminal]


main.go:
package main

import "fmt"

func main() {
   fmt.Println("Hello, World!")

}

Anyone has any suggestions/solutions? Thanks a lot.
Comment 8 Tom Tromey 2018-05-23 14:30:47 UTC
Is this still a problem with newer versions of gdb?
Comment 9 Krzysztof Kowalczyk 2018-06-29 20:17:12 UTC
Yes, this still happens with gdb 8.1 that I got from https://nuwen.net/mingw.html (https://nuwen.net/files/mingw/mingw-15.4-without-git.exe to be specific).

A simple repro:

> cat .\main.go
package main

import "fmt"

func f() {
        fmt.Printf("Hello from f()\n")
}

func main() {
        fmt.Printf("Hello from main\n")
        f()
}


> go build main.go -o main.exe

> gdb --args .\main.exe
GNU gdb (GDB) 8.1
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 "x86_64-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 .\main.exe...done.
warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts
of file C:\Users\kjk\go\src\github.com\kjk\tst\main.exe.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) br main.f
../../src/gdb/buildsym.c:1764: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

Note: I believe this should repro on non-windows as well if gdb is compiled with gdb_assert() enabled.

My theory is that it only happens on Windows because on Windows people compile it with gdb_assert() enabled and on non-windows with gdb_assert() disabled.

Info about gdb:

> gdb --version
GNU gdb (GDB) 8.1
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 "x86_64-w64-mingw32".


(gdb) show configuration                                                                                   
This GDB was configured as follows:                                                                        
   configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32                                         
             --with-auto-load-dir=$debugdir:$datadir/auto-load                                             
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load                                       
             --without-expat                                                                               
             --with-gdb-datadir=/c/temp/gcc/dest/share/gdb (relocatable)                                   
             --with-jit-reader-dir=/c/temp/gcc/dest/lib/gdb (relocatable)                                  
             --without-libunwind-ia64                                                                      
             --without-lzma                                                                                
             --without-guile                                                                               
             --with-separate-debug-dir=/c/temp/gcc/dest/lib/debug (relocatable)                            
             --without-babeltrace
Comment 10 Tom Tromey 2018-06-29 20:36:49 UTC
> ../../src/gdb/buildsym.c:1764: internal-error: void buildsym_init(): Assertion `free_pendings == NULL' failed.

> My theory is that it only happens on Windows because on Windows people compile it with gdb_assert() enabled and on non-windows with gdb_assert() disabled.

buildsym is used by the symbol readers, so if free_pendings is not
null, then it means some symbol reader didn't clean up properly.
So, it may not be easily reproducible on other hosts, because they
may not be using the same object format.

I wonder if you could attach your main.exe file?
That might make it simpler to figure out what is wrong.
Comment 11 Krzysztof Kowalczyk 2018-06-29 20:43:52 UTC
Created attachment 11109 [details]
Go binary generated with go 1.10 on win10

Shows a crash on windows with gdb.

build from main.go:

package main

import "fmt"

func f() {
	fmt.Printf("Hello from f()\n")
}

func main() {
	fmt.Printf("Hello from main\n")
	f()
}

with:
> go build

> go version
go version go1.10.3 windows/amd64
Comment 12 Krzysztof Kowalczyk 2018-06-29 20:45:34 UTC
File attached.

My understanding is that Go uses the same symbol format (DWARF) on all platforms, including Windows.

The difference might be PE vs. Mach vs. Elf.
Comment 13 Krzysztof Kowalczyk 2018-06-29 20:47:24 UTC
Also there is corresponding bug filed for Go at https://github.com/golang/go/issues/21380

The issue might be that Go generates subtly invalid DWARF info in which case Go should fix it as well.
Comment 14 Tom Tromey 2018-06-29 21:13:05 UTC
Thanks.  Patch is here:

https://sourceware.org/ml/gdb-patches/2018-06/msg00736.html

I don't know what went wrong here but I guess COFF+DWARF
isn't used and/or maintained much.
Comment 15 Sourceware Commits 2018-07-17 15:37:38 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4735f0edf4265e3e260e10a12921baf17987a020

commit 4735f0edf4265e3e260e10a12921baf17987a020
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jun 29 15:10:04 2018 -0600

    Use scoped_free_pendings in coff_symtab_read
    
    PR gdb/18624 concerns an assertion failure that occurs when setting a
    breakpoint in a Go program on Windows.
    
    What happens here is that coff_symtab_read uses buildsym but does not
    instantiate scoped_free_pendings.  So, the struct pending objects are
    never released.  Later, dwarf2read.c calls buildsym_init, which
    asserts.
    
    This patch fixes the problem by instantiating scoped_free_pendings in
    coff_symtab_read.
    
    Tested using the test executable from the PR.  I don't know how to
    test this more fully.
    
    gdb/ChangeLog
    2018-07-17  Tom Tromey  <tom@tromey.com>
    
    	PR gdb/18624:
    	* coffread.c (coff_symtab_read): Use scoped_free_pendings.
Comment 16 Tom Tromey 2018-07-17 15:47:42 UTC
Fixed.
Comment 17 Sourceware Commits 2018-07-17 15:47:53 UTC
The gdb-8.2-branch branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=79b38778d788e01e66e82f16bf3d4957439c77d5

commit 79b38778d788e01e66e82f16bf3d4957439c77d5
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jun 29 15:10:04 2018 -0600

    Use scoped_free_pendings in coff_symtab_read
    
    PR gdb/18624 concerns an assertion failure that occurs when setting a
    breakpoint in a Go program on Windows.
    
    What happens here is that coff_symtab_read uses buildsym but does not
    instantiate scoped_free_pendings.  So, the struct pending objects are
    never released.  Later, dwarf2read.c calls buildsym_init, which
    asserts.
    
    This patch fixes the problem by instantiating scoped_free_pendings in
    coff_symtab_read.
    
    Tested using the test executable from the PR.  I don't know how to
    test this more fully.
    
    2018-07-17  Tom Tromey  <tom@tromey.com>
    
    	PR gdb/18624:
    	* coffread.c (coff_symtab_read): Use scoped_free_pendings.
Comment 18 Joel Brobecker 2018-07-31 16:25:44 UTC
Hi Tom. IIUC, we can close this PR, right?
Comment 19 Tom Tromey 2018-07-31 16:40:19 UTC
Yep, I forgot to click the button.