Upstream | cc2ee17 | 1970-01-12 13:46:40 +0000 | [diff] [blame^] | 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 | |
| 16 | #include <iostream> |
| 17 | #include <set> |
| 18 | |
| 19 | using namespace std; |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | set<string> reported_images_error; |
| 24 | |
| 25 | } |
| 26 | |
| 27 | void report_image_error(string const & image, image_error error, bool fatal) |
| 28 | { |
| 29 | if (error == image_ok) |
| 30 | return; |
| 31 | |
| 32 | if (reported_images_error.find(image) == reported_images_error.end()) { |
| 33 | reported_images_error.insert(image); |
| 34 | |
| 35 | // FIXME: hacky |
| 36 | if (error == image_not_found && is_prefix(image, "anon ")) |
| 37 | return; |
| 38 | |
| 39 | cerr << (fatal ? "error: " : "warning: "); |
| 40 | cerr << image << ' '; |
| 41 | |
| 42 | switch (error) { |
| 43 | case image_not_found: |
| 44 | cerr << "could not be found.\n"; |
| 45 | break; |
| 46 | |
| 47 | case image_unreadable: |
| 48 | cerr << "could not be read.\n"; |
| 49 | break; |
| 50 | |
| 51 | case image_multiple_match: |
| 52 | cerr << "matches more than one file: " |
| 53 | "detailed profile will not be provided.\n"; |
| 54 | break; |
| 55 | |
| 56 | case image_format_failure: |
| 57 | cerr << "is not in a usable binary format.\n"; |
| 58 | break; |
| 59 | |
| 60 | case image_ok: |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void report_image_error(inverted_profile const & profile, bool fatal) |
| 68 | { |
| 69 | report_image_error(profile.image, profile.error, fatal); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | void report_image_errors(list<inverted_profile> const & plist) |
| 74 | { |
| 75 | list<inverted_profile>::const_iterator it = plist.begin(); |
| 76 | list<inverted_profile>::const_iterator const end = plist.end(); |
| 77 | |
| 78 | for (; it != end; ++it) { |
| 79 | report_image_error(*it, false); |
| 80 | } |
| 81 | } |