+static const char *const dwarf_regnames_i386[] =
+{
+ "eax", "ecx", "edx", "ebx",
+ "esp", "ebp", "esi", "edi",
+ "eip", "eflags", NULL,
+ "st0", "st1", "st2", "st3",
+ "st4", "st5", "st6", "st7",
+ NULL, NULL,
+ "xmm0", "xmm1", "xmm2", "xmm3",
+ "xmm4", "xmm5", "xmm6", "xmm7",
+ "mm0", "mm1", "mm2", "mm3",
+ "mm4", "mm5", "mm6", "mm7",
+ "fcw", "fsw", "mxcsr",
+ "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
+ "tr", "ldtr"
+};
+
+static const char *const dwarf_regnames_x86_64[] =
+{
+ "rax", "rdx", "rcx", "rbx",
+ "rsi", "rdi", "rbp", "rsp",
+ "r8", "r9", "r10", "r11",
+ "r12", "r13", "r14", "r15",
+ "rip",
+ "xmm0", "xmm1", "xmm2", "xmm3",
+ "xmm4", "xmm5", "xmm6", "xmm7",
+ "xmm8", "xmm9", "xmm10", "xmm11",
+ "xmm12", "xmm13", "xmm14", "xmm15",
+ "st0", "st1", "st2", "st3",
+ "st4", "st5", "st6", "st7",
+ "mm0", "mm1", "mm2", "mm3",
+ "mm4", "mm5", "mm6", "mm7",
+ "rflags",
+ "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
+ "fs.base", "gs.base", NULL, NULL,
+ "tr", "ldtr",
+ "mxcsr", "fcw", "fsw"
+};
+
+static const char *const *dwarf_regnames;
+static unsigned int dwarf_regnames_count;
+
+void
+init_dwarf_regnames (unsigned int e_machine)
+{
+ switch (e_machine)
+ {
+ case EM_386:
+ case EM_486:
+ dwarf_regnames = dwarf_regnames_i386;
+ dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
+ break;
+
+ case EM_X86_64:
+ dwarf_regnames = dwarf_regnames_x86_64;
+ dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
+ break;
+
+ default:
+ break;
+ }
+}
+
+static const char *
+regname (unsigned int regno, int row)
+{
+ static char reg[64];
+ if (dwarf_regnames
+ && regno < dwarf_regnames_count
+ && dwarf_regnames [regno] != NULL)
+ {
+ if (row)
+ return dwarf_regnames [regno];
+ snprintf (reg, sizeof (reg), "r%d (%s)", regno,
+ dwarf_regnames [regno]);
+ }
+ else
+ snprintf (reg, sizeof (reg), "r%d", regno);
+ return reg;
+}
+