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  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Problems with Dynamic Array population
From: "Brown, David L." <[email protected]>
To: Benjamin Franksen <[email protected]>
Cc: EPICS tech-talk <[email protected]>
Date: Fri, 7 Nov 2014 17:02:53 +0000
Hi, all,

I got around the problem.  I don’t know why this is, but when one defines
an array size of 7 elements (like as seen below), assigns them to an array
of three elements outside the state machine, and then reassigns the
elements inside the state machine, there is no core dump.  I also looked
at the size of the array MPS and it said that my array was a size of 56 as
opposed to the 7 elements I defined.  I have convinced myself that this
was a memory allocation problem as the array size (as interpreted by the
state machine) was different than what I expected it to be.  Perhaps I
have a fundamental misunderstanding of how to initially assign variables
in C?  Thank you all for your help and tips.  Here is the working code I
referenced above (still needs testing, but core dumps don’t happen):

char fcoutpreamble[40];
char fcokpreamble[40];

char blah[40];
int i;
double MPS[7];
assign
{
	“PV1”,
	“PV2”,
	“PV3”
}

Monitor MPS;

SS Machine
{
	state Start
 	{
		when()
		{
			if( PV1 = TRUE)
			{
				/* set arguments here*/
				i = sprintf(blah, “%s_input\n”,fcoutpreamble);
				assert( i <= sizeof(blah));
				pvAssign (MPS[2],blah);
				i = sprintf(blah, “%s_raw\n”,fcoutpreamble);
				assert( i <= sizeof(blah));
				pvAssign (MPS[3],blah);
				i = sprintf(blah, “%s_input\n”,fcokpreamble);
				assert( i <= sizeof(blah));
				pvAssign (MPS[4],blah);
				i = sprintf(blah, “%s_raw\n”,fcokpreamble);
				assert( i <= sizeof(blah));
				pvAssign (MPS[5],blah);
				i = sprintf(blah, “PV3”);
				assert( i <= sizeof(blah));
				pvAssign (MPS[6],blah);
			}

			else
			{
				/* set arguments here*/
			}
		}state Idle
	}
}

Dave				

On 11/7/14, 5:05 AM, "Benjamin Franksen"
<[email protected]> wrote:

>Hi David
>
>as I suggested earlier, this is most probably a buffer overrun and the
>error message you get from the sequencer is a result of memory being
>overwritten. Anyway, the best way to check that is to use assertions:
>everywhere you are calling sprintf, assign the result to an integer, and
>insert an assertion stating that this number (which is the number of
>bytes written) is not larger than the buffer, like this:
>
>        int n;
>        ...
>        n = sprintf(blah,"%s:Actuator\n",fcpreamble);
>        assert(n <= sizeof(blah));
>
>(You need to %%#include <assert.h>.) If the assertion fails, you know
>exactly which buffer is not large enough.
>
>BTW1: you should send large programs as attachment, too. This makes it
>much easier to save them or load them into an editor etc.
>
>BTW2: The attachment you sent is not what you wrote it is. It contains
>channel names and IP numbers and I have no idea what to do with it.
>
>When you get a core dump, you should load it into gdb like this
>
>        gdb <path to executable> core
>
>(from the directory that contains the core file) and then issue the 'bt'
>command (back trace). You can send me the output (no attachment needed,
>this is only a few lines of text), or you can examine yourself. You
>might want to use a GUI wrapper around gdb, such as ddd. This allows you
>to display the values of program variables.
>
>Cheers
>Ben
>--
>"Make it so they have to reboot after every typo." -- Scott Adams
>
>________________________________
>
>Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
>
>Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher
>Forschungszentren e.V.
>
>Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv.
>Vorsitzende Dr. Beatrix Vierkorn-Rudolph
>Geschäftsführung: Prof. Dr. Anke Rita Kaysser-Pyzalla, Thomas Frederking
>
>Sitz Berlin, AG Charlottenburg, 89 HRB 5583
>
>Postadresse:
>Hahn-Meitner-Platz 1
>D-14109 Berlin
>
>http://www.helmholtz-berlin.de



Replies:
Re: Problems with Dynamic Array population Eric Norum
Re: Problems with Dynamic Array population Benjamin Franksen
References:
Problems with Dynamic Array population Brown, David L.
Re: Problems with Dynamic Array population Benjamin Franksen

Navigate by Date:
Prev: RE: Asyn and stringin records Mark Rivers
Next: Re: Problems with Dynamic Array population Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Problems with Dynamic Array population Benjamin Franksen
Next: Re: Problems with Dynamic Array population Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·