Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
52c8f8e9
D
delve
项目概览
HugeYuan
/
delve
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
delve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
52c8f8e9
编写于
2月 27, 2015
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove readline dep
上级
2d2d7064
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
111 deletion
+30
-111
client/cli/cli.go
client/cli/cli.go
+30
-25
goreadline/goreadline.go
goreadline/goreadline.go
+0
-86
未找到文件。
client/cli/cli.go
浏览文件 @
52c8f8e9
...
...
@@ -11,17 +11,20 @@ import (
sys
"golang.org/x/sys/unix"
"github.com/derekparker/delve/command"
"github.com/derekparker/delve/goreadline"
"github.com/derekparker/delve/proctl"
"github.com/peterh/liner"
)
const
historyFile
string
=
".dbg_history"
func
Run
(
run
bool
,
pid
int
,
args
[]
string
)
{
var
(
dbp
*
proctl
.
DebuggedProcess
err
error
dbp
*
proctl
.
DebuggedProcess
err
error
line
=
liner
.
NewLiner
()
)
defer
line
.
Close
()
switch
{
case
run
:
...
...
@@ -60,14 +63,17 @@ func Run(run bool, pid int, args []string) {
}()
cmds
:=
command
.
DebugCommands
()
goreadline
.
LoadHistoryFromFile
(
historyFile
)
if
f
,
err
:=
os
.
Open
(
historyFile
);
err
==
nil
{
line
.
ReadHistory
(
f
)
f
.
Close
()
}
fmt
.
Println
(
"Type 'help' for list of commands."
)
for
{
cmdstr
,
err
:=
promptForInput
()
cmdstr
,
err
:=
promptForInput
(
line
)
if
err
!=
nil
{
if
err
==
io
.
EOF
{
handleExit
(
dbp
,
0
)
handleExit
(
dbp
,
line
,
0
)
}
die
(
1
,
"Prompt for input failed.
\n
"
)
}
...
...
@@ -75,7 +81,7 @@ func Run(run bool, pid int, args []string) {
cmdstr
,
args
:=
parseCommand
(
cmdstr
)
if
cmdstr
==
"exit"
{
handleExit
(
dbp
,
0
)
handleExit
(
dbp
,
line
,
0
)
}
cmd
:=
cmds
.
Find
(
cmdstr
)
...
...
@@ -86,18 +92,17 @@ func Run(run bool, pid int, args []string) {
}
}
func
handleExit
(
dbp
*
proctl
.
DebuggedProcess
,
status
int
)
{
errno
:=
goreadline
.
WriteHistoryToFile
(
historyFile
)
if
errno
!=
0
{
f
mt
.
Println
(
"readline:"
,
errno
)
func
handleExit
(
dbp
*
proctl
.
DebuggedProcess
,
line
*
liner
.
State
,
status
int
)
{
if
f
,
err
:=
os
.
Open
(
historyFile
);
err
==
nil
{
line
.
WriteHistory
(
f
)
f
.
Close
(
)
}
prompt
:=
"Would you like to kill the process? [y/n]"
answerp
:=
goreadline
.
ReadLine
(
&
prompt
)
if
answerp
==
nil
{
answer
,
err
:=
line
.
Prompt
(
"Would you like to kill the process? [y/n]"
)
if
err
!=
nil
{
die
(
2
,
io
.
EOF
)
}
answer
:=
strings
.
TrimSuffix
(
*
answerp
,
"
\n
"
)
answer
=
strings
.
TrimSuffix
(
answer
,
"
\n
"
)
for
_
,
bp
:=
range
dbp
.
HWBreakPoints
{
if
bp
==
nil
{
...
...
@@ -115,7 +120,7 @@ func handleExit(dbp *proctl.DebuggedProcess, status int) {
}
fmt
.
Println
(
"Detaching from process..."
)
err
:
=
sys
.
PtraceDetach
(
dbp
.
Process
.
Pid
)
err
=
sys
.
PtraceDetach
(
dbp
.
Process
.
Pid
)
if
err
!=
nil
{
die
(
2
,
"Could not detach"
,
err
)
}
...
...
@@ -143,16 +148,16 @@ func parseCommand(cmdstr string) (string, []string) {
return
vals
[
0
],
vals
[
1
:
]
}
func
promptForInput
()
(
string
,
error
)
{
prompt
:=
"(dlv) "
linep
:=
goreadline
.
ReadLine
(
&
prompt
)
if
linep
==
nil
{
return
""
,
io
.
EOF
func
promptForInput
(
line
*
liner
.
State
)
(
string
,
error
)
{
l
,
err
:=
line
.
Prompt
(
"(dlv) "
)
if
err
!=
nil
{
return
""
,
err
}
line
:=
strings
.
TrimSuffix
(
*
linep
,
"
\n
"
)
if
line
!=
""
{
goreadline
.
AddHistory
(
line
)
l
=
strings
.
TrimSuffix
(
l
,
"
\n
"
)
if
l
!=
""
{
line
.
AppendHistory
(
l
)
}
return
l
ine
,
nil
return
l
,
nil
}
goreadline/goreadline.go
已删除
100644 → 0
浏览文件 @
2d2d7064
package
goreadline
// sniped from https://github.com/rocaltair/goreadline
/*
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>
#cgo LDFLAGS: -lreadline
*/
import
"C"
import
(
sys
"golang.org/x/sys/unix"
"os"
"os/signal"
"unsafe"
)
func
init
()
{
C
.
rl_catch_sigwinch
=
0
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
sys
.
SIGWINCH
)
go
func
()
{
for
sig
:=
range
c
{
switch
sig
{
case
sys
.
SIGWINCH
:
Resize
()
default
:
}
}
}()
}
func
Resize
()
{
C
.
rl_resize_terminal
()
}
func
ReadLine
(
prompt
*
string
)
*
string
{
var
cPrompt
*
C
.
char
if
prompt
!=
nil
{
cPrompt
=
C
.
CString
(
*
prompt
)
}
cLine
:=
C
.
readline
(
cPrompt
)
if
cPrompt
!=
nil
{
C
.
free
(
unsafe
.
Pointer
(
cPrompt
))
}
if
cLine
==
nil
{
return
nil
}
line
:=
C
.
GoString
(
cLine
)
C
.
free
(
unsafe
.
Pointer
(
cLine
))
return
&
line
}
func
AddHistory
(
line
string
)
{
cLine
:=
C
.
CString
(
line
)
C
.
add_history
(
cLine
)
C
.
free
(
unsafe
.
Pointer
(
cLine
))
}
func
ClearHistory
()
{
C
.
clear_history
()
}
func
WriteHistoryToFile
(
fileName
string
)
int
{
cFileName
:=
C
.
CString
(
fileName
)
err
:=
C
.
write_history
(
cFileName
)
C
.
free
(
unsafe
.
Pointer
(
cFileName
))
return
int
(
err
)
}
func
LoadHistoryFromFile
(
fileName
string
)
{
cFileName
:=
C
.
CString
(
fileName
)
C
.
read_history
(
cFileName
)
C
.
free
(
unsafe
.
Pointer
(
cFileName
))
}
func
TruncateHistoryFile
(
fileName
string
,
left
int
)
{
cFileName
:=
C
.
CString
(
fileName
)
cLeft
:=
C
.
int
(
left
)
C
.
history_truncate_file
(
cFileName
,
cLeft
)
C
.
free
(
unsafe
.
Pointer
(
cFileName
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录