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