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