]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-readobj / ARMWinEHPrinter.cpp
1 //===-- ARMWinEHPrinter.cpp - Windows on ARM EH Data Printer ----*- C++ -*-===//
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 // Windows on ARM uses a series of serialised data structures (RuntimeFunction)
11 // to create a table of information for unwinding.  In order to conserve space,
12 // there are two different ways that this data is represented.
13 //
14 // For functions with canonical forms for the prologue and epilogue, the data
15 // can be stored in a "packed" form.  In this case, the data is packed into the
16 // RuntimeFunction's remaining 30-bits and can fully describe the entire frame.
17 //
18 //        +---------------------------------------+
19 //        |         Function Entry Address        |
20 //        +---------------------------------------+
21 //        |           Packed Form Data            |
22 //        +---------------------------------------+
23 //
24 // This layout is parsed by Decoder::dumpPackedEntry.  No unwind bytecode is
25 // associated with such a frame as they can be derived from the provided data.
26 // The decoder does not synthesize this data as it is unnecessary for the
27 // purposes of validation, with the synthesis being required only by a proper
28 // unwinder.
29 //
30 // For functions that are large or do not match canonical forms, the data is
31 // split up into two portions, with the actual data residing in the "exception
32 // data" table (.xdata) with a reference to the entry from the "procedure data"
33 // (.pdata) entry.
34 //
35 // The exception data contains information about the frame setup, all of the
36 // epilogue scopes (for functions for which there are multiple exit points) and
37 // the associated exception handler.  Additionally, the entry contains byte-code
38 // describing how to unwind the function (c.f. Decoder::decodeOpcodes).
39 //
40 //        +---------------------------------------+
41 //        |         Function Entry Address        |
42 //        +---------------------------------------+
43 //        |      Exception Data Entry Address     |
44 //        +---------------------------------------+
45 //
46 // This layout is parsed by Decoder::dumpUnpackedEntry.  Such an entry must
47 // first resolve the exception data entry address.  This structure
48 // (ExceptionDataRecord) has a variable sized header
49 // (c.f. ARM::WinEH::HeaderWords) and encodes most of the same information as
50 // the packed form.  However, because this information is insufficient to
51 // synthesize the unwinding, there are associated unwinding bytecode which make
52 // up the bulk of the Decoder.
53 //
54 // The decoder itself is table-driven, using the first byte to determine the
55 // opcode and dispatching to the associated printing routine.  The bytecode
56 // itself is a variable length instruction encoding that can fully describe the
57 // state of the stack and the necessary operations for unwinding to the
58 // beginning of the frame.
59 //
60 // The byte-code maintains a 1-1 instruction mapping, indicating both the width
61 // of the instruction (Thumb2 instructions are variable length, 16 or 32 bits
62 // wide) allowing the program to unwind from any point in the prologue, body, or
63 // epilogue of the function.
64
65 #include "ARMWinEHPrinter.h"
66 #include "Error.h"
67 #include "llvm/ADT/STLExtras.h"
68 #include "llvm/ADT/StringExtras.h"
69 #include "llvm/Support/ARMWinEH.h"
70 #include "llvm/Support/Format.h"
71
72 using namespace llvm;
73 using namespace llvm::object;
74 using namespace llvm::support;
75
76 namespace llvm {
77 raw_ostream &operator<<(raw_ostream &OS, const ARM::WinEH::ReturnType &RT) {
78   switch (RT) {
79   case ARM::WinEH::ReturnType::RT_POP:
80     OS << "pop {pc}";
81     break;
82   case ARM::WinEH::ReturnType::RT_B:
83     OS << "b target";
84     break;
85   case ARM::WinEH::ReturnType::RT_BW:
86     OS << "b.w target";
87     break;
88   case ARM::WinEH::ReturnType::RT_NoEpilogue:
89     OS << "(no epilogue)";
90     break;
91   }
92   return OS;
93 }
94 }
95
96 static std::string formatSymbol(StringRef Name, uint64_t Address,
97                                 uint64_t Offset = 0) {
98   std::string Buffer;
99   raw_string_ostream OS(Buffer);
100
101   if (!Name.empty())
102     OS << Name << " ";
103
104   if (Offset)
105     OS << format("+0x%X (0x%" PRIX64 ")", Offset, Address);
106   else if (!Name.empty())
107     OS << format("(0x%" PRIX64 ")", Address);
108   else
109     OS << format("0x%" PRIX64, Address);
110
111   return OS.str();
112 }
113
114 namespace llvm {
115 namespace ARM {
116 namespace WinEH {
117 const size_t Decoder::PDataEntrySize = sizeof(RuntimeFunction);
118
119 // TODO name the uops more appropriately
120 const Decoder::RingEntry Decoder::Ring[] = {
121   { 0x80, 0x00, 1, &Decoder::opcode_0xxxxxxx },  // UOP_STACK_FREE (16-bit)
122   { 0xc0, 0x80, 2, &Decoder::opcode_10Lxxxxx },  // UOP_POP (32-bit)
123   { 0xf0, 0xc0, 1, &Decoder::opcode_1100xxxx },  // UOP_STACK_SAVE (16-bit)
124   { 0xf8, 0xd0, 1, &Decoder::opcode_11010Lxx },  // UOP_POP (16-bit)
125   { 0xf8, 0xd8, 1, &Decoder::opcode_11011Lxx },  // UOP_POP (32-bit)
126   { 0xf8, 0xe0, 1, &Decoder::opcode_11100xxx },  // UOP_VPOP (32-bit)
127   { 0xfc, 0xe8, 2, &Decoder::opcode_111010xx },  // UOP_STACK_FREE (32-bit)
128   { 0xfe, 0xec, 2, &Decoder::opcode_1110110L },  // UOP_POP (16-bit)
129   { 0xff, 0xee, 2, &Decoder::opcode_11101110 },  // UOP_MICROSOFT_SPECIFIC (16-bit)
130                                               // UOP_PUSH_MACHINE_FRAME
131                                               // UOP_PUSH_CONTEXT
132                                               // UOP_PUSH_TRAP_FRAME
133                                               // UOP_REDZONE_RESTORE_LR
134   { 0xff, 0xef, 2, &Decoder::opcode_11101111 },  // UOP_LDRPC_POSTINC (32-bit)
135   { 0xff, 0xf5, 2, &Decoder::opcode_11110101 },  // UOP_VPOP (32-bit)
136   { 0xff, 0xf6, 2, &Decoder::opcode_11110110 },  // UOP_VPOP (32-bit)
137   { 0xff, 0xf7, 3, &Decoder::opcode_11110111 },  // UOP_STACK_RESTORE (16-bit)
138   { 0xff, 0xf8, 4, &Decoder::opcode_11111000 },  // UOP_STACK_RESTORE (16-bit)
139   { 0xff, 0xf9, 3, &Decoder::opcode_11111001 },  // UOP_STACK_RESTORE (32-bit)
140   { 0xff, 0xfa, 4, &Decoder::opcode_11111010 },  // UOP_STACK_RESTORE (32-bit)
141   { 0xff, 0xfb, 1, &Decoder::opcode_11111011 },  // UOP_NOP (16-bit)
142   { 0xff, 0xfc, 1, &Decoder::opcode_11111100 },  // UOP_NOP (32-bit)
143   { 0xff, 0xfd, 1, &Decoder::opcode_11111101 },  // UOP_NOP (16-bit) / END
144   { 0xff, 0xfe, 1, &Decoder::opcode_11111110 },  // UOP_NOP (32-bit) / END
145   { 0xff, 0xff, 1, &Decoder::opcode_11111111 },  // UOP_END
146 };
147
148
149 // Unwind opcodes for ARM64.
150 // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
151 const Decoder::RingEntry Decoder::Ring64[] = {
152   { 0xe0, 0x00, 1, &Decoder::opcode_alloc_s },
153   { 0xe0, 0x20, 1, &Decoder::opcode_save_r19r20_x },
154   { 0xc0, 0x40, 1, &Decoder::opcode_save_fplr },
155   { 0xc0, 0x80, 1, &Decoder::opcode_save_fplr_x },
156   { 0xf8, 0xc0, 2, &Decoder::opcode_alloc_m },
157   { 0xfc, 0xc8, 2, &Decoder::opcode_save_regp },
158   { 0xfc, 0xcc, 2, &Decoder::opcode_save_regp_x },
159   { 0xfc, 0xd0, 2, &Decoder::opcode_save_reg },
160   { 0xfe, 0xd4, 2, &Decoder::opcode_save_reg_x },
161   { 0xfe, 0xd6, 2, &Decoder::opcode_save_lrpair },
162   { 0xfe, 0xd8, 2, &Decoder::opcode_save_fregp },
163   { 0xfe, 0xda, 2, &Decoder::opcode_save_fregp_x },
164   { 0xfe, 0xdc, 2, &Decoder::opcode_save_freg },
165   { 0xff, 0xde, 2, &Decoder::opcode_save_freg_x },
166   { 0xff, 0xe0, 4, &Decoder::opcode_alloc_l },
167   { 0xff, 0xe1, 1, &Decoder::opcode_setfp },
168   { 0xff, 0xe2, 2, &Decoder::opcode_addfp },
169   { 0xff, 0xe3, 1, &Decoder::opcode_nop },
170   { 0xff, 0xe4, 1, &Decoder::opcode_end },
171   { 0xff, 0xe5, 1, &Decoder::opcode_end_c },
172 };
173
174 void Decoder::printRegisters(const std::pair<uint16_t, uint32_t> &RegisterMask) {
175   static const char * const GPRRegisterNames[16] = {
176     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
177     "r11", "ip", "sp", "lr", "pc",
178   };
179
180   const uint16_t GPRMask = std::get<0>(RegisterMask);
181   const uint16_t VFPMask = std::get<1>(RegisterMask);
182
183   OS << '{';
184   bool Comma = false;
185   for (unsigned RI = 0, RE = 11; RI < RE; ++RI) {
186     if (GPRMask & (1 << RI)) {
187       if (Comma)
188         OS << ", ";
189       OS << GPRRegisterNames[RI];
190       Comma = true;
191     }
192   }
193   for (unsigned RI = 0, RE = 32; RI < RE; ++RI) {
194     if (VFPMask & (1 << RI)) {
195       if (Comma)
196         OS << ", ";
197       OS << "d" << unsigned(RI);
198       Comma = true;
199     }
200   }
201   for (unsigned RI = 11, RE = 16; RI < RE; ++RI) {
202     if (GPRMask & (1 << RI)) {
203       if (Comma)
204         OS << ", ";
205       OS << GPRRegisterNames[RI];
206       Comma = true;
207     }
208   }
209   OS << '}';
210 }
211
212 ErrorOr<object::SectionRef>
213 Decoder::getSectionContaining(const COFFObjectFile &COFF, uint64_t VA) {
214   for (const auto &Section : COFF.sections()) {
215     uint64_t Address = Section.getAddress();
216     uint64_t Size = Section.getSize();
217
218     if (VA >= Address && (VA - Address) <= Size)
219       return Section;
220   }
221   return readobj_error::unknown_symbol;
222 }
223
224 ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
225                                               uint64_t VA, bool FunctionOnly) {
226   for (const auto &Symbol : COFF.symbols()) {
227     Expected<SymbolRef::Type> Type = Symbol.getType();
228     if (!Type)
229       return errorToErrorCode(Type.takeError());
230     if (FunctionOnly && *Type != SymbolRef::ST_Function)
231       continue;
232
233     Expected<uint64_t> Address = Symbol.getAddress();
234     if (!Address)
235       return errorToErrorCode(Address.takeError());
236     if (*Address == VA)
237       return Symbol;
238   }
239   return readobj_error::unknown_symbol;
240 }
241
242 ErrorOr<SymbolRef> Decoder::getRelocatedSymbol(const COFFObjectFile &,
243                                                const SectionRef &Section,
244                                                uint64_t Offset) {
245   for (const auto &Relocation : Section.relocations()) {
246     uint64_t RelocationOffset = Relocation.getOffset();
247     if (RelocationOffset == Offset)
248       return *Relocation.getSymbol();
249   }
250   return readobj_error::unknown_symbol;
251 }
252
253 bool Decoder::opcode_0xxxxxxx(const uint8_t *OC, unsigned &Offset,
254                               unsigned Length, bool Prologue) {
255   uint8_t Imm = OC[Offset] & 0x7f;
256   SW.startLine() << format("0x%02x                ; %s sp, #(%u * 4)\n",
257                            OC[Offset],
258                            static_cast<const char *>(Prologue ? "sub" : "add"),
259                            Imm);
260   ++Offset;
261   return false;
262 }
263
264 bool Decoder::opcode_10Lxxxxx(const uint8_t *OC, unsigned &Offset,
265                               unsigned Length, bool Prologue) {
266   unsigned Link = (OC[Offset] & 0x20) >> 5;
267   uint16_t RegisterMask = (Link << (Prologue ? 14 : 15))
268                         | ((OC[Offset + 0] & 0x1f) << 8)
269                         | ((OC[Offset + 1] & 0xff) << 0);
270   assert((~RegisterMask & (1 << 13)) && "sp must not be set");
271   assert((~RegisterMask & (1 << (Prologue ? 15 : 14))) && "pc must not be set");
272
273   SW.startLine() << format("0x%02x 0x%02x           ; %s.w ",
274                            OC[Offset + 0], OC[Offset + 1],
275                            Prologue ? "push" : "pop");
276   printRegisters(std::make_pair(RegisterMask, 0));
277   OS << '\n';
278
279   Offset += 2;
280   return false;
281 }
282
283 bool Decoder::opcode_1100xxxx(const uint8_t *OC, unsigned &Offset,
284                               unsigned Length, bool Prologue) {
285   if (Prologue)
286     SW.startLine() << format("0x%02x                ; mov r%u, sp\n",
287                              OC[Offset], OC[Offset] & 0xf);
288   else
289     SW.startLine() << format("0x%02x                ; mov sp, r%u\n",
290                              OC[Offset], OC[Offset] & 0xf);
291   ++Offset;
292   return false;
293 }
294
295 bool Decoder::opcode_11010Lxx(const uint8_t *OC, unsigned &Offset,
296                               unsigned Length, bool Prologue) {
297   unsigned Link = (OC[Offset] & 0x4) >> 3;
298   unsigned Count = (OC[Offset] & 0x3);
299
300   uint16_t GPRMask = (Link << (Prologue ? 14 : 15))
301                    | (((1 << (Count + 1)) - 1) << 4);
302
303   SW.startLine() << format("0x%02x                ; %s ", OC[Offset],
304                            Prologue ? "push" : "pop");
305   printRegisters(std::make_pair(GPRMask, 0));
306   OS << '\n';
307
308   ++Offset;
309   return false;
310 }
311
312 bool Decoder::opcode_11011Lxx(const uint8_t *OC, unsigned &Offset,
313                               unsigned Length, bool Prologue) {
314   unsigned Link = (OC[Offset] & 0x4) >> 2;
315   unsigned Count = (OC[Offset] & 0x3) + 4;
316
317   uint16_t GPRMask = (Link << (Prologue ? 14 : 15))
318                    | (((1 << (Count + 1)) - 1) << 4);
319
320   SW.startLine() << format("0x%02x                ; %s.w ", OC[Offset],
321                            Prologue ? "push" : "pop");
322   printRegisters(std::make_pair(GPRMask, 0));
323   OS << '\n';
324
325   ++Offset;
326   return false;
327 }
328
329 bool Decoder::opcode_11100xxx(const uint8_t *OC, unsigned &Offset,
330                               unsigned Length, bool Prologue) {
331   unsigned High = (OC[Offset] & 0x7);
332   uint32_t VFPMask = (((1 << (High + 1)) - 1) << 8);
333
334   SW.startLine() << format("0x%02x                ; %s ", OC[Offset],
335                            Prologue ? "vpush" : "vpop");
336   printRegisters(std::make_pair(0, VFPMask));
337   OS << '\n';
338
339   ++Offset;
340   return false;
341 }
342
343 bool Decoder::opcode_111010xx(const uint8_t *OC, unsigned &Offset,
344                               unsigned Length, bool Prologue) {
345   uint16_t Imm = ((OC[Offset + 0] & 0x03) << 8) | ((OC[Offset + 1] & 0xff) << 0);
346
347   SW.startLine() << format("0x%02x 0x%02x           ; %s.w sp, #(%u * 4)\n",
348                            OC[Offset + 0], OC[Offset + 1],
349                            static_cast<const char *>(Prologue ? "sub" : "add"),
350                            Imm);
351
352   Offset += 2;
353   return false;
354 }
355
356 bool Decoder::opcode_1110110L(const uint8_t *OC, unsigned &Offset,
357                               unsigned Length, bool Prologue) {
358   uint8_t GPRMask = ((OC[Offset + 0] & 0x01) << (Prologue ? 14 : 15))
359                   | ((OC[Offset + 1] & 0xff) << 0);
360
361   SW.startLine() << format("0x%02x 0x%02x           ; %s ", OC[Offset + 0],
362                            OC[Offset + 1], Prologue ? "push" : "pop");
363   printRegisters(std::make_pair(GPRMask, 0));
364   OS << '\n';
365
366   Offset += 2;
367   return false;
368 }
369
370 bool Decoder::opcode_11101110(const uint8_t *OC, unsigned &Offset,
371                               unsigned Length, bool Prologue) {
372   assert(!Prologue && "may not be used in prologue");
373
374   if (OC[Offset + 1] & 0xf0)
375     SW.startLine() << format("0x%02x 0x%02x           ; reserved\n",
376                              OC[Offset + 0], OC[Offset +  1]);
377   else
378     SW.startLine()
379       << format("0x%02x 0x%02x           ; microsoft-specific (type: %u)\n",
380                 OC[Offset + 0], OC[Offset + 1], OC[Offset + 1] & 0x0f);
381
382   Offset += 2;
383   return false;
384 }
385
386 bool Decoder::opcode_11101111(const uint8_t *OC, unsigned &Offset,
387                               unsigned Length, bool Prologue) {
388   assert(!Prologue && "may not be used in prologue");
389
390   if (OC[Offset + 1] & 0xf0)
391     SW.startLine() << format("0x%02x 0x%02x           ; reserved\n",
392                              OC[Offset + 0], OC[Offset +  1]);
393   else
394     SW.startLine()
395       << format("0x%02x 0x%02x           ; ldr.w lr, [sp], #%u\n",
396                 OC[Offset + 0], OC[Offset + 1], OC[Offset + 1] << 2);
397
398   Offset += 2;
399   return false;
400 }
401
402 bool Decoder::opcode_11110101(const uint8_t *OC, unsigned &Offset,
403                               unsigned Length, bool Prologue) {
404   unsigned Start = (OC[Offset + 1] & 0xf0) >> 4;
405   unsigned End = (OC[Offset + 1] & 0x0f) >> 0;
406   uint32_t VFPMask = ((1 << (End - Start)) - 1) << Start;
407
408   SW.startLine() << format("0x%02x 0x%02x           ; %s ", OC[Offset + 0],
409                            OC[Offset + 1], Prologue ? "vpush" : "vpop");
410   printRegisters(std::make_pair(0, VFPMask));
411   OS << '\n';
412
413   Offset += 2;
414   return false;
415 }
416
417 bool Decoder::opcode_11110110(const uint8_t *OC, unsigned &Offset,
418                               unsigned Length, bool Prologue) {
419   unsigned Start = (OC[Offset + 1] & 0xf0) >> 4;
420   unsigned End = (OC[Offset + 1] & 0x0f) >> 0;
421   uint32_t VFPMask = ((1 << (End - Start)) - 1) << 16;
422
423   SW.startLine() << format("0x%02x 0x%02x           ; %s ", OC[Offset + 0],
424                            OC[Offset + 1], Prologue ? "vpush" : "vpop");
425   printRegisters(std::make_pair(0, VFPMask));
426   OS << '\n';
427
428   Offset += 2;
429   return false;
430 }
431
432 bool Decoder::opcode_11110111(const uint8_t *OC, unsigned &Offset,
433                               unsigned Length, bool Prologue) {
434   uint32_t Imm = (OC[Offset + 1] << 8) | (OC[Offset + 2] << 0);
435
436   SW.startLine() << format("0x%02x 0x%02x 0x%02x      ; %s sp, sp, #(%u * 4)\n",
437                            OC[Offset + 0], OC[Offset + 1], OC[Offset + 2],
438                            static_cast<const char *>(Prologue ? "sub" : "add"),
439                            Imm);
440
441   Offset += 3;
442   return false;
443 }
444
445 bool Decoder::opcode_11111000(const uint8_t *OC, unsigned &Offset,
446                               unsigned Length, bool Prologue) {
447   uint32_t Imm = (OC[Offset + 1] << 16)
448                | (OC[Offset + 2] << 8)
449                | (OC[Offset + 3] << 0);
450
451   SW.startLine()
452     << format("0x%02x 0x%02x 0x%02x 0x%02x ; %s sp, sp, #(%u * 4)\n",
453               OC[Offset + 0], OC[Offset + 1], OC[Offset + 2], OC[Offset + 3],
454               static_cast<const char *>(Prologue ? "sub" : "add"), Imm);
455
456   Offset += 4;
457   return false;
458 }
459
460 bool Decoder::opcode_11111001(const uint8_t *OC, unsigned &Offset,
461                               unsigned Length, bool Prologue) {
462   uint32_t Imm = (OC[Offset + 1] << 8) | (OC[Offset + 2] << 0);
463
464   SW.startLine()
465     << format("0x%02x 0x%02x 0x%02x      ; %s.w sp, sp, #(%u * 4)\n",
466               OC[Offset + 0], OC[Offset + 1], OC[Offset + 2],
467               static_cast<const char *>(Prologue ? "sub" : "add"), Imm);
468
469   Offset += 3;
470   return false;
471 }
472
473 bool Decoder::opcode_11111010(const uint8_t *OC, unsigned &Offset,
474                               unsigned Length, bool Prologue) {
475   uint32_t Imm = (OC[Offset + 1] << 16)
476                | (OC[Offset + 2] << 8)
477                | (OC[Offset + 3] << 0);
478
479   SW.startLine()
480     << format("0x%02x 0x%02x 0x%02x 0x%02x ; %s.w sp, sp, #(%u * 4)\n",
481               OC[Offset + 0], OC[Offset + 1], OC[Offset + 2], OC[Offset + 3],
482               static_cast<const char *>(Prologue ? "sub" : "add"), Imm);
483
484   Offset += 4;
485   return false;
486 }
487
488 bool Decoder::opcode_11111011(const uint8_t *OC, unsigned &Offset,
489                               unsigned Length, bool Prologue) {
490   SW.startLine() << format("0x%02x                ; nop\n", OC[Offset]);
491   ++Offset;
492   return false;
493 }
494
495 bool Decoder::opcode_11111100(const uint8_t *OC, unsigned &Offset,
496                               unsigned Length, bool Prologue) {
497   SW.startLine() << format("0x%02x                ; nop.w\n", OC[Offset]);
498   ++Offset;
499   return false;
500 }
501
502 bool Decoder::opcode_11111101(const uint8_t *OC, unsigned &Offset,
503                               unsigned Length, bool Prologue) {
504   SW.startLine() << format("0x%02x                ; b\n", OC[Offset]);
505   ++Offset;
506   return true;
507 }
508
509 bool Decoder::opcode_11111110(const uint8_t *OC, unsigned &Offset,
510                               unsigned Length, bool Prologue) {
511   SW.startLine() << format("0x%02x                ; b.w\n", OC[Offset]);
512   ++Offset;
513   return true;
514 }
515
516 bool Decoder::opcode_11111111(const uint8_t *OC, unsigned &Offset,
517                               unsigned Length, bool Prologue) {
518   ++Offset;
519   return true;
520 }
521
522 // ARM64 unwind codes start here.
523 bool Decoder::opcode_alloc_s(const uint8_t *OC, unsigned &Offset,
524                              unsigned Length, bool Prologue) {
525   uint32_t NumBytes = (OC[Offset] & 0x1F) << 4;
526   SW.startLine() << format("0x%02x                ; %s sp, #%u\n", OC[Offset],
527                            static_cast<const char *>(Prologue ? "sub" : "add"),
528                            NumBytes);
529   ++Offset;
530   return false;
531 }
532
533 bool Decoder::opcode_save_r19r20_x(const uint8_t *OC, unsigned &Offset,
534                                    unsigned Length, bool Prologue) {
535   uint32_t Off = (OC[Offset] & 0x1F) << 3;
536   if (Prologue)
537     SW.startLine() << format(
538         "0x%02x                ; stp x19, x20, [sp, #-%u]!\n", OC[Offset], Off);
539   else
540     SW.startLine() << format(
541         "0x%02x                ; ldp x19, x20, [sp], #%u\n", OC[Offset], Off);
542   ++Offset;
543   return false;
544 }
545
546 bool Decoder::opcode_save_fplr(const uint8_t *OC, unsigned &Offset,
547                                unsigned Length, bool Prologue) {
548   uint32_t Off = (OC[Offset] & 0x3F) << 3;
549   SW.startLine() << format(
550       "0x%02x                ; %s x29, x30, [sp, #%u]\n", OC[Offset],
551       static_cast<const char *>(Prologue ? "stp" : "ldp"), Off);
552   ++Offset;
553   return false;
554 }
555
556 bool Decoder::opcode_save_fplr_x(const uint8_t *OC, unsigned &Offset,
557                                  unsigned Length, bool Prologue) {
558   uint32_t Off = ((OC[Offset] & 0x3F) + 1) << 3;
559   if (Prologue)
560     SW.startLine() << format(
561         "0x%02x                ; stp x29, x30, [sp, #-%u]!\n", OC[Offset], Off);
562   else
563     SW.startLine() << format(
564         "0x%02x                ; ldp x29, x30, [sp], #%u\n", OC[Offset], Off);
565   ++Offset;
566   return false;
567 }
568
569 bool Decoder::opcode_alloc_m(const uint8_t *OC, unsigned &Offset,
570                              unsigned Length, bool Prologue) {
571   uint32_t NumBytes = ((OC[Offset] & 0x07) << 8);
572   NumBytes |= (OC[Offset + 1] & 0xFF);
573   NumBytes <<= 4;
574   SW.startLine() << format("0x%02x%02x              ; %s sp, #%u\n",
575                            OC[Offset], OC[Offset + 1],
576                            static_cast<const char *>(Prologue ? "sub" : "add"),
577                            NumBytes);
578   Offset += 2;
579   return false;
580 }
581
582 bool Decoder::opcode_save_regp(const uint8_t *OC, unsigned &Offset,
583                                unsigned Length, bool Prologue) {
584   uint32_t Reg = ((OC[Offset] & 0x03) << 8);
585   Reg |= (OC[Offset + 1] & 0xC0);
586   Reg >>= 6;
587   Reg += 19;
588   uint32_t Off = (OC[Offset + 1] & 0x3F) << 3;
589   SW.startLine() << format(
590       "0x%02x%02x              ; %s x%u, x%u, [sp, #%u]\n",
591       OC[Offset], OC[Offset + 1],
592       static_cast<const char *>(Prologue ? "stp" : "ldp"), Reg, Reg + 1, Off);
593   Offset += 2;
594   return false;
595 }
596
597 bool Decoder::opcode_save_regp_x(const uint8_t *OC, unsigned &Offset,
598                                  unsigned Length, bool Prologue) {
599   uint32_t Reg = ((OC[Offset] & 0x03) << 8);
600   Reg |= (OC[Offset + 1] & 0xC0);
601   Reg >>= 6;
602   Reg += 19;
603   uint32_t Off = ((OC[Offset + 1] & 0x3F) + 1) << 3;
604   if (Prologue)
605     SW.startLine() << format(
606         "0x%02x%02x              ; stp x%u, x%u, [sp, #-%u]!\n",
607         OC[Offset], OC[Offset + 1], Reg,
608         Reg + 1, Off);
609   else
610     SW.startLine() << format(
611         "0x%02x%02x              ; ldp x%u, x%u, [sp], #%u\n",
612         OC[Offset], OC[Offset + 1], Reg,
613         Reg + 1, Off);
614   Offset += 2;
615   return false;
616 }
617
618 bool Decoder::opcode_save_reg(const uint8_t *OC, unsigned &Offset,
619                               unsigned Length, bool Prologue) {
620   uint32_t Reg = (OC[Offset] & 0x03) << 8;
621   Reg |= (OC[Offset + 1] & 0xC0);
622   Reg >>= 6;
623   Reg += 19;
624   uint32_t Off = (OC[Offset + 1] & 0x3F) << 3;
625   SW.startLine() << format("0x%02x%02x              ; %s x%u, [sp, #%u]\n",
626                            OC[Offset], OC[Offset + 1],
627                            static_cast<const char *>(Prologue ? "str" : "ldr"),
628                            Reg, Off);
629   Offset += 2;
630   return false;
631 }
632
633 bool Decoder::opcode_save_reg_x(const uint8_t *OC, unsigned &Offset,
634                                 unsigned Length, bool Prologue) {
635   uint32_t Reg = (OC[Offset] & 0x01) << 8;
636   Reg |= (OC[Offset + 1] & 0xE0);
637   Reg >>= 5;
638   Reg += 19;
639   uint32_t Off = ((OC[Offset + 1] & 0x1F) + 1) << 3;
640   if (Prologue)
641     SW.startLine() << format("0x%02x%02x              ; str x%u, [sp, #%u]!\n",
642                              OC[Offset], OC[Offset + 1], Reg, Off);
643   else
644     SW.startLine() << format("0x%02x%02x              ; ldr x%u, [sp], #%u\n",
645                              OC[Offset], OC[Offset + 1], Reg, Off);
646   Offset += 2;
647   return false;
648 }
649
650 bool Decoder::opcode_save_lrpair(const uint8_t *OC, unsigned &Offset,
651                                  unsigned Length, bool Prologue) {
652   uint32_t Reg = (OC[Offset] & 0x01) << 8;
653   Reg |= (OC[Offset + 1] & 0xC0);
654   Reg >>= 6;
655   Reg *= 2;
656   Reg += 19;
657   uint32_t Off = (OC[Offset + 1] & 0x3F) << 3;
658   SW.startLine() << format("0x%02x%02x              ; %s x%u, lr, [sp, #%u]\n",
659                            OC[Offset], OC[Offset + 1],
660                            static_cast<const char *>(Prologue ? "stp" : "ldp"),
661                            Reg, Off);
662   Offset += 2;
663   return false;
664 }
665
666 bool Decoder::opcode_save_fregp(const uint8_t *OC, unsigned &Offset,
667                                 unsigned Length, bool Prologue) {
668   uint32_t Reg = (OC[Offset] & 0x01) << 8;
669   Reg |= (OC[Offset + 1] & 0xC0);
670   Reg >>= 6;
671   Reg += 8;
672   uint32_t Off = (OC[Offset + 1] & 0x3F) << 3;
673   SW.startLine() << format("0x%02x%02x              ; %s d%u, d%u, [sp, #%u]\n",
674                            OC[Offset], OC[Offset + 1],
675                            static_cast<const char *>(Prologue ? "stp" : "ldp"),
676                            Reg, Reg + 1, Off);
677   Offset += 2;
678   return false;
679 }
680
681 bool Decoder::opcode_save_fregp_x(const uint8_t *OC, unsigned &Offset,
682                                   unsigned Length, bool Prologue) {
683   uint32_t Reg = (OC[Offset] & 0x01) << 8;
684   Reg |= (OC[Offset + 1] & 0xC0);
685   Reg >>= 6;
686   Reg += 8;
687   uint32_t Off = ((OC[Offset + 1] & 0x3F) + 1) << 3;
688   if (Prologue)
689     SW.startLine() << format(
690         "0x%02x%02x              ; stp d%u, d%u, [sp, #-%u]!\n", OC[Offset],
691         OC[Offset + 1], Reg, Reg + 1, Off);
692   else
693     SW.startLine() << format(
694         "0x%02x%02x              ; ldp d%u, d%u, [sp], #%u\n", OC[Offset],
695         OC[Offset + 1], Reg, Reg + 1, Off);
696   Offset += 2;
697   return false;
698 }
699
700 bool Decoder::opcode_save_freg(const uint8_t *OC, unsigned &Offset,
701                                unsigned Length, bool Prologue) {
702   uint32_t Reg = (OC[Offset] & 0x01) << 8;
703   Reg |= (OC[Offset + 1] & 0xC0);
704   Reg >>= 6;
705   Reg += 8;
706   uint32_t Off = (OC[Offset + 1] & 0x3F) << 3;
707   SW.startLine() << format("0x%02x%02x                ; %s d%u, [sp, #%u]\n",
708                            OC[Offset], OC[Offset + 1],
709                            static_cast<const char *>(Prologue ? "str" : "ldr"),
710                            Reg, Off);
711   Offset += 2;
712   return false;
713 }
714
715 bool Decoder::opcode_save_freg_x(const uint8_t *OC, unsigned &Offset,
716                                  unsigned Length, bool Prologue) {
717   uint32_t Reg = ((OC[Offset + 1] & 0xE0) >> 5) + 8;
718   uint32_t Off = ((OC[Offset + 1] & 0x1F) + 1) << 3;
719   if (Prologue)
720     SW.startLine() << format(
721         "0x%02x%02x              ; str d%u, [sp, #-%u]!\n", OC[Offset],
722         OC[Offset + 1], Reg, Off);
723   else
724     SW.startLine() << format(
725         "0x%02x%02x              ; ldr d%u, [sp], #%u\n", OC[Offset],
726         OC[Offset + 1], Reg, Off);
727   Offset += 2;
728   return false;
729 }
730
731 bool Decoder::opcode_alloc_l(const uint8_t *OC, unsigned &Offset,
732                              unsigned Length, bool Prologue) {
733   unsigned Off =
734       (OC[Offset + 1] << 16) | (OC[Offset + 2] << 8) | (OC[Offset + 3] << 0);
735   Off <<= 4;
736   SW.startLine() << format(
737       "0x%02x%02x%02x%02x          ; %s sp, #%u\n", OC[Offset], OC[Offset + 1],
738       OC[Offset + 2], OC[Offset + 3],
739       static_cast<const char *>(Prologue ? "sub" : "add"), Off);
740   Offset += 4;
741   return false;
742 }
743
744 bool Decoder::opcode_setfp(const uint8_t *OC, unsigned &Offset, unsigned Length,
745                            bool Prologue) {
746   SW.startLine() << format("0x%02x                ; mov fp, sp\n", OC[Offset]);
747   ++Offset;
748   return false;
749 }
750
751 bool Decoder::opcode_addfp(const uint8_t *OC, unsigned &Offset, unsigned Length,
752                            bool Prologue) {
753   unsigned NumBytes = OC[Offset + 1] << 3;
754   SW.startLine() << format("0x%02x%02x              ; add fp, sp, #%u\n",
755                            OC[Offset], OC[Offset + 1], NumBytes);
756   Offset += 2;
757   return false;
758 }
759
760 bool Decoder::opcode_nop(const uint8_t *OC, unsigned &Offset, unsigned Length,
761                          bool Prologue) {
762   SW.startLine() << format("0x%02x                ; nop\n", OC[Offset]);
763   ++Offset;
764   return false;
765 }
766
767 bool Decoder::opcode_end(const uint8_t *OC, unsigned &Offset, unsigned Length,
768                          bool Prologue) {
769   SW.startLine() << format("0x%02x                ; end\n", OC[Offset]);
770   ++Offset;
771   return true;
772 }
773
774 bool Decoder::opcode_end_c(const uint8_t *OC, unsigned &Offset, unsigned Length,
775                            bool Prologue) {
776   SW.startLine() << format("0x%02x                ; end_c\n", OC[Offset]);
777   ++Offset;
778   return true;
779 }
780
781 void Decoder::decodeOpcodes(ArrayRef<uint8_t> Opcodes, unsigned Offset,
782                             bool Prologue) {
783   assert((!Prologue || Offset == 0) && "prologue should always use offset 0");
784   const RingEntry* DecodeRing = isAArch64 ? Ring64 : Ring;
785   bool Terminated = false;
786   for (unsigned OI = Offset, OE = Opcodes.size(); !Terminated && OI < OE; ) {
787     for (unsigned DI = 0;; ++DI) {
788       if ((isAArch64 && (DI >= array_lengthof(Ring64))) ||
789           (!isAArch64 && (DI >= array_lengthof(Ring)))) {
790         SW.startLine() << format("0x%02x                ; Bad opcode!\n",
791                                  Opcodes.data()[OI]);
792         ++OI;
793         break;
794       }
795
796       if ((Opcodes[OI] & DecodeRing[DI].Mask) == DecodeRing[DI].Value) {
797         if (OI + DecodeRing[DI].Length > OE) {
798           SW.startLine() << format("Opcode 0x%02x goes past the unwind data\n",
799                                     Opcodes[OI]);
800           OI += DecodeRing[DI].Length;
801           break;
802         }
803         Terminated =
804             (this->*DecodeRing[DI].Routine)(Opcodes.data(), OI, 0, Prologue);
805         break;
806       }
807     }
808   }
809 }
810
811 bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF,
812                               const SectionRef &Section,
813                               uint64_t FunctionAddress, uint64_t VA) {
814   ArrayRef<uint8_t> Contents;
815   if (COFF.getSectionContents(COFF.getCOFFSection(Section), Contents))
816     return false;
817
818   uint64_t SectionVA = Section.getAddress();
819   uint64_t Offset = VA - SectionVA;
820   const ulittle32_t *Data =
821     reinterpret_cast<const ulittle32_t *>(Contents.data() + Offset);
822
823   // Sanity check to ensure that the .xdata header is present.
824   // A header is one or two words, followed by at least one word to describe
825   // the unwind codes. Applicable to both ARM and AArch64.
826   if (Contents.size() - Offset < 8)
827     report_fatal_error(".xdata must be at least 8 bytes in size");
828
829   const ExceptionDataRecord XData(Data, isAArch64);
830   DictScope XRS(SW, "ExceptionData");
831   SW.printNumber("FunctionLength",
832                  isAArch64 ? XData.FunctionLengthInBytesAArch64() :
833                  XData.FunctionLengthInBytesARM());
834   SW.printNumber("Version", XData.Vers());
835   SW.printBoolean("ExceptionData", XData.X());
836   SW.printBoolean("EpiloguePacked", XData.E());
837   if (!isAArch64)
838     SW.printBoolean("Fragment", XData.F());
839   SW.printNumber(XData.E() ? "EpilogueOffset" : "EpilogueScopes",
840                  XData.EpilogueCount());
841   uint64_t ByteCodeLength = XData.CodeWords() * sizeof(uint32_t);
842   SW.printNumber("ByteCodeLength", ByteCodeLength);
843
844   if ((int64_t)(Contents.size() - Offset - 4 * HeaderWords(XData) -
845                 (XData.E() ? 0 : XData.EpilogueCount() * 4) -
846                 (XData.X() ? 8 : 0)) < (int64_t)ByteCodeLength)
847     report_fatal_error("Malformed unwind data");
848
849   if (XData.E()) {
850     ArrayRef<uint8_t> UC = XData.UnwindByteCode();
851     if (isAArch64 || !XData.F()) {
852       ListScope PS(SW, "Prologue");
853       decodeOpcodes(UC, 0, /*Prologue=*/true);
854     }
855     if (XData.EpilogueCount()) {
856       ListScope ES(SW, "Epilogue");
857       decodeOpcodes(UC, XData.EpilogueCount(), /*Prologue=*/false);
858     }
859   } else {
860     {
861       ListScope PS(SW, "Prologue");
862       decodeOpcodes(XData.UnwindByteCode(), 0, /*Prologue=*/true);
863     }
864     ArrayRef<ulittle32_t> EpilogueScopes = XData.EpilogueScopes();
865     ListScope ESS(SW, "EpilogueScopes");
866     for (const EpilogueScope ES : EpilogueScopes) {
867       DictScope ESES(SW, "EpilogueScope");
868       SW.printNumber("StartOffset", ES.EpilogueStartOffset());
869       if (!isAArch64)
870         SW.printNumber("Condition", ES.Condition());
871       SW.printNumber("EpilogueStartIndex",
872                      isAArch64 ? ES.EpilogueStartIndexAArch64()
873                                : ES.EpilogueStartIndexARM());
874       if (ES.ES & ~0xffc3ffff)
875         SW.printNumber("ReservedBits", (ES.ES >> 18) & 0xF);
876
877       ListScope Opcodes(SW, "Opcodes");
878       decodeOpcodes(XData.UnwindByteCode(),
879                     isAArch64 ? ES.EpilogueStartIndexAArch64()
880                               : ES.EpilogueStartIndexARM(),
881                     /*Prologue=*/false);
882     }
883   }
884
885   if (XData.X()) {
886     const uint32_t Address = XData.ExceptionHandlerRVA();
887     const uint32_t Parameter = XData.ExceptionHandlerParameter();
888     const size_t HandlerOffset = HeaderWords(XData)
889                                + (XData.E() ? 0 : XData.EpilogueCount())
890                                + XData.CodeWords();
891
892     ErrorOr<SymbolRef> Symbol = getRelocatedSymbol(
893         COFF, Section, Offset + HandlerOffset * sizeof(uint32_t));
894     if (!Symbol)
895       Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
896     if (!Symbol) {
897       ListScope EHS(SW, "ExceptionHandler");
898       SW.printString("Routine", "(null)");
899       return true;
900     }
901
902     Expected<StringRef> Name = Symbol->getName();
903     if (!Name) {
904       std::string Buf;
905       llvm::raw_string_ostream OS(Buf);
906       logAllUnhandledErrors(Name.takeError(), OS);
907       OS.flush();
908       report_fatal_error(Buf);
909     }
910
911     ListScope EHS(SW, "ExceptionHandler");
912     SW.printString("Routine", formatSymbol(*Name, Address));
913     SW.printHex("Parameter", Parameter);
914   }
915
916   return true;
917 }
918
919 bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
920                                 const SectionRef Section, uint64_t Offset,
921                                 unsigned Index, const RuntimeFunction &RF) {
922   assert(RF.Flag() == RuntimeFunctionFlag::RFF_Unpacked &&
923          "packed entry cannot be treated as an unpacked entry");
924
925   ErrorOr<SymbolRef> Function = getRelocatedSymbol(COFF, Section, Offset);
926   if (!Function)
927     Function = getSymbol(COFF, RF.BeginAddress, /*FunctionOnly=*/true);
928
929   ErrorOr<SymbolRef> XDataRecord = getRelocatedSymbol(COFF, Section, Offset + 4);
930   if (!XDataRecord)
931     XDataRecord = getSymbol(COFF, RF.ExceptionInformationRVA());
932
933   if (!RF.BeginAddress && !Function)
934     return false;
935   if (!RF.UnwindData && !XDataRecord)
936     return false;
937
938   StringRef FunctionName;
939   uint64_t FunctionAddress;
940   if (Function) {
941     Expected<StringRef> FunctionNameOrErr = Function->getName();
942     if (!FunctionNameOrErr) {
943       std::string Buf;
944       llvm::raw_string_ostream OS(Buf);
945       logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
946       OS.flush();
947       report_fatal_error(Buf);
948     }
949     FunctionName = *FunctionNameOrErr;
950     Expected<uint64_t> FunctionAddressOrErr = Function->getAddress();
951     if (!FunctionAddressOrErr) {
952       std::string Buf;
953       llvm::raw_string_ostream OS(Buf);
954       logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
955       OS.flush();
956       report_fatal_error(Buf);
957     }
958     FunctionAddress = *FunctionAddressOrErr;
959   } else {
960     FunctionAddress = COFF.getImageBase() + RF.BeginAddress;
961   }
962
963   SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
964
965   if (XDataRecord) {
966     Expected<StringRef> Name = XDataRecord->getName();
967     if (!Name) {
968       std::string Buf;
969       llvm::raw_string_ostream OS(Buf);
970       logAllUnhandledErrors(Name.takeError(), OS);
971       OS.flush();
972       report_fatal_error(Buf);
973     }
974
975     Expected<uint64_t> AddressOrErr = XDataRecord->getAddress();
976     if (!AddressOrErr) {
977       std::string Buf;
978       llvm::raw_string_ostream OS(Buf);
979       logAllUnhandledErrors(AddressOrErr.takeError(), OS);
980       OS.flush();
981       report_fatal_error(Buf);
982     }
983     uint64_t Address = *AddressOrErr;
984
985     SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
986
987     Expected<section_iterator> SIOrErr = XDataRecord->getSection();
988     if (!SIOrErr) {
989       // TODO: Actually report errors helpfully.
990       consumeError(SIOrErr.takeError());
991       return false;
992     }
993     section_iterator SI = *SIOrErr;
994
995     // FIXME: Do we need to add an offset from the relocation?
996     return dumpXDataRecord(COFF, *SI, FunctionAddress,
997                            RF.ExceptionInformationRVA());
998   } else {
999     uint64_t Address = COFF.getImageBase() + RF.ExceptionInformationRVA();
1000     SW.printString("ExceptionRecord", formatSymbol("", Address));
1001
1002     ErrorOr<SectionRef> Section = getSectionContaining(COFF, Address);
1003     if (!Section)
1004       return false;
1005
1006     return dumpXDataRecord(COFF, *Section, FunctionAddress, Address);
1007   }
1008 }
1009
1010 bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
1011                               const SectionRef Section, uint64_t Offset,
1012                               unsigned Index, const RuntimeFunction &RF) {
1013   assert((RF.Flag() == RuntimeFunctionFlag::RFF_Packed ||
1014           RF.Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
1015          "unpacked entry cannot be treated as a packed entry");
1016
1017   ErrorOr<SymbolRef> Function = getRelocatedSymbol(COFF, Section, Offset);
1018   if (!Function)
1019     Function = getSymbol(COFF, RF.BeginAddress, /*FunctionOnly=*/true);
1020
1021   StringRef FunctionName;
1022   uint64_t FunctionAddress;
1023   if (Function) {
1024     Expected<StringRef> FunctionNameOrErr = Function->getName();
1025     if (!FunctionNameOrErr) {
1026       std::string Buf;
1027       llvm::raw_string_ostream OS(Buf);
1028       logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
1029       OS.flush();
1030       report_fatal_error(Buf);
1031     }
1032     FunctionName = *FunctionNameOrErr;
1033     Expected<uint64_t> FunctionAddressOrErr = Function->getAddress();
1034     if (!FunctionAddressOrErr) {
1035       std::string Buf;
1036       llvm::raw_string_ostream OS(Buf);
1037       logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
1038       OS.flush();
1039       report_fatal_error(Buf);
1040     }
1041     FunctionAddress = *FunctionAddressOrErr;
1042   } else {
1043     const pe32_header *PEHeader;
1044     if (COFF.getPE32Header(PEHeader))
1045       return false;
1046     FunctionAddress = PEHeader->ImageBase + RF.BeginAddress;
1047   }
1048
1049   SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
1050   if (!isAArch64)
1051     SW.printBoolean("Fragment",
1052                     RF.Flag() == RuntimeFunctionFlag::RFF_PackedFragment);
1053   SW.printNumber("FunctionLength", RF.FunctionLength());
1054   SW.startLine() << "ReturnType: " << RF.Ret() << '\n';
1055   SW.printBoolean("HomedParameters", RF.H());
1056   SW.startLine() << "SavedRegisters: ";
1057                  printRegisters(SavedRegisterMask(RF));
1058   OS << '\n';
1059   SW.printNumber("StackAdjustment", StackAdjustment(RF) << 2);
1060
1061   return true;
1062 }
1063
1064 bool Decoder::dumpProcedureDataEntry(const COFFObjectFile &COFF,
1065                                      const SectionRef Section, unsigned Index,
1066                                      ArrayRef<uint8_t> Contents) {
1067   uint64_t Offset = PDataEntrySize * Index;
1068   const ulittle32_t *Data =
1069     reinterpret_cast<const ulittle32_t *>(Contents.data() + Offset);
1070
1071   const RuntimeFunction Entry(Data);
1072   DictScope RFS(SW, "RuntimeFunction");
1073   if (Entry.Flag() == RuntimeFunctionFlag::RFF_Unpacked)
1074     return dumpUnpackedEntry(COFF, Section, Offset, Index, Entry);
1075   if (isAArch64) {
1076     SW.startLine() << "Packed unwind data not yet supported for ARM64\n";
1077     return true;
1078   }
1079   return dumpPackedEntry(COFF, Section, Offset, Index, Entry);
1080 }
1081
1082 void Decoder::dumpProcedureData(const COFFObjectFile &COFF,
1083                                 const SectionRef Section) {
1084   ArrayRef<uint8_t> Contents;
1085   if (COFF.getSectionContents(COFF.getCOFFSection(Section), Contents))
1086     return;
1087
1088   if (Contents.size() % PDataEntrySize) {
1089     errs() << ".pdata content is not " << PDataEntrySize << "-byte aligned\n";
1090     return;
1091   }
1092
1093   for (unsigned EI = 0, EE = Contents.size() / PDataEntrySize; EI < EE; ++EI)
1094     if (!dumpProcedureDataEntry(COFF, Section, EI, Contents))
1095       break;
1096 }
1097
1098 std::error_code Decoder::dumpProcedureData(const COFFObjectFile &COFF) {
1099   for (const auto &Section : COFF.sections()) {
1100     StringRef SectionName;
1101     if (std::error_code EC =
1102             COFF.getSectionName(COFF.getCOFFSection(Section), SectionName))
1103       return EC;
1104
1105     if (SectionName.startswith(".pdata"))
1106       dumpProcedureData(COFF, Section);
1107   }
1108   return std::error_code();
1109 }
1110 }
1111 }
1112 }