xref: /freebsd/contrib/llvm-project/llvm/lib/Object/FaultMapParser.cpp (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1 //===----------------------- FaultMapParser.cpp ---------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/Object/FaultMapParser.h"
10 #include "llvm/Support/ErrorHandling.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/raw_ostream.h"
13 
14 using namespace llvm;
15 
16 void printFaultType(FaultMapParser::FaultKind FT, raw_ostream &OS) {
17   switch (FT) {
18   default:
19     llvm_unreachable("unhandled fault type!");
20   case FaultMapParser::FaultingLoad:
21     OS << "FaultingLoad";
22     break;
23   case FaultMapParser::FaultingLoadStore:
24     OS << "FaultingLoadStore";
25     break;
26   case FaultMapParser::FaultingStore:
27     OS << "FaultingStore";
28     break;
29   }
30 }
31 
32 raw_ostream &
33 llvm::operator<<(raw_ostream &OS,
34                  const FaultMapParser::FunctionFaultInfoAccessor &FFI) {
35   OS << "Fault kind: ";
36   printFaultType((FaultMapParser::FaultKind)FFI.getFaultKind(), OS);
37   OS << ", faulting PC offset: " << FFI.getFaultingPCOffset()
38      << ", handling PC offset: " << FFI.getHandlerPCOffset();
39   return OS;
40 }
41 
42 raw_ostream &llvm::operator<<(raw_ostream &OS,
43                               const FaultMapParser::FunctionInfoAccessor &FI) {
44   OS << "FunctionAddress: " << format_hex(FI.getFunctionAddr(), 8)
45      << ", NumFaultingPCs: " << FI.getNumFaultingPCs() << "\n";
46   for (unsigned I = 0, E = FI.getNumFaultingPCs(); I != E; ++I)
47     OS << FI.getFunctionFaultInfoAt(I) << "\n";
48   return OS;
49 }
50 
51 raw_ostream &llvm::operator<<(raw_ostream &OS, const FaultMapParser &FMP) {
52   OS << "Version: " << format_hex(FMP.getFaultMapVersion(), 2) << "\n";
53   OS << "NumFunctions: " << FMP.getNumFunctions() << "\n";
54 
55   if (FMP.getNumFunctions() == 0)
56     return OS;
57 
58   FaultMapParser::FunctionInfoAccessor FI;
59 
60   for (unsigned I = 0, E = FMP.getNumFunctions(); I != E; ++I) {
61     FI = (I == 0) ? FMP.getFirstFunctionInfo() : FI.getNextFunctionInfo();
62     OS << FI;
63   }
64 
65   return OS;
66 }
67