Home | History | Annotate | Download | only in util
      1 /*
      2  * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
      3  * Extracted from probe-finder.c
      4  *
      5  * Written by Masami Hiramatsu <mhiramat (at) redhat.com>
      6  *
      7  * This program is free software; you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation; either version 2 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this program; if not, write to the Free Software
     19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     20  *
     21  */
     22 
     23 #include <libio.h>
     24 /* ANDROID_CHANGE_BEGIN */
     25 #if 0
     26 #include <dwarf-regs.h>
     27 #else
     28 #include "util/include/dwarf-regs.h"
     29 #endif
     30 /* ANDROID_CHANGE_END */
     31 
     32 /*
     33  * Generic dwarf analysis helpers
     34  */
     35 
     36 #define X86_32_MAX_REGS 8
     37 const char *x86_32_regs_table[X86_32_MAX_REGS] = {
     38 	"%ax",
     39 	"%cx",
     40 	"%dx",
     41 	"%bx",
     42 	"$stack",	/* Stack address instead of %sp */
     43 	"%bp",
     44 	"%si",
     45 	"%di",
     46 };
     47 
     48 #define X86_64_MAX_REGS 16
     49 const char *x86_64_regs_table[X86_64_MAX_REGS] = {
     50 	"%ax",
     51 	"%dx",
     52 	"%cx",
     53 	"%bx",
     54 	"%si",
     55 	"%di",
     56 	"%bp",
     57 	"%sp",
     58 	"%r8",
     59 	"%r9",
     60 	"%r10",
     61 	"%r11",
     62 	"%r12",
     63 	"%r13",
     64 	"%r14",
     65 	"%r15",
     66 };
     67 
     68 /* TODO: switching by dwarf address size */
     69 #ifdef __x86_64__
     70 #define ARCH_MAX_REGS X86_64_MAX_REGS
     71 #define arch_regs_table x86_64_regs_table
     72 #else
     73 #define ARCH_MAX_REGS X86_32_MAX_REGS
     74 #define arch_regs_table x86_32_regs_table
     75 #endif
     76 
     77 /* Return architecture dependent register string (for kprobe-tracer) */
     78 const char *get_arch_regstr(unsigned int n)
     79 {
     80 	return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
     81 }
     82