def format_stringbuf(regno):
    cpu = SIM_current_processor()
    va = SIM_read_register(cpu, r0 + regno)
    len = SIM_read_register(cpu, r0 + regno + 1)
    s = "0x%x = \"" % va
    for i in xrange(0, len):
        if i > 64:
            return s + "\" ..."
        try:
            pa = SIM_logical_to_physical(cpu, 1, va + i)
        except:
            return s + "\" ..."
        b = linux_read_byte(cpu, pa)
        if b == 9:
            s += "\\t"
        elif b == 10:
            s += "\\n"
        elif b == 13:
            s += "\\r"
        elif b == 92:
            s += "\\\\"
        elif b >= 32 and b < 127:
            s += chr(b)
        else:
            s += "<%02x>" % b
    return s + "\""