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