NationalSecurityAgency/ghidra · error · ValueError

Cannot convert ({schema}): '{value}', value='{val}'

Error message

Cannot convert ({schema}): '{value}', value='{val}'

What it means

Thrown as a ValueError at the end of the type-conversion function in the gdb agent when no preceding branch matched the gdb.Value's type code and schema combination. This is the catch-all 'cannot convert' error — it means the value's type (gdb.Type code) and requested schema fall through all handled cases (int, char, float, pointer, struct, simple string, etc.).

Source

Thrown at Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/commands.py:854

                    schema = sch.INT_ARR
                elif schema == sch.CHAR_ARR:
                    return to_string(val, type, 'utf-32', full=True), schema
                return to_int_list(val, type), schema
            elif schema is not None:
                return to_int_list(val, type), schema
            elif etype.sizeof == 8:
                return to_int_list(val, type), sch.LONG_ARR
        elif etype.code == gdb.TYPE_CODE_STRING:
            raise ValueError("Conversion of string arrays unimplemented")
        # TODO: Array of C strings?
    elif type.code == gdb.TYPE_CODE_STRING:
        return val.string(), sch.STRING
    elif type.code == gdb.TYPE_CODE_PTR:
        offset = int(val)
        inf = gdb.selected_inferior()
        base, addr = STATE.require_trace().extra.require_mm().map(inf, offset)
        return (base, addr), sch.ADDRESS
    raise ValueError(f"Cannot convert ({schema}): '{value}', value='{val}'")


@cmd('ghidra trace set-value', '-ghidra-trace-set-value', gdb.COMMAND_DATA, True)
def ghidra_trace_set_value(path: str, key: str, value: str,
                           schema: Optional[str] = None, *, is_mi: bool,
                           **kwargs) -> None:
    """Set a value (attribute or element) in the Ghidra trace's object tree.

    A void value implies removal. NOTE: The type of an expression may be
    subject to GDB's current language. e.g., there is no 'bool' in C.
    You may have to change to C++ if you need this type. Alternatively,
    you can use the Python API.
    """

    # NOTE: id parameter is probably not necessary, since this command is for
    # humans.
    # TODO: path and key are two separate parameters.... This is mostly to
    # spare me from porting path parsing to Python, but it may also be useful

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Inspect the gdb.Value's type code (value.type.code) and sizeof before passing it to the trace API.
  2. For unsupported types, extract a primitive representation (address, size, or string) manually before setting the trace value.
  3. Try changing GDB's language to match the expression's language (set language c++ for C++ types).
  4. If the type is a struct, access individual fields and convert them separately.
Defensive patterns

Strategy: try-catch

Validate before calling

SUPPORTED_TYPE_CODES = {
    gdb.TYPE_CODE_INT, gdb.TYPE_CODE_CHAR, gdb.TYPE_CODE_FLT,
    gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY, gdb.TYPE_CODE_STRUCT,
    gdb.TYPE_CODE_STRING,
}

def is_supported_value(val: gdb.Value) -> bool:
    try:
        return val.type.strip_typedefs().code in SUPPORTED_TYPE_CODES
    except Exception:
        return False

Type guard

def is_convertible_type(val: gdb.Value, schema=None) -> bool:
    try:
        t = val.type.strip_typedefs()
        code = t.code
        if code in (gdb.TYPE_CODE_METHOD, gdb.TYPE_CODE_INTERNAL_FUNCTION,
                    gdb.TYPE_CODE_XMETHOD):
            return False
        return True
    except Exception:
        return False

Try / catch

try:
    result = convert_value(val, type, schema)
except ValueError as e:
    if 'Cannot convert' in str(e):
        print(f'Unsupported type code {val.type.code} with schema {schema}. Skipping.')
        result = (str(val), None)
    else:
        raise

Prevention

When it happens

Trigger: Passing a gdb.Value whose type code is uncommon or unsupported (e.g. gdb.TYPE_CODE_METHOD, gdb.TYPE_CODE_INTERNAL_FUNCTION, gdb.TYPE_CODE_XMETHOD, or a complex type with an incompatible schema). Also fires when the value is a struct/union/enum that does not match any handled schema path.

Common situations: Evaluating an expression that yields a method pointer, member function, or vendor-extension type; passing a schema hint that contradicts the actual type code; GDB language mode mismatch (e.g. evaluating a C++ type while in C mode).

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/46398555970ff240. Report an issue: GitHub.