LLDB mainline
SymbolLocator.h
Go to the documentation of this file.
1//===-- SymbolLocator.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SYMBOL_SYMBOLLOCATOR_H
10#define LLDB_SYMBOL_SYMBOLLOCATOR_H
11
15#include "lldb/Utility/Status.h"
16#include "lldb/Utility/UUID.h"
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/Support/Error.h"
20
21#include <optional>
22#include <string>
23#include <system_error>
24#include <vector>
25
26namespace lldb_private {
27
29public:
30 SymbolLocator() = default;
31
32 /// A binary was not found and nothing could say why. Distinct from every
33 /// other error so that a caller composing its own message for a plain miss
34 /// cannot mistake a real failure for one.
35 class NotFound : public llvm::ErrorInfo<NotFound> {
36 public:
37 static char ID;
38
39 void log(llvm::raw_ostream &os) const override;
40 std::error_code convertToErrorCode() const override;
41 };
42
43 /// One binary to search for.
44 struct Request {
45 /// What to look for.
47
48 /// A platform that may know where the binary is. The locator plugins have
49 /// no Platform of their own to consult.
51
52 /// Allow contacting an external symbol server when the local searches come
53 /// up empty.
54 bool external_lookup = false;
55
56 /// How to name this binary in a progress report.
57 std::string description;
58 };
59
60 /// What a search found.
61 struct Result {
62 /// The binary, and its symbol file if there is one to be had.
64
65 /// What an external symbol server had to say about the symbols, even
66 /// though the binary itself was found. Recorded rather than reported, so
67 /// that it reaches the user in the caller's order, and so has to be
68 /// consumed even by a caller that does not report it.
69 std::optional<llvm::Error> symbol_error;
70
71 /// Where the time went, to be merged into the Module once it exists.
73 };
74
75 /// Find a binary and, if possible, its symbols.
76 ///
77 /// Mutates no Target and no Process, which is what lets a caller holding
78 /// several binaries search for all of them before installing any.
79 ///
80 /// \return
81 /// Where the binary is, or an error if it could not be found at all.
82 /// Finding the binary but not its symbols is a success, with
83 /// Result::symbol_error carrying whatever a symbol server had to say
84 /// about them.
85 ///
86 /// A miss carries an external symbol server's explanation if it gave
87 /// one, and is a NotFound when nothing could say why.
88 static llvm::Expected<Result> Locate(const Request &request,
89 const FileSpecList &search_paths);
90
91 /// The platform hooks run on the calling thread, in order. Only the plugin
92 /// searches may run concurrently.
93 ///
94 /// \return One result per request, in the order the requests were given.
95 static std::vector<llvm::Expected<Result>>
96 Locate(llvm::ArrayRef<Request> requests, const FileSpecList &search_paths,
97 bool parallel);
98
99 /// Locate the symbol file for the given UUID on a background thread. This
100 /// function returns immediately. Under the hood it uses the debugger's
101 /// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is
102 /// found, this will notify all target which contain the module with the
103 /// given UUID.
104 static void DownloadSymbolFileAsync(const UUID &uuid);
105
106private:
107 /// Must stay callable concurrently.
108 static llvm::Expected<Result>
109 LocateWithPlugins(const Request &request, const FileSpecList &search_paths);
110};
111
112} // namespace lldb_private
113
114#endif // LLDB_SYMBOL_SYMBOLLOCATOR_H
A file collection class.
A class to count time for plugins.
Definition Statistics.h:94
A binary was not found and nothing could say why.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &os) const override
static void DownloadSymbolFileAsync(const UUID &uuid)
Locate the symbol file for the given UUID on a background thread.
static llvm::Expected< Result > Locate(const Request &request, const FileSpecList &search_paths)
Find a binary and, if possible, its symbols.
static llvm::Expected< Result > LocateWithPlugins(const Request &request, const FileSpecList &search_paths)
Must stay callable concurrently.
Represents UUID's of various sizes.
Definition UUID.h:27
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
One binary to search for.
lldb::PlatformSP platform
A platform that may know where the binary is.
std::string description
How to name this binary in a progress report.
ModuleSpec module_spec
What to look for.
bool external_lookup
Allow contacting an external symbol server when the local searches come up empty.
std::optional< llvm::Error > symbol_error
What an external symbol server had to say about the symbols, even though the binary itself was found.
StatisticsMap statistics
Where the time went, to be merged into the Module once it exists.
ModuleSpec module_spec
The binary, and its symbol file if there is one to be had.