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