Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
794d5b1e
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 搜索 >>
提交
794d5b1e
编写于
5月 04, 2015
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert errors.New change
上级
0358c174
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
65 addition
and
77 deletion
+65
-77
command/command.go
command/command.go
+7
-8
dwarf/reader/reader.go
dwarf/reader/reader.go
+4
-4
proctl/breakpoints_darwin_amd64.go
proctl/breakpoints_darwin_amd64.go
+3
-3
proctl/breakpoints_linux_amd64.go
proctl/breakpoints_linux_amd64.go
+2
-5
proctl/proctl.go
proctl/proctl.go
+1
-2
proctl/proctl_darwin.go
proctl/proctl_darwin.go
+6
-7
proctl/registers_darwin_amd64.go
proctl/registers_darwin_amd64.go
+3
-3
proctl/threads_darwin.go
proctl/threads_darwin.go
+7
-8
proctl/threads_linux.go
proctl/threads_linux.go
+1
-2
proctl/variables.go
proctl/variables.go
+14
-15
proctl/variables_test.go
proctl/variables_test.go
+4
-4
service/debugger/debugger.go
service/debugger/debugger.go
+3
-4
terminal/command.go
terminal/command.go
+7
-8
terminal/command_test.go
terminal/command_test.go
+2
-2
terminal/terminal.go
terminal/terminal.go
+1
-2
未找到文件。
command/command.go
浏览文件 @
794d5b1e
...
...
@@ -4,7 +4,6 @@ package command
import
(
"bufio"
"errors"
"fmt"
"io"
"os"
...
...
@@ -104,7 +103,7 @@ func CommandFunc(fn func() error) cmdfunc {
}
func
noCmdAvailable
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
return
errors
.
New
(
"command not available"
)
return
fmt
.
Errorf
(
"command not available"
)
}
func
nullCommand
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
...
...
@@ -141,7 +140,7 @@ func threads(p *proctl.DebuggedProcess, args ...string) error {
func
thread
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"you must specify a thread"
)
return
fmt
.
Errorf
(
"you must specify a thread"
)
}
oldTid
:=
p
.
CurrentThread
.
Id
tid
,
err
:=
strconv
.
Atoi
(
args
[
0
])
...
...
@@ -205,7 +204,7 @@ func next(p *proctl.DebuggedProcess, args ...string) error {
func
clear
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments"
)
return
fmt
.
Errorf
(
"not enough arguments"
)
}
bp
,
err
:=
p
.
ClearByLocation
(
args
[
0
])
...
...
@@ -251,7 +250,7 @@ func breakpoints(p *proctl.DebuggedProcess, args ...string) error {
func
breakpoint
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments"
)
return
fmt
.
Errorf
(
"not enough arguments"
)
}
bp
,
err
:=
p
.
BreakByLocation
(
args
[
0
])
...
...
@@ -266,7 +265,7 @@ func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
func
printVar
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments"
)
return
fmt
.
Errorf
(
"not enough arguments"
)
}
val
,
err
:=
p
.
EvalSymbol
(
args
[
0
])
...
...
@@ -293,7 +292,7 @@ func filterVariables(vars []*proctl.Variable, filter *regexp.Regexp) []string {
func
info
(
p
*
proctl
.
DebuggedProcess
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments. expected info type [regex]."
)
return
fmt
.
Errorf
(
"not enough arguments. expected info type [regex]."
)
}
// Allow for optional regex
...
...
@@ -346,7 +345,7 @@ func info(p *proctl.DebuggedProcess, args ...string) error {
data
=
filterVariables
(
vars
,
filter
)
default
:
return
errors
.
New
(
"unsupported info type, must be args, funcs, locals, sources, or vars"
)
return
fmt
.
Errorf
(
"unsupported info type, must be args, funcs, locals, sources, or vars"
)
}
// sort and output data
...
...
dwarf/reader/reader.go
浏览文件 @
794d5b1e
...
...
@@ -2,7 +2,7 @@ package reader
import
(
"debug/dwarf"
"
errors
"
"
fmt
"
)
type
Reader
struct
{
...
...
@@ -57,7 +57,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
}
}
return
nil
,
errors
.
New
(
"unable to find function context"
)
return
nil
,
fmt
.
Errorf
(
"unable to find function context"
)
}
// SeekToType moves the reader to the type specified by the entry,
...
...
@@ -66,7 +66,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
func
(
reader
*
Reader
)
SeekToType
(
entry
*
dwarf
.
Entry
,
resolveTypedefs
bool
,
resolvePointerTypes
bool
)
(
*
dwarf
.
Entry
,
error
)
{
offset
,
ok
:=
entry
.
Val
(
dwarf
.
AttrType
)
.
(
dwarf
.
Offset
)
if
!
ok
{
return
nil
,
errors
.
New
(
"entry does not have a type attribute"
)
return
nil
,
fmt
.
Errorf
(
"entry does not have a type attribute"
)
}
// Seek to the first type offset
...
...
@@ -94,7 +94,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol
reader
.
Seek
(
offset
)
}
return
nil
,
errors
.
New
(
"no type entry found"
)
return
nil
,
fmt
.
Errorf
(
"no type entry found"
)
}
// NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry.
...
...
proctl/breakpoints_darwin_amd64.go
浏览文件 @
794d5b1e
package
proctl
import
"
errors
"
import
"
fmt
"
// TODO(darwin)
func
setHardwareBreakpoint
(
reg
,
tid
int
,
addr
uint64
)
error
{
return
errors
.
New
(
"not implemented on darwin"
)
return
fmt
.
Errorf
(
"not implemented on darwin"
)
}
// TODO(darwin)
func
clearHardwareBreakpoint
(
reg
,
tid
int
)
error
{
return
errors
.
New
(
"not implemented on darwin"
)
return
fmt
.
Errorf
(
"not implemented on darwin"
)
}
proctl/breakpoints_linux_amd64.go
浏览文件 @
794d5b1e
...
...
@@ -15,10 +15,7 @@ int offset(int reg) {
*/
import
"C"
import
(
"errors"
"fmt"
)
import
"fmt"
// Sets a hardware breakpoint by setting the contents of the
// debug register `reg` with the address of the instruction
...
...
@@ -26,7 +23,7 @@ import (
// DR0-DR3. Debug register 7 is the control register.
func
setHardwareBreakpoint
(
reg
,
tid
int
,
addr
uint64
)
error
{
if
reg
<
0
||
reg
>
3
{
return
errors
.
New
(
"invalid debug register value"
)
return
fmt
.
Errorf
(
"invalid debug register value"
)
}
var
(
...
...
proctl/proctl.go
浏览文件 @
794d5b1e
...
...
@@ -4,7 +4,6 @@ import (
"debug/dwarf"
"debug/gosym"
"encoding/binary"
"errors"
"fmt"
"os"
"path/filepath"
...
...
@@ -583,7 +582,7 @@ func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, er
func
(
dbp
*
DebuggedProcess
)
run
(
fn
func
()
error
)
error
{
if
dbp
.
exited
{
return
errors
.
New
(
"process has already exited"
)
return
fmt
.
Errorf
(
"process has already exited"
)
}
dbp
.
running
=
true
dbp
.
halt
=
false
...
...
proctl/proctl_darwin.go
浏览文件 @
794d5b1e
...
...
@@ -6,7 +6,6 @@ import "C"
import
(
"debug/gosym"
"debug/macho"
"errors"
"fmt"
"os"
"path/filepath"
...
...
@@ -50,7 +49,7 @@ func Launch(cmd []string) (*DebuggedProcess, error) {
pid
:=
int
(
C
.
fork_exec
(
C
.
CString
(
argv0
),
&
argv
,
&
dbp
.
os
.
task
,
&
dbp
.
os
.
portSet
,
&
dbp
.
os
.
exceptionPort
,
&
dbp
.
os
.
notificationPort
))
if
pid
<=
0
{
return
nil
,
errors
.
New
(
"could not fork/exec"
)
return
nil
,
fmt
.
Errorf
(
"could not fork/exec"
)
}
dbp
.
Pid
=
pid
...
...
@@ -70,7 +69,7 @@ func (dbp *DebuggedProcess) requestManualStop() (err error) {
)
kret
:=
C
.
raise_exception
(
task
,
thread
,
exceptionPort
,
C
.
EXC_BREAKPOINT
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not raise mach exception"
)
return
fmt
.
Errorf
(
"could not raise mach exception"
)
}
return
nil
}
...
...
@@ -82,7 +81,7 @@ func (dbp *DebuggedProcess) updateThreadList() error {
count
=
C
.
thread_count
(
C
.
task_t
(
dbp
.
os
.
task
))
)
if
count
==
-
1
{
return
errors
.
New
(
"could not get thread count"
)
return
fmt
.
Errorf
(
"could not get thread count"
)
}
list
:=
make
([]
uint32
,
count
)
...
...
@@ -90,10 +89,10 @@ func (dbp *DebuggedProcess) updateThreadList() error {
// instead of getting count above and passing in a slice
kret
=
C
.
get_threads
(
C
.
task_t
(
dbp
.
os
.
task
),
unsafe
.
Pointer
(
&
list
[
0
]))
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not get thread list"
)
return
fmt
.
Errorf
(
"could not get thread list"
)
}
if
count
<
0
{
return
errors
.
New
(
"could not get thread list"
)
return
fmt
.
Errorf
(
"could not get thread list"
)
}
for
_
,
port
:=
range
list
{
...
...
@@ -233,7 +232,7 @@ func (dbp *DebuggedProcess) trapWait(pid int) (*ThreadContext, error) {
}
return
nil
,
ManualStopError
{}
case
0
:
return
nil
,
errors
.
New
(
"error while waiting for task"
)
return
nil
,
fmt
.
Errorf
(
"error while waiting for task"
)
}
// Since we cannot be notified of new threads on OS X
...
...
proctl/registers_darwin_amd64.go
浏览文件 @
794d5b1e
...
...
@@ -2,7 +2,7 @@ package proctl
// #include "threads_darwin.h"
import
"C"
import
"
errors
"
import
"
fmt
"
type
Regs
struct
{
pc
,
sp
uint64
...
...
@@ -19,7 +19,7 @@ func (r *Regs) SP() uint64 {
func
(
r
*
Regs
)
SetPC
(
thread
*
ThreadContext
,
pc
uint64
)
error
{
kret
:=
C
.
set_pc
(
thread
.
os
.
thread_act
,
C
.
uint64_t
(
pc
))
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not set pc"
)
return
fmt
.
Errorf
(
"could not set pc"
)
}
return
nil
}
...
...
@@ -28,7 +28,7 @@ func registers(thread *ThreadContext) (Registers, error) {
var
state
C
.
x86_thread_state64_t
kret
:=
C
.
get_registers
(
C
.
mach_port_name_t
(
thread
.
os
.
thread_act
),
&
state
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
nil
,
errors
.
New
(
"could not get registers"
)
return
nil
,
fmt
.
Errorf
(
"could not get registers"
)
}
regs
:=
&
Regs
{
pc
:
uint64
(
state
.
__rip
),
sp
:
uint64
(
state
.
__rsp
)}
return
regs
,
nil
...
...
proctl/threads_darwin.go
浏览文件 @
794d5b1e
...
...
@@ -3,7 +3,6 @@ package proctl
// #include "threads_darwin.h"
import
"C"
import
(
"errors"
"fmt"
"unsafe"
)
...
...
@@ -25,12 +24,12 @@ func (t *ThreadContext) Halt() error {
func
(
t
*
ThreadContext
)
singleStep
()
error
{
kret
:=
C
.
single_step
(
t
.
os
.
thread_act
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not single step"
)
return
fmt
.
Errorf
(
"could not single step"
)
}
t
.
Process
.
trapWait
(
0
)
kret
=
C
.
clear_trap_flag
(
t
.
os
.
thread_act
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not clear CPU trap flag"
)
return
fmt
.
Errorf
(
"could not clear CPU trap flag"
)
}
return
nil
}
...
...
@@ -42,7 +41,7 @@ func (t *ThreadContext) resume() error {
}
kret
:=
C
.
resume_thread
(
t
.
os
.
thread_act
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not continue thread"
)
return
fmt
.
Errorf
(
"could not continue thread"
)
}
return
nil
}
...
...
@@ -65,7 +64,7 @@ func writeMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error)
)
if
ret
:=
C
.
write_memory
(
thread
.
Process
.
os
.
task
,
vm_addr
,
vm_data
,
length
);
ret
<
0
{
return
0
,
errors
.
New
(
"could not write memory"
)
return
0
,
fmt
.
Errorf
(
"could not write memory"
)
}
return
len
(
data
),
nil
}
...
...
@@ -79,7 +78,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
ret
:=
C
.
read_memory
(
thread
.
Process
.
os
.
task
,
vm_addr
,
vm_data
,
length
)
if
ret
<
0
{
return
0
,
errors
.
New
(
"could not read memory"
)
return
0
,
fmt
.
Errorf
(
"could not read memory"
)
}
return
len
(
data
),
nil
}
...
...
@@ -87,7 +86,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
func
(
thread
*
ThreadContext
)
saveRegisters
()
(
Registers
,
error
)
{
kret
:=
C
.
get_registers
(
C
.
mach_port_name_t
(
thread
.
os
.
thread_act
),
&
thread
.
os
.
registers
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
nil
,
errors
.
New
(
"could not save register contents"
)
return
nil
,
fmt
.
Errorf
(
"could not save register contents"
)
}
return
&
Regs
{
pc
:
uint64
(
thread
.
os
.
registers
.
__rip
),
sp
:
uint64
(
thread
.
os
.
registers
.
__rsp
)},
nil
}
...
...
@@ -95,7 +94,7 @@ func (thread *ThreadContext) saveRegisters() (Registers, error) {
func
(
thread
*
ThreadContext
)
restoreRegisters
()
error
{
kret
:=
C
.
set_registers
(
C
.
mach_port_name_t
(
thread
.
os
.
thread_act
),
&
thread
.
os
.
registers
)
if
kret
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not save register contents"
)
return
fmt
.
Errorf
(
"could not save register contents"
)
}
return
nil
}
proctl/threads_linux.go
浏览文件 @
794d5b1e
package
proctl
import
(
"errors"
"fmt"
sys
"golang.org/x/sys/unix"
...
...
@@ -53,7 +52,7 @@ func (t *ThreadContext) blocked() bool {
func
(
thread
*
ThreadContext
)
saveRegisters
()
(
Registers
,
error
)
{
if
err
:=
sys
.
PtraceGetRegs
(
thread
.
Id
,
&
thread
.
os
.
registers
);
err
!=
nil
{
return
nil
,
errors
.
New
(
"could not save register contents"
)
return
nil
,
fmt
.
Errorf
(
"could not save register contents"
)
}
return
&
Regs
{
&
thread
.
os
.
registers
},
nil
}
...
...
proctl/variables.go
浏览文件 @
794d5b1e
...
...
@@ -5,7 +5,6 @@ import (
"debug/dwarf"
"debug/gosym"
"encoding/binary"
"errors"
"fmt"
"strconv"
"strings"
...
...
@@ -84,7 +83,7 @@ func (thread *ThreadContext) AllM() ([]*M, error) {
}
m
:=
binary
.
LittleEndian
.
Uint64
(
mptr
)
if
m
==
0
{
return
nil
,
errors
.
New
(
"allm contains no M pointers"
)
return
nil
,
fmt
.
Errorf
(
"allm contains no M pointers"
)
}
procidInstructions
,
err
:=
instructionsFor
(
"procid"
,
thread
.
Process
,
reader
,
true
)
...
...
@@ -191,7 +190,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
if
entry
.
Tag
==
dwarf
.
TagMember
{
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrDataMemberLoc
)
.
([]
byte
)
if
!
ok
{
return
nil
,
errors
.
New
(
"member data has no data member location attribute"
)
return
nil
,
fmt
.
Errorf
(
"member data has no data member location attribute"
)
}
// clone slice to prevent stomping on the dwarf data
return
append
([]
byte
{},
instructions
...
),
nil
...
...
@@ -200,7 +199,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
// non-member
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrLocation
)
.
([]
byte
)
if
!
ok
{
return
nil
,
errors
.
New
(
"entry has no location attribute"
)
return
nil
,
fmt
.
Errorf
(
"entry has no location attribute"
)
}
// clone slice to prevent stomping on the dwarf data
...
...
@@ -225,7 +224,7 @@ func parseAllMPtr(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrLocation
)
.
([]
byte
)
if
!
ok
{
return
0
,
errors
.
New
(
"type assertion failed"
)
return
0
,
fmt
.
Errorf
(
"type assertion failed"
)
}
addr
,
err
:=
op
.
ExecuteStackProgram
(
0
,
instructions
)
if
err
!=
nil
{
...
...
@@ -321,7 +320,7 @@ func allglenval(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrLocation
)
.
([]
byte
)
if
!
ok
{
return
0
,
errors
.
New
(
"type assertion failed"
)
return
0
,
fmt
.
Errorf
(
"type assertion failed"
)
}
addr
,
err
:=
op
.
ExecuteStackProgram
(
0
,
instructions
)
if
err
!=
nil
{
...
...
@@ -342,7 +341,7 @@ func addressFor(dbp *DebuggedProcess, name string, reader *dwarf.Reader) (uint64
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrLocation
)
.
([]
byte
)
if
!
ok
{
return
0
,
errors
.
New
(
"type assertion failed"
)
return
0
,
fmt
.
Errorf
(
"type assertion failed"
)
}
addr
,
err
:=
op
.
ExecuteStackProgram
(
0
,
instructions
)
if
err
!=
nil
{
...
...
@@ -359,7 +358,7 @@ func offsetFor(name string, reader *dwarf.Reader, parentinstr []byte) (uint64, e
}
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrDataMemberLoc
)
.
([]
byte
)
if
!
ok
{
return
0
,
errors
.
New
(
"type assertion failed"
)
return
0
,
fmt
.
Errorf
(
"type assertion failed"
)
}
offset
,
err
:=
op
.
ExecuteStackProgram
(
0
,
append
(
parentinstr
,
instructions
...
))
if
err
!=
nil
{
...
...
@@ -490,7 +489,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Get parent variable name
parentName
,
ok
:=
parentEntry
.
Val
(
dwarf
.
AttrName
)
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"unable to retrive variable name"
)
return
nil
,
fmt
.
Errorf
(
"unable to retrive variable name"
)
}
// Seek reader to the type information so members can be iterated
...
...
@@ -523,7 +522,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
offset
,
ok
:=
memberEntry
.
Val
(
dwarf
.
AttrType
)
.
(
dwarf
.
Offset
)
if
!
ok
{
return
nil
,
errors
.
New
(
"type assertion failed"
)
return
nil
,
fmt
.
Errorf
(
"type assertion failed"
)
}
data
:=
thread
.
Process
.
dwarf
...
...
@@ -550,7 +549,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Extracts the name, type, and value of a variable from a dwarf entry
func
(
thread
*
ThreadContext
)
extractVariableFromEntry
(
entry
*
dwarf
.
Entry
)
(
*
Variable
,
error
)
{
if
entry
==
nil
{
return
nil
,
errors
.
New
(
"invalid entry"
)
return
nil
,
fmt
.
Errorf
(
"invalid entry"
)
}
if
entry
.
Tag
!=
dwarf
.
TagFormalParameter
&&
entry
.
Tag
!=
dwarf
.
TagVariable
{
...
...
@@ -559,12 +558,12 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
n
,
ok
:=
entry
.
Val
(
dwarf
.
AttrName
)
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"type assertion failed"
)
return
nil
,
fmt
.
Errorf
(
"type assertion failed"
)
}
offset
,
ok
:=
entry
.
Val
(
dwarf
.
AttrType
)
.
(
dwarf
.
Offset
)
if
!
ok
{
return
nil
,
errors
.
New
(
"type assertion failed"
)
return
nil
,
fmt
.
Errorf
(
"type assertion failed"
)
}
data
:=
thread
.
Process
.
dwarf
...
...
@@ -575,7 +574,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
instructions
,
ok
:=
entry
.
Val
(
dwarf
.
AttrLocation
)
.
([]
byte
)
if
!
ok
{
return
nil
,
errors
.
New
(
"type assertion failed"
)
return
nil
,
fmt
.
Errorf
(
"type assertion failed"
)
}
val
,
err
:=
thread
.
extractValue
(
instructions
,
0
,
t
,
true
)
...
...
@@ -911,7 +910,7 @@ func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error)
return
strconv
.
FormatFloat
(
n
,
'f'
,
-
1
,
int
(
size
)
*
8
),
nil
}
return
""
,
errors
.
New
(
"could not read float"
)
return
""
,
fmt
.
Errorf
(
"could not read float"
)
}
func
(
thread
*
ThreadContext
)
readBool
(
addr
uintptr
)
(
string
,
error
)
{
...
...
proctl/variables_test.go
浏览文件 @
794d5b1e
package
proctl
import
(
"
errors
"
"
fmt
"
"path/filepath"
"sort"
"testing"
...
...
@@ -56,8 +56,8 @@ func TestVariableEvaluation(t *testing.T) {
{
"a6.Baz"
,
"8"
,
"int"
,
nil
},
{
"a7.Baz"
,
"5"
,
"int"
,
nil
},
{
"a8.Baz"
,
"feh"
,
"struct string"
,
nil
},
{
"a9.Baz"
,
"nil"
,
"int"
,
errors
.
New
(
"a9 is nil"
)},
{
"a9.NonExistent"
,
"nil"
,
"int"
,
errors
.
New
(
"a9 has no member NonExistent"
)},
{
"a9.Baz"
,
"nil"
,
"int"
,
fmt
.
Errorf
(
"a9 is nil"
)},
{
"a9.NonExistent"
,
"nil"
,
"int"
,
fmt
.
Errorf
(
"a9 has no member NonExistent"
)},
{
"a8"
,
"main.FooBar2 {Bur: 10, Baz: feh}"
,
"main.FooBar2"
,
nil
},
// reread variable after member
{
"i32"
,
"[2]int32 [1,2]"
,
"[2]int32"
,
nil
},
{
"b1"
,
"true"
,
"bool"
,
nil
},
...
...
@@ -70,7 +70,7 @@ func TestVariableEvaluation(t *testing.T) {
{
"f"
,
"main.barfoo"
,
"func()"
,
nil
},
{
"ba"
,
"[]int len: 200, cap: 200, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+136 more]"
,
"struct []int"
,
nil
},
{
"ms"
,
"main.Nest {Level: 0, Nest: *main.Nest {Level: 1, Nest: *main.Nest {...}}}"
,
"main.Nest"
,
nil
},
{
"NonExistent"
,
""
,
""
,
errors
.
New
(
"could not find symbol value for NonExistent"
)},
{
"NonExistent"
,
""
,
""
,
fmt
.
Errorf
(
"could not find symbol value for NonExistent"
)},
}
withTestProcess
(
executablePath
,
t
,
func
(
p
*
DebuggedProcess
)
{
...
...
service/debugger/debugger.go
浏览文件 @
794d5b1e
package
debugger
import
(
"errors"
"fmt"
"log"
"regexp"
...
...
@@ -66,7 +65,7 @@ func New(config *Config) *Debugger {
// operation.
func
(
d
*
Debugger
)
withProcess
(
f
func
(
*
proctl
.
DebuggedProcess
)
error
)
error
{
if
!
d
.
running
{
return
errors
.
New
(
"debugger isn't running"
)
return
fmt
.
Errorf
(
"debugger isn't running"
)
}
result
:=
make
(
chan
error
)
...
...
@@ -162,7 +161,7 @@ func (d *Debugger) Run() error {
// Detach stops the debugger.
func
(
d
*
Debugger
)
Detach
(
kill
bool
)
error
{
if
!
d
.
running
{
return
errors
.
New
(
"debugger isn't running"
)
return
fmt
.
Errorf
(
"debugger isn't running"
)
}
d
.
stop
<-
stopSignal
{
KillProcess
:
kill
}
...
...
@@ -206,7 +205,7 @@ func (d *Debugger) CreateBreakPoint(requestedBp *api.BreakPoint) (*api.BreakPoin
case
len
(
requestedBp
.
FunctionName
)
>
0
:
loc
=
requestedBp
.
FunctionName
default
:
return
errors
.
New
(
"no file or function name specified"
)
return
fmt
.
Errorf
(
"no file or function name specified"
)
}
bp
,
breakError
:=
p
.
BreakByLocation
(
loc
)
...
...
terminal/command.go
浏览文件 @
794d5b1e
...
...
@@ -4,7 +4,6 @@ package terminal
import
(
"bufio"
"errors"
"fmt"
"io"
"os"
...
...
@@ -107,7 +106,7 @@ func CommandFunc(fn func() error) cmdfunc {
}
func
noCmdAvailable
(
client
service
.
Client
,
args
...
string
)
error
{
return
errors
.
New
(
"command not available"
)
return
fmt
.
Errorf
(
"command not available"
)
}
func
nullCommand
(
client
service
.
Client
,
args
...
string
)
error
{
...
...
@@ -221,7 +220,7 @@ func next(client service.Client, args ...string) error {
func
clear
(
client
service
.
Client
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments"
)
return
fmt
.
Errorf
(
"not enough arguments"
)
}
id
,
err
:=
strconv
.
Atoi
(
args
[
0
])
...
...
@@ -273,7 +272,7 @@ func breakpoints(client service.Client, args ...string) error {
func
breakpoint
(
client
service
.
Client
,
args
...
string
)
error
{
if
len
(
args
)
!=
1
{
return
errors
.
New
(
"argument must be either a function name or <file:line>"
)
return
fmt
.
Errorf
(
"argument must be either a function name or <file:line>"
)
}
requestedBp
:=
&
api
.
BreakPoint
{}
tokens
:=
strings
.
Split
(
args
[
0
],
":"
)
...
...
@@ -289,7 +288,7 @@ func breakpoint(client service.Client, args ...string) error {
requestedBp
.
File
=
file
requestedBp
.
Line
=
line
default
:
return
errors
.
New
(
"invalid line reference"
)
return
fmt
.
Errorf
(
"invalid line reference"
)
}
bp
,
err
:=
client
.
CreateBreakPoint
(
requestedBp
)
...
...
@@ -303,7 +302,7 @@ func breakpoint(client service.Client, args ...string) error {
func
printVar
(
client
service
.
Client
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments"
)
return
fmt
.
Errorf
(
"not enough arguments"
)
}
val
,
err
:=
client
.
EvalSymbol
(
args
[
0
])
...
...
@@ -327,7 +326,7 @@ func filterVariables(vars []api.Variable, filter *regexp.Regexp) []string {
func
info
(
client
service
.
Client
,
args
...
string
)
error
{
if
len
(
args
)
==
0
{
return
errors
.
New
(
"not enough arguments. expected info type [regex]."
)
return
fmt
.
Errorf
(
"not enough arguments. expected info type [regex]."
)
}
// Allow for optional regex
...
...
@@ -398,7 +397,7 @@ func info(client service.Client, args ...string) error {
}
default
:
return
errors
.
New
(
"unsupported info type, must be args, funcs, locals, sources, or vars"
)
return
fmt
.
Errorf
(
"unsupported info type, must be args, funcs, locals, sources, or vars"
)
}
// sort and output data
...
...
terminal/command_test.go
浏览文件 @
794d5b1e
package
terminal
import
(
"
errors
"
"
fmt
"
"testing"
"github.com/derekparker/delve/service"
...
...
@@ -25,7 +25,7 @@ func TestCommandDefault(t *testing.T) {
func
TestCommandReplay
(
t
*
testing
.
T
)
{
cmds
:=
DebugCommands
(
nil
)
cmds
.
Register
(
"foo"
,
func
(
client
service
.
Client
,
args
...
string
)
error
{
return
errors
.
New
(
"registered command"
)
},
"foo command"
)
cmds
.
Register
(
"foo"
,
func
(
client
service
.
Client
,
args
...
string
)
error
{
return
fmt
.
Errorf
(
"registered command"
)
},
"foo command"
)
cmd
:=
cmds
.
Find
(
"foo"
)
err
:=
cmd
(
nil
)
...
...
terminal/terminal.go
浏览文件 @
794d5b1e
package
terminal
import
(
"errors"
"fmt"
"io"
"os"
...
...
@@ -80,7 +79,7 @@ func (t *Term) Run() (error, int) {
if
err
==
io
.
EOF
{
err
,
status
=
handleExit
(
t
.
client
,
t
)
}
err
,
status
=
errors
.
New
(
"Prompt for input failed.
\n
"
),
1
err
,
status
=
fmt
.
Errorf
(
"Prompt for input failed.
\n
"
),
1
break
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录