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