Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ln/stack.go
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (39 sloc)
805 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ln | |
import ( | |
"os" | |
"runtime" | |
"strings" | |
) | |
type frame struct { | |
filename string | |
function string | |
lineno int | |
} | |
// skips 2 frames, since Caller returns the current frame, and we need | |
// the caller's caller. | |
func callersFrame() frame { | |
var out frame | |
pc, file, line, ok := runtime.Caller(3) | |
if !ok { | |
return out | |
} | |
srcLoc := strings.LastIndex(file, "/src/") | |
if srcLoc >= 0 { | |
file = file[srcLoc+5:] | |
} | |
out.filename = file | |
out.function = functionName(pc) | |
out.lineno = line | |
return out | |
} | |
func functionName(pc uintptr) string { | |
fn := runtime.FuncForPC(pc) | |
if fn == nil { | |
return "???" | |
} | |
name := fn.Name() | |
beg := strings.LastIndex(name, string(os.PathSeparator)) | |
return name[beg+1:] | |
// end := strings.LastIndex(name, string(os.PathSeparator)) | |
// return name[end+1 : len(name)] | |
} |