Skip to content

Flatten super_BaseClass inheritance chains in struct member access #159

@kumarak

Description

@kumarak

Problem

C++ class hierarchies produce deeply nested struct member access chains in decompiled output:

((log_path.d)->super_QArrayData).ref.atomic._q_value.super___atomic_base<int>._M_i

Expected (flattened):

log_path.d->ref.atomic._q_value._M_i

Root Cause

Ghidra represents C++ base classes as synthesized struct fields named super_BaseClass. The serializer faithfully emits these, and the Clang AST preserves the full chain. No flattening or inheritance-aware processing exists.

Example Ghidra type hierarchy:

struct QString { Data *d; }
struct Data : QArrayData { ... }     →  field: super_QArrayData
struct QArrayData { RefCount ref; }
struct RefCount { QBasicAtomicInt atomic; }
struct QBasicAtomicInt : __atomic_base<int>  →  field: super___atomic_base<int>

Proposed Fix

In TypeBuilder::complete_definition(), when processing composite type fields:

Option A (Simple): Strip super_ prefix from field names → QArrayData.ref instead of super_QArrayData.ref

Option B (Better): Detect super_* fields and inline the base struct's fields at the same offset, flattening the hierarchy entirely

Files

  • lib/patchestry/AST/TypeBuilder.cppcomplete_definition() field processing
  • include/patchestry/Ghidra/PcodeTypes.hppCompositeType::Component

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions