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