php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_vm_trace_map.h
Go to the documentation of this file.
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 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Dmitry Stogov <dmitry@php.net> |
16 +----------------------------------------------------------------------+
17*/
18
19#include "zend_vm_handlers.h"
20#include "zend_sort.h"
21
22#define GEN_MAP(n, name) do { \
23 ZVAL_LONG(&tmp, (zend_long)(uintptr_t)zend_opcode_handlers[n]); \
24 zend_hash_str_add(&vm_trace_ht, #name, sizeof(#name) - 1, &tmp); \
25 } while (0);
26
27#define VM_TRACE_START() do { \
28 zval tmp; \
29 zend_hash_init(&vm_trace_ht, 0, NULL, NULL, 1); \
30 VM_HANDLERS(GEN_MAP) \
31 zend_vm_trace_init(); \
32 } while (0)
33
34#ifdef _WIN64
35# define ADDR_FMT "%016I64x"
36#elif SIZEOF_SIZE_T == 4
37# define ADDR_FMT "%08zx"
38#elif SIZEOF_SIZE_T == 8
39# define ADDR_FMT "%016zx"
40#else
41# error "Unknown SIZEOF_SIZE_T"
42#endif
43
44static HashTable vm_trace_ht;
45
46static int zend_vm_trace_compare(const Bucket *p1, const Bucket *p2)
47{
48 if (Z_LVAL(p1->val) > Z_LVAL(p2->val)) {
49 return 1;
50 } else if (Z_LVAL(p1->val) < Z_LVAL(p2->val)) {
51 return -1;
52 } else {
53 return 0;
54 }
55}
56
57static void zend_vm_trace_init(void)
58{
59 FILE *f;
60 zend_string *key, *prev_key;
61 zval *val;
62 zend_long prev_addr;
63
64 f = fopen("zend_vm.map", "w+");
65 if (f) {
66 zend_hash_sort(&vm_trace_ht, (bucket_compare_func_t)zend_vm_trace_compare, 0);
67 prev_key = NULL;
69 if (prev_key) {
70 fprintf(f, ADDR_FMT" "ADDR_FMT" t %s\n", prev_addr, Z_LVAL_P(val) - prev_addr, ZSTR_VAL(prev_key));
71 }
72 prev_key = key;
73 prev_addr = Z_LVAL_P(val);
75 if (prev_key) {
76 fprintf(f, ADDR_FMT" "ADDR_FMT" t %s\n", prev_addr, 0, ZSTR_VAL(prev_key));
77 }
78 fclose(f);
79 }
80 zend_hash_destroy(&vm_trace_ht);
81}
fprintf($stream, string $format, mixed ... $values)
fclose($stream)
fopen(string $filename, string $mode, bool $use_include_path=false, $context=null)
zval * val
Definition ffi.c:4262
#define NULL
Definition gdcache.h:45
unsigned char key[REFLECTION_KEY_LEN]
zval val
Definition zend_types.h:381
struct _zval_struct zval
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
int(* bucket_compare_func_t)(Bucket *a, Bucket *b)
Definition zend_hash.h:299
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, _key, _val)
Definition zend_hash.h:1374
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
struct _zend_array HashTable
Definition zend_types.h:386
struct _Bucket Bucket
#define Z_LVAL_P(zval_p)
Definition zend_types.h:966
#define Z_LVAL(zval)
Definition zend_types.h:965