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