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