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