@@ -17,11 +17,13 @@ Author: Peter Schrammel
17
17
#include < util/std_expr.h>
18
18
#include < util/message.h>
19
19
#include < util/time_stopping.h>
20
+ #include < util/xml_expr.h>
20
21
21
22
#include < solvers/prop/minimize.h>
22
23
#include < solvers/prop/literal_expr.h>
23
24
24
25
#include < goto-symex/build_goto_trace.h>
26
+ #include < goto-programs/xml_goto_trace.h>
25
27
26
28
#include " counterexample_beautification.h"
27
29
@@ -144,7 +146,7 @@ void fault_localizationt::run(irep_idt goal_id)
144
146
145
147
if (goal_id==ID_nil)
146
148
goal_id=failed->source .pc ->source_location .get_property_id ();
147
- lpointst &lpoints = lpoints_map[goal_id];
149
+ lpointst &lpoints= lpoints_map[goal_id];
148
150
149
151
// collect lpoints
150
152
collect_guards (lpoints);
@@ -168,7 +170,7 @@ void fault_localizationt::report(irep_idt goal_id)
168
170
if (goal_id==ID_nil)
169
171
goal_id=failed->source .pc ->source_location .get_property_id ();
170
172
171
- lpointst &lpoints = lpoints_map[goal_id];
173
+ lpointst &lpoints= lpoints_map[goal_id];
172
174
173
175
if (lpoints.empty ())
174
176
{
@@ -192,6 +194,41 @@ void fault_localizationt::report(irep_idt goal_id)
192
194
<< eom;
193
195
}
194
196
197
+ xmlt fault_localizationt::report_xml (irep_idt goal_id)
198
+ {
199
+ xmlt xml_diagnosis (" diagnosis" );
200
+ xml_diagnosis.new_element (" method" ).data =" linear fault localization" ;
201
+
202
+ if (goal_id==ID_nil)
203
+ goal_id=failed->source .pc ->source_location .get_property_id ();
204
+
205
+ xml_diagnosis.set_attribute (" property" , id2string (goal_id));
206
+
207
+ const lpointst &lpoints=lpoints_map[goal_id];
208
+
209
+ if (lpoints.empty ())
210
+ {
211
+ xml_diagnosis.new_element (" result" ).data =" unable to localize fault" ;
212
+ return xml_diagnosis;
213
+ }
214
+
215
+ debug () << " Fault localization scores:" << eom;
216
+ const lpointt *max=&lpoints.begin ()->second ;
217
+ for (const auto &pair : lpoints)
218
+ {
219
+ const auto &value=pair.second ;
220
+ debug () << value.target ->source_location
221
+ << " \n score: " << value.score << eom;
222
+ if (max->score <value.score )
223
+ max=&value;
224
+ }
225
+
226
+ xmlt xml_location=xml (max->target ->source_location );
227
+ xml_diagnosis.new_element (" result" ).new_element ().swap (xml_location);
228
+
229
+ return xml_diagnosis;
230
+ }
231
+
195
232
safety_checkert::resultt fault_localizationt::operator ()()
196
233
{
197
234
if (options.get_bool_option (" stop-on-fail" ))
@@ -250,8 +287,27 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
250
287
251
288
// localize faults
252
289
run (ID_nil);
253
- status () << " \n ** Most likely fault location:" << eom;
254
- report (ID_nil);
290
+
291
+ switch (bmc.ui )
292
+ {
293
+ case ui_message_handlert::uit::PLAIN:
294
+ {
295
+ status () << " \n ** Most likely fault location:" << eom;
296
+ report (ID_nil);
297
+ break ;
298
+ }
299
+ case ui_message_handlert::uit::XML_UI:
300
+ {
301
+ xmlt dest (" fault-localization" );
302
+ xmlt xml_diagnosis=report_xml (ID_nil);
303
+ dest.new_element ().swap (xml_diagnosis);
304
+ status () << preformatted_output << dest << eom;
305
+ break ;
306
+ }
307
+ case ui_message_handlert::uit::JSON_UI:
308
+ // not implemented
309
+ break ;
310
+ }
255
311
256
312
bmc.report_failure ();
257
313
return safety_checkert::resultt::UNSAFE;
@@ -266,27 +322,27 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
266
322
void fault_localizationt::goal_covered (
267
323
const cover_goalst::goalt &)
268
324
{
269
- for (auto &g : goal_map)
325
+ for (auto &goal_pair : goal_map)
270
326
{
271
327
// failed already?
272
- if (g .second .status ==goalt::statust::FAILURE)
328
+ if (goal_pair .second .status ==goalt::statust::FAILURE)
273
329
continue ;
274
330
275
331
// check whether failed
276
- for (auto &c : g .second .instances )
332
+ for (auto &inst : goal_pair .second .instances )
277
333
{
278
- literalt cond=c ->cond_literal ;
334
+ literalt cond=inst ->cond_literal ;
279
335
280
336
if (solver.l_get (cond).is_false ())
281
337
{
282
- g .second .status =goalt::statust::FAILURE;
283
- symex_target_equationt::SSA_stepst::iterator next=c ;
338
+ goal_pair .second .status =goalt::statust::FAILURE;
339
+ symex_target_equationt::SSA_stepst::iterator next=inst ;
284
340
next++; // include the assertion
285
- build_goto_trace (bmc. equation , next, solver, bmc. ns ,
286
- g .second .goto_trace );
341
+ build_goto_trace (
342
+ bmc. equation , next, solver, bmc. ns , goal_pair .second .goto_trace );
287
343
288
344
// localize faults
289
- run (g .first );
345
+ run (goal_pair .first );
290
346
291
347
break ;
292
348
}
@@ -305,17 +361,29 @@ void fault_localizationt::report(
305
361
if (cover_goals.number_covered ()>0 )
306
362
{
307
363
status () << " \n ** Most likely fault location:" << eom;
308
- for (auto &g : goal_map)
364
+ for (auto &goal_pair : goal_map)
309
365
{
310
- if (g .second .status !=goalt::statust::FAILURE)
366
+ if (goal_pair .second .status !=goalt::statust::FAILURE)
311
367
continue ;
312
- report (g .first );
368
+ report (goal_pair .first );
313
369
}
314
370
}
315
371
break ;
316
372
case ui_message_handlert::uit::XML_UI:
373
+ {
374
+ xmlt dest (" fault-localization" );
375
+ for (auto &goal_pair : goal_map)
376
+ {
377
+ if (goal_pair.second .status !=goalt::statust::FAILURE)
378
+ continue ;
379
+ xmlt xml_diagnosis=report_xml (goal_pair.first );
380
+ dest.new_element ().swap (xml_diagnosis);
381
+ }
382
+ status () << preformatted_output << dest << eom;
383
+ }
317
384
break ;
318
385
case ui_message_handlert::uit::JSON_UI:
386
+ // not implemented
319
387
break ;
320
388
}
321
389
}
0 commit comments