summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/wall2/diag76.py
blob: 989abd3eda1d2cf8c995e72f79bf30278a718326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gdb

inf = gdb.selected_inferior()
pid = inf.pid
maps = []
for line in open("/proc/%d/maps" % pid):
    parts = line.split()
    try:
        lo, hi = [int(x, 16) for x in parts[0].split('-')]
        off = int(parts[2], 16)
        maps.append((lo, hi, off, parts[5] if len(parts) > 5 else ""))
    except Exception:
        pass

def resolve(addr):
    for lo, hi, off, name in maps:
        if lo <= addr < hi:
            return "%s+0x%x" % (name.split('/')[-1], off + (addr - lo))
    return "?"

gdb.execute("set pagination off")
print("=== THREADS ===")
for t in inf.threads():
    try:
        t.switch()
    except Exception as e:
        print("switch err", e)
        continue
    pc = int(gdb.parse_and_eval("$pc"))
    print("TID %s pc=%s" % (t.ptid, resolve(pc)))
    try:
        bt = gdb.execute("bt 12", to_string=True)
    except Exception as e:
        bt = "bt err %s" % e
    for ln in bt.splitlines():
        ln = ln.strip()
        if ln.startswith("#"):
            try:
                a = int(ln.split()[1], 16)
                print("   ", ln, "=>", resolve(a))
            except Exception:
                print("   ", ln)
        else:
            print("   ", ln)
print("DIAG-DONE")
gdb.execute("detach")
gdb.execute("quit")