Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
1f4580cd
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,发现更多精彩内容 >>
提交
1f4580cd
编写于
6月 06, 2014
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: burn bytes for CIE pointer
Also change function sig to be shorter
上级
28694f54
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
58 deletion
+80
-58
dwarf/frame.go
dwarf/frame.go
+76
-54
dwarf/frame_test.go
dwarf/frame_test.go
+4
-4
未找到文件。
dwarf/frame.go
浏览文件 @
1f4580cd
...
...
@@ -9,7 +9,13 @@ import (
"unicode/utf8"
)
type
parsefunc
func
(
*
bytes
.
Buffer
,
CommonEntries
,
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
type
parsefunc
func
(
*
parseContext
)
(
parsefunc
,
*
parseContext
)
type
parseContext
struct
{
Buf
*
bytes
.
Buffer
Entries
CommonEntries
Length
uint32
}
type
CommonEntries
[]
*
CommonInformationEntry
...
...
@@ -75,14 +81,15 @@ func Parse(data []byte) CommonEntries {
var
(
length
uint32
entries
CommonEntries
reader
=
bytes
.
NewBuffer
(
data
)
buf
=
bytes
.
NewBuffer
(
data
)
pctx
=
&
parseContext
{
Buf
:
buf
,
Entries
:
entries
,
Length
:
length
}
)
for
fn
:=
parseLength
;
reader
.
Len
()
!=
0
;
{
fn
,
entries
,
length
=
fn
(
reader
,
entries
,
length
)
for
fn
:=
parseLength
;
buf
.
Len
()
!=
0
;
{
fn
,
pctx
=
fn
(
pctx
)
}
return
e
ntries
return
pctx
.
E
ntries
}
// DecodeLEB128 decodes a Little Endian Base 128
...
...
@@ -118,126 +125,141 @@ func cieEntry(data []byte) bool {
return
bytes
.
Equal
(
data
,
[]
byte
{
0xff
,
0xff
,
0xff
,
0xff
})
}
func
parseLength
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
l
ength
)
func
parseLength
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
ctx
.
L
ength
)
if
cieEntry
(
reader
.
Bytes
()[
0
:
4
])
{
return
parseCIEID
,
append
(
entries
,
&
CommonInformationEntry
{
Length
:
length
}),
length
if
cieEntry
(
ctx
.
Buf
.
Bytes
()[
0
:
4
])
{
ctx
.
Entries
=
append
(
ctx
.
Entries
,
&
CommonInformationEntry
{
Length
:
ctx
.
Length
})
return
parseCIEID
,
ctx
}
entry
:=
entries
[
len
(
e
ntries
)
-
1
]
entry
.
FrameDescriptorEntries
=
append
(
entry
.
FrameDescriptorEntries
,
&
FrameDescriptorEntry
{
Length
:
l
ength
,
CIE_pointer
:
entry
})
entry
:=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
entry
.
FrameDescriptorEntries
=
append
(
entry
.
FrameDescriptorEntries
,
&
FrameDescriptorEntry
{
Length
:
ctx
.
L
ength
,
CIE_pointer
:
entry
})
return
parseInitialLocation
,
entries
,
length
// We aren't reading the CIE pointer from this section so just move the cursor past it.
ctx
.
Buf
.
Next
(
4
)
return
parseInitialLocation
,
ctx
}
func
parseInitialLocation
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseInitialLocation
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
frameEntries
=
entries
[
len
(
e
ntries
)
-
1
]
.
FrameDescriptorEntries
frameEntries
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
.
FrameDescriptorEntries
frame
=
frameEntries
[
len
(
frameEntries
)
-
1
]
)
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
frame
.
InitialLocation
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
frame
.
InitialLocation
)
ctx
.
Length
-=
4
return
parseAddressRange
,
entries
,
length
-
4
return
parseAddressRange
,
ctx
}
func
parseAddressRange
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseAddressRange
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
frameEntries
=
entries
[
len
(
e
ntries
)
-
1
]
.
FrameDescriptorEntries
frameEntries
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
.
FrameDescriptorEntries
frame
=
frameEntries
[
len
(
frameEntries
)
-
1
]
)
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
frame
.
AddressRange
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
frame
.
AddressRange
)
ctx
.
Length
-=
4
return
parseFrameInstructions
,
entries
,
length
-
4
return
parseFrameInstructions
,
ctx
}
func
parseFrameInstructions
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseFrameInstructions
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
// The rest of this entry consists of the instructions
// so we can just grab all of the data from the buffer
// cursor to length.
buf
=
make
([]
byte
,
l
ength
)
frameEntries
=
entries
[
len
(
e
ntries
)
-
1
]
.
FrameDescriptorEntries
buf
=
make
([]
byte
,
ctx
.
L
ength
)
frameEntries
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
.
FrameDescriptorEntries
frame
=
frameEntries
[
len
(
frameEntries
)
-
1
]
)
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
buf
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
buf
)
frame
.
Instructions
=
buf
ctx
.
Length
=
0
return
parseLength
,
entries
,
0
return
parseLength
,
ctx
}
func
parseCIEID
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
var
entry
=
entries
[
len
(
e
ntries
)
-
1
]
func
parseCIEID
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
entry
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
entry
.
CIE_id
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
entry
.
CIE_id
)
ctx
.
Length
-=
4
return
parseVersion
,
entries
,
length
-
4
return
parseVersion
,
ctx
}
func
parseVersion
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
entry
:=
entries
[
len
(
e
ntries
)
-
1
]
func
parseVersion
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
entry
:=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
entry
.
Version
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
entry
.
Version
)
ctx
.
Length
-=
1
return
parseAugmentation
,
entries
,
length
-
1
return
parseAugmentation
,
ctx
}
func
parseAugmentation
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseAugmentation
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
entry
=
entries
[
len
(
e
ntries
)
-
1
]
str
,
c
=
parseString
(
reader
)
entry
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
str
,
c
=
parseString
(
ctx
.
Buf
)
)
entry
.
Augmentation
=
str
return
parseCodeAlignmentFactor
,
entries
,
length
-
c
ctx
.
Length
-=
c
return
parseCodeAlignmentFactor
,
ctx
}
func
parseCodeAlignmentFactor
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseCodeAlignmentFactor
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
entry
=
entries
[
len
(
e
ntries
)
-
1
]
caf
,
c
=
DecodeLEB128
(
reader
)
entry
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
caf
,
c
=
DecodeLEB128
(
ctx
.
Buf
)
)
entry
.
CodeAlignmentFactor
=
caf
ctx
.
Length
-=
c
return
parseDataAlignmentFactor
,
entries
,
length
-
c
return
parseDataAlignmentFactor
,
ctx
}
func
parseDataAlignmentFactor
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseDataAlignmentFactor
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
entry
=
entries
[
len
(
e
ntries
)
-
1
]
daf
,
c
=
DecodeLEB128
(
reader
)
entry
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
daf
,
c
=
DecodeLEB128
(
ctx
.
Buf
)
)
entry
.
DataAlignmentFactor
=
daf
ctx
.
Length
-=
c
return
parseReturnAddressRegister
,
entries
,
length
-
c
return
parseReturnAddressRegister
,
ctx
}
func
parseReturnAddressRegister
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
entry
:=
entries
[
len
(
e
ntries
)
-
1
]
func
parseReturnAddressRegister
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
entry
:=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
entry
.
ReturnAddressRegister
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
entry
.
ReturnAddressRegister
)
ctx
.
Length
-=
1
return
parseInitialInstructions
,
entries
,
length
-
1
return
parseInitialInstructions
,
ctx
}
func
parseInitialInstructions
(
reader
*
bytes
.
Buffer
,
entries
CommonEntries
,
length
uint32
)
(
parsefunc
,
CommonEntries
,
uint32
)
{
func
parseInitialInstructions
(
ctx
*
parseContext
)
(
parsefunc
,
*
parseContext
)
{
var
(
// The rest of this entry consists of the instructions
// so we can just grab all of the data from the buffer
// cursor to length.
buf
=
make
([]
byte
,
l
ength
)
entry
=
entries
[
len
(
e
ntries
)
-
1
]
buf
=
make
([]
byte
,
ctx
.
L
ength
)
entry
=
ctx
.
Entries
[
len
(
ctx
.
E
ntries
)
-
1
]
)
binary
.
Read
(
reader
,
binary
.
LittleEndian
,
&
buf
)
binary
.
Read
(
ctx
.
Buf
,
binary
.
LittleEndian
,
&
buf
)
entry
.
InitialInstructions
=
buf
ctx
.
Length
=
0
return
parseLength
,
entries
,
0
return
parseLength
,
ctx
}
func
parseString
(
data
*
bytes
.
Buffer
)
(
string
,
uint32
)
{
...
...
dwarf/frame_test.go
浏览文件 @
1f4580cd
...
...
@@ -88,11 +88,11 @@ func TestParse(t *testing.T) {
t
.
Fatal
(
"Frame entry does not point to parent CIE"
)
}
if
fe
.
InitialLocation
!=
0x400c00
00000000
{
t
.
Fatal
(
"Initial location not parsed correctly"
)
if
fe
.
InitialLocation
!=
0x400c00
{
t
.
Fatal
f
(
"Initial location not parsed correctly, got %#v"
,
fe
.
InitialLocation
)
}
if
fe
.
AddressRange
!=
0x
bc00000000
{
t
.
Fatal
(
"Address range not parsed correctly"
)
if
fe
.
AddressRange
!=
0x
2b
{
t
.
Fatal
f
(
"Address range not parsed correctly %#v
\n
%#v"
,
fe
.
AddressRange
,
data
[
15
:
48
]
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录