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