Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Target/Target.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
| 18 | #include "lldb/Breakpoint/BreakpointResolver.h" |
| 19 | #include "lldb/Breakpoint/BreakpointResolverAddress.h" |
| 20 | #include "lldb/Breakpoint/BreakpointResolverFileLine.h" |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/BreakpointResolverFileRegex.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Breakpoint/BreakpointResolverName.h" |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 23 | #include "lldb/Breakpoint/Watchpoint.h" |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 24 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Event.h" |
| 26 | #include "lldb/Core/Log.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 27 | #include "lldb/Core/Module.h" |
| 28 | #include "lldb/Core/ModuleSpec.h" |
| 29 | #include "lldb/Core/Section.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 31 | #include "lldb/Core/Timer.h" |
| 32 | #include "lldb/Core/ValueObject.h" |
Sean Callanan | dcf03f8 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 33 | #include "lldb/Expression/ClangASTSource.h" |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 34 | #include "lldb/Expression/ClangUserExpression.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Host/Host.h" |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 36 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 37 | #include "lldb/Interpreter/CommandReturnObject.h" |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 38 | #include "lldb/Interpreter/OptionGroupWatchpoint.h" |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 39 | #include "lldb/Interpreter/OptionValues.h" |
| 40 | #include "lldb/Interpreter/Property.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/lldb-private-log.h" |
| 42 | #include "lldb/Symbol/ObjectFile.h" |
| 43 | #include "lldb/Target/Process.h" |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 44 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 45 | #include "lldb/Target/Thread.h" |
| 46 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | |
| 48 | using namespace lldb; |
| 49 | using namespace lldb_private; |
| 50 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 51 | ConstString & |
| 52 | Target::GetStaticBroadcasterClass () |
| 53 | { |
| 54 | static ConstString class_name ("lldb.target"); |
| 55 | return class_name; |
| 56 | } |
| 57 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | //---------------------------------------------------------------------- |
| 59 | // Target constructor |
| 60 | //---------------------------------------------------------------------- |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 61 | Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) : |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 62 | TargetProperties (this), |
Jim Ingham | 94a5d0d | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 63 | Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 64 | ExecutionContextScope (), |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 65 | m_debugger (debugger), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 66 | m_platform_sp (platform_sp), |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 67 | m_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 68 | m_arch (target_arch), |
Jason Molenda | aa9b36f | 2012-12-13 01:54:18 +0000 | [diff] [blame^] | 69 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 70 | m_images (this), |
Jason Molenda | aa9b36f | 2012-12-13 01:54:18 +0000 | [diff] [blame^] | 71 | #else |
| 72 | // FIXME: The module added notification needed for python scripting support |
| 73 | // causes a problem with in-memory-only Modules at startup if we have |
| 74 | // a breakpoint (the ObjectFile is parsed before we've set the Section load |
| 75 | // addresses leading to an invalid __LINKEDIT section addr on Mac OS X and |
| 76 | // all the problems that will happen from that). |
| 77 | // As a temporary solution for iOS debugging (where all the modules are in-memory-only), |
| 78 | // disable this notification system there. The problem could still happen on |
| 79 | // an x86 system but it is much less common. |
| 80 | // <rdar://problem/12831670> describes the failure mode for on-iOS debugging. |
| 81 | m_images (NULL), |
| 82 | #endif |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 83 | m_section_load_list (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | m_breakpoint_list (false), |
| 85 | m_internal_breakpoint_list (true), |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 86 | m_watchpoint_list (), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 87 | m_process_sp (), |
Filipe Cabecinhas | f7d782b | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 88 | m_valid (true), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 89 | m_search_filter_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | m_image_search_paths (ImageSearchPathsChanged, this), |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 91 | m_scratch_ast_context_ap (NULL), |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 92 | m_scratch_ast_source_ap (NULL), |
| 93 | m_ast_importer_ap (NULL), |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 94 | m_persistent_variables (), |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 95 | m_source_manager(*this), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 96 | m_stop_hooks (), |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 97 | m_stop_hook_next_id (0), |
Enrico Granata | dba1de8 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 98 | m_suppress_stop_hooks (false), |
| 99 | m_suppress_synthetic_value(false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 101 | SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 102 | SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); |
| 103 | SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 104 | |
| 105 | CheckInWithManager(); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 106 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 107 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | if (log) |
| 109 | log->Printf ("%p Target::Target()", this); |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 110 | if (m_arch.IsValid()) |
| 111 | { |
Jason Molenda | 332dc00 | 2012-12-12 02:23:56 +0000 | [diff] [blame] | 112 | LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::Target created with architecture %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str()); |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 113 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | //---------------------------------------------------------------------- |
| 117 | // Destructor |
| 118 | //---------------------------------------------------------------------- |
| 119 | Target::~Target() |
| 120 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 121 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | if (log) |
| 123 | log->Printf ("%p Target::~Target()", this); |
| 124 | DeleteCurrentProcess (); |
| 125 | } |
| 126 | |
| 127 | void |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | Target::Dump (Stream *s, lldb::DescriptionLevel description_level) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | { |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 130 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 131 | if (description_level != lldb::eDescriptionLevelBrief) |
| 132 | { |
| 133 | s->Indent(); |
| 134 | s->PutCString("Target\n"); |
| 135 | s->IndentMore(); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 136 | m_images.Dump(s); |
| 137 | m_breakpoint_list.Dump(s); |
| 138 | m_internal_breakpoint_list.Dump(s); |
| 139 | s->IndentLess(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 140 | } |
| 141 | else |
| 142 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 143 | Module *exe_module = GetExecutableModulePointer(); |
| 144 | if (exe_module) |
| 145 | s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString()); |
Jim Ingham | 53fe9cc | 2011-05-12 01:12:28 +0000 | [diff] [blame] | 146 | else |
| 147 | s->PutCString ("No executable module."); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 148 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void |
Greg Clayton | 0bce9a2 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 152 | Target::CleanupProcess () |
| 153 | { |
| 154 | // Do any cleanup of the target we need to do between process instances. |
| 155 | // NB It is better to do this before destroying the process in case the |
| 156 | // clean up needs some help from the process. |
| 157 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 158 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
| 159 | // Disable watchpoints just on the debugger side. |
| 160 | Mutex::Locker locker; |
| 161 | this->GetWatchpointList().GetListMutex(locker); |
| 162 | DisableAllWatchpoints(false); |
| 163 | ClearAllWatchpointHitCounts(); |
| 164 | } |
| 165 | |
| 166 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | Target::DeleteCurrentProcess () |
| 168 | { |
| 169 | if (m_process_sp.get()) |
| 170 | { |
Greg Clayton | 49480b1 | 2010-09-14 23:52:43 +0000 | [diff] [blame] | 171 | m_section_load_list.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | if (m_process_sp->IsAlive()) |
| 173 | m_process_sp->Destroy(); |
Jim Ingham | 88fa7bd | 2011-02-16 17:54:55 +0000 | [diff] [blame] | 174 | |
| 175 | m_process_sp->Finalize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | |
Greg Clayton | 0bce9a2 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 177 | CleanupProcess (); |
| 178 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | m_process_sp.reset(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | const lldb::ProcessSP & |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 184 | Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | { |
| 186 | DeleteCurrentProcess (); |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 187 | m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | return m_process_sp; |
| 189 | } |
| 190 | |
| 191 | const lldb::ProcessSP & |
| 192 | Target::GetProcessSP () const |
| 193 | { |
| 194 | return m_process_sp; |
| 195 | } |
| 196 | |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 197 | void |
| 198 | Target::Destroy() |
| 199 | { |
| 200 | Mutex::Locker locker (m_mutex); |
Filipe Cabecinhas | f7d782b | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 201 | m_valid = false; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 202 | DeleteCurrentProcess (); |
| 203 | m_platform_sp.reset(); |
| 204 | m_arch.Clear(); |
| 205 | m_images.Clear(); |
| 206 | m_section_load_list.Clear(); |
| 207 | const bool notify = false; |
| 208 | m_breakpoint_list.RemoveAll(notify); |
| 209 | m_internal_breakpoint_list.RemoveAll(notify); |
| 210 | m_last_created_breakpoint.reset(); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 211 | m_last_created_watchpoint.reset(); |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 212 | m_search_filter_sp.reset(); |
| 213 | m_image_search_paths.Clear(notify); |
| 214 | m_scratch_ast_context_ap.reset(); |
Sean Callanan | dcf03f8 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 215 | m_scratch_ast_source_ap.reset(); |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 216 | m_ast_importer_ap.reset(); |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 217 | m_persistent_variables.Clear(); |
| 218 | m_stop_hooks.clear(); |
| 219 | m_stop_hook_next_id = 0; |
| 220 | m_suppress_stop_hooks = false; |
Enrico Granata | dba1de8 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 221 | m_suppress_synthetic_value = false; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | BreakpointList & |
| 226 | Target::GetBreakpointList(bool internal) |
| 227 | { |
| 228 | if (internal) |
| 229 | return m_internal_breakpoint_list; |
| 230 | else |
| 231 | return m_breakpoint_list; |
| 232 | } |
| 233 | |
| 234 | const BreakpointList & |
| 235 | Target::GetBreakpointList(bool internal) const |
| 236 | { |
| 237 | if (internal) |
| 238 | return m_internal_breakpoint_list; |
| 239 | else |
| 240 | return m_breakpoint_list; |
| 241 | } |
| 242 | |
| 243 | BreakpointSP |
| 244 | Target::GetBreakpointByID (break_id_t break_id) |
| 245 | { |
| 246 | BreakpointSP bp_sp; |
| 247 | |
| 248 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 249 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 250 | else |
| 251 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 252 | |
| 253 | return bp_sp; |
| 254 | } |
| 255 | |
| 256 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 257 | Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules, |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 258 | const FileSpecList *source_file_spec_list, |
| 259 | RegularExpression &source_regex, |
| 260 | bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 262 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list)); |
| 263 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex)); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 264 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | BreakpointSP |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 269 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
| 270 | const FileSpec &file, |
| 271 | uint32_t line_no, |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 272 | LazyBool check_inlines, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 273 | LazyBool skip_prologue, |
| 274 | bool internal) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 275 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 276 | if (check_inlines == eLazyBoolCalculate) |
| 277 | { |
| 278 | const InlineStrategy inline_strategy = GetInlineStrategy(); |
| 279 | switch (inline_strategy) |
| 280 | { |
| 281 | case eInlineBreakpointsNever: |
| 282 | check_inlines = eLazyBoolNo; |
| 283 | break; |
| 284 | |
| 285 | case eInlineBreakpointsHeaders: |
| 286 | if (file.IsSourceImplementationFile()) |
| 287 | check_inlines = eLazyBoolNo; |
| 288 | else |
| 289 | check_inlines = eLazyBoolYes; |
| 290 | break; |
| 291 | |
| 292 | case eInlineBreakpointsAlways: |
| 293 | check_inlines = eLazyBoolYes; |
| 294 | break; |
| 295 | } |
| 296 | } |
Greg Clayton | 4636552 | 2012-09-07 23:48:57 +0000 | [diff] [blame] | 297 | SearchFilterSP filter_sp; |
| 298 | if (check_inlines == eLazyBoolNo) |
| 299 | { |
| 300 | // Not checking for inlines, we are looking only for matching compile units |
| 301 | FileSpecList compile_unit_list; |
| 302 | compile_unit_list.Append (file); |
| 303 | filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list); |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | filter_sp = GetSearchFilterForModuleList (containingModules); |
| 308 | } |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 309 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, |
| 310 | file, |
| 311 | line_no, |
| 312 | check_inlines, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 313 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 314 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | BreakpointSP |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 319 | Target::CreateBreakpoint (lldb::addr_t addr, bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 320 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | Address so_addr; |
| 322 | // Attempt to resolve our load address if possible, though it is ok if |
| 323 | // it doesn't resolve to section/offset. |
| 324 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 325 | // Try and resolve as a load address if possible |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 326 | m_section_load_list.ResolveLoadAddress(addr, so_addr); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 327 | if (!so_addr.IsValid()) |
| 328 | { |
| 329 | // The address didn't resolve, so just set this as an absolute address |
| 330 | so_addr.SetOffset (addr); |
| 331 | } |
| 332 | BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 333 | return bp_sp; |
| 334 | } |
| 335 | |
| 336 | BreakpointSP |
| 337 | Target::CreateBreakpoint (Address &addr, bool internal) |
| 338 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 339 | SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); |
| 341 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 342 | } |
| 343 | |
| 344 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 345 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
| 346 | const FileSpecList *containingSourceFiles, |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 347 | const char *func_name, |
| 348 | uint32_t func_name_type_mask, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 349 | LazyBool skip_prologue, |
| 350 | bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 352 | BreakpointSP bp_sp; |
| 353 | if (func_name) |
| 354 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 355 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 356 | |
| 357 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, |
| 358 | func_name, |
| 359 | func_name_type_mask, |
| 360 | Breakpoint::Exact, |
| 361 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 362 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 363 | } |
| 364 | return bp_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 367 | lldb::BreakpointSP |
| 368 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
Greg Clayton | bd5c23d | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 369 | const FileSpecList *containingSourceFiles, |
| 370 | const std::vector<std::string> &func_names, |
| 371 | uint32_t func_name_type_mask, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 372 | LazyBool skip_prologue, |
| 373 | bool internal) |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 374 | { |
| 375 | BreakpointSP bp_sp; |
| 376 | size_t num_names = func_names.size(); |
| 377 | if (num_names > 0) |
| 378 | { |
| 379 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
| 380 | |
| 381 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, |
| 382 | func_names, |
| 383 | func_name_type_mask, |
| 384 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
| 385 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 386 | } |
| 387 | return bp_sp; |
| 388 | } |
| 389 | |
Jim Ingham | c105362 | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 390 | BreakpointSP |
| 391 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
| 392 | const FileSpecList *containingSourceFiles, |
| 393 | const char *func_names[], |
| 394 | size_t num_names, |
| 395 | uint32_t func_name_type_mask, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 396 | LazyBool skip_prologue, |
| 397 | bool internal) |
Jim Ingham | c105362 | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 398 | { |
| 399 | BreakpointSP bp_sp; |
| 400 | if (num_names > 0) |
| 401 | { |
| 402 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
| 403 | |
| 404 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, |
| 405 | func_names, |
| 406 | num_names, |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 407 | func_name_type_mask, |
Jim Ingham | c105362 | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 408 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
| 409 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 410 | } |
| 411 | return bp_sp; |
| 412 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | |
| 414 | SearchFilterSP |
| 415 | Target::GetSearchFilterForModule (const FileSpec *containingModule) |
| 416 | { |
| 417 | SearchFilterSP filter_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | if (containingModule != NULL) |
| 419 | { |
| 420 | // TODO: We should look into sharing module based search filters |
| 421 | // across many breakpoints like we do for the simple target based one |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 422 | filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 423 | } |
| 424 | else |
| 425 | { |
| 426 | if (m_search_filter_sp.get() == NULL) |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 427 | m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | filter_sp = m_search_filter_sp; |
| 429 | } |
| 430 | return filter_sp; |
| 431 | } |
| 432 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 433 | SearchFilterSP |
| 434 | Target::GetSearchFilterForModuleList (const FileSpecList *containingModules) |
| 435 | { |
| 436 | SearchFilterSP filter_sp; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 437 | if (containingModules && containingModules->GetSize() != 0) |
| 438 | { |
| 439 | // TODO: We should look into sharing module based search filters |
| 440 | // across many breakpoints like we do for the simple target based one |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 441 | filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules)); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
| 445 | if (m_search_filter_sp.get() == NULL) |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 446 | m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this())); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 447 | filter_sp = m_search_filter_sp; |
| 448 | } |
| 449 | return filter_sp; |
| 450 | } |
| 451 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 452 | SearchFilterSP |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 453 | Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, |
| 454 | const FileSpecList *containingSourceFiles) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 455 | { |
| 456 | if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0) |
| 457 | return GetSearchFilterForModuleList(containingModules); |
| 458 | |
| 459 | SearchFilterSP filter_sp; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 460 | if (containingModules == NULL) |
| 461 | { |
| 462 | // We could make a special "CU List only SearchFilter". Better yet was if these could be composable, |
| 463 | // but that will take a little reworking. |
| 464 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 465 | filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles)); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 466 | } |
| 467 | else |
| 468 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 469 | filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles)); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 470 | } |
| 471 | return filter_sp; |
| 472 | } |
| 473 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 475 | Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 476 | const FileSpecList *containingSourceFiles, |
| 477 | RegularExpression &func_regex, |
| 478 | LazyBool skip_prologue, |
| 479 | bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 481 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 482 | BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, |
| 483 | func_regex, |
| 484 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | |
| 486 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 487 | } |
| 488 | |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 489 | lldb::BreakpointSP |
| 490 | Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal) |
| 491 | { |
| 492 | return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal); |
| 493 | } |
| 494 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | BreakpointSP |
| 496 | Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal) |
| 497 | { |
| 498 | BreakpointSP bp_sp; |
| 499 | if (filter_sp && resolver_sp) |
| 500 | { |
| 501 | bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp)); |
| 502 | resolver_sp->SetBreakpoint (bp_sp.get()); |
| 503 | |
| 504 | if (internal) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 505 | m_internal_breakpoint_list.Add (bp_sp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | else |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 507 | m_breakpoint_list.Add (bp_sp, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 509 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | if (log) |
| 511 | { |
| 512 | StreamString s; |
| 513 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
| 514 | log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); |
| 515 | } |
| 516 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 517 | bp_sp->ResolveBreakpoint(); |
| 518 | } |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 519 | |
| 520 | if (!internal && bp_sp) |
| 521 | { |
| 522 | m_last_created_breakpoint = bp_sp; |
| 523 | } |
| 524 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 525 | return bp_sp; |
| 526 | } |
| 527 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 528 | bool |
| 529 | Target::ProcessIsValid() |
| 530 | { |
| 531 | return (m_process_sp && m_process_sp->IsAlive()); |
| 532 | } |
| 533 | |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 534 | static bool |
| 535 | CheckIfWatchpointsExhausted(Target *target, Error &error) |
| 536 | { |
| 537 | uint32_t num_supported_hardware_watchpoints; |
| 538 | Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints); |
| 539 | if (rc.Success()) |
| 540 | { |
| 541 | uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize(); |
| 542 | if (num_current_watchpoints >= num_supported_hardware_watchpoints) |
| 543 | error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached", |
| 544 | num_supported_hardware_watchpoints); |
| 545 | } |
| 546 | return false; |
| 547 | } |
| 548 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 549 | // See also Watchpoint::SetWatchpointType(uint32_t type) and |
Johnny Chen | 87ff53b | 2011-09-14 00:26:03 +0000 | [diff] [blame] | 550 | // the OptionGroupWatchpoint::WatchType enum type. |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 551 | WatchpointSP |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 552 | Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error) |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 553 | { |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 554 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 555 | if (log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 556 | log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n", |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 557 | __FUNCTION__, addr, (uint64_t)size, kind); |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 558 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 559 | WatchpointSP wp_sp; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 560 | if (!ProcessIsValid()) |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 561 | { |
| 562 | error.SetErrorString("process is not alive"); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 563 | return wp_sp; |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 564 | } |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 565 | if (addr == LLDB_INVALID_ADDRESS || size == 0) |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 566 | { |
| 567 | if (size == 0) |
| 568 | error.SetErrorString("cannot set a watchpoint with watch_size of 0"); |
| 569 | else |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 570 | error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 571 | return wp_sp; |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 572 | } |
Johnny Chen | 9bf1199 | 2011-09-13 01:15:36 +0000 | [diff] [blame] | 573 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 574 | // Currently we only support one watchpoint per address, with total number |
| 575 | // of watchpoints limited by the hardware which the inferior is running on. |
Johnny Chen | bbf6aa5 | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 576 | |
| 577 | // Grab the list mutex while doing operations. |
| 578 | Mutex::Locker locker; |
| 579 | this->GetWatchpointList().GetListMutex(locker); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 580 | WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr); |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 581 | if (matched_sp) |
| 582 | { |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 583 | size_t old_size = matched_sp->GetByteSize(); |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 584 | uint32_t old_type = |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 585 | (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | |
| 586 | (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 587 | // Return the existing watchpoint if both size and type match. |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 588 | if (size == old_size && kind == old_type) { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 589 | wp_sp = matched_sp; |
| 590 | wp_sp->SetEnabled(false); |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 591 | } else { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 592 | // Nil the matched watchpoint; we will be creating a new one. |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 593 | m_process_sp->DisableWatchpoint(matched_sp.get()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 594 | m_watchpoint_list.Remove(matched_sp->GetID()); |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 595 | } |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Jason Molenda | c4d49fd | 2012-12-05 23:07:34 +0000 | [diff] [blame] | 598 | if (!wp_sp) |
| 599 | { |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 600 | Watchpoint *new_wp = new Watchpoint(*this, addr, size, type); |
Jason Molenda | c4d49fd | 2012-12-05 23:07:34 +0000 | [diff] [blame] | 601 | if (!new_wp) |
| 602 | { |
| 603 | error.SetErrorString("Watchpoint ctor failed, out of memory?"); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 604 | return wp_sp; |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 605 | } |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 606 | new_wp->SetWatchpointType(kind); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 607 | wp_sp.reset(new_wp); |
| 608 | m_watchpoint_list.Add(wp_sp); |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 609 | } |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 610 | |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 611 | error = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 612 | if (log) |
Jason Molenda | c4d49fd | 2012-12-05 23:07:34 +0000 | [diff] [blame] | 613 | log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", |
| 614 | __FUNCTION__, |
| 615 | error.Success() ? "succeeded" : "failed", |
| 616 | wp_sp->GetID()); |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 617 | |
Jason Molenda | c4d49fd | 2012-12-05 23:07:34 +0000 | [diff] [blame] | 618 | if (error.Fail()) |
| 619 | { |
Johnny Chen | 155599b | 2012-03-26 22:00:10 +0000 | [diff] [blame] | 620 | // Enabling the watchpoint on the device side failed. |
| 621 | // Remove the said watchpoint from the list maintained by the target instance. |
| 622 | m_watchpoint_list.Remove(wp_sp->GetID()); |
Johnny Chen | 3f88349 | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 623 | // See if we could provide more helpful error message. |
| 624 | if (!CheckIfWatchpointsExhausted(this, error)) |
| 625 | { |
| 626 | if (!OptionGroupWatchpoint::IsWatchSizeSupported(size)) |
| 627 | error.SetErrorStringWithFormat("watch size of %lu is not supported", size); |
| 628 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 629 | wp_sp.reset(); |
Johnny Chen | 155599b | 2012-03-26 22:00:10 +0000 | [diff] [blame] | 630 | } |
Johnny Chen | 5eb54bb | 2011-09-27 20:29:45 +0000 | [diff] [blame] | 631 | else |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 632 | m_last_created_watchpoint = wp_sp; |
| 633 | return wp_sp; |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | void |
| 637 | Target::RemoveAllBreakpoints (bool internal_also) |
| 638 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 639 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | if (log) |
| 641 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 642 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 643 | m_breakpoint_list.RemoveAll (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | if (internal_also) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 645 | m_internal_breakpoint_list.RemoveAll (false); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 646 | |
| 647 | m_last_created_breakpoint.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | void |
| 651 | Target::DisableAllBreakpoints (bool internal_also) |
| 652 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 653 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | if (log) |
| 655 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 656 | |
| 657 | m_breakpoint_list.SetEnabledAll (false); |
| 658 | if (internal_also) |
| 659 | m_internal_breakpoint_list.SetEnabledAll (false); |
| 660 | } |
| 661 | |
| 662 | void |
| 663 | Target::EnableAllBreakpoints (bool internal_also) |
| 664 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 665 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | if (log) |
| 667 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 668 | |
| 669 | m_breakpoint_list.SetEnabledAll (true); |
| 670 | if (internal_also) |
| 671 | m_internal_breakpoint_list.SetEnabledAll (true); |
| 672 | } |
| 673 | |
| 674 | bool |
| 675 | Target::RemoveBreakpointByID (break_id_t break_id) |
| 676 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 677 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 678 | if (log) |
| 679 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 680 | |
| 681 | if (DisableBreakpointByID (break_id)) |
| 682 | { |
| 683 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 684 | m_internal_breakpoint_list.Remove(break_id, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | else |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 686 | { |
Greg Clayton | 22c9e0d | 2011-01-24 23:35:47 +0000 | [diff] [blame] | 687 | if (m_last_created_breakpoint) |
| 688 | { |
| 689 | if (m_last_created_breakpoint->GetID() == break_id) |
| 690 | m_last_created_breakpoint.reset(); |
| 691 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 692 | m_breakpoint_list.Remove(break_id, true); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 693 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | return true; |
| 695 | } |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | bool |
| 700 | Target::DisableBreakpointByID (break_id_t break_id) |
| 701 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 702 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 703 | if (log) |
| 704 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 705 | |
| 706 | BreakpointSP bp_sp; |
| 707 | |
| 708 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 709 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 710 | else |
| 711 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 712 | if (bp_sp) |
| 713 | { |
| 714 | bp_sp->SetEnabled (false); |
| 715 | return true; |
| 716 | } |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | bool |
| 721 | Target::EnableBreakpointByID (break_id_t break_id) |
| 722 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 723 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 724 | if (log) |
| 725 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", |
| 726 | __FUNCTION__, |
| 727 | break_id, |
| 728 | LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 729 | |
| 730 | BreakpointSP bp_sp; |
| 731 | |
| 732 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 733 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 734 | else |
| 735 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 736 | |
| 737 | if (bp_sp) |
| 738 | { |
| 739 | bp_sp->SetEnabled (true); |
| 740 | return true; |
| 741 | } |
| 742 | return false; |
| 743 | } |
| 744 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 745 | // The flag 'end_to_end', default to true, signifies that the operation is |
| 746 | // performed end to end, for both the debugger and the debuggee. |
| 747 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 748 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end |
| 749 | // to end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 750 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 751 | Target::RemoveAllWatchpoints (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 752 | { |
| 753 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 754 | if (log) |
| 755 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 756 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 757 | if (!end_to_end) { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 758 | m_watchpoint_list.RemoveAll(); |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 759 | return true; |
| 760 | } |
| 761 | |
| 762 | // Otherwise, it's an end to end operation. |
| 763 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 764 | if (!ProcessIsValid()) |
| 765 | return false; |
| 766 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 767 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 768 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 769 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 770 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 771 | if (!wp_sp) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 772 | return false; |
| 773 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 774 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 775 | if (rc.Fail()) |
| 776 | return false; |
| 777 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 778 | m_watchpoint_list.RemoveAll (); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 779 | return true; // Success! |
| 780 | } |
| 781 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 782 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to |
| 783 | // end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 784 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 785 | Target::DisableAllWatchpoints (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 786 | { |
| 787 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 788 | if (log) |
| 789 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 790 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 791 | if (!end_to_end) { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 792 | m_watchpoint_list.SetEnabledAll(false); |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 793 | return true; |
| 794 | } |
| 795 | |
| 796 | // Otherwise, it's an end to end operation. |
| 797 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 798 | if (!ProcessIsValid()) |
| 799 | return false; |
| 800 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 801 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 802 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 803 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 804 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 805 | if (!wp_sp) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 806 | return false; |
| 807 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 808 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 809 | if (rc.Fail()) |
| 810 | return false; |
| 811 | } |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 812 | return true; // Success! |
| 813 | } |
| 814 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 815 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to |
| 816 | // end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 817 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 818 | Target::EnableAllWatchpoints (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 819 | { |
| 820 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 821 | if (log) |
| 822 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 823 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 824 | if (!end_to_end) { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 825 | m_watchpoint_list.SetEnabledAll(true); |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 826 | return true; |
| 827 | } |
| 828 | |
| 829 | // Otherwise, it's an end to end operation. |
| 830 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 831 | if (!ProcessIsValid()) |
| 832 | return false; |
| 833 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 834 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 835 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 836 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 837 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 838 | if (!wp_sp) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 839 | return false; |
| 840 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 841 | Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 842 | if (rc.Fail()) |
| 843 | return false; |
| 844 | } |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 845 | return true; // Success! |
| 846 | } |
| 847 | |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 848 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
| 849 | bool |
| 850 | Target::ClearAllWatchpointHitCounts () |
| 851 | { |
| 852 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 853 | if (log) |
| 854 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 855 | |
| 856 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 857 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 858 | { |
| 859 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 860 | if (!wp_sp) |
| 861 | return false; |
| 862 | |
| 863 | wp_sp->ResetHitCount(); |
| 864 | } |
| 865 | return true; // Success! |
| 866 | } |
| 867 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 868 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 869 | // during these operations. |
| 870 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 871 | Target::IgnoreAllWatchpoints (uint32_t ignore_count) |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 872 | { |
| 873 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 874 | if (log) |
| 875 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 876 | |
| 877 | if (!ProcessIsValid()) |
| 878 | return false; |
| 879 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 880 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 881 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 882 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 883 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 884 | if (!wp_sp) |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 885 | return false; |
| 886 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 887 | wp_sp->SetIgnoreCount(ignore_count); |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 888 | } |
| 889 | return true; // Success! |
| 890 | } |
| 891 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 892 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 893 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 894 | Target::DisableWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 895 | { |
| 896 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 897 | if (log) |
| 898 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 899 | |
| 900 | if (!ProcessIsValid()) |
| 901 | return false; |
| 902 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 903 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 904 | if (wp_sp) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 905 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 906 | Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 907 | if (rc.Success()) |
| 908 | return true; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 909 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 910 | // Else, fallthrough. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 911 | } |
| 912 | return false; |
| 913 | } |
| 914 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 915 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 916 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 917 | Target::EnableWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 918 | { |
| 919 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 920 | if (log) |
| 921 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 922 | |
| 923 | if (!ProcessIsValid()) |
| 924 | return false; |
| 925 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 926 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 927 | if (wp_sp) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 928 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 929 | Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 930 | if (rc.Success()) |
| 931 | return true; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 932 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 933 | // Else, fallthrough. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 934 | } |
| 935 | return false; |
| 936 | } |
| 937 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 938 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 939 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 940 | Target::RemoveWatchpointByID (lldb::watch_id_t watch_id) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 941 | { |
| 942 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 943 | if (log) |
| 944 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 945 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 946 | if (DisableWatchpointByID (watch_id)) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 947 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 948 | m_watchpoint_list.Remove(watch_id); |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 949 | return true; |
| 950 | } |
| 951 | return false; |
| 952 | } |
| 953 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 954 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 955 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 956 | Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count) |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 957 | { |
| 958 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 959 | if (log) |
| 960 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 961 | |
| 962 | if (!ProcessIsValid()) |
| 963 | return false; |
| 964 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 965 | WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); |
| 966 | if (wp_sp) |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 967 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 968 | wp_sp->SetIgnoreCount(ignore_count); |
Johnny Chen | e14cf4e | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 969 | return true; |
| 970 | } |
| 971 | return false; |
| 972 | } |
| 973 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 974 | ModuleSP |
| 975 | Target::GetExecutableModule () |
| 976 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 977 | return m_images.GetModuleAtIndex(0); |
| 978 | } |
| 979 | |
| 980 | Module* |
| 981 | Target::GetExecutableModulePointer () |
| 982 | { |
| 983 | return m_images.GetModulePointerAtIndex(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 986 | static void |
| 987 | LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target) |
| 988 | { |
| 989 | Error error; |
| 990 | if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error)) |
| 991 | { |
| 992 | target->GetDebugger().GetOutputStream().Printf("unable to load scripting data for module %s - error reported was %s\n", |
| 993 | module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), |
| 994 | error.AsCString()); |
| 995 | } |
| 996 | } |
| 997 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 998 | void |
| 999 | Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) |
| 1000 | { |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1001 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1002 | m_images.Clear(); |
| 1003 | m_scratch_ast_context_ap.reset(); |
Sean Callanan | dcf03f8 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 1004 | m_scratch_ast_source_ap.reset(); |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1005 | m_ast_importer_ap.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1006 | |
| 1007 | if (executable_sp.get()) |
| 1008 | { |
| 1009 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 1010 | "Target::SetExecutableModule (executable = '%s/%s')", |
| 1011 | executable_sp->GetFileSpec().GetDirectory().AsCString(), |
| 1012 | executable_sp->GetFileSpec().GetFilename().AsCString()); |
| 1013 | |
| 1014 | m_images.Append(executable_sp); // The first image is our exectuable file |
| 1015 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1016 | // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1017 | if (!m_arch.IsValid()) |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1018 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1019 | m_arch = executable_sp->GetArchitecture(); |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1020 | if (log) |
| 1021 | log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str()); |
| 1022 | } |
| 1023 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | FileSpecList dependent_files; |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1025 | ObjectFile *executable_objfile = executable_sp->GetObjectFile(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1027 | if (executable_objfile && get_dependent_files) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1028 | { |
| 1029 | executable_objfile->GetDependentModules(dependent_files); |
| 1030 | for (uint32_t i=0; i<dependent_files.GetSize(); i++) |
| 1031 | { |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1032 | FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i)); |
| 1033 | FileSpec platform_dependent_file_spec; |
| 1034 | if (m_platform_sp) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1035 | m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1036 | else |
| 1037 | platform_dependent_file_spec = dependent_file_spec; |
| 1038 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1039 | ModuleSpec module_spec (platform_dependent_file_spec, m_arch); |
| 1040 | ModuleSP image_module_sp(GetSharedModule (module_spec)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | if (image_module_sp.get()) |
| 1042 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 1044 | if (objfile) |
| 1045 | objfile->GetDependentModules(dependent_files); |
| 1046 | } |
| 1047 | } |
| 1048 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1053 | bool |
| 1054 | Target::SetArchitecture (const ArchSpec &arch_spec) |
| 1055 | { |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1056 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET)); |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1057 | if (m_arch == arch_spec || !m_arch.IsValid()) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1058 | { |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1059 | // If we haven't got a valid arch spec, or the architectures are |
| 1060 | // compatible, so just update the architecture. Architectures can be |
| 1061 | // equal, yet the triple OS and vendor might change, so we need to do |
| 1062 | // the assignment here just in case. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1063 | m_arch = arch_spec; |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1064 | if (log) |
| 1065 | log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1066 | return true; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | // If we have an executable file, try to reset the executable to the desired architecture |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1071 | if (log) |
Jason Molenda | c4d49fd | 2012-12-05 23:07:34 +0000 | [diff] [blame] | 1072 | log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1073 | m_arch = arch_spec; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1074 | ModuleSP executable_sp = GetExecutableModule (); |
| 1075 | m_images.Clear(); |
| 1076 | m_scratch_ast_context_ap.reset(); |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1077 | m_scratch_ast_source_ap.reset(); |
| 1078 | m_ast_importer_ap.reset(); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1079 | // Need to do something about unsetting breakpoints. |
| 1080 | |
| 1081 | if (executable_sp) |
| 1082 | { |
Jason Molenda | 8c6cf43 | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1083 | if (log) |
| 1084 | log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1085 | ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec); |
| 1086 | Error error = ModuleList::GetSharedModule (module_spec, |
| 1087 | executable_sp, |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1088 | &GetExecutableSearchPaths(), |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1089 | NULL, |
| 1090 | NULL); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1091 | |
| 1092 | if (!error.Fail() && executable_sp) |
| 1093 | { |
| 1094 | SetExecutableModule (executable_sp, true); |
| 1095 | return true; |
| 1096 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1097 | } |
| 1098 | } |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1099 | return false; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1100 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1102 | void |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1103 | Target::WillClearList (const ModuleList& module_list) |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1104 | { |
| 1105 | } |
| 1106 | |
| 1107 | void |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1108 | Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1109 | { |
| 1110 | // A module is being added to this target for the first time |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1111 | ModuleList my_module_list; |
| 1112 | my_module_list.Append(module_sp); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1113 | LoadScriptingResourceForModule(module_sp, this); |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1114 | ModulesDidLoad (my_module_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | void |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1118 | Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp) |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1119 | { |
| 1120 | // A module is being added to this target for the first time |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1121 | ModuleList my_module_list; |
| 1122 | my_module_list.Append(module_sp); |
| 1123 | ModulesDidUnload (my_module_list); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 1127 | Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1128 | { |
Jim Ingham | 3b8a605 | 2011-08-03 01:00:06 +0000 | [diff] [blame] | 1129 | // A module is replacing an already added module |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1130 | m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | void |
| 1134 | Target::ModulesDidLoad (ModuleList &module_list) |
| 1135 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1136 | if (module_list.GetSize()) |
| 1137 | { |
| 1138 | m_breakpoint_list.UpdateBreakpoints (module_list, true); |
| 1139 | // TODO: make event data that packages up the module_list |
| 1140 | BroadcastEvent (eBroadcastBitModulesLoaded, NULL); |
| 1141 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | void |
| 1145 | Target::ModulesDidUnload (ModuleList &module_list) |
| 1146 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1147 | if (module_list.GetSize()) |
| 1148 | { |
| 1149 | m_breakpoint_list.UpdateBreakpoints (module_list, false); |
| 1150 | // TODO: make event data that packages up the module_list |
| 1151 | BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); |
| 1152 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Daniel Dunbar | 705a098 | 2011-10-31 22:50:37 +0000 | [diff] [blame] | 1155 | bool |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1156 | Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec) |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1157 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1158 | if (GetBreakpointsConsultPlatformAvoidList()) |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1159 | { |
| 1160 | ModuleList matchingModules; |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1161 | ModuleSpec module_spec (module_file_spec); |
| 1162 | size_t num_modules = GetImages().FindModules(module_spec, matchingModules); |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1163 | |
| 1164 | // If there is more than one module for this file spec, only return true if ALL the modules are on the |
| 1165 | // black list. |
| 1166 | if (num_modules > 0) |
| 1167 | { |
| 1168 | for (int i = 0; i < num_modules; i++) |
| 1169 | { |
| 1170 | if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i))) |
| 1171 | return false; |
| 1172 | } |
| 1173 | return true; |
| 1174 | } |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1175 | } |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1176 | return false; |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Daniel Dunbar | 705a098 | 2011-10-31 22:50:37 +0000 | [diff] [blame] | 1179 | bool |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1180 | Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp) |
| 1181 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1182 | if (GetBreakpointsConsultPlatformAvoidList()) |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1183 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1184 | if (m_platform_sp) |
| 1185 | return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp); |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1186 | } |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1187 | return false; |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1190 | size_t |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1191 | Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error) |
| 1192 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1193 | SectionSP section_sp (addr.GetSection()); |
| 1194 | if (section_sp) |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1195 | { |
Jason Molenda | 6b028d6 | 2012-04-25 00:06:56 +0000 | [diff] [blame] | 1196 | // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory. |
| 1197 | if (section_sp->IsEncrypted()) |
| 1198 | { |
Greg Clayton | 04e6ada | 2012-05-25 17:05:55 +0000 | [diff] [blame] | 1199 | error.SetErrorString("section is encrypted"); |
Jason Molenda | 6b028d6 | 2012-04-25 00:06:56 +0000 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1202 | ModuleSP module_sp (section_sp->GetModule()); |
| 1203 | if (module_sp) |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1204 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1205 | ObjectFile *objfile = section_sp->GetModule()->GetObjectFile(); |
| 1206 | if (objfile) |
| 1207 | { |
| 1208 | size_t bytes_read = objfile->ReadSectionData (section_sp.get(), |
| 1209 | addr.GetOffset(), |
| 1210 | dst, |
| 1211 | dst_len); |
| 1212 | if (bytes_read > 0) |
| 1213 | return bytes_read; |
| 1214 | else |
| 1215 | error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString()); |
| 1216 | } |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1217 | else |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1218 | error.SetErrorString("address isn't from a object file"); |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1219 | } |
| 1220 | else |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1221 | error.SetErrorString("address isn't in a module"); |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1222 | } |
| 1223 | else |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1224 | error.SetErrorString("address doesn't contain a section that points to a section in a object file"); |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1225 | |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | size_t |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1230 | Target::ReadMemory (const Address& addr, |
| 1231 | bool prefer_file_cache, |
| 1232 | void *dst, |
| 1233 | size_t dst_len, |
| 1234 | Error &error, |
| 1235 | lldb::addr_t *load_addr_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1236 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | error.Clear(); |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1238 | |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1239 | // if we end up reading this from process memory, we will fill this |
| 1240 | // with the actual load address |
| 1241 | if (load_addr_ptr) |
| 1242 | *load_addr_ptr = LLDB_INVALID_ADDRESS; |
| 1243 | |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1244 | size_t bytes_read = 0; |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1245 | |
| 1246 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 1247 | addr_t file_addr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1248 | Address resolved_addr; |
| 1249 | if (!addr.IsSectionOffset()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1250 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1251 | if (m_section_load_list.IsEmpty()) |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1252 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1253 | // No sections are loaded, so we must assume we are not running |
| 1254 | // yet and anything we are given is a file address. |
| 1255 | file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address |
| 1256 | m_images.ResolveFileAddress (file_addr, resolved_addr); |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1257 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1258 | else |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1259 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1260 | // We have at least one section loaded. This can be becuase |
| 1261 | // we have manually loaded some sections with "target modules load ..." |
| 1262 | // or because we have have a live process that has sections loaded |
| 1263 | // through the dynamic loader |
| 1264 | load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address |
| 1265 | m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr); |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1266 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1267 | } |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1268 | if (!resolved_addr.IsValid()) |
| 1269 | resolved_addr = addr; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1270 | |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1271 | |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1272 | if (prefer_file_cache) |
| 1273 | { |
| 1274 | bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
| 1275 | if (bytes_read > 0) |
| 1276 | return bytes_read; |
| 1277 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1278 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1279 | if (ProcessIsValid()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1280 | { |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1281 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1282 | load_addr = resolved_addr.GetLoadAddress (this); |
| 1283 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1284 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1285 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1286 | ModuleSP addr_module_sp (resolved_addr.GetModule()); |
| 1287 | if (addr_module_sp && addr_module_sp->GetFileSpec()) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1288 | error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded", |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1289 | addr_module_sp->GetFileSpec().GetFilename().AsCString(), |
Jason Molenda | 95b7b43 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1290 | resolved_addr.GetFileAddress(), |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1291 | addr_module_sp->GetFileSpec().GetFilename().AsCString()); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1292 | else |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1293 | error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress()); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1294 | } |
| 1295 | else |
| 1296 | { |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1297 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1298 | if (bytes_read != dst_len) |
| 1299 | { |
| 1300 | if (error.Success()) |
| 1301 | { |
| 1302 | if (bytes_read == 0) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1303 | error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1304 | else |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1305 | error.SetErrorStringWithFormat("only %" PRIu64 " of %" PRIu64 " bytes were read from memory at 0x%" PRIx64, (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1308 | if (bytes_read) |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1309 | { |
| 1310 | if (load_addr_ptr) |
| 1311 | *load_addr_ptr = load_addr; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1312 | return bytes_read; |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1313 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1314 | // If the address is not section offset we have an address that |
| 1315 | // doesn't resolve to any address in any currently loaded shared |
| 1316 | // libaries and we failed to read memory so there isn't anything |
| 1317 | // more we can do. If it is section offset, we might be able to |
| 1318 | // read cached memory from the object file. |
| 1319 | if (!resolved_addr.IsSectionOffset()) |
| 1320 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1322 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1323 | |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1324 | if (!prefer_file_cache && resolved_addr.IsSectionOffset()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1325 | { |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1326 | // If we didn't already try and read from the object file cache, then |
| 1327 | // try it after failing to read from the process. |
| 1328 | return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1329 | } |
| 1330 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1333 | size_t |
| 1334 | Target::ReadScalarIntegerFromMemory (const Address& addr, |
| 1335 | bool prefer_file_cache, |
| 1336 | uint32_t byte_size, |
| 1337 | bool is_signed, |
| 1338 | Scalar &scalar, |
| 1339 | Error &error) |
| 1340 | { |
| 1341 | uint64_t uval; |
| 1342 | |
| 1343 | if (byte_size <= sizeof(uval)) |
| 1344 | { |
| 1345 | size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error); |
| 1346 | if (bytes_read == byte_size) |
| 1347 | { |
| 1348 | DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize()); |
| 1349 | uint32_t offset = 0; |
| 1350 | if (byte_size <= 4) |
| 1351 | scalar = data.GetMaxU32 (&offset, byte_size); |
| 1352 | else |
| 1353 | scalar = data.GetMaxU64 (&offset, byte_size); |
| 1354 | |
| 1355 | if (is_signed) |
| 1356 | scalar.SignExtend(byte_size * 8); |
| 1357 | return bytes_read; |
| 1358 | } |
| 1359 | } |
| 1360 | else |
| 1361 | { |
| 1362 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 1363 | } |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | uint64_t |
| 1368 | Target::ReadUnsignedIntegerFromMemory (const Address& addr, |
| 1369 | bool prefer_file_cache, |
| 1370 | size_t integer_byte_size, |
| 1371 | uint64_t fail_value, |
| 1372 | Error &error) |
| 1373 | { |
| 1374 | Scalar scalar; |
| 1375 | if (ReadScalarIntegerFromMemory (addr, |
| 1376 | prefer_file_cache, |
| 1377 | integer_byte_size, |
| 1378 | false, |
| 1379 | scalar, |
| 1380 | error)) |
| 1381 | return scalar.ULongLong(fail_value); |
| 1382 | return fail_value; |
| 1383 | } |
| 1384 | |
| 1385 | bool |
| 1386 | Target::ReadPointerFromMemory (const Address& addr, |
| 1387 | bool prefer_file_cache, |
| 1388 | Error &error, |
| 1389 | Address &pointer_addr) |
| 1390 | { |
| 1391 | Scalar scalar; |
| 1392 | if (ReadScalarIntegerFromMemory (addr, |
| 1393 | prefer_file_cache, |
| 1394 | m_arch.GetAddressByteSize(), |
| 1395 | false, |
| 1396 | scalar, |
| 1397 | error)) |
| 1398 | { |
| 1399 | addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1400 | if (pointer_vm_addr != LLDB_INVALID_ADDRESS) |
| 1401 | { |
| 1402 | if (m_section_load_list.IsEmpty()) |
| 1403 | { |
| 1404 | // No sections are loaded, so we must assume we are not running |
| 1405 | // yet and anything we are given is a file address. |
| 1406 | m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr); |
| 1407 | } |
| 1408 | else |
| 1409 | { |
| 1410 | // We have at least one section loaded. This can be becuase |
| 1411 | // we have manually loaded some sections with "target modules load ..." |
| 1412 | // or because we have have a live process that has sections loaded |
| 1413 | // through the dynamic loader |
| 1414 | m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr); |
| 1415 | } |
| 1416 | // We weren't able to resolve the pointer value, so just return |
| 1417 | // an address with no section |
| 1418 | if (!pointer_addr.IsValid()) |
| 1419 | pointer_addr.SetOffset (pointer_vm_addr); |
| 1420 | return true; |
| 1421 | |
| 1422 | } |
| 1423 | } |
| 1424 | return false; |
| 1425 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1426 | |
| 1427 | ModuleSP |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1428 | Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1429 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1430 | ModuleSP module_sp; |
| 1431 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1432 | Error error; |
| 1433 | |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1434 | // First see if we already have this module in our module list. If we do, then we're done, we don't need |
| 1435 | // to consult the shared modules list. But only do this if we are passed a UUID. |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1436 | |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1437 | if (module_spec.GetUUID().IsValid()) |
| 1438 | module_sp = m_images.FindFirstModule(module_spec); |
| 1439 | |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1440 | if (!module_sp) |
| 1441 | { |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1442 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 1443 | bool did_create_module = false; |
| 1444 | |
| 1445 | // If there are image search path entries, try to use them first to acquire a suitable image. |
| 1446 | if (m_image_search_paths.GetSize()) |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1447 | { |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1448 | ModuleSpec transformed_spec (module_spec); |
| 1449 | if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory())) |
| 1450 | { |
| 1451 | transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename(); |
| 1452 | error = ModuleList::GetSharedModule (transformed_spec, |
| 1453 | module_sp, |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1454 | &GetExecutableSearchPaths(), |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1455 | &old_module_sp, |
| 1456 | &did_create_module); |
| 1457 | } |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1458 | } |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1459 | |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1460 | if (!module_sp) |
| 1461 | { |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1462 | // If we have a UUID, we can check our global shared module list in case |
| 1463 | // we already have it. If we don't have a valid UUID, then we can't since |
| 1464 | // the path in "module_spec" will be a platform path, and we will need to |
| 1465 | // let the platform find that file. For example, we could be asking for |
| 1466 | // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick |
| 1467 | // the local copy of "/usr/lib/dyld" since our platform could be a remote |
| 1468 | // platform that has its own "/usr/lib/dyld" in an SDK or in a local file |
| 1469 | // cache. |
| 1470 | if (module_spec.GetUUID().IsValid()) |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1471 | { |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1472 | // We have a UUID, it is OK to check the global module list... |
| 1473 | error = ModuleList::GetSharedModule (module_spec, |
| 1474 | module_sp, |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1475 | &GetExecutableSearchPaths(), |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1476 | &old_module_sp, |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1477 | &did_create_module); |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1478 | } |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1479 | |
| 1480 | if (!module_sp) |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1481 | { |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1482 | // The platform is responsible for finding and caching an appropriate |
| 1483 | // module in the shared module cache. |
| 1484 | if (m_platform_sp) |
| 1485 | { |
| 1486 | FileSpec platform_file_spec; |
| 1487 | error = m_platform_sp->GetSharedModule (module_spec, |
| 1488 | module_sp, |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1489 | &GetExecutableSearchPaths(), |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1490 | &old_module_sp, |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1491 | &did_create_module); |
| 1492 | } |
| 1493 | else |
| 1494 | { |
| 1495 | error.SetErrorString("no platform is currently set"); |
| 1496 | } |
Greg Clayton | e1ef1e3 | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 1497 | } |
| 1498 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1499 | |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1500 | // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent |
| 1501 | // module in the list already, and if there was, let's remove it. |
| 1502 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1503 | { |
Greg Clayton | 1649a72 | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 1504 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 1505 | if (objfile) |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1506 | { |
Greg Clayton | 1649a72 | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 1507 | switch (objfile->GetType()) |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1508 | { |
Greg Clayton | 1649a72 | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 1509 | case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state |
| 1510 | case ObjectFile::eTypeExecutable: /// A normal executable |
| 1511 | case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable |
| 1512 | case ObjectFile::eTypeObjectFile: /// An intermediate object file |
| 1513 | case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution |
| 1514 | break; |
| 1515 | case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information |
| 1516 | if (error_ptr) |
| 1517 | error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable"); |
| 1518 | return ModuleSP(); |
| 1519 | case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution |
| 1520 | if (error_ptr) |
| 1521 | error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable"); |
| 1522 | return ModuleSP(); |
| 1523 | default: |
| 1524 | if (error_ptr) |
| 1525 | error_ptr->SetErrorString("unsupported file type, please specify an executable"); |
| 1526 | return ModuleSP(); |
| 1527 | } |
| 1528 | // GetSharedModule is not guaranteed to find the old shared module, for instance |
| 1529 | // in the common case where you pass in the UUID, it is only going to find the one |
| 1530 | // module matching the UUID. In fact, it has no good way to know what the "old module" |
| 1531 | // relevant to this target is, since there might be many copies of a module with this file spec |
| 1532 | // in various running debug sessions, but only one of them will belong to this target. |
| 1533 | // So let's remove the UUID from the module list, and look in the target's module list. |
| 1534 | // Only do this if there is SOMETHING else in the module spec... |
| 1535 | if (!old_module_sp) |
| 1536 | { |
| 1537 | if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty()) |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1538 | { |
Greg Clayton | 1649a72 | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 1539 | ModuleSpec module_spec_copy(module_spec.GetFileSpec()); |
| 1540 | module_spec_copy.GetUUID().Clear(); |
| 1541 | |
| 1542 | ModuleList found_modules; |
| 1543 | size_t num_found = m_images.FindModules (module_spec_copy, found_modules); |
| 1544 | if (num_found == 1) |
| 1545 | { |
| 1546 | old_module_sp = found_modules.GetModuleAtIndex(0); |
| 1547 | } |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1548 | } |
| 1549 | } |
Greg Clayton | 1649a72 | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 1550 | |
| 1551 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 1552 | { |
| 1553 | m_images.ReplaceModule(old_module_sp, module_sp); |
| 1554 | Module *old_module_ptr = old_module_sp.get(); |
| 1555 | old_module_sp.reset(); |
| 1556 | ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr); |
| 1557 | } |
| 1558 | else |
| 1559 | m_images.Append(module_sp); |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 1560 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | if (error_ptr) |
| 1564 | *error_ptr = error; |
| 1565 | return module_sp; |
| 1566 | } |
| 1567 | |
| 1568 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1569 | TargetSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1570 | Target::CalculateTarget () |
| 1571 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1572 | return shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1575 | ProcessSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1576 | Target::CalculateProcess () |
| 1577 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1578 | return ProcessSP(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1581 | ThreadSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1582 | Target::CalculateThread () |
| 1583 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1584 | return ThreadSP(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1587 | StackFrameSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1588 | Target::CalculateStackFrame () |
| 1589 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1590 | return StackFrameSP(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1594 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1595 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1596 | exe_ctx.Clear(); |
| 1597 | exe_ctx.SetTargetPtr(this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | PathMappingList & |
| 1601 | Target::GetImageSearchPathList () |
| 1602 | { |
| 1603 | return m_image_search_paths; |
| 1604 | } |
| 1605 | |
| 1606 | void |
| 1607 | Target::ImageSearchPathsChanged |
| 1608 | ( |
| 1609 | const PathMappingList &path_list, |
| 1610 | void *baton |
| 1611 | ) |
| 1612 | { |
| 1613 | Target *target = (Target *)baton; |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1614 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 1615 | if (exe_module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1616 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1617 | target->m_images.Clear(); |
| 1618 | target->SetExecutableModule (exe_module_sp, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | ClangASTContext * |
Johnny Chen | fa21ffd | 2011-11-30 23:18:53 +0000 | [diff] [blame] | 1623 | Target::GetScratchClangASTContext(bool create_on_demand) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1624 | { |
Greg Clayton | 34ce4ea | 2011-08-03 01:23:55 +0000 | [diff] [blame] | 1625 | // Now see if we know the target triple, and if so, create our scratch AST context: |
Johnny Chen | fa21ffd | 2011-11-30 23:18:53 +0000 | [diff] [blame] | 1626 | if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand) |
Sean Callanan | dcf03f8 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 1627 | { |
Greg Clayton | 34ce4ea | 2011-08-03 01:23:55 +0000 | [diff] [blame] | 1628 | m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str())); |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1629 | m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this())); |
Sean Callanan | dcf03f8 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 1630 | m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext()); |
| 1631 | llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy()); |
| 1632 | m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source); |
| 1633 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1634 | return m_scratch_ast_context_ap.get(); |
| 1635 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1636 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1637 | ClangASTImporter * |
| 1638 | Target::GetClangASTImporter() |
| 1639 | { |
| 1640 | ClangASTImporter *ast_importer = m_ast_importer_ap.get(); |
| 1641 | |
| 1642 | if (!ast_importer) |
| 1643 | { |
| 1644 | ast_importer = new ClangASTImporter(); |
| 1645 | m_ast_importer_ap.reset(ast_importer); |
| 1646 | } |
| 1647 | |
| 1648 | return ast_importer; |
| 1649 | } |
| 1650 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1651 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1652 | Target::SettingsInitialize () |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1653 | { |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1654 | Process::SettingsInitialize (); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1655 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1656 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1657 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1658 | Target::SettingsTerminate () |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1659 | { |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1660 | Process::SettingsTerminate (); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1661 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1662 | |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1663 | FileSpecList |
| 1664 | Target::GetDefaultExecutableSearchPaths () |
| 1665 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1666 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 1667 | if (properties_sp) |
| 1668 | return properties_sp->GetExecutableSearchPaths(); |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1669 | return FileSpecList(); |
| 1670 | } |
| 1671 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1672 | ArchSpec |
| 1673 | Target::GetDefaultArchitecture () |
| 1674 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1675 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 1676 | if (properties_sp) |
| 1677 | return properties_sp->GetDefaultArchitecture(); |
Greg Clayton | 469e08d | 2012-05-15 02:44:13 +0000 | [diff] [blame] | 1678 | return ArchSpec(); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | void |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1682 | Target::SetDefaultArchitecture (const ArchSpec &arch) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1683 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1684 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 1685 | if (properties_sp) |
Jason Molenda | 332dc00 | 2012-12-12 02:23:56 +0000 | [diff] [blame] | 1686 | { |
| 1687 | LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::SetDefaultArchitecture setting target's default architecture to %s (%s)", arch.GetArchitectureName(), arch.GetTriple().getTriple().c_str()); |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1688 | return properties_sp->SetDefaultArchitecture(arch); |
Jason Molenda | 332dc00 | 2012-12-12 02:23:56 +0000 | [diff] [blame] | 1689 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1692 | Target * |
| 1693 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 1694 | { |
| 1695 | // The target can either exist in the "process" of ExecutionContext, or in |
| 1696 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 1697 | // will get the target from one of these locations. |
| 1698 | |
| 1699 | Target *target = NULL; |
| 1700 | if (sc_ptr != NULL) |
| 1701 | target = sc_ptr->target_sp.get(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1702 | if (target == NULL && exe_ctx_ptr) |
| 1703 | target = exe_ctx_ptr->GetTargetPtr(); |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1704 | return target; |
| 1705 | } |
| 1706 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1707 | ExecutionResults |
| 1708 | Target::EvaluateExpression |
| 1709 | ( |
| 1710 | const char *expr_cstr, |
| 1711 | StackFrame *frame, |
Enrico Granata | 6cca969 | 2012-07-16 23:10:35 +0000 | [diff] [blame] | 1712 | lldb::ValueObjectSP &result_valobj_sp, |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1713 | const EvaluateExpressionOptions& options |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1714 | ) |
| 1715 | { |
Enrico Granata | 3a08fd1 | 2012-09-18 17:43:16 +0000 | [diff] [blame] | 1716 | result_valobj_sp.reset(); |
| 1717 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1718 | ExecutionResults execution_results = eExecutionSetupError; |
| 1719 | |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1720 | if (expr_cstr == NULL || expr_cstr[0] == '\0') |
| 1721 | return execution_results; |
| 1722 | |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1723 | // We shouldn't run stop hooks in expressions. |
| 1724 | // Be sure to reset this if you return anywhere within this function. |
| 1725 | bool old_suppress_value = m_suppress_stop_hooks; |
| 1726 | m_suppress_stop_hooks = true; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1727 | |
| 1728 | ExecutionContext exe_ctx; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1729 | |
| 1730 | const size_t expr_cstr_len = ::strlen (expr_cstr); |
| 1731 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1732 | if (frame) |
| 1733 | { |
| 1734 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1735 | Error error; |
Greg Clayton | c67efa4 | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 1736 | const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
Enrico Granata | f669850 | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1737 | StackFrame::eExpressionPathOptionsNoFragileObjcIvar | |
| 1738 | StackFrame::eExpressionPathOptionsNoSyntheticChildren; |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1739 | lldb::VariableSP var_sp; |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1740 | |
| 1741 | // Make sure we don't have any things that we know a variable expression |
| 1742 | // won't be able to deal with before calling into it |
| 1743 | if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len) |
| 1744 | { |
| 1745 | result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1746 | options.GetUseDynamic(), |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1747 | expr_path_options, |
| 1748 | var_sp, |
| 1749 | error); |
Enrico Granata | 4d609c9 | 2012-04-24 22:15:37 +0000 | [diff] [blame] | 1750 | // if this expression results in a bitfield, we give up and let the IR handle it |
| 1751 | if (result_valobj_sp && result_valobj_sp->IsBitfield()) |
| 1752 | result_valobj_sp.reset(); |
Greg Clayton | 37bb8dd | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1753 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1754 | } |
| 1755 | else if (m_process_sp) |
| 1756 | { |
| 1757 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 1758 | } |
| 1759 | else |
| 1760 | { |
| 1761 | CalculateExecutionContext(exe_ctx); |
| 1762 | } |
| 1763 | |
| 1764 | if (result_valobj_sp) |
| 1765 | { |
| 1766 | execution_results = eExecutionCompleted; |
| 1767 | // We got a result from the frame variable expression path above... |
| 1768 | ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName()); |
| 1769 | |
| 1770 | lldb::ValueObjectSP const_valobj_sp; |
| 1771 | |
| 1772 | // Check in case our value is already a constant value |
| 1773 | if (result_valobj_sp->GetIsConstant()) |
| 1774 | { |
| 1775 | const_valobj_sp = result_valobj_sp; |
| 1776 | const_valobj_sp->SetName (persistent_variable_name); |
| 1777 | } |
| 1778 | else |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1779 | { |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1780 | if (options.GetUseDynamic() != lldb::eNoDynamicValues) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1781 | { |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1782 | ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(options.GetUseDynamic()); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1783 | if (dynamic_sp) |
| 1784 | result_valobj_sp = dynamic_sp; |
| 1785 | } |
| 1786 | |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1787 | const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1788 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1789 | |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1790 | lldb::ValueObjectSP live_valobj_sp = result_valobj_sp; |
| 1791 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1792 | result_valobj_sp = const_valobj_sp; |
| 1793 | |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1794 | ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp)); |
| 1795 | assert (clang_expr_variable_sp.get()); |
| 1796 | |
| 1797 | // Set flags and live data as appropriate |
| 1798 | |
| 1799 | const Value &result_value = live_valobj_sp->GetValue(); |
| 1800 | |
| 1801 | switch (result_value.GetValueType()) |
| 1802 | { |
| 1803 | case Value::eValueTypeHostAddress: |
| 1804 | case Value::eValueTypeFileAddress: |
| 1805 | // we don't do anything with these for now |
| 1806 | break; |
| 1807 | case Value::eValueTypeScalar: |
Greg Clayton | f0fab4f | 2012-10-30 23:56:14 +0000 | [diff] [blame] | 1808 | case Value::eValueTypeVector: |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1809 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated; |
| 1810 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation; |
| 1811 | break; |
| 1812 | case Value::eValueTypeLoadAddress: |
| 1813 | clang_expr_variable_sp->m_live_sp = live_valobj_sp; |
| 1814 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference; |
| 1815 | break; |
| 1816 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1817 | } |
| 1818 | else |
| 1819 | { |
| 1820 | // Make sure we aren't just trying to see the value of a persistent |
| 1821 | // variable (something like "$0") |
Greg Clayton | a875b64 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 1822 | lldb::ClangExpressionVariableSP persistent_var_sp; |
| 1823 | // Only check for persistent variables the expression starts with a '$' |
| 1824 | if (expr_cstr[0] == '$') |
| 1825 | persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); |
| 1826 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1827 | if (persistent_var_sp) |
| 1828 | { |
| 1829 | result_valobj_sp = persistent_var_sp->GetValueObject (); |
| 1830 | execution_results = eExecutionCompleted; |
| 1831 | } |
| 1832 | else |
| 1833 | { |
| 1834 | const char *prefix = GetExpressionPrefixContentsAsCString(); |
Sean Callanan | 47dc457 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 1835 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1836 | execution_results = ClangUserExpression::Evaluate (exe_ctx, |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1837 | options.GetExecutionPolicy(), |
Sean Callanan | 5b658cc | 2011-11-07 23:35:40 +0000 | [diff] [blame] | 1838 | lldb::eLanguageTypeUnknown, |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 1839 | options.DoesCoerceToId() ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny, |
| 1840 | options.DoesUnwindOnError(), |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1841 | expr_cstr, |
| 1842 | prefix, |
Enrico Granata | 6cca969 | 2012-07-16 23:10:35 +0000 | [diff] [blame] | 1843 | result_valobj_sp, |
Jim Ingham | 47beabb | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 1844 | options.GetRunOthers(), |
| 1845 | options.GetTimeoutUsec()); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1846 | } |
| 1847 | } |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1848 | |
| 1849 | m_suppress_stop_hooks = old_suppress_value; |
| 1850 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1851 | return execution_results; |
| 1852 | } |
| 1853 | |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 1854 | lldb::addr_t |
| 1855 | Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1856 | { |
| 1857 | addr_t code_addr = load_addr; |
| 1858 | switch (m_arch.GetMachine()) |
| 1859 | { |
| 1860 | case llvm::Triple::arm: |
| 1861 | case llvm::Triple::thumb: |
| 1862 | switch (addr_class) |
| 1863 | { |
| 1864 | case eAddressClassData: |
| 1865 | case eAddressClassDebug: |
| 1866 | return LLDB_INVALID_ADDRESS; |
| 1867 | |
| 1868 | case eAddressClassUnknown: |
| 1869 | case eAddressClassInvalid: |
| 1870 | case eAddressClassCode: |
| 1871 | case eAddressClassCodeAlternateISA: |
| 1872 | case eAddressClassRuntime: |
| 1873 | // Check if bit zero it no set? |
| 1874 | if ((code_addr & 1ull) == 0) |
| 1875 | { |
| 1876 | // Bit zero isn't set, check if the address is a multiple of 2? |
| 1877 | if (code_addr & 2ull) |
| 1878 | { |
| 1879 | // The address is a multiple of 2 so it must be thumb, set bit zero |
| 1880 | code_addr |= 1ull; |
| 1881 | } |
| 1882 | else if (addr_class == eAddressClassCodeAlternateISA) |
| 1883 | { |
| 1884 | // We checked the address and the address claims to be the alternate ISA |
| 1885 | // which means thumb, so set bit zero. |
| 1886 | code_addr |= 1ull; |
| 1887 | } |
| 1888 | } |
| 1889 | break; |
| 1890 | } |
| 1891 | break; |
| 1892 | |
| 1893 | default: |
| 1894 | break; |
| 1895 | } |
| 1896 | return code_addr; |
| 1897 | } |
| 1898 | |
| 1899 | lldb::addr_t |
| 1900 | Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1901 | { |
| 1902 | addr_t opcode_addr = load_addr; |
| 1903 | switch (m_arch.GetMachine()) |
| 1904 | { |
| 1905 | case llvm::Triple::arm: |
| 1906 | case llvm::Triple::thumb: |
| 1907 | switch (addr_class) |
| 1908 | { |
| 1909 | case eAddressClassData: |
| 1910 | case eAddressClassDebug: |
| 1911 | return LLDB_INVALID_ADDRESS; |
| 1912 | |
| 1913 | case eAddressClassInvalid: |
| 1914 | case eAddressClassUnknown: |
| 1915 | case eAddressClassCode: |
| 1916 | case eAddressClassCodeAlternateISA: |
| 1917 | case eAddressClassRuntime: |
| 1918 | opcode_addr &= ~(1ull); |
| 1919 | break; |
| 1920 | } |
| 1921 | break; |
| 1922 | |
| 1923 | default: |
| 1924 | break; |
| 1925 | } |
| 1926 | return opcode_addr; |
| 1927 | } |
| 1928 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1929 | lldb::user_id_t |
| 1930 | Target::AddStopHook (Target::StopHookSP &new_hook_sp) |
| 1931 | { |
| 1932 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1933 | new_hook_sp.reset (new StopHook(shared_from_this(), new_uid)); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1934 | m_stop_hooks[new_uid] = new_hook_sp; |
| 1935 | return new_uid; |
| 1936 | } |
| 1937 | |
| 1938 | bool |
| 1939 | Target::RemoveStopHookByID (lldb::user_id_t user_id) |
| 1940 | { |
| 1941 | size_t num_removed; |
| 1942 | num_removed = m_stop_hooks.erase (user_id); |
| 1943 | if (num_removed == 0) |
| 1944 | return false; |
| 1945 | else |
| 1946 | return true; |
| 1947 | } |
| 1948 | |
| 1949 | void |
| 1950 | Target::RemoveAllStopHooks () |
| 1951 | { |
| 1952 | m_stop_hooks.clear(); |
| 1953 | } |
| 1954 | |
| 1955 | Target::StopHookSP |
| 1956 | Target::GetStopHookByID (lldb::user_id_t user_id) |
| 1957 | { |
| 1958 | StopHookSP found_hook; |
| 1959 | |
| 1960 | StopHookCollection::iterator specified_hook_iter; |
| 1961 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1962 | if (specified_hook_iter != m_stop_hooks.end()) |
| 1963 | found_hook = (*specified_hook_iter).second; |
| 1964 | return found_hook; |
| 1965 | } |
| 1966 | |
| 1967 | bool |
| 1968 | Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) |
| 1969 | { |
| 1970 | StopHookCollection::iterator specified_hook_iter; |
| 1971 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1972 | if (specified_hook_iter == m_stop_hooks.end()) |
| 1973 | return false; |
| 1974 | |
| 1975 | (*specified_hook_iter).second->SetIsActive (active_state); |
| 1976 | return true; |
| 1977 | } |
| 1978 | |
| 1979 | void |
| 1980 | Target::SetAllStopHooksActiveState (bool active_state) |
| 1981 | { |
| 1982 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1983 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1984 | { |
| 1985 | (*pos).second->SetIsActive (active_state); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | void |
| 1990 | Target::RunStopHooks () |
| 1991 | { |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1992 | if (m_suppress_stop_hooks) |
| 1993 | return; |
| 1994 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1995 | if (!m_process_sp) |
| 1996 | return; |
Enrico Granata | 5a60f5e | 2012-08-03 22:24:48 +0000 | [diff] [blame] | 1997 | |
| 1998 | // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression |
| 1999 | // since in that case we do not want to run the stop-hooks |
| 2000 | if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression()) |
| 2001 | return; |
| 2002 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2003 | if (m_stop_hooks.empty()) |
| 2004 | return; |
| 2005 | |
| 2006 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 2007 | |
| 2008 | // If there aren't any active stop hooks, don't bother either: |
| 2009 | bool any_active_hooks = false; |
| 2010 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 2011 | { |
| 2012 | if ((*pos).second->IsActive()) |
| 2013 | { |
| 2014 | any_active_hooks = true; |
| 2015 | break; |
| 2016 | } |
| 2017 | } |
| 2018 | if (!any_active_hooks) |
| 2019 | return; |
| 2020 | |
| 2021 | CommandReturnObject result; |
| 2022 | |
| 2023 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 2024 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 2025 | |
| 2026 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 2027 | size_t num_threads = cur_threadlist.GetSize(); |
| 2028 | for (size_t i = 0; i < num_threads; i++) |
| 2029 | { |
| 2030 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); |
| 2031 | if (cur_thread_sp->ThreadStoppedForAReason()) |
| 2032 | { |
| 2033 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 2034 | exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 2035 | sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 2040 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 2041 | if (num_exe_ctx == 0) |
| 2042 | return; |
| 2043 | |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 2044 | result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream()); |
| 2045 | result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2046 | |
| 2047 | bool keep_going = true; |
| 2048 | bool hooks_ran = false; |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 2049 | bool print_hook_header; |
| 2050 | bool print_thread_header; |
| 2051 | |
| 2052 | if (num_exe_ctx == 1) |
| 2053 | print_thread_header = false; |
| 2054 | else |
| 2055 | print_thread_header = true; |
| 2056 | |
| 2057 | if (m_stop_hooks.size() == 1) |
| 2058 | print_hook_header = false; |
| 2059 | else |
| 2060 | print_hook_header = true; |
| 2061 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2062 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) |
| 2063 | { |
| 2064 | // result.Clear(); |
| 2065 | StopHookSP cur_hook_sp = (*pos).second; |
| 2066 | if (!cur_hook_sp->IsActive()) |
| 2067 | continue; |
| 2068 | |
| 2069 | bool any_thread_matched = false; |
| 2070 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) |
| 2071 | { |
| 2072 | if ((cur_hook_sp->GetSpecifier () == NULL |
| 2073 | || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) |
| 2074 | && (cur_hook_sp->GetThreadSpecifier() == NULL |
Jim Ingham | a266491 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 2075 | || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef()))) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2076 | { |
| 2077 | if (!hooks_ran) |
| 2078 | { |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2079 | hooks_ran = true; |
| 2080 | } |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 2081 | if (print_hook_header && !any_thread_matched) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2082 | { |
Johnny Chen | 4d96a74 | 2011-10-24 23:01:06 +0000 | [diff] [blame] | 2083 | const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ? |
| 2084 | cur_hook_sp->GetCommands().GetStringAtIndex(0) : |
| 2085 | NULL); |
| 2086 | if (cmd) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2087 | result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd); |
Johnny Chen | 4d96a74 | 2011-10-24 23:01:06 +0000 | [diff] [blame] | 2088 | else |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2089 | result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2090 | any_thread_matched = true; |
| 2091 | } |
| 2092 | |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 2093 | if (print_thread_header) |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2094 | result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2095 | |
| 2096 | bool stop_on_continue = true; |
| 2097 | bool stop_on_error = true; |
| 2098 | bool echo_commands = false; |
| 2099 | bool print_results = true; |
| 2100 | GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2101 | &exc_ctx_with_reasons[i], |
| 2102 | stop_on_continue, |
| 2103 | stop_on_error, |
| 2104 | echo_commands, |
Enrico Granata | 01bc2d4 | 2012-05-31 01:09:06 +0000 | [diff] [blame] | 2105 | print_results, |
| 2106 | eLazyBoolNo, |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2107 | result); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2108 | |
| 2109 | // If the command started the target going again, we should bag out of |
| 2110 | // running the stop hooks. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2111 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) || |
| 2112 | (result.GetStatus() == eReturnStatusSuccessContinuingResult)) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2113 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2114 | result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2115 | keep_going = false; |
| 2116 | } |
| 2117 | } |
| 2118 | } |
| 2119 | } |
Jason Molenda | 850ac6e | 2011-09-23 00:42:55 +0000 | [diff] [blame] | 2120 | |
Caroline Tice | 4a34808 | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 2121 | result.GetImmediateOutputStream()->Flush(); |
| 2122 | result.GetImmediateErrorStream()->Flush(); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 2125 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2126 | //-------------------------------------------------------------- |
| 2127 | // class Target::StopHook |
| 2128 | //-------------------------------------------------------------- |
| 2129 | |
| 2130 | |
| 2131 | Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : |
| 2132 | UserID (uid), |
| 2133 | m_target_sp (target_sp), |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2134 | m_commands (), |
| 2135 | m_specifier_sp (), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2136 | m_thread_spec_ap(NULL), |
| 2137 | m_active (true) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2138 | { |
| 2139 | } |
| 2140 | |
| 2141 | Target::StopHook::StopHook (const StopHook &rhs) : |
| 2142 | UserID (rhs.GetID()), |
| 2143 | m_target_sp (rhs.m_target_sp), |
| 2144 | m_commands (rhs.m_commands), |
| 2145 | m_specifier_sp (rhs.m_specifier_sp), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2146 | m_thread_spec_ap (NULL), |
| 2147 | m_active (rhs.m_active) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2148 | { |
| 2149 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 2150 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
| 2151 | } |
| 2152 | |
| 2153 | |
| 2154 | Target::StopHook::~StopHook () |
| 2155 | { |
| 2156 | } |
| 2157 | |
| 2158 | void |
| 2159 | Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier) |
| 2160 | { |
| 2161 | m_thread_spec_ap.reset (specifier); |
| 2162 | } |
| 2163 | |
| 2164 | |
| 2165 | void |
| 2166 | Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 2167 | { |
| 2168 | int indent_level = s->GetIndentLevel(); |
| 2169 | |
| 2170 | s->SetIndentLevel(indent_level + 2); |
| 2171 | |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2172 | s->Printf ("Hook: %" PRIu64 "\n", GetID()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 2173 | if (m_active) |
| 2174 | s->Indent ("State: enabled\n"); |
| 2175 | else |
| 2176 | s->Indent ("State: disabled\n"); |
| 2177 | |
| 2178 | if (m_specifier_sp) |
| 2179 | { |
| 2180 | s->Indent(); |
| 2181 | s->PutCString ("Specifier:\n"); |
| 2182 | s->SetIndentLevel (indent_level + 4); |
| 2183 | m_specifier_sp->GetDescription (s, level); |
| 2184 | s->SetIndentLevel (indent_level + 2); |
| 2185 | } |
| 2186 | |
| 2187 | if (m_thread_spec_ap.get() != NULL) |
| 2188 | { |
| 2189 | StreamString tmp; |
| 2190 | s->Indent("Thread:\n"); |
| 2191 | m_thread_spec_ap->GetDescription (&tmp, level); |
| 2192 | s->SetIndentLevel (indent_level + 4); |
| 2193 | s->Indent (tmp.GetData()); |
| 2194 | s->PutCString ("\n"); |
| 2195 | s->SetIndentLevel (indent_level + 2); |
| 2196 | } |
| 2197 | |
| 2198 | s->Indent ("Commands: \n"); |
| 2199 | s->SetIndentLevel (indent_level + 4); |
| 2200 | uint32_t num_commands = m_commands.GetSize(); |
| 2201 | for (uint32_t i = 0; i < num_commands; i++) |
| 2202 | { |
| 2203 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 2204 | s->PutCString ("\n"); |
| 2205 | } |
| 2206 | s->SetIndentLevel (indent_level); |
| 2207 | } |
| 2208 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2209 | //-------------------------------------------------------------- |
| 2210 | // class TargetProperties |
| 2211 | //-------------------------------------------------------------- |
| 2212 | |
| 2213 | OptionEnumValueElement |
| 2214 | lldb_private::g_dynamic_value_types[] = |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2215 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2216 | { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"}, |
| 2217 | { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."}, |
| 2218 | { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."}, |
| 2219 | { 0, NULL, NULL } |
| 2220 | }; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2221 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2222 | static OptionEnumValueElement |
| 2223 | g_inline_breakpoint_enums[] = |
| 2224 | { |
| 2225 | { eInlineBreakpointsNever, "never", "Never look for inline breakpoint locations (fastest). This setting should only be used if you know that no inlining occurs in your programs."}, |
| 2226 | { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."}, |
| 2227 | { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."}, |
| 2228 | { 0, NULL, NULL } |
| 2229 | }; |
| 2230 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2231 | static PropertyDefinition |
| 2232 | g_properties[] = |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2233 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2234 | { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." }, |
| 2235 | { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." }, |
| 2236 | { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." }, |
| 2237 | { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." }, |
| 2238 | { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." }, |
| 2239 | { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and " |
| 2240 | "where it exists on the current system. It consists of an array of duples, the first element of each duple is " |
| 2241 | "some part (starting at the root) of the path to the file when it was built, " |
| 2242 | "and the second is where the remainder of the original build hierarchy is rooted on the local system. " |
| 2243 | "Each element of the array is checked in order and the first one that results in a match wins." }, |
| 2244 | { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." }, |
| 2245 | { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." }, |
| 2246 | { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." }, |
| 2247 | { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." }, |
Greg Clayton | 0c8446c | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 2248 | { "arg0" , OptionValue::eTypeString , false, 0 , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." }, |
| 2249 | { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." }, |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2250 | { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." }, |
| 2251 | { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." }, |
| 2252 | { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." }, |
| 2253 | { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." }, |
| 2254 | { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." }, |
| 2255 | { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" }, |
| 2256 | { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" }, |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2257 | { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. " |
| 2258 | "Breakpoint locations can end up being inlined by the compiler, so that a compile unit 'a.c' might contain an inlined function from another source file. " |
| 2259 | "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. " |
| 2260 | "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. " |
| 2261 | "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the " |
| 2262 | "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings " |
| 2263 | "file and line breakpoints." }, |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2264 | { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL } |
| 2265 | }; |
| 2266 | enum |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2267 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2268 | ePropertyDefaultArch, |
| 2269 | ePropertyExprPrefix, |
| 2270 | ePropertyPreferDynamic, |
| 2271 | ePropertyEnableSynthetic, |
| 2272 | ePropertySkipPrologue, |
| 2273 | ePropertySourceMap, |
| 2274 | ePropertyExecutableSearchPaths, |
| 2275 | ePropertyMaxChildrenCount, |
| 2276 | ePropertyMaxSummaryLength, |
| 2277 | ePropertyBreakpointUseAvoidList, |
Greg Clayton | 0c8446c | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 2278 | ePropertyArg0, |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2279 | ePropertyRunArgs, |
| 2280 | ePropertyEnvVars, |
| 2281 | ePropertyInheritEnv, |
| 2282 | ePropertyInputPath, |
| 2283 | ePropertyOutputPath, |
| 2284 | ePropertyErrorPath, |
| 2285 | ePropertyDisableASLR, |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2286 | ePropertyDisableSTDIO, |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2287 | ePropertyInlineStrategy |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2288 | }; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2289 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2290 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2291 | class TargetOptionValueProperties : public OptionValueProperties |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2292 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2293 | public: |
| 2294 | TargetOptionValueProperties (const ConstString &name) : |
| 2295 | OptionValueProperties (name), |
| 2296 | m_target (NULL), |
| 2297 | m_got_host_env (false) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2298 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2299 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2300 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2301 | // This constructor is used when creating TargetOptionValueProperties when it |
| 2302 | // is part of a new lldb_private::Target instance. It will copy all current |
| 2303 | // global property values as needed |
| 2304 | TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) : |
| 2305 | OptionValueProperties(*target_properties_sp->GetValueProperties()), |
| 2306 | m_target (target), |
| 2307 | m_got_host_env (false) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2308 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | virtual const Property * |
| 2312 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 2313 | { |
| 2314 | // When gettings the value for a key from the target options, we will always |
| 2315 | // try and grab the setting from the current target if there is one. Else we just |
| 2316 | // use the one from this instance. |
| 2317 | if (idx == ePropertyEnvVars) |
| 2318 | GetHostEnvironmentIfNeeded (); |
| 2319 | |
| 2320 | if (exe_ctx) |
| 2321 | { |
| 2322 | Target *target = exe_ctx->GetTargetPtr(); |
| 2323 | if (target) |
| 2324 | { |
| 2325 | TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get()); |
| 2326 | if (this != target_properties) |
| 2327 | return target_properties->ProtectedGetPropertyAtIndex (idx); |
| 2328 | } |
| 2329 | } |
| 2330 | return ProtectedGetPropertyAtIndex (idx); |
| 2331 | } |
| 2332 | protected: |
| 2333 | |
| 2334 | void |
| 2335 | GetHostEnvironmentIfNeeded () const |
| 2336 | { |
| 2337 | if (!m_got_host_env) |
| 2338 | { |
| 2339 | if (m_target) |
| 2340 | { |
| 2341 | m_got_host_env = true; |
| 2342 | const uint32_t idx = ePropertyInheritEnv; |
| 2343 | if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0)) |
| 2344 | { |
| 2345 | PlatformSP platform_sp (m_target->GetPlatform()); |
| 2346 | if (platform_sp) |
| 2347 | { |
| 2348 | StringList env; |
| 2349 | if (platform_sp->GetEnvironment(env)) |
| 2350 | { |
| 2351 | OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars); |
| 2352 | if (env_dict) |
| 2353 | { |
| 2354 | const bool can_replace = false; |
| 2355 | const size_t envc = env.GetSize(); |
| 2356 | for (size_t idx=0; idx<envc; idx++) |
| 2357 | { |
| 2358 | const char *env_entry = env.GetStringAtIndex (idx); |
| 2359 | if (env_entry) |
| 2360 | { |
| 2361 | const char *equal_pos = ::strchr(env_entry, '='); |
| 2362 | ConstString key; |
| 2363 | // It is ok to have environment variables with no values |
| 2364 | const char *value = NULL; |
| 2365 | if (equal_pos) |
| 2366 | { |
| 2367 | key.SetCStringWithLength(env_entry, equal_pos - env_entry); |
| 2368 | if (equal_pos[1]) |
| 2369 | value = equal_pos + 1; |
| 2370 | } |
| 2371 | else |
| 2372 | { |
| 2373 | key.SetCString(env_entry); |
| 2374 | } |
| 2375 | // Don't allow existing keys to be replaced with ones we get from the platform environment |
| 2376 | env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace); |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | Target *m_target; |
| 2387 | mutable bool m_got_host_env; |
| 2388 | }; |
| 2389 | |
| 2390 | TargetProperties::TargetProperties (Target *target) : |
| 2391 | Properties () |
| 2392 | { |
| 2393 | if (target) |
| 2394 | { |
| 2395 | m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties())); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2396 | } |
| 2397 | else |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2398 | { |
| 2399 | m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target"))); |
| 2400 | m_collection_sp->Initialize(g_properties); |
| 2401 | m_collection_sp->AppendProperty(ConstString("process"), |
| 2402 | ConstString("Settings specify to processes."), |
| 2403 | true, |
| 2404 | Process::GetGlobalProperties()->GetValueProperties()); |
| 2405 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2408 | TargetProperties::~TargetProperties () |
| 2409 | { |
| 2410 | } |
| 2411 | ArchSpec |
| 2412 | TargetProperties::GetDefaultArchitecture () const |
| 2413 | { |
| 2414 | OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch); |
| 2415 | if (value) |
| 2416 | return value->GetCurrentValue(); |
| 2417 | return ArchSpec(); |
| 2418 | } |
| 2419 | |
| 2420 | void |
| 2421 | TargetProperties::SetDefaultArchitecture (const ArchSpec& arch) |
| 2422 | { |
| 2423 | OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch); |
| 2424 | if (value) |
| 2425 | return value->SetCurrentValue(arch, true); |
| 2426 | } |
| 2427 | |
| 2428 | lldb::DynamicValueType |
| 2429 | TargetProperties::GetPreferDynamicValue() const |
| 2430 | { |
| 2431 | const uint32_t idx = ePropertyPreferDynamic; |
| 2432 | return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); |
| 2433 | } |
| 2434 | |
| 2435 | bool |
| 2436 | TargetProperties::GetDisableASLR () const |
| 2437 | { |
| 2438 | const uint32_t idx = ePropertyDisableASLR; |
| 2439 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 2440 | } |
| 2441 | |
| 2442 | void |
| 2443 | TargetProperties::SetDisableASLR (bool b) |
| 2444 | { |
| 2445 | const uint32_t idx = ePropertyDisableASLR; |
| 2446 | m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); |
| 2447 | } |
| 2448 | |
| 2449 | bool |
| 2450 | TargetProperties::GetDisableSTDIO () const |
| 2451 | { |
| 2452 | const uint32_t idx = ePropertyDisableSTDIO; |
| 2453 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 2454 | } |
| 2455 | |
| 2456 | void |
| 2457 | TargetProperties::SetDisableSTDIO (bool b) |
| 2458 | { |
| 2459 | const uint32_t idx = ePropertyDisableSTDIO; |
| 2460 | m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); |
| 2461 | } |
| 2462 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 2463 | InlineStrategy |
| 2464 | TargetProperties::GetInlineStrategy () const |
| 2465 | { |
| 2466 | const uint32_t idx = ePropertyInlineStrategy; |
| 2467 | return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); |
| 2468 | } |
| 2469 | |
Greg Clayton | 0c8446c | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 2470 | const char * |
| 2471 | TargetProperties::GetArg0 () const |
| 2472 | { |
| 2473 | const uint32_t idx = ePropertyArg0; |
| 2474 | return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL); |
| 2475 | } |
| 2476 | |
| 2477 | void |
| 2478 | TargetProperties::SetArg0 (const char *arg) |
| 2479 | { |
| 2480 | const uint32_t idx = ePropertyArg0; |
| 2481 | m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg); |
| 2482 | } |
| 2483 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2484 | bool |
| 2485 | TargetProperties::GetRunArguments (Args &args) const |
| 2486 | { |
| 2487 | const uint32_t idx = ePropertyRunArgs; |
| 2488 | return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args); |
| 2489 | } |
| 2490 | |
| 2491 | void |
| 2492 | TargetProperties::SetRunArguments (const Args &args) |
| 2493 | { |
| 2494 | const uint32_t idx = ePropertyRunArgs; |
| 2495 | m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args); |
| 2496 | } |
| 2497 | |
| 2498 | size_t |
| 2499 | TargetProperties::GetEnvironmentAsArgs (Args &env) const |
| 2500 | { |
| 2501 | const uint32_t idx = ePropertyEnvVars; |
| 2502 | return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env); |
| 2503 | } |
| 2504 | |
| 2505 | bool |
| 2506 | TargetProperties::GetSkipPrologue() const |
| 2507 | { |
| 2508 | const uint32_t idx = ePropertySkipPrologue; |
| 2509 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 2510 | } |
| 2511 | |
| 2512 | PathMappingList & |
| 2513 | TargetProperties::GetSourcePathMap () const |
| 2514 | { |
| 2515 | const uint32_t idx = ePropertySourceMap; |
| 2516 | OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx); |
| 2517 | assert(option_value); |
| 2518 | return option_value->GetCurrentValue(); |
| 2519 | } |
| 2520 | |
| 2521 | FileSpecList & |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 2522 | TargetProperties::GetExecutableSearchPaths () |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2523 | { |
| 2524 | const uint32_t idx = ePropertyExecutableSearchPaths; |
| 2525 | OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx); |
| 2526 | assert(option_value); |
| 2527 | return option_value->GetCurrentValue(); |
| 2528 | } |
| 2529 | |
| 2530 | bool |
| 2531 | TargetProperties::GetEnableSyntheticValue () const |
| 2532 | { |
| 2533 | const uint32_t idx = ePropertyEnableSynthetic; |
| 2534 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 2535 | } |
| 2536 | |
| 2537 | uint32_t |
| 2538 | TargetProperties::GetMaximumNumberOfChildrenToDisplay() const |
| 2539 | { |
| 2540 | const uint32_t idx = ePropertyMaxChildrenCount; |
| 2541 | return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value); |
| 2542 | } |
| 2543 | |
| 2544 | uint32_t |
| 2545 | TargetProperties::GetMaximumSizeOfStringSummary() const |
| 2546 | { |
| 2547 | const uint32_t idx = ePropertyMaxSummaryLength; |
| 2548 | return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value); |
| 2549 | } |
| 2550 | |
| 2551 | FileSpec |
| 2552 | TargetProperties::GetStandardInputPath () const |
| 2553 | { |
| 2554 | const uint32_t idx = ePropertyInputPath; |
| 2555 | return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); |
| 2556 | } |
| 2557 | |
| 2558 | void |
| 2559 | TargetProperties::SetStandardInputPath (const char *p) |
| 2560 | { |
| 2561 | const uint32_t idx = ePropertyInputPath; |
| 2562 | m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); |
| 2563 | } |
| 2564 | |
| 2565 | FileSpec |
| 2566 | TargetProperties::GetStandardOutputPath () const |
| 2567 | { |
| 2568 | const uint32_t idx = ePropertyOutputPath; |
| 2569 | return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); |
| 2570 | } |
| 2571 | |
| 2572 | void |
| 2573 | TargetProperties::SetStandardOutputPath (const char *p) |
| 2574 | { |
| 2575 | const uint32_t idx = ePropertyOutputPath; |
| 2576 | m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); |
| 2577 | } |
| 2578 | |
| 2579 | FileSpec |
| 2580 | TargetProperties::GetStandardErrorPath () const |
| 2581 | { |
| 2582 | const uint32_t idx = ePropertyErrorPath; |
| 2583 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx); |
| 2584 | } |
| 2585 | |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 2586 | const char * |
| 2587 | TargetProperties::GetExpressionPrefixContentsAsCString () |
| 2588 | { |
| 2589 | const uint32_t idx = ePropertyExprPrefix; |
| 2590 | OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx); |
| 2591 | if (file) |
Jim Ingham | 7021cda | 2012-08-22 21:21:16 +0000 | [diff] [blame] | 2592 | { |
Greg Clayton | fc04d24 | 2012-08-30 18:15:10 +0000 | [diff] [blame] | 2593 | const bool null_terminate = true; |
| 2594 | DataBufferSP data_sp(file->GetFileContents(null_terminate)); |
Jim Ingham | 7021cda | 2012-08-22 21:21:16 +0000 | [diff] [blame] | 2595 | if (data_sp) |
| 2596 | return (const char *) data_sp->GetBytes(); |
| 2597 | } |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 2598 | return NULL; |
| 2599 | } |
| 2600 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2601 | void |
| 2602 | TargetProperties::SetStandardErrorPath (const char *p) |
| 2603 | { |
| 2604 | const uint32_t idx = ePropertyErrorPath; |
| 2605 | m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); |
| 2606 | } |
| 2607 | |
| 2608 | bool |
| 2609 | TargetProperties::GetBreakpointsConsultPlatformAvoidList () |
| 2610 | { |
| 2611 | const uint32_t idx = ePropertyBreakpointUseAvoidList; |
| 2612 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 2613 | } |
| 2614 | |
| 2615 | const TargetPropertiesSP & |
| 2616 | Target::GetGlobalProperties() |
| 2617 | { |
| 2618 | static TargetPropertiesSP g_settings_sp; |
| 2619 | if (!g_settings_sp) |
| 2620 | { |
| 2621 | g_settings_sp.reset (new TargetProperties (NULL)); |
| 2622 | } |
| 2623 | return g_settings_sp; |
| 2624 | } |
| 2625 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 2626 | const ConstString & |
| 2627 | Target::TargetEventData::GetFlavorString () |
| 2628 | { |
| 2629 | static ConstString g_flavor ("Target::TargetEventData"); |
| 2630 | return g_flavor; |
| 2631 | } |
| 2632 | |
| 2633 | const ConstString & |
| 2634 | Target::TargetEventData::GetFlavor () const |
| 2635 | { |
| 2636 | return TargetEventData::GetFlavorString (); |
| 2637 | } |
| 2638 | |
| 2639 | Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) : |
| 2640 | EventData(), |
| 2641 | m_target_sp (new_target_sp) |
| 2642 | { |
| 2643 | } |
| 2644 | |
| 2645 | Target::TargetEventData::~TargetEventData() |
| 2646 | { |
| 2647 | |
| 2648 | } |
| 2649 | |
| 2650 | void |
| 2651 | Target::TargetEventData::Dump (Stream *s) const |
| 2652 | { |
| 2653 | |
| 2654 | } |
| 2655 | |
| 2656 | const TargetSP |
| 2657 | Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp) |
| 2658 | { |
| 2659 | TargetSP target_sp; |
| 2660 | |
| 2661 | const TargetEventData *data = GetEventDataFromEvent (event_sp.get()); |
| 2662 | if (data) |
| 2663 | target_sp = data->m_target_sp; |
| 2664 | |
| 2665 | return target_sp; |
| 2666 | } |
| 2667 | |
| 2668 | const Target::TargetEventData * |
| 2669 | Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 2670 | { |
| 2671 | if (event_ptr) |
| 2672 | { |
| 2673 | const EventData *event_data = event_ptr->GetData(); |
| 2674 | if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString()) |
| 2675 | return static_cast <const TargetEventData *> (event_ptr->GetData()); |
| 2676 | } |
| 2677 | return NULL; |
| 2678 | } |
| 2679 | |