Skip to content

Commit a60cdcf

Browse files
committed
A helper to trace executed source lines
1 parent e9f295a commit a60cdcf

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Zend/zend_execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,8 @@ static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame(uint
43114311

43124312
#ifdef ZEND_VM_TRACE_HANDLERS
43134313
# include "zend_vm_trace_handlers.h"
4314+
#elif defined(ZEND_VM_TRACE_LINES)
4315+
# include "zend_vm_trace_lines.h"
43144316
#elif defined(ZEND_VM_TRACE_MAP)
43154317
# include "zend_vm_trace_map.h"
43164318
#endif

Zend/zend_vm_trace_lines.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Zend Engine |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.00 of the Zend license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.zend.com/license/2_00.txt. |
11+
| If you did not receive a copy of the Zend license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Authors: Dmitry Stogov <[email protected]> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
#include "zend_sort.h"
20+
21+
#define VM_TRACE(op) zend_vm_trace(execute_data, opline);
22+
#define VM_TRACE_START() zend_vm_trace_init();
23+
#define VM_TRACE_END() zend_vm_trace_finish();
24+
25+
static FILE *vm_trace_file;
26+
27+
static void zend_vm_trace(const zend_execute_data *execute_data, const zend_op *opline)
28+
{
29+
if (EX(func) && EX(func)->op_array.filename) {
30+
fprintf(vm_trace_file, "%s:%d\n", ZSTR_VAL(EX(func)->op_array.filename), opline->lineno);
31+
}
32+
}
33+
34+
static void zend_vm_trace_finish(void)
35+
{
36+
fclose(vm_trace_file);
37+
}
38+
39+
static void zend_vm_trace_init(void)
40+
{
41+
vm_trace_file = fopen("zend_vm_trace.log", "w+");
42+
}

0 commit comments

Comments
 (0)