Skip to content

Commit 8a35ce3

Browse files
authored
gh-91428: Add _PyOpcode_OpName to opcode.h of debug builds (GH-91430)
1 parent 3869a83 commit 8a35ce3

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

Include/opcode.h

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Add ``static const char *const _PyOpcode_OpName[256] = {...};`` to
2+
``opcode.h`` for debug builds to assist in debugging the Python interpreter.
3+
It is now more convenient to make various forms of debugging output more
4+
human-readable by including opcode names rather than just the corresponding
5+
decimal digits.

Tools/scripts/generate_opcode_h.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ def main(opcode_py, outfile='Include/opcode.h'):
108108
for i, (op, _) in enumerate(opcode["_nb_ops"]):
109109
fobj.write(DEFINE.format(op, i))
110110

111+
fobj.write("\n")
112+
fobj.write("#ifdef Py_DEBUG\n")
113+
fobj.write("static const char *const _PyOpcode_OpName[256] = {\n")
114+
for name in opmap:
115+
fobj.write(f''' [{name}] = "{name}",\n''')
116+
fobj.write("};\n")
117+
fobj.write("#endif\n")
118+
111119
fobj.write(footer)
112120

113121

0 commit comments

Comments
 (0)