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