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