Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ProcessGDBRemote.cpp ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 10 | #include "lldb/Host/Config.h" |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | // C Includes |
| 13 | #include <errno.h> |
Stephen Wilson | a78867b | 2011-03-25 18:16:28 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 15 | #ifndef LLDB_DISABLE_POSIX |
Sean Callanan | 224f6f5 | 2012-07-19 18:07:36 +0000 | [diff] [blame] | 16 | #include <netinet/in.h> |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 17 | #include <sys/mman.h> // for mmap |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 18 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include <sys/stat.h> |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 20 | #include <sys/types.h> |
Stephen Wilson | dc91686 | 2011-03-30 00:12:40 +0000 | [diff] [blame] | 21 | #include <time.h> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
| 23 | // C++ Includes |
| 24 | #include <algorithm> |
| 25 | #include <map> |
Benjamin Kramer | 3f69fa6 | 2015-04-03 10:55:00 +0000 | [diff] [blame] | 26 | #include <mutex> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 28 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 29 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/ArchSpec.h" |
| 31 | #include "lldb/Core/Debugger.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 32 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 33 | #include "lldb/Host/FileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/Module.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 35 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/PluginManager.h" |
| 37 | #include "lldb/Core/State.h" |
Greg Clayton | d451c1a | 2012-04-13 21:24:18 +0000 | [diff] [blame] | 38 | #include "lldb/Core/StreamFile.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Core/StreamString.h" |
| 40 | #include "lldb/Core/Timer.h" |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 41 | #include "lldb/Core/Value.h" |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 42 | #include "lldb/DataFormatters/FormatManager.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 43 | #include "lldb/Host/HostThread.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 44 | #include "lldb/Host/StringConvert.h" |
Jason Molenda | d1fae14 | 2012-09-29 08:03:33 +0000 | [diff] [blame] | 45 | #include "lldb/Host/Symbols.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 46 | #include "lldb/Host/ThreadLauncher.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "lldb/Host/TimeValue.h" |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 48 | #include "lldb/Host/XML.h" |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 49 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | 1d19a2f | 2012-10-19 22:22:57 +0000 | [diff] [blame] | 50 | #include "lldb/Interpreter/CommandObject.h" |
| 51 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 52 | #include "lldb/Interpreter/CommandReturnObject.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 53 | #include "lldb/Interpreter/OptionValueProperties.h" |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 54 | #include "lldb/Interpreter/Options.h" |
| 55 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
| 56 | #include "lldb/Interpreter/OptionGroupUInt64.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 57 | #include "lldb/Interpreter/Property.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | #include "lldb/Symbol/ObjectFile.h" |
| 59 | #include "lldb/Target/DynamicLoader.h" |
| 60 | #include "lldb/Target/Target.h" |
| 61 | #include "lldb/Target/TargetList.h" |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 62 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 63 | #include "lldb/Target/SystemRuntime.h" |
Jason Molenda | a34a0c6 | 2010-06-09 21:28:42 +0000 | [diff] [blame] | 64 | #include "lldb/Utility/PseudoTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | |
| 66 | // Project includes |
| 67 | #include "lldb/Host/Host.h" |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 68 | #include "Plugins/Process/Utility/GDBRemoteSignals.h" |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 69 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
Jason Molenda | c42d243 | 2012-07-25 03:40:06 +0000 | [diff] [blame] | 70 | #include "Plugins/Process/Utility/StopInfoMachException.h" |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 71 | #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 72 | #include "Utility/StringExtractorGDBRemote.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | #include "GDBRemoteRegisterContext.h" |
| 74 | #include "ProcessGDBRemote.h" |
| 75 | #include "ProcessGDBRemoteLog.h" |
| 76 | #include "ThreadGDBRemote.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 77 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 78 | #define DEBUGSERVER_BASENAME "debugserver" |
| 79 | using namespace lldb; |
| 80 | using namespace lldb_private; |
| 81 | using namespace lldb_private::process_gdb_remote; |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 82 | |
Greg Clayton | c1422c1 | 2012-04-09 22:46:21 +0000 | [diff] [blame] | 83 | namespace lldb |
| 84 | { |
| 85 | // Provide a function that can easily dump the packet history if we know a |
| 86 | // ProcessGDBRemote * value (which we can get from logs or from debugging). |
| 87 | // We need the function in the lldb namespace so it makes it into the final |
| 88 | // executable since the LLDB shared library only exports stuff in the lldb |
| 89 | // namespace. This allows you to attach with a debugger and call this |
| 90 | // function and get the packet history dumped to a file. |
| 91 | void |
| 92 | DumpProcessGDBRemotePacketHistory (void *p, const char *path) |
| 93 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 94 | StreamFile strm; |
| 95 | Error error (strm.GetFile().Open(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate)); |
Greg Clayton | d451c1a | 2012-04-13 21:24:18 +0000 | [diff] [blame] | 96 | if (error.Success()) |
| 97 | ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory (strm); |
Greg Clayton | c1422c1 | 2012-04-09 22:46:21 +0000 | [diff] [blame] | 98 | } |
Filipe Cabecinhas | c34f776 | 2012-05-23 16:27:09 +0000 | [diff] [blame] | 99 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 101 | namespace { |
Steve Pucci | 5ec012d | 2014-01-16 22:18:14 +0000 | [diff] [blame] | 102 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 103 | static PropertyDefinition |
| 104 | g_properties[] = |
| 105 | { |
| 106 | { "packet-timeout" , OptionValue::eTypeUInt64 , true , 1, NULL, NULL, "Specify the default packet timeout in seconds." }, |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 107 | { "target-definition-file" , OptionValue::eTypeFileSpec , true, 0 , NULL, NULL, "The file that provides the description for remote target registers." }, |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 108 | { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } |
| 109 | }; |
| 110 | |
| 111 | enum |
| 112 | { |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 113 | ePropertyPacketTimeout, |
| 114 | ePropertyTargetDefinitionFile |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | class PluginProperties : public Properties |
| 118 | { |
| 119 | public: |
| 120 | |
| 121 | static ConstString |
| 122 | GetSettingName () |
| 123 | { |
| 124 | return ProcessGDBRemote::GetPluginNameStatic(); |
| 125 | } |
| 126 | |
| 127 | PluginProperties() : |
| 128 | Properties () |
| 129 | { |
| 130 | m_collection_sp.reset (new OptionValueProperties(GetSettingName())); |
| 131 | m_collection_sp->Initialize(g_properties); |
| 132 | } |
| 133 | |
| 134 | virtual |
| 135 | ~PluginProperties() |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | uint64_t |
| 140 | GetPacketTimeout() |
| 141 | { |
| 142 | const uint32_t idx = ePropertyPacketTimeout; |
| 143 | return m_collection_sp->GetPropertyAtIndexAsUInt64(NULL, idx, g_properties[idx].default_uint_value); |
| 144 | } |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 145 | |
| 146 | bool |
| 147 | SetPacketTimeout(uint64_t timeout) |
| 148 | { |
| 149 | const uint32_t idx = ePropertyPacketTimeout; |
| 150 | return m_collection_sp->SetPropertyAtIndexAsUInt64(NULL, idx, timeout); |
| 151 | } |
| 152 | |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 153 | FileSpec |
| 154 | GetTargetDefinitionFile () const |
| 155 | { |
| 156 | const uint32_t idx = ePropertyTargetDefinitionFile; |
| 157 | return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); |
| 158 | } |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | typedef std::shared_ptr<PluginProperties> ProcessKDPPropertiesSP; |
| 162 | |
| 163 | static const ProcessKDPPropertiesSP & |
| 164 | GetGlobalPluginProperties() |
| 165 | { |
| 166 | static ProcessKDPPropertiesSP g_settings_sp; |
| 167 | if (!g_settings_sp) |
| 168 | g_settings_sp.reset (new PluginProperties ()); |
| 169 | return g_settings_sp; |
| 170 | } |
| 171 | |
| 172 | } // anonymous namespace end |
| 173 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 174 | class ProcessGDBRemote::GDBLoadedModuleInfoList |
| 175 | { |
| 176 | public: |
| 177 | |
| 178 | class LoadedModuleInfo |
| 179 | { |
| 180 | public: |
| 181 | |
| 182 | enum e_data_point |
| 183 | { |
| 184 | e_has_name = 0, |
| 185 | e_has_base , |
| 186 | e_has_dynamic , |
| 187 | e_has_link_map , |
| 188 | e_num |
| 189 | }; |
| 190 | |
| 191 | LoadedModuleInfo () |
| 192 | { |
| 193 | for (uint32_t i = 0; i < e_num; ++i) |
| 194 | m_has[i] = false; |
Pavel Labath | cb213b3 | 2015-07-22 08:12:01 +0000 | [diff] [blame] | 195 | } |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 196 | |
| 197 | void set_name (const std::string & name) |
| 198 | { |
| 199 | m_name = name; |
| 200 | m_has[e_has_name] = true; |
| 201 | } |
| 202 | bool get_name (std::string & out) const |
| 203 | { |
| 204 | out = m_name; |
| 205 | return m_has[e_has_name]; |
| 206 | } |
| 207 | |
| 208 | void set_base (const lldb::addr_t base) |
| 209 | { |
| 210 | m_base = base; |
| 211 | m_has[e_has_base] = true; |
| 212 | } |
| 213 | bool get_base (lldb::addr_t & out) const |
| 214 | { |
| 215 | out = m_base; |
| 216 | return m_has[e_has_base]; |
| 217 | } |
| 218 | |
| 219 | void set_link_map (const lldb::addr_t addr) |
| 220 | { |
| 221 | m_link_map = addr; |
| 222 | m_has[e_has_link_map] = true; |
| 223 | } |
| 224 | bool get_link_map (lldb::addr_t & out) const |
| 225 | { |
| 226 | out = m_link_map; |
| 227 | return m_has[e_has_link_map]; |
| 228 | } |
| 229 | |
| 230 | void set_dynamic (const lldb::addr_t addr) |
| 231 | { |
| 232 | m_dynamic = addr; |
| 233 | m_has[e_has_dynamic] = true; |
| 234 | } |
| 235 | bool get_dynamic (lldb::addr_t & out) const |
| 236 | { |
| 237 | out = m_dynamic; |
| 238 | return m_has[e_has_dynamic]; |
| 239 | } |
| 240 | |
| 241 | bool has_info (e_data_point datum) |
| 242 | { |
| 243 | assert (datum < e_num); |
| 244 | return m_has[datum]; |
| 245 | } |
| 246 | |
| 247 | protected: |
| 248 | |
| 249 | bool m_has[e_num]; |
| 250 | std::string m_name; |
| 251 | lldb::addr_t m_link_map; |
| 252 | lldb::addr_t m_base; |
| 253 | lldb::addr_t m_dynamic; |
| 254 | }; |
| 255 | |
| 256 | GDBLoadedModuleInfoList () |
| 257 | : m_list () |
| 258 | , m_link_map (LLDB_INVALID_ADDRESS) |
| 259 | {} |
| 260 | |
| 261 | void add (const LoadedModuleInfo & mod) |
| 262 | { |
| 263 | m_list.push_back (mod); |
| 264 | } |
| 265 | |
| 266 | void clear () |
| 267 | { |
| 268 | m_list.clear (); |
| 269 | } |
| 270 | |
| 271 | std::vector<LoadedModuleInfo> m_list; |
| 272 | lldb::addr_t m_link_map; |
| 273 | }; |
| 274 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 275 | // TODO Randomly assigning a port is unsafe. We should get an unused |
| 276 | // ephemeral port from the kernel and make sure we reserve it before passing |
| 277 | // it to debugserver. |
| 278 | |
| 279 | #if defined (__APPLE__) |
| 280 | #define LOW_PORT (IPPORT_RESERVED) |
| 281 | #define HIGH_PORT (IPPORT_HIFIRSTAUTO) |
| 282 | #else |
| 283 | #define LOW_PORT (1024u) |
| 284 | #define HIGH_PORT (49151u) |
| 285 | #endif |
| 286 | |
Todd Fiala | 013434e | 2014-07-09 01:29:05 +0000 | [diff] [blame] | 287 | #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 288 | static bool rand_initialized = false; |
| 289 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 290 | static inline uint16_t |
| 291 | get_random_port () |
| 292 | { |
| 293 | if (!rand_initialized) |
| 294 | { |
| 295 | time_t seed = time(NULL); |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 296 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 297 | rand_initialized = true; |
| 298 | srand(seed); |
| 299 | } |
| 300 | return (rand() % (HIGH_PORT - LOW_PORT)) + LOW_PORT; |
| 301 | } |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 302 | #endif |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 303 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 304 | ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | ProcessGDBRemote::GetPluginNameStatic() |
| 306 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 307 | static ConstString g_name("gdb-remote"); |
| 308 | return g_name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | const char * |
| 312 | ProcessGDBRemote::GetPluginDescriptionStatic() |
| 313 | { |
| 314 | return "GDB Remote protocol based debugging plug-in."; |
| 315 | } |
| 316 | |
| 317 | void |
| 318 | ProcessGDBRemote::Terminate() |
| 319 | { |
| 320 | PluginManager::UnregisterPlugin (ProcessGDBRemote::CreateInstance); |
| 321 | } |
| 322 | |
| 323 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 324 | lldb::ProcessSP |
| 325 | ProcessGDBRemote::CreateInstance (Target &target, Listener &listener, const FileSpec *crash_file_path) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 327 | lldb::ProcessSP process_sp; |
| 328 | if (crash_file_path == NULL) |
| 329 | process_sp.reset (new ProcessGDBRemote (target, listener)); |
| 330 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | bool |
Greg Clayton | 3a29bdb | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 334 | ProcessGDBRemote::CanDebug (Target &target, bool plugin_specified_by_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | { |
Greg Clayton | 596ed24 | 2011-10-21 21:41:45 +0000 | [diff] [blame] | 336 | if (plugin_specified_by_name) |
| 337 | return true; |
| 338 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | // For now we are just making sure the file exists for a given module |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 340 | Module *exe_module = target.GetExecutableModulePointer(); |
| 341 | if (exe_module) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 342 | { |
| 343 | ObjectFile *exe_objfile = exe_module->GetObjectFile(); |
| 344 | // We can't debug core files... |
| 345 | switch (exe_objfile->GetType()) |
| 346 | { |
| 347 | case ObjectFile::eTypeInvalid: |
| 348 | case ObjectFile::eTypeCoreFile: |
| 349 | case ObjectFile::eTypeDebugInfo: |
| 350 | case ObjectFile::eTypeObjectFile: |
| 351 | case ObjectFile::eTypeSharedLibrary: |
| 352 | case ObjectFile::eTypeStubLibrary: |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 353 | case ObjectFile::eTypeJIT: |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 354 | return false; |
| 355 | case ObjectFile::eTypeExecutable: |
| 356 | case ObjectFile::eTypeDynamicLinker: |
| 357 | case ObjectFile::eTypeUnknown: |
| 358 | break; |
| 359 | } |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 360 | return exe_module->GetFileSpec().Exists(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 361 | } |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 362 | // However, if there is no executable module, we return true since we might be preparing to attach. |
| 363 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | //---------------------------------------------------------------------- |
| 367 | // ProcessGDBRemote constructor |
| 368 | //---------------------------------------------------------------------- |
| 369 | ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : |
| 370 | Process (target, listener), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | m_flags (0), |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 372 | m_gdb_comm (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | m_debugserver_pid (LLDB_INVALID_PROCESS_ID), |
Bhushan D. Attarde | 1e271df | 2015-07-24 04:06:20 +0000 | [diff] [blame] | 374 | m_last_stop_packet_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | m_register_info (), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 376 | m_async_broadcaster (NULL, "lldb.process.gdb-remote.async-broadcaster"), |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 377 | m_async_thread_state_mutex(Mutex::eMutexTypeRecursive), |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 378 | m_thread_ids (), |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 379 | m_jstopinfo_sp (), |
| 380 | m_jthreadsinfo_sp (), |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 381 | m_continue_c_tids (), |
| 382 | m_continue_C_tids (), |
| 383 | m_continue_s_tids (), |
| 384 | m_continue_S_tids (), |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 385 | m_max_memory_size (0), |
| 386 | m_remote_stub_max_memory_size (0), |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 387 | m_addr_to_mmap_size (), |
| 388 | m_thread_create_bp_sp (), |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 389 | m_waiting_for_attach (false), |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 390 | m_destroy_tried_resuming (false), |
Hafiz Abid Qadeer | 85a4daf | 2013-10-18 10:04:33 +0000 | [diff] [blame] | 391 | m_command_sp (), |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 392 | m_breakpoint_pc_offset (0), |
| 393 | m_initial_tid (LLDB_INVALID_THREAD_ID) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | { |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 395 | m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); |
| 396 | m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 397 | m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadDidExit, "async thread did exit"); |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 398 | const uint64_t timeout_seconds = GetGlobalPluginProperties()->GetPacketTimeout(); |
| 399 | if (timeout_seconds > 0) |
| 400 | m_gdb_comm.SetPacketTimeout(timeout_seconds); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | //---------------------------------------------------------------------- |
| 404 | // Destructor |
| 405 | //---------------------------------------------------------------------- |
| 406 | ProcessGDBRemote::~ProcessGDBRemote() |
| 407 | { |
| 408 | // m_mach_process.UnregisterNotificationCallbacks (this); |
| 409 | Clear(); |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 410 | // We need to call finalize on the process before destroying ourselves |
| 411 | // to make sure all of the broadcaster cleanup goes as planned. If we |
| 412 | // destruct this class, then Process::~Process() might have problems |
| 413 | // trying to fully destroy the broadcaster. |
| 414 | Finalize(); |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 415 | |
| 416 | // The general Finalize is going to try to destroy the process and that SHOULD |
| 417 | // shut down the async thread. However, if we don't kill it it will get stranded and |
| 418 | // its connection will go away so when it wakes up it will crash. So kill it for sure here. |
| 419 | StopAsyncThread(); |
| 420 | KillDebugserverProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | //---------------------------------------------------------------------- |
| 424 | // PluginInterface |
| 425 | //---------------------------------------------------------------------- |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 426 | ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 427 | ProcessGDBRemote::GetPluginName() |
| 428 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | return GetPluginNameStatic(); |
| 430 | } |
| 431 | |
| 432 | uint32_t |
| 433 | ProcessGDBRemote::GetPluginVersion() |
| 434 | { |
| 435 | return 1; |
| 436 | } |
| 437 | |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 438 | bool |
| 439 | ProcessGDBRemote::ParsePythonTargetDefinition(const FileSpec &target_definition_fspec) |
| 440 | { |
| 441 | ScriptInterpreter *interpreter = GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
| 442 | Error error; |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 443 | StructuredData::ObjectSP module_object_sp(interpreter->LoadPluginModule(target_definition_fspec, error)); |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 444 | if (module_object_sp) |
| 445 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 446 | StructuredData::DictionarySP target_definition_sp( |
| 447 | interpreter->GetDynamicSettings(module_object_sp, &GetTarget(), "gdb-server-target-definition", error)); |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 448 | |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 449 | if (target_definition_sp) |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 450 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 451 | StructuredData::ObjectSP target_object(target_definition_sp->GetValueForKey("host-info")); |
| 452 | if (target_object) |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 453 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 454 | if (auto host_info_dict = target_object->GetAsDictionary()) |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 455 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 456 | StructuredData::ObjectSP triple_value = host_info_dict->GetValueForKey("triple"); |
| 457 | if (auto triple_string_value = triple_value->GetAsString()) |
| 458 | { |
| 459 | std::string triple_string = triple_string_value->GetValue(); |
| 460 | ArchSpec host_arch(triple_string.c_str()); |
| 461 | if (!host_arch.IsCompatibleMatch(GetTarget().GetArchitecture())) |
| 462 | { |
| 463 | GetTarget().SetArchitecture(host_arch); |
| 464 | } |
| 465 | } |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 466 | } |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 467 | } |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 468 | m_breakpoint_pc_offset = 0; |
| 469 | StructuredData::ObjectSP breakpoint_pc_offset_value = target_definition_sp->GetValueForKey("breakpoint-pc-offset"); |
| 470 | if (breakpoint_pc_offset_value) |
| 471 | { |
| 472 | if (auto breakpoint_pc_int_value = breakpoint_pc_offset_value->GetAsInteger()) |
| 473 | m_breakpoint_pc_offset = breakpoint_pc_int_value->GetValue(); |
| 474 | } |
Hafiz Abid Qadeer | 85a4daf | 2013-10-18 10:04:33 +0000 | [diff] [blame] | 475 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 476 | if (m_register_info.SetRegisterInfo(*target_definition_sp, GetTarget().GetArchitecture()) > 0) |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 477 | { |
| 478 | return true; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | return false; |
| 483 | } |
| 484 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 485 | static size_t |
| 486 | SplitCommaSeparatedRegisterNumberString(const llvm::StringRef &comma_separated_regiter_numbers, std::vector<uint32_t> ®nums, int base) |
| 487 | { |
| 488 | regnums.clear(); |
| 489 | std::pair<llvm::StringRef, llvm::StringRef> value_pair; |
| 490 | value_pair.second = comma_separated_regiter_numbers; |
| 491 | do |
| 492 | { |
| 493 | value_pair = value_pair.second.split(','); |
| 494 | if (!value_pair.first.empty()) |
| 495 | { |
| 496 | uint32_t reg = StringConvert::ToUInt32 (value_pair.first.str().c_str(), LLDB_INVALID_REGNUM, base); |
| 497 | if (reg != LLDB_INVALID_REGNUM) |
| 498 | regnums.push_back (reg); |
| 499 | } |
| 500 | } while (!value_pair.second.empty()); |
| 501 | return regnums.size(); |
| 502 | } |
| 503 | |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 504 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | void |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 506 | ProcessGDBRemote::BuildDynamicRegisterInfo (bool force) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 508 | if (!force && m_register_info.GetNumRegisters() > 0) |
| 509 | return; |
| 510 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 511 | m_register_info.Clear(); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 512 | |
| 513 | // Check if qHostInfo specified a specific packet timeout for this connection. |
| 514 | // If so then lets update our setting so the user knows what the timeout is |
| 515 | // and can see it. |
| 516 | const uint32_t host_packet_timeout = m_gdb_comm.GetHostDefaultPacketTimeout(); |
| 517 | if (host_packet_timeout) |
| 518 | { |
| 519 | GetGlobalPluginProperties()->SetPacketTimeout(host_packet_timeout); |
| 520 | } |
| 521 | |
Ewan Crawford | 0c996a9 | 2015-06-30 13:08:44 +0000 | [diff] [blame] | 522 | // Register info search order: |
| 523 | // 1 - Use the target definition python file if one is specified. |
| 524 | // 2 - If the target definition doesn't have any of the info from the target.xml (registers) then proceed to read the target.xml. |
| 525 | // 3 - Fall back on the qRegisterInfo packets. |
| 526 | |
| 527 | FileSpec target_definition_fspec = GetGlobalPluginProperties()->GetTargetDefinitionFile (); |
| 528 | if (target_definition_fspec) |
| 529 | { |
| 530 | // See if we can get register definitions from a python file |
| 531 | if (ParsePythonTargetDefinition (target_definition_fspec)) |
| 532 | return; |
| 533 | } |
| 534 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 535 | if (GetGDBServerRegisterInfo ()) |
| 536 | return; |
| 537 | |
| 538 | char packet[128]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 539 | uint32_t reg_offset = 0; |
| 540 | uint32_t reg_num = 0; |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 541 | for (StringExtractorGDBRemote::ResponseType response_type = StringExtractorGDBRemote::eResponse; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 542 | response_type == StringExtractorGDBRemote::eResponse; |
| 543 | ++reg_num) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 544 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 545 | const int packet_len = ::snprintf (packet, sizeof(packet), "qRegisterInfo%x", reg_num); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 546 | assert (packet_len < (int)sizeof(packet)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 548 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false) == GDBRemoteCommunication::PacketResult::Success) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 549 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 550 | response_type = response.GetResponseType(); |
| 551 | if (response_type == StringExtractorGDBRemote::eResponse) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 552 | { |
| 553 | std::string name; |
| 554 | std::string value; |
| 555 | ConstString reg_name; |
| 556 | ConstString alt_name; |
| 557 | ConstString set_name; |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 558 | std::vector<uint32_t> value_regs; |
| 559 | std::vector<uint32_t> invalidate_regs; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 560 | RegisterInfo reg_info = { NULL, // Name |
| 561 | NULL, // Alt name |
| 562 | 0, // byte size |
| 563 | reg_offset, // offset |
| 564 | eEncodingUint, // encoding |
| 565 | eFormatHex, // formate |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
| 567 | LLDB_INVALID_REGNUM, // GCC reg num |
| 568 | LLDB_INVALID_REGNUM, // DWARF reg num |
| 569 | LLDB_INVALID_REGNUM, // generic reg num |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 570 | reg_num, // GDB reg num |
| 571 | reg_num // native register number |
Greg Clayton | 435d85a | 2012-02-29 19:27:27 +0000 | [diff] [blame] | 572 | }, |
| 573 | NULL, |
| 574 | NULL |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | while (response.GetNameColonValue(name, value)) |
| 578 | { |
| 579 | if (name.compare("name") == 0) |
| 580 | { |
| 581 | reg_name.SetCString(value.c_str()); |
| 582 | } |
| 583 | else if (name.compare("alt-name") == 0) |
| 584 | { |
| 585 | alt_name.SetCString(value.c_str()); |
| 586 | } |
| 587 | else if (name.compare("bitsize") == 0) |
| 588 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 589 | reg_info.byte_size = StringConvert::ToUInt32(value.c_str(), 0, 0) / CHAR_BIT; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 590 | } |
| 591 | else if (name.compare("offset") == 0) |
| 592 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 593 | uint32_t offset = StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0); |
Jason Molenda | 743e86a | 2010-06-11 23:44:18 +0000 | [diff] [blame] | 594 | if (reg_offset != offset) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | { |
| 596 | reg_offset = offset; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | else if (name.compare("encoding") == 0) |
| 600 | { |
Greg Clayton | 2443cbd | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 601 | const Encoding encoding = Args::StringToEncoding (value.c_str()); |
| 602 | if (encoding != eEncodingInvalid) |
| 603 | reg_info.encoding = encoding; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | } |
| 605 | else if (name.compare("format") == 0) |
| 606 | { |
Greg Clayton | 2443cbd | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 607 | Format format = eFormatInvalid; |
| 608 | if (Args::StringToFormat (value.c_str(), format, NULL).Success()) |
| 609 | reg_info.format = format; |
| 610 | else if (value.compare("binary") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 611 | reg_info.format = eFormatBinary; |
| 612 | else if (value.compare("decimal") == 0) |
| 613 | reg_info.format = eFormatDecimal; |
| 614 | else if (value.compare("hex") == 0) |
| 615 | reg_info.format = eFormatHex; |
| 616 | else if (value.compare("float") == 0) |
| 617 | reg_info.format = eFormatFloat; |
| 618 | else if (value.compare("vector-sint8") == 0) |
| 619 | reg_info.format = eFormatVectorOfSInt8; |
| 620 | else if (value.compare("vector-uint8") == 0) |
| 621 | reg_info.format = eFormatVectorOfUInt8; |
| 622 | else if (value.compare("vector-sint16") == 0) |
| 623 | reg_info.format = eFormatVectorOfSInt16; |
| 624 | else if (value.compare("vector-uint16") == 0) |
| 625 | reg_info.format = eFormatVectorOfUInt16; |
| 626 | else if (value.compare("vector-sint32") == 0) |
| 627 | reg_info.format = eFormatVectorOfSInt32; |
| 628 | else if (value.compare("vector-uint32") == 0) |
| 629 | reg_info.format = eFormatVectorOfUInt32; |
| 630 | else if (value.compare("vector-float32") == 0) |
| 631 | reg_info.format = eFormatVectorOfFloat32; |
| 632 | else if (value.compare("vector-uint128") == 0) |
| 633 | reg_info.format = eFormatVectorOfUInt128; |
| 634 | } |
| 635 | else if (name.compare("set") == 0) |
| 636 | { |
| 637 | set_name.SetCString(value.c_str()); |
| 638 | } |
| 639 | else if (name.compare("gcc") == 0) |
| 640 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 641 | reg_info.kinds[eRegisterKindGCC] = StringConvert::ToUInt32(value.c_str(), LLDB_INVALID_REGNUM, 0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | } |
| 643 | else if (name.compare("dwarf") == 0) |
| 644 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 645 | reg_info.kinds[eRegisterKindDWARF] = StringConvert::ToUInt32(value.c_str(), LLDB_INVALID_REGNUM, 0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | } |
| 647 | else if (name.compare("generic") == 0) |
| 648 | { |
Greg Clayton | 2443cbd | 2012-08-24 01:42:50 +0000 | [diff] [blame] | 649 | reg_info.kinds[eRegisterKindGeneric] = Args::StringToGenericRegister (value.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | } |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 651 | else if (name.compare("container-regs") == 0) |
| 652 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 653 | SplitCommaSeparatedRegisterNumberString(value, value_regs, 16); |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 654 | } |
| 655 | else if (name.compare("invalidate-regs") == 0) |
| 656 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 657 | SplitCommaSeparatedRegisterNumberString(value, invalidate_regs, 16); |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 658 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Jason Molenda | 743e86a | 2010-06-11 23:44:18 +0000 | [diff] [blame] | 661 | reg_info.byte_offset = reg_offset; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | assert (reg_info.byte_size != 0); |
| 663 | reg_offset += reg_info.byte_size; |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 664 | if (!value_regs.empty()) |
| 665 | { |
| 666 | value_regs.push_back(LLDB_INVALID_REGNUM); |
| 667 | reg_info.value_regs = value_regs.data(); |
| 668 | } |
| 669 | if (!invalidate_regs.empty()) |
| 670 | { |
| 671 | invalidate_regs.push_back(LLDB_INVALID_REGNUM); |
| 672 | reg_info.invalidate_regs = invalidate_regs.data(); |
| 673 | } |
| 674 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | m_register_info.AddRegister(reg_info, reg_name, alt_name, set_name); |
| 676 | } |
Todd Fiala | 1a63440 | 2014-01-08 07:52:40 +0000 | [diff] [blame] | 677 | else |
| 678 | { |
| 679 | break; // ensure exit before reg_num is incremented |
| 680 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | } |
| 682 | else |
| 683 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 684 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 688 | if (m_register_info.GetNumRegisters() > 0) |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 689 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 690 | m_register_info.Finalize(GetTarget().GetArchitecture()); |
| 691 | return; |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 692 | } |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 693 | |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 694 | // We didn't get anything if the accumulated reg_num is zero. See if we are |
| 695 | // debugging ARM and fill with a hard coded register set until we can get an |
| 696 | // updated debugserver down on the devices. |
| 697 | // On the other hand, if the accumulated reg_num is positive, see if we can |
| 698 | // add composite registers to the existing primordial ones. |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 699 | bool from_scratch = (m_register_info.GetNumRegisters() == 0); |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 700 | |
| 701 | const ArchSpec &target_arch = GetTarget().GetArchitecture(); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 702 | const ArchSpec &remote_host_arch = m_gdb_comm.GetHostArchitecture(); |
| 703 | const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 704 | |
| 705 | // Use the process' architecture instead of the host arch, if available |
| 706 | ArchSpec remote_arch; |
| 707 | if (remote_process_arch.IsValid ()) |
| 708 | remote_arch = remote_process_arch; |
| 709 | else |
| 710 | remote_arch = remote_host_arch; |
| 711 | |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 712 | if (!target_arch.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | { |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 714 | if (remote_arch.IsValid() |
| 715 | && remote_arch.GetMachine() == llvm::Triple::arm |
| 716 | && remote_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 717 | m_register_info.HardcodeARMRegisters(from_scratch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | } |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 719 | else if (target_arch.GetMachine() == llvm::Triple::arm) |
| 720 | { |
| 721 | m_register_info.HardcodeARMRegisters(from_scratch); |
| 722 | } |
| 723 | |
| 724 | // At this point, we can finalize our register info. |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 725 | m_register_info.Finalize (GetTarget().GetArchitecture()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | Error |
| 729 | ProcessGDBRemote::WillLaunch (Module* module) |
| 730 | { |
| 731 | return WillLaunchOrAttach (); |
| 732 | } |
| 733 | |
| 734 | Error |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 735 | ProcessGDBRemote::WillAttachToProcessWithID (lldb::pid_t pid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 736 | { |
| 737 | return WillLaunchOrAttach (); |
| 738 | } |
| 739 | |
| 740 | Error |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 741 | ProcessGDBRemote::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | { |
| 743 | return WillLaunchOrAttach (); |
| 744 | } |
| 745 | |
| 746 | Error |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 747 | ProcessGDBRemote::DoConnectRemote (Stream *strm, const char *remote_url) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 748 | { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 749 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 750 | Error error (WillLaunchOrAttach ()); |
| 751 | |
| 752 | if (error.Fail()) |
| 753 | return error; |
| 754 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 755 | error = ConnectToDebugserver (remote_url); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 756 | |
| 757 | if (error.Fail()) |
| 758 | return error; |
| 759 | StartAsyncThread (); |
| 760 | |
Greg Clayton | c574ede | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 761 | lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID (); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 762 | if (pid == LLDB_INVALID_PROCESS_ID) |
| 763 | { |
| 764 | // We don't have a valid process ID, so note that we are connected |
| 765 | // and could now request to launch or attach, or get remote process |
| 766 | // listings... |
| 767 | SetPrivateState (eStateConnected); |
| 768 | } |
| 769 | else |
| 770 | { |
| 771 | // We have a valid process |
| 772 | SetID (pid); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 773 | GetThreadList(); |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 774 | StringExtractorGDBRemote response; |
| 775 | if (m_gdb_comm.GetStopReply(response)) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 776 | { |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 777 | SetLastStopPacket(response); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 778 | |
| 779 | // '?' Packets must be handled differently in non-stop mode |
| 780 | if (GetTarget().GetNonStopModeEnabled()) |
| 781 | HandleStopReplySequence(); |
| 782 | |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 783 | if (!m_target.GetArchitecture().IsValid()) |
| 784 | { |
| 785 | if (m_gdb_comm.GetProcessArchitecture().IsValid()) |
| 786 | { |
| 787 | m_target.SetArchitecture(m_gdb_comm.GetProcessArchitecture()); |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | m_target.SetArchitecture(m_gdb_comm.GetHostArchitecture()); |
| 792 | } |
Carlo Kok | 7438912 | 2013-10-14 07:09:13 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 795 | const StateType state = SetThreadStopInfo (response); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 796 | if (state != eStateInvalid) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 797 | { |
| 798 | SetPrivateState (state); |
| 799 | } |
| 800 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 801 | error.SetErrorStringWithFormat ("Process %" PRIu64 " was reported after connecting to '%s', but state was not stopped: %s", pid, remote_url, StateAsCString (state)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 802 | } |
| 803 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 804 | error.SetErrorStringWithFormat ("Process %" PRIu64 " was reported after connecting to '%s', but no stop reply packet was received", pid, remote_url); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 805 | } |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 806 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 807 | if (log) |
| 808 | log->Printf ("ProcessGDBRemote::%s pid %" PRIu64 ": normalizing target architecture initial triple: %s (GetTarget().GetArchitecture().IsValid() %s, m_gdb_comm.GetHostArchitecture().IsValid(): %s)", __FUNCTION__, GetID (), GetTarget ().GetArchitecture ().GetTriple ().getTriple ().c_str (), GetTarget ().GetArchitecture ().IsValid () ? "true" : "false", m_gdb_comm.GetHostArchitecture ().IsValid () ? "true" : "false"); |
| 809 | |
| 810 | |
| 811 | if (error.Success() |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 812 | && !GetTarget().GetArchitecture().IsValid() |
| 813 | && m_gdb_comm.GetHostArchitecture().IsValid()) |
| 814 | { |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 815 | // Prefer the *process'* architecture over that of the *host*, if available. |
| 816 | if (m_gdb_comm.GetProcessArchitecture().IsValid()) |
| 817 | GetTarget().SetArchitecture(m_gdb_comm.GetProcessArchitecture()); |
| 818 | else |
| 819 | GetTarget().SetArchitecture(m_gdb_comm.GetHostArchitecture()); |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 822 | if (log) |
| 823 | log->Printf ("ProcessGDBRemote::%s pid %" PRIu64 ": normalized target architecture triple: %s", __FUNCTION__, GetID (), GetTarget ().GetArchitecture ().GetTriple ().getTriple ().c_str ()); |
| 824 | |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 825 | if (error.Success()) |
| 826 | SetUnixSignals(std::make_shared<GDBRemoteSignals>(GetTarget().GetPlatform()->GetUnixSignals())); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 827 | |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 828 | return error; |
| 829 | } |
| 830 | |
| 831 | Error |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 832 | ProcessGDBRemote::WillLaunchOrAttach () |
| 833 | { |
| 834 | Error error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 835 | m_stdio_communication.Clear (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 836 | return error; |
| 837 | } |
| 838 | |
| 839 | //---------------------------------------------------------------------- |
| 840 | // Process Control |
| 841 | //---------------------------------------------------------------------- |
| 842 | Error |
Jean-Daniel Dupas | 7782de9 | 2013-12-09 22:52:50 +0000 | [diff] [blame] | 843 | ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 844 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 845 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 846 | Error error; |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 847 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 848 | if (log) |
| 849 | log->Printf ("ProcessGDBRemote::%s() entered", __FUNCTION__); |
| 850 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 851 | uint32_t launch_flags = launch_info.GetFlags().Get(); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 852 | FileSpec stdin_file_spec{}; |
| 853 | FileSpec stdout_file_spec{}; |
| 854 | FileSpec stderr_file_spec{}; |
| 855 | FileSpec working_dir = launch_info.GetWorkingDirectory(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 856 | |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 857 | const FileAction *file_action; |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 858 | file_action = launch_info.GetFileActionForFD (STDIN_FILENO); |
| 859 | if (file_action) |
| 860 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 861 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 862 | stdin_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 863 | } |
| 864 | file_action = launch_info.GetFileActionForFD (STDOUT_FILENO); |
| 865 | if (file_action) |
| 866 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 867 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 868 | stdout_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 869 | } |
| 870 | file_action = launch_info.GetFileActionForFD (STDERR_FILENO); |
| 871 | if (file_action) |
| 872 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 873 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 874 | stderr_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 877 | if (log) |
| 878 | { |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 879 | if (stdin_file_spec || stdout_file_spec || stderr_file_spec) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 880 | log->Printf ("ProcessGDBRemote::%s provided with STDIO paths via launch_info: stdin=%s, stdout=%s, stderr=%s", |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 881 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 882 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 883 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 884 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 885 | else |
| 886 | log->Printf ("ProcessGDBRemote::%s no STDIO paths given via launch_info", __FUNCTION__); |
| 887 | } |
| 888 | |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 889 | const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 890 | if (stdin_file_spec || disable_stdio) |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 891 | { |
| 892 | // the inferior will be reading stdin from the specified file |
| 893 | // or stdio is completely disabled |
| 894 | m_stdin_forward = false; |
| 895 | } |
| 896 | else |
| 897 | { |
| 898 | m_stdin_forward = true; |
| 899 | } |
| 900 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 901 | // ::LogSetBitMask (GDBR_LOG_DEFAULT); |
| 902 | // ::LogSetOptions (LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD); |
| 903 | // ::LogSetLogFile ("/dev/stdout"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 904 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 905 | ObjectFile * object_file = exe_module->GetObjectFile(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 906 | if (object_file) |
| 907 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 908 | // Make sure we aren't already connected? |
| 909 | if (!m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 910 | { |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 911 | error = LaunchAndConnectToDebugserver (launch_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | if (error.Success()) |
| 915 | { |
| 916 | lldb_utility::PseudoTerminal pty; |
| 917 | const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0; |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 918 | |
Greg Clayton | f58c269 | 2011-06-24 22:32:10 +0000 | [diff] [blame] | 919 | PlatformSP platform_sp (m_target.GetPlatform()); |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 920 | if (disable_stdio) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 921 | { |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 922 | // set to /dev/null unless redirected to a file above |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 923 | if (!stdin_file_spec) |
| 924 | stdin_file_spec.SetFile("/dev/null", false); |
| 925 | if (!stdout_file_spec) |
| 926 | stdout_file_spec.SetFile("/dev/null", false); |
| 927 | if (!stderr_file_spec) |
| 928 | stderr_file_spec.SetFile("/dev/null", false); |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 929 | } |
| 930 | else if (platform_sp && platform_sp->IsHost()) |
| 931 | { |
| 932 | // If the debugserver is local and we aren't disabling STDIO, lets use |
| 933 | // a pseudo terminal to instead of relying on the 'O' packets for stdio |
| 934 | // since 'O' packets can really slow down debugging if the inferior |
| 935 | // does a lot of output. |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 936 | if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) && |
| 937 | pty.OpenFirstAvailableMaster(O_RDWR|O_NOCTTY, NULL, 0)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 938 | { |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 939 | FileSpec slave_name{pty.GetSlaveName(NULL, 0), false}; |
| 940 | |
| 941 | if (!stdin_file_spec) |
| 942 | stdin_file_spec = slave_name; |
| 943 | |
| 944 | if (!stdout_file_spec) |
| 945 | stdout_file_spec = slave_name; |
| 946 | |
| 947 | if (!stderr_file_spec) |
| 948 | stderr_file_spec = slave_name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 950 | if (log) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 951 | log->Printf ("ProcessGDBRemote::%s adjusted STDIO paths for local platform (IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s", |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 952 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 953 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 954 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 955 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 958 | if (log) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 959 | log->Printf ("ProcessGDBRemote::%s final STDIO paths after all adjustments: stdin=%s, stdout=%s, stderr=%s", |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 960 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 961 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 962 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 963 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 964 | |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 965 | if (stdin_file_spec) |
| 966 | m_gdb_comm.SetSTDIN(stdin_file_spec); |
| 967 | if (stdout_file_spec) |
| 968 | m_gdb_comm.SetSTDOUT(stdout_file_spec); |
| 969 | if (stderr_file_spec) |
| 970 | m_gdb_comm.SetSTDERR(stderr_file_spec); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 971 | |
| 972 | m_gdb_comm.SetDisableASLR (launch_flags & eLaunchFlagDisableASLR); |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 973 | m_gdb_comm.SetDetachOnError (launch_flags & eLaunchFlagDetachOnError); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 974 | |
Greg Clayton | c4103b3 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 975 | m_gdb_comm.SendLaunchArchPacket (m_target.GetArchitecture().GetArchitectureName()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 976 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 977 | const char * launch_event_data = launch_info.GetLaunchEventData(); |
| 978 | if (launch_event_data != NULL && *launch_event_data != '\0') |
| 979 | m_gdb_comm.SendLaunchEventDataPacket (launch_event_data); |
| 980 | |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 981 | if (working_dir) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 982 | { |
| 983 | m_gdb_comm.SetWorkingDir (working_dir); |
| 984 | } |
| 985 | |
| 986 | // Send the environment and the program + arguments after we connect |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 987 | const Args &environment = launch_info.GetEnvironmentEntries(); |
| 988 | if (environment.GetArgumentCount()) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 989 | { |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 990 | size_t num_environment_entries = environment.GetArgumentCount(); |
| 991 | for (size_t i=0; i<num_environment_entries; ++i) |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 992 | { |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 993 | const char *env_entry = environment.GetArgumentAtIndex(i); |
| 994 | if (env_entry == NULL || m_gdb_comm.SendEnvironmentPacket(env_entry) != 0) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 995 | break; |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 996 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 997 | } |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 998 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 999 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1000 | // Scope for the scoped timeout object |
| 1001 | GDBRemoteCommunication::ScopedTimeout timeout (m_gdb_comm, 10); |
| 1002 | |
| 1003 | int arg_packet_err = m_gdb_comm.SendArgumentsPacket (launch_info); |
| 1004 | if (arg_packet_err == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1005 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1006 | std::string error_str; |
| 1007 | if (m_gdb_comm.GetLaunchSuccess (error_str)) |
| 1008 | { |
| 1009 | SetID (m_gdb_comm.GetCurrentProcessID ()); |
| 1010 | } |
| 1011 | else |
| 1012 | { |
| 1013 | error.SetErrorString (error_str.c_str()); |
| 1014 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | } |
| 1016 | else |
| 1017 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1018 | error.SetErrorStringWithFormat("'A' packet returned an error: %i", arg_packet_err); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1019 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1020 | } |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1021 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1022 | if (GetID() == LLDB_INVALID_PROCESS_ID) |
| 1023 | { |
Johnny Chen | 4c1e920 | 2011-08-09 18:56:45 +0000 | [diff] [blame] | 1024 | if (log) |
| 1025 | log->Printf("failed to connect to debugserver: %s", error.AsCString()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1026 | KillDebugserverProcess (); |
| 1027 | return error; |
| 1028 | } |
| 1029 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1030 | StringExtractorGDBRemote response; |
| 1031 | if (m_gdb_comm.GetStopReply(response)) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1032 | { |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1033 | SetLastStopPacket(response); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1034 | // '?' Packets must be handled differently in non-stop mode |
| 1035 | if (GetTarget().GetNonStopModeEnabled()) |
| 1036 | HandleStopReplySequence(); |
| 1037 | |
Tamas Berghammer | e9f4dfe | 2015-03-13 10:32:42 +0000 | [diff] [blame] | 1038 | const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 1039 | |
| 1040 | if (process_arch.IsValid()) |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 1041 | { |
Tamas Berghammer | e9f4dfe | 2015-03-13 10:32:42 +0000 | [diff] [blame] | 1042 | m_target.MergeArchitecture(process_arch); |
| 1043 | } |
| 1044 | else |
| 1045 | { |
| 1046 | const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture(); |
| 1047 | if (host_arch.IsValid()) |
| 1048 | m_target.MergeArchitecture(host_arch); |
Carlo Kok | 7438912 | 2013-10-14 07:09:13 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1051 | SetPrivateState (SetThreadStopInfo (response)); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1052 | |
| 1053 | if (!disable_stdio) |
| 1054 | { |
| 1055 | if (pty.GetMasterFileDescriptor() != lldb_utility::PseudoTerminal::invalid_fd) |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 1056 | SetSTDIOFileDescriptor (pty.ReleaseMasterFileDescriptor()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1057 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1058 | } |
| 1059 | } |
Greg Clayton | c235ac7 | 2011-08-09 05:20:29 +0000 | [diff] [blame] | 1060 | else |
| 1061 | { |
Johnny Chen | 4c1e920 | 2011-08-09 18:56:45 +0000 | [diff] [blame] | 1062 | if (log) |
| 1063 | log->Printf("failed to connect to debugserver: %s", error.AsCString()); |
Greg Clayton | c235ac7 | 2011-08-09 05:20:29 +0000 | [diff] [blame] | 1064 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1065 | } |
| 1066 | else |
| 1067 | { |
| 1068 | // Set our user ID to an invalid process ID. |
| 1069 | SetID(LLDB_INVALID_PROCESS_ID); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 1070 | error.SetErrorStringWithFormat ("failed to get object file from '%s' for arch %s", |
| 1071 | exe_module->GetFileSpec().GetFilename().AsCString(), |
| 1072 | exe_module->GetArchitecture().GetArchitectureName()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1074 | return error; |
Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 1075 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | |
| 1079 | Error |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1080 | ProcessGDBRemote::ConnectToDebugserver (const char *connect_url) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | { |
| 1082 | Error error; |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1083 | // Only connect if we have a valid connect URL |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1084 | Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1085 | |
| 1086 | if (connect_url && connect_url[0]) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1087 | { |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1088 | if (log) |
| 1089 | log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__, connect_url); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1090 | std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor()); |
| 1091 | if (conn_ap.get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1093 | const uint32_t max_retry_count = 50; |
| 1094 | uint32_t retry_count = 0; |
| 1095 | while (!m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | { |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1097 | if (conn_ap->Connect(connect_url, &error) == eConnectionStatusSuccess) |
| 1098 | { |
| 1099 | m_gdb_comm.SetConnection (conn_ap.release()); |
| 1100 | break; |
| 1101 | } |
| 1102 | else if (error.WasInterrupted()) |
| 1103 | { |
| 1104 | // If we were interrupted, don't keep retrying. |
| 1105 | break; |
| 1106 | } |
| 1107 | |
| 1108 | retry_count++; |
| 1109 | |
| 1110 | if (retry_count >= max_retry_count) |
| 1111 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1113 | usleep (100000); |
| 1114 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | if (!m_gdb_comm.IsConnected()) |
| 1119 | { |
| 1120 | if (error.Success()) |
| 1121 | error.SetErrorString("not connected to remote gdb server"); |
| 1122 | return error; |
| 1123 | } |
| 1124 | |
Ewan Crawford | fab40d3 | 2015-06-16 15:50:18 +0000 | [diff] [blame] | 1125 | |
| 1126 | // Start the communications read thread so all incoming data can be |
| 1127 | // parsed into packets and queued as they arrive. |
| 1128 | if (GetTarget().GetNonStopModeEnabled()) |
| 1129 | m_gdb_comm.StartReadThread(); |
| 1130 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1131 | // We always seem to be able to open a connection to a local port |
| 1132 | // so we need to make sure we can then send data to it. If we can't |
| 1133 | // then we aren't actually connected to anything, so try and do the |
| 1134 | // handshake with the remote GDB server and make sure that goes |
| 1135 | // alright. |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 1136 | if (!m_gdb_comm.HandshakeWithServer (&error)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1137 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1138 | m_gdb_comm.Disconnect(); |
| 1139 | if (error.Success()) |
| 1140 | error.SetErrorString("not connected to remote gdb server"); |
| 1141 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | } |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1143 | |
| 1144 | // Send $QNonStop:1 packet on startup if required |
| 1145 | if (GetTarget().GetNonStopModeEnabled()) |
Ewan Crawford | aa7eda7 | 2015-06-24 15:14:26 +0000 | [diff] [blame] | 1146 | GetTarget().SetNonStopModeEnabled (m_gdb_comm.SetNonStopMode(true)); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1147 | |
Greg Clayton | b30c50c | 2015-05-29 00:01:55 +0000 | [diff] [blame] | 1148 | m_gdb_comm.GetEchoSupported (); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1149 | m_gdb_comm.GetThreadSuffixSupported (); |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 1150 | m_gdb_comm.GetListThreadsInStopReplySupported (); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1151 | m_gdb_comm.GetHostInfo (); |
| 1152 | m_gdb_comm.GetVContSupported ('c'); |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 1153 | m_gdb_comm.GetVAttachOrWaitSupported(); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1154 | |
| 1155 | // Ask the remote server for the default thread id |
| 1156 | if (GetTarget().GetNonStopModeEnabled()) |
| 1157 | m_gdb_comm.GetDefaultThreadId(m_initial_tid); |
| 1158 | |
| 1159 | |
Jim Ingham | 03afad8 | 2012-07-02 05:40:07 +0000 | [diff] [blame] | 1160 | size_t num_cmds = GetExtraStartupCommands().GetArgumentCount(); |
| 1161 | for (size_t idx = 0; idx < num_cmds; idx++) |
| 1162 | { |
| 1163 | StringExtractorGDBRemote response; |
Jim Ingham | 03afad8 | 2012-07-02 05:40:07 +0000 | [diff] [blame] | 1164 | m_gdb_comm.SendPacketAndWaitForResponse (GetExtraStartupCommands().GetArgumentAtIndex(idx), response, false); |
| 1165 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | return error; |
| 1167 | } |
| 1168 | |
| 1169 | void |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1170 | ProcessGDBRemote::DidLaunchOrAttach (ArchSpec& process_arch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1171 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1172 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 6d09345 | 2011-02-05 02:25:06 +0000 | [diff] [blame] | 1173 | if (log) |
| 1174 | log->Printf ("ProcessGDBRemote::DidLaunch()"); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 1175 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1176 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 1177 | BuildDynamicRegisterInfo (false); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 1178 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | // See if the GDB server supports the qHostInfo information |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1180 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 1181 | |
| 1182 | // See if the GDB server supports the qProcessInfo packet, if so |
| 1183 | // prefer that over the Host information as it will be more specific |
| 1184 | // to our process. |
| 1185 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1186 | const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 1187 | if (remote_process_arch.IsValid()) |
| 1188 | { |
| 1189 | process_arch = remote_process_arch; |
| 1190 | if (log) |
| 1191 | log->Printf ("ProcessGDBRemote::%s gdb-remote had process architecture, using %s %s", |
| 1192 | __FUNCTION__, |
| 1193 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1194 | process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1195 | } |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1196 | else |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1197 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1198 | process_arch = m_gdb_comm.GetHostArchitecture(); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1199 | if (log) |
| 1200 | log->Printf ("ProcessGDBRemote::%s gdb-remote did not have process architecture, using gdb-remote host architecture %s %s", |
| 1201 | __FUNCTION__, |
| 1202 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1203 | process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1204 | } |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 1205 | |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1206 | if (process_arch.IsValid()) |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1207 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1208 | const ArchSpec &target_arch = GetTarget().GetArchitecture(); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1209 | if (target_arch.IsValid()) |
| 1210 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1211 | if (log) |
| 1212 | log->Printf ("ProcessGDBRemote::%s analyzing target arch, currently %s %s", |
| 1213 | __FUNCTION__, |
| 1214 | target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", |
| 1215 | target_arch.GetTriple().getTriple ().c_str() ? target_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1216 | |
| 1217 | // If the remote host is ARM and we have apple as the vendor, then |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1218 | // ARM executables and shared libraries can have mixed ARM architectures. |
| 1219 | // You can have an armv6 executable, and if the host is armv7, then the |
| 1220 | // system will load the best possible architecture for all shared libraries |
| 1221 | // it has, so we really need to take the remote host architecture as our |
| 1222 | // defacto architecture in this case. |
| 1223 | |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1224 | if (process_arch.GetMachine() == llvm::Triple::arm && |
| 1225 | process_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1226 | { |
Jason Molenda | 921c01b | 2014-08-03 21:42:52 +0000 | [diff] [blame] | 1227 | GetTarget().SetArchitecture (process_arch); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1228 | if (log) |
| 1229 | log->Printf ("ProcessGDBRemote::%s remote process is ARM/Apple, setting target arch to %s %s", |
| 1230 | __FUNCTION__, |
| 1231 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1232 | process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | // Fill in what is missing in the triple |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1237 | const llvm::Triple &remote_triple = process_arch.GetTriple(); |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1238 | llvm::Triple new_target_triple = target_arch.GetTriple(); |
| 1239 | if (new_target_triple.getVendorName().size() == 0) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1240 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1241 | new_target_triple.setVendor (remote_triple.getVendor()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1242 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1243 | if (new_target_triple.getOSName().size() == 0) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1244 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1245 | new_target_triple.setOS (remote_triple.getOS()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1246 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1247 | if (new_target_triple.getEnvironmentName().size() == 0) |
| 1248 | new_target_triple.setEnvironment (remote_triple.getEnvironment()); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1249 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1250 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1251 | ArchSpec new_target_arch = target_arch; |
| 1252 | new_target_arch.SetTriple(new_target_triple); |
| 1253 | GetTarget().SetArchitecture(new_target_arch); |
| 1254 | } |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1255 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1256 | |
| 1257 | if (log) |
| 1258 | log->Printf ("ProcessGDBRemote::%s final target arch after adjustments for remote architecture: %s %s", |
| 1259 | __FUNCTION__, |
| 1260 | target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", |
| 1261 | target_arch.GetTriple().getTriple ().c_str() ? target_arch.GetTriple().getTriple ().c_str() : "<null>"); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1262 | } |
| 1263 | else |
| 1264 | { |
| 1265 | // The target doesn't have a valid architecture yet, set it from |
| 1266 | // the architecture we got from the remote GDB server |
Jason Molenda | 921c01b | 2014-08-03 21:42:52 +0000 | [diff] [blame] | 1267 | GetTarget().SetArchitecture (process_arch); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1268 | } |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1269 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | void |
| 1274 | ProcessGDBRemote::DidLaunch () |
| 1275 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1276 | ArchSpec process_arch; |
| 1277 | DidLaunchOrAttach (process_arch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | Error |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1281 | ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info) |
| 1282 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1283 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1284 | Error error; |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1285 | |
| 1286 | if (log) |
| 1287 | log->Printf ("ProcessGDBRemote::%s()", __FUNCTION__); |
| 1288 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | // Clear out and clean up from any current state |
| 1290 | Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | if (attach_pid != LLDB_INVALID_PROCESS_ID) |
| 1292 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1293 | // Make sure we aren't already connected? |
| 1294 | if (!m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1295 | { |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 1296 | error = LaunchAndConnectToDebugserver (attach_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1297 | |
| 1298 | if (error.Fail()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1300 | const char *error_string = error.AsCString(); |
| 1301 | if (error_string == NULL) |
| 1302 | error_string = "unable to launch " DEBUGSERVER_BASENAME; |
| 1303 | |
| 1304 | SetExitStatus (-1, error_string); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1305 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | if (error.Success()) |
| 1309 | { |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 1310 | m_gdb_comm.SetDetachOnError(attach_info.GetDetachOnError()); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1311 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1312 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1313 | const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid); |
Greg Clayton | 3b60842 | 2011-11-19 02:11:30 +0000 | [diff] [blame] | 1314 | SetID (attach_pid); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1315 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (packet, packet_len)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1316 | } |
| 1317 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1318 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1319 | return error; |
| 1320 | } |
| 1321 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1322 | Error |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 1323 | ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | { |
| 1325 | Error error; |
| 1326 | // Clear out and clean up from any current state |
| 1327 | Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1328 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1329 | if (process_name && process_name[0]) |
| 1330 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1331 | // Make sure we aren't already connected? |
| 1332 | if (!m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1333 | { |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 1334 | error = LaunchAndConnectToDebugserver (attach_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1335 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1336 | if (error.Fail()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1337 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1338 | const char *error_string = error.AsCString(); |
| 1339 | if (error_string == NULL) |
| 1340 | error_string = "unable to launch " DEBUGSERVER_BASENAME; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1341 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1342 | SetExitStatus (-1, error_string); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1343 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | if (error.Success()) |
| 1347 | { |
| 1348 | StreamString packet; |
| 1349 | |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 1350 | m_gdb_comm.SetDetachOnError(attach_info.GetDetachOnError()); |
| 1351 | |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 1352 | if (attach_info.GetWaitForLaunch()) |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 1353 | { |
| 1354 | if (!m_gdb_comm.GetVAttachOrWaitSupported()) |
| 1355 | { |
| 1356 | packet.PutCString ("vAttachWait"); |
| 1357 | } |
| 1358 | else |
| 1359 | { |
| 1360 | if (attach_info.GetIgnoreExisting()) |
| 1361 | packet.PutCString("vAttachWait"); |
| 1362 | else |
| 1363 | packet.PutCString ("vAttachOrWait"); |
| 1364 | } |
| 1365 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1366 | else |
| 1367 | packet.PutCString("vAttachName"); |
| 1368 | packet.PutChar(';'); |
| 1369 | packet.PutBytesAsRawHex8(process_name, strlen(process_name), lldb::endian::InlHostByteOrder(), lldb::endian::InlHostByteOrder()); |
| 1370 | |
| 1371 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (packet.GetData(), packet.GetSize())); |
| 1372 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1373 | } |
| 1374 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1375 | return error; |
| 1376 | } |
| 1377 | |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1378 | void |
| 1379 | ProcessGDBRemote::DidExit () |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1380 | { |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1381 | // When we exit, disconnect from the GDB server communications |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1382 | m_gdb_comm.Disconnect(); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1385 | void |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1386 | ProcessGDBRemote::DidAttach (ArchSpec &process_arch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1387 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1388 | // If you can figure out what the architecture is, fill it in here. |
| 1389 | process_arch.Clear(); |
| 1390 | DidLaunchOrAttach (process_arch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1393 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1394 | Error |
| 1395 | ProcessGDBRemote::WillResume () |
| 1396 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1397 | m_continue_c_tids.clear(); |
| 1398 | m_continue_C_tids.clear(); |
| 1399 | m_continue_s_tids.clear(); |
| 1400 | m_continue_S_tids.clear(); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1401 | m_jstopinfo_sp.reset(); |
| 1402 | m_jthreadsinfo_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1403 | return Error(); |
| 1404 | } |
| 1405 | |
| 1406 | Error |
| 1407 | ProcessGDBRemote::DoResume () |
| 1408 | { |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 1409 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1410 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 6d09345 | 2011-02-05 02:25:06 +0000 | [diff] [blame] | 1411 | if (log) |
| 1412 | log->Printf ("ProcessGDBRemote::Resume()"); |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1413 | |
| 1414 | Listener listener ("gdb-remote.resume-packet-sent"); |
| 1415 | if (listener.StartListeningForEvents (&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent)) |
| 1416 | { |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1417 | listener.StartListeningForEvents (&m_async_broadcaster, ProcessGDBRemote::eBroadcastBitAsyncThreadDidExit); |
| 1418 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1419 | const size_t num_threads = GetThreadList().GetSize(); |
| 1420 | |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1421 | StreamString continue_packet; |
| 1422 | bool continue_packet_error = false; |
| 1423 | if (m_gdb_comm.HasAnyVContSupport ()) |
| 1424 | { |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1425 | if (!GetTarget().GetNonStopModeEnabled() && |
| 1426 | (m_continue_c_tids.size() == num_threads || |
Greg Clayton | e98008c | 2014-02-13 23:34:38 +0000 | [diff] [blame] | 1427 | (m_continue_c_tids.empty() && |
| 1428 | m_continue_C_tids.empty() && |
| 1429 | m_continue_s_tids.empty() && |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1430 | m_continue_S_tids.empty()))) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1431 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1432 | // All threads are continuing, just send a "c" packet |
| 1433 | continue_packet.PutCString ("c"); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1434 | } |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1435 | else |
| 1436 | { |
| 1437 | continue_packet.PutCString ("vCont"); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1438 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1439 | if (!m_continue_c_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1440 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1441 | if (m_gdb_comm.GetVContSupported ('c')) |
| 1442 | { |
| 1443 | for (tid_collection::const_iterator t_pos = m_continue_c_tids.begin(), t_end = m_continue_c_tids.end(); t_pos != t_end; ++t_pos) |
| 1444 | continue_packet.Printf(";c:%4.4" PRIx64, *t_pos); |
| 1445 | } |
| 1446 | else |
| 1447 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1448 | } |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1449 | |
| 1450 | if (!continue_packet_error && !m_continue_C_tids.empty()) |
| 1451 | { |
| 1452 | if (m_gdb_comm.GetVContSupported ('C')) |
| 1453 | { |
| 1454 | for (tid_sig_collection::const_iterator s_pos = m_continue_C_tids.begin(), s_end = m_continue_C_tids.end(); s_pos != s_end; ++s_pos) |
| 1455 | continue_packet.Printf(";C%2.2x:%4.4" PRIx64, s_pos->second, s_pos->first); |
| 1456 | } |
| 1457 | else |
| 1458 | continue_packet_error = true; |
| 1459 | } |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1460 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1461 | if (!continue_packet_error && !m_continue_s_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1462 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1463 | if (m_gdb_comm.GetVContSupported ('s')) |
| 1464 | { |
| 1465 | for (tid_collection::const_iterator t_pos = m_continue_s_tids.begin(), t_end = m_continue_s_tids.end(); t_pos != t_end; ++t_pos) |
| 1466 | continue_packet.Printf(";s:%4.4" PRIx64, *t_pos); |
| 1467 | } |
| 1468 | else |
| 1469 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1470 | } |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (!continue_packet_error && !m_continue_S_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1473 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1474 | if (m_gdb_comm.GetVContSupported ('S')) |
| 1475 | { |
| 1476 | for (tid_sig_collection::const_iterator s_pos = m_continue_S_tids.begin(), s_end = m_continue_S_tids.end(); s_pos != s_end; ++s_pos) |
| 1477 | continue_packet.Printf(";S%2.2x:%4.4" PRIx64, s_pos->second, s_pos->first); |
| 1478 | } |
| 1479 | else |
| 1480 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1481 | } |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (continue_packet_error) |
| 1484 | continue_packet.GetString().clear(); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1485 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1486 | } |
| 1487 | else |
| 1488 | continue_packet_error = true; |
| 1489 | |
| 1490 | if (continue_packet_error) |
| 1491 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1492 | // Either no vCont support, or we tried to use part of the vCont |
| 1493 | // packet that wasn't supported by the remote GDB server. |
| 1494 | // We need to try and make a simple packet that can do our continue |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1495 | const size_t num_continue_c_tids = m_continue_c_tids.size(); |
| 1496 | const size_t num_continue_C_tids = m_continue_C_tids.size(); |
| 1497 | const size_t num_continue_s_tids = m_continue_s_tids.size(); |
| 1498 | const size_t num_continue_S_tids = m_continue_S_tids.size(); |
| 1499 | if (num_continue_c_tids > 0) |
| 1500 | { |
| 1501 | if (num_continue_c_tids == num_threads) |
| 1502 | { |
| 1503 | // All threads are resuming... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1504 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1505 | continue_packet.PutChar ('c'); |
| 1506 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1507 | } |
| 1508 | else if (num_continue_c_tids == 1 && |
| 1509 | num_continue_C_tids == 0 && |
| 1510 | num_continue_s_tids == 0 && |
| 1511 | num_continue_S_tids == 0 ) |
| 1512 | { |
| 1513 | // Only one thread is continuing |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1514 | m_gdb_comm.SetCurrentThreadForRun (m_continue_c_tids.front()); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1515 | continue_packet.PutChar ('c'); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1516 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1520 | if (continue_packet_error && num_continue_C_tids > 0) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1521 | { |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1522 | if ((num_continue_C_tids + num_continue_c_tids) == num_threads && |
| 1523 | num_continue_C_tids > 0 && |
| 1524 | num_continue_s_tids == 0 && |
| 1525 | num_continue_S_tids == 0 ) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1526 | { |
| 1527 | const int continue_signo = m_continue_C_tids.front().second; |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1528 | // Only one thread is continuing |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1529 | if (num_continue_C_tids > 1) |
| 1530 | { |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1531 | // More that one thread with a signal, yet we don't have |
| 1532 | // vCont support and we are being asked to resume each |
| 1533 | // thread with a signal, we need to make sure they are |
| 1534 | // all the same signal, or we can't issue the continue |
| 1535 | // accurately with the current support... |
| 1536 | if (num_continue_C_tids > 1) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1537 | { |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1538 | continue_packet_error = false; |
| 1539 | for (size_t i=1; i<m_continue_C_tids.size(); ++i) |
| 1540 | { |
| 1541 | if (m_continue_C_tids[i].second != continue_signo) |
| 1542 | continue_packet_error = true; |
| 1543 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1544 | } |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1545 | if (!continue_packet_error) |
| 1546 | m_gdb_comm.SetCurrentThreadForRun (-1); |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | // Set the continue thread ID |
| 1551 | continue_packet_error = false; |
| 1552 | m_gdb_comm.SetCurrentThreadForRun (m_continue_C_tids.front().first); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1553 | } |
| 1554 | if (!continue_packet_error) |
| 1555 | { |
| 1556 | // Add threads continuing with the same signo... |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1557 | continue_packet.Printf("C%2.2x", continue_signo); |
| 1558 | } |
| 1559 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1562 | if (continue_packet_error && num_continue_s_tids > 0) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1563 | { |
| 1564 | if (num_continue_s_tids == num_threads) |
| 1565 | { |
| 1566 | // All threads are resuming... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1567 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 1568 | |
| 1569 | // If in Non-Stop-Mode use vCont when stepping |
| 1570 | if (GetTarget().GetNonStopModeEnabled()) |
| 1571 | { |
| 1572 | if (m_gdb_comm.GetVContSupported('s')) |
| 1573 | continue_packet.PutCString("vCont;s"); |
| 1574 | else |
| 1575 | continue_packet.PutChar('s'); |
| 1576 | } |
| 1577 | else |
| 1578 | continue_packet.PutChar('s'); |
| 1579 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1580 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1581 | } |
| 1582 | else if (num_continue_c_tids == 0 && |
| 1583 | num_continue_C_tids == 0 && |
| 1584 | num_continue_s_tids == 1 && |
| 1585 | num_continue_S_tids == 0 ) |
| 1586 | { |
| 1587 | // Only one thread is stepping |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1588 | m_gdb_comm.SetCurrentThreadForRun (m_continue_s_tids.front()); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1589 | continue_packet.PutChar ('s'); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1590 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | if (!continue_packet_error && num_continue_S_tids > 0) |
| 1595 | { |
| 1596 | if (num_continue_S_tids == num_threads) |
| 1597 | { |
| 1598 | const int step_signo = m_continue_S_tids.front().second; |
| 1599 | // Are all threads trying to step with the same signal? |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1600 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1601 | if (num_continue_S_tids > 1) |
| 1602 | { |
| 1603 | for (size_t i=1; i<num_threads; ++i) |
| 1604 | { |
| 1605 | if (m_continue_S_tids[i].second != step_signo) |
| 1606 | continue_packet_error = true; |
| 1607 | } |
| 1608 | } |
| 1609 | if (!continue_packet_error) |
| 1610 | { |
| 1611 | // Add threads stepping with the same signo... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1612 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1613 | continue_packet.Printf("S%2.2x", step_signo); |
| 1614 | } |
| 1615 | } |
| 1616 | else if (num_continue_c_tids == 0 && |
| 1617 | num_continue_C_tids == 0 && |
| 1618 | num_continue_s_tids == 0 && |
| 1619 | num_continue_S_tids == 1 ) |
| 1620 | { |
| 1621 | // Only one thread is stepping with signal |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1622 | m_gdb_comm.SetCurrentThreadForRun (m_continue_S_tids.front().first); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1623 | continue_packet.Printf("S%2.2x", m_continue_S_tids.front().second); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1624 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | if (continue_packet_error) |
| 1630 | { |
| 1631 | error.SetErrorString ("can't make continue packet for this resume"); |
| 1632 | } |
| 1633 | else |
| 1634 | { |
| 1635 | EventSP event_sp; |
| 1636 | TimeValue timeout; |
| 1637 | timeout = TimeValue::Now(); |
| 1638 | timeout.OffsetWithSeconds (5); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1639 | if (!m_async_thread.IsJoinable()) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1640 | { |
| 1641 | error.SetErrorString ("Trying to resume but the async thread is dead."); |
| 1642 | if (log) |
| 1643 | log->Printf ("ProcessGDBRemote::DoResume: Trying to resume but the async thread is dead."); |
| 1644 | return error; |
| 1645 | } |
| 1646 | |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1647 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (continue_packet.GetData(), continue_packet.GetSize())); |
| 1648 | |
| 1649 | if (listener.WaitForEvent (&timeout, event_sp) == false) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1650 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1651 | error.SetErrorString("Resume timed out."); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1652 | if (log) |
| 1653 | log->Printf ("ProcessGDBRemote::DoResume: Resume timed out."); |
| 1654 | } |
| 1655 | else if (event_sp->BroadcasterIs (&m_async_broadcaster)) |
| 1656 | { |
| 1657 | error.SetErrorString ("Broadcast continue, but the async thread was killed before we got an ack back."); |
| 1658 | if (log) |
| 1659 | log->Printf ("ProcessGDBRemote::DoResume: Broadcast continue, but the async thread was killed before we got an ack back."); |
| 1660 | return error; |
| 1661 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1662 | } |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 1665 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1668 | void |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1669 | ProcessGDBRemote::HandleStopReplySequence () |
| 1670 | { |
| 1671 | while(true) |
| 1672 | { |
| 1673 | // Send vStopped |
| 1674 | StringExtractorGDBRemote response; |
| 1675 | m_gdb_comm.SendPacketAndWaitForResponse("vStopped", response, false); |
| 1676 | |
| 1677 | // OK represents end of signal list |
| 1678 | if (response.IsOKResponse()) |
| 1679 | break; |
| 1680 | |
| 1681 | // If not OK or a normal packet we have a problem |
| 1682 | if (!response.IsNormalResponse()) |
| 1683 | break; |
| 1684 | |
| 1685 | SetLastStopPacket(response); |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | void |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1690 | ProcessGDBRemote::ClearThreadIDList () |
| 1691 | { |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1692 | Mutex::Locker locker(m_thread_list_real.GetMutex()); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1693 | m_thread_ids.clear(); |
| 1694 | } |
| 1695 | |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1696 | size_t |
| 1697 | ProcessGDBRemote::UpdateThreadIDsFromStopReplyThreadsValue (std::string &value) |
| 1698 | { |
| 1699 | m_thread_ids.clear(); |
| 1700 | size_t comma_pos; |
| 1701 | lldb::tid_t tid; |
| 1702 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 1703 | { |
| 1704 | value[comma_pos] = '\0'; |
| 1705 | // thread in big endian hex |
| 1706 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
| 1707 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1708 | m_thread_ids.push_back (tid); |
| 1709 | value.erase(0, comma_pos + 1); |
| 1710 | } |
| 1711 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
| 1712 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1713 | m_thread_ids.push_back (tid); |
| 1714 | return m_thread_ids.size(); |
| 1715 | } |
| 1716 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1717 | bool |
| 1718 | ProcessGDBRemote::UpdateThreadIDList () |
| 1719 | { |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1720 | Mutex::Locker locker(m_thread_list_real.GetMutex()); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1721 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1722 | if (m_jthreadsinfo_sp) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1723 | { |
| 1724 | // If we have the JSON threads info, we can get the thread list from that |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1725 | StructuredData::Array *thread_infos = m_jthreadsinfo_sp->GetAsArray(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1726 | if (thread_infos && thread_infos->GetSize() > 0) |
| 1727 | { |
| 1728 | m_thread_ids.clear(); |
| 1729 | thread_infos->ForEach([this](StructuredData::Object* object) -> bool { |
| 1730 | StructuredData::Dictionary *thread_dict = object->GetAsDictionary(); |
| 1731 | if (thread_dict) |
| 1732 | { |
| 1733 | // Set the thread stop info from the JSON dictionary |
| 1734 | SetThreadStopInfo (thread_dict); |
| 1735 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
| 1736 | if (thread_dict->GetValueForKeyAsInteger<lldb::tid_t>("tid", tid)) |
| 1737 | m_thread_ids.push_back(tid); |
| 1738 | } |
| 1739 | return true; // Keep iterating through all thread_info objects |
| 1740 | }); |
| 1741 | } |
| 1742 | if (!m_thread_ids.empty()) |
| 1743 | return true; |
| 1744 | } |
| 1745 | else |
| 1746 | { |
| 1747 | // See if we can get the thread IDs from the current stop reply packets |
| 1748 | // that might contain a "threads" key/value pair |
| 1749 | |
| 1750 | // Lock the thread stack while we access it |
| 1751 | Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); |
| 1752 | // Get the number of stop packets on the stack |
| 1753 | int nItems = m_stop_packet_stack.size(); |
| 1754 | // Iterate over them |
| 1755 | for (int i = 0; i < nItems; i++) |
| 1756 | { |
| 1757 | // Get the thread stop info |
| 1758 | StringExtractorGDBRemote &stop_info = m_stop_packet_stack[i]; |
| 1759 | const std::string &stop_info_str = stop_info.GetStringRef(); |
| 1760 | const size_t threads_pos = stop_info_str.find(";threads:"); |
| 1761 | if (threads_pos != std::string::npos) |
| 1762 | { |
| 1763 | const size_t start = threads_pos + strlen(";threads:"); |
| 1764 | const size_t end = stop_info_str.find(';', start); |
| 1765 | if (end != std::string::npos) |
| 1766 | { |
| 1767 | std::string value = stop_info_str.substr(start, end - start); |
| 1768 | if (UpdateThreadIDsFromStopReplyThreadsValue(value)) |
| 1769 | return true; |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1775 | bool sequence_mutex_unavailable = false; |
| 1776 | m_gdb_comm.GetCurrentThreadIDs (m_thread_ids, sequence_mutex_unavailable); |
| 1777 | if (sequence_mutex_unavailable) |
| 1778 | { |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1779 | return false; // We just didn't get the list |
| 1780 | } |
| 1781 | return true; |
| 1782 | } |
| 1783 | |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1784 | bool |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1785 | ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1786 | { |
| 1787 | // locker will keep a mutex locked until it goes out of scope |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1788 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_THREAD)); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1789 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1790 | log->Printf ("ProcessGDBRemote::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID()); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1791 | |
| 1792 | size_t num_thread_ids = m_thread_ids.size(); |
| 1793 | // The "m_thread_ids" thread ID list should always be updated after each stop |
| 1794 | // reply packet, but in case it isn't, update it here. |
| 1795 | if (num_thread_ids == 0) |
| 1796 | { |
| 1797 | if (!UpdateThreadIDList ()) |
| 1798 | return false; |
| 1799 | num_thread_ids = m_thread_ids.size(); |
| 1800 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1801 | |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1802 | ThreadList old_thread_list_copy(old_thread_list); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1803 | if (num_thread_ids > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1804 | { |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1805 | for (size_t i=0; i<num_thread_ids; ++i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1806 | { |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1807 | tid_t tid = m_thread_ids[i]; |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1808 | ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByProtocolID(tid, false)); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1809 | if (!thread_sp) |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1810 | { |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1811 | thread_sp.reset (new ThreadGDBRemote (*this, tid)); |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1812 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
| 1813 | log->Printf( |
| 1814 | "ProcessGDBRemote::%s Making new thread: %p for thread ID: 0x%" PRIx64 ".\n", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1815 | __FUNCTION__, static_cast<void*>(thread_sp.get()), |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1816 | thread_sp->GetID()); |
| 1817 | } |
| 1818 | else |
| 1819 | { |
| 1820 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
| 1821 | log->Printf( |
| 1822 | "ProcessGDBRemote::%s Found old thread: %p for thread ID: 0x%" PRIx64 ".\n", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1823 | __FUNCTION__, static_cast<void*>(thread_sp.get()), |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1824 | thread_sp->GetID()); |
| 1825 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1826 | new_thread_list.AddThread(thread_sp); |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 1827 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1828 | } |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1829 | |
| 1830 | // Whatever that is left in old_thread_list_copy are not |
| 1831 | // present in new_thread_list. Remove non-existent threads from internal id table. |
| 1832 | size_t old_num_thread_ids = old_thread_list_copy.GetSize(false); |
| 1833 | for (size_t i=0; i<old_num_thread_ids; i++) |
| 1834 | { |
| 1835 | ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex (i, false)); |
| 1836 | if (old_thread_sp) |
| 1837 | { |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1838 | lldb::tid_t old_thread_id = old_thread_sp->GetProtocolID(); |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1839 | m_thread_id_to_index_id_map.erase(old_thread_id); |
| 1840 | } |
| 1841 | } |
| 1842 | |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1843 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1846 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1847 | bool |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1848 | ProcessGDBRemote::GetThreadStopInfoFromJSON (ThreadGDBRemote *thread, const StructuredData::ObjectSP &thread_infos_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1849 | { |
| 1850 | // See if we got thread stop infos for all threads via the "jThreadsInfo" packet |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1851 | if (thread_infos_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1852 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1853 | StructuredData::Array *thread_infos = thread_infos_sp->GetAsArray(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1854 | if (thread_infos) |
| 1855 | { |
| 1856 | lldb::tid_t tid; |
| 1857 | const size_t n = thread_infos->GetSize(); |
| 1858 | for (size_t i=0; i<n; ++i) |
| 1859 | { |
| 1860 | StructuredData::Dictionary *thread_dict = thread_infos->GetItemAtIndex(i)->GetAsDictionary(); |
| 1861 | if (thread_dict) |
| 1862 | { |
| 1863 | if (thread_dict->GetValueForKeyAsInteger<lldb::tid_t>("tid", tid, LLDB_INVALID_THREAD_ID)) |
| 1864 | { |
| 1865 | if (tid == thread->GetID()) |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1866 | return (bool)SetThreadStopInfo(thread_dict); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | |
| 1875 | bool |
| 1876 | ProcessGDBRemote::CalculateThreadStopInfo (ThreadGDBRemote *thread) |
| 1877 | { |
| 1878 | // See if we got thread stop infos for all threads via the "jThreadsInfo" packet |
| 1879 | if (GetThreadStopInfoFromJSON (thread, m_jthreadsinfo_sp)) |
| 1880 | return true; |
| 1881 | |
| 1882 | // See if we got thread stop info for any threads valid stop info reasons threads |
| 1883 | // via the "jstopinfo" packet stop reply packet key/value pair? |
| 1884 | if (m_jstopinfo_sp) |
| 1885 | { |
| 1886 | // If we have "jstopinfo" then we have stop descriptions for all threads |
| 1887 | // that have stop reasons, and if there is no entry for a thread, then |
| 1888 | // it has no stop reason. |
| 1889 | thread->GetRegisterContext()->InvalidateIfNeeded(true); |
| 1890 | if (!GetThreadStopInfoFromJSON (thread, m_jstopinfo_sp)) |
| 1891 | { |
| 1892 | thread->SetStopInfo (StopInfoSP()); |
| 1893 | } |
| 1894 | return true; |
| 1895 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1896 | |
| 1897 | // Fall back to using the qThreadStopInfo packet |
| 1898 | StringExtractorGDBRemote stop_packet; |
| 1899 | if (GetGDBRemote().GetThreadStopInfo(thread->GetProtocolID(), stop_packet)) |
| 1900 | return SetThreadStopInfo (stop_packet) == eStateStopped; |
| 1901 | return false; |
| 1902 | } |
| 1903 | |
| 1904 | |
| 1905 | ThreadSP |
| 1906 | ProcessGDBRemote::SetThreadStopInfo (lldb::tid_t tid, |
| 1907 | ExpeditedRegisterMap &expedited_register_map, |
| 1908 | uint8_t signo, |
| 1909 | const std::string &thread_name, |
| 1910 | const std::string &reason, |
| 1911 | const std::string &description, |
| 1912 | uint32_t exc_type, |
| 1913 | const std::vector<addr_t> &exc_data, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1914 | addr_t thread_dispatch_qaddr, |
| 1915 | bool queue_vars_valid, // Set to true if queue_name, queue_kind and queue_serial are valid |
| 1916 | std::string &queue_name, |
| 1917 | QueueKind queue_kind, |
| 1918 | uint64_t queue_serial) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1919 | { |
| 1920 | ThreadSP thread_sp; |
| 1921 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1922 | { |
| 1923 | // Scope for "locker" below |
| 1924 | { |
| 1925 | // m_thread_list_real does have its own mutex, but we need to |
| 1926 | // hold onto the mutex between the call to m_thread_list_real.FindThreadByID(...) |
| 1927 | // and the m_thread_list_real.AddThread(...) so it doesn't change on us |
| 1928 | Mutex::Locker locker (m_thread_list_real.GetMutex ()); |
| 1929 | thread_sp = m_thread_list_real.FindThreadByProtocolID(tid, false); |
| 1930 | |
| 1931 | if (!thread_sp) |
| 1932 | { |
| 1933 | // Create the thread if we need to |
| 1934 | thread_sp.reset (new ThreadGDBRemote (*this, tid)); |
| 1935 | m_thread_list_real.AddThread(thread_sp); |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | if (thread_sp) |
| 1940 | { |
| 1941 | ThreadGDBRemote *gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); |
| 1942 | gdb_thread->GetRegisterContext()->InvalidateIfNeeded(true); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1943 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1944 | for (const auto &pair : expedited_register_map) |
| 1945 | { |
| 1946 | StringExtractor reg_value_extractor; |
| 1947 | reg_value_extractor.GetStringRef() = pair.second; |
| 1948 | gdb_thread->PrivateSetRegisterValue (pair.first, reg_value_extractor); |
| 1949 | } |
| 1950 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1951 | thread_sp->SetName (thread_name.empty() ? NULL : thread_name.c_str()); |
| 1952 | |
| 1953 | gdb_thread->SetThreadDispatchQAddr (thread_dispatch_qaddr); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1954 | // Check if the GDB server was able to provide the queue name, kind and serial number |
| 1955 | if (queue_vars_valid) |
| 1956 | gdb_thread->SetQueueInfo(std::move(queue_name), queue_kind, queue_serial); |
| 1957 | else |
| 1958 | gdb_thread->ClearQueueInfo(); |
| 1959 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1960 | // Make sure we update our thread stop reason just once |
| 1961 | if (!thread_sp->StopInfoIsUpToDate()) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1962 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1963 | thread_sp->SetStopInfo (StopInfoSP()); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1964 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1965 | if (exc_type != 0) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1966 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1967 | const size_t exc_data_size = exc_data.size(); |
| 1968 | |
| 1969 | thread_sp->SetStopInfo (StopInfoMachException::CreateStopReasonWithMachException (*thread_sp, |
| 1970 | exc_type, |
| 1971 | exc_data_size, |
| 1972 | exc_data_size >= 1 ? exc_data[0] : 0, |
| 1973 | exc_data_size >= 2 ? exc_data[1] : 0, |
| 1974 | exc_data_size >= 3 ? exc_data[2] : 0)); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1975 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1976 | else |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1977 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1978 | bool handled = false; |
| 1979 | bool did_exec = false; |
| 1980 | if (!reason.empty()) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1981 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1982 | if (reason.compare("trace") == 0) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1983 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1984 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); |
| 1985 | handled = true; |
| 1986 | } |
| 1987 | else if (reason.compare("breakpoint") == 0) |
| 1988 | { |
| 1989 | addr_t pc = thread_sp->GetRegisterContext()->GetPC(); |
| 1990 | lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 1991 | if (bp_site_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1992 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1993 | // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, |
| 1994 | // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that |
| 1995 | // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. |
| 1996 | handled = true; |
| 1997 | if (bp_site_sp->ValidForThisThread (thread_sp.get())) |
| 1998 | { |
| 1999 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); |
| 2000 | } |
| 2001 | else |
| 2002 | { |
| 2003 | StopInfoSP invalid_stop_info_sp; |
| 2004 | thread_sp->SetStopInfo (invalid_stop_info_sp); |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | else if (reason.compare("trap") == 0) |
| 2009 | { |
| 2010 | // Let the trap just use the standard signal stop reason below... |
| 2011 | } |
| 2012 | else if (reason.compare("watchpoint") == 0) |
| 2013 | { |
| 2014 | StringExtractor desc_extractor(description.c_str()); |
| 2015 | addr_t wp_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS); |
| 2016 | uint32_t wp_index = desc_extractor.GetU32(LLDB_INVALID_INDEX32); |
| 2017 | watch_id_t watch_id = LLDB_INVALID_WATCH_ID; |
| 2018 | if (wp_addr != LLDB_INVALID_ADDRESS) |
| 2019 | { |
| 2020 | WatchpointSP wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_addr); |
| 2021 | if (wp_sp) |
| 2022 | { |
| 2023 | wp_sp->SetHardwareIndex(wp_index); |
| 2024 | watch_id = wp_sp->GetID(); |
| 2025 | } |
| 2026 | } |
| 2027 | if (watch_id == LLDB_INVALID_WATCH_ID) |
| 2028 | { |
| 2029 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_WATCHPOINTS)); |
| 2030 | if (log) log->Printf ("failed to find watchpoint"); |
| 2031 | } |
| 2032 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithWatchpointID (*thread_sp, watch_id)); |
| 2033 | handled = true; |
| 2034 | } |
| 2035 | else if (reason.compare("exception") == 0) |
| 2036 | { |
| 2037 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException(*thread_sp, description.c_str())); |
| 2038 | handled = true; |
| 2039 | } |
| 2040 | else if (reason.compare("exec") == 0) |
| 2041 | { |
| 2042 | did_exec = true; |
| 2043 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithExec(*thread_sp)); |
| 2044 | handled = true; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | if (!handled && signo && did_exec == false) |
| 2049 | { |
| 2050 | if (signo == SIGTRAP) |
| 2051 | { |
| 2052 | // Currently we are going to assume SIGTRAP means we are either |
| 2053 | // hitting a breakpoint or hardware single stepping. |
| 2054 | handled = true; |
| 2055 | addr_t pc = thread_sp->GetRegisterContext()->GetPC() + m_breakpoint_pc_offset; |
| 2056 | lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 2057 | |
| 2058 | if (bp_site_sp) |
| 2059 | { |
| 2060 | // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, |
| 2061 | // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that |
| 2062 | // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. |
| 2063 | if (bp_site_sp->ValidForThisThread (thread_sp.get())) |
| 2064 | { |
| 2065 | if(m_breakpoint_pc_offset != 0) |
| 2066 | thread_sp->GetRegisterContext()->SetPC(pc); |
| 2067 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); |
| 2068 | } |
| 2069 | else |
| 2070 | { |
| 2071 | StopInfoSP invalid_stop_info_sp; |
| 2072 | thread_sp->SetStopInfo (invalid_stop_info_sp); |
| 2073 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2074 | } |
| 2075 | else |
| 2076 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2077 | // If we were stepping then assume the stop was the result of the trace. If we were |
| 2078 | // not stepping then report the SIGTRAP. |
| 2079 | // FIXME: We are still missing the case where we single step over a trap instruction. |
| 2080 | if (thread_sp->GetTemporaryResumeState() == eStateStepping) |
| 2081 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); |
| 2082 | else |
| 2083 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal(*thread_sp, signo, description.c_str())); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2084 | } |
| 2085 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2086 | if (!handled) |
| 2087 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal (*thread_sp, signo, description.c_str())); |
| 2088 | } |
| 2089 | |
| 2090 | if (!description.empty()) |
| 2091 | { |
| 2092 | lldb::StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); |
| 2093 | if (stop_info_sp) |
| 2094 | { |
| 2095 | const char *stop_info_desc = stop_info_sp->GetDescription(); |
| 2096 | if (!stop_info_desc || !stop_info_desc[0]) |
| 2097 | stop_info_sp->SetDescription (description.c_str()); |
| 2098 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2099 | else |
| 2100 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2101 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException (*thread_sp, description.c_str())); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2102 | } |
| 2103 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2104 | } |
| 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | return thread_sp; |
| 2109 | } |
| 2110 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2111 | lldb::ThreadSP |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2112 | ProcessGDBRemote::SetThreadStopInfo (StructuredData::Dictionary *thread_dict) |
| 2113 | { |
| 2114 | static ConstString g_key_tid("tid"); |
| 2115 | static ConstString g_key_name("name"); |
| 2116 | static ConstString g_key_reason("reason"); |
| 2117 | static ConstString g_key_metype("metype"); |
| 2118 | static ConstString g_key_medata("medata"); |
| 2119 | static ConstString g_key_qaddr("qaddr"); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2120 | static ConstString g_key_queue_name("qname"); |
| 2121 | static ConstString g_key_queue_kind("qkind"); |
| 2122 | static ConstString g_key_queue_serial("qserial"); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2123 | static ConstString g_key_registers("registers"); |
| 2124 | static ConstString g_key_memory("memory"); |
| 2125 | static ConstString g_key_address("address"); |
| 2126 | static ConstString g_key_bytes("bytes"); |
| 2127 | static ConstString g_key_description("description"); |
Pavel Labath | 4a4bb12 | 2015-07-16 14:14:35 +0000 | [diff] [blame] | 2128 | static ConstString g_key_signal("signal"); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Stop with signal and thread info |
| 2131 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
| 2132 | uint8_t signo = 0; |
| 2133 | std::string value; |
| 2134 | std::string thread_name; |
| 2135 | std::string reason; |
| 2136 | std::string description; |
| 2137 | uint32_t exc_type = 0; |
| 2138 | std::vector<addr_t> exc_data; |
| 2139 | addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; |
| 2140 | ExpeditedRegisterMap expedited_register_map; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2141 | bool queue_vars_valid = false; |
| 2142 | std::string queue_name; |
| 2143 | QueueKind queue_kind = eQueueKindUnknown; |
| 2144 | uint64_t queue_serial = 0; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2145 | // Iterate through all of the thread dictionary key/value pairs from the structured data dictionary |
| 2146 | |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2147 | thread_dict->ForEach([this, |
| 2148 | &tid, |
| 2149 | &expedited_register_map, |
| 2150 | &thread_name, |
| 2151 | &signo, |
| 2152 | &reason, |
| 2153 | &description, |
| 2154 | &exc_type, |
| 2155 | &exc_data, |
| 2156 | &thread_dispatch_qaddr, |
| 2157 | &queue_vars_valid, |
| 2158 | &queue_name, |
| 2159 | &queue_kind, |
| 2160 | &queue_serial] |
| 2161 | (ConstString key, StructuredData::Object* object) -> bool |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2162 | { |
| 2163 | if (key == g_key_tid) |
| 2164 | { |
| 2165 | // thread in big endian hex |
| 2166 | tid = object->GetIntegerValue(LLDB_INVALID_THREAD_ID); |
| 2167 | } |
| 2168 | else if (key == g_key_metype) |
| 2169 | { |
| 2170 | // exception type in big endian hex |
| 2171 | exc_type = object->GetIntegerValue(0); |
| 2172 | } |
| 2173 | else if (key == g_key_medata) |
| 2174 | { |
| 2175 | // exception data in big endian hex |
| 2176 | StructuredData::Array *array = object->GetAsArray(); |
| 2177 | if (array) |
| 2178 | { |
| 2179 | array->ForEach([&exc_data](StructuredData::Object* object) -> bool { |
| 2180 | exc_data.push_back(object->GetIntegerValue()); |
| 2181 | return true; // Keep iterating through all array items |
| 2182 | }); |
| 2183 | } |
| 2184 | } |
| 2185 | else if (key == g_key_name) |
| 2186 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2187 | thread_name = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2188 | } |
| 2189 | else if (key == g_key_qaddr) |
| 2190 | { |
| 2191 | thread_dispatch_qaddr = object->GetIntegerValue(LLDB_INVALID_ADDRESS); |
| 2192 | } |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2193 | else if (key == g_key_queue_name) |
| 2194 | { |
| 2195 | queue_vars_valid = true; |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2196 | queue_name = object->GetStringValue(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2197 | } |
| 2198 | else if (key == g_key_queue_kind) |
| 2199 | { |
| 2200 | std::string queue_kind_str = object->GetStringValue(); |
| 2201 | if (queue_kind_str == "serial") |
| 2202 | { |
| 2203 | queue_vars_valid = true; |
| 2204 | queue_kind = eQueueKindSerial; |
| 2205 | } |
| 2206 | else if (queue_kind_str == "concurrent") |
| 2207 | { |
| 2208 | queue_vars_valid = true; |
| 2209 | queue_kind = eQueueKindConcurrent; |
| 2210 | } |
| 2211 | } |
| 2212 | else if (key == g_key_queue_serial) |
| 2213 | { |
| 2214 | queue_serial = object->GetIntegerValue(0); |
| 2215 | if (queue_serial != 0) |
| 2216 | queue_vars_valid = true; |
| 2217 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2218 | else if (key == g_key_reason) |
| 2219 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2220 | reason = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2221 | } |
| 2222 | else if (key == g_key_description) |
| 2223 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2224 | description = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2225 | } |
| 2226 | else if (key == g_key_registers) |
| 2227 | { |
| 2228 | StructuredData::Dictionary *registers_dict = object->GetAsDictionary(); |
| 2229 | |
| 2230 | if (registers_dict) |
| 2231 | { |
| 2232 | registers_dict->ForEach([&expedited_register_map](ConstString key, StructuredData::Object* object) -> bool { |
| 2233 | const uint32_t reg = StringConvert::ToUInt32 (key.GetCString(), UINT32_MAX, 10); |
| 2234 | if (reg != UINT32_MAX) |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2235 | expedited_register_map[reg] = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2236 | return true; // Keep iterating through all array items |
| 2237 | }); |
| 2238 | } |
| 2239 | } |
| 2240 | else if (key == g_key_memory) |
| 2241 | { |
| 2242 | StructuredData::Array *array = object->GetAsArray(); |
| 2243 | if (array) |
| 2244 | { |
| 2245 | array->ForEach([this](StructuredData::Object* object) -> bool { |
| 2246 | StructuredData::Dictionary *mem_cache_dict = object->GetAsDictionary(); |
| 2247 | if (mem_cache_dict) |
| 2248 | { |
| 2249 | lldb::addr_t mem_cache_addr = LLDB_INVALID_ADDRESS; |
| 2250 | if (mem_cache_dict->GetValueForKeyAsInteger<lldb::addr_t>("address", mem_cache_addr)) |
| 2251 | { |
| 2252 | if (mem_cache_addr != LLDB_INVALID_ADDRESS) |
| 2253 | { |
| 2254 | StringExtractor bytes; |
| 2255 | if (mem_cache_dict->GetValueForKeyAsString("bytes", bytes.GetStringRef())) |
| 2256 | { |
| 2257 | bytes.SetFilePos(0); |
| 2258 | |
| 2259 | const size_t byte_size = bytes.GetStringRef().size()/2; |
| 2260 | DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 2261 | const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); |
| 2262 | if (bytes_copied == byte_size) |
| 2263 | m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); |
| 2264 | } |
| 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | return true; // Keep iterating through all array items |
| 2269 | }); |
| 2270 | } |
| 2271 | |
| 2272 | } |
Pavel Labath | 4a4bb12 | 2015-07-16 14:14:35 +0000 | [diff] [blame] | 2273 | else if (key == g_key_signal) |
| 2274 | signo = object->GetIntegerValue(LLDB_INVALID_SIGNAL_NUMBER); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2275 | return true; // Keep iterating through all dictionary key/value pairs |
| 2276 | }); |
| 2277 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2278 | return SetThreadStopInfo (tid, |
| 2279 | expedited_register_map, |
| 2280 | signo, |
| 2281 | thread_name, |
| 2282 | reason, |
| 2283 | description, |
| 2284 | exc_type, |
| 2285 | exc_data, |
| 2286 | thread_dispatch_qaddr, |
| 2287 | queue_vars_valid, |
| 2288 | queue_name, |
| 2289 | queue_kind, |
| 2290 | queue_serial); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2291 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2292 | |
| 2293 | StateType |
| 2294 | ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) |
| 2295 | { |
Greg Clayton | dd0e5a5 | 2011-06-02 22:22:38 +0000 | [diff] [blame] | 2296 | stop_packet.SetFilePos (0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2297 | const char stop_type = stop_packet.GetChar(); |
| 2298 | switch (stop_type) |
| 2299 | { |
| 2300 | case 'T': |
| 2301 | case 'S': |
| 2302 | { |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 2303 | // This is a bit of a hack, but is is required. If we did exec, we |
| 2304 | // need to clear our thread lists and also know to rebuild our dynamic |
| 2305 | // register info before we lookup and threads and populate the expedited |
| 2306 | // register values so we need to know this right away so we can cleanup |
| 2307 | // and update our registers. |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2308 | const uint32_t stop_id = GetStopID(); |
| 2309 | if (stop_id == 0) |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 2310 | { |
| 2311 | // Our first stop, make sure we have a process ID, and also make |
| 2312 | // sure we know about our registers |
| 2313 | if (GetID() == LLDB_INVALID_PROCESS_ID) |
| 2314 | { |
Greg Clayton | c574ede | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 2315 | lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID (); |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 2316 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 2317 | SetID (pid); |
| 2318 | } |
| 2319 | BuildDynamicRegisterInfo (true); |
| 2320 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2321 | // Stop with signal and thread info |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2322 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2323 | const uint8_t signo = stop_packet.GetHexU8(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2324 | std::string key; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2325 | std::string value; |
| 2326 | std::string thread_name; |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2327 | std::string reason; |
| 2328 | std::string description; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2329 | uint32_t exc_type = 0; |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 2330 | std::vector<addr_t> exc_data; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2331 | addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2332 | bool queue_vars_valid = false; // says if locals below that start with "queue_" are valid |
| 2333 | std::string queue_name; |
| 2334 | QueueKind queue_kind = eQueueKindUnknown; |
| 2335 | uint64_t queue_serial = 0; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2336 | ExpeditedRegisterMap expedited_register_map; |
| 2337 | while (stop_packet.GetNameColonValue(key, value)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2338 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2339 | if (key.compare("metype") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2340 | { |
| 2341 | // exception type in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2342 | exc_type = StringConvert::ToUInt32 (value.c_str(), 0, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2343 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2344 | else if (key.compare("medata") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2345 | { |
| 2346 | // exception data in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2347 | exc_data.push_back(StringConvert::ToUInt64 (value.c_str(), 0, 16)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2348 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2349 | else if (key.compare("thread") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2350 | { |
| 2351 | // thread in big endian hex |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2352 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2353 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2354 | else if (key.compare("threads") == 0) |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2355 | { |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 2356 | Mutex::Locker locker(m_thread_list_real.GetMutex()); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2357 | m_thread_ids.clear(); |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 2358 | // A comma separated list of all threads in the current |
| 2359 | // process that includes the thread for this stop reply |
| 2360 | // packet |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2361 | size_t comma_pos; |
| 2362 | lldb::tid_t tid; |
| 2363 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 2364 | { |
| 2365 | value[comma_pos] = '\0'; |
| 2366 | // thread in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2367 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2368 | if (tid != LLDB_INVALID_THREAD_ID) |
| 2369 | m_thread_ids.push_back (tid); |
| 2370 | value.erase(0, comma_pos + 1); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2371 | } |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2372 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2373 | if (tid != LLDB_INVALID_THREAD_ID) |
| 2374 | m_thread_ids.push_back (tid); |
| 2375 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2376 | else if (key.compare("jstopinfo") == 0) |
Greg Clayton | a5801ad | 2015-07-15 22:59:03 +0000 | [diff] [blame] | 2377 | { |
| 2378 | StringExtractor json_extractor; |
| 2379 | // Swap "value" over into "name_extractor" |
| 2380 | json_extractor.GetStringRef().swap(value); |
| 2381 | // Now convert the HEX bytes into a string value |
| 2382 | json_extractor.GetHexByteString (value); |
| 2383 | |
| 2384 | // This JSON contains thread IDs and thread stop info for all threads. |
| 2385 | // It doesn't contain expedited registers, memory or queue info. |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2386 | m_jstopinfo_sp = StructuredData::ParseJSON (value); |
Greg Clayton | a5801ad | 2015-07-15 22:59:03 +0000 | [diff] [blame] | 2387 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2388 | else if (key.compare("hexname") == 0) |
Greg Clayton | de9d049 | 2011-01-08 03:17:57 +0000 | [diff] [blame] | 2389 | { |
| 2390 | StringExtractor name_extractor; |
| 2391 | // Swap "value" over into "name_extractor" |
| 2392 | name_extractor.GetStringRef().swap(value); |
| 2393 | // Now convert the HEX bytes into a string value |
| 2394 | name_extractor.GetHexByteString (value); |
| 2395 | thread_name.swap (value); |
| 2396 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2397 | else if (key.compare("name") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2398 | { |
| 2399 | thread_name.swap (value); |
| 2400 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2401 | else if (key.compare("qaddr") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2402 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2403 | thread_dispatch_qaddr = StringConvert::ToUInt64 (value.c_str(), 0, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2404 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2405 | else if (key.compare("qname") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2406 | { |
| 2407 | queue_vars_valid = true; |
| 2408 | StringExtractor name_extractor; |
| 2409 | // Swap "value" over into "name_extractor" |
| 2410 | name_extractor.GetStringRef().swap(value); |
| 2411 | // Now convert the HEX bytes into a string value |
| 2412 | name_extractor.GetHexByteString (value); |
| 2413 | queue_name.swap (value); |
| 2414 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2415 | else if (key.compare("qkind") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2416 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2417 | if (value == "serial") |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2418 | { |
| 2419 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2420 | queue_kind = eQueueKindSerial; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2421 | } |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2422 | else if (value == "concurrent") |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2423 | { |
| 2424 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2425 | queue_kind = eQueueKindConcurrent; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2426 | } |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2427 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2428 | else if (key.compare("qserial") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2429 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2430 | queue_serial = StringConvert::ToUInt64 (value.c_str(), 0, 0); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2431 | if (queue_serial != 0) |
| 2432 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2433 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2434 | else if (key.compare("reason") == 0) |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2435 | { |
| 2436 | reason.swap(value); |
| 2437 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2438 | else if (key.compare("description") == 0) |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2439 | { |
| 2440 | StringExtractor desc_extractor; |
| 2441 | // Swap "value" over into "name_extractor" |
| 2442 | desc_extractor.GetStringRef().swap(value); |
| 2443 | // Now convert the HEX bytes into a string value |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 2444 | desc_extractor.GetHexByteString (value); |
| 2445 | description.swap(value); |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2446 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2447 | else if (key.compare("memory") == 0) |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2448 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2449 | // Expedited memory. GDB servers can choose to send back expedited memory |
| 2450 | // that can populate the L1 memory cache in the process so that things like |
| 2451 | // the frame pointer backchain can be expedited. This will help stack |
| 2452 | // backtracing be more efficient by not having to send as many memory read |
| 2453 | // requests down the remote GDB server. |
Chaoren Lin | 7a30608 | 2015-06-23 03:17:01 +0000 | [diff] [blame] | 2454 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2455 | // Key/value pair format: memory:<addr>=<bytes>; |
| 2456 | // <addr> is a number whose base will be interpreted by the prefix: |
| 2457 | // "0x[0-9a-fA-F]+" for hex |
| 2458 | // "0[0-7]+" for octal |
| 2459 | // "[1-9]+" for decimal |
| 2460 | // <bytes> is native endian ASCII hex bytes just like the register values |
| 2461 | llvm::StringRef value_ref(value); |
| 2462 | std::pair<llvm::StringRef, llvm::StringRef> pair; |
| 2463 | pair = value_ref.split('='); |
| 2464 | if (!pair.first.empty() && !pair.second.empty()) |
| 2465 | { |
| 2466 | std::string addr_str(pair.first.str()); |
| 2467 | const lldb::addr_t mem_cache_addr = StringConvert::ToUInt64(addr_str.c_str(), LLDB_INVALID_ADDRESS, 0); |
| 2468 | if (mem_cache_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2469 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2470 | StringExtractor bytes; |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2471 | bytes.GetStringRef() = pair.second.str(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2472 | const size_t byte_size = bytes.GetStringRef().size()/2; |
| 2473 | DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 2474 | const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); |
| 2475 | if (bytes_copied == byte_size) |
| 2476 | m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2480 | else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) |
| 2481 | { |
| 2482 | uint32_t reg = StringConvert::ToUInt32 (key.c_str(), UINT32_MAX, 16); |
| 2483 | if (reg != UINT32_MAX) |
| 2484 | expedited_register_map[reg] = std::move(value); |
| 2485 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2486 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2487 | |
Bhushan D. Attarde | 1e271df | 2015-07-24 04:06:20 +0000 | [diff] [blame] | 2488 | if (tid == LLDB_INVALID_THREAD_ID) |
| 2489 | { |
| 2490 | // A thread id may be invalid if the response is old style 'S' packet which does not provide the |
| 2491 | // thread information. So update the thread list and choose the first one. |
| 2492 | UpdateThreadIDList (); |
| 2493 | |
| 2494 | if (!m_thread_ids.empty ()) |
| 2495 | { |
| 2496 | tid = m_thread_ids.front (); |
| 2497 | } |
| 2498 | } |
| 2499 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2500 | ThreadSP thread_sp = SetThreadStopInfo (tid, |
| 2501 | expedited_register_map, |
| 2502 | signo, |
| 2503 | thread_name, |
| 2504 | reason, |
| 2505 | description, |
| 2506 | exc_type, |
| 2507 | exc_data, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2508 | thread_dispatch_qaddr, |
| 2509 | queue_vars_valid, |
| 2510 | queue_name, |
| 2511 | queue_kind, |
| 2512 | queue_serial); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2513 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2514 | return eStateStopped; |
| 2515 | } |
| 2516 | break; |
| 2517 | |
| 2518 | case 'W': |
Todd Fiala | ff6131a | 2014-05-19 04:57:23 +0000 | [diff] [blame] | 2519 | case 'X': |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2520 | // process exited |
| 2521 | return eStateExited; |
| 2522 | |
| 2523 | default: |
| 2524 | break; |
| 2525 | } |
| 2526 | return eStateInvalid; |
| 2527 | } |
| 2528 | |
| 2529 | void |
| 2530 | ProcessGDBRemote::RefreshStateAfterStop () |
| 2531 | { |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 2532 | Mutex::Locker locker(m_thread_list_real.GetMutex()); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2533 | m_thread_ids.clear(); |
| 2534 | // Set the thread stop info. It might have a "threads" key whose value is |
| 2535 | // a list of all thread IDs in the current process, so m_thread_ids might |
| 2536 | // get set. |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2537 | |
| 2538 | // Scope for the lock |
| 2539 | { |
| 2540 | // Lock the thread stack while we access it |
| 2541 | Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); |
| 2542 | // Get the number of stop packets on the stack |
| 2543 | int nItems = m_stop_packet_stack.size(); |
| 2544 | // Iterate over them |
| 2545 | for (int i = 0; i < nItems; i++) |
| 2546 | { |
| 2547 | // Get the thread stop info |
| 2548 | StringExtractorGDBRemote stop_info = m_stop_packet_stack[i]; |
| 2549 | // Process thread stop info |
| 2550 | SetThreadStopInfo(stop_info); |
| 2551 | } |
| 2552 | // Clear the thread stop stack |
| 2553 | m_stop_packet_stack.clear(); |
| 2554 | } |
| 2555 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2556 | // Check to see if SetThreadStopInfo() filled in m_thread_ids? |
| 2557 | if (m_thread_ids.empty()) |
| 2558 | { |
| 2559 | // No, we need to fetch the thread list manually |
| 2560 | UpdateThreadIDList(); |
| 2561 | } |
| 2562 | |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 2563 | // If we have queried for a default thread id |
| 2564 | if (m_initial_tid != LLDB_INVALID_THREAD_ID) |
| 2565 | { |
| 2566 | m_thread_list.SetSelectedThreadByID(m_initial_tid); |
| 2567 | m_initial_tid = LLDB_INVALID_THREAD_ID; |
| 2568 | } |
| 2569 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2570 | // Let all threads recover from stopping and do any clean up based |
| 2571 | // on the previous thread state (if any). |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 2572 | m_thread_list_real.RefreshStateAfterStop(); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2573 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | Error |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2577 | ProcessGDBRemote::DoHalt (bool &caused_stop) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2578 | { |
| 2579 | Error error; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2580 | |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 2581 | bool timed_out = false; |
| 2582 | Mutex::Locker locker; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2583 | |
| 2584 | if (m_public_state.GetValue() == eStateAttaching) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2585 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2586 | // We are being asked to halt during an attach. We need to just close |
| 2587 | // our file handle and debugserver will go away, and we can be done... |
| 2588 | m_gdb_comm.Disconnect(); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2589 | } |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2590 | else |
| 2591 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 2592 | if (!m_gdb_comm.SendInterrupt (locker, 2, timed_out)) |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2593 | { |
| 2594 | if (timed_out) |
| 2595 | error.SetErrorString("timed out sending interrupt packet"); |
| 2596 | else |
| 2597 | error.SetErrorString("unknown error sending interrupt packet"); |
| 2598 | } |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 2599 | |
| 2600 | caused_stop = m_gdb_comm.GetInterruptWasSent (); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2601 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2602 | return error; |
| 2603 | } |
| 2604 | |
| 2605 | Error |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2606 | ProcessGDBRemote::DoDetach(bool keep_stopped) |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2607 | { |
| 2608 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2609 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2610 | if (log) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2611 | log->Printf ("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped); |
| 2612 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2613 | error = m_gdb_comm.Detach (keep_stopped); |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2614 | if (log) |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2615 | { |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2616 | if (error.Success()) |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2617 | log->PutCString ("ProcessGDBRemote::DoDetach() detach packet sent successfully"); |
| 2618 | else |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2619 | log->Printf ("ProcessGDBRemote::DoDetach() detach packet send failed: %s", error.AsCString() ? error.AsCString() : "<unknown error>"); |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2620 | } |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2621 | |
| 2622 | if (!error.Success()) |
| 2623 | return error; |
| 2624 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2625 | // Sleep for one second to let the process get all detached... |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2626 | StopAsyncThread (); |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2627 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2628 | SetPrivateState (eStateDetached); |
| 2629 | ResumePrivateStateThread(); |
| 2630 | |
| 2631 | //KillDebugserverProcess (); |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2632 | return error; |
| 2633 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2634 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2635 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2636 | Error |
| 2637 | ProcessGDBRemote::DoDestroy () |
| 2638 | { |
| 2639 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2640 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2641 | if (log) |
| 2642 | log->Printf ("ProcessGDBRemote::DoDestroy()"); |
| 2643 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2644 | // There is a bug in older iOS debugservers where they don't shut down the process |
| 2645 | // they are debugging properly. If the process is sitting at a breakpoint or an exception, |
| 2646 | // this can cause problems with restarting. So we check to see if any of our threads are stopped |
| 2647 | // at a breakpoint, and if so we remove all the breakpoints, resume the process, and THEN |
| 2648 | // destroy it again. |
| 2649 | // |
| 2650 | // Note, we don't have a good way to test the version of debugserver, but I happen to know that |
| 2651 | // the set of all the iOS debugservers which don't support GetThreadSuffixSupported() and that of |
| 2652 | // the debugservers with this bug are equal. There really should be a better way to test this! |
| 2653 | // |
| 2654 | // We also use m_destroy_tried_resuming to make sure we only do this once, if we resume and then halt and |
| 2655 | // get called here to destroy again and we're still at a breakpoint or exception, then we should |
| 2656 | // just do the straight-forward kill. |
| 2657 | // |
| 2658 | // And of course, if we weren't able to stop the process by the time we get here, it isn't |
| 2659 | // necessary (or helpful) to do any of this. |
| 2660 | |
| 2661 | if (!m_gdb_comm.GetThreadSuffixSupported() && m_public_state.GetValue() != eStateRunning) |
| 2662 | { |
| 2663 | PlatformSP platform_sp = GetTarget().GetPlatform(); |
| 2664 | |
| 2665 | // FIXME: These should be ConstStrings so we aren't doing strcmp'ing. |
| 2666 | if (platform_sp |
| 2667 | && platform_sp->GetName() |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 2668 | && platform_sp->GetName() == PlatformRemoteiOS::GetPluginNameStatic()) |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2669 | { |
| 2670 | if (m_destroy_tried_resuming) |
| 2671 | { |
| 2672 | if (log) |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2673 | log->PutCString ("ProcessGDBRemote::DoDestroy() - Tried resuming to destroy once already, not doing it again."); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2674 | } |
| 2675 | else |
| 2676 | { |
| 2677 | // At present, the plans are discarded and the breakpoints disabled Process::Destroy, |
| 2678 | // but we really need it to happen here and it doesn't matter if we do it twice. |
| 2679 | m_thread_list.DiscardThreadPlans(); |
| 2680 | DisableAllBreakpointSites(); |
| 2681 | |
| 2682 | bool stop_looks_like_crash = false; |
| 2683 | ThreadList &threads = GetThreadList(); |
| 2684 | |
| 2685 | { |
Jim Ingham | 4535037 | 2012-09-11 00:08:52 +0000 | [diff] [blame] | 2686 | Mutex::Locker locker(threads.GetMutex()); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2687 | |
| 2688 | size_t num_threads = threads.GetSize(); |
| 2689 | for (size_t i = 0; i < num_threads; i++) |
| 2690 | { |
| 2691 | ThreadSP thread_sp = threads.GetThreadAtIndex(i); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2692 | StopInfoSP stop_info_sp = thread_sp->GetPrivateStopInfo(); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2693 | StopReason reason = eStopReasonInvalid; |
| 2694 | if (stop_info_sp) |
| 2695 | reason = stop_info_sp->GetStopReason(); |
| 2696 | if (reason == eStopReasonBreakpoint |
| 2697 | || reason == eStopReasonException) |
| 2698 | { |
| 2699 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2700 | log->Printf ("ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64 " stopped with reason: %s.", |
| 2701 | thread_sp->GetProtocolID(), |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2702 | stop_info_sp->GetDescription()); |
| 2703 | stop_looks_like_crash = true; |
| 2704 | break; |
| 2705 | } |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | if (stop_looks_like_crash) |
| 2710 | { |
| 2711 | if (log) |
| 2712 | log->PutCString ("ProcessGDBRemote::DoDestroy() - Stopped at a breakpoint, continue and then kill."); |
| 2713 | m_destroy_tried_resuming = true; |
| 2714 | |
| 2715 | // If we are going to run again before killing, it would be good to suspend all the threads |
| 2716 | // before resuming so they won't get into more trouble. Sadly, for the threads stopped with |
| 2717 | // the breakpoint or exception, the exception doesn't get cleared if it is suspended, so we do |
| 2718 | // have to run the risk of letting those threads proceed a bit. |
| 2719 | |
| 2720 | { |
Jim Ingham | 4535037 | 2012-09-11 00:08:52 +0000 | [diff] [blame] | 2721 | Mutex::Locker locker(threads.GetMutex()); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2722 | |
| 2723 | size_t num_threads = threads.GetSize(); |
| 2724 | for (size_t i = 0; i < num_threads; i++) |
| 2725 | { |
| 2726 | ThreadSP thread_sp = threads.GetThreadAtIndex(i); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2727 | StopInfoSP stop_info_sp = thread_sp->GetPrivateStopInfo(); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2728 | StopReason reason = eStopReasonInvalid; |
| 2729 | if (stop_info_sp) |
| 2730 | reason = stop_info_sp->GetStopReason(); |
| 2731 | if (reason != eStopReasonBreakpoint |
| 2732 | && reason != eStopReasonException) |
| 2733 | { |
| 2734 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2735 | log->Printf ("ProcessGDBRemote::DoDestroy() - Suspending thread: 0x%4.4" PRIx64 " before running.", |
| 2736 | thread_sp->GetProtocolID()); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2737 | thread_sp->SetResumeState(eStateSuspended); |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | Resume (); |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 2742 | return Destroy(false); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2743 | } |
| 2744 | } |
| 2745 | } |
| 2746 | } |
| 2747 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2748 | // Interrupt if our inferior is running... |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2749 | int exit_status = SIGABRT; |
| 2750 | std::string exit_string; |
| 2751 | |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 2752 | if (m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2753 | { |
Jim Ingham | aab7837 | 2011-10-28 01:11:35 +0000 | [diff] [blame] | 2754 | if (m_public_state.GetValue() != eStateAttaching) |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2755 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2756 | StringExtractorGDBRemote response; |
| 2757 | bool send_async = true; |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 2758 | GDBRemoteCommunication::ScopedTimeout (m_gdb_comm, 3); |
Filipe Cabecinhas | 9e10605 | 2012-08-22 13:25:58 +0000 | [diff] [blame] | 2759 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2760 | if (m_gdb_comm.SendPacketAndWaitForResponse("k", 1, response, send_async) == GDBRemoteCommunication::PacketResult::Success) |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2761 | { |
| 2762 | char packet_cmd = response.GetChar(0); |
| 2763 | |
| 2764 | if (packet_cmd == 'W' || packet_cmd == 'X') |
| 2765 | { |
Jim Ingham | eac0aa4 | 2014-02-21 22:36:11 +0000 | [diff] [blame] | 2766 | #if defined(__APPLE__) |
Jim Ingham | 9d67cc5 | 2014-02-21 22:35:29 +0000 | [diff] [blame] | 2767 | // For Native processes on Mac OS X, we launch through the Host Platform, then hand the process off |
| 2768 | // to debugserver, which becomes the parent process through "PT_ATTACH". Then when we go to kill |
| 2769 | // the process on Mac OS X we call ptrace(PT_KILL) to kill it, then we call waitpid which returns |
| 2770 | // with no error and the correct status. But amusingly enough that doesn't seem to actually reap |
| 2771 | // the process, but instead it is left around as a Zombie. Probably the kernel is in the process of |
| 2772 | // switching ownership back to lldb which was the original parent, and gets confused in the handoff. |
| 2773 | // Anyway, so call waitpid here to finally reap it. |
| 2774 | PlatformSP platform_sp(GetTarget().GetPlatform()); |
| 2775 | if (platform_sp && platform_sp->IsHost()) |
| 2776 | { |
| 2777 | int status; |
| 2778 | ::pid_t reap_pid; |
| 2779 | reap_pid = waitpid (GetID(), &status, WNOHANG); |
| 2780 | if (log) |
| 2781 | log->Printf ("Reaped pid: %d, status: %d.\n", reap_pid, status); |
| 2782 | } |
| 2783 | #endif |
Greg Clayton | 09c3e3d | 2011-12-06 04:51:14 +0000 | [diff] [blame] | 2784 | SetLastStopPacket (response); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2785 | ClearThreadIDList (); |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2786 | exit_status = response.GetHexU8(); |
| 2787 | } |
| 2788 | else |
| 2789 | { |
| 2790 | if (log) |
| 2791 | log->Printf ("ProcessGDBRemote::DoDestroy - got unexpected response to k packet: %s", response.GetStringRef().c_str()); |
| 2792 | exit_string.assign("got unexpected response to k packet: "); |
| 2793 | exit_string.append(response.GetStringRef()); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | else |
| 2797 | { |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2798 | if (log) |
| 2799 | log->Printf ("ProcessGDBRemote::DoDestroy - failed to send k packet"); |
| 2800 | exit_string.assign("failed to send the k packet"); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2801 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2802 | } |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2803 | else |
| 2804 | { |
| 2805 | if (log) |
Ed Maste | b3a5333 | 2014-03-17 17:05:22 +0000 | [diff] [blame] | 2806 | log->Printf ("ProcessGDBRemote::DoDestroy - killed or interrupted while attaching"); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 2807 | exit_string.assign ("killed or interrupted while attaching."); |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2808 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2809 | } |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2810 | else |
| 2811 | { |
| 2812 | // If we missed setting the exit status on the way out, do it here. |
| 2813 | // NB set exit status can be called multiple times, the first one sets the status. |
| 2814 | exit_string.assign("destroying when not connected to debugserver"); |
| 2815 | } |
| 2816 | |
| 2817 | SetExitStatus(exit_status, exit_string.c_str()); |
| 2818 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2819 | StopAsyncThread (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2820 | KillDebugserverProcess (); |
| 2821 | return error; |
| 2822 | } |
| 2823 | |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2824 | void |
| 2825 | ProcessGDBRemote::SetLastStopPacket (const StringExtractorGDBRemote &response) |
| 2826 | { |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2827 | const bool did_exec = response.GetStringRef().find(";reason:exec;") != std::string::npos; |
| 2828 | if (did_exec) |
| 2829 | { |
| 2830 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
| 2831 | if (log) |
| 2832 | log->Printf ("ProcessGDBRemote::SetLastStopPacket () - detected exec"); |
| 2833 | |
| 2834 | m_thread_list_real.Clear(); |
| 2835 | m_thread_list.Clear(); |
| 2836 | BuildDynamicRegisterInfo (true); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2837 | m_gdb_comm.ResetDiscoverableSettings (did_exec); |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2838 | } |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2839 | |
| 2840 | // Scope the lock |
| 2841 | { |
| 2842 | // Lock the thread stack while we access it |
| 2843 | Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2844 | |
| 2845 | // We are are not using non-stop mode, there can only be one last stop |
| 2846 | // reply packet, so clear the list. |
| 2847 | if (GetTarget().GetNonStopModeEnabled() == false) |
| 2848 | m_stop_packet_stack.clear(); |
| 2849 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2850 | // Add this stop packet to the stop packet stack |
| 2851 | // This stack will get popped and examined when we switch to the |
| 2852 | // Stopped state |
| 2853 | m_stop_packet_stack.push_back(response); |
| 2854 | } |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2857 | //------------------------------------------------------------------ |
| 2858 | // Process Queries |
| 2859 | //------------------------------------------------------------------ |
| 2860 | |
| 2861 | bool |
| 2862 | ProcessGDBRemote::IsAlive () |
| 2863 | { |
Greg Clayton | 10177aa | 2010-12-08 05:08:21 +0000 | [diff] [blame] | 2864 | return m_gdb_comm.IsConnected() && m_private_state.GetValue() != eStateExited; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | addr_t |
| 2868 | ProcessGDBRemote::GetImageInfoAddress() |
| 2869 | { |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 2870 | // request the link map address via the $qShlibInfoAddr packet |
| 2871 | lldb::addr_t addr = m_gdb_comm.GetShlibInfoAddr(); |
| 2872 | |
| 2873 | // the loaded module list can also provides a link map address |
| 2874 | if (addr == LLDB_INVALID_ADDRESS) |
| 2875 | { |
| 2876 | GDBLoadedModuleInfoList list; |
| 2877 | if (GetLoadedModuleList (list).Success()) |
| 2878 | addr = list.m_link_map; |
| 2879 | } |
| 2880 | |
| 2881 | return addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2884 | void |
| 2885 | ProcessGDBRemote::WillPublicStop () |
| 2886 | { |
| 2887 | // See if the GDB remote client supports the JSON threads info. |
| 2888 | // If so, we gather stop info for all threads, expedited registers, |
| 2889 | // expedited memory, runtime queue information (iOS and MacOSX only), |
| 2890 | // and more. Expediting memory will help stack backtracing be much |
| 2891 | // faster. Expediting registers will make sure we don't have to read |
| 2892 | // the thread registers for GPRs. |
| 2893 | m_jthreadsinfo_sp = m_gdb_comm.GetThreadsInfo(); |
| 2894 | |
| 2895 | if (m_jthreadsinfo_sp) |
| 2896 | { |
| 2897 | // Now set the stop info for each thread and also expedite any registers |
| 2898 | // and memory that was in the jThreadsInfo response. |
| 2899 | StructuredData::Array *thread_infos = m_jthreadsinfo_sp->GetAsArray(); |
| 2900 | if (thread_infos) |
| 2901 | { |
| 2902 | const size_t n = thread_infos->GetSize(); |
| 2903 | for (size_t i=0; i<n; ++i) |
| 2904 | { |
| 2905 | StructuredData::Dictionary *thread_dict = thread_infos->GetItemAtIndex(i)->GetAsDictionary(); |
| 2906 | if (thread_dict) |
| 2907 | SetThreadStopInfo(thread_dict); |
| 2908 | } |
| 2909 | } |
| 2910 | } |
| 2911 | } |
| 2912 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2913 | //------------------------------------------------------------------ |
| 2914 | // Process Memory |
| 2915 | //------------------------------------------------------------------ |
| 2916 | size_t |
| 2917 | ProcessGDBRemote::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 2918 | { |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 2919 | GetMaxMemorySize (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2920 | if (size > m_max_memory_size) |
| 2921 | { |
| 2922 | // Keep memory read sizes down to a sane limit. This function will be |
| 2923 | // called multiple times in order to complete the task by |
| 2924 | // lldb_private::Process so it is ok to do this. |
| 2925 | size = m_max_memory_size; |
| 2926 | } |
| 2927 | |
| 2928 | char packet[64]; |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 2929 | int packet_len; |
| 2930 | bool binary_memory_read = m_gdb_comm.GetxPacketSupported(); |
| 2931 | if (binary_memory_read) |
| 2932 | { |
| 2933 | packet_len = ::snprintf (packet, sizeof(packet), "x0x%" PRIx64 ",0x%" PRIx64, (uint64_t)addr, (uint64_t)size); |
| 2934 | } |
| 2935 | else |
| 2936 | { |
| 2937 | packet_len = ::snprintf (packet, sizeof(packet), "m%" PRIx64 ",%" PRIx64, (uint64_t)addr, (uint64_t)size); |
| 2938 | } |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2939 | assert (packet_len + 1 < (int)sizeof(packet)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2940 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2941 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, true) == GDBRemoteCommunication::PacketResult::Success) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2942 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2943 | if (response.IsNormalResponse()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2944 | { |
| 2945 | error.Clear(); |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 2946 | if (binary_memory_read) |
| 2947 | { |
| 2948 | // The lower level GDBRemoteCommunication packet receive layer has already de-quoted any |
| 2949 | // 0x7d character escaping that was present in the packet |
| 2950 | |
| 2951 | size_t data_received_size = response.GetBytesLeft(); |
| 2952 | if (data_received_size > size) |
| 2953 | { |
| 2954 | // Don't write past the end of BUF if the remote debug server gave us too |
| 2955 | // much data for some reason. |
| 2956 | data_received_size = size; |
| 2957 | } |
| 2958 | memcpy (buf, response.GetStringRef().data(), data_received_size); |
| 2959 | return data_received_size; |
| 2960 | } |
| 2961 | else |
| 2962 | { |
| 2963 | return response.GetHexBytes(buf, size, '\xdd'); |
| 2964 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2965 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2966 | else if (response.IsErrorResponse()) |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 2967 | error.SetErrorStringWithFormat("memory read failed for 0x%" PRIx64, addr); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2968 | else if (response.IsUnsupportedResponse()) |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 2969 | error.SetErrorStringWithFormat("GDB server does not support reading memory"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2970 | else |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 2971 | error.SetErrorStringWithFormat("unexpected response to GDB server memory read packet '%s': '%s'", packet, response.GetStringRef().c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2972 | } |
| 2973 | else |
| 2974 | { |
Jim Ingham | 35579dd | 2013-06-03 19:34:01 +0000 | [diff] [blame] | 2975 | error.SetErrorStringWithFormat("failed to send packet: '%s'", packet); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2976 | } |
| 2977 | return 0; |
| 2978 | } |
| 2979 | |
| 2980 | size_t |
| 2981 | ProcessGDBRemote::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 2982 | { |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 2983 | GetMaxMemorySize (); |
Greg Clayton | b4aaf2e | 2011-05-16 02:35:02 +0000 | [diff] [blame] | 2984 | if (size > m_max_memory_size) |
| 2985 | { |
| 2986 | // Keep memory read sizes down to a sane limit. This function will be |
| 2987 | // called multiple times in order to complete the task by |
| 2988 | // lldb_private::Process so it is ok to do this. |
| 2989 | size = m_max_memory_size; |
| 2990 | } |
| 2991 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2992 | StreamString packet; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2993 | packet.Printf("M%" PRIx64 ",%" PRIx64 ":", addr, (uint64_t)size); |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 2994 | packet.PutBytesAsRawHex8(buf, size, lldb::endian::InlHostByteOrder(), lldb::endian::InlHostByteOrder()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2995 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2996 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, true) == GDBRemoteCommunication::PacketResult::Success) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2997 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2998 | if (response.IsOKResponse()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2999 | { |
| 3000 | error.Clear(); |
| 3001 | return size; |
| 3002 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3003 | else if (response.IsErrorResponse()) |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 3004 | error.SetErrorStringWithFormat("memory write failed for 0x%" PRIx64, addr); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3005 | else if (response.IsUnsupportedResponse()) |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3006 | error.SetErrorStringWithFormat("GDB server does not support writing memory"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3007 | else |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3008 | error.SetErrorStringWithFormat("unexpected response to GDB server memory write packet '%s': '%s'", packet.GetString().c_str(), response.GetStringRef().c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3009 | } |
| 3010 | else |
| 3011 | { |
Jim Ingham | 35579dd | 2013-06-03 19:34:01 +0000 | [diff] [blame] | 3012 | error.SetErrorStringWithFormat("failed to send packet: '%s'", packet.GetString().c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3013 | } |
| 3014 | return 0; |
| 3015 | } |
| 3016 | |
| 3017 | lldb::addr_t |
| 3018 | ProcessGDBRemote::DoAllocateMemory (size_t size, uint32_t permissions, Error &error) |
| 3019 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3020 | Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS|LIBLLDB_LOG_EXPRESSIONS)); |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3021 | addr_t allocated_addr = LLDB_INVALID_ADDRESS; |
| 3022 | |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3023 | LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory(); |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3024 | switch (supported) |
| 3025 | { |
| 3026 | case eLazyBoolCalculate: |
| 3027 | case eLazyBoolYes: |
| 3028 | allocated_addr = m_gdb_comm.AllocateMemory (size, permissions); |
| 3029 | if (allocated_addr != LLDB_INVALID_ADDRESS || supported == eLazyBoolYes) |
| 3030 | return allocated_addr; |
| 3031 | |
| 3032 | case eLazyBoolNo: |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3033 | // Call mmap() to create memory in the inferior.. |
| 3034 | unsigned prot = 0; |
| 3035 | if (permissions & lldb::ePermissionsReadable) |
| 3036 | prot |= eMmapProtRead; |
| 3037 | if (permissions & lldb::ePermissionsWritable) |
| 3038 | prot |= eMmapProtWrite; |
| 3039 | if (permissions & lldb::ePermissionsExecutable) |
| 3040 | prot |= eMmapProtExec; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3041 | |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3042 | if (InferiorCallMmap(this, allocated_addr, 0, size, prot, |
| 3043 | eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) |
| 3044 | m_addr_to_mmap_size[allocated_addr] = size; |
| 3045 | else |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3046 | { |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3047 | allocated_addr = LLDB_INVALID_ADDRESS; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3048 | if (log) |
| 3049 | log->Printf ("ProcessGDBRemote::%s no direct stub support for memory allocation, and InferiorCallMmap also failed - is stub missing register context save/restore capability?", __FUNCTION__); |
| 3050 | } |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | } |
| 3053 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3054 | if (allocated_addr == LLDB_INVALID_ADDRESS) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3055 | error.SetErrorStringWithFormat("unable to allocate %" PRIu64 " bytes of memory with permissions %s", (uint64_t)size, GetPermissionsAsCString (permissions)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3056 | else |
| 3057 | error.Clear(); |
| 3058 | return allocated_addr; |
| 3059 | } |
| 3060 | |
| 3061 | Error |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 3062 | ProcessGDBRemote::GetMemoryRegionInfo (addr_t load_addr, |
| 3063 | MemoryRegionInfo ®ion_info) |
| 3064 | { |
| 3065 | |
| 3066 | Error error (m_gdb_comm.GetMemoryRegionInfo (load_addr, region_info)); |
| 3067 | return error; |
| 3068 | } |
| 3069 | |
| 3070 | Error |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 3071 | ProcessGDBRemote::GetWatchpointSupportInfo (uint32_t &num) |
| 3072 | { |
| 3073 | |
| 3074 | Error error (m_gdb_comm.GetWatchpointSupportInfo (num)); |
| 3075 | return error; |
| 3076 | } |
| 3077 | |
| 3078 | Error |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 3079 | ProcessGDBRemote::GetWatchpointSupportInfo (uint32_t &num, bool& after) |
| 3080 | { |
| 3081 | Error error (m_gdb_comm.GetWatchpointSupportInfo (num, after)); |
| 3082 | return error; |
| 3083 | } |
| 3084 | |
| 3085 | Error |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3086 | ProcessGDBRemote::DoDeallocateMemory (lldb::addr_t addr) |
| 3087 | { |
| 3088 | Error error; |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3089 | LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory(); |
| 3090 | |
| 3091 | switch (supported) |
| 3092 | { |
| 3093 | case eLazyBoolCalculate: |
| 3094 | // We should never be deallocating memory without allocating memory |
| 3095 | // first so we should never get eLazyBoolCalculate |
| 3096 | error.SetErrorString ("tried to deallocate memory without ever allocating memory"); |
| 3097 | break; |
| 3098 | |
| 3099 | case eLazyBoolYes: |
| 3100 | if (!m_gdb_comm.DeallocateMemory (addr)) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3101 | error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3102 | break; |
| 3103 | |
| 3104 | case eLazyBoolNo: |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3105 | // Call munmap() to deallocate memory in the inferior.. |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3106 | { |
| 3107 | MMapMap::iterator pos = m_addr_to_mmap_size.find(addr); |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3108 | if (pos != m_addr_to_mmap_size.end() && |
| 3109 | InferiorCallMunmap(this, addr, pos->second)) |
| 3110 | m_addr_to_mmap_size.erase (pos); |
| 3111 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3112 | error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3113 | } |
| 3114 | break; |
| 3115 | } |
| 3116 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3117 | return error; |
| 3118 | } |
| 3119 | |
| 3120 | |
| 3121 | //------------------------------------------------------------------ |
| 3122 | // Process STDIO |
| 3123 | //------------------------------------------------------------------ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3124 | size_t |
| 3125 | ProcessGDBRemote::PutSTDIN (const char *src, size_t src_len, Error &error) |
| 3126 | { |
| 3127 | if (m_stdio_communication.IsConnected()) |
| 3128 | { |
| 3129 | ConnectionStatus status; |
| 3130 | m_stdio_communication.Write(src, src_len, status, NULL); |
| 3131 | } |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 3132 | else if (m_stdin_forward) |
Vince Harron | e0be425 | 2015-02-06 18:32:57 +0000 | [diff] [blame] | 3133 | { |
| 3134 | m_gdb_comm.SendStdinNotification(src, src_len); |
| 3135 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3136 | return 0; |
| 3137 | } |
| 3138 | |
| 3139 | Error |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3140 | ProcessGDBRemote::EnableBreakpointSite (BreakpointSite *bp_site) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3141 | { |
| 3142 | Error error; |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3143 | assert(bp_site != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3144 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3145 | // Get logging info |
| 3146 | Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3147 | user_id_t site_id = bp_site->GetID(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3148 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3149 | // Get the breakpoint address |
| 3150 | const addr_t addr = bp_site->GetLoadAddress(); |
| 3151 | |
| 3152 | // Log that a breakpoint was requested |
| 3153 | if (log) |
| 3154 | log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 ") address = 0x%" PRIx64, site_id, (uint64_t)addr); |
| 3155 | |
| 3156 | // Breakpoint already exists and is enabled |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3157 | if (bp_site->IsEnabled()) |
| 3158 | { |
| 3159 | if (log) |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3160 | log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)", site_id, (uint64_t)addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3161 | return error; |
| 3162 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3163 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3164 | // Get the software breakpoint trap opcode size |
| 3165 | const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site); |
| 3166 | |
| 3167 | // SupportsGDBStoppointPacket() simply checks a boolean, indicating if this breakpoint type |
| 3168 | // is supported by the remote stub. These are set to true by default, and later set to false |
| 3169 | // only after we receive an unimplemented response when sending a breakpoint packet. This means |
| 3170 | // initially that unless we were specifically instructed to use a hardware breakpoint, LLDB will |
| 3171 | // attempt to set a software breakpoint. HardwareRequired() also queries a boolean variable which |
| 3172 | // indicates if the user specifically asked for hardware breakpoints. If true then we will |
| 3173 | // skip over software breakpoints. |
| 3174 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware) && (!bp_site->HardwareRequired())) |
| 3175 | { |
| 3176 | // Try to send off a software breakpoint packet ($Z0) |
| 3177 | if (m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointSoftware, true, addr, bp_op_size) == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3178 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3179 | // The breakpoint was placed successfully |
| 3180 | bp_site->SetEnabled(true); |
| 3181 | bp_site->SetType(BreakpointSite::eExternal); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 3182 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3183 | } |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3184 | |
| 3185 | // SendGDBStoppointTypePacket() will return an error if it was unable to set this |
| 3186 | // breakpoint. We need to differentiate between a error specific to placing this breakpoint |
| 3187 | // or if we have learned that this breakpoint type is unsupported. To do this, we |
| 3188 | // must test the support boolean for this breakpoint type to see if it now indicates that |
| 3189 | // this breakpoint type is unsupported. If they are still supported then we should return |
| 3190 | // with the error code. If they are now unsupported, then we would like to fall through |
| 3191 | // and try another form of breakpoint. |
| 3192 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware)) |
| 3193 | return error; |
| 3194 | |
| 3195 | // We reach here when software breakpoints have been found to be unsupported. For future |
| 3196 | // calls to set a breakpoint, we will not attempt to set a breakpoint with a type that is |
| 3197 | // known not to be supported. |
| 3198 | if (log) |
| 3199 | log->Printf("Software breakpoints are unsupported"); |
| 3200 | |
| 3201 | // So we will fall through and try a hardware breakpoint |
| 3202 | } |
| 3203 | |
| 3204 | // The process of setting a hardware breakpoint is much the same as above. We check the |
| 3205 | // supported boolean for this breakpoint type, and if it is thought to be supported then we |
| 3206 | // will try to set this breakpoint with a hardware breakpoint. |
| 3207 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointHardware)) |
| 3208 | { |
| 3209 | // Try to send off a hardware breakpoint packet ($Z1) |
| 3210 | if (m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointHardware, true, addr, bp_op_size) == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3211 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3212 | // The breakpoint was placed successfully |
| 3213 | bp_site->SetEnabled(true); |
| 3214 | bp_site->SetType(BreakpointSite::eHardware); |
| 3215 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3216 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3217 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3218 | // Check if the error was something other then an unsupported breakpoint type |
| 3219 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointHardware)) |
| 3220 | { |
| 3221 | // Unable to set this hardware breakpoint |
| 3222 | error.SetErrorString("failed to set hardware breakpoint (hardware breakpoint resources might be exhausted or unavailable)"); |
| 3223 | return error; |
| 3224 | } |
| 3225 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3226 | // We will reach here when the stub gives an unsupported response to a hardware breakpoint |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3227 | if (log) |
| 3228 | log->Printf("Hardware breakpoints are unsupported"); |
| 3229 | |
| 3230 | // Finally we will falling through to a #trap style breakpoint |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3233 | // Don't fall through when hardware breakpoints were specifically requested |
| 3234 | if (bp_site->HardwareRequired()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3235 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3236 | error.SetErrorString("hardware breakpoints are not supported"); |
| 3237 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3238 | } |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3239 | |
| 3240 | // As a last resort we want to place a manual breakpoint. An instruction |
| 3241 | // is placed into the process memory using memory write packets. |
| 3242 | return EnableSoftwareBreakpoint(bp_site); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | Error |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3246 | ProcessGDBRemote::DisableBreakpointSite (BreakpointSite *bp_site) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3247 | { |
| 3248 | Error error; |
| 3249 | assert (bp_site != NULL); |
| 3250 | addr_t addr = bp_site->GetLoadAddress(); |
| 3251 | user_id_t site_id = bp_site->GetID(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3252 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3253 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3254 | log->Printf ("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 ") addr = 0x%8.8" PRIx64, site_id, (uint64_t)addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3255 | |
| 3256 | if (bp_site->IsEnabled()) |
| 3257 | { |
| 3258 | const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode (bp_site); |
| 3259 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3260 | BreakpointSite::Type bp_type = bp_site->GetType(); |
| 3261 | switch (bp_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3262 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3263 | case BreakpointSite::eSoftware: |
| 3264 | error = DisableSoftwareBreakpoint (bp_site); |
| 3265 | break; |
| 3266 | |
| 3267 | case BreakpointSite::eHardware: |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3268 | if (m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointHardware, false, addr, bp_op_size)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3269 | error.SetErrorToGenericError(); |
| 3270 | break; |
| 3271 | |
| 3272 | case BreakpointSite::eExternal: |
Jim Ingham | a04ef75 | 2014-03-07 11:18:02 +0000 | [diff] [blame] | 3273 | { |
| 3274 | GDBStoppointType stoppoint_type; |
| 3275 | if (bp_site->IsHardware()) |
| 3276 | stoppoint_type = eBreakpointHardware; |
| 3277 | else |
| 3278 | stoppoint_type = eBreakpointSoftware; |
| 3279 | |
| 3280 | if (m_gdb_comm.SendGDBStoppointTypePacket(stoppoint_type, false, addr, bp_op_size)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3281 | error.SetErrorToGenericError(); |
Jim Ingham | a04ef75 | 2014-03-07 11:18:02 +0000 | [diff] [blame] | 3282 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3283 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3284 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3285 | if (error.Success()) |
| 3286 | bp_site->SetEnabled(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3287 | } |
| 3288 | else |
| 3289 | { |
| 3290 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3291 | log->Printf ("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", site_id, (uint64_t)addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3292 | return error; |
| 3293 | } |
| 3294 | |
| 3295 | if (error.Success()) |
| 3296 | error.SetErrorToGenericError(); |
| 3297 | return error; |
| 3298 | } |
| 3299 | |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3300 | // Pre-requisite: wp != NULL. |
| 3301 | static GDBStoppointType |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3302 | GetGDBStoppointType (Watchpoint *wp) |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3303 | { |
| 3304 | assert(wp); |
| 3305 | bool watch_read = wp->WatchpointRead(); |
| 3306 | bool watch_write = wp->WatchpointWrite(); |
| 3307 | |
| 3308 | // watch_read and watch_write cannot both be false. |
| 3309 | assert(watch_read || watch_write); |
| 3310 | if (watch_read && watch_write) |
| 3311 | return eWatchpointReadWrite; |
Johnny Chen | 6d487a9 | 2011-09-09 20:35:15 +0000 | [diff] [blame] | 3312 | else if (watch_read) |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3313 | return eWatchpointRead; |
Johnny Chen | 6d487a9 | 2011-09-09 20:35:15 +0000 | [diff] [blame] | 3314 | else // Must be watch_write, then. |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3315 | return eWatchpointWrite; |
| 3316 | } |
| 3317 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3318 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3319 | ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3320 | { |
| 3321 | Error error; |
| 3322 | if (wp) |
| 3323 | { |
| 3324 | user_id_t watchID = wp->GetID(); |
| 3325 | addr_t addr = wp->GetLoadAddress(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3326 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3327 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3328 | log->Printf ("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")", watchID); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3329 | if (wp->IsEnabled()) |
| 3330 | { |
| 3331 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3332 | log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.", watchID, (uint64_t)addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3333 | return error; |
| 3334 | } |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3335 | |
| 3336 | GDBStoppointType type = GetGDBStoppointType(wp); |
| 3337 | // Pass down an appropriate z/Z packet... |
| 3338 | if (m_gdb_comm.SupportsGDBStoppointPacket (type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3339 | { |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3340 | if (m_gdb_comm.SendGDBStoppointTypePacket(type, true, addr, wp->GetByteSize()) == 0) |
| 3341 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3342 | wp->SetEnabled(true, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3343 | return error; |
| 3344 | } |
| 3345 | else |
| 3346 | error.SetErrorString("sending gdb watchpoint packet failed"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3347 | } |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3348 | else |
| 3349 | error.SetErrorString("watchpoints not supported"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3350 | } |
| 3351 | else |
| 3352 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3353 | error.SetErrorString("Watchpoint argument was NULL."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3354 | } |
| 3355 | if (error.Success()) |
| 3356 | error.SetErrorToGenericError(); |
| 3357 | return error; |
| 3358 | } |
| 3359 | |
| 3360 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3361 | ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3362 | { |
| 3363 | Error error; |
| 3364 | if (wp) |
| 3365 | { |
| 3366 | user_id_t watchID = wp->GetID(); |
| 3367 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3368 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3369 | |
| 3370 | addr_t addr = wp->GetLoadAddress(); |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3371 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3372 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3373 | log->Printf ("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 ") addr = 0x%8.8" PRIx64, watchID, (uint64_t)addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3374 | |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3375 | if (!wp->IsEnabled()) |
| 3376 | { |
| 3377 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3378 | log->Printf ("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", watchID, (uint64_t)addr); |
Johnny Chen | 892943f | 2012-08-23 22:28:26 +0000 | [diff] [blame] | 3379 | // See also 'class WatchpointSentry' within StopInfo.cpp. |
| 3380 | // This disabling attempt might come from the user-supplied actions, we'll route it in order for |
| 3381 | // the watchpoint object to intelligently process this action. |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3382 | wp->SetEnabled(false, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3383 | return error; |
| 3384 | } |
| 3385 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3386 | if (wp->IsHardware()) |
| 3387 | { |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3388 | GDBStoppointType type = GetGDBStoppointType(wp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3389 | // Pass down an appropriate z/Z packet... |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3390 | if (m_gdb_comm.SendGDBStoppointTypePacket(type, false, addr, wp->GetByteSize()) == 0) |
| 3391 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3392 | wp->SetEnabled(false, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3393 | return error; |
| 3394 | } |
| 3395 | else |
| 3396 | error.SetErrorString("sending gdb watchpoint packet failed"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3397 | } |
| 3398 | // TODO: clear software watchpoints if we implement them |
| 3399 | } |
| 3400 | else |
| 3401 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3402 | error.SetErrorString("Watchpoint argument was NULL."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3403 | } |
| 3404 | if (error.Success()) |
| 3405 | error.SetErrorToGenericError(); |
| 3406 | return error; |
| 3407 | } |
| 3408 | |
| 3409 | void |
| 3410 | ProcessGDBRemote::Clear() |
| 3411 | { |
| 3412 | m_flags = 0; |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 3413 | m_thread_list_real.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3414 | m_thread_list.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | Error |
| 3418 | ProcessGDBRemote::DoSignal (int signo) |
| 3419 | { |
| 3420 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3421 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3422 | if (log) |
| 3423 | log->Printf ("ProcessGDBRemote::DoSignal (signal = %d)", signo); |
| 3424 | |
| 3425 | if (!m_gdb_comm.SendAsyncSignal (signo)) |
| 3426 | error.SetErrorStringWithFormat("failed to send signal %i", signo); |
| 3427 | return error; |
| 3428 | } |
| 3429 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3430 | Error |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3431 | ProcessGDBRemote::LaunchAndConnectToDebugserver (const ProcessInfo &process_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3432 | { |
| 3433 | Error error; |
| 3434 | if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID) |
| 3435 | { |
| 3436 | // If we locate debugserver, keep that located version around |
| 3437 | static FileSpec g_debugserver_file_spec; |
| 3438 | |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 3439 | ProcessLaunchInfo debugserver_launch_info; |
Oleksiy Vyalov | f8ce61c | 2015-01-28 17:36:59 +0000 | [diff] [blame] | 3440 | // Make debugserver run in its own session so signals generated by |
| 3441 | // special terminal key sequences (^C) don't affect debugserver. |
| 3442 | debugserver_launch_info.SetLaunchInSeparateProcessGroup(true); |
| 3443 | |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3444 | debugserver_launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false); |
| 3445 | debugserver_launch_info.SetUserID(process_info.GetUserID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3446 | |
Todd Fiala | 013434e | 2014-07-09 01:29:05 +0000 | [diff] [blame] | 3447 | #if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__)) |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 3448 | // On iOS, still do a local connection using a random port |
Greg Clayton | 1681092 | 2014-02-27 19:38:18 +0000 | [diff] [blame] | 3449 | const char *hostname = "127.0.0.1"; |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 3450 | uint16_t port = get_random_port (); |
| 3451 | #else |
| 3452 | // Set hostname being NULL to do the reverse connect where debugserver |
| 3453 | // will bind to port zero and it will communicate back to us the port |
| 3454 | // that we will connect to |
| 3455 | const char *hostname = NULL; |
| 3456 | uint16_t port = 0; |
| 3457 | #endif |
| 3458 | |
| 3459 | error = m_gdb_comm.StartDebugserverProcess (hostname, |
| 3460 | port, |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3461 | debugserver_launch_info, |
| 3462 | port); |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3463 | |
| 3464 | if (error.Success ()) |
| 3465 | m_debugserver_pid = debugserver_launch_info.GetProcessID(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3466 | else |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3467 | m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3468 | |
| 3469 | if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) |
| 3470 | StartAsyncThread (); |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3471 | |
| 3472 | if (error.Fail()) |
| 3473 | { |
| 3474 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
| 3475 | |
| 3476 | if (log) |
| 3477 | log->Printf("failed to start debugserver process: %s", error.AsCString()); |
| 3478 | return error; |
| 3479 | } |
| 3480 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3481 | if (m_gdb_comm.IsConnected()) |
| 3482 | { |
| 3483 | // Finish the connection process by doing the handshake without connecting (send NULL URL) |
| 3484 | ConnectToDebugserver (NULL); |
| 3485 | } |
| 3486 | else |
| 3487 | { |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 3488 | StreamString connect_url; |
| 3489 | connect_url.Printf("connect://%s:%u", hostname, port); |
| 3490 | error = ConnectToDebugserver (connect_url.GetString().c_str()); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3491 | } |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3492 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3493 | } |
| 3494 | return error; |
| 3495 | } |
| 3496 | |
| 3497 | bool |
| 3498 | ProcessGDBRemote::MonitorDebugserverProcess |
| 3499 | ( |
| 3500 | void *callback_baton, |
| 3501 | lldb::pid_t debugserver_pid, |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3502 | bool exited, // True if the process did exit |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3503 | int signo, // Zero for no signal |
| 3504 | int exit_status // Exit value of process if signal is zero |
| 3505 | ) |
| 3506 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3507 | // The baton is a "ProcessGDBRemote *". Now this class might be gone |
| 3508 | // and might not exist anymore, so we need to carefully try to get the |
| 3509 | // target for this process first since we have a race condition when |
| 3510 | // we are done running between getting the notice that the inferior |
| 3511 | // process has died and the debugserver that was debugging this process. |
| 3512 | // In our test suite, we are also continually running process after |
| 3513 | // process, so we must be very careful to make sure: |
| 3514 | // 1 - process object hasn't been deleted already |
| 3515 | // 2 - that a new process object hasn't been recreated in its place |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3516 | |
| 3517 | // "debugserver_pid" argument passed in is the process ID for |
| 3518 | // debugserver that we are tracking... |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3519 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3520 | |
Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 3521 | ProcessGDBRemote *process = (ProcessGDBRemote *)callback_baton; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3522 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3523 | // Get a shared pointer to the target that has a matching process pointer. |
| 3524 | // This target could be gone, or the target could already have a new process |
| 3525 | // object inside of it |
| 3526 | TargetSP target_sp (Debugger::FindTargetWithProcess(process)); |
| 3527 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3528 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3529 | log->Printf ("ProcessGDBRemote::MonitorDebugserverProcess (baton=%p, pid=%" PRIu64 ", signo=%i (0x%x), exit_status=%i)", callback_baton, debugserver_pid, signo, signo, exit_status); |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3530 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3531 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3532 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3533 | // We found a process in a target that matches, but another thread |
| 3534 | // might be in the process of launching a new process that will |
| 3535 | // soon replace it, so get a shared pointer to the process so we |
| 3536 | // can keep it alive. |
| 3537 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 3538 | // Now we have a shared pointer to the process that can't go away on us |
| 3539 | // so we now make sure it was the same as the one passed in, and also make |
| 3540 | // sure that our previous "process *" didn't get deleted and have a new |
| 3541 | // "process *" created in its place with the same pointer. To verify this |
| 3542 | // we make sure the process has our debugserver process ID. If we pass all |
| 3543 | // of these tests, then we are sure that this process is the one we were |
| 3544 | // looking for. |
| 3545 | if (process_sp && process == process_sp.get() && process->m_debugserver_pid == debugserver_pid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3546 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3547 | // Sleep for a half a second to make sure our inferior process has |
| 3548 | // time to set its exit status before we set it incorrectly when |
| 3549 | // both the debugserver and the inferior process shut down. |
| 3550 | usleep (500000); |
| 3551 | // If our process hasn't yet exited, debugserver might have died. |
| 3552 | // If the process did exit, the we are reaping it. |
| 3553 | const StateType state = process->GetState(); |
| 3554 | |
| 3555 | if (process->m_debugserver_pid != LLDB_INVALID_PROCESS_ID && |
| 3556 | state != eStateInvalid && |
| 3557 | state != eStateUnloaded && |
| 3558 | state != eStateExited && |
| 3559 | state != eStateDetached) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3560 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3561 | char error_str[1024]; |
| 3562 | if (signo) |
| 3563 | { |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 3564 | const char *signal_cstr = process->GetUnixSignals()->GetSignalAsCString(signo); |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3565 | if (signal_cstr) |
| 3566 | ::snprintf (error_str, sizeof (error_str), DEBUGSERVER_BASENAME " died with signal %s", signal_cstr); |
| 3567 | else |
| 3568 | ::snprintf (error_str, sizeof (error_str), DEBUGSERVER_BASENAME " died with signal %i", signo); |
| 3569 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3570 | else |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3571 | { |
| 3572 | ::snprintf (error_str, sizeof (error_str), DEBUGSERVER_BASENAME " died with an exit status of 0x%8.8x", exit_status); |
| 3573 | } |
Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 3574 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3575 | process->SetExitStatus (-1, error_str); |
| 3576 | } |
| 3577 | // Debugserver has exited we need to let our ProcessGDBRemote |
| 3578 | // know that it no longer has a debugserver instance |
| 3579 | process->m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 3580 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3581 | } |
| 3582 | return true; |
| 3583 | } |
| 3584 | |
| 3585 | void |
| 3586 | ProcessGDBRemote::KillDebugserverProcess () |
| 3587 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3588 | m_gdb_comm.Disconnect(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3589 | if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) |
| 3590 | { |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3591 | Host::Kill (m_debugserver_pid, SIGINT); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3592 | m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | void |
| 3597 | ProcessGDBRemote::Initialize() |
| 3598 | { |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3599 | static std::once_flag g_once_flag; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3600 | |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3601 | std::call_once(g_once_flag, []() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3602 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3603 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 3604 | GetPluginDescriptionStatic(), |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3605 | CreateInstance, |
| 3606 | DebuggerInitialize); |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3607 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3610 | void |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3611 | ProcessGDBRemote::DebuggerInitialize (Debugger &debugger) |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3612 | { |
| 3613 | if (!PluginManager::GetSettingForProcessPlugin(debugger, PluginProperties::GetSettingName())) |
| 3614 | { |
| 3615 | const bool is_global_setting = true; |
| 3616 | PluginManager::CreateSettingForProcessPlugin (debugger, |
| 3617 | GetGlobalPluginProperties()->GetValueProperties(), |
| 3618 | ConstString ("Properties for the gdb-remote process plug-in."), |
| 3619 | is_global_setting); |
| 3620 | } |
| 3621 | } |
| 3622 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3623 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3624 | ProcessGDBRemote::StartAsyncThread () |
| 3625 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3626 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3627 | |
| 3628 | if (log) |
| 3629 | log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3630 | |
| 3631 | Mutex::Locker start_locker(m_async_thread_state_mutex); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3632 | if (!m_async_thread.IsJoinable()) |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3633 | { |
| 3634 | // Create a thread that watches our internal state and controls which |
| 3635 | // events make it to clients (into the DCProcess event queue). |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3636 | |
| 3637 | m_async_thread = ThreadLauncher::LaunchThread("<lldb.process.gdb-remote.async>", ProcessGDBRemote::AsyncThread, this, NULL); |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3638 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3639 | else if (log) |
| 3640 | log->Printf("ProcessGDBRemote::%s () - Called when Async thread was already running.", __FUNCTION__); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3641 | |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3642 | return m_async_thread.IsJoinable(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | void |
| 3646 | ProcessGDBRemote::StopAsyncThread () |
| 3647 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3648 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3649 | |
| 3650 | if (log) |
| 3651 | log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); |
| 3652 | |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3653 | Mutex::Locker start_locker(m_async_thread_state_mutex); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3654 | if (m_async_thread.IsJoinable()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3655 | { |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3656 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); |
| 3657 | |
| 3658 | // This will shut down the async thread. |
| 3659 | m_gdb_comm.Disconnect(); // Disconnect from the debug server. |
| 3660 | |
| 3661 | // Stop the stdio thread |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3662 | m_async_thread.Join(nullptr); |
Pavel Labath | a55a953 | 2015-03-11 09:53:42 +0000 | [diff] [blame] | 3663 | m_async_thread.Reset(); |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3664 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3665 | else if (log) |
| 3666 | log->Printf("ProcessGDBRemote::%s () - Called when Async thread was not running.", __FUNCTION__); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3669 | bool |
| 3670 | ProcessGDBRemote::HandleNotifyPacket (StringExtractorGDBRemote &packet) |
| 3671 | { |
| 3672 | // get the packet at a string |
| 3673 | const std::string &pkt = packet.GetStringRef(); |
| 3674 | // skip %stop: |
| 3675 | StringExtractorGDBRemote stop_info(pkt.c_str() + 5); |
| 3676 | |
| 3677 | // pass as a thread stop info packet |
| 3678 | SetLastStopPacket(stop_info); |
| 3679 | |
| 3680 | // check for more stop reasons |
| 3681 | HandleStopReplySequence(); |
| 3682 | |
| 3683 | // if the process is stopped then we need to fake a resume |
| 3684 | // so that we can stop properly with the new break. This |
| 3685 | // is possible due to SetPrivateState() broadcasting the |
| 3686 | // state change as a side effect. |
| 3687 | if (GetPrivateState() == lldb::StateType::eStateStopped) |
| 3688 | { |
| 3689 | SetPrivateState(lldb::StateType::eStateRunning); |
| 3690 | } |
| 3691 | |
| 3692 | // since we have some stopped packets we can halt the process |
| 3693 | SetPrivateState(lldb::StateType::eStateStopped); |
| 3694 | |
| 3695 | return true; |
| 3696 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3697 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3698 | thread_result_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3699 | ProcessGDBRemote::AsyncThread (void *arg) |
| 3700 | { |
| 3701 | ProcessGDBRemote *process = (ProcessGDBRemote*) arg; |
| 3702 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3703 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3704 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3705 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") thread starting...", __FUNCTION__, arg, process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3706 | |
| 3707 | Listener listener ("ProcessGDBRemote::AsyncThread"); |
| 3708 | EventSP event_sp; |
| 3709 | const uint32_t desired_event_mask = eBroadcastBitAsyncContinue | |
| 3710 | eBroadcastBitAsyncThreadShouldExit; |
| 3711 | |
| 3712 | if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask) |
| 3713 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3714 | listener.StartListeningForEvents (&process->m_gdb_comm, Communication::eBroadcastBitReadThreadDidExit | |
| 3715 | GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify); |
| 3716 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3717 | bool done = false; |
| 3718 | while (!done) |
| 3719 | { |
| 3720 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3721 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3722 | if (listener.WaitForEvent (NULL, event_sp)) |
| 3723 | { |
| 3724 | const uint32_t event_type = event_sp->GetType(); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3725 | if (event_sp->BroadcasterIs (&process->m_async_broadcaster)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3726 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3727 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3728 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3729 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3730 | switch (event_type) |
| 3731 | { |
| 3732 | case eBroadcastBitAsyncContinue: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3733 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3734 | const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3735 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3736 | if (continue_packet) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3737 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3738 | const char *continue_cstr = (const char *)continue_packet->GetBytes (); |
| 3739 | const size_t continue_cstr_len = continue_packet->GetByteSize (); |
| 3740 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3741 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3742 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3743 | if (::strstr (continue_cstr, "vAttach") == NULL) |
| 3744 | process->SetPrivateState(eStateRunning); |
| 3745 | StringExtractorGDBRemote response; |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3746 | |
| 3747 | // If in Non-Stop-Mode |
| 3748 | if (process->GetTarget().GetNonStopModeEnabled()) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3749 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3750 | // send the vCont packet |
| 3751 | if (!process->GetGDBRemote().SendvContPacket(process, continue_cstr, continue_cstr_len, response)) |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3752 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3753 | // Something went wrong |
| 3754 | done = true; |
| 3755 | break; |
| 3756 | } |
| 3757 | } |
| 3758 | // If in All-Stop-Mode |
| 3759 | else |
| 3760 | { |
| 3761 | StateType stop_state = process->GetGDBRemote().SendContinuePacketAndWaitForResponse (process, continue_cstr, continue_cstr_len, response); |
| 3762 | |
| 3763 | // We need to immediately clear the thread ID list so we are sure to get a valid list of threads. |
| 3764 | // The thread ID list might be contained within the "response", or the stop reply packet that |
| 3765 | // caused the stop. So clear it now before we give the stop reply packet to the process |
| 3766 | // using the process->SetLastStopPacket()... |
| 3767 | process->ClearThreadIDList (); |
| 3768 | |
| 3769 | switch (stop_state) |
| 3770 | { |
| 3771 | case eStateStopped: |
| 3772 | case eStateCrashed: |
| 3773 | case eStateSuspended: |
| 3774 | process->SetLastStopPacket (response); |
| 3775 | process->SetPrivateState (stop_state); |
| 3776 | break; |
| 3777 | |
| 3778 | case eStateExited: |
| 3779 | { |
| 3780 | process->SetLastStopPacket (response); |
| 3781 | process->ClearThreadIDList(); |
| 3782 | response.SetFilePos(1); |
| 3783 | |
| 3784 | int exit_status = response.GetHexU8(); |
| 3785 | const char *desc_cstr = NULL; |
| 3786 | StringExtractor extractor; |
| 3787 | std::string desc_string; |
| 3788 | if (response.GetBytesLeft() > 0 && response.GetChar('-') == ';') |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3789 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3790 | std::string desc_token; |
| 3791 | while (response.GetNameColonValue (desc_token, desc_string)) |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3792 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3793 | if (desc_token == "description") |
| 3794 | { |
| 3795 | extractor.GetStringRef().swap(desc_string); |
| 3796 | extractor.SetFilePos(0); |
| 3797 | extractor.GetHexByteString (desc_string); |
| 3798 | desc_cstr = desc_string.c_str(); |
| 3799 | } |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3800 | } |
| 3801 | } |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3802 | process->SetExitStatus(exit_status, desc_cstr); |
| 3803 | done = true; |
| 3804 | break; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3805 | } |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3806 | case eStateInvalid: |
Jason Molenda | 752e1e8 | 2015-07-29 01:42:16 +0000 | [diff] [blame^] | 3807 | { |
| 3808 | // Check to see if we were trying to attach and if we got back |
| 3809 | // the "E87" error code from debugserver -- this indicates that |
| 3810 | // the process is not debuggable. Return a slightly more helpful |
| 3811 | // error message about why the attach failed. |
| 3812 | if (::strstr (continue_cstr, "vAttach") != NULL |
| 3813 | && response.GetError() == 0x87) |
| 3814 | { |
| 3815 | process->SetExitStatus(-1, "cannot attach to process due to System Integrity Protection"); |
| 3816 | } |
| 3817 | // E01 code from vAttach means that the attach failed |
| 3818 | if (::strstr (continue_cstr, "vAttach") != NULL |
| 3819 | && response.GetError() == 0x1) |
| 3820 | { |
| 3821 | process->SetExitStatus(-1, "unable to attach"); |
| 3822 | } |
| 3823 | else |
| 3824 | { |
| 3825 | process->SetExitStatus(-1, "lost connection"); |
| 3826 | } |
| 3827 | break; |
| 3828 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3829 | |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3830 | default: |
| 3831 | process->SetPrivateState (stop_state); |
| 3832 | break; |
| 3833 | } // switch(stop_state) |
| 3834 | } // else // if in All-stop-mode |
| 3835 | } // if (continue_packet) |
| 3836 | } // case eBroadcastBitAysncContinue |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3837 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3838 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3839 | case eBroadcastBitAsyncThreadShouldExit: |
| 3840 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3841 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3842 | done = true; |
| 3843 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3844 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3845 | default: |
| 3846 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3847 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3848 | done = true; |
| 3849 | break; |
| 3850 | } |
| 3851 | } |
| 3852 | else if (event_sp->BroadcasterIs (&process->m_gdb_comm)) |
| 3853 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3854 | switch (event_type) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3855 | { |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3856 | case Communication::eBroadcastBitReadThreadDidExit: |
| 3857 | process->SetExitStatus (-1, "lost connection"); |
| 3858 | done = true; |
| 3859 | break; |
| 3860 | |
| 3861 | case GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify: |
| 3862 | { |
| 3863 | lldb_private::Event *event = event_sp.get(); |
| 3864 | const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event); |
| 3865 | StringExtractorGDBRemote notify((const char*)continue_packet->GetBytes()); |
| 3866 | // Hand this over to the process to handle |
| 3867 | process->HandleNotifyPacket(notify); |
| 3868 | break; |
| 3869 | } |
| 3870 | |
| 3871 | default: |
| 3872 | if (log) |
| 3873 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); |
| 3874 | done = true; |
| 3875 | break; |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3876 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3877 | } |
| 3878 | } |
| 3879 | else |
| 3880 | { |
| 3881 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3882 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3883 | done = true; |
| 3884 | } |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3889 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") thread exiting...", __FUNCTION__, arg, process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3890 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3891 | return NULL; |
| 3892 | } |
| 3893 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3894 | //uint32_t |
| 3895 | //ProcessGDBRemote::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) |
| 3896 | //{ |
| 3897 | // // If we are planning to launch the debugserver remotely, then we need to fire up a debugserver |
| 3898 | // // process and ask it for the list of processes. But if we are local, we can let the Host do it. |
| 3899 | // if (m_local_debugserver) |
| 3900 | // { |
| 3901 | // return Host::ListProcessesMatchingName (name, matches, pids); |
| 3902 | // } |
| 3903 | // else |
| 3904 | // { |
| 3905 | // // FIXME: Implement talking to the remote debugserver. |
| 3906 | // return 0; |
| 3907 | // } |
| 3908 | // |
| 3909 | //} |
| 3910 | // |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3911 | bool |
| 3912 | ProcessGDBRemote::NewThreadNotifyBreakpointHit (void *baton, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3913 | StoppointCallbackContext *context, |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3914 | lldb::user_id_t break_id, |
| 3915 | lldb::user_id_t break_loc_id) |
| 3916 | { |
| 3917 | // I don't think I have to do anything here, just make sure I notice the new thread when it starts to |
| 3918 | // run so I can stop it if that's what I want to do. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3919 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3920 | if (log) |
| 3921 | log->Printf("Hit New Thread Notification breakpoint."); |
| 3922 | return false; |
| 3923 | } |
| 3924 | |
| 3925 | |
| 3926 | bool |
| 3927 | ProcessGDBRemote::StartNoticingNewThreads() |
| 3928 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3929 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3930 | if (m_thread_create_bp_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3931 | { |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3932 | if (log && log->GetVerbose()) |
| 3933 | log->Printf("Enabled noticing new thread breakpoint."); |
| 3934 | m_thread_create_bp_sp->SetEnabled(true); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3935 | } |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3936 | else |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3937 | { |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3938 | PlatformSP platform_sp (m_target.GetPlatform()); |
| 3939 | if (platform_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3940 | { |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3941 | m_thread_create_bp_sp = platform_sp->SetThreadCreationBreakpoint(m_target); |
| 3942 | if (m_thread_create_bp_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3943 | { |
Jim Ingham | 37cfeab | 2011-10-15 00:21:37 +0000 | [diff] [blame] | 3944 | if (log && log->GetVerbose()) |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3945 | log->Printf("Successfully created new thread notification breakpoint %i", m_thread_create_bp_sp->GetID()); |
| 3946 | m_thread_create_bp_sp->SetCallback (ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3947 | } |
| 3948 | else |
| 3949 | { |
| 3950 | if (log) |
| 3951 | log->Printf("Failed to create new thread notification breakpoint."); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | } |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3955 | return m_thread_create_bp_sp.get() != NULL; |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | bool |
| 3959 | ProcessGDBRemote::StopNoticingNewThreads() |
| 3960 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3961 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 37cfeab | 2011-10-15 00:21:37 +0000 | [diff] [blame] | 3962 | if (log && log->GetVerbose()) |
Jim Ingham | 0e97cbc | 2011-02-08 05:19:01 +0000 | [diff] [blame] | 3963 | log->Printf ("Disabling new thread notification breakpoint."); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 3964 | |
| 3965 | if (m_thread_create_bp_sp) |
| 3966 | m_thread_create_bp_sp->SetEnabled(false); |
| 3967 | |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3968 | return true; |
| 3969 | } |
| 3970 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3971 | DynamicLoader * |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 3972 | ProcessGDBRemote::GetDynamicLoader () |
| 3973 | { |
| 3974 | if (m_dyld_ap.get() == NULL) |
Jason Molenda | 2e56a25 | 2013-05-11 03:09:05 +0000 | [diff] [blame] | 3975 | m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 3976 | return m_dyld_ap.get(); |
| 3977 | } |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 3978 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3979 | Error |
| 3980 | ProcessGDBRemote::SendEventData(const char *data) |
| 3981 | { |
| 3982 | int return_value; |
| 3983 | bool was_supported; |
| 3984 | |
| 3985 | Error error; |
| 3986 | |
| 3987 | return_value = m_gdb_comm.SendLaunchEventDataPacket (data, &was_supported); |
| 3988 | if (return_value != 0) |
| 3989 | { |
| 3990 | if (!was_supported) |
| 3991 | error.SetErrorString("Sending events is not supported for this process."); |
| 3992 | else |
| 3993 | error.SetErrorStringWithFormat("Error sending event data: %d.", return_value); |
| 3994 | } |
| 3995 | return error; |
| 3996 | } |
| 3997 | |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 3998 | const DataBufferSP |
| 3999 | ProcessGDBRemote::GetAuxvData() |
| 4000 | { |
| 4001 | DataBufferSP buf; |
| 4002 | if (m_gdb_comm.GetQXferAuxvReadSupported()) |
| 4003 | { |
| 4004 | std::string response_string; |
| 4005 | if (m_gdb_comm.SendPacketsAndConcatenateResponses("qXfer:auxv:read::", response_string) == GDBRemoteCommunication::PacketResult::Success) |
| 4006 | buf.reset(new DataBufferHeap(response_string.c_str(), response_string.length())); |
| 4007 | } |
| 4008 | return buf; |
| 4009 | } |
| 4010 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4011 | StructuredData::ObjectSP |
| 4012 | ProcessGDBRemote::GetExtendedInfoForThread (lldb::tid_t tid) |
| 4013 | { |
| 4014 | StructuredData::ObjectSP object_sp; |
| 4015 | |
| 4016 | if (m_gdb_comm.GetThreadExtendedInfoSupported()) |
| 4017 | { |
| 4018 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4019 | SystemRuntime *runtime = GetSystemRuntime(); |
| 4020 | if (runtime) |
| 4021 | { |
| 4022 | runtime->AddThreadExtendedInfoPacketHints (args_dict); |
| 4023 | } |
| 4024 | args_dict->GetAsDictionary()->AddIntegerItem ("thread", tid); |
| 4025 | |
| 4026 | StreamString packet; |
| 4027 | packet << "jThreadExtendedInfo:"; |
| 4028 | args_dict->Dump (packet); |
| 4029 | |
| 4030 | // FIXME the final character of a JSON dictionary, '}', is the escape |
| 4031 | // character in gdb-remote binary mode. lldb currently doesn't escape |
| 4032 | // these characters in its packet output -- so we add the quoted version |
| 4033 | // of the } character here manually in case we talk to a debugserver which |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4034 | // un-escapes the characters at packet read time. |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4035 | packet << (char) (0x7d ^ 0x20); |
| 4036 | |
| 4037 | StringExtractorGDBRemote response; |
| 4038 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == GDBRemoteCommunication::PacketResult::Success) |
| 4039 | { |
| 4040 | StringExtractorGDBRemote::ResponseType response_type = response.GetResponseType(); |
| 4041 | if (response_type == StringExtractorGDBRemote::eResponse) |
| 4042 | { |
| 4043 | if (!response.Empty()) |
| 4044 | { |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4045 | object_sp = StructuredData::ParseJSON (response.GetStringRef()); |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | } |
| 4050 | return object_sp; |
| 4051 | } |
| 4052 | |
| 4053 | StructuredData::ObjectSP |
| 4054 | ProcessGDBRemote::GetLoadedDynamicLibrariesInfos (lldb::addr_t image_list_address, lldb::addr_t image_count) |
| 4055 | { |
| 4056 | StructuredData::ObjectSP object_sp; |
| 4057 | |
| 4058 | if (m_gdb_comm.GetLoadedDynamicLibrariesInfosSupported()) |
| 4059 | { |
| 4060 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4061 | args_dict->GetAsDictionary()->AddIntegerItem ("image_list_address", image_list_address); |
| 4062 | args_dict->GetAsDictionary()->AddIntegerItem ("image_count", image_count); |
| 4063 | |
| 4064 | StreamString packet; |
| 4065 | packet << "jGetLoadedDynamicLibrariesInfos:"; |
| 4066 | args_dict->Dump (packet); |
| 4067 | |
| 4068 | // FIXME the final character of a JSON dictionary, '}', is the escape |
| 4069 | // character in gdb-remote binary mode. lldb currently doesn't escape |
| 4070 | // these characters in its packet output -- so we add the quoted version |
| 4071 | // of the } character here manually in case we talk to a debugserver which |
| 4072 | // un-escapes the characters at packet read time. |
| 4073 | packet << (char) (0x7d ^ 0x20); |
| 4074 | |
| 4075 | StringExtractorGDBRemote response; |
| 4076 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == GDBRemoteCommunication::PacketResult::Success) |
| 4077 | { |
| 4078 | StringExtractorGDBRemote::ResponseType response_type = response.GetResponseType(); |
| 4079 | if (response_type == StringExtractorGDBRemote::eResponse) |
| 4080 | { |
| 4081 | if (!response.Empty()) |
| 4082 | { |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4083 | // The packet has already had the 0x7d xor quoting stripped out at the |
| 4084 | // GDBRemoteCommunication packet receive level. |
| 4085 | object_sp = StructuredData::ParseJSON (response.GetStringRef()); |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | return object_sp; |
| 4091 | } |
| 4092 | |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4093 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4094 | // Establish the largest memory read/write payloads we should use. |
| 4095 | // If the remote stub has a max packet size, stay under that size. |
| 4096 | // |
| 4097 | // If the remote stub's max packet size is crazy large, use a |
| 4098 | // reasonable largeish default. |
| 4099 | // |
| 4100 | // If the remote stub doesn't advertise a max packet size, use a |
| 4101 | // conservative default. |
| 4102 | |
| 4103 | void |
| 4104 | ProcessGDBRemote::GetMaxMemorySize() |
| 4105 | { |
| 4106 | const uint64_t reasonable_largeish_default = 128 * 1024; |
| 4107 | const uint64_t conservative_default = 512; |
| 4108 | |
| 4109 | if (m_max_memory_size == 0) |
| 4110 | { |
| 4111 | uint64_t stub_max_size = m_gdb_comm.GetRemoteMaxPacketSize(); |
| 4112 | if (stub_max_size != UINT64_MAX && stub_max_size != 0) |
| 4113 | { |
| 4114 | // Save the stub's claimed maximum packet size |
| 4115 | m_remote_stub_max_memory_size = stub_max_size; |
| 4116 | |
| 4117 | // Even if the stub says it can support ginormous packets, |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4118 | // don't exceed our reasonable largeish default packet size. |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4119 | if (stub_max_size > reasonable_largeish_default) |
| 4120 | { |
| 4121 | stub_max_size = reasonable_largeish_default; |
| 4122 | } |
| 4123 | |
| 4124 | m_max_memory_size = stub_max_size; |
| 4125 | } |
| 4126 | else |
| 4127 | { |
| 4128 | m_max_memory_size = conservative_default; |
| 4129 | } |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | void |
| 4134 | ProcessGDBRemote::SetUserSpecifiedMaxMemoryTransferSize (uint64_t user_specified_max) |
| 4135 | { |
| 4136 | if (user_specified_max != 0) |
| 4137 | { |
| 4138 | GetMaxMemorySize (); |
| 4139 | |
| 4140 | if (m_remote_stub_max_memory_size != 0) |
| 4141 | { |
| 4142 | if (m_remote_stub_max_memory_size < user_specified_max) |
| 4143 | { |
| 4144 | m_max_memory_size = m_remote_stub_max_memory_size; // user specified a packet size too big, go as big |
| 4145 | // as the remote stub says we can go. |
| 4146 | } |
| 4147 | else |
| 4148 | { |
| 4149 | m_max_memory_size = user_specified_max; // user's packet size is good |
| 4150 | } |
| 4151 | } |
| 4152 | else |
| 4153 | { |
| 4154 | m_max_memory_size = user_specified_max; // user's packet size is probably fine |
| 4155 | } |
| 4156 | } |
| 4157 | } |
| 4158 | |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 4159 | bool |
| 4160 | ProcessGDBRemote::GetModuleSpec(const FileSpec& module_file_spec, |
| 4161 | const ArchSpec& arch, |
| 4162 | ModuleSpec &module_spec) |
| 4163 | { |
| 4164 | Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM); |
| 4165 | |
| 4166 | if (!m_gdb_comm.GetModuleInfo (module_file_spec, arch, module_spec)) |
| 4167 | { |
| 4168 | if (log) |
| 4169 | log->Printf ("ProcessGDBRemote::%s - failed to get module info for %s:%s", |
| 4170 | __FUNCTION__, module_file_spec.GetPath ().c_str (), |
| 4171 | arch.GetTriple ().getTriple ().c_str ()); |
| 4172 | return false; |
| 4173 | } |
| 4174 | |
| 4175 | if (log) |
| 4176 | { |
| 4177 | StreamString stream; |
| 4178 | module_spec.Dump (stream); |
| 4179 | log->Printf ("ProcessGDBRemote::%s - got module info for (%s:%s) : %s", |
| 4180 | __FUNCTION__, module_file_spec.GetPath ().c_str (), |
| 4181 | arch.GetTriple ().getTriple ().c_str (), stream.GetString ().c_str ()); |
| 4182 | } |
| 4183 | |
| 4184 | return true; |
| 4185 | } |
| 4186 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4187 | namespace { |
| 4188 | |
| 4189 | typedef std::vector<std::string> stringVec; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4190 | |
| 4191 | typedef std::vector<struct GdbServerRegisterInfo> GDBServerRegisterVec; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4192 | struct RegisterSetInfo |
| 4193 | { |
| 4194 | ConstString name; |
| 4195 | }; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4196 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4197 | typedef std::map<uint32_t, RegisterSetInfo> RegisterSetMap; |
| 4198 | |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4199 | struct GdbServerTargetInfo |
| 4200 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4201 | std::string arch; |
| 4202 | std::string osabi; |
| 4203 | stringVec includes; |
| 4204 | RegisterSetMap reg_set_map; |
| 4205 | XMLNode feature_node; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4206 | }; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4207 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4208 | bool |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4209 | ParseRegisters (XMLNode feature_node, GdbServerTargetInfo &target_info, GDBRemoteDynamicRegisterInfo &dyn_reg_info) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4210 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4211 | if (!feature_node) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4212 | return false; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4213 | |
| 4214 | uint32_t prev_reg_num = 0; |
| 4215 | uint32_t reg_offset = 0; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4216 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4217 | feature_node.ForEachChildElementWithName("reg", [&target_info, &dyn_reg_info, &prev_reg_num, ®_offset](const XMLNode ®_node) -> bool { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4218 | std::string gdb_group; |
| 4219 | std::string gdb_type; |
| 4220 | ConstString reg_name; |
| 4221 | ConstString alt_name; |
| 4222 | ConstString set_name; |
| 4223 | std::vector<uint32_t> value_regs; |
| 4224 | std::vector<uint32_t> invalidate_regs; |
| 4225 | bool encoding_set = false; |
| 4226 | bool format_set = false; |
| 4227 | RegisterInfo reg_info = { NULL, // Name |
| 4228 | NULL, // Alt name |
| 4229 | 0, // byte size |
| 4230 | reg_offset, // offset |
| 4231 | eEncodingUint, // encoding |
| 4232 | eFormatHex, // formate |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4233 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4234 | LLDB_INVALID_REGNUM, // GCC reg num |
| 4235 | LLDB_INVALID_REGNUM, // DWARF reg num |
| 4236 | LLDB_INVALID_REGNUM, // generic reg num |
| 4237 | prev_reg_num, // GDB reg num |
| 4238 | prev_reg_num // native register number |
| 4239 | }, |
| 4240 | NULL, |
| 4241 | NULL |
| 4242 | }; |
| 4243 | |
Ewan Crawford | 682e842 | 2015-06-26 09:38:27 +0000 | [diff] [blame] | 4244 | reg_node.ForEachAttribute([&target_info, &gdb_group, &gdb_type, ®_name, &alt_name, &set_name, &value_regs, &invalidate_regs, &encoding_set, &format_set, ®_info, &prev_reg_num, ®_offset](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4245 | if (name == "name") |
| 4246 | { |
| 4247 | reg_name.SetString(value); |
| 4248 | } |
| 4249 | else if (name == "bitsize") |
| 4250 | { |
| 4251 | reg_info.byte_size = StringConvert::ToUInt32(value.data(), 0, 0) / CHAR_BIT; |
| 4252 | } |
| 4253 | else if (name == "type") |
| 4254 | { |
| 4255 | gdb_type = value.str(); |
| 4256 | } |
| 4257 | else if (name == "group") |
| 4258 | { |
| 4259 | gdb_group = value.str(); |
| 4260 | } |
| 4261 | else if (name == "regnum") |
| 4262 | { |
| 4263 | const uint32_t regnum = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
| 4264 | if (regnum != LLDB_INVALID_REGNUM) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4265 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4266 | reg_info.kinds[eRegisterKindGDB] = regnum; |
| 4267 | reg_info.kinds[eRegisterKindLLDB] = regnum; |
| 4268 | prev_reg_num = regnum; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4269 | } |
| 4270 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4271 | else if (name == "offset") |
| 4272 | { |
| 4273 | reg_offset = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4274 | } |
| 4275 | else if (name == "altname") |
| 4276 | { |
| 4277 | alt_name.SetString(value); |
| 4278 | } |
| 4279 | else if (name == "encoding") |
| 4280 | { |
| 4281 | encoding_set = true; |
| 4282 | reg_info.encoding = Args::StringToEncoding (value.data(), eEncodingUint); |
| 4283 | } |
| 4284 | else if (name == "format") |
| 4285 | { |
| 4286 | format_set = true; |
| 4287 | Format format = eFormatInvalid; |
| 4288 | if (Args::StringToFormat (value.data(), format, NULL).Success()) |
| 4289 | reg_info.format = format; |
| 4290 | else if (value == "vector-sint8") |
| 4291 | reg_info.format = eFormatVectorOfSInt8; |
| 4292 | else if (value == "vector-uint8") |
| 4293 | reg_info.format = eFormatVectorOfUInt8; |
| 4294 | else if (value == "vector-sint16") |
| 4295 | reg_info.format = eFormatVectorOfSInt16; |
| 4296 | else if (value == "vector-uint16") |
| 4297 | reg_info.format = eFormatVectorOfUInt16; |
| 4298 | else if (value == "vector-sint32") |
| 4299 | reg_info.format = eFormatVectorOfSInt32; |
| 4300 | else if (value == "vector-uint32") |
| 4301 | reg_info.format = eFormatVectorOfUInt32; |
| 4302 | else if (value == "vector-float32") |
| 4303 | reg_info.format = eFormatVectorOfFloat32; |
| 4304 | else if (value == "vector-uint128") |
| 4305 | reg_info.format = eFormatVectorOfUInt128; |
| 4306 | } |
| 4307 | else if (name == "group_id") |
| 4308 | { |
| 4309 | const uint32_t set_id = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4310 | RegisterSetMap::const_iterator pos = target_info.reg_set_map.find(set_id); |
| 4311 | if (pos != target_info.reg_set_map.end()) |
| 4312 | set_name = pos->second.name; |
| 4313 | } |
| 4314 | else if (name == "gcc_regnum") |
| 4315 | { |
| 4316 | reg_info.kinds[eRegisterKindGCC] = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
| 4317 | } |
| 4318 | else if (name == "dwarf_regnum") |
| 4319 | { |
| 4320 | reg_info.kinds[eRegisterKindDWARF] = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
| 4321 | } |
| 4322 | else if (name == "generic") |
| 4323 | { |
| 4324 | reg_info.kinds[eRegisterKindGeneric] = Args::StringToGenericRegister(value.data()); |
| 4325 | } |
| 4326 | else if (name == "value_regnums") |
| 4327 | { |
| 4328 | SplitCommaSeparatedRegisterNumberString(value, value_regs, 0); |
| 4329 | } |
| 4330 | else if (name == "invalidate_regnums") |
| 4331 | { |
| 4332 | SplitCommaSeparatedRegisterNumberString(value, invalidate_regs, 0); |
| 4333 | } |
| 4334 | else |
| 4335 | { |
| 4336 | printf("unhandled attribute %s = %s\n", name.data(), value.data()); |
| 4337 | } |
| 4338 | return true; // Keep iterating through all attributes |
| 4339 | }); |
| 4340 | |
| 4341 | if (!gdb_type.empty() && !(encoding_set || format_set)) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4342 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4343 | if (gdb_type.find("int") == 0) |
| 4344 | { |
| 4345 | reg_info.format = eFormatHex; |
| 4346 | reg_info.encoding = eEncodingUint; |
| 4347 | } |
| 4348 | else if (gdb_type == "data_ptr" || gdb_type == "code_ptr") |
| 4349 | { |
| 4350 | reg_info.format = eFormatAddressInfo; |
| 4351 | reg_info.encoding = eEncodingUint; |
| 4352 | } |
| 4353 | else if (gdb_type == "i387_ext" || gdb_type == "float") |
| 4354 | { |
| 4355 | reg_info.format = eFormatFloat; |
| 4356 | reg_info.encoding = eEncodingIEEE754; |
| 4357 | } |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4358 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4359 | |
| 4360 | // Only update the register set name if we didn't get a "reg_set" attribute. |
| 4361 | // "set_name" will be empty if we didn't have a "reg_set" attribute. |
| 4362 | if (!set_name && !gdb_group.empty()) |
| 4363 | set_name.SetCString(gdb_group.c_str()); |
| 4364 | |
| 4365 | reg_info.byte_offset = reg_offset; |
| 4366 | assert (reg_info.byte_size != 0); |
| 4367 | reg_offset += reg_info.byte_size; |
| 4368 | if (!value_regs.empty()) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4369 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4370 | value_regs.push_back(LLDB_INVALID_REGNUM); |
| 4371 | reg_info.value_regs = value_regs.data(); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4372 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4373 | if (!invalidate_regs.empty()) |
| 4374 | { |
| 4375 | invalidate_regs.push_back(LLDB_INVALID_REGNUM); |
| 4376 | reg_info.invalidate_regs = invalidate_regs.data(); |
| 4377 | } |
| 4378 | |
Ewan Crawford | 682e842 | 2015-06-26 09:38:27 +0000 | [diff] [blame] | 4379 | ++prev_reg_num; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4380 | dyn_reg_info.AddRegister(reg_info, reg_name, alt_name, set_name); |
| 4381 | |
| 4382 | return true; // Keep iterating through all "reg" elements |
| 4383 | }); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4384 | return true; |
| 4385 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4386 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4387 | } // namespace {} |
| 4388 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4389 | |
| 4390 | // query the target of gdb-remote for extended target information |
| 4391 | // return: 'true' on success |
| 4392 | // 'false' on failure |
| 4393 | bool |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4394 | ProcessGDBRemote::GetGDBServerRegisterInfo () |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4395 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4396 | // Make sure LLDB has an XML parser it can use first |
| 4397 | if (!XMLDocument::XMLEnabled()) |
| 4398 | return false; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4399 | |
| 4400 | // redirect libxml2's error handler since the default prints to stdout |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4401 | |
| 4402 | GDBRemoteCommunicationClient & comm = m_gdb_comm; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4403 | |
| 4404 | // check that we have extended feature read support |
| 4405 | if ( !comm.GetQXferFeaturesReadSupported( ) ) |
| 4406 | return false; |
| 4407 | |
| 4408 | // request the target xml file |
| 4409 | std::string raw; |
| 4410 | lldb_private::Error lldberr; |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4411 | if (!comm.ReadExtFeature(ConstString("features"), |
| 4412 | ConstString("target.xml"), |
| 4413 | raw, |
| 4414 | lldberr)) |
| 4415 | { |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4418 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4419 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4420 | XMLDocument xml_document; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4421 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4422 | if (xml_document.ParseMemory(raw.c_str(), raw.size(), "target.xml")) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4423 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4424 | GdbServerTargetInfo target_info; |
| 4425 | |
| 4426 | XMLNode target_node = xml_document.GetRootElement("target"); |
| 4427 | if (target_node) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4428 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4429 | XMLNode feature_node; |
| 4430 | target_node.ForEachChildElement([&target_info, this, &feature_node](const XMLNode &node) -> bool |
| 4431 | { |
| 4432 | llvm::StringRef name = node.GetName(); |
| 4433 | if (name == "architecture") |
| 4434 | { |
| 4435 | node.GetElementText(target_info.arch); |
| 4436 | } |
| 4437 | else if (name == "osabi") |
| 4438 | { |
| 4439 | node.GetElementText(target_info.osabi); |
| 4440 | } |
Ewan Crawford | 682e842 | 2015-06-26 09:38:27 +0000 | [diff] [blame] | 4441 | else if (name == "xi:include" || name == "include") |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4442 | { |
| 4443 | llvm::StringRef href = node.GetAttributeValue("href"); |
| 4444 | if (!href.empty()) |
| 4445 | target_info.includes.push_back(href.str()); |
| 4446 | } |
| 4447 | else if (name == "feature") |
| 4448 | { |
| 4449 | feature_node = node; |
| 4450 | } |
| 4451 | else if (name == "groups") |
| 4452 | { |
| 4453 | node.ForEachChildElementWithName("group", [&target_info](const XMLNode &node) -> bool { |
| 4454 | uint32_t set_id = UINT32_MAX; |
| 4455 | RegisterSetInfo set_info; |
| 4456 | |
| 4457 | node.ForEachAttribute([&set_id, &set_info](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
| 4458 | if (name == "id") |
| 4459 | set_id = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4460 | if (name == "name") |
| 4461 | set_info.name = ConstString(value); |
| 4462 | return true; // Keep iterating through all attributes |
| 4463 | }); |
| 4464 | |
| 4465 | if (set_id != UINT32_MAX) |
| 4466 | target_info.reg_set_map[set_id] = set_info; |
| 4467 | return true; // Keep iterating through all "group" elements |
| 4468 | }); |
| 4469 | } |
| 4470 | return true; // Keep iterating through all children of the target_node |
| 4471 | }); |
| 4472 | |
| 4473 | if (feature_node) |
| 4474 | { |
| 4475 | ParseRegisters(feature_node, target_info, this->m_register_info); |
| 4476 | } |
| 4477 | |
| 4478 | for (const auto &include : target_info.includes) |
| 4479 | { |
| 4480 | // request register file |
| 4481 | std::string xml_data; |
| 4482 | if (!comm.ReadExtFeature(ConstString("features"), |
| 4483 | ConstString(include), |
| 4484 | xml_data, |
| 4485 | lldberr)) |
| 4486 | continue; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4487 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4488 | XMLDocument include_xml_document; |
| 4489 | include_xml_document.ParseMemory(xml_data.data(), xml_data.size(), include.c_str()); |
| 4490 | XMLNode include_feature_node = include_xml_document.GetRootElement("feature"); |
| 4491 | if (include_feature_node) |
| 4492 | { |
| 4493 | ParseRegisters(include_feature_node, target_info, this->m_register_info); |
| 4494 | } |
| 4495 | } |
| 4496 | this->m_register_info.Finalize(GetTarget().GetArchitecture()); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4497 | } |
| 4498 | } |
| 4499 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4500 | return m_register_info.GetNumRegisters() > 0; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4503 | Error |
| 4504 | ProcessGDBRemote::GetLoadedModuleList (GDBLoadedModuleInfoList & list) |
| 4505 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4506 | // Make sure LLDB has an XML parser it can use first |
| 4507 | if (!XMLDocument::XMLEnabled()) |
| 4508 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4509 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4510 | Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS); |
| 4511 | if (log) |
| 4512 | log->Printf ("ProcessGDBRemote::%s", __FUNCTION__); |
| 4513 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4514 | GDBRemoteCommunicationClient & comm = m_gdb_comm; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4515 | |
| 4516 | // check that we have extended feature read support |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4517 | if (comm.GetQXferLibrariesSVR4ReadSupported ()) { |
| 4518 | list.clear (); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4519 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4520 | // request the loaded library list |
| 4521 | std::string raw; |
| 4522 | lldb_private::Error lldberr; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4523 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4524 | if (!comm.ReadExtFeature (ConstString ("libraries-svr4"), ConstString (""), raw, lldberr)) |
| 4525 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4526 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4527 | // parse the xml file in memory |
| 4528 | if (log) |
| 4529 | log->Printf ("parsing: %s", raw.c_str()); |
| 4530 | XMLDocument doc; |
| 4531 | |
| 4532 | if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) |
| 4533 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4534 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4535 | XMLNode root_element = doc.GetRootElement("library-list-svr4"); |
| 4536 | if (!root_element) |
| 4537 | return Error(); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4538 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4539 | // main link map structure |
| 4540 | llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm"); |
| 4541 | if (!main_lm.empty()) |
| 4542 | { |
| 4543 | list.m_link_map = StringConvert::ToUInt64(main_lm.data(), LLDB_INVALID_ADDRESS, 0); |
| 4544 | } |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4545 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4546 | root_element.ForEachChildElementWithName("library", [log, &list](const XMLNode &library) -> bool { |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4547 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4548 | GDBLoadedModuleInfoList::LoadedModuleInfo module; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4549 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4550 | library.ForEachAttribute([log, &module](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4551 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4552 | if (name == "name") |
| 4553 | module.set_name (value.str()); |
| 4554 | else if (name == "lm") |
| 4555 | { |
| 4556 | // the address of the link_map struct. |
| 4557 | module.set_link_map(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4558 | } |
| 4559 | else if (name == "l_addr") |
| 4560 | { |
| 4561 | // the displacement as read from the field 'l_addr' of the link_map struct. |
| 4562 | module.set_base(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4563 | |
| 4564 | } |
| 4565 | else if (name == "l_ld") |
| 4566 | { |
| 4567 | // the memory address of the libraries PT_DYAMIC section. |
| 4568 | module.set_dynamic(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4569 | } |
| 4570 | |
| 4571 | return true; // Keep iterating over all properties of "library" |
| 4572 | }); |
| 4573 | |
| 4574 | if (log) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4575 | { |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4576 | std::string name; |
| 4577 | lldb::addr_t lm=0, base=0, ld=0; |
| 4578 | |
| 4579 | module.get_name (name); |
| 4580 | module.get_link_map (lm); |
| 4581 | module.get_base (base); |
| 4582 | module.get_dynamic (ld); |
| 4583 | |
| 4584 | log->Printf ("found (link_map:0x08%" PRIx64 ", base:0x08%" PRIx64 ", ld:0x08%" PRIx64 ", name:'%s')", lm, base, ld, name.c_str()); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4585 | } |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4586 | |
| 4587 | list.add (module); |
| 4588 | return true; // Keep iterating over all "library" elements in the root node |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4589 | }); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4590 | |
| 4591 | if (log) |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4592 | log->Printf ("found %" PRId32 " modules in total", (int) list.m_list.size()); |
| 4593 | } else if (comm.GetQXferLibrariesReadSupported ()) { |
| 4594 | list.clear (); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4595 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4596 | // request the loaded library list |
| 4597 | std::string raw; |
| 4598 | lldb_private::Error lldberr; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4599 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4600 | if (!comm.ReadExtFeature (ConstString ("libraries"), ConstString (""), raw, lldberr)) |
| 4601 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4602 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4603 | if (log) |
| 4604 | log->Printf ("parsing: %s", raw.c_str()); |
| 4605 | XMLDocument doc; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4606 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4607 | if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) |
| 4608 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4609 | |
| 4610 | XMLNode root_element = doc.GetRootElement("library-list"); |
| 4611 | if (!root_element) |
| 4612 | return Error(); |
| 4613 | |
| 4614 | root_element.ForEachChildElementWithName("library", [log, &list](const XMLNode &library) -> bool { |
| 4615 | GDBLoadedModuleInfoList::LoadedModuleInfo module; |
| 4616 | |
| 4617 | llvm::StringRef name = library.GetAttributeValue("name"); |
| 4618 | module.set_name(name.str()); |
| 4619 | |
| 4620 | // The base address of a given library will be the address of its |
| 4621 | // first section. Most remotes send only one section for Windows |
| 4622 | // targets for example. |
| 4623 | const XMLNode §ion = library.FindFirstChildElementWithName("section"); |
| 4624 | llvm::StringRef address = section.GetAttributeValue("address"); |
| 4625 | module.set_base(StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4626 | |
| 4627 | if (log) |
| 4628 | { |
| 4629 | std::string name; |
| 4630 | lldb::addr_t base = 0; |
| 4631 | module.get_name (name); |
| 4632 | module.get_base (base); |
| 4633 | |
| 4634 | log->Printf ("found (base:0x%" PRIx64 ", name:'%s')", base, name.c_str()); |
| 4635 | } |
| 4636 | |
| 4637 | list.add (module); |
| 4638 | return true; // Keep iterating over all "library" elements in the root node |
| 4639 | }); |
| 4640 | |
| 4641 | if (log) |
| 4642 | log->Printf ("found %" PRId32 " modules in total", (int) list.m_list.size()); |
| 4643 | } else { |
| 4644 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4645 | } |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4646 | |
| 4647 | return Error(); |
| 4648 | } |
| 4649 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4650 | lldb::ModuleSP |
| 4651 | ProcessGDBRemote::LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_addr) |
| 4652 | { |
| 4653 | Target &target = m_process->GetTarget(); |
| 4654 | ModuleList &modules = target.GetImages(); |
| 4655 | ModuleSP module_sp; |
| 4656 | |
| 4657 | bool changed = false; |
| 4658 | |
| 4659 | ModuleSpec module_spec (file, target.GetArchitecture()); |
| 4660 | if ((module_sp = modules.FindFirstModule (module_spec))) |
| 4661 | { |
| 4662 | module_sp->SetLoadAddress (target, base_addr, true, changed); |
| 4663 | } |
| 4664 | else if ((module_sp = target.GetSharedModule (module_spec))) |
| 4665 | { |
| 4666 | module_sp->SetLoadAddress (target, base_addr, true, changed); |
| 4667 | } |
| 4668 | |
| 4669 | return module_sp; |
| 4670 | } |
| 4671 | |
| 4672 | size_t |
| 4673 | ProcessGDBRemote::LoadModules () |
| 4674 | { |
| 4675 | using lldb_private::process_gdb_remote::ProcessGDBRemote; |
| 4676 | |
| 4677 | // request a list of loaded libraries from GDBServer |
| 4678 | GDBLoadedModuleInfoList module_list; |
| 4679 | if (GetLoadedModuleList (module_list).Fail()) |
| 4680 | return 0; |
| 4681 | |
| 4682 | // get a list of all the modules |
| 4683 | ModuleList new_modules; |
| 4684 | |
| 4685 | for (GDBLoadedModuleInfoList::LoadedModuleInfo & modInfo : module_list.m_list) |
| 4686 | { |
| 4687 | std::string mod_name; |
| 4688 | lldb::addr_t mod_base; |
| 4689 | |
| 4690 | bool valid = true; |
| 4691 | valid &= modInfo.get_name (mod_name); |
| 4692 | valid &= modInfo.get_base (mod_base); |
| 4693 | if (!valid) |
| 4694 | continue; |
| 4695 | |
| 4696 | // hack (cleaner way to get file name only?) (win/unix compat?) |
Vince Harron | 4cc8d20 | 2015-05-10 08:33:58 +0000 | [diff] [blame] | 4697 | size_t marker = mod_name.rfind ('/'); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4698 | if (marker == std::string::npos) |
| 4699 | marker = 0; |
| 4700 | else |
| 4701 | marker += 1; |
| 4702 | |
| 4703 | FileSpec file (mod_name.c_str()+marker, true); |
| 4704 | lldb::ModuleSP module_sp = LoadModuleAtAddress (file, mod_base); |
| 4705 | |
| 4706 | if (module_sp.get()) |
| 4707 | new_modules.Append (module_sp); |
| 4708 | } |
| 4709 | |
| 4710 | if (new_modules.GetSize() > 0) |
| 4711 | { |
| 4712 | Target & target = m_target; |
| 4713 | |
| 4714 | new_modules.ForEach ([&target](const lldb::ModuleSP module_sp) -> bool |
| 4715 | { |
| 4716 | lldb_private::ObjectFile * obj = module_sp->GetObjectFile (); |
| 4717 | if (!obj) |
| 4718 | return true; |
| 4719 | |
| 4720 | if (obj->GetType () != ObjectFile::Type::eTypeExecutable) |
| 4721 | return true; |
| 4722 | |
| 4723 | lldb::ModuleSP module_copy_sp = module_sp; |
| 4724 | target.SetExecutableModule (module_copy_sp, false); |
| 4725 | return false; |
| 4726 | }); |
| 4727 | |
| 4728 | ModuleList &loaded_modules = m_process->GetTarget().GetImages(); |
| 4729 | loaded_modules.AppendIfNeeded (new_modules); |
| 4730 | m_process->GetTarget().ModulesDidLoad (new_modules); |
| 4731 | } |
| 4732 | |
| 4733 | return new_modules.GetSize(); |
| 4734 | } |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4735 | |
Tamas Berghammer | 783bfc8 | 2015-06-18 20:43:56 +0000 | [diff] [blame] | 4736 | Error |
| 4737 | ProcessGDBRemote::GetFileLoadAddress(const FileSpec& file, bool& is_loaded, lldb::addr_t& load_addr) |
| 4738 | { |
| 4739 | is_loaded = false; |
| 4740 | load_addr = LLDB_INVALID_ADDRESS; |
| 4741 | |
| 4742 | std::string file_path = file.GetPath(false); |
| 4743 | if (file_path.empty ()) |
| 4744 | return Error("Empty file name specified"); |
| 4745 | |
| 4746 | StreamString packet; |
| 4747 | packet.PutCString("qFileLoadAddress:"); |
| 4748 | packet.PutCStringAsRawHex8(file_path.c_str()); |
| 4749 | |
| 4750 | StringExtractorGDBRemote response; |
| 4751 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), response, false) != GDBRemoteCommunication::PacketResult::Success) |
| 4752 | return Error("Sending qFileLoadAddress packet failed"); |
| 4753 | |
| 4754 | if (response.IsErrorResponse()) |
| 4755 | { |
| 4756 | if (response.GetError() == 1) |
| 4757 | { |
| 4758 | // The file is not loaded into the inferior |
| 4759 | is_loaded = false; |
| 4760 | load_addr = LLDB_INVALID_ADDRESS; |
| 4761 | return Error(); |
| 4762 | } |
| 4763 | |
| 4764 | return Error("Fetching file load address from remote server returned an error"); |
| 4765 | } |
| 4766 | |
| 4767 | if (response.IsNormalResponse()) |
| 4768 | { |
| 4769 | is_loaded = true; |
| 4770 | load_addr = response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 4771 | return Error(); |
| 4772 | } |
| 4773 | |
| 4774 | return Error("Unknown error happened during sending the load address packet"); |
| 4775 | } |
| 4776 | |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 4777 | |
| 4778 | void |
| 4779 | ProcessGDBRemote::ModulesDidLoad (ModuleList &module_list) |
| 4780 | { |
| 4781 | // We must call the lldb_private::Process::ModulesDidLoad () first before we do anything |
| 4782 | Process::ModulesDidLoad (module_list); |
| 4783 | |
| 4784 | // After loading shared libraries, we can ask our remote GDB server if |
| 4785 | // it needs any symbols. |
| 4786 | m_gdb_comm.ServeSymbolLookups(this); |
| 4787 | } |
| 4788 | |
| 4789 | |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 4790 | class CommandObjectProcessGDBRemoteSpeedTest: public CommandObjectParsed |
| 4791 | { |
| 4792 | public: |
| 4793 | CommandObjectProcessGDBRemoteSpeedTest(CommandInterpreter &interpreter) : |
| 4794 | CommandObjectParsed (interpreter, |
| 4795 | "process plugin packet speed-test", |
| 4796 | "Tests packet speeds of various sizes to determine the performance characteristics of the GDB remote connection. ", |
| 4797 | NULL), |
| 4798 | m_option_group (interpreter), |
| 4799 | m_num_packets (LLDB_OPT_SET_1, false, "count", 'c', 0, eArgTypeCount, "The number of packets to send of each varying size (default is 1000).", 1000), |
| 4800 | m_max_send (LLDB_OPT_SET_1, false, "max-send", 's', 0, eArgTypeCount, "The maximum number of bytes to send in a packet. Sizes increase in powers of 2 while the size is less than or equal to this option value. (default 1024).", 1024), |
| 4801 | m_max_recv (LLDB_OPT_SET_1, false, "max-receive", 'r', 0, eArgTypeCount, "The maximum number of bytes to receive in a packet. Sizes increase in powers of 2 while the size is less than or equal to this option value. (default 1024).", 1024), |
| 4802 | m_json (LLDB_OPT_SET_1, false, "json", 'j', "Print the output as JSON data for easy parsing.", false, true) |
| 4803 | { |
| 4804 | m_option_group.Append (&m_num_packets, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4805 | m_option_group.Append (&m_max_send, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4806 | m_option_group.Append (&m_max_recv, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4807 | m_option_group.Append (&m_json, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4808 | m_option_group.Finalize(); |
| 4809 | } |
| 4810 | |
| 4811 | ~CommandObjectProcessGDBRemoteSpeedTest () |
| 4812 | { |
| 4813 | } |
| 4814 | |
| 4815 | |
| 4816 | Options * |
| 4817 | GetOptions () override |
| 4818 | { |
| 4819 | return &m_option_group; |
| 4820 | } |
| 4821 | |
| 4822 | bool |
| 4823 | DoExecute (Args& command, CommandReturnObject &result) override |
| 4824 | { |
| 4825 | const size_t argc = command.GetArgumentCount(); |
| 4826 | if (argc == 0) |
| 4827 | { |
| 4828 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 4829 | if (process) |
| 4830 | { |
| 4831 | StreamSP output_stream_sp (m_interpreter.GetDebugger().GetAsyncOutputStream()); |
| 4832 | result.SetImmediateOutputStream (output_stream_sp); |
| 4833 | |
| 4834 | const uint32_t num_packets = (uint32_t)m_num_packets.GetOptionValue().GetCurrentValue(); |
| 4835 | const uint64_t max_send = m_max_send.GetOptionValue().GetCurrentValue(); |
| 4836 | const uint64_t max_recv = m_max_recv.GetOptionValue().GetCurrentValue(); |
| 4837 | const bool json = m_json.GetOptionValue().GetCurrentValue(); |
| 4838 | if (output_stream_sp) |
| 4839 | process->GetGDBRemote().TestPacketSpeed (num_packets, max_send, max_recv, json, *output_stream_sp); |
| 4840 | else |
| 4841 | { |
| 4842 | process->GetGDBRemote().TestPacketSpeed (num_packets, max_send, max_recv, json, result.GetOutputStream()); |
| 4843 | } |
| 4844 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4845 | return true; |
| 4846 | } |
| 4847 | } |
| 4848 | else |
| 4849 | { |
| 4850 | result.AppendErrorWithFormat ("'%s' takes no arguments", m_cmd_name.c_str()); |
| 4851 | } |
| 4852 | result.SetStatus (eReturnStatusFailed); |
| 4853 | return false; |
| 4854 | } |
| 4855 | protected: |
| 4856 | OptionGroupOptions m_option_group; |
| 4857 | OptionGroupUInt64 m_num_packets; |
| 4858 | OptionGroupUInt64 m_max_send; |
| 4859 | OptionGroupUInt64 m_max_recv; |
| 4860 | OptionGroupBoolean m_json; |
| 4861 | |
| 4862 | }; |
| 4863 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4864 | class CommandObjectProcessGDBRemotePacketHistory : public CommandObjectParsed |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 4865 | { |
| 4866 | private: |
| 4867 | |
| 4868 | public: |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4869 | CommandObjectProcessGDBRemotePacketHistory(CommandInterpreter &interpreter) : |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 4870 | CommandObjectParsed (interpreter, |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4871 | "process plugin packet history", |
| 4872 | "Dumps the packet history buffer. ", |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 4873 | NULL) |
| 4874 | { |
| 4875 | } |
| 4876 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4877 | ~CommandObjectProcessGDBRemotePacketHistory () |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 4878 | { |
| 4879 | } |
| 4880 | |
| 4881 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 4882 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 4883 | { |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4884 | const size_t argc = command.GetArgumentCount(); |
| 4885 | if (argc == 0) |
| 4886 | { |
| 4887 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 4888 | if (process) |
| 4889 | { |
| 4890 | process->GetGDBRemote().DumpHistory(result.GetOutputStream()); |
| 4891 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4892 | return true; |
| 4893 | } |
| 4894 | } |
| 4895 | else |
| 4896 | { |
| 4897 | result.AppendErrorWithFormat ("'%s' takes no arguments", m_cmd_name.c_str()); |
| 4898 | } |
| 4899 | result.SetStatus (eReturnStatusFailed); |
| 4900 | return false; |
| 4901 | } |
| 4902 | }; |
| 4903 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4904 | class CommandObjectProcessGDBRemotePacketXferSize : public CommandObjectParsed |
| 4905 | { |
| 4906 | private: |
| 4907 | |
| 4908 | public: |
| 4909 | CommandObjectProcessGDBRemotePacketXferSize(CommandInterpreter &interpreter) : |
| 4910 | CommandObjectParsed (interpreter, |
| 4911 | "process plugin packet xfer-size", |
| 4912 | "Maximum size that lldb will try to read/write one one chunk.", |
| 4913 | NULL) |
| 4914 | { |
| 4915 | } |
| 4916 | |
| 4917 | ~CommandObjectProcessGDBRemotePacketXferSize () |
| 4918 | { |
| 4919 | } |
| 4920 | |
| 4921 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 4922 | DoExecute (Args& command, CommandReturnObject &result) override |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4923 | { |
| 4924 | const size_t argc = command.GetArgumentCount(); |
| 4925 | if (argc == 0) |
| 4926 | { |
| 4927 | result.AppendErrorWithFormat ("'%s' takes an argument to specify the max amount to be transferred when reading/writing", m_cmd_name.c_str()); |
| 4928 | result.SetStatus (eReturnStatusFailed); |
| 4929 | return false; |
| 4930 | } |
| 4931 | |
| 4932 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 4933 | if (process) |
| 4934 | { |
| 4935 | const char *packet_size = command.GetArgumentAtIndex(0); |
| 4936 | errno = 0; |
| 4937 | uint64_t user_specified_max = strtoul (packet_size, NULL, 10); |
| 4938 | if (errno == 0 && user_specified_max != 0) |
| 4939 | { |
| 4940 | process->SetUserSpecifiedMaxMemoryTransferSize (user_specified_max); |
| 4941 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4942 | return true; |
| 4943 | } |
| 4944 | } |
| 4945 | result.SetStatus (eReturnStatusFailed); |
| 4946 | return false; |
| 4947 | } |
| 4948 | }; |
| 4949 | |
| 4950 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4951 | class CommandObjectProcessGDBRemotePacketSend : public CommandObjectParsed |
| 4952 | { |
| 4953 | private: |
| 4954 | |
| 4955 | public: |
| 4956 | CommandObjectProcessGDBRemotePacketSend(CommandInterpreter &interpreter) : |
| 4957 | CommandObjectParsed (interpreter, |
| 4958 | "process plugin packet send", |
| 4959 | "Send a custom packet through the GDB remote protocol and print the answer. " |
| 4960 | "The packet header and footer will automatically be added to the packet prior to sending and stripped from the result.", |
| 4961 | NULL) |
| 4962 | { |
| 4963 | } |
| 4964 | |
| 4965 | ~CommandObjectProcessGDBRemotePacketSend () |
| 4966 | { |
| 4967 | } |
| 4968 | |
| 4969 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 4970 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4971 | { |
| 4972 | const size_t argc = command.GetArgumentCount(); |
| 4973 | if (argc == 0) |
| 4974 | { |
| 4975 | result.AppendErrorWithFormat ("'%s' takes a one or more packet content arguments", m_cmd_name.c_str()); |
| 4976 | result.SetStatus (eReturnStatusFailed); |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
| 4980 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 4981 | if (process) |
| 4982 | { |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 4983 | for (size_t i=0; i<argc; ++ i) |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 4984 | { |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 4985 | const char *packet_cstr = command.GetArgumentAtIndex(0); |
| 4986 | bool send_async = true; |
| 4987 | StringExtractorGDBRemote response; |
| 4988 | process->GetGDBRemote().SendPacketAndWaitForResponse(packet_cstr, response, send_async); |
| 4989 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4990 | Stream &output_strm = result.GetOutputStream(); |
| 4991 | output_strm.Printf (" packet: %s\n", packet_cstr); |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 4992 | std::string &response_str = response.GetStringRef(); |
| 4993 | |
Han Ming Ong | 399289e | 2013-06-21 19:56:59 +0000 | [diff] [blame] | 4994 | if (strstr(packet_cstr, "qGetProfileData") != NULL) |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 4995 | { |
| 4996 | response_str = process->GetGDBRemote().HarmonizeThreadIdsForProfileData(process, response); |
| 4997 | } |
| 4998 | |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 4999 | if (response_str.empty()) |
| 5000 | output_strm.PutCString ("response: \nerror: UNIMPLEMENTED\n"); |
| 5001 | else |
| 5002 | output_strm.Printf ("response: %s\n", response.GetStringRef().c_str()); |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5003 | } |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5004 | } |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5005 | return true; |
| 5006 | } |
| 5007 | }; |
| 5008 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5009 | class CommandObjectProcessGDBRemotePacketMonitor : public CommandObjectRaw |
| 5010 | { |
| 5011 | private: |
| 5012 | |
| 5013 | public: |
| 5014 | CommandObjectProcessGDBRemotePacketMonitor(CommandInterpreter &interpreter) : |
| 5015 | CommandObjectRaw (interpreter, |
| 5016 | "process plugin packet monitor", |
Greg Clayton | eee5e98 | 2013-02-14 18:39:30 +0000 | [diff] [blame] | 5017 | "Send a qRcmd packet through the GDB remote protocol and print the response." |
| 5018 | "The argument passed to this command will be hex encoded into a valid 'qRcmd' packet, sent and the response will be printed.", |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5019 | NULL) |
| 5020 | { |
| 5021 | } |
| 5022 | |
| 5023 | ~CommandObjectProcessGDBRemotePacketMonitor () |
| 5024 | { |
| 5025 | } |
| 5026 | |
| 5027 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 5028 | DoExecute (const char *command, CommandReturnObject &result) override |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5029 | { |
| 5030 | if (command == NULL || command[0] == '\0') |
| 5031 | { |
| 5032 | result.AppendErrorWithFormat ("'%s' takes a command string argument", m_cmd_name.c_str()); |
| 5033 | result.SetStatus (eReturnStatusFailed); |
| 5034 | return false; |
| 5035 | } |
| 5036 | |
| 5037 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5038 | if (process) |
| 5039 | { |
| 5040 | StreamString packet; |
Greg Clayton | eee5e98 | 2013-02-14 18:39:30 +0000 | [diff] [blame] | 5041 | packet.PutCString("qRcmd,"); |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5042 | packet.PutBytesAsRawHex8(command, strlen(command)); |
| 5043 | const char *packet_cstr = packet.GetString().c_str(); |
| 5044 | |
| 5045 | bool send_async = true; |
| 5046 | StringExtractorGDBRemote response; |
| 5047 | process->GetGDBRemote().SendPacketAndWaitForResponse(packet_cstr, response, send_async); |
| 5048 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5049 | Stream &output_strm = result.GetOutputStream(); |
| 5050 | output_strm.Printf (" packet: %s\n", packet_cstr); |
| 5051 | const std::string &response_str = response.GetStringRef(); |
| 5052 | |
| 5053 | if (response_str.empty()) |
| 5054 | output_strm.PutCString ("response: \nerror: UNIMPLEMENTED\n"); |
| 5055 | else |
| 5056 | output_strm.Printf ("response: %s\n", response.GetStringRef().c_str()); |
| 5057 | } |
| 5058 | return true; |
| 5059 | } |
| 5060 | }; |
| 5061 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5062 | class CommandObjectProcessGDBRemotePacket : public CommandObjectMultiword |
| 5063 | { |
| 5064 | private: |
| 5065 | |
| 5066 | public: |
| 5067 | CommandObjectProcessGDBRemotePacket(CommandInterpreter &interpreter) : |
| 5068 | CommandObjectMultiword (interpreter, |
| 5069 | "process plugin packet", |
| 5070 | "Commands that deal with GDB remote packets.", |
| 5071 | NULL) |
| 5072 | { |
| 5073 | LoadSubCommand ("history", CommandObjectSP (new CommandObjectProcessGDBRemotePacketHistory (interpreter))); |
| 5074 | LoadSubCommand ("send", CommandObjectSP (new CommandObjectProcessGDBRemotePacketSend (interpreter))); |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5075 | LoadSubCommand ("monitor", CommandObjectSP (new CommandObjectProcessGDBRemotePacketMonitor (interpreter))); |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5076 | LoadSubCommand ("xfer-size", CommandObjectSP (new CommandObjectProcessGDBRemotePacketXferSize (interpreter))); |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5077 | LoadSubCommand ("speed-test", CommandObjectSP (new CommandObjectProcessGDBRemoteSpeedTest (interpreter))); |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | ~CommandObjectProcessGDBRemotePacket () |
| 5081 | { |
| 5082 | } |
| 5083 | }; |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5084 | |
| 5085 | class CommandObjectMultiwordProcessGDBRemote : public CommandObjectMultiword |
| 5086 | { |
| 5087 | public: |
| 5088 | CommandObjectMultiwordProcessGDBRemote (CommandInterpreter &interpreter) : |
| 5089 | CommandObjectMultiword (interpreter, |
| 5090 | "process plugin", |
| 5091 | "A set of commands for operating on a ProcessGDBRemote process.", |
| 5092 | "process plugin <subcommand> [<subcommand-options>]") |
| 5093 | { |
| 5094 | LoadSubCommand ("packet", CommandObjectSP (new CommandObjectProcessGDBRemotePacket (interpreter))); |
| 5095 | } |
| 5096 | |
| 5097 | ~CommandObjectMultiwordProcessGDBRemote () |
| 5098 | { |
| 5099 | } |
| 5100 | }; |
| 5101 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5102 | CommandObject * |
| 5103 | ProcessGDBRemote::GetPluginCommandObject() |
| 5104 | { |
| 5105 | if (!m_command_sp) |
| 5106 | m_command_sp.reset (new CommandObjectMultiwordProcessGDBRemote (GetTarget().GetDebugger().GetCommandInterpreter())); |
| 5107 | return m_command_sp.get(); |
| 5108 | } |