GrammaTech / gtirb-rewriting

Python API for rewriting GTIRB files
GNU General Public License v3.0
16 stars 3 forks source link

Example is not clear for me. AttributeError: 'ellipsis' object has no attribute '_function_matches' #1

Closed swang206 closed 3 years ago

swang206 commented 3 years ago

https://github.com/GrammaTech/gtirb-rewriting/blob/68872e364c8e8a2cc65e14455727c419ebb4b37e/doc/Getting-Started.md#inserting-a-function-call

# at the top of the file
from gtirb_rewriting.patches import CallPatch

# in a Pass's begin_module callback:
exit_sym = context.get_or_insert_extern_symbol('exit', 'libc.so.6')
context.register_insert(..., CallPatch(exit_sym, [42]))

I just run this program:

import argparse
import logging

import gtirb
import gtirb_functions

from gtirb_rewriting import *
from gtirb_rewriting.patches import CallPatch

class NopPass(Pass):
    def begin_module(self, module, functions, context):
        exit_sym = context.get_or_insert_extern_symbol('exit', 'libc.so.6')
        context.register_insert(..., CallPatch(exit_sym, [42]))

def main():
    logging.basicConfig(format="%(message)s")

    ap = argparse.ArgumentParser()
    ap.add_argument("infile")
    ap.add_argument("outfile")
    ap.add_argument("--verbose", action="store_true")
    args = ap.parse_args()

    if args.verbose:
        logging.getLogger("gtirb_rewriting").setLevel(logging.DEBUG)

    ir = gtirb.IR.load_protobuf(args.infile)

    pass_man = PassManager()
    pass_man.add(NopPass())
    pass_man.run(ir)

    ir.save_protobuf(args.outfile)

if __name__ == "__main__":
    main()

but I get errors:

(base) cqwrteur@BU-Precision-Tower-5810:~/fast_io_cleanup/npp64test/gtirb-rewrite$ python dis2.py ./hw.ir ./hw_ir.out
Traceback (most recent call last):
  File "/home/cqwrteur/fast_io_cleanup/npp64test/gtirb-rewrite/dis2.py", line 38, in <module>
    main()
  File "/home/cqwrteur/fast_io_cleanup/npp64test/gtirb-rewrite/dis2.py", line 33, in main
    pass_man.run(ir)
  File "/home/cqwrteur/miniconda3/lib/python3.9/site-packages/gtirb_rewriting-0.0.22.dev0-py3.9.egg/gtirb_rewriting/passes.py", line 104, in run
  File "/home/cqwrteur/miniconda3/lib/python3.9/site-packages/gtirb_rewriting-0.0.22.dev0-py3.9.egg/gtirb_rewriting/rewriting.py", line 545, in apply
  File "/home/cqwrteur/miniconda3/lib/python3.9/site-packages/gtirb_rewriting-0.0.22.dev0-py3.9.egg/gtirb_rewriting/rewriting.py", line 548, in <listcomp>
AttributeError: 'ellipsis' object has no attribute '_function_matches'

Can you write full python code in an examples folder for all Common Tasks & Questions?

swang206 commented 3 years ago

it looks like it is ...'s problem

close