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 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 10 | #include "lldb/Host/Config.h" |
| 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 |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 18 | #include <sys/socket.h> |
Zachary Turner | bd22bf2 | 2016-08-12 16:52:31 +0000 | [diff] [blame] | 19 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include <sys/stat.h> |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 21 | #include <sys/types.h> |
Stephen Wilson | dc91686 | 2011-03-30 00:12:40 +0000 | [diff] [blame] | 22 | #include <time.h> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | // C++ Includes |
| 25 | #include <algorithm> |
| 26 | #include <map> |
Benjamin Kramer | 3f69fa6 | 2015-04-03 10:55:00 +0000 | [diff] [blame] | 27 | #include <mutex> |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 28 | #include <sstream> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 30 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 31 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Core/ArchSpec.h" |
| 33 | #include "lldb/Core/Debugger.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 34 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 35 | #include "lldb/Host/FileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Core/Module.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 37 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | #include "lldb/Core/PluginManager.h" |
| 39 | #include "lldb/Core/State.h" |
Greg Clayton | d451c1a | 2012-04-13 21:24:18 +0000 | [diff] [blame] | 40 | #include "lldb/Core/StreamFile.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Core/StreamString.h" |
| 42 | #include "lldb/Core/Timer.h" |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 43 | #include "lldb/Core/Value.h" |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 44 | #include "lldb/DataFormatters/FormatManager.h" |
Zachary Turner | 4eff2d3 | 2015-10-14 21:37:36 +0000 | [diff] [blame] | 45 | #include "lldb/Host/FileSystem.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 46 | #include "lldb/Host/HostThread.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 47 | #include "lldb/Host/StringConvert.h" |
Jason Molenda | d1fae14 | 2012-09-29 08:03:33 +0000 | [diff] [blame] | 48 | #include "lldb/Host/Symbols.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 49 | #include "lldb/Host/ThreadLauncher.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #include "lldb/Host/TimeValue.h" |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 51 | #include "lldb/Host/XML.h" |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 52 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | 1d19a2f | 2012-10-19 22:22:57 +0000 | [diff] [blame] | 53 | #include "lldb/Interpreter/CommandObject.h" |
| 54 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 55 | #include "lldb/Interpreter/CommandReturnObject.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 56 | #include "lldb/Interpreter/OptionValueProperties.h" |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 57 | #include "lldb/Interpreter/Options.h" |
| 58 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
| 59 | #include "lldb/Interpreter/OptionGroupUInt64.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 60 | #include "lldb/Interpreter/Property.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "lldb/Symbol/ObjectFile.h" |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 62 | #include "lldb/Target/ABI.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | #include "lldb/Target/DynamicLoader.h" |
| 64 | #include "lldb/Target/Target.h" |
| 65 | #include "lldb/Target/TargetList.h" |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 66 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 67 | #include "lldb/Target/SystemRuntime.h" |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 68 | #include "lldb/Utility/CleanUp.h" |
Jason Molenda | a34a0c6 | 2010-06-09 21:28:42 +0000 | [diff] [blame] | 69 | #include "lldb/Utility/PseudoTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 71 | // Project includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | #include "lldb/Host/Host.h" |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 73 | #include "Plugins/Process/Utility/GDBRemoteSignals.h" |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 74 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
Jason Molenda | c42d243 | 2012-07-25 03:40:06 +0000 | [diff] [blame] | 75 | #include "Plugins/Process/Utility/StopInfoMachException.h" |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 76 | #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 77 | #include "Utility/StringExtractorGDBRemote.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | #include "GDBRemoteRegisterContext.h" |
| 79 | #include "ProcessGDBRemote.h" |
| 80 | #include "ProcessGDBRemoteLog.h" |
| 81 | #include "ThreadGDBRemote.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 82 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 83 | #define DEBUGSERVER_BASENAME "debugserver" |
| 84 | using namespace lldb; |
| 85 | using namespace lldb_private; |
| 86 | using namespace lldb_private::process_gdb_remote; |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 87 | |
Greg Clayton | c1422c1 | 2012-04-09 22:46:21 +0000 | [diff] [blame] | 88 | namespace lldb |
| 89 | { |
| 90 | // Provide a function that can easily dump the packet history if we know a |
| 91 | // ProcessGDBRemote * value (which we can get from logs or from debugging). |
| 92 | // We need the function in the lldb namespace so it makes it into the final |
| 93 | // executable since the LLDB shared library only exports stuff in the lldb |
| 94 | // namespace. This allows you to attach with a debugger and call this |
| 95 | // function and get the packet history dumped to a file. |
| 96 | void |
| 97 | DumpProcessGDBRemotePacketHistory (void *p, const char *path) |
| 98 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 99 | StreamFile strm; |
| 100 | Error error (strm.GetFile().Open(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate)); |
Greg Clayton | d451c1a | 2012-04-13 21:24:18 +0000 | [diff] [blame] | 101 | if (error.Success()) |
| 102 | ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory (strm); |
Greg Clayton | c1422c1 | 2012-04-09 22:46:21 +0000 | [diff] [blame] | 103 | } |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 104 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 106 | namespace { |
Steve Pucci | 5ec012d | 2014-01-16 22:18:14 +0000 | [diff] [blame] | 107 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 108 | static PropertyDefinition |
| 109 | g_properties[] = |
| 110 | { |
| 111 | { "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] | 112 | { "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] | 113 | { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } |
| 114 | }; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 115 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 116 | enum |
| 117 | { |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 118 | ePropertyPacketTimeout, |
| 119 | ePropertyTargetDefinitionFile |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 120 | }; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 121 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 122 | class PluginProperties : public Properties |
| 123 | { |
| 124 | public: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 125 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 126 | static ConstString |
| 127 | GetSettingName () |
| 128 | { |
| 129 | return ProcessGDBRemote::GetPluginNameStatic(); |
| 130 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 131 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 132 | PluginProperties() : |
| 133 | Properties () |
| 134 | { |
| 135 | m_collection_sp.reset (new OptionValueProperties(GetSettingName())); |
| 136 | m_collection_sp->Initialize(g_properties); |
| 137 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 138 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 139 | virtual |
| 140 | ~PluginProperties() |
| 141 | { |
| 142 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 143 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 144 | uint64_t |
| 145 | GetPacketTimeout() |
| 146 | { |
| 147 | const uint32_t idx = ePropertyPacketTimeout; |
| 148 | return m_collection_sp->GetPropertyAtIndexAsUInt64(NULL, idx, g_properties[idx].default_uint_value); |
| 149 | } |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 150 | |
| 151 | bool |
| 152 | SetPacketTimeout(uint64_t timeout) |
| 153 | { |
| 154 | const uint32_t idx = ePropertyPacketTimeout; |
| 155 | return m_collection_sp->SetPropertyAtIndexAsUInt64(NULL, idx, timeout); |
| 156 | } |
| 157 | |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 158 | FileSpec |
| 159 | GetTargetDefinitionFile () const |
| 160 | { |
| 161 | const uint32_t idx = ePropertyTargetDefinitionFile; |
| 162 | return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); |
| 163 | } |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 164 | }; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 165 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 166 | typedef std::shared_ptr<PluginProperties> ProcessKDPPropertiesSP; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 167 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 168 | static const ProcessKDPPropertiesSP & |
| 169 | GetGlobalPluginProperties() |
| 170 | { |
| 171 | static ProcessKDPPropertiesSP g_settings_sp; |
| 172 | if (!g_settings_sp) |
| 173 | g_settings_sp.reset (new PluginProperties ()); |
| 174 | return g_settings_sp; |
| 175 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 176 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 177 | } // anonymous namespace end |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 178 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 179 | // TODO Randomly assigning a port is unsafe. We should get an unused |
| 180 | // ephemeral port from the kernel and make sure we reserve it before passing |
| 181 | // it to debugserver. |
| 182 | |
| 183 | #if defined (__APPLE__) |
| 184 | #define LOW_PORT (IPPORT_RESERVED) |
| 185 | #define HIGH_PORT (IPPORT_HIFIRSTAUTO) |
| 186 | #else |
| 187 | #define LOW_PORT (1024u) |
| 188 | #define HIGH_PORT (49151u) |
| 189 | #endif |
| 190 | |
Todd Fiala | 013434e | 2014-07-09 01:29:05 +0000 | [diff] [blame] | 191 | #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 192 | static bool rand_initialized = false; |
| 193 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 194 | static inline uint16_t |
| 195 | get_random_port () |
| 196 | { |
| 197 | if (!rand_initialized) |
| 198 | { |
| 199 | time_t seed = time(NULL); |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 200 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 201 | rand_initialized = true; |
| 202 | srand(seed); |
| 203 | } |
| 204 | return (rand() % (HIGH_PORT - LOW_PORT)) + LOW_PORT; |
| 205 | } |
Saleem Abdulrasool | a68f7b6 | 2014-03-20 06:08:36 +0000 | [diff] [blame] | 206 | #endif |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 207 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 208 | ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | ProcessGDBRemote::GetPluginNameStatic() |
| 210 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 211 | static ConstString g_name("gdb-remote"); |
| 212 | return g_name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | const char * |
| 216 | ProcessGDBRemote::GetPluginDescriptionStatic() |
| 217 | { |
| 218 | return "GDB Remote protocol based debugging plug-in."; |
| 219 | } |
| 220 | |
| 221 | void |
| 222 | ProcessGDBRemote::Terminate() |
| 223 | { |
| 224 | PluginManager::UnregisterPlugin (ProcessGDBRemote::CreateInstance); |
| 225 | } |
| 226 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 227 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 228 | lldb::ProcessSP |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 229 | ProcessGDBRemote::CreateInstance (lldb::TargetSP target_sp, ListenerSP listener_sp, const FileSpec *crash_file_path) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 231 | lldb::ProcessSP process_sp; |
| 232 | if (crash_file_path == NULL) |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 233 | process_sp.reset (new ProcessGDBRemote (target_sp, listener_sp)); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 234 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | bool |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 238 | ProcessGDBRemote::CanDebug (lldb::TargetSP target_sp, bool plugin_specified_by_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | { |
Greg Clayton | 596ed24 | 2011-10-21 21:41:45 +0000 | [diff] [blame] | 240 | if (plugin_specified_by_name) |
| 241 | return true; |
| 242 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | // For now we are just making sure the file exists for a given module |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 244 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 245 | if (exe_module) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 246 | { |
| 247 | ObjectFile *exe_objfile = exe_module->GetObjectFile(); |
| 248 | // We can't debug core files... |
| 249 | switch (exe_objfile->GetType()) |
| 250 | { |
| 251 | case ObjectFile::eTypeInvalid: |
| 252 | case ObjectFile::eTypeCoreFile: |
| 253 | case ObjectFile::eTypeDebugInfo: |
| 254 | case ObjectFile::eTypeObjectFile: |
| 255 | case ObjectFile::eTypeSharedLibrary: |
| 256 | case ObjectFile::eTypeStubLibrary: |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 257 | case ObjectFile::eTypeJIT: |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 258 | return false; |
| 259 | case ObjectFile::eTypeExecutable: |
| 260 | case ObjectFile::eTypeDynamicLinker: |
| 261 | case ObjectFile::eTypeUnknown: |
| 262 | break; |
| 263 | } |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 264 | return exe_module->GetFileSpec().Exists(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 265 | } |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 266 | // However, if there is no executable module, we return true since we might be preparing to attach. |
| 267 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 270 | //---------------------------------------------------------------------- |
| 271 | // ProcessGDBRemote constructor |
| 272 | //---------------------------------------------------------------------- |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 273 | ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, ListenerSP listener_sp) |
| 274 | : Process(target_sp, listener_sp), |
| 275 | m_flags(0), |
| 276 | m_gdb_comm(), |
| 277 | m_debugserver_pid(LLDB_INVALID_PROCESS_ID), |
| 278 | m_last_stop_packet_mutex(), |
| 279 | m_register_info(), |
| 280 | m_async_broadcaster(NULL, "lldb.process.gdb-remote.async-broadcaster"), |
| 281 | m_async_listener_sp(Listener::MakeListener("lldb.process.gdb-remote.async-listener")), |
| 282 | m_async_thread_state_mutex(), |
| 283 | m_thread_ids(), |
| 284 | m_thread_pcs(), |
| 285 | m_jstopinfo_sp(), |
| 286 | m_jthreadsinfo_sp(), |
| 287 | m_continue_c_tids(), |
| 288 | m_continue_C_tids(), |
| 289 | m_continue_s_tids(), |
| 290 | m_continue_S_tids(), |
| 291 | m_max_memory_size(0), |
| 292 | m_remote_stub_max_memory_size(0), |
| 293 | m_addr_to_mmap_size(), |
| 294 | m_thread_create_bp_sp(), |
| 295 | m_waiting_for_attach(false), |
| 296 | m_destroy_tried_resuming(false), |
| 297 | m_command_sp(), |
| 298 | m_breakpoint_pc_offset(0), |
| 299 | m_initial_tid(LLDB_INVALID_THREAD_ID) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 301 | m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); |
| 302 | m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue, "async thread continue"); |
| 303 | m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadDidExit, "async thread did exit"); |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 304 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 305 | Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_ASYNC)); |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 306 | |
| 307 | const uint32_t async_event_mask = eBroadcastBitAsyncContinue | eBroadcastBitAsyncThreadShouldExit; |
| 308 | |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 309 | if (m_async_listener_sp->StartListeningForEvents(&m_async_broadcaster, async_event_mask) != async_event_mask) |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 310 | { |
| 311 | if (log) |
| 312 | log->Printf("ProcessGDBRemote::%s failed to listen for m_async_broadcaster events", __FUNCTION__); |
| 313 | } |
| 314 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 315 | const uint32_t gdb_event_mask = |
| 316 | Communication::eBroadcastBitReadThreadDidExit | GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify; |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 317 | if (m_async_listener_sp->StartListeningForEvents(&m_gdb_comm, gdb_event_mask) != gdb_event_mask) |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 318 | { |
| 319 | if (log) |
| 320 | log->Printf("ProcessGDBRemote::%s failed to listen for m_gdb_comm events", __FUNCTION__); |
| 321 | } |
| 322 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 323 | const uint64_t timeout_seconds = GetGlobalPluginProperties()->GetPacketTimeout(); |
| 324 | if (timeout_seconds > 0) |
| 325 | m_gdb_comm.SetPacketTimeout(timeout_seconds); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 328 | //---------------------------------------------------------------------- |
| 329 | // Destructor |
| 330 | //---------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 331 | ProcessGDBRemote::~ProcessGDBRemote() |
| 332 | { |
| 333 | // m_mach_process.UnregisterNotificationCallbacks (this); |
| 334 | Clear(); |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 335 | // We need to call finalize on the process before destroying ourselves |
| 336 | // to make sure all of the broadcaster cleanup goes as planned. If we |
| 337 | // destruct this class, then Process::~Process() might have problems |
| 338 | // trying to fully destroy the broadcaster. |
| 339 | Finalize(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 340 | |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 341 | // The general Finalize is going to try to destroy the process and that SHOULD |
| 342 | // shut down the async thread. However, if we don't kill it it will get stranded and |
| 343 | // its connection will go away so when it wakes up it will crash. So kill it for sure here. |
| 344 | StopAsyncThread(); |
| 345 | KillDebugserverProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | //---------------------------------------------------------------------- |
| 349 | // PluginInterface |
| 350 | //---------------------------------------------------------------------- |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 351 | ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | ProcessGDBRemote::GetPluginName() |
| 353 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | return GetPluginNameStatic(); |
| 355 | } |
| 356 | |
| 357 | uint32_t |
| 358 | ProcessGDBRemote::GetPluginVersion() |
| 359 | { |
| 360 | return 1; |
| 361 | } |
| 362 | |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 363 | bool |
| 364 | ProcessGDBRemote::ParsePythonTargetDefinition(const FileSpec &target_definition_fspec) |
| 365 | { |
| 366 | ScriptInterpreter *interpreter = GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
| 367 | Error error; |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 368 | StructuredData::ObjectSP module_object_sp(interpreter->LoadPluginModule(target_definition_fspec, error)); |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 369 | if (module_object_sp) |
| 370 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 371 | StructuredData::DictionarySP target_definition_sp( |
| 372 | interpreter->GetDynamicSettings(module_object_sp, &GetTarget(), "gdb-server-target-definition", error)); |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 373 | |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 374 | if (target_definition_sp) |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 375 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 376 | StructuredData::ObjectSP target_object(target_definition_sp->GetValueForKey("host-info")); |
| 377 | if (target_object) |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 378 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 379 | if (auto host_info_dict = target_object->GetAsDictionary()) |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 380 | { |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 381 | StructuredData::ObjectSP triple_value = host_info_dict->GetValueForKey("triple"); |
| 382 | if (auto triple_string_value = triple_value->GetAsString()) |
| 383 | { |
| 384 | std::string triple_string = triple_string_value->GetValue(); |
| 385 | ArchSpec host_arch(triple_string.c_str()); |
| 386 | if (!host_arch.IsCompatibleMatch(GetTarget().GetArchitecture())) |
| 387 | { |
| 388 | GetTarget().SetArchitecture(host_arch); |
| 389 | } |
| 390 | } |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 391 | } |
Greg Clayton | 312bcbe | 2013-10-17 01:10:23 +0000 | [diff] [blame] | 392 | } |
Zachary Turner | 0641ca1 | 2015-03-17 20:04:04 +0000 | [diff] [blame] | 393 | m_breakpoint_pc_offset = 0; |
| 394 | StructuredData::ObjectSP breakpoint_pc_offset_value = target_definition_sp->GetValueForKey("breakpoint-pc-offset"); |
| 395 | if (breakpoint_pc_offset_value) |
| 396 | { |
| 397 | if (auto breakpoint_pc_int_value = breakpoint_pc_offset_value->GetAsInteger()) |
| 398 | m_breakpoint_pc_offset = breakpoint_pc_int_value->GetValue(); |
| 399 | } |
Hafiz Abid Qadeer | 85a4daf | 2013-10-18 10:04:33 +0000 | [diff] [blame] | 400 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 401 | if (m_register_info.SetRegisterInfo(*target_definition_sp, GetTarget().GetArchitecture()) > 0) |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 402 | { |
| 403 | return true; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | return false; |
| 408 | } |
| 409 | |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 410 | // If the remote stub didn't give us eh_frame or DWARF register numbers for a register, |
| 411 | // see if the ABI can provide them. |
| 412 | // DWARF and eh_frame register numbers are defined as a part of the ABI. |
| 413 | static void |
| 414 | AugmentRegisterInfoViaABI (RegisterInfo ®_info, ConstString reg_name, ABISP abi_sp) |
| 415 | { |
| 416 | if (reg_info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM |
| 417 | || reg_info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) |
| 418 | { |
| 419 | if (abi_sp) |
| 420 | { |
| 421 | RegisterInfo abi_reg_info; |
| 422 | if (abi_sp->GetRegisterInfoByName (reg_name, abi_reg_info)) |
| 423 | { |
Greg Clayton | b1583dc | 2015-12-04 18:37:48 +0000 | [diff] [blame] | 424 | if (reg_info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM && |
| 425 | abi_reg_info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM) |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 426 | { |
| 427 | reg_info.kinds[eRegisterKindEHFrame] = abi_reg_info.kinds[eRegisterKindEHFrame]; |
| 428 | } |
Greg Clayton | b1583dc | 2015-12-04 18:37:48 +0000 | [diff] [blame] | 429 | if (reg_info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM && |
| 430 | abi_reg_info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM) |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 431 | { |
| 432 | reg_info.kinds[eRegisterKindDWARF] = abi_reg_info.kinds[eRegisterKindDWARF]; |
| 433 | } |
Greg Clayton | b1583dc | 2015-12-04 18:37:48 +0000 | [diff] [blame] | 434 | if (reg_info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM && |
| 435 | abi_reg_info.kinds[eRegisterKindGeneric] != LLDB_INVALID_REGNUM) |
| 436 | { |
| 437 | reg_info.kinds[eRegisterKindGeneric] = abi_reg_info.kinds[eRegisterKindGeneric]; |
| 438 | } |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 444 | static size_t |
| 445 | SplitCommaSeparatedRegisterNumberString(const llvm::StringRef &comma_separated_regiter_numbers, std::vector<uint32_t> ®nums, int base) |
| 446 | { |
| 447 | regnums.clear(); |
| 448 | std::pair<llvm::StringRef, llvm::StringRef> value_pair; |
| 449 | value_pair.second = comma_separated_regiter_numbers; |
| 450 | do |
| 451 | { |
| 452 | value_pair = value_pair.second.split(','); |
| 453 | if (!value_pair.first.empty()) |
| 454 | { |
| 455 | uint32_t reg = StringConvert::ToUInt32 (value_pair.first.str().c_str(), LLDB_INVALID_REGNUM, base); |
| 456 | if (reg != LLDB_INVALID_REGNUM) |
| 457 | regnums.push_back (reg); |
| 458 | } |
| 459 | } while (!value_pair.second.empty()); |
| 460 | return regnums.size(); |
| 461 | } |
| 462 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 463 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | void |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 465 | ProcessGDBRemote::BuildDynamicRegisterInfo (bool force) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 467 | if (!force && m_register_info.GetNumRegisters() > 0) |
| 468 | return; |
| 469 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | m_register_info.Clear(); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 471 | |
| 472 | // Check if qHostInfo specified a specific packet timeout for this connection. |
| 473 | // If so then lets update our setting so the user knows what the timeout is |
| 474 | // and can see it. |
| 475 | const uint32_t host_packet_timeout = m_gdb_comm.GetHostDefaultPacketTimeout(); |
| 476 | if (host_packet_timeout) |
| 477 | { |
| 478 | GetGlobalPluginProperties()->SetPacketTimeout(host_packet_timeout); |
| 479 | } |
| 480 | |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 481 | // Register info search order: |
Ewan Crawford | 0c996a9 | 2015-06-30 13:08:44 +0000 | [diff] [blame] | 482 | // 1 - Use the target definition python file if one is specified. |
| 483 | // 2 - If the target definition doesn't have any of the info from the target.xml (registers) then proceed to read the target.xml. |
| 484 | // 3 - Fall back on the qRegisterInfo packets. |
| 485 | |
| 486 | FileSpec target_definition_fspec = GetGlobalPluginProperties()->GetTargetDefinitionFile (); |
Jason Molenda | 91e468c | 2015-08-20 04:29:46 +0000 | [diff] [blame] | 487 | if (!target_definition_fspec.Exists()) |
| 488 | { |
| 489 | // If the filename doesn't exist, it may be a ~ not having been expanded - try to resolve it. |
| 490 | target_definition_fspec.ResolvePath(); |
| 491 | } |
Ewan Crawford | 0c996a9 | 2015-06-30 13:08:44 +0000 | [diff] [blame] | 492 | if (target_definition_fspec) |
| 493 | { |
| 494 | // See if we can get register definitions from a python file |
| 495 | if (ParsePythonTargetDefinition (target_definition_fspec)) |
Jason Molenda | 5543abb | 2015-08-20 03:05:09 +0000 | [diff] [blame] | 496 | { |
Ewan Crawford | 0c996a9 | 2015-06-30 13:08:44 +0000 | [diff] [blame] | 497 | return; |
Jason Molenda | 5543abb | 2015-08-20 03:05:09 +0000 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
| 501 | StreamSP stream_sp = GetTarget().GetDebugger().GetAsyncOutputStream(); |
| 502 | stream_sp->Printf ("ERROR: target description file %s failed to parse.\n", target_definition_fspec.GetPath().c_str()); |
| 503 | } |
Ewan Crawford | 0c996a9 | 2015-06-30 13:08:44 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 506 | const ArchSpec &target_arch = GetTarget().GetArchitecture(); |
| 507 | const ArchSpec &remote_host_arch = m_gdb_comm.GetHostArchitecture(); |
| 508 | const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 509 | |
| 510 | // Use the process' architecture instead of the host arch, if available |
| 511 | ArchSpec arch_to_use; |
| 512 | if (remote_process_arch.IsValid ()) |
| 513 | arch_to_use = remote_process_arch; |
| 514 | else |
| 515 | arch_to_use = remote_host_arch; |
| 516 | |
| 517 | if (!arch_to_use.IsValid()) |
| 518 | arch_to_use = target_arch; |
| 519 | |
| 520 | if (GetGDBServerRegisterInfo (arch_to_use)) |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 521 | return; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 522 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 523 | char packet[128]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 524 | uint32_t reg_offset = 0; |
| 525 | uint32_t reg_num = 0; |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 526 | for (StringExtractorGDBRemote::ResponseType response_type = StringExtractorGDBRemote::eResponse; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 527 | response_type == StringExtractorGDBRemote::eResponse; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 528 | ++reg_num) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 530 | const int packet_len = ::snprintf (packet, sizeof(packet), "qRegisterInfo%x", reg_num); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 531 | assert (packet_len < (int)sizeof(packet)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 532 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 533 | 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] | 534 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 535 | response_type = response.GetResponseType(); |
| 536 | if (response_type == StringExtractorGDBRemote::eResponse) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 537 | { |
| 538 | std::string name; |
| 539 | std::string value; |
| 540 | ConstString reg_name; |
| 541 | ConstString alt_name; |
| 542 | ConstString set_name; |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 543 | std::vector<uint32_t> value_regs; |
| 544 | std::vector<uint32_t> invalidate_regs; |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 545 | std::vector<uint8_t> dwarf_opcode_bytes; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | RegisterInfo reg_info = { NULL, // Name |
| 547 | NULL, // Alt name |
| 548 | 0, // byte size |
| 549 | reg_offset, // offset |
| 550 | eEncodingUint, // encoding |
Jason Molenda | bf67a30 | 2015-09-01 05:17:01 +0000 | [diff] [blame] | 551 | eFormatHex, // format |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 552 | { |
Jason Molenda | bf67a30 | 2015-09-01 05:17:01 +0000 | [diff] [blame] | 553 | LLDB_INVALID_REGNUM, // eh_frame reg num |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 554 | LLDB_INVALID_REGNUM, // DWARF reg num |
| 555 | LLDB_INVALID_REGNUM, // generic reg num |
Jason Molenda | 63bd0db | 2015-09-15 23:20:34 +0000 | [diff] [blame] | 556 | reg_num, // process plugin reg num |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 557 | reg_num // native register number |
Greg Clayton | 435d85a | 2012-02-29 19:27:27 +0000 | [diff] [blame] | 558 | }, |
| 559 | NULL, |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 560 | NULL, |
| 561 | NULL, // Dwarf expression opcode bytes pointer |
| 562 | 0 // Dwarf expression opcode bytes length |
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 | } |
Jason Molenda | a18f707 | 2015-08-15 01:21:01 +0000 | [diff] [blame] | 627 | else if (name.compare("gcc") == 0 || name.compare("ehframe") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 628 | { |
Jason Molenda | a18f707 | 2015-08-15 01:21:01 +0000 | [diff] [blame] | 629 | reg_info.kinds[eRegisterKindEHFrame] = 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 | } |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 647 | else if (name.compare("dynamic_size_dwarf_expr_bytes") == 0) |
| 648 | { |
| 649 | size_t dwarf_opcode_len = value.length () / 2; |
| 650 | assert (dwarf_opcode_len > 0); |
| 651 | |
| 652 | dwarf_opcode_bytes.resize (dwarf_opcode_len); |
| 653 | StringExtractor opcode_extractor; |
| 654 | reg_info.dynamic_size_dwarf_len = dwarf_opcode_len; |
| 655 | |
| 656 | // Swap "value" over into "opcode_extractor" |
| 657 | opcode_extractor.GetStringRef ().swap (value); |
| 658 | uint32_t ret_val = opcode_extractor.GetHexBytesAvail (dwarf_opcode_bytes.data (), |
| 659 | dwarf_opcode_len); |
| 660 | assert (dwarf_opcode_len == ret_val); |
| 661 | |
| 662 | reg_info.dynamic_size_dwarf_expr_bytes = dwarf_opcode_bytes.data (); |
| 663 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Jason Molenda | 743e86a | 2010-06-11 23:44:18 +0000 | [diff] [blame] | 666 | reg_info.byte_offset = reg_offset; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 667 | assert (reg_info.byte_size != 0); |
| 668 | reg_offset += reg_info.byte_size; |
Greg Clayton | ce1ffcf | 2013-01-21 22:17:50 +0000 | [diff] [blame] | 669 | if (!value_regs.empty()) |
| 670 | { |
| 671 | value_regs.push_back(LLDB_INVALID_REGNUM); |
| 672 | reg_info.value_regs = value_regs.data(); |
| 673 | } |
| 674 | if (!invalidate_regs.empty()) |
| 675 | { |
| 676 | invalidate_regs.push_back(LLDB_INVALID_REGNUM); |
| 677 | reg_info.invalidate_regs = invalidate_regs.data(); |
| 678 | } |
| 679 | |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 680 | // We have to make a temporary ABI here, and not use the GetABI because this code |
| 681 | // gets called in DidAttach, when the target architecture (and consequently the ABI we'll get from |
| 682 | // the process) may be wrong. |
| 683 | ABISP abi_to_use = ABI::FindPlugin(arch_to_use); |
| 684 | |
| 685 | AugmentRegisterInfoViaABI (reg_info, reg_name, abi_to_use); |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 686 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | m_register_info.AddRegister(reg_info, reg_name, alt_name, set_name); |
| 688 | } |
Todd Fiala | 1a63440 | 2014-01-08 07:52:40 +0000 | [diff] [blame] | 689 | else |
| 690 | { |
| 691 | break; // ensure exit before reg_num is incremented |
| 692 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 693 | } |
| 694 | else |
| 695 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 696 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 700 | if (m_register_info.GetNumRegisters() > 0) |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 701 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 702 | m_register_info.Finalize(GetTarget().GetArchitecture()); |
| 703 | return; |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 704 | } |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 705 | |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 706 | // We didn't get anything if the accumulated reg_num is zero. See if we are |
| 707 | // debugging ARM and fill with a hard coded register set until we can get an |
| 708 | // updated debugserver down on the devices. |
| 709 | // On the other hand, if the accumulated reg_num is positive, see if we can |
| 710 | // add composite registers to the existing primordial ones. |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 711 | bool from_scratch = (m_register_info.GetNumRegisters() == 0); |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 712 | |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 713 | if (!target_arch.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | { |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 715 | if (arch_to_use.IsValid() |
| 716 | && (arch_to_use.GetMachine() == llvm::Triple::arm || arch_to_use.GetMachine() == llvm::Triple::thumb) |
| 717 | && arch_to_use.GetTriple().getVendor() == llvm::Triple::Apple) |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 718 | m_register_info.HardcodeARMRegisters(from_scratch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | } |
Jason Molenda | 6d9fe8c | 2015-08-21 00:13:37 +0000 | [diff] [blame] | 720 | else if (target_arch.GetMachine() == llvm::Triple::arm |
| 721 | || target_arch.GetMachine() == llvm::Triple::thumb) |
Johnny Chen | 2fa9de1 | 2012-05-14 18:44:23 +0000 | [diff] [blame] | 722 | { |
| 723 | m_register_info.HardcodeARMRegisters(from_scratch); |
| 724 | } |
| 725 | |
| 726 | // At this point, we can finalize our register info. |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 727 | m_register_info.Finalize (GetTarget().GetArchitecture()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | Error |
| 731 | ProcessGDBRemote::WillLaunch (Module* module) |
| 732 | { |
| 733 | return WillLaunchOrAttach (); |
| 734 | } |
| 735 | |
| 736 | Error |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 737 | ProcessGDBRemote::WillAttachToProcessWithID (lldb::pid_t pid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | { |
| 739 | return WillLaunchOrAttach (); |
| 740 | } |
| 741 | |
| 742 | Error |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 743 | ProcessGDBRemote::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | { |
| 745 | return WillLaunchOrAttach (); |
| 746 | } |
| 747 | |
| 748 | Error |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 749 | ProcessGDBRemote::DoConnectRemote (Stream *strm, const char *remote_url) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 750 | { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 751 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 752 | Error error (WillLaunchOrAttach ()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 753 | |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 754 | if (error.Fail()) |
| 755 | return error; |
| 756 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 757 | error = ConnectToDebugserver (remote_url); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 758 | |
| 759 | if (error.Fail()) |
| 760 | return error; |
| 761 | StartAsyncThread (); |
| 762 | |
Greg Clayton | c574ede | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 763 | lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID (); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 764 | if (pid == LLDB_INVALID_PROCESS_ID) |
| 765 | { |
| 766 | // We don't have a valid process ID, so note that we are connected |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 767 | // and could now request to launch or attach, or get remote process |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 768 | // listings... |
| 769 | SetPrivateState (eStateConnected); |
| 770 | } |
| 771 | else |
| 772 | { |
| 773 | // We have a valid process |
| 774 | SetID (pid); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 775 | GetThreadList(); |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 776 | StringExtractorGDBRemote response; |
| 777 | if (m_gdb_comm.GetStopReply(response)) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 778 | { |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 779 | SetLastStopPacket(response); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 780 | |
| 781 | // '?' Packets must be handled differently in non-stop mode |
| 782 | if (GetTarget().GetNonStopModeEnabled()) |
| 783 | HandleStopReplySequence(); |
| 784 | |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 785 | Target &target = GetTarget(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 786 | if (!target.GetArchitecture().IsValid()) |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 787 | { |
| 788 | if (m_gdb_comm.GetProcessArchitecture().IsValid()) |
| 789 | { |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 790 | target.SetArchitecture(m_gdb_comm.GetProcessArchitecture()); |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 791 | } |
| 792 | else |
| 793 | { |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 794 | target.SetArchitecture(m_gdb_comm.GetHostArchitecture()); |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 795 | } |
Carlo Kok | 7438912 | 2013-10-14 07:09:13 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 798 | const StateType state = SetThreadStopInfo (response); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 799 | if (state != eStateInvalid) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 800 | { |
| 801 | SetPrivateState (state); |
| 802 | } |
| 803 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 804 | error.SetErrorStringWithFormat ("Process %" PRIu64 " was reported after connecting to '%s', but state was not stopped: %s", pid, remote_url, StateAsCString (state)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 805 | } |
| 806 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 807 | 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] | 808 | } |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 809 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 810 | if (log) |
| 811 | 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"); |
| 812 | |
| 813 | |
| 814 | if (error.Success() |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 815 | && !GetTarget().GetArchitecture().IsValid() |
| 816 | && m_gdb_comm.GetHostArchitecture().IsValid()) |
| 817 | { |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 818 | // Prefer the *process'* architecture over that of the *host*, if available. |
| 819 | if (m_gdb_comm.GetProcessArchitecture().IsValid()) |
| 820 | GetTarget().SetArchitecture(m_gdb_comm.GetProcessArchitecture()); |
| 821 | else |
| 822 | GetTarget().SetArchitecture(m_gdb_comm.GetHostArchitecture()); |
Jason Molenda | 16d127c | 2012-05-03 22:37:30 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 825 | if (log) |
| 826 | log->Printf ("ProcessGDBRemote::%s pid %" PRIu64 ": normalized target architecture triple: %s", __FUNCTION__, GetID (), GetTarget ().GetArchitecture ().GetTriple ().getTriple ().c_str ()); |
| 827 | |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 828 | if (error.Success()) |
Jaydeep Patil | 6fc590d | 2015-07-30 05:06:51 +0000 | [diff] [blame] | 829 | { |
| 830 | PlatformSP platform_sp = GetTarget().GetPlatform(); |
| 831 | if (platform_sp && platform_sp->IsConnected()) |
| 832 | SetUnixSignals(platform_sp->GetUnixSignals()); |
| 833 | else |
| 834 | SetUnixSignals(UnixSignals::Create(GetTarget().GetArchitecture())); |
| 835 | } |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 836 | |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 837 | return error; |
| 838 | } |
| 839 | |
| 840 | Error |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 841 | ProcessGDBRemote::WillLaunchOrAttach () |
| 842 | { |
| 843 | Error error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 844 | m_stdio_communication.Clear (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 845 | return error; |
| 846 | } |
| 847 | |
| 848 | //---------------------------------------------------------------------- |
| 849 | // Process Control |
| 850 | //---------------------------------------------------------------------- |
| 851 | Error |
Jean-Daniel Dupas | 7782de9 | 2013-12-09 22:52:50 +0000 | [diff] [blame] | 852 | ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 853 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 854 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 855 | Error error; |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 856 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 857 | if (log) |
| 858 | log->Printf ("ProcessGDBRemote::%s() entered", __FUNCTION__); |
| 859 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 860 | uint32_t launch_flags = launch_info.GetFlags().Get(); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 861 | FileSpec stdin_file_spec{}; |
| 862 | FileSpec stdout_file_spec{}; |
| 863 | FileSpec stderr_file_spec{}; |
| 864 | FileSpec working_dir = launch_info.GetWorkingDirectory(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 865 | |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 866 | const FileAction *file_action; |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 867 | file_action = launch_info.GetFileActionForFD (STDIN_FILENO); |
| 868 | if (file_action) |
| 869 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 870 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 871 | stdin_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 872 | } |
| 873 | file_action = launch_info.GetFileActionForFD (STDOUT_FILENO); |
| 874 | if (file_action) |
| 875 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 876 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 877 | stdout_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 878 | } |
| 879 | file_action = launch_info.GetFileActionForFD (STDERR_FILENO); |
| 880 | if (file_action) |
| 881 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 882 | if (file_action->GetAction() == FileAction::eFileActionOpen) |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 883 | stderr_file_spec = file_action->GetFileSpec(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 886 | if (log) |
| 887 | { |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 888 | if (stdin_file_spec || stdout_file_spec || stderr_file_spec) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 889 | 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] | 890 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 891 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 892 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 893 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 894 | else |
| 895 | log->Printf ("ProcessGDBRemote::%s no STDIO paths given via launch_info", __FUNCTION__); |
| 896 | } |
| 897 | |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 898 | const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 899 | if (stdin_file_spec || disable_stdio) |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 900 | { |
| 901 | // the inferior will be reading stdin from the specified file |
| 902 | // or stdio is completely disabled |
| 903 | m_stdin_forward = false; |
| 904 | } |
| 905 | else |
| 906 | { |
| 907 | m_stdin_forward = true; |
| 908 | } |
| 909 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 910 | // ::LogSetBitMask (GDBR_LOG_DEFAULT); |
| 911 | // ::LogSetOptions (LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD); |
| 912 | // ::LogSetLogFile ("/dev/stdout"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 913 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 914 | ObjectFile * object_file = exe_module->GetObjectFile(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 915 | if (object_file) |
| 916 | { |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 917 | error = EstablishConnectionIfNeeded (launch_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 918 | if (error.Success()) |
| 919 | { |
| 920 | lldb_utility::PseudoTerminal pty; |
| 921 | const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0; |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 922 | |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 923 | PlatformSP platform_sp (GetTarget().GetPlatform()); |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 924 | if (disable_stdio) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 925 | { |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 926 | // set to /dev/null unless redirected to a file above |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 927 | if (!stdin_file_spec) |
Zachary Turner | 4eff2d3 | 2015-10-14 21:37:36 +0000 | [diff] [blame] | 928 | stdin_file_spec.SetFile(FileSystem::DEV_NULL, false); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 929 | if (!stdout_file_spec) |
Zachary Turner | 4eff2d3 | 2015-10-14 21:37:36 +0000 | [diff] [blame] | 930 | stdout_file_spec.SetFile(FileSystem::DEV_NULL, false); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 931 | if (!stderr_file_spec) |
Zachary Turner | 4eff2d3 | 2015-10-14 21:37:36 +0000 | [diff] [blame] | 932 | stderr_file_spec.SetFile(FileSystem::DEV_NULL, false); |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 933 | } |
| 934 | else if (platform_sp && platform_sp->IsHost()) |
| 935 | { |
| 936 | // If the debugserver is local and we aren't disabling STDIO, lets use |
| 937 | // a pseudo terminal to instead of relying on the 'O' packets for stdio |
| 938 | // since 'O' packets can really slow down debugging if the inferior |
| 939 | // does a lot of output. |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 940 | if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) && |
| 941 | pty.OpenFirstAvailableMaster(O_RDWR|O_NOCTTY, NULL, 0)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 942 | { |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 943 | FileSpec slave_name{pty.GetSlaveName(NULL, 0), false}; |
| 944 | |
| 945 | if (!stdin_file_spec) |
| 946 | stdin_file_spec = slave_name; |
| 947 | |
| 948 | if (!stdout_file_spec) |
| 949 | stdout_file_spec = slave_name; |
| 950 | |
| 951 | if (!stderr_file_spec) |
| 952 | stderr_file_spec = slave_name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 954 | if (log) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 955 | 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] | 956 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 957 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 958 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 959 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 962 | if (log) |
Vince Harron | 4a8abd3 | 2015-02-13 19:15:24 +0000 | [diff] [blame] | 963 | 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] | 964 | __FUNCTION__, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 965 | stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", |
| 966 | stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", |
| 967 | stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 968 | |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 969 | if (stdin_file_spec) |
| 970 | m_gdb_comm.SetSTDIN(stdin_file_spec); |
| 971 | if (stdout_file_spec) |
| 972 | m_gdb_comm.SetSTDOUT(stdout_file_spec); |
| 973 | if (stderr_file_spec) |
| 974 | m_gdb_comm.SetSTDERR(stderr_file_spec); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 975 | |
| 976 | m_gdb_comm.SetDisableASLR (launch_flags & eLaunchFlagDisableASLR); |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 977 | m_gdb_comm.SetDetachOnError (launch_flags & eLaunchFlagDetachOnError); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 978 | |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 979 | m_gdb_comm.SendLaunchArchPacket (GetTarget().GetArchitecture().GetArchitectureName()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 980 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 981 | const char * launch_event_data = launch_info.GetLaunchEventData(); |
| 982 | if (launch_event_data != NULL && *launch_event_data != '\0') |
| 983 | m_gdb_comm.SendLaunchEventDataPacket (launch_event_data); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 984 | |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 985 | if (working_dir) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 986 | { |
| 987 | m_gdb_comm.SetWorkingDir (working_dir); |
| 988 | } |
| 989 | |
| 990 | // Send the environment and the program + arguments after we connect |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 991 | const Args &environment = launch_info.GetEnvironmentEntries(); |
| 992 | if (environment.GetArgumentCount()) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 993 | { |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 994 | size_t num_environment_entries = environment.GetArgumentCount(); |
| 995 | for (size_t i=0; i<num_environment_entries; ++i) |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 996 | { |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 997 | const char *env_entry = environment.GetArgumentAtIndex(i); |
| 998 | if (env_entry == NULL || m_gdb_comm.SendEnvironmentPacket(env_entry) != 0) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 999 | break; |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1000 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1001 | } |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1002 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1003 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1004 | // Scope for the scoped timeout object |
| 1005 | GDBRemoteCommunication::ScopedTimeout timeout (m_gdb_comm, 10); |
| 1006 | |
| 1007 | int arg_packet_err = m_gdb_comm.SendArgumentsPacket (launch_info); |
| 1008 | if (arg_packet_err == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1009 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1010 | std::string error_str; |
| 1011 | if (m_gdb_comm.GetLaunchSuccess (error_str)) |
| 1012 | { |
| 1013 | SetID (m_gdb_comm.GetCurrentProcessID ()); |
| 1014 | } |
| 1015 | else |
| 1016 | { |
| 1017 | error.SetErrorString (error_str.c_str()); |
| 1018 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1019 | } |
| 1020 | else |
| 1021 | { |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1022 | error.SetErrorStringWithFormat("'A' packet returned an error: %i", arg_packet_err); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1024 | } |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 1025 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1026 | if (GetID() == LLDB_INVALID_PROCESS_ID) |
| 1027 | { |
Johnny Chen | 4c1e920 | 2011-08-09 18:56:45 +0000 | [diff] [blame] | 1028 | if (log) |
| 1029 | log->Printf("failed to connect to debugserver: %s", error.AsCString()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1030 | KillDebugserverProcess (); |
| 1031 | return error; |
| 1032 | } |
| 1033 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1034 | StringExtractorGDBRemote response; |
| 1035 | if (m_gdb_comm.GetStopReply(response)) |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1036 | { |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1037 | SetLastStopPacket(response); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1038 | // '?' Packets must be handled differently in non-stop mode |
| 1039 | if (GetTarget().GetNonStopModeEnabled()) |
| 1040 | HandleStopReplySequence(); |
| 1041 | |
Tamas Berghammer | e9f4dfe | 2015-03-13 10:32:42 +0000 | [diff] [blame] | 1042 | const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 1043 | |
| 1044 | if (process_arch.IsValid()) |
Jason Molenda | c62bd7b | 2013-12-21 05:20:36 +0000 | [diff] [blame] | 1045 | { |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 1046 | GetTarget().MergeArchitecture(process_arch); |
Tamas Berghammer | e9f4dfe | 2015-03-13 10:32:42 +0000 | [diff] [blame] | 1047 | } |
| 1048 | else |
| 1049 | { |
| 1050 | const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture(); |
| 1051 | if (host_arch.IsValid()) |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 1052 | GetTarget().MergeArchitecture(host_arch); |
Carlo Kok | 7438912 | 2013-10-14 07:09:13 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 1055 | SetPrivateState (SetThreadStopInfo (response)); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1056 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1057 | if (!disable_stdio) |
| 1058 | { |
| 1059 | if (pty.GetMasterFileDescriptor() != lldb_utility::PseudoTerminal::invalid_fd) |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 1060 | SetSTDIOFileDescriptor (pty.ReleaseMasterFileDescriptor()); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1061 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1062 | } |
| 1063 | } |
Greg Clayton | c235ac7 | 2011-08-09 05:20:29 +0000 | [diff] [blame] | 1064 | else |
| 1065 | { |
Johnny Chen | 4c1e920 | 2011-08-09 18:56:45 +0000 | [diff] [blame] | 1066 | if (log) |
| 1067 | log->Printf("failed to connect to debugserver: %s", error.AsCString()); |
Greg Clayton | c235ac7 | 2011-08-09 05:20:29 +0000 | [diff] [blame] | 1068 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1069 | } |
| 1070 | else |
| 1071 | { |
| 1072 | // Set our user ID to an invalid process ID. |
| 1073 | SetID(LLDB_INVALID_PROCESS_ID); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1074 | error.SetErrorStringWithFormat ("failed to get object file from '%s' for arch %s", |
| 1075 | exe_module->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 1076 | exe_module->GetArchitecture().GetArchitectureName()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1077 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1078 | return error; |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1079 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1082 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1083 | Error |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1084 | ProcessGDBRemote::ConnectToDebugserver (const char *connect_url) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | { |
| 1086 | Error error; |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1087 | // Only connect if we have a valid connect URL |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1088 | Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1089 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1090 | if (connect_url && connect_url[0]) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | { |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1092 | if (log) |
| 1093 | log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__, connect_url); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1094 | std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor()); |
| 1095 | if (conn_ap.get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | { |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1097 | const uint32_t max_retry_count = 50; |
| 1098 | uint32_t retry_count = 0; |
| 1099 | while (!m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | { |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1101 | if (conn_ap->Connect(connect_url, &error) == eConnectionStatusSuccess) |
| 1102 | { |
| 1103 | m_gdb_comm.SetConnection (conn_ap.release()); |
| 1104 | break; |
| 1105 | } |
| 1106 | else if (error.WasInterrupted()) |
| 1107 | { |
| 1108 | // If we were interrupted, don't keep retrying. |
| 1109 | break; |
| 1110 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1111 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1112 | retry_count++; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1113 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1114 | if (retry_count >= max_retry_count) |
| 1115 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1116 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 1117 | usleep (100000); |
| 1118 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | if (!m_gdb_comm.IsConnected()) |
| 1123 | { |
| 1124 | if (error.Success()) |
| 1125 | error.SetErrorString("not connected to remote gdb server"); |
| 1126 | return error; |
| 1127 | } |
| 1128 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1129 | |
Ewan Crawford | fab40d3 | 2015-06-16 15:50:18 +0000 | [diff] [blame] | 1130 | // Start the communications read thread so all incoming data can be |
| 1131 | // parsed into packets and queued as they arrive. |
| 1132 | if (GetTarget().GetNonStopModeEnabled()) |
| 1133 | m_gdb_comm.StartReadThread(); |
| 1134 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1135 | // We always seem to be able to open a connection to a local port |
| 1136 | // so we need to make sure we can then send data to it. If we can't |
| 1137 | // then we aren't actually connected to anything, so try and do the |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1138 | // handshake with the remote GDB server and make sure that goes |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1139 | // alright. |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 1140 | if (!m_gdb_comm.HandshakeWithServer (&error)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1141 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1142 | m_gdb_comm.Disconnect(); |
| 1143 | if (error.Success()) |
| 1144 | error.SetErrorString("not connected to remote gdb server"); |
| 1145 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1146 | } |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Send $QNonStop:1 packet on startup if required |
| 1149 | if (GetTarget().GetNonStopModeEnabled()) |
Ewan Crawford | aa7eda7 | 2015-06-24 15:14:26 +0000 | [diff] [blame] | 1150 | GetTarget().SetNonStopModeEnabled (m_gdb_comm.SetNonStopMode(true)); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1151 | |
Greg Clayton | b30c50c | 2015-05-29 00:01:55 +0000 | [diff] [blame] | 1152 | m_gdb_comm.GetEchoSupported (); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1153 | m_gdb_comm.GetThreadSuffixSupported (); |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 1154 | m_gdb_comm.GetListThreadsInStopReplySupported (); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1155 | m_gdb_comm.GetHostInfo (); |
| 1156 | m_gdb_comm.GetVContSupported ('c'); |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 1157 | m_gdb_comm.GetVAttachOrWaitSupported(); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Ask the remote server for the default thread id |
| 1160 | if (GetTarget().GetNonStopModeEnabled()) |
| 1161 | m_gdb_comm.GetDefaultThreadId(m_initial_tid); |
| 1162 | |
| 1163 | |
Jim Ingham | 03afad8 | 2012-07-02 05:40:07 +0000 | [diff] [blame] | 1164 | size_t num_cmds = GetExtraStartupCommands().GetArgumentCount(); |
| 1165 | for (size_t idx = 0; idx < num_cmds; idx++) |
| 1166 | { |
| 1167 | StringExtractorGDBRemote response; |
Jim Ingham | 03afad8 | 2012-07-02 05:40:07 +0000 | [diff] [blame] | 1168 | m_gdb_comm.SendPacketAndWaitForResponse (GetExtraStartupCommands().GetArgumentAtIndex(idx), response, false); |
| 1169 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 | return error; |
| 1171 | } |
| 1172 | |
| 1173 | void |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1174 | ProcessGDBRemote::DidLaunchOrAttach (ArchSpec& process_arch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1176 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 6d09345 | 2011-02-05 02:25:06 +0000 | [diff] [blame] | 1177 | if (log) |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame^] | 1178 | log->Printf ("ProcessGDBRemote::%s()", __FUNCTION__); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 1179 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 1181 | BuildDynamicRegisterInfo (false); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 1182 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1183 | // See if the GDB server supports the qHostInfo information |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1184 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 1185 | |
| 1186 | // See if the GDB server supports the qProcessInfo packet, if so |
| 1187 | // prefer that over the Host information as it will be more specific |
| 1188 | // to our process. |
| 1189 | |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1190 | const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); |
| 1191 | if (remote_process_arch.IsValid()) |
| 1192 | { |
| 1193 | process_arch = remote_process_arch; |
| 1194 | if (log) |
| 1195 | log->Printf ("ProcessGDBRemote::%s gdb-remote had process architecture, using %s %s", |
| 1196 | __FUNCTION__, |
| 1197 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1198 | process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1199 | } |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1200 | else |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1201 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1202 | process_arch = m_gdb_comm.GetHostArchitecture(); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1203 | if (log) |
| 1204 | log->Printf ("ProcessGDBRemote::%s gdb-remote did not have process architecture, using gdb-remote host architecture %s %s", |
| 1205 | __FUNCTION__, |
| 1206 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1207 | process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1208 | } |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 1209 | |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1210 | if (process_arch.IsValid()) |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1211 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1212 | const ArchSpec &target_arch = GetTarget().GetArchitecture(); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1213 | if (target_arch.IsValid()) |
| 1214 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1215 | if (log) |
| 1216 | log->Printf ("ProcessGDBRemote::%s analyzing target arch, currently %s %s", |
| 1217 | __FUNCTION__, |
| 1218 | target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", |
| 1219 | target_arch.GetTriple().getTriple ().c_str() ? target_arch.GetTriple().getTriple ().c_str() : "<null>"); |
| 1220 | |
| 1221 | // 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] | 1222 | // ARM executables and shared libraries can have mixed ARM architectures. |
| 1223 | // You can have an armv6 executable, and if the host is armv7, then the |
| 1224 | // system will load the best possible architecture for all shared libraries |
| 1225 | // it has, so we really need to take the remote host architecture as our |
| 1226 | // defacto architecture in this case. |
| 1227 | |
Jason Molenda | 6d9fe8c | 2015-08-21 00:13:37 +0000 | [diff] [blame] | 1228 | if ((process_arch.GetMachine() == llvm::Triple::arm || process_arch.GetMachine() == llvm::Triple::thumb) |
| 1229 | && process_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1230 | { |
Jason Molenda | 921c01b | 2014-08-03 21:42:52 +0000 | [diff] [blame] | 1231 | GetTarget().SetArchitecture (process_arch); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1232 | if (log) |
| 1233 | log->Printf ("ProcessGDBRemote::%s remote process is ARM/Apple, setting target arch to %s %s", |
| 1234 | __FUNCTION__, |
| 1235 | process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", |
| 1236 | 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] | 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | // Fill in what is missing in the triple |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1241 | const llvm::Triple &remote_triple = process_arch.GetTriple(); |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1242 | llvm::Triple new_target_triple = target_arch.GetTriple(); |
| 1243 | if (new_target_triple.getVendorName().size() == 0) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1244 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1245 | new_target_triple.setVendor (remote_triple.getVendor()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1246 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1247 | if (new_target_triple.getOSName().size() == 0) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1248 | { |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1249 | new_target_triple.setOS (remote_triple.getOS()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1250 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1251 | if (new_target_triple.getEnvironmentName().size() == 0) |
| 1252 | new_target_triple.setEnvironment (remote_triple.getEnvironment()); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1253 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1254 | |
Tamas Berghammer | e724af1 | 2015-03-13 10:32:37 +0000 | [diff] [blame] | 1255 | ArchSpec new_target_arch = target_arch; |
| 1256 | new_target_arch.SetTriple(new_target_triple); |
| 1257 | GetTarget().SetArchitecture(new_target_arch); |
| 1258 | } |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1259 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1260 | |
| 1261 | if (log) |
| 1262 | log->Printf ("ProcessGDBRemote::%s final target arch after adjustments for remote architecture: %s %s", |
| 1263 | __FUNCTION__, |
| 1264 | target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", |
| 1265 | 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] | 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | // The target doesn't have a valid architecture yet, set it from |
| 1270 | // the architecture we got from the remote GDB server |
Jason Molenda | 921c01b | 2014-08-03 21:42:52 +0000 | [diff] [blame] | 1271 | GetTarget().SetArchitecture (process_arch); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1272 | } |
Greg Clayton | 0d0c12a | 2011-02-09 03:09:55 +0000 | [diff] [blame] | 1273 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame^] | 1274 | |
| 1275 | // Find out which StructuredDataPlugins are supported by the |
| 1276 | // debug monitor. These plugins transmit data over async $J packets. |
| 1277 | auto supported_packets_array = |
| 1278 | m_gdb_comm.GetSupportedStructuredDataPlugins(); |
| 1279 | if (supported_packets_array) |
| 1280 | MapSupportedStructuredDataPlugins(*supported_packets_array); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | void |
| 1285 | ProcessGDBRemote::DidLaunch () |
| 1286 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1287 | ArchSpec process_arch; |
| 1288 | DidLaunchOrAttach (process_arch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | Error |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1292 | ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info) |
| 1293 | { |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1294 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1295 | Error error; |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1296 | |
| 1297 | if (log) |
| 1298 | log->Printf ("ProcessGDBRemote::%s()", __FUNCTION__); |
| 1299 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1300 | // Clear out and clean up from any current state |
| 1301 | Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1302 | if (attach_pid != LLDB_INVALID_PROCESS_ID) |
| 1303 | { |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 1304 | error = EstablishConnectionIfNeeded (attach_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1305 | if (error.Success()) |
| 1306 | { |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 1307 | m_gdb_comm.SetDetachOnError(attach_info.GetDetachOnError()); |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1308 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1309 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1310 | const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1311 | SetID (attach_pid); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1312 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (packet, packet_len)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1313 | } |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 1314 | else |
| 1315 | SetExitStatus (-1, error.AsCString()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1316 | } |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 1317 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1318 | return error; |
| 1319 | } |
| 1320 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | Error |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 1322 | ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1323 | { |
| 1324 | Error error; |
| 1325 | // Clear out and clean up from any current state |
| 1326 | Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1328 | if (process_name && process_name[0]) |
| 1329 | { |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 1330 | error = EstablishConnectionIfNeeded (attach_info); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1331 | if (error.Success()) |
| 1332 | { |
| 1333 | StreamString packet; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1334 | |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 1335 | m_gdb_comm.SetDetachOnError(attach_info.GetDetachOnError()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1336 | |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 1337 | if (attach_info.GetWaitForLaunch()) |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 1338 | { |
| 1339 | if (!m_gdb_comm.GetVAttachOrWaitSupported()) |
| 1340 | { |
| 1341 | packet.PutCString ("vAttachWait"); |
| 1342 | } |
| 1343 | else |
| 1344 | { |
| 1345 | if (attach_info.GetIgnoreExisting()) |
| 1346 | packet.PutCString("vAttachWait"); |
| 1347 | else |
| 1348 | packet.PutCString ("vAttachOrWait"); |
| 1349 | } |
| 1350 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1351 | else |
| 1352 | packet.PutCString("vAttachName"); |
| 1353 | packet.PutChar(';'); |
Bruce Mitchener | 9ccb970 | 2015-11-07 04:40:13 +0000 | [diff] [blame] | 1354 | packet.PutBytesAsRawHex8(process_name, strlen(process_name), endian::InlHostByteOrder(), endian::InlHostByteOrder()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1355 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 1356 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (packet.GetData(), packet.GetSize())); |
| 1357 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | } |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 1359 | else |
| 1360 | SetExitStatus (-1, error.AsCString()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1361 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1362 | return error; |
| 1363 | } |
| 1364 | |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1365 | void |
| 1366 | ProcessGDBRemote::DidExit () |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1367 | { |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1368 | // When we exit, disconnect from the GDB server communications |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1369 | m_gdb_comm.Disconnect(); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | void |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1373 | ProcessGDBRemote::DidAttach (ArchSpec &process_arch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1374 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 1375 | // If you can figure out what the architecture is, fill it in here. |
| 1376 | process_arch.Clear(); |
| 1377 | DidLaunchOrAttach (process_arch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1381 | Error |
| 1382 | ProcessGDBRemote::WillResume () |
| 1383 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1384 | m_continue_c_tids.clear(); |
| 1385 | m_continue_C_tids.clear(); |
| 1386 | m_continue_s_tids.clear(); |
| 1387 | m_continue_S_tids.clear(); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1388 | m_jstopinfo_sp.reset(); |
| 1389 | m_jthreadsinfo_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1390 | return Error(); |
| 1391 | } |
| 1392 | |
| 1393 | Error |
| 1394 | ProcessGDBRemote::DoResume () |
| 1395 | { |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 1396 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1397 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 6d09345 | 2011-02-05 02:25:06 +0000 | [diff] [blame] | 1398 | if (log) |
| 1399 | log->Printf ("ProcessGDBRemote::Resume()"); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1400 | |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 1401 | ListenerSP listener_sp (Listener::MakeListener("gdb-remote.resume-packet-sent")); |
| 1402 | if (listener_sp->StartListeningForEvents (&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent)) |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1403 | { |
Jim Ingham | 583bbb1 | 2016-03-07 21:50:25 +0000 | [diff] [blame] | 1404 | listener_sp->StartListeningForEvents (&m_async_broadcaster, ProcessGDBRemote::eBroadcastBitAsyncThreadDidExit); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1405 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1406 | const size_t num_threads = GetThreadList().GetSize(); |
| 1407 | |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1408 | StreamString continue_packet; |
| 1409 | bool continue_packet_error = false; |
| 1410 | if (m_gdb_comm.HasAnyVContSupport ()) |
| 1411 | { |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1412 | if (!GetTarget().GetNonStopModeEnabled() && |
| 1413 | (m_continue_c_tids.size() == num_threads || |
Greg Clayton | e98008c | 2014-02-13 23:34:38 +0000 | [diff] [blame] | 1414 | (m_continue_c_tids.empty() && |
| 1415 | m_continue_C_tids.empty() && |
| 1416 | m_continue_s_tids.empty() && |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1417 | m_continue_S_tids.empty()))) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1418 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1419 | // All threads are continuing, just send a "c" packet |
| 1420 | continue_packet.PutCString ("c"); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1421 | } |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1422 | else |
| 1423 | { |
| 1424 | continue_packet.PutCString ("vCont"); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1425 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1426 | if (!m_continue_c_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1427 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1428 | if (m_gdb_comm.GetVContSupported ('c')) |
| 1429 | { |
| 1430 | 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) |
| 1431 | continue_packet.Printf(";c:%4.4" PRIx64, *t_pos); |
| 1432 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1433 | else |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1434 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1435 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1436 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1437 | if (!continue_packet_error && !m_continue_C_tids.empty()) |
| 1438 | { |
| 1439 | if (m_gdb_comm.GetVContSupported ('C')) |
| 1440 | { |
| 1441 | 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) |
| 1442 | continue_packet.Printf(";C%2.2x:%4.4" PRIx64, s_pos->second, s_pos->first); |
| 1443 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1444 | else |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1445 | continue_packet_error = true; |
| 1446 | } |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1447 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1448 | if (!continue_packet_error && !m_continue_s_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1449 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1450 | if (m_gdb_comm.GetVContSupported ('s')) |
| 1451 | { |
| 1452 | 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) |
| 1453 | continue_packet.Printf(";s:%4.4" PRIx64, *t_pos); |
| 1454 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1455 | else |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1456 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1457 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1458 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1459 | if (!continue_packet_error && !m_continue_S_tids.empty()) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1460 | { |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1461 | if (m_gdb_comm.GetVContSupported ('S')) |
| 1462 | { |
| 1463 | 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) |
| 1464 | continue_packet.Printf(";S%2.2x:%4.4" PRIx64, s_pos->second, s_pos->first); |
| 1465 | } |
| 1466 | else |
| 1467 | continue_packet_error = true; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1468 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1469 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1470 | if (continue_packet_error) |
| 1471 | continue_packet.GetString().clear(); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1472 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1473 | } |
| 1474 | else |
| 1475 | continue_packet_error = true; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1476 | |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1477 | if (continue_packet_error) |
| 1478 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1479 | // Either no vCont support, or we tried to use part of the vCont |
| 1480 | // packet that wasn't supported by the remote GDB server. |
| 1481 | // 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] | 1482 | const size_t num_continue_c_tids = m_continue_c_tids.size(); |
| 1483 | const size_t num_continue_C_tids = m_continue_C_tids.size(); |
| 1484 | const size_t num_continue_s_tids = m_continue_s_tids.size(); |
| 1485 | const size_t num_continue_S_tids = m_continue_S_tids.size(); |
| 1486 | if (num_continue_c_tids > 0) |
| 1487 | { |
| 1488 | if (num_continue_c_tids == num_threads) |
| 1489 | { |
| 1490 | // All threads are resuming... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1491 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1492 | continue_packet.PutChar ('c'); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1493 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1494 | } |
| 1495 | else if (num_continue_c_tids == 1 && |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1496 | num_continue_C_tids == 0 && |
| 1497 | num_continue_s_tids == 0 && |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1498 | num_continue_S_tids == 0 ) |
| 1499 | { |
| 1500 | // Only one thread is continuing |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1501 | m_gdb_comm.SetCurrentThreadForRun (m_continue_c_tids.front()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1502 | continue_packet.PutChar ('c'); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1503 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1507 | if (continue_packet_error && num_continue_C_tids > 0) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1508 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1509 | if ((num_continue_C_tids + num_continue_c_tids) == num_threads && |
| 1510 | num_continue_C_tids > 0 && |
| 1511 | num_continue_s_tids == 0 && |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1512 | num_continue_S_tids == 0 ) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1513 | { |
| 1514 | const int continue_signo = m_continue_C_tids.front().second; |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1515 | // Only one thread is continuing |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1516 | if (num_continue_C_tids > 1) |
| 1517 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1518 | // More that one thread with a signal, yet we don't have |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1519 | // vCont support and we are being asked to resume each |
| 1520 | // thread with a signal, we need to make sure they are |
| 1521 | // all the same signal, or we can't issue the continue |
| 1522 | // accurately with the current support... |
| 1523 | if (num_continue_C_tids > 1) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1524 | { |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1525 | continue_packet_error = false; |
| 1526 | for (size_t i=1; i<m_continue_C_tids.size(); ++i) |
| 1527 | { |
| 1528 | if (m_continue_C_tids[i].second != continue_signo) |
| 1529 | continue_packet_error = true; |
| 1530 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1531 | } |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1532 | if (!continue_packet_error) |
| 1533 | m_gdb_comm.SetCurrentThreadForRun (-1); |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | // Set the continue thread ID |
| 1538 | continue_packet_error = false; |
| 1539 | m_gdb_comm.SetCurrentThreadForRun (m_continue_C_tids.front().first); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1540 | } |
| 1541 | if (!continue_packet_error) |
| 1542 | { |
| 1543 | // Add threads continuing with the same signo... |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1544 | continue_packet.Printf("C%2.2x", continue_signo); |
| 1545 | } |
| 1546 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1549 | if (continue_packet_error && num_continue_s_tids > 0) |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1550 | { |
| 1551 | if (num_continue_s_tids == num_threads) |
| 1552 | { |
| 1553 | // All threads are resuming... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1554 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 1555 | |
| 1556 | // If in Non-Stop-Mode use vCont when stepping |
| 1557 | if (GetTarget().GetNonStopModeEnabled()) |
| 1558 | { |
| 1559 | if (m_gdb_comm.GetVContSupported('s')) |
| 1560 | continue_packet.PutCString("vCont;s"); |
| 1561 | else |
| 1562 | continue_packet.PutChar('s'); |
| 1563 | } |
| 1564 | else |
| 1565 | continue_packet.PutChar('s'); |
| 1566 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1567 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1568 | } |
| 1569 | else if (num_continue_c_tids == 0 && |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1570 | num_continue_C_tids == 0 && |
| 1571 | num_continue_s_tids == 1 && |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1572 | num_continue_S_tids == 0 ) |
| 1573 | { |
| 1574 | // Only one thread is stepping |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1575 | m_gdb_comm.SetCurrentThreadForRun (m_continue_s_tids.front()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1576 | continue_packet.PutChar ('s'); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1577 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | if (!continue_packet_error && num_continue_S_tids > 0) |
| 1582 | { |
| 1583 | if (num_continue_S_tids == num_threads) |
| 1584 | { |
| 1585 | const int step_signo = m_continue_S_tids.front().second; |
| 1586 | // Are all threads trying to step with the same signal? |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1587 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1588 | if (num_continue_S_tids > 1) |
| 1589 | { |
| 1590 | for (size_t i=1; i<num_threads; ++i) |
| 1591 | { |
| 1592 | if (m_continue_S_tids[i].second != step_signo) |
| 1593 | continue_packet_error = true; |
| 1594 | } |
| 1595 | } |
| 1596 | if (!continue_packet_error) |
| 1597 | { |
| 1598 | // Add threads stepping with the same signo... |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1599 | m_gdb_comm.SetCurrentThreadForRun (-1); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1600 | continue_packet.Printf("S%2.2x", step_signo); |
| 1601 | } |
| 1602 | } |
| 1603 | else if (num_continue_c_tids == 0 && |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1604 | num_continue_C_tids == 0 && |
| 1605 | num_continue_s_tids == 0 && |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1606 | num_continue_S_tids == 1 ) |
| 1607 | { |
| 1608 | // Only one thread is stepping with signal |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1609 | m_gdb_comm.SetCurrentThreadForRun (m_continue_S_tids.front().first); |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1610 | continue_packet.Printf("S%2.2x", m_continue_S_tids.front().second); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1611 | continue_packet_error = false; |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1612 | } |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | if (continue_packet_error) |
| 1617 | { |
| 1618 | error.SetErrorString ("can't make continue packet for this resume"); |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | EventSP event_sp; |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1623 | if (!m_async_thread.IsJoinable()) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1624 | { |
| 1625 | error.SetErrorString ("Trying to resume but the async thread is dead."); |
| 1626 | if (log) |
| 1627 | log->Printf ("ProcessGDBRemote::DoResume: Trying to resume but the async thread is dead."); |
| 1628 | return error; |
| 1629 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1630 | |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1631 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (continue_packet.GetData(), continue_packet.GetSize())); |
| 1632 | |
Saleem Abdulrasool | 2d6a9ec | 2016-07-28 17:32:20 +0000 | [diff] [blame] | 1633 | if (listener_sp->WaitForEvent(std::chrono::seconds(5), event_sp) == false) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1634 | { |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1635 | error.SetErrorString("Resume timed out."); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 1636 | if (log) |
| 1637 | log->Printf ("ProcessGDBRemote::DoResume: Resume timed out."); |
| 1638 | } |
| 1639 | else if (event_sp->BroadcasterIs (&m_async_broadcaster)) |
| 1640 | { |
| 1641 | error.SetErrorString ("Broadcast continue, but the async thread was killed before we got an ack back."); |
| 1642 | if (log) |
| 1643 | log->Printf ("ProcessGDBRemote::DoResume: Broadcast continue, but the async thread was killed before we got an ack back."); |
| 1644 | return error; |
| 1645 | } |
Greg Clayton | 71fc2a3 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 1646 | } |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 1649 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1652 | void |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 1653 | ProcessGDBRemote::HandleStopReplySequence () |
| 1654 | { |
| 1655 | while(true) |
| 1656 | { |
| 1657 | // Send vStopped |
| 1658 | StringExtractorGDBRemote response; |
| 1659 | m_gdb_comm.SendPacketAndWaitForResponse("vStopped", response, false); |
| 1660 | |
| 1661 | // OK represents end of signal list |
| 1662 | if (response.IsOKResponse()) |
| 1663 | break; |
| 1664 | |
| 1665 | // If not OK or a normal packet we have a problem |
| 1666 | if (!response.IsNormalResponse()) |
| 1667 | break; |
| 1668 | |
| 1669 | SetLastStopPacket(response); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | void |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1674 | ProcessGDBRemote::ClearThreadIDList () |
| 1675 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1676 | std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex()); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1677 | m_thread_ids.clear(); |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1678 | m_thread_pcs.clear(); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1681 | size_t |
| 1682 | ProcessGDBRemote::UpdateThreadIDsFromStopReplyThreadsValue (std::string &value) |
| 1683 | { |
| 1684 | m_thread_ids.clear(); |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1685 | m_thread_pcs.clear(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1686 | size_t comma_pos; |
| 1687 | lldb::tid_t tid; |
| 1688 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 1689 | { |
| 1690 | value[comma_pos] = '\0'; |
| 1691 | // thread in big endian hex |
| 1692 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
| 1693 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1694 | m_thread_ids.push_back (tid); |
| 1695 | value.erase(0, comma_pos + 1); |
| 1696 | } |
| 1697 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
| 1698 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1699 | m_thread_ids.push_back (tid); |
| 1700 | return m_thread_ids.size(); |
| 1701 | } |
| 1702 | |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1703 | size_t |
| 1704 | ProcessGDBRemote::UpdateThreadPCsFromStopReplyThreadsValue (std::string &value) |
| 1705 | { |
| 1706 | m_thread_pcs.clear(); |
| 1707 | size_t comma_pos; |
| 1708 | lldb::addr_t pc; |
| 1709 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 1710 | { |
| 1711 | value[comma_pos] = '\0'; |
| 1712 | pc = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_ADDRESS, 16); |
| 1713 | if (pc != LLDB_INVALID_ADDRESS) |
| 1714 | m_thread_pcs.push_back (pc); |
| 1715 | value.erase(0, comma_pos + 1); |
| 1716 | } |
| 1717 | pc = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_ADDRESS, 16); |
| 1718 | if (pc != LLDB_INVALID_THREAD_ID) |
| 1719 | m_thread_pcs.push_back (pc); |
| 1720 | return m_thread_pcs.size(); |
| 1721 | } |
| 1722 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1723 | bool |
| 1724 | ProcessGDBRemote::UpdateThreadIDList () |
| 1725 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1726 | std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex()); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1727 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1728 | if (m_jthreadsinfo_sp) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1729 | { |
| 1730 | // If we have the JSON threads info, we can get the thread list from that |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1731 | StructuredData::Array *thread_infos = m_jthreadsinfo_sp->GetAsArray(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1732 | if (thread_infos && thread_infos->GetSize() > 0) |
| 1733 | { |
| 1734 | m_thread_ids.clear(); |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1735 | m_thread_pcs.clear(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1736 | thread_infos->ForEach([this](StructuredData::Object* object) -> bool { |
| 1737 | StructuredData::Dictionary *thread_dict = object->GetAsDictionary(); |
| 1738 | if (thread_dict) |
| 1739 | { |
| 1740 | // Set the thread stop info from the JSON dictionary |
| 1741 | SetThreadStopInfo (thread_dict); |
| 1742 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
| 1743 | if (thread_dict->GetValueForKeyAsInteger<lldb::tid_t>("tid", tid)) |
| 1744 | m_thread_ids.push_back(tid); |
| 1745 | } |
| 1746 | return true; // Keep iterating through all thread_info objects |
| 1747 | }); |
| 1748 | } |
| 1749 | if (!m_thread_ids.empty()) |
| 1750 | return true; |
| 1751 | } |
| 1752 | else |
| 1753 | { |
| 1754 | // See if we can get the thread IDs from the current stop reply packets |
| 1755 | // that might contain a "threads" key/value pair |
| 1756 | |
| 1757 | // Lock the thread stack while we access it |
Greg Clayton | fc1e77a98 | 2015-11-03 22:42:04 +0000 | [diff] [blame] | 1758 | //Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1759 | std::unique_lock<std::recursive_mutex> stop_stack_lock(m_last_stop_packet_mutex, std::defer_lock); |
| 1760 | if (stop_stack_lock.try_lock()) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1761 | { |
Greg Clayton | fc1e77a98 | 2015-11-03 22:42:04 +0000 | [diff] [blame] | 1762 | // Get the number of stop packets on the stack |
| 1763 | int nItems = m_stop_packet_stack.size(); |
| 1764 | // Iterate over them |
| 1765 | for (int i = 0; i < nItems; i++) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1766 | { |
Greg Clayton | fc1e77a98 | 2015-11-03 22:42:04 +0000 | [diff] [blame] | 1767 | // Get the thread stop info |
| 1768 | StringExtractorGDBRemote &stop_info = m_stop_packet_stack[i]; |
| 1769 | const std::string &stop_info_str = stop_info.GetStringRef(); |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1770 | |
| 1771 | m_thread_pcs.clear(); |
| 1772 | const size_t thread_pcs_pos = stop_info_str.find(";thread-pcs:"); |
| 1773 | if (thread_pcs_pos != std::string::npos) |
| 1774 | { |
| 1775 | const size_t start = thread_pcs_pos + strlen(";thread-pcs:"); |
| 1776 | const size_t end = stop_info_str.find(';', start); |
| 1777 | if (end != std::string::npos) |
| 1778 | { |
| 1779 | std::string value = stop_info_str.substr(start, end - start); |
| 1780 | UpdateThreadPCsFromStopReplyThreadsValue(value); |
| 1781 | } |
| 1782 | } |
| 1783 | |
Greg Clayton | fc1e77a98 | 2015-11-03 22:42:04 +0000 | [diff] [blame] | 1784 | const size_t threads_pos = stop_info_str.find(";threads:"); |
| 1785 | if (threads_pos != std::string::npos) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1786 | { |
Greg Clayton | fc1e77a98 | 2015-11-03 22:42:04 +0000 | [diff] [blame] | 1787 | const size_t start = threads_pos + strlen(";threads:"); |
| 1788 | const size_t end = stop_info_str.find(';', start); |
| 1789 | if (end != std::string::npos) |
| 1790 | { |
| 1791 | std::string value = stop_info_str.substr(start, end - start); |
| 1792 | if (UpdateThreadIDsFromStopReplyThreadsValue(value)) |
| 1793 | return true; |
| 1794 | } |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1800 | bool sequence_mutex_unavailable = false; |
| 1801 | m_gdb_comm.GetCurrentThreadIDs (m_thread_ids, sequence_mutex_unavailable); |
| 1802 | if (sequence_mutex_unavailable) |
| 1803 | { |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1804 | return false; // We just didn't get the list |
| 1805 | } |
| 1806 | return true; |
| 1807 | } |
| 1808 | |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1809 | bool |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1810 | ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1811 | { |
| 1812 | // locker will keep a mutex locked until it goes out of scope |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1813 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_THREAD)); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1814 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1815 | log->Printf ("ProcessGDBRemote::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1816 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1817 | size_t num_thread_ids = m_thread_ids.size(); |
| 1818 | // The "m_thread_ids" thread ID list should always be updated after each stop |
| 1819 | // reply packet, but in case it isn't, update it here. |
| 1820 | if (num_thread_ids == 0) |
| 1821 | { |
| 1822 | if (!UpdateThreadIDList ()) |
| 1823 | return false; |
| 1824 | num_thread_ids = m_thread_ids.size(); |
| 1825 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1826 | |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1827 | ThreadList old_thread_list_copy(old_thread_list); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1828 | if (num_thread_ids > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1829 | { |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1830 | for (size_t i=0; i<num_thread_ids; ++i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1831 | { |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 1832 | tid_t tid = m_thread_ids[i]; |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1833 | ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByProtocolID(tid, false)); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1834 | if (!thread_sp) |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1835 | { |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1836 | thread_sp.reset (new ThreadGDBRemote (*this, tid)); |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1837 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
| 1838 | log->Printf( |
| 1839 | "ProcessGDBRemote::%s Making new thread: %p for thread ID: 0x%" PRIx64 ".\n", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1840 | __FUNCTION__, static_cast<void*>(thread_sp.get()), |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1841 | thread_sp->GetID()); |
| 1842 | } |
| 1843 | else |
| 1844 | { |
| 1845 | if (log && log->GetMask().Test(GDBR_LOG_VERBOSE)) |
| 1846 | log->Printf( |
| 1847 | "ProcessGDBRemote::%s Found old thread: %p for thread ID: 0x%" PRIx64 ".\n", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1848 | __FUNCTION__, static_cast<void*>(thread_sp.get()), |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1849 | thread_sp->GetID()); |
| 1850 | } |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1851 | // The m_thread_pcs vector has pc values in big-endian order, not target-endian, unlike most |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1852 | // of the register read/write packets in gdb-remote protocol. |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1853 | // Early in the process startup, we may not yet have set the process ByteOrder so we ignore these; |
| 1854 | // they are a performance improvement over fetching thread register values individually, the |
| 1855 | // method we will fall back to if needed. |
| 1856 | if (m_thread_ids.size() == m_thread_pcs.size() && thread_sp.get() && GetByteOrder() != eByteOrderInvalid) |
| 1857 | { |
| 1858 | ThreadGDBRemote *gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); |
| 1859 | RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext()); |
| 1860 | if (reg_ctx_sp) |
| 1861 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1862 | uint32_t pc_regnum = reg_ctx_sp->ConvertRegisterKindToRegisterNumber |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 1863 | (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC); |
| 1864 | if (pc_regnum != LLDB_INVALID_REGNUM) |
| 1865 | { |
| 1866 | gdb_thread->PrivateSetRegisterValue (pc_regnum, m_thread_pcs[i]); |
| 1867 | } |
| 1868 | } |
| 1869 | } |
Greg Clayton | 88f86b6 | 2016-06-10 23:23:34 +0000 | [diff] [blame] | 1870 | new_thread_list.AddThreadSortedByIndexID (thread_sp); |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 1871 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1872 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1873 | |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1874 | // Whatever that is left in old_thread_list_copy are not |
| 1875 | // present in new_thread_list. Remove non-existent threads from internal id table. |
| 1876 | size_t old_num_thread_ids = old_thread_list_copy.GetSize(false); |
| 1877 | for (size_t i=0; i<old_num_thread_ids; i++) |
| 1878 | { |
| 1879 | ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex (i, false)); |
| 1880 | if (old_thread_sp) |
| 1881 | { |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1882 | lldb::tid_t old_thread_id = old_thread_sp->GetProtocolID(); |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1883 | m_thread_id_to_index_id_map.erase(old_thread_id); |
| 1884 | } |
| 1885 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 1886 | |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1887 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1890 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1891 | bool |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1892 | ProcessGDBRemote::GetThreadStopInfoFromJSON (ThreadGDBRemote *thread, const StructuredData::ObjectSP &thread_infos_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1893 | { |
| 1894 | // See if we got thread stop infos for all threads via the "jThreadsInfo" packet |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1895 | if (thread_infos_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1896 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1897 | StructuredData::Array *thread_infos = thread_infos_sp->GetAsArray(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1898 | if (thread_infos) |
| 1899 | { |
| 1900 | lldb::tid_t tid; |
| 1901 | const size_t n = thread_infos->GetSize(); |
| 1902 | for (size_t i=0; i<n; ++i) |
| 1903 | { |
| 1904 | StructuredData::Dictionary *thread_dict = thread_infos->GetItemAtIndex(i)->GetAsDictionary(); |
| 1905 | if (thread_dict) |
| 1906 | { |
| 1907 | if (thread_dict->GetValueForKeyAsInteger<lldb::tid_t>("tid", tid, LLDB_INVALID_THREAD_ID)) |
| 1908 | { |
| 1909 | if (tid == thread->GetID()) |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1910 | return (bool)SetThreadStopInfo(thread_dict); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 1916 | return false; |
| 1917 | } |
| 1918 | |
| 1919 | bool |
| 1920 | ProcessGDBRemote::CalculateThreadStopInfo (ThreadGDBRemote *thread) |
| 1921 | { |
| 1922 | // See if we got thread stop infos for all threads via the "jThreadsInfo" packet |
| 1923 | if (GetThreadStopInfoFromJSON (thread, m_jthreadsinfo_sp)) |
| 1924 | return true; |
| 1925 | |
| 1926 | // See if we got thread stop info for any threads valid stop info reasons threads |
| 1927 | // via the "jstopinfo" packet stop reply packet key/value pair? |
| 1928 | if (m_jstopinfo_sp) |
| 1929 | { |
| 1930 | // If we have "jstopinfo" then we have stop descriptions for all threads |
| 1931 | // that have stop reasons, and if there is no entry for a thread, then |
| 1932 | // it has no stop reason. |
| 1933 | thread->GetRegisterContext()->InvalidateIfNeeded(true); |
| 1934 | if (!GetThreadStopInfoFromJSON (thread, m_jstopinfo_sp)) |
| 1935 | { |
| 1936 | thread->SetStopInfo (StopInfoSP()); |
| 1937 | } |
| 1938 | return true; |
| 1939 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1940 | |
| 1941 | // Fall back to using the qThreadStopInfo packet |
| 1942 | StringExtractorGDBRemote stop_packet; |
| 1943 | if (GetGDBRemote().GetThreadStopInfo(thread->GetProtocolID(), stop_packet)) |
| 1944 | return SetThreadStopInfo (stop_packet) == eStateStopped; |
| 1945 | return false; |
| 1946 | } |
| 1947 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 1948 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1949 | ThreadSP |
| 1950 | ProcessGDBRemote::SetThreadStopInfo (lldb::tid_t tid, |
| 1951 | ExpeditedRegisterMap &expedited_register_map, |
| 1952 | uint8_t signo, |
| 1953 | const std::string &thread_name, |
| 1954 | const std::string &reason, |
| 1955 | const std::string &description, |
| 1956 | uint32_t exc_type, |
| 1957 | const std::vector<addr_t> &exc_data, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1958 | addr_t thread_dispatch_qaddr, |
| 1959 | bool queue_vars_valid, // Set to true if queue_name, queue_kind and queue_serial are valid |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 1960 | LazyBool associated_with_dispatch_queue, |
| 1961 | addr_t dispatch_queue_t, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1962 | std::string &queue_name, |
| 1963 | QueueKind queue_kind, |
| 1964 | uint64_t queue_serial) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1965 | { |
| 1966 | ThreadSP thread_sp; |
| 1967 | if (tid != LLDB_INVALID_THREAD_ID) |
| 1968 | { |
| 1969 | // Scope for "locker" below |
| 1970 | { |
| 1971 | // m_thread_list_real does have its own mutex, but we need to |
| 1972 | // hold onto the mutex between the call to m_thread_list_real.FindThreadByID(...) |
| 1973 | // and the m_thread_list_real.AddThread(...) so it doesn't change on us |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1974 | std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex()); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1975 | thread_sp = m_thread_list_real.FindThreadByProtocolID(tid, false); |
| 1976 | |
| 1977 | if (!thread_sp) |
| 1978 | { |
| 1979 | // Create the thread if we need to |
| 1980 | thread_sp.reset (new ThreadGDBRemote (*this, tid)); |
| 1981 | m_thread_list_real.AddThread(thread_sp); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | if (thread_sp) |
| 1986 | { |
| 1987 | ThreadGDBRemote *gdb_thread = static_cast<ThreadGDBRemote *> (thread_sp.get()); |
| 1988 | gdb_thread->GetRegisterContext()->InvalidateIfNeeded(true); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 1989 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1990 | for (const auto &pair : expedited_register_map) |
| 1991 | { |
| 1992 | StringExtractor reg_value_extractor; |
| 1993 | reg_value_extractor.GetStringRef() = pair.second; |
| 1994 | gdb_thread->PrivateSetRegisterValue (pair.first, reg_value_extractor); |
| 1995 | } |
| 1996 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1997 | thread_sp->SetName (thread_name.empty() ? NULL : thread_name.c_str()); |
| 1998 | |
| 1999 | gdb_thread->SetThreadDispatchQAddr (thread_dispatch_qaddr); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2000 | // Check if the GDB server was able to provide the queue name, kind and serial number |
| 2001 | if (queue_vars_valid) |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2002 | gdb_thread->SetQueueInfo(std::move(queue_name), queue_kind, queue_serial, dispatch_queue_t, associated_with_dispatch_queue); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2003 | else |
| 2004 | gdb_thread->ClearQueueInfo(); |
| 2005 | |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2006 | gdb_thread->SetAssociatedWithLibdispatchQueue (associated_with_dispatch_queue); |
| 2007 | |
| 2008 | if (dispatch_queue_t != LLDB_INVALID_ADDRESS) |
| 2009 | gdb_thread->SetQueueLibdispatchQueueAddress (dispatch_queue_t); |
| 2010 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2011 | // Make sure we update our thread stop reason just once |
| 2012 | if (!thread_sp->StopInfoIsUpToDate()) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2013 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2014 | thread_sp->SetStopInfo (StopInfoSP()); |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2015 | // If there's a memory thread backed by this thread, we need to use it to calcualte StopInfo. |
| 2016 | ThreadSP memory_thread_sp = m_thread_list.FindThreadByProtocolID(thread_sp->GetProtocolID()); |
| 2017 | if (memory_thread_sp) |
| 2018 | thread_sp = memory_thread_sp; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2019 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2020 | if (exc_type != 0) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2021 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2022 | const size_t exc_data_size = exc_data.size(); |
| 2023 | |
| 2024 | thread_sp->SetStopInfo (StopInfoMachException::CreateStopReasonWithMachException (*thread_sp, |
| 2025 | exc_type, |
| 2026 | exc_data_size, |
| 2027 | exc_data_size >= 1 ? exc_data[0] : 0, |
| 2028 | exc_data_size >= 2 ? exc_data[1] : 0, |
| 2029 | exc_data_size >= 3 ? exc_data[2] : 0)); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2030 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2031 | else |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2032 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2033 | bool handled = false; |
| 2034 | bool did_exec = false; |
| 2035 | if (!reason.empty()) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2036 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2037 | if (reason.compare("trace") == 0) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2038 | { |
Pavel Labath | ef40912 | 2016-04-07 08:16:10 +0000 | [diff] [blame] | 2039 | addr_t pc = thread_sp->GetRegisterContext()->GetPC(); |
| 2040 | lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 2041 | |
| 2042 | // If the current pc is a breakpoint site then the StopInfo should be set to Breakpoint |
| 2043 | // Otherwise, it will be set to Trace. |
| 2044 | if (bp_site_sp && bp_site_sp->ValidForThisThread(thread_sp.get())) |
| 2045 | { |
| 2046 | thread_sp->SetStopInfo( |
| 2047 | StopInfo::CreateStopReasonWithBreakpointSiteID(*thread_sp, bp_site_sp->GetID())); |
| 2048 | } |
| 2049 | else |
| 2050 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2051 | handled = true; |
| 2052 | } |
| 2053 | else if (reason.compare("breakpoint") == 0) |
| 2054 | { |
Pavel Labath | ef40912 | 2016-04-07 08:16:10 +0000 | [diff] [blame] | 2055 | addr_t pc = thread_sp->GetRegisterContext()->GetPC(); |
| 2056 | lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 2057 | if (bp_site_sp) |
| 2058 | { |
| 2059 | // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, |
| 2060 | // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that |
| 2061 | // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. |
| 2062 | handled = true; |
| 2063 | if (bp_site_sp->ValidForThisThread (thread_sp.get())) |
| 2064 | { |
| 2065 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); |
| 2066 | } |
| 2067 | else |
| 2068 | { |
| 2069 | StopInfoSP invalid_stop_info_sp; |
| 2070 | thread_sp->SetStopInfo (invalid_stop_info_sp); |
| 2071 | } |
| 2072 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2073 | } |
| 2074 | else if (reason.compare("trap") == 0) |
| 2075 | { |
| 2076 | // Let the trap just use the standard signal stop reason below... |
| 2077 | } |
| 2078 | else if (reason.compare("watchpoint") == 0) |
| 2079 | { |
| 2080 | StringExtractor desc_extractor(description.c_str()); |
| 2081 | addr_t wp_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS); |
| 2082 | uint32_t wp_index = desc_extractor.GetU32(LLDB_INVALID_INDEX32); |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 2083 | addr_t wp_hit_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2084 | watch_id_t watch_id = LLDB_INVALID_WATCH_ID; |
| 2085 | if (wp_addr != LLDB_INVALID_ADDRESS) |
| 2086 | { |
Mohit K. Bhakkad | 6846bc8 | 2015-12-02 17:45:02 +0000 | [diff] [blame] | 2087 | WatchpointSP wp_sp; |
| 2088 | ArchSpec::Core core = GetTarget().GetArchitecture().GetCore(); |
Omair Javaid | 43507f5 | 2016-06-16 16:41:22 +0000 | [diff] [blame] | 2089 | if ((core >= ArchSpec::kCore_mips_first && core <= ArchSpec::kCore_mips_last) || |
Omair Javaid | c6dc90e | 2016-06-27 11:18:23 +0000 | [diff] [blame] | 2090 | (core >= ArchSpec::eCore_arm_generic && core <= ArchSpec::eCore_arm_aarch64)) |
Mohit K. Bhakkad | 6846bc8 | 2015-12-02 17:45:02 +0000 | [diff] [blame] | 2091 | wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_hit_addr); |
| 2092 | if (!wp_sp) |
| 2093 | wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_addr); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2094 | if (wp_sp) |
| 2095 | { |
| 2096 | wp_sp->SetHardwareIndex(wp_index); |
| 2097 | watch_id = wp_sp->GetID(); |
| 2098 | } |
| 2099 | } |
| 2100 | if (watch_id == LLDB_INVALID_WATCH_ID) |
| 2101 | { |
| 2102 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_WATCHPOINTS)); |
| 2103 | if (log) log->Printf ("failed to find watchpoint"); |
| 2104 | } |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 2105 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithWatchpointID (*thread_sp, watch_id, wp_hit_addr)); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2106 | handled = true; |
| 2107 | } |
| 2108 | else if (reason.compare("exception") == 0) |
| 2109 | { |
| 2110 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException(*thread_sp, description.c_str())); |
| 2111 | handled = true; |
| 2112 | } |
| 2113 | else if (reason.compare("exec") == 0) |
| 2114 | { |
| 2115 | did_exec = true; |
| 2116 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithExec(*thread_sp)); |
| 2117 | handled = true; |
| 2118 | } |
| 2119 | } |
Pavel Labath | 3ce324a | 2016-04-06 09:10:29 +0000 | [diff] [blame] | 2120 | else if (!signo) |
| 2121 | { |
Pavel Labath | ef40912 | 2016-04-07 08:16:10 +0000 | [diff] [blame] | 2122 | addr_t pc = thread_sp->GetRegisterContext()->GetPC(); |
| 2123 | lldb::BreakpointSiteSP bp_site_sp = |
| 2124 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 2125 | |
Pavel Labath | 3ce324a | 2016-04-06 09:10:29 +0000 | [diff] [blame] | 2126 | // If the current pc is a breakpoint site then the StopInfo should be set to Breakpoint |
| 2127 | // even though the remote stub did not set it as such. This can happen when |
| 2128 | // the thread is involuntarily interrupted (e.g. due to stops on other |
| 2129 | // threads) just as it is about to execute the breakpoint instruction. |
Pavel Labath | ef40912 | 2016-04-07 08:16:10 +0000 | [diff] [blame] | 2130 | if (bp_site_sp && bp_site_sp->ValidForThisThread(thread_sp.get())) |
| 2131 | { |
| 2132 | thread_sp->SetStopInfo( |
| 2133 | StopInfo::CreateStopReasonWithBreakpointSiteID(*thread_sp, bp_site_sp->GetID())); |
Pavel Labath | 3ce324a | 2016-04-06 09:10:29 +0000 | [diff] [blame] | 2134 | handled = true; |
Pavel Labath | ef40912 | 2016-04-07 08:16:10 +0000 | [diff] [blame] | 2135 | } |
Pavel Labath | 3ce324a | 2016-04-06 09:10:29 +0000 | [diff] [blame] | 2136 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2137 | |
| 2138 | if (!handled && signo && did_exec == false) |
| 2139 | { |
| 2140 | if (signo == SIGTRAP) |
| 2141 | { |
| 2142 | // Currently we are going to assume SIGTRAP means we are either |
| 2143 | // hitting a breakpoint or hardware single stepping. |
| 2144 | handled = true; |
| 2145 | addr_t pc = thread_sp->GetRegisterContext()->GetPC() + m_breakpoint_pc_offset; |
| 2146 | lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 2147 | |
| 2148 | if (bp_site_sp) |
| 2149 | { |
| 2150 | // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread, |
| 2151 | // we can just report no reason. We don't need to worry about stepping over the breakpoint here, that |
| 2152 | // will be taken care of when the thread resumes and notices that there's a breakpoint under the pc. |
| 2153 | if (bp_site_sp->ValidForThisThread (thread_sp.get())) |
| 2154 | { |
| 2155 | if(m_breakpoint_pc_offset != 0) |
| 2156 | thread_sp->GetRegisterContext()->SetPC(pc); |
| 2157 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID (*thread_sp, bp_site_sp->GetID())); |
| 2158 | } |
| 2159 | else |
| 2160 | { |
| 2161 | StopInfoSP invalid_stop_info_sp; |
| 2162 | thread_sp->SetStopInfo (invalid_stop_info_sp); |
| 2163 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2164 | } |
| 2165 | else |
| 2166 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2167 | // If we were stepping then assume the stop was the result of the trace. If we were |
| 2168 | // not stepping then report the SIGTRAP. |
| 2169 | // FIXME: We are still missing the case where we single step over a trap instruction. |
| 2170 | if (thread_sp->GetTemporaryResumeState() == eStateStepping) |
| 2171 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonToTrace (*thread_sp)); |
| 2172 | else |
| 2173 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal(*thread_sp, signo, description.c_str())); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2174 | } |
| 2175 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2176 | if (!handled) |
| 2177 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithSignal (*thread_sp, signo, description.c_str())); |
| 2178 | } |
| 2179 | |
| 2180 | if (!description.empty()) |
| 2181 | { |
| 2182 | lldb::StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); |
| 2183 | if (stop_info_sp) |
| 2184 | { |
| 2185 | const char *stop_info_desc = stop_info_sp->GetDescription(); |
| 2186 | if (!stop_info_desc || !stop_info_desc[0]) |
| 2187 | stop_info_sp->SetDescription (description.c_str()); |
| 2188 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2189 | else |
| 2190 | { |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2191 | thread_sp->SetStopInfo (StopInfo::CreateStopReasonWithException (*thread_sp, description.c_str())); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2192 | } |
| 2193 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | } |
| 2197 | } |
| 2198 | return thread_sp; |
| 2199 | } |
| 2200 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2201 | lldb::ThreadSP |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2202 | ProcessGDBRemote::SetThreadStopInfo (StructuredData::Dictionary *thread_dict) |
| 2203 | { |
| 2204 | static ConstString g_key_tid("tid"); |
| 2205 | static ConstString g_key_name("name"); |
| 2206 | static ConstString g_key_reason("reason"); |
| 2207 | static ConstString g_key_metype("metype"); |
| 2208 | static ConstString g_key_medata("medata"); |
| 2209 | static ConstString g_key_qaddr("qaddr"); |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2210 | static ConstString g_key_dispatch_queue_t("dispatch_queue_t"); |
| 2211 | static ConstString g_key_associated_with_dispatch_queue("associated_with_dispatch_queue"); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2212 | static ConstString g_key_queue_name("qname"); |
| 2213 | static ConstString g_key_queue_kind("qkind"); |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2214 | static ConstString g_key_queue_serial_number("qserialnum"); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2215 | static ConstString g_key_registers("registers"); |
| 2216 | static ConstString g_key_memory("memory"); |
| 2217 | static ConstString g_key_address("address"); |
| 2218 | static ConstString g_key_bytes("bytes"); |
| 2219 | static ConstString g_key_description("description"); |
Pavel Labath | 4a4bb12 | 2015-07-16 14:14:35 +0000 | [diff] [blame] | 2220 | static ConstString g_key_signal("signal"); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2221 | |
| 2222 | // Stop with signal and thread info |
| 2223 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
| 2224 | uint8_t signo = 0; |
| 2225 | std::string value; |
| 2226 | std::string thread_name; |
| 2227 | std::string reason; |
| 2228 | std::string description; |
| 2229 | uint32_t exc_type = 0; |
| 2230 | std::vector<addr_t> exc_data; |
| 2231 | addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; |
| 2232 | ExpeditedRegisterMap expedited_register_map; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2233 | bool queue_vars_valid = false; |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2234 | addr_t dispatch_queue_t = LLDB_INVALID_ADDRESS; |
| 2235 | LazyBool associated_with_dispatch_queue = eLazyBoolCalculate; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2236 | std::string queue_name; |
| 2237 | QueueKind queue_kind = eQueueKindUnknown; |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2238 | uint64_t queue_serial_number = 0; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2239 | // Iterate through all of the thread dictionary key/value pairs from the structured data dictionary |
| 2240 | |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2241 | thread_dict->ForEach([this, |
| 2242 | &tid, |
| 2243 | &expedited_register_map, |
| 2244 | &thread_name, |
| 2245 | &signo, |
| 2246 | &reason, |
| 2247 | &description, |
| 2248 | &exc_type, |
| 2249 | &exc_data, |
| 2250 | &thread_dispatch_qaddr, |
| 2251 | &queue_vars_valid, |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2252 | &associated_with_dispatch_queue, |
| 2253 | &dispatch_queue_t, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2254 | &queue_name, |
| 2255 | &queue_kind, |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2256 | &queue_serial_number] |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2257 | (ConstString key, StructuredData::Object* object) -> bool |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2258 | { |
| 2259 | if (key == g_key_tid) |
| 2260 | { |
| 2261 | // thread in big endian hex |
| 2262 | tid = object->GetIntegerValue(LLDB_INVALID_THREAD_ID); |
| 2263 | } |
| 2264 | else if (key == g_key_metype) |
| 2265 | { |
| 2266 | // exception type in big endian hex |
| 2267 | exc_type = object->GetIntegerValue(0); |
| 2268 | } |
| 2269 | else if (key == g_key_medata) |
| 2270 | { |
| 2271 | // exception data in big endian hex |
| 2272 | StructuredData::Array *array = object->GetAsArray(); |
| 2273 | if (array) |
| 2274 | { |
| 2275 | array->ForEach([&exc_data](StructuredData::Object* object) -> bool { |
| 2276 | exc_data.push_back(object->GetIntegerValue()); |
| 2277 | return true; // Keep iterating through all array items |
| 2278 | }); |
| 2279 | } |
| 2280 | } |
| 2281 | else if (key == g_key_name) |
| 2282 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2283 | thread_name = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2284 | } |
| 2285 | else if (key == g_key_qaddr) |
| 2286 | { |
| 2287 | thread_dispatch_qaddr = object->GetIntegerValue(LLDB_INVALID_ADDRESS); |
| 2288 | } |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2289 | else if (key == g_key_queue_name) |
| 2290 | { |
| 2291 | queue_vars_valid = true; |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2292 | queue_name = object->GetStringValue(); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2293 | } |
| 2294 | else if (key == g_key_queue_kind) |
| 2295 | { |
| 2296 | std::string queue_kind_str = object->GetStringValue(); |
| 2297 | if (queue_kind_str == "serial") |
| 2298 | { |
| 2299 | queue_vars_valid = true; |
| 2300 | queue_kind = eQueueKindSerial; |
| 2301 | } |
| 2302 | else if (queue_kind_str == "concurrent") |
| 2303 | { |
| 2304 | queue_vars_valid = true; |
| 2305 | queue_kind = eQueueKindConcurrent; |
| 2306 | } |
| 2307 | } |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2308 | else if (key == g_key_queue_serial_number) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2309 | { |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2310 | queue_serial_number = object->GetIntegerValue(0); |
| 2311 | if (queue_serial_number != 0) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2312 | queue_vars_valid = true; |
| 2313 | } |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2314 | else if (key == g_key_dispatch_queue_t) |
| 2315 | { |
| 2316 | dispatch_queue_t = object->GetIntegerValue(0); |
| 2317 | if (dispatch_queue_t != 0 && dispatch_queue_t != LLDB_INVALID_ADDRESS) |
| 2318 | queue_vars_valid = true; |
| 2319 | } |
| 2320 | else if (key == g_key_associated_with_dispatch_queue) |
| 2321 | { |
| 2322 | queue_vars_valid = true; |
| 2323 | bool associated = object->GetBooleanValue (); |
| 2324 | if (associated) |
| 2325 | associated_with_dispatch_queue = eLazyBoolYes; |
| 2326 | else |
| 2327 | associated_with_dispatch_queue = eLazyBoolNo; |
| 2328 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2329 | else if (key == g_key_reason) |
| 2330 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2331 | reason = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2332 | } |
| 2333 | else if (key == g_key_description) |
| 2334 | { |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2335 | description = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2336 | } |
| 2337 | else if (key == g_key_registers) |
| 2338 | { |
| 2339 | StructuredData::Dictionary *registers_dict = object->GetAsDictionary(); |
| 2340 | |
| 2341 | if (registers_dict) |
| 2342 | { |
| 2343 | registers_dict->ForEach([&expedited_register_map](ConstString key, StructuredData::Object* object) -> bool { |
| 2344 | const uint32_t reg = StringConvert::ToUInt32 (key.GetCString(), UINT32_MAX, 10); |
| 2345 | if (reg != UINT32_MAX) |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2346 | expedited_register_map[reg] = object->GetStringValue(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2347 | return true; // Keep iterating through all array items |
| 2348 | }); |
| 2349 | } |
| 2350 | } |
| 2351 | else if (key == g_key_memory) |
| 2352 | { |
| 2353 | StructuredData::Array *array = object->GetAsArray(); |
| 2354 | if (array) |
| 2355 | { |
| 2356 | array->ForEach([this](StructuredData::Object* object) -> bool { |
| 2357 | StructuredData::Dictionary *mem_cache_dict = object->GetAsDictionary(); |
| 2358 | if (mem_cache_dict) |
| 2359 | { |
| 2360 | lldb::addr_t mem_cache_addr = LLDB_INVALID_ADDRESS; |
| 2361 | if (mem_cache_dict->GetValueForKeyAsInteger<lldb::addr_t>("address", mem_cache_addr)) |
| 2362 | { |
| 2363 | if (mem_cache_addr != LLDB_INVALID_ADDRESS) |
| 2364 | { |
| 2365 | StringExtractor bytes; |
| 2366 | if (mem_cache_dict->GetValueForKeyAsString("bytes", bytes.GetStringRef())) |
| 2367 | { |
| 2368 | bytes.SetFilePos(0); |
| 2369 | |
| 2370 | const size_t byte_size = bytes.GetStringRef().size()/2; |
| 2371 | DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 2372 | const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); |
| 2373 | if (bytes_copied == byte_size) |
| 2374 | m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | } |
| 2379 | return true; // Keep iterating through all array items |
| 2380 | }); |
| 2381 | } |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 2382 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2383 | } |
Pavel Labath | 4a4bb12 | 2015-07-16 14:14:35 +0000 | [diff] [blame] | 2384 | else if (key == g_key_signal) |
| 2385 | signo = object->GetIntegerValue(LLDB_INVALID_SIGNAL_NUMBER); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2386 | return true; // Keep iterating through all dictionary key/value pairs |
| 2387 | }); |
| 2388 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2389 | return SetThreadStopInfo (tid, |
| 2390 | expedited_register_map, |
| 2391 | signo, |
| 2392 | thread_name, |
| 2393 | reason, |
| 2394 | description, |
| 2395 | exc_type, |
| 2396 | exc_data, |
| 2397 | thread_dispatch_qaddr, |
| 2398 | queue_vars_valid, |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2399 | associated_with_dispatch_queue, |
| 2400 | dispatch_queue_t, |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2401 | queue_name, |
| 2402 | queue_kind, |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2403 | queue_serial_number); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2404 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2405 | |
| 2406 | StateType |
| 2407 | ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet) |
| 2408 | { |
Greg Clayton | dd0e5a5 | 2011-06-02 22:22:38 +0000 | [diff] [blame] | 2409 | stop_packet.SetFilePos (0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2410 | const char stop_type = stop_packet.GetChar(); |
| 2411 | switch (stop_type) |
| 2412 | { |
| 2413 | case 'T': |
| 2414 | case 'S': |
| 2415 | { |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 2416 | // This is a bit of a hack, but is is required. If we did exec, we |
| 2417 | // need to clear our thread lists and also know to rebuild our dynamic |
| 2418 | // register info before we lookup and threads and populate the expedited |
| 2419 | // register values so we need to know this right away so we can cleanup |
| 2420 | // and update our registers. |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2421 | const uint32_t stop_id = GetStopID(); |
| 2422 | if (stop_id == 0) |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 2423 | { |
| 2424 | // Our first stop, make sure we have a process ID, and also make |
| 2425 | // sure we know about our registers |
| 2426 | if (GetID() == LLDB_INVALID_PROCESS_ID) |
| 2427 | { |
Greg Clayton | c574ede | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 2428 | lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID (); |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 2429 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 2430 | SetID (pid); |
| 2431 | } |
| 2432 | BuildDynamicRegisterInfo (true); |
| 2433 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2434 | // Stop with signal and thread info |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2435 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2436 | const uint8_t signo = stop_packet.GetHexU8(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2437 | std::string key; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2438 | std::string value; |
| 2439 | std::string thread_name; |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2440 | std::string reason; |
| 2441 | std::string description; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2442 | uint32_t exc_type = 0; |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 2443 | std::vector<addr_t> exc_data; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2444 | addr_t thread_dispatch_qaddr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2445 | bool queue_vars_valid = false; // says if locals below that start with "queue_" are valid |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2446 | addr_t dispatch_queue_t = LLDB_INVALID_ADDRESS; |
| 2447 | LazyBool associated_with_dispatch_queue = eLazyBoolCalculate; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2448 | std::string queue_name; |
| 2449 | QueueKind queue_kind = eQueueKindUnknown; |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2450 | uint64_t queue_serial_number = 0; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2451 | ExpeditedRegisterMap expedited_register_map; |
| 2452 | while (stop_packet.GetNameColonValue(key, value)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2453 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2454 | if (key.compare("metype") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2455 | { |
| 2456 | // exception type in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2457 | exc_type = StringConvert::ToUInt32 (value.c_str(), 0, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2458 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2459 | else if (key.compare("medata") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2460 | { |
| 2461 | // exception data in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2462 | exc_data.push_back(StringConvert::ToUInt64 (value.c_str(), 0, 16)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2463 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2464 | else if (key.compare("thread") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2465 | { |
| 2466 | // thread in big endian hex |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2467 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2468 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2469 | else if (key.compare("threads") == 0) |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2470 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2471 | std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex()); |
| 2472 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2473 | m_thread_ids.clear(); |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 2474 | // A comma separated list of all threads in the current |
| 2475 | // process that includes the thread for this stop reply |
| 2476 | // packet |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2477 | size_t comma_pos; |
| 2478 | lldb::tid_t tid; |
| 2479 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 2480 | { |
| 2481 | value[comma_pos] = '\0'; |
| 2482 | // thread in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2483 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2484 | if (tid != LLDB_INVALID_THREAD_ID) |
| 2485 | m_thread_ids.push_back (tid); |
| 2486 | value.erase(0, comma_pos + 1); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2487 | } |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2488 | tid = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_THREAD_ID, 16); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2489 | if (tid != LLDB_INVALID_THREAD_ID) |
| 2490 | m_thread_ids.push_back (tid); |
| 2491 | } |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 2492 | else if (key.compare("thread-pcs") == 0) |
| 2493 | { |
| 2494 | m_thread_pcs.clear(); |
| 2495 | // A comma separated list of all threads in the current |
| 2496 | // process that includes the thread for this stop reply |
| 2497 | // packet |
| 2498 | size_t comma_pos; |
| 2499 | lldb::addr_t pc; |
| 2500 | while ((comma_pos = value.find(',')) != std::string::npos) |
| 2501 | { |
| 2502 | value[comma_pos] = '\0'; |
| 2503 | // thread in big endian hex |
| 2504 | pc = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_ADDRESS, 16); |
| 2505 | if (pc != LLDB_INVALID_ADDRESS) |
| 2506 | m_thread_pcs.push_back (pc); |
| 2507 | value.erase(0, comma_pos + 1); |
| 2508 | } |
| 2509 | pc = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_ADDRESS, 16); |
| 2510 | if (pc != LLDB_INVALID_ADDRESS) |
| 2511 | m_thread_pcs.push_back (pc); |
| 2512 | } |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2513 | else if (key.compare("jstopinfo") == 0) |
Greg Clayton | a5801ad | 2015-07-15 22:59:03 +0000 | [diff] [blame] | 2514 | { |
| 2515 | StringExtractor json_extractor; |
| 2516 | // Swap "value" over into "name_extractor" |
| 2517 | json_extractor.GetStringRef().swap(value); |
| 2518 | // Now convert the HEX bytes into a string value |
| 2519 | json_extractor.GetHexByteString (value); |
| 2520 | |
| 2521 | // This JSON contains thread IDs and thread stop info for all threads. |
| 2522 | // It doesn't contain expedited registers, memory or queue info. |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2523 | m_jstopinfo_sp = StructuredData::ParseJSON (value); |
Greg Clayton | a5801ad | 2015-07-15 22:59:03 +0000 | [diff] [blame] | 2524 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2525 | else if (key.compare("hexname") == 0) |
Greg Clayton | de9d049 | 2011-01-08 03:17:57 +0000 | [diff] [blame] | 2526 | { |
| 2527 | StringExtractor name_extractor; |
| 2528 | // Swap "value" over into "name_extractor" |
| 2529 | name_extractor.GetStringRef().swap(value); |
| 2530 | // Now convert the HEX bytes into a string value |
| 2531 | name_extractor.GetHexByteString (value); |
| 2532 | thread_name.swap (value); |
| 2533 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2534 | else if (key.compare("name") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2535 | { |
| 2536 | thread_name.swap (value); |
| 2537 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2538 | else if (key.compare("qaddr") == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2539 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2540 | thread_dispatch_qaddr = StringConvert::ToUInt64 (value.c_str(), 0, 16); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2541 | } |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2542 | else if (key.compare("dispatch_queue_t") == 0) |
| 2543 | { |
| 2544 | queue_vars_valid = true; |
| 2545 | dispatch_queue_t = StringConvert::ToUInt64 (value.c_str(), 0, 16); |
| 2546 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2547 | else if (key.compare("qname") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2548 | { |
| 2549 | queue_vars_valid = true; |
| 2550 | StringExtractor name_extractor; |
| 2551 | // Swap "value" over into "name_extractor" |
| 2552 | name_extractor.GetStringRef().swap(value); |
| 2553 | // Now convert the HEX bytes into a string value |
| 2554 | name_extractor.GetHexByteString (value); |
| 2555 | queue_name.swap (value); |
| 2556 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2557 | else if (key.compare("qkind") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2558 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2559 | if (value == "serial") |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2560 | { |
| 2561 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2562 | queue_kind = eQueueKindSerial; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2563 | } |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2564 | else if (value == "concurrent") |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2565 | { |
| 2566 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2567 | queue_kind = eQueueKindConcurrent; |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2568 | } |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2569 | } |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2570 | else if (key.compare("qserialnum") == 0) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2571 | { |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2572 | queue_serial_number = StringConvert::ToUInt64 (value.c_str(), 0, 0); |
| 2573 | if (queue_serial_number != 0) |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2574 | queue_vars_valid = true; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 2575 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2576 | else if (key.compare("reason") == 0) |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2577 | { |
| 2578 | reason.swap(value); |
| 2579 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2580 | else if (key.compare("description") == 0) |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2581 | { |
| 2582 | StringExtractor desc_extractor; |
| 2583 | // Swap "value" over into "name_extractor" |
| 2584 | desc_extractor.GetStringRef().swap(value); |
| 2585 | // Now convert the HEX bytes into a string value |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 2586 | desc_extractor.GetHexByteString (value); |
| 2587 | description.swap(value); |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 2588 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2589 | else if (key.compare("memory") == 0) |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2590 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2591 | // Expedited memory. GDB servers can choose to send back expedited memory |
| 2592 | // that can populate the L1 memory cache in the process so that things like |
| 2593 | // the frame pointer backchain can be expedited. This will help stack |
| 2594 | // backtracing be more efficient by not having to send as many memory read |
| 2595 | // requests down the remote GDB server. |
Chaoren Lin | 7a30608 | 2015-06-23 03:17:01 +0000 | [diff] [blame] | 2596 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2597 | // Key/value pair format: memory:<addr>=<bytes>; |
| 2598 | // <addr> is a number whose base will be interpreted by the prefix: |
| 2599 | // "0x[0-9a-fA-F]+" for hex |
| 2600 | // "0[0-7]+" for octal |
| 2601 | // "[1-9]+" for decimal |
| 2602 | // <bytes> is native endian ASCII hex bytes just like the register values |
| 2603 | llvm::StringRef value_ref(value); |
| 2604 | std::pair<llvm::StringRef, llvm::StringRef> pair; |
| 2605 | pair = value_ref.split('='); |
| 2606 | if (!pair.first.empty() && !pair.second.empty()) |
| 2607 | { |
| 2608 | std::string addr_str(pair.first.str()); |
| 2609 | const lldb::addr_t mem_cache_addr = StringConvert::ToUInt64(addr_str.c_str(), LLDB_INVALID_ADDRESS, 0); |
| 2610 | if (mem_cache_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2611 | { |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2612 | StringExtractor bytes; |
Pavel Labath | 3a29f8b | 2015-07-28 09:18:32 +0000 | [diff] [blame] | 2613 | bytes.GetStringRef() = pair.second.str(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2614 | const size_t byte_size = bytes.GetStringRef().size()/2; |
| 2615 | DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); |
| 2616 | const size_t bytes_copied = bytes.GetHexBytes (data_buffer_sp->GetBytes(), byte_size, 0); |
| 2617 | if (bytes_copied == byte_size) |
| 2618 | m_memory_cache.AddL1CacheData(mem_cache_addr, data_buffer_sp); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2619 | } |
| 2620 | } |
| 2621 | } |
Jaydeep Patil | 725666c | 2015-08-13 03:46:01 +0000 | [diff] [blame] | 2622 | else if (key.compare("watch") == 0 || key.compare("rwatch") == 0 || key.compare("awatch") == 0) |
| 2623 | { |
| 2624 | // Support standard GDB remote stop reply packet 'TAAwatch:addr' |
| 2625 | lldb::addr_t wp_addr = StringConvert::ToUInt64 (value.c_str(), LLDB_INVALID_ADDRESS, 16); |
| 2626 | WatchpointSP wp_sp = GetTarget().GetWatchpointList().FindByAddress(wp_addr); |
| 2627 | uint32_t wp_index = LLDB_INVALID_INDEX32; |
| 2628 | |
| 2629 | if (wp_sp) |
| 2630 | wp_index = wp_sp->GetHardwareIndex(); |
| 2631 | |
| 2632 | reason = "watchpoint"; |
| 2633 | StreamString ostr; |
| 2634 | ostr.Printf("%" PRIu64 " %" PRIu32, wp_addr, wp_index); |
| 2635 | description = ostr.GetString().c_str(); |
| 2636 | } |
Stephane Sezer | 2618e91 | 2015-08-21 16:51:56 +0000 | [diff] [blame] | 2637 | else if (key.compare("library") == 0) |
| 2638 | { |
| 2639 | LoadModules(); |
| 2640 | } |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2641 | else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) |
| 2642 | { |
| 2643 | uint32_t reg = StringConvert::ToUInt32 (key.c_str(), UINT32_MAX, 16); |
| 2644 | if (reg != UINT32_MAX) |
| 2645 | expedited_register_map[reg] = std::move(value); |
| 2646 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2647 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2648 | |
Bhushan D. Attarde | 1e271df | 2015-07-24 04:06:20 +0000 | [diff] [blame] | 2649 | if (tid == LLDB_INVALID_THREAD_ID) |
| 2650 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2651 | // A thread id may be invalid if the response is old style 'S' packet which does not provide the |
Bhushan D. Attarde | 1e271df | 2015-07-24 04:06:20 +0000 | [diff] [blame] | 2652 | // thread information. So update the thread list and choose the first one. |
| 2653 | UpdateThreadIDList (); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2654 | |
Bhushan D. Attarde | 1e271df | 2015-07-24 04:06:20 +0000 | [diff] [blame] | 2655 | if (!m_thread_ids.empty ()) |
| 2656 | { |
| 2657 | tid = m_thread_ids.front (); |
| 2658 | } |
| 2659 | } |
| 2660 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2661 | ThreadSP thread_sp = SetThreadStopInfo (tid, |
| 2662 | expedited_register_map, |
| 2663 | signo, |
| 2664 | thread_name, |
| 2665 | reason, |
| 2666 | description, |
| 2667 | exc_type, |
| 2668 | exc_data, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2669 | thread_dispatch_qaddr, |
| 2670 | queue_vars_valid, |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 2671 | associated_with_dispatch_queue, |
| 2672 | dispatch_queue_t, |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2673 | queue_name, |
| 2674 | queue_kind, |
Jason Molenda | 26d84e8 | 2016-01-08 00:20:48 +0000 | [diff] [blame] | 2675 | queue_serial_number); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2676 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2677 | return eStateStopped; |
| 2678 | } |
| 2679 | break; |
| 2680 | |
| 2681 | case 'W': |
Todd Fiala | ff6131a | 2014-05-19 04:57:23 +0000 | [diff] [blame] | 2682 | case 'X': |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2683 | // process exited |
| 2684 | return eStateExited; |
| 2685 | |
| 2686 | default: |
| 2687 | break; |
| 2688 | } |
| 2689 | return eStateInvalid; |
| 2690 | } |
| 2691 | |
| 2692 | void |
| 2693 | ProcessGDBRemote::RefreshStateAfterStop () |
| 2694 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2695 | std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex()); |
| 2696 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2697 | m_thread_ids.clear(); |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 2698 | m_thread_pcs.clear(); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2699 | // Set the thread stop info. It might have a "threads" key whose value is |
| 2700 | // a list of all thread IDs in the current process, so m_thread_ids might |
| 2701 | // get set. |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2702 | |
| 2703 | // Scope for the lock |
| 2704 | { |
| 2705 | // Lock the thread stack while we access it |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 2706 | std::lock_guard<std::recursive_mutex> guard(m_last_stop_packet_mutex); |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2707 | // Get the number of stop packets on the stack |
| 2708 | int nItems = m_stop_packet_stack.size(); |
| 2709 | // Iterate over them |
| 2710 | for (int i = 0; i < nItems; i++) |
| 2711 | { |
| 2712 | // Get the thread stop info |
| 2713 | StringExtractorGDBRemote stop_info = m_stop_packet_stack[i]; |
| 2714 | // Process thread stop info |
| 2715 | SetThreadStopInfo(stop_info); |
| 2716 | } |
| 2717 | // Clear the thread stop stack |
| 2718 | m_stop_packet_stack.clear(); |
| 2719 | } |
| 2720 | |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2721 | // Check to see if SetThreadStopInfo() filled in m_thread_ids? |
| 2722 | if (m_thread_ids.empty()) |
| 2723 | { |
| 2724 | // No, we need to fetch the thread list manually |
| 2725 | UpdateThreadIDList(); |
| 2726 | } |
| 2727 | |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 2728 | // If we have queried for a default thread id |
| 2729 | if (m_initial_tid != LLDB_INVALID_THREAD_ID) |
| 2730 | { |
| 2731 | m_thread_list.SetSelectedThreadByID(m_initial_tid); |
| 2732 | m_initial_tid = LLDB_INVALID_THREAD_ID; |
| 2733 | } |
| 2734 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2735 | // Let all threads recover from stopping and do any clean up based |
| 2736 | // on the previous thread state (if any). |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 2737 | m_thread_list_real.RefreshStateAfterStop(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2738 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | Error |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2742 | ProcessGDBRemote::DoHalt (bool &caused_stop) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2743 | { |
| 2744 | Error error; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2745 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2746 | if (m_public_state.GetValue() == eStateAttaching) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2747 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2748 | // We are being asked to halt during an attach. We need to just close |
| 2749 | // our file handle and debugserver will go away, and we can be done... |
| 2750 | m_gdb_comm.Disconnect(); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2751 | } |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2752 | else |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 2753 | caused_stop = m_gdb_comm.Interrupt(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2754 | return error; |
| 2755 | } |
| 2756 | |
| 2757 | Error |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2758 | ProcessGDBRemote::DoDetach(bool keep_stopped) |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2759 | { |
| 2760 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2761 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2762 | if (log) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2763 | log->Printf ("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2764 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2765 | error = m_gdb_comm.Detach (keep_stopped); |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2766 | if (log) |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2767 | { |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2768 | if (error.Success()) |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2769 | log->PutCString ("ProcessGDBRemote::DoDetach() detach packet sent successfully"); |
| 2770 | else |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2771 | 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] | 2772 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2773 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 2774 | if (!error.Success()) |
| 2775 | return error; |
| 2776 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2777 | // Sleep for one second to let the process get all detached... |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2778 | StopAsyncThread (); |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2779 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 2780 | SetPrivateState (eStateDetached); |
| 2781 | ResumePrivateStateThread(); |
| 2782 | |
| 2783 | //KillDebugserverProcess (); |
Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 2784 | return error; |
| 2785 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2786 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 2787 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2788 | Error |
| 2789 | ProcessGDBRemote::DoDestroy () |
| 2790 | { |
| 2791 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2792 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2793 | if (log) |
| 2794 | log->Printf ("ProcessGDBRemote::DoDestroy()"); |
| 2795 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2796 | // There is a bug in older iOS debugservers where they don't shut down the process |
| 2797 | // they are debugging properly. If the process is sitting at a breakpoint or an exception, |
| 2798 | // this can cause problems with restarting. So we check to see if any of our threads are stopped |
| 2799 | // at a breakpoint, and if so we remove all the breakpoints, resume the process, and THEN |
| 2800 | // destroy it again. |
| 2801 | // |
| 2802 | // Note, we don't have a good way to test the version of debugserver, but I happen to know that |
| 2803 | // the set of all the iOS debugservers which don't support GetThreadSuffixSupported() and that of |
| 2804 | // the debugservers with this bug are equal. There really should be a better way to test this! |
| 2805 | // |
| 2806 | // We also use m_destroy_tried_resuming to make sure we only do this once, if we resume and then halt and |
| 2807 | // get called here to destroy again and we're still at a breakpoint or exception, then we should |
| 2808 | // just do the straight-forward kill. |
| 2809 | // |
| 2810 | // And of course, if we weren't able to stop the process by the time we get here, it isn't |
| 2811 | // necessary (or helpful) to do any of this. |
| 2812 | |
| 2813 | if (!m_gdb_comm.GetThreadSuffixSupported() && m_public_state.GetValue() != eStateRunning) |
| 2814 | { |
| 2815 | PlatformSP platform_sp = GetTarget().GetPlatform(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2816 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2817 | // FIXME: These should be ConstStrings so we aren't doing strcmp'ing. |
| 2818 | if (platform_sp |
| 2819 | && platform_sp->GetName() |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 2820 | && platform_sp->GetName() == PlatformRemoteiOS::GetPluginNameStatic()) |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2821 | { |
| 2822 | if (m_destroy_tried_resuming) |
| 2823 | { |
| 2824 | if (log) |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2825 | 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] | 2826 | } |
| 2827 | else |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2828 | { |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2829 | // At present, the plans are discarded and the breakpoints disabled Process::Destroy, |
| 2830 | // but we really need it to happen here and it doesn't matter if we do it twice. |
| 2831 | m_thread_list.DiscardThreadPlans(); |
| 2832 | DisableAllBreakpointSites(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2833 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2834 | bool stop_looks_like_crash = false; |
| 2835 | ThreadList &threads = GetThreadList(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2836 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2837 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2838 | std::lock_guard<std::recursive_mutex> guard(threads.GetMutex()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2839 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2840 | size_t num_threads = threads.GetSize(); |
| 2841 | for (size_t i = 0; i < num_threads; i++) |
| 2842 | { |
| 2843 | ThreadSP thread_sp = threads.GetThreadAtIndex(i); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2844 | StopInfoSP stop_info_sp = thread_sp->GetPrivateStopInfo(); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2845 | StopReason reason = eStopReasonInvalid; |
| 2846 | if (stop_info_sp) |
| 2847 | reason = stop_info_sp->GetStopReason(); |
| 2848 | if (reason == eStopReasonBreakpoint |
| 2849 | || reason == eStopReasonException) |
| 2850 | { |
| 2851 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2852 | log->Printf ("ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64 " stopped with reason: %s.", |
| 2853 | thread_sp->GetProtocolID(), |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2854 | stop_info_sp->GetDescription()); |
| 2855 | stop_looks_like_crash = true; |
| 2856 | break; |
| 2857 | } |
| 2858 | } |
| 2859 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2860 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2861 | if (stop_looks_like_crash) |
| 2862 | { |
| 2863 | if (log) |
| 2864 | log->PutCString ("ProcessGDBRemote::DoDestroy() - Stopped at a breakpoint, continue and then kill."); |
| 2865 | m_destroy_tried_resuming = true; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2866 | |
| 2867 | // If we are going to run again before killing, it would be good to suspend all the threads |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2868 | // before resuming so they won't get into more trouble. Sadly, for the threads stopped with |
| 2869 | // the breakpoint or exception, the exception doesn't get cleared if it is suspended, so we do |
| 2870 | // have to run the risk of letting those threads proceed a bit. |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2871 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2872 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2873 | std::lock_guard<std::recursive_mutex> guard(threads.GetMutex()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2874 | |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2875 | size_t num_threads = threads.GetSize(); |
| 2876 | for (size_t i = 0; i < num_threads; i++) |
| 2877 | { |
| 2878 | ThreadSP thread_sp = threads.GetThreadAtIndex(i); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2879 | StopInfoSP stop_info_sp = thread_sp->GetPrivateStopInfo(); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2880 | StopReason reason = eStopReasonInvalid; |
| 2881 | if (stop_info_sp) |
| 2882 | reason = stop_info_sp->GetStopReason(); |
| 2883 | if (reason != eStopReasonBreakpoint |
| 2884 | && reason != eStopReasonException) |
| 2885 | { |
| 2886 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2887 | log->Printf ("ProcessGDBRemote::DoDestroy() - Suspending thread: 0x%4.4" PRIx64 " before running.", |
| 2888 | thread_sp->GetProtocolID()); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2889 | thread_sp->SetResumeState(eStateSuspended); |
| 2890 | } |
| 2891 | } |
| 2892 | } |
| 2893 | Resume (); |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 2894 | return Destroy(false); |
Jim Ingham | 43c555d | 2012-07-04 00:35:43 +0000 | [diff] [blame] | 2895 | } |
| 2896 | } |
| 2897 | } |
| 2898 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 2899 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2900 | // Interrupt if our inferior is running... |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2901 | int exit_status = SIGABRT; |
| 2902 | std::string exit_string; |
| 2903 | |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 2904 | if (m_gdb_comm.IsConnected()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2905 | { |
Jim Ingham | aab7837 | 2011-10-28 01:11:35 +0000 | [diff] [blame] | 2906 | if (m_public_state.GetValue() != eStateAttaching) |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2907 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2908 | StringExtractorGDBRemote response; |
| 2909 | bool send_async = true; |
Tamas Berghammer | 912800c | 2015-02-24 10:23:39 +0000 | [diff] [blame] | 2910 | GDBRemoteCommunication::ScopedTimeout (m_gdb_comm, 3); |
Filipe Cabecinhas | 9e10605 | 2012-08-22 13:25:58 +0000 | [diff] [blame] | 2911 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2912 | 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] | 2913 | { |
| 2914 | char packet_cmd = response.GetChar(0); |
| 2915 | |
| 2916 | if (packet_cmd == 'W' || packet_cmd == 'X') |
| 2917 | { |
Jim Ingham | eac0aa4 | 2014-02-21 22:36:11 +0000 | [diff] [blame] | 2918 | #if defined(__APPLE__) |
Jason Molenda | 17b4539 | 2016-06-23 04:24:16 +0000 | [diff] [blame] | 2919 | // For Native processes on Mac OS X, we launch through the Host Platform, then hand the process off |
Jim Ingham | 9d67cc5 | 2014-02-21 22:35:29 +0000 | [diff] [blame] | 2920 | // to debugserver, which becomes the parent process through "PT_ATTACH". Then when we go to kill |
Jason Molenda | 17b4539 | 2016-06-23 04:24:16 +0000 | [diff] [blame] | 2921 | // the process on Mac OS X we call ptrace(PT_KILL) to kill it, then we call waitpid which returns |
Jim Ingham | 9d67cc5 | 2014-02-21 22:35:29 +0000 | [diff] [blame] | 2922 | // with no error and the correct status. But amusingly enough that doesn't seem to actually reap |
| 2923 | // the process, but instead it is left around as a Zombie. Probably the kernel is in the process of |
| 2924 | // switching ownership back to lldb which was the original parent, and gets confused in the handoff. |
| 2925 | // Anyway, so call waitpid here to finally reap it. |
| 2926 | PlatformSP platform_sp(GetTarget().GetPlatform()); |
| 2927 | if (platform_sp && platform_sp->IsHost()) |
| 2928 | { |
| 2929 | int status; |
| 2930 | ::pid_t reap_pid; |
| 2931 | reap_pid = waitpid (GetID(), &status, WNOHANG); |
| 2932 | if (log) |
| 2933 | log->Printf ("Reaped pid: %d, status: %d.\n", reap_pid, status); |
| 2934 | } |
| 2935 | #endif |
Greg Clayton | 09c3e3d | 2011-12-06 04:51:14 +0000 | [diff] [blame] | 2936 | SetLastStopPacket (response); |
Greg Clayton | 9e92090 | 2012-04-10 02:25:43 +0000 | [diff] [blame] | 2937 | ClearThreadIDList (); |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2938 | exit_status = response.GetHexU8(); |
| 2939 | } |
| 2940 | else |
| 2941 | { |
| 2942 | if (log) |
| 2943 | log->Printf ("ProcessGDBRemote::DoDestroy - got unexpected response to k packet: %s", response.GetStringRef().c_str()); |
| 2944 | exit_string.assign("got unexpected response to k packet: "); |
| 2945 | exit_string.append(response.GetStringRef()); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | else |
| 2949 | { |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2950 | if (log) |
| 2951 | log->Printf ("ProcessGDBRemote::DoDestroy - failed to send k packet"); |
| 2952 | exit_string.assign("failed to send the k packet"); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2953 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2954 | } |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2955 | else |
| 2956 | { |
| 2957 | if (log) |
Ed Maste | b3a5333 | 2014-03-17 17:05:22 +0000 | [diff] [blame] | 2958 | log->Printf ("ProcessGDBRemote::DoDestroy - killed or interrupted while attaching"); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 2959 | exit_string.assign ("killed or interrupted while attaching."); |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2960 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2961 | } |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 2962 | else |
| 2963 | { |
| 2964 | // If we missed setting the exit status on the way out, do it here. |
| 2965 | // NB set exit status can be called multiple times, the first one sets the status. |
| 2966 | exit_string.assign("destroying when not connected to debugserver"); |
| 2967 | } |
| 2968 | |
| 2969 | SetExitStatus(exit_status, exit_string.c_str()); |
| 2970 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2971 | StopAsyncThread (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2972 | KillDebugserverProcess (); |
| 2973 | return error; |
| 2974 | } |
| 2975 | |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2976 | void |
| 2977 | ProcessGDBRemote::SetLastStopPacket (const StringExtractorGDBRemote &response) |
| 2978 | { |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2979 | const bool did_exec = response.GetStringRef().find(";reason:exec;") != std::string::npos; |
| 2980 | if (did_exec) |
| 2981 | { |
| 2982 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
| 2983 | if (log) |
| 2984 | log->Printf ("ProcessGDBRemote::SetLastStopPacket () - detected exec"); |
| 2985 | |
| 2986 | m_thread_list_real.Clear(); |
| 2987 | m_thread_list.Clear(); |
| 2988 | BuildDynamicRegisterInfo (true); |
Greg Clayton | 2e59d4f | 2015-06-29 20:08:51 +0000 | [diff] [blame] | 2989 | m_gdb_comm.ResetDiscoverableSettings (did_exec); |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 2990 | } |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 2991 | |
| 2992 | // Scope the lock |
| 2993 | { |
| 2994 | // Lock the thread stack while we access it |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 2995 | std::lock_guard<std::recursive_mutex> guard(m_last_stop_packet_mutex); |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 2996 | |
| 2997 | // We are are not using non-stop mode, there can only be one last stop |
| 2998 | // reply packet, so clear the list. |
| 2999 | if (GetTarget().GetNonStopModeEnabled() == false) |
| 3000 | m_stop_packet_stack.clear(); |
| 3001 | |
Ewan Crawford | 9aa2da00 | 2015-05-27 14:12:34 +0000 | [diff] [blame] | 3002 | // Add this stop packet to the stop packet stack |
| 3003 | // This stack will get popped and examined when we switch to the |
| 3004 | // Stopped state |
| 3005 | m_stop_packet_stack.push_back(response); |
| 3006 | } |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
Chaoren Lin | c963a22 | 2015-09-01 16:58:45 +0000 | [diff] [blame] | 3009 | void |
| 3010 | ProcessGDBRemote::SetUnixSignals(const UnixSignalsSP &signals_sp) |
| 3011 | { |
| 3012 | Process::SetUnixSignals(std::make_shared<GDBRemoteSignals>(signals_sp)); |
| 3013 | } |
| 3014 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3015 | //------------------------------------------------------------------ |
| 3016 | // Process Queries |
| 3017 | //------------------------------------------------------------------ |
| 3018 | |
| 3019 | bool |
| 3020 | ProcessGDBRemote::IsAlive () |
| 3021 | { |
Jason Molenda | 1d3b356 | 2015-11-05 23:54:29 +0000 | [diff] [blame] | 3022 | return m_gdb_comm.IsConnected() && Process::IsAlive(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | addr_t |
| 3026 | ProcessGDBRemote::GetImageInfoAddress() |
| 3027 | { |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 3028 | // request the link map address via the $qShlibInfoAddr packet |
| 3029 | lldb::addr_t addr = m_gdb_comm.GetShlibInfoAddr(); |
| 3030 | |
| 3031 | // the loaded module list can also provides a link map address |
| 3032 | if (addr == LLDB_INVALID_ADDRESS) |
| 3033 | { |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 3034 | LoadedModuleInfoList list; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 3035 | if (GetLoadedModuleList (list).Success()) |
| 3036 | addr = list.m_link_map; |
| 3037 | } |
| 3038 | |
| 3039 | return addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 3042 | void |
| 3043 | ProcessGDBRemote::WillPublicStop () |
| 3044 | { |
| 3045 | // See if the GDB remote client supports the JSON threads info. |
| 3046 | // If so, we gather stop info for all threads, expedited registers, |
| 3047 | // expedited memory, runtime queue information (iOS and MacOSX only), |
| 3048 | // and more. Expediting memory will help stack backtracing be much |
| 3049 | // faster. Expediting registers will make sure we don't have to read |
| 3050 | // the thread registers for GPRs. |
| 3051 | m_jthreadsinfo_sp = m_gdb_comm.GetThreadsInfo(); |
| 3052 | |
| 3053 | if (m_jthreadsinfo_sp) |
| 3054 | { |
| 3055 | // Now set the stop info for each thread and also expedite any registers |
| 3056 | // and memory that was in the jThreadsInfo response. |
| 3057 | StructuredData::Array *thread_infos = m_jthreadsinfo_sp->GetAsArray(); |
| 3058 | if (thread_infos) |
| 3059 | { |
| 3060 | const size_t n = thread_infos->GetSize(); |
| 3061 | for (size_t i=0; i<n; ++i) |
| 3062 | { |
| 3063 | StructuredData::Dictionary *thread_dict = thread_infos->GetItemAtIndex(i)->GetAsDictionary(); |
| 3064 | if (thread_dict) |
| 3065 | SetThreadStopInfo(thread_dict); |
| 3066 | } |
| 3067 | } |
| 3068 | } |
| 3069 | } |
| 3070 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3071 | //------------------------------------------------------------------ |
| 3072 | // Process Memory |
| 3073 | //------------------------------------------------------------------ |
| 3074 | size_t |
| 3075 | ProcessGDBRemote::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 3076 | { |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 3077 | GetMaxMemorySize (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3078 | if (size > m_max_memory_size) |
| 3079 | { |
| 3080 | // Keep memory read sizes down to a sane limit. This function will be |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3081 | // called multiple times in order to complete the task by |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3082 | // lldb_private::Process so it is ok to do this. |
| 3083 | size = m_max_memory_size; |
| 3084 | } |
| 3085 | |
| 3086 | char packet[64]; |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 3087 | int packet_len; |
| 3088 | bool binary_memory_read = m_gdb_comm.GetxPacketSupported(); |
Pavel Labath | 3bf1125 | 2015-10-14 12:59:37 +0000 | [diff] [blame] | 3089 | packet_len = ::snprintf(packet, sizeof(packet), "%c%" PRIx64 ",%" PRIx64, |
| 3090 | binary_memory_read ? 'x' : 'm', (uint64_t)addr, (uint64_t)size); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 3091 | assert (packet_len + 1 < (int)sizeof(packet)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3092 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3093 | 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] | 3094 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3095 | if (response.IsNormalResponse()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3096 | { |
| 3097 | error.Clear(); |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 3098 | if (binary_memory_read) |
| 3099 | { |
| 3100 | // The lower level GDBRemoteCommunication packet receive layer has already de-quoted any |
| 3101 | // 0x7d character escaping that was present in the packet |
| 3102 | |
| 3103 | size_t data_received_size = response.GetBytesLeft(); |
| 3104 | if (data_received_size > size) |
| 3105 | { |
| 3106 | // Don't write past the end of BUF if the remote debug server gave us too |
| 3107 | // much data for some reason. |
| 3108 | data_received_size = size; |
| 3109 | } |
| 3110 | memcpy (buf, response.GetStringRef().data(), data_received_size); |
| 3111 | return data_received_size; |
| 3112 | } |
| 3113 | else |
| 3114 | { |
| 3115 | return response.GetHexBytes(buf, size, '\xdd'); |
| 3116 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3117 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3118 | else if (response.IsErrorResponse()) |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 3119 | error.SetErrorStringWithFormat("memory read failed for 0x%" PRIx64, addr); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3120 | else if (response.IsUnsupportedResponse()) |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3121 | error.SetErrorStringWithFormat("GDB server does not support reading memory"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3122 | else |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3123 | 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] | 3124 | } |
| 3125 | else |
| 3126 | { |
Jim Ingham | 35579dd | 2013-06-03 19:34:01 +0000 | [diff] [blame] | 3127 | error.SetErrorStringWithFormat("failed to send packet: '%s'", packet); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3128 | } |
| 3129 | return 0; |
| 3130 | } |
| 3131 | |
| 3132 | size_t |
| 3133 | ProcessGDBRemote::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 3134 | { |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 3135 | GetMaxMemorySize (); |
Greg Clayton | b4aaf2e | 2011-05-16 02:35:02 +0000 | [diff] [blame] | 3136 | if (size > m_max_memory_size) |
| 3137 | { |
| 3138 | // Keep memory read sizes down to a sane limit. This function will be |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3139 | // called multiple times in order to complete the task by |
Greg Clayton | b4aaf2e | 2011-05-16 02:35:02 +0000 | [diff] [blame] | 3140 | // lldb_private::Process so it is ok to do this. |
| 3141 | size = m_max_memory_size; |
| 3142 | } |
| 3143 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3144 | StreamString packet; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3145 | packet.Printf("M%" PRIx64 ",%" PRIx64 ":", addr, (uint64_t)size); |
Bruce Mitchener | 9ccb970 | 2015-11-07 04:40:13 +0000 | [diff] [blame] | 3146 | packet.PutBytesAsRawHex8(buf, size, endian::InlHostByteOrder(), endian::InlHostByteOrder()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3147 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3148 | 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] | 3149 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3150 | if (response.IsOKResponse()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3151 | { |
| 3152 | error.Clear(); |
| 3153 | return size; |
| 3154 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3155 | else if (response.IsErrorResponse()) |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 3156 | error.SetErrorStringWithFormat("memory write failed for 0x%" PRIx64, addr); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 3157 | else if (response.IsUnsupportedResponse()) |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3158 | error.SetErrorStringWithFormat("GDB server does not support writing memory"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3159 | else |
Greg Clayton | 9944cd7 | 2012-09-19 01:46:31 +0000 | [diff] [blame] | 3160 | 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] | 3161 | } |
| 3162 | else |
| 3163 | { |
Jim Ingham | 35579dd | 2013-06-03 19:34:01 +0000 | [diff] [blame] | 3164 | error.SetErrorStringWithFormat("failed to send packet: '%s'", packet.GetString().c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3165 | } |
| 3166 | return 0; |
| 3167 | } |
| 3168 | |
| 3169 | lldb::addr_t |
| 3170 | ProcessGDBRemote::DoAllocateMemory (size_t size, uint32_t permissions, Error &error) |
| 3171 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3172 | Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS|LIBLLDB_LOG_EXPRESSIONS)); |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3173 | addr_t allocated_addr = LLDB_INVALID_ADDRESS; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3174 | |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 3175 | if (m_gdb_comm.SupportsAllocDeallocMemory() != eLazyBoolNo) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3176 | { |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 3177 | allocated_addr = m_gdb_comm.AllocateMemory (size, permissions); |
| 3178 | if (allocated_addr != LLDB_INVALID_ADDRESS || m_gdb_comm.SupportsAllocDeallocMemory() == eLazyBoolYes) |
| 3179 | return allocated_addr; |
| 3180 | } |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3181 | |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 3182 | if (m_gdb_comm.SupportsAllocDeallocMemory() == eLazyBoolNo) |
| 3183 | { |
| 3184 | // Call mmap() to create memory in the inferior.. |
| 3185 | unsigned prot = 0; |
| 3186 | if (permissions & lldb::ePermissionsReadable) |
| 3187 | prot |= eMmapProtRead; |
| 3188 | if (permissions & lldb::ePermissionsWritable) |
| 3189 | prot |= eMmapProtWrite; |
| 3190 | if (permissions & lldb::ePermissionsExecutable) |
| 3191 | prot |= eMmapProtExec; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3192 | |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 3193 | if (InferiorCallMmap(this, allocated_addr, 0, size, prot, |
| 3194 | eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) |
| 3195 | m_addr_to_mmap_size[allocated_addr] = size; |
| 3196 | else |
| 3197 | { |
| 3198 | allocated_addr = LLDB_INVALID_ADDRESS; |
| 3199 | if (log) |
| 3200 | log->Printf ("ProcessGDBRemote::%s no direct stub support for memory allocation, and InferiorCallMmap also failed - is stub missing register context save/restore capability?", __FUNCTION__); |
| 3201 | } |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 3202 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3203 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3204 | if (allocated_addr == LLDB_INVALID_ADDRESS) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3205 | 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] | 3206 | else |
| 3207 | error.Clear(); |
| 3208 | return allocated_addr; |
| 3209 | } |
| 3210 | |
| 3211 | Error |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3212 | ProcessGDBRemote::GetMemoryRegionInfo (addr_t load_addr, |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 3213 | MemoryRegionInfo ®ion_info) |
| 3214 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3215 | |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 3216 | Error error (m_gdb_comm.GetMemoryRegionInfo (load_addr, region_info)); |
| 3217 | return error; |
| 3218 | } |
| 3219 | |
| 3220 | Error |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 3221 | ProcessGDBRemote::GetWatchpointSupportInfo (uint32_t &num) |
| 3222 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3223 | |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 3224 | Error error (m_gdb_comm.GetWatchpointSupportInfo (num)); |
| 3225 | return error; |
| 3226 | } |
| 3227 | |
| 3228 | Error |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 3229 | ProcessGDBRemote::GetWatchpointSupportInfo (uint32_t &num, bool& after) |
| 3230 | { |
Jaydeep Patil | 725666c | 2015-08-13 03:46:01 +0000 | [diff] [blame] | 3231 | Error error (m_gdb_comm.GetWatchpointSupportInfo (num, after, GetTarget().GetArchitecture())); |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 3232 | return error; |
| 3233 | } |
| 3234 | |
| 3235 | Error |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3236 | ProcessGDBRemote::DoDeallocateMemory (lldb::addr_t addr) |
| 3237 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3238 | Error error; |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3239 | LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory(); |
| 3240 | |
| 3241 | switch (supported) |
| 3242 | { |
| 3243 | case eLazyBoolCalculate: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3244 | // We should never be deallocating memory without allocating memory |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3245 | // first so we should never get eLazyBoolCalculate |
| 3246 | error.SetErrorString ("tried to deallocate memory without ever allocating memory"); |
| 3247 | break; |
| 3248 | |
| 3249 | case eLazyBoolYes: |
| 3250 | if (!m_gdb_comm.DeallocateMemory (addr)) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3251 | error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3252 | break; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3253 | |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3254 | case eLazyBoolNo: |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3255 | // Call munmap() to deallocate memory in the inferior.. |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3256 | { |
| 3257 | MMapMap::iterator pos = m_addr_to_mmap_size.find(addr); |
Peter Collingbourne | 99f9aa0 | 2011-06-03 20:40:38 +0000 | [diff] [blame] | 3258 | if (pos != m_addr_to_mmap_size.end() && |
| 3259 | InferiorCallMunmap(this, addr, pos->second)) |
| 3260 | m_addr_to_mmap_size.erase (pos); |
| 3261 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3262 | error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 3263 | } |
| 3264 | break; |
| 3265 | } |
| 3266 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3267 | return error; |
| 3268 | } |
| 3269 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 3270 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3271 | //------------------------------------------------------------------ |
| 3272 | // Process STDIO |
| 3273 | //------------------------------------------------------------------ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3274 | size_t |
| 3275 | ProcessGDBRemote::PutSTDIN (const char *src, size_t src_len, Error &error) |
| 3276 | { |
| 3277 | if (m_stdio_communication.IsConnected()) |
| 3278 | { |
| 3279 | ConnectionStatus status; |
| 3280 | m_stdio_communication.Write(src, src_len, status, NULL); |
| 3281 | } |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 3282 | else if (m_stdin_forward) |
Vince Harron | e0be425 | 2015-02-06 18:32:57 +0000 | [diff] [blame] | 3283 | { |
| 3284 | m_gdb_comm.SendStdinNotification(src, src_len); |
| 3285 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3286 | return 0; |
| 3287 | } |
| 3288 | |
| 3289 | Error |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3290 | ProcessGDBRemote::EnableBreakpointSite (BreakpointSite *bp_site) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3291 | { |
| 3292 | Error error; |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3293 | assert(bp_site != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3294 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3295 | // Get logging info |
| 3296 | Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3297 | user_id_t site_id = bp_site->GetID(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3298 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3299 | // Get the breakpoint address |
| 3300 | const addr_t addr = bp_site->GetLoadAddress(); |
| 3301 | |
| 3302 | // Log that a breakpoint was requested |
| 3303 | if (log) |
| 3304 | log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 ") address = 0x%" PRIx64, site_id, (uint64_t)addr); |
| 3305 | |
| 3306 | // Breakpoint already exists and is enabled |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3307 | if (bp_site->IsEnabled()) |
| 3308 | { |
| 3309 | if (log) |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3310 | 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] | 3311 | return error; |
| 3312 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3313 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3314 | // Get the software breakpoint trap opcode size |
| 3315 | const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site); |
| 3316 | |
| 3317 | // SupportsGDBStoppointPacket() simply checks a boolean, indicating if this breakpoint type |
| 3318 | // is supported by the remote stub. These are set to true by default, and later set to false |
| 3319 | // only after we receive an unimplemented response when sending a breakpoint packet. This means |
| 3320 | // initially that unless we were specifically instructed to use a hardware breakpoint, LLDB will |
| 3321 | // attempt to set a software breakpoint. HardwareRequired() also queries a boolean variable which |
| 3322 | // indicates if the user specifically asked for hardware breakpoints. If true then we will |
| 3323 | // skip over software breakpoints. |
| 3324 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware) && (!bp_site->HardwareRequired())) |
| 3325 | { |
| 3326 | // Try to send off a software breakpoint packet ($Z0) |
Jim Ingham | 906d91e | 2016-05-19 02:13:44 +0000 | [diff] [blame] | 3327 | uint8_t error_no = m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointSoftware, true, addr, bp_op_size); |
| 3328 | if (error_no == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3329 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3330 | // The breakpoint was placed successfully |
| 3331 | bp_site->SetEnabled(true); |
| 3332 | bp_site->SetType(BreakpointSite::eExternal); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 3333 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3334 | } |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3335 | |
| 3336 | // SendGDBStoppointTypePacket() will return an error if it was unable to set this |
| 3337 | // breakpoint. We need to differentiate between a error specific to placing this breakpoint |
| 3338 | // or if we have learned that this breakpoint type is unsupported. To do this, we |
| 3339 | // must test the support boolean for this breakpoint type to see if it now indicates that |
| 3340 | // this breakpoint type is unsupported. If they are still supported then we should return |
| 3341 | // with the error code. If they are now unsupported, then we would like to fall through |
| 3342 | // and try another form of breakpoint. |
| 3343 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware)) |
Jim Ingham | 906d91e | 2016-05-19 02:13:44 +0000 | [diff] [blame] | 3344 | { |
| 3345 | if (error_no != UINT8_MAX) |
| 3346 | error.SetErrorStringWithFormat("error: %d sending the breakpoint request", errno); |
| 3347 | else |
| 3348 | error.SetErrorString("error sending the breakpoint request"); |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3349 | return error; |
Jim Ingham | 906d91e | 2016-05-19 02:13:44 +0000 | [diff] [blame] | 3350 | } |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3351 | |
| 3352 | // We reach here when software breakpoints have been found to be unsupported. For future |
| 3353 | // calls to set a breakpoint, we will not attempt to set a breakpoint with a type that is |
| 3354 | // known not to be supported. |
| 3355 | if (log) |
| 3356 | log->Printf("Software breakpoints are unsupported"); |
| 3357 | |
| 3358 | // So we will fall through and try a hardware breakpoint |
| 3359 | } |
| 3360 | |
| 3361 | // The process of setting a hardware breakpoint is much the same as above. We check the |
| 3362 | // supported boolean for this breakpoint type, and if it is thought to be supported then we |
| 3363 | // will try to set this breakpoint with a hardware breakpoint. |
| 3364 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointHardware)) |
| 3365 | { |
| 3366 | // Try to send off a hardware breakpoint packet ($Z1) |
Jim Ingham | 906d91e | 2016-05-19 02:13:44 +0000 | [diff] [blame] | 3367 | uint8_t error_no = m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointHardware, true, addr, bp_op_size); |
| 3368 | if (error_no == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3369 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3370 | // The breakpoint was placed successfully |
| 3371 | bp_site->SetEnabled(true); |
| 3372 | bp_site->SetType(BreakpointSite::eHardware); |
| 3373 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3374 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3375 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3376 | // Check if the error was something other then an unsupported breakpoint type |
| 3377 | if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointHardware)) |
| 3378 | { |
| 3379 | // Unable to set this hardware breakpoint |
Jim Ingham | 906d91e | 2016-05-19 02:13:44 +0000 | [diff] [blame] | 3380 | if (error_no != UINT8_MAX) |
| 3381 | error.SetErrorStringWithFormat("error: %d sending the hardware breakpoint request " |
| 3382 | "(hardware breakpoint resources might be exhausted or unavailable)", |
| 3383 | error_no); |
| 3384 | else |
| 3385 | error.SetErrorString("error sending the hardware breakpoint request (hardware breakpoint resources " |
| 3386 | "might be exhausted or unavailable)"); |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3387 | return error; |
| 3388 | } |
| 3389 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3390 | // 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] | 3391 | if (log) |
| 3392 | log->Printf("Hardware breakpoints are unsupported"); |
| 3393 | |
| 3394 | // Finally we will falling through to a #trap style breakpoint |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3397 | // Don't fall through when hardware breakpoints were specifically requested |
| 3398 | if (bp_site->HardwareRequired()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3399 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3400 | error.SetErrorString("hardware breakpoints are not supported"); |
| 3401 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3402 | } |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3403 | |
| 3404 | // As a last resort we want to place a manual breakpoint. An instruction |
| 3405 | // is placed into the process memory using memory write packets. |
| 3406 | return EnableSoftwareBreakpoint(bp_site); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | Error |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3410 | ProcessGDBRemote::DisableBreakpointSite (BreakpointSite *bp_site) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3411 | { |
| 3412 | Error error; |
| 3413 | assert (bp_site != NULL); |
| 3414 | addr_t addr = bp_site->GetLoadAddress(); |
| 3415 | user_id_t site_id = bp_site->GetID(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3416 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3417 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3418 | 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] | 3419 | |
| 3420 | if (bp_site->IsEnabled()) |
| 3421 | { |
| 3422 | const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode (bp_site); |
| 3423 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3424 | BreakpointSite::Type bp_type = bp_site->GetType(); |
| 3425 | switch (bp_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3426 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3427 | case BreakpointSite::eSoftware: |
| 3428 | error = DisableSoftwareBreakpoint (bp_site); |
| 3429 | break; |
| 3430 | |
| 3431 | case BreakpointSite::eHardware: |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3432 | if (m_gdb_comm.SendGDBStoppointTypePacket(eBreakpointHardware, false, addr, bp_op_size)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3433 | error.SetErrorToGenericError(); |
| 3434 | break; |
| 3435 | |
| 3436 | case BreakpointSite::eExternal: |
Jim Ingham | a04ef75 | 2014-03-07 11:18:02 +0000 | [diff] [blame] | 3437 | { |
| 3438 | GDBStoppointType stoppoint_type; |
| 3439 | if (bp_site->IsHardware()) |
| 3440 | stoppoint_type = eBreakpointHardware; |
| 3441 | else |
| 3442 | stoppoint_type = eBreakpointSoftware; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3443 | |
Jim Ingham | a04ef75 | 2014-03-07 11:18:02 +0000 | [diff] [blame] | 3444 | if (m_gdb_comm.SendGDBStoppointTypePacket(stoppoint_type, false, addr, bp_op_size)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3445 | error.SetErrorToGenericError(); |
Jim Ingham | a04ef75 | 2014-03-07 11:18:02 +0000 | [diff] [blame] | 3446 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3447 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3448 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3449 | if (error.Success()) |
| 3450 | bp_site->SetEnabled(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3451 | } |
| 3452 | else |
| 3453 | { |
| 3454 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 3455 | 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] | 3456 | return error; |
| 3457 | } |
| 3458 | |
| 3459 | if (error.Success()) |
| 3460 | error.SetErrorToGenericError(); |
| 3461 | return error; |
| 3462 | } |
| 3463 | |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3464 | // Pre-requisite: wp != NULL. |
| 3465 | static GDBStoppointType |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3466 | GetGDBStoppointType (Watchpoint *wp) |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3467 | { |
| 3468 | assert(wp); |
| 3469 | bool watch_read = wp->WatchpointRead(); |
| 3470 | bool watch_write = wp->WatchpointWrite(); |
| 3471 | |
| 3472 | // watch_read and watch_write cannot both be false. |
| 3473 | assert(watch_read || watch_write); |
| 3474 | if (watch_read && watch_write) |
| 3475 | return eWatchpointReadWrite; |
Johnny Chen | 6d487a9 | 2011-09-09 20:35:15 +0000 | [diff] [blame] | 3476 | else if (watch_read) |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3477 | return eWatchpointRead; |
Johnny Chen | 6d487a9 | 2011-09-09 20:35:15 +0000 | [diff] [blame] | 3478 | else // Must be watch_write, then. |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3479 | return eWatchpointWrite; |
| 3480 | } |
| 3481 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3482 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3483 | ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3484 | { |
| 3485 | Error error; |
| 3486 | if (wp) |
| 3487 | { |
| 3488 | user_id_t watchID = wp->GetID(); |
| 3489 | addr_t addr = wp->GetLoadAddress(); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3490 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3491 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3492 | log->Printf ("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")", watchID); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3493 | if (wp->IsEnabled()) |
| 3494 | { |
| 3495 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3496 | 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] | 3497 | return error; |
| 3498 | } |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3499 | |
| 3500 | GDBStoppointType type = GetGDBStoppointType(wp); |
| 3501 | // Pass down an appropriate z/Z packet... |
| 3502 | if (m_gdb_comm.SupportsGDBStoppointPacket (type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3503 | { |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3504 | if (m_gdb_comm.SendGDBStoppointTypePacket(type, true, addr, wp->GetByteSize()) == 0) |
| 3505 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3506 | wp->SetEnabled(true, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3507 | return error; |
| 3508 | } |
| 3509 | else |
| 3510 | error.SetErrorString("sending gdb watchpoint packet failed"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3511 | } |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3512 | else |
| 3513 | error.SetErrorString("watchpoints not supported"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3514 | } |
| 3515 | else |
| 3516 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3517 | error.SetErrorString("Watchpoint argument was NULL."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3518 | } |
| 3519 | if (error.Success()) |
| 3520 | error.SetErrorToGenericError(); |
| 3521 | return error; |
| 3522 | } |
| 3523 | |
| 3524 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3525 | ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3526 | { |
| 3527 | Error error; |
| 3528 | if (wp) |
| 3529 | { |
| 3530 | user_id_t watchID = wp->GetID(); |
| 3531 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3532 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3533 | |
| 3534 | addr_t addr = wp->GetLoadAddress(); |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3535 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3536 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3537 | 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] | 3538 | |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3539 | if (!wp->IsEnabled()) |
| 3540 | { |
| 3541 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3542 | 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] | 3543 | // See also 'class WatchpointSentry' within StopInfo.cpp. |
| 3544 | // This disabling attempt might come from the user-supplied actions, we'll route it in order for |
| 3545 | // the watchpoint object to intelligently process this action. |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3546 | wp->SetEnabled(false, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3547 | return error; |
| 3548 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3549 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3550 | if (wp->IsHardware()) |
| 3551 | { |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3552 | GDBStoppointType type = GetGDBStoppointType(wp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3553 | // Pass down an appropriate z/Z packet... |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3554 | if (m_gdb_comm.SendGDBStoppointTypePacket(type, false, addr, wp->GetByteSize()) == 0) |
| 3555 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3556 | wp->SetEnabled(false, notify); |
Johnny Chen | 11309a3 | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 3557 | return error; |
| 3558 | } |
| 3559 | else |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3560 | error.SetErrorString("sending gdb watchpoint packet failed"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3561 | } |
| 3562 | // TODO: clear software watchpoints if we implement them |
| 3563 | } |
| 3564 | else |
| 3565 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 3566 | error.SetErrorString("Watchpoint argument was NULL."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3567 | } |
| 3568 | if (error.Success()) |
| 3569 | error.SetErrorToGenericError(); |
| 3570 | return error; |
| 3571 | } |
| 3572 | |
| 3573 | void |
| 3574 | ProcessGDBRemote::Clear() |
| 3575 | { |
| 3576 | m_flags = 0; |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 3577 | m_thread_list_real.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3578 | m_thread_list.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | Error |
| 3582 | ProcessGDBRemote::DoSignal (int signo) |
| 3583 | { |
| 3584 | Error error; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3585 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3586 | if (log) |
| 3587 | log->Printf ("ProcessGDBRemote::DoSignal (signal = %d)", signo); |
| 3588 | |
| 3589 | if (!m_gdb_comm.SendAsyncSignal (signo)) |
| 3590 | error.SetErrorStringWithFormat("failed to send signal %i", signo); |
| 3591 | return error; |
| 3592 | } |
| 3593 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3594 | Error |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 3595 | ProcessGDBRemote::EstablishConnectionIfNeeded (const ProcessInfo &process_info) |
| 3596 | { |
| 3597 | // Make sure we aren't already connected? |
| 3598 | if (m_gdb_comm.IsConnected()) |
| 3599 | return Error(); |
| 3600 | |
| 3601 | PlatformSP platform_sp (GetTarget ().GetPlatform ()); |
| 3602 | if (platform_sp && !platform_sp->IsHost ()) |
| 3603 | return Error("Lost debug server connection"); |
| 3604 | |
| 3605 | auto error = LaunchAndConnectToDebugserver (process_info); |
| 3606 | if (error.Fail()) |
| 3607 | { |
| 3608 | const char *error_string = error.AsCString(); |
| 3609 | if (error_string == nullptr) |
| 3610 | error_string = "unable to launch " DEBUGSERVER_BASENAME; |
| 3611 | } |
| 3612 | return error; |
| 3613 | } |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3614 | #if defined (__APPLE__) |
| 3615 | #define USE_SOCKETPAIR_FOR_LOCAL_CONNECTION 1 |
| 3616 | #endif |
| 3617 | |
| 3618 | #ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION |
| 3619 | static bool SetCloexecFlag(int fd) |
| 3620 | { |
| 3621 | #if defined(FD_CLOEXEC) |
| 3622 | int flags = ::fcntl(fd, F_GETFD); |
| 3623 | if (flags == -1) |
| 3624 | return false; |
| 3625 | return (::fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == 0); |
| 3626 | #else |
| 3627 | return false; |
| 3628 | #endif |
| 3629 | } |
| 3630 | #endif |
Oleksiy Vyalov | afd6ce4 | 2015-11-23 19:32:24 +0000 | [diff] [blame] | 3631 | |
| 3632 | Error |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3633 | ProcessGDBRemote::LaunchAndConnectToDebugserver (const ProcessInfo &process_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3634 | { |
Pavel Labath | 998bdc5 | 2016-05-11 16:59:04 +0000 | [diff] [blame] | 3635 | using namespace std::placeholders; // For _1, _2, etc. |
| 3636 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3637 | Error error; |
| 3638 | if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID) |
| 3639 | { |
| 3640 | // If we locate debugserver, keep that located version around |
| 3641 | static FileSpec g_debugserver_file_spec; |
| 3642 | |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 3643 | ProcessLaunchInfo debugserver_launch_info; |
Oleksiy Vyalov | f8ce61c | 2015-01-28 17:36:59 +0000 | [diff] [blame] | 3644 | // Make debugserver run in its own session so signals generated by |
| 3645 | // special terminal key sequences (^C) don't affect debugserver. |
| 3646 | debugserver_launch_info.SetLaunchInSeparateProcessGroup(true); |
| 3647 | |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3648 | const std::weak_ptr<ProcessGDBRemote> this_wp = std::static_pointer_cast<ProcessGDBRemote>(shared_from_this()); |
| 3649 | debugserver_launch_info.SetMonitorProcessCallback(std::bind(MonitorDebugserverProcess, this_wp, _1, _2, _3, _4), |
Pavel Labath | 998bdc5 | 2016-05-11 16:59:04 +0000 | [diff] [blame] | 3650 | false); |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3651 | debugserver_launch_info.SetUserID(process_info.GetUserID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3652 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 3653 | |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3654 | int communication_fd = -1; |
| 3655 | #ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION |
| 3656 | // Auto close the sockets we might open up unless everything goes OK. This |
| 3657 | // helps us not leak file descriptors when things go wrong. |
| 3658 | lldb_utility::CleanUp <int, int> our_socket(-1, -1, close); |
| 3659 | lldb_utility::CleanUp <int, int> gdb_socket(-1, -1, close); |
| 3660 | |
| 3661 | // Use a socketpair on Apple for now until other platforms can verify it |
| 3662 | // works and is fast enough |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 3663 | { |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3664 | int sockets[2]; /* the pair of socket descriptors */ |
| 3665 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) |
| 3666 | { |
| 3667 | error.SetErrorToErrno(); |
| 3668 | return error; |
| 3669 | } |
| 3670 | |
| 3671 | our_socket.set(sockets[0]); |
| 3672 | gdb_socket.set(sockets[1]); |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3675 | // Don't let any child processes inherit our communication socket |
| 3676 | SetCloexecFlag(our_socket.get()); |
| 3677 | communication_fd = gdb_socket.get(); |
| 3678 | #endif |
| 3679 | |
| 3680 | error = m_gdb_comm.StartDebugserverProcess(nullptr, GetTarget().GetPlatform().get(), debugserver_launch_info, nullptr, nullptr, communication_fd); |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3681 | |
| 3682 | if (error.Success ()) |
| 3683 | m_debugserver_pid = debugserver_launch_info.GetProcessID(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3684 | else |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3685 | m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3686 | |
| 3687 | if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3688 | { |
| 3689 | #ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION |
| 3690 | // Our process spawned correctly, we can now set our connection to use our |
| 3691 | // end of the socket pair |
| 3692 | m_gdb_comm.SetConnection(new ConnectionFileDescriptor(our_socket.release(), true)); |
| 3693 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3694 | StartAsyncThread (); |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3695 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3696 | |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3697 | if (error.Fail()) |
| 3698 | { |
| 3699 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
| 3700 | |
| 3701 | if (log) |
| 3702 | log->Printf("failed to start debugserver process: %s", error.AsCString()); |
| 3703 | return error; |
| 3704 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3705 | |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3706 | if (m_gdb_comm.IsConnected()) |
| 3707 | { |
| 3708 | // Finish the connection process by doing the handshake without connecting (send NULL URL) |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3709 | ConnectToDebugserver(NULL); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3710 | } |
| 3711 | else |
| 3712 | { |
Greg Clayton | c6c420f | 2016-08-12 16:46:18 +0000 | [diff] [blame] | 3713 | error.SetErrorString("connection failed"); |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 3714 | } |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 3715 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3716 | } |
| 3717 | return error; |
| 3718 | } |
| 3719 | |
| 3720 | bool |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3721 | ProcessGDBRemote::MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp, lldb::pid_t debugserver_pid, |
Pavel Labath | 998bdc5 | 2016-05-11 16:59:04 +0000 | [diff] [blame] | 3722 | bool exited, // True if the process did exit |
| 3723 | int signo, // Zero for no signal |
| 3724 | int exit_status // Exit value of process if signal is zero |
| 3725 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3726 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3727 | // "debugserver_pid" argument passed in is the process ID for |
| 3728 | // debugserver that we are tracking... |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3729 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3730 | const bool handled = true; |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 3731 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3732 | if (log) |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3733 | log->Printf("ProcessGDBRemote::%s(process_wp, pid=%" PRIu64 ", signo=%i (0x%x), exit_status=%i)", __FUNCTION__, |
| 3734 | debugserver_pid, signo, signo, exit_status); |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3735 | |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3736 | std::shared_ptr<ProcessGDBRemote> process_sp = process_wp.lock(); |
| 3737 | if (log) |
Saleem Abdulrasool | abdfc21 | 2016-05-15 18:18:13 +0000 | [diff] [blame] | 3738 | log->Printf("ProcessGDBRemote::%s(process = %p)", __FUNCTION__, static_cast<void *>(process_sp.get())); |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3739 | if (!process_sp || process_sp->m_debugserver_pid != debugserver_pid) |
| 3740 | return handled; |
| 3741 | |
| 3742 | // Sleep for a half a second to make sure our inferior process has |
| 3743 | // time to set its exit status before we set it incorrectly when |
| 3744 | // both the debugserver and the inferior process shut down. |
| 3745 | usleep(500000); |
| 3746 | // If our process hasn't yet exited, debugserver might have died. |
| 3747 | // If the process did exit, then we are reaping it. |
| 3748 | const StateType state = process_sp->GetState(); |
| 3749 | |
| 3750 | if (state != eStateInvalid && state != eStateUnloaded && state != eStateExited && state != eStateDetached) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3751 | { |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3752 | char error_str[1024]; |
| 3753 | if (signo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3754 | { |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3755 | const char *signal_cstr = process_sp->GetUnixSignals()->GetSignalAsCString(signo); |
| 3756 | if (signal_cstr) |
| 3757 | ::snprintf(error_str, sizeof(error_str), DEBUGSERVER_BASENAME " died with signal %s", signal_cstr); |
| 3758 | else |
| 3759 | ::snprintf(error_str, sizeof(error_str), DEBUGSERVER_BASENAME " died with signal %i", signo); |
Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 3760 | } |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3761 | else |
| 3762 | { |
| 3763 | ::snprintf(error_str, sizeof(error_str), DEBUGSERVER_BASENAME " died with an exit status of 0x%8.8x", |
| 3764 | exit_status); |
| 3765 | } |
| 3766 | |
| 3767 | process_sp->SetExitStatus(-1, error_str); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3768 | } |
Pavel Labath | 194357c | 2016-05-12 11:10:01 +0000 | [diff] [blame] | 3769 | // Debugserver has exited we need to let our ProcessGDBRemote |
| 3770 | // know that it no longer has a debugserver instance |
| 3771 | process_sp->m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
| 3772 | return handled; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | void |
| 3776 | ProcessGDBRemote::KillDebugserverProcess () |
| 3777 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3778 | m_gdb_comm.Disconnect(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3779 | if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) |
| 3780 | { |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3781 | Host::Kill (m_debugserver_pid, SIGINT); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3782 | m_debugserver_pid = LLDB_INVALID_PROCESS_ID; |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | void |
| 3787 | ProcessGDBRemote::Initialize() |
| 3788 | { |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3789 | static std::once_flag g_once_flag; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3790 | |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3791 | std::call_once(g_once_flag, []() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3792 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3793 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 3794 | GetPluginDescriptionStatic(), |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3795 | CreateInstance, |
| 3796 | DebuggerInitialize); |
Davide Italiano | c8d6982 | 2015-04-03 04:24:32 +0000 | [diff] [blame] | 3797 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3800 | void |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 3801 | ProcessGDBRemote::DebuggerInitialize (Debugger &debugger) |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 3802 | { |
| 3803 | if (!PluginManager::GetSettingForProcessPlugin(debugger, PluginProperties::GetSettingName())) |
| 3804 | { |
| 3805 | const bool is_global_setting = true; |
| 3806 | PluginManager::CreateSettingForProcessPlugin (debugger, |
| 3807 | GetGlobalPluginProperties()->GetValueProperties(), |
| 3808 | ConstString ("Properties for the gdb-remote process plug-in."), |
| 3809 | is_global_setting); |
| 3810 | } |
| 3811 | } |
| 3812 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3813 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3814 | ProcessGDBRemote::StartAsyncThread () |
| 3815 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3816 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3817 | |
| 3818 | if (log) |
| 3819 | log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3820 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 3821 | std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3822 | if (!m_async_thread.IsJoinable()) |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3823 | { |
| 3824 | // Create a thread that watches our internal state and controls which |
| 3825 | // events make it to clients (into the DCProcess event queue). |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3826 | |
| 3827 | 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] | 3828 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3829 | else if (log) |
| 3830 | log->Printf("ProcessGDBRemote::%s () - Called when Async thread was already running.", __FUNCTION__); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3831 | |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3832 | return m_async_thread.IsJoinable(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | void |
| 3836 | ProcessGDBRemote::StopAsyncThread () |
| 3837 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3838 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3839 | |
| 3840 | if (log) |
| 3841 | log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); |
| 3842 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 3843 | std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3844 | if (m_async_thread.IsJoinable()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3845 | { |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3846 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3847 | |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3848 | // This will shut down the async thread. |
| 3849 | m_gdb_comm.Disconnect(); // Disconnect from the debug server. |
| 3850 | |
| 3851 | // Stop the stdio thread |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3852 | m_async_thread.Join(nullptr); |
Pavel Labath | a55a953 | 2015-03-11 09:53:42 +0000 | [diff] [blame] | 3853 | m_async_thread.Reset(); |
Jim Ingham | 455fa5c | 2012-11-01 01:15:33 +0000 | [diff] [blame] | 3854 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3855 | else if (log) |
| 3856 | log->Printf("ProcessGDBRemote::%s () - Called when Async thread was not running.", __FUNCTION__); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
Ewan Crawford | 76df288 | 2015-06-23 12:32:06 +0000 | [diff] [blame] | 3859 | bool |
| 3860 | ProcessGDBRemote::HandleNotifyPacket (StringExtractorGDBRemote &packet) |
| 3861 | { |
| 3862 | // get the packet at a string |
| 3863 | const std::string &pkt = packet.GetStringRef(); |
| 3864 | // skip %stop: |
| 3865 | StringExtractorGDBRemote stop_info(pkt.c_str() + 5); |
| 3866 | |
| 3867 | // pass as a thread stop info packet |
| 3868 | SetLastStopPacket(stop_info); |
| 3869 | |
| 3870 | // check for more stop reasons |
| 3871 | HandleStopReplySequence(); |
| 3872 | |
| 3873 | // if the process is stopped then we need to fake a resume |
| 3874 | // so that we can stop properly with the new break. This |
| 3875 | // is possible due to SetPrivateState() broadcasting the |
| 3876 | // state change as a side effect. |
| 3877 | if (GetPrivateState() == lldb::StateType::eStateStopped) |
| 3878 | { |
| 3879 | SetPrivateState(lldb::StateType::eStateRunning); |
| 3880 | } |
| 3881 | |
| 3882 | // since we have some stopped packets we can halt the process |
| 3883 | SetPrivateState(lldb::StateType::eStateStopped); |
| 3884 | |
| 3885 | return true; |
| 3886 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3887 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3888 | thread_result_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3889 | ProcessGDBRemote::AsyncThread (void *arg) |
| 3890 | { |
| 3891 | ProcessGDBRemote *process = (ProcessGDBRemote*) arg; |
| 3892 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3893 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3894 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3895 | 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] | 3896 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3897 | EventSP event_sp; |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3898 | bool done = false; |
| 3899 | while (!done) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3900 | { |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3901 | if (log) |
| 3902 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID()); |
Saleem Abdulrasool | 2d6a9ec | 2016-07-28 17:32:20 +0000 | [diff] [blame] | 3903 | if (process->m_async_listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3904 | { |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3905 | const uint32_t event_type = event_sp->GetType(); |
| 3906 | if (event_sp->BroadcasterIs (&process->m_async_broadcaster)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3907 | { |
| 3908 | if (log) |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3909 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type); |
| 3910 | |
| 3911 | switch (event_type) |
| 3912 | { |
| 3913 | case eBroadcastBitAsyncContinue: |
| 3914 | { |
| 3915 | const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get()); |
| 3916 | |
| 3917 | if (continue_packet) |
| 3918 | { |
| 3919 | const char *continue_cstr = (const char *)continue_packet->GetBytes (); |
| 3920 | const size_t continue_cstr_len = continue_packet->GetByteSize (); |
| 3921 | if (log) |
| 3922 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr); |
| 3923 | |
| 3924 | if (::strstr (continue_cstr, "vAttach") == NULL) |
| 3925 | process->SetPrivateState(eStateRunning); |
| 3926 | StringExtractorGDBRemote response; |
| 3927 | |
| 3928 | // If in Non-Stop-Mode |
| 3929 | if (process->GetTarget().GetNonStopModeEnabled()) |
| 3930 | { |
| 3931 | // send the vCont packet |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 3932 | if (!process->GetGDBRemote().SendvContPacket( |
| 3933 | llvm::StringRef(continue_cstr, continue_cstr_len), response)) |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3934 | { |
| 3935 | // Something went wrong |
| 3936 | done = true; |
| 3937 | break; |
| 3938 | } |
| 3939 | } |
| 3940 | // If in All-Stop-Mode |
| 3941 | else |
| 3942 | { |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 3943 | StateType stop_state = process->GetGDBRemote().SendContinuePacketAndWaitForResponse( |
| 3944 | *process, *process->GetUnixSignals(), |
| 3945 | llvm::StringRef(continue_cstr, continue_cstr_len), response); |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3946 | |
| 3947 | // We need to immediately clear the thread ID list so we are sure to get a valid list of threads. |
| 3948 | // The thread ID list might be contained within the "response", or the stop reply packet that |
| 3949 | // caused the stop. So clear it now before we give the stop reply packet to the process |
| 3950 | // using the process->SetLastStopPacket()... |
| 3951 | process->ClearThreadIDList (); |
| 3952 | |
| 3953 | switch (stop_state) |
| 3954 | { |
| 3955 | case eStateStopped: |
| 3956 | case eStateCrashed: |
| 3957 | case eStateSuspended: |
| 3958 | process->SetLastStopPacket (response); |
| 3959 | process->SetPrivateState (stop_state); |
| 3960 | break; |
| 3961 | |
| 3962 | case eStateExited: |
| 3963 | { |
| 3964 | process->SetLastStopPacket (response); |
| 3965 | process->ClearThreadIDList(); |
| 3966 | response.SetFilePos(1); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 3967 | |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 3968 | int exit_status = response.GetHexU8(); |
| 3969 | const char *desc_cstr = NULL; |
| 3970 | StringExtractor extractor; |
| 3971 | std::string desc_string; |
| 3972 | if (response.GetBytesLeft() > 0 && response.GetChar('-') == ';') |
| 3973 | { |
| 3974 | std::string desc_token; |
| 3975 | while (response.GetNameColonValue (desc_token, desc_string)) |
| 3976 | { |
| 3977 | if (desc_token == "description") |
| 3978 | { |
| 3979 | extractor.GetStringRef().swap(desc_string); |
| 3980 | extractor.SetFilePos(0); |
| 3981 | extractor.GetHexByteString (desc_string); |
| 3982 | desc_cstr = desc_string.c_str(); |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | process->SetExitStatus(exit_status, desc_cstr); |
| 3987 | done = true; |
| 3988 | break; |
| 3989 | } |
| 3990 | case eStateInvalid: |
| 3991 | { |
| 3992 | // Check to see if we were trying to attach and if we got back |
| 3993 | // the "E87" error code from debugserver -- this indicates that |
| 3994 | // the process is not debuggable. Return a slightly more helpful |
| 3995 | // error message about why the attach failed. |
| 3996 | if (::strstr (continue_cstr, "vAttach") != NULL |
| 3997 | && response.GetError() == 0x87) |
| 3998 | { |
| 3999 | process->SetExitStatus(-1, "cannot attach to process due to System Integrity Protection"); |
| 4000 | } |
| 4001 | // E01 code from vAttach means that the attach failed |
| 4002 | if (::strstr (continue_cstr, "vAttach") != NULL |
| 4003 | && response.GetError() == 0x1) |
| 4004 | { |
| 4005 | process->SetExitStatus(-1, "unable to attach"); |
| 4006 | } |
| 4007 | else |
| 4008 | { |
| 4009 | process->SetExitStatus(-1, "lost connection"); |
| 4010 | } |
| 4011 | break; |
| 4012 | } |
| 4013 | |
| 4014 | default: |
| 4015 | process->SetPrivateState (stop_state); |
| 4016 | break; |
| 4017 | } // switch(stop_state) |
| 4018 | } // else // if in All-stop-mode |
| 4019 | } // if (continue_packet) |
| 4020 | } // case eBroadcastBitAysncContinue |
| 4021 | break; |
| 4022 | |
| 4023 | case eBroadcastBitAsyncThreadShouldExit: |
| 4024 | if (log) |
| 4025 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID()); |
| 4026 | done = true; |
| 4027 | break; |
| 4028 | |
| 4029 | default: |
| 4030 | if (log) |
| 4031 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); |
| 4032 | done = true; |
| 4033 | break; |
| 4034 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4035 | } |
Pavel Labath | 5055685 | 2015-09-03 09:36:22 +0000 | [diff] [blame] | 4036 | else if (event_sp->BroadcasterIs (&process->m_gdb_comm)) |
| 4037 | { |
| 4038 | switch (event_type) |
| 4039 | { |
| 4040 | case Communication::eBroadcastBitReadThreadDidExit: |
| 4041 | process->SetExitStatus (-1, "lost connection"); |
| 4042 | done = true; |
| 4043 | break; |
| 4044 | |
| 4045 | case GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify: |
| 4046 | { |
| 4047 | lldb_private::Event *event = event_sp.get(); |
| 4048 | const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event); |
| 4049 | StringExtractorGDBRemote notify((const char*)continue_packet->GetBytes()); |
| 4050 | // Hand this over to the process to handle |
| 4051 | process->HandleNotifyPacket(notify); |
| 4052 | break; |
| 4053 | } |
| 4054 | |
| 4055 | default: |
| 4056 | if (log) |
| 4057 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); |
| 4058 | done = true; |
| 4059 | break; |
| 4060 | } |
| 4061 | } |
| 4062 | } |
| 4063 | else |
| 4064 | { |
| 4065 | if (log) |
| 4066 | log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID()); |
| 4067 | done = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4072 | 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] | 4073 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4074 | return NULL; |
| 4075 | } |
| 4076 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 4077 | //uint32_t |
| 4078 | //ProcessGDBRemote::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) |
| 4079 | //{ |
| 4080 | // // If we are planning to launch the debugserver remotely, then we need to fire up a debugserver |
| 4081 | // // process and ask it for the list of processes. But if we are local, we can let the Host do it. |
| 4082 | // if (m_local_debugserver) |
| 4083 | // { |
| 4084 | // return Host::ListProcessesMatchingName (name, matches, pids); |
| 4085 | // } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4086 | // else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 4087 | // { |
| 4088 | // // FIXME: Implement talking to the remote debugserver. |
| 4089 | // return 0; |
| 4090 | // } |
| 4091 | // |
| 4092 | //} |
| 4093 | // |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4094 | bool |
| 4095 | ProcessGDBRemote::NewThreadNotifyBreakpointHit (void *baton, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 4096 | StoppointCallbackContext *context, |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4097 | lldb::user_id_t break_id, |
| 4098 | lldb::user_id_t break_loc_id) |
| 4099 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4100 | // I don't think I have to do anything here, just make sure I notice the new thread when it starts to |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4101 | // 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] | 4102 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4103 | if (log) |
| 4104 | log->Printf("Hit New Thread Notification breakpoint."); |
| 4105 | return false; |
| 4106 | } |
| 4107 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 4108 | |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4109 | bool |
| 4110 | ProcessGDBRemote::StartNoticingNewThreads() |
| 4111 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 4112 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4113 | if (m_thread_create_bp_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4114 | { |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4115 | if (log && log->GetVerbose()) |
| 4116 | log->Printf("Enabled noticing new thread breakpoint."); |
| 4117 | m_thread_create_bp_sp->SetEnabled(true); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4118 | } |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4119 | else |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4120 | { |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 4121 | PlatformSP platform_sp (GetTarget().GetPlatform()); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4122 | if (platform_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4123 | { |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 4124 | m_thread_create_bp_sp = platform_sp->SetThreadCreationBreakpoint(GetTarget()); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4125 | if (m_thread_create_bp_sp) |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4126 | { |
Jim Ingham | 37cfeab | 2011-10-15 00:21:37 +0000 | [diff] [blame] | 4127 | if (log && log->GetVerbose()) |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4128 | log->Printf("Successfully created new thread notification breakpoint %i", m_thread_create_bp_sp->GetID()); |
| 4129 | m_thread_create_bp_sp->SetCallback (ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4130 | } |
| 4131 | else |
| 4132 | { |
| 4133 | if (log) |
| 4134 | log->Printf("Failed to create new thread notification breakpoint."); |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4135 | } |
| 4136 | } |
| 4137 | } |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4138 | return m_thread_create_bp_sp.get() != NULL; |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | bool |
| 4142 | ProcessGDBRemote::StopNoticingNewThreads() |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4143 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 4144 | Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 37cfeab | 2011-10-15 00:21:37 +0000 | [diff] [blame] | 4145 | if (log && log->GetVerbose()) |
Jim Ingham | 0e97cbc | 2011-02-08 05:19:01 +0000 | [diff] [blame] | 4146 | log->Printf ("Disabling new thread notification breakpoint."); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 4147 | |
| 4148 | if (m_thread_create_bp_sp) |
| 4149 | m_thread_create_bp_sp->SetEnabled(false); |
| 4150 | |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4151 | return true; |
| 4152 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4153 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 4154 | DynamicLoader * |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 4155 | ProcessGDBRemote::GetDynamicLoader () |
| 4156 | { |
| 4157 | if (m_dyld_ap.get() == NULL) |
Jason Molenda | 2e56a25 | 2013-05-11 03:09:05 +0000 | [diff] [blame] | 4158 | m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); |
Jason Molenda | 5e8534e | 2012-10-03 01:29:34 +0000 | [diff] [blame] | 4159 | return m_dyld_ap.get(); |
| 4160 | } |
Jim Ingham | 1c823b4 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 4161 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 4162 | Error |
| 4163 | ProcessGDBRemote::SendEventData(const char *data) |
| 4164 | { |
| 4165 | int return_value; |
| 4166 | bool was_supported; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4167 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 4168 | Error error; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4169 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 4170 | return_value = m_gdb_comm.SendLaunchEventDataPacket (data, &was_supported); |
| 4171 | if (return_value != 0) |
| 4172 | { |
| 4173 | if (!was_supported) |
| 4174 | error.SetErrorString("Sending events is not supported for this process."); |
| 4175 | else |
| 4176 | error.SetErrorStringWithFormat("Error sending event data: %d.", return_value); |
| 4177 | } |
| 4178 | return error; |
| 4179 | } |
| 4180 | |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 4181 | const DataBufferSP |
| 4182 | ProcessGDBRemote::GetAuxvData() |
| 4183 | { |
| 4184 | DataBufferSP buf; |
| 4185 | if (m_gdb_comm.GetQXferAuxvReadSupported()) |
| 4186 | { |
| 4187 | std::string response_string; |
| 4188 | if (m_gdb_comm.SendPacketsAndConcatenateResponses("qXfer:auxv:read::", response_string) == GDBRemoteCommunication::PacketResult::Success) |
| 4189 | buf.reset(new DataBufferHeap(response_string.c_str(), response_string.length())); |
| 4190 | } |
| 4191 | return buf; |
| 4192 | } |
| 4193 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4194 | StructuredData::ObjectSP |
| 4195 | ProcessGDBRemote::GetExtendedInfoForThread (lldb::tid_t tid) |
| 4196 | { |
| 4197 | StructuredData::ObjectSP object_sp; |
| 4198 | |
| 4199 | if (m_gdb_comm.GetThreadExtendedInfoSupported()) |
| 4200 | { |
| 4201 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4202 | SystemRuntime *runtime = GetSystemRuntime(); |
| 4203 | if (runtime) |
| 4204 | { |
| 4205 | runtime->AddThreadExtendedInfoPacketHints (args_dict); |
| 4206 | } |
| 4207 | args_dict->GetAsDictionary()->AddIntegerItem ("thread", tid); |
| 4208 | |
| 4209 | StreamString packet; |
| 4210 | packet << "jThreadExtendedInfo:"; |
Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 4211 | args_dict->Dump (packet, false); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4212 | |
| 4213 | // FIXME the final character of a JSON dictionary, '}', is the escape |
| 4214 | // character in gdb-remote binary mode. lldb currently doesn't escape |
| 4215 | // these characters in its packet output -- so we add the quoted version |
| 4216 | // 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] | 4217 | // un-escapes the characters at packet read time. |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4218 | packet << (char) (0x7d ^ 0x20); |
| 4219 | |
| 4220 | StringExtractorGDBRemote response; |
Greg Clayton | 830c81d | 2016-04-01 00:41:29 +0000 | [diff] [blame] | 4221 | response.SetResponseValidatorToJSON(); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4222 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == GDBRemoteCommunication::PacketResult::Success) |
| 4223 | { |
| 4224 | StringExtractorGDBRemote::ResponseType response_type = response.GetResponseType(); |
| 4225 | if (response_type == StringExtractorGDBRemote::eResponse) |
| 4226 | { |
| 4227 | if (!response.Empty()) |
| 4228 | { |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4229 | object_sp = StructuredData::ParseJSON (response.GetStringRef()); |
| 4230 | } |
| 4231 | } |
| 4232 | } |
| 4233 | } |
| 4234 | return object_sp; |
| 4235 | } |
| 4236 | |
| 4237 | StructuredData::ObjectSP |
| 4238 | ProcessGDBRemote::GetLoadedDynamicLibrariesInfos (lldb::addr_t image_list_address, lldb::addr_t image_count) |
| 4239 | { |
Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 4240 | |
| 4241 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4242 | args_dict->GetAsDictionary()->AddIntegerItem ("image_list_address", image_list_address); |
| 4243 | args_dict->GetAsDictionary()->AddIntegerItem ("image_count", image_count); |
| 4244 | |
| 4245 | return GetLoadedDynamicLibrariesInfos_sender (args_dict); |
| 4246 | } |
| 4247 | |
| 4248 | StructuredData::ObjectSP |
| 4249 | ProcessGDBRemote::GetLoadedDynamicLibrariesInfos () |
| 4250 | { |
| 4251 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4252 | |
| 4253 | args_dict->GetAsDictionary()->AddBooleanItem ("fetch_all_solibs", true); |
| 4254 | |
| 4255 | return GetLoadedDynamicLibrariesInfos_sender (args_dict); |
| 4256 | } |
| 4257 | |
| 4258 | StructuredData::ObjectSP |
| 4259 | ProcessGDBRemote::GetLoadedDynamicLibrariesInfos (const std::vector<lldb::addr_t> &load_addresses) |
| 4260 | { |
| 4261 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4262 | StructuredData::ArraySP addresses(new StructuredData::Array); |
| 4263 | |
| 4264 | for (auto addr : load_addresses) |
| 4265 | { |
| 4266 | StructuredData::ObjectSP addr_sp (new StructuredData::Integer (addr)); |
| 4267 | addresses->AddItem (addr_sp); |
| 4268 | } |
| 4269 | |
| 4270 | args_dict->GetAsDictionary()->AddItem ("solib_addresses", addresses); |
| 4271 | |
| 4272 | return GetLoadedDynamicLibrariesInfos_sender (args_dict); |
| 4273 | } |
| 4274 | |
| 4275 | StructuredData::ObjectSP |
| 4276 | ProcessGDBRemote::GetLoadedDynamicLibrariesInfos_sender (StructuredData::ObjectSP args_dict) |
| 4277 | { |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4278 | StructuredData::ObjectSP object_sp; |
| 4279 | |
| 4280 | if (m_gdb_comm.GetLoadedDynamicLibrariesInfosSupported()) |
| 4281 | { |
Jason Molenda | 1d3b356 | 2015-11-05 23:54:29 +0000 | [diff] [blame] | 4282 | // Scope for the scoped timeout object |
| 4283 | GDBRemoteCommunication::ScopedTimeout timeout (m_gdb_comm, 10); |
| 4284 | |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4285 | StreamString packet; |
| 4286 | packet << "jGetLoadedDynamicLibrariesInfos:"; |
Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 4287 | args_dict->Dump (packet, false); |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4288 | |
| 4289 | // FIXME the final character of a JSON dictionary, '}', is the escape |
| 4290 | // character in gdb-remote binary mode. lldb currently doesn't escape |
| 4291 | // these characters in its packet output -- so we add the quoted version |
| 4292 | // of the } character here manually in case we talk to a debugserver which |
| 4293 | // un-escapes the characters at packet read time. |
| 4294 | packet << (char) (0x7d ^ 0x20); |
| 4295 | |
| 4296 | StringExtractorGDBRemote response; |
Greg Clayton | 830c81d | 2016-04-01 00:41:29 +0000 | [diff] [blame] | 4297 | response.SetResponseValidatorToJSON(); |
Jason Molenda | 20ee21b | 2015-07-10 23:15:22 +0000 | [diff] [blame] | 4298 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == GDBRemoteCommunication::PacketResult::Success) |
| 4299 | { |
| 4300 | StringExtractorGDBRemote::ResponseType response_type = response.GetResponseType(); |
| 4301 | if (response_type == StringExtractorGDBRemote::eResponse) |
| 4302 | { |
| 4303 | if (!response.Empty()) |
| 4304 | { |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 4305 | object_sp = StructuredData::ParseJSON (response.GetStringRef()); |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | return object_sp; |
| 4311 | } |
| 4312 | |
Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 4313 | |
| 4314 | |
| 4315 | |
Jason Molenda | 3739735 | 2016-07-22 00:17:55 +0000 | [diff] [blame] | 4316 | StructuredData::ObjectSP |
| 4317 | ProcessGDBRemote::GetSharedCacheInfo () |
| 4318 | { |
| 4319 | StructuredData::ObjectSP object_sp; |
| 4320 | StructuredData::ObjectSP args_dict(new StructuredData::Dictionary()); |
| 4321 | |
| 4322 | if (m_gdb_comm.GetSharedCacheInfoSupported()) |
| 4323 | { |
| 4324 | StreamString packet; |
| 4325 | packet << "jGetSharedCacheInfo:"; |
| 4326 | args_dict->Dump (packet, false); |
| 4327 | |
| 4328 | // FIXME the final character of a JSON dictionary, '}', is the escape |
| 4329 | // character in gdb-remote binary mode. lldb currently doesn't escape |
| 4330 | // these characters in its packet output -- so we add the quoted version |
| 4331 | // of the } character here manually in case we talk to a debugserver which |
| 4332 | // un-escapes the characters at packet read time. |
| 4333 | packet << (char) (0x7d ^ 0x20); |
| 4334 | |
| 4335 | StringExtractorGDBRemote response; |
| 4336 | response.SetResponseValidatorToJSON(); |
| 4337 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, false) == GDBRemoteCommunication::PacketResult::Success) |
| 4338 | { |
| 4339 | StringExtractorGDBRemote::ResponseType response_type = response.GetResponseType(); |
| 4340 | if (response_type == StringExtractorGDBRemote::eResponse) |
| 4341 | { |
| 4342 | if (!response.Empty()) |
| 4343 | { |
| 4344 | object_sp = StructuredData::ParseJSON (response.GetStringRef()); |
| 4345 | } |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | return object_sp; |
| 4350 | } |
| 4351 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame^] | 4352 | Error |
| 4353 | ProcessGDBRemote::ConfigureStructuredData(const ConstString &type_name, |
| 4354 | const StructuredData::ObjectSP |
| 4355 | &config_sp) |
| 4356 | { |
| 4357 | return m_gdb_comm.ConfigureRemoteStructuredData(type_name, config_sp); |
| 4358 | } |
Jason Molenda | 3739735 | 2016-07-22 00:17:55 +0000 | [diff] [blame] | 4359 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4360 | // Establish the largest memory read/write payloads we should use. |
| 4361 | // If the remote stub has a max packet size, stay under that size. |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4362 | // |
| 4363 | // If the remote stub's max packet size is crazy large, use a |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4364 | // reasonable largeish default. |
| 4365 | // |
| 4366 | // If the remote stub doesn't advertise a max packet size, use a |
| 4367 | // conservative default. |
| 4368 | |
| 4369 | void |
| 4370 | ProcessGDBRemote::GetMaxMemorySize() |
| 4371 | { |
| 4372 | const uint64_t reasonable_largeish_default = 128 * 1024; |
| 4373 | const uint64_t conservative_default = 512; |
| 4374 | |
| 4375 | if (m_max_memory_size == 0) |
| 4376 | { |
| 4377 | uint64_t stub_max_size = m_gdb_comm.GetRemoteMaxPacketSize(); |
| 4378 | if (stub_max_size != UINT64_MAX && stub_max_size != 0) |
| 4379 | { |
| 4380 | // Save the stub's claimed maximum packet size |
| 4381 | m_remote_stub_max_memory_size = stub_max_size; |
| 4382 | |
| 4383 | // Even if the stub says it can support ginormous packets, |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4384 | // don't exceed our reasonable largeish default packet size. |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 4385 | if (stub_max_size > reasonable_largeish_default) |
| 4386 | { |
| 4387 | stub_max_size = reasonable_largeish_default; |
| 4388 | } |
| 4389 | |
| 4390 | m_max_memory_size = stub_max_size; |
| 4391 | } |
| 4392 | else |
| 4393 | { |
| 4394 | m_max_memory_size = conservative_default; |
| 4395 | } |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | void |
| 4400 | ProcessGDBRemote::SetUserSpecifiedMaxMemoryTransferSize (uint64_t user_specified_max) |
| 4401 | { |
| 4402 | if (user_specified_max != 0) |
| 4403 | { |
| 4404 | GetMaxMemorySize (); |
| 4405 | |
| 4406 | if (m_remote_stub_max_memory_size != 0) |
| 4407 | { |
| 4408 | if (m_remote_stub_max_memory_size < user_specified_max) |
| 4409 | { |
| 4410 | m_max_memory_size = m_remote_stub_max_memory_size; // user specified a packet size too big, go as big |
| 4411 | // as the remote stub says we can go. |
| 4412 | } |
| 4413 | else |
| 4414 | { |
| 4415 | m_max_memory_size = user_specified_max; // user's packet size is good |
| 4416 | } |
| 4417 | } |
| 4418 | else |
| 4419 | { |
| 4420 | m_max_memory_size = user_specified_max; // user's packet size is probably fine |
| 4421 | } |
| 4422 | } |
| 4423 | } |
| 4424 | |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 4425 | bool |
| 4426 | ProcessGDBRemote::GetModuleSpec(const FileSpec& module_file_spec, |
| 4427 | const ArchSpec& arch, |
| 4428 | ModuleSpec &module_spec) |
| 4429 | { |
| 4430 | Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM); |
| 4431 | |
| 4432 | if (!m_gdb_comm.GetModuleInfo (module_file_spec, arch, module_spec)) |
| 4433 | { |
| 4434 | if (log) |
| 4435 | log->Printf ("ProcessGDBRemote::%s - failed to get module info for %s:%s", |
| 4436 | __FUNCTION__, module_file_spec.GetPath ().c_str (), |
| 4437 | arch.GetTriple ().getTriple ().c_str ()); |
| 4438 | return false; |
| 4439 | } |
| 4440 | |
| 4441 | if (log) |
| 4442 | { |
| 4443 | StreamString stream; |
| 4444 | module_spec.Dump (stream); |
| 4445 | log->Printf ("ProcessGDBRemote::%s - got module info for (%s:%s) : %s", |
| 4446 | __FUNCTION__, module_file_spec.GetPath ().c_str (), |
| 4447 | arch.GetTriple ().getTriple ().c_str (), stream.GetString ().c_str ()); |
| 4448 | } |
| 4449 | |
| 4450 | return true; |
| 4451 | } |
| 4452 | |
Jim Ingham | 13c30d2 | 2015-11-05 22:33:17 +0000 | [diff] [blame] | 4453 | bool |
| 4454 | ProcessGDBRemote::GetHostOSVersion(uint32_t &major, |
| 4455 | uint32_t &minor, |
| 4456 | uint32_t &update) |
| 4457 | { |
| 4458 | if (m_gdb_comm.GetOSVersion(major, minor, update)) |
| 4459 | return true; |
| 4460 | // We failed to get the host OS version, defer to the base |
| 4461 | // implementation to correctly invalidate the arguments. |
| 4462 | return Process::GetHostOSVersion(major, minor, update); |
| 4463 | } |
| 4464 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4465 | namespace { |
| 4466 | |
| 4467 | typedef std::vector<std::string> stringVec; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4468 | |
| 4469 | typedef std::vector<struct GdbServerRegisterInfo> GDBServerRegisterVec; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4470 | struct RegisterSetInfo |
| 4471 | { |
| 4472 | ConstString name; |
| 4473 | }; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4474 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4475 | typedef std::map<uint32_t, RegisterSetInfo> RegisterSetMap; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4476 | |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4477 | struct GdbServerTargetInfo |
| 4478 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4479 | std::string arch; |
| 4480 | std::string osabi; |
| 4481 | stringVec includes; |
| 4482 | RegisterSetMap reg_set_map; |
| 4483 | XMLNode feature_node; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4484 | }; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4485 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4486 | bool |
Francis Ricci | 55954ae | 2016-04-25 21:03:55 +0000 | [diff] [blame] | 4487 | ParseRegisters (XMLNode feature_node, GdbServerTargetInfo &target_info, GDBRemoteDynamicRegisterInfo &dyn_reg_info, ABISP abi_sp, uint32_t &cur_reg_num, uint32_t ®_offset) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4488 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4489 | if (!feature_node) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4490 | return false; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4491 | |
Jason Molenda | 63bd0db | 2015-09-15 23:20:34 +0000 | [diff] [blame] | 4492 | feature_node.ForEachChildElementWithName("reg", [&target_info, &dyn_reg_info, &cur_reg_num, ®_offset, &abi_sp](const XMLNode ®_node) -> bool { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4493 | std::string gdb_group; |
| 4494 | std::string gdb_type; |
| 4495 | ConstString reg_name; |
| 4496 | ConstString alt_name; |
| 4497 | ConstString set_name; |
| 4498 | std::vector<uint32_t> value_regs; |
| 4499 | std::vector<uint32_t> invalidate_regs; |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 4500 | std::vector<uint8_t> dwarf_opcode_bytes; |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4501 | bool encoding_set = false; |
| 4502 | bool format_set = false; |
| 4503 | RegisterInfo reg_info = { NULL, // Name |
| 4504 | NULL, // Alt name |
| 4505 | 0, // byte size |
| 4506 | reg_offset, // offset |
| 4507 | eEncodingUint, // encoding |
Jason Molenda | bf67a30 | 2015-09-01 05:17:01 +0000 | [diff] [blame] | 4508 | eFormatHex, // format |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4509 | { |
Jason Molenda | bf67a30 | 2015-09-01 05:17:01 +0000 | [diff] [blame] | 4510 | LLDB_INVALID_REGNUM, // eh_frame reg num |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4511 | LLDB_INVALID_REGNUM, // DWARF reg num |
| 4512 | LLDB_INVALID_REGNUM, // generic reg num |
Jason Molenda | 63bd0db | 2015-09-15 23:20:34 +0000 | [diff] [blame] | 4513 | cur_reg_num, // process plugin reg num |
| 4514 | cur_reg_num // native register number |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4515 | }, |
| 4516 | NULL, |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 4517 | NULL, |
| 4518 | NULL, // Dwarf Expression opcode bytes pointer |
| 4519 | 0 // Dwarf Expression opcode bytes length |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4520 | }; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4521 | |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 4522 | reg_node.ForEachAttribute([&target_info, &gdb_group, &gdb_type, ®_name, &alt_name, &set_name, &value_regs, &invalidate_regs, &encoding_set, &format_set, ®_info, &cur_reg_num, ®_offset, &dwarf_opcode_bytes](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4523 | if (name == "name") |
| 4524 | { |
| 4525 | reg_name.SetString(value); |
| 4526 | } |
| 4527 | else if (name == "bitsize") |
| 4528 | { |
| 4529 | reg_info.byte_size = StringConvert::ToUInt32(value.data(), 0, 0) / CHAR_BIT; |
| 4530 | } |
| 4531 | else if (name == "type") |
| 4532 | { |
| 4533 | gdb_type = value.str(); |
| 4534 | } |
| 4535 | else if (name == "group") |
| 4536 | { |
| 4537 | gdb_group = value.str(); |
| 4538 | } |
| 4539 | else if (name == "regnum") |
| 4540 | { |
| 4541 | const uint32_t regnum = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
| 4542 | if (regnum != LLDB_INVALID_REGNUM) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4543 | { |
Jason Molenda | 63bd0db | 2015-09-15 23:20:34 +0000 | [diff] [blame] | 4544 | reg_info.kinds[eRegisterKindProcessPlugin] = regnum; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4545 | } |
| 4546 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4547 | else if (name == "offset") |
| 4548 | { |
| 4549 | reg_offset = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4550 | } |
| 4551 | else if (name == "altname") |
| 4552 | { |
| 4553 | alt_name.SetString(value); |
| 4554 | } |
| 4555 | else if (name == "encoding") |
| 4556 | { |
| 4557 | encoding_set = true; |
| 4558 | reg_info.encoding = Args::StringToEncoding (value.data(), eEncodingUint); |
| 4559 | } |
| 4560 | else if (name == "format") |
| 4561 | { |
| 4562 | format_set = true; |
| 4563 | Format format = eFormatInvalid; |
| 4564 | if (Args::StringToFormat (value.data(), format, NULL).Success()) |
| 4565 | reg_info.format = format; |
| 4566 | else if (value == "vector-sint8") |
| 4567 | reg_info.format = eFormatVectorOfSInt8; |
| 4568 | else if (value == "vector-uint8") |
| 4569 | reg_info.format = eFormatVectorOfUInt8; |
| 4570 | else if (value == "vector-sint16") |
| 4571 | reg_info.format = eFormatVectorOfSInt16; |
| 4572 | else if (value == "vector-uint16") |
| 4573 | reg_info.format = eFormatVectorOfUInt16; |
| 4574 | else if (value == "vector-sint32") |
| 4575 | reg_info.format = eFormatVectorOfSInt32; |
| 4576 | else if (value == "vector-uint32") |
| 4577 | reg_info.format = eFormatVectorOfUInt32; |
| 4578 | else if (value == "vector-float32") |
| 4579 | reg_info.format = eFormatVectorOfFloat32; |
| 4580 | else if (value == "vector-uint128") |
| 4581 | reg_info.format = eFormatVectorOfUInt128; |
| 4582 | } |
| 4583 | else if (name == "group_id") |
| 4584 | { |
| 4585 | const uint32_t set_id = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4586 | RegisterSetMap::const_iterator pos = target_info.reg_set_map.find(set_id); |
| 4587 | if (pos != target_info.reg_set_map.end()) |
| 4588 | set_name = pos->second.name; |
| 4589 | } |
Jason Molenda | a18f707 | 2015-08-15 01:21:01 +0000 | [diff] [blame] | 4590 | else if (name == "gcc_regnum" || name == "ehframe_regnum") |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4591 | { |
Jason Molenda | a18f707 | 2015-08-15 01:21:01 +0000 | [diff] [blame] | 4592 | reg_info.kinds[eRegisterKindEHFrame] = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4593 | } |
| 4594 | else if (name == "dwarf_regnum") |
| 4595 | { |
| 4596 | reg_info.kinds[eRegisterKindDWARF] = StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); |
| 4597 | } |
| 4598 | else if (name == "generic") |
| 4599 | { |
| 4600 | reg_info.kinds[eRegisterKindGeneric] = Args::StringToGenericRegister(value.data()); |
| 4601 | } |
| 4602 | else if (name == "value_regnums") |
| 4603 | { |
| 4604 | SplitCommaSeparatedRegisterNumberString(value, value_regs, 0); |
| 4605 | } |
| 4606 | else if (name == "invalidate_regnums") |
| 4607 | { |
| 4608 | SplitCommaSeparatedRegisterNumberString(value, invalidate_regs, 0); |
| 4609 | } |
Nitesh Jain | 52b6cc5 | 2016-08-01 13:45:51 +0000 | [diff] [blame] | 4610 | else if (name == "dynamic_size_dwarf_expr_bytes") |
| 4611 | { |
| 4612 | StringExtractor opcode_extractor; |
| 4613 | std::string opcode_string = value.str (); |
| 4614 | size_t dwarf_opcode_len = opcode_string.length () / 2; |
| 4615 | assert (dwarf_opcode_len > 0); |
| 4616 | |
| 4617 | dwarf_opcode_bytes.resize (dwarf_opcode_len); |
| 4618 | reg_info.dynamic_size_dwarf_len = dwarf_opcode_len; |
| 4619 | opcode_extractor.GetStringRef ().swap (opcode_string); |
| 4620 | uint32_t ret_val = opcode_extractor.GetHexBytesAvail (dwarf_opcode_bytes.data (), |
| 4621 | dwarf_opcode_len); |
| 4622 | assert (dwarf_opcode_len == ret_val); |
| 4623 | |
| 4624 | reg_info.dynamic_size_dwarf_expr_bytes = dwarf_opcode_bytes.data (); |
| 4625 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4626 | else |
| 4627 | { |
| 4628 | printf("unhandled attribute %s = %s\n", name.data(), value.data()); |
| 4629 | } |
| 4630 | return true; // Keep iterating through all attributes |
| 4631 | }); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4632 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4633 | if (!gdb_type.empty() && !(encoding_set || format_set)) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4634 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4635 | if (gdb_type.find("int") == 0) |
| 4636 | { |
| 4637 | reg_info.format = eFormatHex; |
| 4638 | reg_info.encoding = eEncodingUint; |
| 4639 | } |
| 4640 | else if (gdb_type == "data_ptr" || gdb_type == "code_ptr") |
| 4641 | { |
| 4642 | reg_info.format = eFormatAddressInfo; |
| 4643 | reg_info.encoding = eEncodingUint; |
| 4644 | } |
| 4645 | else if (gdb_type == "i387_ext" || gdb_type == "float") |
| 4646 | { |
| 4647 | reg_info.format = eFormatFloat; |
| 4648 | reg_info.encoding = eEncodingIEEE754; |
| 4649 | } |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4650 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4651 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4652 | // Only update the register set name if we didn't get a "reg_set" attribute. |
| 4653 | // "set_name" will be empty if we didn't have a "reg_set" attribute. |
| 4654 | if (!set_name && !gdb_group.empty()) |
| 4655 | set_name.SetCString(gdb_group.c_str()); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4656 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4657 | reg_info.byte_offset = reg_offset; |
| 4658 | assert (reg_info.byte_size != 0); |
| 4659 | reg_offset += reg_info.byte_size; |
| 4660 | if (!value_regs.empty()) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4661 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4662 | value_regs.push_back(LLDB_INVALID_REGNUM); |
| 4663 | reg_info.value_regs = value_regs.data(); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4664 | } |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4665 | if (!invalidate_regs.empty()) |
| 4666 | { |
| 4667 | invalidate_regs.push_back(LLDB_INVALID_REGNUM); |
| 4668 | reg_info.invalidate_regs = invalidate_regs.data(); |
| 4669 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4670 | |
Jason Molenda | 63bd0db | 2015-09-15 23:20:34 +0000 | [diff] [blame] | 4671 | ++cur_reg_num; |
Jason Molenda | 21586c8 | 2015-09-09 03:36:24 +0000 | [diff] [blame] | 4672 | AugmentRegisterInfoViaABI (reg_info, reg_name, abi_sp); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4673 | dyn_reg_info.AddRegister(reg_info, reg_name, alt_name, set_name); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4674 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4675 | return true; // Keep iterating through all "reg" elements |
| 4676 | }); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4677 | return true; |
| 4678 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4679 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 4680 | } // namespace {} |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4681 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4682 | |
| 4683 | // query the target of gdb-remote for extended target information |
| 4684 | // return: 'true' on success |
| 4685 | // 'false' on failure |
| 4686 | bool |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 4687 | ProcessGDBRemote::GetGDBServerRegisterInfo (ArchSpec &arch_to_use) |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4688 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4689 | // Make sure LLDB has an XML parser it can use first |
| 4690 | if (!XMLDocument::XMLEnabled()) |
| 4691 | return false; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4692 | |
| 4693 | // redirect libxml2's error handler since the default prints to stdout |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4694 | |
| 4695 | GDBRemoteCommunicationClient & comm = m_gdb_comm; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4696 | |
| 4697 | // check that we have extended feature read support |
| 4698 | if ( !comm.GetQXferFeaturesReadSupported( ) ) |
| 4699 | return false; |
| 4700 | |
| 4701 | // request the target xml file |
| 4702 | std::string raw; |
| 4703 | lldb_private::Error lldberr; |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4704 | if (!comm.ReadExtFeature(ConstString("features"), |
| 4705 | ConstString("target.xml"), |
| 4706 | raw, |
| 4707 | lldberr)) |
| 4708 | { |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4709 | return false; |
| 4710 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4711 | |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4712 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4713 | XMLDocument xml_document; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4714 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4715 | if (xml_document.ParseMemory(raw.c_str(), raw.size(), "target.xml")) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4716 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4717 | GdbServerTargetInfo target_info; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4718 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4719 | XMLNode target_node = xml_document.GetRootElement("target"); |
| 4720 | if (target_node) |
Jason Molenda | 6ae1aab | 2015-04-17 19:15:02 +0000 | [diff] [blame] | 4721 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4722 | XMLNode feature_node; |
| 4723 | target_node.ForEachChildElement([&target_info, this, &feature_node](const XMLNode &node) -> bool |
| 4724 | { |
| 4725 | llvm::StringRef name = node.GetName(); |
| 4726 | if (name == "architecture") |
| 4727 | { |
| 4728 | node.GetElementText(target_info.arch); |
| 4729 | } |
| 4730 | else if (name == "osabi") |
| 4731 | { |
| 4732 | node.GetElementText(target_info.osabi); |
| 4733 | } |
Ewan Crawford | 682e842 | 2015-06-26 09:38:27 +0000 | [diff] [blame] | 4734 | else if (name == "xi:include" || name == "include") |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4735 | { |
| 4736 | llvm::StringRef href = node.GetAttributeValue("href"); |
| 4737 | if (!href.empty()) |
| 4738 | target_info.includes.push_back(href.str()); |
| 4739 | } |
| 4740 | else if (name == "feature") |
| 4741 | { |
| 4742 | feature_node = node; |
| 4743 | } |
| 4744 | else if (name == "groups") |
| 4745 | { |
| 4746 | node.ForEachChildElementWithName("group", [&target_info](const XMLNode &node) -> bool { |
| 4747 | uint32_t set_id = UINT32_MAX; |
| 4748 | RegisterSetInfo set_info; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4749 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4750 | node.ForEachAttribute([&set_id, &set_info](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
| 4751 | if (name == "id") |
| 4752 | set_id = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); |
| 4753 | if (name == "name") |
| 4754 | set_info.name = ConstString(value); |
| 4755 | return true; // Keep iterating through all attributes |
| 4756 | }); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4757 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4758 | if (set_id != UINT32_MAX) |
| 4759 | target_info.reg_set_map[set_id] = set_info; |
| 4760 | return true; // Keep iterating through all "group" elements |
| 4761 | }); |
| 4762 | } |
| 4763 | return true; // Keep iterating through all children of the target_node |
| 4764 | }); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4765 | |
Francis Ricci | 55954ae | 2016-04-25 21:03:55 +0000 | [diff] [blame] | 4766 | // Initialize these outside of ParseRegisters, since they should not be reset inside each include feature |
| 4767 | uint32_t cur_reg_num = 0; |
| 4768 | uint32_t reg_offset = 0; |
| 4769 | |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 4770 | // Don't use Process::GetABI, this code gets called from DidAttach, and in that context we haven't |
| 4771 | // set the Target's architecture yet, so the ABI is also potentially incorrect. |
| 4772 | ABISP abi_to_use_sp = ABI::FindPlugin(arch_to_use); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4773 | if (feature_node) |
| 4774 | { |
Francis Ricci | 55954ae | 2016-04-25 21:03:55 +0000 | [diff] [blame] | 4775 | ParseRegisters(feature_node, target_info, this->m_register_info, abi_to_use_sp, cur_reg_num, reg_offset); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4776 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4777 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4778 | for (const auto &include : target_info.includes) |
| 4779 | { |
| 4780 | // request register file |
| 4781 | std::string xml_data; |
| 4782 | if (!comm.ReadExtFeature(ConstString("features"), |
| 4783 | ConstString(include), |
| 4784 | xml_data, |
| 4785 | lldberr)) |
| 4786 | continue; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4787 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4788 | XMLDocument include_xml_document; |
| 4789 | include_xml_document.ParseMemory(xml_data.data(), xml_data.size(), include.c_str()); |
| 4790 | XMLNode include_feature_node = include_xml_document.GetRootElement("feature"); |
| 4791 | if (include_feature_node) |
| 4792 | { |
Francis Ricci | 55954ae | 2016-04-25 21:03:55 +0000 | [diff] [blame] | 4793 | ParseRegisters(include_feature_node, target_info, this->m_register_info, abi_to_use_sp, cur_reg_num, reg_offset); |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4794 | } |
| 4795 | } |
Jim Ingham | 7b71c0b | 2016-02-18 23:58:45 +0000 | [diff] [blame] | 4796 | this->m_register_info.Finalize(arch_to_use); |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4800 | return m_register_info.GetNumRegisters() > 0; |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4803 | Error |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 4804 | ProcessGDBRemote::GetLoadedModuleList (LoadedModuleInfoList & list) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4805 | { |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4806 | // Make sure LLDB has an XML parser it can use first |
| 4807 | if (!XMLDocument::XMLEnabled()) |
| 4808 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4809 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4810 | Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS); |
| 4811 | if (log) |
| 4812 | log->Printf ("ProcessGDBRemote::%s", __FUNCTION__); |
| 4813 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4814 | GDBRemoteCommunicationClient & comm = m_gdb_comm; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4815 | |
| 4816 | // check that we have extended feature read support |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4817 | if (comm.GetQXferLibrariesSVR4ReadSupported ()) { |
| 4818 | list.clear (); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4819 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4820 | // request the loaded library list |
| 4821 | std::string raw; |
| 4822 | lldb_private::Error lldberr; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4823 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4824 | if (!comm.ReadExtFeature (ConstString ("libraries-svr4"), ConstString (""), raw, lldberr)) |
| 4825 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4826 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4827 | // parse the xml file in memory |
| 4828 | if (log) |
| 4829 | log->Printf ("parsing: %s", raw.c_str()); |
| 4830 | XMLDocument doc; |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4831 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4832 | if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) |
| 4833 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4834 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4835 | XMLNode root_element = doc.GetRootElement("library-list-svr4"); |
| 4836 | if (!root_element) |
| 4837 | return Error(); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4838 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4839 | // main link map structure |
| 4840 | llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm"); |
| 4841 | if (!main_lm.empty()) |
| 4842 | { |
| 4843 | list.m_link_map = StringConvert::ToUInt64(main_lm.data(), LLDB_INVALID_ADDRESS, 0); |
| 4844 | } |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4845 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4846 | root_element.ForEachChildElementWithName("library", [log, &list](const XMLNode &library) -> bool { |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4847 | |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 4848 | LoadedModuleInfoList::LoadedModuleInfo module; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4849 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4850 | library.ForEachAttribute([log, &module](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4851 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4852 | if (name == "name") |
| 4853 | module.set_name (value.str()); |
| 4854 | else if (name == "lm") |
| 4855 | { |
| 4856 | // the address of the link_map struct. |
| 4857 | module.set_link_map(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4858 | } |
| 4859 | else if (name == "l_addr") |
| 4860 | { |
| 4861 | // the displacement as read from the field 'l_addr' of the link_map struct. |
| 4862 | module.set_base(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4863 | // base address is always a displacement, not an absolute value. |
| 4864 | module.set_base_is_offset(true); |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4865 | } |
| 4866 | else if (name == "l_ld") |
| 4867 | { |
| 4868 | // the memory address of the libraries PT_DYAMIC section. |
| 4869 | module.set_dynamic(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0)); |
| 4870 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 4871 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4872 | return true; // Keep iterating over all properties of "library" |
| 4873 | }); |
| 4874 | |
| 4875 | if (log) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4876 | { |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4877 | std::string name; |
| 4878 | lldb::addr_t lm=0, base=0, ld=0; |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4879 | bool base_is_offset; |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4880 | |
| 4881 | module.get_name (name); |
| 4882 | module.get_link_map (lm); |
| 4883 | module.get_base (base); |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4884 | module.get_base_is_offset (base_is_offset); |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4885 | module.get_dynamic (ld); |
| 4886 | |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4887 | log->Printf ("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64 "[%s], ld:0x%08" PRIx64 ", name:'%s')", lm, base, (base_is_offset ? "offset" : "absolute"), ld, name.c_str()); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4888 | } |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4889 | |
| 4890 | list.add (module); |
| 4891 | return true; // Keep iterating over all "library" elements in the root node |
Greg Clayton | d04f0ed | 2015-05-26 18:00:51 +0000 | [diff] [blame] | 4892 | }); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4893 | |
| 4894 | if (log) |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4895 | log->Printf ("found %" PRId32 " modules in total", (int) list.m_list.size()); |
| 4896 | } else if (comm.GetQXferLibrariesReadSupported ()) { |
| 4897 | list.clear (); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4898 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4899 | // request the loaded library list |
| 4900 | std::string raw; |
| 4901 | lldb_private::Error lldberr; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4902 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4903 | if (!comm.ReadExtFeature (ConstString ("libraries"), ConstString (""), raw, lldberr)) |
| 4904 | return Error (0, ErrorType::eErrorTypeGeneric); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4905 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4906 | if (log) |
| 4907 | log->Printf ("parsing: %s", raw.c_str()); |
| 4908 | XMLDocument doc; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4909 | |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4910 | if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) |
| 4911 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4912 | |
| 4913 | XMLNode root_element = doc.GetRootElement("library-list"); |
| 4914 | if (!root_element) |
| 4915 | return Error(); |
| 4916 | |
| 4917 | root_element.ForEachChildElementWithName("library", [log, &list](const XMLNode &library) -> bool { |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 4918 | LoadedModuleInfoList::LoadedModuleInfo module; |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4919 | |
| 4920 | llvm::StringRef name = library.GetAttributeValue("name"); |
| 4921 | module.set_name(name.str()); |
| 4922 | |
| 4923 | // The base address of a given library will be the address of its |
| 4924 | // first section. Most remotes send only one section for Windows |
| 4925 | // targets for example. |
| 4926 | const XMLNode §ion = library.FindFirstChildElementWithName("section"); |
| 4927 | llvm::StringRef address = section.GetAttributeValue("address"); |
| 4928 | module.set_base(StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0)); |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4929 | // These addresses are absolute values. |
| 4930 | module.set_base_is_offset(false); |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4931 | |
| 4932 | if (log) |
| 4933 | { |
| 4934 | std::string name; |
| 4935 | lldb::addr_t base = 0; |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4936 | bool base_is_offset; |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4937 | module.get_name (name); |
| 4938 | module.get_base (base); |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4939 | module.get_base_is_offset (base_is_offset); |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4940 | |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4941 | log->Printf ("found (base:0x%08" PRIx64 "[%s], name:'%s')", base, (base_is_offset ? "offset" : "absolute"), name.c_str()); |
Stephane Sezer | 9a7cacb | 2015-07-08 19:14:03 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | list.add (module); |
| 4945 | return true; // Keep iterating over all "library" elements in the root node |
| 4946 | }); |
| 4947 | |
| 4948 | if (log) |
| 4949 | log->Printf ("found %" PRId32 " modules in total", (int) list.m_list.size()); |
| 4950 | } else { |
| 4951 | return Error (0, ErrorType::eErrorTypeGeneric); |
| 4952 | } |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4953 | |
| 4954 | return Error(); |
| 4955 | } |
| 4956 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4957 | lldb::ModuleSP |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4958 | ProcessGDBRemote::LoadModuleAtAddress (const FileSpec &file, lldb::addr_t link_map, |
| 4959 | lldb::addr_t base_addr, bool value_is_offset) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4960 | { |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4961 | DynamicLoader *loader = GetDynamicLoader(); |
| 4962 | if (!loader) |
| 4963 | return nullptr; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4964 | |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4965 | return loader->LoadModuleAtAddress(file, link_map, base_addr, value_is_offset); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | size_t |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 4969 | ProcessGDBRemote::LoadModules (LoadedModuleInfoList &module_list) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4970 | { |
| 4971 | using lldb_private::process_gdb_remote::ProcessGDBRemote; |
| 4972 | |
| 4973 | // request a list of loaded libraries from GDBServer |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4974 | if (GetLoadedModuleList (module_list).Fail()) |
| 4975 | return 0; |
| 4976 | |
| 4977 | // get a list of all the modules |
| 4978 | ModuleList new_modules; |
| 4979 | |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 4980 | for (LoadedModuleInfoList::LoadedModuleInfo & modInfo : module_list.m_list) |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4981 | { |
| 4982 | std::string mod_name; |
| 4983 | lldb::addr_t mod_base; |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4984 | lldb::addr_t link_map; |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4985 | bool mod_base_is_offset; |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4986 | |
| 4987 | bool valid = true; |
| 4988 | valid &= modInfo.get_name (mod_name); |
| 4989 | valid &= modInfo.get_base (mod_base); |
Stephane Sezer | c6845a0 | 2015-08-20 22:07:48 +0000 | [diff] [blame] | 4990 | valid &= modInfo.get_base_is_offset (mod_base_is_offset); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 4991 | if (!valid) |
| 4992 | continue; |
| 4993 | |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4994 | if (!modInfo.get_link_map (link_map)) |
| 4995 | link_map = LLDB_INVALID_ADDRESS; |
| 4996 | |
Francis Ricci | a030061 | 2016-04-27 17:10:15 +0000 | [diff] [blame] | 4997 | FileSpec file (mod_name.c_str(), true); |
Stephane Sezer | 3553c0e | 2016-04-05 17:25:32 +0000 | [diff] [blame] | 4998 | lldb::ModuleSP module_sp = LoadModuleAtAddress (file, link_map, mod_base, |
| 4999 | mod_base_is_offset); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 5000 | |
| 5001 | if (module_sp.get()) |
| 5002 | new_modules.Append (module_sp); |
| 5003 | } |
| 5004 | |
| 5005 | if (new_modules.GetSize() > 0) |
| 5006 | { |
Francis Ricci | be8cab7 | 2016-04-25 21:02:24 +0000 | [diff] [blame] | 5007 | ModuleList removed_modules; |
Zachary Turner | 7529df9 | 2015-09-01 20:02:29 +0000 | [diff] [blame] | 5008 | Target &target = GetTarget(); |
Francis Ricci | be8cab7 | 2016-04-25 21:02:24 +0000 | [diff] [blame] | 5009 | ModuleList &loaded_modules = m_process->GetTarget().GetImages(); |
| 5010 | |
| 5011 | for (size_t i = 0; i < loaded_modules.GetSize(); ++i) |
| 5012 | { |
| 5013 | const lldb::ModuleSP loaded_module = loaded_modules.GetModuleAtIndex(i); |
| 5014 | |
| 5015 | bool found = false; |
| 5016 | for (size_t j = 0; j < new_modules.GetSize(); ++j) |
| 5017 | { |
| 5018 | if (new_modules.GetModuleAtIndex(j).get() == loaded_module.get()) |
| 5019 | found = true; |
| 5020 | } |
| 5021 | |
Francis Ricci | 80dbd15 | 2016-06-06 15:00:50 +0000 | [diff] [blame] | 5022 | // The main executable will never be included in libraries-svr4, don't remove it |
| 5023 | if (!found && loaded_module.get() != target.GetExecutableModulePointer()) |
Francis Ricci | be8cab7 | 2016-04-25 21:02:24 +0000 | [diff] [blame] | 5024 | { |
Francis Ricci | 80dbd15 | 2016-06-06 15:00:50 +0000 | [diff] [blame] | 5025 | removed_modules.Append (loaded_module); |
Francis Ricci | be8cab7 | 2016-04-25 21:02:24 +0000 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | loaded_modules.Remove (removed_modules); |
| 5030 | m_process->GetTarget().ModulesDidUnload (removed_modules, false); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 5031 | |
| 5032 | new_modules.ForEach ([&target](const lldb::ModuleSP module_sp) -> bool |
| 5033 | { |
| 5034 | lldb_private::ObjectFile * obj = module_sp->GetObjectFile (); |
| 5035 | if (!obj) |
| 5036 | return true; |
| 5037 | |
| 5038 | if (obj->GetType () != ObjectFile::Type::eTypeExecutable) |
| 5039 | return true; |
| 5040 | |
| 5041 | lldb::ModuleSP module_copy_sp = module_sp; |
| 5042 | target.SetExecutableModule (module_copy_sp, false); |
| 5043 | return false; |
| 5044 | }); |
| 5045 | |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 5046 | loaded_modules.AppendIfNeeded (new_modules); |
| 5047 | m_process->GetTarget().ModulesDidLoad (new_modules); |
| 5048 | } |
| 5049 | |
| 5050 | return new_modules.GetSize(); |
Stephane Sezer | 87b0fe0 | 2016-01-12 19:02:41 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | size_t |
| 5054 | ProcessGDBRemote::LoadModules () |
| 5055 | { |
| 5056 | LoadedModuleInfoList module_list; |
| 5057 | return LoadModules (module_list); |
Aidan Dodds | c0c8385 | 2015-05-08 09:36:31 +0000 | [diff] [blame] | 5058 | } |
Colin Riley | c3c95b2 | 2015-04-16 15:51:33 +0000 | [diff] [blame] | 5059 | |
Tamas Berghammer | 783bfc8 | 2015-06-18 20:43:56 +0000 | [diff] [blame] | 5060 | Error |
| 5061 | ProcessGDBRemote::GetFileLoadAddress(const FileSpec& file, bool& is_loaded, lldb::addr_t& load_addr) |
| 5062 | { |
| 5063 | is_loaded = false; |
| 5064 | load_addr = LLDB_INVALID_ADDRESS; |
| 5065 | |
| 5066 | std::string file_path = file.GetPath(false); |
| 5067 | if (file_path.empty ()) |
| 5068 | return Error("Empty file name specified"); |
| 5069 | |
| 5070 | StreamString packet; |
| 5071 | packet.PutCString("qFileLoadAddress:"); |
| 5072 | packet.PutCStringAsRawHex8(file_path.c_str()); |
| 5073 | |
| 5074 | StringExtractorGDBRemote response; |
| 5075 | if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), response, false) != GDBRemoteCommunication::PacketResult::Success) |
| 5076 | return Error("Sending qFileLoadAddress packet failed"); |
| 5077 | |
| 5078 | if (response.IsErrorResponse()) |
| 5079 | { |
| 5080 | if (response.GetError() == 1) |
| 5081 | { |
| 5082 | // The file is not loaded into the inferior |
| 5083 | is_loaded = false; |
| 5084 | load_addr = LLDB_INVALID_ADDRESS; |
| 5085 | return Error(); |
| 5086 | } |
| 5087 | |
| 5088 | return Error("Fetching file load address from remote server returned an error"); |
| 5089 | } |
| 5090 | |
| 5091 | if (response.IsNormalResponse()) |
| 5092 | { |
| 5093 | is_loaded = true; |
| 5094 | load_addr = response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 5095 | return Error(); |
| 5096 | } |
| 5097 | |
| 5098 | return Error("Unknown error happened during sending the load address packet"); |
| 5099 | } |
| 5100 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5101 | |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 5102 | void |
| 5103 | ProcessGDBRemote::ModulesDidLoad (ModuleList &module_list) |
| 5104 | { |
| 5105 | // We must call the lldb_private::Process::ModulesDidLoad () first before we do anything |
| 5106 | Process::ModulesDidLoad (module_list); |
| 5107 | |
| 5108 | // After loading shared libraries, we can ask our remote GDB server if |
| 5109 | // it needs any symbols. |
| 5110 | m_gdb_comm.ServeSymbolLookups(this); |
| 5111 | } |
| 5112 | |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 5113 | void |
| 5114 | ProcessGDBRemote::HandleAsyncStdout(llvm::StringRef out) |
| 5115 | { |
| 5116 | AppendSTDOUT(out.data(), out.size()); |
| 5117 | } |
| 5118 | |
| 5119 | static const char *end_delimiter = "--end--;"; |
| 5120 | static const int end_delimiter_len = 8; |
| 5121 | |
| 5122 | void |
| 5123 | ProcessGDBRemote::HandleAsyncMisc(llvm::StringRef data) |
| 5124 | { |
| 5125 | std::string input = data.str(); // '1' to move beyond 'A' |
| 5126 | if (m_partial_profile_data.length() > 0) |
| 5127 | { |
| 5128 | m_partial_profile_data.append(input); |
| 5129 | input = m_partial_profile_data; |
| 5130 | m_partial_profile_data.clear(); |
| 5131 | } |
| 5132 | |
| 5133 | size_t found, pos = 0, len = input.length(); |
| 5134 | while ((found = input.find(end_delimiter, pos)) != std::string::npos) |
| 5135 | { |
| 5136 | StringExtractorGDBRemote profileDataExtractor(input.substr(pos, found).c_str()); |
| 5137 | std::string profile_data = HarmonizeThreadIdsForProfileData(profileDataExtractor); |
| 5138 | BroadcastAsyncProfileData(profile_data); |
| 5139 | |
| 5140 | pos = found + end_delimiter_len; |
| 5141 | } |
| 5142 | |
| 5143 | if (pos < len) |
| 5144 | { |
| 5145 | // Last incomplete chunk. |
| 5146 | m_partial_profile_data = input.substr(pos); |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | std::string |
| 5151 | ProcessGDBRemote::HarmonizeThreadIdsForProfileData(StringExtractorGDBRemote &profileDataExtractor) |
| 5152 | { |
| 5153 | std::map<uint64_t, uint32_t> new_thread_id_to_used_usec_map; |
| 5154 | std::stringstream final_output; |
| 5155 | std::string name, value; |
| 5156 | |
| 5157 | // Going to assuming thread_used_usec comes first, else bail out. |
| 5158 | while (profileDataExtractor.GetNameColonValue(name, value)) |
| 5159 | { |
| 5160 | if (name.compare("thread_used_id") == 0) |
| 5161 | { |
| 5162 | StringExtractor threadIDHexExtractor(value.c_str()); |
| 5163 | uint64_t thread_id = threadIDHexExtractor.GetHexMaxU64(false, 0); |
| 5164 | |
| 5165 | bool has_used_usec = false; |
| 5166 | uint32_t curr_used_usec = 0; |
| 5167 | std::string usec_name, usec_value; |
| 5168 | uint32_t input_file_pos = profileDataExtractor.GetFilePos(); |
| 5169 | if (profileDataExtractor.GetNameColonValue(usec_name, usec_value)) |
| 5170 | { |
| 5171 | if (usec_name.compare("thread_used_usec") == 0) |
| 5172 | { |
| 5173 | has_used_usec = true; |
| 5174 | curr_used_usec = strtoull(usec_value.c_str(), NULL, 0); |
| 5175 | } |
| 5176 | else |
| 5177 | { |
| 5178 | // We didn't find what we want, it is probably |
| 5179 | // an older version. Bail out. |
| 5180 | profileDataExtractor.SetFilePos(input_file_pos); |
| 5181 | } |
| 5182 | } |
| 5183 | |
| 5184 | if (has_used_usec) |
| 5185 | { |
| 5186 | uint32_t prev_used_usec = 0; |
| 5187 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_used_usec_map.find(thread_id); |
| 5188 | if (iterator != m_thread_id_to_used_usec_map.end()) |
| 5189 | { |
| 5190 | prev_used_usec = m_thread_id_to_used_usec_map[thread_id]; |
| 5191 | } |
| 5192 | |
| 5193 | uint32_t real_used_usec = curr_used_usec - prev_used_usec; |
| 5194 | // A good first time record is one that runs for at least 0.25 sec |
| 5195 | bool good_first_time = (prev_used_usec == 0) && (real_used_usec > 250000); |
| 5196 | bool good_subsequent_time = |
| 5197 | (prev_used_usec > 0) && ((real_used_usec > 0) || (HasAssignedIndexIDToThread(thread_id))); |
| 5198 | |
| 5199 | if (good_first_time || good_subsequent_time) |
| 5200 | { |
| 5201 | // We try to avoid doing too many index id reservation, |
| 5202 | // resulting in fast increase of index ids. |
| 5203 | |
| 5204 | final_output << name << ":"; |
| 5205 | int32_t index_id = AssignIndexIDToThread(thread_id); |
| 5206 | final_output << index_id << ";"; |
| 5207 | |
| 5208 | final_output << usec_name << ":" << usec_value << ";"; |
| 5209 | } |
| 5210 | else |
| 5211 | { |
| 5212 | // Skip past 'thread_used_name'. |
| 5213 | std::string local_name, local_value; |
| 5214 | profileDataExtractor.GetNameColonValue(local_name, local_value); |
| 5215 | } |
| 5216 | |
| 5217 | // Store current time as previous time so that they can be compared later. |
| 5218 | new_thread_id_to_used_usec_map[thread_id] = curr_used_usec; |
| 5219 | } |
| 5220 | else |
| 5221 | { |
| 5222 | // Bail out and use old string. |
| 5223 | final_output << name << ":" << value << ";"; |
| 5224 | } |
| 5225 | } |
| 5226 | else |
| 5227 | { |
| 5228 | final_output << name << ":" << value << ";"; |
| 5229 | } |
| 5230 | } |
| 5231 | final_output << end_delimiter; |
| 5232 | m_thread_id_to_used_usec_map = new_thread_id_to_used_usec_map; |
| 5233 | |
| 5234 | return final_output.str(); |
| 5235 | } |
| 5236 | |
| 5237 | void |
| 5238 | ProcessGDBRemote::HandleStopReply() |
| 5239 | { |
| 5240 | if (GetStopID() != 0) |
| 5241 | return; |
| 5242 | |
| 5243 | if (GetID() == LLDB_INVALID_PROCESS_ID) |
| 5244 | { |
| 5245 | lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID(); |
| 5246 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 5247 | SetID(pid); |
| 5248 | } |
| 5249 | BuildDynamicRegisterInfo(true); |
| 5250 | } |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5251 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame^] | 5252 | bool |
| 5253 | ProcessGDBRemote::HandleAsyncStructuredData(const StructuredData::ObjectSP |
| 5254 | &object_sp) |
| 5255 | { |
| 5256 | return RouteAsyncStructuredData(object_sp); |
| 5257 | } |
| 5258 | |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5259 | class CommandObjectProcessGDBRemoteSpeedTest: public CommandObjectParsed |
| 5260 | { |
| 5261 | public: |
| 5262 | CommandObjectProcessGDBRemoteSpeedTest(CommandInterpreter &interpreter) : |
| 5263 | CommandObjectParsed (interpreter, |
| 5264 | "process plugin packet speed-test", |
| 5265 | "Tests packet speeds of various sizes to determine the performance characteristics of the GDB remote connection. ", |
| 5266 | NULL), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 5267 | m_option_group (), |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5268 | 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), |
| 5269 | 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), |
| 5270 | 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), |
| 5271 | m_json (LLDB_OPT_SET_1, false, "json", 'j', "Print the output as JSON data for easy parsing.", false, true) |
| 5272 | { |
| 5273 | m_option_group.Append (&m_num_packets, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 5274 | m_option_group.Append (&m_max_send, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 5275 | m_option_group.Append (&m_max_recv, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 5276 | m_option_group.Append (&m_json, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 5277 | m_option_group.Finalize(); |
| 5278 | } |
| 5279 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5280 | ~CommandObjectProcessGDBRemoteSpeedTest () |
| 5281 | { |
| 5282 | } |
| 5283 | |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5284 | |
| 5285 | Options * |
| 5286 | GetOptions () override |
| 5287 | { |
| 5288 | return &m_option_group; |
| 5289 | } |
| 5290 | |
| 5291 | bool |
| 5292 | DoExecute (Args& command, CommandReturnObject &result) override |
| 5293 | { |
| 5294 | const size_t argc = command.GetArgumentCount(); |
| 5295 | if (argc == 0) |
| 5296 | { |
| 5297 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5298 | if (process) |
| 5299 | { |
| 5300 | StreamSP output_stream_sp (m_interpreter.GetDebugger().GetAsyncOutputStream()); |
| 5301 | result.SetImmediateOutputStream (output_stream_sp); |
| 5302 | |
| 5303 | const uint32_t num_packets = (uint32_t)m_num_packets.GetOptionValue().GetCurrentValue(); |
| 5304 | const uint64_t max_send = m_max_send.GetOptionValue().GetCurrentValue(); |
| 5305 | const uint64_t max_recv = m_max_recv.GetOptionValue().GetCurrentValue(); |
| 5306 | const bool json = m_json.GetOptionValue().GetCurrentValue(); |
| 5307 | if (output_stream_sp) |
| 5308 | process->GetGDBRemote().TestPacketSpeed (num_packets, max_send, max_recv, json, *output_stream_sp); |
| 5309 | else |
| 5310 | { |
| 5311 | process->GetGDBRemote().TestPacketSpeed (num_packets, max_send, max_recv, json, result.GetOutputStream()); |
| 5312 | } |
| 5313 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5314 | return true; |
| 5315 | } |
| 5316 | } |
| 5317 | else |
| 5318 | { |
| 5319 | result.AppendErrorWithFormat ("'%s' takes no arguments", m_cmd_name.c_str()); |
| 5320 | } |
| 5321 | result.SetStatus (eReturnStatusFailed); |
| 5322 | return false; |
| 5323 | } |
| 5324 | protected: |
| 5325 | OptionGroupOptions m_option_group; |
| 5326 | OptionGroupUInt64 m_num_packets; |
| 5327 | OptionGroupUInt64 m_max_send; |
| 5328 | OptionGroupUInt64 m_max_recv; |
| 5329 | OptionGroupBoolean m_json; |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5330 | |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5331 | }; |
| 5332 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5333 | class CommandObjectProcessGDBRemotePacketHistory : public CommandObjectParsed |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5334 | { |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5335 | private: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5336 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5337 | public: |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5338 | CommandObjectProcessGDBRemotePacketHistory(CommandInterpreter &interpreter) : |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5339 | CommandObjectParsed (interpreter, |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5340 | "process plugin packet history", |
| 5341 | "Dumps the packet history buffer. ", |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5342 | NULL) |
| 5343 | { |
| 5344 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5345 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5346 | ~CommandObjectProcessGDBRemotePacketHistory () |
| 5347 | { |
| 5348 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5349 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5350 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 5351 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5352 | { |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5353 | const size_t argc = command.GetArgumentCount(); |
| 5354 | if (argc == 0) |
| 5355 | { |
| 5356 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5357 | if (process) |
| 5358 | { |
| 5359 | process->GetGDBRemote().DumpHistory(result.GetOutputStream()); |
| 5360 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5361 | return true; |
| 5362 | } |
| 5363 | } |
| 5364 | else |
| 5365 | { |
| 5366 | result.AppendErrorWithFormat ("'%s' takes no arguments", m_cmd_name.c_str()); |
| 5367 | } |
| 5368 | result.SetStatus (eReturnStatusFailed); |
| 5369 | return false; |
| 5370 | } |
| 5371 | }; |
| 5372 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5373 | class CommandObjectProcessGDBRemotePacketXferSize : public CommandObjectParsed |
| 5374 | { |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5375 | private: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5376 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5377 | public: |
| 5378 | CommandObjectProcessGDBRemotePacketXferSize(CommandInterpreter &interpreter) : |
| 5379 | CommandObjectParsed (interpreter, |
| 5380 | "process plugin packet xfer-size", |
| 5381 | "Maximum size that lldb will try to read/write one one chunk.", |
| 5382 | NULL) |
| 5383 | { |
| 5384 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5385 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5386 | ~CommandObjectProcessGDBRemotePacketXferSize () |
| 5387 | { |
| 5388 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5389 | |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5390 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 5391 | DoExecute (Args& command, CommandReturnObject &result) override |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5392 | { |
| 5393 | const size_t argc = command.GetArgumentCount(); |
| 5394 | if (argc == 0) |
| 5395 | { |
| 5396 | result.AppendErrorWithFormat ("'%s' takes an argument to specify the max amount to be transferred when reading/writing", m_cmd_name.c_str()); |
| 5397 | result.SetStatus (eReturnStatusFailed); |
| 5398 | return false; |
| 5399 | } |
| 5400 | |
| 5401 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5402 | if (process) |
| 5403 | { |
| 5404 | const char *packet_size = command.GetArgumentAtIndex(0); |
| 5405 | errno = 0; |
| 5406 | uint64_t user_specified_max = strtoul (packet_size, NULL, 10); |
| 5407 | if (errno == 0 && user_specified_max != 0) |
| 5408 | { |
| 5409 | process->SetUserSpecifiedMaxMemoryTransferSize (user_specified_max); |
| 5410 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5411 | return true; |
| 5412 | } |
| 5413 | } |
| 5414 | result.SetStatus (eReturnStatusFailed); |
| 5415 | return false; |
| 5416 | } |
| 5417 | }; |
| 5418 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5419 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5420 | class CommandObjectProcessGDBRemotePacketSend : public CommandObjectParsed |
| 5421 | { |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5422 | private: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5423 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5424 | public: |
| 5425 | CommandObjectProcessGDBRemotePacketSend(CommandInterpreter &interpreter) : |
| 5426 | CommandObjectParsed (interpreter, |
| 5427 | "process plugin packet send", |
| 5428 | "Send a custom packet through the GDB remote protocol and print the answer. " |
| 5429 | "The packet header and footer will automatically be added to the packet prior to sending and stripped from the result.", |
| 5430 | NULL) |
| 5431 | { |
| 5432 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5433 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5434 | ~CommandObjectProcessGDBRemotePacketSend () |
| 5435 | { |
| 5436 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5437 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5438 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 5439 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5440 | { |
| 5441 | const size_t argc = command.GetArgumentCount(); |
| 5442 | if (argc == 0) |
| 5443 | { |
| 5444 | result.AppendErrorWithFormat ("'%s' takes a one or more packet content arguments", m_cmd_name.c_str()); |
| 5445 | result.SetStatus (eReturnStatusFailed); |
| 5446 | return false; |
| 5447 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5448 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5449 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5450 | if (process) |
| 5451 | { |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 5452 | for (size_t i=0; i<argc; ++ i) |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5453 | { |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 5454 | const char *packet_cstr = command.GetArgumentAtIndex(0); |
| 5455 | bool send_async = true; |
| 5456 | StringExtractorGDBRemote response; |
| 5457 | process->GetGDBRemote().SendPacketAndWaitForResponse(packet_cstr, response, send_async); |
| 5458 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5459 | Stream &output_strm = result.GetOutputStream(); |
| 5460 | output_strm.Printf (" packet: %s\n", packet_cstr); |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 5461 | std::string &response_str = response.GetStringRef(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5462 | |
Han Ming Ong | 399289e | 2013-06-21 19:56:59 +0000 | [diff] [blame] | 5463 | if (strstr(packet_cstr, "qGetProfileData") != NULL) |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 5464 | { |
Pavel Labath | 8c1b6bd | 2016-08-09 12:04:46 +0000 | [diff] [blame] | 5465 | response_str = process->HarmonizeThreadIdsForProfileData(response); |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 5466 | } |
| 5467 | |
Han Ming Ong | 8414585 | 2012-11-26 20:42:03 +0000 | [diff] [blame] | 5468 | if (response_str.empty()) |
| 5469 | output_strm.PutCString ("response: \nerror: UNIMPLEMENTED\n"); |
| 5470 | else |
| 5471 | output_strm.Printf ("response: %s\n", response.GetStringRef().c_str()); |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5472 | } |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5473 | } |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5474 | return true; |
| 5475 | } |
| 5476 | }; |
| 5477 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5478 | class CommandObjectProcessGDBRemotePacketMonitor : public CommandObjectRaw |
| 5479 | { |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5480 | private: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5481 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5482 | public: |
| 5483 | CommandObjectProcessGDBRemotePacketMonitor(CommandInterpreter &interpreter) : |
| 5484 | CommandObjectRaw (interpreter, |
| 5485 | "process plugin packet monitor", |
Greg Clayton | eee5e98 | 2013-02-14 18:39:30 +0000 | [diff] [blame] | 5486 | "Send a qRcmd packet through the GDB remote protocol and print the response." |
| 5487 | "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] | 5488 | NULL) |
| 5489 | { |
| 5490 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5491 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5492 | ~CommandObjectProcessGDBRemotePacketMonitor () |
| 5493 | { |
| 5494 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5495 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5496 | bool |
Tamas Berghammer | 30b8cd3 | 2015-03-23 15:50:03 +0000 | [diff] [blame] | 5497 | DoExecute (const char *command, CommandReturnObject &result) override |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5498 | { |
| 5499 | if (command == NULL || command[0] == '\0') |
| 5500 | { |
| 5501 | result.AppendErrorWithFormat ("'%s' takes a command string argument", m_cmd_name.c_str()); |
| 5502 | result.SetStatus (eReturnStatusFailed); |
| 5503 | return false; |
| 5504 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5505 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5506 | ProcessGDBRemote *process = (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr(); |
| 5507 | if (process) |
| 5508 | { |
| 5509 | StreamString packet; |
Greg Clayton | eee5e98 | 2013-02-14 18:39:30 +0000 | [diff] [blame] | 5510 | packet.PutCString("qRcmd,"); |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5511 | packet.PutBytesAsRawHex8(command, strlen(command)); |
| 5512 | const char *packet_cstr = packet.GetString().c_str(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5513 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5514 | bool send_async = true; |
| 5515 | StringExtractorGDBRemote response; |
| 5516 | process->GetGDBRemote().SendPacketAndWaitForResponse(packet_cstr, response, send_async); |
| 5517 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 5518 | Stream &output_strm = result.GetOutputStream(); |
| 5519 | output_strm.Printf (" packet: %s\n", packet_cstr); |
| 5520 | const std::string &response_str = response.GetStringRef(); |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5521 | |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5522 | if (response_str.empty()) |
| 5523 | output_strm.PutCString ("response: \nerror: UNIMPLEMENTED\n"); |
| 5524 | else |
| 5525 | output_strm.Printf ("response: %s\n", response.GetStringRef().c_str()); |
| 5526 | } |
| 5527 | return true; |
| 5528 | } |
| 5529 | }; |
| 5530 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5531 | class CommandObjectProcessGDBRemotePacket : public CommandObjectMultiword |
| 5532 | { |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5533 | private: |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5534 | |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5535 | public: |
| 5536 | CommandObjectProcessGDBRemotePacket(CommandInterpreter &interpreter) : |
| 5537 | CommandObjectMultiword (interpreter, |
| 5538 | "process plugin packet", |
| 5539 | "Commands that deal with GDB remote packets.", |
| 5540 | NULL) |
| 5541 | { |
| 5542 | LoadSubCommand ("history", CommandObjectSP (new CommandObjectProcessGDBRemotePacketHistory (interpreter))); |
| 5543 | LoadSubCommand ("send", CommandObjectSP (new CommandObjectProcessGDBRemotePacketSend (interpreter))); |
Greg Clayton | ba4a0a5 | 2013-02-01 23:03:47 +0000 | [diff] [blame] | 5544 | LoadSubCommand ("monitor", CommandObjectSP (new CommandObjectProcessGDBRemotePacketMonitor (interpreter))); |
Jason Molenda | 6076bf4 | 2014-05-06 04:34:52 +0000 | [diff] [blame] | 5545 | LoadSubCommand ("xfer-size", CommandObjectSP (new CommandObjectProcessGDBRemotePacketXferSize (interpreter))); |
Greg Clayton | e034a04 | 2015-05-21 20:52:06 +0000 | [diff] [blame] | 5546 | LoadSubCommand ("speed-test", CommandObjectSP (new CommandObjectProcessGDBRemoteSpeedTest (interpreter))); |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5547 | } |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5548 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5549 | ~CommandObjectProcessGDBRemotePacket () |
| 5550 | { |
Ed Maste | 81b4c5f | 2016-01-04 01:43:47 +0000 | [diff] [blame] | 5551 | } |
Greg Clayton | 02686b8 | 2012-10-15 22:42:16 +0000 | [diff] [blame] | 5552 | }; |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5553 | |
| 5554 | class CommandObjectMultiwordProcessGDBRemote : public CommandObjectMultiword |
| 5555 | { |
| 5556 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 5557 | CommandObjectMultiwordProcessGDBRemote(CommandInterpreter &interpreter) |
| 5558 | : CommandObjectMultiword(interpreter, "process plugin", "Commands for operating on a ProcessGDBRemote process.", |
| 5559 | "process plugin <subcommand> [<subcommand-options>]") |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5560 | { |
| 5561 | LoadSubCommand ("packet", CommandObjectSP (new CommandObjectProcessGDBRemotePacket (interpreter))); |
| 5562 | } |
| 5563 | |
Eugene Zelenko | 0722f08 | 2015-10-24 01:28:05 +0000 | [diff] [blame] | 5564 | ~CommandObjectMultiwordProcessGDBRemote () |
| 5565 | { |
| 5566 | } |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5567 | }; |
| 5568 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 5569 | CommandObject * |
| 5570 | ProcessGDBRemote::GetPluginCommandObject() |
| 5571 | { |
| 5572 | if (!m_command_sp) |
| 5573 | m_command_sp.reset (new CommandObjectMultiwordProcessGDBRemote (GetTarget().GetDebugger().GetCommandInterpreter())); |
| 5574 | return m_command_sp.get(); |
| 5575 | } |