@@ -422,13 +422,12 @@ parse_coro_chain(
422422static PyObject *
423423create_task_result (
424424 RemoteUnwinderObject * unwinder ,
425- uintptr_t task_address
425+ uintptr_t task_address ,
426+ char is_task
426427) {
427428 PyObject * result = NULL ;
428429 PyObject * call_stack = NULL ;
429430 PyObject * tn = NULL ;
430- char task_obj [SIZEOF_TASK_OBJ ];
431- uintptr_t coro_addr ;
432431
433432 // Create call_stack first since it's the first tuple element
434433 call_stack = PyList_New (0 );
@@ -444,25 +443,27 @@ create_task_result(
444443 goto error ;
445444 }
446445
447- // Parse coroutine chain
448- if (_Py_RemoteDebug_PagedReadRemoteMemory (& unwinder -> handle , task_address ,
449- (size_t )unwinder -> async_debug_offsets .asyncio_task_object .size ,
450- task_obj ) < 0 ) {
451- set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to read task object for coro chain" );
452- goto error ;
453- }
454-
455- coro_addr = GET_MEMBER_NO_TAG (uintptr_t , task_obj , unwinder -> async_debug_offsets .asyncio_task_object .task_coro );
456-
457- if ((void * )coro_addr != NULL ) {
458- if (parse_coro_chain (unwinder , coro_addr , call_stack ) < 0 ) {
459- set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to parse coroutine chain" );
446+ if (is_task ) {
447+ char task_obj [SIZEOF_TASK_OBJ ];
448+ if (_Py_RemoteDebug_PagedReadRemoteMemory (& unwinder -> handle , task_address ,
449+ (size_t )unwinder -> async_debug_offsets .asyncio_task_object .size ,
450+ task_obj ) < 0 ) {
451+ set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to read task object for coro chain" );
460452 goto error ;
461453 }
462454
463- if (PyList_Reverse (call_stack )) {
464- set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to reverse call stack" );
465- goto error ;
455+ uintptr_t coro_addr = GET_MEMBER_NO_TAG (uintptr_t , task_obj , unwinder -> async_debug_offsets .asyncio_task_object .task_coro );
456+
457+ if ((void * )coro_addr != NULL ) {
458+ if (parse_coro_chain (unwinder , coro_addr , call_stack ) < 0 ) {
459+ set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to parse coroutine chain" );
460+ goto error ;
461+ }
462+
463+ if (PyList_Reverse (call_stack )) {
464+ set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to reverse call stack" );
465+ goto error ;
466+ }
466467 }
467468 }
468469
@@ -506,33 +507,10 @@ parse_task(
506507 goto error ;
507508 }
508509
509- if (is_task ) {
510- result = create_task_result (unwinder , task_address );
511- if (!result ) {
512- set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to create task result" );
513- goto error ;
514- }
515- } else {
516- // Create an empty CoroInfo for non-task objects
517- RemoteDebuggingState * state = RemoteDebugging_GetStateFromObject ((PyObject * )unwinder );
518- result = PyStructSequence_New (state -> CoroInfo_Type );
519- if (result == NULL ) {
520- set_exception_cause (unwinder , PyExc_MemoryError , "Failed to create empty CoroInfo" );
521- goto error ;
522- }
523- PyObject * empty_list = PyList_New (0 );
524- if (empty_list == NULL ) {
525- set_exception_cause (unwinder , PyExc_MemoryError , "Failed to create empty list" );
526- goto error ;
527- }
528- PyObject * task_name = PyLong_FromUnsignedLongLong (task_address );
529- if (task_name == NULL ) {
530- Py_DECREF (empty_list );
531- set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to create task name" );
532- goto error ;
533- }
534- PyStructSequence_SetItem (result , 0 , empty_list ); // This steals the reference
535- PyStructSequence_SetItem (result , 1 , task_name ); // This steals the reference
510+ result = create_task_result (unwinder , task_address , is_task );
511+ if (result == NULL ) {
512+ set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to create task result" );
513+ goto error ;
536514 }
537515 if (PyList_Append (render_to , result )) {
538516 set_exception_cause (unwinder , PyExc_RuntimeError , "Failed to append task result to render list" );
0 commit comments