<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189134] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189134">189134</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2015-08-28 17:10:07 -0700 (Fri, 28 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerMacroAssemblerPrintercpp">trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerMacroAssemblerPrinterh">trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189133 => 189134)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-08-28 23:43:34 UTC (rev 189133)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-08-29 00:10:07 UTC (rev 189134)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-08-28  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+        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):
+
</ins><span class="cx"> 2015-08-28  Khem Raj  &lt;raj.khem@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         JavaScriptCore fails to build using GCC 5
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerMacroAssemblerPrintercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp (189133 => 189134)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp        2015-08-28 23:43:34 UTC (rev 189133)
+++ trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp        2015-08-29 00:10:07 UTC (rev 189134)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> // print stream. Hence, no indentation will be applied.
</span><span class="cx"> void printRegister(CPUState&amp;, RegisterID);
</span><span class="cx"> void printRegister(CPUState&amp;, FPRegisterID);
</span><ins>+void printMemory(CPUState&amp;, const Memory&amp;);
</ins><span class="cx">     
</span><span class="cx"> static void printIndent(int indentation)
</span><span class="cx"> {
</span><span class="lines">@@ -110,6 +111,62 @@
</span><span class="cx">     dataLogF(&quot;%s:&lt;0x%016llx %.13g&gt;&quot;, name, u.uint64Value, u.doubleValue);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void printMemory(CPUState&amp; cpu, const Memory&amp; memory)
+{
+    uint8_t* ptr = nullptr;
+    switch (memory.addressType) {
+    case Memory::AddressType::Address: {
+        ptr = reinterpret_cast&lt;uint8_t*&gt;(cpu.registerValue(memory.u.address.base));
+        ptr += memory.u.address.offset;
+        break;
+    }
+    case Memory::AddressType::AbsoluteAddress: {
+        ptr = reinterpret_cast&lt;uint8_t*&gt;(const_cast&lt;void*&gt;(memory.u.absoluteAddress.m_ptr));
+        break;
+    }
+    }
+
+    if (memory.dumpStyle == Memory::SingleWordDump) {
+        if (memory.numBytes == sizeof(int8_t)) {
+            auto p = reinterpret_cast&lt;int8_t*&gt;(ptr);
+            dataLogF(&quot;%p:&lt;0x%02x %d&gt;&quot;, p, *p, *p);
+            return;
+        }
+        if (memory.numBytes == sizeof(int16_t)) {
+            auto p = reinterpret_cast&lt;int16_t*&gt;(ptr);
+            dataLogF(&quot;%p:&lt;0x%04x %d&gt;&quot;, p, *p, *p);
+            return;
+        }
+        if (memory.numBytes == sizeof(int32_t)) {
+            auto p = reinterpret_cast&lt;int32_t*&gt;(ptr);
+            dataLogF(&quot;%p:&lt;0x%08x %d&gt;&quot;, p, *p, *p);
+            return;
+        }
+        if (memory.numBytes == sizeof(int64_t)) {
+            auto p = reinterpret_cast&lt;int64_t*&gt;(ptr);
+            dataLogF(&quot;%p:&lt;0x%016llx %lld&gt;&quot;, p, *p, *p);
+            return;
+        }
+        // Else, unknown word size. Fall thru and dump in the generic way.
+    }
+
+    // Generic dump: dump rows of 16 bytes in 4 byte groupings.
+    size_t numBytes = memory.numBytes;
+    for (size_t i = 0; i &lt; numBytes; i++) {
+        if (!(i % 16))
+            dataLogF(&quot;%p: &quot;, &amp;ptr[i]);
+        else if (!(i % 4))
+            dataLog(&quot; &quot;);
+
+        dataLogF(&quot;%02x&quot;, ptr[i]);
+
+        if (i % 16 == 15)
+            dataLog(&quot;\n&quot;);
+    }
+    if (numBytes % 16 &lt; 15)
+        dataLog(&quot;\n&quot;);
+}
+
</ins><span class="cx"> void MacroAssemblerPrinter::printCallback(ProbeContext* context)
</span><span class="cx"> {
</span><span class="cx">     typedef PrintArg Arg;
</span><span class="lines">@@ -127,6 +184,9 @@
</span><span class="cx">         case Arg::Type::FPRegisterID:
</span><span class="cx">             printRegister(context-&gt;cpu, arg.u.fpRegisterID);
</span><span class="cx">             break;
</span><ins>+        case Arg::Type::Memory:
+            printMemory(context-&gt;cpu, arg.u.memory);
+            break;
</ins><span class="cx">         case Arg::Type::ConstCharPtr:
</span><span class="cx">             dataLog(arg.u.constCharPtr);
</span><span class="cx">             break;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerMacroAssemblerPrinterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h (189133 => 189134)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h        2015-08-28 23:43:34 UTC (rev 189133)
+++ trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h        2015-08-29 00:10:07 UTC (rev 189134)
</span><span class="lines">@@ -67,6 +67,15 @@
</span><span class="cx"> //      //      }
</span><span class="cx"> //      jit.print(AllRegisters());
</span><span class="cx"> //
</span><ins>+//      jit.print(MemWord&lt;uint8_t&gt;(regID), &quot;\n&quot;);   // Emits code to print a byte pointed to by the register.
+//      jit.print(MemWord&lt;uint32_t&gt;(regID), &quot;\n&quot;);  // Emits code to print a 32-bit word pointed to by the register.
+//
+//      jit.print(MemWord&lt;uint8_t&gt;(Address(regID, 23), &quot;\n&quot;);     // Emits code to print a byte at the address.
+//      jit.print(MemWord&lt;intptr_t&gt;(AbsoluteAddress(&amp;cb), &quot;\n&quot;);  // Emits code to print an intptr_t sized word at the address.
+//
+//      jit.print(Memory(reg, 100), &quot;\n&quot;);              // Emits code to print a 100 bytes at the address pointed by the register.
+//      jit.print(Memory(Address(reg, 4), 100), &quot;\n&quot;);  // Emits code to print a 100 bytes at the address.
+//
</ins><span class="cx"> //      // Print multiple things at once. This incurs the probe overhead only once
</span><span class="cx"> //      // to print all the items.
</span><span class="cx"> //      jit.print(&quot;cb:&quot;, cb, &quot; regID:&quot;, regID, &quot; cpu:\n&quot;, AllRegisters());
</span><span class="lines">@@ -81,6 +90,72 @@
</span><span class="cx"> // See MacroAssemblerPrinter::print() below for details.
</span><span class="cx"> struct AllRegisters { };
</span><span class="cx"> 
</span><ins>+struct Memory {
+    using Address = MacroAssembler::Address;
+    using AbsoluteAddress = MacroAssembler::AbsoluteAddress;
+    using RegisterID = MacroAssembler::RegisterID;
+
+    enum class AddressType {
+        Address,
+        AbsoluteAddress,
+    };
+
+    enum DumpStyle {
+        SingleWordDump,
+        GenericDump,
+    };
+
+    Memory(RegisterID&amp; reg, size_t bytes, DumpStyle style = GenericDump)
+        : addressType(AddressType::Address)
+        , dumpStyle(style)
+        , numBytes(bytes)
+    {
+        u.address = Address(reg, 0);
+    }
+
+    Memory(const Address&amp; address, size_t bytes, DumpStyle style = GenericDump)
+        : addressType(AddressType::Address)
+        , dumpStyle(style)
+        , numBytes(bytes)
+    {
+        u.address = address;
+    }
+
+    Memory(const AbsoluteAddress&amp; address, size_t bytes, DumpStyle style = GenericDump)
+        : addressType(AddressType::AbsoluteAddress)
+        , dumpStyle(style)
+        , numBytes(bytes)
+    {
+        u.absoluteAddress = address;
+    }
+
+    AddressType addressType;
+    DumpStyle dumpStyle;
+    size_t numBytes;
+    union UnionedAddress {
+        UnionedAddress() { }
+
+        Address address;
+        AbsoluteAddress absoluteAddress;
+    } u;
+};
+
+template &lt;typename IntType&gt;
+struct MemWord : public Memory {
+    MemWord(RegisterID&amp; reg)
+        : Memory(reg, sizeof(IntType), Memory::SingleWordDump)
+    { }
+
+    MemWord(const Address&amp; address)
+        : Memory(address, sizeof(IntType), Memory::SingleWordDump)
+    { }
+
+    MemWord(const AbsoluteAddress&amp; address)
+        : Memory(address, sizeof(IntType), Memory::SingleWordDump)
+    { }
+};
+
+
</ins><span class="cx"> class MacroAssemblerPrinter {
</span><span class="cx">     using CPUState = MacroAssembler::CPUState;
</span><span class="cx">     using ProbeContext = MacroAssembler::ProbeContext;
</span><span class="lines">@@ -103,6 +178,7 @@
</span><span class="cx">             AllRegisters,
</span><span class="cx">             RegisterID,
</span><span class="cx">             FPRegisterID,
</span><ins>+            Memory,
</ins><span class="cx">             ConstCharPtr,
</span><span class="cx">             ConstVoidPtr,
</span><span class="cx">             IntptrValue,
</span><span class="lines">@@ -125,7 +201,13 @@
</span><span class="cx">         {
</span><span class="cx">             u.fpRegisterID = regID;
</span><span class="cx">         }
</span><del>-        
</del><ins>+
+        PrintArg(const Memory&amp; memory)
+            : type(Type::Memory)
+        {
+            u.memory = memory;
+        }
+
</ins><span class="cx">         PrintArg(const char* ptr)
</span><span class="cx">             : type(Type::ConstCharPtr)
</span><span class="cx">         {
</span><span class="lines">@@ -163,9 +245,12 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         Type type;
</span><del>-        union {
</del><ins>+        union Value {
+            Value() { }
+
</ins><span class="cx">             RegisterID gpRegisterID;
</span><span class="cx">             FPRegisterID fpRegisterID;
</span><ins>+            Memory memory;
</ins><span class="cx">             const char* constCharPtr;
</span><span class="cx">             const void* constVoidPtr;
</span><span class="cx">             intptr_t intptrValue;
</span></span></pre>
</div>
</div>

</body>
</html>