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 | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/WatchpointLocation.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" |
Caroline Tice | 4a34808 | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamAsynchronousIO.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 27 | #include "lldb/Core/Timer.h" |
| 28 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 29 | #include "lldb/Expression/ClangUserExpression.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Host/Host.h" |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 31 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 32 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/lldb-private-log.h" |
| 34 | #include "lldb/Symbol/ObjectFile.h" |
| 35 | #include "lldb/Target/Process.h" |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 36 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 37 | #include "lldb/Target/Thread.h" |
| 38 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
| 40 | using namespace lldb; |
| 41 | using namespace lldb_private; |
| 42 | |
| 43 | //---------------------------------------------------------------------- |
| 44 | // Target constructor |
| 45 | //---------------------------------------------------------------------- |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 46 | Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) : |
| 47 | Broadcaster ("lldb.target"), |
| 48 | ExecutionContextScope (), |
Greg Clayton | c0c1b0c | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 49 | TargetInstanceSettings (*GetSettingsController()), |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 50 | m_debugger (debugger), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 51 | m_platform_sp (platform_sp), |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 52 | m_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 53 | m_arch (target_arch), |
| 54 | m_images (), |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 55 | m_section_load_list (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | m_breakpoint_list (false), |
| 57 | m_internal_breakpoint_list (true), |
Johnny Chen | 9a3c2a5 | 2011-09-06 20:05:25 +0000 | [diff] [blame] | 58 | m_watchpoint_location_list (), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 59 | m_process_sp (), |
| 60 | m_search_filter_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | m_image_search_paths (ImageSearchPathsChanged, this), |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 62 | m_scratch_ast_context_ap (NULL), |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 63 | m_persistent_variables (), |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 64 | m_source_manager(*this), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 65 | m_stop_hooks (), |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 66 | m_stop_hook_next_id (0), |
| 67 | m_suppress_stop_hooks (false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 69 | SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 70 | SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); |
| 71 | SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); |
| 72 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 73 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | if (log) |
| 75 | log->Printf ("%p Target::Target()", this); |
| 76 | } |
| 77 | |
| 78 | //---------------------------------------------------------------------- |
| 79 | // Destructor |
| 80 | //---------------------------------------------------------------------- |
| 81 | Target::~Target() |
| 82 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 83 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | if (log) |
| 85 | log->Printf ("%p Target::~Target()", this); |
| 86 | DeleteCurrentProcess (); |
| 87 | } |
| 88 | |
| 89 | void |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 90 | Target::Dump (Stream *s, lldb::DescriptionLevel description_level) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | { |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 92 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 93 | if (description_level != lldb::eDescriptionLevelBrief) |
| 94 | { |
| 95 | s->Indent(); |
| 96 | s->PutCString("Target\n"); |
| 97 | s->IndentMore(); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 98 | m_images.Dump(s); |
| 99 | m_breakpoint_list.Dump(s); |
| 100 | m_internal_breakpoint_list.Dump(s); |
| 101 | s->IndentLess(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 105 | Module *exe_module = GetExecutableModulePointer(); |
| 106 | if (exe_module) |
| 107 | s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString()); |
Jim Ingham | 53fe9cc | 2011-05-12 01:12:28 +0000 | [diff] [blame] | 108 | else |
| 109 | s->PutCString ("No executable module."); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 110 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void |
| 114 | Target::DeleteCurrentProcess () |
| 115 | { |
| 116 | if (m_process_sp.get()) |
| 117 | { |
Greg Clayton | 49480b1 | 2010-09-14 23:52:43 +0000 | [diff] [blame] | 118 | m_section_load_list.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | if (m_process_sp->IsAlive()) |
| 120 | m_process_sp->Destroy(); |
Jim Ingham | 88fa7bd | 2011-02-16 17:54:55 +0000 | [diff] [blame] | 121 | |
| 122 | m_process_sp->Finalize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | |
| 124 | // Do any cleanup of the target we need to do between process instances. |
| 125 | // NB It is better to do this before destroying the process in case the |
| 126 | // clean up needs some help from the process. |
| 127 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 128 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 129 | // Disable watchpoint locations just on the debugger side. |
| 130 | DisableAllWatchpointLocations(false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | m_process_sp.reset(); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | const lldb::ProcessSP & |
| 136 | Target::CreateProcess (Listener &listener, const char *plugin_name) |
| 137 | { |
| 138 | DeleteCurrentProcess (); |
| 139 | m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener)); |
| 140 | return m_process_sp; |
| 141 | } |
| 142 | |
| 143 | const lldb::ProcessSP & |
| 144 | Target::GetProcessSP () const |
| 145 | { |
| 146 | return m_process_sp; |
| 147 | } |
| 148 | |
| 149 | lldb::TargetSP |
| 150 | Target::GetSP() |
| 151 | { |
Greg Clayton | 987c7eb | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 152 | // This object contains an instrusive ref count base class so we can |
| 153 | // easily make a shared pointer to this object |
| 154 | return TargetSP(this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 157 | void |
| 158 | Target::Destroy() |
| 159 | { |
| 160 | Mutex::Locker locker (m_mutex); |
| 161 | DeleteCurrentProcess (); |
| 162 | m_platform_sp.reset(); |
| 163 | m_arch.Clear(); |
| 164 | m_images.Clear(); |
| 165 | m_section_load_list.Clear(); |
| 166 | const bool notify = false; |
| 167 | m_breakpoint_list.RemoveAll(notify); |
| 168 | m_internal_breakpoint_list.RemoveAll(notify); |
| 169 | m_last_created_breakpoint.reset(); |
Johnny Chen | 5eb54bb | 2011-09-27 20:29:45 +0000 | [diff] [blame^] | 170 | m_last_created_watchpoint_location.reset(); |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 171 | m_search_filter_sp.reset(); |
| 172 | m_image_search_paths.Clear(notify); |
| 173 | m_scratch_ast_context_ap.reset(); |
| 174 | m_persistent_variables.Clear(); |
| 175 | m_stop_hooks.clear(); |
| 176 | m_stop_hook_next_id = 0; |
| 177 | m_suppress_stop_hooks = false; |
| 178 | } |
| 179 | |
| 180 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | BreakpointList & |
| 182 | Target::GetBreakpointList(bool internal) |
| 183 | { |
| 184 | if (internal) |
| 185 | return m_internal_breakpoint_list; |
| 186 | else |
| 187 | return m_breakpoint_list; |
| 188 | } |
| 189 | |
| 190 | const BreakpointList & |
| 191 | Target::GetBreakpointList(bool internal) const |
| 192 | { |
| 193 | if (internal) |
| 194 | return m_internal_breakpoint_list; |
| 195 | else |
| 196 | return m_breakpoint_list; |
| 197 | } |
| 198 | |
| 199 | BreakpointSP |
| 200 | Target::GetBreakpointByID (break_id_t break_id) |
| 201 | { |
| 202 | BreakpointSP bp_sp; |
| 203 | |
| 204 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 205 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 206 | else |
| 207 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 208 | |
| 209 | return bp_sp; |
| 210 | } |
| 211 | |
| 212 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 213 | Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules, |
| 214 | const FileSpecList *source_file_spec_list, |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 215 | RegularExpression &source_regex, |
| 216 | bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 217 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 218 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list)); |
| 219 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex)); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 220 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | BreakpointSP |
| 225 | Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal) |
| 226 | { |
| 227 | SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines)); |
| 229 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | BreakpointSP |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 234 | Target::CreateBreakpoint (lldb::addr_t addr, bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | Address so_addr; |
| 237 | // Attempt to resolve our load address if possible, though it is ok if |
| 238 | // it doesn't resolve to section/offset. |
| 239 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 240 | // Try and resolve as a load address if possible |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 241 | m_section_load_list.ResolveLoadAddress(addr, so_addr); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 242 | if (!so_addr.IsValid()) |
| 243 | { |
| 244 | // The address didn't resolve, so just set this as an absolute address |
| 245 | so_addr.SetOffset (addr); |
| 246 | } |
| 247 | BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | return bp_sp; |
| 249 | } |
| 250 | |
| 251 | BreakpointSP |
| 252 | Target::CreateBreakpoint (Address &addr, bool internal) |
| 253 | { |
| 254 | TargetSP target_sp = this->GetSP(); |
| 255 | SearchFilterSP filter_sp(new SearchFilter (target_sp)); |
| 256 | BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); |
| 257 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 258 | } |
| 259 | |
| 260 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 261 | Target::CreateBreakpoint (const FileSpecList *containingModules, |
| 262 | const FileSpecList *containingSourceFiles, |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 263 | const char *func_name, |
| 264 | uint32_t func_name_type_mask, |
| 265 | bool internal, |
| 266 | LazyBool skip_prologue) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 268 | BreakpointSP bp_sp; |
| 269 | if (func_name) |
| 270 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 271 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 272 | |
| 273 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, |
| 274 | func_name, |
| 275 | func_name_type_mask, |
| 276 | Breakpoint::Exact, |
| 277 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 278 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 279 | } |
| 280 | return bp_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
| 284 | SearchFilterSP |
| 285 | Target::GetSearchFilterForModule (const FileSpec *containingModule) |
| 286 | { |
| 287 | SearchFilterSP filter_sp; |
| 288 | lldb::TargetSP target_sp = this->GetSP(); |
| 289 | if (containingModule != NULL) |
| 290 | { |
| 291 | // TODO: We should look into sharing module based search filters |
| 292 | // across many breakpoints like we do for the simple target based one |
| 293 | filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule)); |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | if (m_search_filter_sp.get() == NULL) |
| 298 | m_search_filter_sp.reset (new SearchFilter (target_sp)); |
| 299 | filter_sp = m_search_filter_sp; |
| 300 | } |
| 301 | return filter_sp; |
| 302 | } |
| 303 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 304 | SearchFilterSP |
| 305 | Target::GetSearchFilterForModuleList (const FileSpecList *containingModules) |
| 306 | { |
| 307 | SearchFilterSP filter_sp; |
| 308 | lldb::TargetSP target_sp = this->GetSP(); |
| 309 | if (containingModules && containingModules->GetSize() != 0) |
| 310 | { |
| 311 | // TODO: We should look into sharing module based search filters |
| 312 | // across many breakpoints like we do for the simple target based one |
| 313 | filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules)); |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | if (m_search_filter_sp.get() == NULL) |
| 318 | m_search_filter_sp.reset (new SearchFilter (target_sp)); |
| 319 | filter_sp = m_search_filter_sp; |
| 320 | } |
| 321 | return filter_sp; |
| 322 | } |
| 323 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 324 | SearchFilterSP |
| 325 | Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles) |
| 326 | { |
| 327 | if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0) |
| 328 | return GetSearchFilterForModuleList(containingModules); |
| 329 | |
| 330 | SearchFilterSP filter_sp; |
| 331 | lldb::TargetSP target_sp = this->GetSP(); |
| 332 | if (containingModules == NULL) |
| 333 | { |
| 334 | // We could make a special "CU List only SearchFilter". Better yet was if these could be composable, |
| 335 | // but that will take a little reworking. |
| 336 | |
| 337 | filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, FileSpecList(), *containingSourceFiles)); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, *containingModules, *containingSourceFiles)); |
| 342 | } |
| 343 | return filter_sp; |
| 344 | } |
| 345 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | BreakpointSP |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 347 | Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules, |
| 348 | const FileSpecList *containingSourceFiles, |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 349 | RegularExpression &func_regex, |
| 350 | bool internal, |
| 351 | LazyBool skip_prologue) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 353 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 354 | BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, |
| 355 | func_regex, |
| 356 | skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 357 | |
| 358 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 359 | } |
| 360 | |
| 361 | BreakpointSP |
| 362 | Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal) |
| 363 | { |
| 364 | BreakpointSP bp_sp; |
| 365 | if (filter_sp && resolver_sp) |
| 366 | { |
| 367 | bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp)); |
| 368 | resolver_sp->SetBreakpoint (bp_sp.get()); |
| 369 | |
| 370 | if (internal) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 371 | m_internal_breakpoint_list.Add (bp_sp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | else |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 373 | m_breakpoint_list.Add (bp_sp, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 375 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | if (log) |
| 377 | { |
| 378 | StreamString s; |
| 379 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
| 380 | log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); |
| 381 | } |
| 382 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | bp_sp->ResolveBreakpoint(); |
| 384 | } |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 385 | |
| 386 | if (!internal && bp_sp) |
| 387 | { |
| 388 | m_last_created_breakpoint = bp_sp; |
| 389 | } |
| 390 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | return bp_sp; |
| 392 | } |
| 393 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 394 | bool |
| 395 | Target::ProcessIsValid() |
| 396 | { |
| 397 | return (m_process_sp && m_process_sp->IsAlive()); |
| 398 | } |
| 399 | |
Johnny Chen | 87ff53b | 2011-09-14 00:26:03 +0000 | [diff] [blame] | 400 | // See also WatchpointLocation::SetWatchpointType(uint32_t type) and |
| 401 | // the OptionGroupWatchpoint::WatchType enum type. |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 402 | WatchpointLocationSP |
| 403 | Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) |
| 404 | { |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 405 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 406 | if (log) |
| 407 | log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n", |
| 408 | __FUNCTION__, addr, size, type); |
| 409 | |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 410 | WatchpointLocationSP wp_loc_sp; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 411 | if (!ProcessIsValid()) |
Johnny Chen | 61286a5 | 2011-09-13 18:30:59 +0000 | [diff] [blame] | 412 | return wp_loc_sp; |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 413 | if (addr == LLDB_INVALID_ADDRESS || size == 0) |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 414 | return wp_loc_sp; |
Johnny Chen | 9bf1199 | 2011-09-13 01:15:36 +0000 | [diff] [blame] | 415 | |
Johnny Chen | 87ff53b | 2011-09-14 00:26:03 +0000 | [diff] [blame] | 416 | // Currently we only support one watchpoint location per address, with total |
| 417 | // number of watchpoint locations limited by the hardware which the inferior |
| 418 | // is running on. |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 419 | WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr); |
| 420 | if (matched_sp) |
| 421 | { |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 422 | size_t old_size = matched_sp->GetByteSize(); |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 423 | uint32_t old_type = |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 424 | (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | |
| 425 | (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 426 | // Return the existing watchpoint location if both size and type match. |
| 427 | if (size == old_size && type == old_type) { |
| 428 | wp_loc_sp = matched_sp; |
| 429 | wp_loc_sp->SetEnabled(false); |
| 430 | } else { |
| 431 | // Nil the matched watchpoint location; we will be creating a new one. |
| 432 | m_process_sp->DisableWatchpoint(matched_sp.get()); |
| 433 | m_watchpoint_location_list.Remove(matched_sp->GetID()); |
| 434 | } |
Johnny Chen | 69b6ec8 | 2011-09-13 23:29:31 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 437 | if (!wp_loc_sp) { |
| 438 | WatchpointLocation *new_loc = new WatchpointLocation(addr, size); |
| 439 | if (!new_loc) { |
| 440 | printf("WatchpointLocation ctor failed, out of memory?\n"); |
| 441 | return wp_loc_sp; |
| 442 | } |
| 443 | new_loc->SetWatchpointType(type); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 444 | new_loc->SetTarget(this); |
Johnny Chen | 22a56cc | 2011-09-14 22:20:15 +0000 | [diff] [blame] | 445 | wp_loc_sp.reset(new_loc); |
| 446 | m_watchpoint_location_list.Add(wp_loc_sp); |
| 447 | } |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 448 | |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 449 | Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); |
Johnny Chen | 5b2fc57 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 450 | if (log) |
| 451 | log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", |
| 452 | __FUNCTION__, |
| 453 | rc.Success() ? "succeeded" : "failed", |
| 454 | wp_loc_sp->GetID()); |
| 455 | |
Johnny Chen | 5eb54bb | 2011-09-27 20:29:45 +0000 | [diff] [blame^] | 456 | if (rc.Fail()) |
| 457 | wp_loc_sp.reset(); |
| 458 | else |
| 459 | m_last_created_watchpoint_location = wp_loc_sp; |
Johnny Chen | 9bf1199 | 2011-09-13 01:15:36 +0000 | [diff] [blame] | 460 | return wp_loc_sp; |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | void |
| 464 | Target::RemoveAllBreakpoints (bool internal_also) |
| 465 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 466 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 467 | if (log) |
| 468 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 469 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 470 | m_breakpoint_list.RemoveAll (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | if (internal_also) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 472 | m_internal_breakpoint_list.RemoveAll (false); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 473 | |
| 474 | m_last_created_breakpoint.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void |
| 478 | Target::DisableAllBreakpoints (bool internal_also) |
| 479 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 480 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | if (log) |
| 482 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 483 | |
| 484 | m_breakpoint_list.SetEnabledAll (false); |
| 485 | if (internal_also) |
| 486 | m_internal_breakpoint_list.SetEnabledAll (false); |
| 487 | } |
| 488 | |
| 489 | void |
| 490 | Target::EnableAllBreakpoints (bool internal_also) |
| 491 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 492 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | if (log) |
| 494 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 495 | |
| 496 | m_breakpoint_list.SetEnabledAll (true); |
| 497 | if (internal_also) |
| 498 | m_internal_breakpoint_list.SetEnabledAll (true); |
| 499 | } |
| 500 | |
| 501 | bool |
| 502 | Target::RemoveBreakpointByID (break_id_t break_id) |
| 503 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 504 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | if (log) |
| 506 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 507 | |
| 508 | if (DisableBreakpointByID (break_id)) |
| 509 | { |
| 510 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 511 | m_internal_breakpoint_list.Remove(break_id, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | else |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 513 | { |
Greg Clayton | 22c9e0d | 2011-01-24 23:35:47 +0000 | [diff] [blame] | 514 | if (m_last_created_breakpoint) |
| 515 | { |
| 516 | if (m_last_created_breakpoint->GetID() == break_id) |
| 517 | m_last_created_breakpoint.reset(); |
| 518 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 519 | m_breakpoint_list.Remove(break_id, true); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 520 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | return true; |
| 522 | } |
| 523 | return false; |
| 524 | } |
| 525 | |
| 526 | bool |
| 527 | Target::DisableBreakpointByID (break_id_t break_id) |
| 528 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 529 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 530 | if (log) |
| 531 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 532 | |
| 533 | BreakpointSP bp_sp; |
| 534 | |
| 535 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 536 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 537 | else |
| 538 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 539 | if (bp_sp) |
| 540 | { |
| 541 | bp_sp->SetEnabled (false); |
| 542 | return true; |
| 543 | } |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | bool |
| 548 | Target::EnableBreakpointByID (break_id_t break_id) |
| 549 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 550 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 551 | if (log) |
| 552 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", |
| 553 | __FUNCTION__, |
| 554 | break_id, |
| 555 | LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 556 | |
| 557 | BreakpointSP bp_sp; |
| 558 | |
| 559 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 560 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 561 | else |
| 562 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 563 | |
| 564 | if (bp_sp) |
| 565 | { |
| 566 | bp_sp->SetEnabled (true); |
| 567 | return true; |
| 568 | } |
| 569 | return false; |
| 570 | } |
| 571 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 572 | // The flag 'end_to_end', default to true, signifies that the operation is |
| 573 | // performed end to end, for both the debugger and the debuggee. |
| 574 | |
| 575 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list |
| 576 | // for end to end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 577 | bool |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 578 | Target::RemoveAllWatchpointLocations (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 579 | { |
| 580 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 581 | if (log) |
| 582 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 583 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 584 | if (!end_to_end) { |
| 585 | m_watchpoint_location_list.RemoveAll(); |
| 586 | return true; |
| 587 | } |
| 588 | |
| 589 | // Otherwise, it's an end to end operation. |
| 590 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 591 | if (!ProcessIsValid()) |
| 592 | return false; |
| 593 | |
| 594 | size_t num_watchpoints = m_watchpoint_location_list.GetSize(); |
| 595 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 596 | { |
| 597 | WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); |
| 598 | if (!wp_loc_sp) |
| 599 | return false; |
| 600 | |
| 601 | Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); |
| 602 | if (rc.Fail()) |
| 603 | return false; |
| 604 | } |
| 605 | m_watchpoint_location_list.RemoveAll (); |
| 606 | return true; // Success! |
| 607 | } |
| 608 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 609 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list |
| 610 | // for end to end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 611 | bool |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 612 | Target::DisableAllWatchpointLocations (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 613 | { |
| 614 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 615 | if (log) |
| 616 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 617 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 618 | if (!end_to_end) { |
| 619 | m_watchpoint_location_list.SetEnabledAll(false); |
| 620 | return true; |
| 621 | } |
| 622 | |
| 623 | // Otherwise, it's an end to end operation. |
| 624 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 625 | if (!ProcessIsValid()) |
| 626 | return false; |
| 627 | |
| 628 | size_t num_watchpoints = m_watchpoint_location_list.GetSize(); |
| 629 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 630 | { |
| 631 | WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); |
| 632 | if (!wp_loc_sp) |
| 633 | return false; |
| 634 | |
| 635 | Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); |
| 636 | if (rc.Fail()) |
| 637 | return false; |
| 638 | } |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 639 | return true; // Success! |
| 640 | } |
| 641 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 642 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list |
| 643 | // for end to end operations. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 644 | bool |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 645 | Target::EnableAllWatchpointLocations (bool end_to_end) |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 646 | { |
| 647 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 648 | if (log) |
| 649 | log->Printf ("Target::%s\n", __FUNCTION__); |
| 650 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 651 | if (!end_to_end) { |
| 652 | m_watchpoint_location_list.SetEnabledAll(true); |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | // Otherwise, it's an end to end operation. |
| 657 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 658 | if (!ProcessIsValid()) |
| 659 | return false; |
| 660 | |
| 661 | size_t num_watchpoints = m_watchpoint_location_list.GetSize(); |
| 662 | for (size_t i = 0; i < num_watchpoints; ++i) |
| 663 | { |
| 664 | WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); |
| 665 | if (!wp_loc_sp) |
| 666 | return false; |
| 667 | |
| 668 | Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); |
| 669 | if (rc.Fail()) |
| 670 | return false; |
| 671 | } |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 672 | return true; // Success! |
| 673 | } |
| 674 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 675 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 676 | bool |
| 677 | Target::DisableWatchpointLocationByID (lldb::watch_id_t watch_id) |
| 678 | { |
| 679 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 680 | if (log) |
| 681 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 682 | |
| 683 | if (!ProcessIsValid()) |
| 684 | return false; |
| 685 | |
| 686 | WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id); |
| 687 | if (wp_loc_sp) |
| 688 | { |
| 689 | Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 690 | if (rc.Success()) |
| 691 | return true; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 692 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 693 | // Else, fallthrough. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 694 | } |
| 695 | return false; |
| 696 | } |
| 697 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 698 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 699 | bool |
| 700 | Target::EnableWatchpointLocationByID (lldb::watch_id_t watch_id) |
| 701 | { |
| 702 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 703 | if (log) |
| 704 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 705 | |
| 706 | if (!ProcessIsValid()) |
| 707 | return false; |
| 708 | |
| 709 | WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id); |
| 710 | if (wp_loc_sp) |
| 711 | { |
| 712 | Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 713 | if (rc.Success()) |
| 714 | return true; |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 715 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 716 | // Else, fallthrough. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 717 | } |
| 718 | return false; |
| 719 | } |
| 720 | |
Johnny Chen | c86582f | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 721 | // Assumption: Caller holds the list mutex lock for m_watchpoint_location_list. |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 722 | bool |
| 723 | Target::RemoveWatchpointLocationByID (lldb::watch_id_t watch_id) |
| 724 | { |
| 725 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); |
| 726 | if (log) |
| 727 | log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
| 728 | |
| 729 | if (DisableWatchpointLocationByID (watch_id)) |
| 730 | { |
| 731 | m_watchpoint_location_list.Remove(watch_id); |
| 732 | return true; |
| 733 | } |
| 734 | return false; |
| 735 | } |
| 736 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | ModuleSP |
| 738 | Target::GetExecutableModule () |
| 739 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 740 | return m_images.GetModuleAtIndex(0); |
| 741 | } |
| 742 | |
| 743 | Module* |
| 744 | Target::GetExecutableModulePointer () |
| 745 | { |
| 746 | return m_images.GetModulePointerAtIndex(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void |
| 750 | Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) |
| 751 | { |
| 752 | m_images.Clear(); |
| 753 | m_scratch_ast_context_ap.reset(); |
| 754 | |
| 755 | if (executable_sp.get()) |
| 756 | { |
| 757 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 758 | "Target::SetExecutableModule (executable = '%s/%s')", |
| 759 | executable_sp->GetFileSpec().GetDirectory().AsCString(), |
| 760 | executable_sp->GetFileSpec().GetFilename().AsCString()); |
| 761 | |
| 762 | m_images.Append(executable_sp); // The first image is our exectuable file |
| 763 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 764 | // 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] | 765 | if (!m_arch.IsValid()) |
| 766 | m_arch = executable_sp->GetArchitecture(); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 767 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 768 | FileSpecList dependent_files; |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 769 | ObjectFile *executable_objfile = executable_sp->GetObjectFile(); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 770 | // Let's find the file & line for main and set the default source file from there. |
| 771 | if (!m_source_manager.DefaultFileAndLineSet()) |
| 772 | { |
| 773 | SymbolContextList sc_list; |
| 774 | uint32_t num_matches; |
| 775 | ConstString main_name("main"); |
| 776 | bool symbols_okay = false; // Force it to be a debug symbol. |
| 777 | bool append = false; |
| 778 | num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list); |
| 779 | for (uint32_t idx = 0; idx < num_matches; idx++) |
| 780 | { |
| 781 | SymbolContext sc; |
| 782 | sc_list.GetContextAtIndex(idx, sc); |
| 783 | if (sc.line_entry.file) |
| 784 | { |
| 785 | m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line); |
| 786 | break; |
| 787 | } |
| 788 | } |
| 789 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 791 | if (executable_objfile && get_dependent_files) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | { |
| 793 | executable_objfile->GetDependentModules(dependent_files); |
| 794 | for (uint32_t i=0; i<dependent_files.GetSize(); i++) |
| 795 | { |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 796 | FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i)); |
| 797 | FileSpec platform_dependent_file_spec; |
| 798 | if (m_platform_sp) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 799 | m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 800 | else |
| 801 | platform_dependent_file_spec = dependent_file_spec; |
| 802 | |
| 803 | ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec, |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 804 | m_arch)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | if (image_module_sp.get()) |
| 806 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 808 | if (objfile) |
| 809 | objfile->GetDependentModules(dependent_files); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | } |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 815 | |
| 816 | UpdateInstanceName(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 820 | bool |
| 821 | Target::SetArchitecture (const ArchSpec &arch_spec) |
| 822 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 823 | if (m_arch == arch_spec) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 824 | { |
| 825 | // If we're setting the architecture to our current architecture, we |
| 826 | // don't need to do anything. |
| 827 | return true; |
| 828 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 829 | else if (!m_arch.IsValid()) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 830 | { |
| 831 | // If we haven't got a valid arch spec, then we just need to set it. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 832 | m_arch = arch_spec; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 833 | return true; |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | // 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] | 838 | m_arch = arch_spec; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 839 | ModuleSP executable_sp = GetExecutableModule (); |
| 840 | m_images.Clear(); |
| 841 | m_scratch_ast_context_ap.reset(); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 842 | // Need to do something about unsetting breakpoints. |
| 843 | |
| 844 | if (executable_sp) |
| 845 | { |
| 846 | FileSpec exec_file_spec = executable_sp->GetFileSpec(); |
| 847 | Error error = ModuleList::GetSharedModule(exec_file_spec, |
| 848 | arch_spec, |
| 849 | NULL, |
| 850 | NULL, |
| 851 | 0, |
| 852 | executable_sp, |
| 853 | NULL, |
| 854 | NULL); |
| 855 | |
| 856 | if (!error.Fail() && executable_sp) |
| 857 | { |
| 858 | SetExecutableModule (executable_sp, true); |
| 859 | return true; |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | return false; |
| 864 | } |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | return false; |
| 869 | } |
| 870 | } |
| 871 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | void |
| 874 | Target::ModuleAdded (ModuleSP &module_sp) |
| 875 | { |
| 876 | // A module is being added to this target for the first time |
| 877 | ModuleList module_list; |
| 878 | module_list.Append(module_sp); |
| 879 | ModulesDidLoad (module_list); |
| 880 | } |
| 881 | |
| 882 | void |
| 883 | Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) |
| 884 | { |
Jim Ingham | 3b8a605 | 2011-08-03 01:00:06 +0000 | [diff] [blame] | 885 | // A module is replacing an already added module |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 886 | ModuleList module_list; |
| 887 | module_list.Append (old_module_sp); |
| 888 | ModulesDidUnload (module_list); |
| 889 | module_list.Clear (); |
| 890 | module_list.Append (new_module_sp); |
| 891 | ModulesDidLoad (module_list); |
| 892 | } |
| 893 | |
| 894 | void |
| 895 | Target::ModulesDidLoad (ModuleList &module_list) |
| 896 | { |
| 897 | m_breakpoint_list.UpdateBreakpoints (module_list, true); |
| 898 | // TODO: make event data that packages up the module_list |
| 899 | BroadcastEvent (eBroadcastBitModulesLoaded, NULL); |
| 900 | } |
| 901 | |
| 902 | void |
| 903 | Target::ModulesDidUnload (ModuleList &module_list) |
| 904 | { |
| 905 | m_breakpoint_list.UpdateBreakpoints (module_list, false); |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 906 | |
| 907 | // Remove the images from the target image list |
| 908 | m_images.Remove(module_list); |
| 909 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 910 | // TODO: make event data that packages up the module_list |
| 911 | BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); |
| 912 | } |
| 913 | |
| 914 | size_t |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 915 | Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error) |
| 916 | { |
| 917 | const Section *section = addr.GetSection(); |
| 918 | if (section && section->GetModule()) |
| 919 | { |
| 920 | ObjectFile *objfile = section->GetModule()->GetObjectFile(); |
| 921 | if (objfile) |
| 922 | { |
| 923 | size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile, |
| 924 | addr.GetOffset(), |
| 925 | dst, |
| 926 | dst_len); |
| 927 | if (bytes_read > 0) |
| 928 | return bytes_read; |
| 929 | else |
| 930 | error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString()); |
| 931 | } |
| 932 | else |
| 933 | { |
| 934 | error.SetErrorString("address isn't from a object file"); |
| 935 | } |
| 936 | } |
| 937 | else |
| 938 | { |
| 939 | error.SetErrorString("address doesn't contain a section that points to a section in a object file"); |
| 940 | } |
| 941 | return 0; |
| 942 | } |
| 943 | |
| 944 | size_t |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 945 | Target::ReadMemory (const Address& addr, |
| 946 | bool prefer_file_cache, |
| 947 | void *dst, |
| 948 | size_t dst_len, |
| 949 | Error &error, |
| 950 | lldb::addr_t *load_addr_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 951 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | error.Clear(); |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 953 | |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 954 | // if we end up reading this from process memory, we will fill this |
| 955 | // with the actual load address |
| 956 | if (load_addr_ptr) |
| 957 | *load_addr_ptr = LLDB_INVALID_ADDRESS; |
| 958 | |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 959 | size_t bytes_read = 0; |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 960 | |
| 961 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 962 | addr_t file_addr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 963 | Address resolved_addr; |
| 964 | if (!addr.IsSectionOffset()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 965 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 966 | if (m_section_load_list.IsEmpty()) |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 967 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 968 | // No sections are loaded, so we must assume we are not running |
| 969 | // yet and anything we are given is a file address. |
| 970 | file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address |
| 971 | m_images.ResolveFileAddress (file_addr, resolved_addr); |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 972 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 973 | else |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 974 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 975 | // We have at least one section loaded. This can be becuase |
| 976 | // we have manually loaded some sections with "target modules load ..." |
| 977 | // or because we have have a live process that has sections loaded |
| 978 | // through the dynamic loader |
| 979 | load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address |
| 980 | m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr); |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 981 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 982 | } |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 983 | if (!resolved_addr.IsValid()) |
| 984 | resolved_addr = addr; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 985 | |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 986 | |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 987 | if (prefer_file_cache) |
| 988 | { |
| 989 | bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
| 990 | if (bytes_read > 0) |
| 991 | return bytes_read; |
| 992 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 993 | |
Johnny Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 994 | if (ProcessIsValid()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 995 | { |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 996 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 997 | load_addr = resolved_addr.GetLoadAddress (this); |
| 998 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 999 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1000 | { |
| 1001 | if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) |
| 1002 | error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n", |
| 1003 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), |
Jason Molenda | 95b7b43 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1004 | resolved_addr.GetFileAddress(), |
| 1005 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString()); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1006 | else |
| 1007 | error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress()); |
| 1008 | } |
| 1009 | else |
| 1010 | { |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1011 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1012 | if (bytes_read != dst_len) |
| 1013 | { |
| 1014 | if (error.Success()) |
| 1015 | { |
| 1016 | if (bytes_read == 0) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1017 | error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1018 | else |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1019 | error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1022 | if (bytes_read) |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1023 | { |
| 1024 | if (load_addr_ptr) |
| 1025 | *load_addr_ptr = load_addr; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1026 | return bytes_read; |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1027 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1028 | // If the address is not section offset we have an address that |
| 1029 | // doesn't resolve to any address in any currently loaded shared |
| 1030 | // libaries and we failed to read memory so there isn't anything |
| 1031 | // more we can do. If it is section offset, we might be able to |
| 1032 | // read cached memory from the object file. |
| 1033 | if (!resolved_addr.IsSectionOffset()) |
| 1034 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1035 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1036 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1037 | |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1038 | if (!prefer_file_cache && resolved_addr.IsSectionOffset()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1039 | { |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1040 | // If we didn't already try and read from the object file cache, then |
| 1041 | // try it after failing to read from the process. |
| 1042 | return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1043 | } |
| 1044 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1047 | size_t |
| 1048 | Target::ReadScalarIntegerFromMemory (const Address& addr, |
| 1049 | bool prefer_file_cache, |
| 1050 | uint32_t byte_size, |
| 1051 | bool is_signed, |
| 1052 | Scalar &scalar, |
| 1053 | Error &error) |
| 1054 | { |
| 1055 | uint64_t uval; |
| 1056 | |
| 1057 | if (byte_size <= sizeof(uval)) |
| 1058 | { |
| 1059 | size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error); |
| 1060 | if (bytes_read == byte_size) |
| 1061 | { |
| 1062 | DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize()); |
| 1063 | uint32_t offset = 0; |
| 1064 | if (byte_size <= 4) |
| 1065 | scalar = data.GetMaxU32 (&offset, byte_size); |
| 1066 | else |
| 1067 | scalar = data.GetMaxU64 (&offset, byte_size); |
| 1068 | |
| 1069 | if (is_signed) |
| 1070 | scalar.SignExtend(byte_size * 8); |
| 1071 | return bytes_read; |
| 1072 | } |
| 1073 | } |
| 1074 | else |
| 1075 | { |
| 1076 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 1077 | } |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | uint64_t |
| 1082 | Target::ReadUnsignedIntegerFromMemory (const Address& addr, |
| 1083 | bool prefer_file_cache, |
| 1084 | size_t integer_byte_size, |
| 1085 | uint64_t fail_value, |
| 1086 | Error &error) |
| 1087 | { |
| 1088 | Scalar scalar; |
| 1089 | if (ReadScalarIntegerFromMemory (addr, |
| 1090 | prefer_file_cache, |
| 1091 | integer_byte_size, |
| 1092 | false, |
| 1093 | scalar, |
| 1094 | error)) |
| 1095 | return scalar.ULongLong(fail_value); |
| 1096 | return fail_value; |
| 1097 | } |
| 1098 | |
| 1099 | bool |
| 1100 | Target::ReadPointerFromMemory (const Address& addr, |
| 1101 | bool prefer_file_cache, |
| 1102 | Error &error, |
| 1103 | Address &pointer_addr) |
| 1104 | { |
| 1105 | Scalar scalar; |
| 1106 | if (ReadScalarIntegerFromMemory (addr, |
| 1107 | prefer_file_cache, |
| 1108 | m_arch.GetAddressByteSize(), |
| 1109 | false, |
| 1110 | scalar, |
| 1111 | error)) |
| 1112 | { |
| 1113 | addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1114 | if (pointer_vm_addr != LLDB_INVALID_ADDRESS) |
| 1115 | { |
| 1116 | if (m_section_load_list.IsEmpty()) |
| 1117 | { |
| 1118 | // No sections are loaded, so we must assume we are not running |
| 1119 | // yet and anything we are given is a file address. |
| 1120 | m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr); |
| 1121 | } |
| 1122 | else |
| 1123 | { |
| 1124 | // We have at least one section loaded. This can be becuase |
| 1125 | // we have manually loaded some sections with "target modules load ..." |
| 1126 | // or because we have have a live process that has sections loaded |
| 1127 | // through the dynamic loader |
| 1128 | m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr); |
| 1129 | } |
| 1130 | // We weren't able to resolve the pointer value, so just return |
| 1131 | // an address with no section |
| 1132 | if (!pointer_addr.IsValid()) |
| 1133 | pointer_addr.SetOffset (pointer_vm_addr); |
| 1134 | return true; |
| 1135 | |
| 1136 | } |
| 1137 | } |
| 1138 | return false; |
| 1139 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1140 | |
| 1141 | ModuleSP |
| 1142 | Target::GetSharedModule |
| 1143 | ( |
| 1144 | const FileSpec& file_spec, |
| 1145 | const ArchSpec& arch, |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 1146 | const lldb_private::UUID *uuid_ptr, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | const ConstString *object_name, |
| 1148 | off_t object_offset, |
| 1149 | Error *error_ptr |
| 1150 | ) |
| 1151 | { |
| 1152 | // Don't pass in the UUID so we can tell if we have a stale value in our list |
| 1153 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 1154 | bool did_create_module = false; |
| 1155 | ModuleSP module_sp; |
| 1156 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1157 | Error error; |
| 1158 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1159 | // If there are image search path entries, try to use them first to acquire a suitable image. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1160 | if (m_image_search_paths.GetSize()) |
| 1161 | { |
| 1162 | FileSpec transformed_spec; |
| 1163 | if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory())) |
| 1164 | { |
| 1165 | transformed_spec.GetFilename() = file_spec.GetFilename(); |
| 1166 | error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1170 | // The platform is responsible for finding and caching an appropriate |
| 1171 | // module in the shared module cache. |
| 1172 | if (m_platform_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1173 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1174 | FileSpec platform_file_spec; |
| 1175 | error = m_platform_sp->GetSharedModule (file_spec, |
| 1176 | arch, |
| 1177 | uuid_ptr, |
| 1178 | object_name, |
| 1179 | object_offset, |
| 1180 | module_sp, |
| 1181 | &old_module_sp, |
| 1182 | &did_create_module); |
| 1183 | } |
| 1184 | else |
| 1185 | { |
| 1186 | error.SetErrorString("no platform is currently set"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1189 | // If a module hasn't been found yet, use the unmodified path. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1190 | if (module_sp) |
| 1191 | { |
| 1192 | m_images.Append (module_sp); |
| 1193 | if (did_create_module) |
| 1194 | { |
| 1195 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 1196 | ModuleUpdated(old_module_sp, module_sp); |
| 1197 | else |
| 1198 | ModuleAdded(module_sp); |
| 1199 | } |
| 1200 | } |
| 1201 | if (error_ptr) |
| 1202 | *error_ptr = error; |
| 1203 | return module_sp; |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | Target * |
| 1208 | Target::CalculateTarget () |
| 1209 | { |
| 1210 | return this; |
| 1211 | } |
| 1212 | |
| 1213 | Process * |
| 1214 | Target::CalculateProcess () |
| 1215 | { |
| 1216 | return NULL; |
| 1217 | } |
| 1218 | |
| 1219 | Thread * |
| 1220 | Target::CalculateThread () |
| 1221 | { |
| 1222 | return NULL; |
| 1223 | } |
| 1224 | |
| 1225 | StackFrame * |
| 1226 | Target::CalculateStackFrame () |
| 1227 | { |
| 1228 | return NULL; |
| 1229 | } |
| 1230 | |
| 1231 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1232 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1234 | exe_ctx.Clear(); |
| 1235 | exe_ctx.SetTargetPtr(this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | PathMappingList & |
| 1239 | Target::GetImageSearchPathList () |
| 1240 | { |
| 1241 | return m_image_search_paths; |
| 1242 | } |
| 1243 | |
| 1244 | void |
| 1245 | Target::ImageSearchPathsChanged |
| 1246 | ( |
| 1247 | const PathMappingList &path_list, |
| 1248 | void *baton |
| 1249 | ) |
| 1250 | { |
| 1251 | Target *target = (Target *)baton; |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1252 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 1253 | if (exe_module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1254 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1255 | target->m_images.Clear(); |
| 1256 | target->SetExecutableModule (exe_module_sp, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | ClangASTContext * |
| 1261 | Target::GetScratchClangASTContext() |
| 1262 | { |
Greg Clayton | 34ce4ea | 2011-08-03 01:23:55 +0000 | [diff] [blame] | 1263 | // Now see if we know the target triple, and if so, create our scratch AST context: |
| 1264 | if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid()) |
| 1265 | m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1266 | return m_scratch_ast_context_ap.get(); |
| 1267 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1268 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1269 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1270 | Target::SettingsInitialize () |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1271 | { |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1272 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 1273 | usc.reset (new SettingsController); |
| 1274 | UserSettingsController::InitializeSettingsController (usc, |
| 1275 | SettingsController::global_settings_table, |
| 1276 | SettingsController::instance_settings_table); |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1277 | |
| 1278 | // Now call SettingsInitialize() on each 'child' setting of Target |
| 1279 | Process::SettingsInitialize (); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1280 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1281 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1282 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1283 | Target::SettingsTerminate () |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1284 | { |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1285 | |
| 1286 | // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings. |
| 1287 | |
| 1288 | Process::SettingsTerminate (); |
| 1289 | |
| 1290 | // Now terminate Target Settings. |
| 1291 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1292 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 1293 | UserSettingsController::FinalizeSettingsController (usc); |
| 1294 | usc.reset(); |
| 1295 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1296 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1297 | UserSettingsControllerSP & |
| 1298 | Target::GetSettingsController () |
| 1299 | { |
| 1300 | static UserSettingsControllerSP g_settings_controller; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1301 | return g_settings_controller; |
| 1302 | } |
| 1303 | |
| 1304 | ArchSpec |
| 1305 | Target::GetDefaultArchitecture () |
| 1306 | { |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1307 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 1308 | |
| 1309 | if (settings_controller_sp) |
| 1310 | return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture (); |
| 1311 | return ArchSpec(); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | void |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1315 | Target::SetDefaultArchitecture (const ArchSpec& arch) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1316 | { |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1317 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 1318 | |
| 1319 | if (settings_controller_sp) |
| 1320 | static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1323 | Target * |
| 1324 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 1325 | { |
| 1326 | // The target can either exist in the "process" of ExecutionContext, or in |
| 1327 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 1328 | // will get the target from one of these locations. |
| 1329 | |
| 1330 | Target *target = NULL; |
| 1331 | if (sc_ptr != NULL) |
| 1332 | target = sc_ptr->target_sp.get(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1333 | if (target == NULL && exe_ctx_ptr) |
| 1334 | target = exe_ctx_ptr->GetTargetPtr(); |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1335 | return target; |
| 1336 | } |
| 1337 | |
| 1338 | |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 1339 | void |
| 1340 | Target::UpdateInstanceName () |
| 1341 | { |
| 1342 | StreamString sstr; |
| 1343 | |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1344 | Module *exe_module = GetExecutableModulePointer(); |
| 1345 | if (exe_module) |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 1346 | { |
Greg Clayton | bf6e210 | 2010-10-27 02:06:37 +0000 | [diff] [blame] | 1347 | sstr.Printf ("%s_%s", |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1348 | exe_module->GetFileSpec().GetFilename().AsCString(), |
| 1349 | exe_module->GetArchitecture().GetArchitectureName()); |
| 1350 | GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData()); |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1354 | const char * |
| 1355 | Target::GetExpressionPrefixContentsAsCString () |
| 1356 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 1357 | if (m_expr_prefix_contents_sp) |
| 1358 | return (const char *)m_expr_prefix_contents_sp->GetBytes(); |
| 1359 | return NULL; |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1362 | ExecutionResults |
| 1363 | Target::EvaluateExpression |
| 1364 | ( |
| 1365 | const char *expr_cstr, |
| 1366 | StackFrame *frame, |
Sean Callanan | 47dc457 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 1367 | lldb_private::ExecutionPolicy execution_policy, |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1368 | bool unwind_on_error, |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1369 | bool keep_in_memory, |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1370 | lldb::DynamicValueType use_dynamic, |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1371 | lldb::ValueObjectSP &result_valobj_sp |
| 1372 | ) |
| 1373 | { |
| 1374 | ExecutionResults execution_results = eExecutionSetupError; |
| 1375 | |
| 1376 | result_valobj_sp.reset(); |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1377 | |
| 1378 | // We shouldn't run stop hooks in expressions. |
| 1379 | // Be sure to reset this if you return anywhere within this function. |
| 1380 | bool old_suppress_value = m_suppress_stop_hooks; |
| 1381 | m_suppress_stop_hooks = true; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1382 | |
| 1383 | ExecutionContext exe_ctx; |
| 1384 | if (frame) |
| 1385 | { |
| 1386 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1387 | Error error; |
Greg Clayton | c67efa4 | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 1388 | const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
Enrico Granata | f669850 | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1389 | StackFrame::eExpressionPathOptionsNoFragileObjcIvar | |
| 1390 | StackFrame::eExpressionPathOptionsNoSyntheticChildren; |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1391 | lldb::VariableSP var_sp; |
| 1392 | result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, |
| 1393 | use_dynamic, |
| 1394 | expr_path_options, |
| 1395 | var_sp, |
| 1396 | error); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1397 | } |
| 1398 | else if (m_process_sp) |
| 1399 | { |
| 1400 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 1401 | } |
| 1402 | else |
| 1403 | { |
| 1404 | CalculateExecutionContext(exe_ctx); |
| 1405 | } |
| 1406 | |
| 1407 | if (result_valobj_sp) |
| 1408 | { |
| 1409 | execution_results = eExecutionCompleted; |
| 1410 | // We got a result from the frame variable expression path above... |
| 1411 | ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName()); |
| 1412 | |
| 1413 | lldb::ValueObjectSP const_valobj_sp; |
| 1414 | |
| 1415 | // Check in case our value is already a constant value |
| 1416 | if (result_valobj_sp->GetIsConstant()) |
| 1417 | { |
| 1418 | const_valobj_sp = result_valobj_sp; |
| 1419 | const_valobj_sp->SetName (persistent_variable_name); |
| 1420 | } |
| 1421 | else |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1422 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1423 | if (use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1424 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1425 | ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1426 | if (dynamic_sp) |
| 1427 | result_valobj_sp = dynamic_sp; |
| 1428 | } |
| 1429 | |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1430 | const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1431 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1432 | |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1433 | lldb::ValueObjectSP live_valobj_sp = result_valobj_sp; |
| 1434 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1435 | result_valobj_sp = const_valobj_sp; |
| 1436 | |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1437 | ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp)); |
| 1438 | assert (clang_expr_variable_sp.get()); |
| 1439 | |
| 1440 | // Set flags and live data as appropriate |
| 1441 | |
| 1442 | const Value &result_value = live_valobj_sp->GetValue(); |
| 1443 | |
| 1444 | switch (result_value.GetValueType()) |
| 1445 | { |
| 1446 | case Value::eValueTypeHostAddress: |
| 1447 | case Value::eValueTypeFileAddress: |
| 1448 | // we don't do anything with these for now |
| 1449 | break; |
| 1450 | case Value::eValueTypeScalar: |
| 1451 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated; |
| 1452 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation; |
| 1453 | break; |
| 1454 | case Value::eValueTypeLoadAddress: |
| 1455 | clang_expr_variable_sp->m_live_sp = live_valobj_sp; |
| 1456 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference; |
| 1457 | break; |
| 1458 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1459 | } |
| 1460 | else |
| 1461 | { |
| 1462 | // Make sure we aren't just trying to see the value of a persistent |
| 1463 | // variable (something like "$0") |
Greg Clayton | a875b64 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 1464 | lldb::ClangExpressionVariableSP persistent_var_sp; |
| 1465 | // Only check for persistent variables the expression starts with a '$' |
| 1466 | if (expr_cstr[0] == '$') |
| 1467 | persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); |
| 1468 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1469 | if (persistent_var_sp) |
| 1470 | { |
| 1471 | result_valobj_sp = persistent_var_sp->GetValueObject (); |
| 1472 | execution_results = eExecutionCompleted; |
| 1473 | } |
| 1474 | else |
| 1475 | { |
| 1476 | const char *prefix = GetExpressionPrefixContentsAsCString(); |
Sean Callanan | 47dc457 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 1477 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1478 | execution_results = ClangUserExpression::Evaluate (exe_ctx, |
Sean Callanan | 47dc457 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 1479 | execution_policy, |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 1480 | unwind_on_error, |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1481 | expr_cstr, |
| 1482 | prefix, |
| 1483 | result_valobj_sp); |
| 1484 | } |
| 1485 | } |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1486 | |
| 1487 | m_suppress_stop_hooks = old_suppress_value; |
| 1488 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1489 | return execution_results; |
| 1490 | } |
| 1491 | |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 1492 | lldb::addr_t |
| 1493 | Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1494 | { |
| 1495 | addr_t code_addr = load_addr; |
| 1496 | switch (m_arch.GetMachine()) |
| 1497 | { |
| 1498 | case llvm::Triple::arm: |
| 1499 | case llvm::Triple::thumb: |
| 1500 | switch (addr_class) |
| 1501 | { |
| 1502 | case eAddressClassData: |
| 1503 | case eAddressClassDebug: |
| 1504 | return LLDB_INVALID_ADDRESS; |
| 1505 | |
| 1506 | case eAddressClassUnknown: |
| 1507 | case eAddressClassInvalid: |
| 1508 | case eAddressClassCode: |
| 1509 | case eAddressClassCodeAlternateISA: |
| 1510 | case eAddressClassRuntime: |
| 1511 | // Check if bit zero it no set? |
| 1512 | if ((code_addr & 1ull) == 0) |
| 1513 | { |
| 1514 | // Bit zero isn't set, check if the address is a multiple of 2? |
| 1515 | if (code_addr & 2ull) |
| 1516 | { |
| 1517 | // The address is a multiple of 2 so it must be thumb, set bit zero |
| 1518 | code_addr |= 1ull; |
| 1519 | } |
| 1520 | else if (addr_class == eAddressClassCodeAlternateISA) |
| 1521 | { |
| 1522 | // We checked the address and the address claims to be the alternate ISA |
| 1523 | // which means thumb, so set bit zero. |
| 1524 | code_addr |= 1ull; |
| 1525 | } |
| 1526 | } |
| 1527 | break; |
| 1528 | } |
| 1529 | break; |
| 1530 | |
| 1531 | default: |
| 1532 | break; |
| 1533 | } |
| 1534 | return code_addr; |
| 1535 | } |
| 1536 | |
| 1537 | lldb::addr_t |
| 1538 | Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const |
| 1539 | { |
| 1540 | addr_t opcode_addr = load_addr; |
| 1541 | switch (m_arch.GetMachine()) |
| 1542 | { |
| 1543 | case llvm::Triple::arm: |
| 1544 | case llvm::Triple::thumb: |
| 1545 | switch (addr_class) |
| 1546 | { |
| 1547 | case eAddressClassData: |
| 1548 | case eAddressClassDebug: |
| 1549 | return LLDB_INVALID_ADDRESS; |
| 1550 | |
| 1551 | case eAddressClassInvalid: |
| 1552 | case eAddressClassUnknown: |
| 1553 | case eAddressClassCode: |
| 1554 | case eAddressClassCodeAlternateISA: |
| 1555 | case eAddressClassRuntime: |
| 1556 | opcode_addr &= ~(1ull); |
| 1557 | break; |
| 1558 | } |
| 1559 | break; |
| 1560 | |
| 1561 | default: |
| 1562 | break; |
| 1563 | } |
| 1564 | return opcode_addr; |
| 1565 | } |
| 1566 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1567 | lldb::user_id_t |
| 1568 | Target::AddStopHook (Target::StopHookSP &new_hook_sp) |
| 1569 | { |
| 1570 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
| 1571 | new_hook_sp.reset (new StopHook(GetSP(), new_uid)); |
| 1572 | m_stop_hooks[new_uid] = new_hook_sp; |
| 1573 | return new_uid; |
| 1574 | } |
| 1575 | |
| 1576 | bool |
| 1577 | Target::RemoveStopHookByID (lldb::user_id_t user_id) |
| 1578 | { |
| 1579 | size_t num_removed; |
| 1580 | num_removed = m_stop_hooks.erase (user_id); |
| 1581 | if (num_removed == 0) |
| 1582 | return false; |
| 1583 | else |
| 1584 | return true; |
| 1585 | } |
| 1586 | |
| 1587 | void |
| 1588 | Target::RemoveAllStopHooks () |
| 1589 | { |
| 1590 | m_stop_hooks.clear(); |
| 1591 | } |
| 1592 | |
| 1593 | Target::StopHookSP |
| 1594 | Target::GetStopHookByID (lldb::user_id_t user_id) |
| 1595 | { |
| 1596 | StopHookSP found_hook; |
| 1597 | |
| 1598 | StopHookCollection::iterator specified_hook_iter; |
| 1599 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1600 | if (specified_hook_iter != m_stop_hooks.end()) |
| 1601 | found_hook = (*specified_hook_iter).second; |
| 1602 | return found_hook; |
| 1603 | } |
| 1604 | |
| 1605 | bool |
| 1606 | Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) |
| 1607 | { |
| 1608 | StopHookCollection::iterator specified_hook_iter; |
| 1609 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1610 | if (specified_hook_iter == m_stop_hooks.end()) |
| 1611 | return false; |
| 1612 | |
| 1613 | (*specified_hook_iter).second->SetIsActive (active_state); |
| 1614 | return true; |
| 1615 | } |
| 1616 | |
| 1617 | void |
| 1618 | Target::SetAllStopHooksActiveState (bool active_state) |
| 1619 | { |
| 1620 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1621 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1622 | { |
| 1623 | (*pos).second->SetIsActive (active_state); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | void |
| 1628 | Target::RunStopHooks () |
| 1629 | { |
Jim Ingham | 3613ae1 | 2011-05-12 02:06:14 +0000 | [diff] [blame] | 1630 | if (m_suppress_stop_hooks) |
| 1631 | return; |
| 1632 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1633 | if (!m_process_sp) |
| 1634 | return; |
| 1635 | |
| 1636 | if (m_stop_hooks.empty()) |
| 1637 | return; |
| 1638 | |
| 1639 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1640 | |
| 1641 | // If there aren't any active stop hooks, don't bother either: |
| 1642 | bool any_active_hooks = false; |
| 1643 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1644 | { |
| 1645 | if ((*pos).second->IsActive()) |
| 1646 | { |
| 1647 | any_active_hooks = true; |
| 1648 | break; |
| 1649 | } |
| 1650 | } |
| 1651 | if (!any_active_hooks) |
| 1652 | return; |
| 1653 | |
| 1654 | CommandReturnObject result; |
| 1655 | |
| 1656 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 1657 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 1658 | |
| 1659 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 1660 | size_t num_threads = cur_threadlist.GetSize(); |
| 1661 | for (size_t i = 0; i < num_threads; i++) |
| 1662 | { |
| 1663 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); |
| 1664 | if (cur_thread_sp->ThreadStoppedForAReason()) |
| 1665 | { |
| 1666 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 1667 | exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 1668 | sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 1673 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 1674 | if (num_exe_ctx == 0) |
| 1675 | return; |
| 1676 | |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 1677 | result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream()); |
| 1678 | result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1679 | |
| 1680 | bool keep_going = true; |
| 1681 | bool hooks_ran = false; |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 1682 | bool print_hook_header; |
| 1683 | bool print_thread_header; |
| 1684 | |
| 1685 | if (num_exe_ctx == 1) |
| 1686 | print_thread_header = false; |
| 1687 | else |
| 1688 | print_thread_header = true; |
| 1689 | |
| 1690 | if (m_stop_hooks.size() == 1) |
| 1691 | print_hook_header = false; |
| 1692 | else |
| 1693 | print_hook_header = true; |
| 1694 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1695 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) |
| 1696 | { |
| 1697 | // result.Clear(); |
| 1698 | StopHookSP cur_hook_sp = (*pos).second; |
| 1699 | if (!cur_hook_sp->IsActive()) |
| 1700 | continue; |
| 1701 | |
| 1702 | bool any_thread_matched = false; |
| 1703 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) |
| 1704 | { |
| 1705 | if ((cur_hook_sp->GetSpecifier () == NULL |
| 1706 | || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) |
| 1707 | && (cur_hook_sp->GetThreadSpecifier() == NULL |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1708 | || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr()))) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1709 | { |
| 1710 | if (!hooks_ran) |
| 1711 | { |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1712 | hooks_ran = true; |
| 1713 | } |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 1714 | if (print_hook_header && !any_thread_matched) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1715 | { |
| 1716 | result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID()); |
| 1717 | any_thread_matched = true; |
| 1718 | } |
| 1719 | |
Jim Ingham | c54840c | 2011-03-22 01:47:27 +0000 | [diff] [blame] | 1720 | if (print_thread_header) |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1721 | result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID()); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1722 | |
| 1723 | bool stop_on_continue = true; |
| 1724 | bool stop_on_error = true; |
| 1725 | bool echo_commands = false; |
| 1726 | bool print_results = true; |
| 1727 | GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1728 | &exc_ctx_with_reasons[i], |
| 1729 | stop_on_continue, |
| 1730 | stop_on_error, |
| 1731 | echo_commands, |
| 1732 | print_results, |
| 1733 | result); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1734 | |
| 1735 | // If the command started the target going again, we should bag out of |
| 1736 | // running the stop hooks. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1737 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) || |
| 1738 | (result.GetStatus() == eReturnStatusSuccessContinuingResult)) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1739 | { |
| 1740 | result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID()); |
| 1741 | keep_going = false; |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | } |
Jason Molenda | 850ac6e | 2011-09-23 00:42:55 +0000 | [diff] [blame] | 1746 | |
Caroline Tice | 4a34808 | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 1747 | result.GetImmediateOutputStream()->Flush(); |
| 1748 | result.GetImmediateErrorStream()->Flush(); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1751 | bool |
| 1752 | Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide) |
| 1753 | { |
| 1754 | bool changed = false; |
| 1755 | if (module) |
| 1756 | { |
| 1757 | ObjectFile *object_file = module->GetObjectFile(); |
| 1758 | if (object_file) |
| 1759 | { |
| 1760 | SectionList *section_list = object_file->GetSectionList (); |
| 1761 | if (section_list) |
| 1762 | { |
| 1763 | // All sections listed in the dyld image info structure will all |
| 1764 | // either be fixed up already, or they will all be off by a single |
| 1765 | // slide amount that is determined by finding the first segment |
| 1766 | // that is at file offset zero which also has bytes (a file size |
| 1767 | // that is greater than zero) in the object file. |
| 1768 | |
| 1769 | // Determine the slide amount (if any) |
| 1770 | const size_t num_sections = section_list->GetSize(); |
| 1771 | size_t sect_idx = 0; |
| 1772 | for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1773 | { |
| 1774 | // Iterate through the object file sections to find the |
| 1775 | // first section that starts of file offset zero and that |
| 1776 | // has bytes in the file... |
| 1777 | Section *section = section_list->GetSectionAtIndex (sect_idx).get(); |
| 1778 | if (section) |
| 1779 | { |
| 1780 | if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide)) |
| 1781 | changed = true; |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | return changed; |
| 1788 | } |
| 1789 | |
| 1790 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1791 | //-------------------------------------------------------------- |
| 1792 | // class Target::StopHook |
| 1793 | //-------------------------------------------------------------- |
| 1794 | |
| 1795 | |
| 1796 | Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : |
| 1797 | UserID (uid), |
| 1798 | m_target_sp (target_sp), |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1799 | m_commands (), |
| 1800 | m_specifier_sp (), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 1801 | m_thread_spec_ap(NULL), |
| 1802 | m_active (true) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1803 | { |
| 1804 | } |
| 1805 | |
| 1806 | Target::StopHook::StopHook (const StopHook &rhs) : |
| 1807 | UserID (rhs.GetID()), |
| 1808 | m_target_sp (rhs.m_target_sp), |
| 1809 | m_commands (rhs.m_commands), |
| 1810 | m_specifier_sp (rhs.m_specifier_sp), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 1811 | m_thread_spec_ap (NULL), |
| 1812 | m_active (rhs.m_active) |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 1813 | { |
| 1814 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 1815 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
| 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | Target::StopHook::~StopHook () |
| 1820 | { |
| 1821 | } |
| 1822 | |
| 1823 | void |
| 1824 | Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier) |
| 1825 | { |
| 1826 | m_thread_spec_ap.reset (specifier); |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | void |
| 1831 | Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 1832 | { |
| 1833 | int indent_level = s->GetIndentLevel(); |
| 1834 | |
| 1835 | s->SetIndentLevel(indent_level + 2); |
| 1836 | |
| 1837 | s->Printf ("Hook: %d\n", GetID()); |
| 1838 | if (m_active) |
| 1839 | s->Indent ("State: enabled\n"); |
| 1840 | else |
| 1841 | s->Indent ("State: disabled\n"); |
| 1842 | |
| 1843 | if (m_specifier_sp) |
| 1844 | { |
| 1845 | s->Indent(); |
| 1846 | s->PutCString ("Specifier:\n"); |
| 1847 | s->SetIndentLevel (indent_level + 4); |
| 1848 | m_specifier_sp->GetDescription (s, level); |
| 1849 | s->SetIndentLevel (indent_level + 2); |
| 1850 | } |
| 1851 | |
| 1852 | if (m_thread_spec_ap.get() != NULL) |
| 1853 | { |
| 1854 | StreamString tmp; |
| 1855 | s->Indent("Thread:\n"); |
| 1856 | m_thread_spec_ap->GetDescription (&tmp, level); |
| 1857 | s->SetIndentLevel (indent_level + 4); |
| 1858 | s->Indent (tmp.GetData()); |
| 1859 | s->PutCString ("\n"); |
| 1860 | s->SetIndentLevel (indent_level + 2); |
| 1861 | } |
| 1862 | |
| 1863 | s->Indent ("Commands: \n"); |
| 1864 | s->SetIndentLevel (indent_level + 4); |
| 1865 | uint32_t num_commands = m_commands.GetSize(); |
| 1866 | for (uint32_t i = 0; i < num_commands; i++) |
| 1867 | { |
| 1868 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 1869 | s->PutCString ("\n"); |
| 1870 | } |
| 1871 | s->SetIndentLevel (indent_level); |
| 1872 | } |
| 1873 | |
| 1874 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1875 | //-------------------------------------------------------------- |
| 1876 | // class Target::SettingsController |
| 1877 | //-------------------------------------------------------------- |
| 1878 | |
| 1879 | Target::SettingsController::SettingsController () : |
| 1880 | UserSettingsController ("target", Debugger::GetSettingsController()), |
| 1881 | m_default_architecture () |
| 1882 | { |
| 1883 | m_default_settings.reset (new TargetInstanceSettings (*this, false, |
| 1884 | InstanceSettings::GetDefaultName().AsCString())); |
| 1885 | } |
| 1886 | |
| 1887 | Target::SettingsController::~SettingsController () |
| 1888 | { |
| 1889 | } |
| 1890 | |
| 1891 | lldb::InstanceSettingsSP |
| 1892 | Target::SettingsController::CreateInstanceSettings (const char *instance_name) |
| 1893 | { |
Greg Clayton | c0c1b0c | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 1894 | TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(), |
| 1895 | false, |
| 1896 | instance_name); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1897 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 1898 | return new_settings_sp; |
| 1899 | } |
| 1900 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1901 | |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1902 | #define TSC_DEFAULT_ARCH "default-arch" |
| 1903 | #define TSC_EXPR_PREFIX "expr-prefix" |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1904 | #define TSC_PREFER_DYNAMIC "prefer-dynamic-value" |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 1905 | #define TSC_SKIP_PROLOGUE "skip-prologue" |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 1906 | #define TSC_SOURCE_MAP "source-map" |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1907 | #define TSC_MAX_CHILDREN "max-children-count" |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1908 | #define TSC_MAX_STRLENSUMMARY "max-string-summary-length" |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1909 | |
| 1910 | |
| 1911 | static const ConstString & |
| 1912 | GetSettingNameForDefaultArch () |
| 1913 | { |
| 1914 | static ConstString g_const_string (TSC_DEFAULT_ARCH); |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1915 | return g_const_string; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1918 | static const ConstString & |
| 1919 | GetSettingNameForExpressionPrefix () |
| 1920 | { |
| 1921 | static ConstString g_const_string (TSC_EXPR_PREFIX); |
| 1922 | return g_const_string; |
| 1923 | } |
| 1924 | |
| 1925 | static const ConstString & |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1926 | GetSettingNameForPreferDynamicValue () |
| 1927 | { |
| 1928 | static ConstString g_const_string (TSC_PREFER_DYNAMIC); |
| 1929 | return g_const_string; |
| 1930 | } |
| 1931 | |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 1932 | static const ConstString & |
| 1933 | GetSettingNameForSourcePathMap () |
| 1934 | { |
| 1935 | static ConstString g_const_string (TSC_SOURCE_MAP); |
| 1936 | return g_const_string; |
| 1937 | } |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1938 | |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 1939 | static const ConstString & |
| 1940 | GetSettingNameForSkipPrologue () |
| 1941 | { |
| 1942 | static ConstString g_const_string (TSC_SKIP_PROLOGUE); |
| 1943 | return g_const_string; |
| 1944 | } |
| 1945 | |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1946 | static const ConstString & |
| 1947 | GetSettingNameForMaxChildren () |
| 1948 | { |
| 1949 | static ConstString g_const_string (TSC_MAX_CHILDREN); |
| 1950 | return g_const_string; |
| 1951 | } |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 1952 | |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1953 | static const ConstString & |
| 1954 | GetSettingNameForMaxStringSummaryLength () |
| 1955 | { |
| 1956 | static ConstString g_const_string (TSC_MAX_STRLENSUMMARY); |
| 1957 | return g_const_string; |
| 1958 | } |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 1959 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1960 | bool |
| 1961 | Target::SettingsController::SetGlobalVariable (const ConstString &var_name, |
| 1962 | const char *index_value, |
| 1963 | const char *value, |
| 1964 | const SettingEntry &entry, |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1965 | const VarSetOperationType op, |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1966 | Error&err) |
| 1967 | { |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1968 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1969 | { |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1970 | m_default_architecture.SetTriple (value, NULL); |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1971 | if (!m_default_architecture.IsValid()) |
| 1972 | err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1973 | } |
| 1974 | return true; |
| 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | bool |
| 1979 | Target::SettingsController::GetGlobalVariable (const ConstString &var_name, |
| 1980 | StringList &value, |
| 1981 | Error &err) |
| 1982 | { |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1983 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1984 | { |
Greg Clayton | bf6e210 | 2010-10-27 02:06:37 +0000 | [diff] [blame] | 1985 | // If the arch is invalid (the default), don't show a string for it |
| 1986 | if (m_default_architecture.IsValid()) |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1987 | value.AppendString (m_default_architecture.GetArchitectureName()); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1988 | return true; |
| 1989 | } |
| 1990 | else |
| 1991 | err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1992 | |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | //-------------------------------------------------------------- |
| 1997 | // class TargetInstanceSettings |
| 1998 | //-------------------------------------------------------------- |
| 1999 | |
Greg Clayton | 638351a | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 2000 | TargetInstanceSettings::TargetInstanceSettings |
| 2001 | ( |
| 2002 | UserSettingsController &owner, |
| 2003 | bool live_instance, |
| 2004 | const char *name |
| 2005 | ) : |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2006 | InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2007 | m_expr_prefix_file (), |
| 2008 | m_expr_prefix_contents_sp (), |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2009 | m_prefer_dynamic_value (2), |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2010 | m_skip_prologue (true, true), |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2011 | m_source_map (NULL, NULL), |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2012 | m_max_children_display(256), |
| 2013 | m_max_strlen_length(1024) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2014 | { |
| 2015 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 2016 | // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 2017 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 2018 | // This is true for CreateInstanceName() too. |
| 2019 | |
| 2020 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 2021 | { |
| 2022 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 2023 | m_owner.RegisterInstanceSettings (this); |
| 2024 | } |
| 2025 | |
| 2026 | if (live_instance) |
| 2027 | { |
| 2028 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 2029 | CopyInstanceSettings (pending_settings,false); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2034 | InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()), |
| 2035 | m_expr_prefix_file (rhs.m_expr_prefix_file), |
| 2036 | m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp), |
| 2037 | m_prefer_dynamic_value (rhs.m_prefer_dynamic_value), |
| 2038 | m_skip_prologue (rhs.m_skip_prologue), |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2039 | m_source_map (rhs.m_source_map), |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2040 | m_max_children_display(rhs.m_max_children_display), |
| 2041 | m_max_strlen_length(rhs.m_max_strlen_length) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2042 | { |
| 2043 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 2044 | { |
| 2045 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 2046 | CopyInstanceSettings (pending_settings,false); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | TargetInstanceSettings::~TargetInstanceSettings () |
| 2051 | { |
| 2052 | } |
| 2053 | |
| 2054 | TargetInstanceSettings& |
| 2055 | TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) |
| 2056 | { |
| 2057 | if (this != &rhs) |
| 2058 | { |
| 2059 | } |
| 2060 | |
| 2061 | return *this; |
| 2062 | } |
| 2063 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2064 | void |
| 2065 | TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 2066 | const char *index_value, |
| 2067 | const char *value, |
| 2068 | const ConstString &instance_name, |
| 2069 | const SettingEntry &entry, |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 2070 | VarSetOperationType op, |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2071 | Error &err, |
| 2072 | bool pending) |
| 2073 | { |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2074 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2075 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2076 | err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file); |
| 2077 | if (err.Success()) |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2078 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2079 | switch (op) |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2080 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2081 | default: |
| 2082 | break; |
| 2083 | case eVarSetOperationAssign: |
| 2084 | case eVarSetOperationAppend: |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2085 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2086 | if (!m_expr_prefix_file.GetCurrentValue().Exists()) |
| 2087 | { |
| 2088 | err.SetErrorToGenericError (); |
| 2089 | err.SetErrorStringWithFormat ("%s does not exist.\n", value); |
| 2090 | return; |
| 2091 | } |
| 2092 | |
| 2093 | m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents(); |
| 2094 | |
| 2095 | if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0) |
| 2096 | { |
| 2097 | err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value); |
| 2098 | m_expr_prefix_contents_sp.reset(); |
| 2099 | } |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2100 | } |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | case eVarSetOperationClear: |
| 2103 | m_expr_prefix_contents_sp.reset(); |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2104 | } |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2105 | } |
| 2106 | } |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2107 | else if (var_name == GetSettingNameForPreferDynamicValue()) |
| 2108 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2109 | int new_value; |
| 2110 | UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err); |
| 2111 | if (err.Success()) |
| 2112 | m_prefer_dynamic_value = new_value; |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 2113 | } |
| 2114 | else if (var_name == GetSettingNameForSkipPrologue()) |
| 2115 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2116 | err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue); |
| 2117 | } |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2118 | else if (var_name == GetSettingNameForMaxChildren()) |
| 2119 | { |
| 2120 | bool ok; |
| 2121 | uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok); |
| 2122 | if (ok) |
| 2123 | m_max_children_display = new_value; |
| 2124 | } |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2125 | else if (var_name == GetSettingNameForMaxStringSummaryLength()) |
| 2126 | { |
| 2127 | bool ok; |
| 2128 | uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok); |
| 2129 | if (ok) |
| 2130 | m_max_strlen_length = new_value; |
| 2131 | } |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2132 | else if (var_name == GetSettingNameForSourcePathMap ()) |
| 2133 | { |
| 2134 | switch (op) |
| 2135 | { |
| 2136 | case eVarSetOperationReplace: |
| 2137 | case eVarSetOperationInsertBefore: |
| 2138 | case eVarSetOperationInsertAfter: |
| 2139 | case eVarSetOperationRemove: |
| 2140 | default: |
| 2141 | break; |
| 2142 | case eVarSetOperationAssign: |
| 2143 | m_source_map.Clear(true); |
| 2144 | // Fall through to append.... |
| 2145 | case eVarSetOperationAppend: |
| 2146 | { |
| 2147 | Args args(value); |
| 2148 | const uint32_t argc = args.GetArgumentCount(); |
| 2149 | if (argc & 1 || argc == 0) |
| 2150 | { |
| 2151 | err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc); |
| 2152 | } |
| 2153 | else |
| 2154 | { |
| 2155 | char resolved_new_path[PATH_MAX]; |
| 2156 | FileSpec file_spec; |
| 2157 | const char *old_path; |
| 2158 | for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2) |
| 2159 | { |
| 2160 | const char *new_path = args.GetArgumentAtIndex(idx+1); |
| 2161 | assert (new_path); // We have an even number of paths, this shouldn't happen! |
| 2162 | |
| 2163 | file_spec.SetFile(new_path, true); |
| 2164 | if (file_spec.Exists()) |
| 2165 | { |
| 2166 | if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path)) |
| 2167 | { |
| 2168 | err.SetErrorStringWithFormat("new path '%s' is too long", new_path); |
| 2169 | return; |
| 2170 | } |
| 2171 | } |
| 2172 | else |
| 2173 | { |
| 2174 | err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path); |
| 2175 | return; |
| 2176 | } |
| 2177 | m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true); |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | break; |
| 2182 | |
| 2183 | case eVarSetOperationClear: |
| 2184 | m_source_map.Clear(true); |
| 2185 | break; |
| 2186 | } |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2187 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | void |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2191 | TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2192 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2193 | TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get()); |
| 2194 | |
| 2195 | if (!new_settings_ptr) |
| 2196 | return; |
| 2197 | |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2198 | m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file; |
| 2199 | m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp; |
| 2200 | m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value; |
| 2201 | m_skip_prologue = new_settings_ptr->m_skip_prologue; |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2202 | m_max_children_display = new_settings_ptr->m_max_children_display; |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2203 | m_max_strlen_length = new_settings_ptr->m_max_strlen_length; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
Caroline Tice | bcb5b45 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 2206 | bool |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2207 | TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 2208 | const ConstString &var_name, |
| 2209 | StringList &value, |
Caroline Tice | bcb5b45 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 2210 | Error *err) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2211 | { |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2212 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2213 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2214 | char path[PATH_MAX]; |
| 2215 | const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path)); |
| 2216 | if (path_len > 0) |
| 2217 | value.AppendString (path, path_len); |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2218 | } |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2219 | else if (var_name == GetSettingNameForPreferDynamicValue()) |
| 2220 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2221 | value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2222 | } |
Greg Clayton | 17cd995 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 2223 | else if (var_name == GetSettingNameForSkipPrologue()) |
| 2224 | { |
| 2225 | if (m_skip_prologue) |
| 2226 | value.AppendString ("true"); |
| 2227 | else |
| 2228 | value.AppendString ("false"); |
| 2229 | } |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 2230 | else if (var_name == GetSettingNameForSourcePathMap ()) |
| 2231 | { |
| 2232 | } |
Enrico Granata | 018921d | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2233 | else if (var_name == GetSettingNameForMaxChildren()) |
| 2234 | { |
| 2235 | StreamString count_str; |
| 2236 | count_str.Printf ("%d", m_max_children_display); |
| 2237 | value.AppendString (count_str.GetData()); |
| 2238 | } |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2239 | else if (var_name == GetSettingNameForMaxStringSummaryLength()) |
| 2240 | { |
| 2241 | StreamString count_str; |
| 2242 | count_str.Printf ("%d", m_max_strlen_length); |
| 2243 | value.AppendString (count_str.GetData()); |
| 2244 | } |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 2245 | else |
| 2246 | { |
| 2247 | if (err) |
| 2248 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 2249 | return false; |
| 2250 | } |
| 2251 | |
| 2252 | return true; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | const ConstString |
| 2256 | TargetInstanceSettings::CreateInstanceName () |
| 2257 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2258 | StreamString sstr; |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 2259 | static int instance_count = 1; |
| 2260 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2261 | sstr.Printf ("target_%d", instance_count); |
| 2262 | ++instance_count; |
| 2263 | |
| 2264 | const ConstString ret_val (sstr.GetData()); |
| 2265 | return ret_val; |
| 2266 | } |
| 2267 | |
| 2268 | //-------------------------------------------------- |
| 2269 | // Target::SettingsController Variable Tables |
| 2270 | //-------------------------------------------------- |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2271 | OptionEnumValueElement |
| 2272 | TargetInstanceSettings::g_dynamic_value_types[] = |
| 2273 | { |
Greg Clayton | 577fbc3 | 2011-05-30 00:39:48 +0000 | [diff] [blame] | 2274 | { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"}, |
| 2275 | { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."}, |
| 2276 | { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."}, |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2277 | { 0, NULL, NULL } |
| 2278 | }; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2279 | |
| 2280 | SettingEntry |
| 2281 | Target::SettingsController::global_settings_table[] = |
| 2282 | { |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 2283 | // var-name var-type default enum init'd hidden help-text |
| 2284 | // ================= ================== =========== ==== ====== ====== ========================================================================= |
| 2285 | { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." }, |
| 2286 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
| 2287 | }; |
| 2288 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2289 | SettingEntry |
| 2290 | Target::SettingsController::instance_settings_table[] = |
| 2291 | { |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2292 | // var-name var-type default enum init'd hidden help-text |
| 2293 | // ================= ================== =============== ======================= ====== ====== ========================================================================= |
| 2294 | { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." }, |
| 2295 | { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." }, |
| 2296 | { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." }, |
| 2297 | { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." }, |
| 2298 | { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." }, |
| 2299 | { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." }, |
| 2300 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2301 | }; |