Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
delve
提交
e2236664
D
delve
项目概览
pubx
/
delve
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
delve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e2236664
编写于
1月 20, 2015
作者:
E
epipho
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Genericized array reading
上级
99b614a0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
33 addition
and
31 deletion
+33
-31
_fixtures/testvariables.go
_fixtures/testvariables.go
+2
-1
proctl/variables.go
proctl/variables.go
+22
-23
proctl/variables_test.go
proctl/variables_test.go
+9
-7
未找到文件。
_fixtures/testvariables.go
浏览文件 @
e2236664
...
...
@@ -30,6 +30,7 @@ func foobar(baz string, bar FooBar) {
a8
=
FooBar2
{
Bur
:
10
,
Baz
:
"feh"
}
a9
=
(
*
FooBar
)(
nil
)
a10
=
a1
[
2
:
5
]
a11
=
[
3
]
FooBar
{{
1
,
"a"
},
{
2
,
"b"
},
{
3
,
"c"
}}
b1
=
true
b2
=
false
neg
=
-
1
...
...
@@ -45,7 +46,7 @@ func foobar(baz string, bar FooBar) {
)
barfoo
()
fmt
.
Println
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
,
a9
,
a10
,
b1
,
b2
,
baz
,
neg
,
i8
,
u8
,
u16
,
u32
,
u64
,
up
,
f32
,
i32
,
bar
,
f
)
fmt
.
Println
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
,
a9
,
a10
,
a11
,
b1
,
b2
,
baz
,
neg
,
i8
,
u8
,
u16
,
u32
,
u64
,
up
,
f32
,
i32
,
bar
,
f
)
}
func
main
()
{
...
...
proctl/variables.go
浏览文件 @
e2236664
...
...
@@ -448,7 +448,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
binary
.
LittleEndian
.
PutUint64
(
baseAddr
,
uint64
(
parentAddr
))
parentInstructions
:=
append
([]
byte
{
op
.
DW_OP_addr
},
baseAddr
...
)
val
,
err
:=
thread
.
extractValue
(
append
(
parentInstructions
,
memberInstr
...
),
0
,
t
)
val
,
err
:=
thread
.
extractValue
(
append
(
parentInstructions
,
memberInstr
...
),
0
,
t
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -490,7 +490,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
return
nil
,
fmt
.
Errorf
(
"type assertion failed"
)
}
val
,
err
:=
thread
.
extractValue
(
instructions
,
0
,
t
)
val
,
err
:=
thread
.
extractValue
(
instructions
,
0
,
t
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -556,7 +556,7 @@ func (thread *ThreadContext) extractVariableDataAddress(entry *dwarf.Entry, read
// Extracts the value from the instructions given in the DW_AT_location entry.
// We execute the stack program described in the DW_OP_* instruction stream, and
// then grab the value from the other processes memory.
func
(
thread
*
ThreadContext
)
extractValue
(
instructions
[]
byte
,
addr
int64
,
typ
interface
{})
(
string
,
error
)
{
func
(
thread
*
ThreadContext
)
extractValue
(
instructions
[]
byte
,
addr
int64
,
typ
interface
{}
,
printStructName
bool
)
(
string
,
error
)
{
var
err
error
if
addr
==
0
{
...
...
@@ -585,7 +585,7 @@ func (thread *ThreadContext) extractValue(instructions []byte, addr int64, typ i
return
fmt
.
Sprintf
(
"%s nil"
,
t
.
String
()),
nil
}
val
,
err
:=
thread
.
extractValue
(
nil
,
intaddr
,
t
.
Type
)
val
,
err
:=
thread
.
extractValue
(
nil
,
intaddr
,
t
.
Type
,
printStructName
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -602,18 +602,21 @@ func (thread *ThreadContext) extractValue(instructions []byte, addr int64, typ i
// the value of all the members of the struct.
fields
:=
make
([]
string
,
0
,
len
(
t
.
Field
))
for
_
,
field
:=
range
t
.
Field
{
val
,
err
:=
thread
.
extractValue
(
nil
,
field
.
ByteOffset
+
addr
,
field
.
Type
)
val
,
err
:=
thread
.
extractValue
(
nil
,
field
.
ByteOffset
+
addr
,
field
.
Type
,
printStructName
)
if
err
!=
nil
{
return
""
,
err
}
fields
=
append
(
fields
,
fmt
.
Sprintf
(
"%s: %s"
,
field
.
Name
,
val
))
}
retstr
:=
fmt
.
Sprintf
(
"%s {%s}"
,
t
.
StructName
,
strings
.
Join
(
fields
,
", "
))
return
retstr
,
nil
if
printStructName
{
return
fmt
.
Sprintf
(
"%s {%s}"
,
t
.
StructName
,
strings
.
Join
(
fields
,
", "
)),
nil
}
else
{
return
fmt
.
Sprintf
(
"{%s}"
,
strings
.
Join
(
fields
,
", "
)),
nil
}
}
case
*
dwarf
.
ArrayType
:
return
thread
.
read
Int
Array
(
ptraddress
,
t
)
return
thread
.
readArray
(
ptraddress
,
t
)
case
*
dwarf
.
IntType
:
return
thread
.
readInt
(
ptraddress
,
t
.
ByteSize
)
case
*
dwarf
.
UintType
:
...
...
@@ -681,23 +684,19 @@ func (thread *ThreadContext) readIntSlice(addr uintptr, t *dwarf.StructType) (st
return
""
,
fmt
.
Errorf
(
"Could not read slice"
)
}
func
(
thread
*
ThreadContext
)
readIntArray
(
addr
uintptr
,
t
*
dwarf
.
ArrayType
)
(
string
,
error
)
{
val
,
err
:=
thread
.
readMemory
(
addr
,
uintptr
(
t
.
ByteSize
))
func
(
thread
*
ThreadContext
)
readArray
(
addr
uintptr
,
t
*
dwarf
.
ArrayType
)
(
string
,
error
)
{
vals
:=
make
([]
string
,
0
)
stride
:=
t
.
ByteSize
/
t
.
Count
for
i
:=
int64
(
0
);
i
<
t
.
Count
;
i
++
{
val
,
err
:=
thread
.
extractValue
(
nil
,
int64
(
addr
+
uintptr
(
i
*
stride
)),
t
.
Type
,
false
)
if
err
!=
nil
{
return
""
,
err
}
switch
t
.
Type
.
Size
()
{
case
4
:
members
:=
*
(
*
[]
uint32
)(
unsafe
.
Pointer
(
&
val
))
setSliceLength
(
unsafe
.
Pointer
(
&
members
),
int
(
t
.
Count
))
return
fmt
.
Sprintf
(
"%s %d"
,
t
,
members
),
nil
case
8
:
members
:=
*
(
*
[]
uint64
)(
unsafe
.
Pointer
(
&
val
))
setSliceLength
(
unsafe
.
Pointer
(
&
members
),
int
(
t
.
Count
))
return
fmt
.
Sprintf
(
"%s %d"
,
t
,
members
),
nil
vals
=
append
(
vals
,
val
)
}
return
""
,
fmt
.
Errorf
(
"Could not read array"
)
return
fmt
.
Sprintf
(
"%s [%s]"
,
t
,
strings
.
Join
(
vals
,
","
)),
nil
}
func
(
thread
*
ThreadContext
)
readInt
(
addr
uintptr
,
size
int64
)
(
string
,
error
)
{
...
...
proctl/variables_test.go
浏览文件 @
e2236664
...
...
@@ -39,9 +39,10 @@ func TestVariableEvaluation(t *testing.T) {
testcases
:=
[]
varTest
{
{
"a1"
,
"foofoofoofoofoofoo"
,
"struct string"
,
nil
},
{
"a10"
,
"ofo"
,
"struct string"
,
nil
},
{
"a11"
,
"[3]main.FooBar [{Baz: 1, Bur: a},{Baz: 2, Bur: b},{Baz: 3, Bur: c}]"
,
"[3]main.FooBar"
,
nil
},
{
"a2"
,
"6"
,
"int"
,
nil
},
{
"a3"
,
"7.23"
,
"float64"
,
nil
},
{
"a4"
,
"[2]int [1
2]"
,
"[2]int"
,
nil
},
{
"a4"
,
"[2]int [1
,
2]"
,
"[2]int"
,
nil
},
{
"a5"
,
"len: 5 cap: 5 [1 2 3 4 5]"
,
"struct []int"
,
nil
},
{
"a6"
,
"main.FooBar {Baz: 8, Bur: word}"
,
"main.FooBar"
,
nil
},
{
"a7"
,
"*main.FooBar {Baz: 5, Bur: strum}"
,
"*main.FooBar"
,
nil
},
...
...
@@ -56,7 +57,7 @@ func TestVariableEvaluation(t *testing.T) {
{
"a9.Baz"
,
"nil"
,
"int"
,
errors
.
New
(
"a9 is nil"
)},
{
"a9.NonExistent"
,
"nil"
,
"int"
,
errors
.
New
(
"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
},
{
"i32"
,
"[2]int32 [1
,
2]"
,
"[2]int32"
,
nil
},
{
"b1"
,
"true"
,
"bool"
,
nil
},
{
"b2"
,
"false"
,
"bool"
,
nil
},
{
"i8"
,
"1"
,
"int8"
,
nil
},
{
"u16"
,
"65535"
,
"uint16"
,
nil
},
...
...
@@ -69,7 +70,7 @@ func TestVariableEvaluation(t *testing.T) {
}
withTestProcess
(
executablePath
,
t
,
func
(
p
*
DebuggedProcess
)
{
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
7
)
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
8
)
_
,
err
:=
p
.
Break
(
pc
)
assertNoError
(
err
,
t
,
"Break() returned an error"
)
...
...
@@ -100,7 +101,7 @@ func TestVariableFunctionScoping(t *testing.T) {
}
withTestProcess
(
executablePath
,
t
,
func
(
p
*
DebuggedProcess
)
{
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
7
)
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
8
)
_
,
err
:=
p
.
Break
(
pc
)
assertNoError
(
err
,
t
,
"Break() returned an error"
)
...
...
@@ -166,9 +167,10 @@ func TestLocalVariables(t *testing.T) {
[]
varTest
{
{
"a1"
,
"foofoofoofoofoofoo"
,
"struct string"
,
nil
},
{
"a10"
,
"ofo"
,
"struct string"
,
nil
},
{
"a11"
,
"[3]main.FooBar [{Baz: 1, Bur: a},{Baz: 2, Bur: b},{Baz: 3, Bur: c}]"
,
"[3]main.FooBar"
,
nil
},
{
"a2"
,
"6"
,
"int"
,
nil
},
{
"a3"
,
"7.23"
,
"float64"
,
nil
},
{
"a4"
,
"[2]int [1
2]"
,
"[2]int"
,
nil
},
{
"a4"
,
"[2]int [1
,
2]"
,
"[2]int"
,
nil
},
{
"a5"
,
"len: 5 cap: 5 [1 2 3 4 5]"
,
"struct []int"
,
nil
},
{
"a6"
,
"main.FooBar {Baz: 8, Bur: word}"
,
"main.FooBar"
,
nil
},
{
"a7"
,
"*main.FooBar {Baz: 5, Bur: strum}"
,
"*main.FooBar"
,
nil
},
...
...
@@ -178,7 +180,7 @@ func TestLocalVariables(t *testing.T) {
{
"b2"
,
"false"
,
"bool"
,
nil
},
{
"f"
,
"main.barfoo"
,
"func()"
,
nil
},
{
"f32"
,
"1.2"
,
"float32"
,
nil
},
{
"i32"
,
"[2]int32 [1
2]"
,
"[2]int32"
,
nil
},
{
"i32"
,
"[2]int32 [1
,
2]"
,
"[2]int32"
,
nil
},
{
"i8"
,
"1"
,
"int8"
,
nil
},
{
"neg"
,
"-1"
,
"int"
,
nil
},
{
"u16"
,
"65535"
,
"uint16"
,
nil
},
...
...
@@ -193,7 +195,7 @@ func TestLocalVariables(t *testing.T) {
}
withTestProcess
(
executablePath
,
t
,
func
(
p
*
DebuggedProcess
)
{
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
7
)
pc
,
_
,
_
:=
p
.
GoSymTable
.
LineToPC
(
fp
,
4
8
)
_
,
err
:=
p
.
Break
(
pc
)
assertNoError
(
err
,
t
,
"Break() returned an error"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录