• Russ Cox's avatar
    runtime: fix line number in first stack frame in printed stack trace · a22c11b9
    Russ Cox authored
    Originally traceback was only used for printing the stack
    when an unexpected signal came in. In that case, the
    initial PC is taken from the signal and should be used
    unaltered. For the callers, the PC is the return address,
    which might be on the line after the call; we subtract 1
    to get to the CALL instruction.
    
    Traceback is now used for a variety of things, and for
    almost all of those the initial PC is a return address,
    whether from getcallerpc, or gp->sched.pc, or gp->syscallpc.
    In those cases, we need to subtract 1 from this initial PC,
    but the traceback code had a hard rule "never subtract 1
    from the initial PC", left over from the signal handling days.
    
    Change gentraceback to take a flag that specifies whether
    we are tracing a trap.
    
    Change traceback to default to "starting with a return PC",
    which is the overwhelmingly common case.
    
    Add tracebacktrap, like traceback but starting with a trap PC.
    
    Use tracebacktrap in signal handlers.
    
    Fixes #7690.
    
    LGTM=iant, r
    R=r, iant
    CC=golang-codereviews
    https://golang.org/cl/167810044
    a22c11b9
os_windows_amd64.c 4.21 KB