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