Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go123
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go123
Commits
608a1c5a
Commit
608a1c5a
authored
Dec 13, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xruntime: Factor out routine to get complete current traceback from exc
It is xruntime.Traceback()
parent
662c8077
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
43 deletions
+61
-43
exc/error.go
exc/error.go
+4
-43
xruntime/xruntime.go
xruntime/xruntime.go
+57
-0
No files found.
exc/error.go
View file @
608a1c5a
...
@@ -15,10 +15,10 @@ package main
...
@@ -15,10 +15,10 @@ package main
import
(
import
(
"fmt"
"fmt"
"runtime"
"strings"
"strings"
"lab.nexedi.com/kirr/go123/myname"
"lab.nexedi.com/kirr/go123/myname"
"lab.nexedi.com/kirr/go123/xruntime"
)
)
// error type which is raised by raise(arg)
// error type which is raised by raise(arg)
...
@@ -31,8 +31,8 @@ func (e *Error) Error() string {
...
@@ -31,8 +31,8 @@ func (e *Error) Error() string {
msgv
:=
[]
string
{}
msgv
:=
[]
string
{}
msg
:=
""
msg
:=
""
for
e
!=
nil
{
for
e
!=
nil
{
// TODO(go1.7) -> runtime.Frame (see x
t
raceback())
// TODO(go1.7) -> runtime.Frame (see x
runtime.T
raceback())
if
f
,
ok
:=
e
.
arg
.
(
Frame
);
ok
{
if
f
,
ok
:=
e
.
arg
.
(
xruntime
.
Frame
);
ok
{
//msg = f.Function
//msg = f.Function
//msg = fmt.Sprintf("%s (%s:%d)", f.Function, f.File, f.Line)
//msg = fmt.Sprintf("%s (%s:%d)", f.Function, f.File, f.Line)
msg
=
strings
.
TrimPrefix
(
f
.
Name
(),
_errorpkgdot
)
// XXX -> better prettyfunc
msg
=
strings
.
TrimPrefix
(
f
.
Name
(),
_errorpkgdot
)
// XXX -> better prettyfunc
...
@@ -135,45 +135,6 @@ func erraddcontext(e *Error, arg interface{}) *Error {
...
@@ -135,45 +135,6 @@ func erraddcontext(e *Error, arg interface{}) *Error {
return
&
Error
{
arg
,
e
}
return
&
Error
{
arg
,
e
}
}
}
// TODO(go1.7) goes away in favour of runtime.Frame
type
Frame
struct
{
*
runtime
.
Func
pc
uintptr
}
// get current calling traceback as []Frame
// nskip meaning: the same as in runtime.Callers()
// TODO(go1.7) []Frame -> []runtime.Frame
func
xtraceback
(
nskip
int
)
[]
Frame
{
// all callers
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
nskip
+
1
,
pcv
)
if
n
<
len
(
pcv
)
{
pcv
=
pcv
[
:
n
]
break
}
}
// pcv -> frames
/*
framev := make([]runtime.Frame, 0, len(pcv))
frames := runtime.CallersFrames(pcv)
for more := true; more; {
var frame runtime.Frame
frame, more = frames.Next()
framev = append(framev, frame)
}
*/
framev
:=
make
([]
Frame
,
0
,
len
(
pcv
))
for
_
,
pc
:=
range
pcv
{
framev
=
append
(
framev
,
Frame
{
runtime
.
FuncForPC
(
pc
),
pc
})
}
return
framev
}
var
(
var
(
_errorpkgname
string
// package name under which error.go lives
_errorpkgname
string
// package name under which error.go lives
_errorpkgdot
string
// errorpkg.
_errorpkgdot
string
// errorpkg.
...
@@ -191,7 +152,7 @@ func init() {
...
@@ -191,7 +152,7 @@ func init() {
// see also: erraddcontext()
// see also: erraddcontext()
func
erraddcallingcontext
(
topfunc
string
,
e
*
Error
)
*
Error
{
func
erraddcallingcontext
(
topfunc
string
,
e
*
Error
)
*
Error
{
seenraise
:=
false
seenraise
:=
false
for
_
,
f
:=
range
x
t
raceback
(
2
)
{
for
_
,
f
:=
range
x
runtime
.
T
raceback
(
2
)
{
// do not show anything after raise*()
// do not show anything after raise*()
if
!
seenraise
&&
strings
.
HasPrefix
(
f
.
Name
(),
_errorraise
)
{
if
!
seenraise
&&
strings
.
HasPrefix
(
f
.
Name
(),
_errorraise
)
{
seenraise
=
true
seenraise
=
true
...
...
xruntime/xruntime.go
0 → 100644
View file @
608a1c5a
// Copyright (C) 2015-2016 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// Package xruntime provides addons to standard package runtime
package
xruntime
import
(
"runtime"
)
// TODO(go1.7) goes away in favour of runtime.Frame
type
Frame
struct
{
*
runtime
.
Func
Pc
uintptr
}
// get current calling traceback as []Frame
// nskip meaning: the same as in runtime.Callers()
// TODO(go1.7) []Frame -> []runtime.Frame
func
Traceback
(
nskip
int
)
[]
Frame
{
// all callers
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
nskip
+
1
,
pcv
)
if
n
<
len
(
pcv
)
{
pcv
=
pcv
[
:
n
]
break
}
}
// pcv -> frames
/*
framev := make([]runtime.Frame, 0, len(pcv))
frames := runtime.CallersFrames(pcv)
for more := true; more; {
var frame runtime.Frame
frame, more = frames.Next()
framev = append(framev, frame)
}
*/
framev
:=
make
([]
Frame
,
0
,
len
(
pcv
))
for
_
,
pc
:=
range
pcv
{
framev
=
append
(
framev
,
Frame
{
runtime
.
FuncForPC
(
pc
),
pc
})
}
return
framev
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment