Types are resolved from right to left: we get the variable name first and then all specifiers (like const or pointer) in a chain of DW_AT_type DIEs. Call this function recursively until we get a complete type string.
| 2847 | // DIEs. Call this function recursively until we get a complete type |
| 2848 | // string. |
| 2849 | static void set_parameter_string(dwarf_fileobject &fobj, Dwarf_Die die, |
| 2850 | type_context_t &context) { |
| 2851 | char *name; |
| 2852 | Dwarf_Error error = DW_DLE_NE; |
| 2853 | |
| 2854 | // typedefs contain also the base type, so we skip it and only |
| 2855 | // print the typedef name |
| 2856 | if (!context.is_typedef) { |
| 2857 | if (dwarf_diename(die, &name, &error) == DW_DLV_OK) { |
| 2858 | if (!context.text.empty()) { |
| 2859 | context.text.insert(0, " "); |
| 2860 | } |
| 2861 | context.text.insert(0, std::string(name)); |
| 2862 | dwarf_dealloc(fobj.dwarf_handle.get(), name, DW_DLA_STRING); |
| 2863 | } |
| 2864 | } else { |
| 2865 | context.is_typedef = false; |
| 2866 | context.has_type = true; |
| 2867 | if (context.is_const) { |
| 2868 | context.text.insert(0, "const "); |
| 2869 | context.is_const = false; |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | bool next_type_is_const = false; |
| 2874 | bool is_keyword = true; |
| 2875 | |
| 2876 | Dwarf_Half tag = 0; |
| 2877 | Dwarf_Bool has_attr = 0; |
| 2878 | if (dwarf_tag(die, &tag, &error) == DW_DLV_OK) { |
| 2879 | switch (tag) { |
| 2880 | case DW_TAG_structure_type: |
| 2881 | case DW_TAG_union_type: |
| 2882 | case DW_TAG_class_type: |
| 2883 | case DW_TAG_enumeration_type: |
| 2884 | context.has_type = true; |
| 2885 | if (dwarf_hasattr(die, DW_AT_signature, &has_attr, &error) == |
| 2886 | DW_DLV_OK) { |
| 2887 | // If we have a signature it means the type is defined |
| 2888 | // in .debug_types, so we need to load the DIE pointed |
| 2889 | // at by the signature and resolve it |
| 2890 | if (has_attr) { |
| 2891 | std::string type = |
| 2892 | get_type_by_signature(fobj.dwarf_handle.get(), die); |
| 2893 | if (context.is_const) |
| 2894 | type.insert(0, "const "); |
| 2895 | |
| 2896 | if (!context.text.empty()) |
| 2897 | context.text.insert(0, " "); |
| 2898 | context.text.insert(0, type); |
| 2899 | } |
| 2900 | |
| 2901 | // Treat enums like typedefs, and skip printing its |
| 2902 | // base type |
| 2903 | context.is_typedef = (tag == DW_TAG_enumeration_type); |
| 2904 | } |
| 2905 | break; |
| 2906 | case DW_TAG_const_type: |
no test coverage detected