Where am I now — Really?

Decompilation for Precise Program Location Information

(enter "s" to see presenter text for slides)

Line numbers are not good enough


x = prev[prev[0]]                      # which prev ?
y = a / b / c                          # which divide is invalid?
[x[0] for i in d[j] if got[i] == e[i]] # lots going on here
exec("a=%s; b=y" % z)                  # code created at runtime

Python 3.6 bytecode


prev[prev[0]]
compiles to:

  2       10 LOAD_NAME           prev
          12 LOAD_NAME           prev
          14 LOAD_CONST          0
          16 BINARY_SUBSCR
          18 BINARY_SUBSCR
          20 POP_TOP

English Sentence Parse

“I ate the mango.”

    sentence
     0. subject
        pronoun, first person
          I
     1. verb, past tense
          ate
     2. object
          noun phrase
          0. definite article
             the
          1. noun
             mango
    3. punctuation
             .

Bytecode Assembly Parse

stmts (4)
  ...
  1. stmt
    0. expr
       binary_subscr
         0. expr
            L.   2      10  LOAD_NAME 'prev'
         1. expr
            binary_subscr
            0. expr
                        12  LOAD_NAME 'prev'
            1. expr
                        14  LOAD_CONST 0
            2.          16  BINARY_SUBSCR
        2.          18  BINARY_SUBSCR
    1.          20  POP_TOP

Bytecode assembly Parse

2 10 LOAD_NAME "prev"
  12 LOAD_NAME "prev"
  14 LOAD_CONST 0
  16 BINARY_SUBSCR
  18 BINARY_SUBSCR
when parsed becomes:
    0. expr
       binary_subscr
         0. expr
            L.   2      10  LOAD_NAME 'prev'
         1. expr
            binary_subscr
            0. expr
                        12  LOAD_NAME 'prev'
            1. expr
                        14  LOAD_CONST 0
            2.          16  BINARY_SUBSCR
         2.          18  BINARY_SUBSCR
...

Displaying the results

At offset 16:
instruction      16  BINARY_SUBSCR

prev[prev[0]]
     -------
At offset 18:
instruction      18  BINARY_SUBSCR

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

This comes from the tree structure in the parse.

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...






- end