can't find method

Open
#20 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
cli, compilers

Research direction

Start by reproducing pyc-xasm --pyc-file test .\compiled_code.pyasm with the supplied Python 3.9 bytecode and inspect how the method and constant entries are handled. Done means the greet method is recognized rather than reported as bogus and the sample disassembly is processed successfully.

Written by the indexing model from the issue text.

Description

I got this problem: can't find method greet
appending bogus greet to list of constants

when running pyc-xasm --pyc-file test .\compiled_code.pyasm

this is the code that generated compiled_code.pyasm

source_code = """
def greet():
    print("Hello, world!")
"""

compiled_code = compile(source_code, "<string>", "exec")
pyc_file = "compiled_code.pyasm"
with open(pyc_file, "w") as file:
    xdis.std.disassemble(compiled_code, file=file)

and this is the compiled_code:

# pydisasm version 6.0.5
# Python bytecode 3.9 ()
# Disassembled from Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]
# Method Name:       <module>
# Filename:          <string>
# Argument count:    0
# Position-only argument count: 0
# Keyword-only arguments: 0
# Number of locals:  0
# Stack size:        2
# Flags:             0x00000040 (NOFREE)
# First Line:        2
# Constants:
#    0: <code object greet at 0x000002028CC845B0, file "<string>", line 2>
#    1: 'greet'
#    2: None
# Names:
#    0: greet
  2:           0 LOAD_CONST           (<code object greet at 0x000002028CC845B0, file "<string>", line 2>)
               2 LOAD_CONST           ('greet')
               4 MAKE_FUNCTION        (Neither defaults, keyword-only args, annotations, nor closures)
               6 STORE_NAME           (greet)
               8 LOAD_CONST           (None)
              10 RETURN_VALUE


# Method Name:       greet
# Filename:          <string>
# Argument count:    0
# Position-only argument count: 0
# Keyword-only arguments: 0
# Number of locals:  0
# Stack size:        2
# Flags:             0x00000043 (NOFREE | NEWLOCALS | OPTIMIZED)
# First Line:        2
# Constants:
#    0: None
#    1: 'Hello, world!'
# Names:
#    0: print
  3:           0 LOAD_GLOBAL          (print)
               2 LOAD_CONST           ('Hello, world!')
               4 CALL_FUNCTION        1
               6 POP_TOP
               8 LOAD_CONST           (None)
              10 RETURN_VALUE


Dominant language
Python
Stars
119
Forks
13
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rocky/python-xasm

All issues in rocky/python-xasm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.