Test and Measurement Forum

libps3000a.so segfault

Discussion forum for the new Picoscope Linux software

libps3000a.so segfault

Postby tobczo » Sat Nov 01, 2014 8:17 am

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Mon Nov 03, 2014 9:25 am

Hi Tobiasz,

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

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

Re: libps3000a.so segfault

Postby tobczo » Sun Nov 09, 2014 7:37 pm

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Tue Nov 11, 2014 1:34 pm

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
mario_
Site Admin
Site Admin
 
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Postby tobczo » Tue Nov 11, 2014 1:51 pm

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

Postby tobczo » Fri Nov 28, 2014 9:03 am

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Mon Dec 01, 2014 8:41 am

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
mario_
Site Admin
Site Admin
 
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Postby tobczo » Fri Dec 05, 2014 7:34 am

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Wed Dec 10, 2014 9:07 am

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
mario_
Site Admin
Site Admin
 
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Postby tobczo » Fri Dec 12, 2014 8:35 pm

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

Postby tobczo » Fri Jan 23, 2015 11:39 pm

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Thu Jan 29, 2015 11:50 am

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
mario_
Site Admin
Site Admin
 
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Postby tobczo » Fri Jan 30, 2015 10:24 am

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 69 times
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Re: libps3000a.so segfault

Postby mario_ » Fri Jan 30, 2015 3:49 pm

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
mario_
Site Admin
Site Admin
 
Posts: 112
Joined: Fri Sep 13, 2013 12:57 pm

Re: libps3000a.so segfault

Postby tobczo » Sat Jan 31, 2015 12:07 am

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
tobczo
Newbie
 
Posts: 0
Joined: Sat Nov 01, 2014 7:54 am

Next

Return to PicoScope for Linux

Who is online

Users browsing this forum: No registered users and 0 guests