]>
Commit | Line | Data |
---|---|---|
8785ced0 | 1 | /* Low level child interface to ptrace. |
5bf970f9 | 2 | |
1d506c26 | 3 | Copyright (C) 2004-2024 Free Software Foundation, Inc. |
5bf970f9 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
5bf970f9 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5bf970f9 AC |
19 | |
20 | #ifndef INF_PTRACE_H | |
21 | #define INF_PTRACE_H | |
22 | ||
b146ba14 | 23 | #include "gdbsupport/event-pipe.h" |
f6ac5f3d | 24 | #include "inf-child.h" |
5bf970f9 | 25 | |
f6ac5f3d PA |
26 | /* An abstract prototype ptrace target. The client can override it |
27 | with local methods. */ | |
5bf970f9 | 28 | |
f6ac5f3d PA |
29 | struct inf_ptrace_target : public inf_child_target |
30 | { | |
31 | ~inf_ptrace_target () override = 0; | |
8785ced0 | 32 | |
f6ac5f3d PA |
33 | void attach (const char *, int) override; |
34 | ||
35 | void detach (inferior *inf, int) override; | |
36 | ||
b146ba14 JB |
37 | void close () override; |
38 | ||
f6ac5f3d PA |
39 | void resume (ptid_t, int, enum gdb_signal) override; |
40 | ||
b60cea74 | 41 | ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override; |
f6ac5f3d PA |
42 | |
43 | void files_info () override; | |
44 | ||
45 | void kill () override; | |
46 | ||
47 | void create_inferior (const char *, const std::string &, | |
48 | char **, int) override; | |
f6ac5f3d PA |
49 | |
50 | void mourn_inferior () override; | |
51 | ||
57810aa7 | 52 | bool thread_alive (ptid_t ptid) override; |
f6ac5f3d | 53 | |
a068643d | 54 | std::string pid_to_str (ptid_t) override; |
f6ac5f3d PA |
55 | |
56 | enum target_xfer_status xfer_partial (enum target_object object, | |
57 | const char *annex, | |
58 | gdb_byte *readbuf, | |
59 | const gdb_byte *writebuf, | |
60 | ULONGEST offset, ULONGEST len, | |
61 | ULONGEST *xfered_len) override; | |
62 | ||
b146ba14 JB |
63 | bool is_async_p () override |
64 | { return m_event_pipe.is_open (); } | |
65 | ||
66 | int async_wait_fd () override | |
67 | { return m_event_pipe.event_fd (); } | |
68 | ||
69 | /* Helper routine used from SIGCHLD handlers to signal the async | |
70 | event pipe. */ | |
71 | static void async_file_mark_if_open () | |
72 | { | |
73 | if (m_event_pipe.is_open ()) | |
74 | m_event_pipe.mark (); | |
75 | } | |
76 | ||
f6ac5f3d | 77 | protected: |
b146ba14 JB |
78 | /* Helper routines for interacting with the async event pipe. */ |
79 | bool async_file_open () | |
8674f082 | 80 | { return m_event_pipe.open_pipe (); } |
b146ba14 | 81 | void async_file_close () |
8674f082 | 82 | { m_event_pipe.close_pipe (); } |
b146ba14 JB |
83 | void async_file_flush () |
84 | { m_event_pipe.flush (); } | |
85 | void async_file_mark () | |
86 | { m_event_pipe.mark (); } | |
87 | ||
f6ac5f3d PA |
88 | /* Cleanup the inferior after a successful ptrace detach. */ |
89 | void detach_success (inferior *inf); | |
200fd287 AB |
90 | |
91 | /* Some targets don't allow us to request notification of inferior events | |
92 | such as fork and vfork immediately after the inferior is created. | |
93 | (This is because of how gdb creates inferiors via invoking a shell to | |
94 | do it. In such a scenario, if the shell init file has commands in it, | |
95 | the shell will fork and exec for each of those commands, and we will | |
96 | see each such fork event. Very bad.) | |
97 | ||
98 | Such targets will supply an appropriate definition for this | |
99 | function. */ | |
100 | virtual void post_startup_inferior (ptid_t ptid) = 0; | |
b146ba14 JB |
101 | |
102 | private: | |
103 | static event_pipe m_event_pipe; | |
f6ac5f3d | 104 | }; |
8785ced0 | 105 | |
f09db380 | 106 | #ifndef __NetBSD__ |
94309df7 | 107 | /* Return which PID to pass to ptrace in order to observe/control the |
f09db380 KR |
108 | tracee identified by PTID. |
109 | ||
110 | Unlike most other Operating Systems, NetBSD tracks both pid and lwp | |
111 | and avoids this function. */ | |
94309df7 JB |
112 | |
113 | extern pid_t get_ptrace_pid (ptid_t); | |
f09db380 | 114 | #endif |
94309df7 | 115 | |
5bf970f9 | 116 | #endif |