Skip to content

dtrace add prev method and prev class #10580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Zend/zend_dtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int t
ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
{
int lineno;
const char *scope, *filename, *funcname, *classname;
scope = filename = funcname = classname = NULL;
const char *scope, *filename, *funcname, *classname, *prev_funcname, *prev_classname;
scope = filename = funcname = classname = prev_funcname = prev_classname = NULL;

/* we need filename and lineno for both execute and function probes */
if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()
Expand All @@ -68,20 +68,22 @@ ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
classname = get_active_class_name(&scope);
funcname = get_active_function_name();
prev_funcname = get_prev_active_function_name();
prev_classname = get_prev_active_class_name(NULL);
}

if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
}

if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope, (char *)prev_funcname, (char *)prev_classname);
}

execute_ex(execute_data);

if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope, (char *)prev_funcname, (char *)prev_classname);
}

if (DTRACE_EXECUTE_RETURN_ENABLED()) {
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_dtrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ provider php {
probe error(char *errormsg, char *request_file, int lineno);
probe execute__entry(char* request_file, int lineno);
probe execute__return(char* request_file, int lineno);
probe function__entry(char* function_name, char* request_file, int lineno, char* classname, char* scope);
probe function__return(char* function_name, char* request_file, int lineno, char* classname, char* scope);
probe function__entry(char* function_name, char* request_file, int lineno, char* classname, char* scope, char* prev_function_name, char* prev_classname);
probe function__return(char* function_name, char* request_file, int lineno, char* classname, char* scope, char* prev_function_name, char* prev_classname);
};

/*#pragma D attributes Private/Private/Unknown provider php module
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named

/* services */
ZEND_API const char *get_active_class_name(const char **space);
ZEND_API const char *get_prev_active_class_name(const char **space);
ZEND_API const char *get_active_function_name(void);
ZEND_API const char *get_prev_active_function_name(void);
Comment on lines +380 to +382
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't like to add these new function to public API.
I won't object of you move their implementation into zend_dtrace.c.

ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
ZEND_API zend_string *get_active_function_or_method_name(void);
Expand Down
71 changes: 71 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,43 @@ void shutdown_executor(void) /* {{{ */
}
/* }}} */

/* return class name and "::" or "". */
ZEND_API const char *get_prev_active_class_name(const char **space) /* {{{ */
{
zend_function *func;

if (!zend_is_executing()) {
if (space) {
*space = "";
}
return "";
}

zend_execute_data *prev = EG(current_execute_data)->prev_execute_data;
if(!prev) {
return NULL;
}
func = prev->func;
switch (func->type) {
case ZEND_USER_FUNCTION:
case ZEND_INTERNAL_FUNCTION:
{
zend_class_entry *ce = func->common.scope;

if (space) {
*space = ce ? "::" : "";
}
return ce ? ZSTR_VAL(ce->name) : "";
}
default:
if (space) {
*space = "";
}
return "";
}
}
/* }}} */

/* return class name and "::" or "". */
ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
{
Expand Down Expand Up @@ -553,6 +590,40 @@ ZEND_API const char *get_active_function_name(void) /* {{{ */
}
/* }}} */

ZEND_API const char *get_prev_active_function_name(void) /* {{{ */
{
zend_function *func;

if (!zend_is_executing()) {
return NULL;
}

zend_execute_data *prev = EG(current_execute_data)->prev_execute_data;
if(!prev) {
return NULL;
}
func = prev->func;
switch (func->type) {
case ZEND_USER_FUNCTION: {
zend_string *function_name = func->common.function_name;

if (function_name) {
return ZSTR_VAL(function_name);
} else {
return "main";
}
}
break;
case ZEND_INTERNAL_FUNCTION:
return ZSTR_VAL(func->common.function_name);
break;
default:
return NULL;
}
}
/* }}} */


ZEND_API zend_string *get_active_function_or_method_name(void) /* {{{ */
{
ZEND_ASSERT(zend_is_executing());
Expand Down