LookupResult.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //===- LookupResult.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. #include "llvm/DebugInfo/GSYM/LookupResult.h"
  9. #include "llvm/ADT/SmallString.h"
  10. #include "llvm/DebugInfo/GSYM/ExtractRanges.h"
  11. #include "llvm/Support/Format.h"
  12. #include "llvm/Support/Path.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. #include <ciso646>
  15. using namespace llvm;
  16. using namespace gsym;
  17. std::string LookupResult::getSourceFile(uint32_t Index) const {
  18. std::string Fullpath;
  19. if (Index < Locations.size()) {
  20. if (!Locations[Index].Dir.empty()) {
  21. if (Locations[Index].Base.empty()) {
  22. Fullpath = std::string(Locations[Index].Dir);
  23. } else {
  24. llvm::SmallString<64> Storage;
  25. llvm::sys::path::append(Storage, Locations[Index].Dir,
  26. Locations[Index].Base);
  27. Fullpath.assign(Storage.begin(), Storage.end());
  28. }
  29. } else if (!Locations[Index].Base.empty())
  30. Fullpath = std::string(Locations[Index].Base);
  31. }
  32. return Fullpath;
  33. }
  34. raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const SourceLocation &SL) {
  35. OS << SL.Name;
  36. if (SL.Offset > 0)
  37. OS << " + " << SL.Offset;
  38. if (SL.Dir.size() || SL.Base.size()) {
  39. OS << " @ ";
  40. if (!SL.Dir.empty()) {
  41. OS << SL.Dir;
  42. if (SL.Dir.contains('\\') && !SL.Dir.contains('/'))
  43. OS << '\\';
  44. else
  45. OS << '/';
  46. }
  47. if (SL.Base.empty())
  48. OS << "<invalid-file>";
  49. else
  50. OS << SL.Base;
  51. OS << ':' << SL.Line;
  52. }
  53. return OS;
  54. }
  55. raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const LookupResult &LR) {
  56. OS << HEX64(LR.LookupAddr) << ": ";
  57. auto NumLocations = LR.Locations.size();
  58. for (size_t I = 0; I < NumLocations; ++I) {
  59. if (I > 0) {
  60. OS << '\n';
  61. OS.indent(20);
  62. }
  63. const bool IsInlined = I + 1 != NumLocations;
  64. OS << LR.Locations[I];
  65. if (IsInlined)
  66. OS << " [inlined]";
  67. }
  68. OS << '\n';
  69. return OS;
  70. }