inf-ptrace.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Low level child interface to ptrace.
  2. Copyright (C) 2004-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. #ifndef INF_PTRACE_H
  15. #define INF_PTRACE_H
  16. #include "gdbsupport/event-pipe.h"
  17. #include "inf-child.h"
  18. /* An abstract prototype ptrace target. The client can override it
  19. with local methods. */
  20. struct inf_ptrace_target : public inf_child_target
  21. {
  22. ~inf_ptrace_target () override = 0;
  23. void attach (const char *, int) override;
  24. void detach (inferior *inf, int) override;
  25. void close () override;
  26. void resume (ptid_t, int, enum gdb_signal) override;
  27. ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
  28. void files_info () override;
  29. void kill () override;
  30. void create_inferior (const char *, const std::string &,
  31. char **, int) override;
  32. void mourn_inferior () override;
  33. bool thread_alive (ptid_t ptid) override;
  34. std::string pid_to_str (ptid_t) override;
  35. enum target_xfer_status xfer_partial (enum target_object object,
  36. const char *annex,
  37. gdb_byte *readbuf,
  38. const gdb_byte *writebuf,
  39. ULONGEST offset, ULONGEST len,
  40. ULONGEST *xfered_len) override;
  41. bool is_async_p () override
  42. { return m_event_pipe.is_open (); }
  43. int async_wait_fd () override
  44. { return m_event_pipe.event_fd (); }
  45. /* Helper routine used from SIGCHLD handlers to signal the async
  46. event pipe. */
  47. static void async_file_mark_if_open ()
  48. {
  49. if (m_event_pipe.is_open ())
  50. m_event_pipe.mark ();
  51. }
  52. protected:
  53. /* Helper routines for interacting with the async event pipe. */
  54. bool async_file_open ()
  55. { return m_event_pipe.open_pipe (); }
  56. void async_file_close ()
  57. { m_event_pipe.close_pipe (); }
  58. void async_file_flush ()
  59. { m_event_pipe.flush (); }
  60. void async_file_mark ()
  61. { m_event_pipe.mark (); }
  62. /* Cleanup the inferior after a successful ptrace detach. */
  63. void detach_success (inferior *inf);
  64. /* Some targets don't allow us to request notification of inferior events
  65. such as fork and vfork immediately after the inferior is created.
  66. (This is because of how gdb creates inferiors via invoking a shell to
  67. do it. In such a scenario, if the shell init file has commands in it,
  68. the shell will fork and exec for each of those commands, and we will
  69. see each such fork event. Very bad.)
  70. Such targets will supply an appropriate definition for this
  71. function. */
  72. virtual void post_startup_inferior (ptid_t ptid) = 0;
  73. private:
  74. static event_pipe m_event_pipe;
  75. };
  76. #ifndef __NetBSD__
  77. /* Return which PID to pass to ptrace in order to observe/control the
  78. tracee identified by PTID.
  79. Unlike most other Operating Systems, NetBSD tracks both pid and lwp
  80. and avoids this function. */
  81. extern pid_t get_ptrace_pid (ptid_t);
  82. #endif
  83. #endif