make debug_backtrace 5.4 compatible

This was spewing on mediawiki and we need to update. It is backwards compat.

I tried to put the constants in PHP but failed. I spent 30 mins on it. I'll come back to it next time I get the itch.

Closes #812
Esse commit está contido em:
Paul Tarjan
2013-06-06 13:33:03 -07:00
commit de Sara Golemon
commit 613295121f
10 arquivos alterados com 86 adições e 24 exclusões
+3 -1
Ver Arquivo
@@ -660,7 +660,9 @@ public:
Array debugBacktrace(bool skip = false,
bool withSelf = false,
bool withThis = false,
VMParserFrame* parserFrame = nullptr);
VMParserFrame* parserFrame = nullptr,
bool ignoreArgs = false,
int limit = 0);
VarEnv* getVarEnv();
void setVar(StringData* name, TypedValue* v, bool ref);
Array getLocalDefinedVariables(int frame);
+34 -7
Ver Arquivo
@@ -23,8 +23,15 @@
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
Array f_debug_backtrace(bool provide_object /* = true */) {
return g_vmContext->debugBacktrace(true, false, provide_object);
const int DEBUG_BACKTRACE_PROVIDE_OBJECT = 1;
const int DEBUG_BACKTRACE_IGNORE_ARGS = 2;
Array f_debug_backtrace(int64_t options /* = 1 */, int64_t limit /* = 0 */) {
bool provide_object = options & DEBUG_BACKTRACE_PROVIDE_OBJECT;
bool ignore_args = options & DEBUG_BACKTRACE_IGNORE_ARGS;
return g_vmContext->debugBacktrace(
true, false, provide_object, nullptr, ignore_args, limit
);
}
/**
@@ -45,8 +52,10 @@ Array f_hphp_debug_caller_info() {
return Array::Create();
}
void f_debug_print_backtrace() {
echo(debug_string_backtrace(true));
void f_debug_print_backtrace(int64_t options /* = 0 */,
int64_t limit /* = 0 */) {
bool ignore_args = options & DEBUG_BACKTRACE_IGNORE_ARGS;
echo(debug_string_backtrace(true, ignore_args, limit));
}
static const StaticString s_class("class");
@@ -55,12 +64,15 @@ static const StaticString s_function("function");
static const StaticString s_file("file");
static const StaticString s_line("line");
static const StaticString s_message("message");
static const StaticString s_args("args");
String debug_string_backtrace(bool skip) {
String debug_string_backtrace(bool skip, bool ignore_args /* = false */,
int limit /* = 0 */) {
if (RuntimeOption::InjectedStackTrace) {
Array bt;
StringBuffer buf;
bt = g_vmContext->debugBacktrace(skip);
bt = g_vmContext->debugBacktrace(skip, false, false, nullptr,
ignore_args, limit);
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
@@ -73,7 +85,19 @@ String debug_string_backtrace(bool skip) {
buf.append(frame->get(s_type).toString());
}
buf.append(frame->get(s_function).toString());
buf.append("()");
buf.append("(");
if (!ignore_args) {
bool first = true;
for (ArrayIter it = frame->get(s_args).begin(); !it.end(); it.next()) {
if (!first) {
buf.append(", ");
} else {
first = false;
}
buf.append(it.second().toString());
}
}
buf.append(")");
if (frame.exists(s_file)) {
buf.append(" called at [");
buf.append(frame->get(s_file).toString());
@@ -191,5 +215,8 @@ bool f_user_error(CStrRef error_msg, int error_type /* = k_E_USER_NOTICE */) {
return f_trigger_error(error_msg, error_type);
}
const int64_t k_DEBUG_BACKTRACE_PROVIDE_OBJECT = 1;
const int64_t k_DEBUG_BACKTRACE_IGNORE_ARGS = 2;
///////////////////////////////////////////////////////////////////////////////
}
+6 -4
Ver Arquivo
@@ -25,10 +25,11 @@
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
Array f_debug_backtrace(bool provide_object = true);
Array f_debug_backtrace(int64_t options = 1, int64_t limit = 0);
Array f_hphp_debug_caller_info();
void f_debug_print_backtrace();
String debug_string_backtrace(bool skip);
void f_debug_print_backtrace(int64_t options = 0, int64_t limit = 0);
String debug_string_backtrace(bool skip, bool ignore_args = false,
int limit = 0);
Array f_error_get_last();
bool f_error_log(CStrRef message, int message_type = 0, CStrRef destination = null_string, CStrRef extra_headers = null_string);
int64_t f_error_reporting(CVarRef level = uninit_null());
@@ -41,7 +42,8 @@ void f_hphp_throw_fatal_error(CStrRef error_msg);
void f_hphp_clear_unflushed();
bool f_trigger_error(CStrRef error_msg, int error_type = k_E_USER_NOTICE);
bool f_user_error(CStrRef error_msg, int error_type = k_E_USER_NOTICE);
extern const int64_t k_DEBUG_BACKTRACE_PROVIDE_OBJECT;
extern const int64_t k_DEBUG_BACKTRACE_IGNORE_ARGS;
///////////////////////////////////////////////////////////////////////////////
}
+8 -3
Ver Arquivo
@@ -1965,7 +1965,9 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
bool withSelf /* = false */,
bool withThis /* = false */,
VMParserFrame*
parserFrame /* = NULL */) {
parserFrame /* = NULL */,
bool ignoreArgs /* = false */,
int limit /* = 0 */) {
Array bt = Array::Create();
// If there is a parser frame, put it at the beginning of
@@ -2032,7 +2034,8 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
// Handle the subsequent VM frames
Offset prevPc = 0;
for (ActRec* prevFp = getPrevVMState(fp, &prevPc); fp != nullptr;
for (ActRec* prevFp = getPrevVMState(fp, &prevPc);
fp != nullptr && (limit == 0 || depth < limit);
fp = prevFp, pc = prevPc, prevFp = getPrevVMState(fp, &prevPc)) {
// do not capture frame for HPHP only functions
if (fp->m_func->isNoInjection()) {
@@ -2115,7 +2118,9 @@ Array VMExecutionContext::debugBacktrace(bool skip /* = false */,
}
Array args = Array::Create();
if (funcname.same(s_include)) {
if (ignoreArgs) {
// do nothing
} else if (funcname.same(s_include)) {
if (depth) {
args.append(const_cast<StringData*>(curUnit->filepath()));
frame.set(s_args, args, true);
+31 -5
Ver Arquivo
@@ -1,6 +1,14 @@
{
"preamble": "",
"consts": [
{
"name": "DEBUG_BACKTRACE_PROVIDE_OBJECT",
"type": "Int64"
},
{
"name": "DEBUG_BACKTRACE_IGNORE_ARGS",
"type": "Int64"
}
],
"funcs": [
{
@@ -16,10 +24,16 @@
},
"args": [
{
"name": "provide_object",
"type": "Boolean",
"value": "true",
"desc": "Whether or not to populate the \"object\" index."
"name": "options",
"type": "Int64",
"value": "1",
"desc": "Whether or not to populate the \"object\" index.\n\nDEBUG_BACKTRACE_PROVIDE_OBJECT: Whether or not to populate the \"object\" index.\nDEBUG_BACKTRACE_IGNORE_ARGS: Whether or not to omit the \"args\" index, and thus all the function/method arguments, to save memory."
},
{
"name": "limit",
"type": "Int64",
"value": "0",
"desc": "This parameter can be used to limit the number of stack frames returned. By default (limit=0) it returns all stack frames."
}
]
},
@@ -35,6 +49,18 @@
"desc": "No value is returned."
},
"args": [
{
"name": "options",
"type": "Int64",
"value": "0",
"desc": "Whether or not to populate the \"object\" index.\n\nDEBUG_BACKTRACE_IGNORE_ARGS: Whether or not to omit the \"args\" index, and thus all the function/method arguments, to save memory."
},
{
"name": "limit",
"type": "Int64",
"value": "0",
"desc": "This parameter can be used to limit the number of stack frames returned. By default (limit=0) it returns all stack frames."
}
]
},
{
@@ -283,4 +309,4 @@
],
"classes": [
]
}
}
+4 -4
Ver Arquivo
@@ -1,12 +1,12 @@
Use: 246 2000
Args: 777 500
#0 funk() called at %s:17]
#1 {closure}() called at %s:27]
#0 funk(777, 500) called at %s:17]
#1 {closure}(777) called at %s:27]
#2 main() called at %s:33]
Use: 246 4000
Args: 888 500
#0 funk() called at %s:17]
#1 {closure}() called at %s:28]
#0 funk(888, 500) called at %s:17]
#1 {closure}(888) called at %s:28]
#2 main() called at %s:33]
object(Closure$%s)#1 (2) {
["use_by_val":"Closure$%s":private]=>