vendor: Upgrade go-stack

This commit is contained in:
Oskar Thorén 2017-09-02 19:47:21 +02:00 committed by Ivan Daniluk
parent beb552d13c
commit 680090bdf9
2 changed files with 20 additions and 39 deletions

View File

@ -1,13 +1,21 @@
Copyright 2014 Chris Hines The MIT License (MIT)
Licensed under the Apache License, Version 2.0 (the "License"); Copyright (c) 2014 Chris Hines
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Unless required by applicable law or agreed to in writing, software The above copyright notice and this permission notice shall be included in all
distributed under the License is distributed on an "AS IS" BASIS, copies or substantial portions of the Software.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
limitations under the License. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -39,7 +39,7 @@ func Caller(skip int) Call {
} }
c.pc = pcs[1] c.pc = pcs[1]
if runtime.FuncForPC(pcs[0]) != sigpanic { if runtime.FuncForPC(pcs[0]).Name() != "runtime.sigpanic" {
c.pc-- c.pc--
} }
c.fn = runtime.FuncForPC(c.pc) c.fn = runtime.FuncForPC(c.pc)
@ -205,33 +205,6 @@ func (cs CallStack) Format(s fmt.State, verb rune) {
s.Write(closeBracketBytes) s.Write(closeBracketBytes)
} }
// findSigpanic intentionally executes faulting code to generate a stack trace
// containing an entry for runtime.sigpanic.
func findSigpanic() *runtime.Func {
var fn *runtime.Func
var p *int
func() int {
defer func() {
if p := recover(); p != nil {
var pcs [512]uintptr
n := runtime.Callers(2, pcs[:])
for _, pc := range pcs[:n] {
f := runtime.FuncForPC(pc)
if f.Name() == "runtime.sigpanic" {
fn = f
break
}
}
}
}()
// intentional nil pointer dereference to trigger sigpanic
return *p
}()
return fn
}
var sigpanic = findSigpanic()
// Trace returns a CallStack for the current goroutine with element 0 // Trace returns a CallStack for the current goroutine with element 0
// identifying the calling function. // identifying the calling function.
func Trace() CallStack { func Trace() CallStack {
@ -241,7 +214,7 @@ func Trace() CallStack {
for i, pc := range pcs[:n] { for i, pc := range pcs[:n] {
pcFix := pc pcFix := pc
if i > 0 && cs[i-1].fn != sigpanic { if i > 0 && cs[i-1].fn.Name() != "runtime.sigpanic" {
pcFix-- pcFix--
} }
cs[i] = Call{ cs[i] = Call{