Repository navigation
Expand file tree
/
Copy pathremote_debugging.po
More file actions
1455 lines (1301 loc) · 69.5 KB
/
Copy pathremote_debugging.po
File metadata and controls
1455 lines (1301 loc) · 69.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
# Nyuan Zhang, 2025
# 99 <wh2099@pm.me>, 2026
# zhoubo, 2026
# Freesand Leo <yuqinju@163.com>, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.15\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-05 20:53+0000\n"
"PO-Revision-Date: 2025-09-16 00:00+0000\n"
"Last-Translator: Freesand Leo <yuqinju@163.com>, 2026\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../howto/remote_debugging.rst:4
msgid "Remote debugging attachment protocol"
msgstr "远程调试附加协议"
#: ../../howto/remote_debugging.rst:6
msgid ""
"This protocol enables external tools to attach to a running CPython process "
"and execute Python code remotely."
msgstr "此协议使得外部工具能够附加到正在运行的 CPython 进程并远程执行 Python 代码。"
#: ../../howto/remote_debugging.rst:9
msgid ""
"Attaching to another Python process may require additional permissions or "
"configuration, depending on the platform."
msgstr "附加到另一个 Python 进程可能需要额外的权限或配置,这取决于具体平台。"
#: ../../howto/remote_debugging.rst:13
msgid "Disabling remote debugging"
msgstr "禁用远程调试"
#: ../../howto/remote_debugging.rst:15
msgid "To disable remote debugging support, use any of the following:"
msgstr "要禁用远程调试支持,请使用下列方式之一:"
#: ../../howto/remote_debugging.rst:17
msgid ""
"Set the :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` environment variable to ``1`` "
"before starting the interpreter."
msgstr "在启动解释器之前将 :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` 环境变量设为 ``1``。"
#: ../../howto/remote_debugging.rst:19
msgid "Use the :option:`-X disable-remote-debug` command-line option."
msgstr "使用 :option:`-X disable-remote-debug` 命令行选项。"
#: ../../howto/remote_debugging.rst:20
msgid "Compile Python with the :option:`--without-remote-debug` build flag."
msgstr "编译 Python 时使用 :option:`--without-remote-debug` 构建旗标。"
#: ../../howto/remote_debugging.rst:25
msgid "Permission requirements"
msgstr "权限需求"
#: ../../howto/remote_debugging.rst:27
msgid ""
"Attaching to a running Python process for remote debugging requires special "
"configuration on most platforms. The specific requirements and "
"troubleshooting steps depend on your operating system:"
msgstr "附加到正在运行的 Python 进程用于远程调试在大多数平台上都需要特殊的配置。 具体的要求和故障排除步骤取决于你的操作系统:"
#: ../../howto/remote_debugging.rst:32
msgid "Linux"
msgstr "Linux"
#: ../../howto/remote_debugging.rst:33
msgid ""
"In general, you can debug your own processes, but there are several common "
"configurations that may disable this. Some Linux distributions enable "
"**ptrace restrictions**, aka \"Yama,\" as a form of system hardening. Recent"
" versions of the ``setpriv`` command (util-linux 2.41, released June 2025) "
"let you loosen ptrace restrictions on a per-process basis:"
msgstr ""
"总的来说,你可以调试你所拥有的进程,但有几种常见配置可能会禁用此功能。 某些 Linux 发行版会启用 **ptrace 限制**,或称 "
"\"Yama\" 作为一种系统加固方式。 最新版本的 ``setpriv`` 命令(util-linux 2.41,2025 年 6 "
"月发布)让你可以基于每个进程放松 ptrace 限制:"
#: ../../howto/remote_debugging.rst:39
msgid "``setpriv --ptracer any python3``"
msgstr "``setpriv --ptracer any python3``"
#: ../../howto/remote_debugging.rst:41
msgid ""
"(This is configured on the process *being debugged*.) You can also turn off "
"ptrace restrictions for all processes until reboot with:"
msgstr "(这是在 *正被调试的* 进程上配置的。)。 你也可以使用以下命令为所有进程关闭 ptrace 限制直到重启系统:"
#: ../../howto/remote_debugging.rst:44
msgid "``echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope``"
msgstr "``echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope``"
#: ../../howto/remote_debugging.rst:46
msgid ""
"This can also be configured persistently, usually in ``/etc/sysctl.d``."
msgstr "这也可以被持久化配置,通常是在 ``/etc/sysctl.d`` 中。"
#: ../../howto/remote_debugging.rst:50
msgid ""
"Disabling ``ptrace_scope`` reduces system hardening and should only be done "
"in low-security environments."
msgstr "禁用 ``ptrace_scope`` 会降低系统加固程度,因此仅应在低安全级别环境中执行。"
#: ../../howto/remote_debugging.rst:53
msgid ""
"It is also possible that the ``ptrace`` system call is disabled because of a"
" security filter. In particular, this was common with older versions of some"
" container software. Docker 19.03 or newer (released 2019) and containerd "
"1.6.7 or newer (released 2022) will automatically allow usage of the "
"``ptrace`` system call inside containers, when running on Linux kernel 4.8 "
"or higher. If you cannot upgrade to these versions, you can create your "
"container with an option like ``--security-opt seccomp=unconfined`` to "
"disable the system call security filter for that container. This weakens the"
" container's isolation and should only be done in low-security environments."
msgstr ""
"``ptrace`` 系统调用也可能因安全过滤器而被禁用。尤其常见于某些容器软件的旧版本。Docker 19.03 或更高版本(发布于 2019 "
"年)以及 containerd 1.6.7 或更高版本(发布于 2022 年)在基于 Linux 内核 4.8 或更高版本运行时,将自动允许在容器内使用"
" ``ptrace`` 系统调用。如果您无法升级到这些版本,可以通过使用诸如 ``--security-opt seccomp=unconfined``"
" 之类的选项创建容器,以禁用该容器的系统调用安全过滤器。这会削弱容器的隔离性,因此应仅在低安全级别环境中使用此方法。"
#: ../../howto/remote_debugging.rst:63
msgid ""
"If you need to trace a process that you *do not* own, you will need "
"superuser access or equivalent. This also applies to processes that have "
"changed their security credentials, e.g., set-user-ID or set-group-ID "
"processes (though this is unusual for Python). Try running the debugging "
"command with ``sudo -E``."
msgstr ""
"如果您需要跟踪一个*并非*由您所有进程的进程,则需要超级用户权限或同等权限。这也适用于已更改安全凭据的进程,例如 set-user-ID 或 set-"
"group-ID 进程(尽管在 Python 中这种情况并不常见)。请尝试使用 ``sudo -E`` 运行调试命令。"
#: ../../howto/remote_debugging.rst:70
msgid ""
"The ``CAP_SYS_PTRACE`` capability is equivalent to superuser access, in that"
" it allows debugging *any* process, not just your own. You may see advice on"
" the internet suggesting using it to work around ptrace restrictions or "
"system call filters. This may work in practice, as would ``sudo``, but this "
"gives the debugging process much more access than it needs and should only "
"be done in low-security environments."
msgstr ""
"``CAP_SYS_PTRACE`` "
"功能等同于超级用户权限,因为它允许对*任意*进程进行调试,而不仅仅是自己的进程。您可能会在网络上看到一些建议,建议利用该功能来绕过 ptrace "
"的限制或系统调用过滤器。这种做法在实践中或许可行,``sudo`` "
"同样如此;但这样一来,调试进程将获得远超其所需权限的访问权限,因此应仅在低安全级别环境中使用。"
#: ../../howto/remote_debugging.rst:77
msgid ""
"Finally, note that a process can only have one tracer at a time. If you have"
" already attached to a Python process under ``strace``, ``gdb``, etc., you "
"won't be able to simultaneously use remote debugging. (Superuser access "
"cannot get around this restriction.)"
msgstr ""
"最后请注意,一个进程一次只能使用一个追踪器。如果您已经通过 ``strace``、``gdb`` 等标识符连接到某个 Python "
"进程,就无法同时使用远程调试功能。(超级用户权限也无法绕过这一限制。)"
#: ../../howto/remote_debugging.rst:83
msgid "macOS"
msgstr "macOS"
#: ../../howto/remote_debugging.rst:84
msgid "By default, macOS disables the ability to debug other processes."
msgstr "默认情况下,macOS 会禁用对其他进程的调试功能。"
#: ../../howto/remote_debugging.rst:86
msgid ""
"You can modify your Python binary to opt in to being debugged by giving it "
"an **ad-hoc code signature** with an **entitlement** enabling it to be "
"debugged. (An ad-hoc \"signature\" is just a configuration without any "
"actual cryptographic signature or a need for a certificate or anything else "
"such as an Apple developer program membership.)"
msgstr ""
"您可以通过为 Python "
"二进制文件提供一个**临时代码签名**,并设置一项允许对其进行调试的**权限**,从而将其修改为接受调试。(临时“签名”仅是一种配置,不包含任何实际的加密签名,也不需要证书或其他类似材料,例如"
" Apple 开发者计划会员资格。)"
#: ../../howto/remote_debugging.rst:92
msgid ""
"The following commands will create a file ``get-task-allow.plist`` with the "
"necessary entitlement and add it to the Python binary:"
msgstr "以下命令将创建一个具有必要权限的文件 ``get-task-allow.plist``,并将其添加到 Python 二进制文件中:"
#: ../../howto/remote_debugging.rst:95
msgid ""
"echo '{\"com.apple.security.get-task-allow\": true}' | plutil -convert xml1 -o get-task-allow.plist -\n"
"codesign --sign - --entitlements get-task-allow.plist path/to/bin/python3"
msgstr ""
"echo ‘{\"com.apple.security.get-task-allow\": true}’ | plutil -convert xml1 -o get-task-allow.plist -\n"
"codesign --sign - --entitlements get-task-allow.plist path/to/bin/python3"
#: ../../howto/remote_debugging.rst:100
msgid ""
"where ``path/to/bin/python3`` is the path to your Python binary, which you "
"can find by e.g. running ``which python3`` or evaluating "
"``sys._base_executable`` at the Python REPL. (These instructions are for a "
"non-framework build of Python. Framework builds may need to be configured "
"differently.)"
msgstr ""
"其中 ``path/to/bin/python3`` 是 Python 二进制文件的路径;您可以通过例如运行 ``which python3`` 或在 "
"Python REPL 中评估 ``sys._base_executable`` 来找到该路径。(这些说明适用于非框架构建的 "
"Python;框架构建可能需要采用不同的配置方式。)"
#: ../../howto/remote_debugging.rst:105
msgid ""
"You should then be able to debug your own Python processes started with that"
" binary."
msgstr "之后,您应该就能对使用该二进制文件启动的自有 Python 进程进行调试了。"
#: ../../howto/remote_debugging.rst:108
msgid ""
"Alternatively, much as with Linux, processes with superuser privileges e.g. "
"``sudo`` are not subject to this check and can debug any user's process on "
"the system (though there are additional checks on specific binaries, such as"
" OS-provided commands, due to System Integrity Protection)."
msgstr ""
"或者,与 Linux 类似,具有超级用户权限的进程(例如 "
"``sudo``)不受此检查的限制,因此可以调试系统中任何用户的进程(不过,由于系统完整性保护的存在,针对特定二进制文件——例如操作系统提供的命令——还会进行额外的检查)。"
#: ../../howto/remote_debugging.rst:114
msgid "Windows"
msgstr "Windows"
#: ../../howto/remote_debugging.rst:115
msgid ""
"To attach to another process, you usually need to run your debugging tool "
"with administrative privileges. Start the command prompt or terminal as "
"Administrator."
msgstr "要附加到另一个进程,您通常需要以管理员权限运行调试工具:以管理员身份运行命令提示符或者终端。"
#: ../../howto/remote_debugging.rst:119
msgid ""
"Some processes may still be inaccessible even with Administrator rights, "
"unless you have the ``SeDebugPrivilege`` privilege enabled."
msgstr "使用管理员权限时,除非启用 ``SeDebugPrivilege`` 权限,否则有的进程仍可能无法被访问。"
#: ../../howto/remote_debugging.rst:122
msgid ""
"To resolve file or folder access issues, adjust the security permissions:"
msgstr "要解决文件或文件夹访问的问题,请调整安全权限:"
#: ../../howto/remote_debugging.rst:124
msgid "Right-click the file or folder and select **Properties**."
msgstr "右键文件或文件夹并选择 **属性**。"
#: ../../howto/remote_debugging.rst:125
msgid "Go to the **Security** tab to view users and groups with access."
msgstr "在 **安全** 选项卡中查看有访问权限的用户和用户组。"
#: ../../howto/remote_debugging.rst:126
msgid "Click **Edit** to modify permissions."
msgstr "点击 **编辑** 以调整权限。"
#: ../../howto/remote_debugging.rst:127
msgid "Select your user account."
msgstr "选择您的用户账户。"
#: ../../howto/remote_debugging.rst:128
msgid "In **Permissions**, check **Read** or **Full control** as needed."
msgstr "在 **权限** 中,按需勾选 **读取** 或者 **完全控制**。"
#: ../../howto/remote_debugging.rst:129
msgid "Click **Apply**, then **OK** to confirm."
msgstr "在点击 **应用** 后点击 **确定**。"
#: ../../howto/remote_debugging.rst:134
msgid ""
"Ensure you've satisfied all :ref:`permission-requirements` before "
"proceeding."
msgstr "在继续前,请确保您已满足所有 :ref:`permission-requirements`。"
#: ../../howto/remote_debugging.rst:136
msgid ""
"This section describes the low-level protocol that enables external tools to"
" inject and execute a Python script within a running CPython process."
msgstr "本节描述了低级协议,该协议使外部工具能够在运行的 CPython 进程中注入和执行 Python 脚本。"
#: ../../howto/remote_debugging.rst:139
msgid ""
"This mechanism forms the basis of the :func:`sys.remote_exec` function, "
"which instructs a remote Python process to execute a ``.py`` file. However, "
"this section does not document the usage of that function. Instead, it "
"provides a detailed explanation of the underlying protocol, which takes as "
"input the ``pid`` of a target Python process and the path to a Python source"
" file to be executed. This information supports independent reimplementation"
" of the protocol, regardless of programming language."
msgstr ""
"该机制构成了 :func:`sys.remote_exec` 函数的基础,该函数用于指示远程 Python 进程执行指定的 ``.py`` "
"文件。但本节并不记录该函数的具体用法,而是详细阐述其底层协议的工作原理——该协议以目标 Python 进程的 ``pid`` 和待执行的 Python "
"源文件路径作为输入。这些信息支持协议的独立重新实现,且不受编程语言限制。"
#: ../../howto/remote_debugging.rst:149
msgid ""
"The execution of the injected script depends on the interpreter reaching a "
"safe evaluation point. As a result, execution may be delayed depending on "
"the runtime state of the target process."
msgstr "注入脚本的执行依赖于解释器到达安全的求值点。因此,实际执行时机可能会因目标进程的运行时状态而产生延迟。"
#: ../../howto/remote_debugging.rst:153
msgid ""
"Once injected, the script is executed by the interpreter within the target "
"process the next time a safe evaluation point is reached. This approach "
"enables remote execution capabilities without modifying the behavior or "
"structure of the running Python application."
msgstr ""
"一旦注入,脚本将在解释器下一次达到安全求值点时在目标进程中执行。这种方法能够在不修改运行中 Python 应用的行为或结构的情况下实现远程执行功能。"
#: ../../howto/remote_debugging.rst:158
msgid ""
"Subsequent sections provide a step-by-step description of the protocol, "
"including techniques for locating interpreter structures in memory, safely "
"accessing internal fields, and triggering code execution. Platform-specific "
"variations are noted where applicable, and example implementations are "
"included to clarify each operation."
msgstr ""
"后续各节提供了该协议的逐步描述,包括定位内存中解释器结构的技术、安全访问内部字段以及触发代码执行的方法。适用的情况下会注明平台特定的变体,并包含示例实现以澄清每个操作。"
#: ../../howto/remote_debugging.rst:165
msgid "Locating the PyRuntime structure"
msgstr "定位 PyRuntime 结构"
#: ../../howto/remote_debugging.rst:167
msgid ""
"CPython places the ``PyRuntime`` structure in a dedicated binary section to "
"help external tools find it at runtime. The name and format of this section "
"vary by platform. For example, ``.PyRuntime`` is used on ELF systems, and "
"``__DATA,__PyRuntime`` is used on macOS. Tools can find the offset of this "
"structure by examining the binary on disk."
msgstr ""
"CPython 将 ``PyRuntime`` 结构放置在一个专用的二进制节中,以帮助外部工具在运行时找到它。该节的名称和格式因平台而异。例如,在 "
"ELF 系统上使用 ``.PyRuntime``,在 macOS 上使用 "
"``__DATA,__PyRuntime``。工具可以通过检查磁盘上的二进制文件来找到该结构的偏移量。"
#: ../../howto/remote_debugging.rst:173
msgid ""
"The ``PyRuntime`` structure contains CPython’s global interpreter state and "
"provides access to other internal data, including the list of interpreters, "
"thread states, and debugger support fields."
msgstr ""
"``PyRuntime`` 结构包含 CPython 的全局解释器状态,并提供对其他内部数据的访问,包括解释器列表、线程状态和调试器支持字段。"
#: ../../howto/remote_debugging.rst:177
msgid ""
"To work with a remote Python process, a debugger must first find the memory "
"address of the ``PyRuntime`` structure in the target process. This address "
"can’t be hardcoded or calculated from a symbol name, because it depends on "
"where the operating system loaded the binary."
msgstr ""
"要处理远程 Python 进程,调试器首先必须在目标进程中找到 ``PyRuntime`` "
"结构的内存地址。这个地址不能硬编码或通过符号名计算,因为它取决于操作系统加载二进制文件的位置。"
#: ../../howto/remote_debugging.rst:182
msgid ""
"The method for finding ``PyRuntime`` depends on the platform, but the steps "
"are the same in general:"
msgstr "查找 ``PyRuntime`` 的方法取决于平台,但一般步骤是相同的:"
#: ../../howto/remote_debugging.rst:185
msgid ""
"Find the base address where the Python binary or shared library was loaded "
"in the target process."
msgstr "找到 Python 二进制文件或共享库在目标进程中加载的基址。"
#: ../../howto/remote_debugging.rst:187
msgid ""
"Use the on-disk binary to locate the offset of the ``.PyRuntime`` section."
msgstr "使用磁盘上的二进制文件定位 ``.PyRuntime`` 段的偏移。"
#: ../../howto/remote_debugging.rst:188
msgid ""
"Add the section offset to the base address to compute the address in memory."
msgstr "将段偏移加到基址上,计算出内存中的地址。"
#: ../../howto/remote_debugging.rst:190
msgid ""
"The sections below explain how to do this on each supported platform and "
"include example code."
msgstr "以下部分将说明在每个受支持平台上如何进行此操作,并包括示例代码。"
#: ../../howto/remote_debugging.rst:194
msgid "Linux (ELF)"
msgstr "Linux (ELF)"
#: ../../howto/remote_debugging.rst:195
msgid "To find the ``PyRuntime`` structure on Linux:"
msgstr "在 Linux 上查找 ``PyRuntime`` 结构:"
#: ../../howto/remote_debugging.rst:197
msgid ""
"Read the process’s memory map (for example, ``/proc/<pid>/maps``) to find "
"the address where the Python executable or ``libpython`` was loaded."
msgstr ""
"读取进程的内存映射 (例如,``/proc/<pid>/maps``) 以找到 Python 可执行文件或 ``libpython`` 加载的地址。"
#: ../../howto/remote_debugging.rst:199
msgid ""
"Parse the ELF section headers in the binary to get the offset of the "
"``.PyRuntime`` section."
msgstr "解析二进制文件中的 ELF 段头,获取 ``.PyRuntime`` 段的偏移。"
#: ../../howto/remote_debugging.rst:201
msgid ""
"Add that offset to the base address from step 1 to get the memory address of"
" ``PyRuntime``."
msgstr "将此偏移加到步骤 1 中的基址上,得到 ``PyRuntime`` 的内存地址。"
#: ../../howto/remote_debugging.rst:204 ../../howto/remote_debugging.rst:266
#: ../../howto/remote_debugging.rst:336 ../../howto/remote_debugging.rst:605
msgid "The following is an example implementation::"
msgstr "以下是一个示例实现::"
#: ../../howto/remote_debugging.rst:206
msgid ""
"def find_py_runtime_linux(pid: int) -> int:\n"
" # Step 1: Try to find the Python executable in memory\n"
" binary_path, base_address = find_mapped_binary(\n"
" pid, name_contains=\"python\"\n"
" )\n"
"\n"
" # Step 2: Fallback to shared library if executable is not found\n"
" if binary_path is None:\n"
" binary_path, base_address = find_mapped_binary(\n"
" pid, name_contains=\"libpython\"\n"
" )\n"
"\n"
" # Step 3: Parse ELF headers to get .PyRuntime section offset\n"
" section_offset = parse_elf_section_offset(\n"
" binary_path, \".PyRuntime\"\n"
" )\n"
"\n"
" # Step 4: Compute PyRuntime address in memory\n"
" return base_address + section_offset"
msgstr ""
"def find_py_runtime_linux(pid: int) -> int:\n"
" # 步骤 1:尝试在内存中找到 Python 可执行文件\n"
" binary_path, base_address = find_mapped_binary(\n"
" pid, name_contains=\"python\"\n"
" )\n"
"\n"
" # 步骤 2:如果找不到可执行文件,则回退到共享库\n"
" if binary_path is None:\n"
" binary_path, base_address = find_mapped_binary(\n"
" pid, name_contains=\"libpython\"\n"
" )\n"
"\n"
" # 步骤 3:解析 ELF 头以获取.PyRuntime 节的偏移量\n"
" section_offset = parse_elf_section_offset(\n"
" binary_path, \".PyRuntime\"\n"
" )\n"
"\n"
" # 步骤 4:计算内存中的 PyRuntime 地址\n"
" return base_address + section_offset"
#: ../../howto/remote_debugging.rst:227
msgid ""
"On Linux systems, there are two main approaches to read memory from another "
"process. The first is through the ``/proc`` filesystem, specifically by "
"reading from ``/proc/[pid]/mem`` which provides direct access to the "
"process's memory. This requires appropriate permissions - either being the "
"same user as the target process or having root access. The second approach "
"is using the ``process_vm_readv()`` system call which provides a more "
"efficient way to copy memory between processes. While ptrace's "
"``PTRACE_PEEKTEXT`` operation can also be used to read memory, it is "
"significantly slower as it only reads one word at a time and requires "
"multiple context switches between the tracer and tracee processes."
msgstr ""
"在 Linux 系统上,有两种主要方法读取另一个进程的内存。第一种是通过 ``/proc`` 文件系统,具体来说是通过读取 "
"``/proc/[pid]/mem`` ,它提供了对进程内存的直接访问。这需要适当的权限——要么是与目标进程相同的用户,要么拥有 root "
"权限。第二种方法是使用 ``process_vm_readv()`` 系统调用,它提供了在进程间复制内存的更高效方式。虽然 ptrace 的 "
"``PTRACE_PEEKTEXT`` "
"操作也可以用来读取内存,但它显著较慢,因为它一次只读取一个字,并且需要在跟踪器和被跟踪进程之间进行多次上下文切换。"
#: ../../howto/remote_debugging.rst:238
msgid ""
"For parsing ELF sections, the process involves reading and interpreting the "
"ELF file format structures from the binary file on disk. The ELF header "
"contains a pointer to the section header table. Each section header contains"
" metadata about a section including its name (stored in a separate string "
"table), offset, and size. To find a specific section like .PyRuntime, you "
"need to walk through these headers and match the section name. The section "
"header then provides the offset where that section exists in the file, which"
" can be used to calculate its runtime address when the binary is loaded into"
" memory."
msgstr ""
"为了解析 ELF 节,过程包括从磁盘上的二进制文件中读取和解释 ELF 文件格式结构。ELF "
"头部包含一个指向节头表的指针。每个节头包含有关节的元数据,包括其名称(存储在单独的字符串表中)、偏移量和大小。要查找特定节(如.PyRuntime),需要遍历这些头部并匹配节名称。节头然后提供该节在文件中存在的偏移量,这可以用来计算二进制文件加载到内存时的运行时地址。"
#: ../../howto/remote_debugging.rst:247
msgid ""
"You can read more about the ELF file format in the `ELF specification "
"<https://en.wikipedia.org/wiki/Executable_and_Linkable_Format>`_."
msgstr ""
"你可以在 `ELF 规范 "
"<https://en.wikipedia.org/wiki/Executable_and_Linkable_Format>`_ 中了解更多关于 ELF"
" 文件格式的信息。"
#: ../../howto/remote_debugging.rst:252
msgid "macOS (Mach-O)"
msgstr "macOS (Mach-O)"
#: ../../howto/remote_debugging.rst:253
msgid "To find the ``PyRuntime`` structure on macOS:"
msgstr "在 macOS 上查找 ``PyRuntime`` 结构:"
#: ../../howto/remote_debugging.rst:255
msgid ""
"Call ``task_for_pid()`` to get the ``mach_port_t`` task port for the target "
"process. This handle is needed to read memory using APIs like "
"``mach_vm_read_overwrite`` and ``mach_vm_region``."
msgstr ""
"调用 ``task_for_pid()`` 以获取目标进程的 ``mach_port_t`` 任务端口。此句柄用于通过 "
"``mach_vm_read_overwrite`` 和 ``mach_vm_region`` 等 API 读取内存。"
#: ../../howto/remote_debugging.rst:258
msgid ""
"Scan the memory regions to find the one containing the Python executable or "
"``libpython``."
msgstr "扫描内存区域,找到包含 Python 可执行文件或 ``libpython`` 的区域。"
#: ../../howto/remote_debugging.rst:260
msgid ""
"Load the binary file from disk and parse the Mach-O headers to find the "
"section named ``PyRuntime`` in the ``__DATA`` segment. On macOS, symbol "
"names are automatically prefixed with an underscore, so the ``PyRuntime`` "
"symbol appears as ``_PyRuntime`` in the symbol table, but the section name "
"is not affected."
msgstr ""
"从磁盘加载二进制文件并解析 Mach-O 头部,以在 ``__DATA`` 段中找到名为 ``PyRuntime`` 的节。在 macOS "
"上,符号名称自动以一个下划线为前缀,因此 ``PyRuntime`` 符号在符号表中显示为 ``_PyRuntime``,但节名称不受影响。"
#: ../../howto/remote_debugging.rst:268
msgid ""
"def find_py_runtime_macos(pid: int) -> int:\n"
" # Step 1: Get access to the process's memory\n"
" handle = get_memory_access_handle(pid)\n"
"\n"
" # Step 2: Try to find the Python executable in memory\n"
" binary_path, base_address = find_mapped_binary(\n"
" handle, name_contains=\"python\"\n"
" )\n"
"\n"
" # Step 3: Fallback to libpython if the executable is not found\n"
" if binary_path is None:\n"
" binary_path, base_address = find_mapped_binary(\n"
" handle, name_contains=\"libpython\"\n"
" )\n"
"\n"
" # Step 4: Parse Mach-O headers to get __DATA,__PyRuntime section offset\n"
" section_offset = parse_macho_section_offset(\n"
" binary_path, \"__DATA\", \"__PyRuntime\"\n"
" )\n"
"\n"
" # Step 5: Compute the PyRuntime address in memory\n"
" return base_address + section_offset"
msgstr ""
"def find_py_runtime_macos(pid: int) -> int:\n"
" # 步骤 1:访问进程的内存\n"
" handle = get_memory_access_handle(pid)\n"
"\n"
" # 步骤 2:尝试在内存中找到 Python 可执行文件\n"
" binary_path, base_address = find_mapped_binary(\n"
" handle, name_contains=\"python\"\n"
" )\n"
"\n"
" # 步骤 3:如果找不到可执行文件,则回退到 libpython\n"
" if binary_path is None:\n"
" binary_path, base_address = find_mapped_binary(\n"
" handle, name_contains=\"libpython\"\n"
" )\n"
"\n"
" # 步骤 4:解析 Mach-O 头以获取__DATA,__PyRuntime 段的偏移量\n"
" section_offset = parse_macho_section_offset(\n"
" binary_path, \"__DATA\", \"__PyRuntime\"\n"
" )\n"
"\n"
" # 步骤 5:计算内存中的 PyRuntime 地址\n"
" return base_address + section_offset"
#: ../../howto/remote_debugging.rst:291
msgid ""
"On macOS, accessing another process's memory requires using Mach-O specific "
"APIs and file formats. The first step is obtaining a ``task_port`` handle "
"via ``task_for_pid()``, which provides access to the target process's memory"
" space. This handle enables memory operations through APIs like "
"``mach_vm_read_overwrite()``."
msgstr ""
"在 macOS 上,访问另一个进程的内存需要使用 Mach-O 特定的 API 和文件格式。第一步是通过 ``task_for_pid()`` 获取 "
"``task_port`` 句柄,这提供了对目标进程内存空间的访问。此句柄通过 ``mach_vm_read_overwrite()`` 等 API "
"启用内存操作。"
#: ../../howto/remote_debugging.rst:297
msgid ""
"The process memory can be examined using ``mach_vm_region()`` to scan "
"through the virtual memory space, while ``proc_regionfilename()`` helps "
"identify which binary files are loaded at each memory region. When the "
"Python binary or library is found, its Mach-O headers need to be parsed to "
"locate the ``PyRuntime`` structure."
msgstr ""
"可以使用 ``mach_vm_region()`` 检查进程内存,以扫描虚拟内存空间,而 ``proc_regionfilename()`` "
"帮助识别每个内存区域加载了哪些二进制文件。当找到 Python 二进制文件或库时,需要解析其 Mach-O 头部以定位 ``PyRuntime`` "
"结构。"
#: ../../howto/remote_debugging.rst:302
msgid ""
"The Mach-O format organizes code and data into segments and sections. The "
"``PyRuntime`` structure lives in a section named ``__PyRuntime`` within the "
"``__DATA`` segment. The actual runtime address calculation involves finding "
"the ``__TEXT`` segment which serves as the binary's base address, then "
"locating the ``__DATA`` segment containing our target section. The final "
"address is computed by combining the base address with the appropriate "
"section offsets from the Mach-O headers."
msgstr ""
"Mach-O 格式将代码和数据组织到段和节中。``PyRuntime`` 结构位于 ``__DATA`` 段中的名为 ``__PyRuntime`` "
"的节内。实际的运行时地址计算涉及找到作为二进制文件基址的 ``__TEXT`` 段,然后定位包含目标节的 ``__DATA`` "
"段。最终地址是通过将基址与 Mach-O 头部中的适当节偏移量组合来计算的。"
#: ../../howto/remote_debugging.rst:310
msgid ""
"Note that accessing another process's memory on macOS typically requires "
"elevated privileges - either root access or special security entitlements "
"granted to the debugging process."
msgstr "请注意,在 macOS 上访问另一个进程的内存通常需要提升权限——要么是 root 访问权限,要么是授予调试进程的特殊安全权限。"
#: ../../howto/remote_debugging.rst:316
msgid "Windows (PE)"
msgstr "Windows (PE)"
#: ../../howto/remote_debugging.rst:317
msgid "To find the ``PyRuntime`` structure on Windows:"
msgstr "在 Windows 上查找 ``PyRuntime`` 结构:"
#: ../../howto/remote_debugging.rst:319
msgid ""
"Use the ToolHelp API to enumerate all modules loaded in the target process. "
"This is done using functions such as `CreateToolhelp32Snapshot "
"<https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-"
"tlhelp32-createtoolhelp32snapshot>`_, `Module32First "
"<https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-"
"tlhelp32-module32first>`_, and `Module32Next "
"<https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-"
"tlhelp32-module32next>`_."
msgstr ""
"使用 ToolHelp API 枚举目标进程中加载的所有模块。这通过使用如 `CreateToolhelp32Snapshot "
"<https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-"
"tlhelp32-createtoolhelp32snapshot>`_, `Module32First "
"<https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-"
"tlhelp32-module32first>`_, 和 `Module32Next <https://learn.microsoft.com/en-"
"us/windows/win32/api/tlhelp32/nf-tlhelp32-module32next>`_ 等函数来完成。"
#: ../../howto/remote_debugging.rst:326
msgid ""
"Identify the module corresponding to :file:`python.exe` or "
":file:`python{XY}.dll`, where ``X`` and ``Y`` are the major and minor "
"version numbers of the Python version, and record its base address."
msgstr ""
"识别对应于 :file:`python.exe` 或 :file:`python{XY}.dll` 的模块,其中 ``X`` 和 ``Y`` 是 "
"Python 版本的主次版本号,并记录其基址。"
#: ../../howto/remote_debugging.rst:329
msgid ""
"Locate the ``PyRuntim`` section. Due to the PE format's 8-character limit on"
" section names (defined as ``IMAGE_SIZEOF_SHORT_NAME``), the original name "
"``PyRuntime`` is truncated. This section contains the ``PyRuntime`` "
"structure."
msgstr ""
"定位 ``PyRuntim`` 节。由于 PE 格式对节名称有 8 个字符的限制 (定义为 "
"``IMAGE_SIZEOF_SHORT_NAME``),原始名称 ``PyRuntime`` 被截断。 此节包含 ``PyRuntime`` 结构。"
#: ../../howto/remote_debugging.rst:333
msgid ""
"Retrieve the section’s relative virtual address (RVA) and add it to the base"
" address of the module."
msgstr "检索节的相对虚拟地址(RVA),并将其添加到模块的基址。"
#: ../../howto/remote_debugging.rst:338
msgid ""
"def find_py_runtime_windows(pid: int) -> int:\n"
" # Step 1: Try to find the Python executable in memory\n"
" binary_path, base_address = find_loaded_module(\n"
" pid, name_contains=\"python\"\n"
" )\n"
"\n"
" # Step 2: Fallback to shared pythonXY.dll if the executable is not\n"
" # found\n"
" if binary_path is None:\n"
" binary_path, base_address = find_loaded_module(\n"
" pid, name_contains=\"python3\"\n"
" )\n"
"\n"
" # Step 3: Parse PE section headers to get the RVA of the PyRuntime\n"
" # section. The section name appears as \"PyRuntim\" due to the\n"
" # 8-character limit defined by the PE format (IMAGE_SIZEOF_SHORT_NAME).\n"
" section_rva = parse_pe_section_offset(binary_path, \"PyRuntim\")\n"
"\n"
" # Step 4: Compute PyRuntime address in memory\n"
" return base_address + section_rva"
msgstr ""
"def find_py_runtime_windows(pid: int) -> int:\n"
" # 步骤 1:尝试在内存中找到 Python 可执行文件\n"
" binary_path, base_address = find_loaded_module(\n"
" pid, name_contains=\"python\"\n"
" )\n"
"\n"
" # 步骤 2:如果可执行文件未找到,则回退到共享的 pythonXY.dll\n"
" if binary_path is None:\n"
" binary_path, base_address = find_loaded_module(\n"
" pid, name_contains=\"python3\"\n"
" )\n"
"\n"
" # 步骤 3:解析 PE 节头以获取 PyRuntime 节的相对虚拟地址(RVA)。\n"
" # 由于 PE 格式(IMAGE_SIZEOF_SHORT_NAME)规定的 8 字符限制,\n"
" # 该节的名称显示为\"PyRuntim\"。\n"
" section_rva = parse_pe_section_offset(binary_path, \"PyRuntim\")\n"
"\n"
" # 步骤 4:计算内存中的 PyRuntime 地址\n"
" return base_address + section_rva"
#: ../../howto/remote_debugging.rst:360
msgid ""
"On Windows, accessing another process's memory requires using the Windows "
"API functions like ``CreateToolhelp32Snapshot()`` and "
"``Module32First()/Module32Next()`` to enumerate loaded modules. The "
"``OpenProcess()`` function provides a handle to access the target process's "
"memory space, enabling memory operations through ``ReadProcessMemory()``."
msgstr ""
"在 Windows 上,访问另一个进程的内存需要使用 Windows API 函数,如 ``CreateToolhelp32Snapshot()``"
" 和 ``Module32First()/Module32Next()`` 来枚举已加载的模块。``OpenProcess()`` "
"函数提供了一个句柄,用于访问目标进程的内存空间,通过 ``ReadProcessMemory()`` 实现内存操作。"
#: ../../howto/remote_debugging.rst:366
msgid ""
"The process memory can be examined by enumerating loaded modules to find the"
" Python binary or DLL. When found, its PE headers need to be parsed to "
"locate the ``PyRuntime`` structure."
msgstr ""
"可以通过枚举已加载的模块来检查进程内存,以找到 Python 二进制文件或 DLL。找到后,需要解析其 PE 头以定位 ``PyRuntime`` "
"结构。"
#: ../../howto/remote_debugging.rst:370
msgid ""
"The PE format organizes code and data into sections. The ``PyRuntime`` "
"structure lives in a section named \"PyRuntim\" (truncated from "
"\"PyRuntime\" due to PE's 8-character name limit). The actual runtime "
"address calculation involves finding the module's base address from the "
"module entry, then locating our target section in the PE headers. The final "
"address is computed by combining the base address with the section's virtual"
" address from the PE section headers."
msgstr ""
"PE 格式将代码和数据组织到节中。``PyRuntime`` 结构位于名为 \"PyRuntim\" 的节中(由于 PE 的 8 字符名称限制,从 "
"\"PyRuntime\" 截断)。实际的运行时地址计算涉及从模块入口找到模块的基址,然后在 PE 头中定位目标节。最终地址是通过将基址与 PE "
"节头中的节的虚拟地址组合来计算的。"
#: ../../howto/remote_debugging.rst:377
msgid ""
"Note that accessing another process's memory on Windows typically requires "
"appropriate privileges - either administrative access or the "
"``SeDebugPrivilege`` privilege granted to the debugging process."
msgstr ""
"请注意,在 Windows 上访问另一个进程的内存通常需要适当的权限——要么是管理员访问权限,要么是授予调试进程的 "
"``SeDebugPrivilege`` 权限。"
#: ../../howto/remote_debugging.rst:383
msgid "Reading _Py_DebugOffsets"
msgstr "读取_Py_DebugOffsets"
#: ../../howto/remote_debugging.rst:385
msgid ""
"Once the address of the ``PyRuntime`` structure has been determined, the "
"next step is to read the ``_Py_DebugOffsets`` structure located at the "
"beginning of the ``PyRuntime`` block."
msgstr ""
"一旦确定了 ``PyRuntime`` 结构的地址,下一步就是读取位于 ``PyRuntime`` 块开头的 ``_Py_DebugOffsets``"
" 结构。"
#: ../../howto/remote_debugging.rst:389
msgid ""
"This structure provides version-specific field offsets that are needed to "
"safely read interpreter and thread state memory. These offsets vary between "
"CPython versions and must be checked before use to ensure they are "
"compatible."
msgstr ""
"该结构提供了特定版本的字段偏移量,这些偏移量用于安全地读取解释器和线程状态内存。这些偏移量在 CPython "
"版本之间有所变化,必须在使用前进行检查以确保它们是兼容的。"
#: ../../howto/remote_debugging.rst:393
msgid "To read and check the debug offsets, follow these steps:"
msgstr "要读取和检查调试偏移量,请按照以下步骤操作:"
#: ../../howto/remote_debugging.rst:395
msgid ""
"Read memory from the target process starting at the ``PyRuntime`` address, "
"covering the same number of bytes as the ``_Py_DebugOffsets`` structure. "
"This structure is located at the very start of the ``PyRuntime`` memory "
"block. Its layout is defined in CPython’s internal headers and stays the "
"same within a given minor version, but may change in major versions."
msgstr ""
"从目标进程的 ``PyRuntime`` 地址开始读取内存,覆盖的字节数与 ``_Py_DebugOffsets`` 结构相同。该结构位于 "
"``PyRuntime`` 内存块的起始位置。其布局在 CPython 的内部头文件中定义,并在给定的小版本中保持不变,但在大版本中可能会发生变化。"
#: ../../howto/remote_debugging.rst:401
msgid "Check that the structure contains valid data:"
msgstr "检查该结构是否包含有效数据:"
#: ../../howto/remote_debugging.rst:403
msgid "The ``cookie`` field must match the expected debug marker."
msgstr "``cookie`` 字段必须与预期的调试标记匹配。"
#: ../../howto/remote_debugging.rst:404
msgid ""
"The ``version`` field must match the version of the Python interpreter used "
"by the debugger."
msgstr "``version`` 字段必须与调试器使用的 Python 解释器版本匹配。"
#: ../../howto/remote_debugging.rst:406
msgid ""
"If either the debugger or the target process is using a pre-release version "
"(for example, an alpha, beta, or release candidate), the versions must match"
" exactly."
msgstr "如果调试器或目标进程使用的是预发布版本(例如,alpha、beta 或发布候选版本),则版本必须完全匹配。"
#: ../../howto/remote_debugging.rst:409
msgid ""
"The ``free_threaded`` field must have the same value in both the debugger "
"and the target process."
msgstr "``free_threaded`` 字段在调试器和目标进程中必须具有相同的值。"
#: ../../howto/remote_debugging.rst:412
msgid ""
"If the structure is valid, the offsets it contains can be used to locate "
"fields in memory. If any check fails, the debugger should stop the operation"
" to avoid reading memory in the wrong format."
msgstr "如果结构体有效,其中包含的偏移量可以用于定位内存中的字段。如果任何检查失败,调试器应停止操作,以避免以错误格式读取内存。"
#: ../../howto/remote_debugging.rst:416
msgid ""
"The following is an example implementation that reads and checks "
"``_Py_DebugOffsets``::"
msgstr "以下是一个读取和检查 ``_Py_DebugOffsets`` 的示例实现::"
#: ../../howto/remote_debugging.rst:419
msgid ""
"def read_debug_offsets(pid: int, py_runtime_addr: int) -> DebugOffsets:\n"
" # Step 1: Read memory from the target process at the PyRuntime address\n"
" data = read_process_memory(\n"
" pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE\n"
" )\n"
"\n"
" # Step 2: Deserialize the raw bytes into a _Py_DebugOffsets structure\n"
" debug_offsets = parse_debug_offsets(data)\n"
"\n"
" # Step 3: Validate the contents of the structure\n"
" if debug_offsets.cookie != EXPECTED_COOKIE:\n"
" raise RuntimeError(\"Invalid or missing debug cookie\")\n"
" if debug_offsets.version != LOCAL_PYTHON_VERSION:\n"
" raise RuntimeError(\n"
" \"Mismatch between caller and target Python versions\"\n"
" )\n"
" if debug_offsets.free_threaded != LOCAL_FREE_THREADED:\n"
" raise RuntimeError(\"Mismatch in free-threaded configuration\")\n"
"\n"
" return debug_offsets"
msgstr ""
"def read_debug_offsets(pid: int, py_runtime_addr: int) -> DebugOffsets:\n"
" # 步骤 1:从目标进程中读取 PyRuntime 地址处的内存\n"
" data = read_process_memory(\n"
" pid, address=py_runtime_addr, size=DEBUG_OFFSETS_SIZE\n"
" )\n"
"\n"
" # 步骤 2:将原始字节反序列化为_Py_DebugOffsets 结构体\n"
" debug_offsets = parse_debug_offsets(data)\n"
"\n"
" # 步骤 3:验证结构体的内容\n"
" if debug_offsets.cookie != EXPECTED_COOKIE:\n"
" raise RuntimeError(\"Invalid or missing debug cookie\")\n"
" if debug_offsets.version != LOCAL_PYTHON_VERSION:\n"
" raise RuntimeError(\n"
" \"Mismatch between caller and target Python versions\"\n"
" )\n"
" if debug_offsets.free_threaded != LOCAL_FREE_THREADED:\n"
" raise RuntimeError(\"Mismatch in free-threaded configuration\")\n"
"\n"
" return debug_offsets"
#: ../../howto/remote_debugging.rst:444
msgid "**Process suspension recommended**"
msgstr "**建议挂起进程**"
#: ../../howto/remote_debugging.rst:446
msgid ""
"To avoid race conditions and ensure memory consistency, it is strongly "
"recommended that the target process be suspended before performing any "
"operations that read or write internal interpreter state. The Python runtime"
" may concurrently mutate interpreter data structures—such as creating or "
"destroying threads—during normal execution. This can result in invalid "
"memory reads or writes."
msgstr ""
"为避免竞态条件并确保内存一致性,在执行任何读取或写入解释器内部状态的操作前,强烈建议先挂起目标进程。Python "
"运行时可能在正常执行期间并发修改解释器数据结构(例如创建或销毁线程),这可能导致无效的内存读写操作。"
#: ../../howto/remote_debugging.rst:453
msgid ""
"A debugger may suspend execution by attaching to the process with ``ptrace``"
" or by sending a ``SIGSTOP`` signal. Execution should only be resumed after "
"debugger-side memory operations are complete."
msgstr ""
"调试器可以通过使用 ``ptrace`` 附加到进程或发送 ``SIGSTOP`` 信号来挂起执行。只有在调试器端的内存操作完成后,才应恢复执行。"
#: ../../howto/remote_debugging.rst:459
msgid ""
"Some tools, such as profilers or sampling-based debuggers, may operate on a "
"running process without suspension. In such cases, tools must be explicitly "
"designed to handle partially updated or inconsistent memory. For most "
"debugger implementations, suspending the process remains the safest and most"
" robust approach."
msgstr ""
"一些工具,如性能分析器或基于采样的调试器,可以在不挂起运行进程的情况下操作。在这种情况下,工具必须明确设计以处理部分更新或不一致的内存。对于大多数调试器实现来说,挂起进程仍然是最安全、最稳健的方法。"
#: ../../howto/remote_debugging.rst:467
msgid "Locating the interpreter and thread state"
msgstr "定位解释器和线程状态"
#: ../../howto/remote_debugging.rst:469
msgid ""
"Before code can be injected and executed in a remote Python process, the "
"debugger must choose a thread in which to schedule execution. This is "
"necessary because the control fields used to perform remote code injection "
"are located in the ``_PyRemoteDebuggerSupport`` structure, which is embedded"
" in a ``PyThreadState`` object. These fields are modified by the debugger to"
" request execution of injected scripts."
msgstr ""
"在远程 Python 进程中注入并执行代码前,调试器必须选定一个目标线程来调度执行。这是因为用于远程代码注入的控制字段位于 "
"``_PyRemoteDebuggerSupport`` 结构体中,而该结构体又嵌入在 ``PyThreadState`` "
"对象内。调试器通过修改这些字段来请求执行已注入的脚本。"
#: ../../howto/remote_debugging.rst:476
msgid ""
"The ``PyThreadState`` structure represents a thread running inside a Python "
"interpreter. It maintains the thread’s evaluation context and contains the "
"fields required for debugger coordination. Locating a valid "
"``PyThreadState`` is therefore a key prerequisite for triggering execution "
"remotely."
msgstr ""
"``PyThreadState`` 结构体表示在 Python "
"解释器内运行的线程。它维护线程的求值上下文,并包含调试器协调所需的字段。因此,定位一个有效的 ``PyThreadState`` "
"是触发远程执行的关键前提。"
#: ../../howto/remote_debugging.rst:481
msgid ""
"A thread is typically selected based on its role or ID. In most cases, the "
"main thread is used, but some tools may target a specific thread by its "
"native thread ID. Once the target thread is chosen, the debugger must locate"
" both the interpreter and the associated thread state structures in memory."
msgstr ""
"通常基于线程的角色或 ID 来选择线程。在大多数情况下,使用主线程,但一些工具可能通过其本地线程 ID "
"定位特定线程。一旦选择了目标线程,调试器必须在内存中定位解释器和相关的线程状态结构。"
#: ../../howto/remote_debugging.rst:486
msgid "The relevant internal structures are defined as follows:"
msgstr "相关内部结构体定义如下:"
#: ../../howto/remote_debugging.rst:488
msgid ""
"``PyInterpreterState`` represents an isolated Python interpreter instance. "
"Each interpreter maintains its own set of imported modules, built-in state, "
"and thread state list. Although most Python applications use a single "
"interpreter, CPython supports multiple interpreters in the same process."
msgstr ""
"``PyInterpreterState`` 表示一个隔离的 Python "
"解释器实例。每个解释器维护其自己的导入模块集、内置状态和线程状态列表。尽管大多数 Python 应用程序使用单个解释器,但 CPython "
"支持在同一进程中使用多个解释器。"
#: ../../howto/remote_debugging.rst:493
msgid ""
"``PyThreadState`` represents a thread running within an interpreter. It "
"contains execution state and the control fields used by the debugger."
msgstr "``PyThreadState`` 表示在解释器内运行的线程。它包含执行状态和调试器使用的控制字段。"
#: ../../howto/remote_debugging.rst:496
msgid "To locate a thread:"
msgstr "要定位一个线程:"
#: ../../howto/remote_debugging.rst:498
msgid ""
"Use the offset ``runtime_state.interpreters_head`` to obtain the address of "
"the first interpreter in the ``PyRuntime`` structure. This is the entry "
"point to the linked list of active interpreters."
msgstr ""
"使用偏移量 ``runtime_state.interpreters_head`` 获取 ``PyRuntime`` "