예제 #1
0
def Put1(op, a, b, im):
  # (*emit format-1 instruction,  -0x10000 <= im < 0x10000*)
  global pc
  if im < 0:
    op += 0x1000 # (*set v-bit*)
##    im = abs(im)
  n = code[pc] = (((a+0x40) * 0x10 + b) * 0x10 + op) * 0x10000 + (im % 0x10000); pc += 1
  print >> sys.stderr, dis(n)
예제 #2
0
def Put1(op, a, b, im):
    # (*emit format-1 instruction,  -0x10000 <= im < 0x10000*)
    global pc
    if im < 0:
        op += 0x1000  # (*set v-bit*)


##    im = abs(im)
    n = code[pc] = ((
        (a + 0x40) * 0x10 + b) * 0x10 + op) * 0x10000 + (im % 0x10000)
    pc += 1
    print >> sys.stderr, dis(n)
예제 #3
0
파일: traces.py 프로젝트: alex/tracebin
    def _split_section(cls, ops, i, call_id, chunks, dis_cache):
        start_idx = i
        current_line = None

        while i < len(ops):
            op = ops[i]
            if op.name == "debug_merge_point":
                if op.call_id > call_id:
                    chunks.append(
                        ResOpChunk(ops[start_idx:i])
                    )
                    i = start_idx = cls._split_section(ops, i, op.call_id, chunks, dis_cache)
                elif op.call_id < call_id:
                    chunks.append(
                        ResOpChunk(ops[start_idx:i])
                    )
                    return i
                else:
                    if op.pycode not in dis_cache:
                        dis_cache[op.pycode] = disassembler.dis(op.pycode)
                    code = dis_cache[op.pycode]
                    py_op = code.map[op.bytecode_no]
                    sourcecode, startline = inspect.getsourcelines(code.co)

                    if current_line is None or py_op.lineno > current_line:
                        if start_idx != i:
                            chunks.append(
                                ResOpChunk(ops[start_idx:i])
                            )
                        lines_end = py_op.lineno - startline
                        if current_line is None:
                            source = sourcecode[:lines_end + 1]
                            linenos = range(startline, py_op.lineno + 1)
                        else:
                            source = [sourcecode[lines_end]]
                            linenos = [py_op.lineno]
                        chunks.append(PythonChunk(source, linenos))
                        current_line = py_op.lineno
                        start_idx = i
            i += 1
        if start_idx < len(ops):
            chunks.append(ResOpChunk(ops[start_idx:]))
        return i
예제 #4
0
    def _split_section(cls, ops, i, call_id, chunks, dis_cache):
        start_idx = i
        current_line = None

        while i < len(ops):
            op = ops[i]
            if op.name == "debug_merge_point":
                if op.call_id > call_id:
                    chunks.append(ResOpChunk(ops[start_idx:i]))
                    i = start_idx = cls._split_section(ops, i, op.call_id,
                                                       chunks, dis_cache)
                elif op.call_id < call_id:
                    chunks.append(ResOpChunk(ops[start_idx:i]))
                    return i
                else:
                    if op.pycode not in dis_cache:
                        dis_cache[op.pycode] = disassembler.dis(op.pycode)
                    code = dis_cache[op.pycode]
                    py_op = code.map[op.bytecode_no]
                    sourcecode, startline = inspect.getsourcelines(code.co)

                    if current_line is None or py_op.lineno > current_line:
                        if start_idx != i:
                            chunks.append(ResOpChunk(ops[start_idx:i]))
                        lines_end = py_op.lineno - startline
                        if current_line is None:
                            source = sourcecode[:lines_end + 1]
                            linenos = range(startline, py_op.lineno + 1)
                        else:
                            source = [sourcecode[lines_end]]
                            linenos = [py_op.lineno]
                        chunks.append(PythonChunk(source, linenos))
                        current_line = py_op.lineno
                        start_idx = i
            i += 1
        if start_idx < len(ops):
            chunks.append(ResOpChunk(ops[start_idx:]))
        return i
예제 #5
0
def Put3(op, cond, off):
    # (*emit branch instruction*)
    global pc
    n = code[pc] = ((op + 12) * 0x10 + cond) * 0x1000000 + (off % 0x1000000)
    pc += 1
    print >> sys.stderr, dis(n)
예제 #6
0
def Put2(op, a, b, off):
    # (*emit load/store instruction*)
    global pc
    n = code[pc] = ((op * 0x10 + a) * 0x10 + b) * 0x100000 + (off % 0x100000)
    pc += 1
    print >> sys.stderr, dis(n)
예제 #7
0
def Put0(op, a, b, c):
    # (*emit format-0 instruction*)
    global pc
    n = code[pc] = ((a * 0x10 + b) * 0x10 + op) * 0x10000 + c
    pc += 1
    print >> sys.stderr, dis(n)
예제 #8
0
if len(sys.argv) > 1:
    modname = sys.argv[-1].partition('.')[0]
else:
    modname = 'Files'

#fn = '/home/sforman/Desktop/Oberon/PO/Kernel.Mod.txt'
fn = modname + '.Mod.txt'

text = open(fn).read()
try:
    ORPX.Compile(text)
except:
    print >> sys.stderr
    print >> sys.stderr, '-' * 40
    print >> sys.stderr, 'Error near line %i, character %i' % (
        text[:ORSX._pos].count('\n') + 1,
        ORSX._pos,
    )
    print >> sys.stderr, text[ORSX._pos - 20:ORSX._pos],
    print >> sys.stderr, '^^Err^^',
    print >> sys.stderr, text[ORSX._pos:ORSX._pos + 20]
    print >> sys.stderr, '-' * 40
    raise

for k in sorted(ORGX.code):
    I = ORGX.code[k]
    s = bin(I)[2:]
    s = '0' * (32 - len(s)) + s
    print s, '%08x' % (I, ), disassembler.dis(I)
예제 #9
0
if len(sys.argv) > 1:
  modname = sys.argv[-1].partition('.')[0]
else:
  modname = 'Files'

#fn = '/home/sforman/Desktop/Oberon/PO/Kernel.Mod.txt'
fn = modname + '.Mod.txt'

text = open(fn).read()
try:
  ORPX.Compile(text)
except:
  print >> sys.stderr
  print >> sys.stderr, '-' * 40
  print >> sys.stderr, 'Error near line %i, character %i' % (
    text[:ORSX._pos].count('\n') + 1,
    ORSX._pos,
    )
  print >> sys.stderr, text[ORSX._pos - 20:ORSX._pos],
  print >> sys.stderr, '^^Err^^',
  print >> sys.stderr, text[ORSX._pos:ORSX._pos + 20]
  print >> sys.stderr, '-' * 40
  raise

for k in sorted(ORGX.code):
  I = ORGX.code[k]
  s = bin(I)[2:]
  s = '0' * (32 - len(s)) + s
  print s, '%08x' % (I,), disassembler.dis(I)
예제 #10
0
def Put3(op, cond, off):
  # (*emit branch instruction*)
  global pc
  n = code[pc] = ((op+12) * 0x10 + cond) * 0x1000000 + (off % 0x1000000); pc += 1
  print >> sys.stderr, dis(n)
예제 #11
0
def Put2(op, a, b, off):
  # (*emit load/store instruction*)
  global pc
  n = code[pc] = ((op * 0x10 + a) * 0x10 + b) * 0x100000 + (off % 0x100000); pc += 1
  print >> sys.stderr, dis(n)
예제 #12
0
def Put0(op, a, b, c):
  # (*emit format-0 instruction*)
  global pc
  n = code[pc] = ((a*0x10 + b) * 0x10 + op) * 0x10000 + c; pc += 1
  print >> sys.stderr, dis(n)