From a9fa4568fea6e7d432a2f4dc095429f67e52512f Mon Sep 17 00:00:00 2001 From: Herman Venter Date: Wed, 29 May 2013 15:31:20 -0700 Subject: [PATCH] Always use DebuggerDump for printing values in hphpd client console. The proximal purpose of this differential is to fix the debugger client so that it does not write raw strings to the console (with control characters doing their thing to the console and unprintable characters pretending not to exist). This change in behavior means that the serializer used to convert values to strings can no longer be instantiated with the PrintR option, as it has been in a subset of cases. (The reason being that print_r() must not change its behavior.) Rather than introduce yet another serializer option, I decided to always make the debugger client serialize user visible values using the existing DebuggerDump option, which is already used in a number of such cases and which has no other use. To make the overall change less painful for users, I preferred to change behavior of DebuggerDump to be more like PrintR in a number of cases, primarily the formatting of objects (where the current behavior is to make a JSON like string). This does not impact the behavior of the debugger client API or the behavior of FBIDE, since these do their own thing directly with the DebuggerSerialization format and never see the result of the DebuggerDump format. --- hphp/runtime/base/variable_serializer.cpp | 11 +++++---- hphp/runtime/base/variable_serializer.h | 23 +++++++++---------- .../runtime/eval/debugger/debugger_client.cpp | 2 +- hphp/test/debugger_tests/printThis.expectf | 3 +-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/hphp/runtime/base/variable_serializer.cpp b/hphp/runtime/base/variable_serializer.cpp index 186d1419c..c7de46cea 100644 --- a/hphp/runtime/base/variable_serializer.cpp +++ b/hphp/runtime/base/variable_serializer.cpp @@ -268,7 +268,6 @@ void VariableSerializer::write(const char *v, int len /* = -1 */, m_buf->append(v, len); break; } - case DebuggerDump: case VarExport: { m_buf->append('\''); const char *p = v; @@ -325,6 +324,7 @@ void VariableSerializer::write(const char *v, int len /* = -1 */, m_buf->appendJsonEscape(v, len, m_option); break; } + case DebuggerDump: case PHPOutput: { m_buf->append('"'); for (int i = 0; i < len; ++i) { @@ -519,6 +519,7 @@ void VariableSerializer::writeArrayHeader(int size, bool isVectorData) { info.indent_delta = 0; switch (m_type) { + case DebuggerDump: case PrintR: if (!m_rsrcName.empty()) { m_buf->append("Resource id #"); @@ -608,7 +609,6 @@ void VariableSerializer::writeArrayHeader(int size, bool isVectorData) { } break; case JSON: - case DebuggerDump: info.is_vector = (m_objClass.empty() || m_objCode == 'V' || m_objCode == 'K') && isVectorData; @@ -664,7 +664,7 @@ void VariableSerializer::writePropertyKey(CStrRef prop) { } } else { m_buf->append(prop); - if (m_type != PrintR) m_buf->append('"'); + if (m_type != PrintR && m_type != DebuggerDump) m_buf->append('"'); } } @@ -678,6 +678,7 @@ void VariableSerializer::writeArrayKey(Variant key) { } ArrayInfo &info = m_arrayInfos.back(); switch (m_type) { + case DebuggerDump: case PrintR: { indent(); m_buf->append('['); @@ -718,7 +719,6 @@ void VariableSerializer::writeArrayKey(Variant key) { write(key); break; case JSON: - case DebuggerDump: if (!info.first_element) { m_buf->append(','); } @@ -824,8 +824,10 @@ void VariableSerializer::writeArrayFooter() { m_indent -= info.indent_delta; switch (m_type) { + case DebuggerDump: case PrintR: if (m_rsrcName.empty()) { + if (m_type == DebuggerDump) m_buf->append("\n"); indent(); m_buf->append(")\n"); if (m_indent > 0) { @@ -860,7 +862,6 @@ void VariableSerializer::writeArrayFooter() { m_buf->append('}'); break; case JSON: - case DebuggerDump: if (m_type == JSON && m_option & k_JSON_PRETTY_PRINT) { m_buf->append("\n"); indent(); diff --git a/hphp/runtime/base/variable_serializer.h b/hphp/runtime/base/variable_serializer.h index b4533ea74..9946c4fb0 100644 --- a/hphp/runtime/base/variable_serializer.h +++ b/hphp/runtime/base/variable_serializer.h @@ -29,8 +29,7 @@ class ClassInfo; /** * Maintaining states during serialization of a variable. We use this single - * class to uniformly serialize variables according to different formats: - * print_r(), var_export(), var_dump(), debug_zval_dump() or serialize(). + * class to uniformly serialize variables according to different formats. */ class VariableSerializer { public: @@ -38,16 +37,16 @@ public: * Supported formats. */ enum Type { - PrintR, - VarExport, - VarDump, - DebugDump, - DebuggerDump, - Serialize, - JSON, - APCSerialize, - DebuggerSerialize, - PHPOutput, + PrintR, //print_r() + VarExport, //var_export() + VarDump, //var_dump() + DebugDump, //debug_zval_dump() + DebuggerDump, //used by hphp debugger to obtain user visible output + Serialize, // serialize() + JSON, //json_encode() + APCSerialize, //used in APC serialization (controlled by switch) + DebuggerSerialize, //used by hphp debugger for client<->proxy communication + PHPOutput, //used by compiler to output scalar values into byte code }; /** diff --git a/hphp/runtime/eval/debugger/debugger_client.cpp b/hphp/runtime/eval/debugger/debugger_client.cpp index 5abc68cfa..50e494969 100644 --- a/hphp/runtime/eval/debugger/debugger_client.cpp +++ b/hphp/runtime/eval/debugger/debugger_client.cpp @@ -332,7 +332,7 @@ String DebuggerClient::FormatVariable(CVarRef v, int maxlen /* = 80 */, try { VariableSerializer::Type t = vardump ? VariableSerializer::VarDump : - VariableSerializer::PrintR; + VariableSerializer::DebuggerDump; VariableSerializer vs(t, 0, 2); value = vs.serialize(v, true); } catch (StringBufferLimitException &e) { diff --git a/hphp/test/debugger_tests/printThis.expectf b/hphp/test/debugger_tests/printThis.expectf index 2575253d7..f7d72889b 100644 --- a/hphp/test/debugger_tests/printThis.expectf +++ b/hphp/test/debugger_tests/printThis.expectf @@ -13,8 +13,7 @@ hphpd> run hphpd> print $this Foo Object ( - [prop] => Hello - + [prop] => "Hello\n" )  hphpd> quit