tl;dr; if you want a backtrace with symbols when running the eval.l version of 
maru take a look at the script below

I love reading through x86 assembly as much as the next hacker but as I've 
found myself playing around in eval.l and introducing segfaults it's a little 
slow to figure out where I went wrong.

I first started going down the path of changing emit.l to support Dwarf debug 
symbols but quickly realized how much of a pointless rathole that was.

Thankfully, we generate the assembly and comment it nicely. So I wrote a little 
script to go from gdb backtraces to symbol traces.

e.g.

In your gdb session:

% gdb eval
> r test.l
> ...
> bt
#0  0x00ba1224 in ?? ()
#1  0x0002142d in __L__2865 ()
#2  0x00021860 in __L__2889 ()
#3  0x0002122b in __L__2856 ()
#4  0x000216a2 in __L__2877 ()
#5  0x00006671 in __L__357 ()
#6  0x00004bb7 in __L__223 ()
#7  0x00002145 in start ()


In another terminal

% gdb-bt maru-eval.s "#0  0x00ba1224 in ?? ()
#1  0x0002142d in __L__2865 ()
#2  0x00021860 in __L__2889 ()
#3  0x0002122b in __L__2856 ()
#4  0x000216a2 in __L__2877 ()
#5  0x00006671 in __L__357 ()
#6  0x00004bb7 in __L__223 ()
#7  0x00002145 in start ()"
-------------


#0  0x00ba1224 in ?? ():        ?
#1  0x0002142d in __L__2865 (): read_list
#2  0x00021860 in __L__2889 (): k_read
#3  0x0002122b in __L__2856 (): read_quote
#4  0x000216a2 in __L__2877 (): k_read
#5  0x00006671 in __L__357 ():  repl_stream
#6  0x00004bb7 in __L__223 ():  main

cheers,
shawn



#!/usr/bin/env python

import re
import sys
import os


# Inferring symbols from lables
def find_label(symbol, asm):
    match = re.search("^_%s:$" % symbol, asm, re.MULTILINE)
    if not match:
        return -1
    return match.start()

def funcname_for_index(index, asm):
    if index < 0:
        return "?"

    name_start = asm.rfind("## defunc ", 0, index)
    match = re.search("^## defunc ([_a-zA-Z0-9]*)", asm[name_start:])
    return match.groups(0)[0].strip()

def symbol(label, asm):
    return funcname_for_index(find_label(label, asm), asm)


# Extracting labels from GCC backtraces
def extract_label(bt_entry):
    return re.search("in (.*) \(\)", bt_entry).groups()[0]

def extract_labels(backtrace_entries):
    return [extract_label(bt_entry) for bt_entry in backtrace_entries]


# Generating the symbolicated BT
def symbolicated_bt(backtrace, asm):
    symbols = [symbol(label, asm) for label in extract_labels(backtrace)]
    bt_entries_and_syms = zip(backtrace, symbols)
    return ["%s:\t%s" % (bt_entry, sym) for (bt_entry, sym) in 
bt_entries_and_syms]


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "Usage:"
        print "\t%s \"path/to/assembly.s\" \"multi-line backtrace string\"" % 
os.path.basename(sys.argv[0])
        sys.exit(1)

    backtrace = sys.argv[2].split("\n")
    asm = open(sys.argv[1], "r").read()
    print "-------------\n\n"
    print "\n".join(symbolicated_bt(backtrace, asm))

_______________________________________________
fonc mailing list
fonc@vpri.org
http://vpri.org/mailman/listinfo/fonc

Reply via email to