From dfb0a976c541555ff9c6b01618bbf767a8d324df Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 5 Dec 2022 09:12:39 -0800 Subject: [PATCH] Add additional Code object fields to disassembly output. --- pycdas.cpp | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/pycdas.cpp b/pycdas.cpp index e0fb5f9..d0d44a8 100644 --- a/pycdas.cpp +++ b/pycdas.cpp @@ -86,48 +86,67 @@ void output_object(PycRef obj, PycModule* mod, int indent) iputs(indent, "[Code]\n"); iprintf(indent + 1, "File Name: %s\n", codeObj->fileName()->value()); iprintf(indent + 1, "Object Name: %s\n", codeObj->name()->value()); + if (mod->verCompare(3, 11) >= 0) + iprintf(indent + 1, "Qualified Name: %s\n", codeObj->qualName()->value()); iprintf(indent + 1, "Arg Count: %d\n", codeObj->argCount()); if (mod->verCompare(3, 8) >= 0) iprintf(indent + 1, "Pos Only Arg Count: %d\n", codeObj->posOnlyArgCount()); if (mod->majorVer() >= 3) iprintf(indent + 1, "KW Only Arg Count: %d\n", codeObj->kwOnlyArgCount()); - iprintf(indent + 1, "Locals: %d\n", codeObj->numLocals()); - iprintf(indent + 1, "Stack Size: %d\n", codeObj->stackSize()); - iprintf(indent + 1, "Flags: 0x%08X", codeObj->flags()); - print_coflags(codeObj->flags()); - - if (codeObj->names() != NULL) { - iputs(indent + 1, "[Names]\n"); - for (int i=0; inames()->size(); i++) - output_object(codeObj->names()->get(i), mod, indent + 2); + if (mod->verCompare(3, 11) < 0) + iprintf(indent + 1, "Locals: %d\n", codeObj->numLocals()); + if (mod->verCompare(1, 5) >= 0) + iprintf(indent + 1, "Stack Size: %d\n", codeObj->stackSize()); + if (mod->verCompare(1, 3) >= 0) { + iprintf(indent + 1, "Flags: 0x%08X", codeObj->flags()); + print_coflags(codeObj->flags()); } - if (codeObj->varNames() != NULL) { + iputs(indent + 1, "[Names]\n"); + for (int i=0; inames()->size(); i++) + output_object(codeObj->names()->get(i), mod, indent + 2); + + if (mod->verCompare(1, 3) >= 0 && mod->verCompare(3, 11) < 0) { iputs(indent + 1, "[Var Names]\n"); for (int i=0; ivarNames()->size(); i++) output_object(codeObj->varNames()->get(i), mod, indent + 2); } - if (codeObj->freeVars() != NULL) { + if (mod->verCompare(2, 1) >= 0 && mod->verCompare(3, 11) < 0) { iputs(indent + 1, "[Free Vars]\n"); for (int i=0; ifreeVars()->size(); i++) output_object(codeObj->freeVars()->get(i), mod, indent + 2); - } - if (codeObj->cellVars() != NULL) { iputs(indent + 1, "[Cell Vars]\n"); for (int i=0; icellVars()->size(); i++) output_object(codeObj->cellVars()->get(i), mod, indent + 2); } - if (codeObj->consts() != NULL) { - iputs(indent + 1, "[Constants]\n"); - for (int i=0; iconsts()->size(); i++) - output_object(codeObj->consts()->get(i), mod, indent + 2); + if (mod->verCompare(3, 11) >= 0) { + iputs(indent + 1, "[Locals+Names]\n"); + for (int i=0; ilocalsAndNames()->size(); i++) + output_object(codeObj->localsAndNames()->get(i), mod, indent + 2); + + iputs(indent + 1, "[Locals+Kinds]\n"); + output_object(codeObj->localsAndKinds().cast(), mod, indent + 2); } + iputs(indent + 1, "[Constants]\n"); + for (int i=0; iconsts()->size(); i++) + output_object(codeObj->consts()->get(i), mod, indent + 2); + iputs(indent + 1, "[Disassembly]\n"); bc_disasm(codeObj, mod, indent + 2); + + if (mod->verCompare(1, 5) >= 0) { + iputs(indent + 1, "[Line Number Table]\n"); + output_object(codeObj->lnTable().cast(), mod, indent + 2); + } + + if (mod->verCompare(3, 11) >= 0) { + iputs(indent + 1, "[Exception Table]\n"); + output_object(codeObj->exceptTable().cast(), mod, indent + 2); + } } break; case PycObject::TYPE_STRING: