blob: 304d44730bf6d925558beb2533d1219f01520d30 [file] [log] [blame]
Eli Friedman5423ebf2010-07-02 19:28:44 +00001//===-- 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"
Michael Sartaina7499c92013-07-01 19:45:50 +000011#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"
Eli Friedman5423ebf2010-07-02 19:28:44 +000021
Zachary Turner88c6b622015-03-03 18:34:26 +000022#include "llvm/Support/FileSystem.h"
23
Eli Friedman5423ebf2010-07-02 19:28:44 +000024using namespace lldb;
25using namespace lldb_private;
26
Ed Masted3561c62013-07-02 13:52:38 +000027#if defined (__linux__) || defined (__FreeBSD__)
Michael Sartaina7499c92013-07-01 19:45:50 +000028
29FileSpec
30Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
31{
32 // FIXME
33 return FileSpec();
34}
35
36FileSpec
37Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
38{
39 const char *symbol_filename = module_spec.GetSymbolFileSpec().GetFilename().AsCString();
40 if (!symbol_filename || !symbol_filename[0])
41 return FileSpec();
42
43 FileSpecList debug_file_search_paths (Target::GetDefaultDebugFileSearchPaths());
44
45 // Add module directory.
46 const ConstString &file_dir = module_spec.GetFileSpec().GetDirectory();
47 debug_file_search_paths.AppendIfUnique (FileSpec(file_dir.AsCString("."), true));
48
49 // Add current working directory.
50 debug_file_search_paths.AppendIfUnique (FileSpec(".", true));
51
52 // Add /usr/lib/debug directory.
53 debug_file_search_paths.AppendIfUnique (FileSpec("/usr/lib/debug", true));
54
55 std::string uuid_str;
56 const UUID &module_uuid = module_spec.GetUUID();
57 if (module_uuid.IsValid())
58 {
59 // Some debug files are stored in the .build-id directory like this:
60 // /usr/lib/debug/.build-id/ff/e7fe727889ad82bb153de2ad065b2189693315.debug
61 uuid_str = module_uuid.GetAsString("");
62 uuid_str.insert (2, 1, '/');
63 uuid_str = uuid_str + ".debug";
64 }
65
Ed Masteac7270b2013-11-25 20:33:56 +000066 // Get directory of our module. Needed to check debug files like this:
67 // /usr/lib/debug/usr/lib/library.so.debug
68 std::string module_directory = module_spec.GetFileSpec().GetDirectory().AsCString();
Michael Sartaina7499c92013-07-01 19:45:50 +000069
70 size_t num_directories = debug_file_search_paths.GetSize();
71 for (size_t idx = 0; idx < num_directories; ++idx)
72 {
73 FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex (idx);
74 dirspec.ResolvePath();
75 if (!dirspec.Exists() || !dirspec.IsDirectory())
76 continue;
77
78 std::vector<std::string> files;
79 std::string dirname = dirspec.GetPath();
80
81 files.push_back (dirname + "/" + symbol_filename);
82 files.push_back (dirname + "/.debug/" + symbol_filename);
83 files.push_back (dirname + "/.build-id/" + uuid_str);
Ed Masteac7270b2013-11-25 20:33:56 +000084 files.push_back (dirname + module_directory + "/" + symbol_filename);
Michael Sartaina7499c92013-07-01 19:45:50 +000085
86 const uint32_t num_files = files.size();
87 for (size_t idx_file = 0; idx_file < num_files; ++idx_file)
88 {
89 const std::string &filename = files[idx_file];
90 FileSpec file_spec (filename.c_str(), true);
91
Pavel Labath7257d282015-02-25 10:44:35 +000092 if (llvm::sys::fs::equivalent (file_spec.GetPath(), module_spec.GetFileSpec().GetPath()))
Michael Sartaina7499c92013-07-01 19:45:50 +000093 continue;
94
95 if (file_spec.Exists())
96 {
97 lldb_private::ModuleSpecList specs;
Greg Clayton090b5912013-07-12 22:40:04 +000098 const size_t num_specs = ObjectFile::GetModuleSpecifications (file_spec, 0, 0, specs);
Michael Sartaina7499c92013-07-01 19:45:50 +000099 assert (num_specs <= 1 && "Symbol Vendor supports only a single architecture");
100 if (num_specs == 1)
101 {
102 ModuleSpec mspec;
103 if (specs.GetModuleSpecAtIndex (0, mspec))
104 {
105 if (mspec.GetUUID() == module_uuid)
106 return file_spec;
107 }
108 }
109 }
110 }
111 }
112
113 return FileSpec();
114}
115
116FileSpec
117Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
118 const lldb_private::UUID *uuid,
119 const ArchSpec *arch)
120{
121 // FIXME
122 return FileSpec();
123}
124
125bool
126Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
127{
128 // Fill in the module_spec.GetFileSpec() for the object file and/or the
129 // module_spec.GetSymbolFileSpec() for the debug symbols file.
130 return false;
131}
132
133#elif !defined (__APPLE__)
Greg Clayton2bddd342010-09-07 20:11:56 +0000134
Eli Friedman5423ebf2010-07-02 19:28:44 +0000135FileSpec
Greg Claytonb9a01b32012-02-26 05:51:37 +0000136Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
Eli Friedman5423ebf2010-07-02 19:28:44 +0000137{
Greg Clayton2bddd342010-09-07 20:11:56 +0000138 // FIXME
Eli Friedman5423ebf2010-07-02 19:28:44 +0000139 return FileSpec();
140}
141
142FileSpec
Greg Claytonb9a01b32012-02-26 05:51:37 +0000143Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
Eli Friedman5423ebf2010-07-02 19:28:44 +0000144{
Greg Clayton2bddd342010-09-07 20:11:56 +0000145 // FIXME
Eli Friedman5423ebf2010-07-02 19:28:44 +0000146 return FileSpec();
147}
Greg Clayton2bddd342010-09-07 20:11:56 +0000148
Greg Clayton103f0282012-09-12 02:03:59 +0000149FileSpec
150Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
151 const lldb_private::UUID *uuid,
152 const ArchSpec *arch)
153{
154 return FileSpec();
155}
156
Greg Claytonc8f814d2012-09-27 03:13:55 +0000157bool
Jason Molenda0a725202012-10-09 18:40:44 +0000158Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
Greg Claytonc8f814d2012-09-27 03:13:55 +0000159{
160 // Fill in the module_spec.GetFileSpec() for the object file and/or the
161 // module_spec.GetSymbolFileSpec() for the debug symbols file.
162 return false;
163}
164
Greg Clayton2bddd342010-09-07 20:11:56 +0000165#endif