Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: src/trusted/gdb_rsp/target.h

Issue 5633007: This change contains changes that were made on a separate copy of this code,... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The Native Client Authors. All rights reserved. 2 * Copyright 2010 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 // This module provides interfaces for accessing the debugging state of 8 // This module provides interfaces for accessing the debugging state of
9 // the target. The target can use either the thread that took the 9 // the target. The target can use either the thread that took the
10 // exception or run in it's own thread. To respond to the host, the 10 // exception or run in it's own thread. To respond to the host, the
11 // application must call the run function with a valid Transport 11 // application must call the run function with a valid Transport
12 // which will then be polled for commands. The target will return 12 // which will then be polled for commands. The target will return
13 // from Run when the host disconnects, or requests a continue. 13 // from Run when the host disconnects, or requests a continue.
14 // 14 //
15 // The object is protected by a mutex, so that it is legal to track or 15 // The object is protected by a mutex, so that it is legal to track or
16 // ignore threads as an exception takes place. 16 // ignore threads as an exception takes place.
17 // 17 //
18 // The Run function expects that all threads of interest are stopped 18 // The Run function expects that all threads of interest are stopped
19 // with the Step flag cleared before Run is called. It is expected that 19 // with the Step flag cleared before Run is called. It is expected that
20 // and that all threads are updated with thier modified contexts and 20 // and that all threads are updated with thier modified contexts and
21 // restarted when the target returns from Run. 21 // restarted when the target returns from Run.
22 22
23 #ifndef NATIVE_CLIENT_GDB_RSP_TARGET_H_ 23 #ifndef SRC_TRUSTED_GDB_RSP_TARGET_H_
24 #define NATIVE_CLIENT_GDB_RSP_TARGET_H_ 1 24 #define SRC_TRUSTED_GDB_RSP_TARGET_H_ 1
25 25
26 #include <map> 26 #include <map>
27 #include <string> 27 #include <string>
28 28
29 #include "native_client/src/trusted/gdb_rsp/util.h" 29 #include "native_client/src/trusted/gdb_rsp/util.h"
30 30
31 #include "native_client/src/trusted/port/event.h" 31 #include "native_client/src/trusted/port/event.h"
32 #include "native_client/src/trusted/port/platform.h" 32 #include "native_client/src/trusted/port/platform.h"
33 #include "native_client/src/trusted/port/mutex.h" 33 #include "native_client/src/trusted/port/mutex.h"
34 #include "native_client/src/trusted/port/thread.h" 34 #include "native_client/src/trusted/port/thread.h"
35 35
36 namespace gdb_rsp { 36 namespace gdb_rsp {
37 37
38 class Abi; 38 class Abi;
39 class Packet; 39 class Packet;
40 class Session; 40 class Session;
41 41
42 class Target { 42 class Target {
43 public: 43 public:
44 enum ErrDef { 44 enum ErrDef {
45 NONE = 0, 45 NONE = 0,
46 BAD_FORMAT = 1, 46 BAD_FORMAT = 1,
47 BAD_ARGS = 2, 47 BAD_ARGS = 2,
48 FAILED = 3 48 FAILED = 3
49 }; 49 };
50 50
51 enum State { 51 enum ConState {
52 UNINIT = 0, 52 DETACHED = 0,
53 RUNNING = 1, 53 ATTACHED = 1,
54 STOPPED = 2 54 DETACHING= 2
55 }; 55 };
56 56
57 typedef ErrDef (*QFunc_t)(Target *, stringvec&, std::string); 57 typedef ErrDef (*QFunc_t)(Target *, stringvec&, std::string);
58 typedef std::map<uint32_t, port::IThread*> ThreadMap_t; 58 typedef std::map<uint32_t, port::IThread*> ThreadMap_t;
59 typedef std::map<std::string, std::string> PropertyMap_t; 59 typedef std::map<std::string, std::string> PropertyMap_t;
60 typedef std::map<uint64_t, uint8_t*> BreakMap_t; 60 typedef std::map<uint64_t, uint8_t*> BreakMap_t;
61 61
62 public: 62 public:
63 // Contruct a Target object. By default use the native ABI. 63 // Contruct a Target object. By default use the native ABI.
64 explicit Target(const Abi *abi = NULL); 64 explicit Target(const Abi *abi = NULL);
65 ~Target(); 65 ~Target();
66 66
67 // Init must be the first function called to correctlty 67 // Init must be the first function called to correctlty
68 // build the Target internal structures. 68 // build the Target internal structures.
69 bool Init(); 69 bool Init();
70 70
71 // Set/Get locally cached properties
72 bool SetProperty(const std::string &name, const std::string& val);
73 bool GetProperty(const std::string &name, std::string* val) const;
74
75 // MatchQuery does a longest prefix match against the locally cased
76 // properties, and returns the length of the match, as well as the
77 // requested value.
78 size_t MatchQuery(const std::string& match, std::string* val) const;
79
71 // Add and remove temporary breakpoints. These breakpoints 80 // Add and remove temporary breakpoints. These breakpoints
72 // must be added just before we start running, and removed 81 // must be added just before we start running, and removed
73 // just before we stop running to prevent the debugger from 82 // just before we stop running to prevent the debugger from
74 // seeing the modified memory. 83 // seeing the modified memory.
75 bool AddTemporaryBreakpoint(uint64_t address); 84 bool AddTemporaryBreakpoint(uint64_t address);
76 bool RemoveTemporaryBreakpoints(); 85 bool RemoveTemporaryBreakpoints();
77 86
78 // This function should be called by a tracked thread when it takes 87 // This function should be called by a tracked thread when it takes
79 // an exception. It takes sig_start_ to prevent other exceptions 88 // an exception. It takes sig_start_ to prevent other exceptions
80 // from signalling thread. If wait is true, it will then block on 89 // from signalling thread. If wait is true, it will then block on
81 // sig_done_ until a continue is issued by the host. 90 // sig_done_ until a continue is issued by the host.
82 void Signal(uint32_t id, int8_t sig, bool wait); 91 void Signal(uint32_t id, int8_t sig, bool wait);
83 92
84 // This function will spin on a session, until it closes. If an 93 // This function will spin on a session, until it closes. If an
85 // exception is caught, it will signal the exception thread by 94 // exception is caught, it will signal the exception thread by
86 // setting sig_done_. 95 // setting sig_done_.
87 void Run(Session *ses); 96 void Run(Session *ses);
88 97
89 // This function causes the target to track the state 98 // This function causes the target to track the state
90 // of the specified thread and make it availible to 99 // of the specified thread and make it availible to
91 // a connected host. 100 // a connected host.
92 void TrackThread(port::IThread *thread); 101 void TrackThread(port::IThread *thread);
93 102
94 // This function causes the target to stop tracking the 103 // This function causes the target to stop tracking the
95 // state of the specified thread, which will no longer 104 // state of the specified thread, which will no longer
96 // be visible to the host. 105 // be visible to the host.
97 void IgnoreThread(port::IThread *thread); 106 void IgnoreThread(port::IThread *thread);
98 107
99 protected: 108 protected:
109 // Protected member functions, should only be called by the stub thread
110 // from within "Run", at which point stateMutex_ is already held, so
111 // it is always safe for a protected function to access the signal
112 // state or thread map.
113
114 // Called whenever the target transitions from running to stopped to
115 // update information about the current state.
116 void Update();
117
118 // Called to stop and start all debug threads
119 void Pause();
120 void Resume();
121
100 // This function always succeedes, since all errors 122 // This function always succeedes, since all errors
101 // are reported as an error string of "E<##>" where 123 // are reported as an error string of "E<##>" where
102 // the two digit number. The error codes are not 124 // the two digit number. The error codes are not
103 // not documented, so this implementation uses 125 // not documented, so this implementation uses
104 // ErrDef as errors codes. This function returns 126 // ErrDef as errors codes. This function returns
105 // true a request to continue (or step) is processed. 127 // true a request to continue (or step) is processed.
106 bool ProcessPacket(Packet *pktIn, Packet *pktOut); 128 bool ProcessPacket(Packet *pktIn, Packet *pktOut);
107 129
108 void Destroy(); 130 void Destroy();
109 void Detach(); 131 void Detach();
110 132
111 bool GetFirstThreadId(uint32_t *id); 133 bool GetFirstThreadId(uint32_t *id);
112 bool GetNextThreadId(uint32_t *id); 134 bool GetNextThreadId(uint32_t *id);
113 135
114 uint32_t GetRegThreadId() const; 136 uint32_t GetRegThreadId() const;
115 uint32_t GetRunThreadId() const; 137 uint32_t GetRunThreadId() const;
116 port::IThread *GetThread(uint32_t id); 138 port::IThread *GetThread(uint32_t id) const;
noelallen_use_chromium 2010/12/07 23:04:44 Good catch.
117 139
118 public: 140 private:
141 // Current Target state
142 ConState conState_;
143
119 const Abi *abi_; 144 const Abi *abi_;
120 145
121 // This mutex protects debugging state (threads_, cur_signal, sig_thread_) 146 // This mutex protects debugging state (threads_, cur_signal, sig_thread_).
122 port::IMutex *mutex_; 147 // This mutex is held by the stub thread, while in a broken state.
148 port::IMutex *stateMutex_;
149
150 // This mutex protects the public data (breakpoint, property), and is only
151 // held temporarily as needed.
152 port::IMutex *publicMutex_;
123 153
124 // This event is signalled when the target is really to process an 154 // This event is signalled when the target is really to process an
125 // exception. It ensures only one exception is processed at a time. 155 // exception. It ensures only one exception is processed at a time.
126 port::IEvent *sig_start_; 156 port::IEvent *sig_start_;
127 157
128 // This event is signalled when the target done processing an exception. 158 // This event is signalled when the target done processing an exception.
129 port::IEvent *sig_done_; 159 port::IEvent *sig_done_;
130 160
131 // This value is set if the exception cather is requesting a continue signal 161 // This value is set if the exception cather is requesting a continue signal
132 bool send_done_; 162 bool send_done_;
133 163
134 ThreadMap_t threads_; 164 ThreadMap_t threads_;
135 ThreadMap_t::const_iterator threadItr_; 165 ThreadMap_t::const_iterator threadItr_;
136 BreakMap_t breakMap_; 166 BreakMap_t breakMap_;
137 167
138 168 // A map of generic properties for the target.
139 PropertyMap_t properties_; 169 PropertyMap_t properties_;
140 170
141 uint8_t *ctx_; // Context Scratchpad 171 // Context Scratchpad
172 uint8_t *ctx_;
142 173
143 // The current signal and signaling thread data is protected by 174 // The current signal and signaling thread data is protected by
144 // the mutex, and can only be owned by one thread at a time. 175 // the mutex, and can only be owned by one thread at a time.
145 // These values should only be written via the "Signal" member, 176 // These values should only be written via the "Signal" member,
146 // which will ensure that a new signal does not overwrite a 177 // which will ensure that a new signal does not overwrite a
147 // previous signal. 178 // previous signal.
148 volatile int8_t cur_signal_; 179 volatile int8_t cur_signal_;
149 volatile uint32_t sig_thread_; 180 volatile uint32_t sig_thread_;
150 181
151 uint32_t run_thread_; // Which thread to issue step commands on 182 // The debugger tracks two thread ids for its operations, one for
152 uint32_t reg_thread_; // Which thread to issue context (reg) commands on 183 // getting and setting registers, the other for step and continue.
184 // The value can be 0 for any, -1 for all, or a specific ID for
185 // a specific thread. The "_req_" variable stores the requested
186 // id, while the "_last_" value stores the last value returned.
187 uint32_t run_req_; // Requested thread for run operations.
mmortensen 2010/12/07 22:53:58 If run_req and run_reg can bo -1, why are the decl
mlinck 2010/12/10 21:10:27 Excellent question. I'm not sure what the best ap
noelallen_use_chromium 2010/12/13 19:28:10 I set this to 32b so you would get that behavior.
mlinck 2010/12/14 17:23:24 Changed to int32_t
188 uint32_t reg_req_; // Requested thread for reg operations.
189 mutable uint32_t run_last_; // Last result from a run thread query.
190 mutable uint32_t reg_last_; // Last result from a reg thread query.
153 }; 191 };
154 192
155 193
156 } // namespace gdb_rsp 194 } // namespace gdb_rsp
157 195
158 #endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ 196 #endif // SRC_TRUSTED_GDB_RSP_TARGET_H_
159 197
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698