1 //===----------------------- FaultMapParser.cpp ---------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Object/FaultMapParser.h" 11 12 #include "llvm/Support/ErrorHandling.h" 13 #include "llvm/Support/Format.h" 14 15 using namespace llvm; 16 17 static const char *faultKindToString(FaultMapParser::FaultKind FT) { 18 switch (FT) { 19 default: 20 llvm_unreachable("unhandled fault type!"); 21 22 case FaultMapParser::FaultingLoad: 23 return "FaultingLoad"; 24 } 25 } 26 27 raw_ostream &llvm:: 28 operator<<(raw_ostream &OS, 29 const FaultMapParser::FunctionFaultInfoAccessor &FFI) { 30 OS << "Fault kind: " 31 << faultKindToString((FaultMapParser::FaultKind)FFI.getFaultKind()) 32 << ", faulting PC offset: " << FFI.getFaultingPCOffset() 33 << ", handling PC offset: " << FFI.getHandlerPCOffset(); 34 return OS; 35 } 36 37 raw_ostream &llvm:: 38 operator<<(raw_ostream &OS, const FaultMapParser::FunctionInfoAccessor &FI) { 39 OS << "FunctionAddress: " << format_hex(FI.getFunctionAddr(), 8) 40 << ", NumFaultingPCs: " << FI.getNumFaultingPCs() << "\n"; 41 for (unsigned i = 0, e = FI.getNumFaultingPCs(); i != e; ++i) 42 OS << FI.getFunctionFaultInfoAt(i) << "\n"; 43 return OS; 44 } 45 46 raw_ostream &llvm::operator<<(raw_ostream &OS, const FaultMapParser &FMP) { 47 OS << "Version: " << format_hex(FMP.getFaultMapVersion(), 2) << "\n"; 48 OS << "NumFunctions: " << FMP.getNumFunctions() << "\n"; 49 50 if (FMP.getNumFunctions() == 0) 51 return OS; 52 53 FaultMapParser::FunctionInfoAccessor FI; 54 55 for (unsigned i = 0, e = FMP.getNumFunctions(); i != e; ++i) { 56 FI = (i == 0) ? FMP.getFirstFunctionInfo() : FI.getNextFunctionInfo(); 57 OS << FI; 58 } 59 60 return OS; 61 } 62