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