go-delve/delve · error

malformed qMemoryRegionInfo response packet (error): %s

Error message

malformed qMemoryRegionInfo response packet (error): %s

What it means

This error is returned by memoryRegionInfo when the 'error' field of a qMemoryRegionInfo response is not valid hex-encoded ASCII. A stub that reports an error via the 'error' key must hex-encode the error text; decodeHexString failed on it. Delve reports the packet itself as malformed rather than guessing at the error text.

Source

Thrown at pkg/proc/gdbserial/gdbserver_conn.go:1309

			mri.start = start
		case "size":
			size, err := strconv.ParseUint(string(value), 16, 64)
			if err != nil {
				return nil, fmt.Errorf("malformed qMemoryRegionInfo response packet (size): %v in %s", err, string(resp))
			}
			mri.size = size
		case "permissions":
			mri.permissions = string(value)
		case "name":
			namestr, ok := decodeHexString(value)
			if !ok {
				return nil, fmt.Errorf("malformed qMemoryRegionInfo response packet (name): %s", string(resp))
			}
			mri.name = namestr
		case "error":
			errstr, ok := decodeHexString(value)
			if !ok {
				return nil, fmt.Errorf("malformed qMemoryRegionInfo response packet (error): %s", string(resp))
			}
			return nil, fmt.Errorf("qMemoryRegionInfo error: %s", errstr)
		}
	}

	return mri, nil
}

// exec executes a message to the stub and reads a response.
// The details of the wire protocol are described here:
//
//	https://sourceware.org/gdb/onlinedocs/gdb/Overview.html#Overview
func (conn *gdbConn) exec(cmd []byte, context string) ([]byte, error) {
	if err := conn.send(cmd); err != nil {
		return nil, err
	}
	return conn.recv(cmd, context, false)
}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Fix the stub to hex-encode the error text per the GDB RSP specification
  2. Check the raw response in the error message to read what the stub actually sent
  3. Verify the stub supports qMemoryRegionInfo at all; if not, disable the dependent feature
  4. Upgrade Delve/target toolchain so both sides agree on the protocol

Example fix

// stub before (malformed, plain text)
error:unsupported
// stub after (hex-encoded)
error:756e737570706f72746564
Defensive patterns

Strategy: try-catch

Validate before calling

func validHexString(s string) bool {
    if s == "" || len(s)%2 != 0 { return false }
    _, err := hex.DecodeString(s)
    return err == nil
}
// use: if errorField present && !validHexString(errorField) { /* stub non-conforming */ }

Type guard

func hasWellFormedErrorField(resp []byte) (present, wellFormed bool) {
    for _, kv := range bytes.Split(resp, []byte(",")) {
        parts := bytes.SplitN(kv, []byte(":"), 2)
        if len(parts) == 2 && string(parts[0]) == "error" {
            _, err := hex.DecodeString(string(parts[1]))
            return true, err == nil
        }
    }
    return false, true
}

Try / catch

mri, err := conn.memoryRegionInfo(addr)
if err != nil {
    if strings.Contains(err.Error(), "malformed qMemoryRegionInfo response packet (error)") {
        log.Printf("stub error field not hex-encoded: %v", err)
        return errRegionInfoUnsupported
    }
    return err
}

Prevention

When it happens

Trigger: Querying memory region info through the gdbserial backend when the stub replies with an 'error:<value>' key whose value is not valid hex (e.g. plain-text error messages, odd-length or non-hex characters).

Common situations: Older or non-conforming stubs that send error descriptions as raw ASCII, stubs reporting unsupported-feature errors (qMemoryRegionInfo not implemented) in the wrong format, embedded debug monitors with hand-rolled responses.

Understand the failure class

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/e9912beb0b9b7e2b. Report an issue: GitHub.