mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Move debug builtins to separate file.
This commit is contained in:
parent
cc861528de
commit
33584b00f5
|
@ -8,7 +8,6 @@ import (
|
|||
"math/rand"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
|
@ -75,12 +74,6 @@ func init() {
|
|||
{"esleep", sleep},
|
||||
{"-time", _time},
|
||||
|
||||
// Debugging
|
||||
{"src", src},
|
||||
{"-gc", _gc},
|
||||
{"-stack", _stack},
|
||||
{"-log", _log},
|
||||
|
||||
{"-ifaddrs", _ifaddrs},
|
||||
})
|
||||
// For rand and randint.
|
||||
|
@ -157,42 +150,6 @@ func _time(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
|||
fmt.Fprintln(ec.ports[1].File, dt)
|
||||
}
|
||||
|
||||
func src(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
ec.OutputChan() <- ec.srcMeta
|
||||
}
|
||||
|
||||
func _gc(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func _stack(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
out := ec.ports[1].File
|
||||
// XXX dup with main.go
|
||||
buf := make([]byte, 1024)
|
||||
for runtime.Stack(buf, true) == cap(buf) {
|
||||
buf = make([]byte, cap(buf)*2)
|
||||
}
|
||||
out.Write(buf)
|
||||
}
|
||||
|
||||
func _log(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
var fnamev string
|
||||
ScanArgs(args, &fnamev)
|
||||
fname := fnamev
|
||||
TakeNoOpt(opts)
|
||||
|
||||
maybeThrow(util.SetOutputFile(fname))
|
||||
}
|
||||
|
||||
func _ifaddrs(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
|
53
eval/builtin_fn_debug.go
Normal file
53
eval/builtin_fn_debug.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package eval
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/elves/elvish/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
addToBuiltinFns([]*BuiltinFn{
|
||||
// Debugging
|
||||
{"src", src},
|
||||
{"-gc", _gc},
|
||||
{"-stack", _stack},
|
||||
{"-log", _log},
|
||||
})
|
||||
}
|
||||
|
||||
func src(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
ec.OutputChan() <- ec.srcMeta
|
||||
}
|
||||
|
||||
func _gc(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func _stack(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
TakeNoArg(args)
|
||||
TakeNoOpt(opts)
|
||||
|
||||
out := ec.ports[1].File
|
||||
// XXX dup with main.go
|
||||
buf := make([]byte, 1024)
|
||||
for runtime.Stack(buf, true) == cap(buf) {
|
||||
buf = make([]byte, cap(buf)*2)
|
||||
}
|
||||
out.Write(buf)
|
||||
}
|
||||
|
||||
func _log(ec *Frame, args []interface{}, opts map[string]interface{}) {
|
||||
var fnamev string
|
||||
ScanArgs(args, &fnamev)
|
||||
fname := fnamev
|
||||
TakeNoOpt(opts)
|
||||
|
||||
maybeThrow(util.SetOutputFile(fname))
|
||||
}
|
Loading…
Reference in New Issue
Block a user