LLVM  15.0.0git
DIFetcher.cpp
Go to the documentation of this file.
1 //===-- lib/DebugInfo/Symbolize/DIFetcher.cpp -----------------------------===//
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 /// \file
10 /// This file defines the implementation of the local debug info fetcher, which
11 /// searches cache directories.
12 ///
13 //===----------------------------------------------------------------------===//
14 
16 
18 #include "llvm/Support/Path.h"
19 
20 namespace llvm {
21 namespace symbolize {
22 
23 Optional<std::string>
25  auto GetDebugPath = [&](StringRef Directory) {
26  SmallString<128> Path{Directory};
27  sys::path::append(Path, ".build-id",
28  llvm::toHex(BuildID[0], /*LowerCase=*/true),
29  llvm::toHex(BuildID.slice(1), /*LowerCase=*/true));
30  Path += ".debug";
31  return Path;
32  };
33  if (DebugFileDirectory.empty()) {
34  SmallString<128> Path = GetDebugPath(
35 #if defined(__NetBSD__)
36  // Try /usr/libdata/debug/.build-id/../...
37  "/usr/libdata/debug"
38 #else
39  // Try /usr/lib/debug/.build-id/../...
40  "/usr/lib/debug"
41 #endif
42  );
43  if (llvm::sys::fs::exists(Path))
44  return std::string(Path);
45  } else {
46  for (const auto &Directory : DebugFileDirectory) {
47  // Try <debug-file-directory>/.build-id/../...
48  SmallString<128> Path = GetDebugPath(Directory);
49  if (llvm::sys::fs::exists(Path))
50  return std::string(Path);
51  }
52  }
53  return None;
54 }
55 
56 } // namespace symbolize
57 } // namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
FileSystem.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
Path.h
llvm::symbolize::LocalDIFetcher::fetchBuildID
Optional< std::string > fetchBuildID(ArrayRef< uint8_t > BuildID) const override
Definition: DIFetcher.cpp:24
endif
__FakeVCSRevision h endif() endif() set(generated_files "$
Definition: CMakeLists.txt:16
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:456
llvm::None
const NoneType None
Definition: None.h:24
llvm::SmallString< 128 >
llvm::sys::fs::exists
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1077
llvm::symbolize::toHex
static std::string toHex(uint64_t V)
Definition: DIPrinter.cpp:278
DIFetcher.h
llvm::ArrayRef< uint8_t >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58