1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-25 07:49:18 +00:00

libdwarf: Add some constants from DWARF 5

This is not exhaustive - DWARF 5 has some new enumeration types not
implemented here - but I think I caught all the ones that are extended
in DWARF 5, plus the new compilation unit type (DW_UT_*), needed when
parsing .debug_info headers.

These were useful when extending libdwarf/ctfconvert/readelf to handle
DWARF generated by gcc 12, which is version 5 by default.

Reviewed by:	emaste
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38273
This commit is contained in:
Mark Johnston 2023-02-07 14:33:27 -05:00
parent 9aff05bb1c
commit 7bb441c866
6 changed files with 263 additions and 2 deletions

View File

@ -100,6 +100,7 @@ global:
dwarf_get_OP_name;
dwarf_get_ORD_name;
dwarf_get_TAG_name;
dwarf_get_UT_name;
dwarf_get_VIRTUALITY_name;
dwarf_get_VIS_name;
dwarf_get_abbrev;

View File

@ -90,6 +90,14 @@
#define DW_TAG_type_unit 0x41
#define DW_TAG_rvalue_reference_type 0x42
#define DW_TAG_template_alias 0x43
#define DW_TAG_coarray_type 0x44
#define DW_TAG_generic_subrange 0x45
#define DW_TAG_dynamic_type 0x46
#define DW_TAG_atomic_type 0x47
#define DW_TAG_call_site 0x48
#define DW_TAG_call_site_parameter 0x49
#define DW_TAG_skeleton_unit 0x4a
#define DW_TAG_immutable_type 0x4b
#define DW_TAG_lo_user 0x4080
#define DW_TAG_hi_user 0xffff
@ -205,6 +213,35 @@
#define DW_AT_const_expr 0x6c
#define DW_AT_enum_class 0x6d
#define DW_AT_linkage_name 0x6e
#define DW_AT_string_length_bit_size 0x6f
#define DW_AT_string_length_byte_size 0x70
#define DW_AT_rank 0x71
#define DW_AT_str_offsets_base 0x72
#define DW_AT_addr_base 0x73
#define DW_AT_rnglists_base 0x74
#define DW_AT_dwo_name 0x76
#define DW_AT_reference 0x77
#define DW_AT_rvalue_reference 0x78
#define DW_AT_macros 0x79
#define DW_AT_call_all_calls 0x7a
#define DW_AT_call_all_source_calls 0x7b
#define DW_AT_call_all_tail_calls 0x7c
#define DW_AT_call_return_pc 0x7d
#define DW_AT_call_value 0x7e
#define DW_AT_call_origin 0x7f
#define DW_AT_call_parameter 0x80
#define DW_AT_call_pc 0x81
#define DW_AT_call_tail_call 0x82
#define DW_AT_call_target 0x83
#define DW_AT_call_target_clobbered 0x84
#define DW_AT_call_data_location 0x85
#define DW_AT_call_data_value 0x86
#define DW_AT_noreturn 0x87
#define DW_AT_alignment 0x88
#define DW_AT_export_symbols 0x89
#define DW_AT_deleted 0x8a
#define DW_AT_defaulted 0x8b
#define DW_AT_loclists_base 0x8c
#define DW_AT_lo_user 0x2000
#define DW_AT_hi_user 0x3fff
@ -292,7 +329,25 @@
#define DW_FORM_sec_offset 0x17
#define DW_FORM_exprloc 0x18
#define DW_FORM_flag_present 0x19
#define DW_FORM_strx 0x1a
#define DW_FORM_addrx 0x1b
#define DW_FORM_ref_sup4 0x1c
#define DW_FORM_strp_sup 0x1d
#define DW_FORM_data16 0x1e
#define DW_FORM_line_strp 0x1f
#define DW_FORM_ref_sig8 0x20
#define DW_FORM_implicit_const 0x21
#define DW_FORM_loclistx 0x22
#define DW_FORM_rnglistx 0x23
#define DW_FORM_ref_sup8 0x24
#define DW_FORM_ref_strx1 0x25
#define DW_FORM_ref_strx2 0x26
#define DW_FORM_ref_strx3 0x27
#define DW_FORM_ref_strx4 0x28
#define DW_FORM_ref_addrx1 0x29
#define DW_FORM_ref_addrx2 0x2a
#define DW_FORM_ref_addrx3 0x2b
#define DW_FORM_ref_addrx4 0x2c
#define DW_FORM_GNU_ref_alt 0x1f20
#define DW_FORM_GNU_strp_alt 0x1f21
@ -450,6 +505,16 @@
#define DW_OP_bit_piece 0x9d
#define DW_OP_implicit_value 0x9e
#define DW_OP_stack_value 0x9f
#define DW_OP_implicit_pointer 0xa0
#define DW_OP_addrx 0xa1
#define DW_OP_constx 0xa2
#define DW_OP_entry_value 0xa3
#define DW_OP_const_type 0xa4
#define DW_OP_regval_type 0xa5
#define DW_OP_deref_type 0xa6
#define DW_OP_xderef_type 0xa7
#define DW_OP_convert 0xa8
#define DW_OP_reinterpret 0xa9
#define DW_OP_lo_user 0xe0
#define DW_OP_hi_user 0xff
@ -483,6 +548,9 @@
#define DW_ATE_signed_fixed 0xd
#define DW_ATE_unsigned_fixed 0xe
#define DW_ATE_decimal_float 0xf
#define DW_ATE_UTF 0x10
#define DW_ATE_UCS 0x11
#define DW_ATE_ASCII 0x12
#define DW_ATE_lo_user 0x80
#define DW_ATE_hi_user 0xff
@ -553,6 +621,8 @@
#define DW_CC_normal 0x01
#define DW_CC_program 0x02
#define DW_CC_nocall 0x03
#define DW_CC_pass_by_reference 0x04
#define DW_CC_pass_by_value 0x05
#define DW_CC_lo_user 0x40
#define DW_CC_hi_user 0xff
@ -649,4 +719,17 @@
#define DW_EH_PE_aligned 0x50
#define DW_EH_PE_omit 0xff
/*
* Compilation unit types. DWARF5 only.
*/
#define DW_UT_compile 0x01
#define DW_UT_type 0x02
#define DW_UT_partial 0x03
#define DW_UT_skeleton 0x04
#define DW_UT_split_compile 0x05
#define DW_UT_split_type 0x06
#define DW_UT_lo_user 0x80
#define DW_UT_hi_user 0xff
#endif /* !_DWARF_H_ */

View File

@ -250,6 +250,64 @@ dwarf_get_AT_name(unsigned attr, const char **s)
*s = "DW_AT_visibility"; break;
case DW_AT_vtable_elem_location:
*s = "DW_AT_vtable_elem_location"; break;
case DW_AT_string_length_bit_size:
*s = "DW_AT_string_length_bit_size"; break;
case DW_AT_string_length_byte_size:
*s = "DW_AT_string_length_byte_size"; break;
case DW_AT_rank:
*s = "DW_AT_rank"; break;
case DW_AT_str_offsets_base:
*s = "DW_AT_str_offsets_base"; break;
case DW_AT_addr_base:
*s = "DW_AT_addr_base"; break;
case DW_AT_rnglists_base:
*s = "DW_AT_rnglists_base"; break;
case DW_AT_dwo_name:
*s = "DW_AT_dwo_name"; break;
case DW_AT_reference:
*s = "DW_AT_reference"; break;
case DW_AT_rvalue_reference:
*s = "DW_AT_rvalue_reference"; break;
case DW_AT_macros:
*s = "DW_AT_macros"; break;
case DW_AT_call_all_calls:
*s = "DW_AT_call_all_calls"; break;
case DW_AT_call_all_source_calls:
*s = "DW_AT_call_all_source_calls"; break;
case DW_AT_call_all_tail_calls:
*s = "DW_AT_call_all_tail_calls"; break;
case DW_AT_call_return_pc:
*s = "DW_AT_call_return_pc"; break;
case DW_AT_call_value:
*s = "DW_AT_call_value"; break;
case DW_AT_call_origin:
*s = "DW_AT_call_origin"; break;
case DW_AT_call_parameter:
*s = "DW_AT_call_parameter"; break;
case DW_AT_call_pc:
*s = "DW_AT_call_pc"; break;
case DW_AT_call_tail_call:
*s = "DW_AT_call_tail_call"; break;
case DW_AT_call_target:
*s = "DW_AT_call_target"; break;
case DW_AT_call_target_clobbered:
*s = "DW_AT_call_target_clobbered"; break;
case DW_AT_call_data_location:
*s = "DW_AT_call_data_location"; break;
case DW_AT_call_data_value:
*s = "DW_AT_call_data_value"; break;
case DW_AT_noreturn:
*s = "DW_AT_noreturn"; break;
case DW_AT_alignment:
*s = "DW_AT_alignment"; break;
case DW_AT_export_symbols:
*s = "DW_AT_export_symbols"; break;
case DW_AT_deleted:
*s = "DW_AT_deleted"; break;
case DW_AT_defaulted:
*s = "DW_AT_defaulted"; break;
case DW_AT_loclists_base:
*s = "DW_AT_loclists_base"; break;
case DW_AT_sf_names:
*s = "DW_AT_sf_names"; break;
case DW_AT_src_info:
@ -371,7 +429,7 @@ dwarf_get_ATE_name(unsigned ate, const char **s)
assert(s != NULL);
switch(ate) {
switch (ate) {
case DW_ATE_address:
*s = "DW_ATE_address"; break;
case DW_ATE_boolean:
@ -402,6 +460,12 @@ dwarf_get_ATE_name(unsigned ate, const char **s)
*s = "DW_ATE_unsigned_fixed"; break;
case DW_ATE_decimal_float:
*s = "DW_ATE_decimal_float"; break;
case DW_ATE_UTF:
*s = "DW_ATE_UTF"; break;
case DW_ATE_UCS:
*s = "DW_ATE_UCS"; break;
case DW_ATE_ASCII:
*s = "DW_ATE_ASCII"; break;
case DW_ATE_lo_user:
*s = "DW_ATE_lo_user"; break;
case DW_ATE_hi_user:
@ -426,6 +490,10 @@ dwarf_get_CC_name(unsigned cc, const char **s)
*s = "DW_CC_program"; break;
case DW_CC_nocall:
*s = "DW_CC_nocall"; break;
case DW_CC_pass_by_reference:
*s = "DW_CC_pass_by_reference"; break;
case DW_CC_pass_by_value:
*s = "DW_CC_pass_by_value"; break;
case DW_CC_lo_user:
*s = "DW_CC_lo_user"; break;
case DW_CC_hi_user:
@ -582,6 +650,42 @@ dwarf_get_FORM_name(unsigned form, const char **s)
*s = "DW_FORM_strp"; break;
case DW_FORM_udata:
*s = "DW_FORM_udata"; break;
case DW_FORM_strx:
*s = "DW_FORM_strx"; break;
case DW_FORM_addrx:
*s = "DW_FORM_addrx"; break;
case DW_FORM_ref_sup4:
*s = "DW_FORM_ref_sup4"; break;
case DW_FORM_strp_sup:
*s = "DW_FORM_strp_sup"; break;
case DW_FORM_data16:
*s = "DW_FORM_data16"; break;
case DW_FORM_line_strp:
*s = "DW_FORM_line_strp"; break;
case DW_FORM_implicit_const:
*s = "DW_FORM_implicit_const"; break;
case DW_FORM_loclistx:
*s = "DW_FORM_loclistx"; break;
case DW_FORM_rnglistx:
*s = "DW_FORM_rnglistx"; break;
case DW_FORM_ref_sup8:
*s = "DW_FORM_ref_sup8"; break;
case DW_FORM_ref_strx1:
*s = "DW_FORM_ref_strx1"; break;
case DW_FORM_ref_strx2:
*s = "DW_FORM_ref_strx2"; break;
case DW_FORM_ref_strx3:
*s = "DW_FORM_ref_strx3"; break;
case DW_FORM_ref_strx4:
*s = "DW_FORM_ref_strx4"; break;
case DW_FORM_ref_addrx1:
*s = "DW_FORM_ref_addrx1"; break;
case DW_FORM_ref_addrx2:
*s = "DW_FORM_ref_addrx2"; break;
case DW_FORM_ref_addrx3:
*s = "DW_FORM_ref_addrx3"; break;
case DW_FORM_ref_addrx4:
*s = "DW_FORM_ref_addrx4"; break;
default:
return (DW_DLV_NO_ENTRY);
}
@ -1238,6 +1342,26 @@ dwarf_get_OP_name(unsigned op, const char **s)
*s = "DW_OP_implicit_value"; break;
case DW_OP_stack_value:
*s = "DW_OP_stack_value"; break;
case DW_OP_implicit_pointer:
*s = "DW_OP_implicit_pointer"; break;
case DW_OP_addrx:
*s = "DW_OP_addrx"; break;
case DW_OP_constx:
*s = "DW_OP_constx"; break;
case DW_OP_entry_value:
*s = "DW_OP_entry_value"; break;
case DW_OP_const_type:
*s = "DW_OP_const_type"; break;
case DW_OP_regval_type:
*s = "DW_OP_regval_type"; break;
case DW_OP_deref_type:
*s = "DW_OP_deref_type"; break;
case DW_OP_xderef_type:
*s = "DW_OP_xderef_type"; break;
case DW_OP_convert:
*s = "DW_OP_convert"; break;
case DW_OP_reinterpret:
*s = "DW_OP_reinterpret"; break;
case DW_OP_GNU_push_tls_address:
*s = "DW_OP_GNU_push_tls_address"; break;
case DW_OP_GNU_uninit:
@ -1414,6 +1538,22 @@ dwarf_get_TAG_name(unsigned tag, const char **s)
*s = "DW_TAG_volatile_type"; break;
case DW_TAG_with_stmt:
*s = "DW_TAG_with_stmt"; break;
case DW_TAG_coarray_type:
*s = "DW_TAG_coarray_type"; break;
case DW_TAG_generic_subrange:
*s = "DW_TAG_generic_subrange"; break;
case DW_TAG_dynamic_type:
*s = "DW_TAG_dynamic_type"; break;
case DW_TAG_atomic_type:
*s = "DW_TAG_atomic_type"; break;
case DW_TAG_call_site:
*s = "DW_TAG_call_site"; break;
case DW_TAG_call_site_parameter:
*s = "DW_TAG_call_site_parameter"; break;
case DW_TAG_skeleton_unit:
*s = "DW_TAG_skeleton_unit"; break;
case DW_TAG_immutable_type:
*s = "DW_TAG_immutable_type"; break;
case DW_TAG_format_label:
*s = "DW_TAG_format_label"; break;
case DW_TAG_function_template:
@ -1441,6 +1581,32 @@ dwarf_get_TAG_name(unsigned tag, const char **s)
return (DW_DLV_OK);
}
int
dwarf_get_UT_name(unsigned unit_type, const char **s)
{
assert(s != NULL);
switch (unit_type) {
case DW_UT_compile:
*s = "DW_UT_compile"; break;
case DW_UT_type:
*s = "DW_UT_type"; break;
case DW_UT_partial:
*s = "DW_UT_partial"; break;
case DW_UT_skeleton:
*s = "DW_UT_skeleton"; break;
case DW_UT_split_compile:
*s = "DW_UT_split_compile"; break;
case DW_UT_split_type:
*s = "DW_UT_split_type"; break;
default:
return (DW_DLV_NO_ENTRY);
}
return (DW_DLV_OK);
}
int
dwarf_get_VIRTUALITY_name(unsigned vir, const char **s)
{

View File

@ -24,7 +24,7 @@
.\"
.\" $Id: dwarf_get_AT_name.3 3644 2018-10-15 19:55:01Z jkoshy $
.\"
.Dd April 22, 2011
.Dd January 30, 2023
.Dt DWARF_GET_AT_NAME 3
.Os
.Sh NAME
@ -48,6 +48,7 @@
.Nm dwarf_get_OP_name ,
.Nm dwarf_get_ORD_name ,
.Nm dwarf_get_TAG_name ,
.Nm dwarf_get_UT_name ,
.Nm dwarf_get_VIRTUALITY_name ,
.Nm dwarf_get_VIS_name
.Nd retrieve the symbolic names of DWARF constants
@ -156,6 +157,11 @@
.Fa "char **str"
.Fc
.Ft int
.Fo dwarf_get_UT_name
.Fa "unsigned unit_type"
.Fa "const char **str"
.Fc
.Ft int
.Fo dwarf_get_VIRTUALITY_name
.Fa "unsigned val"
.Fa "char **str"
@ -241,6 +247,9 @@ constants.
.It Fn dwarf_get_TAG_name
.Dv DW_TAG_*
constants.
.It Fn dwarf_get_UT_name
.Dv DW_UT_*
constants.
.It Fn dwarf_get_VIRTUALITY_name
.Dv DW_VIRTUALITY_*
constants.

View File

@ -600,6 +600,7 @@ int dwarf_get_MACINFO_name(unsigned, const char **);
int dwarf_get_OP_name(unsigned, const char **);
int dwarf_get_ORD_name(unsigned, const char **);
int dwarf_get_TAG_name(unsigned, const char **);
int dwarf_get_UT_name(unsigned, const char **);
int dwarf_get_VIRTUALITY_name(unsigned, const char **);
int dwarf_get_VIS_name(unsigned, const char **);
int dwarf_get_abbrev(Dwarf_Debug, Dwarf_Unsigned, Dwarf_Abbrev *,

View File

@ -281,6 +281,7 @@ MLINKS+= \
dwarf_get_AT_name.3 dwarf_get_OP_name.3 \
dwarf_get_AT_name.3 dwarf_get_ORD_name.3 \
dwarf_get_AT_name.3 dwarf_get_TAG_name.3 \
dwarf_get_AT_name.3 dwarf_get_UT_name.3 \
dwarf_get_AT_name.3 dwarf_get_VIRTUALITY_name.3 \
dwarf_get_AT_name.3 dwarf_get_VIS_name.3 \
dwarf_get_cu_die_offset.3 dwarf_get_arange_cu_header_offset.3 \