libps3000a.so segfault

Discussion forum for the Picoscope 6 Linux software
tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

libps3000a.so segfault

Post by tobczo »

Hello,

I get a segfault trying to open the device:
picoscope[32666]: segfault at 0 ip b71ef0cb sp b52fd9b0 error 4 in libps3000a.so.2.0.0[b712d000+45f000]

I have 4 picoscopes 3406B connected to one computer via an usb hub.
My program opens one picoscope, does block readout from three channels 200 times, and closes the device.
And repeats the above procedure, reading different picoscope each time.

After some time (~13 readings) I get the segfault trying to ps3000aOpenUnit.

Regards,
Tobiasz Czopowicz

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Hi Tobiasz,

Can you check if there is anything in system messages regarding USB? (dmesg or check in /var/log/messages)

pzdr.
Mariusz

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mariusz,

each time I connect a picoscope, there appears:
usb 2-1.3: new full-speed USB device number 51 using uhci_hcd
usb 2-1.3: New USB device found, idVendor=0ce9, idProduct=1012
usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-1.3: Product: PicoScope 3000
usb 2-1.3: Manufacturer: Pico Technology

And then, from time to time:
usb 2-1.7: reset full-speed USB device number 49 using uhci_hcd

I have 4 picoscopes connected via usb hub.

The solution for the segfault is to open each picoscope once and keep the connection. It works, but I don't like that.

Maybe there is something wrong with malloc/free in ps3000aOpenUnit and ps3000aCloseUnit?

Regards,
Tobiasz

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Hi Tobiasz,

I have managed to track down the issue and fix it. It was affecting all devices, thus I made the new release available on the repository.

You application was hitting limit of open files (1024 by default) and then crashing. Problem was in handling libusb structures - it was leaving behind open handles to timerfd objects, causing fd leak.


Thanks,
Mario

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

great news! As soon as I find some time (next week, maybe?), I'll test this new release and let you know how it goes.

Regards,
Tobiasz

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

The segfault is, indeed, gone! Thank you!

Unfortunately from time to time now I get:
"terminate called after throwing an instance of 'unsigned int'"
while using ps3000aOpenUnit...

Tobiasz

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Hi Tobiasz,

Terminate is called as certain exception is being thrown and runtime doesn't know what to do with it. Try enclosing ps3000aOpenUnit within try&catch statement to identify what is actually happening.


Mario

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

as you suggested, I have caught the exception.
It is number 11.
Since I catch it, it no longer terminates my program.
Each following call to ps3000aOpenUnit() results with
PICO_OPEN_OPERATION_IN_PROGRESS...

Tobiasz

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Hi Tobiasz,

PICO_OPEN_OPERATION_IN_PROGRESS is returned only in 2 cases - while opening unit asynchronously, and in case the previous open operation is still pending. I can tell that most of OpenUnit is enclosed in its own try/catch, so any subsequent exception should be caught. The code outside try/catch only passes value to *handle you have supplied on open. Can you confirm that handle has a valid address before the call? Also what is the value of the *handle after the exception? (Expect -1)

As the other suggestion you could try using older version of libusb. The one I had the best experience with is 1.0.9. Just compile it, drop .so with its links to /opt/picoscope/lib and run ldconfig.


Mario

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

it took some time to wait for the exception to appear...
Indeed, as You expected, when I caught exception 11, handle was equal to -1. I am sure &handle is a valid address.

I do not use asynchronous picoscope opening.

I use libusb-1, version 2:1.0.11-1 (from debian wheezy repositories). If I find time, I will try to get older version...

Tobiasz

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

finally I had time to come back to the exception issue...
So to make things simple, I wrote a program that connects and disconnects to 3 picoscopes in a loop with few second sleep in between.

I also installed Your version of libusb-1.

Unfortunately I still get exception 11 and PICO_OPEN_OPERATION_IN_PROGRESS...

Cheers,
Tobiasz

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Hi Tobiasz,

I have run suggested test on my desk for several hours, to the amusement of my colleagues - constant click-clacks are quite annoying. The problem wasn't observed though. Maybe it has something to do with specific devices? I used PS3206B, PS3207B (USB3) and PS3406B with power supply plugged in.
I ran through the code and spot one possible location where it may be happening. The fix is included in the latest release, which just has been uploaded to the main repository.

Mario

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

unfortunately, I can't compile my program with new libps3000a.so :(

I attached source of my test program. Maybe I do something wrong?

Tobiasz
Attachments
test-connection.tar.gz
Source of my test program
(70.13 KiB) Downloaded 702 times

mario_
Site Admin
Site Admin
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Post by mario_ »

Works for me...

Code: Select all

[2015-01-30 15:48:35]   Loop 64
[2015-01-30 15:48:35]           Connecting to picoscope with serial number AO483/035... OK
[2015-01-30 15:48:39]           Connecting to picoscope with serial number AV987/021... OK
[2015-01-30 15:48:44]           Connecting to picoscope with serial number CX012/015... OK
[2015-01-30 15:48:52]   Loop 65
[2015-01-30 15:48:52]           Connecting to picoscope with serial number AO483/035... OK
[2015-01-30 15:48:56]           Connecting to picoscope with serial number AV987/021... OK
[2015-01-30 15:49:02]           Connecting to picoscope with serial number CX012/015... OK
How is it failing to compile?

Mario

tobczo
Newbie
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Post by tobczo »

Dear Mario,

my bad - it seems that on 64bit machine I had to link one more library..

Buy anyhow, I see you reached loop 65. I always catch exception "11" in loop 42.

Cheers,
Tobiasz

Post Reply