llvm.org GIT mirror llvm / 9a516cd
Add printing the LC_THREAD load commands with llvm-objdump’s -private-headers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224792 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 5 years ago
6 changed file(s) with 636 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
379379 getRoutinesCommand(const LoadCommandInfo &L) const;
380380 MachO::routines_command_64
381381 getRoutinesCommand64(const LoadCommandInfo &L) const;
382 MachO::thread_command
383 getThreadCommand(const LoadCommandInfo &L) const;
382384
383385 MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
384386 MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
11561156 sys::swapByteOrder(r.reserved6);
11571157 }
11581158
1159 inline void swapStruct(thread_command &t) {
1160 sys::swapByteOrder(t.cmd);
1161 sys::swapByteOrder(t.cmdsize);
1162 }
1163
11591164 inline void swapStruct(dylinker_command &d) {
11601165 sys::swapByteOrder(d.cmd);
11611166 sys::swapByteOrder(d.cmdsize);
14121417 CPU_SUBTYPE_MC980000_ALL = CPU_SUBTYPE_POWERPC_ALL,
14131418 CPU_SUBTYPE_MC98601 = CPU_SUBTYPE_POWERPC_601
14141419 };
1420
1421 struct x86_thread_state64_t {
1422 uint64_t rax;
1423 uint64_t rbx;
1424 uint64_t rcx;
1425 uint64_t rdx;
1426 uint64_t rdi;
1427 uint64_t rsi;
1428 uint64_t rbp;
1429 uint64_t rsp;
1430 uint64_t r8;
1431 uint64_t r9;
1432 uint64_t r10;
1433 uint64_t r11;
1434 uint64_t r12;
1435 uint64_t r13;
1436 uint64_t r14;
1437 uint64_t r15;
1438 uint64_t rip;
1439 uint64_t rflags;
1440 uint64_t cs;
1441 uint64_t fs;
1442 uint64_t gs;
1443 };
1444
1445 enum x86_fp_control_precis {
1446 x86_FP_PREC_24B = 0,
1447 x86_FP_PREC_53B = 2,
1448 x86_FP_PREC_64B = 3
1449 };
1450
1451 enum x86_fp_control_rc {
1452 x86_FP_RND_NEAR = 0,
1453 x86_FP_RND_DOWN = 1,
1454 x86_FP_RND_UP = 2,
1455 x86_FP_CHOP = 3
1456 };
1457
1458 struct fp_control_t {
1459 unsigned short
1460 invalid :1,
1461 denorm :1,
1462 zdiv :1,
1463 ovrfl :1,
1464 undfl :1,
1465 precis :1,
1466 :2,
1467 pc :2,
1468 rc :2,
1469 :1,
1470 :3;
1471 };
1472
1473 struct fp_status_t {
1474 unsigned short
1475 invalid :1,
1476 denorm :1,
1477 zdiv :1,
1478 ovrfl :1,
1479 undfl :1,
1480 precis :1,
1481 stkflt :1,
1482 errsumm :1,
1483 c0 :1,
1484 c1 :1,
1485 c2 :1,
1486 tos :3,
1487 c3 :1,
1488 busy :1;
1489 };
1490
1491 struct mmst_reg {
1492 char mmst_reg[10];
1493 char mmst_rsrv[6];
1494 };
1495
1496 struct xmm_reg {
1497 char xmm_reg[16];
1498 };
1499
1500 struct x86_float_state64_t {
1501 int32_t fpu_reserved[2];
1502 fp_control_t fpu_fcw;
1503 fp_status_t fpu_fsw;
1504 uint8_t fpu_ftw;
1505 uint8_t fpu_rsrv1;
1506 uint16_t fpu_fop;
1507 uint32_t fpu_ip;
1508 uint16_t fpu_cs;
1509 uint16_t fpu_rsrv2;
1510 uint32_t fpu_dp;
1511 uint16_t fpu_ds;
1512 uint16_t fpu_rsrv3;
1513 uint32_t fpu_mxcsr;
1514 uint32_t fpu_mxcsrmask;
1515 mmst_reg fpu_stmm0;
1516 mmst_reg fpu_stmm1;
1517 mmst_reg fpu_stmm2;
1518 mmst_reg fpu_stmm3;
1519 mmst_reg fpu_stmm4;
1520 mmst_reg fpu_stmm5;
1521 mmst_reg fpu_stmm6;
1522 mmst_reg fpu_stmm7;
1523 xmm_reg fpu_xmm0;
1524 xmm_reg fpu_xmm1;
1525 xmm_reg fpu_xmm2;
1526 xmm_reg fpu_xmm3;
1527 xmm_reg fpu_xmm4;
1528 xmm_reg fpu_xmm5;
1529 xmm_reg fpu_xmm6;
1530 xmm_reg fpu_xmm7;
1531 xmm_reg fpu_xmm8;
1532 xmm_reg fpu_xmm9;
1533 xmm_reg fpu_xmm10;
1534 xmm_reg fpu_xmm11;
1535 xmm_reg fpu_xmm12;
1536 xmm_reg fpu_xmm13;
1537 xmm_reg fpu_xmm14;
1538 xmm_reg fpu_xmm15;
1539 char fpu_rsrv4[6*16];
1540 uint32_t fpu_reserved1;
1541 };
1542
1543 struct x86_exception_state64_t {
1544 uint16_t trapno;
1545 uint16_t cpu;
1546 uint32_t err;
1547 uint64_t faultvaddr;
1548 };
1549
1550 inline void swapStruct(x86_thread_state64_t &x) {
1551 sys::swapByteOrder(x.rax);
1552 sys::swapByteOrder(x.rbx);
1553 sys::swapByteOrder(x.rcx);
1554 sys::swapByteOrder(x.rdx);
1555 sys::swapByteOrder(x.rdi);
1556 sys::swapByteOrder(x.rsi);
1557 sys::swapByteOrder(x.rbp);
1558 sys::swapByteOrder(x.rsp);
1559 sys::swapByteOrder(x.r8);
1560 sys::swapByteOrder(x.r9);
1561 sys::swapByteOrder(x.r10);
1562 sys::swapByteOrder(x.r11);
1563 sys::swapByteOrder(x.r12);
1564 sys::swapByteOrder(x.r13);
1565 sys::swapByteOrder(x.r14);
1566 sys::swapByteOrder(x.r15);
1567 sys::swapByteOrder(x.rip);
1568 sys::swapByteOrder(x.rflags);
1569 sys::swapByteOrder(x.cs);
1570 sys::swapByteOrder(x.fs);
1571 sys::swapByteOrder(x.gs);
1572 }
1573
1574 inline void swapStruct(x86_float_state64_t &x) {
1575 sys::swapByteOrder(x.fpu_reserved[0]);
1576 sys::swapByteOrder(x.fpu_reserved[1]);
1577 // TODO swap: fp_control_t fpu_fcw;
1578 // TODO swap: fp_status_t fpu_fsw;
1579 sys::swapByteOrder(x.fpu_fop);
1580 sys::swapByteOrder(x.fpu_ip);
1581 sys::swapByteOrder(x.fpu_cs);
1582 sys::swapByteOrder(x.fpu_rsrv2);
1583 sys::swapByteOrder(x.fpu_dp);
1584 sys::swapByteOrder(x.fpu_ds);
1585 sys::swapByteOrder(x.fpu_rsrv3);
1586 sys::swapByteOrder(x.fpu_mxcsr);
1587 sys::swapByteOrder(x.fpu_mxcsrmask);
1588 sys::swapByteOrder(x.fpu_reserved1);
1589 }
1590
1591 inline void swapStruct(x86_exception_state64_t &x) {
1592 sys::swapByteOrder(x.trapno);
1593 sys::swapByteOrder(x.cpu);
1594 sys::swapByteOrder(x.err);
1595 sys::swapByteOrder(x.faultvaddr);
1596 }
1597
1598 struct x86_state_hdr_t {
1599 uint32_t flavor;
1600 uint32_t count;
1601 };
1602
1603 struct x86_thread_state_t {
1604 x86_state_hdr_t tsh;
1605 union {
1606 x86_thread_state64_t ts64;
1607 } uts;
1608 };
1609
1610 struct x86_float_state_t {
1611 x86_state_hdr_t fsh;
1612 union {
1613 x86_float_state64_t fs64;
1614 } ufs;
1615 };
1616
1617 struct x86_exception_state_t {
1618 x86_state_hdr_t esh;
1619 union {
1620 x86_exception_state64_t es64;
1621 } ues;
1622 };
1623
1624 inline void swapStruct(x86_state_hdr_t &x) {
1625 sys::swapByteOrder(x.flavor);
1626 sys::swapByteOrder(x.count);
1627 }
1628
1629 enum X86ThreadFlavors {
1630 x86_THREAD_STATE32 = 1,
1631 x86_FLOAT_STATE32 = 2,
1632 x86_EXCEPTION_STATE32 = 3,
1633 x86_THREAD_STATE64 = 4,
1634 x86_FLOAT_STATE64 = 5,
1635 x86_EXCEPTION_STATE64 = 6,
1636 x86_THREAD_STATE = 7,
1637 x86_FLOAT_STATE = 8,
1638 x86_EXCEPTION_STATE = 9,
1639 x86_DEBUG_STATE32 = 10,
1640 x86_DEBUG_STATE64 = 11,
1641 x86_DEBUG_STATE = 12
1642 };
1643
1644 inline void swapStruct(x86_thread_state_t &x) {
1645 swapStruct(x.tsh);
1646 if (x.tsh.flavor == x86_THREAD_STATE64)
1647 swapStruct(x.uts.ts64);
1648 }
1649
1650 inline void swapStruct(x86_float_state_t &x) {
1651 swapStruct(x.fsh);
1652 if (x.fsh.flavor == x86_FLOAT_STATE64)
1653 swapStruct(x.ufs.fs64);
1654 }
1655
1656 inline void swapStruct(x86_exception_state_t &x) {
1657 swapStruct(x.esh);
1658 if (x.esh.flavor == x86_EXCEPTION_STATE64)
1659 swapStruct(x.ues.es64);
1660 }
1661
1662 const uint32_t x86_THREAD_STATE64_COUNT =
1663 sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1664 const uint32_t x86_FLOAT_STATE64_COUNT =
1665 sizeof(x86_float_state64_t) / sizeof(uint32_t);
1666 const uint32_t x86_EXCEPTION_STATE64_COUNT =
1667 sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1668
1669 const uint32_t x86_THREAD_STATE_COUNT =
1670 sizeof(x86_thread_state_t) / sizeof(uint32_t);
1671 const uint32_t x86_FLOAT_STATE_COUNT =
1672 sizeof(x86_float_state_t) / sizeof(uint32_t);
1673 const uint32_t x86_EXCEPTION_STATE_COUNT =
1674 sizeof(x86_exception_state_t) / sizeof(uint32_t);
1675
14151676 } // end namespace MachO
14161677 } // end namespace llvm
14171678
23412341 return getStruct(this, L.Ptr);
23422342 }
23432343
2344 MachO::thread_command
2345 MachOObjectFile::getThreadCommand(const LoadCommandInfo &L) const {
2346 return getStruct(this, L.Ptr);
2347 }
2348
23442349 MachO::any_relocation_info
23452350 MachOObjectFile::getRelocation(DataRefImpl Rel) const {
23462351 DataRefImpl Sec;
1414 // RUN: | FileCheck %s -check-prefix=SUB_CLI
1515 // RUN: llvm-objdump -p %p/Inputs/dylibRoutines.macho-x86_64 \
1616 // RUN: | FileCheck %s -check-prefix=ROUTINE
17 // RUN: llvm-objdump -p %p/Inputs/exeThread.macho-x86_64 \
18 // RUN: | FileCheck %s -check-prefix=THREAD
1719
1820 CHECK: Mach header
1921 CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
420422 ROUTINE: reserved4 0
421423 ROUTINE: reserved5 0
422424 ROUTINE: reserved6 0
425
426 THREAD: Load command 10
427 THREAD: cmd LC_UNIXTHREAD
428 THREAD: cmdsize 184
429 THREAD: flavor x86_THREAD_STATE64
430 THREAD: count x86_THREAD_STATE64_COUNT
431 THREAD: rax 0x0000000000000000 rbx 0x0000000000000000 rcx 0x0000000000000000
432 THREAD: rdx 0x0000000000000000 rdi 0x0000000000000000 rsi 0x0000000000000000
433 THREAD: rbp 0x0000000000000000 rsp 0x0000000000000000 r8 0x0000000000000000
434 THREAD: r9 0x0000000000000000 r10 0x0000000000000000 r11 0x0000000000000000
435 THREAD: r12 0x0000000000000000 r13 0x0000000000000000 r14 0x0000000000000000
436 THREAD: r15 0x0000000000000000 rip 0x0000000100000d00
437 THREAD: rflags 0x0000000000000000 cs 0x0000000000000000 fs 0x0000000000000000
438 THREAD: gs 0x0000000000000000
37723772 outs() << " reserved6 " << r.reserved6 << "\n";
37733773 }
37743774
3775 static void Print_x86_thread_state64_t(MachO::x86_thread_state64_t &cpu64) {
3776 outs() << " rax " << format("0x%016" PRIx64, cpu64.rax);
3777 outs() << " rbx " << format("0x%016" PRIx64, cpu64.rbx);
3778 outs() << " rcx " << format("0x%016" PRIx64, cpu64.rcx) << "\n";
3779 outs() << " rdx " << format("0x%016" PRIx64, cpu64.rdx);
3780 outs() << " rdi " << format("0x%016" PRIx64, cpu64.rdi);
3781 outs() << " rsi " << format("0x%016" PRIx64, cpu64.rsi) << "\n";
3782 outs() << " rbp " << format("0x%016" PRIx64, cpu64.rbp);
3783 outs() << " rsp " << format("0x%016" PRIx64, cpu64.rsp);
3784 outs() << " r8 " << format("0x%016" PRIx64, cpu64.r8) << "\n";
3785 outs() << " r9 " << format("0x%016" PRIx64, cpu64.r9);
3786 outs() << " r10 " << format("0x%016" PRIx64, cpu64.r10);
3787 outs() << " r11 " << format("0x%016" PRIx64, cpu64.r11) << "\n";
3788 outs() << " r12 " << format("0x%016" PRIx64, cpu64.r12);
3789 outs() << " r13 " << format("0x%016" PRIx64, cpu64.r13);
3790 outs() << " r14 " << format("0x%016" PRIx64, cpu64.r14) << "\n";
3791 outs() << " r15 " << format("0x%016" PRIx64, cpu64.r15);
3792 outs() << " rip " << format("0x%016" PRIx64, cpu64.rip) << "\n";
3793 outs() << "rflags " << format("0x%016" PRIx64, cpu64.rflags);
3794 outs() << " cs " << format("0x%016" PRIx64, cpu64.cs);
3795 outs() << " fs " << format("0x%016" PRIx64, cpu64.fs) << "\n";
3796 outs() << " gs " << format("0x%016" PRIx64, cpu64.gs) << "\n";
3797 }
3798
3799 static void Print_mmst_reg(MachO::mmst_reg &r) {
3800 uint32_t f;
3801 outs() << "\t mmst_reg ";
3802 for (f = 0; f < 10; f++)
3803 outs() << format("%02" PRIx32, (r.mmst_reg[f] & 0xff)) << " ";
3804 outs() << "\n";
3805 outs() << "\t mmst_rsrv ";
3806 for (f = 0; f < 6; f++)
3807 outs() << format("%02" PRIx32, (r.mmst_rsrv[f] & 0xff)) << " ";
3808 outs() << "\n";
3809 }
3810
3811 static void Print_xmm_reg(MachO::xmm_reg &r) {
3812 uint32_t f;
3813 outs() << "\t xmm_reg ";
3814 for (f = 0; f < 16; f++)
3815 outs() << format("%02" PRIx32, (r.xmm_reg[f] & 0xff)) << " ";
3816 outs() << "\n";
3817 }
3818
3819 static void Print_x86_float_state_t(MachO::x86_float_state64_t &fpu) {
3820 outs() << "\t fpu_reserved[0] " << fpu.fpu_reserved[0];
3821 outs() << " fpu_reserved[1] " << fpu.fpu_reserved[1] << "\n";
3822 outs() << "\t control: invalid " << fpu.fpu_fcw.invalid;
3823 outs() << " denorm " << fpu.fpu_fcw.denorm;
3824 outs() << " zdiv " << fpu.fpu_fcw.zdiv;
3825 outs() << " ovrfl " << fpu.fpu_fcw.ovrfl;
3826 outs() << " undfl " << fpu.fpu_fcw.undfl;
3827 outs() << " precis " << fpu.fpu_fcw.precis << "\n";
3828 outs() << "\t\t pc ";
3829 if (fpu.fpu_fcw.pc == MachO::x86_FP_PREC_24B)
3830 outs() << "FP_PREC_24B ";
3831 else if (fpu.fpu_fcw.pc == MachO::x86_FP_PREC_53B)
3832 outs() << "FP_PREC_53B ";
3833 else if (fpu.fpu_fcw.pc == MachO::x86_FP_PREC_64B)
3834 outs() << "FP_PREC_64B ";
3835 else
3836 outs() << fpu.fpu_fcw.pc << " ";
3837 outs() << "rc ";
3838 if (fpu.fpu_fcw.rc == MachO::x86_FP_RND_NEAR)
3839 outs() << "FP_RND_NEAR ";
3840 else if (fpu.fpu_fcw.rc == MachO::x86_FP_RND_DOWN)
3841 outs() << "FP_RND_DOWN ";
3842 else if (fpu.fpu_fcw.rc == MachO::x86_FP_RND_UP)
3843 outs() << "FP_RND_UP ";
3844 else if (fpu.fpu_fcw.rc == MachO::x86_FP_CHOP)
3845 outs() << "FP_CHOP ";
3846 outs() << "\n";
3847 outs() << "\t status: invalid " << fpu.fpu_fsw.invalid;
3848 outs() << " denorm " << fpu.fpu_fsw.denorm;
3849 outs() << " zdiv " << fpu.fpu_fsw.zdiv;
3850 outs() << " ovrfl " << fpu.fpu_fsw.ovrfl;
3851 outs() << " undfl " << fpu.fpu_fsw.undfl;
3852 outs() << " precis " << fpu.fpu_fsw.precis;
3853 outs() << " stkflt " << fpu.fpu_fsw.stkflt << "\n";
3854 outs() << "\t errsumm " << fpu.fpu_fsw.errsumm;
3855 outs() << " c0 " << fpu.fpu_fsw.c0;
3856 outs() << " c1 " << fpu.fpu_fsw.c1;
3857 outs() << " c2 " << fpu.fpu_fsw.c2;
3858 outs() << " tos " << fpu.fpu_fsw.tos;
3859 outs() << " c3 " << fpu.fpu_fsw.c3;
3860 outs() << " busy " << fpu.fpu_fsw.busy << "\n";
3861 outs() << "\t fpu_ftw " << format("0x%02" PRIx32, fpu.fpu_ftw);
3862 outs() << " fpu_rsrv1 " << format("0x%02" PRIx32, fpu.fpu_rsrv1);
3863 outs() << " fpu_fop " << format("0x%04" PRIx32, fpu.fpu_fop);
3864 outs() << " fpu_ip " << format("0x%08" PRIx32, fpu.fpu_ip) << "\n";
3865 outs() << "\t fpu_cs " << format("0x%04" PRIx32, fpu.fpu_cs);
3866 outs() << " fpu_rsrv2 " << format("0x%04" PRIx32, fpu.fpu_rsrv2);
3867 outs() << " fpu_dp " << format("0x%08" PRIx32, fpu.fpu_dp);
3868 outs() << " fpu_ds " << format("0x%04" PRIx32, fpu.fpu_ds) << "\n";
3869 outs() << "\t fpu_rsrv3 " << format("0x%04" PRIx32, fpu.fpu_rsrv3);
3870 outs() << " fpu_mxcsr " << format("0x%08" PRIx32, fpu.fpu_mxcsr);
3871 outs() << " fpu_mxcsrmask " << format("0x%08" PRIx32, fpu.fpu_mxcsrmask);
3872 outs() << "\n";
3873 outs() << "\t fpu_stmm0:\n";
3874 Print_mmst_reg(fpu.fpu_stmm0);
3875 outs() << "\t fpu_stmm1:\n";
3876 Print_mmst_reg(fpu.fpu_stmm1);
3877 outs() << "\t fpu_stmm2:\n";
3878 Print_mmst_reg(fpu.fpu_stmm2);
3879 outs() << "\t fpu_stmm3:\n";
3880 Print_mmst_reg(fpu.fpu_stmm3);
3881 outs() << "\t fpu_stmm4:\n";
3882 Print_mmst_reg(fpu.fpu_stmm4);
3883 outs() << "\t fpu_stmm5:\n";
3884 Print_mmst_reg(fpu.fpu_stmm5);
3885 outs() << "\t fpu_stmm6:\n";
3886 Print_mmst_reg(fpu.fpu_stmm6);
3887 outs() << "\t fpu_stmm7:\n";
3888 Print_mmst_reg(fpu.fpu_stmm7);
3889 outs() << "\t fpu_xmm0:\n";
3890 Print_xmm_reg(fpu.fpu_xmm0);
3891 outs() << "\t fpu_xmm1:\n";
3892 Print_xmm_reg(fpu.fpu_xmm1);
3893 outs() << "\t fpu_xmm2:\n";
3894 Print_xmm_reg(fpu.fpu_xmm2);
3895 outs() << "\t fpu_xmm3:\n";
3896 Print_xmm_reg(fpu.fpu_xmm3);
3897 outs() << "\t fpu_xmm4:\n";
3898 Print_xmm_reg(fpu.fpu_xmm4);
3899 outs() << "\t fpu_xmm5:\n";
3900 Print_xmm_reg(fpu.fpu_xmm5);
3901 outs() << "\t fpu_xmm6:\n";
3902 Print_xmm_reg(fpu.fpu_xmm6);
3903 outs() << "\t fpu_xmm7:\n";
3904 Print_xmm_reg(fpu.fpu_xmm7);
3905 outs() << "\t fpu_xmm8:\n";
3906 Print_xmm_reg(fpu.fpu_xmm8);
3907 outs() << "\t fpu_xmm9:\n";
3908 Print_xmm_reg(fpu.fpu_xmm9);
3909 outs() << "\t fpu_xmm10:\n";
3910 Print_xmm_reg(fpu.fpu_xmm10);
3911 outs() << "\t fpu_xmm11:\n";
3912 Print_xmm_reg(fpu.fpu_xmm11);
3913 outs() << "\t fpu_xmm12:\n";
3914 Print_xmm_reg(fpu.fpu_xmm12);
3915 outs() << "\t fpu_xmm13:\n";
3916 Print_xmm_reg(fpu.fpu_xmm13);
3917 outs() << "\t fpu_xmm14:\n";
3918 Print_xmm_reg(fpu.fpu_xmm14);
3919 outs() << "\t fpu_xmm15:\n";
3920 Print_xmm_reg(fpu.fpu_xmm15);
3921 outs() << "\t fpu_rsrv4:\n";
3922 for (uint32_t f = 0; f < 6; f++) {
3923 outs() << "\t ";
3924 for (uint32_t g = 0; g < 16; g++)
3925 outs() << format("%02" PRIx32, fpu.fpu_rsrv4[f*g]) << " ";
3926 outs() << "\n";
3927 }
3928 outs() << "\t fpu_reserved1 " << format("0x%08" PRIx32, fpu.fpu_reserved1);
3929 outs() << "\n";
3930 }
3931
3932 static void Print_x86_exception_state_t(MachO::x86_exception_state64_t &exc64) {
3933 outs() << "\t trapno " << format("0x%08" PRIx32, exc64.trapno);
3934 outs() << " err " << format("0x%08" PRIx32, exc64.err);
3935 outs() << " faultvaddr " << format("0x%016" PRIx64, exc64.faultvaddr) << "\n";
3936 }
3937
3938 static void PrintThreadCommand(MachO::thread_command t, const char *Ptr,
3939 bool isLittleEndian, uint32_t cputype) {
3940 if (t.cmd == MachO::LC_THREAD)
3941 outs() << " cmd LC_THREAD\n";
3942 else if (t.cmd == MachO::LC_UNIXTHREAD)
3943 outs() << " cmd LC_UNIXTHREAD\n";
3944 else
3945 outs() << " cmd " << t.cmd << " (unknown)\n";
3946 outs() << " cmdsize " << t.cmdsize;
3947 if (t.cmdsize < sizeof(struct MachO::thread_command) + 2 * sizeof(uint32_t))
3948 outs() << " Incorrect size\n";
3949 else
3950 outs() << "\n";
3951
3952 const char *begin = Ptr + sizeof(struct MachO::thread_command);
3953 const char *end = Ptr + t.cmdsize;
3954 uint32_t flavor, count, left;
3955 if (cputype == MachO::CPU_TYPE_X86_64) {
3956 while (begin < end) {
3957 if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
3958 memcpy((char *)&flavor, begin, sizeof(uint32_t));
3959 begin += sizeof(uint32_t);
3960 } else{
3961 flavor = 0;
3962 begin = end;
3963 }
3964 if (isLittleEndian != sys::IsLittleEndianHost)
3965 sys::swapByteOrder(flavor);
3966 if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
3967 memcpy((char *)&count, begin, sizeof(uint32_t));
3968 begin += sizeof(uint32_t);
3969 } else{
3970 count = 0;
3971 begin = end;
3972 }
3973 if (isLittleEndian != sys::IsLittleEndianHost)
3974 sys::swapByteOrder(count);
3975 if (flavor == MachO::x86_THREAD_STATE64) {
3976 outs() << " flavor x86_THREAD_STATE64\n";
3977 if (count == MachO::x86_THREAD_STATE64_COUNT)
3978 outs() << " count x86_THREAD_STATE64_COUNT\n";
3979 else
3980 outs() << " count " << count
3981 << " (not x86_THREAD_STATE64_COUNT)\n";
3982 MachO::x86_thread_state64_t cpu64;
3983 left = end - begin;
3984 if (left >= sizeof(MachO::x86_thread_state64_t)) {
3985 memcpy(&cpu64, begin, sizeof(MachO::x86_thread_state64_t));
3986 begin += sizeof(MachO::x86_thread_state64_t);
3987 } else {
3988 memset(&cpu64, '\0', sizeof(MachO::x86_thread_state64_t));
3989 memcpy(&cpu64, begin, left);
3990 begin += left;
3991 }
3992 if (isLittleEndian != sys::IsLittleEndianHost)
3993 swapStruct(cpu64);
3994 Print_x86_thread_state64_t(cpu64);
3995 } else if (flavor == MachO::x86_THREAD_STATE) {
3996 outs() << " flavor x86_THREAD_STATE\n";
3997 if (count == MachO::x86_THREAD_STATE_COUNT)
3998 outs() << " count x86_THREAD_STATE_COUNT\n";
3999 else
4000 outs() << " count " << count
4001 << " (not x86_THREAD_STATE_COUNT)\n";
4002 struct MachO::x86_thread_state_t ts;
4003 left = end - begin;
4004 if (left >= sizeof(MachO::x86_thread_state_t)) {
4005 memcpy(&ts, begin, sizeof(MachO::x86_thread_state_t));
4006 begin += sizeof(MachO::x86_thread_state_t);
4007 } else {
4008 memset(&ts, '\0', sizeof(MachO::x86_thread_state_t));
4009 memcpy(&ts, begin, left);
4010 begin += left;
4011 }
4012 if (isLittleEndian != sys::IsLittleEndianHost)
4013 swapStruct(ts);
4014 if (ts.tsh.flavor == MachO::x86_THREAD_STATE64) {
4015 outs() << "\t tsh.flavor x86_THREAD_STATE64 ";
4016 if (ts.tsh.count == MachO::x86_THREAD_STATE64_COUNT)
4017 outs() << "tsh.count x86_THREAD_STATE64_COUNT\n";
4018 else
4019 outs() << "tsh.count " << ts.tsh.count
4020 << " (not x86_THREAD_STATE64_COUNT\n";
4021 Print_x86_thread_state64_t(ts.uts.ts64);
4022 } else {
4023 outs() << "\t tsh.flavor " << ts.tsh.flavor
4024 << " tsh.count " << ts.tsh.count << "\n";
4025 }
4026 } else if (flavor == MachO::x86_FLOAT_STATE) {
4027 outs() << " flavor x86_FLOAT_STATE\n";
4028 if (count == MachO::x86_FLOAT_STATE_COUNT)
4029 outs() << " count x86_FLOAT_STATE_COUNT\n";
4030 else
4031 outs() << " count " << count
4032 << " (not x86_FLOAT_STATE_COUNT)\n";
4033 struct MachO::x86_float_state_t fs;
4034 left = end - begin;
4035 if (left >= sizeof(MachO::x86_float_state_t)) {
4036 memcpy(&fs, begin, sizeof(MachO::x86_float_state_t));
4037 begin += sizeof(MachO::x86_float_state_t);
4038 } else {
4039 memset(&fs, '\0', sizeof(MachO::x86_float_state_t));
4040 memcpy(&fs, begin, left);
4041 begin += left;
4042 }
4043 if (isLittleEndian != sys::IsLittleEndianHost)
4044 swapStruct(fs);
4045 if (fs.fsh.flavor == MachO::x86_FLOAT_STATE64) {
4046 outs() << "\t fsh.flavor x86_FLOAT_STATE64 ";
4047 if (fs.fsh.count == MachO::x86_FLOAT_STATE64_COUNT)
4048 outs() << "fsh.count x86_FLOAT_STATE64_COUNT\n";
4049 else
4050 outs() << "fsh.count " << fs.fsh.count
4051 << " (not x86_FLOAT_STATE64_COUNT\n";
4052 Print_x86_float_state_t(fs.ufs.fs64);
4053 } else {
4054 outs() << "\t fsh.flavor " << fs.fsh.flavor
4055 << " fsh.count " << fs.fsh.count << "\n";
4056 }
4057 } else if (flavor == MachO::x86_EXCEPTION_STATE) {
4058 outs() << " flavor x86_EXCEPTION_STATE\n";
4059 if (count == MachO::x86_EXCEPTION_STATE_COUNT)
4060 outs() << " count x86_EXCEPTION_STATE_COUNT\n";
4061 else
4062 outs() << " count " << count
4063 << " (not x86_EXCEPTION_STATE_COUNT)\n";
4064 struct MachO::x86_exception_state_t es;
4065 left = end - begin;
4066 if (left >= sizeof(MachO::x86_exception_state_t)) {
4067 memcpy(&es, begin, sizeof(MachO::x86_exception_state_t));
4068 begin += sizeof(MachO::x86_exception_state_t);
4069 } else {
4070 memset(&es, '\0', sizeof(MachO::x86_exception_state_t));
4071 memcpy(&es, begin, left);
4072 begin += left;
4073 }
4074 if (isLittleEndian != sys::IsLittleEndianHost)
4075 swapStruct(es);
4076 if (es.esh.flavor == MachO::x86_EXCEPTION_STATE64) {
4077 outs() << "\t esh.flavor x86_EXCEPTION_STATE64\n";
4078 if (es.esh.count == MachO::x86_EXCEPTION_STATE64_COUNT)
4079 outs() << "\t esh.count x86_EXCEPTION_STATE64_COUNT\n";
4080 else
4081 outs() << "\t esh.count " << es.esh.count
4082 << " (not x86_EXCEPTION_STATE64_COUNT\n";
4083 Print_x86_exception_state_t(es.ues.es64);
4084 } else {
4085 outs() << "\t esh.flavor " << es.esh.flavor
4086 << " esh.count " << es.esh.count << "\n";
4087 }
4088 } else {
4089 outs() << " flavor " << flavor << " (unknown)\n";
4090 outs() << " count " << count << "\n";
4091 outs() << " state (unknown)\n";
4092 begin += count * sizeof(uint32_t);
4093 }
4094 }
4095 } else {
4096 while (begin < end) {
4097 if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
4098 memcpy((char *)&flavor, begin, sizeof(uint32_t));
4099 begin += sizeof(uint32_t);
4100 } else{
4101 flavor = 0;
4102 begin = end;
4103 }
4104 if (isLittleEndian != sys::IsLittleEndianHost)
4105 sys::swapByteOrder(flavor);
4106 if (end - begin > (ptrdiff_t)sizeof(uint32_t)) {
4107 memcpy((char *)&count, begin, sizeof(uint32_t));
4108 begin += sizeof(uint32_t);
4109 } else{
4110 count = 0;
4111 begin = end;
4112 }
4113 if (isLittleEndian != sys::IsLittleEndianHost)
4114 sys::swapByteOrder(count);
4115 outs() << " flavor " << flavor << "\n";
4116 outs() << " count " << count << "\n";
4117 outs() << " state (Unknown cputype/cpusubtype)\n";
4118 begin += count * sizeof(uint32_t);
4119 }
4120 }
4121 }
4122
37754123 static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
37764124 if (dl.cmd == MachO::LC_ID_DYLIB)
37774125 outs() << " cmd LC_ID_DYLIB\n";
39464294 } else if (Command.C.cmd == MachO::LC_ROUTINES_64) {
39474295 MachO::routines_command_64 Rc = Obj->getRoutinesCommand64(Command);
39484296 PrintRoutinesCommand64(Rc);
4297 } else if (Command.C.cmd == MachO::LC_THREAD ||
4298 Command.C.cmd == MachO::LC_UNIXTHREAD) {
4299 MachO::thread_command Tc = Obj->getThreadCommand(Command);
4300 PrintThreadCommand(Tc, Command.Ptr, Obj->isLittleEndian(), cputype);
39494301 } else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
39504302 Command.C.cmd == MachO::LC_ID_DYLIB ||
39514303 Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||