@@ -282,20 +282,36 @@ void DumpBacktrace(FILE* fp) {
282
282
void CheckedUvLoopClose (uv_loop_t * loop) {
283
283
if (uv_loop_close (loop) == 0 ) return ;
284
284
285
- auto sym_ctx = NativeSymbolDebuggingContext::New ();
285
+ PrintLibuvHandleInformation (loop, stderr);
286
+
287
+ fflush (stderr);
288
+ // Finally, abort.
289
+ CHECK (0 && " uv_loop_close() while having open handles" );
290
+ }
286
291
287
- fprintf (stderr, " uv loop at [%p] has active handles\n " , loop);
292
+ void PrintLibuvHandleInformation (uv_loop_t * loop, FILE* stream) {
293
+ struct Info {
294
+ std::unique_ptr<NativeSymbolDebuggingContext> ctx;
295
+ FILE* stream;
296
+ };
297
+
298
+ Info info { NativeSymbolDebuggingContext::New (), stream };
299
+
300
+ fprintf (stream, " uv loop at [%p] has %d active handles\n " ,
301
+ loop, loop->active_handles );
288
302
289
303
uv_walk (loop, [](uv_handle_t * handle, void * arg) {
290
- auto sym_ctx = static_cast <NativeSymbolDebuggingContext*>(arg);
304
+ Info* info = static_cast <Info*>(arg);
305
+ NativeSymbolDebuggingContext* sym_ctx = info->ctx .get ();
306
+ FILE* stream = info->stream ;
291
307
292
- fprintf (stderr , " [%p] %s\n " , handle, uv_handle_type_name (handle->type ));
308
+ fprintf (stream , " [%p] %s\n " , handle, uv_handle_type_name (handle->type ));
293
309
294
310
void * close_cb = reinterpret_cast <void *>(handle->close_cb );
295
- fprintf (stderr , " \t Close callback: %p %s\n " ,
311
+ fprintf (stream , " \t Close callback: %p %s\n " ,
296
312
close_cb, sym_ctx->LookupSymbol (close_cb).Display ().c_str ());
297
313
298
- fprintf (stderr , " \t Data: %p %s\n " ,
314
+ fprintf (stream , " \t Data: %p %s\n " ,
299
315
handle->data , sym_ctx->LookupSymbol (handle->data ).Display ().c_str ());
300
316
301
317
// We are also interested in the first field of what `handle->data`
@@ -309,14 +325,10 @@ void CheckedUvLoopClose(uv_loop_t* loop) {
309
325
first_field = *reinterpret_cast <void **>(handle->data );
310
326
311
327
if (first_field != nullptr ) {
312
- fprintf (stderr , " \t (First field): %p %s\n " ,
328
+ fprintf (stream , " \t (First field): %p %s\n " ,
313
329
first_field, sym_ctx->LookupSymbol (first_field).Display ().c_str ());
314
330
}
315
- }, sym_ctx.get ());
316
-
317
- fflush (stderr);
318
- // Finally, abort.
319
- CHECK (0 && " uv_loop_close() while having open handles" );
331
+ }, &info);
320
332
}
321
333
322
334
std::vector<std::string> NativeSymbolDebuggingContext::GetLoadedLibraries () {
0 commit comments