name_storage.cpp

Go to the documentation of this file.
00001 
00012 #include "name_storage.h"
00013 #include "demangle_symbol.h"
00014 #include "file_manip.h"
00015 #include "string_manip.h"
00016 #include "locate_images.h"
00017 #include "op_exception.h"
00018 
00019 using namespace std;
00020 
00021 image_name_storage image_names;
00022 debug_name_storage debug_names;
00023 symbol_name_storage symbol_names;
00024 
00025 
00026 string const & image_name_storage::basename(image_name_id id) const
00027 {
00028     stored_filename const & n = get(id);
00029     if (n.base_filename.empty())
00030         n.base_filename = op_basename(n.filename);
00031     return n.base_filename;
00032 }
00033 
00034 
00035 string const & image_name_storage::get_name(image_name_id id,
00036                         image_name_type type,
00037                         extra_images const & extra) const
00038 {
00039     stored_filename const & n = get(id);
00040     if (type == int_filename) {
00041         return n.filename;
00042     } else if (type == int_basename) {
00043         return basename(id);
00044     } else if (type == int_real_basename) {
00045         if (n.extra_images_uid == 0) {
00046             // recursive call to init real_filename.
00047             get_name(id, int_real_filename, extra);
00048             n.real_base_filename = op_basename(n.real_filename);
00049         }
00050         return n.real_base_filename;
00051     } else if (type == int_real_filename) {
00052         if (n.extra_images_uid == 0) {
00053             // We ignore error here, the real path will be
00054             // identical to the name derived from the sample
00055             // filename in this case. FIXME: this mean than the
00056             // archive path will be ignored if an error occur.
00057             image_error error;
00058             n.real_filename = extra.find_image_path(name(id),
00059                                 error, true);
00060             n.extra_images_uid = extra.get_uid();
00061         }
00062 
00063         if (n.extra_images_uid == extra.get_uid())
00064             return n.real_filename;
00065         throw op_runtime_error("image_name_storage::get_name() called"
00066                        " with different extra parameter");
00067     }
00068 
00069     throw op_runtime_error("invalid parameter to"
00070                    " image_name_storage;;get_name()");
00071 }
00072 
00073 
00074 string const & debug_name_storage::basename(debug_name_id id) const
00075 {
00076     stored_name const & n = get(id);
00077     if (n.name_processed.empty())
00078         n.name_processed = op_basename(n.name);
00079     return n.name_processed;
00080 }
00081 
00082 
00083 string const & symbol_name_storage::demangle(symbol_name_id id) const
00084 {
00085     stored_name const & n = get(id);
00086     if (!n.name_processed.empty() || n.name.empty())
00087         return n.name_processed;
00088 
00089     if (n.name[0] != '?') {
00090         n.name_processed = demangle_symbol(n.name);
00091         return n.name_processed;
00092     }
00093 
00094     if (n.name.length() < 2 || n.name[1] != '?') {
00095         n.name_processed = "(no symbols)";
00096         return n.name_processed;
00097     }
00098     
00099     n.name_processed = "anonymous symbol from section ";
00100     n.name_processed += ltrim(n.name, "?");
00101     return n.name_processed;
00102 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1