--- readelf.c.org Fri Oct 25 15:46:31 2002 +++ readelf.c Tue Jan 20 13:19:32 2004 @@ -1,3 +1,8 @@ +/* +#define __PTRDIFF_TYPE__ int +#define __SIZE_TYPE__ unsigned int +typedef void* __builtin_va_list ; +*/ /* readelf.c -- display contents of an ELF format file Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. @@ -21,12 +26,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define DWARF2_XML +/* +#undef DWARF2_XML + */ +#ifdef DWARF2_XML +#undef DWARF2_XML +#define DWARF2_XML 1 +#else +#define DWARF2_XML 0 +#endif /* DWARF2_XML */ #include #include #include #include #include +#if DWARF2_XML +#include +#include +#endif /* DWARF2_XML */ #if __GNUC__ >= 2 /* Define BFD64 here, even if our default architecture is 32 bit ELF @@ -132,6 +151,9 @@ int do_debug_macinfo; int do_debug_str; int do_debug_loc; +#if DWARF2_XML +int do_debug_xml; +#endif /* DWARF2_XML */ int do_arch; int do_notes; int is_32bit_elf; @@ -266,6 +288,26 @@ static int process_arch_specific PARAMS ((FILE *)); static int process_gnu_liblist PARAMS ((FILE *)); +#if DWARF2_XML +static int xml_indent = 0; +#define MAX_TAG_STACK_DEPTH 1024 +static unsigned long tag_stack [MAX_TAG_STACK_DEPTH]; +static int tag_stack_index = 0; + +static void printf_xml_sub (int indent, int newline, char *fmt, va_list pvar); +static void printf_xml (char *fmt, ...); +static void printf_xml_raw (int indent, int newline, char *fmt, ...); +static void printf_xml_begin (char *fmt, ...); +static void printf_xml_end (char *fmt, ...); +static void printf_xml_line (void); +static void printf_xml_desc (char *fmt); +static void printf_xml_desc2 (char *fmt, ...); +static void push_tag (unsigned long tag); +static unsigned long pop_tag (void); +static char *escape_entity_ref (const char *s); +static int is_offset (unsigned long attribute, unsigned long form); +#endif /* DWARF2_XML */ + typedef int Elf32_Word; #ifndef TRUE @@ -318,7 +360,6 @@ (is_32bit_elf ? get_32bit_elf_symbols (file, section) \ : get_64bit_elf_symbols (file, section)) - static void error VPARAMS ((const char *message, ...)) { @@ -2271,6 +2312,9 @@ {"version", no_argument, 0, 'v'}, {"wide", no_argument, 0, 'W'}, {"help", no_argument, 0, 'H'}, +#if DWARF2_XML + {"xml", no_argument, 0, 'X'}, +#endif /* DWARF2_XML */ {0, no_argument, 0, 0} }; @@ -2305,11 +2349,20 @@ -i --instruction-dump=\n\ Disassemble the contents of section \n")); #endif +#if DWARF2_XML + fprintf (stdout, _("\ + -I --histogram Display histogram of bucket list lengths\n\ + -W --wide Allow output width to exceed 80 characters\n\ + -X --xml Display DWARF2 debug sections in XML. Use with '-w'\n\ + -H --help Display this information\n\ + -v --version Display the version number of readelf\n")); +#else /* DWARF2_XML */ fprintf (stdout, _("\ -I --histogram Display histogram of bucket list lengths\n\ -W --wide Allow output width to exceed 80 characters\n\ -H --help Display this information\n\ -v --version Display the version number of readelf\n")); +#endif /* DWARF2_XML */ fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); exit (0); @@ -2357,7 +2410,11 @@ usage (); while ((c = getopt_long +#if DWARF2_XML + (argc, argv, "ersuahnldSDAIw::x:i:vVWX", options, NULL)) != EOF) +#else /* DWARF2_XML */ (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF) +#endif /* DWARF2_XML */ { char * cp; int section; @@ -2598,6 +2655,16 @@ case 'W': do_wide ++; break; +#if DWARF2_XML + case 'X': + do_debug_xml = 1; + if (!do_debugging) { + /* -X implies -w */ + do_dump ++; + do_debugging = 1; + } + break; +#endif /* DWARF2_XML */ default: oops: /* xgettext:c-format */ @@ -6135,22 +6202,61 @@ len += bytes_read; op_code = * data ++; +#if DWARF2_XML + if (!do_debug_xml) + printf (_(" Extended opcode %d: "), op_code); +#else printf (_(" Extended opcode %d: "), op_code); +#endif /* DWARF2_XML */ switch (op_code) { case DW_LNE_end_sequence: +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_("End of Sequence\n\n")); + } +#else printf (_("End of Sequence\n\n")); +#endif /* DWARF2_XML */ reset_state_machine (is_stmt); break; case DW_LNE_set_address: adr = byte_get (data, pointer_size); +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_("set Address to 0x%lx\n"), adr); + } +#else printf (_("set Address to 0x%lx\n"), adr); +#endif /* DWARF2_XML */ state_machine_regs.address = adr; break; case DW_LNE_define_file: +#if DWARF2_XML + if (do_debug_xml) { + state_machine_regs.last_file_entry++; + } else { + printf (_(" define new File Table entry\n")); + printf (_(" Entry\tDir\tTime\tSize\tName\n")); + + printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); + name = data; + data += strlen ((char *) data) + 1; + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + data += bytes_read; + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + data += bytes_read; + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + printf (_("%s\n\n"), name); + } +#else printf (_(" define new File Table entry\n")); printf (_(" Entry\tDir\tTime\tSize\tName\n")); @@ -6163,6 +6269,7 @@ data += bytes_read; printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); printf (_("%s\n\n"), name); +#endif /* DWARF2_XML */ break; default: @@ -6192,11 +6299,23 @@ unsigned char * end_of_sequence; int i; +#if DWARF2_XML + if (do_debug_xml) + printf_xml_begin ("
", SECTION_NAME (section)); + else + printf (_("\nDump of debug contents of section %s:\n\n"), + SECTION_NAME (section)); +#else printf (_("\nDump of debug contents of section %s:\n\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ while (data < end) { +#if DWARF2_XML + unsigned long offset = data - start; +#endif + external = (DWARF2_External_LineInfo *) data; /* Check the length of the block. */ @@ -6234,6 +6353,20 @@ info.li_line_base <<= 24; info.li_line_base >>= 24; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", offset); + } else { + printf (_(" Length: %ld\n"), info.li_length); + printf (_(" DWARF Version: %d\n"), info.li_version); + printf (_(" Prologue Length: %d\n"), info.li_prologue_length); + printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length); + printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt); + printf (_(" Line Base: %d\n"), info.li_line_base); + printf (_(" Line Range: %d\n"), info.li_line_range); + printf (_(" Opcode Base: %d\n"), info.li_opcode_base); + } +#else printf (_(" Length: %ld\n"), info.li_length); printf (_(" DWARF Version: %d\n"), info.li_version); printf (_(" Prologue Length: %d\n"), info.li_prologue_length); @@ -6242,6 +6375,7 @@ printf (_(" Line Base: %d\n"), info.li_line_base); printf (_(" Line Range: %d\n"), info.li_line_range); printf (_(" Opcode Base: %d\n"), info.li_opcode_base); +#endif /* DWARF2_XML */ end_of_sequence = data + info.li_length + sizeof (external->li_length); @@ -6250,14 +6384,54 @@ /* Display the contents of the Opcodes table. */ standard_opcodes = data + sizeof (* external); +#if DWARF2_XML + if (!do_debug_xml) { + printf (_("\n Opcodes:\n")); + + for (i = 1; i < info.li_opcode_base; i++) + printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); + } +#else printf (_("\n Opcodes:\n")); for (i = 1; i < info.li_opcode_base; i++) printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); +#endif /* DWARF2_XML */ /* Display the contents of the Directory table. */ data = standard_opcodes + info.li_opcode_base - 1; +#if DWARF2_XML + if (do_debug_xml) { + if (* data != 0) + { + int i = 1; + printf_xml_begin (""); + while (* data != 0) + { + printf_xml ("%s", + i++, data); + + data += strlen ((char *) data) + 1; + } + printf_xml_end (""); + } + } else { + if (* data == 0) + printf (_("\n The Directory Table is empty.\n")); + else + { + printf (_("\n The Directory Table:\n")); + + while (* data != 0) + { + printf (_(" %s\n"), data); + + data += strlen ((char *) data) + 1; + } + } + } +#else if (* data == 0) printf (_("\n The Directory Table is empty.\n")); else @@ -6271,11 +6445,64 @@ data += strlen ((char *) data) + 1; } } +#endif /* DWARF2_XML */ /* Skip the NUL at the end of the table. */ data ++; /* Display the contents of the File Name table. */ +#if DWARF2_XML + if (* data != 0) + { + if (do_debug_xml) { + int file_index = 1; + printf_xml_begin (""); + printf_xml (""); + while (* data != 0) + { + unsigned char * name; + int bytes_read; + unsigned long index, time, size; + + state_machine_regs.last_file_entry ++; + name = data; + data += strlen ((char *) data) + 1; + index = read_leb128 (data, & bytes_read, 0); + data += bytes_read; + time = read_leb128 (data, & bytes_read, 0); + data += bytes_read; + size = read_leb128 (data, & bytes_read, 0); + data += bytes_read; + printf_xml ("%s", + file_index++, index, time, size, name); + } + printf_xml_end (""); + } else { + printf (_("\n The File Name Table:\n")); + printf (_(" Entry\tDir\tTime\tSize\tName\n")); + + while (* data != 0) + { + unsigned char * name; + int bytes_read; + + printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); + name = data; + + data += strlen ((char *) data) + 1; + + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + data += bytes_read; + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + data += bytes_read; + printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); + data += bytes_read; + printf (_("%s\n"), name); + } + } + } +#else if (* data == 0) printf (_("\n The File Name Table is empty.\n")); else @@ -6302,12 +6529,21 @@ printf (_("%s\n"), name); } } +#endif /* DWARF2_XML */ /* Skip the NUL at the end of the table. */ data ++; /* Now display the statements. */ +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin (""); + } else { + printf (_("\n Line Number Statements:\n")); + } +#else printf (_("\n Line Number Statements:\n")); +#endif /* DWARF2_XML */ while (data < end_of_sequence) @@ -6323,12 +6559,30 @@ op_code -= info.li_opcode_base; adv = (op_code / info.li_line_range) * info.li_min_insn_length; state_machine_regs.address += adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else{ + printf (_(" Special opcode %d: advance Address by %d to 0x%lx"), + op_code, adv, state_machine_regs.address); + } +#else printf (_(" Special opcode %d: advance Address by %d to 0x%lx"), op_code, adv, state_machine_regs.address); +#endif /* DWARF2_XML */ adv = (op_code % info.li_line_range) + info.li_line_base; state_machine_regs.line += adv; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_line (); + } else { + printf (_(" and Line by %d to %d\n"), + adv, state_machine_regs.line); + } +#else printf (_(" and Line by %d to %d\n"), adv, state_machine_regs.line); +#endif /* DWARF2_XML */ } else switch (op_code) { @@ -6338,49 +6592,107 @@ break; case DW_LNS_copy: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_line (); + } else { + printf (_(" Copy\n")); + } +#else printf (_(" Copy\n")); +#endif /* DWARF2_XML */ break; case DW_LNS_advance_pc: adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0); data += bytes_read; state_machine_regs.address += adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Advance PC by %d to %lx\n"), adv, + state_machine_regs.address); + } +#else printf (_(" Advance PC by %d to %lx\n"), adv, state_machine_regs.address); +#endif /* DWARF2_XML */ break; case DW_LNS_advance_line: adv = read_leb128 (data, & bytes_read, 1); data += bytes_read; state_machine_regs.line += adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Advance Line by %d to %d\n"), adv, + state_machine_regs.line); + } +#else printf (_(" Advance Line by %d to %d\n"), adv, state_machine_regs.line); +#endif /* DWARF2_XML */ break; case DW_LNS_set_file: adv = read_leb128 (data, & bytes_read, 0); data += bytes_read; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set File Name to entry %d in the File Name Table\n"), adv); + } +#else printf (_(" Set File Name to entry %d in the File Name Table\n"), adv); +#endif /* DWARF2_XML */ state_machine_regs.file = adv; break; case DW_LNS_set_column: adv = read_leb128 (data, & bytes_read, 0); data += bytes_read; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set column to %d\n"), adv); + } +#else printf (_(" Set column to %d\n"), adv); +#endif /* DWARF2_XML */ state_machine_regs.column = adv; break; case DW_LNS_negate_stmt: adv = state_machine_regs.is_stmt; adv = ! adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set is_stmt to %d\n"), adv); + } +#else printf (_(" Set is_stmt to %d\n"), adv); +#endif /* DWARF2_XML */ state_machine_regs.is_stmt = adv; break; case DW_LNS_set_basic_block: +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set basic block\n")); + } +#else printf (_(" Set basic block\n")); +#endif /* DWARF2_XML */ state_machine_regs.basic_block = 1; break; @@ -6388,30 +6700,72 @@ adv = (((255 - info.li_opcode_base) / info.li_line_range) * info.li_min_insn_length); state_machine_regs.address += adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Advance PC by constant %d to 0x%lx\n"), adv, + state_machine_regs.address); + } +#else printf (_(" Advance PC by constant %d to 0x%lx\n"), adv, state_machine_regs.address); +#endif /* DWARF2_XML */ break; case DW_LNS_fixed_advance_pc: adv = byte_get (data, 2); data += 2; state_machine_regs.address += adv; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"), + adv, state_machine_regs.address); + } +#else printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"), adv, state_machine_regs.address); +#endif /* DWARF2_XML */ break; case DW_LNS_set_prologue_end: +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set prologue_end to true\n")); + } +#else printf (_(" Set prologue_end to true\n")); +#endif /* DWARF2_XML */ break; case DW_LNS_set_epilogue_begin: +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set epilogue_begin to true\n")); + } +#else printf (_(" Set epilogue_begin to true\n")); +#endif /* DWARF2_XML */ break; case DW_LNS_set_isa: adv = read_leb128 (data, & bytes_read, 0); data += bytes_read; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Set ISA to %d\n"), adv); + } +#else printf (_(" Set ISA to %d\n"), adv); +#endif /* DWARF2_XML */ break; default: @@ -6429,9 +6783,21 @@ break; } } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end (""); + } else { + putchar ('\n'); + } +#else putchar ('\n'); +#endif /* DWARF2_XML */ } +#if DWARF2_XML + if (do_debug_xml) + printf_xml_end ("
"); +#endif /* DWARF2_XML */ return 1; } @@ -6447,7 +6813,15 @@ end = start + section->sh_size; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); + } +#else printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ while (start < end) { @@ -6483,6 +6857,20 @@ continue; } +#if DWARF2_XML + if (!do_debug_xml) { + printf (_(" Length: %ld\n"), + pubnames.pn_length); + printf (_(" Version: %d\n"), + pubnames.pn_version); + printf (_(" Offset into .debug_info section: %ld\n"), + pubnames.pn_offset); + printf (_(" Size of area in .debug_info section: %ld\n"), + pubnames.pn_size); + + printf (_("\n Offset\tName\n")); + } +#else printf (_(" Length: %ld\n"), pubnames.pn_length); printf (_(" Version: %d\n"), @@ -6493,6 +6881,7 @@ pubnames.pn_size); printf (_("\n Offset\tName\n")); +#endif /* DWARF2_XML */ do { @@ -6501,14 +6890,31 @@ if (offset != 0) { data += 4; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + offset + pubnames.pn_offset, data); + } else { + printf (" %ld\t\t%s\n", offset, data); + } +#else printf (" %ld\t\t%s\n", offset, data); +#endif /* DWARF2_XML */ data += strlen ((char *) data) + 1; } } while (offset != 0); } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end ("
"); + } else { + printf ("\n"); + } +#else printf ("\n"); +#endif /* DWARF2_XML */ return 1; } @@ -6909,12 +7315,23 @@ unsigned int bytes_read; enum dwarf_macinfo_record_type op; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); + } +#else printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); +#endif while (curr < end) { unsigned int lineno; const char * string; +#if DWARF2_XML + unsigned long offset = curr - start; +#endif op = * curr; curr ++; @@ -6930,12 +7347,30 @@ filenum = read_leb128 (curr, & bytes_read, 0); curr += bytes_read; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + lineno, filenum, offset); + } else { + printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum); + } +#else printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum); +#endif } break; case DW_MACINFO_end_file: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml (""); + } else { + printf (_(" DW_MACINFO_end_file\n")); + } +#else printf (_(" DW_MACINFO_end_file\n")); +#endif break; case DW_MACINFO_define: @@ -6943,7 +7378,66 @@ curr += bytes_read; string = curr; curr += strlen (string) + 1; +#if DWARF2_XML + if (do_debug_xml) { + int is_define_normal = 1; + char *name = strdup (string); + char *p = (char *)string; + char *body; + while (*p != ' ') { + if (*p == '(') { + is_define_normal = 0; + break; + } + p++; + } + + if (is_define_normal) { /* define_normal */ + p = strchr (name, ' '); + assert (p != NULL); + *p = '\0'; + body = p + 1; + body = escape_entity_ref (body); + printf_xml ("", + lineno, name, name, body); + } else { /* define_func */ + char *signature = strdup (string); + char *args; + p = strchr (signature, ' '); + assert (p != NULL); + *p = '\0'; + body = p + 1; + body = escape_entity_ref (body); + + p = strchr (name, '('); + assert (p != NULL); + *p = '\0'; + args = p + 1; + + printf_xml_begin ("", + lineno, name, signature, body); + while (1) { + while (*p != ',' && *p != ')') + p++; + *p = '\0'; + if (*args != '\0') + printf_xml ("", args); + args = p + 1; + if (*args == ' ') + break; + } + printf_xml_end (""); + free (signature); + } + free (name); + } else { + printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string); + } +#else printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string); +#endif break; case DW_MACINFO_undef: @@ -6951,7 +7445,16 @@ curr += bytes_read; string = curr; curr += strlen (string) + 1; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + lineno, string); + } else { + printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string); + } +#else printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string); +#endif break; case DW_MACINFO_vendor_ext: @@ -6962,12 +7465,27 @@ curr += bytes_read; string = curr; curr += strlen (string) + 1; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + constant, string); + } else { + printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string); + } +#else printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string); +#endif } break; } } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end ("
"); + } +#endif /* DWARF2_XML */ + return 1; } @@ -6981,7 +7499,15 @@ abbrev_entry * entry; unsigned char * end = start + section->sh_size; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); + } +#else printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ do { @@ -6990,30 +7516,78 @@ if (first_abbrev == NULL) continue; +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Number TAG\n")); + } +#else printf (_(" Number TAG\n")); +#endif /* DWARF2_XML */ for (entry = first_abbrev; entry; entry = entry->next) { abbrev_attr * attr; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("", + entry->entry, get_TAG_name (entry->tag), + (entry->children ? "true" : "false")); + + } else { + printf (_(" %ld %s [%s]\n"), + entry->entry, get_TAG_name (entry->tag), + entry->children ? _("has children") : _("no children")); + } +#else printf (_(" %ld %s [%s]\n"), entry->entry, get_TAG_name (entry->tag), entry->children ? _("has children") : _("no children")); +#endif /* DWARF2_XML */ for (attr = entry->first_attr; attr; attr = attr->next) { +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + get_AT_name (attr->attribute), + get_FORM_name (attr->form)); + } else { + printf (_(" %-18s %s\n"), + get_AT_name (attr->attribute), + get_FORM_name (attr->form)); + } +#else printf (_(" %-18s %s\n"), get_AT_name (attr->attribute), get_FORM_name (attr->form)); +#endif /* DWARF2_XML */ } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end (""); + } +#else +#endif /* DWARF2_XML */ } free_abbrevs (); } while (start); +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end ("
"); + } else { + printf ("\n"); + } +#else printf ("\n"); +#endif /* DWARF2_XML */ return 1; } @@ -7024,10 +7598,23 @@ unsigned char * data; unsigned long length; { +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%lu:", length); + while (length --) + printf_xml_raw (0, 0, " %#lx", (unsigned long) byte_get (data ++, 1)); + printf_xml_raw (0, 0, "\""); + } else { + printf (_(" %lu byte block: "), length); + while (length --) + printf ("%lx ", (unsigned long) byte_get (data ++, 1)); + } +#else printf (_(" %lu byte block: "), length); while (length --) printf ("%lx ", (unsigned long) byte_get (data ++, 1)); +#endif /* DWARF2_XML */ return data; } @@ -7047,6 +7634,517 @@ { op = * data ++; +#if DWARF2_XML + if (do_debug_xml) { + switch (op) { + case DW_OP_addr: + /* xxx */ + printf_xml_desc2 ("DW_OP_addr: %lu", + (unsigned long) byte_get (data, pointer_size)); + data += pointer_size; + break; + case DW_OP_deref: printf_xml_desc ("DW_OP_deref"); break; + case DW_OP_const1u: + printf_xml_desc2 ("DW_OP_const1u: %lu", + (unsigned long) byte_get (data++, 1)); + break; + case DW_OP_const1s: + printf_xml_desc2 ("DW_OP_const1s: %ld", + (long) byte_get (data++, 1)); + break; + case DW_OP_const2u: + printf_xml_desc2 ("DW_OP_const2u: %lu", + (unsigned long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_const2s: + printf_xml_desc2 ("DW_OP_const2s: %ld", + (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_const4u: + printf_xml_desc2 ("DW_OP_const4u: %lu", + (unsigned long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_const4s: + printf_xml_desc2 ("DW_OP_const4s: %ld", + (long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_const8u: + printf_xml_desc2 ("DW_OP_const8u: %lu %lu", + (unsigned long) byte_get (data, 4), + (unsigned long) byte_get (data + 4, 4)); + data += 8; + break; + case DW_OP_const8s: + printf_xml_desc2 ("DW_OP_const8s: %ld %ld", + (long) byte_get (data, 4), + (long) byte_get (data + 4, 4)); + data += 8; + break; + case DW_OP_constu: + printf_xml_desc2 ("DW_OP_constu: %lu", + read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_consts: + printf_xml_desc2 ("DW_OP_consts: %ld", + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_dup: printf_xml_desc ("DW_OP_dup"); break; + case DW_OP_drop: printf_xml_desc ("DW_OP_drop"); break; + case DW_OP_over: printf_xml_desc ("DW_OP_over"); break; + case DW_OP_pick: + printf_xml_desc2 ("DW_OP_pick: %ld", + (unsigned long) byte_get (data++, 1)); + break; + case DW_OP_swap: printf_xml_desc ("DW_OP_swap"); break; + case DW_OP_rot: printf_xml_desc ("DW_OP_rot"); break; + case DW_OP_xderef: printf_xml_desc ("DW_OP_xderef"); break; + case DW_OP_abs: printf_xml_desc ("DW_OP_abs"); break; + case DW_OP_and: printf_xml_desc ("DW_OP_and"); break; + case DW_OP_div: printf_xml_desc ("DW_OP_div"); break; + case DW_OP_minus: printf_xml_desc ("DW_OP_minus"); break; + case DW_OP_mod: printf_xml_desc ("DW_OP_mod"); break; + case DW_OP_mul: printf_xml_desc ("DW_OP_mul"); break; + case DW_OP_neg: printf_xml_desc ("DW_OP_neg"); break; + case DW_OP_not: printf_xml_desc ("DW_OP_not"); break; + case DW_OP_or: printf_xml_desc ("DW_OP_or"); break; + case DW_OP_plus: printf_xml_desc ("DW_OP_plus"); break; + case DW_OP_plus_uconst: + printf_xml_desc2 ("DW_OP_plus_uconst: %lu", + read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_shl: printf_xml_desc ("DW_OP_shl"); break; + case DW_OP_shr: printf_xml_desc ("DW_OP_shr"); break; + case DW_OP_shra: printf_xml_desc ("DW_OP_shra"); break; + case DW_OP_xor: printf_xml_desc ("DW_OP_xor"); break; + case DW_OP_bra: + printf_xml_desc2 ("DW_OP_bra: %ld", (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_eq: printf_xml_desc ("DW_OP_eq"); break; + case DW_OP_ge: printf_xml_desc ("DW_OP_ge"); break; + case DW_OP_gt: printf_xml_desc ("DW_OP_gt"); break; + case DW_OP_le: printf_xml_desc ("DW_OP_le"); break; + case DW_OP_lt: printf_xml_desc ("DW_OP_lt"); break; + case DW_OP_ne: printf_xml_desc ("DW_OP_ne"); break; + case DW_OP_skip: + printf_xml_desc2 ("DW_OP_skip: %ld", (long) byte_get (data, 2)); + data += 2; + break; + + case DW_OP_lit0: case DW_OP_lit1: case DW_OP_lit2: case DW_OP_lit3: + case DW_OP_lit4: case DW_OP_lit5: case DW_OP_lit6: case DW_OP_lit7: + case DW_OP_lit8: case DW_OP_lit9: case DW_OP_lit10: case DW_OP_lit11: + case DW_OP_lit12: case DW_OP_lit13: case DW_OP_lit14: case DW_OP_lit15: + case DW_OP_lit16: case DW_OP_lit17: case DW_OP_lit18: case DW_OP_lit19: + case DW_OP_lit20: case DW_OP_lit21: case DW_OP_lit22: case DW_OP_lit23: + case DW_OP_lit24: case DW_OP_lit25: case DW_OP_lit26: case DW_OP_lit27: + case DW_OP_lit28: case DW_OP_lit29: case DW_OP_lit30: case DW_OP_lit31: + printf_xml_desc2 ("DW_OP_lit%d", op - DW_OP_lit0); + break; + + case DW_OP_reg0: case DW_OP_reg1: case DW_OP_reg2: case DW_OP_reg3: + case DW_OP_reg4: case DW_OP_reg5: case DW_OP_reg6: case DW_OP_reg7: + case DW_OP_reg8: case DW_OP_reg9: case DW_OP_reg10: case DW_OP_reg11: + case DW_OP_reg12: case DW_OP_reg13: case DW_OP_reg14: case DW_OP_reg15: + case DW_OP_reg16: case DW_OP_reg17: case DW_OP_reg18: case DW_OP_reg19: + case DW_OP_reg20: case DW_OP_reg21: case DW_OP_reg22: case DW_OP_reg23: + case DW_OP_reg24: case DW_OP_reg25: case DW_OP_reg26: case DW_OP_reg27: + case DW_OP_reg28: case DW_OP_reg29: case DW_OP_reg30: case DW_OP_reg31: + printf_xml_desc2 ("DW_OP_reg%d", op - DW_OP_reg0); + break; + + case DW_OP_breg0: case DW_OP_breg1: case DW_OP_breg2: + case DW_OP_breg3: case DW_OP_breg4: case DW_OP_breg5: + case DW_OP_breg6: case DW_OP_breg7: case DW_OP_breg8: + case DW_OP_breg9: case DW_OP_breg10: case DW_OP_breg11: + case DW_OP_breg12: case DW_OP_breg13: case DW_OP_breg14: + case DW_OP_breg15: case DW_OP_breg16: case DW_OP_breg17: + case DW_OP_breg18: case DW_OP_breg19: case DW_OP_breg20: + case DW_OP_breg21: case DW_OP_breg22: case DW_OP_breg23: + case DW_OP_breg24: case DW_OP_breg25: case DW_OP_breg26: + case DW_OP_breg27: case DW_OP_breg28: case DW_OP_breg29: + case DW_OP_breg30: case DW_OP_breg31: + printf_xml_desc2 ("DW_OP_breg%d: %ld", + op - DW_OP_breg0, + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + + case DW_OP_regx: + printf_xml_desc2 ("DW_OP_regx: %lu", + read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_fbreg: + printf_xml_desc2 ("DW_OP_fbreg: %ld", + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_bregx: + uvalue = read_leb128 (data, &bytes_read, 0); + data += bytes_read; + printf_xml_desc2 ("DW_OP_bregx: %lu %ld", + uvalue, + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_piece: + printf_xml_desc2 ("DW_OP_piece: %lu", + read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_deref_size: + printf_xml_desc2 ("DW_OP_deref_size: %ld", + (long) byte_get (data++, 1)); + break; + case DW_OP_xderef_size: + printf_xml_desc2 ("DW_OP_xderef_size: %ld", + (long) byte_get (data++, 1)); + break; + case DW_OP_nop: + printf_xml_desc ("DW_OP_nop"); + break; + + /* DWARF 2.1 extensions. */ + case DW_OP_push_object_address: + printf_xml_desc ("DW_OP_push_object_address"); + break; + case DW_OP_call2: + printf_xml_desc2 ("DW_OP_call2: <%lx>", (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_call4: + printf_xml_desc2 ("DW_OP_call4: <%lx>", (long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_calli: + printf_xml_desc ("DW_OP_calli"); + break; + + default: + if (op >= DW_OP_lo_user && op <= DW_OP_hi_user) + printf_xml_desc ("User defined location op"); + else + printf_xml_desc ("Unknown location op"); + /* No way to tell where the next op is, so just bail. */ + return; + } + } else { /* do_debug_xml */ + switch (op) + { + case DW_OP_addr: + printf ("DW_OP_addr: %lx", + (unsigned long) byte_get (data, pointer_size)); + data += pointer_size; + break; + case DW_OP_deref: + printf ("DW_OP_deref"); + break; + case DW_OP_const1u: + printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1)); + break; + case DW_OP_const1s: + printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1)); + break; + case DW_OP_const2u: + printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_const2s: + printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_const4u: + printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_const4s: + printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_const8u: + printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), + (unsigned long) byte_get (data + 4, 4)); + data += 8; + break; + case DW_OP_const8s: + printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), + (long) byte_get (data + 4, 4)); + data += 8; + break; + case DW_OP_constu: + printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_consts: + printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_dup: + printf ("DW_OP_dup"); + break; + case DW_OP_drop: + printf ("DW_OP_drop"); + break; + case DW_OP_over: + printf ("DW_OP_over"); + break; + case DW_OP_pick: + printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1)); + break; + case DW_OP_swap: + printf ("DW_OP_swap"); + break; + case DW_OP_rot: + printf ("DW_OP_rot"); + break; + case DW_OP_xderef: + printf ("DW_OP_xderef"); + break; + case DW_OP_abs: + printf ("DW_OP_abs"); + break; + case DW_OP_and: + printf ("DW_OP_and"); + break; + case DW_OP_div: + printf ("DW_OP_div"); + break; + case DW_OP_minus: + printf ("DW_OP_minus"); + break; + case DW_OP_mod: + printf ("DW_OP_mod"); + break; + case DW_OP_mul: + printf ("DW_OP_mul"); + break; + case DW_OP_neg: + printf ("DW_OP_neg"); + break; + case DW_OP_not: + printf ("DW_OP_not"); + break; + case DW_OP_or: + printf ("DW_OP_or"); + break; + case DW_OP_plus: + printf ("DW_OP_plus"); + break; + case DW_OP_plus_uconst: + printf ("DW_OP_plus_uconst: %lu", + read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_shl: + printf ("DW_OP_shl"); + break; + case DW_OP_shr: + printf ("DW_OP_shr"); + break; + case DW_OP_shra: + printf ("DW_OP_shra"); + break; + case DW_OP_xor: + printf ("DW_OP_xor"); + break; + case DW_OP_bra: + printf ("DW_OP_bra: %ld", (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_eq: + printf ("DW_OP_eq"); + break; + case DW_OP_ge: + printf ("DW_OP_ge"); + break; + case DW_OP_gt: + printf ("DW_OP_gt"); + break; + case DW_OP_le: + printf ("DW_OP_le"); + break; + case DW_OP_lt: + printf ("DW_OP_lt"); + break; + case DW_OP_ne: + printf ("DW_OP_ne"); + break; + case DW_OP_skip: + printf ("DW_OP_skip: %ld", (long) byte_get (data, 2)); + data += 2; + break; + + case DW_OP_lit0: + case DW_OP_lit1: + case DW_OP_lit2: + case DW_OP_lit3: + case DW_OP_lit4: + case DW_OP_lit5: + case DW_OP_lit6: + case DW_OP_lit7: + case DW_OP_lit8: + case DW_OP_lit9: + case DW_OP_lit10: + case DW_OP_lit11: + case DW_OP_lit12: + case DW_OP_lit13: + case DW_OP_lit14: + case DW_OP_lit15: + case DW_OP_lit16: + case DW_OP_lit17: + case DW_OP_lit18: + case DW_OP_lit19: + case DW_OP_lit20: + case DW_OP_lit21: + case DW_OP_lit22: + case DW_OP_lit23: + case DW_OP_lit24: + case DW_OP_lit25: + case DW_OP_lit26: + case DW_OP_lit27: + case DW_OP_lit28: + case DW_OP_lit29: + case DW_OP_lit30: + case DW_OP_lit31: + printf ("DW_OP_lit%d", op - DW_OP_lit0); + break; + + case DW_OP_reg0: + case DW_OP_reg1: + case DW_OP_reg2: + case DW_OP_reg3: + case DW_OP_reg4: + case DW_OP_reg5: + case DW_OP_reg6: + case DW_OP_reg7: + case DW_OP_reg8: + case DW_OP_reg9: + case DW_OP_reg10: + case DW_OP_reg11: + case DW_OP_reg12: + case DW_OP_reg13: + case DW_OP_reg14: + case DW_OP_reg15: + case DW_OP_reg16: + case DW_OP_reg17: + case DW_OP_reg18: + case DW_OP_reg19: + case DW_OP_reg20: + case DW_OP_reg21: + case DW_OP_reg22: + case DW_OP_reg23: + case DW_OP_reg24: + case DW_OP_reg25: + case DW_OP_reg26: + case DW_OP_reg27: + case DW_OP_reg28: + case DW_OP_reg29: + case DW_OP_reg30: + case DW_OP_reg31: + printf ("DW_OP_reg%d", op - DW_OP_reg0); + break; + + case DW_OP_breg0: + case DW_OP_breg1: + case DW_OP_breg2: + case DW_OP_breg3: + case DW_OP_breg4: + case DW_OP_breg5: + case DW_OP_breg6: + case DW_OP_breg7: + case DW_OP_breg8: + case DW_OP_breg9: + case DW_OP_breg10: + case DW_OP_breg11: + case DW_OP_breg12: + case DW_OP_breg13: + case DW_OP_breg14: + case DW_OP_breg15: + case DW_OP_breg16: + case DW_OP_breg17: + case DW_OP_breg18: + case DW_OP_breg19: + case DW_OP_breg20: + case DW_OP_breg21: + case DW_OP_breg22: + case DW_OP_breg23: + case DW_OP_breg24: + case DW_OP_breg25: + case DW_OP_breg26: + case DW_OP_breg27: + case DW_OP_breg28: + case DW_OP_breg29: + case DW_OP_breg30: + case DW_OP_breg31: + printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0, + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + + case DW_OP_regx: + printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_fbreg: + printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_bregx: + uvalue = read_leb128 (data, &bytes_read, 0); + data += bytes_read; + printf ("DW_OP_bregx: %lu %ld", uvalue, + read_leb128 (data, &bytes_read, 1)); + data += bytes_read; + break; + case DW_OP_piece: + printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0)); + data += bytes_read; + break; + case DW_OP_deref_size: + printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1)); + break; + case DW_OP_xderef_size: + printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1)); + break; + case DW_OP_nop: + printf ("DW_OP_nop"); + break; + + /* DWARF 2.1 extensions. */ + case DW_OP_push_object_address: + printf ("DW_OP_push_object_address"); + break; + case DW_OP_call2: + printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2)); + data += 2; + break; + case DW_OP_call4: + printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4)); + data += 4; + break; + case DW_OP_calli: + printf ("DW_OP_calli"); + break; + + default: + if (op >= DW_OP_lo_user + && op <= DW_OP_hi_user) + printf (_("(User defined location op)")); + else + printf (_("(Unknown location op)")); + /* No way to tell where the next op is, so just bail. */ + return; + } + } +#else /* DWARF2_XML */ switch (op) { case DW_OP_addr: @@ -7353,9 +8451,15 @@ /* No way to tell where the next op is, so just bail. */ return; } +#endif /* DWARF2_XML */ /* Separate the ops. */ +#if DWARF2_XML + if (!do_debug_xml) + printf ("; "); +#else printf ("; "); +#endif /* DWARF2_XML */ } } @@ -7531,6 +8635,9 @@ unsigned long bytes; bfd_vma addr; +#if DWARF2_XML + return 1; +#endif /* DWARF2-XML */ addr = section->sh_addr; bytes = section->sh_size; @@ -7594,6 +8701,15 @@ unsigned long uvalue = 0; unsigned char * block_start = NULL; int bytes_read; +#if DWARF2_XML + char *at_name = get_AT_name (attribute); +#endif /* DWARF2_XML */ + +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (1, 0, "", uvalue); + } +#else printf (" <#%lx>", uvalue); +#endif /* DWARF2_XML */ break; case DW_FORM_ref1: case DW_FORM_ref2: case DW_FORM_ref4: case DW_FORM_ref_udata: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%lu\"", uvalue + cu_offset); + } else { + printf (" <%lx>", uvalue + cu_offset); + } +#else printf (" <%lx>", uvalue + cu_offset); +#endif /* DWARF2_XML */ break; case DW_FORM_addr: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%lu\"", uvalue); + break; + } else { + printf (" %#lx", uvalue); + } +#else printf (" %#lx", uvalue); +#endif /* DWARF2_XML */ case DW_FORM_flag: case DW_FORM_data1: @@ -7670,19 +8811,45 @@ case DW_FORM_data4: case DW_FORM_sdata: case DW_FORM_udata: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%ld\"", uvalue); + } else { + printf (" %ld", uvalue); + } +#else printf (" %ld", uvalue); +#endif /* DWARF2_XML */ break; case DW_FORM_ref8: case DW_FORM_data8: uvalue = byte_get (data, 4); +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%lu %lu\"", + uvalue, (unsigned long) byte_get (data + 4, 4)); + } else { + printf (" %lx", uvalue); + printf (" %lx", (unsigned long) byte_get (data + 4, 4)); + } +#else printf (" %lx", uvalue); printf (" %lx", (unsigned long) byte_get (data + 4, 4)); +#endif /* DWARF2_XML */ data += 8; break; case DW_FORM_string: +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%s\"", data); + } else { + printf (" %s", data); + } +#else printf (" %s", data); +#endif /* DWARF2_XML */ data += strlen ((char *) data) + 1; break; @@ -7711,8 +8878,17 @@ break; case DW_FORM_strp: - printf (_(" (indirect string, offset: 0x%lx): "), uvalue); +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 0, "\"%s\"", fetch_indirect_string (uvalue)); + } else { + printf (_("(indirect string, offset: 0x%lx): "), uvalue); + printf (fetch_indirect_string (uvalue)); + } +#else + printf (_("(indirect string, offset: 0x%lx): "), uvalue); printf (fetch_indirect_string (uvalue)); +#endif /* DWARF2_XML */ break; case DW_FORM_indirect: @@ -7724,13 +8900,57 @@ break; } +#if DWARF2_XML + /* For some DWARF2 attributes, we add 'value_ref' attributes */ + if (do_debug_xml && is_offset (attribute, form)) { + if (form == DW_FORM_ref_addr) { + printf_xml_raw (0, 0, " value_ref=\"info:%lu\"", uvalue); + } else { + printf_xml_raw (0, 0, " value_ref=\"info:%lu\"", uvalue + cu_offset); + } + } +#endif /* DWARF2_XML*/ + /* For some attributes we can display futher information. */ +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_raw (0, 1, ">"); + xml_indent++; + } else { + printf ("\t"); + } +#else printf ("\t"); +#endif /* DWARF2_XML */ switch (attribute) { case DW_AT_inline: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_INL_not_inlined: printf_xml_desc ("not inlined"); break; + case DW_INL_inlined: printf_xml_desc ("inlined"); break; + case DW_INL_declared_not_inlined: + printf_xml_desc ("declared as inline but ignored"); break; + case DW_INL_declared_inlined: + printf_xml_desc ("declared as inline and inlined"); break; + default: + printf_xml_desc2 ("Unknown inline attribute value: %lx", uvalue); + break; + } + } else { + switch (uvalue) + { + case DW_INL_not_inlined: printf (_("(not inlined)")); break; + case DW_INL_inlined: printf (_("(inlined)")); break; + case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break; + case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break; + default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break; + } + } +#else switch (uvalue) { case DW_INL_not_inlined: printf (_("(not inlined)")); break; @@ -7739,9 +8959,56 @@ case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break; default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break; } +#endif /* DWARF2_XML */ break; case DW_AT_language: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_LANG_C: printf_xml_desc ("non-ANSI C"); break; + case DW_LANG_C89: printf_xml_desc ("ANSI C"); break; + case DW_LANG_C_plus_plus: printf_xml_desc ("C++"); break; + case DW_LANG_Fortran77: printf_xml_desc ("FORTRAN 77"); break; + case DW_LANG_Fortran90: printf_xml_desc ("Fortran 90"); break; + case DW_LANG_Modula2: printf_xml_desc ("Modula 2"); break; + case DW_LANG_Pascal83: printf_xml_desc ("ANSI Pascal"); break; + case DW_LANG_Ada83: printf_xml_desc ("Ada"); break; + case DW_LANG_Cobol74: printf_xml_desc ("Cobol 74"); break; + case DW_LANG_Cobol85: printf_xml_desc ("Cobol 85"); break; + /* DWARF 2.1 values. */ + case DW_LANG_C99: printf_xml_desc ("ANSI C99"); break; + case DW_LANG_Ada95: printf_xml_desc ("ADA 95"); break; + case DW_LANG_Fortran95: printf_xml_desc ("Fortran 95"); break; + /* MIPS extension. */ + case DW_LANG_Mips_Assembler: printf_xml_desc ("MIPS assembler"); break; + default: + printf_xml_desc2 ("Unknown: %lx", uvalue); + break; + } + } else { + switch (uvalue) + { + case DW_LANG_C: printf ("(non-ANSI C)"); break; + case DW_LANG_C89: printf ("(ANSI C)"); break; + case DW_LANG_C_plus_plus: printf ("(C++)"); break; + case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; + case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; + case DW_LANG_Modula2: printf ("(Modula 2)"); break; + case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; + case DW_LANG_Ada83: printf ("(Ada)"); break; + case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; + case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; + /* DWARF 2.1 values. */ + case DW_LANG_C99: printf ("(ANSI C99)"); break; + case DW_LANG_Ada95: printf ("(ADA 95)"); break; + case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; + /* MIPS extension. */ + case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; + default: printf ("(Unknown: %lx)", uvalue); break; + } + } +#else switch (uvalue) { case DW_LANG_C: printf ("(non-ANSI C)"); break; @@ -7762,9 +9029,57 @@ case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; default: printf ("(Unknown: %lx)", uvalue); break; } +#endif /* DWARF2_XML */ break; case DW_AT_encoding: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_ATE_void: printf_xml_desc ("void"); break; + case DW_ATE_address: printf_xml_desc ("machine address"); break; + case DW_ATE_boolean: printf_xml_desc ("boolean"); break; + case DW_ATE_complex_float: printf_xml_desc ("complex float"); break; + case DW_ATE_float: printf_xml_desc ("float"); break; + case DW_ATE_signed: printf_xml_desc ("signed"); break; + case DW_ATE_signed_char: printf_xml_desc ("signed char"); break; + case DW_ATE_unsigned: printf_xml_desc ("unsigned"); break; + case DW_ATE_unsigned_char: printf_xml_desc ("unsigned char"); break; + /* DWARF 2.1 value. */ + case DW_ATE_imaginary_float: + printf_xml_desc ("imaginary float"); + break; + default: + if (uvalue >= DW_ATE_lo_user && uvalue <= DW_ATE_hi_user) + printf_xml_desc ("user defined type"); + else + printf_xml_desc ("unknown type"); + break; + } + } else { + switch (uvalue) + { + case DW_ATE_void: printf ("(void)"); break; + case DW_ATE_address: printf ("(machine address)"); break; + case DW_ATE_boolean: printf ("(boolean)"); break; + case DW_ATE_complex_float: printf ("(complex float)"); break; + case DW_ATE_float: printf ("(float)"); break; + case DW_ATE_signed: printf ("(signed)"); break; + case DW_ATE_signed_char: printf ("(signed char)"); break; + case DW_ATE_unsigned: printf ("(unsigned)"); break; + case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; + /* DWARF 2.1 value. */ + case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; + default: + if (uvalue >= DW_ATE_lo_user + && uvalue <= DW_ATE_hi_user) + printf ("(user defined type)"); + else + printf ("(unknown type)"); + break; + } + } +#else switch (uvalue) { case DW_ATE_void: printf ("(void)"); break; @@ -7786,9 +9101,30 @@ printf ("(unknown type)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_accessibility: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_ACCESS_public: printf_xml_desc ("public"); break; + case DW_ACCESS_protected: printf_xml_desc ("protected"); break; + case DW_ACCESS_private: printf_xml_desc ("private"); break; + default: + printf_xml_desc ("unknown accessibility"); + break; + } + } else { + switch (uvalue) + { + case DW_ACCESS_public: printf ("(public)"); break; + case DW_ACCESS_protected: printf ("(protected)"); break; + case DW_ACCESS_private: printf ("(private)"); break; + default: printf ("(unknown accessibility)"); break; + } + } +#else switch (uvalue) { case DW_ACCESS_public: printf ("(public)"); break; @@ -7796,9 +9132,28 @@ case DW_ACCESS_private: printf ("(private)"); break; default: printf ("(unknown accessibility)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_visibility: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_VIS_local: printf_xml_desc ("local"); break; + case DW_VIS_exported: printf_xml_desc ("exported"); break; + case DW_VIS_qualified: printf_xml_desc ("qualified"); break; + default: printf_xml_desc ("unknown visibility"); break; + } + } else { + switch (uvalue) + { + case DW_VIS_local: printf ("(local)"); break; + case DW_VIS_exported: printf ("(exported)"); break; + case DW_VIS_qualified: printf ("(qualified)"); break; + default: printf ("(unknown visibility)"); break; + } + } +#else switch (uvalue) { case DW_VIS_local: printf ("(local)"); break; @@ -7806,9 +9161,32 @@ case DW_VIS_qualified: printf ("(qualified)"); break; default: printf ("(unknown visibility)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_virtuality: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_VIRTUALITY_none: printf_xml_desc ("none"); break; + case DW_VIRTUALITY_virtual: printf_xml_desc ("virtual"); break; + case DW_VIRTUALITY_pure_virtual: + printf_xml_desc ("pure_virtual"); + break; + default: + printf_xml_desc ("unknown virtuality"); + break; + } + } else { + switch (uvalue) + { + case DW_VIRTUALITY_none: printf ("(none)"); break; + case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; + case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; + default: printf ("(unknown virtuality)"); break; + } + } +#else switch (uvalue) { case DW_VIRTUALITY_none: printf ("(none)"); break; @@ -7816,9 +9194,32 @@ case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; default: printf ("(unknown virtuality)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_identifier_case: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_ID_case_sensitive: printf_xml_desc ("case_sensitive"); break; + case DW_ID_up_case: printf_xml_desc ("up_case"); break; + case DW_ID_down_case: printf_xml_desc ("down_case"); break; + case DW_ID_case_insensitive: + printf_xml_desc ("case_insensitive"); + break; + default: printf_xml_desc ("unknown case"); break; + } + } else { + switch (uvalue) + { + case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; + case DW_ID_up_case: printf ("(up_case)"); break; + case DW_ID_down_case: printf ("(down_case)"); break; + case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; + default: printf ("(unknown case)"); break; + } + } +#else switch (uvalue) { case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; @@ -7827,9 +9228,37 @@ case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; default: printf ("(unknown case)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_calling_convention: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case DW_CC_normal: printf_xml_desc ("normal"); break; + case DW_CC_program: printf_xml_desc ("program"); break; + case DW_CC_nocall: printf_xml_desc ("nocall"); break; + default: + if (uvalue >= DW_CC_lo_user && uvalue <= DW_CC_hi_user) + printf_xml_desc ("user defined"); + else + printf_xml_desc ("unknown convention"); + } + } else { + switch (uvalue) + { + case DW_CC_normal: printf ("(normal)"); break; + case DW_CC_program: printf ("(program)"); break; + case DW_CC_nocall: printf ("(nocall)"); break; + default: + if (uvalue >= DW_CC_lo_user + && uvalue <= DW_CC_hi_user) + printf ("(user defined)"); + else + printf ("(unknown convention)"); + } + } +#else switch (uvalue) { case DW_CC_normal: printf ("(normal)"); break; @@ -7842,15 +9271,33 @@ else printf ("(unknown convention)"); } +#endif /* DWARF2_XML */ break; case DW_AT_ordering: +#if DWARF2_XML + if (do_debug_xml) { + switch (uvalue) { + case -1: printf_xml_desc ("undefined"); break; + case 0: printf_xml_desc ("row major"); break; + case 1: printf_xml_desc ("column major"); break; + } + } else { + switch (uvalue) + { + case -1: printf ("(undefined)"); break; + case 0: printf ("(row major)"); break; + case 1: printf ("(column major)"); break; + } + } +#else switch (uvalue) { case -1: printf ("(undefined)"); break; case 0: printf ("(row major)"); break; case 1: printf ("(column major)"); break; } +#endif /* DWARF2_XML */ break; case DW_AT_frame_base: @@ -7865,15 +9312,35 @@ case DW_AT_lower_bound: if (block_start) { +#if DWARF2_XML + if (do_debug_xml) { + decode_location_expression (block_start, pointer_size, uvalue); + } else { + printf ("("); + decode_location_expression (block_start, pointer_size, uvalue); + printf (")"); + } +#else printf ("("); decode_location_expression (block_start, pointer_size, uvalue); printf (")"); +#endif /* DWARF2_XML */ } else if (form == DW_FORM_data4) { +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_desc ("location list"); + } else { + printf ("("); + printf ("location list"); + printf (")"); + } +#else printf ("("); printf ("location list"); printf (")"); +#endif /* DWARF2_XML */ } break; @@ -7881,6 +9348,15 @@ break; } +#if DWARF2_XML + if (do_debug_xml) { + xml_indent--; + /* + printf_xml ("", at_name); + */ + printf_xml (""); + } +#endif /* DWARF2_XML */ return data; } @@ -7892,10 +9368,22 @@ unsigned long cu_offset; unsigned long pointer_size; { +#if DWARF2_XML + if (do_debug_xml) { + data = read_and_display_attr_value (attribute, form, data, cu_offset, + pointer_size); + } else { + printf (" %-18s:", get_AT_name (attribute)); + data = read_and_display_attr_value (attribute, form, data, cu_offset, + pointer_size); + printf ("\n"); + } +#else printf (" %-18s:", get_AT_name (attribute)); data = read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size); printf ("\n"); +#endif /* DWARF2_XML */ return data; } @@ -7908,7 +9396,15 @@ unsigned char * end = start + section->sh_size; unsigned char * section_begin = start; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); + } +#else printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ load_debug_str (file); load_debug_loc (file); @@ -8001,11 +9497,23 @@ cu_offset = start - section_begin; start += compunit.cu_length + sizeof (external->cu_length); +#if DWARF2_XML + if (do_debug_xml) { + /* do nothing */ + } else { + printf (_(" Compilation Unit @ %lx:\n"), cu_offset); + printf (_(" Length: %ld\n"), compunit.cu_length); + printf (_(" Version: %d\n"), compunit.cu_version); + printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); + printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); + } +#else printf (_(" Compilation Unit @ %lx:\n"), cu_offset); printf (_(" Length: %ld\n"), compunit.cu_length); printf (_(" Version: %d\n"), compunit.cu_version); printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); +#endif /* DWARF2_XML */ if (compunit.cu_version != 2) { @@ -8053,6 +9561,9 @@ unsigned long abbrev_number; abbrev_entry * entry; abbrev_attr * attr; +#if DWARF2_XML + char * tag_name; +#endif /* DWARF2_XML */ abbrev_number = read_leb128 (tags, & bytes_read, 0); tags += bytes_read; @@ -8060,6 +9571,18 @@ /* A null DIE marks the end of a list of children. */ if (abbrev_number == 0) { +#if DWARF2_XML + if (do_debug_xml) { + /* + char *tag_name = get_TAG_name (pop_tag ()); + */ + printf_xml_end (""); + /* + printf_xml_end ("", tag_name); + */ + + } +#endif /* DWARF2_XML */ --level; continue; } @@ -8078,11 +9601,32 @@ return 0; } +#if DWARF2_XML + if (do_debug_xml) { + unsigned long offset; + tag_name = get_TAG_name (entry->tag); + offset = (unsigned long) (tags - section_begin - bytes_read); + /* + if (entry->children) + push_tag (entry->tag); + */ + printf_xml_begin ("", + tag_name, level, offset, abbrev_number); + } else { + printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"), + level, + (unsigned long) (tags - section_begin - bytes_read), + abbrev_number, + get_TAG_name (entry->tag)); + } +#else printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"), level, (unsigned long) (tags - section_begin - bytes_read), abbrev_number, get_TAG_name (entry->tag)); +#endif /* DWARF2_XML */ for (attr = entry->first_attr; attr; attr = attr->next) tags = read_and_display_attr (attr->attribute, @@ -8090,6 +9634,16 @@ tags, cu_offset, compunit.cu_pointer_size); +#if DWARF2_XML + if (do_debug_xml && !entry->children) { + /* + printf_xml_end ("", tag_name); + */ + printf_xml_end (""); + } +#else + /* do nothing */ +#endif if (entry->children) ++level; } @@ -8098,7 +9652,15 @@ free_debug_str (); free_debug_loc (); +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end ("
"); + } else { + printf ("\n"); + } +#else printf ("\n"); +#endif /* DWARF2_XML */ return 1; } @@ -8111,7 +9673,15 @@ { unsigned char * end = start + section->sh_size; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); + } +#else printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ while (start < end) { @@ -8142,6 +9712,25 @@ break; } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("", + arange.ar_length, arange.ar_version, + arange.ar_info_offset, + arange.ar_pointer_size, + arange.ar_segment_size); + } else { + printf (_(" Length: %ld\n"), arange.ar_length); + printf (_(" Version: %d\n"), arange.ar_version); + printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset); + printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); + printf (_(" Segment Size: %d\n"), arange.ar_segment_size); + + printf (_("\n Address Length\n")); + } +#else printf (_(" Length: %ld\n"), arange.ar_length); printf (_(" Version: %d\n"), arange.ar_version); printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset); @@ -8149,6 +9738,7 @@ printf (_(" Segment Size: %d\n"), arange.ar_segment_size); printf (_("\n Address Length\n")); +#endif /* DWARF2_XML */ ranges = start + sizeof (* external); @@ -8171,14 +9761,35 @@ if (address == 0 && length == 0) break; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml ("", + address, length); + } else { + printf (" %8.8lx %lu\n", address, length); + } +#else printf (" %8.8lx %lu\n", address, length); +#endif /* DWARF2_XML */ } +#if DWARF2_XML + if (do_debug_xml) + printf_xml_end (""); +#endif /* DWARF2_XML */ + start += arange.ar_length + sizeof (external->ar_length); } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end ("
"); + } else { + printf ("\n"); + } +#else printf ("\n"); - +#endif /* DWARF2_XML */ return 1; } @@ -8246,6 +9857,86 @@ if (* max_regs < fc->ncols) * max_regs = fc->ncols; +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("", + fc->pc_begin, fc->cfa_reg, fc->cfa_offset); + + for (r = 0; r < fc->ncols; r++) { + char name [100], rule [100]; + + if (fc->col_type[r] != DW_CFA_unreferenced) { + if (r == fc->ra) + sprintf (name, "return address"); + else + sprintf (name, "%d", r); + + switch (fc->col_type[r]) { + case DW_CFA_undefined: strcpy (rule, "undefined"); break; + case DW_CFA_same_value: strcpy (rule, "same_value"); break; + case DW_CFA_offset: + sprintf (rule, "offset: %d", fc->col_offset[r]); break; + case DW_CFA_register: + sprintf (rule, "register: %d", fc->col_offset[r]); break; + default: + strcpy (rule, "N/A"); break; + } + printf_xml ("", name, rule); + } + } + printf_xml_end (""); + } else { + if (* need_col_headers) + { + * need_col_headers = 0; + + printf (" LOC CFA "); + + for (r = 0; r < * max_regs; r++) + if (fc->col_type[r] != DW_CFA_unreferenced) + { + if (r == fc->ra) + printf ("ra "); + else + printf ("r%-4d", r); + } + + printf ("\n"); + } + + printf ("%08lx ", fc->pc_begin); + sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset); + printf ("%-8s ", tmp); + + for (r = 0; r < fc->ncols; r++) + { + if (fc->col_type[r] != DW_CFA_unreferenced) + { + switch (fc->col_type[r]) + { + case DW_CFA_undefined: + strcpy (tmp, "u"); + break; + case DW_CFA_same_value: + strcpy (tmp, "s"); + break; + case DW_CFA_offset: + sprintf (tmp, "c%+d", fc->col_offset[r]); + break; + case DW_CFA_register: + sprintf (tmp, "r%d", fc->col_offset[r]); + break; + default: + strcpy (tmp, "n/a"); + break; + } + printf ("%-5s", tmp); + } + } + printf ("\n"); + } +#else /* DWARF2_XML */ if (* need_col_headers) { * need_col_headers = 0; @@ -8294,6 +9985,7 @@ } } printf ("\n"); +#endif /* DWARF2_XML */ } static int @@ -8330,7 +10022,17 @@ int max_regs = 0; int addr_size = is_32bit_elf ? 4 : 8; +#if DWARF2_XML + if (do_debug_xml) { + if (is_eh) return 1; + do_debug_frames_interp = 1; /* -X and -wf implies -wF */ + printf_xml_begin ("
", SECTION_NAME (section)); + } else { + printf (_("The section %s contains:\n"), SECTION_NAME (section)); + } +#else printf (_("The section %s contains:\n"), SECTION_NAME (section)); +#endif /* DWARF2_XML */ while (start < end) { @@ -8405,10 +10107,29 @@ cie = fc; if (do_debug_frames_interp) +#if DWARF2_XML + if (do_debug_xml) { + printf_xml (""); + printf_xml_begin ("", + (unsigned long)(saved_start - section_start), + length, cie_id, fc->augmentation, + fc->code_factor, fc->data_factor, fc->ra); + } else { + printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", + (unsigned long)(saved_start - section_start), + length, cie_id, fc->augmentation, + fc->code_factor, fc->data_factor, fc->ra); + } +#else printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", (unsigned long)(saved_start - section_start), length, cie_id, fc->augmentation, fc->code_factor, fc->data_factor, fc->ra); +#endif /* DWARF2_XML */ else { printf ("\n%08lx %08lx %08lx CIE\n", @@ -8514,10 +10235,28 @@ start += augmentation_data_len; } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_begin ("", + (unsigned long)(saved_start - section_start), + length, cie_id, + (unsigned long)(cie->chunk_start - section_start), + fc->pc_begin, fc->pc_begin + fc->pc_range); + } else { + printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n", + (unsigned long)(saved_start - section_start), + length, cie_id, + (unsigned long)(cie->chunk_start - section_start), + fc->pc_begin, fc->pc_begin + fc->pc_range); + } +#else printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n", (unsigned long)(saved_start - section_start), length, cie_id, (unsigned long)(cie->chunk_start - section_start), fc->pc_begin, fc->pc_begin + fc->pc_range); +#endif /* DWARF2_XML */ if (! do_debug_frames_interp && augmentation_data_len) { unsigned long i; @@ -8884,10 +10623,26 @@ if (do_debug_frames_interp) frame_display_row (fc, &need_col_headers, &max_regs); +#if DWARF2_XML + if (do_debug_xml) { + if (cie_id == DW_CIE_ID) { + printf_xml_end (""); + printf_xml (""); + } else { + printf_xml_end (""); + } + } +#else +#endif + start = block_end; } +#if DWARF2_XML + printf_xml_end ("
"); +#else printf ("\n"); +#endif /* DWARF2_XML */ return 1; } @@ -8902,6 +10657,9 @@ unsigned char * start ATTRIBUTE_UNUSED; FILE * file ATTRIBUTE_UNUSED; { +#if DWARF2_XML + return 1; +#endif /* DWARF2_XML */ printf (_("Displaying the debug contents of section %s is not yet supported.\n"), SECTION_NAME (section)); @@ -9047,6 +10805,14 @@ } } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml (""); + printf_xml (""); + printf_xml_begin (""); + } +#endif /* DWARF2_XML */ + for (i = 0, section = section_headers; i < elf_header.e_shnum && i < num_dump_sects; i ++, section ++) @@ -9062,6 +10828,12 @@ display_debug_section (section, file); } +#if DWARF2_XML + if (do_debug_xml) { + printf_xml_end (""); + } +#endif /* DWARF2_XML */ + if (i < num_dump_sects) warn (_("Some sections were not dumped because they do not exist!\n")); @@ -10064,6 +11836,191 @@ print_address (addr, stderr); } #endif + +#if DWARF2_XML + /* + Sorry, I know I should use VA_OPEN, but not here for corner-cutting. + */ +static void +printf_xml_sub (int indent, int newline, char *fmt, va_list pvar) +{ + if (indent) + printf ("%*s", xml_indent * 2, ""); + vprintf (fmt, pvar); + if (newline) + printf ("\n"); +} + +static void +printf_xml (char *fmt, ...) +{ + va_list pvar; + va_start (pvar, fmt); + printf_xml_sub (1, 1, fmt, pvar); + va_end (pvar); +} + +static void +printf_xml_raw (int indent, int newline, char *fmt, ...) +{ + va_list pvar; + va_start (pvar, fmt); + printf_xml_sub (indent, newline, fmt, pvar); + va_end (pvar); +} + +static void +printf_xml_begin (char *fmt, ...) +{ + va_list pvar; + va_start (pvar, fmt); + printf_xml_sub (1, 1, fmt, pvar); + va_end (pvar); + xml_indent++; +} + +static void +printf_xml_end (char *fmt, ...) +{ + va_list pvar; + xml_indent--; + va_start (pvar, fmt); + printf_xml_sub (1, 1, fmt, pvar); + va_end (pvar); +} + +static void +printf_xml_line (void) +{ +#if 0 + /* column, is_stmt and basic_block look not to be set correctly. */ + printf_xml ("", + state_machine_regs.address, state_machine_regs.line, + state_machine_regs.column, + (!state_machine_regs.is_stmt ? "false" : "true"), + (!state_machine_regs.basic_block ? "false" : "true")); +#else + printf_xml ("", + state_machine_regs.address, state_machine_regs.line, + state_machine_regs.file); +#endif +} + +static void +printf_xml_desc (char *fmt) +{ + printf_xml ("%s", fmt); +} + +static void +printf_xml_desc2 (char *fmt, ...) +{ +#define FMT_SIZE 1024 + char fmt2 [FMT_SIZE]; + va_list pvar; + va_start (pvar, fmt); + snprintf (fmt2, FMT_SIZE, "%s", fmt); + printf_xml_sub (1, 1, fmt2, pvar); + va_end (pvar); +} + +static void +push_tag (unsigned long tag) +{ + if (tag_stack_index >= MAX_TAG_STACK_DEPTH) { + error ("tag stack overflow\n"); + exit (1); + } + tag_stack [tag_stack_index++] = tag; +} + +static unsigned long +pop_tag (void) +{ + if (tag_stack_index <= 0) { + error ("tag stack underflow\n"); + exit (1); + } + return tag_stack [--tag_stack_index]; +} + +static char * +escape_entity_ref (const char *s) +{ + enum { BUFLEN = 8192 }; + static char buf [BUFLEN]; + char *p = buf, *ent_ref; + + while (*s != '\0') { + switch (*s) { + case '<': ent_ref = "<"; break; + case '>': ent_ref = ">"; break; + case '&': ent_ref = "&"; break; + case '\"': ent_ref = """; break; /* " (for font-lock sanity) */ + case '\'': ent_ref = "'"; break; + default: ent_ref = NULL; break; + } + if (ent_ref == NULL) { + assert (p < buf + BUFLEN); + *p++ = *s++; + } else { + assert (p + strlen (ent_ref) - 1 < buf + BUFLEN); + sprintf (p, ent_ref); + p += strlen (ent_ref); + s++; + } + } + assert (p < buf + BUFLEN); + *p = '\0'; + return buf; +} + +static int +is_offset (unsigned long attribute, unsigned long form) +{ + int attribute_ok, form_ok; + + switch (attribute) { + default: + attribute_ok = 0; + break; + case DW_AT_sibling: + case DW_AT_type: + case DW_AT_discr: + case DW_AT_import: + case DW_AT_common_reference: + case DW_AT_containing_type: + case DW_AT_default_value: + case DW_AT_upper_bound: + case DW_AT_abstract_origin: + case DW_AT_base_types: + case DW_AT_count: + case DW_AT_data_member_location: + case DW_AT_friend: + case DW_AT_priority: + case DW_AT_specification: + case DW_AT_vtable_elem_location: + attribute_ok = 1; + break; + } + + switch (form) { + default: + form_ok = 0; + break; + case DW_FORM_ref_addr: + case DW_FORM_ref1: + case DW_FORM_ref2: + case DW_FORM_ref4: + case DW_FORM_ref8: + case DW_FORM_ref_udata: + form_ok = 1; + break; + } + return attribute_ok && form_ok; +} +#endif /* DWARF2_XML */ int main PARAMS ((int, char **));