Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
b1640238
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 搜索 >>
提交
b1640238
编写于
1月 24, 2016
作者:
A
aarzilli
提交者:
Derek Parker
1月 24, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dwarf/frame: detecting dwarf section endianness
上级
1bfae45b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
69 addition
and
16 deletion
+69
-16
dwarf/frame/entries.go
dwarf/frame/entries.go
+2
-0
dwarf/frame/entries_test.go
dwarf/frame/entries_test.go
+2
-1
dwarf/frame/parser.go
dwarf/frame/parser.go
+24
-1
dwarf/frame/parser_test.go
dwarf/frame/parser_test.go
+2
-1
dwarf/frame/table.go
dwarf/frame/table.go
+5
-3
proc/proc_darwin.go
proc/proc_darwin.go
+10
-2
proc/proc_linux.go
proc/proc_linux.go
+10
-2
proc/proc_windows.go
proc/proc_windows.go
+14
-6
未找到文件。
dwarf/frame/entries.go
浏览文件 @
b1640238
package
frame
import
(
"encoding/binary"
"fmt"
"sort"
)
...
...
@@ -25,6 +26,7 @@ type FrameDescriptionEntry struct {
CIE
*
CommonInformationEntry
Instructions
[]
byte
begin
,
end
uint64
order
binary
.
ByteOrder
}
// Returns whether or not the given address is within the
...
...
dwarf/frame/entries_test.go
浏览文件 @
b1640238
package
frame
import
(
"encoding/binary"
"io/ioutil"
"os"
"testing"
...
...
@@ -39,7 +40,7 @@ func BenchmarkFDEForPC(b *testing.B) {
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
fdes
:=
Parse
(
data
)
fdes
:=
Parse
(
data
,
binary
.
BigEndian
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// bench worst case, exhaustive search
...
...
dwarf/frame/parser.go
浏览文件 @
b1640238
...
...
@@ -23,7 +23,7 @@ type parseContext struct {
// Parse takes in data (a byte slice) and returns a slice of
// commonInformationEntry structures. Each commonInformationEntry
// has a slice of frameDescriptionEntry structures.
func
Parse
(
data
[]
byte
)
FrameDescriptionEntries
{
func
Parse
(
data
[]
byte
,
order
binary
.
ByteOrder
)
FrameDescriptionEntries
{
var
(
buf
=
bytes
.
NewBuffer
(
data
)
pctx
=
&
parseContext
{
buf
:
buf
,
entries
:
NewFrameIndex
()}
...
...
@@ -33,6 +33,10 @@ func Parse(data []byte) FrameDescriptionEntries {
fn
=
fn
(
pctx
)
}
for
i
:=
range
pctx
.
entries
{
pctx
.
entries
[
i
]
.
order
=
order
}
return
pctx
.
entries
}
...
...
@@ -100,3 +104,22 @@ func parseCIE(ctx *parseContext) parsefunc {
return
parselength
}
// DwarfEndian determines the endianness of the DWARF by using the version number field in the debug_info section
// Trick borrowed from "debug/dwarf".New()
func
DwarfEndian
(
infoSec
[]
byte
)
binary
.
ByteOrder
{
if
len
(
infoSec
)
<
6
{
return
binary
.
BigEndian
}
x
,
y
:=
infoSec
[
4
],
infoSec
[
5
]
switch
{
case
x
==
0
&&
y
==
0
:
return
binary
.
BigEndian
case
x
==
0
:
return
binary
.
BigEndian
case
y
==
0
:
return
binary
.
LittleEndian
default
:
return
binary
.
BigEndian
}
}
dwarf/frame/parser_test.go
浏览文件 @
b1640238
package
frame_test
import
(
"encoding/binary"
"io/ioutil"
"os"
"testing"
...
...
@@ -24,6 +25,6 @@ func BenchmarkParse(b *testing.B) {
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
frame
.
Parse
(
data
)
frame
.
Parse
(
data
,
binary
.
BigEndian
)
}
}
dwarf/frame/table.go
浏览文件 @
b1640238
...
...
@@ -24,6 +24,7 @@ type DWRule struct {
type
FrameContext
struct
{
loc
uint64
order
binary
.
ByteOrder
address
uint64
cfa
CurrentFrameAddress
regs
map
[
uint64
]
DWRule
...
...
@@ -138,6 +139,7 @@ func executeCIEInstructions(cie *CommonInformationEntry) *FrameContext {
// Unwind the stack to find the return address register.
func
executeDwarfProgramUntilPC
(
fde
*
FrameDescriptionEntry
,
pc
uint64
)
*
FrameContext
{
frame
:=
executeCIEInstructions
(
fde
.
CIE
)
frame
.
order
=
fde
.
order
frame
.
loc
=
fde
.
Begin
()
frame
.
address
=
pc
fdeInstructions
:=
make
([]
byte
,
len
(
fde
.
Instructions
))
...
...
@@ -237,14 +239,14 @@ func advanceloc1(frame *FrameContext) {
func
advanceloc2
(
frame
*
FrameContext
)
{
var
delta
uint16
binary
.
Read
(
frame
.
buf
,
binary
.
BigEndian
,
&
delta
)
binary
.
Read
(
frame
.
buf
,
frame
.
order
,
&
delta
)
frame
.
loc
+=
uint64
(
delta
)
*
frame
.
codeAlignment
}
func
advanceloc4
(
frame
*
FrameContext
)
{
var
delta
uint32
binary
.
Read
(
frame
.
buf
,
binary
.
BigEndian
,
&
delta
)
binary
.
Read
(
frame
.
buf
,
frame
.
order
,
&
delta
)
frame
.
loc
+=
uint64
(
delta
)
*
frame
.
codeAlignment
}
...
...
@@ -280,7 +282,7 @@ func restore(frame *FrameContext) {
func
setloc
(
frame
*
FrameContext
)
{
var
loc
uint64
binary
.
Read
(
frame
.
buf
,
binary
.
BigEndian
,
&
loc
)
binary
.
Read
(
frame
.
buf
,
frame
.
order
,
&
loc
)
frame
.
loc
=
loc
}
...
...
proc/proc_darwin.go
浏览文件 @
b1640238
...
...
@@ -193,13 +193,21 @@ func (dbp *Process) addThread(port int, attach bool) (*Thread, error) {
func
(
dbp
*
Process
)
parseDebugFrame
(
exe
*
macho
.
File
,
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
if
sec
:=
exe
.
Section
(
"__debug_frame"
);
sec
!=
nil
{
debugFrameSec
:=
exe
.
Section
(
"__debug_frame"
)
debugInfoSec
:=
exe
.
Section
(
"__debug_info"
)
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
)
}
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
)
dat
,
err
:=
debugInfoSec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_info section"
,
err
)
os
.
Exit
(
1
)
}
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
))
}
else
{
fmt
.
Println
(
"could not find __debug_frame section in binary"
)
os
.
Exit
(
1
)
...
...
proc/proc_linux.go
浏览文件 @
b1640238
...
...
@@ -179,13 +179,21 @@ func (dbp *Process) findExecutable(path string) (*elf.File, error) {
func
(
dbp
*
Process
)
parseDebugFrame
(
exe
*
elf
.
File
,
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
if
sec
:=
exe
.
Section
(
".debug_frame"
);
sec
!=
nil
{
debugFrameSec
:=
exe
.
Section
(
".debug_frame"
)
debugInfoSec
:=
exe
.
Section
(
".debug_info"
)
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
)
}
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
)
dat
,
err
:=
debugInfoSec
.
Data
()
if
err
!=
nil
{
fmt
.
Println
(
"could not get .debug_info section"
,
err
)
os
.
Exit
(
1
)
}
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
))
}
else
{
fmt
.
Println
(
"could not find .debug_frame section in binary"
)
os
.
Exit
(
1
)
...
...
proc/proc_windows.go
浏览文件 @
b1640238
...
...
@@ -158,16 +158,24 @@ func (dbp *Process) addThread(hThread sys.Handle, threadID int, attach bool) (*T
func
(
dbp
*
Process
)
parseDebugFrame
(
exe
*
pe
.
File
,
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
if
sec
:=
exe
.
Section
(
".debug_frame"
);
sec
!=
nil
{
debugFrame
,
err
:=
sec
.
Data
()
if
err
!=
nil
&&
uint32
(
len
(
debugFrame
))
<
sec
.
Size
{
debugFrameSec
:=
exe
.
Section
(
".debug_frame"
)
debugInfoSec
:=
exe
.
Section
(
".debug_info"
)
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
)
}
if
0
<
sec
.
VirtualSize
&&
sec
.
VirtualSize
<
sec
.
Size
{
debugFrame
=
debugFrame
[
:
sec
.
VirtualSize
]
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
)
}
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
)
dbp
.
frameEntries
=
frame
.
Parse
(
debugFrame
,
frame
.
DwarfEndian
(
dat
)
)
}
else
{
fmt
.
Println
(
"could not find .debug_frame section in binary"
)
os
.
Exit
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录