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