Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1 | //===-- Target.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 | |
| 10 | #include "lldb/Target/Target.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Breakpoint/BreakpointResolver.h" |
| 17 | #include "lldb/Breakpoint/BreakpointResolverAddress.h" |
| 18 | #include "lldb/Breakpoint/BreakpointResolverFileLine.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 | [diff] [blame] | 19 | #include "lldb/Breakpoint/BreakpointResolverFileRegex.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 20 | #include "lldb/Breakpoint/BreakpointResolverName.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 21 | #include "lldb/Breakpoint/Watchpoint.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 22 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 23 | #include "lldb/Core/Event.h" |
| 24 | #include "lldb/Core/Log.h" |
Caroline Tice | 969ed3d1 | 2011-05-02 20:41:46 | [diff] [blame] | 25 | #include "lldb/Core/StreamAsynchronousIO.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 26 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 27 | #include "lldb/Core/Timer.h" |
| 28 | #include "lldb/Core/ValueObject.h" |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 | [diff] [blame^] | 29 | #include "lldb/Expression/ClangASTSource.h" |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 | [diff] [blame] | 30 | #include "lldb/Expression/ClangUserExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 31 | #include "lldb/Host/Host.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 32 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 33 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 34 | #include "lldb/lldb-private-log.h" |
| 35 | #include "lldb/Symbol/ObjectFile.h" |
| 36 | #include "lldb/Target/Process.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 37 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 38 | #include "lldb/Target/Thread.h" |
| 39 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
| 44 | //---------------------------------------------------------------------- |
| 45 | // Target constructor |
| 46 | //---------------------------------------------------------------------- |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 47 | Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) : |
| 48 | Broadcaster ("lldb.target"), |
| 49 | ExecutionContextScope (), |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 50 | TargetInstanceSettings (*GetSettingsController()), |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 | [diff] [blame] | 51 | m_debugger (debugger), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 52 | m_platform_sp (platform_sp), |
Greg Clayton | af67cec | 2010-12-20 20:49:23 | [diff] [blame] | 53 | m_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 54 | m_arch (target_arch), |
| 55 | m_images (), |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 56 | m_section_load_list (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 57 | m_breakpoint_list (false), |
| 58 | m_internal_breakpoint_list (true), |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 59 | m_watchpoint_list (), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 60 | m_process_sp (), |
| 61 | m_search_filter_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 62 | m_image_search_paths (ImageSearchPathsChanged, this), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 63 | m_scratch_ast_context_ap (NULL), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 64 | m_persistent_variables (), |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 | [diff] [blame] | 65 | m_source_manager(*this), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 66 | m_stop_hooks (), |
Jim Ingham | 6026ca3 | 2011-05-12 02:06:14 | [diff] [blame] | 67 | m_stop_hook_next_id (0), |
| 68 | m_suppress_stop_hooks (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 69 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 | [diff] [blame] | 70 | SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 71 | SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); |
| 72 | SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); |
| 73 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 74 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 75 | if (log) |
| 76 | log->Printf ("%p Target::Target()", this); |
| 77 | } |
| 78 | |
| 79 | //---------------------------------------------------------------------- |
| 80 | // Destructor |
| 81 | //---------------------------------------------------------------------- |
| 82 | Target::~Target() |
| 83 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 84 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 85 | if (log) |
| 86 | log->Printf ("%p Target::~Target()", this); |
| 87 | DeleteCurrentProcess (); |
| 88 | } |
| 89 | |
| 90 | void |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 91 | Target::Dump (Stream *s, lldb::DescriptionLevel description_level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 92 | { |
Greg Clayton | 8941142 | 2010-10-08 00:21:05 | [diff] [blame] | 93 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 94 | if (description_level != lldb::eDescriptionLevelBrief) |
| 95 | { |
| 96 | s->Indent(); |
| 97 | s->PutCString("Target\n"); |
| 98 | s->IndentMore(); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 | [diff] [blame] | 99 | m_images.Dump(s); |
| 100 | m_breakpoint_list.Dump(s); |
| 101 | m_internal_breakpoint_list.Dump(s); |
| 102 | s->IndentLess(); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 103 | } |
| 104 | else |
| 105 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 106 | Module *exe_module = GetExecutableModulePointer(); |
| 107 | if (exe_module) |
| 108 | s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString()); |
Jim Ingham | 48028b6 | 2011-05-12 01:12:28 | [diff] [blame] | 109 | else |
| 110 | s->PutCString ("No executable module."); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 111 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void |
| 115 | Target::DeleteCurrentProcess () |
| 116 | { |
| 117 | if (m_process_sp.get()) |
| 118 | { |
Greg Clayton | 17f6920 | 2010-09-14 23:52:43 | [diff] [blame] | 119 | m_section_load_list.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 120 | if (m_process_sp->IsAlive()) |
| 121 | m_process_sp->Destroy(); |
Jim Ingham | d0a3e12b | 2011-02-16 17:54:55 | [diff] [blame] | 122 | |
| 123 | m_process_sp->Finalize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 124 | |
| 125 | // Do any cleanup of the target we need to do between process instances. |
| 126 | // NB It is better to do this before destroying the process in case the |
| 127 | // clean up needs some help from the process. |
| 128 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 129 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 130 | // Disable watchpoints just on the debugger side. |
| 131 | DisableAllWatchpoints(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 132 | m_process_sp.reset(); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | const lldb::ProcessSP & |
| 137 | Target::CreateProcess (Listener &listener, const char *plugin_name) |
| 138 | { |
| 139 | DeleteCurrentProcess (); |
| 140 | m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener)); |
| 141 | return m_process_sp; |
| 142 | } |
| 143 | |
| 144 | const lldb::ProcessSP & |
| 145 | Target::GetProcessSP () const |
| 146 | { |
| 147 | return m_process_sp; |
| 148 | } |
| 149 | |
| 150 | lldb::TargetSP |
| 151 | Target::GetSP() |
| 152 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 | [diff] [blame] | 153 | // This object contains an instrusive ref count base class so we can |
| 154 | // easily make a shared pointer to this object |
| 155 | return TargetSP(this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 156 | } |
| 157 | |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 | [diff] [blame] | 158 | void |
| 159 | Target::Destroy() |
| 160 | { |
| 161 | Mutex::Locker locker (m_mutex); |
| 162 | DeleteCurrentProcess (); |
| 163 | m_platform_sp.reset(); |
| 164 | m_arch.Clear(); |
| 165 | m_images.Clear(); |
| 166 | m_section_load_list.Clear(); |
| 167 | const bool notify = false; |
| 168 | m_breakpoint_list.RemoveAll(notify); |
| 169 | m_internal_breakpoint_list.RemoveAll(notify); |
| 170 | m_last_created_breakpoint.reset(); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 171 | m_last_created_watchpoint.reset(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 | [diff] [blame] | 172 | m_search_filter_sp.reset(); |
| 173 | m_image_search_paths.Clear(notify); |
| 174 | m_scratch_ast_context_ap.reset(); |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 | [diff] [blame^] | 175 | m_scratch_ast_source_ap.reset(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 | [diff] [blame] | 176 | m_persistent_variables.Clear(); |
| 177 | m_stop_hooks.clear(); |
| 178 | m_stop_hook_next_id = 0; |
| 179 | m_suppress_stop_hooks = false; |
| 180 | } |
| 181 | |
| 182 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 183 | BreakpointList & |
| 184 | Target::GetBreakpointList(bool internal) |
| 185 | { |
| 186 | if (internal) |
| 187 | return m_internal_breakpoint_list; |
| 188 | else |
| 189 | return m_breakpoint_list; |
| 190 | } |
| 191 | |
| 192 | const BreakpointList & |
| 193 | Target::GetBreakpointList(bool internal) const |
| 194 | { |
| 195 | if (internal) |
| 196 | return m_internal_breakpoint_list; |
| 197 | else |
| 198 | return m_breakpoint_list; |
| 199 | } |
| 200 | |
| 201 | BreakpointSP |
| 202 | Target::GetBreakpointByID (break_id_t break_id) |
| 203 | { |
| 204 | BreakpointSP bp_sp; |
| 205 | |
| 206 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 207 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 208 | else |
| 209 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 210 | |
| 211 | return bp_sp; |
| 212 | } |
| 213 | |
| 214 | BreakpointSP |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 215 | Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules, |
| 216 | const FileSpecList *source_file_spec_list, |
Jim Ingham | 969795f | 2011-09-21 01:17:13 | [diff] [blame] | 217 | RegularExpression &source_regex, |
| 218 | bool internal) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 219 | { |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 220 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list)); |
| 221 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 | [diff] [blame] | 222 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 223 | } |
| 224 | |
| 225 | |
| 226 | BreakpointSP |
| 227 | Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal) |
| 228 | { |
| 229 | SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 230 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines)); |
| 231 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | BreakpointSP |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 236 | Target::CreateBreakpoint (lldb::addr_t addr, bool internal) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 237 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 238 | Address so_addr; |
| 239 | // Attempt to resolve our load address if possible, though it is ok if |
| 240 | // it doesn't resolve to section/offset. |
| 241 | |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 242 | // Try and resolve as a load address if possible |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 243 | m_section_load_list.ResolveLoadAddress(addr, so_addr); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 244 | if (!so_addr.IsValid()) |
| 245 | { |
| 246 | // The address didn't resolve, so just set this as an absolute address |
| 247 | so_addr.SetOffset (addr); |
| 248 | } |
| 249 | BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 250 | return bp_sp; |
| 251 | } |
| 252 | |
| 253 | BreakpointSP |
| 254 | Target::CreateBreakpoint (Address &addr, bool internal) |
| 255 | { |
| 256 | TargetSP target_sp = this->GetSP(); |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 257 | SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (target_sp)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 258 | BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); |
| 259 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 260 | } |
| 261 | |
| 262 | BreakpointSP |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 263 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
| 264 | const FileSpecList *containingSourceFiles, |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 265 | const char *func_name, |
| 266 | uint32_t func_name_type_mask, |
| 267 | bool internal, |
| 268 | LazyBool skip_prologue) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 269 | { |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 | [diff] [blame] | 270 | BreakpointSP bp_sp; |
| 271 | if (func_name) |
| 272 | { |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 273 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 274 | |
| 275 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, |
| 276 | func_name, |
| 277 | func_name_type_mask, |
| 278 | Breakpoint::Exact, |
| 279 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 | [diff] [blame] | 280 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 281 | } |
| 282 | return bp_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
| 286 | SearchFilterSP |
| 287 | Target::GetSearchFilterForModule (const FileSpec *containingModule) |
| 288 | { |
| 289 | SearchFilterSP filter_sp; |
| 290 | lldb::TargetSP target_sp = this->GetSP(); |
| 291 | if (containingModule != NULL) |
| 292 | { |
| 293 | // TODO: We should look into sharing module based search filters |
| 294 | // across many breakpoints like we do for the simple target based one |
| 295 | filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule)); |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | if (m_search_filter_sp.get() == NULL) |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 300 | m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 301 | filter_sp = m_search_filter_sp; |
| 302 | } |
| 303 | return filter_sp; |
| 304 | } |
| 305 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 | [diff] [blame] | 306 | SearchFilterSP |
| 307 | Target::GetSearchFilterForModuleList (const FileSpecList *containingModules) |
| 308 | { |
| 309 | SearchFilterSP filter_sp; |
| 310 | lldb::TargetSP target_sp = this->GetSP(); |
| 311 | if (containingModules && containingModules->GetSize() != 0) |
| 312 | { |
| 313 | // TODO: We should look into sharing module based search filters |
| 314 | // across many breakpoints like we do for the simple target based one |
| 315 | filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules)); |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | if (m_search_filter_sp.get() == NULL) |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 320 | m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 | [diff] [blame] | 321 | filter_sp = m_search_filter_sp; |
| 322 | } |
| 323 | return filter_sp; |
| 324 | } |
| 325 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 326 | SearchFilterSP |
| 327 | Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles) |
| 328 | { |
| 329 | if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0) |
| 330 | return GetSearchFilterForModuleList(containingModules); |
| 331 | |
| 332 | SearchFilterSP filter_sp; |
| 333 | lldb::TargetSP target_sp = this->GetSP(); |
| 334 | if (containingModules == NULL) |
| 335 | { |
| 336 | // We could make a special "CU List only SearchFilter". Better yet was if these could be composable, |
| 337 | // but that will take a little reworking. |
| 338 | |
| 339 | filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, FileSpecList(), *containingSourceFiles)); |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, *containingModules, *containingSourceFiles)); |
| 344 | } |
| 345 | return filter_sp; |
| 346 | } |
| 347 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 348 | BreakpointSP |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 349 | Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules, |
| 350 | const FileSpecList *containingSourceFiles, |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 351 | RegularExpression &func_regex, |
| 352 | bool internal, |
| 353 | LazyBool skip_prologue) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 354 | { |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 | [diff] [blame] | 355 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 356 | BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, |
| 357 | func_regex, |
| 358 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 359 | |
| 360 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 361 | } |
| 362 | |
| 363 | BreakpointSP |
| 364 | Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal) |
| 365 | { |
| 366 | BreakpointSP bp_sp; |
| 367 | if (filter_sp && resolver_sp) |
| 368 | { |
| 369 | bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp)); |
| 370 | resolver_sp->SetBreakpoint (bp_sp.get()); |
| 371 | |
| 372 | if (internal) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 373 | m_internal_breakpoint_list.Add (bp_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 374 | else |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 375 | m_breakpoint_list.Add (bp_sp, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 376 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 377 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 378 | if (log) |
| 379 | { |
| 380 | StreamString s; |
| 381 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
| 382 | log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); |
| 383 | } |
| 384 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 385 | bp_sp->ResolveBreakpoint(); |
| 386 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 387 | |
| 388 | if (!internal && bp_sp) |
| 389 | { |
| 390 | m_last_created_breakpoint = bp_sp; |
| 391 | } |
| 392 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 393 | return bp_sp; |
| 394 | } |
| 395 | |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 396 | bool |
| 397 | Target::ProcessIsValid() |
| 398 | { |
| 399 | return (m_process_sp && m_process_sp->IsAlive()); |
| 400 | } |
| 401 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 402 | // See also Watchpoint::SetWatchpointType(uint32_t type) and |
Johnny Chen | ab9ee76 | 2011-09-14 00:26:03 | [diff] [blame] | 403 | // the OptionGroupWatchpoint::WatchType enum type. |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 404 | WatchpointSP |
| 405 | Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type) |
Johnny Chen | 887062a | 2011-09-12 23:38:44 | [diff] [blame] | 406 | { |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 407 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 408 | if (log) |
| 409 | log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n", |
| 410 | __FUNCTION__, addr, size, type); |
| 411 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 412 | WatchpointSP wp_sp; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 413 | if (!ProcessIsValid()) |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 414 | return wp_sp; |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 415 | if (addr == LLDB_INVALID_ADDRESS || size == 0) |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 416 | return wp_sp; |
Johnny Chen | 7313a64 | 2011-09-13 01:15:36 | [diff] [blame] | 417 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 418 | // Currently we only support one watchpoint per address, with total number |
| 419 | // of watchpoints limited by the hardware which the inferior is running on. |
| 420 | WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr); |
Johnny Chen | 3c53258 | 2011-09-13 23:29:31 | [diff] [blame] | 421 | if (matched_sp) |
| 422 | { |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 423 | size_t old_size = matched_sp->GetByteSize(); |
Johnny Chen | 3c53258 | 2011-09-13 23:29:31 | [diff] [blame] | 424 | uint32_t old_type = |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 425 | (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | |
| 426 | (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 427 | // Return the existing watchpoint if both size and type match. |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 428 | if (size == old_size && type == old_type) { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 429 | wp_sp = matched_sp; |
| 430 | wp_sp->SetEnabled(false); |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 431 | } else { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 432 | // Nil the matched watchpoint; we will be creating a new one. |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 433 | m_process_sp->DisableWatchpoint(matched_sp.get()); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 434 | m_watchpoint_list.Remove(matched_sp->GetID()); |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 435 | } |
Johnny Chen | 3c53258 | 2011-09-13 23:29:31 | [diff] [blame] | 436 | } |
| 437 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 438 | if (!wp_sp) { |
| 439 | Watchpoint *new_wp = new Watchpoint(addr, size); |
| 440 | if (!new_wp) { |
| 441 | printf("Watchpoint ctor failed, out of memory?\n"); |
| 442 | return wp_sp; |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 443 | } |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 444 | new_wp->SetWatchpointType(type); |
| 445 | new_wp->SetTarget(this); |
| 446 | wp_sp.reset(new_wp); |
| 447 | m_watchpoint_list.Add(wp_sp); |
Johnny Chen | 45e541f | 2011-09-14 22:20:15 | [diff] [blame] | 448 | } |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 449 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 450 | Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 451 | if (log) |
| 452 | log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", |
| 453 | __FUNCTION__, |
| 454 | rc.Success() ? "succeeded" : "failed", |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 455 | wp_sp->GetID()); |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 | [diff] [blame] | 456 | |
Johnny Chen | 9d954d8 | 2011-09-27 20:29:45 | [diff] [blame] | 457 | if (rc.Fail()) |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 458 | wp_sp.reset(); |
Johnny Chen | 9d954d8 | 2011-09-27 20:29:45 | [diff] [blame] | 459 | else |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 460 | m_last_created_watchpoint = wp_sp; |
| 461 | return wp_sp; |
Johnny Chen | 887062a | 2011-09-12 23:38:44 | [diff] [blame] | 462 | } |
| 463 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 464 | void |
| 465 | Target::RemoveAllBreakpoints (bool internal_also) |
| 466 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 467 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 468 | if (log) |
| 469 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 470 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 471 | m_breakpoint_list.RemoveAll (true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 472 | if (internal_also) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 473 | m_internal_breakpoint_list.RemoveAll (false); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 474 | |
| 475 | m_last_created_breakpoint.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | void |
| 479 | Target::DisableAllBreakpoints (bool internal_also) |
| 480 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 481 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 482 | if (log) |
| 483 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 484 | |
| 485 | m_breakpoint_list.SetEnabledAll (false); |
| 486 | if (internal_also) |
| 487 | m_internal_breakpoint_list.SetEnabledAll (false); |
| 488 | } |
| 489 | |
| 490 | void |
| 491 | Target::EnableAllBreakpoints (bool internal_also) |
| 492 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 493 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 494 | if (log) |
| 495 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 496 | |
| 497 | m_breakpoint_list.SetEnabledAll (true); |
| 498 | if (internal_also) |
| 499 | m_internal_breakpoint_list.SetEnabledAll (true); |
| 500 | } |
| 501 | |
| 502 | bool |
| 503 | Target::RemoveBreakpointByID (break_id_t break_id) |
| 504 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 505 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 506 | if (log) |
| 507 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 508 | |
| 509 | if (DisableBreakpointByID (break_id)) |
| 510 | { |
| 511 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 512 | m_internal_breakpoint_list.Remove(break_id, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 513 | else |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 514 | { |
Greg Clayton | aa1c587 | 2011-01-24 23:35:47 | [diff] [blame] | 515 | if (m_last_created_breakpoint) |
| 516 | { |
| 517 | if (m_last_created_breakpoint->GetID() == break_id) |
| 518 | m_last_created_breakpoint.reset(); |
| 519 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 520 | m_breakpoint_list.Remove(break_id, true); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 521 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 522 | return true; |
| 523 | } |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | bool |
| 528 | Target::DisableBreakpointByID (break_id_t break_id) |
| 529 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 530 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 531 | if (log) |
| 532 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 533 | |
| 534 | BreakpointSP bp_sp; |
| 535 | |
| 536 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 537 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 538 | else |
| 539 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 540 | if (bp_sp) |
| 541 | { |
| 542 | bp_sp->SetEnabled (false); |
| 543 | return true; |
| 544 | } |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | bool |
| 549 | Target::EnableBreakpointByID (break_id_t break_id) |
| 550 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 551 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 552 | if (log) |
| 553 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", |
| 554 | __FUNCTION__, |
| 555 | break_id, |
| 556 | LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 557 | |
| 558 | BreakpointSP bp_sp; |
| 559 | |
| 560 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 561 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 562 | else |
| 563 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 564 | |
| 565 | if (bp_sp) |
| 566 | { |
| 567 | bp_sp->SetEnabled (true); |
| 568 | return true; |
| 569 | } |
| 570 | return false; |
| 571 | } |
| 572 | |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 573 | // The flag 'end_to_end', default to true, signifies that the operation is |
| 574 | // performed end to end, for both the debugger and the debuggee. |
| 575 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 576 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end |
| 577 | // to end operations. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 578 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 579 | Target::RemoveAllWatchpoints (bool end_to_end) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 580 | { |
| 581 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 582 | if (log) |
| 583 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 584 | |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 585 | if (!end_to_end) { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 586 | m_watchpoint_list.RemoveAll(); |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 587 | return true; |
| 588 | } |
| 589 | |
| 590 | // Otherwise, it's an end to end operation. |
| 591 | |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 592 | if (!ProcessIsValid()) |
| 593 | return false; |
| 594 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 595 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 596 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 597 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 598 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 599 | if (!wp_sp) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 600 | return false; |
| 601 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 602 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 603 | if (rc.Fail()) |
| 604 | return false; |
| 605 | } |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 606 | m_watchpoint_list.RemoveAll (); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 607 | return true; // Success! |
| 608 | } |
| 609 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 610 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to |
| 611 | // end operations. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 612 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 613 | Target::DisableAllWatchpoints (bool end_to_end) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 614 | { |
| 615 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 616 | if (log) |
| 617 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 618 | |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 619 | if (!end_to_end) { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 620 | m_watchpoint_list.SetEnabledAll(false); |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 621 | return true; |
| 622 | } |
| 623 | |
| 624 | // Otherwise, it's an end to end operation. |
| 625 | |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 626 | if (!ProcessIsValid()) |
| 627 | return false; |
| 628 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 629 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 630 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 631 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 632 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 633 | if (!wp_sp) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 634 | return false; |
| 635 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 636 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 637 | if (rc.Fail()) |
| 638 | return false; |
| 639 | } |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 640 | return true; // Success! |
| 641 | } |
| 642 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 643 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to |
| 644 | // end operations. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 645 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 646 | Target::EnableAllWatchpoints (bool end_to_end) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 647 | { |
| 648 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 649 | if (log) |
| 650 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 651 | |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 652 | if (!end_to_end) { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 653 | m_watchpoint_list.SetEnabledAll(true); |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 | [diff] [blame] | 654 | return true; |
| 655 | } |
| 656 | |
| 657 | // Otherwise, it's an end to end operation. |
| 658 | |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 659 | if (!ProcessIsValid()) |
| 660 | return false; |
| 661 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 662 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 663 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 664 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 665 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 666 | if (!wp_sp) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 667 | return false; |
| 668 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 669 | Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 670 | if (rc.Fail()) |
| 671 | return false; |
| 672 | } |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 673 | return true; // Success! |
| 674 | } |
| 675 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 676 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 677 | // during these operations. |
| 678 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 679 | Target::IgnoreAllWatchpoints (uint32_t ignore_count) |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 680 | { |
| 681 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 682 | if (log) |
| 683 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 684 | |
| 685 | if (!ProcessIsValid()) |
| 686 | return false; |
| 687 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 688 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 689 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 690 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 691 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 692 | if (!wp_sp) |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 693 | return false; |
| 694 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 695 | wp_sp->SetIgnoreCount(ignore_count); |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 696 | } |
| 697 | return true; // Success! |
| 698 | } |
| 699 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 700 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 701 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 702 | Target::DisableWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 703 | { |
| 704 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 705 | if (log) |
| 706 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 707 | |
| 708 | if (!ProcessIsValid()) |
| 709 | return false; |
| 710 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 711 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 712 | if (wp_sp) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 713 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 714 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | f04ee93 | 2011-09-22 18:04:58 | [diff] [blame] | 715 | if (rc.Success()) |
| 716 | return true; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 717 | |
Johnny Chen | f04ee93 | 2011-09-22 18:04:58 | [diff] [blame] | 718 | // Else, fallthrough. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 719 | } |
| 720 | return false; |
| 721 | } |
| 722 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 723 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 724 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 725 | Target::EnableWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 726 | { |
| 727 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 728 | if (log) |
| 729 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 730 | |
| 731 | if (!ProcessIsValid()) |
| 732 | return false; |
| 733 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 734 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 735 | if (wp_sp) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 736 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 737 | Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | f04ee93 | 2011-09-22 18:04:58 | [diff] [blame] | 738 | if (rc.Success()) |
| 739 | return true; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 740 | |
Johnny Chen | f04ee93 | 2011-09-22 18:04:58 | [diff] [blame] | 741 | // Else, fallthrough. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 742 | } |
| 743 | return false; |
| 744 | } |
| 745 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 746 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 747 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 748 | Target::RemoveWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 749 | { |
| 750 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 751 | if (log) |
| 752 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 753 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 754 | if (DisableWatchpointByID (watch_id)) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 755 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 756 | m_watchpoint_list.Remove(watch_id); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 757 | return true; |
| 758 | } |
| 759 | return false; |
| 760 | } |
| 761 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 762 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 763 | bool |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 764 | Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count) |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 765 | { |
| 766 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 767 | if (log) |
| 768 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 769 | |
| 770 | if (!ProcessIsValid()) |
| 771 | return false; |
| 772 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 773 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 774 | if (wp_sp) |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 775 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 | [diff] [blame] | 776 | wp_sp->SetIgnoreCount(ignore_count); |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 | [diff] [blame] | 777 | return true; |
| 778 | } |
| 779 | return false; |
| 780 | } |
| 781 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 782 | ModuleSP |
| 783 | Target::GetExecutableModule () |
| 784 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 785 | return m_images.GetModuleAtIndex(0); |
| 786 | } |
| 787 | |
| 788 | Module* |
| 789 | Target::GetExecutableModulePointer () |
| 790 | { |
| 791 | return m_images.GetModulePointerAtIndex(0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | void |
| 795 | Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) |
| 796 | { |
| 797 | m_images.Clear(); |
| 798 | m_scratch_ast_context_ap.reset(); |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 | [diff] [blame^] | 799 | m_scratch_ast_source_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 800 | |
| 801 | if (executable_sp.get()) |
| 802 | { |
| 803 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 804 | "Target::SetExecutableModule (executable = '%s/%s')", |
| 805 | executable_sp->GetFileSpec().GetDirectory().AsCString(), |
| 806 | executable_sp->GetFileSpec().GetFilename().AsCString()); |
| 807 | |
| 808 | m_images.Append(executable_sp); // The first image is our exectuable file |
| 809 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 810 | // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 811 | if (!m_arch.IsValid()) |
| 812 | m_arch = executable_sp->GetArchitecture(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 813 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 814 | FileSpecList dependent_files; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 | [diff] [blame] | 815 | ObjectFile *executable_objfile = executable_sp->GetObjectFile(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 816 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 | [diff] [blame] | 817 | if (executable_objfile && get_dependent_files) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 818 | { |
| 819 | executable_objfile->GetDependentModules(dependent_files); |
| 820 | for (uint32_t i=0; i<dependent_files.GetSize(); i++) |
| 821 | { |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 822 | FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i)); |
| 823 | FileSpec platform_dependent_file_spec; |
| 824 | if (m_platform_sp) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 | [diff] [blame] | 825 | m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 826 | else |
| 827 | platform_dependent_file_spec = dependent_file_spec; |
| 828 | |
| 829 | ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 830 | m_arch)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 831 | if (image_module_sp.get()) |
| 832 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 833 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 834 | if (objfile) |
| 835 | objfile->GetDependentModules(dependent_files); |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 840 | } |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 841 | |
| 842 | UpdateInstanceName(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 846 | bool |
| 847 | Target::SetArchitecture (const ArchSpec &arch_spec) |
| 848 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 849 | if (m_arch == arch_spec) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 850 | { |
| 851 | // If we're setting the architecture to our current architecture, we |
| 852 | // don't need to do anything. |
| 853 | return true; |
| 854 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 855 | else if (!m_arch.IsValid()) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 856 | { |
| 857 | // If we haven't got a valid arch spec, then we just need to set it. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 858 | m_arch = arch_spec; |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 859 | return true; |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | // If we have an executable file, try to reset the executable to the desired architecture |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 864 | m_arch = arch_spec; |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 865 | ModuleSP executable_sp = GetExecutableModule (); |
| 866 | m_images.Clear(); |
| 867 | m_scratch_ast_context_ap.reset(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 868 | // Need to do something about unsetting breakpoints. |
| 869 | |
| 870 | if (executable_sp) |
| 871 | { |
| 872 | FileSpec exec_file_spec = executable_sp->GetFileSpec(); |
| 873 | Error error = ModuleList::GetSharedModule(exec_file_spec, |
| 874 | arch_spec, |
| 875 | NULL, |
| 876 | NULL, |
| 877 | 0, |
| 878 | executable_sp, |
| 879 | NULL, |
| 880 | NULL); |
| 881 | |
| 882 | if (!error.Fail() && executable_sp) |
| 883 | { |
| 884 | SetExecutableModule (executable_sp, true); |
| 885 | return true; |
| 886 | } |
| 887 | else |
| 888 | { |
| 889 | return false; |
| 890 | } |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | return false; |
| 895 | } |
| 896 | } |
| 897 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 898 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 899 | void |
| 900 | Target::ModuleAdded (ModuleSP &module_sp) |
| 901 | { |
| 902 | // A module is being added to this target for the first time |
| 903 | ModuleList module_list; |
| 904 | module_list.Append(module_sp); |
| 905 | ModulesDidLoad (module_list); |
| 906 | } |
| 907 | |
| 908 | void |
| 909 | Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) |
| 910 | { |
Jim Ingham | e716ae0 | 2011-08-03 01:00:06 | [diff] [blame] | 911 | // A module is replacing an already added module |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 912 | ModuleList module_list; |
| 913 | module_list.Append (old_module_sp); |
| 914 | ModulesDidUnload (module_list); |
| 915 | module_list.Clear (); |
| 916 | module_list.Append (new_module_sp); |
| 917 | ModulesDidLoad (module_list); |
| 918 | } |
| 919 | |
| 920 | void |
| 921 | Target::ModulesDidLoad (ModuleList &module_list) |
| 922 | { |
| 923 | m_breakpoint_list.UpdateBreakpoints (module_list, true); |
| 924 | // TODO: make event data that packages up the module_list |
| 925 | BroadcastEvent (eBroadcastBitModulesLoaded, NULL); |
| 926 | } |
| 927 | |
| 928 | void |
| 929 | Target::ModulesDidUnload (ModuleList &module_list) |
| 930 | { |
| 931 | m_breakpoint_list.UpdateBreakpoints (module_list, false); |
Greg Clayton | a4d7830 | 2010-12-06 23:51:26 | [diff] [blame] | 932 | |
| 933 | // Remove the images from the target image list |
| 934 | m_images.Remove(module_list); |
| 935 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 936 | // TODO: make event data that packages up the module_list |
| 937 | BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); |
| 938 | } |
| 939 | |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 940 | |
Daniel Dunbar | f9f7032 | 2011-10-31 22:50:37 | [diff] [blame] | 941 | bool |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 942 | Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec) |
| 943 | { |
| 944 | |
| 945 | if (!m_breakpoints_use_platform_avoid) |
| 946 | return false; |
| 947 | else |
| 948 | { |
| 949 | ModuleList matchingModules; |
| 950 | const ArchSpec *arch_ptr = NULL; |
| 951 | const lldb_private::UUID *uuid_ptr= NULL; |
| 952 | const ConstString *object_name = NULL; |
| 953 | size_t num_modules = GetImages().FindModules(&module_spec, arch_ptr, uuid_ptr, object_name, matchingModules); |
| 954 | |
| 955 | // If there is more than one module for this file spec, only return true if ALL the modules are on the |
| 956 | // black list. |
| 957 | if (num_modules > 0) |
| 958 | { |
| 959 | for (int i = 0; i < num_modules; i++) |
| 960 | { |
| 961 | if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i))) |
| 962 | return false; |
| 963 | } |
| 964 | return true; |
| 965 | } |
| 966 | else |
| 967 | return false; |
| 968 | } |
| 969 | } |
| 970 | |
Daniel Dunbar | f9f7032 | 2011-10-31 22:50:37 | [diff] [blame] | 971 | bool |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 972 | Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp) |
| 973 | { |
| 974 | if (!m_breakpoints_use_platform_avoid) |
| 975 | return false; |
| 976 | else if (GetPlatform()) |
| 977 | { |
| 978 | return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp); |
| 979 | } |
| 980 | else |
| 981 | return false; |
| 982 | } |
| 983 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 984 | size_t |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 985 | Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error) |
| 986 | { |
| 987 | const Section *section = addr.GetSection(); |
| 988 | if (section && section->GetModule()) |
| 989 | { |
| 990 | ObjectFile *objfile = section->GetModule()->GetObjectFile(); |
| 991 | if (objfile) |
| 992 | { |
| 993 | size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile, |
| 994 | addr.GetOffset(), |
| 995 | dst, |
| 996 | dst_len); |
| 997 | if (bytes_read > 0) |
| 998 | return bytes_read; |
| 999 | else |
| 1000 | error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString()); |
| 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | error.SetErrorString("address isn't from a object file"); |
| 1005 | } |
| 1006 | } |
| 1007 | else |
| 1008 | { |
| 1009 | error.SetErrorString("address doesn't contain a section that points to a section in a object file"); |
| 1010 | } |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | size_t |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 1015 | Target::ReadMemory (const Address& addr, |
| 1016 | bool prefer_file_cache, |
| 1017 | void *dst, |
| 1018 | size_t dst_len, |
| 1019 | Error &error, |
| 1020 | lldb::addr_t *load_addr_ptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1021 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1022 | error.Clear(); |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 1023 | |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 1024 | // if we end up reading this from process memory, we will fill this |
| 1025 | // with the actual load address |
| 1026 | if (load_addr_ptr) |
| 1027 | *load_addr_ptr = LLDB_INVALID_ADDRESS; |
| 1028 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 1029 | size_t bytes_read = 0; |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1030 | |
| 1031 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 1032 | addr_t file_addr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 | [diff] [blame] | 1033 | Address resolved_addr; |
| 1034 | if (!addr.IsSectionOffset()) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1035 | { |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 1036 | if (m_section_load_list.IsEmpty()) |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1037 | { |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 1038 | // No sections are loaded, so we must assume we are not running |
| 1039 | // yet and anything we are given is a file address. |
| 1040 | file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address |
| 1041 | m_images.ResolveFileAddress (file_addr, resolved_addr); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1042 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1043 | else |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1044 | { |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 1045 | // We have at least one section loaded. This can be becuase |
| 1046 | // we have manually loaded some sections with "target modules load ..." |
| 1047 | // or because we have have a live process that has sections loaded |
| 1048 | // through the dynamic loader |
| 1049 | load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address |
| 1050 | m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1051 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1052 | } |
Greg Clayton | 357132e | 2011-03-26 19:14:58 | [diff] [blame] | 1053 | if (!resolved_addr.IsValid()) |
| 1054 | resolved_addr = addr; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1055 | |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1056 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 1057 | if (prefer_file_cache) |
| 1058 | { |
| 1059 | bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
| 1060 | if (bytes_read > 0) |
| 1061 | return bytes_read; |
| 1062 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1063 | |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 | [diff] [blame] | 1064 | if (ProcessIsValid()) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1065 | { |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1066 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1067 | load_addr = resolved_addr.GetLoadAddress (this); |
| 1068 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1069 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1070 | { |
| 1071 | if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 1072 | error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded", |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1073 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 | [diff] [blame] | 1074 | resolved_addr.GetFileAddress(), |
| 1075 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString()); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1076 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 1077 | error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress()); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1078 | } |
| 1079 | else |
| 1080 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 1081 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1082 | if (bytes_read != dst_len) |
| 1083 | { |
| 1084 | if (error.Success()) |
| 1085 | { |
| 1086 | if (bytes_read == 0) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 1087 | error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1088 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 1089 | error.SetErrorStringWithFormat("only %zu of %zu bytes were read from memory at 0x%llx", bytes_read, dst_len, load_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1090 | } |
| 1091 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1092 | if (bytes_read) |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 1093 | { |
| 1094 | if (load_addr_ptr) |
| 1095 | *load_addr_ptr = load_addr; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1096 | return bytes_read; |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 1097 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1098 | // If the address is not section offset we have an address that |
| 1099 | // doesn't resolve to any address in any currently loaded shared |
| 1100 | // libaries and we failed to read memory so there isn't anything |
| 1101 | // more we can do. If it is section offset, we might be able to |
| 1102 | // read cached memory from the object file. |
| 1103 | if (!resolved_addr.IsSectionOffset()) |
| 1104 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1105 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1106 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1107 | |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 | [diff] [blame] | 1108 | if (!prefer_file_cache && resolved_addr.IsSectionOffset()) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1109 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 1110 | // If we didn't already try and read from the object file cache, then |
| 1111 | // try it after failing to read from the process. |
| 1112 | return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 1113 | } |
| 1114 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1115 | } |
| 1116 | |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 | [diff] [blame] | 1117 | size_t |
| 1118 | Target::ReadScalarIntegerFromMemory (const Address& addr, |
| 1119 | bool prefer_file_cache, |
| 1120 | uint32_t byte_size, |
| 1121 | bool is_signed, |
| 1122 | Scalar &scalar, |
| 1123 | Error &error) |
| 1124 | { |
| 1125 | uint64_t uval; |
| 1126 | |
| 1127 | if (byte_size <= sizeof(uval)) |
| 1128 | { |
| 1129 | size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error); |
| 1130 | if (bytes_read == byte_size) |
| 1131 | { |
| 1132 | DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize()); |
| 1133 | uint32_t offset = 0; |
| 1134 | if (byte_size <= 4) |
| 1135 | scalar = data.GetMaxU32 (&offset, byte_size); |
| 1136 | else |
| 1137 | scalar = data.GetMaxU64 (&offset, byte_size); |
| 1138 | |
| 1139 | if (is_signed) |
| 1140 | scalar.SignExtend(byte_size * 8); |
| 1141 | return bytes_read; |
| 1142 | } |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 1147 | } |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | uint64_t |
| 1152 | Target::ReadUnsignedIntegerFromMemory (const Address& addr, |
| 1153 | bool prefer_file_cache, |
| 1154 | size_t integer_byte_size, |
| 1155 | uint64_t fail_value, |
| 1156 | Error &error) |
| 1157 | { |
| 1158 | Scalar scalar; |
| 1159 | if (ReadScalarIntegerFromMemory (addr, |
| 1160 | prefer_file_cache, |
| 1161 | integer_byte_size, |
| 1162 | false, |
| 1163 | scalar, |
| 1164 | error)) |
| 1165 | return scalar.ULongLong(fail_value); |
| 1166 | return fail_value; |
| 1167 | } |
| 1168 | |
| 1169 | bool |
| 1170 | Target::ReadPointerFromMemory (const Address& addr, |
| 1171 | bool prefer_file_cache, |
| 1172 | Error &error, |
| 1173 | Address &pointer_addr) |
| 1174 | { |
| 1175 | Scalar scalar; |
| 1176 | if (ReadScalarIntegerFromMemory (addr, |
| 1177 | prefer_file_cache, |
| 1178 | m_arch.GetAddressByteSize(), |
| 1179 | false, |
| 1180 | scalar, |
| 1181 | error)) |
| 1182 | { |
| 1183 | addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1184 | if (pointer_vm_addr != LLDB_INVALID_ADDRESS) |
| 1185 | { |
| 1186 | if (m_section_load_list.IsEmpty()) |
| 1187 | { |
| 1188 | // No sections are loaded, so we must assume we are not running |
| 1189 | // yet and anything we are given is a file address. |
| 1190 | m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr); |
| 1191 | } |
| 1192 | else |
| 1193 | { |
| 1194 | // We have at least one section loaded. This can be becuase |
| 1195 | // we have manually loaded some sections with "target modules load ..." |
| 1196 | // or because we have have a live process that has sections loaded |
| 1197 | // through the dynamic loader |
| 1198 | m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr); |
| 1199 | } |
| 1200 | // We weren't able to resolve the pointer value, so just return |
| 1201 | // an address with no section |
| 1202 | if (!pointer_addr.IsValid()) |
| 1203 | pointer_addr.SetOffset (pointer_vm_addr); |
| 1204 | return true; |
| 1205 | |
| 1206 | } |
| 1207 | } |
| 1208 | return false; |
| 1209 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1210 | |
| 1211 | ModuleSP |
| 1212 | Target::GetSharedModule |
| 1213 | ( |
| 1214 | const FileSpec& file_spec, |
| 1215 | const ArchSpec& arch, |
Greg Clayton | 6083026 | 2011-02-04 18:53:10 | [diff] [blame] | 1216 | const lldb_private::UUID *uuid_ptr, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1217 | const ConstString *object_name, |
| 1218 | off_t object_offset, |
| 1219 | Error *error_ptr |
| 1220 | ) |
| 1221 | { |
| 1222 | // Don't pass in the UUID so we can tell if we have a stale value in our list |
| 1223 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 1224 | bool did_create_module = false; |
| 1225 | ModuleSP module_sp; |
| 1226 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1227 | Error error; |
| 1228 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1229 | // If there are image search path entries, try to use them first to acquire a suitable image. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1230 | if (m_image_search_paths.GetSize()) |
| 1231 | { |
| 1232 | FileSpec transformed_spec; |
| 1233 | if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory())) |
| 1234 | { |
| 1235 | transformed_spec.GetFilename() = file_spec.GetFilename(); |
| 1236 | error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module); |
| 1237 | } |
| 1238 | } |
| 1239 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1240 | // The platform is responsible for finding and caching an appropriate |
| 1241 | // module in the shared module cache. |
| 1242 | if (m_platform_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1243 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1244 | FileSpec platform_file_spec; |
| 1245 | error = m_platform_sp->GetSharedModule (file_spec, |
| 1246 | arch, |
| 1247 | uuid_ptr, |
| 1248 | object_name, |
| 1249 | object_offset, |
| 1250 | module_sp, |
| 1251 | &old_module_sp, |
| 1252 | &did_create_module); |
| 1253 | } |
| 1254 | else |
| 1255 | { |
| 1256 | error.SetErrorString("no platform is currently set"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1257 | } |
| 1258 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1259 | // If a module hasn't been found yet, use the unmodified path. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1260 | if (module_sp) |
| 1261 | { |
| 1262 | m_images.Append (module_sp); |
| 1263 | if (did_create_module) |
| 1264 | { |
| 1265 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 1266 | ModuleUpdated(old_module_sp, module_sp); |
| 1267 | else |
| 1268 | ModuleAdded(module_sp); |
| 1269 | } |
| 1270 | } |
| 1271 | if (error_ptr) |
| 1272 | *error_ptr = error; |
| 1273 | return module_sp; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | Target * |
| 1278 | Target::CalculateTarget () |
| 1279 | { |
| 1280 | return this; |
| 1281 | } |
| 1282 | |
| 1283 | Process * |
| 1284 | Target::CalculateProcess () |
| 1285 | { |
| 1286 | return NULL; |
| 1287 | } |
| 1288 | |
| 1289 | Thread * |
| 1290 | Target::CalculateThread () |
| 1291 | { |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | |
| 1295 | StackFrame * |
| 1296 | Target::CalculateStackFrame () |
| 1297 | { |
| 1298 | return NULL; |
| 1299 | } |
| 1300 | |
| 1301 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 1302 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1303 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 | [diff] [blame] | 1304 | exe_ctx.Clear(); |
| 1305 | exe_ctx.SetTargetPtr(this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | PathMappingList & |
| 1309 | Target::GetImageSearchPathList () |
| 1310 | { |
| 1311 | return m_image_search_paths; |
| 1312 | } |
| 1313 | |
| 1314 | void |
| 1315 | Target::ImageSearchPathsChanged |
| 1316 | ( |
| 1317 | const PathMappingList &path_list, |
| 1318 | void *baton |
| 1319 | ) |
| 1320 | { |
| 1321 | Target *target = (Target *)baton; |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 1322 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 1323 | if (exe_module_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1324 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 1325 | target->m_images.Clear(); |
| 1326 | target->SetExecutableModule (exe_module_sp, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | ClangASTContext * |
| 1331 | Target::GetScratchClangASTContext() |
| 1332 | { |
Greg Clayton | 73da244 | 2011-08-03 01:23:55 | [diff] [blame] | 1333 | // Now see if we know the target triple, and if so, create our scratch AST context: |
| 1334 | if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid()) |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 | [diff] [blame^] | 1335 | { |
Greg Clayton | 73da244 | 2011-08-03 01:23:55 | [diff] [blame] | 1336 | m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str())); |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 | [diff] [blame^] | 1337 | m_scratch_ast_source_ap.reset (new ClangASTSource(GetSP())); |
| 1338 | m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext()); |
| 1339 | llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy()); |
| 1340 | m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source); |
| 1341 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1342 | return m_scratch_ast_context_ap.get(); |
| 1343 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1344 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1345 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 1346 | Target::SettingsInitialize () |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1347 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1348 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 1349 | usc.reset (new SettingsController); |
| 1350 | UserSettingsController::InitializeSettingsController (usc, |
| 1351 | SettingsController::global_settings_table, |
| 1352 | SettingsController::instance_settings_table); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 1353 | |
| 1354 | // Now call SettingsInitialize() on each 'child' setting of Target |
| 1355 | Process::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1356 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1357 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1358 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 1359 | Target::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1360 | { |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 1361 | |
| 1362 | // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings. |
| 1363 | |
| 1364 | Process::SettingsTerminate (); |
| 1365 | |
| 1366 | // Now terminate Target Settings. |
| 1367 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1368 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 1369 | UserSettingsController::FinalizeSettingsController (usc); |
| 1370 | usc.reset(); |
| 1371 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1372 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 1373 | UserSettingsControllerSP & |
| 1374 | Target::GetSettingsController () |
| 1375 | { |
| 1376 | static UserSettingsControllerSP g_settings_controller; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1377 | return g_settings_controller; |
| 1378 | } |
| 1379 | |
| 1380 | ArchSpec |
| 1381 | Target::GetDefaultArchitecture () |
| 1382 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1383 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 1384 | |
| 1385 | if (settings_controller_sp) |
| 1386 | return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture (); |
| 1387 | return ArchSpec(); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1391 | Target::SetDefaultArchitecture (const ArchSpec& arch) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1392 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1393 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 1394 | |
| 1395 | if (settings_controller_sp) |
| 1396 | static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1397 | } |
| 1398 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 1399 | Target * |
| 1400 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 1401 | { |
| 1402 | // The target can either exist in the "process" of ExecutionContext, or in |
| 1403 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 1404 | // will get the target from one of these locations. |
| 1405 | |
| 1406 | Target *target = NULL; |
| 1407 | if (sc_ptr != NULL) |
| 1408 | target = sc_ptr->target_sp.get(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 | [diff] [blame] | 1409 | if (target == NULL && exe_ctx_ptr) |
| 1410 | target = exe_ctx_ptr->GetTargetPtr(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 1411 | return target; |
| 1412 | } |
| 1413 | |
| 1414 | |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 1415 | void |
| 1416 | Target::UpdateInstanceName () |
| 1417 | { |
| 1418 | StreamString sstr; |
| 1419 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 1420 | Module *exe_module = GetExecutableModulePointer(); |
| 1421 | if (exe_module) |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 1422 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 1423 | sstr.Printf ("%s_%s", |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 | [diff] [blame] | 1424 | exe_module->GetFileSpec().GetFilename().AsCString(), |
| 1425 | exe_module->GetArchitecture().GetArchitectureName()); |
| 1426 | GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData()); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1430 | const char * |
| 1431 | Target::GetExpressionPrefixContentsAsCString () |
| 1432 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 1433 | if (m_expr_prefix_contents_sp) |
| 1434 | return (const char *)m_expr_prefix_contents_sp->GetBytes(); |
| 1435 | return NULL; |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1436 | } |
| 1437 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1438 | ExecutionResults |
| 1439 | Target::EvaluateExpression |
| 1440 | ( |
| 1441 | const char *expr_cstr, |
| 1442 | StackFrame *frame, |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 | [diff] [blame] | 1443 | lldb_private::ExecutionPolicy execution_policy, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1444 | bool unwind_on_error, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 1445 | bool keep_in_memory, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 1446 | lldb::DynamicValueType use_dynamic, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1447 | lldb::ValueObjectSP &result_valobj_sp |
| 1448 | ) |
| 1449 | { |
| 1450 | ExecutionResults execution_results = eExecutionSetupError; |
| 1451 | |
| 1452 | result_valobj_sp.reset(); |
Jim Ingham | 6026ca3 | 2011-05-12 02:06:14 | [diff] [blame] | 1453 | |
| 1454 | // We shouldn't run stop hooks in expressions. |
| 1455 | // Be sure to reset this if you return anywhere within this function. |
| 1456 | bool old_suppress_value = m_suppress_stop_hooks; |
| 1457 | m_suppress_stop_hooks = true; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1458 | |
| 1459 | ExecutionContext exe_ctx; |
| 1460 | if (frame) |
| 1461 | { |
| 1462 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 | [diff] [blame] | 1463 | Error error; |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 | [diff] [blame] | 1464 | const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 | [diff] [blame] | 1465 | StackFrame::eExpressionPathOptionsNoFragileObjcIvar | |
| 1466 | StackFrame::eExpressionPathOptionsNoSyntheticChildren; |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 1467 | lldb::VariableSP var_sp; |
| 1468 | result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, |
| 1469 | use_dynamic, |
| 1470 | expr_path_options, |
| 1471 | var_sp, |
| 1472 | error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1473 | } |
| 1474 | else if (m_process_sp) |
| 1475 | { |
| 1476 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 1477 | } |
| 1478 | else |
| 1479 | { |
| 1480 | CalculateExecutionContext(exe_ctx); |
| 1481 | } |
| 1482 | |
| 1483 | if (result_valobj_sp) |
| 1484 | { |
| 1485 | execution_results = eExecutionCompleted; |
| 1486 | // We got a result from the frame variable expression path above... |
| 1487 | ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName()); |
| 1488 | |
| 1489 | lldb::ValueObjectSP const_valobj_sp; |
| 1490 | |
| 1491 | // Check in case our value is already a constant value |
| 1492 | if (result_valobj_sp->GetIsConstant()) |
| 1493 | { |
| 1494 | const_valobj_sp = result_valobj_sp; |
| 1495 | const_valobj_sp->SetName (persistent_variable_name); |
| 1496 | } |
| 1497 | else |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 1498 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 1499 | if (use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 1500 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 1501 | ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 1502 | if (dynamic_sp) |
| 1503 | result_valobj_sp = dynamic_sp; |
| 1504 | } |
| 1505 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 | [diff] [blame] | 1506 | const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 1507 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1508 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 1509 | lldb::ValueObjectSP live_valobj_sp = result_valobj_sp; |
| 1510 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1511 | result_valobj_sp = const_valobj_sp; |
| 1512 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 1513 | ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp)); |
| 1514 | assert (clang_expr_variable_sp.get()); |
| 1515 | |
| 1516 | // Set flags and live data as appropriate |
| 1517 | |
| 1518 | const Value &result_value = live_valobj_sp->GetValue(); |
| 1519 | |
| 1520 | switch (result_value.GetValueType()) |
| 1521 | { |
| 1522 | case Value::eValueTypeHostAddress: |
| 1523 | case Value::eValueTypeFileAddress: |
| 1524 | // we don't do anything with these for now |
| 1525 | break; |
| 1526 | case Value::eValueTypeScalar: |
| 1527 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated; |
| 1528 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation; |
| 1529 | break; |
| 1530 | case Value::eValueTypeLoadAddress: |
| 1531 | clang_expr_variable_sp->m_live_sp = live_valobj_sp; |
| 1532 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference; |
| 1533 | break; |
| 1534 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | // Make sure we aren't just trying to see the value of a persistent |
| 1539 | // variable (something like "$0") |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 | [diff] [blame] | 1540 | lldb::ClangExpressionVariableSP persistent_var_sp; |
| 1541 | // Only check for persistent variables the expression starts with a '$' |
| 1542 | if (expr_cstr[0] == '$') |
| 1543 | persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); |
| 1544 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1545 | if (persistent_var_sp) |
| 1546 | { |
| 1547 | result_valobj_sp = persistent_var_sp->GetValueObject (); |
| 1548 | execution_results = eExecutionCompleted; |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | const char *prefix = GetExpressionPrefixContentsAsCString(); |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 | [diff] [blame] | 1553 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1554 | execution_results = ClangUserExpression::Evaluate (exe_ctx, |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 | [diff] [blame] | 1555 | execution_policy, |
Sean Callanan | c7b6506 | 2011-11-07 23:35:40 | [diff] [blame] | 1556 | lldb::eLanguageTypeUnknown, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 1557 | unwind_on_error, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1558 | expr_cstr, |
| 1559 | prefix, |
| 1560 | result_valobj_sp); |
| 1561 | } |
| 1562 | } |
Jim Ingham | 6026ca3 | 2011-05-12 02:06:14 | [diff] [blame] | 1563 | |
| 1564 | m_suppress_stop_hooks = old_suppress_value; |
| 1565 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 1566 | return execution_results; |
| 1567 | } |
| 1568 | |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 | [diff] [blame] | 1569 | lldb::addr_t |
| 1570 | Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1571 | { |
| 1572 | addr_t code_addr = load_addr; |
| 1573 | switch (m_arch.GetMachine()) |
| 1574 | { |
| 1575 | case llvm::Triple::arm: |
| 1576 | case llvm::Triple::thumb: |
| 1577 | switch (addr_class) |
| 1578 | { |
| 1579 | case eAddressClassData: |
| 1580 | case eAddressClassDebug: |
| 1581 | return LLDB_INVALID_ADDRESS; |
| 1582 | |
| 1583 | case eAddressClassUnknown: |
| 1584 | case eAddressClassInvalid: |
| 1585 | case eAddressClassCode: |
| 1586 | case eAddressClassCodeAlternateISA: |
| 1587 | case eAddressClassRuntime: |
| 1588 | // Check if bit zero it no set? |
| 1589 | if ((code_addr & 1ull) == 0) |
| 1590 | { |
| 1591 | // Bit zero isn't set, check if the address is a multiple of 2? |
| 1592 | if (code_addr & 2ull) |
| 1593 | { |
| 1594 | // The address is a multiple of 2 so it must be thumb, set bit zero |
| 1595 | code_addr |= 1ull; |
| 1596 | } |
| 1597 | else if (addr_class == eAddressClassCodeAlternateISA) |
| 1598 | { |
| 1599 | // We checked the address and the address claims to be the alternate ISA |
| 1600 | // which means thumb, so set bit zero. |
| 1601 | code_addr |= 1ull; |
| 1602 | } |
| 1603 | } |
| 1604 | break; |
| 1605 | } |
| 1606 | break; |
| 1607 | |
| 1608 | default: |
| 1609 | break; |
| 1610 | } |
| 1611 | return code_addr; |
| 1612 | } |
| 1613 | |
| 1614 | lldb::addr_t |
| 1615 | Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1616 | { |
| 1617 | addr_t opcode_addr = load_addr; |
| 1618 | switch (m_arch.GetMachine()) |
| 1619 | { |
| 1620 | case llvm::Triple::arm: |
| 1621 | case llvm::Triple::thumb: |
| 1622 | switch (addr_class) |
| 1623 | { |
| 1624 | case eAddressClassData: |
| 1625 | case eAddressClassDebug: |
| 1626 | return LLDB_INVALID_ADDRESS; |
| 1627 | |
| 1628 | case eAddressClassInvalid: |
| 1629 | case eAddressClassUnknown: |
| 1630 | case eAddressClassCode: |
| 1631 | case eAddressClassCodeAlternateISA: |
| 1632 | case eAddressClassRuntime: |
| 1633 | opcode_addr &= ~(1ull); |
| 1634 | break; |
| 1635 | } |
| 1636 | break; |
| 1637 | |
| 1638 | default: |
| 1639 | break; |
| 1640 | } |
| 1641 | return opcode_addr; |
| 1642 | } |
| 1643 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1644 | lldb::user_id_t |
| 1645 | Target::AddStopHook (Target::StopHookSP &new_hook_sp) |
| 1646 | { |
| 1647 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
| 1648 | new_hook_sp.reset (new StopHook(GetSP(), new_uid)); |
| 1649 | m_stop_hooks[new_uid] = new_hook_sp; |
| 1650 | return new_uid; |
| 1651 | } |
| 1652 | |
| 1653 | bool |
| 1654 | Target::RemoveStopHookByID (lldb::user_id_t user_id) |
| 1655 | { |
| 1656 | size_t num_removed; |
| 1657 | num_removed = m_stop_hooks.erase (user_id); |
| 1658 | if (num_removed == 0) |
| 1659 | return false; |
| 1660 | else |
| 1661 | return true; |
| 1662 | } |
| 1663 | |
| 1664 | void |
| 1665 | Target::RemoveAllStopHooks () |
| 1666 | { |
| 1667 | m_stop_hooks.clear(); |
| 1668 | } |
| 1669 | |
| 1670 | Target::StopHookSP |
| 1671 | Target::GetStopHookByID (lldb::user_id_t user_id) |
| 1672 | { |
| 1673 | StopHookSP found_hook; |
| 1674 | |
| 1675 | StopHookCollection::iterator specified_hook_iter; |
| 1676 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1677 | if (specified_hook_iter != m_stop_hooks.end()) |
| 1678 | found_hook = (*specified_hook_iter).second; |
| 1679 | return found_hook; |
| 1680 | } |
| 1681 | |
| 1682 | bool |
| 1683 | Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) |
| 1684 | { |
| 1685 | StopHookCollection::iterator specified_hook_iter; |
| 1686 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1687 | if (specified_hook_iter == m_stop_hooks.end()) |
| 1688 | return false; |
| 1689 | |
| 1690 | (*specified_hook_iter).second->SetIsActive (active_state); |
| 1691 | return true; |
| 1692 | } |
| 1693 | |
| 1694 | void |
| 1695 | Target::SetAllStopHooksActiveState (bool active_state) |
| 1696 | { |
| 1697 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1698 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1699 | { |
| 1700 | (*pos).second->SetIsActive (active_state); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | void |
| 1705 | Target::RunStopHooks () |
| 1706 | { |
Jim Ingham | 6026ca3 | 2011-05-12 02:06:14 | [diff] [blame] | 1707 | if (m_suppress_stop_hooks) |
| 1708 | return; |
| 1709 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1710 | if (!m_process_sp) |
| 1711 | return; |
| 1712 | |
| 1713 | if (m_stop_hooks.empty()) |
| 1714 | return; |
| 1715 | |
| 1716 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1717 | |
| 1718 | // If there aren't any active stop hooks, don't bother either: |
| 1719 | bool any_active_hooks = false; |
| 1720 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1721 | { |
| 1722 | if ((*pos).second->IsActive()) |
| 1723 | { |
| 1724 | any_active_hooks = true; |
| 1725 | break; |
| 1726 | } |
| 1727 | } |
| 1728 | if (!any_active_hooks) |
| 1729 | return; |
| 1730 | |
| 1731 | CommandReturnObject result; |
| 1732 | |
| 1733 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 1734 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 1735 | |
| 1736 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 1737 | size_t num_threads = cur_threadlist.GetSize(); |
| 1738 | for (size_t i = 0; i < num_threads; i++) |
| 1739 | { |
| 1740 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); |
| 1741 | if (cur_thread_sp->ThreadStoppedForAReason()) |
| 1742 | { |
| 1743 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 1744 | exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 1745 | sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 1750 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 1751 | if (num_exe_ctx == 0) |
| 1752 | return; |
| 1753 | |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 | [diff] [blame] | 1754 | result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream()); |
| 1755 | result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1756 | |
| 1757 | bool keep_going = true; |
| 1758 | bool hooks_ran = false; |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1759 | bool print_hook_header; |
| 1760 | bool print_thread_header; |
| 1761 | |
| 1762 | if (num_exe_ctx == 1) |
| 1763 | print_thread_header = false; |
| 1764 | else |
| 1765 | print_thread_header = true; |
| 1766 | |
| 1767 | if (m_stop_hooks.size() == 1) |
| 1768 | print_hook_header = false; |
| 1769 | else |
| 1770 | print_hook_header = true; |
| 1771 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1772 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) |
| 1773 | { |
| 1774 | // result.Clear(); |
| 1775 | StopHookSP cur_hook_sp = (*pos).second; |
| 1776 | if (!cur_hook_sp->IsActive()) |
| 1777 | continue; |
| 1778 | |
| 1779 | bool any_thread_matched = false; |
| 1780 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) |
| 1781 | { |
| 1782 | if ((cur_hook_sp->GetSpecifier () == NULL |
| 1783 | || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) |
| 1784 | && (cur_hook_sp->GetThreadSpecifier() == NULL |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 | [diff] [blame] | 1785 | || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr()))) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1786 | { |
| 1787 | if (!hooks_ran) |
| 1788 | { |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1789 | hooks_ran = true; |
| 1790 | } |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1791 | if (print_hook_header && !any_thread_matched) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1792 | { |
Johnny Chen | aeab25c | 2011-10-24 23:01:06 | [diff] [blame] | 1793 | const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ? |
| 1794 | cur_hook_sp->GetCommands().GetStringAtIndex(0) : |
| 1795 | NULL); |
| 1796 | if (cmd) |
| 1797 | result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd); |
| 1798 | else |
| 1799 | result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1800 | any_thread_matched = true; |
| 1801 | } |
| 1802 | |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1803 | if (print_thread_header) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 | [diff] [blame] | 1804 | result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1805 | |
| 1806 | bool stop_on_continue = true; |
| 1807 | bool stop_on_error = true; |
| 1808 | bool echo_commands = false; |
| 1809 | bool print_results = true; |
| 1810 | GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1811 | &exc_ctx_with_reasons[i], |
| 1812 | stop_on_continue, |
| 1813 | stop_on_error, |
| 1814 | echo_commands, |
| 1815 | print_results, |
| 1816 | result); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1817 | |
| 1818 | // If the command started the target going again, we should bag out of |
| 1819 | // running the stop hooks. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 | [diff] [blame] | 1820 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) || |
| 1821 | (result.GetStatus() == eReturnStatusSuccessContinuingResult)) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1822 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 | [diff] [blame] | 1823 | result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1824 | keep_going = false; |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | } |
Jason Molenda | 879cf77 | 2011-09-23 00:42:55 | [diff] [blame] | 1829 | |
Caroline Tice | 969ed3d1 | 2011-05-02 20:41:46 | [diff] [blame] | 1830 | result.GetImmediateOutputStream()->Flush(); |
| 1831 | result.GetImmediateErrorStream()->Flush(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1832 | } |
| 1833 | |
Greg Clayton | 7b24238 | 2011-07-08 00:48:09 | [diff] [blame] | 1834 | bool |
| 1835 | Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide) |
| 1836 | { |
| 1837 | bool changed = false; |
| 1838 | if (module) |
| 1839 | { |
| 1840 | ObjectFile *object_file = module->GetObjectFile(); |
| 1841 | if (object_file) |
| 1842 | { |
| 1843 | SectionList *section_list = object_file->GetSectionList (); |
| 1844 | if (section_list) |
| 1845 | { |
| 1846 | // All sections listed in the dyld image info structure will all |
| 1847 | // either be fixed up already, or they will all be off by a single |
| 1848 | // slide amount that is determined by finding the first segment |
| 1849 | // that is at file offset zero which also has bytes (a file size |
| 1850 | // that is greater than zero) in the object file. |
| 1851 | |
| 1852 | // Determine the slide amount (if any) |
| 1853 | const size_t num_sections = section_list->GetSize(); |
| 1854 | size_t sect_idx = 0; |
| 1855 | for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1856 | { |
| 1857 | // Iterate through the object file sections to find the |
| 1858 | // first section that starts of file offset zero and that |
| 1859 | // has bytes in the file... |
| 1860 | Section *section = section_list->GetSectionAtIndex (sect_idx).get(); |
| 1861 | if (section) |
| 1862 | { |
| 1863 | if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide)) |
| 1864 | changed = true; |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | } |
| 1870 | return changed; |
| 1871 | } |
| 1872 | |
| 1873 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1874 | //-------------------------------------------------------------- |
| 1875 | // class Target::StopHook |
| 1876 | //-------------------------------------------------------------- |
| 1877 | |
| 1878 | |
| 1879 | Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : |
| 1880 | UserID (uid), |
| 1881 | m_target_sp (target_sp), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1882 | m_commands (), |
| 1883 | m_specifier_sp (), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 | [diff] [blame] | 1884 | m_thread_spec_ap(NULL), |
| 1885 | m_active (true) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1886 | { |
| 1887 | } |
| 1888 | |
| 1889 | Target::StopHook::StopHook (const StopHook &rhs) : |
| 1890 | UserID (rhs.GetID()), |
| 1891 | m_target_sp (rhs.m_target_sp), |
| 1892 | m_commands (rhs.m_commands), |
| 1893 | m_specifier_sp (rhs.m_specifier_sp), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 | [diff] [blame] | 1894 | m_thread_spec_ap (NULL), |
| 1895 | m_active (rhs.m_active) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1896 | { |
| 1897 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 1898 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
| 1899 | } |
| 1900 | |
| 1901 | |
| 1902 | Target::StopHook::~StopHook () |
| 1903 | { |
| 1904 | } |
| 1905 | |
| 1906 | void |
| 1907 | Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier) |
| 1908 | { |
| 1909 | m_thread_spec_ap.reset (specifier); |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | void |
| 1914 | Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 1915 | { |
| 1916 | int indent_level = s->GetIndentLevel(); |
| 1917 | |
| 1918 | s->SetIndentLevel(indent_level + 2); |
| 1919 | |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 | [diff] [blame] | 1920 | s->Printf ("Hook: %llu\n", GetID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1921 | if (m_active) |
| 1922 | s->Indent ("State: enabled\n"); |
| 1923 | else |
| 1924 | s->Indent ("State: disabled\n"); |
| 1925 | |
| 1926 | if (m_specifier_sp) |
| 1927 | { |
| 1928 | s->Indent(); |
| 1929 | s->PutCString ("Specifier:\n"); |
| 1930 | s->SetIndentLevel (indent_level + 4); |
| 1931 | m_specifier_sp->GetDescription (s, level); |
| 1932 | s->SetIndentLevel (indent_level + 2); |
| 1933 | } |
| 1934 | |
| 1935 | if (m_thread_spec_ap.get() != NULL) |
| 1936 | { |
| 1937 | StreamString tmp; |
| 1938 | s->Indent("Thread:\n"); |
| 1939 | m_thread_spec_ap->GetDescription (&tmp, level); |
| 1940 | s->SetIndentLevel (indent_level + 4); |
| 1941 | s->Indent (tmp.GetData()); |
| 1942 | s->PutCString ("\n"); |
| 1943 | s->SetIndentLevel (indent_level + 2); |
| 1944 | } |
| 1945 | |
| 1946 | s->Indent ("Commands: \n"); |
| 1947 | s->SetIndentLevel (indent_level + 4); |
| 1948 | uint32_t num_commands = m_commands.GetSize(); |
| 1949 | for (uint32_t i = 0; i < num_commands; i++) |
| 1950 | { |
| 1951 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 1952 | s->PutCString ("\n"); |
| 1953 | } |
| 1954 | s->SetIndentLevel (indent_level); |
| 1955 | } |
| 1956 | |
| 1957 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1958 | //-------------------------------------------------------------- |
| 1959 | // class Target::SettingsController |
| 1960 | //-------------------------------------------------------------- |
| 1961 | |
| 1962 | Target::SettingsController::SettingsController () : |
| 1963 | UserSettingsController ("target", Debugger::GetSettingsController()), |
| 1964 | m_default_architecture () |
| 1965 | { |
| 1966 | m_default_settings.reset (new TargetInstanceSettings (*this, false, |
| 1967 | InstanceSettings::GetDefaultName().AsCString())); |
| 1968 | } |
| 1969 | |
| 1970 | Target::SettingsController::~SettingsController () |
| 1971 | { |
| 1972 | } |
| 1973 | |
| 1974 | lldb::InstanceSettingsSP |
| 1975 | Target::SettingsController::CreateInstanceSettings (const char *instance_name) |
| 1976 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 1977 | TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(), |
| 1978 | false, |
| 1979 | instance_name); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1980 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 1981 | return new_settings_sp; |
| 1982 | } |
| 1983 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1984 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 1985 | #define TSC_DEFAULT_ARCH "default-arch" |
| 1986 | #define TSC_EXPR_PREFIX "expr-prefix" |
| 1987 | #define TSC_PREFER_DYNAMIC "prefer-dynamic-value" |
| 1988 | #define TSC_SKIP_PROLOGUE "skip-prologue" |
| 1989 | #define TSC_SOURCE_MAP "source-map" |
| 1990 | #define TSC_MAX_CHILDREN "max-children-count" |
| 1991 | #define TSC_MAX_STRLENSUMMARY "max-string-summary-length" |
| 1992 | #define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list" |
| 1993 | #define TSC_RUN_ARGS "run-args" |
| 1994 | #define TSC_ENV_VARS "env-vars" |
| 1995 | #define TSC_INHERIT_ENV "inherit-env" |
| 1996 | #define TSC_STDIN_PATH "input-path" |
| 1997 | #define TSC_STDOUT_PATH "output-path" |
| 1998 | #define TSC_STDERR_PATH "error-path" |
| 1999 | #define TSC_DISABLE_ASLR "disable-aslr" |
| 2000 | #define TSC_DISABLE_STDIO "disable-stdio" |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2001 | |
| 2002 | |
| 2003 | static const ConstString & |
| 2004 | GetSettingNameForDefaultArch () |
| 2005 | { |
| 2006 | static ConstString g_const_string (TSC_DEFAULT_ARCH); |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2007 | return g_const_string; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2008 | } |
| 2009 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2010 | static const ConstString & |
| 2011 | GetSettingNameForExpressionPrefix () |
| 2012 | { |
| 2013 | static ConstString g_const_string (TSC_EXPR_PREFIX); |
| 2014 | return g_const_string; |
| 2015 | } |
| 2016 | |
| 2017 | static const ConstString & |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 2018 | GetSettingNameForPreferDynamicValue () |
| 2019 | { |
| 2020 | static ConstString g_const_string (TSC_PREFER_DYNAMIC); |
| 2021 | return g_const_string; |
| 2022 | } |
| 2023 | |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2024 | static const ConstString & |
| 2025 | GetSettingNameForSourcePathMap () |
| 2026 | { |
| 2027 | static ConstString g_const_string (TSC_SOURCE_MAP); |
| 2028 | return g_const_string; |
| 2029 | } |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2030 | |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 | [diff] [blame] | 2031 | static const ConstString & |
| 2032 | GetSettingNameForSkipPrologue () |
| 2033 | { |
| 2034 | static ConstString g_const_string (TSC_SKIP_PROLOGUE); |
| 2035 | return g_const_string; |
| 2036 | } |
| 2037 | |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 | [diff] [blame] | 2038 | static const ConstString & |
| 2039 | GetSettingNameForMaxChildren () |
| 2040 | { |
| 2041 | static ConstString g_const_string (TSC_MAX_CHILDREN); |
| 2042 | return g_const_string; |
| 2043 | } |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 | [diff] [blame] | 2044 | |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2045 | static const ConstString & |
| 2046 | GetSettingNameForMaxStringSummaryLength () |
| 2047 | { |
| 2048 | static ConstString g_const_string (TSC_MAX_STRLENSUMMARY); |
| 2049 | return g_const_string; |
| 2050 | } |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 | [diff] [blame] | 2051 | |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2052 | static const ConstString & |
| 2053 | GetSettingNameForPlatformAvoid () |
| 2054 | { |
| 2055 | static ConstString g_const_string (TSC_PLATFORM_AVOID); |
| 2056 | return g_const_string; |
| 2057 | } |
| 2058 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2059 | const ConstString & |
| 2060 | GetSettingNameForRunArgs () |
| 2061 | { |
| 2062 | static ConstString g_const_string (TSC_RUN_ARGS); |
| 2063 | return g_const_string; |
| 2064 | } |
| 2065 | |
| 2066 | const ConstString & |
| 2067 | GetSettingNameForEnvVars () |
| 2068 | { |
| 2069 | static ConstString g_const_string (TSC_ENV_VARS); |
| 2070 | return g_const_string; |
| 2071 | } |
| 2072 | |
| 2073 | const ConstString & |
| 2074 | GetSettingNameForInheritHostEnv () |
| 2075 | { |
| 2076 | static ConstString g_const_string (TSC_INHERIT_ENV); |
| 2077 | return g_const_string; |
| 2078 | } |
| 2079 | |
| 2080 | const ConstString & |
| 2081 | GetSettingNameForInputPath () |
| 2082 | { |
| 2083 | static ConstString g_const_string (TSC_STDIN_PATH); |
| 2084 | return g_const_string; |
| 2085 | } |
| 2086 | |
| 2087 | const ConstString & |
| 2088 | GetSettingNameForOutputPath () |
| 2089 | { |
| 2090 | static ConstString g_const_string (TSC_STDOUT_PATH); |
| 2091 | return g_const_string; |
| 2092 | } |
| 2093 | |
| 2094 | const ConstString & |
| 2095 | GetSettingNameForErrorPath () |
| 2096 | { |
| 2097 | static ConstString g_const_string (TSC_STDERR_PATH); |
| 2098 | return g_const_string; |
| 2099 | } |
| 2100 | |
| 2101 | const ConstString & |
| 2102 | GetSettingNameForDisableASLR () |
| 2103 | { |
| 2104 | static ConstString g_const_string (TSC_DISABLE_ASLR); |
| 2105 | return g_const_string; |
| 2106 | } |
| 2107 | |
| 2108 | const ConstString & |
| 2109 | GetSettingNameForDisableSTDIO () |
| 2110 | { |
| 2111 | static ConstString g_const_string (TSC_DISABLE_STDIO); |
| 2112 | return g_const_string; |
| 2113 | } |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2114 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2115 | bool |
| 2116 | Target::SettingsController::SetGlobalVariable (const ConstString &var_name, |
| 2117 | const char *index_value, |
| 2118 | const char *value, |
| 2119 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 2120 | const VarSetOperationType op, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2121 | Error&err) |
| 2122 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2123 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2124 | { |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 | [diff] [blame] | 2125 | m_default_architecture.SetTriple (value, NULL); |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 2126 | if (!m_default_architecture.IsValid()) |
| 2127 | err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2128 | } |
| 2129 | return true; |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | bool |
| 2134 | Target::SettingsController::GetGlobalVariable (const ConstString &var_name, |
| 2135 | StringList &value, |
| 2136 | Error &err) |
| 2137 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2138 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2139 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 2140 | // If the arch is invalid (the default), don't show a string for it |
| 2141 | if (m_default_architecture.IsValid()) |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 2142 | value.AppendString (m_default_architecture.GetArchitectureName()); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2143 | return true; |
| 2144 | } |
| 2145 | else |
| 2146 | err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 2147 | |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
| 2151 | //-------------------------------------------------------------- |
| 2152 | // class TargetInstanceSettings |
| 2153 | //-------------------------------------------------------------- |
| 2154 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 | [diff] [blame] | 2155 | TargetInstanceSettings::TargetInstanceSettings |
| 2156 | ( |
| 2157 | UserSettingsController &owner, |
| 2158 | bool live_instance, |
| 2159 | const char *name |
| 2160 | ) : |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2161 | InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2162 | m_expr_prefix_file (), |
| 2163 | m_expr_prefix_contents_sp (), |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 2164 | m_prefer_dynamic_value (2), |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2165 | m_skip_prologue (true, true), |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 | [diff] [blame] | 2166 | m_source_map (NULL, NULL), |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2167 | m_max_children_display(256), |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2168 | m_max_strlen_length(1024), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2169 | m_breakpoints_use_platform_avoid (true, true), |
| 2170 | m_run_args (), |
| 2171 | m_env_vars (), |
| 2172 | m_input_path (), |
| 2173 | m_output_path (), |
| 2174 | m_error_path (), |
| 2175 | m_disable_aslr (true), |
| 2176 | m_disable_stdio (false), |
| 2177 | m_inherit_host_env (true), |
| 2178 | m_got_host_env (false) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2179 | { |
| 2180 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 2181 | // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 2182 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 2183 | // This is true for CreateInstanceName() too. |
| 2184 | |
| 2185 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 2186 | { |
| 2187 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 2188 | m_owner.RegisterInstanceSettings (this); |
| 2189 | } |
| 2190 | |
| 2191 | if (live_instance) |
| 2192 | { |
| 2193 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 2194 | CopyInstanceSettings (pending_settings,false); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2199 | InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()), |
| 2200 | m_expr_prefix_file (rhs.m_expr_prefix_file), |
| 2201 | m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp), |
| 2202 | m_prefer_dynamic_value (rhs.m_prefer_dynamic_value), |
| 2203 | m_skip_prologue (rhs.m_skip_prologue), |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 | [diff] [blame] | 2204 | m_source_map (rhs.m_source_map), |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2205 | m_max_children_display (rhs.m_max_children_display), |
| 2206 | m_max_strlen_length (rhs.m_max_strlen_length), |
| 2207 | m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid), |
| 2208 | m_run_args (rhs.m_run_args), |
| 2209 | m_env_vars (rhs.m_env_vars), |
| 2210 | m_input_path (rhs.m_input_path), |
| 2211 | m_output_path (rhs.m_output_path), |
| 2212 | m_error_path (rhs.m_error_path), |
| 2213 | m_disable_aslr (rhs.m_disable_aslr), |
| 2214 | m_disable_stdio (rhs.m_disable_stdio), |
| 2215 | m_inherit_host_env (rhs.m_inherit_host_env) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2216 | { |
| 2217 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 2218 | { |
| 2219 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 2220 | CopyInstanceSettings (pending_settings,false); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | TargetInstanceSettings::~TargetInstanceSettings () |
| 2225 | { |
| 2226 | } |
| 2227 | |
| 2228 | TargetInstanceSettings& |
| 2229 | TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) |
| 2230 | { |
| 2231 | if (this != &rhs) |
| 2232 | { |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2233 | m_expr_prefix_file = rhs.m_expr_prefix_file; |
| 2234 | m_expr_prefix_contents_sp = rhs.m_expr_prefix_contents_sp; |
| 2235 | m_prefer_dynamic_value = rhs.m_prefer_dynamic_value; |
| 2236 | m_skip_prologue = rhs.m_skip_prologue; |
| 2237 | m_source_map = rhs.m_source_map; |
| 2238 | m_max_children_display = rhs.m_max_children_display; |
| 2239 | m_max_strlen_length = rhs.m_max_strlen_length; |
| 2240 | m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid; |
| 2241 | m_run_args = rhs.m_run_args; |
| 2242 | m_env_vars = rhs.m_env_vars; |
| 2243 | m_input_path = rhs.m_input_path; |
| 2244 | m_output_path = rhs.m_output_path; |
| 2245 | m_error_path = rhs.m_error_path; |
| 2246 | m_disable_aslr = rhs.m_disable_aslr; |
| 2247 | m_disable_stdio = rhs.m_disable_stdio; |
| 2248 | m_inherit_host_env = rhs.m_inherit_host_env; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | return *this; |
| 2252 | } |
| 2253 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2254 | void |
| 2255 | TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 2256 | const char *index_value, |
| 2257 | const char *value, |
| 2258 | const ConstString &instance_name, |
| 2259 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 2260 | VarSetOperationType op, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2261 | Error &err, |
| 2262 | bool pending) |
| 2263 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2264 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2265 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2266 | err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file); |
| 2267 | if (err.Success()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2268 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2269 | switch (op) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2270 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2271 | default: |
| 2272 | break; |
| 2273 | case eVarSetOperationAssign: |
| 2274 | case eVarSetOperationAppend: |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2275 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2276 | if (!m_expr_prefix_file.GetCurrentValue().Exists()) |
| 2277 | { |
| 2278 | err.SetErrorToGenericError (); |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 2279 | err.SetErrorStringWithFormat ("%s does not exist", value); |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2280 | return; |
| 2281 | } |
| 2282 | |
| 2283 | m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents(); |
| 2284 | |
| 2285 | if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0) |
| 2286 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 | [diff] [blame] | 2287 | err.SetErrorStringWithFormat ("couldn't read data from '%s'", value); |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2288 | m_expr_prefix_contents_sp.reset(); |
| 2289 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2290 | } |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2291 | break; |
| 2292 | case eVarSetOperationClear: |
| 2293 | m_expr_prefix_contents_sp.reset(); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2294 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2295 | } |
| 2296 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 2297 | else if (var_name == GetSettingNameForPreferDynamicValue()) |
| 2298 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 2299 | int new_value; |
| 2300 | UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err); |
| 2301 | if (err.Success()) |
| 2302 | m_prefer_dynamic_value = new_value; |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 | [diff] [blame] | 2303 | } |
| 2304 | else if (var_name == GetSettingNameForSkipPrologue()) |
| 2305 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2306 | err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue); |
| 2307 | } |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 | [diff] [blame] | 2308 | else if (var_name == GetSettingNameForMaxChildren()) |
| 2309 | { |
| 2310 | bool ok; |
| 2311 | uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok); |
| 2312 | if (ok) |
| 2313 | m_max_children_display = new_value; |
| 2314 | } |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2315 | else if (var_name == GetSettingNameForMaxStringSummaryLength()) |
| 2316 | { |
| 2317 | bool ok; |
| 2318 | uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok); |
| 2319 | if (ok) |
| 2320 | m_max_strlen_length = new_value; |
| 2321 | } |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2322 | else if (var_name == GetSettingNameForSourcePathMap ()) |
| 2323 | { |
| 2324 | switch (op) |
| 2325 | { |
| 2326 | case eVarSetOperationReplace: |
| 2327 | case eVarSetOperationInsertBefore: |
| 2328 | case eVarSetOperationInsertAfter: |
| 2329 | case eVarSetOperationRemove: |
| 2330 | default: |
| 2331 | break; |
| 2332 | case eVarSetOperationAssign: |
| 2333 | m_source_map.Clear(true); |
| 2334 | // Fall through to append.... |
| 2335 | case eVarSetOperationAppend: |
| 2336 | { |
| 2337 | Args args(value); |
| 2338 | const uint32_t argc = args.GetArgumentCount(); |
| 2339 | if (argc & 1 || argc == 0) |
| 2340 | { |
| 2341 | err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc); |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | char resolved_new_path[PATH_MAX]; |
| 2346 | FileSpec file_spec; |
| 2347 | const char *old_path; |
| 2348 | for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2) |
| 2349 | { |
| 2350 | const char *new_path = args.GetArgumentAtIndex(idx+1); |
| 2351 | assert (new_path); // We have an even number of paths, this shouldn't happen! |
| 2352 | |
| 2353 | file_spec.SetFile(new_path, true); |
| 2354 | if (file_spec.Exists()) |
| 2355 | { |
| 2356 | if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path)) |
| 2357 | { |
| 2358 | err.SetErrorStringWithFormat("new path '%s' is too long", new_path); |
| 2359 | return; |
| 2360 | } |
| 2361 | } |
| 2362 | else |
| 2363 | { |
| 2364 | err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path); |
| 2365 | return; |
| 2366 | } |
| 2367 | m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true); |
| 2368 | } |
| 2369 | } |
| 2370 | } |
| 2371 | break; |
| 2372 | |
| 2373 | case eVarSetOperationClear: |
| 2374 | m_source_map.Clear(true); |
| 2375 | break; |
| 2376 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 2377 | } |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2378 | else if (var_name == GetSettingNameForPlatformAvoid ()) |
| 2379 | { |
| 2380 | err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid); |
| 2381 | } |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2382 | else if (var_name == GetSettingNameForRunArgs()) |
| 2383 | { |
| 2384 | UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err); |
| 2385 | } |
| 2386 | else if (var_name == GetSettingNameForEnvVars()) |
| 2387 | { |
| 2388 | // This is nice for local debugging, but it is isn't correct for |
| 2389 | // remote debugging. We need to stop process.env-vars from being |
| 2390 | // populated with the host environment and add this as a launch option |
| 2391 | // and get the correct environment from the Target's platform. |
| 2392 | // GetHostEnvironmentIfNeeded (); |
| 2393 | UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err); |
| 2394 | } |
| 2395 | else if (var_name == GetSettingNameForInputPath()) |
| 2396 | { |
| 2397 | UserSettingsController::UpdateStringVariable (op, m_input_path, value, err); |
| 2398 | } |
| 2399 | else if (var_name == GetSettingNameForOutputPath()) |
| 2400 | { |
| 2401 | UserSettingsController::UpdateStringVariable (op, m_output_path, value, err); |
| 2402 | } |
| 2403 | else if (var_name == GetSettingNameForErrorPath()) |
| 2404 | { |
| 2405 | UserSettingsController::UpdateStringVariable (op, m_error_path, value, err); |
| 2406 | } |
| 2407 | else if (var_name == GetSettingNameForDisableASLR()) |
| 2408 | { |
| 2409 | UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err); |
| 2410 | } |
| 2411 | else if (var_name == GetSettingNameForDisableSTDIO ()) |
| 2412 | { |
| 2413 | UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err); |
| 2414 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | void |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2418 | TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2419 | { |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2420 | TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get()); |
| 2421 | |
| 2422 | if (!new_settings_ptr) |
| 2423 | return; |
| 2424 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2425 | *this = *new_settings_ptr; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2426 | } |
| 2427 | |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 2428 | bool |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2429 | TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 2430 | const ConstString &var_name, |
| 2431 | StringList &value, |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 2432 | Error *err) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2433 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2434 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2435 | { |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2436 | char path[PATH_MAX]; |
| 2437 | const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path)); |
| 2438 | if (path_len > 0) |
| 2439 | value.AppendString (path, path_len); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2440 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 2441 | else if (var_name == GetSettingNameForPreferDynamicValue()) |
| 2442 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 2443 | value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 | [diff] [blame] | 2444 | } |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 | [diff] [blame] | 2445 | else if (var_name == GetSettingNameForSkipPrologue()) |
| 2446 | { |
| 2447 | if (m_skip_prologue) |
| 2448 | value.AppendString ("true"); |
| 2449 | else |
| 2450 | value.AppendString ("false"); |
| 2451 | } |
Greg Clayton | 7e14f91 | 2011-04-23 02:04:55 | [diff] [blame] | 2452 | else if (var_name == GetSettingNameForSourcePathMap ()) |
| 2453 | { |
| 2454 | } |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 | [diff] [blame] | 2455 | else if (var_name == GetSettingNameForMaxChildren()) |
| 2456 | { |
| 2457 | StreamString count_str; |
| 2458 | count_str.Printf ("%d", m_max_children_display); |
| 2459 | value.AppendString (count_str.GetData()); |
| 2460 | } |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2461 | else if (var_name == GetSettingNameForMaxStringSummaryLength()) |
| 2462 | { |
| 2463 | StreamString count_str; |
| 2464 | count_str.Printf ("%d", m_max_strlen_length); |
| 2465 | value.AppendString (count_str.GetData()); |
| 2466 | } |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2467 | else if (var_name == GetSettingNameForPlatformAvoid()) |
| 2468 | { |
| 2469 | if (m_breakpoints_use_platform_avoid) |
| 2470 | value.AppendString ("true"); |
| 2471 | else |
| 2472 | value.AppendString ("false"); |
| 2473 | } |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2474 | else if (var_name == GetSettingNameForRunArgs()) |
| 2475 | { |
| 2476 | if (m_run_args.GetArgumentCount() > 0) |
| 2477 | { |
| 2478 | for (int i = 0; i < m_run_args.GetArgumentCount(); ++i) |
| 2479 | value.AppendString (m_run_args.GetArgumentAtIndex (i)); |
| 2480 | } |
| 2481 | } |
| 2482 | else if (var_name == GetSettingNameForEnvVars()) |
| 2483 | { |
| 2484 | GetHostEnvironmentIfNeeded (); |
| 2485 | |
| 2486 | if (m_env_vars.size() > 0) |
| 2487 | { |
| 2488 | std::map<std::string, std::string>::iterator pos; |
| 2489 | for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos) |
| 2490 | { |
| 2491 | StreamString value_str; |
| 2492 | value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str()); |
| 2493 | value.AppendString (value_str.GetData()); |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | else if (var_name == GetSettingNameForInputPath()) |
| 2498 | { |
| 2499 | value.AppendString (m_input_path.c_str()); |
| 2500 | } |
| 2501 | else if (var_name == GetSettingNameForOutputPath()) |
| 2502 | { |
| 2503 | value.AppendString (m_output_path.c_str()); |
| 2504 | } |
| 2505 | else if (var_name == GetSettingNameForErrorPath()) |
| 2506 | { |
| 2507 | value.AppendString (m_error_path.c_str()); |
| 2508 | } |
| 2509 | else if (var_name == GetSettingNameForInheritHostEnv()) |
| 2510 | { |
| 2511 | if (m_inherit_host_env) |
| 2512 | value.AppendString ("true"); |
| 2513 | else |
| 2514 | value.AppendString ("false"); |
| 2515 | } |
| 2516 | else if (var_name == GetSettingNameForDisableASLR()) |
| 2517 | { |
| 2518 | if (m_disable_aslr) |
| 2519 | value.AppendString ("true"); |
| 2520 | else |
| 2521 | value.AppendString ("false"); |
| 2522 | } |
| 2523 | else if (var_name == GetSettingNameForDisableSTDIO()) |
| 2524 | { |
| 2525 | if (m_disable_stdio) |
| 2526 | value.AppendString ("true"); |
| 2527 | else |
| 2528 | value.AppendString ("false"); |
| 2529 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2530 | else |
| 2531 | { |
| 2532 | if (err) |
| 2533 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 2534 | return false; |
| 2535 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 2536 | return true; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2537 | } |
| 2538 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2539 | void |
| 2540 | Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded () |
| 2541 | { |
| 2542 | if (m_inherit_host_env && !m_got_host_env) |
| 2543 | { |
| 2544 | m_got_host_env = true; |
| 2545 | StringList host_env; |
| 2546 | const size_t host_env_count = Host::GetEnvironment (host_env); |
| 2547 | for (size_t idx=0; idx<host_env_count; idx++) |
| 2548 | { |
| 2549 | const char *env_entry = host_env.GetStringAtIndex (idx); |
| 2550 | if (env_entry) |
| 2551 | { |
| 2552 | const char *equal_pos = ::strchr(env_entry, '='); |
| 2553 | if (equal_pos) |
| 2554 | { |
| 2555 | std::string key (env_entry, equal_pos - env_entry); |
| 2556 | std::string value (equal_pos + 1); |
| 2557 | if (m_env_vars.find (key) == m_env_vars.end()) |
| 2558 | m_env_vars[key] = value; |
| 2559 | } |
| 2560 | } |
| 2561 | } |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | |
| 2566 | size_t |
| 2567 | Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env) |
| 2568 | { |
| 2569 | GetHostEnvironmentIfNeeded (); |
| 2570 | |
| 2571 | dictionary::const_iterator pos, end = m_env_vars.end(); |
| 2572 | for (pos = m_env_vars.begin(); pos != end; ++pos) |
| 2573 | { |
| 2574 | std::string env_var_equal_value (pos->first); |
| 2575 | env_var_equal_value.append(1, '='); |
| 2576 | env_var_equal_value.append (pos->second); |
| 2577 | env.AppendArgument (env_var_equal_value.c_str()); |
| 2578 | } |
| 2579 | return env.GetArgumentCount(); |
| 2580 | } |
| 2581 | |
| 2582 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2583 | const ConstString |
| 2584 | TargetInstanceSettings::CreateInstanceName () |
| 2585 | { |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2586 | StreamString sstr; |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 2587 | static int instance_count = 1; |
| 2588 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2589 | sstr.Printf ("target_%d", instance_count); |
| 2590 | ++instance_count; |
| 2591 | |
| 2592 | const ConstString ret_val (sstr.GetData()); |
| 2593 | return ret_val; |
| 2594 | } |
| 2595 | |
| 2596 | //-------------------------------------------------- |
| 2597 | // Target::SettingsController Variable Tables |
| 2598 | //-------------------------------------------------- |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 2599 | OptionEnumValueElement |
| 2600 | TargetInstanceSettings::g_dynamic_value_types[] = |
| 2601 | { |
Greg Clayton | 5d2fbfe | 2011-05-30 00:39:48 | [diff] [blame] | 2602 | { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"}, |
| 2603 | { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."}, |
| 2604 | { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."}, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 | [diff] [blame] | 2605 | { 0, NULL, NULL } |
| 2606 | }; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2607 | |
| 2608 | SettingEntry |
| 2609 | Target::SettingsController::global_settings_table[] = |
| 2610 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 2611 | // var-name var-type default enum init'd hidden help-text |
| 2612 | // ================= ================== =========== ==== ====== ====== ========================================================================= |
| 2613 | { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." }, |
| 2614 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
| 2615 | }; |
| 2616 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2617 | SettingEntry |
| 2618 | Target::SettingsController::instance_settings_table[] = |
| 2619 | { |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2620 | // var-name var-type default enum init'd hidden help-text |
| 2621 | // ================= ================== =============== ======================= ====== ====== ========================================================================= |
| 2622 | { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." }, |
| 2623 | { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." }, |
| 2624 | { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." }, |
| 2625 | { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." }, |
| 2626 | { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." }, |
| 2627 | { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." }, |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 | [diff] [blame] | 2628 | { TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." }, |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 | [diff] [blame] | 2629 | { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." }, |
| 2630 | { TSC_ENV_VARS , eSetVarTypeDictionary, NULL , NULL, false, false, "A list of all the environment variables to be passed to the executable's environment, and their values." }, |
| 2631 | { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." }, |
| 2632 | { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." }, |
| 2633 | { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." }, |
| 2634 | { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." }, |
| 2635 | // { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." }, |
| 2636 | { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" }, |
| 2637 | { TSC_DISABLE_STDIO , eSetVarTypeBoolean, "false" , NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" }, |
Enrico Granata | 9128ee2f | 2011-09-06 19:20:51 | [diff] [blame] | 2638 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 2639 | }; |