EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Crash in pvData
From: Mark Rivers via Core-talk <[email protected]>
To: 'Michael Davidsaver' <[email protected]>, "[email protected]" <[email protected]>
Date: Sat, 29 Jun 2019 21:06:55 +0000

Hi Michael,

 

Thanks for the quick reply.  I think you have identified the problem, but the solution does not seem to be working.

 

You suggested this code:

 

    if(!valueFld) {

        valueFld = PVDC->createPVScalar<PVString>();

        destUnion->put(valueFld);

    }

    value->put(value);

 

That did not compile, so I changed it to this, i.e. replace destUnion->put() with destUnion->set() and value->put(value) with valueFld->put(&value[0])

I also added some debugging printfs.

 

    if(!valueFld) {

        valueFld = PVDC->createPVScalar<PVString>();

        destUnion->set(valueFld);

    }

printf("Writing attribute %s value=%s\n", src->getName(), &value[0]);

    valueFld->put(&value[0]);

printf("Wrote attribute %s OK\n", src->getName());

}

 

I also have a printf in ntNDArrayConverter::fromAttributes the prints the name and datatype of each attribute as it iterates.

 

This is the output:

 

ntNDArrayConverter::fromAttributes name=ColorMode dataType=4

ntNDArrayConverter::fromAttributes name=SaveDest dataType=8

Writing attribute SaveDest value=Continuous

Wrote attribute SaveDest OK

ntNDArrayConverter::fromAttributes name=beam_x dataType=7

ntNDArrayConverter::fromAttributes name=beam_x_units dataType=8

Writing attribute beam_x_units value=mm

Wrote attribute beam_x_units OK

ntNDArrayConverter::fromAttributes name=ColorMode dataType=4

ntNDArrayConverter::fromAttributes name=SaveDest dataType=8

Writing attribute SaveDest value=Continuous

Wrote attribute SaveDest OK

ntNDArrayConverter::fromAttributes name=beam_x dataType=7

ntNDArrayConverter::fromAttributes name=beam_x_units dataType=8

Writing attribute beam_x_units value=mm

Wrote attribute beam_x_units OK

ntNDArrayConverter::fromAttributes name=ColorMode dataType=4

ntNDArrayConverter::fromAttributes name=DataType dataType=4

ntNDArrayConverter::fromAttributes name=SaveDest dataType=8

Writing attribute SaveDest value=Continuous

Wrote attribute SaveDest OK

ntNDArrayConverter::fromAttributes name=beam_x dataType=7

ntNDArrayConverter::fromAttributes name=beam_x_units dataType=8

Writing attribute beam_x_units value=mm

Wrote attribute beam_x_units OK

ntNDArrayConverter::fromAttributes name=ColorMode dataType=4

ntNDArrayConverter::fromAttributes name=SaveDest dataType=8

Writing attribute SaveDest value=Continuous

Segmentation fault (core dumped)

 

Note that it initially was working OK when there were only 4 attributes (ColorMode, SaveDest, beam_x, and beam_x_units).  Only SaveDest and beam_x_units are string attributes (datatype=8), the others are epicsInt32 (datatype=4) and epicsFloat64 (datatype=7).

 

After some time another attribute appears in the list, DataType.  This is also epicsInt32.  Shortly after that is added, but not immediately, there is an access violation writing SaveDest, which is a string attribute.

 

This is the stack trace:

#0  0x00007fd6e95cb2ad in  () at /lib64/libstdc++.so.6

#1  0x00007fd6e962ee5e in std::string::assign(std::string const&) () at /lib64/libstdc++.so.6

#2  0x00000000006c128d in epics::pvData::detail::ScalarStorageOps<std::string>::store(std::string const&) (__str="Continuous", this=0x7fd594002030)

    at /usr/include/c++/4.8.2/bits/basic_string.h:547

#3  0x00000000006c128d in epics::pvData::detail::ScalarStorageOps<std::string>::store(std::string const&) (this=this@entry=0x7fd594002030, val="Continuous")

    at /usr/local/epics-devel/base-7.0.2/include/pv/pvData.h:362

#4  0x00000000006cca5a in NTNDArrayConverter::fromStringAttribute(std::tr1::shared_ptr<epics::pvData::PVStructure>, NDAttribute*) (v="Continuous", this=0x7fd594001fd0)

    at /corvette/usr/local/epics-devel/base-7.0.2/include/pv/pvData.h:399

#5  0x00000000006cca5a in NTNDArrayConverter::fromStringAttribute(std::tr1::shared_ptr<epics::pvData::PVStructure>, NDAttribute*) (this=this@entry=0x35481d0, dest=

    std::tr1::shared_ptr (count 3, weak 1) 0x7fd594001a70, src="" at ../ntndArrayConverter.cpp:544

#6  0x00000000006cd06a in NTNDArrayConverter::fromAttributes(NDArray*) (this=this@entry=0x35481d0, src="" at ../ntndArrayConverter.cpp:591

#7  0x00000000006cf66d in NTNDArrayConverter::fromArray(NDArray*) (this=0x35481d0, src="" at ../ntndArrayConverter.cpp:240

#8  0x000000000066c6c8 in NTNDArrayRecord::update(NDArray*) (this=0x35459b0, pArray=0x7fd5640012b0) at ../NDPluginPva.cpp:85

#9  0x000000000066c7fd in NDPluginPva::processCallbacks(NDArray*) (this=0x3504340, pArray=0x7fd5640012b0) at ../NDPluginPva.cpp:124

#10 0x000000000066f5c6 in NDPluginDriver::processTask() (this=0x3504340) at ../NDPluginDriver.cpp:524

#11 0x00000000012accc9 in epicsThreadCallEntryPoint(void*) (pPvt=0x3503090) at ../../src/osi/epicsThread.cpp:83

#12 0x00000000012b273c in start_routine (arg=0x346a4c0) at ../../src/osi/os/posix/osdThread.c:403

#13 0x00007fd6e9ed0e25 in start_thread () at /lib64/libpthread.so.0

#14 0x00007fd6e8d89bad in clone () at /lib64/libc.so.6

 

Line 544 is this line:

 

    valueFld->put(&value[0]);

 

So it seems like this has not solved the problem?

 

It seems like the previous function in NTNDArrayConverter may also have issues:

 

template <typename pvAttrType, typename valueType>

void NTNDArrayConverter::fromAttribute (PVStructurePtr dest, NDAttribute *src)

{

    valueType value;

    src->getValue(src->getDataType(), (void*)&value);

 

    PVUnionPtr destUnion(dest->getSubField<PVUnion>("value"));

 

    if(!destUnion->get())

        destUnion->set(PVDC->createPVScalar<pvAttrType>());

 

    static_pointer_cast<pvAttrType>(destUnion->get())->put(value);

}

 

Is this also assuming that the datatype of that attribute has not changed?

 

Thanks,

 

Mark

 

 

-----Original Message-----
From: Michael Davidsaver <[email protected]>
Sent: Saturday, June 29, 2019 10:48 AM
To: Mark Rivers <[email protected]>; [email protected]
Subject: Re: Crash in pvData

 

On 6/29/19 7:37 AM, Mark Rivers via Core-talk wrote:

> Folks,

>

>  

>

> I have an NDArray with a string attribute holding the value “Continuous”.  When the NDArray gets converted to an NTNDArray in NTNDArrayConverter I am getting this crash:

>

>  

>

> #0  0x00007fad6f64e2ad in  () at /lib64/libstdc++.so.6

>

> #1  0x00007fad6f6b1e5e in std::string::assign(std::string const&) ()

> at /lib64/libstdc++.so.6

>

> #2  0x00000000006c113d in

> epics::pvData::detail::ScalarStorageOps<std::string>::store(std::strin

> g const&) (__str="Continuous", this=0x7fac14002650)

>

>     at /usr/include/c++/4.8.2/bits/basic_string.h:547

>

> #3  0x00000000006c113d in

> epics::pvData::detail::ScalarStorageOps<std::string>::store(std::strin

> g const&) (this=this@entry=0x7fac14002650, val="Continuous")

>

>     at /usr/local/epics-devel/base-7.0.2/include/pv/pvData.h:362

>

> #4  0x00000000006cbf41 in

> NTNDArrayConverter::fromStringAttribute(std::tr1::shared_ptr<epics::pv

> Data::PVStructure>, NDAttribute*) (v="Continuous",

> this=0x7fac140025f0)

>

>     at

> /corvette/usr/local/epics-devel/base-7.0.2/include/pv/pvData.h:399

>

> #5  0x00000000006cbf41 in

> NTNDArrayConverter::fromStringAttribute(std::tr1::shared_ptr<epics::pv

> Data::PVStructure>, NDAttribute*) (this=this@entry=0x2fb0130, dest=

>

>     std::tr1::shared_ptr (count 3, weak 1) 0x7fac140020b0,

> src="" at ../ntndArrayConverter.cpp:543

>

> #6  0x00000000006ccc62 in NTNDArrayConverter::fromAttributes(NDArray*)

> (this=this@entry=0x2fb0130, src="" at

> ../ntndArrayConverter.cpp:589

>

> #7  0x00000000006cf38d in NTNDArrayConverter::fromArray(NDArray*)

> (this=0x2fb0130, src="" at

> ../ntndArrayConverter.cpp:240

>

> #8  0x000000000066c578 in NTNDArrayRecord::update(NDArray*)

> (this=0x2fad910, pArray=0x7fac94001270) at ../NDPluginPva.cpp:85

>

> #9  0x000000000066c6ad in NDPluginPva::processCallbacks(NDArray*)

> (this=0x2f6c2a0, pArray=0x7fac94001270) at ../NDPluginPva.cpp:124

>

> #10 0x000000000066f476 in NDPluginDriver::processTask()

> (this=0x2f6c2a0) at ../NDPluginDriver.cpp:524

>

> #11 0x00000000012ac7f9 in epicsThreadCallEntryPoint(void*)

> (pPvt=0x2f6aff0) at ../../src/osi/epicsThread.cpp:83

>

> #12 0x00000000012b226c in start_routine (arg=0x2f6aeb0) at

> ../../src/osi/os/posix/osdThread.c:403

>

> #13 0x00007fad6ff53e25 in start_thread () at /lib64/libpthread.so.0

>

> #14 0x00007fad6ee0cbad in clone () at /lib64/libc.so.6

>

>  

>

> This is base 7.0.2.2 on linux-x86_64.

>

>  

>

> Any idea why this is crashing?

 

I first suspect static cast in NTNDArrayConverter::fromStringAttribute()

 

https://github.com/areaDetector/ADCore/blob/44b3a9b62e65f8a8bfb180292f77d08a5e2c4fdd/ADApp/ntndArrayConverterSrc/ntndArrayConverter.cpp#L535-L544

 

From the logic, this code will break if the union already contains something which isn't a PVString.

 

Assuming that the value should always be stored as a string (as opposed to attempting a conversion).  Maybe change to something like:

 

> std::vector<char> value(attrDataSize); // same as malloc(), with

> auto-free()

> src->getValue(attrDataType, &value[0], attrDataSize);

> 

> PVUnionPtr destUnion(dest->getSubFieldT<PVUnion>("value")); // note

> the added T PVStringPtr valueFld(destUnion->get<PVString>());

> if(!valueFld) {

>    valueFld = PVDC->createPVScalar<PVString>();

>    destUnion->put(valueFld);

> }

> value->put(value);


Replies:
RE: Crash in pvData Mark Rivers via Core-talk
Re: Crash in pvData Michael Davidsaver via Core-talk
References:
Crash in pvData Mark Rivers via Core-talk
Re: Crash in pvData Michael Davidsaver via Core-talk

Navigate by Date:
Prev: Re: Crash in pvData Michael Davidsaver via Core-talk
Next: RE: Crash in pvData Mark Rivers via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Crash in pvData Michael Davidsaver via Core-talk
Next: RE: Crash in pvData Mark Rivers via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
ANJ, 30 Jun 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·