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