Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
delve
提交
ff3e2344
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,发现更多精彩内容 >>
提交
ff3e2344
编写于
11月 07, 2015
作者:
A
aarzilli
提交者:
Derek Parker
12月 15, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
proc/eval: Support type casts between basic types
上级
a0ba4818
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
114 addition
and
27 deletion
+114
-27
_fixtures/testvariables3.go
_fixtures/testvariables3.go
+4
-1
proc/eval.go
proc/eval.go
+89
-18
proc/variables.go
proc/variables.go
+11
-8
service/test/variables_test.go
service/test/variables_test.go
+10
-0
未找到文件。
_fixtures/testvariables3.go
浏览文件 @
ff3e2344
...
@@ -93,11 +93,14 @@ func main() {
...
@@ -93,11 +93,14 @@ func main() {
m2
:=
map
[
int
]
*
astruct
{
1
:
&
astruct
{
10
,
11
}}
m2
:=
map
[
int
]
*
astruct
{
1
:
&
astruct
{
10
,
11
}}
m3
:=
map
[
astruct
]
int
{{
1
,
1
}
:
42
,
{
2
,
2
}
:
43
}
m3
:=
map
[
astruct
]
int
{{
1
,
1
}
:
42
,
{
2
,
2
}
:
43
}
up1
:=
unsafe
.
Pointer
(
&
i1
)
up1
:=
unsafe
.
Pointer
(
&
i1
)
i4
:=
800
i5
:=
-
3
i6
:=
-
500
var
amb1
=
1
var
amb1
=
1
runtime
.
Breakpoint
()
runtime
.
Breakpoint
()
for
amb1
:=
0
;
amb1
<
10
;
amb1
++
{
for
amb1
:=
0
;
amb1
<
10
;
amb1
++
{
fmt
.
Println
(
amb1
)
fmt
.
Println
(
amb1
)
}
}
fmt
.
Println
(
i1
,
i2
,
i3
,
p1
,
amb1
,
s1
,
a1
,
p2
,
p3
,
s2
,
as1
,
str1
,
f1
,
fn1
,
fn2
,
nilslice
,
nilptr
,
ch1
,
chnil
,
m1
,
mnil
,
m2
,
m3
,
up1
)
fmt
.
Println
(
i1
,
i2
,
i3
,
p1
,
amb1
,
s1
,
a1
,
p2
,
p3
,
s2
,
as1
,
str1
,
f1
,
fn1
,
fn2
,
nilslice
,
nilptr
,
ch1
,
chnil
,
m1
,
mnil
,
m2
,
m3
,
up1
,
i4
,
i5
,
i6
)
}
}
proc/eval.go
浏览文件 @
ff3e2344
...
@@ -3,6 +3,7 @@ package proc
...
@@ -3,6 +3,7 @@ package proc
import
(
import
(
"bytes"
"bytes"
"debug/dwarf"
"debug/dwarf"
"encoding/binary"
"fmt"
"fmt"
"go/ast"
"go/ast"
"go/constant"
"go/constant"
...
@@ -165,7 +166,7 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
...
@@ -165,7 +166,7 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
fnnode
=
p
.
X
fnnode
=
p
.
X
}
}
var
typ
dwarf
.
Type
var
styp
,
typ
dwarf
.
Type
if
snode
,
ok
:=
fnnode
.
(
*
ast
.
StarExpr
);
ok
{
if
snode
,
ok
:=
fnnode
.
(
*
ast
.
StarExpr
);
ok
{
// Pointer types only appear in the dwarf informations when
// Pointer types only appear in the dwarf informations when
...
@@ -177,33 +178,103 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
...
@@ -177,33 +178,103 @@ func (scope *EvalScope) evalTypeCast(node *ast.CallExpr) (*Variable, error) {
return
nil
,
err
return
nil
,
err
}
}
typ
=
&
dwarf
.
PtrType
{
dwarf
.
CommonType
{
int64
(
scope
.
Thread
.
dbp
.
arch
.
PtrSize
()),
exprToString
(
fnnode
)},
ptyp
}
typ
=
&
dwarf
.
PtrType
{
dwarf
.
CommonType
{
int64
(
scope
.
Thread
.
dbp
.
arch
.
PtrSize
()),
exprToString
(
fnnode
)},
ptyp
}
styp
=
typ
}
else
{
}
else
{
typ
,
err
=
scope
.
findType
(
exprToString
(
fnnode
))
s
typ
,
err
=
scope
.
findType
(
exprToString
(
fnnode
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
typ
=
resolveTypedef
(
styp
)
}
}
// only supports cast of integer constants into pointers
converr
:=
fmt
.
Errorf
(
"can not convert
\"
%s
\"
to %s"
,
exprToString
(
node
.
Args
[
0
]),
typ
.
String
())
ptyp
,
isptrtyp
:=
typ
.
(
*
dwarf
.
PtrType
)
if
!
isptrtyp
{
return
nil
,
fmt
.
Errorf
(
"can not convert
\"
%s
\"
to %s"
,
exprToString
(
node
.
Args
[
0
]),
typ
.
String
())
}
switch
argv
.
Kind
{
v
:=
newVariable
(
""
,
0
,
styp
,
scope
.
Thread
)
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
v
.
loaded
=
true
// ok
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
switch
ttyp
:=
typ
.
(
type
)
{
// ok
case
*
dwarf
.
PtrType
:
default
:
switch
argv
.
Kind
{
return
nil
,
fmt
.
Errorf
(
"can not convert
\"
%s
\"
to %s"
,
exprToString
(
node
.
Args
[
0
]),
typ
.
String
())
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
// ok
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
// ok
default
:
return
nil
,
converr
}
n
,
_
:=
constant
.
Int64Val
(
argv
.
Value
)
v
.
Children
=
[]
Variable
{
*
newVariable
(
""
,
uintptr
(
n
),
ttyp
.
Type
,
scope
.
Thread
)}
return
v
,
nil
case
*
dwarf
.
UintType
:
switch
argv
.
Kind
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
n
,
_
:=
constant
.
Int64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeUint64
(
convertInt
(
uint64
(
n
),
false
,
ttyp
.
Size
()))
return
v
,
nil
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
n
,
_
:=
constant
.
Uint64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeUint64
(
convertInt
(
n
,
false
,
ttyp
.
Size
()))
return
v
,
nil
case
reflect
.
Float32
,
reflect
.
Float64
:
x
,
_
:=
constant
.
Float64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeUint64
(
uint64
(
x
))
return
v
,
nil
}
case
*
dwarf
.
IntType
:
switch
argv
.
Kind
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
n
,
_
:=
constant
.
Int64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeInt64
(
int64
(
convertInt
(
uint64
(
n
),
true
,
ttyp
.
Size
())))
return
v
,
nil
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
n
,
_
:=
constant
.
Uint64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeInt64
(
int64
(
convertInt
(
n
,
true
,
ttyp
.
Size
())))
return
v
,
nil
case
reflect
.
Float32
,
reflect
.
Float64
:
x
,
_
:=
constant
.
Float64Val
(
argv
.
Value
)
v
.
Value
=
constant
.
MakeInt64
(
int64
(
x
))
return
v
,
nil
}
case
*
dwarf
.
FloatType
:
switch
argv
.
Kind
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
fallthrough
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
fallthrough
case
reflect
.
Float32
,
reflect
.
Float64
:
v
.
Value
=
argv
.
Value
return
v
,
nil
}
case
*
dwarf
.
ComplexType
:
switch
argv
.
Kind
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
fallthrough
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
fallthrough
case
reflect
.
Float32
,
reflect
.
Float64
:
v
.
Value
=
argv
.
Value
return
v
,
nil
}
}
}
n
,
_
:=
constant
.
Int64Val
(
argv
.
Value
)
return
nil
,
converr
}
v
:=
newVariable
(
""
,
0
,
ptyp
,
scope
.
Thread
)
func
convertInt
(
n
uint64
,
signed
bool
,
size
int64
)
uint64
{
v
.
Children
=
[]
Variable
{
*
newVariable
(
""
,
uintptr
(
n
),
ptyp
.
Type
,
scope
.
Thread
)}
buf
:=
make
([]
byte
,
64
/
8
)
return
v
,
nil
binary
.
BigEndian
.
PutUint64
(
buf
,
n
)
m
:=
64
/
8
-
int
(
size
)
s
:=
byte
(
0
)
if
signed
&&
(
buf
[
m
]
&
0x80
>
0
)
{
s
=
0xff
}
for
i
:=
0
;
i
<
m
;
i
++
{
buf
[
i
]
=
s
}
return
uint64
(
binary
.
BigEndian
.
Uint64
(
buf
))
}
}
// Evaluates identifier expressions
// Evaluates identifier expressions
...
...
proc/variables.go
浏览文件 @
ff3e2344
...
@@ -118,14 +118,7 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread
...
@@ -118,14 +118,7 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread
thread
:
thread
,
thread
:
thread
,
}
}
v
.
RealType
=
v
.
DwarfType
v
.
RealType
=
resolveTypedef
(
v
.
DwarfType
)
for
{
if
tt
,
ok
:=
v
.
RealType
.
(
*
dwarf
.
TypedefType
);
ok
{
v
.
RealType
=
tt
.
Type
}
else
{
break
}
}
switch
t
:=
v
.
RealType
.
(
type
)
{
switch
t
:=
v
.
RealType
.
(
type
)
{
case
*
dwarf
.
PtrType
:
case
*
dwarf
.
PtrType
:
...
@@ -201,6 +194,16 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread
...
@@ -201,6 +194,16 @@ func newVariable(name string, addr uintptr, dwarfType dwarf.Type, thread *Thread
return
v
return
v
}
}
func
resolveTypedef
(
typ
dwarf
.
Type
)
dwarf
.
Type
{
for
{
if
tt
,
ok
:=
typ
.
(
*
dwarf
.
TypedefType
);
ok
{
typ
=
tt
.
Type
}
else
{
return
typ
}
}
}
func
newConstant
(
val
constant
.
Value
,
thread
*
Thread
)
*
Variable
{
func
newConstant
(
val
constant
.
Value
,
thread
*
Thread
)
*
Variable
{
v
:=
&
Variable
{
Value
:
val
,
thread
:
thread
,
loaded
:
true
}
v
:=
&
Variable
{
Value
:
val
,
thread
:
thread
,
loaded
:
true
}
switch
val
.
Kind
()
{
switch
val
.
Kind
()
{
...
...
service/test/variables_test.go
浏览文件 @
ff3e2344
...
@@ -487,6 +487,16 @@ func TestEvalExpression(t *testing.T) {
...
@@ -487,6 +487,16 @@ func TestEvalExpression(t *testing.T) {
{
"*(i2 + i3)"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"expression
\"
(i2 + i3)
\"
(int) can not be dereferenced"
)},
{
"*(i2 + i3)"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"expression
\"
(i2 + i3)
\"
(int) can not be dereferenced"
)},
{
"i2.member"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"i2 (type int) is not a struct"
)},
{
"i2.member"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"i2 (type int) is not a struct"
)},
{
"fmt.Println(
\"
hello
\"
)"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"no type entry found"
)},
{
"fmt.Println(
\"
hello
\"
)"
,
false
,
""
,
""
,
""
,
fmt
.
Errorf
(
"no type entry found"
)},
// typecasts
{
"uint(i2)"
,
false
,
"2"
,
""
,
"uint"
,
nil
},
{
"int8(i2)"
,
false
,
"2"
,
""
,
"int8"
,
nil
},
{
"int(f1)"
,
false
,
"3"
,
""
,
"int"
,
nil
},
{
"complex128(f1)"
,
false
,
"(3 + 0i)"
,
""
,
"complex128"
,
nil
},
{
"uint8(i4)"
,
false
,
"32"
,
""
,
"uint8"
,
nil
},
{
"uint8(i5)"
,
false
,
"253"
,
""
,
"uint8"
,
nil
},
{
"int8(i5)"
,
false
,
"-3"
,
""
,
"int8"
,
nil
},
{
"int8(i6)"
,
false
,
"12"
,
""
,
"int8"
,
nil
},
}
}
withTestProcess
(
"testvariables3"
,
t
,
func
(
p
*
proc
.
Process
,
fixture
protest
.
Fixture
)
{
withTestProcess
(
"testvariables3"
,
t
,
func
(
p
*
proc
.
Process
,
fixture
protest
.
Fixture
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录