rs6000-aix-nat.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "inferior.h"
  16. #include "target.h"
  17. #include "gdbcore.h"
  18. #include "symfile.h"
  19. #include "objfiles.h"
  20. #include "bfd.h"
  21. #include "gdb-stabs.h"
  22. #include "regcache.h"
  23. #include "arch-utils.h"
  24. #include "inf-child.h"
  25. #include "inf-ptrace.h"
  26. #include "ppc-tdep.h"
  27. #include "rs6000-aix-tdep.h"
  28. #include "exec.h"
  29. #include "observable.h"
  30. #include "xcoffread.h"
  31. #include <sys/ptrace.h>
  32. #include <sys/reg.h>
  33. #include <sys/dir.h>
  34. #include <sys/user.h>
  35. #include <signal.h>
  36. #include <sys/ioctl.h>
  37. #include <fcntl.h>
  38. #include <a.out.h>
  39. #include <sys/file.h>
  40. #include <sys/stat.h>
  41. #include "gdb_bfd.h"
  42. #include <sys/core.h>
  43. #define __LDINFO_PTRACE32__ /* for __ld_info32 */
  44. #define __LDINFO_PTRACE64__ /* for __ld_info64 */
  45. #include <sys/ldr.h>
  46. #include <sys/systemcfg.h>
  47. /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
  48. debugging 32-bit and 64-bit processes. Define a typedef and macros for
  49. accessing fields in the appropriate structures. */
  50. /* In 32-bit compilation mode (which is the only mode from which ptrace()
  51. works on 4.3), __ld_info32 is #defined as equivalent to ld_info. */
  52. #if defined (__ld_info32) || defined (__ld_info64)
  53. # define ARCH3264
  54. #endif
  55. /* Return whether the current architecture is 64-bit. */
  56. #ifndef ARCH3264
  57. # define ARCH64() 0
  58. #else
  59. # define ARCH64() (register_size (target_gdbarch (), 0) == 8)
  60. #endif
  61. class rs6000_nat_target final : public inf_ptrace_target
  62. {
  63. public:
  64. void fetch_registers (struct regcache *, int) override;
  65. void store_registers (struct regcache *, int) override;
  66. enum target_xfer_status xfer_partial (enum target_object object,
  67. const char *annex,
  68. gdb_byte *readbuf,
  69. const gdb_byte *writebuf,
  70. ULONGEST offset, ULONGEST len,
  71. ULONGEST *xfered_len) override;
  72. void create_inferior (const char *, const std::string &,
  73. char **, int) override;
  74. ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
  75. protected:
  76. void post_startup_inferior (ptid_t ptid) override
  77. { /* Nothing. */ }
  78. private:
  79. enum target_xfer_status
  80. xfer_shared_libraries (enum target_object object,
  81. const char *annex, gdb_byte *readbuf,
  82. const gdb_byte *writebuf,
  83. ULONGEST offset, ULONGEST len,
  84. ULONGEST *xfered_len);
  85. };
  86. static rs6000_nat_target the_rs6000_nat_target;
  87. /* Given REGNO, a gdb register number, return the corresponding
  88. number suitable for use as a ptrace() parameter. Return -1 if
  89. there's no suitable mapping. Also, set the int pointed to by
  90. ISFLOAT to indicate whether REGNO is a floating point register. */
  91. static int
  92. regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
  93. {
  94. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  95. *isfloat = 0;
  96. if (tdep->ppc_gp0_regnum <= regno
  97. && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
  98. return regno;
  99. else if (tdep->ppc_fp0_regnum >= 0
  100. && tdep->ppc_fp0_regnum <= regno
  101. && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
  102. {
  103. *isfloat = 1;
  104. return regno - tdep->ppc_fp0_regnum + FPR0;
  105. }
  106. else if (regno == gdbarch_pc_regnum (gdbarch))
  107. return IAR;
  108. else if (regno == tdep->ppc_ps_regnum)
  109. return MSR;
  110. else if (regno == tdep->ppc_cr_regnum)
  111. return CR;
  112. else if (regno == tdep->ppc_lr_regnum)
  113. return LR;
  114. else if (regno == tdep->ppc_ctr_regnum)
  115. return CTR;
  116. else if (regno == tdep->ppc_xer_regnum)
  117. return XER;
  118. else if (tdep->ppc_fpscr_regnum >= 0
  119. && regno == tdep->ppc_fpscr_regnum)
  120. return FPSCR;
  121. else if (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum)
  122. return MQ;
  123. else
  124. return -1;
  125. }
  126. /* Call ptrace(REQ, ID, ADDR, DATA, BUF). */
  127. static int
  128. rs6000_ptrace32 (int req, int id, int *addr, int data, int *buf)
  129. {
  130. #ifdef HAVE_PTRACE64
  131. int ret = ptrace64 (req, id, (uintptr_t) addr, data, buf);
  132. #else
  133. int ret = ptrace (req, id, (int *)addr, data, buf);
  134. #endif
  135. #if 0
  136. printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
  137. req, id, (unsigned int)addr, data, (unsigned int)buf, ret);
  138. #endif
  139. return ret;
  140. }
  141. /* Call ptracex(REQ, ID, ADDR, DATA, BUF). */
  142. static int
  143. rs6000_ptrace64 (int req, int id, long long addr, int data, void *buf)
  144. {
  145. #ifdef ARCH3264
  146. # ifdef HAVE_PTRACE64
  147. int ret = ptrace64 (req, id, addr, data, (PTRACE_TYPE_ARG5) buf);
  148. # else
  149. int ret = ptracex (req, id, addr, data, (PTRACE_TYPE_ARG5) buf);
  150. # endif
  151. #else
  152. int ret = 0;
  153. #endif
  154. #if 0
  155. printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
  156. req, id, hex_string (addr), data, (unsigned int)buf, ret);
  157. #endif
  158. return ret;
  159. }
  160. /* Fetch register REGNO from the inferior. */
  161. static void
  162. fetch_register (struct regcache *regcache, int regno)
  163. {
  164. struct gdbarch *gdbarch = regcache->arch ();
  165. int addr[PPC_MAX_REGISTER_SIZE];
  166. int nr, isfloat;
  167. pid_t pid = regcache->ptid ().pid ();
  168. /* Retrieved values may be -1, so infer errors from errno. */
  169. errno = 0;
  170. nr = regmap (gdbarch, regno, &isfloat);
  171. /* Floating-point registers. */
  172. if (isfloat)
  173. rs6000_ptrace32 (PT_READ_FPR, pid, addr, nr, 0);
  174. /* Bogus register number. */
  175. else if (nr < 0)
  176. {
  177. if (regno >= gdbarch_num_regs (gdbarch))
  178. gdb_printf (gdb_stderr,
  179. "gdb error: register no %d not implemented.\n",
  180. regno);
  181. return;
  182. }
  183. /* Fixed-point registers. */
  184. else
  185. {
  186. if (!ARCH64 ())
  187. *addr = rs6000_ptrace32 (PT_READ_GPR, pid, (int *) nr, 0, 0);
  188. else
  189. {
  190. /* PT_READ_GPR requires the buffer parameter to point to long long,
  191. even if the register is really only 32 bits. */
  192. long long buf;
  193. rs6000_ptrace64 (PT_READ_GPR, pid, nr, 0, &buf);
  194. if (register_size (gdbarch, regno) == 8)
  195. memcpy (addr, &buf, 8);
  196. else
  197. *addr = buf;
  198. }
  199. }
  200. if (!errno)
  201. regcache->raw_supply (regno, (char *) addr);
  202. else
  203. {
  204. #if 0
  205. /* FIXME: this happens 3 times at the start of each 64-bit program. */
  206. perror (_("ptrace read"));
  207. #endif
  208. errno = 0;
  209. }
  210. }
  211. /* Store register REGNO back into the inferior. */
  212. static void
  213. store_register (struct regcache *regcache, int regno)
  214. {
  215. struct gdbarch *gdbarch = regcache->arch ();
  216. int addr[PPC_MAX_REGISTER_SIZE];
  217. int nr, isfloat;
  218. pid_t pid = regcache->ptid ().pid ();
  219. /* Fetch the register's value from the register cache. */
  220. regcache->raw_collect (regno, addr);
  221. /* -1 can be a successful return value, so infer errors from errno. */
  222. errno = 0;
  223. nr = regmap (gdbarch, regno, &isfloat);
  224. /* Floating-point registers. */
  225. if (isfloat)
  226. rs6000_ptrace32 (PT_WRITE_FPR, pid, addr, nr, 0);
  227. /* Bogus register number. */
  228. else if (nr < 0)
  229. {
  230. if (regno >= gdbarch_num_regs (gdbarch))
  231. gdb_printf (gdb_stderr,
  232. "gdb error: register no %d not implemented.\n",
  233. regno);
  234. }
  235. /* Fixed-point registers. */
  236. else
  237. {
  238. /* The PT_WRITE_GPR operation is rather odd. For 32-bit inferiors,
  239. the register's value is passed by value, but for 64-bit inferiors,
  240. the address of a buffer containing the value is passed. */
  241. if (!ARCH64 ())
  242. rs6000_ptrace32 (PT_WRITE_GPR, pid, (int *) nr, *addr, 0);
  243. else
  244. {
  245. /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
  246. area, even if the register is really only 32 bits. */
  247. long long buf;
  248. if (register_size (gdbarch, regno) == 8)
  249. memcpy (&buf, addr, 8);
  250. else
  251. buf = *addr;
  252. rs6000_ptrace64 (PT_WRITE_GPR, pid, nr, 0, &buf);
  253. }
  254. }
  255. if (errno)
  256. {
  257. perror (_("ptrace write"));
  258. errno = 0;
  259. }
  260. }
  261. /* Read from the inferior all registers if REGNO == -1 and just register
  262. REGNO otherwise. */
  263. void
  264. rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
  265. {
  266. struct gdbarch *gdbarch = regcache->arch ();
  267. if (regno != -1)
  268. fetch_register (regcache, regno);
  269. else
  270. {
  271. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  272. /* Read 32 general purpose registers. */
  273. for (regno = tdep->ppc_gp0_regnum;
  274. regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
  275. regno++)
  276. {
  277. fetch_register (regcache, regno);
  278. }
  279. /* Read general purpose floating point registers. */
  280. if (tdep->ppc_fp0_regnum >= 0)
  281. for (regno = 0; regno < ppc_num_fprs; regno++)
  282. fetch_register (regcache, tdep->ppc_fp0_regnum + regno);
  283. /* Read special registers. */
  284. fetch_register (regcache, gdbarch_pc_regnum (gdbarch));
  285. fetch_register (regcache, tdep->ppc_ps_regnum);
  286. fetch_register (regcache, tdep->ppc_cr_regnum);
  287. fetch_register (regcache, tdep->ppc_lr_regnum);
  288. fetch_register (regcache, tdep->ppc_ctr_regnum);
  289. fetch_register (regcache, tdep->ppc_xer_regnum);
  290. if (tdep->ppc_fpscr_regnum >= 0)
  291. fetch_register (regcache, tdep->ppc_fpscr_regnum);
  292. if (tdep->ppc_mq_regnum >= 0)
  293. fetch_register (regcache, tdep->ppc_mq_regnum);
  294. }
  295. }
  296. /* Store our register values back into the inferior.
  297. If REGNO is -1, do this for all registers.
  298. Otherwise, REGNO specifies which register (so we can save time). */
  299. void
  300. rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
  301. {
  302. struct gdbarch *gdbarch = regcache->arch ();
  303. if (regno != -1)
  304. store_register (regcache, regno);
  305. else
  306. {
  307. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  308. /* Write general purpose registers first. */
  309. for (regno = tdep->ppc_gp0_regnum;
  310. regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
  311. regno++)
  312. {
  313. store_register (regcache, regno);
  314. }
  315. /* Write floating point registers. */
  316. if (tdep->ppc_fp0_regnum >= 0)
  317. for (regno = 0; regno < ppc_num_fprs; regno++)
  318. store_register (regcache, tdep->ppc_fp0_regnum + regno);
  319. /* Write special registers. */
  320. store_register (regcache, gdbarch_pc_regnum (gdbarch));
  321. store_register (regcache, tdep->ppc_ps_regnum);
  322. store_register (regcache, tdep->ppc_cr_regnum);
  323. store_register (regcache, tdep->ppc_lr_regnum);
  324. store_register (regcache, tdep->ppc_ctr_regnum);
  325. store_register (regcache, tdep->ppc_xer_regnum);
  326. if (tdep->ppc_fpscr_regnum >= 0)
  327. store_register (regcache, tdep->ppc_fpscr_regnum);
  328. if (tdep->ppc_mq_regnum >= 0)
  329. store_register (regcache, tdep->ppc_mq_regnum);
  330. }
  331. }
  332. /* Implement the to_xfer_partial target_ops method. */
  333. enum target_xfer_status
  334. rs6000_nat_target::xfer_partial (enum target_object object,
  335. const char *annex, gdb_byte *readbuf,
  336. const gdb_byte *writebuf,
  337. ULONGEST offset, ULONGEST len,
  338. ULONGEST *xfered_len)
  339. {
  340. pid_t pid = inferior_ptid.pid ();
  341. int arch64 = ARCH64 ();
  342. switch (object)
  343. {
  344. case TARGET_OBJECT_LIBRARIES_AIX:
  345. return xfer_shared_libraries (object, annex,
  346. readbuf, writebuf,
  347. offset, len, xfered_len);
  348. case TARGET_OBJECT_MEMORY:
  349. {
  350. union
  351. {
  352. PTRACE_TYPE_RET word;
  353. gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
  354. } buffer;
  355. ULONGEST rounded_offset;
  356. LONGEST partial_len;
  357. /* Round the start offset down to the next long word
  358. boundary. */
  359. rounded_offset = offset & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
  360. /* Since ptrace will transfer a single word starting at that
  361. rounded_offset the partial_len needs to be adjusted down to
  362. that (remember this function only does a single transfer).
  363. Should the required length be even less, adjust it down
  364. again. */
  365. partial_len = (rounded_offset + sizeof (PTRACE_TYPE_RET)) - offset;
  366. if (partial_len > len)
  367. partial_len = len;
  368. if (writebuf)
  369. {
  370. /* If OFFSET:PARTIAL_LEN is smaller than
  371. ROUNDED_OFFSET:WORDSIZE then a read/modify write will
  372. be needed. Read in the entire word. */
  373. if (rounded_offset < offset
  374. || (offset + partial_len
  375. < rounded_offset + sizeof (PTRACE_TYPE_RET)))
  376. {
  377. /* Need part of initial word -- fetch it. */
  378. if (arch64)
  379. buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
  380. rounded_offset, 0, NULL);
  381. else
  382. buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
  383. (int *) (uintptr_t)
  384. rounded_offset,
  385. 0, NULL);
  386. }
  387. /* Copy data to be written over corresponding part of
  388. buffer. */
  389. memcpy (buffer.byte + (offset - rounded_offset),
  390. writebuf, partial_len);
  391. errno = 0;
  392. if (arch64)
  393. rs6000_ptrace64 (PT_WRITE_D, pid,
  394. rounded_offset, buffer.word, NULL);
  395. else
  396. rs6000_ptrace32 (PT_WRITE_D, pid,
  397. (int *) (uintptr_t) rounded_offset,
  398. buffer.word, NULL);
  399. if (errno)
  400. return TARGET_XFER_EOF;
  401. }
  402. if (readbuf)
  403. {
  404. errno = 0;
  405. if (arch64)
  406. buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
  407. rounded_offset, 0, NULL);
  408. else
  409. buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
  410. (int *)(uintptr_t)rounded_offset,
  411. 0, NULL);
  412. if (errno)
  413. return TARGET_XFER_EOF;
  414. /* Copy appropriate bytes out of the buffer. */
  415. memcpy (readbuf, buffer.byte + (offset - rounded_offset),
  416. partial_len);
  417. }
  418. *xfered_len = (ULONGEST) partial_len;
  419. return TARGET_XFER_OK;
  420. }
  421. default:
  422. return TARGET_XFER_E_IO;
  423. }
  424. }
  425. /* Wait for the child specified by PTID to do something. Return the
  426. process ID of the child, or MINUS_ONE_PTID in case of error; store
  427. the status in *OURSTATUS. */
  428. ptid_t
  429. rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
  430. target_wait_flags options)
  431. {
  432. pid_t pid;
  433. int status, save_errno;
  434. do
  435. {
  436. set_sigint_trap ();
  437. do
  438. {
  439. pid = waitpid (ptid.pid (), &status, 0);
  440. save_errno = errno;
  441. }
  442. while (pid == -1 && errno == EINTR);
  443. clear_sigint_trap ();
  444. if (pid == -1)
  445. {
  446. gdb_printf (gdb_stderr,
  447. _("Child process unexpectedly missing: %s.\n"),
  448. safe_strerror (save_errno));
  449. /* Claim it exited with unknown signal. */
  450. ourstatus->set_signalled (GDB_SIGNAL_UNKNOWN);
  451. return inferior_ptid;
  452. }
  453. /* Ignore terminated detached child processes. */
  454. if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
  455. pid = -1;
  456. }
  457. while (pid == -1);
  458. /* AIX has a couple of strange returns from wait(). */
  459. /* stop after load" status. */
  460. if (status == 0x57c)
  461. ourstatus->set_loaded ();
  462. /* signal 0. I have no idea why wait(2) returns with this status word. */
  463. else if (status == 0x7f)
  464. ourstatus->set_spurious ();
  465. /* A normal waitstatus. Let the usual macros deal with it. */
  466. else
  467. *ourstatus = host_status_to_waitstatus (status);
  468. return ptid_t (pid);
  469. }
  470. /* Set the current architecture from the host running GDB. Called when
  471. starting a child process. */
  472. void
  473. rs6000_nat_target::create_inferior (const char *exec_file,
  474. const std::string &allargs,
  475. char **env, int from_tty)
  476. {
  477. enum bfd_architecture arch;
  478. unsigned long mach;
  479. bfd abfd;
  480. inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
  481. if (__power_rs ())
  482. {
  483. arch = bfd_arch_rs6000;
  484. mach = bfd_mach_rs6k;
  485. }
  486. else
  487. {
  488. arch = bfd_arch_powerpc;
  489. mach = bfd_mach_ppc;
  490. }
  491. /* FIXME: schauer/2002-02-25:
  492. We don't know if we are executing a 32 or 64 bit executable,
  493. and have no way to pass the proper word size to rs6000_gdbarch_init.
  494. So we have to avoid switching to a new architecture, if the architecture
  495. matches already.
  496. Blindly calling rs6000_gdbarch_init used to work in older versions of
  497. GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
  498. determine the wordsize. */
  499. if (current_program_space->exec_bfd ())
  500. {
  501. const struct bfd_arch_info *exec_bfd_arch_info;
  502. exec_bfd_arch_info
  503. = bfd_get_arch_info (current_program_space->exec_bfd ());
  504. if (arch == exec_bfd_arch_info->arch)
  505. return;
  506. }
  507. bfd_default_set_arch_mach (&abfd, arch, mach);
  508. gdbarch_info info;
  509. info.bfd_arch_info = bfd_get_arch_info (&abfd);
  510. info.abfd = current_program_space->exec_bfd ();
  511. if (!gdbarch_update_p (info))
  512. internal_error (__FILE__, __LINE__,
  513. _("rs6000_create_inferior: failed "
  514. "to select architecture"));
  515. }
  516. /* Shared Object support. */
  517. /* Return the LdInfo data for the given process. Raises an error
  518. if the data could not be obtained. */
  519. static gdb::byte_vector
  520. rs6000_ptrace_ldinfo (ptid_t ptid)
  521. {
  522. const int pid = ptid.pid ();
  523. gdb::byte_vector ldi (1024);
  524. int rc = -1;
  525. while (1)
  526. {
  527. if (ARCH64 ())
  528. rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi.data (),
  529. ldi.size (), NULL);
  530. else
  531. rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi.data (),
  532. ldi.size (), NULL);
  533. if (rc != -1)
  534. break; /* Success, we got the entire ld_info data. */
  535. if (errno != ENOMEM)
  536. perror_with_name (_("ptrace ldinfo"));
  537. /* ldi is not big enough. Double it and try again. */
  538. ldi.resize (ldi.size () * 2);
  539. }
  540. return ldi;
  541. }
  542. /* Implement the to_xfer_partial target_ops method for
  543. TARGET_OBJECT_LIBRARIES_AIX objects. */
  544. enum target_xfer_status
  545. rs6000_nat_target::xfer_shared_libraries
  546. (enum target_object object,
  547. const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
  548. ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
  549. {
  550. ULONGEST result;
  551. /* This function assumes that it is being run with a live process.
  552. Core files are handled via gdbarch. */
  553. gdb_assert (target_has_execution ());
  554. if (writebuf)
  555. return TARGET_XFER_E_IO;
  556. gdb::byte_vector ldi_buf = rs6000_ptrace_ldinfo (inferior_ptid);
  557. result = rs6000_aix_ld_info_to_xml (target_gdbarch (), ldi_buf.data (),
  558. readbuf, offset, len, 1);
  559. if (result == 0)
  560. return TARGET_XFER_EOF;
  561. else
  562. {
  563. *xfered_len = result;
  564. return TARGET_XFER_OK;
  565. }
  566. }
  567. void _initialize_rs6000_nat ();
  568. void
  569. _initialize_rs6000_nat ()
  570. {
  571. add_inf_child_target (&the_rs6000_nat_target);
  572. }