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