Skip to content

gh-91428: Add _PyOpcode_OpName to opcode.h of debug builds #91430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Add ``static const char *const _PyOpcode_OpName[256] = {...};`` to
``opcode.h`` for debug builds to assist in debugging the Python interpreter.
It is now more convenient to make various forms of debugging output more
human-readable by including opcode names rather than just the corresponding
decimal digits.
8 changes: 8 additions & 0 deletions Tools/scripts/generate_opcode_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def main(opcode_py, outfile='Include/opcode.h'):
for i, (op, _) in enumerate(opcode["_nb_ops"]):
fobj.write(DEFINE.format(op, i))

fobj.write("\n")
fobj.write("#ifdef Py_DEBUG\n")
fobj.write("static const char *const _PyOpcode_OpName[256] = {\n")
for name in opmap:
fobj.write(f''' [{name}] = "{name}",\n''')
fobj.write("};\n")
fobj.write("#endif\n")

fobj.write(footer)


Expand Down