<commit_before>require 'elf/object_file'
require 'elf/symbol_table_section'
require 'elf/text_section'
require 'elf/string_table_section'

module Elf

  class ObjectWriter
    def initialize(machine , target = Elf::Constants::TARGET_ARM )
      @object = Elf::ObjectFile.new(target)
      @object_machine = machine
      sym_strtab = Elf::StringTableSection.new(".strtab")
      @object.add_section sym_strtab
      @symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
      @object.add_section @symbol_table

      @text = Elf::TextSection.new(".text")
      @object.add_section @text

      assembler = Register::Assembler.new(@object_machine)
      set_text assembler.write_as_string

      # for debug add labels to the block positions
      @object_machine.space.classes.values.each do |clazz|
        clazz.instance_methods.each do |f|
          f.info.blocks.each do |b|
              add_symbol "#{clazz.name}::#{f.name}@#{b.name}" , b.position
            end
        end
      end
#      @object_machine.space.main.blocks.each do |b|
#        add_symbol "main@#{b.name}" , b.position
#      end
#      add_symbol "#register@#{@object_machine.space.init.name}" , @object_machine.space.init.position
      @object_machine.objects.each do |slot|
        if( slot.respond_to? :sof_reference_name )
          label = "#{slot.sof_reference_name}"
        else
          label = "#{slot.class.name}::#{slot.position.to_s(16)}"
        end
        label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
        label += "=#{slot.name}" if slot.is_a?(Parfait::BinaryCode)
        add_symbol  label , slot.position
      end
    end
    attr_reader :text
    def set_text(text)
      @text.text = text
      add_symbol "_start", 0
    end
    def add_symbol(name, offset, linkage = Elf::Constants::STB_GLOBAL)
      @symbol_table.add_func_symbol name, offset, @text, linkage
    end

    def save(filename)
      to = File.open(filename, 'wb')<commit_msg>change method debug format for gdb autocomplete<commit_after>require 'elf/object_file'
require 'elf/symbol_table_section'
require 'elf/text_section'
require 'elf/string_table_section'

module Elf

  class ObjectWriter
    def initialize(machine , target = Elf::Constants::TARGET_ARM )
      @object = Elf::ObjectFile.new(target)
      @object_machine = machine
      sym_strtab = Elf::StringTableSection.new(".strtab")
      @object.add_section sym_strtab
      @symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
      @object.add_section @symbol_table

      @text = Elf::TextSection.new(".text")
      @object.add_section @text

      assembler = Register::Assembler.new(@object_machine)
      set_text assembler.write_as_string

      # for debug add labels to the block positions
      @object_machine.space.classes.values.each do |clazz|
        clazz.instance_methods.each do |f|
          f.info.blocks.each do |b|
              add_symbol "#{clazz.name}::#{f.name}-#{b.name}" , b.position
            end
        end
      end
#      @object_machine.space.main.blocks.each do |b|
#        add_symbol "main@#{b.name}" , b.position
#      end
#      add_symbol "#register@#{@object_machine.space.init.name}" , @object_machine.space.init.position
      @object_machine.objects.each do |slot|
        if( slot.respond_to? :sof_reference_name )
          label = "#{slot.sof_reference_name}"
        else
          label = "#{slot.class.name}::#{slot.position.to_s(16)}"
        end
        label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
        label += "=#{slot.name}" if slot.is_a?(Parfait::BinaryCode)
        add_symbol  label , slot.position
      end
    end
    attr_reader :text
    def set_text(text)
      @text.text = text
      add_symbol "_start", 0
    end
    def add_symbol(name, offset, linkage = Elf::Constants::STB_GLOBAL)
      @symbol_table.add_func_symbol name, offset, @text, linkage
    end

    def save(filename)
      to = File.open(filename, 'wb')
{'fraction_non_alphanumeric': 0.12531328320802004, 'fraction_numerical': 0.0015037593984962407, 'mean_word_length': 2.9436758893280635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2065772', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1299, 'n_words': 251}