Decompilation, Translation, and Debugging

Where am I now — Really?

(enter "s" to see presenter text for slides; video is here.)

A Python Error


Traceback (most recent call last):
  File "bug.py", line 2, in <module>
    i / j / k
ZeroDivisionError: integer division or modulo by zero
		

Was j zero, or was k zero?

More errors where line numbers are not good enough


x = prev[prev[0]]                      # which prev ?
		

[e[0] for i in d[j] if got[i] == e[i]] # lots going on here
		

exec(some_code % 10, namespace)        # code at runtime
		

An Error where no file exists


exec(some_code)
		

Traceback (most recent call last):
  File "bug-exec.py", line 3, in <module>
    exec(template % 10, namespace)
  File "<string>", line 1, in <module>
NameError: name 'bad' is not defined
		

File "<string>"?

Programmer to Computer

A programmer may write:


  x + y
		

but the C Python interpreter sees:


  2:  8 LOAD_NAME    x
     10 LOAD_NAME    y
     12 BINARY_ADD
		

Spanish to English

A person says in Spanish: “mango fragante”
might translate in English to: “fragrant mango”

A person says in Spanish: “Entiendo”
might translate in English to: “I understand”

A person says in Spanish: “templado”
might translate in English to: “not hot and not cold”

Side-by-side Translation

1: Whose woods these are I think I know.
2: His house is in the village though

1: A quién pertenece este bosque creo que sé
2: Aunque su casa en el pueblo está

Side-by-side Translation

1: Whose woods these are I think I know.
2: His house is in the village though

1: A quién pertenece este bosque creo que sé
2: Aunque su casa en el pueblo está

Side-by-side Translation

1: Whose woods these are I think I know.
2: His house is in the village though

1: A quién pertenece este bosque creo que sé
2: Aunque su casa en el pueblo está

Side-by-side Python translation


  x = 1  # line 1
  y = 2  # line 2
		

  1: 0 LOAD_CONST  1
     2 STORE_NAME  x

  2: 4 LOAD_CONST  2
     6 STORE_NAME  y
    

English Sentence Parse

“I eat tripe.”

“I eat tripe.”
    sentence
      0. subject
        pronoun
          I
      1. predicate
         0. verb
            eat
         1. object
            tripe
			

Spanish Sentence Parse

“Como mondongo.”

“Como mondongo.”
    sentence
    0. subject
         I
      1. predicate
         0. verb
            eat
         1. object
            mondongo
		

Bytecode Parse

 prev[prev[0]]

parses to:

translates to:


2  6 LOAD_NAME "prev"
   8 LOAD_NAME "prev"
  10 LOAD_CONST 0
  12 BINARY_SUBSCR
  14 BINARY_SUBSCR
				

uncompyle6 (de)parses to:

In listing form:


       Subscript
         0. Expr
            L.   2       6  LOAD_NAME 'prev'
         1. Expr
            Subscript
            0. Expr
                         8  LOAD_NAME 'prev'
            1. Expr
                        10  LOAD_CONST 0
            2.          12  BINARY_SUBSCR
         2.          14  BINARY_SUBSCR
...
			

Parse to Text

With Instruction Operands

With "Expr" rule

With "Subscr" rule

Parse at offset 12

Parse at offset 12 Display

instruction      12  BINARY_SUBSCR

prev[prev[0]]
     -------
				

Parse at offset 14

Parse at offset 14 Text display

instruction      14  BINARY_SUBSCR

prev[prev[0]]
-------------
		  

trepan2 help

deparsing comprehension errors

Debugging code created at runtime

Debugging code when there is no source

There is more to do...

Emacs Lisp:

(/ a (/ b c)))
			
gives:

0	varref	  a
1	varref	  b
2	varref	  c
3	quo
4	quo
5	return
			

Links...












- fin