Skip to content

Commit 0820332

Browse files
committed
Add a TRACE() function, for easier debugging of travis builds.
1 parent 62d6a78 commit 0820332

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/macros.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#ifndef NODE_PHP_EMBED_SRC_MACROS_H
22
#define NODE_PHP_EMBED_SRC_MACROS_H
33

4+
// Poor man's trace mechanism; helpful for tracking down crashes on obscure
5+
// architectures using travis.
6+
#ifdef NODE_PHP_EMBED_DEBUG
7+
# define TRACEX(msg, ...) fprintf(stderr, msg " %s\n", __VA_ARGS__, __func__)
8+
#else
9+
# define TRACEX(msg, ...)
10+
#endif
11+
#define TRACE(msg) TRACEX(msg "%s", "") /* hack to eat up required argument */
12+
413
#define NEW_STR(str) \
514
Nan::New<v8::String>(str).ToLocalChecked()
615

src/node_php_embed.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class node_php_embed::PhpRequestWorker : public AsyncMessageWorker {
5656
// V8 data structures here, so everything we need for input and output
5757
// should go on `this`.
5858
void Execute(MessageChannel &messageChannel) {
59+
TRACE("> PhpRequestWorker");
5960
TSRMLS_FETCH();
6061
if (php_request_startup(TSRMLS_C) == FAILURE) {
6162
Nan::ThrowError("can't create request");
@@ -89,6 +90,7 @@ class node_php_embed::PhpRequestWorker : public AsyncMessageWorker {
8990
// freeing the PHP size.
9091
ClearAllPhpIds();
9192
php_request_shutdown(NULL);
93+
TRACE("< PhpRequestWorker");
9294
}
9395
// Executed when the async work is complete.
9496
// This function will be run inside the main event loop
@@ -111,6 +113,7 @@ class node_php_embed::PhpRequestWorker : public AsyncMessageWorker {
111113
/* PHP extension metadata */
112114

113115
static int node_php_embed_ub_write(const char *str, unsigned int str_length TSRMLS_DC) {
116+
TRACE(">");
114117
// Fetch the ExecutionStream object for this thread.
115118
AsyncMessageWorker::MessageChannel *messageChannel = NODE_PHP_EMBED_G(messageChannel);
116119
PhpRequestWorker *worker = (PhpRequestWorker *)
@@ -124,6 +127,7 @@ static int node_php_embed_ub_write(const char *str, unsigned int str_length TSRM
124127
buf.SetString(str, str_length, 1);
125128
call_user_function(EG(function_table), stream.PtrPtr(), &method,
126129
retval.Ptr(), 1, buf.PtrPtr() TSRMLS_CC);
130+
TRACE("<");
127131
return str_length;
128132
}
129133

@@ -135,6 +139,7 @@ static void node_php_embed_flush(void *server_context) {
135139

136140
static void node_php_embed_register_server_variables(zval *track_vars_array TSRMLS_DC)
137141
{
142+
TRACE(">");
138143
// Fetch the ExecutionStream object for this thread.
139144
AsyncMessageWorker::MessageChannel *messageChannel = NODE_PHP_EMBED_G(messageChannel);
140145
PhpRequestWorker *worker = (PhpRequestWorker *)
@@ -149,17 +154,21 @@ static void node_php_embed_register_server_variables(zval *track_vars_array TSRM
149154
char contextName[] = { "CONTEXT" };
150155
php_register_variable_ex(contextName, context.Transfer(TSRMLS_C), track_vars_array TSRMLS_CC);
151156
// XXX call a JS function passing in $_SERVER to allow init?
157+
TRACE("<");
152158
}
153159

154160
NAN_METHOD(setIniPath) {
161+
TRACE(">");
155162
REQUIRE_ARGUMENT_STRING(0, iniPath);
156163
if (php_embed_module.php_ini_path_override) {
157164
delete[] php_embed_module.php_ini_path_override;
158165
}
159166
php_embed_module.php_ini_path_override = strdup(*iniPath);
167+
TRACE("<");
160168
}
161169

162170
NAN_METHOD(request) {
171+
TRACE(">");
163172
REQUIRE_ARGUMENTS(4);
164173
REQUIRE_ARGUMENT_STRING(0, source);
165174
if (!*source) {
@@ -177,6 +186,7 @@ NAN_METHOD(request) {
177186

178187
node_php_embed_ensure_init();
179188
Nan::AsyncQueueWorker(new PhpRequestWorker(callback, stream, context, *source));
189+
TRACE("<");
180190
}
181191

182192
/** PHP module housekeeping */
@@ -196,7 +206,9 @@ static void node_php_embed_globals_dtor(zend_node_php_embed_globals *node_php_em
196206
}
197207

198208
PHP_MINIT_FUNCTION(node_php_embed) {
209+
TRACE("> PHP_MINIT_FUNCTION");
199210
PHP_MINIT(node_php_jsobject_class)(INIT_FUNC_ARGS_PASSTHRU);
211+
TRACE("< PHP_MINIT_FUNCTION");
200212
return SUCCESS;
201213
}
202214

@@ -228,6 +240,7 @@ static void node_php_embed_ensure_init(void) {
228240
if (node_php_embed_inited) {
229241
return;
230242
}
243+
TRACE(">");
231244
node_php_embed_inited = true;
232245
char *argv[] = { NULL };
233246
int argc = 0;
@@ -236,9 +249,11 @@ static void node_php_embed_ensure_init(void) {
236249
php_request_shutdown(NULL);
237250
zend_startup_module(&node_php_embed_module_entry);
238251
node::AtExit(ModuleShutdown, NULL);
252+
TRACE("<");
239253
}
240254

241255
NAN_MODULE_INIT(ModuleInit) {
256+
TRACE(">");
242257
php_embed_module.php_ini_path_override = NULL;
243258
php_embed_module.php_ini_ignore = true;
244259
php_embed_module.php_ini_ignore_cwd = true;
@@ -251,15 +266,18 @@ NAN_MODULE_INIT(ModuleInit) {
251266
// Export functions
252267
NAN_EXPORT(target, setIniPath);
253268
NAN_EXPORT(target, request);
269+
TRACE("<");
254270
}
255271

256272
void ModuleShutdown(void *arg) {
273+
TRACE(">");
257274
TSRMLS_FETCH();
258275
php_request_startup(TSRMLS_C);
259276
php_embed_shutdown(TSRMLS_C);
260277
if (php_embed_module.php_ini_path_override) {
261278
delete[] php_embed_module.php_ini_path_override;
262279
}
280+
TRACE("<");
263281
}
264282

265283
NODE_MODULE(node_php_embed, ModuleInit)

src/node_php_jsobject_class.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class JsHasPropertyMsg : public MessageToJs {
5656
}
5757
protected:
5858
virtual void InJs(ObjectMapper *m) {
59+
TRACE("> JsHasPropertyMsg");
5960
retval_.SetBool(false);
6061
v8::Local<v8::Object> jsObj = Nan::To<v8::Object>(object_.ToJs(m))
6162
.ToLocalChecked();
@@ -99,20 +100,23 @@ class JsHasPropertyMsg : public MessageToJs {
99100
}
100101
}
101102
}
103+
TRACE("< JsHasPropertyMsg");
102104
}
103105
};
104106

105107
#if USE_MAGIC_ISSET
106108

107109
PHP_METHOD(JsObject, __isset) {
108110
zval *member;
111+
TRACE(">");
109112
PARSE_PARAMS(__isset, "z/", &member);
110113
convert_to_string(member);
111114
JsHasPropertyMsg msg(obj->channel, obj->id, member, 0);
112115
obj->channel->Send(&msg);
113116
msg.WaitForResponse();
114117
THROW_IF_EXCEPTION("JS exception thrown during __isset of \"%*s\"",
115118
Z_STRLEN_P(member), Z_STRVAL_P(member));
119+
TRACE("<");
116120
RETURN_BOOL(msg.retval_.AsBool());
117121
}
118122

@@ -125,6 +129,7 @@ static int node_php_jsobject_has_property(zval *object, zval *member, int has_se
125129
* 1 (set) whether property exists and is true-ish - empty()
126130
* 2 (exists) whether property exists - property_exists()
127131
*/
132+
TRACE(">");
128133
if (Z_TYPE_P(member) != IS_STRING) {
129134
return false;
130135
}
@@ -135,6 +140,7 @@ static int node_php_jsobject_has_property(zval *object, zval *member, int has_se
135140
msg.WaitForResponse();
136141
// ok, result is in msg.retval_ or msg.exception_
137142
if (msg.HasException()) { return false; /* sigh */ }
143+
TRACE("<");
138144
return msg.retval_.AsBool();
139145
}
140146
#endif /* USE_MAGIC_ISSET */
@@ -150,6 +156,7 @@ class JsReadPropertyMsg : public MessageToJs {
150156
}
151157
protected:
152158
virtual void InJs(ObjectMapper *m) {
159+
TRACE("> JsReadPropertyMsg");
153160
v8::Local<v8::Object> jsObj = Nan::To<v8::Object>(object_.ToJs(m))
154161
.ToLocalChecked();
155162
v8::Local<v8::String> jsKey = Nan::To<v8::String>(member_.ToJs(m))
@@ -165,11 +172,13 @@ class JsReadPropertyMsg : public MessageToJs {
165172
} else {
166173
retval_.SetNull();
167174
}
175+
TRACE("< JsReadPropertyMsg");
168176
}
169177
};
170178

171179

172180
PHP_METHOD(JsObject, __get) {
181+
TRACE(">");
173182
zval *member;
174183
PARSE_PARAMS(__get, "z/", &member);
175184
convert_to_string(member);
@@ -179,6 +188,7 @@ PHP_METHOD(JsObject, __get) {
179188
THROW_IF_EXCEPTION("JS exception thrown during __get of \"%*s\"",
180189
Z_STRLEN_P(member), Z_STRVAL_P(member));
181190
msg.retval_.ToPhp(obj->channel, return_value, return_value_ptr TSRMLS_CC);
191+
TRACE("<");
182192
}
183193

184194
class JsWritePropertyMsg : public MessageToJs {
@@ -192,6 +202,7 @@ class JsWritePropertyMsg : public MessageToJs {
192202
}
193203
protected:
194204
virtual void InJs(ObjectMapper *m) {
205+
TRACE("> HasPropertyMsg");
195206
v8::Local<v8::Object> jsObj = Nan::To<v8::Object>(object_.ToJs(m))
196207
.ToLocalChecked();
197208
v8::Local<v8::String> jsKey = Nan::To<v8::String>(member_.ToJs(m))
@@ -201,11 +212,13 @@ class JsWritePropertyMsg : public MessageToJs {
201212
if (Nan::Set(jsObj, jsKey, jsVal).FromMaybe(false)) {
202213
retval_.SetBool(true);
203214
}
215+
TRACE("< HasPropertyMsg");
204216
}
205217
};
206218

207219
PHP_METHOD(JsObject, __set) {
208220
zval *member; zval *value;
221+
TRACE(">");
209222
PARSE_PARAMS(__set, "z/z", &member, &value);
210223
convert_to_string(member);
211224
JsWritePropertyMsg msg(obj->channel, obj->id, member, value);
@@ -214,6 +227,7 @@ PHP_METHOD(JsObject, __set) {
214227
THROW_IF_EXCEPTION("JS exception thrown during __set of \"%*s\"",
215228
Z_STRLEN_P(member), Z_STRVAL_P(member));
216229
msg.retval_.ToPhp(obj->channel, return_value, return_value_ptr TSRMLS_CC);
230+
TRACE("<");
217231
}
218232

219233
class JsDeletePropertyMsg : public MessageToJs {
@@ -226,6 +240,7 @@ class JsDeletePropertyMsg : public MessageToJs {
226240
}
227241
protected:
228242
virtual void InJs(ObjectMapper *m) {
243+
TRACE("> DeletePropertyMsg");
229244
v8::Local<v8::Object> jsObj = Nan::To<v8::Object>(object_.ToJs(m))
230245
.ToLocalChecked();
231246
v8::Local<v8::String> jsKey = Nan::To<v8::String>(member_.ToJs(m))
@@ -234,11 +249,13 @@ class JsDeletePropertyMsg : public MessageToJs {
234249
if (Nan::Delete(jsObj, jsKey).FromMaybe(false)) {
235250
retval_.SetBool(true);
236251
}
252+
TRACE("< DeletePropertyMsg");
237253
}
238254
};
239255

240256
PHP_METHOD(JsObject, __unset) {
241257
zval *member;
258+
TRACE(">");
242259
PARSE_PARAMS(__unset, "z/", &member);
243260
convert_to_string(member);
244261
JsDeletePropertyMsg msg(obj->channel, obj->id, member);
@@ -247,6 +264,7 @@ PHP_METHOD(JsObject, __unset) {
247264
THROW_IF_EXCEPTION("JS exception thrown during __unset of \"%*s\"",
248265
Z_STRLEN_P(member), Z_STRVAL_P(member));
249266
msg.retval_.ToPhp(obj->channel, return_value, return_value_ptr TSRMLS_CC);
267+
TRACE("<");
250268
}
251269

252270
class JsInvokeMethodMsg : public MessageToJs {
@@ -265,6 +283,7 @@ class JsInvokeMethodMsg : public MessageToJs {
265283
Value &Argv(int n) { return argv_[n]; }
266284
protected:
267285
virtual void InJs(ObjectMapper *m) {
286+
TRACE("> JsInvokeMethodMsg");
268287
Nan::MaybeLocal<v8::Object> jsObj =
269288
Nan::To<v8::Object>(object_.ToJs(m));
270289
if (jsObj.IsEmpty()) {
@@ -291,11 +310,13 @@ class JsInvokeMethodMsg : public MessageToJs {
291310
if (!result.IsEmpty()) {
292311
retval_.Set(m, result.ToLocalChecked());
293312
}
313+
TRACE("< JsInvokeMethodMsg");
294314
}
295315
};
296316

297317
PHP_METHOD(JsObject, __call) {
298318
zval *member; zval *args;
319+
TRACE(">");
299320
PARSE_PARAMS(__unset, "z/a", &member, &args);
300321
convert_to_string(member);
301322
HashTable *arrht = Z_ARRVAL_P(args);
@@ -315,6 +336,7 @@ PHP_METHOD(JsObject, __call) {
315336
THROW_IF_EXCEPTION("JS exception thrown during __call of \"%*s\"",
316337
Z_STRLEN_P(member), Z_STRVAL_P(member));
317338
msg.retval_.ToPhp(obj->channel, return_value, return_value_ptr TSRMLS_CC);
339+
TRACE("<");
318340
}
319341

320342

@@ -324,25 +346,30 @@ PHP_METHOD(JsObject, __call) {
324346
* for dimensions as well, so that $obj['foo'] acts like $obj->foo. */
325347

326348
static int node_php_jsobject_has_dimension(zval *obj, zval *idx, int chk_type TSRMLS_DC) {
349+
TRACE(">");
327350
// thunk!
328351
if (chk_type == 0) { chk_type = 2; }
329352
// use standard has_property method with new chk_type
330353
return node_php_jsobject_handlers.has_property(obj, idx, chk_type ZEND_HASH_KEY_NULL TSRMLS_CC);
331354
}
332355
static zval *node_php_jsobject_read_dimension(zval *obj, zval *off, int type TSRMLS_DC) {
356+
TRACE(">");
333357
// use standard read_property method
334358
return node_php_jsobject_handlers.read_property(obj, off, type ZEND_HASH_KEY_NULL TSRMLS_CC);
335359
}
336360
static void node_php_jsobject_write_dimension(zval *obj, zval *off, zval *val TSRMLS_DC) {
361+
TRACE(">");
337362
// use standard write_property method
338363
node_php_jsobject_handlers.write_property(obj, off, val ZEND_HASH_KEY_NULL TSRMLS_CC);
339364
}
340365
static void node_php_jsobject_unset_dimension(zval *obj, zval *off TSRMLS_DC) {
366+
TRACE(">");
341367
// use standard unset_property method
342368
node_php_jsobject_handlers.unset_property(obj, off ZEND_HASH_KEY_NULL TSRMLS_CC);
343369
}
344370

345371
static void node_php_jsobject_free_storage(void *object, zend_object_handle handle TSRMLS_DC) {
372+
TRACE(">");
346373
node_php_jsobject *c = (node_php_jsobject *) object;
347374

348375
#if 0
@@ -369,9 +396,11 @@ static void node_php_jsobject_free_storage(void *object, zend_object_handle hand
369396
// another JS->PHP call first, which would revive the PHP-side wrapper.
370397

371398
efree(object);
399+
TRACE("<");
372400
}
373401

374402
static zend_object_value node_php_jsobject_new(zend_class_entry *ce TSRMLS_DC) {
403+
TRACE(">");
375404
zend_object_value retval;
376405
node_php_jsobject *c;
377406

@@ -382,10 +411,12 @@ static zend_object_value node_php_jsobject_new(zend_class_entry *ce TSRMLS_DC) {
382411
retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) node_php_jsobject_free_storage, NULL TSRMLS_CC);
383412
retval.handlers = &node_php_jsobject_handlers;
384413

414+
TRACE("<");
385415
return retval;
386416
}
387417

388418
void node_php_embed::node_php_jsobject_create(zval *res, JsMessageChannel *channel, objid_t id TSRMLS_DC) {
419+
TRACE(">");
389420
node_php_jsobject *c;
390421

391422
object_init_ex(res, php_ce_jsobject);
@@ -400,15 +431,18 @@ void node_php_embed::node_php_jsobject_create(zval *res, JsMessageChannel *chann
400431

401432
ctx->node_php_jsobjects.push_front(c);
402433
#endif
434+
TRACE("<");
403435
}
404436

405437
#define STUB_METHOD(name) \
406438
PHP_METHOD(JsObject, name) { \
439+
TRACE(">"); \
407440
zend_throw_exception( \
408441
zend_exception_get_default(TSRMLS_C), \
409442
"Can't directly construct, serialize, or unserialize JsObject.", \
410443
0 TSRMLS_CC \
411444
); \
445+
TRACE("<"); \
412446
RETURN_FALSE; \
413447
}
414448

@@ -456,6 +490,7 @@ static const zend_function_entry node_php_jsobject_methods[] = {
456490

457491

458492
PHP_MINIT_FUNCTION(node_php_jsobject_class) {
493+
TRACE("> PHP_MINIT_FUNCTION");
459494
zend_class_entry ce;
460495
/* JsObject Class */
461496
INIT_CLASS_ENTRY(ce, "JsObject", node_php_jsobject_methods);
@@ -488,5 +523,6 @@ PHP_MINIT_FUNCTION(node_php_jsobject_class) {
488523
node_php_jsobject_handlers.has_dimension = node_php_jsobject_has_dimension;
489524
node_php_jsobject_handlers.unset_dimension = node_php_jsobject_unset_dimension;
490525

526+
TRACE("< PHP_MINIT_FUNCTION");
491527
return SUCCESS;
492528
}

0 commit comments

Comments
 (0)