OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_DEBUG_STUB_DEBUG_HOST_H_ | |
8 #define NATIVE_CLIENT_SRC_TRUSTED_DEBUG_STUB_DEBUG_HOST_H_ 1 | |
9 | |
10 #include <map> | |
11 #include "native_client/src/include/portability.h" | |
12 #include "debug_conn/debug_flags.h" | |
13 /* | |
14 * This module provides interfaces for the host side of the | |
15 * connection. | |
16 * | |
17 */ | |
18 | |
19 | |
20 namespace nacl_debug_conn { | |
21 | |
22 class DebugPipe; | |
23 class DebugPacket; | |
24 | |
25 class DebugHost { | |
26 private: | |
27 explicit DebugHost(DebugPipe *pipe); | |
28 | |
29 public: | |
30 enum DHResult { | |
31 DHR_BUSY = -4, // Target is busy (running) | |
32 DHR_FAILED = -3, // Transaction completed with failure | |
33 DHR_LOST = -2, // Lost connection during transaction | |
34 DHR_TIMEOUT =-1, // Transaction Timed out | |
35 DHR_PENDING = 0, // Transaction is pending as expected | |
36 DHR_OK = 1 // Transaction Succeeded | |
37 }; | |
38 | |
39 enum { | |
40 DHF_RUNNING = 1 // Thread info is stale, so reload. | |
41 }; | |
42 | |
43 public: | |
44 typedef void (__stdcall *DHAsync)(DHResult res, void *obj); | |
45 typedef void (__stdcall *DHAsyncStr)(DHResult res, | |
46 void* obj, | |
47 const char* str); | |
48 public: | |
49 ~DebugHost(); | |
50 static DebugHost *SocketConnect(const char *addr); | |
51 | |
52 public: | |
53 void SetOutputAsync(DHAsyncStr reply, void *obj); | |
54 void SetStopAsync(DHAsync reply, void *obj); | |
55 | |
56 DHResult GetArchAsync(DHAsyncStr reply, void *obj); | |
57 DHResult GetThreadsAsync(DHAsyncStr reply, void *obj); | |
58 | |
59 DHResult GetLastSig(int *sig); | |
60 | |
61 DHResult GetMemory(uint64_t offs, void *buf, uint32_t max); | |
62 DHResult SetMemory(uint64_t offs, void *data, uint32_t max); | |
63 | |
64 DHResult GetRegisters(void *data, uint32_t max); | |
65 DHResult SetRegisters(void *data, uint32_t size); | |
66 | |
67 DHResult RequestBreak(); // Attempts to immediately break | |
68 DHResult RequestContinue(); // Continues execution, not blocking. | |
69 DHResult RequestStep(); // Continues exectuion for one step or | |
70 // until next exception. | |
71 | |
72 bool HasBreakpoint(uint64_t offs); | |
73 DHResult AddBreakpoint(uint64_t offs); | |
74 DHResult RemoveBreakpoint(uint64_t offs); | |
75 | |
76 bool IsRunning(); | |
77 DebugHost::DHResult WaitForReply(); | |
78 | |
79 protected: | |
80 DHResult SendStringAsync(const char *str, DHAsyncStr reply, void *obj); | |
81 DHResult SendString(const char *str, const char **ppReply); | |
82 DHResult RequestStepBackground(); // Attempts to step but returns | |
83 // immediately. | |
84 struct BreakpointRecord { | |
85 uint64_t offs; | |
86 bool enabled; | |
87 bool suspended; | |
88 char previousContents; | |
89 }; | |
90 | |
91 DHResult EnableBreakpoint(uint64_t offs); | |
92 DHResult DisableBreakpoint(uint64_t offs); | |
93 DHResult SuspendBreakpoint(uint64_t offs); | |
94 DHResult ResumeBreakpoint(uint64_t offs); | |
95 | |
96 DHResult FetchThreadInfo(); | |
97 DHResult Transact(DebugPacket *outPkt, DebugPacket *in); | |
98 DHResult SendAndWaitForBreak(const char *str, bool wait); | |
99 DHResult BreakpointStatusChanged(uint64_t offs); | |
100 | |
101 private: | |
102 DebugPipe *pipe_; | |
103 std::map<uint64_t, BreakpointRecord> breaks_; | |
104 DHAsyncStr outputFunc_; | |
105 void *outputObj_; | |
106 DHAsync stopFunc_; | |
107 void *stopObj_; | |
108 DebugFlags flags_; | |
109 }; | |
110 | |
111 | |
112 } // namespace nacl_debug_conn | |
113 | |
114 | |
115 #endif | |
116 | |
OLD | NEW |