// File: lega911[P]ijson/src/exception.cpp
// Function: get_traceback(Buffer&)
void get_traceback(Buffer &r) {
        void *addr[32];
        char **names;

        int n = backtrace(addr, 32);
        names = backtrace_symbols(addr, n);
        if(!names) return;

        size_t funcsize = 256;
        char *func = (char*)malloc(funcsize);

        Buffer bname(256);
        for(int i = 1; i<n; i++) {
            Slice line(names[i]);
            Slice file = line.split_left('(');
            Slice _name = line.split_left('+');
            line = line.split_left(')');
            bname.set(_name);
            bname.add("\0", 1);

            int status;
	        char* ret = abi::__cxa_demangle(bname.ptr(), func, &funcsize, &status);
            if(status == 0) {
                func = ret;
                r.add(file);
                r.add(": ");
                r.add(func);
                r.add(" +");
                r.add(line);
            } else {
                r.add((char*)names[i]);
            }
            r.add("\n");
        }
        r.add("\0", 1);
        free(func);
        free(names);
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
leaq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x19400
movl %eax, -0x11c(%rbp)
leaq -0x110(%rbp), %rdi
movl -0x11c(%rbp), %esi
callq 0x19410
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x22cbe
jmp 0x22fd7
movq $0x100, -0x128(%rbp) # imm = 0x100
movq -0x128(%rbp), %rdi
callq 0x19390
movq %rax, -0x130(%rbp)
leaq -0x140(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x1f190
movl $0x1, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jge 0x22f9c
movq -0x118(%rbp), %rax
movslq -0x144(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x158(%rbp), %rdi
callq 0x1f4b0
jmp 0x22d29
leaq -0x158(%rbp), %rdi
movl $0x28, %esi
callq 0x232a0
movl %edx, -0x1e4(%rbp)
movq %rax, -0x1e0(%rbp)
jmp 0x22d49
movl -0x1e4(%rbp), %eax
movq -0x1e0(%rbp), %rcx
movq %rcx, -0x188(%rbp)
movl %eax, -0x180(%rbp)
movl -0x180(%rbp), %eax
movl %eax, -0x170(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x158(%rbp), %rdi
movl $0x2b, %esi
callq 0x232a0
movl %edx, -0x1f4(%rbp)
movq %rax, -0x1f0(%rbp)
jmp 0x22d9d
movl -0x1f4(%rbp), %eax
movq -0x1f0(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1a0(%rbp)
movl -0x1a0(%rbp), %eax
movl %eax, -0x190(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x158(%rbp), %rdi
movl $0x29, %esi
callq 0x232a0
movl %edx, -0x204(%rbp)
movq %rax, -0x200(%rbp)
jmp 0x22df1
movl -0x204(%rbp), %eax
movq -0x200(%rbp), %rcx
movq %rcx, -0x1c8(%rbp)
movl %eax, -0x1c0(%rbp)
movl -0x1c0(%rbp), %eax
movl %eax, -0x1b0(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl -0x1b0(%rbp), %eax
movl %eax, -0x150(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x1ed20
jmp 0x22e54
leaq 0x15cbe(%rip), %rsi     # 0x38b19
leaq -0x140(%rbp), %rdi
movl $0x1, %edx
callq 0x1e8b0
jmp 0x22e6e
leaq -0x140(%rbp), %rdi
callq 0x1e6f0
movq %rax, -0x210(%rbp)
jmp 0x22e83
movq -0x210(%rbp), %rdi
movq -0x130(%rbp), %rsi
leaq -0x128(%rbp), %rdx
leaq -0x1cc(%rbp), %rcx
callq 0x19270
movq %rax, -0x218(%rbp)
jmp 0x22ead
movq -0x218(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpl $0x0, -0x1cc(%rbp)
jne 0x22f55
movq -0x1d8(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x1ea60
jmp 0x22ee8
movq -0x8(%rbp), %rdi
leaq 0x16574(%rip), %rsi     # 0x39467
callq 0x1f2c0
jmp 0x22efa
movq -0x8(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x1f2c0
jmp 0x22f0c
movq -0x8(%rbp), %rdi
leaq 0x15bff(%rip), %rsi     # 0x38b16
callq 0x1f2c0
jmp 0x22f1e
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x1ea60
jmp 0x22f30
jmp 0x22f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x1f460
jmp 0x22fe0
movq -0x8(%rbp), %rdi
movq -0x118(%rbp), %rax
movslq -0x144(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1f2c0
jmp 0x22f72
jmp 0x22f74
movq -0x8(%rbp), %rdi
leaq 0x1571b(%rip), %rsi     # 0x3869a
callq 0x1f2c0
jmp 0x22f86
jmp 0x22f88
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x22cf7
movq -0x8(%rbp), %rdi
leaq 0x15b72(%rip), %rsi     # 0x38b19
movl $0x1, %edx
callq 0x1e8b0
jmp 0x22fb3
movq -0x130(%rbp), %rdi
callq 0x19350
movq -0x118(%rbp), %rdi
callq 0x19350
leaq -0x140(%rbp), %rdi
callq 0x1f460
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq -0x160(%rbp), %rdi
callq 0x194a0
nopl (%rax)