 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
77.8% |
14 / 18 |
| Generated: |
2009-05-17 22:47 |
|
Branches Executed: |
100.0% |
18 / 18 |
| |
|
Line Coverage: |
73.8% |
31 / 42 |
| |
 |
|
 |
1 : /* -*- mode: c++; c-basic-offset: 2; -*- */
2 :
3 : #include "Common.h"
4 :
5 : #include <stdlib.h>
6 : #include <stdio.h>
7 : #include <stdarg.h>
8 : #include <assert.h>
9 : #include <string.h>
10 :
11 : #include <set>
12 :
13 : using namespace klee;
14 :
15 : FILE* klee::klee_warning_file = NULL;
16 : FILE* klee::klee_message_file = NULL;
17 :
18 :
19 : /* Prints a message/warning.
20 :
21 : If pfx is NULL, this is a regular message, and it's sent to
22 : klee_message_file (messages.txt). Otherwise, it is sent to
23 : klee_warning_file (warnings.txt).
24 :
25 : Iff onlyToFile is false, the message is also printed on stderr.
26 : */
27 529: static void klee_vmessage(const char *pfx, bool onlyToFile, const char *msg, va_list ap) {
28 529: FILE *f = stderr;
529: branch 0 taken
0: branch 1 not taken
29 529: if (!onlyToFile) {
30 : fprintf(f, "KLEE: ");
153: branch 0 taken
376: branch 1 taken
31 529: if (pfx) fprintf(f, "%s: ", pfx);
32 : vfprintf(f, msg, ap);
33 : fprintf(f, "\n");
34 529: fflush(f);
35 : }
36 :
376: branch 0 taken
153: branch 1 taken
37 529: if (pfx == NULL)
38 376: f = klee_message_file;
39 153: else f = klee_warning_file;
40 :
529: branch 0 taken
0: branch 1 not taken
41 529: if (f) {
42 : fprintf(f, "KLEE: ");
153: branch 0 taken
376: branch 1 taken
43 529: if (pfx) fprintf(f, "%s: ", pfx);
44 : vfprintf(f, msg, ap);
45 : fprintf(f, "\n");
46 529: fflush(f);
47 : }
48 529: }
49 :
50 :
51 376: void klee::klee_message(const char *msg, ...) {
52 : va_list ap;
53 376: va_start(ap, msg);
54 376: klee_vmessage(NULL, false, msg, ap);
55 376: va_end(ap);
56 376: }
57 :
58 : /* Message to be written only to file */
59 0: void klee::klee_message_to_file(const char *msg, ...) {
60 : va_list ap;
61 0: va_start(ap, msg);
62 0: klee_vmessage(NULL, true, msg, ap);
63 0: va_end(ap);
64 0: }
65 :
66 0: void klee::klee_error(const char *msg, ...) {
67 : va_list ap;
68 0: va_start(ap, msg);
69 0: klee_vmessage("ERROR", false, msg, ap);
70 0: va_end(ap);
71 0: exit(1);
72 : }
73 :
74 95: void klee::klee_warning(const char *msg, ...) {
75 : va_list ap;
76 95: va_start(ap, msg);
77 95: klee_vmessage("WARNING", false, msg, ap);
78 95: va_end(ap);
79 95: }
80 :
81 :
82 : /* Prints a warning once per message. */
83 310: void klee::klee_warning_once(const void *id, const char *msg, ...) {
38: branch 0 taken
272: branch 1 taken
38: branch 3 taken
0: branch 4 not taken
84 348: static std::set< std::pair<const void*, const char*> > keys;
85 : std::pair<const void*, const char*> key;
86 :
87 :
88 : /* "calling external" messages contain the actual arguments with
89 : which we called the external function, so we need to ignore them
90 : when computing the key. */
310: branch 1 taken
0: branch 2 not taken
91 310: if (strncmp(msg, "calling external", strlen("calling external")) != 0)
92 620: key = std::make_pair(id, msg);
93 0: else key = std::make_pair(id, "calling external");
94 :
58: branch 0 taken
252: branch 1 taken
95 310: if (!keys.count(key)) {
96 : keys.insert(key);
97 :
98 : va_list ap;
99 58: va_start(ap, msg);
100 58: klee_vmessage("WARNING", false, msg, ap);
101 58: va_end(ap);
102 : }
103 310: }
Generated: 2009-05-17 22:47 by zcov