_UPT_access_mem.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003-2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
  5. This file is part of libunwind.
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22. #include "_UPT_internal.h"
  23. #if HAVE_DECL_PTRACE_POKEDATA || HAVE_TTRACE
  24. int
  25. _UPT_access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val,
  26. int write, void *arg)
  27. {
  28. struct UPT_info *ui = arg;
  29. pid_t pid = ui->pid;
  30. errno = 0;
  31. if (write)
  32. {
  33. Debug (16, "mem[%lx] <- %lx\n", (long) addr, (long) *val);
  34. #ifdef HAVE_TTRACE
  35. # warning No support for ttrace() yet.
  36. #else
  37. ptrace (PTRACE_POKEDATA, pid, addr, *val);
  38. if (errno)
  39. return -UNW_EINVAL;
  40. #endif
  41. }
  42. else
  43. {
  44. #ifdef HAVE_TTRACE
  45. # warning No support for ttrace() yet.
  46. #else
  47. *val = ptrace (PTRACE_PEEKDATA, pid, addr, 0);
  48. if (errno)
  49. return -UNW_EINVAL;
  50. #endif
  51. Debug (16, "mem[%lx] -> %lx\n", (long) addr, (long) *val);
  52. }
  53. return 0;
  54. }
  55. #elif HAVE_DECL_PT_IO
  56. int
  57. _UPT_access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val,
  58. int write, void *arg)
  59. {
  60. struct UPT_info *ui = arg;
  61. pid_t pid = ui->pid;
  62. struct ptrace_io_desc iod;
  63. iod.piod_offs = (void *)addr;
  64. iod.piod_addr = val;
  65. iod.piod_len = sizeof(*val);
  66. iod.piod_op = write ? PIOD_WRITE_D : PIOD_READ_D;
  67. if (write)
  68. Debug (16, "mem[%lx] <- %lx\n", (long) addr, (long) *val);
  69. if (ptrace(PT_IO, pid, (caddr_t)&iod, 0) == -1)
  70. return -UNW_EINVAL;
  71. if (!write)
  72. Debug (16, "mem[%lx] -> %lx\n", (long) addr, (long) *val);
  73. return 0;
  74. }
  75. #else
  76. #error Fix me
  77. #endif