go-delve/delve · error
could not determine location (scope is nil)
Error message
could not determine location (scope is nil)
What it means
RegexLocationSpec.Find resolves a regex location spec (e.g. breakpoints like b /main\..*/) by filtering scope.BinInfo.Functions. It needs an EvalScope to access the binary info; when scope is nil there is no current frame to obtain it from, so the search cannot run and this error is returned.
Source
Thrown at pkg/locspec/locations.go:283
}
return true
}
func packageMatch(specPkg, symPkg string, packageMap map[string][]string) bool {
for _, pkg := range packageMap[specPkg] {
if partialPackageMatch(pkg, symPkg) {
return true
}
}
return partialPackageMatch(specPkg, symPkg)
}
// Find will search all functions in the target program and filter them via the
// regex location spec. Only functions matching the regex will be returned.
func (loc *RegexLocationSpec) Find(t *proc.Target, _ []string, scope *proc.EvalScope, locStr string, includeNonExecutableLines bool, _ [][2]string) ([]api.Location, string, error) {
if scope == nil {
//TODO(aarzilli): this needs only the list of function we should make it work
return nil, "", errors.New("could not determine location (scope is nil)")
}
funcs := scope.BinInfo.Functions
matches, err := regexFilterFuncs(loc.FuncRegex, funcs)
if err != nil {
return nil, "", err
}
r := make([]api.Location, 0, len(matches))
for i := range matches {
addrs, _ := proc.FindFunctionLocation(t, matches[i], 0)
if len(addrs) > 0 {
r = append(r, addressesToLocation(addrs))
}
}
return r, "", nil
}
// Find returns the locations specified via the address location spec.
func (loc *AddrLocationSpec) Find(t *proc.Target, _ []string, scope *proc.EvalScope, locStr string, includeNonExecutableLines bool, _ [][2]string) ([]api.Location, string, error) {View on GitHub (pinned to a23773e6c3)
Solutions
- Start/attach to the target before setting regex breakpoints so a valid scope exists
- Resolve the function list independently (proc.Functions from the loaded BinInfo) and filter it yourself
- Check scope != nil before invoking Find and report a clearer error to the user
Example fix
// before
locs, err := locspec.Find(target, funcs, nil, "/main\..*/", false, nil)
// after
if scope == nil {
return errors.New("target must be running to use regex breakpoints")
}
locs, err := locspec.Find(target, funcs, scope, "/main\..*/", false, nil) Defensive patterns
Strategy: validation
Validate before calling
if scope == nil {
return errors.New("regex breakpoints require a running target")
}
locs, err := spec.Find(target, funcs, scope, locStr, false, dirs) Try / catch
locs, _, err := spec.Find(t, funcs, scope, locStr, false, nil)
if err != nil && strings.Contains(err.Error(), "scope is nil") {
return fmt.Errorf("start or attach to the target before setting this breakpoint: %w", err)
} Prevention
- Set function-name breakpoints only after launch/attach
- In API clients, create the EvalScope from the current goroutine before Find
- Prefer AbsoluteFileLocationSpecs when no scope exists
When it happens
Trigger: Calling Find with a nil *proc.EvalScope while the target is not running — e.g. setting a regex breakpoint before launch/attach, or calling the API without a current goroutine/frame.
Common situations: Scripting dlv via the API and setting breakpoints before starting the program; issuing regex breakpoints from a state where the process is not yet attached.
Related errors
- could not determine current location (scope is nil)
- Malformed breakpoint location, no line offset specified
- could not determine current location
- cannot write a breakpoint to a core file
- runtime.copystack has too many return instructions
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/596b19ecaa5d8434.
Report an issue: GitHub.