This patch adds support for dumping the unwind info from ARM64 COFF object files. This is required so that we can add test cases to https://reviews.llvm.org/D50166 (MCLayer support for ARM64 exception handling). Only unpacked unwind data is supported, as that is what D50166 currently supports.
I tested this with objects produced by both cl.exe and clang that includes the Windows ARM64 exception handling patches. The output that is produced looks like:
Case 1: single epilogue
File: test.obj
Format: COFF-ARM64
Arch: aarch64
AddressSize: 64bit
UnwindInformation [
RuntimeFunction {
  Function: $LN6 (0x0)
  ExceptionRecord: $unwind$?func@@YAHH@Z (0x0)
  ExceptionData {
    FunctionLength: 340
    Version: 0
    ExceptionData: No
    EpiloguePacked: Yes
    EpilogueOffset: 15
    ByteCodeLength: 28
    Prologue [
      0xe002dac8          ; sub sp, #2993280
      0xe3                ; nop
      0xe3                ; nop
      0xe3                ; nop
      0xd885              ; stp d10, d11, [sp, #40]
      0xd803              ; stp d8, d9, [sp, #24]
      0xd2c2              ; str x30, [sp, #16]
      0x28                ; stp x19, x20, [sp, #-64]!
      0xe4                ; end
    ]
    Epilogue [
      0xe002dac8          ; add sp, #2993280
      0xd885              ; ldp d10, d11, [sp, #40]
      0xd803              ; ldp d8, d9, [sp, #24]
      0xd2c2              ; ldr x30, [sp, #16]
      0x28                ; ldp x19, x20, [sp], #64
      0xe4                ; end
    ]
  }
}]
Case 2: multiple epilogues
File: test1.obj
Format: COFF-ARM64
Arch: aarch64
AddressSize: 64bit
UnwindInformation [
RuntimeFunction {
  Function: $LN6 (0x0)
  ExceptionRecord: $unwind$?func@@YAHH@Z (0x0)
  ExceptionData {
    FunctionLength: 72
    Version: 0
    ExceptionData: No
    EpiloguePacked: No
    EpilogueScopes: 2
    ByteCodeLength: 8
    Prologue [
      0x1f                ; sub sp, #496
      0xd600              ; stp x19, lr, [sp, #0]
      0x01                ; sub sp, #16
      0xe4                ; end
    ]
    EpilogueScopes [
      EpilogueScope {
        StartOffset: 8
        EpilogueStartIndex: 0
        Opcodes [
          0x1f                ; add sp, #496
          0xd600              ; ldp x19, lr, [sp, #0]
          0x01                ; add sp, #16
          0xe4                ; end
        ]
      }
      EpilogueScope {
        StartOffset: 14
        EpilogueStartIndex: 0
        Opcodes [
          0x1f                ; add sp, #496
          0xd600              ; ldp x19, lr, [sp, #0]
          0x01                ; add sp, #16
          0xe4                ; end
        ]
      }
    ]
  }
}]
Testing uncovered an encoding issue for the large stack size unwind opcode in D50166. I will update that patch with the fix and test cases that rely on this patch.
Using a template here is not helping make the code more readable.
Maybe there should be one function for both ARM and AArch64 that takes a reference to the ExceptionDataRecord?