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) |
| 431 | m_platform_sp->GetFile (dependent_file_spec, platform_dependent_file_spec); |
| 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 | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 590 | Address resolved_addr(addr); |
| 591 | if (!resolved_addr.IsSectionOffset()) |
| 592 | { |
| 593 | if (process_is_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 594 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 595 | m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 596 | } |
| 597 | else |
| 598 | { |
| 599 | m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr); |
| 600 | } |
| 601 | } |
| 602 | |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 603 | if (prefer_file_cache) |
| 604 | { |
| 605 | bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
| 606 | if (bytes_read > 0) |
| 607 | return bytes_read; |
| 608 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 609 | |
| 610 | if (process_is_valid) |
| 611 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 | [diff] [blame] | 612 | lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 613 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 614 | { |
| 615 | if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) |
| 616 | error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n", |
| 617 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), |
| 618 | resolved_addr.GetFileAddress()); |
| 619 | else |
| 620 | error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress()); |
| 621 | } |
| 622 | else |
| 623 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 624 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 625 | if (bytes_read != dst_len) |
| 626 | { |
| 627 | if (error.Success()) |
| 628 | { |
| 629 | if (bytes_read == 0) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 630 | error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 631 | else |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 632 | 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] | 633 | } |
| 634 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 635 | if (bytes_read) |
| 636 | return bytes_read; |
| 637 | // If the address is not section offset we have an address that |
| 638 | // doesn't resolve to any address in any currently loaded shared |
| 639 | // libaries and we failed to read memory so there isn't anything |
| 640 | // more we can do. If it is section offset, we might be able to |
| 641 | // read cached memory from the object file. |
| 642 | if (!resolved_addr.IsSectionOffset()) |
| 643 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 644 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 645 | } |
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 (!prefer_file_cache) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 648 | { |
Greg Clayton | db59823 | 2011-01-07 01:57:07 | [diff] [blame] | 649 | // If we didn't already try and read from the object file cache, then |
| 650 | // try it after failing to read from the process. |
| 651 | return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 | [diff] [blame] | 652 | } |
| 653 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | |
| 657 | ModuleSP |
| 658 | Target::GetSharedModule |
| 659 | ( |
| 660 | const FileSpec& file_spec, |
| 661 | const ArchSpec& arch, |
Greg Clayton | 6083026 | 2011-02-04 18:53:10 | [diff] [blame] | 662 | const lldb_private::UUID *uuid_ptr, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 663 | const ConstString *object_name, |
| 664 | off_t object_offset, |
| 665 | Error *error_ptr |
| 666 | ) |
| 667 | { |
| 668 | // Don't pass in the UUID so we can tell if we have a stale value in our list |
| 669 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 670 | bool did_create_module = false; |
| 671 | ModuleSP module_sp; |
| 672 | |
| 673 | // If there are image search path entries, try to use them first to acquire a suitable image. |
| 674 | |
| 675 | Error error; |
| 676 | |
| 677 | if (m_image_search_paths.GetSize()) |
| 678 | { |
| 679 | FileSpec transformed_spec; |
| 680 | if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory())) |
| 681 | { |
| 682 | transformed_spec.GetFilename() = file_spec.GetFilename(); |
| 683 | error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | // If a module hasn't been found yet, use the unmodified path. |
| 688 | |
| 689 | if (!module_sp) |
| 690 | { |
| 691 | error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module)); |
| 692 | } |
| 693 | |
| 694 | if (module_sp) |
| 695 | { |
| 696 | m_images.Append (module_sp); |
| 697 | if (did_create_module) |
| 698 | { |
| 699 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 700 | ModuleUpdated(old_module_sp, module_sp); |
| 701 | else |
| 702 | ModuleAdded(module_sp); |
| 703 | } |
| 704 | } |
| 705 | if (error_ptr) |
| 706 | *error_ptr = error; |
| 707 | return module_sp; |
| 708 | } |
| 709 | |
| 710 | |
| 711 | Target * |
| 712 | Target::CalculateTarget () |
| 713 | { |
| 714 | return this; |
| 715 | } |
| 716 | |
| 717 | Process * |
| 718 | Target::CalculateProcess () |
| 719 | { |
| 720 | return NULL; |
| 721 | } |
| 722 | |
| 723 | Thread * |
| 724 | Target::CalculateThread () |
| 725 | { |
| 726 | return NULL; |
| 727 | } |
| 728 | |
| 729 | StackFrame * |
| 730 | Target::CalculateStackFrame () |
| 731 | { |
| 732 | return NULL; |
| 733 | } |
| 734 | |
| 735 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 736 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 737 | { |
| 738 | exe_ctx.target = this; |
| 739 | exe_ctx.process = NULL; // Do NOT fill in process... |
| 740 | exe_ctx.thread = NULL; |
| 741 | exe_ctx.frame = NULL; |
| 742 | } |
| 743 | |
| 744 | PathMappingList & |
| 745 | Target::GetImageSearchPathList () |
| 746 | { |
| 747 | return m_image_search_paths; |
| 748 | } |
| 749 | |
| 750 | void |
| 751 | Target::ImageSearchPathsChanged |
| 752 | ( |
| 753 | const PathMappingList &path_list, |
| 754 | void *baton |
| 755 | ) |
| 756 | { |
| 757 | Target *target = (Target *)baton; |
| 758 | if (target->m_images.GetSize() > 1) |
| 759 | { |
| 760 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 761 | if (exe_module_sp) |
| 762 | { |
| 763 | target->m_images.Clear(); |
| 764 | target->SetExecutableModule (exe_module_sp, true); |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | ClangASTContext * |
| 770 | Target::GetScratchClangASTContext() |
| 771 | { |
| 772 | return m_scratch_ast_context_ap.get(); |
| 773 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 774 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 775 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 776 | Target::SettingsInitialize () |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 777 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 778 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 779 | usc.reset (new SettingsController); |
| 780 | UserSettingsController::InitializeSettingsController (usc, |
| 781 | SettingsController::global_settings_table, |
| 782 | SettingsController::instance_settings_table); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 783 | |
| 784 | // Now call SettingsInitialize() on each 'child' setting of Target |
| 785 | Process::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 786 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 787 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 788 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 789 | Target::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 790 | { |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 | [diff] [blame] | 791 | |
| 792 | // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings. |
| 793 | |
| 794 | Process::SettingsTerminate (); |
| 795 | |
| 796 | // Now terminate Target Settings. |
| 797 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 798 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 799 | UserSettingsController::FinalizeSettingsController (usc); |
| 800 | usc.reset(); |
| 801 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 802 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 | [diff] [blame] | 803 | UserSettingsControllerSP & |
| 804 | Target::GetSettingsController () |
| 805 | { |
| 806 | static UserSettingsControllerSP g_settings_controller; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 807 | return g_settings_controller; |
| 808 | } |
| 809 | |
| 810 | ArchSpec |
| 811 | Target::GetDefaultArchitecture () |
| 812 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 813 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 814 | |
| 815 | if (settings_controller_sp) |
| 816 | return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture (); |
| 817 | return ArchSpec(); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 821 | Target::SetDefaultArchitecture (const ArchSpec& arch) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 822 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 823 | lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController()); |
| 824 | |
| 825 | if (settings_controller_sp) |
| 826 | static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 827 | } |
| 828 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 | [diff] [blame] | 829 | Target * |
| 830 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 831 | { |
| 832 | // The target can either exist in the "process" of ExecutionContext, or in |
| 833 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 834 | // will get the target from one of these locations. |
| 835 | |
| 836 | Target *target = NULL; |
| 837 | if (sc_ptr != NULL) |
| 838 | target = sc_ptr->target_sp.get(); |
| 839 | if (target == NULL) |
| 840 | { |
| 841 | if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL) |
| 842 | target = &exe_ctx_ptr->process->GetTarget(); |
| 843 | } |
| 844 | return target; |
| 845 | } |
| 846 | |
| 847 | |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 848 | void |
| 849 | Target::UpdateInstanceName () |
| 850 | { |
| 851 | StreamString sstr; |
| 852 | |
| 853 | ModuleSP module_sp = GetExecutableModule(); |
| 854 | if (module_sp) |
| 855 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 856 | sstr.Printf ("%s_%s", |
| 857 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 858 | module_sp->GetArchitecture().GetArchitectureName()); |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 859 | GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), |
| 860 | sstr.GetData()); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 864 | const char * |
| 865 | Target::GetExpressionPrefixContentsAsCString () |
| 866 | { |
| 867 | return m_expr_prefix_contents.c_str(); |
| 868 | } |
| 869 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 870 | ExecutionResults |
| 871 | Target::EvaluateExpression |
| 872 | ( |
| 873 | const char *expr_cstr, |
| 874 | StackFrame *frame, |
| 875 | bool unwind_on_error, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 876 | bool keep_in_memory, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 877 | lldb::ValueObjectSP &result_valobj_sp |
| 878 | ) |
| 879 | { |
| 880 | ExecutionResults execution_results = eExecutionSetupError; |
| 881 | |
| 882 | result_valobj_sp.reset(); |
| 883 | |
| 884 | ExecutionContext exe_ctx; |
| 885 | if (frame) |
| 886 | { |
| 887 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 | [diff] [blame] | 888 | Error error; |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 | [diff] [blame] | 889 | const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
| 890 | StackFrame::eExpressionPathOptionsNoFragileObjcIvar; |
| 891 | result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, expr_path_options, error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 892 | } |
| 893 | else if (m_process_sp) |
| 894 | { |
| 895 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 896 | } |
| 897 | else |
| 898 | { |
| 899 | CalculateExecutionContext(exe_ctx); |
| 900 | } |
| 901 | |
| 902 | if (result_valobj_sp) |
| 903 | { |
| 904 | execution_results = eExecutionCompleted; |
| 905 | // We got a result from the frame variable expression path above... |
| 906 | ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName()); |
| 907 | |
| 908 | lldb::ValueObjectSP const_valobj_sp; |
| 909 | |
| 910 | // Check in case our value is already a constant value |
| 911 | if (result_valobj_sp->GetIsConstant()) |
| 912 | { |
| 913 | const_valobj_sp = result_valobj_sp; |
| 914 | const_valobj_sp->SetName (persistent_variable_name); |
| 915 | } |
| 916 | else |
| 917 | const_valobj_sp = result_valobj_sp->CreateConstantValue (exe_ctx.GetBestExecutionContextScope(), |
| 918 | persistent_variable_name); |
| 919 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 920 | lldb::ValueObjectSP live_valobj_sp = result_valobj_sp; |
| 921 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 922 | result_valobj_sp = const_valobj_sp; |
| 923 | |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 924 | ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp)); |
| 925 | assert (clang_expr_variable_sp.get()); |
| 926 | |
| 927 | // Set flags and live data as appropriate |
| 928 | |
| 929 | const Value &result_value = live_valobj_sp->GetValue(); |
| 930 | |
| 931 | switch (result_value.GetValueType()) |
| 932 | { |
| 933 | case Value::eValueTypeHostAddress: |
| 934 | case Value::eValueTypeFileAddress: |
| 935 | // we don't do anything with these for now |
| 936 | break; |
| 937 | case Value::eValueTypeScalar: |
| 938 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated; |
| 939 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation; |
| 940 | break; |
| 941 | case Value::eValueTypeLoadAddress: |
| 942 | clang_expr_variable_sp->m_live_sp = live_valobj_sp; |
| 943 | clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference; |
| 944 | break; |
| 945 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 946 | } |
| 947 | else |
| 948 | { |
| 949 | // Make sure we aren't just trying to see the value of a persistent |
| 950 | // variable (something like "$0") |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 | [diff] [blame] | 951 | lldb::ClangExpressionVariableSP persistent_var_sp; |
| 952 | // Only check for persistent variables the expression starts with a '$' |
| 953 | if (expr_cstr[0] == '$') |
| 954 | persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); |
| 955 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 956 | if (persistent_var_sp) |
| 957 | { |
| 958 | result_valobj_sp = persistent_var_sp->GetValueObject (); |
| 959 | execution_results = eExecutionCompleted; |
| 960 | } |
| 961 | else |
| 962 | { |
| 963 | const char *prefix = GetExpressionPrefixContentsAsCString(); |
| 964 | |
| 965 | execution_results = ClangUserExpression::Evaluate (exe_ctx, |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 | [diff] [blame] | 966 | unwind_on_error, |
| 967 | keep_in_memory, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 | [diff] [blame] | 968 | expr_cstr, |
| 969 | prefix, |
| 970 | result_valobj_sp); |
| 971 | } |
| 972 | } |
| 973 | return execution_results; |
| 974 | } |
| 975 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 976 | lldb::user_id_t |
| 977 | Target::AddStopHook (Target::StopHookSP &new_hook_sp) |
| 978 | { |
| 979 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
| 980 | new_hook_sp.reset (new StopHook(GetSP(), new_uid)); |
| 981 | m_stop_hooks[new_uid] = new_hook_sp; |
| 982 | return new_uid; |
| 983 | } |
| 984 | |
| 985 | bool |
| 986 | Target::RemoveStopHookByID (lldb::user_id_t user_id) |
| 987 | { |
| 988 | size_t num_removed; |
| 989 | num_removed = m_stop_hooks.erase (user_id); |
| 990 | if (num_removed == 0) |
| 991 | return false; |
| 992 | else |
| 993 | return true; |
| 994 | } |
| 995 | |
| 996 | void |
| 997 | Target::RemoveAllStopHooks () |
| 998 | { |
| 999 | m_stop_hooks.clear(); |
| 1000 | } |
| 1001 | |
| 1002 | Target::StopHookSP |
| 1003 | Target::GetStopHookByID (lldb::user_id_t user_id) |
| 1004 | { |
| 1005 | StopHookSP found_hook; |
| 1006 | |
| 1007 | StopHookCollection::iterator specified_hook_iter; |
| 1008 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1009 | if (specified_hook_iter != m_stop_hooks.end()) |
| 1010 | found_hook = (*specified_hook_iter).second; |
| 1011 | return found_hook; |
| 1012 | } |
| 1013 | |
| 1014 | bool |
| 1015 | Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) |
| 1016 | { |
| 1017 | StopHookCollection::iterator specified_hook_iter; |
| 1018 | specified_hook_iter = m_stop_hooks.find (user_id); |
| 1019 | if (specified_hook_iter == m_stop_hooks.end()) |
| 1020 | return false; |
| 1021 | |
| 1022 | (*specified_hook_iter).second->SetIsActive (active_state); |
| 1023 | return true; |
| 1024 | } |
| 1025 | |
| 1026 | void |
| 1027 | Target::SetAllStopHooksActiveState (bool active_state) |
| 1028 | { |
| 1029 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1030 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1031 | { |
| 1032 | (*pos).second->SetIsActive (active_state); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | void |
| 1037 | Target::RunStopHooks () |
| 1038 | { |
| 1039 | if (!m_process_sp) |
| 1040 | return; |
| 1041 | |
| 1042 | if (m_stop_hooks.empty()) |
| 1043 | return; |
| 1044 | |
| 1045 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 1046 | |
| 1047 | // If there aren't any active stop hooks, don't bother either: |
| 1048 | bool any_active_hooks = false; |
| 1049 | for (pos = m_stop_hooks.begin(); pos != end; pos++) |
| 1050 | { |
| 1051 | if ((*pos).second->IsActive()) |
| 1052 | { |
| 1053 | any_active_hooks = true; |
| 1054 | break; |
| 1055 | } |
| 1056 | } |
| 1057 | if (!any_active_hooks) |
| 1058 | return; |
| 1059 | |
| 1060 | CommandReturnObject result; |
| 1061 | |
| 1062 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 1063 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 1064 | |
| 1065 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 1066 | size_t num_threads = cur_threadlist.GetSize(); |
| 1067 | for (size_t i = 0; i < num_threads; i++) |
| 1068 | { |
| 1069 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); |
| 1070 | if (cur_thread_sp->ThreadStoppedForAReason()) |
| 1071 | { |
| 1072 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 1073 | exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 1074 | sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 1079 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 1080 | if (num_exe_ctx == 0) |
| 1081 | return; |
| 1082 | |
| 1083 | result.SetImmediateOutputFile (m_debugger.GetOutputFile().GetStream()); |
| 1084 | result.SetImmediateErrorFile (m_debugger.GetErrorFile().GetStream()); |
| 1085 | |
| 1086 | bool keep_going = true; |
| 1087 | bool hooks_ran = false; |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1088 | bool print_hook_header; |
| 1089 | bool print_thread_header; |
| 1090 | |
| 1091 | if (num_exe_ctx == 1) |
| 1092 | print_thread_header = false; |
| 1093 | else |
| 1094 | print_thread_header = true; |
| 1095 | |
| 1096 | if (m_stop_hooks.size() == 1) |
| 1097 | print_hook_header = false; |
| 1098 | else |
| 1099 | print_hook_header = true; |
| 1100 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1101 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) |
| 1102 | { |
| 1103 | // result.Clear(); |
| 1104 | StopHookSP cur_hook_sp = (*pos).second; |
| 1105 | if (!cur_hook_sp->IsActive()) |
| 1106 | continue; |
| 1107 | |
| 1108 | bool any_thread_matched = false; |
| 1109 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) |
| 1110 | { |
| 1111 | if ((cur_hook_sp->GetSpecifier () == NULL |
| 1112 | || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) |
| 1113 | && (cur_hook_sp->GetThreadSpecifier() == NULL |
| 1114 | || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread))) |
| 1115 | { |
| 1116 | if (!hooks_ran) |
| 1117 | { |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1118 | result.AppendMessage("\n** Stop Hooks **"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1119 | hooks_ran = true; |
| 1120 | } |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1121 | if (print_hook_header && !any_thread_matched) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1122 | { |
| 1123 | result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID()); |
| 1124 | any_thread_matched = true; |
| 1125 | } |
| 1126 | |
Jim Ingham | 381e25b | 2011-03-22 01:47:27 | [diff] [blame] | 1127 | if (print_thread_header) |
| 1128 | result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 | [diff] [blame] | 1129 | |
| 1130 | bool stop_on_continue = true; |
| 1131 | bool stop_on_error = true; |
| 1132 | bool echo_commands = false; |
| 1133 | bool print_results = true; |
| 1134 | GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), |
| 1135 | &exc_ctx_with_reasons[i], |
| 1136 | stop_on_continue, |
| 1137 | stop_on_error, |
| 1138 | echo_commands, |
| 1139 | print_results, |
| 1140 | result); |
| 1141 | |
| 1142 | // If the command started the target going again, we should bag out of |
| 1143 | // running the stop hooks. |
| 1144 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) |
| 1145 | || (result.GetStatus() == eReturnStatusSuccessContinuingResult)) |
| 1146 | { |
| 1147 | result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID()); |
| 1148 | keep_going = false; |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | if (hooks_ran) |
| 1154 | result.AppendMessage ("\n** End Stop Hooks **\n"); |
| 1155 | } |
| 1156 | |
| 1157 | //-------------------------------------------------------------- |
| 1158 | // class Target::StopHook |
| 1159 | //-------------------------------------------------------------- |
| 1160 | |
| 1161 | |
| 1162 | Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : |
| 1163 | UserID (uid), |
| 1164 | m_target_sp (target_sp), |
| 1165 | m_active (true), |
| 1166 | m_commands (), |
| 1167 | m_specifier_sp (), |
| 1168 | m_thread_spec_ap(NULL) |
| 1169 | { |
| 1170 | } |
| 1171 | |
| 1172 | Target::StopHook::StopHook (const StopHook &rhs) : |
| 1173 | UserID (rhs.GetID()), |
| 1174 | m_target_sp (rhs.m_target_sp), |
| 1175 | m_commands (rhs.m_commands), |
| 1176 | m_specifier_sp (rhs.m_specifier_sp), |
| 1177 | m_active (rhs.m_active), |
| 1178 | m_thread_spec_ap (NULL) |
| 1179 | { |
| 1180 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 1181 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | Target::StopHook::~StopHook () |
| 1186 | { |
| 1187 | } |
| 1188 | |
| 1189 | void |
| 1190 | Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier) |
| 1191 | { |
| 1192 | m_thread_spec_ap.reset (specifier); |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | void |
| 1197 | Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 1198 | { |
| 1199 | int indent_level = s->GetIndentLevel(); |
| 1200 | |
| 1201 | s->SetIndentLevel(indent_level + 2); |
| 1202 | |
| 1203 | s->Printf ("Hook: %d\n", GetID()); |
| 1204 | if (m_active) |
| 1205 | s->Indent ("State: enabled\n"); |
| 1206 | else |
| 1207 | s->Indent ("State: disabled\n"); |
| 1208 | |
| 1209 | if (m_specifier_sp) |
| 1210 | { |
| 1211 | s->Indent(); |
| 1212 | s->PutCString ("Specifier:\n"); |
| 1213 | s->SetIndentLevel (indent_level + 4); |
| 1214 | m_specifier_sp->GetDescription (s, level); |
| 1215 | s->SetIndentLevel (indent_level + 2); |
| 1216 | } |
| 1217 | |
| 1218 | if (m_thread_spec_ap.get() != NULL) |
| 1219 | { |
| 1220 | StreamString tmp; |
| 1221 | s->Indent("Thread:\n"); |
| 1222 | m_thread_spec_ap->GetDescription (&tmp, level); |
| 1223 | s->SetIndentLevel (indent_level + 4); |
| 1224 | s->Indent (tmp.GetData()); |
| 1225 | s->PutCString ("\n"); |
| 1226 | s->SetIndentLevel (indent_level + 2); |
| 1227 | } |
| 1228 | |
| 1229 | s->Indent ("Commands: \n"); |
| 1230 | s->SetIndentLevel (indent_level + 4); |
| 1231 | uint32_t num_commands = m_commands.GetSize(); |
| 1232 | for (uint32_t i = 0; i < num_commands; i++) |
| 1233 | { |
| 1234 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 1235 | s->PutCString ("\n"); |
| 1236 | } |
| 1237 | s->SetIndentLevel (indent_level); |
| 1238 | } |
| 1239 | |
| 1240 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1241 | //-------------------------------------------------------------- |
| 1242 | // class Target::SettingsController |
| 1243 | //-------------------------------------------------------------- |
| 1244 | |
| 1245 | Target::SettingsController::SettingsController () : |
| 1246 | UserSettingsController ("target", Debugger::GetSettingsController()), |
| 1247 | m_default_architecture () |
| 1248 | { |
| 1249 | m_default_settings.reset (new TargetInstanceSettings (*this, false, |
| 1250 | InstanceSettings::GetDefaultName().AsCString())); |
| 1251 | } |
| 1252 | |
| 1253 | Target::SettingsController::~SettingsController () |
| 1254 | { |
| 1255 | } |
| 1256 | |
| 1257 | lldb::InstanceSettingsSP |
| 1258 | Target::SettingsController::CreateInstanceSettings (const char *instance_name) |
| 1259 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 1260 | TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(), |
| 1261 | false, |
| 1262 | instance_name); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1263 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 1264 | return new_settings_sp; |
| 1265 | } |
| 1266 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1267 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1268 | #define TSC_DEFAULT_ARCH "default-arch" |
| 1269 | #define TSC_EXPR_PREFIX "expr-prefix" |
| 1270 | #define TSC_EXEC_LEVEL "execution-level" |
| 1271 | #define TSC_EXEC_MODE "execution-mode" |
| 1272 | #define TSC_EXEC_OS_TYPE "execution-os-type" |
| 1273 | |
| 1274 | |
| 1275 | static const ConstString & |
| 1276 | GetSettingNameForDefaultArch () |
| 1277 | { |
| 1278 | static ConstString g_const_string (TSC_DEFAULT_ARCH); |
| 1279 | |
| 1280 | return g_const_string; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1281 | } |
| 1282 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1283 | static const ConstString & |
| 1284 | GetSettingNameForExpressionPrefix () |
| 1285 | { |
| 1286 | static ConstString g_const_string (TSC_EXPR_PREFIX); |
| 1287 | return g_const_string; |
| 1288 | } |
| 1289 | |
| 1290 | static const ConstString & |
| 1291 | GetSettingNameForExecutionLevel () |
| 1292 | { |
| 1293 | static ConstString g_const_string (TSC_EXEC_LEVEL); |
| 1294 | return g_const_string; |
| 1295 | } |
| 1296 | |
| 1297 | static const ConstString & |
| 1298 | GetSettingNameForExecutionMode () |
| 1299 | { |
| 1300 | static ConstString g_const_string (TSC_EXEC_MODE); |
| 1301 | return g_const_string; |
| 1302 | } |
| 1303 | |
| 1304 | static const ConstString & |
| 1305 | GetSettingNameForExecutionOSType () |
| 1306 | { |
| 1307 | static ConstString g_const_string (TSC_EXEC_OS_TYPE); |
| 1308 | return g_const_string; |
| 1309 | } |
| 1310 | |
| 1311 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1312 | bool |
| 1313 | Target::SettingsController::SetGlobalVariable (const ConstString &var_name, |
| 1314 | const char *index_value, |
| 1315 | const char *value, |
| 1316 | const SettingEntry &entry, |
| 1317 | const lldb::VarSetOperationType op, |
| 1318 | Error&err) |
| 1319 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1320 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1321 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1322 | m_default_architecture.SetTriple (value); |
| 1323 | if (!m_default_architecture.IsValid()) |
| 1324 | err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1325 | } |
| 1326 | return true; |
| 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | bool |
| 1331 | Target::SettingsController::GetGlobalVariable (const ConstString &var_name, |
| 1332 | StringList &value, |
| 1333 | Error &err) |
| 1334 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1335 | if (var_name == GetSettingNameForDefaultArch()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1336 | { |
Greg Clayton | 307de25 | 2010-10-27 02:06:37 | [diff] [blame] | 1337 | // If the arch is invalid (the default), don't show a string for it |
| 1338 | if (m_default_architecture.IsValid()) |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 | [diff] [blame] | 1339 | value.AppendString (m_default_architecture.GetArchitectureName()); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1340 | return true; |
| 1341 | } |
| 1342 | else |
| 1343 | err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1344 | |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
| 1348 | //-------------------------------------------------------------- |
| 1349 | // class TargetInstanceSettings |
| 1350 | //-------------------------------------------------------------- |
| 1351 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 | [diff] [blame] | 1352 | TargetInstanceSettings::TargetInstanceSettings |
| 1353 | ( |
| 1354 | UserSettingsController &owner, |
| 1355 | bool live_instance, |
| 1356 | const char *name |
| 1357 | ) : |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1358 | InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
| 1359 | m_expr_prefix_path (), |
| 1360 | m_expr_prefix_contents (), |
| 1361 | m_execution_level (eExecutionLevelAuto), |
| 1362 | m_execution_mode (eExecutionModeAuto), |
| 1363 | m_execution_os_type (eExecutionOSTypeAuto) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1364 | { |
| 1365 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 1366 | // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 1367 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 1368 | // This is true for CreateInstanceName() too. |
| 1369 | |
| 1370 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 1371 | { |
| 1372 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 1373 | m_owner.RegisterInstanceSettings (this); |
| 1374 | } |
| 1375 | |
| 1376 | if (live_instance) |
| 1377 | { |
| 1378 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1379 | CopyInstanceSettings (pending_settings,false); |
| 1380 | //m_owner.RemovePendingSettings (m_instance_name); |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 | [diff] [blame] | 1385 | InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1386 | { |
| 1387 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 1388 | { |
| 1389 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1390 | CopyInstanceSettings (pending_settings,false); |
| 1391 | //m_owner.RemovePendingSettings (m_instance_name); |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | TargetInstanceSettings::~TargetInstanceSettings () |
| 1396 | { |
| 1397 | } |
| 1398 | |
| 1399 | TargetInstanceSettings& |
| 1400 | TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) |
| 1401 | { |
| 1402 | if (this != &rhs) |
| 1403 | { |
| 1404 | } |
| 1405 | |
| 1406 | return *this; |
| 1407 | } |
| 1408 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1409 | void |
| 1410 | TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 1411 | const char *index_value, |
| 1412 | const char *value, |
| 1413 | const ConstString &instance_name, |
| 1414 | const SettingEntry &entry, |
| 1415 | lldb::VarSetOperationType op, |
| 1416 | Error &err, |
| 1417 | bool pending) |
| 1418 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1419 | int new_enum = -1; |
| 1420 | |
| 1421 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1422 | { |
| 1423 | switch (op) |
| 1424 | { |
| 1425 | default: |
| 1426 | err.SetErrorToGenericError (); |
| 1427 | err.SetErrorString ("Unrecognized operation. Cannot update value.\n"); |
| 1428 | return; |
| 1429 | case lldb::eVarSetOperationAssign: |
| 1430 | { |
| 1431 | FileSpec file_spec(value, true); |
| 1432 | |
| 1433 | if (!file_spec.Exists()) |
| 1434 | { |
| 1435 | err.SetErrorToGenericError (); |
| 1436 | err.SetErrorStringWithFormat ("%s does not exist.\n", value); |
| 1437 | return; |
| 1438 | } |
| 1439 | |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1440 | DataBufferSP data_sp (file_spec.ReadFileContents()); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1441 | |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1442 | if (!data_sp && data_sp->GetByteSize() == 0) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1443 | { |
| 1444 | err.SetErrorToGenericError (); |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1445 | err.SetErrorStringWithFormat ("Couldn't read from %s\n", value); |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1446 | return; |
| 1447 | } |
| 1448 | |
| 1449 | m_expr_prefix_path = value; |
Greg Clayton | c3f381b | 2011-02-03 17:47:47 | [diff] [blame] | 1450 | 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] | 1451 | } |
| 1452 | return; |
| 1453 | case lldb::eVarSetOperationAppend: |
| 1454 | err.SetErrorToGenericError (); |
| 1455 | err.SetErrorString ("Cannot append to a path.\n"); |
| 1456 | return; |
| 1457 | case lldb::eVarSetOperationClear: |
| 1458 | m_expr_prefix_path.clear (); |
| 1459 | m_expr_prefix_contents.clear (); |
| 1460 | return; |
| 1461 | } |
| 1462 | } |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1463 | else if (var_name == GetSettingNameForExecutionLevel ()) |
| 1464 | { |
| 1465 | UserSettingsController::UpdateEnumVariable (entry.enum_values, &new_enum, value, err); |
| 1466 | if (err.Success()) |
| 1467 | m_execution_level = (ExecutionLevel)new_enum; |
| 1468 | } |
| 1469 | else if (var_name == GetSettingNameForExecutionMode ()) |
| 1470 | { |
| 1471 | UserSettingsController::UpdateEnumVariable (entry.enum_values, &new_enum, value, err); |
| 1472 | if (err.Success()) |
| 1473 | m_execution_mode = (ExecutionMode)new_enum; |
| 1474 | } |
| 1475 | else if (var_name == GetSettingNameForExecutionOSType ()) |
| 1476 | { |
| 1477 | UserSettingsController::UpdateEnumVariable (entry.enum_values, &new_enum, value, err); |
| 1478 | if (err.Success()) |
| 1479 | m_execution_os_type = (ExecutionOSType)new_enum; |
| 1480 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | void |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1484 | TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1485 | { |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1486 | TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get()); |
| 1487 | |
| 1488 | if (!new_settings_ptr) |
| 1489 | return; |
| 1490 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1491 | m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path; |
| 1492 | m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents; |
| 1493 | m_execution_level = new_settings_ptr->m_execution_level; |
| 1494 | m_execution_mode = new_settings_ptr->m_execution_mode; |
| 1495 | m_execution_os_type = new_settings_ptr->m_execution_os_type; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1496 | } |
| 1497 | |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 1498 | bool |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1499 | TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 1500 | const ConstString &var_name, |
| 1501 | StringList &value, |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 | [diff] [blame] | 1502 | Error *err) |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1503 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1504 | if (var_name == GetSettingNameForExpressionPrefix ()) |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1505 | { |
| 1506 | value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size()); |
| 1507 | } |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1508 | else if (var_name == GetSettingNameForExecutionLevel ()) |
| 1509 | { |
| 1510 | value.AppendString (UserSettingsController::EnumToString (entry.enum_values, m_execution_level)); |
| 1511 | } |
| 1512 | else if (var_name == GetSettingNameForExecutionMode ()) |
| 1513 | { |
| 1514 | value.AppendString (UserSettingsController::EnumToString (entry.enum_values, m_execution_mode)); |
| 1515 | } |
| 1516 | else if (var_name == GetSettingNameForExecutionOSType ()) |
| 1517 | { |
| 1518 | value.AppendString (UserSettingsController::EnumToString (entry.enum_values, m_execution_os_type)); |
| 1519 | } |
Sean Callanan | 322f529 | 2010-10-29 00:29:03 | [diff] [blame] | 1520 | else |
| 1521 | { |
| 1522 | if (err) |
| 1523 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
| 1527 | return true; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | const ConstString |
| 1531 | TargetInstanceSettings::CreateInstanceName () |
| 1532 | { |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1533 | StreamString sstr; |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 | [diff] [blame] | 1534 | static int instance_count = 1; |
| 1535 | |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1536 | sstr.Printf ("target_%d", instance_count); |
| 1537 | ++instance_count; |
| 1538 | |
| 1539 | const ConstString ret_val (sstr.GetData()); |
| 1540 | return ret_val; |
| 1541 | } |
| 1542 | |
| 1543 | //-------------------------------------------------- |
| 1544 | // Target::SettingsController Variable Tables |
| 1545 | //-------------------------------------------------- |
| 1546 | |
| 1547 | SettingEntry |
| 1548 | Target::SettingsController::global_settings_table[] = |
| 1549 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1550 | // var-name var-type default enum init'd hidden help-text |
| 1551 | // ================= ================== =========== ==== ====== ====== ========================================================================= |
| 1552 | { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." }, |
| 1553 | { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL } |
| 1554 | }; |
| 1555 | |
| 1556 | static lldb::OptionEnumValueElement |
| 1557 | g_execution_level_enums[] = |
| 1558 | { |
| 1559 | { eExecutionLevelAuto , "auto" , "Automatically detect the execution level (user/kernel)." }, |
| 1560 | { eExecutionLevelKernel , "kernel" , "Treat executables as kernel executables." }, |
| 1561 | { eExecutionLevelUser , "user" , "Treat executables as user space executables." }, |
| 1562 | { 0 , NULL , NULL } |
| 1563 | }; |
| 1564 | |
| 1565 | static lldb::OptionEnumValueElement |
| 1566 | g_execution_mode_enums[] = |
| 1567 | { |
| 1568 | { eExecutionModeAuto , "auto" , "Automatically detect the execution mode (static/dynamic)." }, |
| 1569 | { eExecutionModeStatic , "static" , "All executables are static and addresses at the virtual addresses in the object files." }, |
| 1570 | { eExecutionModeDynamic , "dynamic" , "Executables and shared libraries are dynamically loaded.." }, |
| 1571 | { 0 , NULL , NULL } |
| 1572 | }; |
| 1573 | |
| 1574 | static lldb::OptionEnumValueElement |
| 1575 | g_execution_os_enums[] = |
| 1576 | { |
| 1577 | { eExecutionOSTypeAuto , "auto" , "Automatically detect the execution OS (none/halted/live)." }, |
| 1578 | { eExecutionOSTypeNone , "none" , "There is no operating system available (no processes or threads)." }, |
| 1579 | { eExecutionOSTypeHalted, "halted" , "There is an operating system, but it is halted when the debugger is halted. " |
| 1580 | "Processes and threads must be discovered by accessing symbols and reading " |
| 1581 | "memory." }, |
| 1582 | { eExecutionOSTypeLive , "live" , "There is a live operating system with debug services that can be used to " |
| 1583 | "get processes, threads and theirs states." }, |
| 1584 | { 0, NULL, NULL } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1585 | }; |
| 1586 | |
| 1587 | SettingEntry |
| 1588 | Target::SettingsController::instance_settings_table[] = |
| 1589 | { |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 | [diff] [blame] | 1590 | // var-name var-type default enum-table init'd hidden help-text |
| 1591 | // ================= ================== =========== ========================= ====== ====== ========================================================================= |
| 1592 | { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL , false, false, "Path to a file containing expressions to be prepended to all expressions." }, |
| 1593 | { TSC_EXEC_LEVEL , eSetVarTypeEnum , "auto" , g_execution_level_enums , false, false, "Sets the execution level for a target." }, |
| 1594 | { TSC_EXEC_MODE , eSetVarTypeEnum , "auto" , g_execution_mode_enums , false, false, "Sets the execution mode for a target." }, |
| 1595 | { TSC_EXEC_OS_TYPE , eSetVarTypeEnum , "auto" , g_execution_os_enums , false, false, "Sets the execution OS for a target." }, |
| 1596 | { NULL , eSetVarTypeNone , NULL , NULL , false, false, NULL } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 | [diff] [blame] | 1597 | }; |