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" 14*da650094SDouglas 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()) { 24aeda128aSGreg Clayton Fullpath = 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()) 32aeda128aSGreg Clayton Fullpath = 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) { 38aeda128aSGreg Clayton OS << SL.Name << " @ "; 39aeda128aSGreg Clayton if (!SL.Dir.empty()) { 40aeda128aSGreg Clayton OS << SL.Dir; 41aeda128aSGreg Clayton if (SL.Dir.contains('\\') and not SL.Dir.contains('/')) 42aeda128aSGreg Clayton OS << '\\'; 43aeda128aSGreg Clayton else 44aeda128aSGreg Clayton OS << '/'; 45aeda128aSGreg Clayton } 46aeda128aSGreg Clayton if (SL.Base.empty()) 47aeda128aSGreg Clayton OS << "<invalid-file>"; 48aeda128aSGreg Clayton else 49aeda128aSGreg Clayton OS << SL.Base; 50aeda128aSGreg Clayton OS << ':' << SL.Line; 51aeda128aSGreg Clayton return OS; 52aeda128aSGreg Clayton } 53aeda128aSGreg Clayton 54aeda128aSGreg Clayton raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const LookupResult &LR) { 55aeda128aSGreg Clayton OS << HEX64(LR.LookupAddr) << ": "; 56aeda128aSGreg Clayton auto NumLocations = LR.Locations.size(); 57aeda128aSGreg Clayton for (size_t I = 0; I < NumLocations; ++I) { 58aeda128aSGreg Clayton if (I > 0) { 59aeda128aSGreg Clayton OS << '\n'; 60aeda128aSGreg Clayton OS.indent(20); 61aeda128aSGreg Clayton } 62aeda128aSGreg Clayton const bool IsInlined = I + 1 != NumLocations; 63aeda128aSGreg Clayton OS << LR.Locations[I]; 64aeda128aSGreg Clayton if (IsInlined) 65aeda128aSGreg Clayton OS << " [inlined]"; 66aeda128aSGreg Clayton } 67aeda128aSGreg Clayton OS << '\n'; 68aeda128aSGreg Clayton return OS; 69aeda128aSGreg Clayton } 70