@@ -133,6 +133,10 @@ return_section_address(
133
133
134
134
cmd = (struct segment_command_64 * )((void * )cmd + cmd -> cmdsize );
135
135
}
136
+
137
+ // We should not be here, but if we are there, we should say about this
138
+ PyErr_SetString (
139
+ PyExc_RuntimeError , "Cannot find section address.\n" );
136
140
return 0 ;
137
141
}
138
142
@@ -188,6 +192,8 @@ search_section_in_file(
188
192
189
193
munmap (map , fs .st_size );
190
194
if (close (fd ) != 0 ) {
195
+ // This might hide one of the above exceptions, maybe we
196
+ // should chain them?
191
197
PyErr_SetFromErrno (PyExc_OSError );
192
198
}
193
199
return result ;
@@ -217,7 +223,6 @@ search_map_for_section(pid_t pid, const char* secname, const char* substr) {
217
223
218
224
mach_port_t proc_ref = pid_to_task (pid );
219
225
if (proc_ref == 0 ) {
220
- PyErr_SetString (PyExc_PermissionError , "Cannot get task for PID" );
221
226
return 0 ;
222
227
}
223
228
@@ -260,6 +265,9 @@ search_map_for_section(pid_t pid, const char* secname, const char* substr) {
260
265
261
266
address += size ;
262
267
}
268
+
269
+ PyErr_SetString (PyExc_RuntimeError ,
270
+ "mach_vm_region failed to find the section" );
263
271
return 0 ;
264
272
}
265
273
@@ -306,6 +314,8 @@ find_map_start_address(pid_t pid, char* result_filename, const char* map)
306
314
307
315
if (!match_found ) {
308
316
map_filename [0 ] = '\0' ;
317
+ PyErr_Format (PyExc_RuntimeError ,
318
+ "Cannot find map start address for map: %s" , map );
309
319
}
310
320
311
321
return result_address ;
@@ -401,6 +411,8 @@ search_map_for_section(pid_t pid, const char* secname, const char* map)
401
411
static uintptr_t
402
412
search_map_for_section (pid_t pid , const char * secname , const char * map )
403
413
{
414
+ PyErr_SetString (PyExc_NotImplementedError ,
415
+ "Not supported on this platform" );
404
416
return 0 ;
405
417
}
406
418
#endif
@@ -419,7 +431,8 @@ get_py_runtime(pid_t pid)
419
431
static uintptr_t
420
432
get_async_debug (pid_t pid )
421
433
{
422
- uintptr_t result = search_map_for_section (pid , "AsyncioDebug" , "_asyncio.cpython" );
434
+ uintptr_t result = search_map_for_section (pid , "AsyncioDebug" ,
435
+ "_asyncio.cpython" );
423
436
if (result == 0 && !PyErr_Occurred ()) {
424
437
PyErr_SetString (PyExc_RuntimeError , "Cannot find AsyncioDebug section" );
425
438
}
@@ -482,6 +495,9 @@ read_memory(pid_t pid, uintptr_t remote_address, size_t len, void* dst)
482
495
}
483
496
total_bytes_read = len ;
484
497
#else
498
+ PyErr_SetString (
499
+ PyExc_RuntimeError ,
500
+ "Memory reading is not supported on this platform" );
485
501
return -1 ;
486
502
#endif
487
503
return total_bytes_read ;
@@ -789,6 +805,9 @@ parse_coro_chain(
789
805
pid ,
790
806
coro_address + offsets -> gen_object .gi_frame_state ,
791
807
& gi_frame_state );
808
+ if (err ) {
809
+ return -1 ;
810
+ }
792
811
793
812
if (gi_frame_state == FRAME_SUSPENDED_YIELD_FROM ) {
794
813
char owner ;
0 commit comments