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