{"record":{"id":"46398555970ff240","repo":"NationalSecurityAgency/ghidra","slug":"cannot-convert-schema-value-value-val","errorCode":null,"errorMessage":"Cannot convert ({schema}): '{value}', value='{val}'","messagePattern":"Cannot convert \\((.+?)\\): '(.+?)', value='(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/commands.py","lineNumber":854,"sourceCode":"                    schema = sch.INT_ARR\n                elif schema == sch.CHAR_ARR:\n                    return to_string(val, type, 'utf-32', full=True), schema\n                return to_int_list(val, type), schema\n            elif schema is not None:\n                return to_int_list(val, type), schema\n            elif etype.sizeof == 8:\n                return to_int_list(val, type), sch.LONG_ARR\n        elif etype.code == gdb.TYPE_CODE_STRING:\n            raise ValueError(\"Conversion of string arrays unimplemented\")\n        # TODO: Array of C strings?\n    elif type.code == gdb.TYPE_CODE_STRING:\n        return val.string(), sch.STRING\n    elif type.code == gdb.TYPE_CODE_PTR:\n        offset = int(val)\n        inf = gdb.selected_inferior()\n        base, addr = STATE.require_trace().extra.require_mm().map(inf, offset)\n        return (base, addr), sch.ADDRESS\n    raise ValueError(f\"Cannot convert ({schema}): '{value}', value='{val}'\")\n\n\n@cmd('ghidra trace set-value', '-ghidra-trace-set-value', gdb.COMMAND_DATA, True)\ndef ghidra_trace_set_value(path: str, key: str, value: str,\n                           schema: Optional[str] = None, *, is_mi: bool,\n                           **kwargs) -> None:\n    \"\"\"Set a value (attribute or element) in the Ghidra trace's object tree.\n\n    A void value implies removal. NOTE: The type of an expression may be\n    subject to GDB's current language. e.g., there is no 'bool' in C.\n    You may have to change to C++ if you need this type. Alternatively,\n    you can use the Python API.\n    \"\"\"\n\n    # NOTE: id parameter is probably not necessary, since this command is for\n    # humans.\n    # TODO: path and key are two separate parameters.... This is mostly to\n    # spare me from porting path parsing to Python, but it may also be useful","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/commands.py#L836-L872","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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).","solutions":["Inspect the gdb.Value's type code (value.type.code) and sizeof before passing it to the trace API.","For unsupported types, extract a primitive representation (address, size, or string) manually before setting the trace value.","Try changing GDB's language to match the expression's language (set language c++ for C++ types).","If the type is a struct, access individual fields and convert them separately."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"SUPPORTED_TYPE_CODES = {\n    gdb.TYPE_CODE_INT, gdb.TYPE_CODE_CHAR, gdb.TYPE_CODE_FLT,\n    gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY, gdb.TYPE_CODE_STRUCT,\n    gdb.TYPE_CODE_STRING,\n}\n\ndef is_supported_value(val: gdb.Value) -> bool:\n    try:\n        return val.type.strip_typedefs().code in SUPPORTED_TYPE_CODES\n    except Exception:\n        return False","typeGuard":"def is_convertible_type(val: gdb.Value, schema=None) -> bool:\n    try:\n        t = val.type.strip_typedefs()\n        code = t.code\n        if code in (gdb.TYPE_CODE_METHOD, gdb.TYPE_CODE_INTERNAL_FUNCTION,\n                    gdb.TYPE_CODE_XMETHOD):\n            return False\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    result = convert_value(val, type, schema)\nexcept ValueError as e:\n    if 'Cannot convert' in str(e):\n        print(f'Unsupported type code {val.type.code} with schema {schema}. Skipping.')\n        result = (str(val), None)\n    else:\n        raise","preventionTips":["Inspect val.type.code before passing to the conversion API.","For method pointers and exotic types, extract a primitive representation manually.","Ensure GDB language mode matches the expression's source language.","Break structs into individual fields and convert each separately."],"tags":["gdb","type-conversion","unsupported-type","value-mapping"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}