@@ -438,6 +438,56 @@ def _extract_coroutine_stacks_lineno_only(self, stack_trace):
438438# ============================================================================
439439
440440
441+ @requires_remote_subprocess_debugging ()
442+ class TestSelfStackTrace (RemoteInspectionTestBase ):
443+ @skip_if_not_supported
444+ @unittest .skipIf (
445+ sys .platform == "linux" and not PROCESS_VM_READV_SUPPORTED ,
446+ "Test only runs on Linux with process_vm_readv support" ,
447+ )
448+ def test_self_trace_with_large_linetable (self ):
449+ script = textwrap .dedent ("""\
450+ import os
451+ import _remote_debugging
452+
453+ assignments = "\\ n".join(
454+ f"value_{i} = {i}" for i in range(1000)
455+ )
456+ expected_lineno = len(assignments.splitlines()) + 1
457+ source = (
458+ f"{assignments}\\ n"
459+ "stack_trace = "
460+ "_remote_debugging.RemoteUnwinder(os.getpid()).get_stack_trace()\\ n"
461+ )
462+ code = compile(source, "large_linetable.py", "exec")
463+ assert len(code.co_linetable) > 4096, len(code.co_linetable)
464+ namespace = {"os": os, "_remote_debugging": _remote_debugging}
465+ exec(code, namespace)
466+ large_linetable_frames = [
467+ frame
468+ for interpreter in namespace["stack_trace"]
469+ for thread in interpreter.threads
470+ for frame in thread.frame_info
471+ if frame.filename == "large_linetable.py"
472+ ]
473+ assert len(large_linetable_frames) == 1, large_linetable_frames
474+ assert large_linetable_frames[0].location.lineno == expected_lineno, (
475+ large_linetable_frames[0]
476+ )
477+ """ )
478+
479+ result = subprocess .run (
480+ [sys .executable , "-c" , script ],
481+ capture_output = True ,
482+ text = True ,
483+ timeout = SHORT_TIMEOUT ,
484+ )
485+ self .assertEqual (
486+ result .returncode , 0 ,
487+ f"stdout: { result .stdout } \n stderr: { result .stderr } "
488+ )
489+
490+
441491@requires_remote_subprocess_debugging ()
442492class TestGetStackTrace (RemoteInspectionTestBase ):
443493 @skip_if_not_supported
0 commit comments