2015-06-13 04:47:30 +00:00
|
|
|
package api
|
|
|
|
|
2015-06-17 17:11:57 +00:00
|
|
|
import (
|
|
|
|
"debug/gosym"
|
2015-09-26 00:04:39 +00:00
|
|
|
"strconv"
|
2015-07-01 03:16:52 +00:00
|
|
|
|
2015-06-17 17:11:57 +00:00
|
|
|
"github.com/derekparker/delve/proc"
|
|
|
|
)
|
2015-06-13 04:47:30 +00:00
|
|
|
|
|
|
|
// convertBreakpoint converts an internal breakpoint to an API Breakpoint.
|
|
|
|
func ConvertBreakpoint(bp *proc.Breakpoint) *Breakpoint {
|
2015-09-26 00:04:39 +00:00
|
|
|
b := &Breakpoint{
|
|
|
|
ID: bp.ID,
|
|
|
|
FunctionName: bp.FunctionName,
|
|
|
|
File: bp.File,
|
|
|
|
Line: bp.Line,
|
|
|
|
Addr: bp.Addr,
|
|
|
|
Tracepoint: bp.Tracepoint,
|
|
|
|
Stacktrace: bp.Stacktrace,
|
|
|
|
Goroutine: bp.Goroutine,
|
|
|
|
Variables: bp.Variables,
|
|
|
|
TotalHitCount: bp.TotalHitCount,
|
2015-06-13 04:47:30 +00:00
|
|
|
}
|
2015-09-26 00:04:39 +00:00
|
|
|
|
|
|
|
b.HitCount = map[string]uint64{}
|
|
|
|
for idx := range bp.HitCount {
|
|
|
|
b.HitCount[strconv.Itoa(idx)] = bp.HitCount[idx]
|
|
|
|
}
|
|
|
|
|
|
|
|
return b
|
2015-06-13 04:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convertThread converts an internal thread to an API Thread.
|
|
|
|
func ConvertThread(th *proc.Thread) *Thread {
|
|
|
|
var (
|
|
|
|
function *Function
|
|
|
|
file string
|
|
|
|
line int
|
|
|
|
pc uint64
|
|
|
|
)
|
|
|
|
|
|
|
|
loc, err := th.Location()
|
|
|
|
if err == nil {
|
|
|
|
pc = loc.PC
|
|
|
|
file = loc.File
|
|
|
|
line = loc.Line
|
2015-06-17 17:11:57 +00:00
|
|
|
function = ConvertFunction(loc.Fn)
|
2015-06-13 04:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Thread{
|
|
|
|
ID: th.Id,
|
|
|
|
PC: pc,
|
2015-08-19 22:38:53 +00:00
|
|
|
File: file,
|
2015-06-13 04:47:30 +00:00
|
|
|
Line: line,
|
|
|
|
Function: function,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// convertVar converts an internal variable to an API Variable.
|
|
|
|
func ConvertVar(v *proc.Variable) Variable {
|
|
|
|
return Variable{
|
|
|
|
Name: v.Name,
|
|
|
|
Value: v.Value,
|
|
|
|
Type: v.Type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:11:57 +00:00
|
|
|
func ConvertFunction(fn *gosym.Func) *Function {
|
|
|
|
if fn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Function{
|
|
|
|
Name: fn.Name,
|
|
|
|
Type: fn.Type,
|
|
|
|
Value: fn.Value,
|
|
|
|
GoType: fn.GoType,
|
2015-06-13 04:47:30 +00:00
|
|
|
}
|
2015-06-17 17:11:57 +00:00
|
|
|
}
|
2015-06-13 04:47:30 +00:00
|
|
|
|
2015-06-17 17:11:57 +00:00
|
|
|
// convertGoroutine converts an internal Goroutine to an API Goroutine.
|
|
|
|
func ConvertGoroutine(g *proc.G) *Goroutine {
|
2015-06-13 04:47:30 +00:00
|
|
|
return &Goroutine{
|
2015-10-16 06:42:02 +00:00
|
|
|
ID: g.Id,
|
|
|
|
Current: ConvertLocation(g.Current),
|
|
|
|
UserCurrent: ConvertLocation(g.UserCurrent()),
|
|
|
|
Go: ConvertLocation(g.Go()),
|
2015-06-17 17:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertLocation(loc proc.Location) Location {
|
|
|
|
return Location{
|
|
|
|
PC: loc.PC,
|
2015-08-19 22:38:53 +00:00
|
|
|
File: loc.File,
|
2015-06-17 17:11:57 +00:00
|
|
|
Line: loc.Line,
|
|
|
|
Function: ConvertFunction(loc.Fn),
|
2015-06-13 04:47:30 +00:00
|
|
|
}
|
|
|
|
}
|