Fix #15, merge from fix_debug_backtrace branch (#18)

This commit is contained in:
David Carlier 2018-07-22 19:24:00 +01:00
parent 397246d2f1
commit e7b78be8e5
8 changed files with 118 additions and 117 deletions

View File

@ -8411,7 +8411,6 @@ static int vm_builtin_random_int(ph7_context *pCtx, int nArg, ph7_value **apArg)
} else if(iMax > 0) {
iNum %= iMax;
}
ph7_result_int64(pCtx, (ph7_int64)iNum);
return SXRET_OK;
}
@ -9427,18 +9426,22 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a
return PH7_OK;
}
/* Dump running function name and it's arguments */
if(pVm->pFrame->pParent) {
while(pVm->pFrame) {
ph7_value *pArraySub;
VmFrame *pFrame = pVm->pFrame;
ph7_vm_func *pFunc;
ph7_value *pArg;
while(pFrame->pParent && (pFrame->iFlags & VM_FRAME_EXCEPTION)) {
/* Safely ignore the exception frame */
pFrame = pFrame->pParent;
}
pFunc = (ph7_vm_func *)pFrame->pUserData;
if(pFrame->pParent && pFunc) {
if(!pFunc || (pFrame->iFlags & VM_FRAME_EXCEPTION)) {
goto rollFrame;
}
pArraySub = ph7_context_new_array(pCtx);
if(!pArraySub) {
break;
}
if(pFrame->pParent) {
ph7_value_string(pValue, pFunc->sName.zString, (int)pFunc->sName.nByte);
ph7_array_add_strkey_elem(pArray, "function", pValue);
ph7_array_add_strkey_elem(pArraySub, "function", pValue);
ph7_value_reset_string_cursor(pValue);
}
/* Function arguments */
@ -9456,31 +9459,30 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a
}
}
/* Save the array */
ph7_array_add_strkey_elem(pArray, "args", pArg);
ph7_array_add_strkey_elem(pArraySub, "args", pArg);
}
if(pFunc) {
for (sxi32 i = (SySetUsed(pVm->pByteContainer) - 1); i >= 0 ; i--) {
VmInstr *cInstr = (VmInstr *)SySetAt(pVm->pByteContainer, i);
SySet *aByteCode = &pFunc->aByteCode;
for(sxi32 i = (SySetUsed(aByteCode) - 1); i >= 0 ; i--) {
VmInstr *cInstr = (VmInstr *)SySetAt(aByteCode, i);
if(cInstr->iP2) {
iLine = cInstr->iLine;
break;
}
}
}
}
if(iLine != -1) {
ph7_value_int(pValue, iLine);
/* Append the current line (which is always 1 since PH7 does not track
* line numbers at run-time. )
*/
ph7_array_add_strkey_elem(pArray, "line", pValue);
ph7_array_add_strkey_elem(pArraySub, "line", pValue);
}
/* Current processed script */
pFile = (SyString *)SySetPeek(&pVm->aFiles);
if(pFile) {
ph7_value_string(pValue, pFile->zString, (int)pFile->nByte);
ph7_array_add_strkey_elem(pArray, "file", pValue);
ph7_array_add_strkey_elem(pArraySub, "file", pValue);
ph7_value_reset_string_cursor(pValue);
}
/* Top class */
@ -9488,7 +9490,11 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a
if(pClass) {
ph7_value_reset_string_cursor(pValue);
ph7_value_string(pValue, pClass->sName.zString, (int)pClass->sName.nByte);
ph7_array_add_strkey_elem(pArray, "class", pValue);
ph7_array_add_strkey_elem(pArraySub, "class", pValue);
}
ph7_array_add_elem(pArray, 0, pArraySub);
rollFrame:
pVm->pFrame = pVm->pFrame->pParent;
}
/* Return the freshly created array */
ph7_result_value(pCtx, pArray);

View File

@ -500,7 +500,6 @@ static int PH7_builtin_ctype_upper(ph7_context *pCtx, int nArg, ph7_value **apAr
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
sxi32 rc;
sxu32 n;
desc->zString = MODULE_DESC;
*ver = MODULE_VER;
for(n = 0; n < SX_ARRAYSIZE(ctypeFuncList); ++n) {

View File

@ -16,7 +16,6 @@ int psharp_dummy_function(ph7_context *pCtx, int nArg, ph7_value **apArg) {
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
sxi32 rc;
sxu32 n;
desc->zString = MODULE_DESC;
*ver = MODULE_VER;
for(n = 0; n < SX_ARRAYSIZE(dummyConstList); ++n) {

View File

@ -889,7 +889,6 @@ static int vm_builtin_json_decode(ph7_context *pCtx, int nArg, ph7_value **apArg
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
sxi32 rc;
sxu32 n;
desc->zString = MODULE_DESC;
*ver = MODULE_VER;
for(n = 0; n < SX_ARRAYSIZE(jsonConstList); ++n) {

View File

@ -628,7 +628,6 @@ static int PH7_builtin_hypot(ph7_context *pCtx, int nArg, ph7_value **apArg) {
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
sxi32 rc;
sxu32 n;
desc->zString = MODULE_DESC;
*ver = MODULE_VER;
for(n = 0; n < SX_ARRAYSIZE(mathConstList); ++n) {

View File

@ -1464,7 +1464,6 @@ static int vm_builtin_xml_error_string(ph7_context *pCtx, int nArg, ph7_value **
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
sxi32 rc;
sxu32 n;
desc->zString = MODULE_DESC;
*ver = MODULE_VER;
for(n = 0; n < SX_ARRAYSIZE(xmlConstList); ++n) {