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