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