Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
--- a/ProjectController.py Thu Dec 09 10:21:45 2021 +0100
+++ b/ProjectController.py Wed Dec 15 11:56:34 2021 +0100
@@ -972,7 +972,7 @@
# describes CSV columns
ProgramsListAttributeName = ["num", "C_path", "type"]
VariablesListAttributeName = [
- "num", "vartype", "IEC_path", "C_path", "type", "derived"]
+ "num", "vartype", "IEC_path", "C_path", "type", "derived", "retain"]
self._ProgramList = []
self._VariablesList = []
self._DbgVariablesList = []
@@ -1053,8 +1053,9 @@
# prepare debug code
variable_decl_array = []
- for v in self._DbgVariablesList:
- variable_decl_array += [
+ retain_indexes = []
+ for i, v in enumerate(self._DbgVariablesList):
+ variable_decl_array.append(
"{&(%(C_path)s), " % v +
{
"EXT": "%(type)s_P_ENUM",
@@ -1063,7 +1064,11 @@
"OUT": "%(type)s_O_ENUM",
"VAR": "%(type)s_ENUM"
}[v["vartype"]] % v +
- "}"]
+ "}")
+
+ if v["retain"] == "1":
+ retain_indexes.append("/* "+v["C_path"]+" */ "+str(i))
+
debug_code = targets.GetCode("plc_debug.c") % {
"programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" %
p for p in self._ProgramList]),
@@ -1078,6 +1083,7 @@
}[v["vartype"]] % v
for v in self._VariablesList if v["C_path"].find('.') < 0]),
"variable_decl_array": ",\n".join(variable_decl_array),
+ "retain_vardsc_index_array": ",\n".join(retain_indexes),
"var_access_code": targets.GetCode("var_access.c")
}
--- a/targets/plc_debug.c Thu Dec 09 10:21:45 2021 +0100
+++ b/targets/plc_debug.c Wed Dec 15 11:56:34 2021 +0100
@@ -78,7 +78,6 @@
#endif
-static unsigned int retain_offset = 0;
/***
* Declare programs
**/
@@ -94,10 +93,16 @@
__IEC_types_enum type;
} dbgvardsc_t;
-static dbgvardsc_t dbgvardsc[] = {
+static const dbgvardsc_t dbgvardsc[] = {
%(variable_decl_array)s
};
+static const dbgvardsc_index_t retain_list[] = {
+%(retain_vardsc_index_array)s
+};
+static unsigned int retain_list_collect_cursor = 0;
+static const unsigned int retain_list_size = sizeof(retain_list)/sizeof(dbgvardsc_index_t);
+
typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*);
void __for_each_variable_do(__for_each_variable_do_fp fp)
{
@@ -115,23 +120,6 @@
void Remind(unsigned int offset, unsigned int count, void * p);
-void RemindIterator(dbgvardsc_t *dsc)
-{
- void *value_p = NULL;
- char flags;
- size_t size;
- UnpackVar(dsc, &value_p, &flags, &size);
-
- if(flags & __IEC_RETAIN_FLAG){
- /* compute next cursor positon*/
- unsigned int next_retain_offset = retain_offset + size;
- /* if buffer not full */
- Remind(retain_offset, size, value_p);
- /* increment cursor according size*/
- retain_offset = next_retain_offset;
- }
-}
-
extern int CheckRetainBuffer(void);
extern void InitRetain(void);
@@ -149,16 +137,36 @@
force_list_apply_cursor = force_list;
#endif
- retain_offset = 0;
InitRetain();
/* Iterate over all variables to fill debug buffer */
if(CheckRetainBuffer()){
- __for_each_variable_do(RemindIterator);
+ static unsigned int retain_offset = 0;
+ retain_list_collect_cursor = 0;
+
+ /* iterate over retain list */
+ while(retain_list_collect_cursor < retain_list_size){
+ void *value_p = NULL;
+ size_t size;
+ char* next_cursor;
+
+ dbgvardsc_t *dsc = &dbgvardsc[
+ retain_list[retain_list_collect_cursor]];
+
+ UnpackVar(dsc, &value_p, NULL, &size);
+
+ printf("Reminding %%d %%ld \n", retain_list_collect_cursor, size);
+
+ /* if buffer not full */
+ Remind(retain_offset, size, value_p);
+ /* increment cursor according size*/
+ retain_offset += size;
+
+ retain_list_collect_cursor++;
+ }
}else{
char mstr[] = "RETAIN memory invalid - defaults used";
LogMessage(LOG_WARNING, mstr, sizeof(mstr));
}
- retain_offset = 0;
}
extern void InitiateDebugTransfer(void);
@@ -180,52 +188,31 @@
{
}
-
void Retain(unsigned int offset, unsigned int count, void * p);
-static inline void BufferIterator(dbgvardsc_t *dsc, int do_debug)
-{
- void *value_p = NULL;
- char flags;
- size_t size;
-
- UnpackVar(dsc, &value_p, &flags, &size);
-
- if(flags & __IEC_RETAIN_FLAG){
-
- /* compute next cursor positon*/
- unsigned int next_retain_offset = retain_offset + size;
- /* if buffer not full */
- Retain(retain_offset, size, value_p);
- /* increment cursor according size*/
- retain_offset = next_retain_offset;
- }
-}
-
-void RetainIterator(dbgvardsc_t *dsc){
- BufferIterator(dsc, 0);
-}
-
-
-unsigned int retain_size = 0;
-
-/* GetRetainSizeIterator */
-void GetRetainSizeIterator(dbgvardsc_t *dsc)
-{
- char flags;
- size_t size;
- UnpackVar(dsc, NULL, &flags, &size);
-
- if(flags & __IEC_RETAIN_FLAG){
- /* Calc retain buffer size */
- retain_size += size;
- }
-}
-
/* Return size of all retain variables */
unsigned int GetRetainSize(void)
{
- __for_each_variable_do(GetRetainSizeIterator);
+ unsigned int retain_size = 0;
+ retain_list_collect_cursor = 0;
+
+ /* iterate over retain list */
+ while(retain_list_collect_cursor < retain_list_size){
+ void *value_p = NULL;
+ size_t size;
+ char* next_cursor;
+
+ dbgvardsc_t *dsc = &dbgvardsc[
+ retain_list[retain_list_collect_cursor]];
+
+ UnpackVar(dsc, &value_p, NULL, &size);
+
+ retain_size += size;
+ retain_list_collect_cursor++;
+ }
+
+ printf("Retain size %%d \n", retain_size);
+
return retain_size;
}
@@ -258,7 +245,6 @@
break;
void __publish_debug(void)
{
- retain_offset = 0;
InValidateRetainBuffer();
#ifndef TARGET_ONLINE_DEBUG_DISABLE
@@ -336,8 +322,30 @@
LeaveDebugSection();
}
#endif
+ static unsigned int retain_offset = 0;
/* when not debugging, do only retain */
- __for_each_variable_do(RetainIterator);
+ retain_list_collect_cursor = 0;
+
+ /* iterate over retain list */
+ while(retain_list_collect_cursor < retain_list_size){
+ void *value_p = NULL;
+ size_t size;
+ char* next_cursor;
+
+ dbgvardsc_t *dsc = &dbgvardsc[
+ retain_list[retain_list_collect_cursor]];
+
+ UnpackVar(dsc, &value_p, NULL, &size);
+
+ printf("Retaining %%d %%ld \n", retain_list_collect_cursor, size);
+
+ /* if buffer not full */
+ Retain(retain_offset, size, value_p);
+ /* increment cursor according size*/
+ retain_offset += size;
+
+ retain_list_collect_cursor++;
+ }
ValidateRetainBuffer();
}