blob: c00f4ccc67ba54750aed2ef8360ce63079da1170 [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
22using namespace lldb;
23using namespace lldb_private;
24
Ed Masted3561c62013-07-02 13:52:38 +000025#if defined (__linux__) || defined (__FreeBSD__)
Michael Sartaina7499c92013-07-01 19:45:50 +000026
27FileSpec
28Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
29{
30 // FIXME
31 return FileSpec();
32}
33
34FileSpec
35Symbols::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, 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__)
Greg Clayton2bddd342010-09-07 20:11:56 +0000132
Eli Friedman5423ebf2010-07-02 19:28:44 +0000133FileSpec
Greg Claytonb9a01b32012-02-26 05:51:37 +0000134Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
Eli Friedman5423ebf2010-07-02 19:28:44 +0000135{
Greg Clayton2bddd342010-09-07 20:11:56 +0000136 // FIXME
Eli Friedman5423ebf2010-07-02 19:28:44 +0000137 return FileSpec();
138}
139
140FileSpec
Greg Claytonb9a01b32012-02-26 05:51:37 +0000141Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
Eli Friedman5423ebf2010-07-02 19:28:44 +0000142{
Greg Clayton2bddd342010-09-07 20:11:56 +0000143 // FIXME
Eli Friedman5423ebf2010-07-02 19:28:44 +0000144 return FileSpec();
145}
Greg Clayton2bddd342010-09-07 20:11:56 +0000146
Greg Clayton103f0282012-09-12 02:03:59 +0000147FileSpec
148Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
149 const lldb_private::UUID *uuid,
150 const ArchSpec *arch)
151{
152 return FileSpec();
153}
154
Greg Claytonc8f814d2012-09-27 03:13:55 +0000155bool
Jason Molenda0a725202012-10-09 18:40:44 +0000156Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
Greg Claytonc8f814d2012-09-27 03:13:55 +0000157{
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
Greg Clayton2bddd342010-09-07 20:11:56 +0000163#endif