98 extern void InitRetain(void); |
98 extern void InitRetain(void); |
99 |
99 |
100 void __init_debug(void) |
100 void __init_debug(void) |
101 { |
101 { |
102 /* init local static vars */ |
102 /* init local static vars */ |
103 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
103 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
104 buffer_cursor = debug_buffer; |
104 buffer_cursor = debug_buffer; |
105 buffer_state = BUFFER_FREE; |
105 buffer_state = BUFFER_FREE; |
106 #endif |
106 #endif |
107 |
107 |
108 retain_offset = 0; |
108 retain_offset = 0; |
109 InitRetain(); |
109 InitRetain(); |
110 /* Iterate over all variables to fill debug buffer */ |
110 /* Iterate over all variables to fill debug buffer */ |
111 if(CheckRetainBuffer()){ |
111 if(CheckRetainBuffer()){ |
112 __for_each_variable_do(RemindIterator); |
112 __for_each_variable_do(RemindIterator); |
113 }else{ |
113 }else{ |
114 char mstr[] = "RETAIN memory invalid - defaults used"; |
114 char mstr[] = "RETAIN memory invalid - defaults used"; |
115 LogMessage(LOG_WARNING, mstr, sizeof(mstr)); |
115 LogMessage(LOG_WARNING, mstr, sizeof(mstr)); |
116 } |
116 } |
117 retain_offset = 0; |
117 retain_offset = 0; |
118 } |
118 } |
119 |
119 |
148 visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
148 visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
149 |
149 |
150 if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){ |
150 if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){ |
151 USINT size = __get_type_enum_size(dsc->type); |
151 USINT size = __get_type_enum_size(dsc->type); |
152 |
152 |
153 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
153 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
154 if(flags & __IEC_DEBUG_FLAG){ |
154 if(flags & __IEC_DEBUG_FLAG){ |
155 /* copy visible variable to buffer */; |
155 /* copy visible variable to buffer */; |
156 if(do_debug){ |
156 if(do_debug){ |
157 /* compute next cursor positon. |
157 /* compute next cursor positon. |
158 No need to check overflow, as BUFFER_SIZE |
158 No need to check overflow, as BUFFER_SIZE |
159 is computed large enough */ |
159 is computed large enough */ |
160 if((dsc->type == STRING_ENUM) || |
160 if(__Is_a_string(dsc)){ |
161 (dsc->type == STRING_P_ENUM) || |
|
162 (dsc->type == STRING_O_ENUM)){ |
|
163 /* optimization for strings */ |
161 /* optimization for strings */ |
164 size = ((STRING*)visible_value_p)->len + 1; |
162 size = ((STRING*)visible_value_p)->len + 1; |
165 } |
163 } |
166 char* next_cursor = buffer_cursor + size; |
164 char* next_cursor = buffer_cursor + size; |
167 /* copy data to the buffer */ |
165 /* copy data to the buffer */ |
172 /* re-force real value of outputs (M and Q)*/ |
170 /* re-force real value of outputs (M and Q)*/ |
173 if((flags & __IEC_FORCE_FLAG) && (flags & __IEC_OUTPUT_FLAG)){ |
171 if((flags & __IEC_FORCE_FLAG) && (flags & __IEC_OUTPUT_FLAG)){ |
174 memcpy(real_value_p, visible_value_p, size); |
172 memcpy(real_value_p, visible_value_p, size); |
175 } |
173 } |
176 } |
174 } |
177 #endif |
175 #endif |
178 |
176 |
179 if(flags & __IEC_RETAIN_FLAG){ |
177 if(flags & __IEC_RETAIN_FLAG){ |
180 /* compute next cursor positon*/ |
178 /* compute next cursor positon*/ |
181 unsigned int next_retain_offset = retain_offset + size; |
179 unsigned int next_retain_offset = retain_offset + size; |
182 /* if buffer not full */ |
180 /* if buffer not full */ |