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.
Esse commit está contido em:
Herman Venter
2013-05-29 15:31:20 -07:00
commit de sgolemon
commit a9fa4568fe
4 arquivos alterados com 19 adições e 20 exclusões
+6 -5
Ver Arquivo
@@ -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();
+11 -12
Ver Arquivo
@@ -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
};
/**
+1 -1
Ver Arquivo
@@ -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) {
+1 -2
Ver Arquivo
@@ -13,8 +13,7 @@ hphpd> run
hphpd> print $this
Foo Object
(
[prop] => Hello
[prop] => "Hello\n"
)

hphpd> quit