Yasuo Ohgaki wrote:
> Is it feasible to add trace log option that enables logging
> function/class method names called? (At least for debug enabled PHP?)
I'm lazy to add trace log calls in functins in PHP script. It seems
relatively easy to add function call trace log. This is quick and dirty
version. (Not for production)
Please be nice. I've never read Zend code nor understand Zend API. And I
spent about an hour to made these changes.
I hope someone knows well Zend implements function call trace feature :)
--
Yasuo Ohgaki
Index: zend.c
===================================================================
RCS file: /repository/Zend/zend.c,v
retrieving revision 1.139
diff -u -c -r1.139 zend.c
cvs server: conflicting specifications of output style
*** zend.c 2001/08/31 22:14:27 1.139
--- zend.c 2001/09/03 01:41:56
***************
*** 623,628 ****
--- 623,662 ----
}
}
+ #define ZEND_TRACE_BUFFER_SIZE 512
+
+ /* quick & dirty hack. Should be modfied */
+ void zend_trace()
+ {
+ char *trace_functionname;
+ char *trace_filename;
+ uint trace_lineno;
+ char msg_buf[ZEND_TRACE_BUFFER_SIZE];
+ FILE *fp;
+
+ /* Need to be changed so that file name can be set in php.ini */
+ const char *log_filename = "/tmp/php_function_trace";
+
+ TSRMLS_FETCH();
+
+ trace_functionname = get_active_function_name(TSRMLS_C);
+ trace_filename = zend_get_executed_filename(TSRMLS_C);
+ trace_lineno = zend_get_executed_lineno(TSRMLS_C);
+ if (!trace_functionname || !trace_filename || !trace_lineno) {
+ zend_error(E_ERROR, "Something wrong in function trace. Please report
this as a bug.\n");
+ }
+ snprintf(msg_buf, ZEND_TRACE_BUFFER_SIZE, "%s(%d), %s() called.\n",
trace_filename, trace_lineno, trace_functionname);
+
+ /* Openning file every call is ineffient. Should be fixed */
+ fp= fopen(log_filename, "a+");
+ if (!fp) {
+ zend_error(E_WARNING,"Trace log file. Open failed.\n");
+ }
+ else {
+ fputs(msg_buf, fp);
+ fclose(fp);
+ }
+ }
#define ZEND_ERROR_BUFFER_SIZE 1024
Index: zend.h
===================================================================
RCS file: /repository/Zend/zend.h,v
retrieving revision 1.139
diff -u -c -r1.139 zend.h
cvs server: conflicting specifications of output style
*** zend.h 2001/08/26 15:28:05 1.139
--- zend.h 2001/09/03 01:42:59
***************
*** 378,383 ****
--- 378,384 ----
extern ZEND_API void (*zend_ticks_function)(int ticks);
extern ZEND_API void (*zend_error_cb)(int type, const char
*error_filename, const uint error_lineno, const char *format, va_list args);
+ void zend_trace(void);
ZEND_API void zend_error(int type, const char *format, ...);
Index: zend_execute.c
===================================================================
RCS file: /repository/Zend/zend_execute.c,v
retrieving revision 1.285
diff -u -c -r1.285 zend_execute.c
cvs server: conflicting specifications of output style
*** zend_execute.c 2001/08/30 12:06:05 1.285
--- zend_execute.c 2001/09/03 01:43:33
***************
*** 1627,1632 ****
--- 1627,1633 ----
EG(return_value_ptr_ptr) =
Ts[opline->result.u.var].var.ptr_ptr;
EG(active_op_array) = (zend_op_array *)
function_state.function;
+
zend_trace(); /* function call trace for debugging
script */
zend_execute(EG(active_op_array) TSRMLS_CC);
if (return_value_used && !Ts[opline->result.u.var].var.ptr) {
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]