1 /**
2 * @file image_errors.cpp
3 * Report errors in images
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author John Levon
9 */
10
11 #include "image_errors.h"
12
13 #include "arrange_profiles.h"
14 #include "string_manip.h"
15 #include "locate_images.h"
16
17 #include <iostream>
18 #include <set>
19
20 using namespace std;
21
22 namespace {
23
24 set<string> reported_images_error;
25
26 }
27
report_image_error(string const & image,image_error error,bool fatal,extra_images const & extra)28 void report_image_error(string const & image, image_error error, bool fatal,
29 extra_images const & extra)
30 {
31 if (error == image_ok)
32 return;
33
34 string image_name = extra.get_archive_path() + image;
35
36 if (reported_images_error.find(image_name) ==
37 reported_images_error.end()) {
38 reported_images_error.insert(image_name);
39
40 // FIXME: hacky
41 if (error == image_not_found && is_prefix(image, "anon "))
42 return;
43
44 cerr << (fatal ? "error: " : "warning: ");
45 cerr << image_name << ' ';
46
47 switch (error) {
48 case image_not_found:
49 cerr << "could not be found.\n";
50 break;
51
52 case image_unreadable:
53 cerr << "could not be read.\n";
54 break;
55
56 case image_multiple_match:
57 cerr << "matches more than one file: "
58 "detailed profile will not be provided.\n";
59 break;
60
61 case image_format_failure:
62 cerr << "is not in a usable binary format.\n";
63 break;
64
65 case image_ok:
66 break;
67 }
68 }
69 }
70
71
report_image_error(inverted_profile const & profile,bool fatal,extra_images const & extra)72 void report_image_error(inverted_profile const & profile, bool fatal,
73 extra_images const & extra)
74 {
75 report_image_error(profile.image, profile.error, fatal, extra);
76 }
77
78
report_image_errors(list<inverted_profile> const & plist,extra_images const & extra)79 void report_image_errors(list<inverted_profile> const & plist,
80 extra_images const & extra)
81 {
82 list<inverted_profile>::const_iterator it = plist.begin();
83 list<inverted_profile>::const_iterator const end = plist.end();
84
85 for (; it != end; ++it)
86 report_image_error(*it, false, extra);
87 }
88