EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  <20222023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  <20222023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Segmentation fault when using asyn Octect writeRead
From: Abdalla Ahmad via Tech-talk <tech-talk at aps.anl.gov>
To: Mark Rivers <rivers at cars.uchicago.edu>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Thu, 13 Oct 2022 13:14:01 +0000

Hello Mark

 

Please find attached gdb backtrace. You are right about the conversion, but for the casting since it returns raw data, either I do memcpy to a float pointer or:

 

*value = *(epicsFloat64*) &temp;

 

Either way it did not work. I think Something is wrong with the asyn user I am passing, its address is 0x5 for some reason.

 

Thanks

Abdalla.

 

From: Mark Rivers <rivers at cars.uchicago.edu>
Sent: Thursday, October 13, 2022 4:04 PM
To: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>; tech-talk at aps.anl.gov
Subject: Re: Segmentation fault when using asyn Octect writeRead

 

> The device returns all readings, float and integer, as a raw unsigned 32-bit integer and then I cast the raw data pointer into float pointer if needed. 

 

Then your code is wrong.  You are passing a pointer to a different data type, and not actually doing an int to float conversion.  The code should be this:

 

asynStatus PSController::readFloat64(asynUser* asyn, epicsFloat64* value)

{

      u32 temp;

      asynStatus status = performIO(asyn, &temp);

      *value = (epicsFloat64) temp;

      return status;

}

 

Please print the address of this->device using printf("this->device=%p\n", this->device) just before the call to pasynOctetSyncIO->writeRead().

 

Please also send the actual output of the gdb backtrace.

 

Mark

 

 


From: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>
Sent: Thursday, October 13, 2022 7:36 AM
To: Mark Rivers <rivers at cars.uchicago.edu>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: RE: Segmentation fault when using asyn Octect writeRead

 

Hello Mark

 

Yes that was an indexing mistake but it did not work. The device returns all readings, float and integer, as a raw unsigned 32-bit integer and then I cast the raw data pointer into float pointer if needed. I did ran the IOC under GDB and it crashes on the call to writeRead, exactly at line 238 in asynOctetSyncIO.c where it tries to cast the userPvt pointer of the asynUser to ioPvt*.

 

Best Regards,

Abdalla.

 

From: Mark Rivers <rivers at cars.uchicago.edu>
Sent: Thursday, October 13, 2022 3:09 PM
To: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>; tech-talk at aps.anl.gov
Subject: Re: Segmentation fault when using asyn Octect writeRead

 

Hi Abdalla,

 

I think I see an error in your driver:

 

    memcpy(tx_array + 0, &(tx.status),  sizeof(u16));

    memcpy(tx_array + 2, &(tx.command), sizeof(u16));

    memcpy(tx_array + 2, &(tx.address), sizeof(u16));

    memcpy(tx_array + 4, &(tx.data),    sizeof(u32));

 

You are copying to tx_array+2 twice.  I think you probably mean

 

    memcpy(tx_array + 0, &(tx.status),  sizeof(u16));

    memcpy(tx_array + 2, &(tx.command), sizeof(u16));

    memcpy(tx_array + 4, &(tx.address), sizeof(u16));

    memcpy(tx_array + 6, &(tx.data),    sizeof(u32));

 

The following also looks like it might be an error.  You are passing a pointer to a float cast to u32*.  Does your device really return a 32-bit float, or does it return an integer?

 

asynStatus PSController::readFloat64(asynUser* asyn, epicsFloat64* value)

{

      float temp = (float) *value;

      asynStatus status = performIO(asyn, (u32*) &temp);

      *value = temp;

      return status;

}

 

Neither of these problems is likely to cause the crash.  Please run the program under gdb and send the output of "backtrace" when it crashes.

 

Mark

 

 


From: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>
Sent: Thursday, October 13, 2022 5:48 AM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; Mark Rivers <rivers at cars.uchicago.edu>
Subject: Segmentation fault when using asyn Octect writeRead

 

Hello

 

I am writing a driver to control a custom power supply using asynPortDriver, I am using asynOctetSyncIO->writeRead interface to do IO with the controller but the IOC crashes on calling the function (https://github.com/AbdallaDalleh/psc-asyn-driver/blob/main/pscApp/src/PSController.cpp#L83 ). The asynOctetSyncIO interface crashes specifically on line 238, when casting the userPvt pointer of the passed asynUser pointer. I used this interface many times before and I have no idea why the segmentation fault happens.

 

Best Regards,

Abdalla.

Address: 0x5

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffee9dd700 (LWP 26562)]
writeRead (pasynUser=0x5, write_buffer=0x7fffee9dcd30 "", write_buffer_len=10, read_buffer=0x7fffee9dcd40 "\031p\251=", read_buffer_len=10, timeout=1, nbytesOut=0x7fffee9dcce0, nbytesIn=0x7fffee9dccf0, 
    eomReason=0x7fffee9dccd0) at ../../asyn/interfaces/asynOctetSyncIO.c:238
238     ioPvt      *pioPvt = (ioPvt *)pasynUser->userPvt;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-222.el7.x86_64 libgcc-4.8.5-28.el7_5.1.x86_64 libstdc++-4.8.5-28.el7_5.1.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 readline-6.2-10.el7.x86_64
(gdb) backtrace
#0  writeRead (pasynUser=0x5, write_buffer=0x7fffee9dcd30 "", write_buffer_len=10, read_buffer=0x7fffee9dcd40 "\031p\251=", read_buffer_len=10, timeout=1, nbytesOut=0x7fffee9dcce0, nbytesIn=0x7fffee9dccf0, 
    eomReason=0x7fffee9dccd0) at ../../asyn/interfaces/asynOctetSyncIO.c:238
#1  0x00007ffff7bd8567 in PSController::performIO (this=0x6d1680, asyn=<optimized out>, value=value@entry=0x7fffee9dcd7c) at ../PSController.cpp:84
#2  0x00007ffff7bd85f2 in PSController::readFloat64 (this=<optimized out>, asyn=<optimized out>, value=0x717018) at ../PSController.cpp:35
#3  0x00007ffff79724a5 in readFloat64 (drvPvt=0x6d1680, pasynUser=0x717138, value=0x717018) at ../../asyn/asynPortDriver/asynPortDriver.cpp:2319
#4  0x00007ffff7993177 in processCallbackInput (pasynUser=0x717138) at ../../asyn/devEpics/devAsynFloat64.c:329
#5  0x00007ffff794f963 in portThread (pport=0x6d6790) at ../../asyn/asynDriver/asynManager.c:913
#6  0x00007ffff6fd07dc in start_routine () from /opt/epics/base/lib/linux-x86_64/libCom.so.3.15.6
#7  0x00007ffff618de25 in start_thread () from /lib64/libpthread.so.0
#8  0x00007ffff64a0bad in clone () from /lib64/libc.so.6
(gdb) 


Replies:
Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
References:
Segmentation fault when using asyn Octect writeRead Abdalla Ahmad via Tech-talk
Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
RE: Segmentation fault when using asyn Octect writeRead Abdalla Ahmad via Tech-talk
Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk

Navigate by Date:
Prev: Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
Next: Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  <20222023  2024 
Navigate by Thread:
Prev: Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
Next: Re: Segmentation fault when using asyn Octect writeRead Mark Rivers via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  <20222023  2024 
ANJ, 13 Oct 2022 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·