Skip to content

Commit 5c23809

Browse files
committed
troubleshooting
1 parent 73c3600 commit 5c23809

File tree

1 file changed

+54
-35
lines changed

1 file changed

+54
-35
lines changed

agent/php_internal_instrument.c

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ static void nr_php_instrument_delegate(nrinternalfn_t* wraprec,
151151
int nr_zend_call_old_handler(nrphpfn_t oldhandler,
152152
INTERNAL_FUNCTION_PARAMETERS) {
153153
volatile int zcaught = 0;
154-
zend_try { oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU); }
155-
zend_catch { zcaught = 1; }
154+
zend_try {
155+
oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
156+
}
157+
zend_catch {
158+
zcaught = 1;
159+
}
156160
zend_end_try();
157161
return zcaught;
158162
}
@@ -333,7 +337,8 @@ static void record_mysql_error(TSRMLS_D) {
333337

334338
errdup = nr_strndup(errormsgstr, errormsglen);
335339
stack_json = nr_php_backtrace_to_json(0 TSRMLS_CC);
336-
nr_txn_record_error(NRPRG(txn), errprio, true, errdup, "MysqlError", stack_json);
340+
nr_txn_record_error(NRPRG(txn), errprio, true, errdup, "MysqlError",
341+
stack_json);
337342
nr_free(errdup);
338343
nr_free(stack_json);
339344

@@ -647,17 +652,18 @@ NR_INNER_WRAPPER(mysqli_construct) {
647652

648653
#if ZEND_MODULE_API_NO >= ZEND_8_1_X_API_NO
649654
bool port_is_null = 1;
650-
const char *type_spec = "|s!s!s!s!l!s!";
655+
const char* type_spec = "|s!s!s!s!l!s!";
651656
if (FAILURE
652657
== zend_parse_parameters_ex(
653658
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, type_spec, &host,
654659
&host_len, &username, &username_len, &password, &password_len,
655-
&database, &database_len, &port, &port_is_null, &socket, &socket_len)) {
660+
&database, &database_len, &port, &port_is_null, &socket,
661+
&socket_len)) {
656662
nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
657663
return;
658664
}
659665
#else
660-
const char *type_spec = "|ssssls";
666+
const char* type_spec = "|ssssls";
661667
if (FAILURE
662668
== zend_parse_parameters_ex(
663669
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, type_spec, &host,
@@ -811,11 +817,11 @@ NR_INNER_WRAPPER(mysqli_commit) {
811817
nr_string_len_t name_len = 0;
812818

813819
#if ZEND_MODULE_API_NO >= ZEND_8_1_X_API_NO
814-
const char *proc_type_spec = "o|ls!";
815-
const char *oo_type_spec = "|ls!";
820+
const char* proc_type_spec = "o|ls!";
821+
const char* oo_type_spec = "|ls!";
816822
#else
817-
const char *proc_type_spec = "o|ls";
818-
const char *oo_type_spec = "|ls";
823+
const char* proc_type_spec = "o|ls";
824+
const char* oo_type_spec = "|ls";
819825
#endif
820826

821827
if (FAILURE
@@ -824,8 +830,8 @@ NR_INNER_WRAPPER(mysqli_commit) {
824830
&mysqli_obj, &flags, &name, &name_len)) {
825831
if (FAILURE
826832
== zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
827-
ZEND_NUM_ARGS() TSRMLS_CC, oo_type_spec, &flags,
828-
&name, &name_len)) {
833+
ZEND_NUM_ARGS() TSRMLS_CC, oo_type_spec,
834+
&flags, &name, &name_len)) {
829835
nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
830836
return;
831837
} else {
@@ -883,29 +889,29 @@ NR_INNER_WRAPPER(mysqli_real_connect) {
883889
*/
884890
#if ZEND_MODULE_API_NO >= ZEND_8_1_X_API_NO
885891
bool port_is_null = 1;
886-
const char *proc_type_spec = "o|s!s!s!s!l!s!l";
887-
const char *oo_type_spec = "|s!s!s!s!l!s!l";
892+
const char* proc_type_spec = "o|s!s!s!s!l!s!l";
893+
const char* oo_type_spec = "|s!s!s!s!l!s!l";
888894
if (FAILURE
889895
== zend_parse_parameters_ex(
890896
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, proc_type_spec,
891897
&mysqli_obj, &host, &host_len, &username, &username_len, &password,
892-
&password_len, &database, &database_len, &port, &port_is_null, &socket, &socket_len,
893-
&flags)) {
898+
&password_len, &database, &database_len, &port, &port_is_null,
899+
&socket, &socket_len, &flags)) {
894900
if (FAILURE
895901
== zend_parse_parameters_ex(
896902
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, oo_type_spec,
897903
&host, &host_len, &username, &username_len, &password,
898-
&password_len, &database, &database_len, &port, &port_is_null, &socket,
899-
&socket_len, &flags)) {
904+
&password_len, &database, &database_len, &port, &port_is_null,
905+
&socket, &socket_len, &flags)) {
900906
nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
901907
return;
902908
} else {
903909
mysqli_obj = NR_PHP_INTERNAL_FN_THIS();
904910
}
905911
}
906912
#else
907-
const char *proc_type_spec = "o|sssslsl";
908-
const char *oo_type_spec = "|sssslsl";
913+
const char* proc_type_spec = "o|sssslsl";
914+
const char* oo_type_spec = "|sssslsl";
909915
if (FAILURE
910916
== zend_parse_parameters_ex(
911917
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, proc_type_spec,
@@ -1411,14 +1417,14 @@ NR_INNER_WRAPPER(mysqli_stmt_construct) {
14111417
nr_string_len_t sqlstrlen = 0;
14121418

14131419
#if ZEND_MODULE_API_NO >= ZEND_8_1_X_API_NO
1414-
const char *type_spec = "o|s!";
1420+
const char* type_spec = "o|s!";
14151421
#else
1416-
const char *type_spec = "o|s";
1422+
const char* type_spec = "o|s";
14171423
#endif
14181424
if (FAILURE
14191425
== zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
1420-
ZEND_NUM_ARGS() TSRMLS_CC, type_spec, &mysqli_obj,
1421-
&sqlstr, &sqlstrlen)) {
1426+
ZEND_NUM_ARGS() TSRMLS_CC, type_spec,
1427+
&mysqli_obj, &sqlstr, &sqlstrlen)) {
14221428
nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
14231429
return;
14241430
}
@@ -1541,10 +1547,9 @@ NR_INNER_WRAPPER(memcached_add_server) {
15411547
int zcaught = 0;
15421548

15431549
if (SUCCESS
1544-
== zend_parse_parameters_ex(
1545-
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|ll", &host,
1546-
&host_len, &port, &weight) &&
1547-
NULL != host) {
1550+
== zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(),
1551+
"s|ll", &host, &host_len, &port, &weight)
1552+
&& NULL != host) {
15481553
nr_php_memcached_create_instance_metric(host, port);
15491554
}
15501555
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
@@ -1561,15 +1566,16 @@ NR_INNER_WRAPPER(memcached_add_servers) {
15611566
int zcaught = 0;
15621567

15631568
if (SUCCESS
1564-
== zend_parse_parameters_ex(
1565-
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &servers)) {
1569+
== zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a",
1570+
&servers)) {
15661571
if (NULL != servers && Z_TYPE_P(servers) == IS_ARRAY) {
15671572
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(servers), server) {
15681573
zval* host = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 0);
15691574
zval* port = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 1);
1570-
if (nr_php_is_zval_valid_string(host) &&
1571-
nr_php_is_zval_valid_integer(port)) {
1572-
nr_php_memcached_create_instance_metric(Z_STRVAL_P(host), Z_LVAL_P(port));
1575+
if (nr_php_is_zval_valid_string(host)
1576+
&& nr_php_is_zval_valid_integer(port)) {
1577+
nr_php_memcached_create_instance_metric(Z_STRVAL_P(host),
1578+
Z_LVAL_P(port));
15731579
}
15741580
}
15751581
ZEND_HASH_FOREACH_END();
@@ -3020,19 +3026,26 @@ static inline int nr_php_should_instrument_exception_handler(
30203026
*/
30213027
NR_INNER_WRAPPER(exception_common) {
30223028
zval* exception_handler = NULL;
3029+
nrl_warning(NRL_ERROR,
3030+
"exception_common: attempting to restore NR exception handler");
30233031

30243032
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
30253033
exception_handler = &EG(user_exception_handler);
30263034
#else
30273035
exception_handler = EG(user_exception_handler);
30283036
#endif
3037+
nrl_warning(NRL_ERROR, "exception_common: old handler: %s",
3038+
Z_STRVAL_P(exception_handler));
30293039

30303040
/*
30313041
* Remove instrumentation from the current exception handler, if any.
30323042
*/
30333043
if (nr_php_should_instrument_exception_handler(exception_handler TSRMLS_CC)) {
30343044
zend_function* func;
30353045

3046+
nrl_warning(NRL_ERROR,
3047+
"exception_common: should instrument exception handler");
3048+
30363049
func = nr_php_zval_to_function(exception_handler TSRMLS_CC);
30373050
nr_php_remove_exception_function(func TSRMLS_CC);
30383051
}
@@ -3048,12 +3061,17 @@ NR_INNER_WRAPPER(exception_common) {
30483061
#else
30493062
exception_handler = EG(user_exception_handler);
30503063
#endif
3064+
nrl_warning(NRL_ERROR, "exception_common: new handler?: %s",
3065+
Z_STRVAL_P(exception_handler));
30513066

30523067
/*
30533068
* Add instrumentation to the new exception handler, if any.
30543069
*/
30553070
if (nr_php_should_instrument_exception_handler(exception_handler TSRMLS_CC)) {
30563071
zend_function* func;
3072+
nrl_warning(
3073+
NRL_ERROR,
3074+
"exception_common: should instrument exception handler(again?)");
30573075

30583076
func = nr_php_zval_to_function(exception_handler TSRMLS_CC);
30593077
nr_php_add_exception_function(func TSRMLS_CC);
@@ -3062,6 +3080,7 @@ NR_INNER_WRAPPER(exception_common) {
30623080
#else
30633081
} else if (NULL == exception_handler) {
30643082
#endif /* PHP7+ */
3083+
nrl_warning(NRL_ERROR, "exception_common: installing nr exception handler");
30653084
nr_php_error_install_exception_handler(TSRMLS_C);
30663085
}
30673086
}
@@ -3758,7 +3777,7 @@ void nr_php_generate_internal_wrap_records(void) {
37583777
NR_INTERNAL_WRAPREC("redis::xclaim", redis_xclaim, redis_function, 0,
37593778
"xclaim")
37603779
NR_INTERNAL_WRAPREC("redis::xdel", redis_xdel, redis_function, 0, "xdel")
3761-
NR_INTERNAL_WRAPREC("redis::xgroup", redis_xgroup, redis_function, 0,
3780+
NR_INTERNAL_WRAPREC("redis::xgroup", redis_xgroup, redis_function, 0,
37623781
"xgroup")
37633782
NR_INTERNAL_WRAPREC("redis::xinfo", redis_xinfo, redis_function, 0, "xinfo")
37643783
NR_INTERNAL_WRAPREC("redis::xlen", redis_xlen, redis_function, 0, "xlen")
@@ -3808,7 +3827,7 @@ void nr_php_generate_internal_wrap_records(void) {
38083827
redis_function, 0, "zrevrangebyscore")
38093828
NR_INTERNAL_WRAPREC("redis::zrevrank", redis_zrevrank, redis_function, 0,
38103829
"zrevrank")
3811-
NR_INTERNAL_WRAPREC("redis::zscore", redis_zscore, redis_function, 0,
3830+
NR_INTERNAL_WRAPREC("redis::zscore", redis_zscore, redis_function, 0,
38123831
"zscore")
38133832
NR_INTERNAL_WRAPREC("redis::zunionstore", redis_zunionstore, redis_function,
38143833
0, "zunionstore")

0 commit comments

Comments
 (0)