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