--- /dev/null
+#-------------------------------------------------------------------------------\r
+# elftools: dwarf/constants.py\r
+#\r
+# Constants and flags\r
+#\r
+# Eli Bendersky (eliben@gmail.com)\r
+# This code is in the public domain\r
+#-------------------------------------------------------------------------------\r
+\r
+# Inline codes\r
+#\r
+DW_INL_not_inlined=0\r
+DW_INL_inlined=1\r
+DW_INL_declared_not_inlined=2\r
+DW_INL_declared_inlined=3\r
+\r
+\r
+# Source languages\r
+#\r
+DW_LANG_C89=0x0001\r
+DW_LANG_C=0x0002\r
+DW_LANG_Ada83=0x0003\r
+DW_LANG_C_plus_plus=0x0004\r
+DW_LANG_Cobol74=0x0005\r
+DW_LANG_Cobol85=0x0006\r
+DW_LANG_Fortran77=0x0007\r
+DW_LANG_Fortran90=0x0008\r
+DW_LANG_Pascal83=0x0009\r
+DW_LANG_Modula2=0x000a\r
+DW_LANG_Java=0x000b\r
+DW_LANG_C99=0x000c\r
+DW_LANG_Ada95=0x000d\r
+DW_LANG_Fortran95=0x000e\r
+DW_LANG_PLI=0x000f\r
+DW_LANG_ObjC=0x0010\r
+DW_LANG_ObjC_plus_plus=0x0011\r
+DW_LANG_UPC=0x0012\r
+DW_LANG_D=0x0013\r
+DW_LANG_Python=0x0014\r
+DW_LANG_Mips_Assembler=0x8001\r
+DW_LANG_Upc=0x8765\r
+DW_LANG_HP_Bliss=0x8003\r
+DW_LANG_HP_Basic91=0x8004\r
+DW_LANG_HP_Pascal91=0x8005\r
+DW_LANG_HP_IMacro=0x8006\r
+DW_LANG_HP_Assembler=0x8007\r
+\r
+\r
+# Encoding\r
+#\r
+DW_ATE_void=0x0\r
+DW_ATE_address=0x1\r
+DW_ATE_boolean=0x2\r
+DW_ATE_complex_float=0x3\r
+DW_ATE_float=0x4\r
+DW_ATE_signed=0x5\r
+DW_ATE_signed_char=0x6\r
+DW_ATE_unsigned=0x7\r
+DW_ATE_unsigned_char=0x8\r
+DW_ATE_imaginary_float=0x9\r
+DW_ATE_packed_decimal=0xa\r
+DW_ATE_numeric_string=0xb\r
+DW_ATE_edited=0xc\r
+DW_ATE_signed_fixed=0xd\r
+DW_ATE_unsigned_fixed=0xe\r
+DW_ATE_decimal_float=0xf\r
+DW_ATE_UTF=0x10\r
+DW_ATE_lo_user=0x80\r
+DW_ATE_hi_user=0xff\r
+DW_ATE_HP_float80=0x80\r
+DW_ATE_HP_complex_float80=0x81\r
+DW_ATE_HP_float128=0x82\r
+DW_ATE_HP_complex_float128=0x83\r
+DW_ATE_HP_floathpintel=0x84\r
+DW_ATE_HP_imaginary_float80=0x85\r
+DW_ATE_HP_imaginary_float128=0x86\r
+\r
+\r
#-------------------------------------------------------------------------------\r
from collections import defaultdict\r
\r
+from .constants import *\r
\r
-def describe_attr_value(attr, die, section_offset):\r
- """ Given an AttributeValue extracted, return the textual representation of\r
- its value, suitable for tools like readelf.\r
+\r
+def describe_attr_value(attrname, attr, die, section_offset):\r
+ """ Given an attribute (attrname is the name, attr is the AttributeValue),\r
+ return the textual representation of its value, suitable for tools like\r
+ readelf.\r
\r
To cover all cases, this function needs some extra arguments:\r
\r
section_offset: offset in the stream of the section the DIE belongs to\r
"""\r
descr_func = _ATTR_DESCRIPTION_MAP[attr.form]\r
- return descr_func(attr, die, section_offset)\r
+ val_description = descr_func(attr, die, section_offset)\r
+ \r
+ # For some attributes we can display further information\r
+ extra_info_func = _EXTRA_INFO_DESCRIPTION_MAP[attrname]\r
+ extra_info = extra_info_func(attr, die, section_offset)\r
+ return str(val_description) + '\t' + extra_info \r
\r
\r
#-------------------------------------------------------------------------------\r
def _describe_attr_strp(attr, die, section_offset):
return '(indirect string, offset: 0x%x): %s' % (attr.raw_value, attr.value)\r
\r
+def _describe_attr_debool(attr, die, section_offset):\r
+ """ To be consistent with readelf, generate 1 for True flags, 0 for False\r
+ flags.
+ """\r
+ return '1' if attr.value else '0'\r
+\r
def _describe_attr_block(attr, die, section_offset):
s = '%s byte block: ' % len(attr.value)\r
s += ' '.join('%x' % item for item in attr.value)\r
DW_FORM_data8=_describe_attr_split_64bit,\r
DW_FORM_addr=_describe_attr_hex,\r
DW_FORM_sec_offset=_describe_attr_hex,\r
- DW_FORM_flag_present=_describe_attr_value_passthrough,\r
- DW_FORM_flag=_describe_attr_value_passthrough,\r
+ DW_FORM_flag=_describe_attr_debool,\r
DW_FORM_data1=_describe_attr_value_passthrough,\r
DW_FORM_data2=_describe_attr_value_passthrough,\r
DW_FORM_sdata=_describe_attr_value_passthrough,\r
DW_FORM_block=_describe_attr_block,\r
)\r
\r
+\r
+\r
+def _describe_empty(attr, die, section_offset):
+ return ''\r
+\r
+def _describe_dw_inl_extra(attr, die, section_offset):
+ return _DESCR_DW_INL.get(\r
+ attr.value,\r
+ ' (Unknown inline attribute value: %x)' % attr.value)\r
+\r
+def _describe_dw_lang_extra(attr, die, section_offset):\r
+ return _DESCR_DW_LANG.get(\r
+ attr.value,\r
+ ' (Unknown: %x)' % attr.value)\r
+\r
+def _describe_dw_ate_extra(attr, die, section_offset):
+ return _DESCR_DW_ATE.get(\r
+ attr.value,\r
+ ' (unknown type)')\r
+\r
+\r
+_EXTRA_INFO_DESCRIPTION_MAP = defaultdict(\r
+ lambda: _describe_empty, # default_factory\r
+ \r
+ DW_AT_inline=_describe_dw_inl_extra,\r
+ DW_AT_language=_describe_dw_lang_extra,\r
+ DW_AT_encoding=_describe_dw_ate_extra,\r
+)\r
+\r
+\r
+_DESCR_DW_INL = {\r
+ DW_INL_not_inlined: '(not inlined)',\r
+ DW_INL_inlined: '(inlined)',\r
+ DW_INL_declared_not_inlined: '(declared as inline but ignored)',\r
+ DW_INL_declared_inlined: '(declared as inline and inlined)',\r
+}\r
+\r
+_DESCR_DW_LANG = {\r
+ DW_LANG_C89: '(ANSI C)',\r
+ DW_LANG_C: '(non-ANSI C)',\r
+ DW_LANG_Ada83: '(Ada)',\r
+ DW_LANG_C_plus_plus: '(C++)',\r
+ DW_LANG_Cobol74: '(Cobol 74)',\r
+ DW_LANG_Cobol85: '(Cobol 85)',\r
+ DW_LANG_Fortran77: '(FORTRAN 77)',\r
+ DW_LANG_Fortran90: '(Fortran 90)',\r
+ DW_LANG_Pascal83: '(ANSI Pascal)',\r
+ DW_LANG_Modula2: '(Modula 2)',\r
+ DW_LANG_Java: '(Java)',\r
+ DW_LANG_C99: '(ANSI C99)',\r
+ DW_LANG_Ada95: '(ADA 95)',\r
+ DW_LANG_Fortran95: '(Fortran 95)',\r
+ DW_LANG_PLI: '(PLI)',\r
+ DW_LANG_ObjC: '(Objective C)',\r
+ DW_LANG_ObjC_plus_plus: '(Objective C++)',\r
+ DW_LANG_UPC: '(Unified Parallel C)',\r
+ DW_LANG_D: '(D)',\r
+ DW_LANG_Python: '(Python)',\r
+ DW_LANG_Mips_Assembler: '(MIPS assembler)',\r
+ DW_LANG_Upc: '(nified Parallel C)',\r
+ DW_LANG_HP_Bliss: '(HP Bliss)',\r
+ DW_LANG_HP_Basic91: '(HP Basic 91)',\r
+ DW_LANG_HP_Pascal91: '(HP Pascal 91)',\r
+ DW_LANG_HP_IMacro: '(HP IMacro)',\r
+ DW_LANG_HP_Assembler: '(HP assembler)',\r
+}\r
+\r
+_DESCR_DW_ATE = {\r
+ DW_ATE_void: '(void)',\r
+ DW_ATE_address: '(machine address)',\r
+ DW_ATE_boolean: '(boolean)',\r
+ DW_ATE_complex_float: '(complex float)',\r
+ DW_ATE_float: '(float)',\r
+ DW_ATE_signed: '(signed)',\r
+ DW_ATE_signed_char: '(signed char)',\r
+ DW_ATE_unsigned: '(unsigned)',\r
+ DW_ATE_unsigned_char: '(unsigned char)',\r
+ DW_ATE_imaginary_float: '(imaginary float)',\r
+ DW_ATE_decimal_float: '(decimal float)',\r
+ DW_ATE_packed_decimal: '(packed_decimal)',\r
+ DW_ATE_numeric_string: '(numeric_string)',\r
+ DW_ATE_edited: '(edited)',\r
+ DW_ATE_signed_fixed: '(signed_fixed)',\r
+ DW_ATE_unsigned_fixed: '(unsigned_fixed)',\r
+ DW_ATE_HP_float80: '(HP_float80)',\r
+ DW_ATE_HP_complex_float80: '(HP_complex_float80)',\r
+ DW_ATE_HP_float128: '(HP_float128)',\r
+ DW_ATE_HP_complex_float128: '(HP_complex_float128)',\r
+ DW_ATE_HP_floathpintel: '(HP_floathpintel)',\r
+ DW_ATE_HP_imaginary_float80: '(HP_imaginary_float80)',\r
+ DW_ATE_HP_imaginary_float128: '(HP_imaginary_float128)',\r
+}\r
+\r