OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #ifndef EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_API_LINUX_H_ | |
5 #define EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_API_LINUX_H_ | |
6 | |
7 #include <signal.h> | |
8 #include <sys/ptrace.h> | |
9 #include <sys/types.h> | |
10 #include <sys/user.h> | |
11 | |
12 #include <deque> | |
13 #include <string> | |
14 | |
15 // some usefull string functions | |
16 void Split(const char* str_in, | |
17 const char* delimiters, | |
18 std::deque<std::string>* out); | |
19 std::string GetAppPathOutOfCmdLine(const char* cmd_line); | |
20 std::string GetAppNameOutOfCmdLine(const char* cmd_line); | |
21 | |
22 namespace debug { | |
23 class DebugEvent; | |
24 | |
25 class DebugApi { | |
26 public: | |
27 DebugApi() {} | |
28 virtual ~DebugApi() {} | |
29 | |
30 virtual bool StartProcess(const char* cmd_line, | |
31 bool trace, | |
32 pid_t* child_pid_out); | |
33 virtual bool SetupProc(pid_t pid); | |
34 virtual bool GetNewChildPid(pid_t pid, pid_t* child_pid_out); | |
35 | |
36 virtual bool DebugBreak(pid_t pid); | |
37 virtual bool SingleStep(pid_t pid); | |
38 | |
39 virtual bool EnableSingleStep(pid_t pid, bool enable); | |
40 virtual bool PostASignal(pid_t pid, int signo, int sig_value); | |
41 virtual bool PostASignal(pid_t pid, int signo, void* sig_value); | |
42 | |
43 virtual bool WaitForDebugEvent(DebugEvent* de); //TODO: add optional pid | |
44 virtual bool ContinueDebugEvent(pid_t process_id, int signo); | |
45 | |
46 virtual bool ReadDebugString(DebugEvent* de, std::string* string); | |
47 | |
48 virtual bool ReadProcessMemory(pid_t pid, | |
49 void* addr, | |
50 void* dest, | |
51 size_t size, | |
52 size_t* readed_bytes_out); | |
53 | |
54 virtual bool WriteProcessMemory(pid_t pid, | |
55 void* addr, | |
56 void* src, | |
57 size_t size, | |
58 size_t* written_bytes_out); | |
59 | |
60 virtual bool ReadThreadContext(pid_t pid, user_regs_struct* context); | |
61 virtual bool WriteThreadContext(pid_t pid, user_regs_struct* context); | |
62 virtual void PrintThreadContext(const user_regs_struct& context); | |
63 | |
64 virtual bool GetIp(pid_t pid, char** ip); | |
65 virtual bool SetIp(pid_t pid, char* ip); | |
66 virtual bool GetRax(pid_t pid, char** ip); | |
67 }; | |
68 | |
69 static const int EVENT_FORK = (SIGTRAP | (PTRACE_EVENT_FORK << 8)); | |
70 static const int EVENT_VFORK = (SIGTRAP | (PTRACE_EVENT_VFORK << 8)); | |
71 static const int EVENT_CLONE = (SIGTRAP | (PTRACE_EVENT_CLONE << 8)); | |
72 static const int EVENT_EXEC = (SIGTRAP | (PTRACE_EVENT_EXEC << 8)); | |
73 static const int EVENT_VFORK_DONE = (SIGTRAP | (PTRACE_EVENT_VFORK_DONE << 8)); | |
74 static const int EVENT_EXIT = (SIGTRAP | (PTRACE_EVENT_EXIT << 8)); | |
75 | |
76 class DebugEvent { | |
77 public: | |
78 enum EventCode {UNKNOWN, | |
79 HIT_BREAKPOINT, | |
80 SINGLE_STEP_TRAP, | |
81 OUTPUT_DEBUG_STRING, | |
82 PROCESS_TERMINATED, // child process terminated due | |
83 // to the receipt of a signal that was not caught. | |
84 PROCESS_EXITED, | |
85 PROCESS_STOPPED, | |
86 PROCESS_CONTINUED_WITH_SIGCONT}; | |
87 | |
88 DebugEvent() { Reset(); } | |
89 | |
90 void Reset(); | |
91 void Print(); | |
92 bool IsProcessDied() { return event_code_ == PROCESS_EXITED; } | |
93 | |
94 pid_t process_id_; | |
95 EventCode event_code_; | |
96 int signal_no_; | |
97 int signal_code_; | |
98 sigval signal_value_; | |
99 int exit_code_; | |
100 char* ip_; | |
101 char* addr_; | |
102 }; | |
103 | |
104 } // namespace debug | |
105 #endif // EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_API_LINUX_H_ | |
106 | |
OLD | NEW |