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