Sha256: f85eba1ec29265c3f2ab9dadcb33f0cfe02948e392257c34e6272f05514df4a5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module MemDump
    # Replace the address in the 'class' attribute by the class name
    def self.replace_class_address_by_name(dump, add_reference_to_class: false)
        class_names = Hash.new
        iclasses = Hash.new
        dump.each_record do |row|
            if row['type'] == 'CLASS' || row['type'] == 'MODULE'
                class_names[row['address']] = row['name']
            elsif row['type'] == 'ICLASS' || row['type'] == "IMEMO"
                iclasses[row['address']] = row
            end
        end

        iclass_size = 0
        while !iclasses.empty? && (iclass_size != iclasses.size)
            iclass_size = iclasses.size
            iclasses.delete_if do |_, r|
                if (klass = r['class']) && (class_name = class_names[klass])
                    class_names[r['address']] = "I(#{class_name})"
                    r['class'] = class_name
                    r['class_address'] = klass
                    if add_reference_to_class
                        (r['references'] ||= Set.new) << klass
                    end
                    true
                end
            end
        end

        dump.map do |r|
            if klass = r['class']
                r = r.dup
                r['class'] = class_names[klass] || klass
                r['class_address'] = klass
                if add_reference_to_class
                    (r['references'] ||= Set.new) << klass
                end
            end
            r
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
memdump-0.2.0 lib/memdump/replace_class_address_by_name.rb