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