1480093f4SDimitry Andric //===- LookupResult.cpp -------------------------------------------------*-===// 2480093f4SDimitry Andric // 3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6480093f4SDimitry Andric // 7480093f4SDimitry Andric //===----------------------------------------------------------------------===// 8480093f4SDimitry Andric 9480093f4SDimitry Andric #include "llvm/DebugInfo/GSYM/LookupResult.h" 10480093f4SDimitry Andric #include "llvm/ADT/SmallString.h" 11*81ad6265SDimitry Andric #include "llvm/DebugInfo/GSYM/ExtractRanges.h" 12480093f4SDimitry Andric #include "llvm/Support/Format.h" 13480093f4SDimitry Andric #include "llvm/Support/Path.h" 14480093f4SDimitry Andric #include "llvm/Support/raw_ostream.h" 15480093f4SDimitry Andric #include <ciso646> 16480093f4SDimitry Andric 17480093f4SDimitry Andric using namespace llvm; 18480093f4SDimitry Andric using namespace gsym; 19480093f4SDimitry Andric getSourceFile(uint32_t Index) const20480093f4SDimitry Andricstd::string LookupResult::getSourceFile(uint32_t Index) const { 21480093f4SDimitry Andric std::string Fullpath; 22480093f4SDimitry Andric if (Index < Locations.size()) { 23480093f4SDimitry Andric if (!Locations[Index].Dir.empty()) { 24480093f4SDimitry Andric if (Locations[Index].Base.empty()) { 255ffd83dbSDimitry Andric Fullpath = std::string(Locations[Index].Dir); 26480093f4SDimitry Andric } else { 27480093f4SDimitry Andric llvm::SmallString<64> Storage; 28480093f4SDimitry Andric llvm::sys::path::append(Storage, Locations[Index].Dir, 29480093f4SDimitry Andric Locations[Index].Base); 30480093f4SDimitry Andric Fullpath.assign(Storage.begin(), Storage.end()); 31480093f4SDimitry Andric } 32480093f4SDimitry Andric } else if (!Locations[Index].Base.empty()) 335ffd83dbSDimitry Andric Fullpath = std::string(Locations[Index].Base); 34480093f4SDimitry Andric } 35480093f4SDimitry Andric return Fullpath; 36480093f4SDimitry Andric } 37480093f4SDimitry Andric operator <<(raw_ostream & OS,const SourceLocation & SL)38480093f4SDimitry Andricraw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const SourceLocation &SL) { 395ffd83dbSDimitry Andric OS << SL.Name; 405ffd83dbSDimitry Andric if (SL.Offset > 0) 415ffd83dbSDimitry Andric OS << " + " << SL.Offset; 425ffd83dbSDimitry Andric if (SL.Dir.size() || SL.Base.size()) { 435ffd83dbSDimitry Andric OS << " @ "; 44480093f4SDimitry Andric if (!SL.Dir.empty()) { 45480093f4SDimitry Andric OS << SL.Dir; 46*81ad6265SDimitry Andric if (SL.Dir.contains('\\') && !SL.Dir.contains('/')) 47480093f4SDimitry Andric OS << '\\'; 48480093f4SDimitry Andric else 49480093f4SDimitry Andric OS << '/'; 50480093f4SDimitry Andric } 51480093f4SDimitry Andric if (SL.Base.empty()) 52480093f4SDimitry Andric OS << "<invalid-file>"; 53480093f4SDimitry Andric else 54480093f4SDimitry Andric OS << SL.Base; 55480093f4SDimitry Andric OS << ':' << SL.Line; 565ffd83dbSDimitry Andric } 57480093f4SDimitry Andric return OS; 58480093f4SDimitry Andric } 59480093f4SDimitry Andric operator <<(raw_ostream & OS,const LookupResult & LR)60480093f4SDimitry Andricraw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const LookupResult &LR) { 61480093f4SDimitry Andric OS << HEX64(LR.LookupAddr) << ": "; 62480093f4SDimitry Andric auto NumLocations = LR.Locations.size(); 63480093f4SDimitry Andric for (size_t I = 0; I < NumLocations; ++I) { 64480093f4SDimitry Andric if (I > 0) { 65480093f4SDimitry Andric OS << '\n'; 66480093f4SDimitry Andric OS.indent(20); 67480093f4SDimitry Andric } 68480093f4SDimitry Andric const bool IsInlined = I + 1 != NumLocations; 69480093f4SDimitry Andric OS << LR.Locations[I]; 70480093f4SDimitry Andric if (IsInlined) 71480093f4SDimitry Andric OS << " [inlined]"; 72480093f4SDimitry Andric } 73480093f4SDimitry Andric OS << '\n'; 74480093f4SDimitry Andric return OS; 75480093f4SDimitry Andric } 76