Beispiel #1
0
func (d *Debugger) Stacktrace(goroutineId, depth int) ([]api.Location, error) {
	var rawlocs []proc.Location
	var rawloc *proc.Location
	var err error

	if goroutineId < 0 {
		rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
		if err != nil {
			return nil, err
		}
		rawloc, err = d.process.CurrentThread.Location()
		if err != nil {
			return nil, err
		}
	} else {
		gs, err := d.process.GoroutinesInfo()
		if err != nil {
			return nil, err
		}
		for _, g := range gs {
			if g.Id == goroutineId {
				rawlocs, err = d.process.GoroutineStacktrace(g, depth)
				if err != nil {
					return nil, err
				}
				rawloc = d.process.GoroutineLocation(g)
				break
			}
		}

		if rawlocs == nil {
			return nil, fmt.Errorf("Unknown goroutine id %d\n", goroutineId)
		}
	}

	locations := make([]api.Location, 0, len(rawlocs)+1)

	locations = append(locations, api.ConvertLocation(*rawloc))
	for i := range rawlocs {
		rawlocs[i].Line--
		locations = append(locations, api.ConvertLocation(rawlocs[i]))
	}

	return locations, nil
}
Beispiel #2
0
func convertStacktrace(rawlocs []proc.Location) []api.Location {
	locations := make([]api.Location, 0, len(rawlocs))
	for i := range rawlocs {
		rawlocs[i].Line--
		locations = append(locations, api.ConvertLocation(rawlocs[i]))
	}

	return locations
}
Beispiel #3
0
func (d *Debugger) convertStacktrace(rawlocs []proc.Stackframe, full bool) ([]api.Stackframe, error) {
	locations := make([]api.Stackframe, 0, len(rawlocs))
	for i := range rawlocs {
		frame := api.Stackframe{Location: api.ConvertLocation(rawlocs[i].Call)}
		if full {
			scope := rawlocs[i].Scope(d.process.CurrentThread)
			lv, err := scope.LocalVariables()
			if err != nil {
				return nil, err
			}
			av, err := scope.FunctionArguments()
			if err != nil {
				return nil, err
			}
			frame.Locals = convertVars(lv)
			frame.Arguments = convertVars(av)
		}
		locations = append(locations, frame)
	}

	return locations, nil
}
Beispiel #4
0
func (d *Debugger) convertStacktrace(rawlocs []proc.Stackframe, cfg *proc.LoadConfig) ([]api.Stackframe, error) {
	locations := make([]api.Stackframe, 0, len(rawlocs))
	for i := range rawlocs {
		frame := api.Stackframe{Location: api.ConvertLocation(rawlocs[i].Call)}
		if cfg != nil {
			var err error
			scope := rawlocs[i].Scope(d.process.CurrentThread)
			locals, err := scope.LocalVariables(*cfg)
			if err != nil {
				return nil, err
			}
			arguments, err := scope.FunctionArguments(*cfg)
			if err != nil {
				return nil, err
			}

			frame.Locals = convertVars(locals)
			frame.Arguments = convertVars(arguments)
		}
		locations = append(locations, frame)
	}

	return locations, nil
}