1 //===-- Symbols.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
23 using namespace lldb_private;
25 #if defined (__linux__) || defined (__FreeBSD__)
28 Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
35 Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
37 const char *symbol_filename = module_spec.GetSymbolFileSpec().GetFilename().AsCString();
38 if (!symbol_filename || !symbol_filename[0])
41 FileSpecList debug_file_search_paths (Target::GetDefaultDebugFileSearchPaths());
43 // Add module directory.
44 const ConstString &file_dir = module_spec.GetFileSpec().GetDirectory();
45 debug_file_search_paths.AppendIfUnique (FileSpec(file_dir.AsCString("."), true));
47 // Add current working directory.
48 debug_file_search_paths.AppendIfUnique (FileSpec(".", true));
50 // Add /usr/lib/debug directory.
51 debug_file_search_paths.AppendIfUnique (FileSpec("/usr/lib/debug", true));
54 const UUID &module_uuid = module_spec.GetUUID();
55 if (module_uuid.IsValid())
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";
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();
68 size_t num_directories = debug_file_search_paths.GetSize();
69 for (size_t idx = 0; idx < num_directories; ++idx)
71 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex (idx);
72 dirspec.ResolvePath();
73 if (!dirspec.Exists() || !dirspec.IsDirectory())
76 std::vector<std::string> files;
77 std::string dirname = dirspec.GetPath();
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);
84 const uint32_t num_files = files.size();
85 for (size_t idx_file = 0; idx_file < num_files; ++idx_file)
87 const std::string &filename = files[idx_file];
88 FileSpec file_spec (filename.c_str(), true);
90 if (file_spec == module_spec.GetFileSpec())
93 if (file_spec.Exists())
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");
101 if (specs.GetModuleSpecAtIndex (0, mspec))
103 if (mspec.GetUUID() == module_uuid)
115 Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
116 const lldb_private::UUID *uuid,
117 const ArchSpec *arch)
124 Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
126 // Fill in the module_spec.GetFileSpec() for the object file and/or the
127 // module_spec.GetSymbolFileSpec() for the debug symbols file.
131 #elif !defined (__APPLE__)
134 Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
141 Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
148 Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
149 const lldb_private::UUID *uuid,
150 const ArchSpec *arch)
156 Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
158 // Fill in the module_spec.GetFileSpec() for the object file and/or the
159 // module_spec.GetSymbolFileSpec() for the debug symbols file.