11fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce//===-- Symbols.cpp ---------------------------------------------*- C++ -*-===// 21fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// 31fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// The LLVM Compiler Infrastructure 41fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// 51fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// This file is distributed under the University of Illinois Open Source 61fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// License. See LICENSE.TXT for details. 71fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce// 81fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce//===----------------------------------------------------------------------===// 91fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 101fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Host/Symbols.h" 111fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/ArchSpec.h" 121fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/DataBuffer.h" 131fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/DataExtractor.h" 141fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/Module.h" 151fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/ModuleSpec.h" 161fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/StreamString.h" 171fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/Timer.h" 181fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Core/UUID.h" 191fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Symbol/ObjectFile.h" 201fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#include "lldb/Target/Target.h" 211fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 221fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruceusing namespace lldb; 231fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruceusing namespace lldb_private; 241fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 251fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce#if defined (__linux__) || defined (__FreeBSD__) 261fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 271fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" BruceFileSpec 281fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" BruceSymbols::LocateExecutableObjectFile (const ModuleSpec &module_spec) 291fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce{ 301fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // FIXME 311fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce return FileSpec(); 321fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce} 331fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 341fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" BruceFileSpec 351fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" BruceSymbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec) 361fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce{ 371fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce const char *symbol_filename = module_spec.GetSymbolFileSpec().GetFilename().AsCString(); 381fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce if (!symbol_filename || !symbol_filename[0]) 391fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce return FileSpec(); 401fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 411fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce FileSpecList debug_file_search_paths (Target::GetDefaultDebugFileSearchPaths()); 421fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 431fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // Add module directory. 441fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce const ConstString &file_dir = module_spec.GetFileSpec().GetDirectory(); 451fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce debug_file_search_paths.AppendIfUnique (FileSpec(file_dir.AsCString("."), true)); 461fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 471fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // Add current working directory. 481fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce debug_file_search_paths.AppendIfUnique (FileSpec(".", true)); 491fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 501fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // Add /usr/lib/debug directory. 511fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce debug_file_search_paths.AppendIfUnique (FileSpec("/usr/lib/debug", true)); 521fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 531fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce std::string uuid_str; 541fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce const UUID &module_uuid = module_spec.GetUUID(); 551fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce if (module_uuid.IsValid()) 561fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce { 571fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // Some debug files are stored in the .build-id directory like this: 581fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // /usr/lib/debug/.build-id/ff/e7fe727889ad82bb153de2ad065b2189693315.debug 591fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce uuid_str = module_uuid.GetAsString(""); 601fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce uuid_str.insert (2, 1, '/'); 611fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce uuid_str = uuid_str + ".debug"; 621fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce } 631fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 641fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // Get full path to our module. Needed to check debug files like this: 651fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce // /usr/lib/debug/usr/lib/libboost_date_time.so.1.46.1 661fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce std::string module_filename = module_spec.GetFileSpec().GetPath(); 671fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 681fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce size_t num_directories = debug_file_search_paths.GetSize(); 691fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce for (size_t idx = 0; idx < num_directories; ++idx) 701fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce { 711fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex (idx); 721fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce dirspec.ResolvePath(); 731fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce if (!dirspec.Exists() || !dirspec.IsDirectory()) 741fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce continue; 751fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 761fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce std::vector<std::string> files; 771fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce std::string dirname = dirspec.GetPath(); 781fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 791fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce files.push_back (dirname + "/" + symbol_filename); 801fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce files.push_back (dirname + "/.debug/" + symbol_filename); 811fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce files.push_back (dirname + "/.build-id/" + uuid_str); 821fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce files.push_back (dirname + module_filename); 831fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 841fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce const uint32_t num_files = files.size(); 851fe11a5d1b7932a8a4a4e6e8cf1aedd21fcdb3aaJohn "Juce" Bruce 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 114FileSpec 115Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle, 116 const lldb_private::UUID *uuid, 117 const ArchSpec *arch) 118{ 119 // FIXME 120 return FileSpec(); 121} 122 123bool 124Symbols::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 133FileSpec 134Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec) 135{ 136 // FIXME 137 return FileSpec(); 138} 139 140FileSpec 141Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec) 142{ 143 // FIXME 144 return FileSpec(); 145} 146 147FileSpec 148Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle, 149 const lldb_private::UUID *uuid, 150 const ArchSpec *arch) 151{ 152 return FileSpec(); 153} 154 155bool 156Symbols::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