Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
9ee21686
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,体验更适合开发者的 AI 搜索 >>
提交
9ee21686
编写于
8月 15, 2017
作者:
A
aarzilli
提交者:
Derek Parker
8月 30, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
proc: report errors when loading executable on attach
Fixes #940
上级
f553c95e
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
189 addition
and
72 deletion
+189
-72
pkg/proc/bininfo.go
pkg/proc/bininfo.go
+63
-50
pkg/proc/core/core.go
pkg/proc/core/core.go
+7
-1
pkg/proc/core/core_test.go
pkg/proc/core/core_test.go
+1
-1
pkg/proc/gdbserial/gdbserver.go
pkg/proc/gdbserial/gdbserver.go
+4
-1
pkg/proc/gdbserial/rr_test.go
pkg/proc/gdbserial/rr_test.go
+1
-1
pkg/proc/native/proc.go
pkg/proc/native/proc.go
+7
-4
pkg/proc/native/proc_darwin.go
pkg/proc/native/proc_darwin.go
+6
-1
pkg/proc/native/proc_linux.go
pkg/proc/native/proc_linux.go
+6
-1
pkg/proc/native/proc_windows.go
pkg/proc/native/proc_windows.go
+6
-1
pkg/proc/proc_test.go
pkg/proc/proc_test.go
+65
-3
pkg/proc/test/support.go
pkg/proc/test/support.go
+18
-3
pkg/terminal/command_test.go
pkg/terminal/command_test.go
+1
-1
service/test/integration1_test.go
service/test/integration1_test.go
+2
-2
service/test/integration2_test.go
service/test/integration2_test.go
+1
-1
service/test/variables_test.go
service/test/variables_test.go
+1
-1
未找到文件。
pkg/proc/bininfo.go
浏览文件 @
9ee21686
...
...
@@ -43,6 +43,9 @@ type BinaryInfo struct {
loadModuleDataOnce
sync
.
Once
moduleData
[]
moduleData
nameOfRuntimeType
map
[
uintptr
]
nameOfRuntimeTypeEntry
loadErrMu
sync
.
Mutex
loadErr
error
}
var
UnsupportedLinuxArchErr
=
errors
.
New
(
"unsupported architecture - only linux/amd64 is supported"
)
...
...
@@ -131,6 +134,16 @@ func (bi *BinaryInfo) Close() error {
return
bi
.
closer
.
Close
()
}
func
(
bi
*
BinaryInfo
)
setLoadError
(
fmtstr
string
,
args
...
interface
{})
{
bi
.
loadErrMu
.
Lock
()
bi
.
loadErr
=
fmt
.
Errorf
(
fmtstr
,
args
...
)
bi
.
loadErrMu
.
Unlock
()
}
func
(
bi
*
BinaryInfo
)
LoadError
()
error
{
return
bi
.
loadErr
}
// ELF ///////////////////////////////////////////////////////////////
func
(
bi
*
BinaryInfo
)
LoadBinaryInfoElf
(
path
string
,
wg
*
sync
.
WaitGroup
)
error
{
...
...
@@ -169,18 +182,18 @@ func (bi *BinaryInfo) parseDebugFrameElf(exe *elf.File, wg *sync.WaitGroup) {
if
debugFrameSec
!=
nil
&&
debugInfoSec
!=
nil
{
debugFrame
,
err
:=
exe
.
Section
(
".debug_frame"
)
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_frame section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_frame section: %v
"
,
err
)
return
}
dat
,
err
:=
debugInfoSec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_info section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_frame section: %v
"
,
err
)
return
}
bi
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
))
}
else
{
fmt
.
Println
(
"could not find .debug_frame section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find .debug_frame section in binary"
)
return
}
}
...
...
@@ -196,24 +209,24 @@ func (bi *BinaryInfo) obtainGoSymbolsElf(exe *elf.File, wg *sync.WaitGroup) {
if
sec
:=
exe
.
Section
(
".gosymtab"
);
sec
!=
nil
{
symdat
,
err
=
sec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .gosymtab section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .gosymtab section: %v
"
,
err
)
return
}
}
if
sec
:=
exe
.
Section
(
".gopclntab"
);
sec
!=
nil
{
pclndat
,
err
=
sec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .gopclntab section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .gopclntab section: %v
"
,
err
)
return
}
}
pcln
:=
gosym
.
NewLineTable
(
pclndat
,
exe
.
Section
(
".text"
)
.
Addr
)
tab
,
err
:=
gosym
.
NewTable
(
symdat
,
pcln
)
if
err
!=
nil
{
fmt
.
Println
(
"could not get initialize line table
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get initialize line table: %v
"
,
err
)
return
}
bi
.
goSymTable
=
tab
...
...
@@ -225,13 +238,13 @@ func (bi *BinaryInfo) parseDebugLineInfoElf(exe *elf.File, wg *sync.WaitGroup) {
if
sec
:=
exe
.
Section
(
".debug_line"
);
sec
!=
nil
{
debugLine
,
err
:=
exe
.
Section
(
".debug_line"
)
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_line section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_line section: %v
"
,
err
)
return
}
bi
.
lineInfo
=
line
.
Parse
(
debugLine
)
}
else
{
fmt
.
Println
(
"could not find .debug_line section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find .debug_line section in binary"
)
return
}
}
...
...
@@ -246,8 +259,8 @@ func (bi *BinaryInfo) setGStructOffsetElf(exe *elf.File, wg *sync.WaitGroup) {
// offset in libc's TLS block.
symbols
,
err
:=
exe
.
Symbols
()
if
err
!=
nil
{
fmt
.
Println
(
"could not parse ELF symbols
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not parse ELF symbols: %v
"
,
err
)
return
}
var
tlsg
*
elf
.
Symbol
for
_
,
symbol
:=
range
symbols
{
...
...
@@ -325,41 +338,41 @@ func (bi *BinaryInfo) parseDebugFramePE(exe *pe.File, wg *sync.WaitGroup) {
if
debugFrameSec
!=
nil
&&
debugInfoSec
!=
nil
{
debugFrame
,
err
:=
debugFrameSec
.
Data
()
if
err
!=
nil
&&
uint32
(
len
(
debugFrame
))
<
debugFrameSec
.
Size
{
fmt
.
Println
(
"could not get .debug_frame section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_frame section: %v
"
,
err
)
return
}
if
0
<
debugFrameSec
.
VirtualSize
&&
debugFrameSec
.
VirtualSize
<
debugFrameSec
.
Size
{
debugFrame
=
debugFrame
[
:
debugFrameSec
.
VirtualSize
]
}
dat
,
err
:=
debugInfoSec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_info section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_info section: %v
"
,
err
)
return
}
bi
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
))
}
else
{
fmt
.
Println
(
"could not find .debug_frame section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find .debug_frame section in binary"
)
return
}
}
func
(
dbp
*
BinaryInfo
)
obtainGoSymbolsPE
(
exe
*
pe
.
File
,
wg
*
sync
.
WaitGroup
)
{
func
(
bi
*
BinaryInfo
)
obtainGoSymbolsPE
(
exe
*
pe
.
File
,
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
_
,
symdat
,
pclndat
,
err
:=
pclnPE
(
exe
)
if
err
!=
nil
{
fmt
.
Println
(
"could not get Go symbols
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get Go symbols: %v
"
,
err
)
return
}
pcln
:=
gosym
.
NewLineTable
(
pclndat
,
uint64
(
exe
.
Section
(
".text"
)
.
Offset
))
tab
,
err
:=
gosym
.
NewTable
(
symdat
,
pcln
)
if
err
!=
nil
{
fmt
.
Println
(
"could not get initialize line table
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get initialize line table: %v
"
,
err
)
return
}
dbp
.
goSymTable
=
tab
bi
.
goSymTable
=
tab
}
// Borrowed from https://golang.org/src/cmd/internal/objfile/pe.go
...
...
@@ -438,16 +451,16 @@ func (bi *BinaryInfo) parseDebugLineInfoPE(exe *pe.File, wg *sync.WaitGroup) {
if
sec
:=
exe
.
Section
(
".debug_line"
);
sec
!=
nil
{
debugLine
,
err
:=
sec
.
Data
()
if
err
!=
nil
&&
uint32
(
len
(
debugLine
))
<
sec
.
Size
{
fmt
.
Println
(
"could not get .debug_line section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_line section: %v
"
,
err
)
return
}
if
0
<
sec
.
VirtualSize
&&
sec
.
VirtualSize
<
sec
.
Size
{
debugLine
=
debugLine
[
:
sec
.
VirtualSize
]
}
bi
.
lineInfo
=
line
.
Parse
(
debugLine
)
}
else
{
fmt
.
Println
(
"could not find .debug_line section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find .debug_line section in binary"
)
return
}
}
...
...
@@ -485,18 +498,18 @@ func (bi *BinaryInfo) parseDebugFrameMacho(exe *macho.File, wg *sync.WaitGroup)
if
debugFrameSec
!=
nil
&&
debugInfoSec
!=
nil
{
debugFrame
,
err
:=
exe
.
Section
(
"__debug_frame"
)
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get __debug_frame section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get __debug_frame section: %v
"
,
err
)
return
}
dat
,
err
:=
debugInfoSec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_info section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .debug_info section: %v
"
,
err
)
return
}
bi
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
))
}
else
{
fmt
.
Println
(
"could not find __debug_frame section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find __debug_frame section in binary"
)
return
}
}
...
...
@@ -512,24 +525,24 @@ func (bi *BinaryInfo) obtainGoSymbolsMacho(exe *macho.File, wg *sync.WaitGroup)
if
sec
:=
exe
.
Section
(
"__gosymtab"
);
sec
!=
nil
{
symdat
,
err
=
sec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .gosymtab section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .gosymtab section: %v
"
,
err
)
return
}
}
if
sec
:=
exe
.
Section
(
"__gopclntab"
);
sec
!=
nil
{
pclndat
,
err
=
sec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .gopclntab section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get .gopclntab section: %v
"
,
err
)
return
}
}
pcln
:=
gosym
.
NewLineTable
(
pclndat
,
exe
.
Section
(
"__text"
)
.
Addr
)
tab
,
err
:=
gosym
.
NewTable
(
symdat
,
pcln
)
if
err
!=
nil
{
fmt
.
Println
(
"could not get initialize line table
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get initialize line table: %v
"
,
err
)
return
}
bi
.
goSymTable
=
tab
...
...
@@ -541,12 +554,12 @@ func (bi *BinaryInfo) parseDebugLineInfoMacho(exe *macho.File, wg *sync.WaitGrou
if
sec
:=
exe
.
Section
(
"__debug_line"
);
sec
!=
nil
{
debugLine
,
err
:=
exe
.
Section
(
"__debug_line"
)
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get __debug_line section
"
,
err
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not get __debug_line section: %v
"
,
err
)
return
}
bi
.
lineInfo
=
line
.
Parse
(
debugLine
)
}
else
{
fmt
.
Println
(
"could not find __debug_line section in binary"
)
os
.
Exit
(
1
)
bi
.
setLoadError
(
"could not find __debug_line section in binary"
)
return
}
}
pkg/proc/core/core.go
浏览文件 @
9ee21686
...
...
@@ -175,8 +175,14 @@ func OpenCore(corePath, exePath string) (*Process, error) {
}
var
wg
sync
.
WaitGroup
p
.
bi
.
LoadBinaryInfo
(
exePath
,
&
wg
)
err
=
p
.
bi
.
LoadBinaryInfo
(
exePath
,
&
wg
)
wg
.
Wait
()
if
err
==
nil
{
err
=
p
.
bi
.
LoadError
()
}
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
th
:=
range
p
.
core
.
Threads
{
p
.
currentThread
=
th
...
...
pkg/proc/core/core_test.go
浏览文件 @
9ee21686
...
...
@@ -132,7 +132,7 @@ func withCoreFile(t *testing.T, name, args string) *Process {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
fix
:=
test
.
BuildFixture
(
name
)
fix
:=
test
.
BuildFixture
(
name
,
0
)
bashCmd
:=
fmt
.
Sprintf
(
"cd %v && ulimit -c unlimited && GOTRACEBACK=crash %v %s"
,
tempDir
,
fix
.
Path
,
args
)
exec
.
Command
(
"bash"
,
"-c"
,
bashCmd
)
.
Run
()
cores
,
err
:=
filepath
.
Glob
(
path
.
Join
(
tempDir
,
"core*"
))
...
...
pkg/proc/gdbserial/gdbserver.go
浏览文件 @
9ee21686
...
...
@@ -263,11 +263,14 @@ func (p *Process) Connect(conn net.Conn, path string, pid int) error {
var
wg
sync
.
WaitGroup
err
=
p
.
bi
.
LoadBinaryInfo
(
path
,
&
wg
)
wg
.
Wait
()
if
err
==
nil
{
err
=
p
.
bi
.
LoadError
()
}
if
err
!=
nil
{
conn
.
Close
()
return
err
}
wg
.
Wait
()
// None of the stubs we support returns the value of fs_base or gs_base
// along with the registers, therefore we have to resort to executing a MOV
...
...
pkg/proc/gdbserial/rr_test.go
浏览文件 @
9ee21686
...
...
@@ -13,7 +13,7 @@ import (
)
func
withTestRecording
(
name
string
,
t
testing
.
TB
,
fn
func
(
p
*
gdbserial
.
Process
,
fixture
protest
.
Fixture
))
{
fixture
:=
protest
.
BuildFixture
(
name
)
fixture
:=
protest
.
BuildFixture
(
name
,
0
)
protest
.
MustHaveRecordingAllowed
(
t
)
if
path
,
_
:=
exec
.
LookPath
(
"rr"
);
path
==
""
{
t
.
Skip
(
"test skipped, rr not found"
)
...
...
pkg/proc/native/proc.go
浏览文件 @
9ee21686
...
...
@@ -163,10 +163,13 @@ func (dbp *Process) LoadInformation(path string) error {
wg
.
Add
(
1
)
go
dbp
.
loadProcessInformation
(
&
wg
)
dbp
.
bi
.
LoadBinaryInfo
(
path
,
&
wg
)
err
:=
dbp
.
bi
.
LoadBinaryInfo
(
path
,
&
wg
)
wg
.
Wait
()
if
err
==
nil
{
err
=
dbp
.
bi
.
LoadError
()
}
return
nil
return
err
}
// RequestManualStop sets the `halt` flag and
...
...
@@ -388,11 +391,11 @@ func (dbp *Process) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) {
func
initializeDebugProcess
(
dbp
*
Process
,
path
string
)
(
*
Process
,
error
)
{
err
:=
dbp
.
LoadInformation
(
path
)
if
err
!=
nil
{
return
nil
,
err
return
dbp
,
err
}
if
err
:=
dbp
.
updateThreadList
();
err
!=
nil
{
return
nil
,
err
return
dbp
,
err
}
// selectedGoroutine can not be set correctly by the call to updateThreadList
...
...
pkg/proc/native/proc_darwin.go
浏览文件 @
9ee21686
...
...
@@ -152,7 +152,12 @@ func Attach(pid int) (*Process, error) {
return
nil
,
err
}
return
initializeDebugProcess
(
dbp
,
""
)
dbp
,
err
=
initializeDebugProcess
(
dbp
,
""
)
if
err
!=
nil
{
dbp
.
Detach
(
false
)
return
nil
,
err
}
return
dbp
,
nil
}
// Kill kills the process.
...
...
pkg/proc/native/proc_linux.go
浏览文件 @
9ee21686
...
...
@@ -90,7 +90,12 @@ func Attach(pid int) (*Process, error) {
return
nil
,
err
}
return
initializeDebugProcess
(
dbp
,
""
)
dbp
,
err
=
initializeDebugProcess
(
dbp
,
""
)
if
err
!=
nil
{
dbp
.
Detach
(
false
)
return
nil
,
err
}
return
dbp
,
nil
}
// Kill kills the target process.
...
...
pkg/proc/native/proc_windows.go
浏览文件 @
9ee21686
...
...
@@ -162,7 +162,12 @@ func Attach(pid int) (*Process, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
newDebugProcess
(
New
(
pid
),
exepath
)
dbp
,
err
:=
newDebugProcess
(
New
(
pid
),
exepath
)
if
err
!=
nil
{
dbp
.
Detach
(
false
)
return
nil
,
err
}
return
dbp
,
nil
}
// Kill kills the process.
...
...
pkg/proc/proc_test.go
浏览文件 @
9ee21686
...
...
@@ -48,7 +48,7 @@ func TestMain(m *testing.M) {
}
func
withTestProcess
(
name
string
,
t
testing
.
TB
,
fn
func
(
p
proc
.
Process
,
fixture
protest
.
Fixture
))
{
fixture
:=
protest
.
BuildFixture
(
name
)
fixture
:=
protest
.
BuildFixture
(
name
,
0
)
var
p
proc
.
Process
var
err
error
var
tracedir
string
...
...
@@ -81,7 +81,7 @@ func withTestProcess(name string, t testing.TB, fn func(p proc.Process, fixture
}
func
withTestProcessArgs
(
name
string
,
t
testing
.
TB
,
wd
string
,
fn
func
(
p
proc
.
Process
,
fixture
protest
.
Fixture
),
args
[]
string
)
{
fixture
:=
protest
.
BuildFixture
(
name
)
fixture
:=
protest
.
BuildFixture
(
name
,
0
)
var
p
proc
.
Process
var
err
error
var
tracedir
string
...
...
@@ -2794,7 +2794,7 @@ func TestAttachDetach(t *testing.T) {
if
testBackend
==
"rr"
{
return
}
fixture
:=
protest
.
BuildFixture
(
"testnextnethttp"
)
fixture
:=
protest
.
BuildFixture
(
"testnextnethttp"
,
0
)
cmd
:=
exec
.
Command
(
fixture
.
Path
)
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
...
...
@@ -3085,3 +3085,65 @@ func TestShadowedFlag(t *testing.T) {
}
})
}
func
TestAttachStripped
(
t
*
testing
.
T
)
{
if
testBackend
==
"lldb"
&&
runtime
.
GOOS
==
"linux"
{
bs
,
_
:=
ioutil
.
ReadFile
(
"/proc/sys/kernel/yama/ptrace_scope"
)
if
bs
==
nil
||
strings
.
TrimSpace
(
string
(
bs
))
!=
"0"
{
t
.
Logf
(
"can not run TestAttachStripped: %v
\n
"
,
bs
)
return
}
}
if
testBackend
==
"rr"
{
return
}
if
runtime
.
GOOS
==
"darwin"
{
t
.
Log
(
"-s does not produce stripped executables on macOS"
)
return
}
fixture
:=
protest
.
BuildFixture
(
"testnextnethttp"
,
protest
.
LinkStrip
)
cmd
:=
exec
.
Command
(
fixture
.
Path
)
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
assertNoError
(
cmd
.
Start
(),
t
,
"starting fixture"
)
// wait for testnextnethttp to start listening
t0
:=
time
.
Now
()
for
{
conn
,
err
:=
net
.
Dial
(
"tcp"
,
"localhost:9191"
)
if
err
==
nil
{
conn
.
Close
()
break
}
time
.
Sleep
(
50
*
time
.
Millisecond
)
if
time
.
Since
(
t0
)
>
10
*
time
.
Second
{
t
.
Fatal
(
"fixture did not start"
)
}
}
var
p
proc
.
Process
var
err
error
switch
testBackend
{
case
"native"
:
p
,
err
=
native
.
Attach
(
cmd
.
Process
.
Pid
)
case
"lldb"
:
path
:=
""
if
runtime
.
GOOS
==
"darwin"
{
path
=
fixture
.
Path
}
p
,
err
=
gdbserial
.
LLDBAttach
(
cmd
.
Process
.
Pid
,
path
)
default
:
t
.
Fatalf
(
"unknown backend %q"
,
testBackend
)
}
t
.
Logf
(
"error is %v"
,
err
)
if
err
==
nil
{
p
.
Detach
(
true
)
t
.
Fatalf
(
"expected error after attach, got nothing"
)
}
else
{
cmd
.
Process
.
Kill
()
}
os
.
Remove
(
fixture
.
Path
)
}
pkg/proc/test/support.go
浏览文件 @
9ee21686
...
...
@@ -38,8 +38,14 @@ func FindFixturesDir() string {
return
fixturesDir
}
func
BuildFixture
(
name
string
)
Fixture
{
if
f
,
ok
:=
Fixtures
[
name
];
ok
{
type
BuildFlags
uint32
const
(
LinkStrip
=
1
<<
iota
)
func
BuildFixture
(
name
string
,
flags
BuildFlags
)
Fixture
{
if
f
,
ok
:=
Fixtures
[
name
];
ok
&&
flags
==
0
{
return
f
}
...
...
@@ -62,6 +68,9 @@ func BuildFixture(name string) Fixture {
// Work-around for https://github.com/golang/go/issues/13154
buildFlags
=
append
(
buildFlags
,
"-ldflags=-linkmode internal"
)
}
if
flags
&
LinkStrip
!=
0
{
buildFlags
=
append
(
buildFlags
,
"-ldflags=-s"
)
}
buildFlags
=
append
(
buildFlags
,
"-gcflags=-N -l"
,
"-o"
,
tmpfile
)
if
path
!=
""
{
buildFlags
=
append
(
buildFlags
,
name
+
".go"
)
...
...
@@ -80,7 +89,13 @@ func BuildFixture(name string) Fixture {
source
,
_
:=
filepath
.
Abs
(
path
)
source
=
filepath
.
ToSlash
(
source
)
Fixtures
[
name
]
=
Fixture
{
Name
:
name
,
Path
:
tmpfile
,
Source
:
source
}
fixture
:=
Fixture
{
Name
:
name
,
Path
:
tmpfile
,
Source
:
source
}
if
flags
!=
0
{
return
fixture
}
Fixtures
[
name
]
=
fixture
return
Fixtures
[
name
]
}
...
...
pkg/terminal/command_test.go
浏览文件 @
9ee21686
...
...
@@ -104,7 +104,7 @@ func withTestTerminal(name string, t testing.TB, fn func(*FakeTerminal)) {
defer
listener
.
Close
()
server
:=
rpccommon
.
NewServer
(
&
service
.
Config
{
Listener
:
listener
,
ProcessArgs
:
[]
string
{
test
.
BuildFixture
(
name
)
.
Path
},
ProcessArgs
:
[]
string
{
test
.
BuildFixture
(
name
,
0
)
.
Path
},
Backend
:
testBackend
,
},
false
)
if
err
:=
server
.
Run
();
err
!=
nil
{
...
...
service/test/integration1_test.go
浏览文件 @
9ee21686
...
...
@@ -31,7 +31,7 @@ func withTestClient1(name string, t *testing.T, fn func(c *rpc1.RPCClient)) {
defer
listener
.
Close
()
server
:=
rpccommon
.
NewServer
(
&
service
.
Config
{
Listener
:
listener
,
ProcessArgs
:
[]
string
{
protest
.
BuildFixture
(
name
)
.
Path
},
ProcessArgs
:
[]
string
{
protest
.
BuildFixture
(
name
,
0
)
.
Path
},
Backend
:
testBackend
,
},
false
)
if
err
:=
server
.
Run
();
err
!=
nil
{
...
...
service/test/integration2_test.go
浏览文件 @
9ee21686
...
...
@@ -48,7 +48,7 @@ func withTestClient2(name string, t *testing.T, fn func(c service.Client)) {
defer
listener
.
Close
()
server
:=
rpccommon
.
NewServer
(
&
service
.
Config
{
Listener
:
listener
,
ProcessArgs
:
[]
string
{
protest
.
BuildFixture
(
name
)
.
Path
},
ProcessArgs
:
[]
string
{
protest
.
BuildFixture
(
name
,
0
)
.
Path
},
Backend
:
testBackend
,
},
false
)
if
err
:=
server
.
Run
();
err
!=
nil
{
...
...
service/test/variables_test.go
浏览文件 @
9ee21686
...
...
@@ -106,7 +106,7 @@ func setVariable(p proc.Process, symbol, value string) error {
}
func
withTestProcess
(
name
string
,
t
*
testing
.
T
,
fn
func
(
p
proc
.
Process
,
fixture
protest
.
Fixture
))
{
fixture
:=
protest
.
BuildFixture
(
name
)
fixture
:=
protest
.
BuildFixture
(
name
,
0
)
var
p
proc
.
Process
var
err
error
var
tracedir
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录