Segfault on context creation
brandondube opened this issue · 7 comments
A MWE:
package main
import (
"log"
"github.com/gotmc/usbtmc"
_ "github.com/gotmc/usbtmc/driver/truveris"
)
func main() {
ctx, err := usbtmc.NewContext()
if err != nil {
log.Fatal(err)
}
ctx.SetDebugLevel(1)
}
Output:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x49c9c0]
goroutine 1 [running]:
<>/vendor/github.com/gotmc/usbtmc.NewContext(0x4c92e0, 0x78a790, 0x0)
/media/psf/Home/go/src/<>/vendor/github.com/gotmc/usbtmc/context.go:20 +0x70
main.main()
/media/psf/Home/go/src/<>/cmd/ldctest/main.go:19 +0x26
This is without any of the other drivers installed. If I uninstall this driver and install another, I get the same segfault with the other two.
- Do you have the libusb driver installed (e.g.,
brew install libusb
on macOS)? - Did you run your Go program with root privileges (e.g.,
sudo myprog
)?
Libusb1.0-dev is installed (and the lib is on the path), I didn’t run with sudo but lsusb-vvv doesn’t complain about permissions / cant open devices.
‘Bare’ google/gousb context succeeded but usbtmc panics.
Have you tried running as sudo?
@brandondube — A few more questions:
- What test equipment are you trying to communicate with?
- What hardware and O/S are you using?
- What version of libusb are you using?
I just noticed that there had been a typo in the README if you were trying to use the google/gousb driver. The correct import statement should be:
import (
"github.com/gotmc/usbtmc"
_ "github.com/gotmc/usbtmc/driver/google"
)
Prior to running that, make sure you install the google/gousb driver using
$ go get -v github.com/google/gousb
The typo is probably the cause. I'm not back at work until the week after next, but to the 1,2,3 above:
-
test equipment - Thorlabs ITC4001
-
hardware / OS -- a supermicro server (or at least one in a supermicro case, not sure who the mfg is) in a standard ATX chassis, USB 2.0 connection over the Thorlabs provided cable. Ubuntu 16.04 LTS.
-
libusb-dev 1.0.12
I did not try sudo, my user account on the server has permissions to access USB devices, but I don't have (and definitely can't get) sudo -- our IT manages that.
If it is the typo, checking if the driver is nil before the first call that uses it and bailing then would be a sensible fix. Perhaps the valid/usable import statements (_ "..."
) could be included in a fmt.Errorf
.
In the interim, I have already made a very bare-bones impl of usbtmc for that thorlabs controller on top of google/gousb
with hardcoded vid/pid, endpoint nos, etc, and bulk transfer r/w only, though it is owned by my employer so I cannot share.
Closing due to inactivity. Let me know if this is still an issue, and I'll reopen.