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