GDB (API)
/home/stan/gdb/src/gdb/arm-wince-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Windows CE running on ARM processors,
00002    for GDB.
00003 
00004    Copyright (C) 2007-2013 Free Software Foundation, Inc.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 #include "defs.h"
00022 #include "osabi.h"
00023 #include "gdbcore.h"
00024 #include "target.h"
00025 #include "frame.h"
00026 
00027 #include "gdb_string.h"
00028 
00029 #include "arm-tdep.h"
00030 #include "windows-tdep.h"
00031 
00032 static const gdb_byte arm_wince_le_breakpoint[] = { 0x10, 0x00, 0x00, 0xe6 };
00033 static const gdb_byte arm_wince_thumb_le_breakpoint[] = { 0xfe, 0xdf };
00034 
00035 /* Description of the longjmp buffer.  */
00036 #define ARM_WINCE_JB_ELEMENT_SIZE       INT_REGISTER_SIZE
00037 #define ARM_WINCE_JB_PC                 10
00038 
00039 static CORE_ADDR
00040 arm_pe_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
00041 {
00042   struct gdbarch *gdbarch = get_frame_arch (frame);
00043   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00044   ULONGEST indirect;
00045   struct bound_minimal_symbol indsym;
00046   const char *symname;
00047   CORE_ADDR next_pc;
00048 
00049   /* The format of an ARM DLL trampoline is:
00050        ldr  ip, [pc]
00051        ldr  pc, [ip]
00052        .dw __imp_<func>  */
00053 
00054   if (pc == 0
00055       || read_memory_unsigned_integer (pc + 0, 4, byte_order) != 0xe59fc000
00056       || read_memory_unsigned_integer (pc + 4, 4, byte_order) != 0xe59cf000)
00057     return 0;
00058 
00059   indirect = read_memory_unsigned_integer (pc + 8, 4, byte_order);
00060   if (indirect == 0)
00061     return 0;
00062 
00063   indsym = lookup_minimal_symbol_by_pc (indirect);
00064   if (indsym.minsym == NULL)
00065     return 0;
00066 
00067   symname = SYMBOL_LINKAGE_NAME (indsym.minsym);
00068   if (symname == NULL || strncmp (symname, "__imp_", 6) != 0)
00069     return 0;
00070 
00071   next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
00072   if (next_pc != 0)
00073     return next_pc;
00074 
00075   /* Check with the default arm gdbarch_skip_trampoline.  */
00076   return arm_skip_stub (frame, pc);
00077 }
00078 
00079 /* GCC emits a call to __gccmain in the prologue of main.
00080 
00081    The function below examines the code pointed at by PC and checks to
00082    see if it corresponds to a call to __gccmain.  If so, it returns
00083    the address of the instruction following that call.  Otherwise, it
00084    simply returns PC.  */
00085 
00086 static CORE_ADDR
00087 arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
00088 {
00089   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00090   ULONGEST this_instr;
00091 
00092   this_instr = read_memory_unsigned_integer (pc, 4, byte_order);
00093 
00094   /* bl offset <__gccmain> */
00095   if ((this_instr & 0xfff00000) == 0xeb000000)
00096     {
00097 #define sign_extend(V, N) \
00098   (((long) (V) ^ (1L << ((N) - 1))) - (1L << ((N) - 1)))
00099 
00100       long offset = sign_extend (this_instr & 0x000fffff, 23) << 2;
00101       CORE_ADDR call_dest = (pc + 8 + offset) & 0xffffffffU;
00102       struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
00103 
00104       if (s.minsym != NULL
00105           && SYMBOL_LINKAGE_NAME (s.minsym) != NULL
00106           && strcmp (SYMBOL_LINKAGE_NAME (s.minsym), "__gccmain") == 0)
00107         pc += 4;
00108     }
00109 
00110   return pc;
00111 }
00112 
00113 static void
00114 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00115 {
00116   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00117 
00118   windows_init_abi (info, gdbarch);
00119 
00120   tdep->arm_breakpoint = arm_wince_le_breakpoint;
00121   tdep->arm_breakpoint_size = sizeof (arm_wince_le_breakpoint);
00122   tdep->thumb_breakpoint = arm_wince_thumb_le_breakpoint;
00123   tdep->thumb_breakpoint_size = sizeof (arm_wince_thumb_le_breakpoint);
00124   tdep->struct_return = pcc_struct_return;
00125 
00126   tdep->fp_model = ARM_FLOAT_SOFT_VFP;
00127 
00128   tdep->jb_pc = ARM_WINCE_JB_PC;
00129   tdep->jb_elt_size = ARM_WINCE_JB_ELEMENT_SIZE;
00130 
00131   /* On ARM WinCE char defaults to signed.  */
00132   set_gdbarch_char_signed (gdbarch, 1);
00133 
00134   /* Shared library handling.  */
00135   set_gdbarch_skip_trampoline_code (gdbarch, arm_pe_skip_trampoline_code);
00136 
00137   /* Single stepping.  */
00138   set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
00139 
00140   /* Skip call to __gccmain that gcc places in main.  */
00141   set_gdbarch_skip_main_prologue (gdbarch, arm_wince_skip_main_prologue);
00142 }
00143 
00144 static enum gdb_osabi
00145 arm_wince_osabi_sniffer (bfd *abfd)
00146 {
00147   const char *target_name = bfd_get_target (abfd);
00148 
00149   if (strcmp (target_name, "pei-arm-wince-little") == 0)
00150     return GDB_OSABI_WINCE;
00151 
00152   return GDB_OSABI_UNKNOWN;
00153 }
00154 
00155 /* Provide a prototype to silence -Wmissing-prototypes.  */
00156 void _initialize_arm_wince_tdep (void);
00157 
00158 void
00159 _initialize_arm_wince_tdep (void)
00160 {
00161   gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_coff_flavour,
00162                                   arm_wince_osabi_sniffer);
00163 
00164   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_WINCE,
00165                           arm_wince_init_abi);
00166 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines