poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Introduce dwarf-abbrev.pk pickle for decoding the .debug_abbrev sect


From: Jose E. Marchesi
Subject: Re: Introduce dwarf-abbrev.pk pickle for decoding the .debug_abbrev section
Date: Tue, 19 Sep 2023 11:29:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

> Hello folks,
>
> I suggest to introduce the dwarf-abbrev.pk pickle for decoding
> the .debug_abbrev section.  The patch comes with a testcase.

Hello Martin.

Thank you very much for working on this :)

Please see some comments below.

> -TESTS = test-dwarf.pk
> +TESTS = test-dwarf.pk test-dwarf-abbrev.pk

I think it would be better to just put the new etsts in test-dwarf.pk.
Is a new file really necessary?

> +var DW_CHILDREN_no = 0x00,
> +    DW_CHILDREN_yes = 0x01;
> +
> +type Pretty_DW_CHILDREN_T = struct
> +  {
> +    type Entry = struct
> +    {
> +        uint<64> tag;
> +        string value;
> +    };
> +
> +    Entry[] entries = Entry[]();
> +
> +    method add = (uint<64> tag, string value) void:
> +    {
> +      apush (entries, Entry { tag = tag, value = value });
> +    }
> +
> +    method get = (uint<64> tag) string:
> +    {
> +      for(entry in entries where entry.tag ==  tag)
> +        return entry.value;
> +      raise E_inval;
> +    }
> +  };

I see these Pretty* data structures act like registries for DWARF
configuration parameters, a very similar approach that I used in the ELF
pickle.  I have some suggestions:

- I would put the DWARF contiguration registry in its own pickle:
  dwarf-config.pk.  Similar to elf-config.pk in the ELF pickle.

- I would use a single type Dwarf_Config, containing entries for all
  different kinds of parameters.   Something like this:

    /* Valid classes are: dw-form, dw-at, ... */

    type Dwarf_Config =
      struct
      {
        type Entry =
          struct
          {
            string class;
            uint<64> tag;
            string name;
            string doc;
          };

        method add = (int<32> class, uint<64> tag, string name) void: { ... }
        method get_name = (int<32> class, uint<64> tag) string: { ... }
      };

- Then, in dwarf-common.pk or perhaps in dwarf.pk, you can have a single
  variable for the entire registry:

  Dwarf_Config dwarf_config;

- Then in dwarf-info.pk or dwarf-abbrev.pk or wherever makes more sense,
  you populate the registry with invocations like:

  dwarf_config.add
    :class "dw-at"
    :tag DW_AT_string_length
    :doc "This DIE attribute reflects the length in bytes of blah blah";

- The Dwarf_Config type can have methods for checking whether a given
  value for some given CLASS is valid or not.  You can then use it for
  the constraints in the pickle structs.  Also, you can use it for
  pretty printing using field pretty-printers.  This is an example from
  elf-64.pk:

  type Elf64_RelInfo =
    struct Elf64_Xword
    {
      uint<32> r_sym;
      uint<32> r_type : elf_config.check_enum ("reloc-types", elf_mach, r_type);

      method _print_r_type = void:
      {
        printf "#<%s>", elf_config.format_enum ("reloc-types", elf_mach, 
r_type);
      }
    };

  Note how this type uses services of the ELF configuration registry
  (elf_config) in order to both check the integrity of the field r_type
  and to pretty-print it.

WDYT?

> +var Pretty_DW_CHILDREN = Pretty_DW_CHILDREN_T {};
> +
> +Pretty_DW_CHILDREN.add (DW_CHILDREN_no, "DW_CHILDREN_no");
> +Pretty_DW_CHILDREN.add (DW_CHILDREN_yes, "DW_CHILDREN_yes");
> +
> +
> +type Dwarf_Abbrev_Table_Hdr =
> +  struct
> +  {
> +    /*
> +     * 7.5.3 Abbreviations Tables
> +     * [...] Each declaration begins with an unsigned LEB128 number
> +     * representing the abbreviation code itself.  [...]  The
> +     * abbreviation code is followed by another unsigned LEB128
> +     * number that encodes the entry's tag.  [...]
> +     */
> +
> +     ULEB128 code : code.value != 0;
> +     ULEB128 tag;
> +
> +    /*
> +     * [...] Following the tag encoding is a 1-byte value that
> +     * determines whether a debugging information entry using this
> +     * abbreviation has child entries or not. [...]
> +     */
> +
> +     uint<8> children;
> +  };
> +
> +
> +type Dwarf_Abbrev_Table_Entry =
> +  struct
> +  {
> +    /*
> +     * 7.5.3 Abbreviations Tables
> +     * [...] Finally, the child encoding is followed by a series of
> +     * attribute specifications. Each attribute specification
> +     * consists of two parts. The first part is an unsigned LEB128
> +     * number representing the attribute's name. The second part is
> +     * an unsigned LEB128 number representing the attribute's form.
> +     */
> +
> +     ULEB128 name : name.value != 0;
> +     ULEB128 form : form.value != 0;
> +  };
> +
> +type Dwarf_Abbrev_Table_Null_Entry =
> +  struct
> +  {
> +    /*
> +     * A set of Dwarf_Abbrev_Table_Entry items is terminated by
> +     * one Dwarf_Abbrev_Table_Null_Entry
> +     */
> +
> +     ULEB128 name : name.value == 0;
> +     ULEB128 form : form.value == 0;
> +  };
> +
> +
> +
> +type Dwarf_Abbrev_Table =
> +  struct
> +  {
> +    Dwarf_Abbrev_Table_Hdr header;
> +    Dwarf_Abbrev_Table_Entry[] entries = Dwarf_Abbrev_Table_Entry[]();
> +    Dwarf_Abbrev_Table_Null_Entry nullentry;
> +
> +    method _print = void:
> +      {
> +        printf ("%u64d, %s, %s\n", header.code.value,
> +                                     Pretty_DW_TAG.get (header.tag.value),
> +                                     Pretty_DW_CHILDREN.get 
> (header.children));
> +        for (entry in entries)
> +          {
> +            printf ("\t%s, %s\n", Pretty_DW_AT.get (entry.name.value), 
> Pretty_DW_FORM.get (entry.form.value));
> +          }
> +      }
> +  };
> +
> +type Dwarf_Abbrev_Tables =
> +  struct
> +  {
> +    Dwarf_Abbrev_Table[] abbrev_tables = Dwarf_Abbrev_Table[]();
> +  };
> diff --git a/dwarf-info.pk b/dwarf-info.pk
> index f8adc52..106a00e 100644
> --- a/dwarf-info.pk
> +++ b/dwarf-info.pk
> @@ -110,6 +110,114 @@ var DW_TAG_array_type = 0x01,
>      DW_TAG_GNU_call_site_parameter = 0x410a,
>      DW_TAG_hi_user = 0xffff;
>
> +type Pretty_DW_TAG_T = struct
> +  {
> +    type Entry = struct
> +    {
> +      uint<64> tag;
> +      string value;
> +    };
> +
> +    Entry[] entries = Entry[]();
> +
> +    method add = (uint<64> tag, string value) void:
> +    {
> +      apush (entries, Entry { tag = tag, value = value });
> +    }
> +
> +    method get = (uint<64> tag) string:
> +    {
> +      for(entry in entries where entry.tag ==  tag)
> +        return entry.value;
> +      raise E_inval;
> +    }
> +  };
> +
> +var Pretty_DW_TAG = Pretty_DW_TAG_T {};
> +
> +Pretty_DW_TAG.add (DW_TAG_array_type, "DW_TAG_array_type");
> +Pretty_DW_TAG.add (DW_TAG_class_type, "DW_TAG_class_type");
> +Pretty_DW_TAG.add (DW_TAG_entry_point, "DW_TAG_entry_point");
> +Pretty_DW_TAG.add (DW_TAG_enumeration_type, "DW_TAG_enumeration_type");
> +Pretty_DW_TAG.add (DW_TAG_formal_parameter, "DW_TAG_formal_parameter");
> +Pretty_DW_TAG.add (DW_TAG_imported_declaration, 
> "DW_TAG_imported_declaration");
> +Pretty_DW_TAG.add (DW_TAG_label, "DW_TAG_label");
> +Pretty_DW_TAG.add (DW_TAG_lexical_block, "DW_TAG_lexical_block");
> +Pretty_DW_TAG.add (DW_TAG_member, "DW_TAG_member");
> +Pretty_DW_TAG.add (DW_TAG_pointer_type, "DW_TAG_pointer_type");
> +Pretty_DW_TAG.add (DW_TAG_reference_type, "DW_TAG_reference_type");
> +Pretty_DW_TAG.add (DW_TAG_compile_unit, "DW_TAG_compile_unit");
> +Pretty_DW_TAG.add (DW_TAG_string_type, "DW_TAG_string_type");
> +Pretty_DW_TAG.add (DW_TAG_structure_type, "DW_TAG_structure_type");
> +Pretty_DW_TAG.add (DW_TAG_subroutine_type, "DW_TAG_subroutine_type");
> +Pretty_DW_TAG.add (DW_TAG_typedef, "DW_TAG_typedef");
> +Pretty_DW_TAG.add (DW_TAG_union_type, "DW_TAG_union_type");
> +Pretty_DW_TAG.add (DW_TAG_unspecified_parameters, 
> "DW_TAG_unspecified_parameters");
> +Pretty_DW_TAG.add (DW_TAG_variant, "DW_TAG_variant");
> +Pretty_DW_TAG.add (DW_TAG_common_block, "DW_TAG_common_block");
> +Pretty_DW_TAG.add (DW_TAG_common_inclusion, "DW_TAG_common_inclusion");
> +Pretty_DW_TAG.add (DW_TAG_inheritance, "DW_TAG_inheritance");
> +Pretty_DW_TAG.add (DW_TAG_inlined_subroutine, "DW_TAG_inlined_subroutine");
> +Pretty_DW_TAG.add (DW_TAG_module, "DW_TAG_module");
> +Pretty_DW_TAG.add (DW_TAG_ptr_to_member_type, "DW_TAG_ptr_to_member_type");
> +Pretty_DW_TAG.add (DW_TAG_set_type, "DW_TAG_set_type");
> +Pretty_DW_TAG.add (DW_TAG_subrange_type, "DW_TAG_subrange_type");
> +Pretty_DW_TAG.add (DW_TAG_with_stmt, "DW_TAG_with_stmt");
> +Pretty_DW_TAG.add (DW_TAG_access_declaration, "DW_TAG_access_declaration");
> +Pretty_DW_TAG.add (DW_TAG_base_type, "DW_TAG_base_type");
> +Pretty_DW_TAG.add (DW_TAG_catch_block, "DW_TAG_catch_block");
> +Pretty_DW_TAG.add (DW_TAG_const_type, "DW_TAG_const_type");
> +Pretty_DW_TAG.add (DW_TAG_constant, "DW_TAG_constant");
> +Pretty_DW_TAG.add (DW_TAG_enumerator, "DW_TAG_enumerator");
> +Pretty_DW_TAG.add (DW_TAG_file_type, "DW_TAG_file_type");
> +Pretty_DW_TAG.add (DW_TAG_friend, "DW_TAG_friend");
> +Pretty_DW_TAG.add (DW_TAG_namelist, "DW_TAG_namelist");
> +Pretty_DW_TAG.add (DW_TAG_namelist_item, "DW_TAG_namelist_item");
> +Pretty_DW_TAG.add (DW_TAG_packed_type, "DW_TAG_packed_type");
> +Pretty_DW_TAG.add (DW_TAG_subprogram, "DW_TAG_subprogram");
> +Pretty_DW_TAG.add (DW_TAG_template_type_parameter, 
> "DW_TAG_template_type_parameter");
> +Pretty_DW_TAG.add (DW_TAG_template_value_parameter, 
> "DW_TAG_template_value_parameter");
> +Pretty_DW_TAG.add (DW_TAG_thrown_type, "DW_TAG_thrown_type");
> +Pretty_DW_TAG.add (DW_TAG_try_block, "DW_TAG_try_block");
> +Pretty_DW_TAG.add (DW_TAG_variant_part, "DW_TAG_variant_part");
> +Pretty_DW_TAG.add (DW_TAG_variable, "DW_TAG_variable");
> +Pretty_DW_TAG.add (DW_TAG_volatile_type, "DW_TAG_volatile_type");
> +Pretty_DW_TAG.add (DW_TAG_dwarf_procedure, "DW_TAG_dwarf_procedure");
> +Pretty_DW_TAG.add (DW_TAG_restrict_type, "DW_TAG_restrict_type");
> +Pretty_DW_TAG.add (DW_TAG_interface_type, "DW_TAG_interface_type");
> +Pretty_DW_TAG.add (DW_TAG_namespace, "DW_TAG_namespace");
> +Pretty_DW_TAG.add (DW_TAG_imported_module, "DW_TAG_imported_module");
> +Pretty_DW_TAG.add (DW_TAG_unspecified_type, "DW_TAG_unspecified_type");
> +Pretty_DW_TAG.add (DW_TAG_partial_unit, "DW_TAG_partial_unit");
> +Pretty_DW_TAG.add (DW_TAG_imported_unit, "DW_TAG_imported_unit");
> +Pretty_DW_TAG.add (DW_TAG_condition, "DW_TAG_condition");
> +Pretty_DW_TAG.add (DW_TAG_shared_type, "DW_TAG_shared_type");
> +Pretty_DW_TAG.add (DW_TAG_type_unit, "DW_TAG_type_unit");
> +Pretty_DW_TAG.add (DW_TAG_rvalue_reference_type, 
> "DW_TAG_rvalue_reference_type");
> +Pretty_DW_TAG.add (DW_TAG_template_alias, "DW_TAG_template_alias");
> +Pretty_DW_TAG.add (DW_TAG_coarray_type, "DW_TAG_coarray_type");
> +Pretty_DW_TAG.add (DW_TAG_generic_subrange, "DW_TAG_generic_subrange");
> +Pretty_DW_TAG.add (DW_TAG_dynamic_type, "DW_TAG_dynamic_type");
> +Pretty_DW_TAG.add (DW_TAG_atomic_type, "DW_TAG_atomic_type");
> +Pretty_DW_TAG.add (DW_TAG_call_site, "DW_TAG_call_site");
> +Pretty_DW_TAG.add (DW_TAG_call_site_parameter, "DW_TAG_call_site_parameter");
> +Pretty_DW_TAG.add (DW_TAG_skeleton_unit, "DW_TAG_skeleton_unit");
> +Pretty_DW_TAG.add (DW_TAG_immutable_type, "DW_TAG_immutable_type");
> +Pretty_DW_TAG.add (DW_TAG_lo_user, "DW_TAG_lo_user");
> +Pretty_DW_TAG.add (DW_TAG_MIPS_loop, "DW_TAG_MIPS_loop");
> +Pretty_DW_TAG.add (DW_TAG_format_label, "DW_TAG_format_label");
> +Pretty_DW_TAG.add (DW_TAG_function_template, "DW_TAG_function_template");
> +Pretty_DW_TAG.add (DW_TAG_class_template, "DW_TAG_class_template");
> +Pretty_DW_TAG.add (DW_TAG_GNU_BINCL, "DW_TAG_GNU_BINCL");
> +Pretty_DW_TAG.add (DW_TAG_GNU_EINCL, "DW_TAG_GNU_EINCL");
> +Pretty_DW_TAG.add (DW_TAG_GNU_template_template_param, 
> "DW_TAG_GNU_template_template_param");
> +Pretty_DW_TAG.add (DW_TAG_GNU_template_parameter_pack, 
> "DW_TAG_GNU_template_parameter_pack");
> +Pretty_DW_TAG.add (DW_TAG_GNU_formal_parameter_pack, 
> "DW_TAG_GNU_formal_parameter_pack");
> +Pretty_DW_TAG.add (DW_TAG_GNU_call_site, "DW_TAG_GNU_call_site");
> +Pretty_DW_TAG.add (DW_TAG_GNU_call_site_parameter, 
> "DW_TAG_GNU_call_site_parameter");
> +Pretty_DW_TAG.add (DW_TAG_hi_user, "DW_TAG_hi_user");
> +
> +
>  /* DWARF Attributes.  */
>
>  var DW_AT_sibling = 0x01,
> @@ -313,6 +421,211 @@ var DW_AT_sibling = 0x01,
>      DW_AT_GNU_bias = 0x2305,
>      DW_AT_hi_user = 0x3ff;
>
> +type Pretty_DW_AT_T = struct
> +  {
> +    type Entry = struct
> +    {
> +      uint<64> tag;
> +      string value;
> +    };
> +
> +    Entry[] entries = Entry[]();
> +
> +    method add = (uint<64> tag, string value) void:
> +    {
> +      apush (entries, Entry { tag = tag, value = value });
> +    }
> +
> +    method get = (uint<64> tag) string:
> +    {
> +      for(entry in entries where entry.tag ==  tag)
> +        return entry.value;
> +      raise E_inval;
> +    }
> +  };
> +
> +var Pretty_DW_AT = Pretty_DW_TAG_T {};
> +
> +Pretty_DW_AT.add (DW_AT_sibling, "DW_AT_sibling");
> +Pretty_DW_AT.add (DW_AT_location, "DW_AT_location");
> +Pretty_DW_AT.add (DW_AT_name, "DW_AT_name");
> +Pretty_DW_AT.add (DW_AT_ordering, "DW_AT_ordering");
> +Pretty_DW_AT.add (DW_AT_byte_size, "DW_AT_byte_size");
> +Pretty_DW_AT.add (DW_AT_bit_offset, "DW_AT_bit_offset");
> +Pretty_DW_AT.add (DW_AT_bit_size, "DW_AT_bit_size");
> +Pretty_DW_AT.add (DW_AT_stmt_list, "DW_AT_stmt_list");
> +Pretty_DW_AT.add (DW_AT_low_pc, "DW_AT_low_pc");
> +Pretty_DW_AT.add (DW_AT_high_pc, "DW_AT_high_pc");
> +Pretty_DW_AT.add (DW_AT_language, "DW_AT_language");
> +Pretty_DW_AT.add (DW_AT_discr, "DW_AT_discr");
> +Pretty_DW_AT.add (DW_AT_discr_value, "DW_AT_discr_value");
> +Pretty_DW_AT.add (DW_AT_visibility, "DW_AT_visibility");
> +Pretty_DW_AT.add (DW_AT_import, "DW_AT_import");
> +Pretty_DW_AT.add (DW_AT_string_length, "DW_AT_string_length");
> +Pretty_DW_AT.add (DW_AT_common_reference, "DW_AT_common_reference");
> +Pretty_DW_AT.add (DW_AT_comp_dir, "DW_AT_comp_dir");
> +Pretty_DW_AT.add (DW_AT_const_value, "DW_AT_const_value");
> +Pretty_DW_AT.add (DW_AT_containing_type, "DW_AT_containing_type");
> +Pretty_DW_AT.add (DW_AT_default_value, "DW_AT_default_value");
> +Pretty_DW_AT.add (DW_AT_inline, "DW_AT_inline");
> +Pretty_DW_AT.add (DW_AT_is_optional, "DW_AT_is_optional");
> +Pretty_DW_AT.add (DW_AT_lower_bound, "DW_AT_lower_bound");
> +Pretty_DW_AT.add (DW_AT_producer, "DW_AT_producer");
> +Pretty_DW_AT.add (DW_AT_prototyped, "DW_AT_prototyped");
> +Pretty_DW_AT.add (DW_AT_return_addr, "DW_AT_return_addr");
> +Pretty_DW_AT.add (DW_AT_start_scope, "DW_AT_start_scope");
> +Pretty_DW_AT.add (DW_AT_bit_stride, "DW_AT_bit_stride");
> +Pretty_DW_AT.add (DW_AT_upper_bound, "DW_AT_upper_bound");
> +Pretty_DW_AT.add (DW_AT_abstract_origin, "DW_AT_abstract_origin");
> +Pretty_DW_AT.add (DW_AT_accessibility, "DW_AT_accessibility");
> +Pretty_DW_AT.add (DW_AT_address_class, "DW_AT_address_class");
> +Pretty_DW_AT.add (DW_AT_artificial, "DW_AT_artificial");
> +Pretty_DW_AT.add (DW_AT_base_types, "DW_AT_base_types");
> +Pretty_DW_AT.add (DW_AT_calling_convention, "DW_AT_calling_convention");
> +Pretty_DW_AT.add (DW_AT_count, "DW_AT_count");
> +Pretty_DW_AT.add (DW_AT_data_member_location, "DW_AT_data_member_location");
> +Pretty_DW_AT.add (DW_AT_decl_column, "DW_AT_decl_column");
> +Pretty_DW_AT.add (DW_AT_decl_file, "DW_AT_decl_file");
> +Pretty_DW_AT.add (DW_AT_decl_line, "DW_AT_decl_line");
> +Pretty_DW_AT.add (DW_AT_declaration, "DW_AT_declaration");
> +Pretty_DW_AT.add (DW_AT_discr_list, "DW_AT_discr_list");
> +Pretty_DW_AT.add (DW_AT_encoding, "DW_AT_encoding");
> +Pretty_DW_AT.add (DW_AT_external, "DW_AT_external");
> +Pretty_DW_AT.add (DW_AT_frame_base, "DW_AT_frame_base");
> +Pretty_DW_AT.add (DW_AT_friend, "DW_AT_friend");
> +Pretty_DW_AT.add (DW_AT_identifier_case, "DW_AT_identifier_case");
> +Pretty_DW_AT.add (DW_AT_macro_info, "DW_AT_macro_info");
> +Pretty_DW_AT.add (DW_AT_namelist_item, "DW_AT_namelist_item");
> +Pretty_DW_AT.add (DW_AT_priority, "DW_AT_priority");
> +Pretty_DW_AT.add (DW_AT_segment, "DW_AT_segment");
> +Pretty_DW_AT.add (DW_AT_specification, "DW_AT_specification");
> +Pretty_DW_AT.add (DW_AT_static_link, "DW_AT_static_link");
> +Pretty_DW_AT.add (DW_AT_type, "DW_AT_type");
> +Pretty_DW_AT.add (DW_AT_use_location, "DW_AT_use_location");
> +Pretty_DW_AT.add (DW_AT_variable_parameter, "DW_AT_variable_parameter");
> +Pretty_DW_AT.add (DW_AT_virtuality, "DW_AT_virtuality");
> +Pretty_DW_AT.add (DW_AT_vtable_elem_location, "DW_AT_vtable_elem_location");
> +Pretty_DW_AT.add (DW_AT_allocated, "DW_AT_allocated");
> +Pretty_DW_AT.add (DW_AT_associated, "DW_AT_associated");
> +Pretty_DW_AT.add (DW_AT_data_location, "DW_AT_data_location");
> +Pretty_DW_AT.add (DW_AT_byte_stride, "DW_AT_byte_stride");
> +Pretty_DW_AT.add (DW_AT_entry_pc, "DW_AT_entry_pc");
> +Pretty_DW_AT.add (DW_AT_use_UTF8, "DW_AT_use_UTF8");
> +Pretty_DW_AT.add (DW_AT_extension, "DW_AT_extension");
> +Pretty_DW_AT.add (DW_AT_ranges, "DW_AT_ranges");
> +Pretty_DW_AT.add (DW_AT_trampoline, "DW_AT_trampoline");
> +Pretty_DW_AT.add (DW_AT_call_column, "DW_AT_call_column");
> +Pretty_DW_AT.add (DW_AT_call_file, "DW_AT_call_file");
> +Pretty_DW_AT.add (DW_AT_call_line, "DW_AT_call_line");
> +Pretty_DW_AT.add (DW_AT_description, "DW_AT_description");
> +Pretty_DW_AT.add (DW_AT_binary_scale, "DW_AT_binary_scale");
> +Pretty_DW_AT.add (DW_AT_decimal_scale, "DW_AT_decimal_scale");
> +Pretty_DW_AT.add (DW_AT_small, "DW_AT_small");
> +Pretty_DW_AT.add (DW_AT_decimal_sign, "DW_AT_decimal_sign");
> +Pretty_DW_AT.add (DW_AT_digit_count, "DW_AT_digit_count");
> +Pretty_DW_AT.add (DW_AT_picture_string, "DW_AT_picture_string");
> +Pretty_DW_AT.add (DW_AT_mutable, "DW_AT_mutable");
> +Pretty_DW_AT.add (DW_AT_threads_scaled, "DW_AT_threads_scaled");
> +Pretty_DW_AT.add (DW_AT_explicit, "DW_AT_explicit");
> +Pretty_DW_AT.add (DW_AT_object_pointer, "DW_AT_object_pointer");
> +Pretty_DW_AT.add (DW_AT_endianity, "DW_AT_endianity");
> +Pretty_DW_AT.add (DW_AT_elemental, "DW_AT_elemental");
> +Pretty_DW_AT.add (DW_AT_pure, "DW_AT_pure");
> +Pretty_DW_AT.add (DW_AT_recursive, "DW_AT_recursive");
> +Pretty_DW_AT.add (DW_AT_signature, "DW_AT_signature");
> +Pretty_DW_AT.add (DW_AT_main_subprogram, "DW_AT_main_subprogram");
> +Pretty_DW_AT.add (DW_AT_data_bit_offset, "DW_AT_data_bit_offset");
> +Pretty_DW_AT.add (DW_AT_const_expr, "DW_AT_const_expr");
> +Pretty_DW_AT.add (DW_AT_enum_class, "DW_AT_enum_class");
> +Pretty_DW_AT.add (DW_AT_linkage_name, "DW_AT_linkage_name");
> +Pretty_DW_AT.add (DW_AT_string_length_bit_size, 
> "DW_AT_string_length_bit_size");
> +Pretty_DW_AT.add (DW_AT_string_length_byte_size, 
> "DW_AT_string_length_byte_size");
> +Pretty_DW_AT.add (DW_AT_rank, "DW_AT_rank");
> +Pretty_DW_AT.add (DW_AT_str_offsets_base, "DW_AT_str_offsets_base");
> +Pretty_DW_AT.add (DW_AT_addr_base, "DW_AT_addr_base");
> +Pretty_DW_AT.add (DW_AT_rnglists_base, "DW_AT_rnglists_base");
> +Pretty_DW_AT.add (DW_AT_dwo_name, "DW_AT_dwo_name");
> +Pretty_DW_AT.add (DW_AT_reference, "DW_AT_reference");
> +Pretty_DW_AT.add (DW_AT_rvalue_reference, "DW_AT_rvalue_reference");
> +Pretty_DW_AT.add (DW_AT_macros, "DW_AT_macros");
> +Pretty_DW_AT.add (DW_AT_call_all_calls, "DW_AT_call_all_calls");
> +Pretty_DW_AT.add (DW_AT_call_all_source_calls, 
> "DW_AT_call_all_source_calls");
> +Pretty_DW_AT.add (DW_AT_call_all_tail_calls, "DW_AT_call_all_tail_calls");
> +Pretty_DW_AT.add (DW_AT_call_return_pc, "DW_AT_call_return_pc");
> +Pretty_DW_AT.add (DW_AT_call_value, "DW_AT_call_value");
> +Pretty_DW_AT.add (DW_AT_call_origin, "DW_AT_call_origin");
> +Pretty_DW_AT.add (DW_AT_call_parameter, "DW_AT_call_parameter");
> +Pretty_DW_AT.add (DW_AT_call_pc, "DW_AT_call_pc");
> +Pretty_DW_AT.add (DW_AT_call_tail_call, "DW_AT_call_tail_call");
> +Pretty_DW_AT.add (DW_AT_call_target, "DW_AT_call_target");
> +Pretty_DW_AT.add (DW_AT_call_target_clobbered, 
> "DW_AT_call_target_clobbered");
> +Pretty_DW_AT.add (DW_AT_call_data_location, "DW_AT_call_data_location");
> +Pretty_DW_AT.add (DW_AT_call_data_value, "DW_AT_call_data_value");
> +Pretty_DW_AT.add (DW_AT_noreturn, "DW_AT_noreturn");
> +Pretty_DW_AT.add (DW_AT_alignment, "DW_AT_alignment");
> +Pretty_DW_AT.add (DW_AT_export_symbols, "DW_AT_export_symbols");
> +Pretty_DW_AT.add (DW_AT_deleted, "DW_AT_deleted");
> +Pretty_DW_AT.add (DW_AT_defaulted, "DW_AT_defaulted");
> +Pretty_DW_AT.add (DW_AT_loclists_base, "DW_AT_loclists_base");
> +Pretty_DW_AT.add (DW_AT_lo_user, "DW_AT_lo_user");
> +Pretty_DW_AT.add (DW_AT_MIPS_fde, "DW_AT_MIPS_fde");
> +Pretty_DW_AT.add (DW_AT_MIPS_loop_begin, "DW_AT_MIPS_loop_begin");
> +Pretty_DW_AT.add (DW_AT_MIPS_tail_loop_begin, "DW_AT_MIPS_tail_loop_begin");
> +Pretty_DW_AT.add (DW_AT_MIPS_epilog_begin, "DW_AT_MIPS_epilog_begin");
> +Pretty_DW_AT.add (DW_AT_MIPS_loop_unroll_factor, 
> "DW_AT_MIPS_loop_unroll_factor");
> +Pretty_DW_AT.add (DW_AT_MIPS_software_pipeline_depth, 
> "DW_AT_MIPS_software_pipeline_depth");
> +Pretty_DW_AT.add (DW_AT_MIPS_linkage_name, "DW_AT_MIPS_linkage_name");
> +Pretty_DW_AT.add (DW_AT_MIPS_stride, "DW_AT_MIPS_stride");
> +Pretty_DW_AT.add (DW_AT_MIPS_abstract_name, "DW_AT_MIPS_abstract_name");
> +Pretty_DW_AT.add (DW_AT_MIPS_clone_origin, "DW_AT_MIPS_clone_origin");
> +Pretty_DW_AT.add (DW_AT_MIPS_has_inlines, "DW_AT_MIPS_has_inlines");
> +Pretty_DW_AT.add (DW_AT_MIPS_stride_byte, "DW_AT_MIPS_stride_byte");
> +Pretty_DW_AT.add (DW_AT_MIPS_stride_elem, "DW_AT_MIPS_stride_elem");
> +Pretty_DW_AT.add (DW_AT_MIPS_ptr_dopetype, "DW_AT_MIPS_ptr_dopetype");
> +Pretty_DW_AT.add (DW_AT_MIPS_allocatable_dopetype, 
> "DW_AT_MIPS_allocatable_dopetype");
> +Pretty_DW_AT.add (DW_AT_MIPS_assumed_shape_dopetype, 
> "DW_AT_MIPS_assumed_shape_dopetype");
> +Pretty_DW_AT.add (DW_AT_MIPS_assumed_size, "DW_AT_MIPS_assumed_size");
> +Pretty_DW_AT.add (DW_AT_sf_names, "DW_AT_sf_names");
> +Pretty_DW_AT.add (DW_AT_src_info, "DW_AT_src_info");
> +Pretty_DW_AT.add (DW_AT_mac_info, "DW_AT_mac_info");
> +Pretty_DW_AT.add (DW_AT_src_coords, "DW_AT_src_coords");
> +Pretty_DW_AT.add (DW_AT_body_begin, "DW_AT_body_begin");
> +Pretty_DW_AT.add (DW_AT_body_end, "DW_AT_body_end");
> +Pretty_DW_AT.add (DW_AT_GNU_vector, "DW_AT_GNU_vector");
> +Pretty_DW_AT.add (DW_AT_GNU_guarded_by, "DW_AT_GNU_guarded_by");
> +Pretty_DW_AT.add (DW_AT_GNU_pt_guarded_by, "DW_AT_GNU_pt_guarded_by");
> +Pretty_DW_AT.add (DW_AT_GNU_guarded, "DW_AT_GNU_guarded");
> +Pretty_DW_AT.add (DW_AT_GNU_pt_guarded, "DW_AT_GNU_pt_guarded");
> +Pretty_DW_AT.add (DW_AT_GNU_locks_excluded, "DW_AT_GNU_locks_excluded");
> +Pretty_DW_AT.add (DW_AT_GNU_exclusive_locks_required, 
> "DW_AT_GNU_exclusive_locks_required");
> +Pretty_DW_AT.add (DW_AT_GNU_shared_locks_required, 
> "DW_AT_GNU_shared_locks_required");
> +Pretty_DW_AT.add (DW_AT_GNU_odr_signature, "DW_AT_GNU_odr_signature");
> +Pretty_DW_AT.add (DW_AT_GNU_template_name, "DW_AT_GNU_template_name");
> +Pretty_DW_AT.add (DW_AT_GNU_call_site_value, "DW_AT_GNU_call_site_value");
> +Pretty_DW_AT.add (DW_AT_GNU_call_site_data_value, 
> "DW_AT_GNU_call_site_data_value");
> +Pretty_DW_AT.add (DW_AT_GNU_call_site_target, "DW_AT_GNU_call_site_target");
> +Pretty_DW_AT.add (DW_AT_GNU_call_site_target_clobbered, 
> "DW_AT_GNU_call_site_target_clobbered");
> +Pretty_DW_AT.add (DW_AT_GNU_tail_call, "DW_AT_GNU_tail_call");
> +Pretty_DW_AT.add (DW_AT_GNU_all_tail_call_sites, 
> "DW_AT_GNU_all_tail_call_sites");
> +Pretty_DW_AT.add (DW_AT_GNU_all_call_sites, "DW_AT_GNU_all_call_sites");
> +Pretty_DW_AT.add (DW_AT_GNU_all_source_call_sites, 
> "DW_AT_GNU_all_source_call_sites");
> +Pretty_DW_AT.add (DW_AT_GNU_locviews, "DW_AT_GNU_locviews");
> +Pretty_DW_AT.add (DW_AT_GNU_entry_view, "DW_AT_GNU_entry_view");
> +Pretty_DW_AT.add (DW_AT_GNU_macros, "DW_AT_GNU_macros");
> +Pretty_DW_AT.add (DW_AT_GNU_deleted, "DW_AT_GNU_deleted");
> +Pretty_DW_AT.add (DW_AT_GNU_dwo_name, "DW_AT_GNU_dwo_name");
> +Pretty_DW_AT.add (DW_AT_GNU_dwo_id, "DW_AT_GNU_dwo_id");
> +Pretty_DW_AT.add (DW_AT_GNU_ranges_base, "DW_AT_GNU_ranges_base");
> +Pretty_DW_AT.add (DW_AT_GNU_addr_base, "DW_AT_GNU_addr_base");
> +Pretty_DW_AT.add (DW_AT_GNU_pubnames, "DW_AT_GNU_pubnames");
> +Pretty_DW_AT.add (DW_AT_GNU_pubtypes, "DW_AT_GNU_pubtypes");
> +Pretty_DW_AT.add (DW_AT_GNU_numerator, "DW_AT_GNU_numerator");
> +Pretty_DW_AT.add (DW_AT_GNU_denominator, "DW_AT_GNU_denominator");
> +Pretty_DW_AT.add (DW_AT_GNU_bias, "DW_AT_GNU_bias");
> +Pretty_DW_AT.add (DW_AT_GNU_bias, "DW_AT_GNU_bias");
> +Pretty_DW_AT.add (DW_AT_hi_user, "DW_AT_hi_user");
> +
> +
>  /* DWARF form encodings.  */
>
>  var DW_FORM_addr = 0x01,
> @@ -364,6 +677,80 @@ var DW_FORM_addr = 0x01,
>      DW_FORM_GNU_ref_alt = 0x1f20,
>      DW_FORM_GNU_strp_alt = 0x1f21;
>
> +type Pretty_DW_FORM_T = struct
> +  {
> +    type Entry = struct
> +    {
> +      uint<64> tag;
> +      string value;
> +    };
> +
> +    Entry[] entries = Entry[]();
> +
> +    method add = (uint<64> tag, string value) void:
> +    {
> +      apush (entries, Entry { tag = tag, value = value });
> +    }
> +
> +    method get = (uint<64> tag) string:
> +    {
> +      for(entry in entries where entry.tag ==  tag)
> +        return entry.value;
> +      raise E_inval;
> +    }
> +  };
> +
> +var Pretty_DW_FORM = Pretty_DW_TAG_T {};
> +
> +Pretty_DW_FORM.add (DW_FORM_addr, "DW_FORM_addr");
> +Pretty_DW_FORM.add (DW_FORM_block2, "DW_FORM_block2");
> +Pretty_DW_FORM.add (DW_FORM_block4, "DW_FORM_block4");
> +Pretty_DW_FORM.add (DW_FORM_data2, "DW_FORM_data2");
> +Pretty_DW_FORM.add (DW_FORM_data4, "DW_FORM_data4");
> +Pretty_DW_FORM.add (DW_FORM_data8, "DW_FORM_data8");
> +Pretty_DW_FORM.add (DW_FORM_string, "DW_FORM_string");
> +Pretty_DW_FORM.add (DW_FORM_block, "DW_FORM_block");
> +Pretty_DW_FORM.add (DW_FORM_block1, "DW_FORM_block1");
> +Pretty_DW_FORM.add (DW_FORM_data1, "DW_FORM_data1");
> +Pretty_DW_FORM.add (DW_FORM_flag, "DW_FORM_flag");
> +Pretty_DW_FORM.add (DW_FORM_sdata, "DW_FORM_sdata");
> +Pretty_DW_FORM.add (DW_FORM_strp, "DW_FORM_strp");
> +Pretty_DW_FORM.add (DW_FORM_udata, "DW_FORM_udata");
> +Pretty_DW_FORM.add (DW_FORM_ref_addr, "DW_FORM_ref_addr");
> +Pretty_DW_FORM.add (DW_FORM_ref1, "DW_FORM_ref1");
> +Pretty_DW_FORM.add (DW_FORM_ref2, "DW_FORM_ref2");
> +Pretty_DW_FORM.add (DW_FORM_ref4, "DW_FORM_ref4");
> +Pretty_DW_FORM.add (DW_FORM_ref8, "DW_FORM_ref8");
> +Pretty_DW_FORM.add (DW_FORM_ref_udata, "DW_FORM_ref_udata");
> +Pretty_DW_FORM.add (DW_FORM_indirect, "DW_FORM_indirect");
> +Pretty_DW_FORM.add (DW_FORM_sec_offset, "DW_FORM_sec_offset");
> +Pretty_DW_FORM.add (DW_FORM_exprloc, "DW_FORM_exprloc");
> +Pretty_DW_FORM.add (DW_FORM_flag_present, "DW_FORM_flag_present");
> +Pretty_DW_FORM.add (DW_FORM_strx, "DW_FORM_strx");
> +Pretty_DW_FORM.add (DW_FORM_addrx, "DW_FORM_addrx");
> +Pretty_DW_FORM.add (DW_FORM_ref_sup4, "DW_FORM_ref_sup4");
> +Pretty_DW_FORM.add (DW_FORM_strp_sup, "DW_FORM_strp_sup");
> +Pretty_DW_FORM.add (DW_FORM_data16, "DW_FORM_data16");
> +Pretty_DW_FORM.add (DW_FORM_line_strp, "DW_FORM_line_strp");
> +Pretty_DW_FORM.add (DW_FORM_ref_sig8, "DW_FORM_ref_sig8");
> +Pretty_DW_FORM.add (DW_FORM_implicit_const, "DW_FORM_implicit_const");
> +Pretty_DW_FORM.add (DW_FORM_loclistx, "DW_FORM_loclistx");
> +Pretty_DW_FORM.add (DW_FORM_rnglistx, "DW_FORM_rnglistx");
> +Pretty_DW_FORM.add (DW_FORM_ref_sup8, "DW_FORM_ref_sup8");
> +Pretty_DW_FORM.add (DW_FORM_strx1, "DW_FORM_strx1");
> +Pretty_DW_FORM.add (DW_FORM_strx2, "DW_FORM_strx2");
> +Pretty_DW_FORM.add (DW_FORM_strx3, "DW_FORM_strx3");
> +Pretty_DW_FORM.add (DW_FORM_strx4, "DW_FORM_strx4");
> +Pretty_DW_FORM.add (DW_FORM_addrx1, "DW_FORM_addrx1");
> +Pretty_DW_FORM.add (DW_FORM_addrx2, "DW_FORM_addrx2");
> +Pretty_DW_FORM.add (DW_FORM_addrx3, "DW_FORM_addrx3");
> +Pretty_DW_FORM.add (DW_FORM_addrx4, "DW_FORM_addrx4");
> +Pretty_DW_FORM.add (DW_FORM_GNU_addr_index, "DW_FORM_GNU_addr_index");
> +Pretty_DW_FORM.add (DW_FORM_GNU_str_index, "DW_FORM_GNU_str_index");
> +Pretty_DW_FORM.add (DW_FORM_GNU_ref_alt, "DW_FORM_GNU_ref_alt");
> +Pretty_DW_FORM.add (DW_FORM_GNU_strp_alt, "DW_FORM_GNU_strp_alt");
> +
> +
>  /* Contributions are stored in .debug_info sections.  */
>
>  type Dwarf_CU_Header =
> diff --git a/dwarf.pk b/dwarf.pk
> index 1d3f8c4..159b61e 100644
> --- a/dwarf.pk
> +++ b/dwarf.pk
> @@ -17,6 +17,7 @@
>   */
>
>  load "dwarf-common.pk";
> +load "dwarf-abbrev.pk";
>  load "dwarf-info.pk";
>  load "dwarf-expr.pk";
>  load "dwarf-frame.pk";
> diff --git a/test-dwarf-abbrev.pk.in b/test-dwarf-abbrev.pk.in
> new file mode 100644
> index 0000000..9cc723b
> --- /dev/null
> +++ b/test-dwarf-abbrev.pk.in
> @@ -0,0 +1,75 @@
> +#!@POKE@ -L
> +!#
> +
> +/*  test-dwarf-abbrev.pk - Tests for the dwarf-abbrev pickle.  */
> +
> +/* Copyright (C) 2022 Oracle, Inc.  */
> +
> +/* This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 3 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +load pktest;
> +load dwarf;
> +
> +var data = open ("*data*");
> +
> +uint<8>[19] @ data : 0#B = [
> +  0x01UB, 0x11UB, 0x01UB, 0x25UB, 0x0eUB, 0x13UB, 0x0bUB, 0x03UB, 0x1fUB,
> +  0x1bUB, 0x1fUB, 0x11UB, 0x01UB, 0x12UB, 0x07UB, 0x10UB, 0x17UB, 0x00UB,
> +  0x00UB
> +];
> +
> +var tests = [
> +  PkTest {
> +    name = "dwarf-abbrev test",
> +    todo = "WIP",
> +    func = lambda (string name) void:
> +      {
> +        var tbl = Dwarf_Abbrev_Tables @ data: 0#B;
> +        var h = tbl.abbrev_tables[0].header;
> +        var e = tbl.abbrev_tables[0].entries;
> +        var n = tbl.abbrev_tables[0].nullentry;
> +
> +        assert (h.code.value == 1);
> +        assert (Pretty_DW_TAG.get (h.tag.value) == "DW_TAG_compile_unit");
> +        assert (Pretty_DW_CHILDREN.get (h.children) == "DW_CHILDREN_yes");
> +
> +        assert (Pretty_DW_AT.get (e[0].name.value) == "DW_AT_producer");
> +        assert (Pretty_DW_FORM.get (e[0].form.value) == "DW_FORM_strp");
> +
> +        assert (Pretty_DW_AT.get (e[1].name.value) == "DW_AT_language");
> +        assert (Pretty_DW_FORM.get (e[1].form.value) == "DW_FORM_data1");
> +
> +        assert (Pretty_DW_AT.get (e[2].name.value) == "DW_AT_name");
> +        assert (Pretty_DW_FORM.get (e[2].form.value) == "DW_FORM_line_strp");
> +
> +        assert (Pretty_DW_AT.get (e[3].name.value) == "DW_AT_comp_dir");
> +        assert (Pretty_DW_FORM.get (e[3].form.value) == "DW_FORM_line_strp");
> +
> +        assert (Pretty_DW_AT.get (e[4].name.value) == "DW_AT_low_pc");
> +        assert (Pretty_DW_FORM.get (e[4].form.value) == "DW_FORM_addr");
> +
> +        assert (Pretty_DW_AT.get (e[5].name.value) == "DW_AT_high_pc");
> +        assert (Pretty_DW_FORM.get (e[5].form.value) == "DW_FORM_data8");
> +
> +        assert (Pretty_DW_AT.get (e[6].name.value) == "DW_AT_stmt_list");
> +        assert (Pretty_DW_FORM.get (e[6].form.value) == 
> "DW_FORM_sec_offset");
> +
> +        assert (n.name.value == 0);
> +        assert (n.form.value == 0);
> +      }
> +  },];
> +
> +exit (pktest_run (tests) ? 0 : 1);
> +



reply via email to

[Prev in Thread] Current Thread [Next in Thread]