LLVM  15.0.0git
LookupResult.cpp
Go to the documentation of this file.
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 
10 #include "llvm/ADT/SmallString.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/Path.h"
15 #include <ciso646>
16 
17 using namespace llvm;
18 using namespace gsym;
19 
20 std::string LookupResult::getSourceFile(uint32_t Index) const {
21  std::string Fullpath;
22  if (Index < Locations.size()) {
23  if (!Locations[Index].Dir.empty()) {
24  if (Locations[Index].Base.empty()) {
25  Fullpath = std::string(Locations[Index].Dir);
26  } else {
27  llvm::SmallString<64> Storage;
28  llvm::sys::path::append(Storage, Locations[Index].Dir,
29  Locations[Index].Base);
30  Fullpath.assign(Storage.begin(), Storage.end());
31  }
32  } else if (!Locations[Index].Base.empty())
33  Fullpath = std::string(Locations[Index].Base);
34  }
35  return Fullpath;
36 }
37 
39  OS << SL.Name;
40  if (SL.Offset > 0)
41  OS << " + " << SL.Offset;
42  if (SL.Dir.size() || SL.Base.size()) {
43  OS << " @ ";
44  if (!SL.Dir.empty()) {
45  OS << SL.Dir;
46  if (SL.Dir.contains('\\') && !SL.Dir.contains('/'))
47  OS << '\\';
48  else
49  OS << '/';
50  }
51  if (SL.Base.empty())
52  OS << "<invalid-file>";
53  else
54  OS << SL.Base;
55  OS << ':' << SL.Line;
56  }
57  return OS;
58 }
59 
61  OS << HEX64(LR.LookupAddr) << ": ";
62  auto NumLocations = LR.Locations.size();
63  for (size_t I = 0; I < NumLocations; ++I) {
64  if (I > 0) {
65  OS << '\n';
66  OS.indent(20);
67  }
68  const bool IsInlined = I + 1 != NumLocations;
69  OS << LR.Locations[I];
70  if (IsInlined)
71  OS << " [inlined]";
72  }
73  OS << '\n';
74  return OS;
75 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::gsym::LookupResult::getSourceFile
std::string getSourceFile(uint32_t Index) const
Definition: LookupResult.cpp:20
Path.h
llvm::gsym::LookupResult
Definition: LookupResult.h:38
llvm::gsym::LookupResult::Locations
SourceLocations Locations
The source locations that match this address.
Definition: LookupResult.h:51
ExtractRanges.h
llvm::gsym::SourceLocation::Name
StringRef Name
Function or symbol name.
Definition: LookupResult.h:22
Format.h
llvm::gsym::SourceLocation::Dir
StringRef Dir
Line entry source file directory path.
Definition: LookupResult.h:23
llvm::gsym::SourceLocation::Offset
uint32_t Offset
Byte size offset within the named function.
Definition: LookupResult.h:26
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::gsym::operator<<
raw_ostream & operator<<(raw_ostream &OS, const FunctionInfo &R)
Definition: FunctionInfo.cpp:27
SmallString.h
llvm::StringRef::contains
LLVM_NODISCARD bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:462
HEX64
#define HEX64(v)
Definition: ExtractRanges.h:21
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::SmallString< 64 >
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
LookupResult.h
llvm::gsym::LookupResult::LookupAddr
uint64_t LookupAddr
The address that this lookup pertains to.
Definition: LookupResult.h:39
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::gsym::SourceLocation::Base
StringRef Base
Line entry source file basename.
Definition: LookupResult.h:24
uint32_t
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition: raw_ostream.cpp:496
llvm::gsym::SourceLocation
Definition: LookupResult.h:21
raw_ostream.h
llvm::gsym::SourceLocation::Line
uint32_t Line
Source file line number.
Definition: LookupResult.h:25
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58