Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
2f0b80d6
Unverified
Commit
2f0b80d6
authored
May 29, 2024
by
Inphi
Committed by
GitHub
May 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cannon: Add traceback debugger (#10669)
* cannon: Add traceback debugger * review comments * fix go lint
parent
e6d1ee00
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
0 deletions
+81
-0
run.go
cannon/cmd/run.go
+17
-0
instrumented.go
cannon/mipsevm/instrumented.go
+19
-0
mips.go
cannon/mipsevm/mips.go
+45
-0
No files found.
cannon/cmd/run.go
View file @
2f0b80d6
...
@@ -99,6 +99,10 @@ var (
...
@@ -99,6 +99,10 @@ var (
Name
:
"pprof.cpu"
,
Name
:
"pprof.cpu"
,
Usage
:
"enable pprof cpu profiling"
,
Usage
:
"enable pprof cpu profiling"
,
}
}
RunDebugFlag
=
&
cli
.
BoolFlag
{
Name
:
"debug"
,
Usage
:
"enable debug mode, which includes stack traces and other debug info in the output. Requires --meta."
,
}
OutFilePerm
=
os
.
FileMode
(
0
o755
)
OutFilePerm
=
os
.
FileMode
(
0
o755
)
)
)
...
@@ -336,6 +340,15 @@ func Run(ctx *cli.Context) error {
...
@@ -336,6 +340,15 @@ func Run(ctx *cli.Context) error {
}
}
us
:=
mipsevm
.
NewInstrumentedState
(
state
,
po
,
outLog
,
errLog
)
us
:=
mipsevm
.
NewInstrumentedState
(
state
,
po
,
outLog
,
errLog
)
debugProgram
:=
ctx
.
Bool
(
RunDebugFlag
.
Name
)
if
debugProgram
{
if
metaPath
:=
ctx
.
Path
(
RunMetaFlag
.
Name
);
metaPath
==
""
{
return
fmt
.
Errorf
(
"cannot enable debug mode without a metadata file"
)
}
if
err
:=
us
.
InitDebug
(
meta
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to initialize debug mode: %w"
,
err
)
}
}
proofFmt
:=
ctx
.
String
(
RunProofFmtFlag
.
Name
)
proofFmt
:=
ctx
.
String
(
RunProofFmtFlag
.
Name
)
snapshotFmt
:=
ctx
.
String
(
RunSnapshotFmtFlag
.
Name
)
snapshotFmt
:=
ctx
.
String
(
RunSnapshotFmtFlag
.
Name
)
...
@@ -442,6 +455,9 @@ func Run(ctx *cli.Context) error {
...
@@ -442,6 +455,9 @@ func Run(ctx *cli.Context) error {
}
}
}
}
l
.
Info
(
"Execution stopped"
,
"exited"
,
state
.
Exited
,
"code"
,
state
.
ExitCode
)
l
.
Info
(
"Execution stopped"
,
"exited"
,
state
.
Exited
,
"code"
,
state
.
ExitCode
)
if
debugProgram
{
us
.
Traceback
()
}
if
err
:=
jsonutil
.
WriteJSON
(
ctx
.
Path
(
RunOutputFlag
.
Name
),
state
,
OutFilePerm
);
err
!=
nil
{
if
err
:=
jsonutil
.
WriteJSON
(
ctx
.
Path
(
RunOutputFlag
.
Name
),
state
,
OutFilePerm
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to write state output: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to write state output: %w"
,
err
)
...
@@ -468,5 +484,6 @@ var RunCommand = &cli.Command{
...
@@ -468,5 +484,6 @@ var RunCommand = &cli.Command{
RunMetaFlag
,
RunMetaFlag
,
RunInfoAtFlag
,
RunInfoAtFlag
,
RunPProfCPU
,
RunPProfCPU
,
RunDebugFlag
,
},
},
}
}
cannon/mipsevm/instrumented.go
View file @
2f0b80d6
package
mipsevm
package
mipsevm
import
(
import
(
"errors"
"io"
"io"
)
)
...
@@ -9,6 +10,12 @@ type PreimageOracle interface {
...
@@ -9,6 +10,12 @@ type PreimageOracle interface {
GetPreimage
(
k
[
32
]
byte
)
[]
byte
GetPreimage
(
k
[
32
]
byte
)
[]
byte
}
}
type
Debug
struct
{
stack
[]
uint32
caller
[]
uint32
meta
*
Metadata
}
type
InstrumentedState
struct
{
type
InstrumentedState
struct
{
state
*
State
state
*
State
...
@@ -27,6 +34,9 @@ type InstrumentedState struct {
...
@@ -27,6 +34,9 @@ type InstrumentedState struct {
lastPreimageKey
[
32
]
byte
lastPreimageKey
[
32
]
byte
// offset we last read from, or max uint32 if nothing is read this step
// offset we last read from, or max uint32 if nothing is read this step
lastPreimageOffset
uint32
lastPreimageOffset
uint32
debug
Debug
debugEnabled
bool
}
}
const
(
const
(
...
@@ -53,6 +63,15 @@ func NewInstrumentedState(state *State, po PreimageOracle, stdOut, stdErr io.Wri
...
@@ -53,6 +63,15 @@ func NewInstrumentedState(state *State, po PreimageOracle, stdOut, stdErr io.Wri
}
}
}
}
func
(
m
*
InstrumentedState
)
InitDebug
(
meta
*
Metadata
)
error
{
if
meta
==
nil
{
return
errors
.
New
(
"metadata is nil"
)
}
m
.
debugEnabled
=
true
m
.
debug
.
meta
=
meta
return
nil
}
func
(
m
*
InstrumentedState
)
Step
(
proof
bool
)
(
wit
*
StepWitness
,
err
error
)
{
func
(
m
*
InstrumentedState
)
Step
(
proof
bool
)
(
wit
*
StepWitness
,
err
error
)
{
m
.
memProofEnabled
=
proof
m
.
memProofEnabled
=
proof
m
.
lastMemAccess
=
^
uint32
(
0
)
m
.
lastMemAccess
=
^
uint32
(
0
)
...
...
cannon/mipsevm/mips.go
View file @
2f0b80d6
...
@@ -179,6 +179,49 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -179,6 +179,49 @@ func (m *InstrumentedState) handleSyscall() error {
return
nil
return
nil
}
}
func
(
m
*
InstrumentedState
)
pushStack
(
target
uint32
)
{
if
!
m
.
debugEnabled
{
return
}
m
.
debug
.
stack
=
append
(
m
.
debug
.
stack
,
target
)
m
.
debug
.
caller
=
append
(
m
.
debug
.
caller
,
m
.
state
.
PC
)
}
func
(
m
*
InstrumentedState
)
popStack
()
{
if
!
m
.
debugEnabled
{
return
}
if
len
(
m
.
debug
.
stack
)
!=
0
{
fn
:=
m
.
debug
.
meta
.
LookupSymbol
(
m
.
state
.
PC
)
topFn
:=
m
.
debug
.
meta
.
LookupSymbol
(
m
.
debug
.
stack
[
len
(
m
.
debug
.
stack
)
-
1
])
if
fn
!=
topFn
{
// most likely the function was inlined. Snap back to the last return.
i
:=
len
(
m
.
debug
.
stack
)
-
1
for
;
i
>=
0
;
i
--
{
if
m
.
debug
.
meta
.
LookupSymbol
(
m
.
debug
.
stack
[
i
])
==
fn
{
m
.
debug
.
stack
=
m
.
debug
.
stack
[
:
i
]
m
.
debug
.
caller
=
m
.
debug
.
caller
[
:
i
]
break
}
}
}
else
{
m
.
debug
.
stack
=
m
.
debug
.
stack
[
:
len
(
m
.
debug
.
stack
)
-
1
]
m
.
debug
.
caller
=
m
.
debug
.
caller
[
:
len
(
m
.
debug
.
caller
)
-
1
]
}
}
else
{
fmt
.
Printf
(
"ERROR: stack underflow at pc=%x. step=%d
\n
"
,
m
.
state
.
PC
,
m
.
state
.
Step
)
}
}
func
(
m
*
InstrumentedState
)
Traceback
()
{
fmt
.
Printf
(
"traceback at pc=%x. step=%d
\n
"
,
m
.
state
.
PC
,
m
.
state
.
Step
)
for
i
:=
len
(
m
.
debug
.
stack
)
-
1
;
i
>=
0
;
i
--
{
s
:=
m
.
debug
.
stack
[
i
]
idx
:=
len
(
m
.
debug
.
stack
)
-
i
-
1
fmt
.
Printf
(
"
\t
%d %x in %s caller=%08x
\n
"
,
idx
,
s
,
m
.
debug
.
meta
.
LookupSymbol
(
s
),
m
.
debug
.
caller
[
i
])
}
}
func
(
m
*
InstrumentedState
)
handleBranch
(
opcode
uint32
,
insn
uint32
,
rtReg
uint32
,
rs
uint32
)
error
{
func
(
m
*
InstrumentedState
)
handleBranch
(
opcode
uint32
,
insn
uint32
,
rtReg
uint32
,
rs
uint32
)
error
{
if
m
.
state
.
NextPC
!=
m
.
state
.
PC
+
4
{
if
m
.
state
.
NextPC
!=
m
.
state
.
PC
+
4
{
panic
(
"branch in delay slot"
)
panic
(
"branch in delay slot"
)
...
@@ -291,6 +334,7 @@ func (m *InstrumentedState) mipsStep() error {
...
@@ -291,6 +334,7 @@ func (m *InstrumentedState) mipsStep() error {
}
}
// Take top 4 bits of the next PC (its 256 MB region), and concatenate with the 26-bit offset
// Take top 4 bits of the next PC (its 256 MB region), and concatenate with the 26-bit offset
target
:=
(
m
.
state
.
NextPC
&
0xF0000000
)
|
((
insn
&
0x03FFFFFF
)
<<
2
)
target
:=
(
m
.
state
.
NextPC
&
0xF0000000
)
|
((
insn
&
0x03FFFFFF
)
<<
2
)
m
.
pushStack
(
target
)
return
m
.
handleJump
(
linkReg
,
target
)
return
m
.
handleJump
(
linkReg
,
target
)
}
}
...
@@ -356,6 +400,7 @@ func (m *InstrumentedState) mipsStep() error {
...
@@ -356,6 +400,7 @@ func (m *InstrumentedState) mipsStep() error {
if
fun
==
9
{
if
fun
==
9
{
linkReg
=
rdReg
linkReg
=
rdReg
}
}
m
.
popStack
()
return
m
.
handleJump
(
linkReg
,
rs
)
return
m
.
handleJump
(
linkReg
,
rs
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment