DIFetcher.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "llvm/DebugInfo/Symbolize/DIFetcher.h"
  15. #include "llvm/Debuginfod/Debuginfod.h"
  16. #include "llvm/Support/FileSystem.h"
  17. #include "llvm/Support/Path.h"
  18. namespace llvm {
  19. namespace symbolize {
  20. Optional<std::string>
  21. LocalDIFetcher::fetchBuildID(ArrayRef<uint8_t> BuildID) const {
  22. auto GetDebugPath = [&](StringRef Directory) {
  23. SmallString<128> Path{Directory};
  24. sys::path::append(Path, ".build-id",
  25. llvm::toHex(BuildID[0], /*LowerCase=*/true),
  26. llvm::toHex(BuildID.slice(1), /*LowerCase=*/true));
  27. Path += ".debug";
  28. return Path;
  29. };
  30. if (DebugFileDirectory.empty()) {
  31. SmallString<128> Path = GetDebugPath(
  32. #if defined(__NetBSD__)
  33. // Try /usr/libdata/debug/.build-id/../...
  34. "/usr/libdata/debug"
  35. #else
  36. // Try /usr/lib/debug/.build-id/../...
  37. "/usr/lib/debug"
  38. #endif
  39. );
  40. if (llvm::sys::fs::exists(Path))
  41. return std::string(Path);
  42. } else {
  43. for (const auto &Directory : DebugFileDirectory) {
  44. // Try <debug-file-directory>/.build-id/../...
  45. SmallString<128> Path = GetDebugPath(Directory);
  46. if (llvm::sys::fs::exists(Path))
  47. return std::string(Path);
  48. }
  49. }
  50. return None;
  51. }
  52. } // namespace symbolize
  53. } // namespace llvm