提交 0b3cf1cd 编写于 作者: D Derek Parker

Add command to print active breakpoints

上级 464a6b96
......@@ -85,6 +85,8 @@ Once inside a debugging session, the following commands may be used:
* `goroutines` - Print status of all goroutines.
* `breakpoints` - Print information on all active breakpoints.
* `print $var` - Evaluate a variable.
* `info $type [regex]` - Outputs information about the symbol table. An optional regex filters the list. Example `info funcs unicode`. Valid types are:
......
......@@ -50,6 +50,7 @@ func DebugCommands() *Commands {
command{aliases: []string{"threads"}, cmdFn: threads, helpMsg: "Print out info for every traced thread."},
command{aliases: []string{"clear"}, cmdFn: clear, helpMsg: "Deletes breakpoint."},
command{aliases: []string{"goroutines"}, cmdFn: goroutines, helpMsg: "Print out info for every goroutine."},
command{aliases: []string{"breakpoints", "bp"}, cmdFn: breakpoints, helpMsg: "Print out info for active breakpoints."},
command{aliases: []string{"print", "p"}, cmdFn: printVar, helpMsg: "Evaluate a variable."},
command{aliases: []string{"info"}, cmdFn: info, helpMsg: "Provides info about args, funcs, locals, sources, or vars."},
command{aliases: []string{"exit"}, cmdFn: nullCommand, helpMsg: "Exit the debugger."},
......@@ -165,6 +166,37 @@ func clear(p *proctl.DebuggedProcess, args ...string) error {
return nil
}
type ById []*proctl.BreakPoint
func (a ById) Len() int { return len(a) }
func (a ById) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ById) Less(i, j int) bool { return a[i].ID < a[j].ID }
func breakpoints(p *proctl.DebuggedProcess, args ...string) error {
bps := make([]*proctl.BreakPoint, 0, len(p.BreakPoints)+4)
for _, bp := range p.HWBreakPoints {
if bp == nil {
continue
}
bps = append(bps, bp)
}
for _, bp := range p.BreakPoints {
if bp.Temp {
continue
}
bps = append(bps, bp)
}
sort.Sort(ById(bps))
for _, bp := range bps {
fmt.Println(bp)
}
return nil
}
func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 {
return fmt.Errorf("not enough arguments")
......
......@@ -15,7 +15,11 @@ type BreakPoint struct {
Addr uint64
OriginalData []byte
ID int
temp bool
Temp bool
}
func (bp *BreakPoint) String() string {
return fmt.Sprintf("Breakpoint %d at %#v %s:%d", bp.ID, bp.Addr, bp.File, bp.Line)
}
// Returned when trying to set a breakpoint at
......
......@@ -274,7 +274,7 @@ func (dbp *DebuggedProcess) Continue() error {
// Check for hardware breakpoint
for _, bp := range dbp.HWBreakPoints {
if bp != nil && bp.Addr == pc {
if !bp.temp {
if !bp.Temp {
return dbp.Halt()
}
return nil
......@@ -282,7 +282,7 @@ func (dbp *DebuggedProcess) Continue() error {
}
// Check to see if we have hit a software breakpoint.
if bp, ok := dbp.BreakPoints[pc-1]; ok {
if !bp.temp {
if !bp.Temp {
return dbp.Halt()
}
return nil
......
......@@ -185,7 +185,7 @@ func (thread *ThreadContext) continueToReturnAddress(pc uint64, fde *frame.Frame
return err
}
}
bp.temp = true
bp.Temp = true
// Ensure we cleanup after ourselves no matter what.
defer thread.clearTempBreakpoint(bp.Addr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册