tinyzimmer / go-gst

Gstreamer bindings and utilities for golang
GNU Lesser General Public License v2.1
130 stars 37 forks source link

Debugger Enablement #19

Closed atishnazir closed 3 years ago

atishnazir commented 3 years ago

Background: I'm trying to trackdown a C buffer overflow somewhere in my project and really need to be able to use delve/gdb to catch those segfaults. Unfortunately when trying to produce debug builds the linker falls over when trying to deal with the shim inline functions:

go build -o /tmp/___1worker -gcflags all="-N -l" <redacted> #gosetup
# github.com/tinyzimmer/go-gst/gst
/usr/bin/ld: $WORK/b222/_x005.o: in function `_cgo_9fe65b6dd3a1_Cfunc_toGstAllocator':
/tmp/go-build/cgo-gcc-prolog:145: undefined reference to `toGstAllocator'
/usr/bin/ld: $WORK/b222/_x006.o: in function `binParentAddElement':
../../../../../cognitive-i/go-gst/gst/gst_bin.go:10: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x006.o: in function `binParentDeepElementAdded':
../../../../../cognitive-i/go-gst/gst/gst_bin.go:18: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x006.o: in function `binParentDeepElementRemoved':
../../../../../cognitive-i/go-gst/gst/gst_bin.go:26: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x006.o: in function `binParentDoLatency':
../../../../../cognitive-i/go-gst/gst/gst_bin.go:34: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x006.o: in function `binParentElementAdded':
../../../../../cognitive-i/go-gst/gst/gst_bin.go:42: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x006.o:/home/na/workspace/cognitive-i/go-gst/gst/gst_bin.go:50: more undefined references to `toGstBinClass' follow
/usr/bin/ld: $WORK/b222/_x006.o: in function `_cgo_9fe65b6dd3a1_Cfunc_toGstBin':
/tmp/go-build/cgo-gcc-prolog:662: undefined reference to `toGstBin'
/usr/bin/ld: $WORK/b222/_x008.o: in function `_cgo_9fe65b6dd3a1_Cfunc_toGstBinClass':
/tmp/go-build/cgo-gcc-prolog:165: undefined reference to `toGstBinClass'
/usr/bin/ld: $WORK/b222/_x009.o: in function `_cgo_9fe65b6dd3a1_Cfunc_bufferIsWritable':
/tmp/go-build/cgo-gcc-prolog:53: undefined reference to `bufferIsWritable'

...

/usr/bin/ld: $WORK/b222/_x061.o: in function `_cgo_9fe65b6dd3a1_Cfunc_getBufferValue':
/tmp/go-build/cgo-gcc-prolog:89: undefined reference to `getBufferValue'
collect2: error: ld returned 1 exit status

Compilation finished with exit code 2

As a fix I've converted all the inline functions into defined symbols and now I am able to produce debug builds that I can run with delve (under Goland).

I'm undecided whether this is this right course of action so opening the PR more as a discussion piece.

tinyzimmer commented 3 years ago

Hey thanks for the PR! I'll want some time to play with it myself, but I like where your head is at. Debugging has generally been a pain with this library, and moving all the coercions to a single C source file was something I had considered just from a compilation speed standpoint.

I got a few things up in the air at the moment, but I'll dig into it when I get a chance.

atishnazir commented 3 years ago

Hi, Have you had a chance to tinker with this change? I've been using for a few weeks and found it invaluable (in the end the pointer spray was due to the Go GC finalising something it shouldn't have). I've not got any better suggestions.

Thanks

tinyzimmer commented 3 years ago

Yea sorry it's been a crazy couple weeks, I'll take a look tomorrow I promise.

tinyzimmer commented 3 years ago

Looks good. You are right that it makes a huge difference to debugging.

In terms of the Go GC finalizing something it shouldn't - that is behavior I've experienced before too. When I replicate it I'm able to replicate it consistently. But then I seemingly can't get it to happen in other areas working exactly the same way. There are actually references to this issue in some of the examples. One way of dealing with it is here and another here. It truly is bizarre and I hope to figure out the cause some day.

Will merge and tag this for now.