1 //===-- Symbols.cpp ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Host/Symbols.h" 11 #include "lldb/Core/ArchSpec.h" 12 #include "lldb/Core/DataBuffer.h" 13 #include "lldb/Core/DataExtractor.h" 14 #include "lldb/Core/Module.h" 15 #include "lldb/Core/ModuleSpec.h" 16 #include "lldb/Core/StreamString.h" 17 #include "lldb/Core/Timer.h" 18 #include "lldb/Core/UUID.h" 19 #include "lldb/Symbol/ObjectFile.h" 20 #include "lldb/Target/Target.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 #if defined (__linux__) || defined (__FreeBSD__) 26 27 FileSpec 28 Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec) 29 { 30 // FIXME 31 return FileSpec(); 32 } 33 34 FileSpec 35 Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec) 36 { 37 const char *symbol_filename = module_spec.GetSymbolFileSpec().GetFilename().AsCString(); 38 if (!symbol_filename || !symbol_filename[0]) 39 return FileSpec(); 40 41 FileSpecList debug_file_search_paths (Target::GetDefaultDebugFileSearchPaths()); 42 43 // Add module directory. 44 const ConstString &file_dir = module_spec.GetFileSpec().GetDirectory(); 45 debug_file_search_paths.AppendIfUnique (FileSpec(file_dir.AsCString("."), true)); 46 47 // Add current working directory. 48 debug_file_search_paths.AppendIfUnique (FileSpec(".", true)); 49 50 // Add /usr/lib/debug directory. 51 debug_file_search_paths.AppendIfUnique (FileSpec("/usr/lib/debug", true)); 52 53 std::string uuid_str; 54 const UUID &module_uuid = module_spec.GetUUID(); 55 if (module_uuid.IsValid()) 56 { 57 // Some debug files are stored in the .build-id directory like this: 58 // /usr/lib/debug/.build-id/ff/e7fe727889ad82bb153de2ad065b2189693315.debug 59 uuid_str = module_uuid.GetAsString(""); 60 uuid_str.insert (2, 1, '/'); 61 uuid_str = uuid_str + ".debug"; 62 } 63 64 // Get full path to our module. Needed to check debug files like this: 65 // /usr/lib/debug/usr/lib/libboost_date_time.so.1.46.1 66 std::string module_filename = module_spec.GetFileSpec().GetPath(); 67 68 size_t num_directories = debug_file_search_paths.GetSize(); 69 for (size_t idx = 0; idx < num_directories; ++idx) 70 { 71 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex (idx); 72 dirspec.ResolvePath(); 73 if (!dirspec.Exists() || !dirspec.IsDirectory()) 74 continue; 75 76 std::vector<std::string> files; 77 std::string dirname = dirspec.GetPath(); 78 79 files.push_back (dirname + "/" + symbol_filename); 80 files.push_back (dirname + "/.debug/" + symbol_filename); 81 files.push_back (dirname + "/.build-id/" + uuid_str); 82 files.push_back (dirname + module_filename); 83 84 const uint32_t num_files = files.size(); 85 for (size_t idx_file = 0; idx_file < num_files; ++idx_file) 86 { 87 const std::string &filename = files[idx_file]; 88 FileSpec file_spec (filename.c_str(), true); 89 90 if (file_spec == module_spec.GetFileSpec()) 91 continue; 92 93 if (file_spec.Exists()) 94 { 95 lldb_private::ModuleSpecList specs; 96 const size_t num_specs = ObjectFile::GetModuleSpecifications (file_spec, 0, 0, specs); 97 assert (num_specs <= 1 && "Symbol Vendor supports only a single architecture"); 98 if (num_specs == 1) 99 { 100 ModuleSpec mspec; 101 if (specs.GetModuleSpecAtIndex (0, mspec)) 102 { 103 if (mspec.GetUUID() == module_uuid) 104 return file_spec; 105 } 106 } 107 } 108 } 109 } 110 111 return FileSpec(); 112 } 113 114 FileSpec 115 Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle, 116 const lldb_private::UUID *uuid, 117 const ArchSpec *arch) 118 { 119 // FIXME 120 return FileSpec(); 121 } 122 123 bool 124 Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup) 125 { 126 // Fill in the module_spec.GetFileSpec() for the object file and/or the 127 // module_spec.GetSymbolFileSpec() for the debug symbols file. 128 return false; 129 } 130 131 #elif !defined (__APPLE__) 132 133 FileSpec 134 Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec) 135 { 136 // FIXME 137 return FileSpec(); 138 } 139 140 FileSpec 141 Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec) 142 { 143 // FIXME 144 return FileSpec(); 145 } 146 147 FileSpec 148 Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle, 149 const lldb_private::UUID *uuid, 150 const ArchSpec *arch) 151 { 152 return FileSpec(); 153 } 154 155 bool 156 Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup) 157 { 158 // Fill in the module_spec.GetFileSpec() for the object file and/or the 159 // module_spec.GetSymbolFileSpec() for the debug symbols file. 160 return false; 161 } 162 163 #endif 164