LookupResult.cpp 2.1 KB

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