Skip to content

Commit

Permalink
fix: When extracting PCs from stack frames, try the PC field (#393)
Browse files Browse the repository at this point in the history
Some error types may return stack traces already defined as `[]runtime.Frame`.
In this case, the program counter will be in the `PC` field.

fixes: #391
  • Loading branch information
kat-co committed Feb 25, 2022
1 parent dc2eb25 commit 5c2f2a7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions stacktrace.go
Expand Up @@ -114,17 +114,20 @@ func extractPcs(method reflect.Value) []uintptr {
for i := 0; i < stacktrace.Len(); i++ {
pc := stacktrace.Index(i)

if pc.Kind() == reflect.Uintptr {
switch pc.Kind() {
case reflect.Uintptr:
pcs = append(pcs, uintptr(pc.Uint()))
continue
}

if pc.Kind() == reflect.Struct {
field := pc.FieldByName("ProgramCounter")
if field.IsValid() && field.Kind() == reflect.Uintptr {
pcs = append(pcs, uintptr(field.Uint()))
continue
}
case reflect.Struct:
for _, fieldName := range []string{"ProgramCounter", "PC"} {
field := pc.FieldByName(fieldName)
if !field.IsValid() {
continue
}
if field.Kind() == reflect.Uintptr {
pcs = append(pcs, uintptr(field.Uint()))
break
}
}
}
}

Expand Down

0 comments on commit 5c2f2a7

Please sign in to comment.