FaultMapParser.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "llvm/Object/FaultMapParser.h"
  9. #include "llvm/Support/ErrorHandling.h"
  10. #include "llvm/Support/Format.h"
  11. #include "llvm/Support/raw_ostream.h"
  12. using namespace llvm;
  13. void printFaultType(FaultMapParser::FaultKind FT, raw_ostream &OS) {
  14. switch (FT) {
  15. default:
  16. llvm_unreachable("unhandled fault type!");
  17. case FaultMapParser::FaultingLoad:
  18. OS << "FaultingLoad";
  19. break;
  20. case FaultMapParser::FaultingLoadStore:
  21. OS << "FaultingLoadStore";
  22. break;
  23. case FaultMapParser::FaultingStore:
  24. OS << "FaultingStore";
  25. break;
  26. }
  27. }
  28. raw_ostream &
  29. llvm::operator<<(raw_ostream &OS,
  30. const FaultMapParser::FunctionFaultInfoAccessor &FFI) {
  31. OS << "Fault kind: ";
  32. printFaultType((FaultMapParser::FaultKind)FFI.getFaultKind(), OS);
  33. OS << ", faulting PC offset: " << FFI.getFaultingPCOffset()
  34. << ", handling PC offset: " << FFI.getHandlerPCOffset();
  35. return OS;
  36. }
  37. raw_ostream &llvm::operator<<(raw_ostream &OS,
  38. 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. raw_ostream &llvm::operator<<(raw_ostream &OS, const FaultMapParser &FMP) {
  46. OS << "Version: " << format_hex(FMP.getFaultMapVersion(), 2) << "\n";
  47. OS << "NumFunctions: " << FMP.getNumFunctions() << "\n";
  48. if (FMP.getNumFunctions() == 0)
  49. return OS;
  50. FaultMapParser::FunctionInfoAccessor FI;
  51. for (unsigned I = 0, E = FMP.getNumFunctions(); I != E; ++I) {
  52. FI = (I == 0) ? FMP.getFirstFunctionInfo() : FI.getNextFunctionInfo();
  53. OS << FI;
  54. }
  55. return OS;
  56. }