1 /** 2 * @file name_storage.cpp 3 * Storage of global names (filenames and symbols) 4 * 5 * @remark Copyright 2002 OProfile authors 6 * @remark Read the file COPYING 7 * 8 * @author Philippe Elie 9 * @author John Levon 10 */ 11 12 #include "name_storage.h" 13 #include "demangle_symbol.h" 14 #include "file_manip.h" 15 #include "string_manip.h" 16 #include "locate_images.h" 17 #include "op_exception.h" 18 19 using namespace std; 20 21 image_name_storage image_names; 22 debug_name_storage debug_names; 23 symbol_name_storage symbol_names; 24 25 26 string const & image_name_storage::basename(image_name_id id) const 27 { 28 stored_filename const & n = get(id); 29 if (n.base_filename.empty()) 30 n.base_filename = op_basename(n.filename); 31 return n.base_filename; 32 } 33 34 35 string const & image_name_storage::get_name(image_name_id id, 36 image_name_type type, 37 extra_images const & extra) const 38 { 39 stored_filename const & n = get(id); 40 if (type == int_filename) { 41 return n.filename; 42 } else if (type == int_basename) { 43 return basename(id); 44 } else if (type == int_real_basename) { 45 if (n.extra_images_uid == 0) { 46 // recursive call to init real_filename. 47 get_name(id, int_real_filename, extra); 48 n.real_base_filename = op_basename(n.real_filename); 49 } 50 return n.real_base_filename; 51 } else if (type == int_real_filename) { 52 if (n.extra_images_uid == 0) { 53 // We ignore error here, the real path will be 54 // identical to the name derived from the sample 55 // filename in this case. FIXME: this mean than the 56 // archive path will be ignored if an error occur. 57 image_error error; 58 n.real_filename = extra.find_image_path(name(id), 59 error, true); 60 n.extra_images_uid = extra.get_uid(); 61 } 62 63 if (n.extra_images_uid == extra.get_uid()) 64 return n.real_filename; 65 throw op_runtime_error("image_name_storage::get_name() called" 66 " with different extra parameter"); 67 } 68 69 throw op_runtime_error("invalid parameter to" 70 " image_name_storage;;get_name()"); 71 } 72 73 74 string const & debug_name_storage::basename(debug_name_id id) const 75 { 76 stored_name const & n = get(id); 77 if (n.name_processed.empty()) 78 n.name_processed = op_basename(n.name); 79 return n.name_processed; 80 } 81 82 83 string const & symbol_name_storage::demangle(symbol_name_id id) const 84 { 85 stored_name const & n = get(id); 86 if (!n.name_processed.empty() || n.name.empty()) 87 return n.name_processed; 88 89 if (n.name[0] != '?') { 90 n.name_processed = demangle_symbol(n.name); 91 return n.name_processed; 92 } 93 94 if (n.name.length() < 2 || n.name[1] != '?') { 95 n.name_processed = "(no symbols)"; 96 return n.name_processed; 97 } 98 99 n.name_processed = "anonymous symbol from section "; 100 n.name_processed += ltrim(n.name, "?"); 101 return n.name_processed; 102 } 103