Implement jerry_get_backtrace_from API function (#4454)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-01-12 19:52:05 +01:00
committed by GitHub
parent c46f4c3e40
commit 3193e6d0dc
7 changed files with 313 additions and 6 deletions
+44 -1
View File
@@ -4523,9 +4523,52 @@ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, /**< per
jerry_value_t
jerry_get_backtrace (uint32_t max_depth) /**< depth limit of the backtrace */
{
return vm_get_backtrace (max_depth);
return vm_get_backtrace (max_depth, NULL);
} /* jerry_get_backtrace */
/**
* Get backtrace. The backtrace is an array of strings where
* each string contains the position of the corresponding frame.
* The array length is zero if the backtrace is not available.
*
* @return array value
*/
jerry_value_t
jerry_get_backtrace_from (uint32_t max_depth, /**< depth limit of the backtrace */
jerry_value_t ignored_function) /**< collect backtrace after this function */
{
ecma_object_t *ignored_function_p = NULL;
if (ecma_is_value_object (ignored_function))
{
ignored_function_p = ecma_get_object_from_value (ignored_function);
while (true)
{
ecma_object_type_t type = ecma_get_object_type (ignored_function_p);
if (type == ECMA_OBJECT_TYPE_FUNCTION || type == ECMA_OBJECT_TYPE_NATIVE_FUNCTION)
{
break;
}
if (type == ECMA_OBJECT_TYPE_BOUND_FUNCTION)
{
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) ignored_function_p;
jmem_cpointer_tag_t target_function = bound_func_p->header.u.bound_function.target_function;
ignored_function_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t, target_function);
continue;
}
ignored_function_p = NULL;
break;
}
}
return vm_get_backtrace (max_depth, ignored_function_p);
} /* jerry_get_backtrace_from */
/**
* Get the resource name (usually a file name) of the currently executed script or the given function object
*
+1 -1
View File
@@ -152,7 +152,7 @@ ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error typ
NULL);
ecma_deref_ecma_string (stack_str_p);
ecma_value_t backtrace_value = vm_get_backtrace (0);
ecma_value_t backtrace_value = vm_get_backtrace (0, NULL);
prop_value_p->value = backtrace_value;
ecma_deref_object (ecma_get_object_from_value (backtrace_value));
+1
View File
@@ -750,6 +750,7 @@ jerry_context_t *jerry_create_context (uint32_t heap_size, jerry_context_alloc_t
*/
void jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, void *user_p, uint32_t frequency);
jerry_value_t jerry_get_backtrace (uint32_t max_depth);
jerry_value_t jerry_get_backtrace_from (uint32_t max_depth, jerry_value_t ignored_function);
jerry_value_t jerry_get_resource_name (const jerry_value_t value);
jerry_value_t jerry_get_new_target (void);
+33 -2
View File
@@ -59,15 +59,45 @@ vm_is_direct_eval_form_call (void)
* @return array ecma value
*/
ecma_value_t
vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimited */
vm_get_backtrace (uint32_t max_depth, /**< maximum backtrace depth, 0 = unlimited */
ecma_object_t *ignored_function_p) /**< ignore functions up to this function */
{
#if ENABLED (JERRY_LINE_INFO)
vm_frame_ctx_t *context_p = JERRY_CONTEXT (vm_top_context_p);
if (ignored_function_p != NULL)
{
JERRY_ASSERT (ecma_get_object_type (ignored_function_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (ignored_function_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
while (true)
{
if (context_p == NULL)
{
context_p = JERRY_CONTEXT (vm_top_context_p);
break;
}
if (context_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_ARG_LIST)
{
vm_frame_ctx_shared_args_t *shared_args_p = (vm_frame_ctx_shared_args_t *) context_p->shared_p;
if (shared_args_p->function_object_p == ignored_function_p)
{
context_p = context_p->prev_context_p;
break;
}
}
context_p = context_p->prev_context_p;
}
}
if (max_depth == 0)
{
max_depth = UINT32_MAX;
}
vm_frame_ctx_t *context_p = JERRY_CONTEXT (vm_top_context_p);
ecma_object_t *array_p = ecma_op_new_array_object (0);
JERRY_ASSERT (ecma_op_object_is_fast_array (array_p));
uint32_t index = 0;
@@ -108,6 +138,7 @@ vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimite
return ecma_make_object_value (array_p);
#else /* !ENABLED (JERRY_LINE_INFO) */
JERRY_UNUSED (max_depth);
JERRY_UNUSED (ignored_function_p);
return ecma_make_object_value (ecma_op_new_array_object (0));
#endif /* ENABLED (JERRY_LINE_INFO) */
+1 -1
View File
@@ -490,7 +490,7 @@ ecma_value_t vm_execute (vm_frame_ctx_t *frame_ctx_p);
bool vm_is_strict_mode (void);
bool vm_is_direct_eval_form_call (void);
ecma_value_t vm_get_backtrace (uint32_t max_depth);
ecma_value_t vm_get_backtrace (uint32_t max_depth, ecma_object_t *ignored_function_p);
/**
* @}