1*aeda128aSGreg Clayton //===- LookupResult.cpp -------------------------------------------------*-===// 2*aeda128aSGreg Clayton // 3*aeda128aSGreg Clayton // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*aeda128aSGreg Clayton // See https://llvm.org/LICENSE.txt for license information. 5*aeda128aSGreg Clayton // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*aeda128aSGreg Clayton // 7*aeda128aSGreg Clayton //===----------------------------------------------------------------------===// 8*aeda128aSGreg Clayton 9*aeda128aSGreg Clayton #include "llvm/DebugInfo/GSYM/LookupResult.h" 10*aeda128aSGreg Clayton #include "llvm/ADT/SmallString.h" 11*aeda128aSGreg Clayton #include "llvm/Support/Format.h" 12*aeda128aSGreg Clayton #include "llvm/Support/Path.h" 13*aeda128aSGreg Clayton #include "llvm/Support/raw_ostream.h" 14*aeda128aSGreg Clayton 15*aeda128aSGreg Clayton using namespace llvm; 16*aeda128aSGreg Clayton using namespace gsym; 17*aeda128aSGreg Clayton 18*aeda128aSGreg Clayton std::string LookupResult::getSourceFile(uint32_t Index) const { 19*aeda128aSGreg Clayton std::string Fullpath; 20*aeda128aSGreg Clayton if (Index < Locations.size()) { 21*aeda128aSGreg Clayton if (!Locations[Index].Dir.empty()) { 22*aeda128aSGreg Clayton if (Locations[Index].Base.empty()) { 23*aeda128aSGreg Clayton Fullpath = Locations[Index].Dir; 24*aeda128aSGreg Clayton } else { 25*aeda128aSGreg Clayton llvm::SmallString<64> Storage; 26*aeda128aSGreg Clayton llvm::sys::path::append(Storage, Locations[Index].Dir, 27*aeda128aSGreg Clayton Locations[Index].Base); 28*aeda128aSGreg Clayton Fullpath.assign(Storage.begin(), Storage.end()); 29*aeda128aSGreg Clayton } 30*aeda128aSGreg Clayton } else if (!Locations[Index].Base.empty()) 31*aeda128aSGreg Clayton Fullpath = Locations[Index].Base; 32*aeda128aSGreg Clayton } 33*aeda128aSGreg Clayton return Fullpath; 34*aeda128aSGreg Clayton } 35*aeda128aSGreg Clayton 36*aeda128aSGreg Clayton raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const SourceLocation &SL) { 37*aeda128aSGreg Clayton OS << SL.Name << " @ "; 38*aeda128aSGreg Clayton if (!SL.Dir.empty()) { 39*aeda128aSGreg Clayton OS << SL.Dir; 40*aeda128aSGreg Clayton if (SL.Dir.contains('\\') and not SL.Dir.contains('/')) 41*aeda128aSGreg Clayton OS << '\\'; 42*aeda128aSGreg Clayton else 43*aeda128aSGreg Clayton OS << '/'; 44*aeda128aSGreg Clayton } 45*aeda128aSGreg Clayton if (SL.Base.empty()) 46*aeda128aSGreg Clayton OS << "<invalid-file>"; 47*aeda128aSGreg Clayton else 48*aeda128aSGreg Clayton OS << SL.Base; 49*aeda128aSGreg Clayton OS << ':' << SL.Line; 50*aeda128aSGreg Clayton return OS; 51*aeda128aSGreg Clayton } 52*aeda128aSGreg Clayton 53*aeda128aSGreg Clayton raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const LookupResult &LR) { 54*aeda128aSGreg Clayton OS << HEX64(LR.LookupAddr) << ": "; 55*aeda128aSGreg Clayton auto NumLocations = LR.Locations.size(); 56*aeda128aSGreg Clayton for (size_t I = 0; I < NumLocations; ++I) { 57*aeda128aSGreg Clayton if (I > 0) { 58*aeda128aSGreg Clayton OS << '\n'; 59*aeda128aSGreg Clayton OS.indent(20); 60*aeda128aSGreg Clayton } 61*aeda128aSGreg Clayton const bool IsInlined = I + 1 != NumLocations; 62*aeda128aSGreg Clayton OS << LR.Locations[I]; 63*aeda128aSGreg Clayton if (IsInlined) 64*aeda128aSGreg Clayton OS << " [inlined]"; 65*aeda128aSGreg Clayton } 66*aeda128aSGreg Clayton OS << '\n'; 67*aeda128aSGreg Clayton return OS; 68*aeda128aSGreg Clayton } 69