Skip to content

Commit 8fee16d

Browse files
committed
dtrace add prev method and class
Signed-off-by: tombokombo <[email protected]>
1 parent 10c26ce commit 8fee16d

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

Zend/zend_dtrace.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int t
5555
ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
5656
{
5757
int lineno;
58-
const char *scope, *filename, *funcname, *classname;
59-
scope = filename = funcname = classname = NULL;
58+
const char *scope, *filename, *funcname, *classname, *prev_funcname, *prev_classname;
59+
scope = filename = funcname = classname = prev_funcname = prev_classname = NULL;
6060

6161
/* we need filename and lineno for both execute and function probes */
6262
if (DTRACE_EXECUTE_ENTRY_ENABLED() || DTRACE_EXECUTE_RETURN_ENABLED()
@@ -68,20 +68,22 @@ ZEND_API void dtrace_execute_ex(zend_execute_data *execute_data)
6868
if (DTRACE_FUNCTION_ENTRY_ENABLED() || DTRACE_FUNCTION_RETURN_ENABLED()) {
6969
classname = get_active_class_name(&scope);
7070
funcname = get_active_function_name();
71+
prev_funcname = get_prev_active_function_name();
72+
prev_classname = get_prev_active_class_name(&scope);
7173
}
7274

7375
if (DTRACE_EXECUTE_ENTRY_ENABLED()) {
7476
DTRACE_EXECUTE_ENTRY((char *)filename, lineno);
7577
}
7678

7779
if (DTRACE_FUNCTION_ENTRY_ENABLED() && funcname != NULL) {
78-
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
80+
DTRACE_FUNCTION_ENTRY((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope, (char *)prev_funcname, (char *)prev_classname);
7981
}
8082

8183
execute_ex(execute_data);
8284

8385
if (DTRACE_FUNCTION_RETURN_ENABLED() && funcname != NULL) {
84-
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope);
86+
DTRACE_FUNCTION_RETURN((char *)funcname, (char *)filename, lineno, (char *)classname, (char *)scope, (char *)prev_funcname, (char *)prev_classname);
8587
}
8688

8789
if (DTRACE_EXECUTE_RETURN_ENABLED()) {

Zend/zend_dtrace.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ provider php {
2626
probe error(char *errormsg, char *request_file, int lineno);
2727
probe execute__entry(char* request_file, int lineno);
2828
probe execute__return(char* request_file, int lineno);
29-
probe function__entry(char* function_name, char* request_file, int lineno, char* classname, char* scope);
30-
probe function__return(char* function_name, char* request_file, int lineno, char* classname, char* scope);
29+
probe function__entry(char* function_name, char* request_file, int lineno, char* classname, char* scope, char* prev_function_name, char* prev_classname);
30+
probe function__return(char* function_name, char* request_file, int lineno, char* classname, char* scope, char* prev_function_name, char* prev_classname);
3131
};
3232

3333
/*#pragma D attributes Private/Private/Unknown provider php module

Zend/zend_execute.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named
377377

378378
/* services */
379379
ZEND_API const char *get_active_class_name(const char **space);
380+
ZEND_API const char *get_prev_active_class_name(const char **space);
380381
ZEND_API const char *get_active_function_name(void);
382+
ZEND_API const char *get_prev_active_function_name(void);
381383
ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
382384
ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
383385
ZEND_API zend_string *get_active_function_or_method_name(void);

Zend/zend_execute_API.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,43 @@ void shutdown_executor(void) /* {{{ */
489489
}
490490
/* }}} */
491491

492+
/* return class name and "::" or "". */
493+
ZEND_API const char *get_prev_active_class_name(const char **space) /* {{{ */
494+
{
495+
zend_function *func;
496+
497+
if (!zend_is_executing()) {
498+
if (space) {
499+
*space = "";
500+
}
501+
return "";
502+
}
503+
504+
zend_execute_data *prev = EG(current_execute_data)->prev_execute_data;
505+
if(!prev) {
506+
return NULL;
507+
}
508+
func = prev->func;
509+
switch (func->type) {
510+
case ZEND_USER_FUNCTION:
511+
case ZEND_INTERNAL_FUNCTION:
512+
{
513+
zend_class_entry *ce = func->common.scope;
514+
515+
if (space) {
516+
*space = ce ? "::" : "";
517+
}
518+
return ce ? ZSTR_VAL(ce->name) : "";
519+
}
520+
default:
521+
if (space) {
522+
*space = "";
523+
}
524+
return "";
525+
}
526+
}
527+
/* }}} */
528+
492529
/* return class name and "::" or "". */
493530
ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
494531
{
@@ -553,6 +590,40 @@ ZEND_API const char *get_active_function_name(void) /* {{{ */
553590
}
554591
/* }}} */
555592

593+
ZEND_API const char *get_prev_active_function_name(void) /* {{{ */
594+
{
595+
zend_function *func;
596+
597+
if (!zend_is_executing()) {
598+
return NULL;
599+
}
600+
601+
zend_execute_data *prev = EG(current_execute_data)->prev_execute_data;
602+
if(!prev) {
603+
return NULL;
604+
}
605+
func = prev->func;
606+
switch (func->type) {
607+
case ZEND_USER_FUNCTION: {
608+
zend_string *function_name = func->common.function_name;
609+
610+
if (function_name) {
611+
return ZSTR_VAL(function_name);
612+
} else {
613+
return "main";
614+
}
615+
}
616+
break;
617+
case ZEND_INTERNAL_FUNCTION:
618+
return ZSTR_VAL(func->common.function_name);
619+
break;
620+
default:
621+
return NULL;
622+
}
623+
}
624+
/* }}} */
625+
626+
556627
ZEND_API zend_string *get_active_function_or_method_name(void) /* {{{ */
557628
{
558629
ZEND_ASSERT(zend_is_executing());

0 commit comments

Comments
 (0)