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