本文整理汇总了Golang中github.com/derekparker/delve/service/rpc.NewServer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewServer函数的具体用法?Golang NewServer怎么用?Golang NewServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewServer函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: traceCmd
func traceCmd(cmd *cobra.Command, args []string) {
status := func() int {
const debugname = "debug"
var processArgs []string
if traceAttachPid == 0 {
if err := gobuild(debugname); err != nil {
return 1
}
fp, err := filepath.Abs("./" + debugname)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return 1
}
defer os.Remove(fp)
processArgs = append([]string{"./" + debugname}, args...)
}
// Make a TCP listener
listener, err := net.Listen("tcp", Addr)
if err != nil {
fmt.Printf("couldn't start listener: %s\n", err)
return 1
}
defer listener.Close()
// Create and start a debug server
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: processArgs,
AttachPid: traceAttachPid,
}, Log)
if err := server.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
client := rpc.NewClient(listener.Addr().String())
funcs, err := client.ListFunctions(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
for i := range funcs {
_, err := client.CreateBreakpoint(&api.Breakpoint{FunctionName: funcs[i], Tracepoint: true, Line: -1, Stacktrace: traceStackDepth})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
}
cmds := terminal.DebugCommands(client)
cmd := cmds.Find("continue")
err = cmd(terminal.New(client, nil), "")
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
return 0
}()
os.Exit(status)
}
开发者ID:ethobis,项目名称:delve,代码行数:59,代码来源:main.go
示例2: TestRestart_attachPid
func TestRestart_attachPid(t *testing.T) {
// Assert it does not work and returns error.
// We cannot restart a process we did not spawn.
server := rpc.NewServer(&service.Config{
Listener: nil,
AttachPid: 999,
}, false)
if err := server.Restart(nil, nil); err == nil {
t.Fatal("expected error on restart after attaching to pid but got none")
}
}
开发者ID:yigen520,项目名称:delve,代码行数:11,代码来源:integration_test.go
示例3: TestRunWithInvalidPath
func TestRunWithInvalidPath(t *testing.T) {
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("couldn't start listener: %s\n", err)
}
defer listener.Close()
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: []string{"invalid_path"},
}, false)
if err := server.Run(); err == nil {
t.Fatal("Expected Run to return error for invalid program path")
}
}
开发者ID:yigen520,项目名称:delve,代码行数:14,代码来源:integration_test.go
示例4: execute
func execute(attachPid int, processArgs []string, conf *config.Config) int {
// Make a TCP listener
listener, err := net.Listen("tcp", Addr)
if err != nil {
fmt.Printf("couldn't start listener: %s\n", err)
return 1
}
defer listener.Close()
if Headless && (InitFile != "") {
fmt.Fprintf(os.Stderr, "Warning: init file ignored\n")
}
// Create and start a debugger server
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: processArgs,
AttachPid: attachPid,
}, Log)
if err := server.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
var status int
if !Headless {
// Create and start a terminal
var client service.Client
client = rpc.NewClient(listener.Addr().String())
term := terminal.New(client, conf)
term.InitFile = InitFile
status, err = term.Run()
} else {
ch := make(chan os.Signal)
signal.Notify(ch, sys.SIGINT)
<-ch
err = server.Stop(true)
}
if err != nil {
fmt.Println(err)
}
return status
}
开发者ID:CedarLogic,项目名称:delve,代码行数:45,代码来源:main.go
示例5: withTestClient
func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("couldn't start listener: %s\n", err)
}
defer listener.Close()
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: []string{protest.BuildFixture(name).Path},
}, false)
if err := server.Run(); err != nil {
t.Fatal(err)
}
client := rpc.NewClient(listener.Addr().String())
defer func() {
client.Detach(true)
}()
fn(client)
}
开发者ID:yigen520,项目名称:delve,代码行数:20,代码来源:integration_test.go
示例6: main
func main() {
// Main dlv root command.
rootCommand := &cobra.Command{
Use: "dlv",
Short: "Delve is a debugger for the Go programming language.",
Long: `Delve is a source level debugger for Go programs.
Delve enables you to interact with your program by controlling the execution of the process,
evaluating variables, and providing information of thread / goroutine state, CPU register state and more.
The goal of this tool is to provide a simple yet powerful interface for debugging Go programs.
`,
}
rootCommand.PersistentFlags().StringVarP(&Addr, "listen", "l", "localhost:0", "Debugging server listen address.")
rootCommand.PersistentFlags().BoolVarP(&Log, "log", "", false, "Enable debugging server logging.")
rootCommand.PersistentFlags().BoolVarP(&Headless, "headless", "", false, "Run debug server only, in headless mode.")
// 'version' subcommand.
versionCommand := &cobra.Command{
Use: "version",
Short: "Prints version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Delve version: " + version)
},
}
rootCommand.AddCommand(versionCommand)
// 'run' subcommand.
runCommand := &cobra.Command{
Use: "run",
Short: "Compile and begin debugging program.",
Long: `Compiles your program with optimizations disabled,
starts and attaches to it, and enables you to immediately begin debugging your program.`,
Run: func(cmd *cobra.Command, args []string) {
status := func() int {
const debugname = "debug"
goBuild := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
goBuild.Stderr = os.Stderr
err := goBuild.Run()
if err != nil {
return 1
}
fp, err := filepath.Abs("./" + debugname)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return 1
}
defer os.Remove(fp)
processArgs := append([]string{"./" + debugname}, args...)
return execute(0, processArgs)
}()
os.Exit(status)
},
}
rootCommand.AddCommand(runCommand)
// 'trace' subcommand.
var traceAttachPid int
traceCommand := &cobra.Command{
Use: "trace [regexp] [flags]",
Short: "Compile and begin tracing program.",
Long: "Trace program execution. Will set a tracepoint on every function matching [regexp] and output information when tracepoint is hit.",
Run: func(cmd *cobra.Command, args []string) {
status := func() int {
const debugname = "debug"
var processArgs []string
if traceAttachPid == 0 {
goBuild := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
goBuild.Stderr = os.Stderr
err := goBuild.Run()
if err != nil {
return 1
}
fp, err := filepath.Abs("./" + debugname)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return 1
}
defer os.Remove(fp)
processArgs = append([]string{"./" + debugname}, args...)
}
// Make a TCP listener
listener, err := net.Listen("tcp", Addr)
if err != nil {
fmt.Printf("couldn't start listener: %s\n", err)
return 1
}
defer listener.Close()
// Create and start a debugger server
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: processArgs,
AttachPid: traceAttachPid,
}, Log)
if err := server.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
//.........这里部分代码省略.........
开发者ID:joeshaw,项目名称:delve,代码行数:101,代码来源:main.go
示例7: main
//.........这里部分代码省略.........
traceCommand := &cobra.Command{
Use: "trace [regexp]",
Short: "Compile and begin tracing program.",
Long: "Trace program execution. Will set a tracepoint on every function matching [regexp] and output information when tracepoint is hit.",
Run: func(cmd *cobra.Command, args []string) {
status := func() int {
const debugname = "debug"
var processArgs []string
if traceAttachPid == 0 {
goBuild := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l", BuildFlags)
goBuild.Stderr = os.Stderr
err := goBuild.Run()
if err != nil {
return 1
}
fp, err := filepath.Abs("./" + debugname)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return 1
}
defer os.Remove(fp)
processArgs = append([]string{"./" + debugname}, args...)
}
// Make a TCP listener
listener, err := net.Listen("tcp", Addr)
if err != nil {
fmt.Printf("couldn't start listener: %s\n", err)
return 1
}
defer listener.Close()
// Create and start a debugger server
server := rpc.NewServer(&service.Config{
Listener: listener,
ProcessArgs: processArgs,
AttachPid: traceAttachPid,
}, Log)
if err := server.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
sigChan := make(chan os.Signal)
signal.Notify(sigChan, sys.SIGINT)
client := rpc.NewClient(listener.Addr().String())
funcs, err := client.ListFunctions(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
for i := range funcs {
_, err := client.CreateBreakpoint(&api.Breakpoint{FunctionName: funcs[i], Tracepoint: true})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
}
stateChan := client.Continue()
for {
select {
case state := <-stateChan:
if state == nil {
return 0
}
if state.Err != nil {
fmt.Fprintln(os.Stderr, state.Err)
开发者ID:CedarLogic,项目名称:delve,代码行数:67,代码来源:main.go
注:本文中的github.com/derekparker/delve/service/rpc.NewServer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论