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