GDB (API)
/home/stan/gdb/src/gdb/rs6000-nat.c
Go to the documentation of this file.
00001 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"
00022 #include "target.h"
00023 #include "gdbcore.h"
00024 #include "symfile.h"
00025 #include "objfiles.h"
00026 #include "libbfd.h"             /* For bfd_default_set_arch_mach (FIXME) */
00027 #include "bfd.h"
00028 #include "exceptions.h"
00029 #include "gdb-stabs.h"
00030 #include "regcache.h"
00031 #include "arch-utils.h"
00032 #include "inf-child.h"
00033 #include "inf-ptrace.h"
00034 #include "ppc-tdep.h"
00035 #include "rs6000-tdep.h"
00036 #include "rs6000-aix-tdep.h"
00037 #include "exec.h"
00038 #include "observer.h"
00039 #include "xcoffread.h"
00040 
00041 #include <sys/ptrace.h>
00042 #include <sys/reg.h>
00043 
00044 #include <sys/dir.h>
00045 #include <sys/user.h>
00046 #include <signal.h>
00047 #include <sys/ioctl.h>
00048 #include <fcntl.h>
00049 #include <errno.h>
00050 
00051 #include <a.out.h>
00052 #include <sys/file.h>
00053 #include "gdb_stat.h"
00054 #include "gdb_bfd.h"
00055 #include <sys/core.h>
00056 #define __LDINFO_PTRACE32__     /* for __ld_info32 */
00057 #define __LDINFO_PTRACE64__     /* for __ld_info64 */
00058 #include <sys/ldr.h>
00059 #include <sys/systemcfg.h>
00060 
00061 /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
00062    debugging 32-bit and 64-bit processes.  Define a typedef and macros for
00063    accessing fields in the appropriate structures.  */
00064 
00065 /* In 32-bit compilation mode (which is the only mode from which ptrace()
00066    works on 4.3), __ld_info32 is #defined as equivalent to ld_info.  */
00067 
00068 #if defined (__ld_info32) || defined (__ld_info64)
00069 # define ARCH3264
00070 #endif
00071 
00072 /* Return whether the current architecture is 64-bit.  */
00073 
00074 #ifndef ARCH3264
00075 # define ARCH64() 0
00076 #else
00077 # define ARCH64() (register_size (target_gdbarch (), 0) == 8)
00078 #endif
00079 
00080 static void exec_one_dummy_insn (struct regcache *);
00081 
00082 static LONGEST rs6000_xfer_shared_libraries
00083   (struct target_ops *ops, enum target_object object,
00084    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
00085    ULONGEST offset, LONGEST len);
00086 
00087 /* Given REGNO, a gdb register number, return the corresponding
00088    number suitable for use as a ptrace() parameter.  Return -1 if
00089    there's no suitable mapping.  Also, set the int pointed to by
00090    ISFLOAT to indicate whether REGNO is a floating point register.  */
00091 
00092 static int
00093 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
00094 {
00095   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00096 
00097   *isfloat = 0;
00098   if (tdep->ppc_gp0_regnum <= regno
00099       && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
00100     return regno;
00101   else if (tdep->ppc_fp0_regnum >= 0
00102            && tdep->ppc_fp0_regnum <= regno
00103            && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
00104     {
00105       *isfloat = 1;
00106       return regno - tdep->ppc_fp0_regnum + FPR0;
00107     }
00108   else if (regno == gdbarch_pc_regnum (gdbarch))
00109     return IAR;
00110   else if (regno == tdep->ppc_ps_regnum)
00111     return MSR;
00112   else if (regno == tdep->ppc_cr_regnum)
00113     return CR;
00114   else if (regno == tdep->ppc_lr_regnum)
00115     return LR;
00116   else if (regno == tdep->ppc_ctr_regnum)
00117     return CTR;
00118   else if (regno == tdep->ppc_xer_regnum)
00119     return XER;
00120   else if (tdep->ppc_fpscr_regnum >= 0
00121            && regno == tdep->ppc_fpscr_regnum)
00122     return FPSCR;
00123   else if (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum)
00124     return MQ;
00125   else
00126     return -1;
00127 }
00128 
00129 /* Call ptrace(REQ, ID, ADDR, DATA, BUF).  */
00130 
00131 static int
00132 rs6000_ptrace32 (int req, int id, int *addr, int data, int *buf)
00133 {
00134 #ifdef HAVE_PTRACE64
00135   int ret = ptrace64 (req, id, (uintptr_t) addr, data, buf);
00136 #else
00137   int ret = ptrace (req, id, (int *)addr, data, buf);
00138 #endif
00139 #if 0
00140   printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
00141           req, id, (unsigned int)addr, data, (unsigned int)buf, ret);
00142 #endif
00143   return ret;
00144 }
00145 
00146 /* Call ptracex(REQ, ID, ADDR, DATA, BUF).  */
00147 
00148 static int
00149 rs6000_ptrace64 (int req, int id, long long addr, int data, void *buf)
00150 {
00151 #ifdef ARCH3264
00152 #  ifdef HAVE_PTRACE64
00153   int ret = ptrace64 (req, id, addr, data, buf);
00154 #  else
00155   int ret = ptracex (req, id, addr, data, buf);
00156 #  endif
00157 #else
00158   int ret = 0;
00159 #endif
00160 #if 0
00161   printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
00162           req, id, hex_string (addr), data, (unsigned int)buf, ret);
00163 #endif
00164   return ret;
00165 }
00166 
00167 /* Fetch register REGNO from the inferior.  */
00168 
00169 static void
00170 fetch_register (struct regcache *regcache, int regno)
00171 {
00172   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00173   int addr[MAX_REGISTER_SIZE];
00174   int nr, isfloat;
00175 
00176   /* Retrieved values may be -1, so infer errors from errno.  */
00177   errno = 0;
00178 
00179   nr = regmap (gdbarch, regno, &isfloat);
00180 
00181   /* Floating-point registers.  */
00182   if (isfloat)
00183     rs6000_ptrace32 (PT_READ_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);
00184 
00185   /* Bogus register number.  */
00186   else if (nr < 0)
00187     {
00188       if (regno >= gdbarch_num_regs (gdbarch))
00189         fprintf_unfiltered (gdb_stderr,
00190                             "gdb error: register no %d not implemented.\n",
00191                             regno);
00192       return;
00193     }
00194 
00195   /* Fixed-point registers.  */
00196   else
00197     {
00198       if (!ARCH64 ())
00199         *addr = rs6000_ptrace32 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
00200                                  (int *) nr, 0, 0);
00201       else
00202         {
00203           /* PT_READ_GPR requires the buffer parameter to point to long long,
00204              even if the register is really only 32 bits.  */
00205           long long buf;
00206           rs6000_ptrace64 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
00207                            nr, 0, &buf);
00208           if (register_size (gdbarch, regno) == 8)
00209             memcpy (addr, &buf, 8);
00210           else
00211             *addr = buf;
00212         }
00213     }
00214 
00215   if (!errno)
00216     regcache_raw_supply (regcache, regno, (char *) addr);
00217   else
00218     {
00219 #if 0
00220       /* FIXME: this happens 3 times at the start of each 64-bit program.  */
00221       perror (_("ptrace read"));
00222 #endif
00223       errno = 0;
00224     }
00225 }
00226 
00227 /* Store register REGNO back into the inferior.  */
00228 
00229 static void
00230 store_register (struct regcache *regcache, int regno)
00231 {
00232   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00233   int addr[MAX_REGISTER_SIZE];
00234   int nr, isfloat;
00235 
00236   /* Fetch the register's value from the register cache.  */
00237   regcache_raw_collect (regcache, regno, addr);
00238 
00239   /* -1 can be a successful return value, so infer errors from errno.  */
00240   errno = 0;
00241 
00242   nr = regmap (gdbarch, regno, &isfloat);
00243 
00244   /* Floating-point registers.  */
00245   if (isfloat)
00246     rs6000_ptrace32 (PT_WRITE_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);
00247 
00248   /* Bogus register number.  */
00249   else if (nr < 0)
00250     {
00251       if (regno >= gdbarch_num_regs (gdbarch))
00252         fprintf_unfiltered (gdb_stderr,
00253                             "gdb error: register no %d not implemented.\n",
00254                             regno);
00255     }
00256 
00257   /* Fixed-point registers.  */
00258   else
00259     {
00260       if (regno == gdbarch_sp_regnum (gdbarch))
00261         /* Execute one dummy instruction (which is a breakpoint) in inferior
00262            process to give kernel a chance to do internal housekeeping.
00263            Otherwise the following ptrace(2) calls will mess up user stack
00264            since kernel will get confused about the bottom of the stack
00265            (%sp).  */
00266         exec_one_dummy_insn (regcache);
00267 
00268       /* The PT_WRITE_GPR operation is rather odd.  For 32-bit inferiors,
00269          the register's value is passed by value, but for 64-bit inferiors,
00270          the address of a buffer containing the value is passed.  */
00271       if (!ARCH64 ())
00272         rs6000_ptrace32 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
00273                          (int *) nr, *addr, 0);
00274       else
00275         {
00276           /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
00277              area, even if the register is really only 32 bits.  */
00278           long long buf;
00279           if (register_size (gdbarch, regno) == 8)
00280             memcpy (&buf, addr, 8);
00281           else
00282             buf = *addr;
00283           rs6000_ptrace64 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
00284                            nr, 0, &buf);
00285         }
00286     }
00287 
00288   if (errno)
00289     {
00290       perror (_("ptrace write"));
00291       errno = 0;
00292     }
00293 }
00294 
00295 /* Read from the inferior all registers if REGNO == -1 and just register
00296    REGNO otherwise.  */
00297 
00298 static void
00299 rs6000_fetch_inferior_registers (struct target_ops *ops,
00300                                  struct regcache *regcache, int regno)
00301 {
00302   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00303   if (regno != -1)
00304     fetch_register (regcache, regno);
00305 
00306   else
00307     {
00308       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00309 
00310       /* Read 32 general purpose registers.  */
00311       for (regno = tdep->ppc_gp0_regnum;
00312            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
00313            regno++)
00314         {
00315           fetch_register (regcache, regno);
00316         }
00317 
00318       /* Read general purpose floating point registers.  */
00319       if (tdep->ppc_fp0_regnum >= 0)
00320         for (regno = 0; regno < ppc_num_fprs; regno++)
00321           fetch_register (regcache, tdep->ppc_fp0_regnum + regno);
00322 
00323       /* Read special registers.  */
00324       fetch_register (regcache, gdbarch_pc_regnum (gdbarch));
00325       fetch_register (regcache, tdep->ppc_ps_regnum);
00326       fetch_register (regcache, tdep->ppc_cr_regnum);
00327       fetch_register (regcache, tdep->ppc_lr_regnum);
00328       fetch_register (regcache, tdep->ppc_ctr_regnum);
00329       fetch_register (regcache, tdep->ppc_xer_regnum);
00330       if (tdep->ppc_fpscr_regnum >= 0)
00331         fetch_register (regcache, tdep->ppc_fpscr_regnum);
00332       if (tdep->ppc_mq_regnum >= 0)
00333         fetch_register (regcache, tdep->ppc_mq_regnum);
00334     }
00335 }
00336 
00337 /* Store our register values back into the inferior.
00338    If REGNO is -1, do this for all registers.
00339    Otherwise, REGNO specifies which register (so we can save time).  */
00340 
00341 static void
00342 rs6000_store_inferior_registers (struct target_ops *ops,
00343                                  struct regcache *regcache, int regno)
00344 {
00345   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00346   if (regno != -1)
00347     store_register (regcache, regno);
00348 
00349   else
00350     {
00351       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00352 
00353       /* Write general purpose registers first.  */
00354       for (regno = tdep->ppc_gp0_regnum;
00355            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
00356            regno++)
00357         {
00358           store_register (regcache, regno);
00359         }
00360 
00361       /* Write floating point registers.  */
00362       if (tdep->ppc_fp0_regnum >= 0)
00363         for (regno = 0; regno < ppc_num_fprs; regno++)
00364           store_register (regcache, tdep->ppc_fp0_regnum + regno);
00365 
00366       /* Write special registers.  */
00367       store_register (regcache, gdbarch_pc_regnum (gdbarch));
00368       store_register (regcache, tdep->ppc_ps_regnum);
00369       store_register (regcache, tdep->ppc_cr_regnum);
00370       store_register (regcache, tdep->ppc_lr_regnum);
00371       store_register (regcache, tdep->ppc_ctr_regnum);
00372       store_register (regcache, tdep->ppc_xer_regnum);
00373       if (tdep->ppc_fpscr_regnum >= 0)
00374         store_register (regcache, tdep->ppc_fpscr_regnum);
00375       if (tdep->ppc_mq_regnum >= 0)
00376         store_register (regcache, tdep->ppc_mq_regnum);
00377     }
00378 }
00379 
00380 
00381 /* Attempt a transfer all LEN bytes starting at OFFSET between the
00382    inferior's OBJECT:ANNEX space and GDB's READBUF/WRITEBUF buffer.
00383    Return the number of bytes actually transferred.  */
00384 
00385 static LONGEST
00386 rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
00387                      const char *annex, gdb_byte *readbuf,
00388                      const gdb_byte *writebuf,
00389                      ULONGEST offset, LONGEST len)
00390 {
00391   pid_t pid = ptid_get_pid (inferior_ptid);
00392   int arch64 = ARCH64 ();
00393 
00394   switch (object)
00395     {
00396     case TARGET_OBJECT_LIBRARIES_AIX:
00397       return rs6000_xfer_shared_libraries (ops, object, annex,
00398                                            readbuf, writebuf,
00399                                            offset, len);
00400     case TARGET_OBJECT_MEMORY:
00401       {
00402         union
00403         {
00404           PTRACE_TYPE_RET word;
00405           gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
00406         } buffer;
00407         ULONGEST rounded_offset;
00408         LONGEST partial_len;
00409 
00410         /* Round the start offset down to the next long word
00411            boundary.  */
00412         rounded_offset = offset & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
00413 
00414         /* Since ptrace will transfer a single word starting at that
00415            rounded_offset the partial_len needs to be adjusted down to
00416            that (remember this function only does a single transfer).
00417            Should the required length be even less, adjust it down
00418            again.  */
00419         partial_len = (rounded_offset + sizeof (PTRACE_TYPE_RET)) - offset;
00420         if (partial_len > len)
00421           partial_len = len;
00422 
00423         if (writebuf)
00424           {
00425             /* If OFFSET:PARTIAL_LEN is smaller than
00426                ROUNDED_OFFSET:WORDSIZE then a read/modify write will
00427                be needed.  Read in the entire word.  */
00428             if (rounded_offset < offset
00429                 || (offset + partial_len
00430                     < rounded_offset + sizeof (PTRACE_TYPE_RET)))
00431               {
00432                 /* Need part of initial word -- fetch it.  */
00433                 if (arch64)
00434                   buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
00435                                                  rounded_offset, 0, NULL);
00436                 else
00437                   buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
00438                                                  (int *) (uintptr_t)
00439                                                  rounded_offset,
00440                                                  0, NULL);
00441               }
00442 
00443             /* Copy data to be written over corresponding part of
00444                buffer.  */
00445             memcpy (buffer.byte + (offset - rounded_offset),
00446                     writebuf, partial_len);
00447 
00448             errno = 0;
00449             if (arch64)
00450               rs6000_ptrace64 (PT_WRITE_D, pid,
00451                                rounded_offset, buffer.word, NULL);
00452             else
00453               rs6000_ptrace32 (PT_WRITE_D, pid,
00454                                (int *) (uintptr_t) rounded_offset,
00455                                buffer.word, NULL);
00456             if (errno)
00457               return 0;
00458           }
00459 
00460         if (readbuf)
00461           {
00462             errno = 0;
00463             if (arch64)
00464               buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
00465                                              rounded_offset, 0, NULL);
00466             else
00467               buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
00468                                              (int *)(uintptr_t)rounded_offset,
00469                                              0, NULL);
00470             if (errno)
00471               return 0;
00472 
00473             /* Copy appropriate bytes out of the buffer.  */
00474             memcpy (readbuf, buffer.byte + (offset - rounded_offset),
00475                     partial_len);
00476           }
00477 
00478         return partial_len;
00479       }
00480 
00481     default:
00482       return -1;
00483     }
00484 }
00485 
00486 /* Wait for the child specified by PTID to do something.  Return the
00487    process ID of the child, or MINUS_ONE_PTID in case of error; store
00488    the status in *OURSTATUS.  */
00489 
00490 static ptid_t
00491 rs6000_wait (struct target_ops *ops,
00492              ptid_t ptid, struct target_waitstatus *ourstatus, int options)
00493 {
00494   pid_t pid;
00495   int status, save_errno;
00496 
00497   do
00498     {
00499       set_sigint_trap ();
00500 
00501       do
00502         {
00503           pid = waitpid (ptid_get_pid (ptid), &status, 0);
00504           save_errno = errno;
00505         }
00506       while (pid == -1 && errno == EINTR);
00507 
00508       clear_sigint_trap ();
00509 
00510       if (pid == -1)
00511         {
00512           fprintf_unfiltered (gdb_stderr,
00513                               _("Child process unexpectedly missing: %s.\n"),
00514                               safe_strerror (save_errno));
00515 
00516           /* Claim it exited with unknown signal.  */
00517           ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
00518           ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
00519           return inferior_ptid;
00520         }
00521 
00522       /* Ignore terminated detached child processes.  */
00523       if (!WIFSTOPPED (status) && pid != ptid_get_pid (inferior_ptid))
00524         pid = -1;
00525     }
00526   while (pid == -1);
00527 
00528   /* AIX has a couple of strange returns from wait().  */
00529 
00530   /* stop after load" status.  */
00531   if (status == 0x57c)
00532     ourstatus->kind = TARGET_WAITKIND_LOADED;
00533   /* signal 0.  I have no idea why wait(2) returns with this status word.  */
00534   else if (status == 0x7f)
00535     ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
00536   /* A normal waitstatus.  Let the usual macros deal with it.  */
00537   else
00538     store_waitstatus (ourstatus, status);
00539 
00540   return pid_to_ptid (pid);
00541 }
00542 
00543 /* Execute one dummy breakpoint instruction.  This way we give the kernel
00544    a chance to do some housekeeping and update inferior's internal data,
00545    including u_area.  */
00546 
00547 static void
00548 exec_one_dummy_insn (struct regcache *regcache)
00549 {
00550 #define DUMMY_INSN_ADDR AIX_TEXT_SEGMENT_BASE+0x200
00551 
00552   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00553   int ret, status, pid;
00554   CORE_ADDR prev_pc;
00555   void *bp;
00556 
00557   /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address.  We
00558      assume that this address will never be executed again by the real
00559      code.  */
00560 
00561   bp = deprecated_insert_raw_breakpoint (gdbarch, NULL, DUMMY_INSN_ADDR);
00562 
00563   /* You might think this could be done with a single ptrace call, and
00564      you'd be correct for just about every platform I've ever worked
00565      on.  However, rs6000-ibm-aix4.1.3 seems to have screwed this up --
00566      the inferior never hits the breakpoint (it's also worth noting
00567      powerpc-ibm-aix4.1.3 works correctly).  */
00568   prev_pc = regcache_read_pc (regcache);
00569   regcache_write_pc (regcache, DUMMY_INSN_ADDR);
00570   if (ARCH64 ())
00571     ret = rs6000_ptrace64 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
00572                            1, 0, NULL);
00573   else
00574     ret = rs6000_ptrace32 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
00575                            (int *) 1, 0, NULL);
00576 
00577   if (ret != 0)
00578     perror (_("pt_continue"));
00579 
00580   do
00581     {
00582       pid = waitpid (ptid_get_pid (inferior_ptid), &status, 0);
00583     }
00584   while (pid != ptid_get_pid (inferior_ptid));
00585 
00586   regcache_write_pc (regcache, prev_pc);
00587   deprecated_remove_raw_breakpoint (gdbarch, bp);
00588 }
00589 
00590 
00591 /* Set the current architecture from the host running GDB.  Called when
00592    starting a child process.  */
00593 
00594 static void (*super_create_inferior) (struct target_ops *,char *exec_file, 
00595                                       char *allargs, char **env, int from_tty);
00596 static void
00597 rs6000_create_inferior (struct target_ops * ops, char *exec_file,
00598                         char *allargs, char **env, int from_tty)
00599 {
00600   enum bfd_architecture arch;
00601   unsigned long mach;
00602   bfd abfd;
00603   struct gdbarch_info info;
00604 
00605   super_create_inferior (ops, exec_file, allargs, env, from_tty);
00606 
00607   if (__power_rs ())
00608     {
00609       arch = bfd_arch_rs6000;
00610       mach = bfd_mach_rs6k;
00611     }
00612   else
00613     {
00614       arch = bfd_arch_powerpc;
00615       mach = bfd_mach_ppc;
00616     }
00617 
00618   /* FIXME: schauer/2002-02-25:
00619      We don't know if we are executing a 32 or 64 bit executable,
00620      and have no way to pass the proper word size to rs6000_gdbarch_init.
00621      So we have to avoid switching to a new architecture, if the architecture
00622      matches already.
00623      Blindly calling rs6000_gdbarch_init used to work in older versions of
00624      GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
00625      determine the wordsize.  */
00626   if (exec_bfd)
00627     {
00628       const struct bfd_arch_info *exec_bfd_arch_info;
00629 
00630       exec_bfd_arch_info = bfd_get_arch_info (exec_bfd);
00631       if (arch == exec_bfd_arch_info->arch)
00632         return;
00633     }
00634 
00635   bfd_default_set_arch_mach (&abfd, arch, mach);
00636 
00637   gdbarch_info_init (&info);
00638   info.bfd_arch_info = bfd_get_arch_info (&abfd);
00639   info.abfd = exec_bfd;
00640 
00641   if (!gdbarch_update_p (info))
00642     internal_error (__FILE__, __LINE__,
00643                     _("rs6000_create_inferior: failed "
00644                       "to select architecture"));
00645 }
00646 
00647 
00648 /* Shared Object support.  */
00649 
00650 /* Return the LdInfo data for the given process.  Raises an error
00651    if the data could not be obtained.
00652 
00653    The returned value must be deallocated after use.  */
00654 
00655 static gdb_byte *
00656 rs6000_ptrace_ldinfo (ptid_t ptid)
00657 {
00658   const int pid = ptid_get_pid (ptid);
00659   int ldi_size = 1024;
00660   gdb_byte *ldi = xmalloc (ldi_size);
00661   int rc = -1;
00662 
00663   while (1)
00664     {
00665       if (ARCH64 ())
00666         rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi, ldi_size,
00667                               NULL);
00668       else
00669         rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi, ldi_size, NULL);
00670 
00671       if (rc != -1)
00672         break; /* Success, we got the entire ld_info data.  */
00673 
00674       if (errno != ENOMEM)
00675         perror_with_name (_("ptrace ldinfo"));
00676 
00677       /* ldi is not big enough.  Double it and try again.  */
00678       ldi_size *= 2;
00679       ldi = xrealloc (ldi, ldi_size);
00680     }
00681 
00682   return ldi;
00683 }
00684 
00685 /* Implement the to_xfer_partial target_ops method for
00686    TARGET_OBJECT_LIBRARIES_AIX objects.  */
00687 
00688 static LONGEST
00689 rs6000_xfer_shared_libraries
00690   (struct target_ops *ops, enum target_object object,
00691    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
00692    ULONGEST offset, LONGEST len)
00693 {
00694   gdb_byte *ldi_buf;
00695   ULONGEST result;
00696   struct cleanup *cleanup;
00697 
00698   /* This function assumes that it is being run with a live process.
00699      Core files are handled via gdbarch.  */
00700   gdb_assert (target_has_execution);
00701 
00702   if (writebuf)
00703     return -1;
00704 
00705   ldi_buf = rs6000_ptrace_ldinfo (inferior_ptid);
00706   gdb_assert (ldi_buf != NULL);
00707   cleanup = make_cleanup (xfree, ldi_buf);
00708   result = rs6000_aix_ld_info_to_xml (target_gdbarch (), ldi_buf,
00709                                       readbuf, offset, len, 1);
00710   xfree (ldi_buf);
00711 
00712   do_cleanups (cleanup);
00713   return result;
00714 }
00715 
00716 void _initialize_rs6000_nat (void);
00717 
00718 void
00719 _initialize_rs6000_nat (void)
00720 {
00721   struct target_ops *t;
00722 
00723   t = inf_ptrace_target ();
00724   t->to_fetch_registers = rs6000_fetch_inferior_registers;
00725   t->to_store_registers = rs6000_store_inferior_registers;
00726   t->to_xfer_partial = rs6000_xfer_partial;
00727 
00728   super_create_inferior = t->to_create_inferior;
00729   t->to_create_inferior = rs6000_create_inferior;
00730 
00731   t->to_wait = rs6000_wait;
00732 
00733   add_target (t);
00734 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines