Changeset 189134 in webkit


Ignore:
Timestamp:
Aug 28, 2015, 5:10:07 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

Add MacroAssemblerPrinter support for printing memory.
https://bugs.webkit.org/show_bug.cgi?id=148600

Reviewed by Saam Barati.

Previously, we can dump registers at runtime. Now we can dump memory too.
See comment in MacroAssemblerPrinter.h for examples of how to do this.

  • assembler/MacroAssemblerPrinter.cpp:

(JSC::printMemory):
(JSC::MacroAssemblerPrinter::printCallback):

  • assembler/MacroAssemblerPrinter.h:

(JSC::Memory::Memory):
(JSC::MemWord::MemWord):
(JSC::MacroAssemblerPrinter::PrintArg::PrintArg):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189133 r189134  
     12015-08-28  Mark Lam  <mark.lam@apple.com>
     2
     3        Add MacroAssemblerPrinter support for printing memory.
     4        https://bugs.webkit.org/show_bug.cgi?id=148600
     5
     6        Reviewed by Saam Barati.
     7
     8        Previously, we can dump registers at runtime.  Now we can dump memory too.
     9        See comment in MacroAssemblerPrinter.h for examples of how to do this.
     10
     11        * assembler/MacroAssemblerPrinter.cpp:
     12        (JSC::printMemory):
     13        (JSC::MacroAssemblerPrinter::printCallback):
     14        * assembler/MacroAssemblerPrinter.h:
     15        (JSC::Memory::Memory):
     16        (JSC::MemWord::MemWord):
     17        (JSC::MacroAssemblerPrinter::PrintArg::PrintArg):
     18
    1192015-08-28  Khem Raj  <raj.khem@gmail.com>
    220
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp

    r189130 r189134  
    4747void printRegister(CPUState&, RegisterID);
    4848void printRegister(CPUState&, FPRegisterID);
     49void printMemory(CPUState&, const Memory&);
    4950   
    5051static void printIndent(int indentation)
     
    111112}
    112113
     114void printMemory(CPUState& cpu, const Memory& memory)
     115{
     116    uint8_t* ptr = nullptr;
     117    switch (memory.addressType) {
     118    case Memory::AddressType::Address: {
     119        ptr = reinterpret_cast<uint8_t*>(cpu.registerValue(memory.u.address.base));
     120        ptr += memory.u.address.offset;
     121        break;
     122    }
     123    case Memory::AddressType::AbsoluteAddress: {
     124        ptr = reinterpret_cast<uint8_t*>(const_cast<void*>(memory.u.absoluteAddress.m_ptr));
     125        break;
     126    }
     127    }
     128
     129    if (memory.dumpStyle == Memory::SingleWordDump) {
     130        if (memory.numBytes == sizeof(int8_t)) {
     131            auto p = reinterpret_cast<int8_t*>(ptr);
     132            dataLogF("%p:<0x%02x %d>", p, *p, *p);
     133            return;
     134        }
     135        if (memory.numBytes == sizeof(int16_t)) {
     136            auto p = reinterpret_cast<int16_t*>(ptr);
     137            dataLogF("%p:<0x%04x %d>", p, *p, *p);
     138            return;
     139        }
     140        if (memory.numBytes == sizeof(int32_t)) {
     141            auto p = reinterpret_cast<int32_t*>(ptr);
     142            dataLogF("%p:<0x%08x %d>", p, *p, *p);
     143            return;
     144        }
     145        if (memory.numBytes == sizeof(int64_t)) {
     146            auto p = reinterpret_cast<int64_t*>(ptr);
     147            dataLogF("%p:<0x%016llx %lld>", p, *p, *p);
     148            return;
     149        }
     150        // Else, unknown word size. Fall thru and dump in the generic way.
     151    }
     152
     153    // Generic dump: dump rows of 16 bytes in 4 byte groupings.
     154    size_t numBytes = memory.numBytes;
     155    for (size_t i = 0; i < numBytes; i++) {
     156        if (!(i % 16))
     157            dataLogF("%p: ", &ptr[i]);
     158        else if (!(i % 4))
     159            dataLog(" ");
     160
     161        dataLogF("%02x", ptr[i]);
     162
     163        if (i % 16 == 15)
     164            dataLog("\n");
     165    }
     166    if (numBytes % 16 < 15)
     167        dataLog("\n");
     168}
     169
    113170void MacroAssemblerPrinter::printCallback(ProbeContext* context)
    114171{
     
    128185            printRegister(context->cpu, arg.u.fpRegisterID);
    129186            break;
     187        case Arg::Type::Memory:
     188            printMemory(context->cpu, arg.u.memory);
     189            break;
    130190        case Arg::Type::ConstCharPtr:
    131191            dataLog(arg.u.constCharPtr);
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h

    r189130 r189134  
    6868//      jit.print(AllRegisters());
    6969//
     70//      jit.print(MemWord<uint8_t>(regID), "\n");   // Emits code to print a byte pointed to by the register.
     71//      jit.print(MemWord<uint32_t>(regID), "\n");  // Emits code to print a 32-bit word pointed to by the register.
     72//
     73//      jit.print(MemWord<uint8_t>(Address(regID, 23), "\n");     // Emits code to print a byte at the address.
     74//      jit.print(MemWord<intptr_t>(AbsoluteAddress(&cb), "\n");  // Emits code to print an intptr_t sized word at the address.
     75//
     76//      jit.print(Memory(reg, 100), "\n");              // Emits code to print a 100 bytes at the address pointed by the register.
     77//      jit.print(Memory(Address(reg, 4), 100), "\n");  // Emits code to print a 100 bytes at the address.
     78//
    7079//      // Print multiple things at once. This incurs the probe overhead only once
    7180//      // to print all the items.
     
    8190// See MacroAssemblerPrinter::print() below for details.
    8291struct AllRegisters { };
     92
     93struct Memory {
     94    using Address = MacroAssembler::Address;
     95    using AbsoluteAddress = MacroAssembler::AbsoluteAddress;
     96    using RegisterID = MacroAssembler::RegisterID;
     97
     98    enum class AddressType {
     99        Address,
     100        AbsoluteAddress,
     101    };
     102
     103    enum DumpStyle {
     104        SingleWordDump,
     105        GenericDump,
     106    };
     107
     108    Memory(RegisterID& reg, size_t bytes, DumpStyle style = GenericDump)
     109        : addressType(AddressType::Address)
     110        , dumpStyle(style)
     111        , numBytes(bytes)
     112    {
     113        u.address = Address(reg, 0);
     114    }
     115
     116    Memory(const Address& address, size_t bytes, DumpStyle style = GenericDump)
     117        : addressType(AddressType::Address)
     118        , dumpStyle(style)
     119        , numBytes(bytes)
     120    {
     121        u.address = address;
     122    }
     123
     124    Memory(const AbsoluteAddress& address, size_t bytes, DumpStyle style = GenericDump)
     125        : addressType(AddressType::AbsoluteAddress)
     126        , dumpStyle(style)
     127        , numBytes(bytes)
     128    {
     129        u.absoluteAddress = address;
     130    }
     131
     132    AddressType addressType;
     133    DumpStyle dumpStyle;
     134    size_t numBytes;
     135    union UnionedAddress {
     136        UnionedAddress() { }
     137
     138        Address address;
     139        AbsoluteAddress absoluteAddress;
     140    } u;
     141};
     142
     143template <typename IntType>
     144struct MemWord : public Memory {
     145    MemWord(RegisterID& reg)
     146        : Memory(reg, sizeof(IntType), Memory::SingleWordDump)
     147    { }
     148
     149    MemWord(const Address& address)
     150        : Memory(address, sizeof(IntType), Memory::SingleWordDump)
     151    { }
     152
     153    MemWord(const AbsoluteAddress& address)
     154        : Memory(address, sizeof(IntType), Memory::SingleWordDump)
     155    { }
     156};
     157
    83158
    84159class MacroAssemblerPrinter {
     
    104179            RegisterID,
    105180            FPRegisterID,
     181            Memory,
    106182            ConstCharPtr,
    107183            ConstVoidPtr,
     
    126202            u.fpRegisterID = regID;
    127203        }
    128        
     204
     205        PrintArg(const Memory& memory)
     206            : type(Type::Memory)
     207        {
     208            u.memory = memory;
     209        }
     210
    129211        PrintArg(const char* ptr)
    130212            : type(Type::ConstCharPtr)
     
    164246       
    165247        Type type;
    166         union {
     248        union Value {
     249            Value() { }
     250
    167251            RegisterID gpRegisterID;
    168252            FPRegisterID fpRegisterID;
     253            Memory memory;
    169254            const char* constCharPtr;
    170255            const void* constVoidPtr;
Note: See TracChangeset for help on using the changeset viewer.