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" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 23 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 24 | #include "lldb/Core/Timer.h" |
| 25 | #include "lldb/Core/ValueObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 26 | #include "lldb/Host/Host.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 27 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 28 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 29 | #include "lldb/lldb-private-log.h" |
| 30 | #include "lldb/Symbol/ObjectFile.h" |
| 31 | #include "lldb/Target/Process.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 32 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 33 | #include "lldb/Target/Thread.h" |
| 34 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 35 | |
| 36 | using namespace lldb; |
| 37 | using namespace lldb_private; |
| 38 | |
| 39 | //---------------------------------------------------------------------- |
| 40 | // Target constructor |
| 41 | //---------------------------------------------------------------------- |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 42 | Target::Target(Debugger &debugger, const lldb::PlatformSP &platform_sp) : |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 | [diff] [blame] | 43 | Broadcaster("lldb.target"), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 44 | m_platform_sp (platform_sp), |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 45 | TargetInstanceSettings (*GetSettingsController()), |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 | [diff] [blame] | 46 | m_debugger (debugger), |
Greg Clayton | af67cec | 2010-12-20 20:49:23 | [diff] [blame] | 47 | m_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 48 | m_images(), |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 49 | m_section_load_list (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 50 | m_breakpoint_list (false), |
| 51 | m_internal_breakpoint_list (true), |
| 52 | m_process_sp(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 53 | m_search_filter_sp(), |
| 54 | m_image_search_paths (ImageSearchPathsChanged, this), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 55 | m_scratch_ast_context_ap (NULL), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 56 | m_persistent_variables (), |
| 57 | m_stop_hook_next_id(0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 58 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 | [diff] [blame] | 59 | SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 60 | SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); |
| 61 | SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); |
| 62 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 63 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 64 | if (log) |
| 65 | log->Printf ("%p Target::Target()", this); |
| 66 | } |
| 67 | |
| 68 | //---------------------------------------------------------------------- |
| 69 | // Destructor |
| 70 | //---------------------------------------------------------------------- |
| 71 | Target::~Target() |
| 72 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 73 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 74 | if (log) |
| 75 | log->Printf ("%p Target::~Target()", this); |
| 76 | DeleteCurrentProcess (); |
| 77 | } |
| 78 | |
| 79 | void |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 80 | Target::Dump (Stream *s, lldb::DescriptionLevel description_level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 81 | { |
Greg Clayton | 8941142 | 2010-10-08 00:21:05 | [diff] [blame] | 82 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 83 | if (description_level != lldb::eDescriptionLevelBrief) |
| 84 | { |
| 85 | s->Indent(); |
| 86 | s->PutCString("Target\n"); |
| 87 | s->IndentMore(); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 | [diff] [blame] | 88 | m_images.Dump(s); |
| 89 | m_breakpoint_list.Dump(s); |
| 90 | m_internal_breakpoint_list.Dump(s); |
| 91 | s->IndentLess(); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 92 | } |
| 93 | else |
| 94 | { |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 | [diff] [blame] | 95 | s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 | [diff] [blame] | 96 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void |
| 100 | Target::DeleteCurrentProcess () |
| 101 | { |
| 102 | if (m_process_sp.get()) |
| 103 | { |
Greg Clayton | 17f6920 | 2010-09-14 23:52:43 | [diff] [blame] | 104 | m_section_load_list.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 105 | if (m_process_sp->IsAlive()) |
| 106 | m_process_sp->Destroy(); |
Jim Ingham | d0a3e12b | 2011-02-16 17:54:55 | [diff] [blame] | 107 | |
| 108 | m_process_sp->Finalize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 109 | |
| 110 | // Do any cleanup of the target we need to do between process instances. |
| 111 | // NB It is better to do this before destroying the process in case the |
| 112 | // clean up needs some help from the process. |
| 113 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 114 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
| 115 | m_process_sp.reset(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | const lldb::ProcessSP & |
| 120 | Target::CreateProcess (Listener &listener, const char *plugin_name) |
| 121 | { |
| 122 | DeleteCurrentProcess (); |
| 123 | m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener)); |
| 124 | return m_process_sp; |
| 125 | } |
| 126 | |
| 127 | const lldb::ProcessSP & |
| 128 | Target::GetProcessSP () const |
| 129 | { |
| 130 | return m_process_sp; |
| 131 | } |
| 132 | |
| 133 | lldb::TargetSP |
| 134 | Target::GetSP() |
| 135 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 | [diff] [blame] | 136 | return m_debugger.GetTargetList().GetTargetSP(this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | BreakpointList & |
| 140 | Target::GetBreakpointList(bool internal) |
| 141 | { |
| 142 | if (internal) |
| 143 | return m_internal_breakpoint_list; |
| 144 | else |
| 145 | return m_breakpoint_list; |
| 146 | } |
| 147 | |
| 148 | const BreakpointList & |
| 149 | Target::GetBreakpointList(bool internal) const |
| 150 | { |
| 151 | if (internal) |
| 152 | return m_internal_breakpoint_list; |
| 153 | else |
| 154 | return m_breakpoint_list; |
| 155 | } |
| 156 | |
| 157 | BreakpointSP |
| 158 | Target::GetBreakpointByID (break_id_t break_id) |
| 159 | { |
| 160 | BreakpointSP bp_sp; |
| 161 | |
| 162 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 163 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 164 | else |
| 165 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 166 | |
| 167 | return bp_sp; |
| 168 | } |
| 169 | |
| 170 | BreakpointSP |
| 171 | Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal) |
| 172 | { |
| 173 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 174 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines)); |
| 175 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | BreakpointSP |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 180 | Target::CreateBreakpoint (lldb::addr_t addr, bool internal) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 181 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 182 | Address so_addr; |
| 183 | // Attempt to resolve our load address if possible, though it is ok if |
| 184 | // it doesn't resolve to section/offset. |
| 185 | |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 186 | // Try and resolve as a load address if possible |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 187 | m_section_load_list.ResolveLoadAddress(addr, so_addr); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 | [diff] [blame] | 188 | if (!so_addr.IsValid()) |
| 189 | { |
| 190 | // The address didn't resolve, so just set this as an absolute address |
| 191 | so_addr.SetOffset (addr); |
| 192 | } |
| 193 | BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 194 | return bp_sp; |
| 195 | } |
| 196 | |
| 197 | BreakpointSP |
| 198 | Target::CreateBreakpoint (Address &addr, bool internal) |
| 199 | { |
| 200 | TargetSP target_sp = this->GetSP(); |
| 201 | SearchFilterSP filter_sp(new SearchFilter (target_sp)); |
| 202 | BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); |
| 203 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 204 | } |
| 205 | |
| 206 | BreakpointSP |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 | [diff] [blame] | 207 | Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 208 | { |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 | [diff] [blame] | 209 | BreakpointSP bp_sp; |
| 210 | if (func_name) |
| 211 | { |
| 212 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 213 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact)); |
| 214 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 215 | } |
| 216 | return bp_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | SearchFilterSP |
| 221 | Target::GetSearchFilterForModule (const FileSpec *containingModule) |
| 222 | { |
| 223 | SearchFilterSP filter_sp; |
| 224 | lldb::TargetSP target_sp = this->GetSP(); |
| 225 | if (containingModule != NULL) |
| 226 | { |
| 227 | // TODO: We should look into sharing module based search filters |
| 228 | // across many breakpoints like we do for the simple target based one |
| 229 | filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule)); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | if (m_search_filter_sp.get() == NULL) |
| 234 | m_search_filter_sp.reset (new SearchFilter (target_sp)); |
| 235 | filter_sp = m_search_filter_sp; |
| 236 | } |
| 237 | return filter_sp; |
| 238 | } |
| 239 | |
| 240 | BreakpointSP |
| 241 | Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal) |
| 242 | { |
| 243 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 244 | BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex)); |
| 245 | |
| 246 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 247 | } |
| 248 | |
| 249 | BreakpointSP |
| 250 | Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal) |
| 251 | { |
| 252 | BreakpointSP bp_sp; |
| 253 | if (filter_sp && resolver_sp) |
| 254 | { |
| 255 | bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp)); |
| 256 | resolver_sp->SetBreakpoint (bp_sp.get()); |
| 257 | |
| 258 | if (internal) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 259 | m_internal_breakpoint_list.Add (bp_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 260 | else |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 261 | m_breakpoint_list.Add (bp_sp, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 262 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 263 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 264 | if (log) |
| 265 | { |
| 266 | StreamString s; |
| 267 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
| 268 | log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); |
| 269 | } |
| 270 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 271 | bp_sp->ResolveBreakpoint(); |
| 272 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 273 | |
| 274 | if (!internal && bp_sp) |
| 275 | { |
| 276 | m_last_created_breakpoint = bp_sp; |
| 277 | } |
| 278 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 279 | return bp_sp; |
| 280 | } |
| 281 | |
| 282 | void |
| 283 | Target::RemoveAllBreakpoints (bool internal_also) |
| 284 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 285 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 286 | if (log) |
| 287 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 288 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 289 | m_breakpoint_list.RemoveAll (true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 290 | if (internal_also) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 291 | m_internal_breakpoint_list.RemoveAll (false); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 292 | |
| 293 | m_last_created_breakpoint.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void |
| 297 | Target::DisableAllBreakpoints (bool internal_also) |
| 298 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 299 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 300 | if (log) |
| 301 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 302 | |
| 303 | m_breakpoint_list.SetEnabledAll (false); |
| 304 | if (internal_also) |
| 305 | m_internal_breakpoint_list.SetEnabledAll (false); |
| 306 | } |
| 307 | |
| 308 | void |
| 309 | Target::EnableAllBreakpoints (bool internal_also) |
| 310 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 311 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 312 | if (log) |
| 313 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 314 | |
| 315 | m_breakpoint_list.SetEnabledAll (true); |
| 316 | if (internal_also) |
| 317 | m_internal_breakpoint_list.SetEnabledAll (true); |
| 318 | } |
| 319 | |
| 320 | bool |
| 321 | Target::RemoveBreakpointByID (break_id_t break_id) |
| 322 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 323 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 324 | if (log) |
| 325 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 326 | |
| 327 | if (DisableBreakpointByID (break_id)) |
| 328 | { |
| 329 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 330 | m_internal_breakpoint_list.Remove(break_id, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 331 | else |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 332 | { |
Greg Clayton | aa1c587 | 2011-01-24 23:35:47 | [diff] [blame] | 333 | if (m_last_created_breakpoint) |
| 334 | { |
| 335 | if (m_last_created_breakpoint->GetID() == break_id) |
| 336 | m_last_created_breakpoint.reset(); |
| 337 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 | [diff] [blame] | 338 | m_breakpoint_list.Remove(break_id, true); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 | [diff] [blame] | 339 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 340 | return true; |
| 341 | } |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | bool |
| 346 | Target::DisableBreakpointByID (break_id_t break_id) |
| 347 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 348 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 349 | if (log) |
| 350 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 351 | |
| 352 | BreakpointSP bp_sp; |
| 353 | |
| 354 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 355 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 356 | else |
| 357 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 358 | if (bp_sp) |
| 359 | { |
| 360 | bp_sp->SetEnabled (false); |
| 361 | return true; |
| 362 | } |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | bool |
| 367 | Target::EnableBreakpointByID (break_id_t break_id) |
| 368 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 369 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 370 | if (log) |
| 371 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", |
| 372 | __FUNCTION__, |
| 373 | break_id, |
| 374 | LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 375 | |
| 376 | BreakpointSP bp_sp; |
| 377 | |
| 378 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 379 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 380 | else |
| 381 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 382 | |
| 383 | if (bp_sp) |
| 384 | { |
| 385 | bp_sp->SetEnabled (true); |
| 386 | return true; |
| 387 | } |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | ModuleSP |
| 392 | Target::GetExecutableModule () |
| 393 | { |
| 394 | ModuleSP executable_sp; |
| 395 | if (m_images.GetSize() > 0) |
| 396 | executable_sp = m_images.GetModuleAtIndex(0); |
| 397 | return executable_sp; |
| 398 | } |
| 399 | |
| 400 | void |
| 401 | Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) |
| 402 | { |
| 403 | m_images.Clear(); |
| 404 | m_scratch_ast_context_ap.reset(); |
| 405 | |
| 406 | if (executable_sp.get()) |
| 407 | { |
| 408 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 409 | "Target::SetExecutableModule (executable = '%s/%s')", |
| 410 | executable_sp->GetFileSpec().GetDirectory().AsCString(), |
| 411 | executable_sp->GetFileSpec().GetFilename().AsCString()); |
| 412 | |
| 413 | m_images.Append(executable_sp); // The first image is our exectuable file |
| 414 | |
| 415 | ArchSpec exe_arch = executable_sp->GetArchitecture(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 416 | // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. |
| 417 | if (!m_arch_spec.IsValid()) |
| 418 | m_arch_spec = exe_arch; |
| 419 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 420 | FileSpecList dependent_files; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 | [diff] [blame] | 421 | ObjectFile *executable_objfile = executable_sp->GetObjectFile(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 422 | |
| 423 | if (executable_objfile) |
| 424 | { |
| 425 | executable_objfile->GetDependentModules(dependent_files); |
| 426 | for (uint32_t i=0; i<dependent_files.GetSize(); i++) |
| 427 | { |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 428 | FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i)); |
| 429 | FileSpec platform_dependent_file_spec; |
| 430 | if (m_platform_sp) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 | [diff] [blame] | 431 | m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 | [diff] [blame] | 432 | else |
| 433 | platform_dependent_file_spec = dependent_file_spec; |
| 434 | |
| 435 | ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec, |
| 436 | exe_arch)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 437 | if (image_module_sp.get()) |
| 438 | { |
| 439 | //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY |
| 440 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 441 | if (objfile) |
| 442 | objfile->GetDependentModules(dependent_files); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | // Now see if we know the target triple, and if so, create our scratch AST context: |
Greg Clayton | 514487e | 2011-02-15 21:59:32 | [diff] [blame] | 448 | if (m_arch_spec.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 449 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 | [diff] [blame] | 450 | m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch_spec.GetTriple().str().c_str())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 451 | } |
| 452 | } |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 453 | |
| 454 | UpdateInstanceName(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 458 | bool |
| 459 | Target::SetArchitecture (const ArchSpec &arch_spec) |
| 460 | { |
| 461 | if (m_arch_spec == arch_spec) |
| 462 | { |
| 463 | // If we're setting the architecture to our current architecture, we |
| 464 | // don't need to do anything. |
| 465 | return true; |
| 466 | } |
| 467 | else if (!m_arch_spec.IsValid()) |
| 468 | { |
| 469 | // If we haven't got a valid arch spec, then we just need to set it. |
| 470 | m_arch_spec = arch_spec; |
| 471 | return true; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | // If we have an executable file, try to reset the executable to the desired architecture |
| 476 | m_arch_spec = arch_spec; |
| 477 | ModuleSP executable_sp = GetExecutableModule (); |
| 478 | m_images.Clear(); |
| 479 | m_scratch_ast_context_ap.reset(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 | [diff] [blame] | 480 | // Need to do something about unsetting breakpoints. |
| 481 | |
| 482 | if (executable_sp) |
| 483 | { |
| 484 | FileSpec exec_file_spec = executable_sp->GetFileSpec(); |
| 485 | Error error = ModuleList::GetSharedModule(exec_file_spec, |
| 486 | arch_spec, |
| 487 | NULL, |
| 488 | NULL, |
| 489 | 0, |
| 490 | executable_sp, |
| 491 | NULL, |
| 492 | NULL); |
| 493 | |
| 494 | if (!error.Fail() && executable_sp) |
| 495 | { |
| 496 | SetExecutableModule (executable_sp, true); |
| 497 | return true; |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | return false; |
| 502 | } |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | return false; |
| 507 | } |
| 508 | } |
| 509 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 510 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 511 | void |
| 512 | Target::ModuleAdded (ModuleSP &module_sp) |
| 513 | { |
| 514 | // A module is being added to this target for the first time |
| 515 | ModuleList module_list; |
| 516 | module_list.Append(module_sp); |
| 517 | ModulesDidLoad (module_list); |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) |
| 522 | { |
| 523 | // A module is being added to this target for the first time |
| 524 | ModuleList module_list; |
| 525 | module_list.Append (old_module_sp); |
| 526 | ModulesDidUnload (module_list); |
| 527 | module_list.Clear (); |
| 528 | module_list.Append (new_module_sp); |
| 529 | ModulesDidLoad (module_list); |
| 530 | } |
| 531 | |
| 532 | void |
| 533 | Target::ModulesDidLoad (ModuleList &module_list) |
| 534 | { |
| 535 | m_breakpoint_list.UpdateBreakpoints (module_list, true); |
| 536 | // TODO: make event data that packages up the module_list |
| 537 | BroadcastEvent (eBroadcastBitModulesLoaded, NULL); |
| 538 | } |
| 539 | |
| 540 | void |
| 541 | Target::ModulesDidUnload (ModuleList &module_list) |
| 542 | { |
| 543 | m_breakpoint_list.UpdateBreakpoints (module_list, false); |
Greg Clayton | a4d7830 | 2010-12-06 23:51:26 | [diff] [blame] | 544 | |
| 545 | // Remove the images from the target image list |
| 546 | m_images.Remove(module_list); |
| 547 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 548 | // TODO: make event data that packages up the module_list |
| 549 | BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); |
| 550 | } |
| 551 | |
| 552 | size_t |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 553 | Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error) |
| 554 | { |
| 555 | const Section *section = addr.GetSection(); |
| 556 | if (section && section->GetModule()) |
| 557 | { |
| 558 | ObjectFile *objfile = section->GetModule()->GetObjectFile(); |
| 559 | if (objfile) |
| 560 | { |
| 561 | size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile, |
| 562 | addr.GetOffset(), |
| 563 | dst, |
| 564 | dst_len); |
| 565 | if (bytes_read > 0) |
| 566 | return bytes_read; |
| 567 | else |
| 568 | error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString()); |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | error.SetErrorString("address isn't from a object file"); |
| 573 | } |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | error.SetErrorString("address doesn't contain a section that points to a section in a object file"); |
| 578 | } |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | size_t |
| 583 | Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size_t dst_len, Error &error) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 584 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 585 | error.Clear(); |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 586 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 587 | bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); |
| 588 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 589 | size_t bytes_read = 0; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 | [diff] [blame^] | 590 | Address resolved_addr; |
| 591 | if (!addr.IsSectionOffset()) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 592 | { |
| 593 | if (process_is_valid) |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 594 | m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 595 | else |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 596 | m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 597 | } |
Greg Clayton | 357132e | 2011-03-26 19:14:58 | [diff] [blame^] | 598 | if (!resolved_addr.IsValid()) |
| 599 | resolved_addr = addr; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 600 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 601 | if (prefer_file_cache) |
| 602 | { |
| 603 | bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
| 604 | if (bytes_read > 0) |
| 605 | return bytes_read; |
| 606 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 607 | |
| 608 | if (process_is_valid) |
| 609 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 610 | lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 611 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 612 | { |
| 613 | if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) |
| 614 | error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n", |
| 615 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), |
| 616 | resolved_addr.GetFileAddress()); |
| 617 | else |
| 618 | error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress()); |
| 619 | } |
| 620 | else |
| 621 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 622 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 623 | if (bytes_read != dst_len) |
| 624 | { |
| 625 | if (error.Success()) |
| 626 | { |
| 627 | if (bytes_read == 0) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 628 | error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 629 | else |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 630 | 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] | 631 | } |
| 632 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 633 | if (bytes_read) |
| 634 | return bytes_read; |
| 635 | // If the address is not section offset we have an address that |
| 636 | // doesn't resolve to any address in any currently loaded shared |
| 637 | // libaries and we failed to read memory so there isn't anything |
| 638 | // more we can do. If it is section offset, we might be able to |
| 639 | // read cached memory from the object file. |
| 640 | if (!resolved_addr.IsSectionOffset()) |
| 641 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 642 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 643 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 644 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 645 | if (!prefer_file_cache) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 646 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 647 | // If we didn't already try and read from the object file cache, then |
| 648 | // try it after failing to read from the process. |
| 649 | return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 650 | } |
| 651 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
| 655 | ModuleSP |
| 656 | Target::GetSharedModule |
| 657 | ( |
| 658 | const FileSpec& file_spec, |
| 659 | const ArchSpec& arch, |
Greg Clayton | 6083026 | 2011-02-04 18:53:10 | [diff] [blame] | 660 | const lldb_private::UUID *uuid_ptr, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 661 | const ConstString *object_name, |
| 662 | off_t object_offset, |
| 663 | Error *error_ptr |
| 664 | ) |
| 665 | { |
| 666 | // Don't pass in the UUID so we can tell if we have a stale value in our list |
| 667 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 668 | bool did_create_module = false; |
| 669 | ModuleSP module_sp; |
| 670 | |
| 671 | // If there are image search path entries, try to use them first to acquire a suitable image. |
| 672 | |
| 673 | Error error; |
| 674 | |
| 675 | if (m_image_search_paths.GetSize()) |
| 676 | { |
| 677 | FileSpec transformed_spec; |
| 678 | if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory())) |
| 679 | { |
| 680 | transformed_spec.GetFilename() = file_spec.GetFilename(); |
| 681 | error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | // If a module hasn't been found yet, use the unmodified path. |
| 686 | |
| 687 | if (!module_sp) |
| 688 | { |
| 689 | error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module)); |
| 690 | } |
| 691 | |
| 692 | if (module_sp) |
| 693 | { |
| 694 | m_images.Append (module_sp); |
| 695 | if (did_create_module) |
| 696 | { |
| 697 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 698 | ModuleUpdated(old_module_sp, module_sp); |
| 699 | else |
| 700 | ModuleAdded(module_sp); |
| 701 | } |
| 702 | } |
| 703 | if (error_ptr) |
| 704 | *error_ptr = error; |
| 705 | return module_sp; |
| 706 | } |
| 707 | |
| 708 | |
| 709 | Target * |
| 710 | Target::CalculateTarget () |
| 711 | { |
| 712 | return this; |
| 713 | } |
| 714 | |
| 715 | Process * |
| 716 | Target::CalculateProcess () |
| 717 | { |
| 718 | return NULL; |
| 719 | } |
| 720 | |
| 721 | Thread * |
| 722 | Target::CalculateThread () |
| 723 | { |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | StackFrame * |
| 728 | Target::CalculateStackFrame () |
| 729 | { |
| 730 | return NULL; |
| 731 | } |
| 732 | |
| 733 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 734 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 735 | { |
| 736 | exe_ctx.target = this; |
| 737 | exe_ctx.process = NULL; // Do NOT fill in process... |
| 738 | exe_ctx.thread = NULL; |
| 739 | exe_ctx.frame = NULL; |
| 740 | } |
| 741 | |
| 742 | PathMappingList & |
| 743 | Target::GetImageSearchPathList () |
| 744 | { |
| 745 | return m_image_search_paths; |
| 746 | } |
| 747 | |
| 748 | void |
| 749 | Target::ImageSearchPathsChanged |
| 750 | ( |
| 751 | const PathMappingList &path_list, |
| 752 | void *baton |
| 753 | ) |
| 754 | { |
| 755 | Target *target = (Target *)baton; |
| 756 | if (target->m_images.GetSize() > 1) |
| 757 | { |
| 758 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 759 | if (exe_module_sp) |
| 760 | { |
| 761 | target->m_images.Clear(); |
| 762 | target->SetExecutableModule (exe_module_sp, true); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | ClangASTContext * |
| 768 | Target::GetScratchClangASTContext() |
| 769 | { |
| 770 | return m_scratch_ast_context_ap.get(); |
| 771 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 772 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 773 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 774 | Target::SettingsInitialize () |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 775 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 776 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 777 | usc.reset (new SettingsController); |
| 778 | UserSettingsController::InitializeSettingsController (usc, |
| 779 | SettingsController::global_settings_table, |
| 780 | SettingsController::instance_settings_table); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 781 | |
| 782 | // Now call SettingsInitialize() on each 'child' setting of Target |
| 783 | Process::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 784 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 785 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 786 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 787 | Target::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 788 | { |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 789 | |
| 790 | // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings. |
| 791 | |
| 792 | Process::SettingsTerminate (); |
| 793 | |
| 794 | // Now terminate Target Settings. |
| 795 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 796 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 797 | UserSettingsController::FinalizeSettingsController (usc); |
| 798 | usc.reset(); |
| 799 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 800 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 801 | UserSettingsControllerSP & |
| 802 | Target::GetSettingsController () |
| 803 | { |
| 804 | static UserSettingsControllerSP g_settings_controller; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 805 | return g_settings_controller; |
| 806 | } |
| 807 | |
| 808 | ArchSpec |
| 809 | Target::GetDefaultArchitecture () |
| 810 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 811 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 812 | |
| 813 | if (settings_controller_sp) |
| 814 | return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture (); |
| 815 | return ArchSpec(); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | void |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 819 | Target::SetDefaultArchitecture (const ArchSpec& arch) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 820 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 821 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 822 | |
| 823 | if (settings_controller_sp) |
| 824 | static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 825 | } |
| 826 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 827 | Target * |
| 828 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 829 | { |
| 830 | // The target can either exist in the "process" of ExecutionContext, or in |
| 831 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 832 | // will get the target from one of these locations. |
| 833 | |
| 834 | Target *target = NULL; |
| 835 | if (sc_ptr != NULL) |
| 836 | target = sc_ptr->target_sp.get(); |
| 837 | if (target == NULL) |
| 838 | { |
| 839 | if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL) |
| 840 | target = &exe_ctx_ptr->process->GetTarget(); |
| 841 | } |
| 842 | return target; |
| 843 | } |
| 844 | |
| 845 | |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 846 | void |
| 847 | Target::UpdateInstanceName () |
| 848 | { |
| 849 | StreamString sstr; |
| 850 | |
| 851 | ModuleSP module_sp = GetExecutableModule(); |
| 852 | if (module_sp) |
| 853 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 854 | sstr.Printf ("%s_%s", |
| 855 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 856 | module_sp->GetArchitecture().GetArchitectureName()); |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 857 | GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), |
| 858 | sstr.GetData()); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 862 | const char * |
| 863 | Target::GetExpressionPrefixContentsAsCString () |
| 864 | { |
| 865 | return m_expr_prefix_contents.c_str(); |
| 866 | } |
| 867 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 868 | ExecutionResults |
| 869 | Target::EvaluateExpression |
| 870 | ( |
| 871 | const char *expr_cstr, |
| 872 | StackFrame *frame, |
| 873 | bool unwind_on_error, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 874 | bool keep_in_memory, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 875 | lldb::ValueObjectSP &result_valobj_sp |
| 876 | ) |
| 877 | { |
| 878 | ExecutionResults execution_results = eExecutionSetupError; |
| 879 | |
| 880 | result_valobj_sp.reset(); |
| 881 | |
| 882 | ExecutionContext exe_ctx; |
| 883 | if (frame) |
| 884 | { |
| 885 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 | [diff] [blame] | 886 | Error error; |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 | [diff] [blame] | 887 | const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
| 888 | StackFrame::eExpressionPathOptionsNoFragileObjcIvar; |
| 889 | result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, expr_path_options, error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 890 | } |
| 891 | else if (m_process_sp) |
| 892 | { |
| 893 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 894 | } |
| 895 | else |
| 896 | { |
| 897 | CalculateExecutionContext(exe_ctx); |
| 898 | } |
| 899 | |
| 900 | if (result_valobj_sp) |
| 901 | { |
| 902 | execution_results = eExecutionCompleted; |
| 903 | // We got a result from the frame variable expression path above... |
| 904 | ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName()); |
| 905 | |
| 906 | lldb::ValueObjectSP const_valobj_sp; |
| 907 | |
| 908 | // Check in case our value is already a constant value |
| 909 | if (result_valobj_sp->GetIsConstant()) |
| 910 | { |
| 911 | const_valobj_sp = result_valobj_sp; |
| 912 | const_valobj_sp->SetName (persistent_variable_name); |
| 913 | } |
| 914 | else |
| 915 | const_valobj_sp = result_valobj_sp->CreateConstantValue (exe_ctx.GetBestExecutionContextScope(), |
| 916 | persistent_variable_name); |
| 917 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 918 | lldb::ValueObjectSP live_valobj_sp = result_valobj_sp; |
| 919 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 920 | result_valobj_sp = const_valobj_sp; |
| 921 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 922 | ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp)); |
| 923 | assert (clang_expr_variable_sp.get()); |
| 924 | |
| 925 | // Set flags and live data as appropriate |
| 926 | |
| 927 | const Value &result_value = live_valobj_sp->GetValue(); |
| 928 | |
| 929 | switch (result_value.GetValueType()) |
| 930 | { |
| 931 | case Value::eValueTypeHostAddress: |
| 932 | case Value::eValueTypeFileAddress: |
| 933 | // we don't do anything with these for now |
| 934 | break; |
| 935 | case Value::eValueTypeScalar: |
| 936 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated; |
| 937 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation; |
| 938 | break; |
| 939 | case Value::eValueTypeLoadAddress: |
| 940 | clang_expr_variable_sp->m_live_sp = live_valobj_sp; |
| 941 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference; |
| 942 | break; |
| 943 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 944 | } |
| 945 | else |
| 946 | { |
| 947 | // Make sure we aren't just trying to see the value of a persistent |
| 948 | // variable (something like "$0") |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 | [diff] [blame] | 949 | lldb::ClangExpressionVariableSP persistent_var_sp; |
| 950 | // Only check for persistent variables the expression starts with a '$' |
| 951 | if (expr_cstr[0] == '$') |
| 952 | persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); |
| 953 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 954 | if (persistent_var_sp) |
| 955 | { |
| 956 | result_valobj_sp = persistent_var_sp->GetValueObject (); |
| 957 | execution_results = eExecutionCompleted; |
| 958 | } |
| 959 | else |
| 960 | { |
| 961 | const char *prefix = GetExpressionPrefixContentsAsCString(); |
| 962 | |
| 963 | execution_results = ClangUserExpression::Evaluate (exe_ctx, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 964 | unwind_on_error, |
| 965 | keep_in_memory, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 966 | expr_cstr, |
| 967 | prefix, |
| 968 | result_valobj_sp); |
| 969 | } |
| 970 | } |
| 971 | return execution_results; |
| 972 | } |
| 973 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 974 | lldb::user_id_t |
| 975 | Target::AddStopHook (Target::StopHookSP &new_hook_sp) |
| 976 | { |
| 977 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
| 978 | new_hook_sp.reset (new StopHook(GetSP(), new_uid)); |
| 979 | m_stop_hooks[new_uid] = new_hook_sp; |
| 980 | return new_uid; |
| 981 | } |
| 982 | |
| 983 | bool |
| 984 | Target::RemoveStopHookByID (lldb::user_id_t user_id) |
| 985 | { |
| 986 | size_t num_removed; |
| 987 | num_removed = m_stop_hooks.erase (user_id); |
| 988 | if (num_removed == 0) |
| 989 | return false; |
| 990 | else |
| 991 | return true; |
| 992 | } |
| 993 | |
| 994 | void |
| 995 | Target::RemoveAllStopHooks () |
| 996 | { |
| 997 | m_stop_hooks.clear(); |
| 998 | } |
| 999 | |
| 1000 | Target::StopHookSP |
| 1001 | Target::GetStopHookByID (lldb::user_id_t user_id) |
| 1002 | { |
| 1003 | StopHookSP found_hook; |
| 1004 | |
| 1005 | StopHookCollection::iterator specified_hook_iter; |
| 1006 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1007 | if (specified_hook_iter != m_stop_hooks.end()) |
| 1008 | found_hook = (*specified_hook_iter).second; |
| 1009 | return found_hook; |
| 1010 | } |
| 1011 | |
| 1012 | bool |
| 1013 | Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) |
| 1014 | { |
| 1015 | StopHookCollection::iterator specified_hook_iter; |
| 1016 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1017 | if (specified_hook_iter == m_stop_hooks.end()) |
| 1018 | return false; |
| 1019 | |
| 1020 | (*specified_hook_iter).second->SetIsActive (active_state); |
| 1021 | return true; |
| 1022 | } |
| 1023 | |
| 1024 | void |
| 1025 | Target::SetAllStopHooksActiveState (bool active_state) |
| 1026 | { |
| 1027 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1028 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1029 | { |
| 1030 | (*pos).second->SetIsActive (active_state); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | void |
| 1035 | Target::RunStopHooks () |
| 1036 | { |
| 1037 | if (!m_process_sp) |
| 1038 | return; |
| 1039 | |
| 1040 | if (m_stop_hooks.empty()) |
| 1041 | return; |
| 1042 | |
| 1043 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1044 | |
| 1045 | // If there aren't any active stop hooks, don't bother either: |
| 1046 | bool any_active_hooks = false; |
| 1047 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1048 | { |
| 1049 | if ((*pos).second->IsActive()) |
| 1050 | { |
| 1051 | any_active_hooks = true; |
| 1052 | break; |
| 1053 | } |
| 1054 | } |
| 1055 | if (!any_active_hooks) |
| 1056 | return; |
| 1057 | |
| 1058 | CommandReturnObject result; |
| 1059 | |
| 1060 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 1061 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 1062 | |
| 1063 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 1064 | size_t num_threads = cur_threadlist.GetSize(); |
| 1065 | for (size_t i = 0; i < num_threads; i++) |
| 1066 | { |
| 1067 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); |
| 1068 | if (cur_thread_sp->ThreadStoppedForAReason()) |
| 1069 | { |
| 1070 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 1071 | exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 1072 | sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 1077 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 1078 | if (num_exe_ctx == 0) |
| 1079 | return; |
| 1080 | |
| 1081 | result.SetImmediateOutputFile (m_debugger.GetOutputFile().GetStream()); |
| 1082 | result.SetImmediateErrorFile (m_debugger.GetErrorFile().GetStream()); |
| 1083 | |
| 1084 | bool keep_going = true; |
| 1085 | bool hooks_ran = false; |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1086 | bool print_hook_header; |
| 1087 | bool print_thread_header; |
| 1088 | |
| 1089 | if (num_exe_ctx == 1) |
| 1090 | print_thread_header = false; |
| 1091 | else |
| 1092 | print_thread_header = true; |
| 1093 | |
| 1094 | if (m_stop_hooks.size() == 1) |
| 1095 | print_hook_header = false; |
| 1096 | else |
| 1097 | print_hook_header = true; |
| 1098 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1099 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) |
| 1100 | { |
| 1101 | // result.Clear(); |
| 1102 | StopHookSP cur_hook_sp = (*pos).second; |
| 1103 | if (!cur_hook_sp->IsActive()) |
| 1104 | continue; |
| 1105 | |
| 1106 | bool any_thread_matched = false; |
| 1107 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) |
| 1108 | { |
| 1109 | if ((cur_hook_sp->GetSpecifier () == NULL |
| 1110 | || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) |
| 1111 | && (cur_hook_sp->GetThreadSpecifier() == NULL |
| 1112 | || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread))) |
| 1113 | { |
| 1114 | if (!hooks_ran) |
| 1115 | { |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1116 | result.AppendMessage("\n** Stop Hooks **"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1117 | hooks_ran = true; |
| 1118 | } |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1119 | if (print_hook_header && !any_thread_matched) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1120 | { |
| 1121 | result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID()); |
| 1122 | any_thread_matched = true; |
| 1123 | } |
| 1124 | |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1125 | if (print_thread_header) |
| 1126 | result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1127 | |
| 1128 | bool stop_on_continue = true; |
| 1129 | bool stop_on_error = true; |
| 1130 | bool echo_commands = false; |
| 1131 | bool print_results = true; |
| 1132 | GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), |
| 1133 | &exc_ctx_with_reasons[i], |
| 1134 | stop_on_continue, |
| 1135 | stop_on_error, |
| 1136 | echo_commands, |
| 1137 | print_results, |
| 1138 | result); |
| 1139 | |
| 1140 | // If the command started the target going again, we should bag out of |
| 1141 | // running the stop hooks. |
| 1142 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) |
| 1143 | || (result.GetStatus() == eReturnStatusSuccessContinuingResult)) |
| 1144 | { |
| 1145 | result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID()); |
| 1146 | keep_going = false; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | if (hooks_ran) |
| 1152 | result.AppendMessage ("\n** End Stop Hooks **\n"); |
| 1153 | } |
| 1154 | |
| 1155 | //-------------------------------------------------------------- |
| 1156 | // class Target::StopHook |
| 1157 | //-------------------------------------------------------------- |
| 1158 | |
| 1159 | |
| 1160 | Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : |
| 1161 | UserID (uid), |
| 1162 | m_target_sp (target_sp), |
| 1163 | m_active (true), |
| 1164 | m_commands (), |
| 1165 | m_specifier_sp (), |
| 1166 | m_thread_spec_ap(NULL) |
| 1167 | { |
| 1168 | } |
| 1169 | |
| 1170 | Target::StopHook::StopHook (const StopHook &rhs) : |
| 1171 | UserID (rhs.GetID()), |
| 1172 | m_target_sp (rhs.m_target_sp), |
| 1173 | m_commands (rhs.m_commands), |
| 1174 | m_specifier_sp (rhs.m_specifier_sp), |
| 1175 | m_active (rhs.m_active), |
| 1176 | m_thread_spec_ap (NULL) |
| 1177 | { |
| 1178 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 1179 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | Target::StopHook::~StopHook () |
| 1184 | { |
| 1185 | } |
| 1186 | |
| 1187 | void |
| 1188 | Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier) |
| 1189 | { |
| 1190 | m_thread_spec_ap.reset (specifier); |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | void |
| 1195 | Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 1196 | { |
| 1197 | int indent_level = s->GetIndentLevel(); |
| 1198 | |
| 1199 | s->SetIndentLevel(indent_level + 2); |
| 1200 | |
| 1201 | s->Printf ("Hook: %d\n", GetID()); |
| 1202 | if (m_active) |
| 1203 | s->Indent ("State: enabled\n"); |
| 1204 | else |
| 1205 | s->Indent ("State: disabled\n"); |
| 1206 | |
| 1207 | if (m_specifier_sp) |
| 1208 | { |
| 1209 | s->Indent(); |
| 1210 | s->PutCString ("Specifier:\n"); |
| 1211 | s->SetIndentLevel (indent_level + 4); |
| 1212 | m_specifier_sp->GetDescription (s, level); |
| 1213 | s->SetIndentLevel (indent_level + 2); |
| 1214 | } |
| 1215 | |
| 1216 | if (m_thread_spec_ap.get() != NULL) |
| 1217 | { |
| 1218 | StreamString tmp; |
| 1219 | s->Indent("Thread:\n"); |
| 1220 | m_thread_spec_ap->GetDescription (&tmp, level); |
| 1221 | s->SetIndentLevel (indent_level + 4); |
| 1222 | s->Indent (tmp.GetData()); |
| 1223 | s->PutCString ("\n"); |
| 1224 | s->SetIndentLevel (indent_level + 2); |
| 1225 | } |
| 1226 | |
| 1227 | s->Indent ("Commands: \n"); |
| 1228 | s->SetIndentLevel (indent_level + 4); |
| 1229 | uint32_t num_commands = m_commands.GetSize(); |
| 1230 | for (uint32_t i = 0; i < num_commands; i++) |
| 1231 | { |
| 1232 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 1233 | s->PutCString ("\n"); |
| 1234 | } |
| 1235 | s->SetIndentLevel (indent_level); |
| 1236 | } |
| 1237 | |
| 1238 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1239 | //-------------------------------------------------------------- |
| 1240 | // class Target::SettingsController |
| 1241 | //-------------------------------------------------------------- |
| 1242 | |
| 1243 | Target::SettingsController::SettingsController () : |
| 1244 | UserSettingsController ("target", Debugger::GetSettingsController()), |
| 1245 | m_default_architecture () |
| 1246 | { |
| 1247 | m_default_settings.reset (new TargetInstanceSettings (*this, false, |
| 1248 | InstanceSettings::GetDefaultName().AsCString())); |
| 1249 | } |
| 1250 | |
| 1251 | Target::SettingsController::~SettingsController () |
| 1252 | { |
| 1253 | } |
| 1254 | |
| 1255 | lldb::InstanceSettingsSP |
| 1256 | Target::SettingsController::CreateInstanceSettings (const char *instance_name) |
| 1257 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 1258 | TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(), |
| 1259 | false, |
| 1260 | instance_name); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1261 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 1262 | return new_settings_sp; |
| 1263 | } |
| 1264 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1265 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1266 | #define TSC_DEFAULT_ARCH "default-arch" |
| 1267 | #define TSC_EXPR_PREFIX "expr-prefix" |
| 1268 | #define TSC_EXEC_LEVEL "execution-level" |
| 1269 | #define TSC_EXEC_MODE "execution-mode" |
| 1270 | #define TSC_EXEC_OS_TYPE "execution-os-type" |
| 1271 | |
| 1272 | |
| 1273 | static const ConstString & |
| 1274 | GetSettingNameForDefaultArch () |
| 1275 | { |
| 1276 | static ConstString g_const_string (TSC_DEFAULT_ARCH); |
| 1277 | |
| 1278 | return g_const_string; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1279 | } |
| 1280 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1281 | static const ConstString & |
| 1282 | GetSettingNameForExpressionPrefix () |
| 1283 | { |
| 1284 | static ConstString g_const_string (TSC_EXPR_PREFIX); |
| 1285 | return g_const_string; |
| 1286 | } |
| 1287 | |
| 1288 | static const ConstString & |
| 1289 | GetSettingNameForExecutionLevel () |
| 1290 | { |
| 1291 | static ConstString g_const_string (TSC_EXEC_LEVEL); |
| 1292 | return g_const_string; |
| 1293 | } |
| 1294 | |
| 1295 | static const ConstString & |
| 1296 | GetSettingNameForExecutionMode () |
| 1297 | { |
| 1298 | static ConstString g_const_string (TSC_EXEC_MODE); |
| 1299 | return g_const_string; |
| 1300 | } |
| 1301 | |
| 1302 | static const ConstString & |
| 1303 | GetSettingNameForExecutionOSType () |
| 1304 | { |
| 1305 | static ConstString g_const_string (TSC_EXEC_OS_TYPE); |
| 1306 | return g_const_string; |
| 1307 | } |
| 1308 | |
| 1309 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1310 | bool |
| 1311 | Target::SettingsController::SetGlobalVariable (const ConstString &var_name, |
| 1312 | const char *index_value, |
| 1313 | const char *value, |
| 1314 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1315 | const VarSetOperationType op, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1316 | Error&err) |
| 1317 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1318 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1319 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1320 | m_default_architecture.SetTriple (value); |
| 1321 | if (!m_default_architecture.IsValid()) |
| 1322 | err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1323 | } |
| 1324 | return true; |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | bool |
| 1329 | Target::SettingsController::GetGlobalVariable (const ConstString &var_name, |
| 1330 | StringList &value, |
| 1331 | Error &err) |
| 1332 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1333 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1334 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 1335 | // If the arch is invalid (the default), don't show a string for it |
| 1336 | if (m_default_architecture.IsValid()) |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1337 | value.AppendString (m_default_architecture.GetArchitectureName()); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1338 | return true; |
| 1339 | } |
| 1340 | else |
| 1341 | err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1342 | |
| 1343 | return false; |
| 1344 | } |
| 1345 | |
| 1346 | //-------------------------------------------------------------- |
| 1347 | // class TargetInstanceSettings |
| 1348 | //-------------------------------------------------------------- |
| 1349 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 | [diff] [blame] | 1350 | TargetInstanceSettings::TargetInstanceSettings |
| 1351 | ( |
| 1352 | UserSettingsController &owner, |
| 1353 | bool live_instance, |
| 1354 | const char *name |
| 1355 | ) : |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1356 | InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
| 1357 | m_expr_prefix_path (), |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1358 | m_expr_prefix_contents () |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1359 | { |
| 1360 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 1361 | // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 1362 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 1363 | // This is true for CreateInstanceName() too. |
| 1364 | |
| 1365 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 1366 | { |
| 1367 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 1368 | m_owner.RegisterInstanceSettings (this); |
| 1369 | } |
| 1370 | |
| 1371 | if (live_instance) |
| 1372 | { |
| 1373 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1374 | CopyInstanceSettings (pending_settings,false); |
| 1375 | //m_owner.RemovePendingSettings (m_instance_name); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 1380 | InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1381 | { |
| 1382 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 1383 | { |
| 1384 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1385 | CopyInstanceSettings (pending_settings,false); |
| 1386 | //m_owner.RemovePendingSettings (m_instance_name); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | TargetInstanceSettings::~TargetInstanceSettings () |
| 1391 | { |
| 1392 | } |
| 1393 | |
| 1394 | TargetInstanceSettings& |
| 1395 | TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) |
| 1396 | { |
| 1397 | if (this != &rhs) |
| 1398 | { |
| 1399 | } |
| 1400 | |
| 1401 | return *this; |
| 1402 | } |
| 1403 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1404 | void |
| 1405 | TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 1406 | const char *index_value, |
| 1407 | const char *value, |
| 1408 | const ConstString &instance_name, |
| 1409 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1410 | VarSetOperationType op, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1411 | Error &err, |
| 1412 | bool pending) |
| 1413 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1414 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1415 | { |
| 1416 | switch (op) |
| 1417 | { |
| 1418 | default: |
| 1419 | err.SetErrorToGenericError (); |
| 1420 | err.SetErrorString ("Unrecognized operation. Cannot update value.\n"); |
| 1421 | return; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1422 | case eVarSetOperationAssign: |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1423 | { |
| 1424 | FileSpec file_spec(value, true); |
| 1425 | |
| 1426 | if (!file_spec.Exists()) |
| 1427 | { |
| 1428 | err.SetErrorToGenericError (); |
| 1429 | err.SetErrorStringWithFormat ("%s does not exist.\n", value); |
| 1430 | return; |
| 1431 | } |
| 1432 | |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1433 | DataBufferSP data_sp (file_spec.ReadFileContents()); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1434 | |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1435 | if (!data_sp && data_sp->GetByteSize() == 0) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1436 | { |
| 1437 | err.SetErrorToGenericError (); |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1438 | err.SetErrorStringWithFormat ("Couldn't read from %s\n", value); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1439 | return; |
| 1440 | } |
| 1441 | |
| 1442 | m_expr_prefix_path = value; |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1443 | m_expr_prefix_contents.assign(reinterpret_cast<const char *>(data_sp->GetBytes()), data_sp->GetByteSize()); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1444 | } |
| 1445 | return; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1446 | case eVarSetOperationAppend: |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1447 | err.SetErrorToGenericError (); |
| 1448 | err.SetErrorString ("Cannot append to a path.\n"); |
| 1449 | return; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1450 | case eVarSetOperationClear: |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1451 | m_expr_prefix_path.clear (); |
| 1452 | m_expr_prefix_contents.clear (); |
| 1453 | return; |
| 1454 | } |
| 1455 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | void |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1459 | TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1460 | { |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1461 | TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get()); |
| 1462 | |
| 1463 | if (!new_settings_ptr) |
| 1464 | return; |
| 1465 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1466 | m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path; |
| 1467 | m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1468 | } |
| 1469 | |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 1470 | bool |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1471 | TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 1472 | const ConstString &var_name, |
| 1473 | StringList &value, |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 1474 | Error *err) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1475 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1476 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1477 | { |
| 1478 | value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size()); |
| 1479 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1480 | else |
| 1481 | { |
| 1482 | if (err) |
| 1483 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1484 | return false; |
| 1485 | } |
| 1486 | |
| 1487 | return true; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | const ConstString |
| 1491 | TargetInstanceSettings::CreateInstanceName () |
| 1492 | { |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1493 | StreamString sstr; |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 1494 | static int instance_count = 1; |
| 1495 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1496 | sstr.Printf ("target_%d", instance_count); |
| 1497 | ++instance_count; |
| 1498 | |
| 1499 | const ConstString ret_val (sstr.GetData()); |
| 1500 | return ret_val; |
| 1501 | } |
| 1502 | |
| 1503 | //-------------------------------------------------- |
| 1504 | // Target::SettingsController Variable Tables |
| 1505 | //-------------------------------------------------- |
| 1506 | |
| 1507 | SettingEntry |
| 1508 | Target::SettingsController::global_settings_table[] = |
| 1509 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1510 | // var-name var-type default enum init'd hidden help-text |
| 1511 | // ================= ================== =========== ==== ====== ====== ========================================================================= |
| 1512 | { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." }, |
| 1513 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
| 1514 | }; |
| 1515 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1516 | SettingEntry |
| 1517 | Target::SettingsController::instance_settings_table[] = |
| 1518 | { |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 | [diff] [blame] | 1519 | // var-name var-type default enum init'd hidden help-text |
| 1520 | // ================= ================== =========== ==== ====== ====== ========================================================================= |
| 1521 | { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." }, |
| 1522 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1523 | }; |