1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/Target/Target.h"
16 // Other libraries and framework includes
18 #include "lldb/Breakpoint/BreakpointResolver.h"
19 #include "lldb/Breakpoint/BreakpointResolverAddress.h"
20 #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
21 #include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
22 #include "lldb/Breakpoint/BreakpointResolverName.h"
23 #include "lldb/Breakpoint/Watchpoint.h"
24 #include "lldb/Core/Debugger.h"
25 #include "lldb/Core/Event.h"
26 #include "lldb/Core/Log.h"
27 #include "lldb/Core/Module.h"
28 #include "lldb/Core/ModuleSpec.h"
29 #include "lldb/Core/Section.h"
30 #include "lldb/Core/SourceManager.h"
31 #include "lldb/Core/State.h"
32 #include "lldb/Core/StreamFile.h"
33 #include "lldb/Core/StreamString.h"
34 #include "lldb/Core/Timer.h"
35 #include "lldb/Core/ValueObject.h"
36 #include "lldb/Expression/ClangASTSource.h"
37 #include "lldb/Expression/ClangUserExpression.h"
38 #include "lldb/Host/FileSpec.h"
39 #include "lldb/Host/Host.h"
40 #include "lldb/Interpreter/CommandInterpreter.h"
41 #include "lldb/Interpreter/CommandReturnObject.h"
42 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
43 #include "lldb/Interpreter/OptionValues.h"
44 #include "lldb/Interpreter/Property.h"
45 #include "lldb/lldb-private-log.h"
46 #include "lldb/Symbol/ObjectFile.h"
47 #include "lldb/Target/Process.h"
48 #include "lldb/Target/SectionLoadList.h"
49 #include "lldb/Target/StackFrame.h"
50 #include "lldb/Target/SystemRuntime.h"
51 #include "lldb/Target/Thread.h"
52 #include "lldb/Target/ThreadSpec.h"
55 using namespace lldb_private;
58 Target::GetStaticBroadcasterClass ()
60 static ConstString class_name ("lldb.target");
64 //----------------------------------------------------------------------
66 //----------------------------------------------------------------------
67 Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp, bool is_dummy_target) :
68 TargetProperties (this),
69 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
70 ExecutionContextScope (),
71 m_debugger (debugger),
72 m_platform_sp (platform_sp),
73 m_mutex (Mutex::eMutexTypeRecursive),
76 m_section_load_history (),
77 m_breakpoint_list (false),
78 m_internal_breakpoint_list (true),
81 m_search_filter_sp (),
82 m_image_search_paths (ImageSearchPathsChanged, this),
83 m_scratch_ast_context_ap (),
84 m_scratch_ast_source_ap (),
86 m_persistent_variables (),
87 m_source_manager_ap(),
89 m_stop_hook_next_id (0),
91 m_suppress_stop_hooks (false),
92 m_is_dummy_target(is_dummy_target)
95 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
96 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
97 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
98 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
99 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
101 CheckInWithManager();
103 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
105 log->Printf ("%p Target::Target()", static_cast<void*>(this));
106 if (m_arch.IsValid())
108 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::Target created with architecture %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
113 Target::PrimeFromDummyTarget(Target *target)
118 m_stop_hooks = target->m_stop_hooks;
120 for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints())
122 if (breakpoint_sp->IsInternal())
125 BreakpointSP new_bp (new Breakpoint (*this, *breakpoint_sp.get()));
126 AddBreakpoint (new_bp, false);
130 //----------------------------------------------------------------------
132 //----------------------------------------------------------------------
135 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
137 log->Printf ("%p Target::~Target()", static_cast<void*>(this));
138 DeleteCurrentProcess ();
142 Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
144 // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
145 if (description_level != lldb::eDescriptionLevelBrief)
148 s->PutCString("Target\n");
151 m_breakpoint_list.Dump(s);
152 m_internal_breakpoint_list.Dump(s);
157 Module *exe_module = GetExecutableModulePointer();
159 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
161 s->PutCString ("No executable module.");
166 Target::CleanupProcess ()
168 // Do any cleanup of the target we need to do between process instances.
169 // NB It is better to do this before destroying the process in case the
170 // clean up needs some help from the process.
171 m_breakpoint_list.ClearAllBreakpointSites();
172 m_internal_breakpoint_list.ClearAllBreakpointSites();
173 // Disable watchpoints just on the debugger side.
174 Mutex::Locker locker;
175 this->GetWatchpointList().GetListMutex(locker);
176 DisableAllWatchpoints(false);
177 ClearAllWatchpointHitCounts();
181 Target::DeleteCurrentProcess ()
183 if (m_process_sp.get())
185 m_section_load_history.Clear();
186 if (m_process_sp->IsAlive())
187 m_process_sp->Destroy();
189 m_process_sp->Finalize();
193 m_process_sp.reset();
197 const lldb::ProcessSP &
198 Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
200 DeleteCurrentProcess ();
201 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
205 const lldb::ProcessSP &
206 Target::GetProcessSP () const
214 Mutex::Locker locker (m_mutex);
216 DeleteCurrentProcess ();
217 m_platform_sp.reset();
220 m_section_load_history.Clear();
221 const bool notify = false;
222 m_breakpoint_list.RemoveAll(notify);
223 m_internal_breakpoint_list.RemoveAll(notify);
224 m_last_created_breakpoint.reset();
225 m_last_created_watchpoint.reset();
226 m_search_filter_sp.reset();
227 m_image_search_paths.Clear(notify);
228 m_persistent_variables.Clear();
229 m_stop_hooks.clear();
230 m_stop_hook_next_id = 0;
231 m_suppress_stop_hooks = false;
236 Target::GetBreakpointList(bool internal)
239 return m_internal_breakpoint_list;
241 return m_breakpoint_list;
244 const BreakpointList &
245 Target::GetBreakpointList(bool internal) const
248 return m_internal_breakpoint_list;
250 return m_breakpoint_list;
254 Target::GetBreakpointByID (break_id_t break_id)
258 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
259 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
261 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
267 Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
268 const FileSpecList *source_file_spec_list,
269 RegularExpression &source_regex,
273 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
274 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
275 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
280 Target::CreateBreakpoint (const FileSpecList *containingModules,
281 const FileSpec &file,
283 LazyBool check_inlines,
284 LazyBool skip_prologue,
288 if (check_inlines == eLazyBoolCalculate)
290 const InlineStrategy inline_strategy = GetInlineStrategy();
291 switch (inline_strategy)
293 case eInlineBreakpointsNever:
294 check_inlines = eLazyBoolNo;
297 case eInlineBreakpointsHeaders:
298 if (file.IsSourceImplementationFile())
299 check_inlines = eLazyBoolNo;
301 check_inlines = eLazyBoolYes;
304 case eInlineBreakpointsAlways:
305 check_inlines = eLazyBoolYes;
309 SearchFilterSP filter_sp;
310 if (check_inlines == eLazyBoolNo)
312 // Not checking for inlines, we are looking only for matching compile units
313 FileSpecList compile_unit_list;
314 compile_unit_list.Append (file);
315 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
319 filter_sp = GetSearchFilterForModuleList (containingModules);
321 if (skip_prologue == eLazyBoolCalculate)
322 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
324 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
329 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
334 Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
337 // Attempt to resolve our load address if possible, though it is ok if
338 // it doesn't resolve to section/offset.
340 // Try and resolve as a load address if possible
341 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
342 if (!so_addr.IsValid())
344 // The address didn't resolve, so just set this as an absolute address
345 so_addr.SetOffset (addr);
347 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
352 Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
354 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
355 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
356 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
360 Target::CreateBreakpoint (const FileSpecList *containingModules,
361 const FileSpecList *containingSourceFiles,
362 const char *func_name,
363 uint32_t func_name_type_mask,
364 LazyBool skip_prologue,
371 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
373 if (skip_prologue == eLazyBoolCalculate)
374 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
376 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
381 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
387 Target::CreateBreakpoint (const FileSpecList *containingModules,
388 const FileSpecList *containingSourceFiles,
389 const std::vector<std::string> &func_names,
390 uint32_t func_name_type_mask,
391 LazyBool skip_prologue,
396 size_t num_names = func_names.size();
399 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
401 if (skip_prologue == eLazyBoolCalculate)
402 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
404 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
408 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
414 Target::CreateBreakpoint (const FileSpecList *containingModules,
415 const FileSpecList *containingSourceFiles,
416 const char *func_names[],
418 uint32_t func_name_type_mask,
419 LazyBool skip_prologue,
426 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
428 if (skip_prologue == eLazyBoolCalculate)
429 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
431 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
436 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
442 Target::GetSearchFilterForModule (const FileSpec *containingModule)
444 SearchFilterSP filter_sp;
445 if (containingModule != NULL)
447 // TODO: We should look into sharing module based search filters
448 // across many breakpoints like we do for the simple target based one
449 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
453 if (m_search_filter_sp.get() == NULL)
454 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
455 filter_sp = m_search_filter_sp;
461 Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
463 SearchFilterSP filter_sp;
464 if (containingModules && containingModules->GetSize() != 0)
466 // TODO: We should look into sharing module based search filters
467 // across many breakpoints like we do for the simple target based one
468 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
472 if (m_search_filter_sp.get() == NULL)
473 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
474 filter_sp = m_search_filter_sp;
480 Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
481 const FileSpecList *containingSourceFiles)
483 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
484 return GetSearchFilterForModuleList(containingModules);
486 SearchFilterSP filter_sp;
487 if (containingModules == NULL)
489 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
490 // but that will take a little reworking.
492 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
496 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
502 Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
503 const FileSpecList *containingSourceFiles,
504 RegularExpression &func_regex,
505 LazyBool skip_prologue,
509 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
511 (skip_prologue == eLazyBoolCalculate) ? GetSkipPrologue()
512 : static_cast<bool>(skip_prologue);
513 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
517 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
521 Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
523 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
527 Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
530 if (filter_sp && resolver_sp)
532 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
533 resolver_sp->SetBreakpoint (bp_sp.get());
534 AddBreakpoint (bp_sp, internal);
540 Target::AddBreakpoint (lldb::BreakpointSP bp_sp, bool internal)
545 m_internal_breakpoint_list.Add (bp_sp, false);
547 m_breakpoint_list.Add (bp_sp, true);
549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
553 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
554 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
557 bp_sp->ResolveBreakpoint();
561 m_last_created_breakpoint = bp_sp;
566 Target::ProcessIsValid()
568 return (m_process_sp && m_process_sp->IsAlive());
572 CheckIfWatchpointsExhausted(Target *target, Error &error)
574 uint32_t num_supported_hardware_watchpoints;
575 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
578 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
579 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
580 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
581 num_supported_hardware_watchpoints);
586 // See also Watchpoint::SetWatchpointType(uint32_t type) and
587 // the OptionGroupWatchpoint::WatchType enum type.
589 Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
591 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
593 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
594 __FUNCTION__, addr, (uint64_t)size, kind);
597 if (!ProcessIsValid())
599 error.SetErrorString("process is not alive");
603 if (addr == LLDB_INVALID_ADDRESS || size == 0)
606 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
608 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
612 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
614 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
617 // Currently we only support one watchpoint per address, with total number
618 // of watchpoints limited by the hardware which the inferior is running on.
620 // Grab the list mutex while doing operations.
621 const bool notify = false; // Don't notify about all the state changes we do on creating the watchpoint.
622 Mutex::Locker locker;
623 this->GetWatchpointList().GetListMutex(locker);
624 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
627 size_t old_size = matched_sp->GetByteSize();
629 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
630 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
631 // Return the existing watchpoint if both size and type match.
632 if (size == old_size && kind == old_type)
635 wp_sp->SetEnabled(false, notify);
639 // Nil the matched watchpoint; we will be creating a new one.
640 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
641 m_watchpoint_list.Remove(matched_sp->GetID(), true);
647 wp_sp.reset(new Watchpoint(*this, addr, size, type));
648 wp_sp->SetWatchpointType(kind, notify);
649 m_watchpoint_list.Add (wp_sp, true);
652 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
654 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
656 error.Success() ? "succeeded" : "failed",
661 // Enabling the watchpoint on the device side failed.
662 // Remove the said watchpoint from the list maintained by the target instance.
663 m_watchpoint_list.Remove (wp_sp->GetID(), true);
664 // See if we could provide more helpful error message.
665 if (!CheckIfWatchpointsExhausted(this, error))
667 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
668 error.SetErrorStringWithFormat("watch size of %" PRIu64 " is not supported", (uint64_t)size);
673 m_last_created_watchpoint = wp_sp;
678 Target::RemoveAllBreakpoints (bool internal_also)
680 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
682 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
684 m_breakpoint_list.RemoveAll (true);
686 m_internal_breakpoint_list.RemoveAll (false);
688 m_last_created_breakpoint.reset();
692 Target::DisableAllBreakpoints (bool internal_also)
694 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
696 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
698 m_breakpoint_list.SetEnabledAll (false);
700 m_internal_breakpoint_list.SetEnabledAll (false);
704 Target::EnableAllBreakpoints (bool internal_also)
706 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
708 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
710 m_breakpoint_list.SetEnabledAll (true);
712 m_internal_breakpoint_list.SetEnabledAll (true);
716 Target::RemoveBreakpointByID (break_id_t break_id)
718 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
720 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
722 if (DisableBreakpointByID (break_id))
724 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
725 m_internal_breakpoint_list.Remove(break_id, false);
728 if (m_last_created_breakpoint)
730 if (m_last_created_breakpoint->GetID() == break_id)
731 m_last_created_breakpoint.reset();
733 m_breakpoint_list.Remove(break_id, true);
741 Target::DisableBreakpointByID (break_id_t break_id)
743 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
745 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
749 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
750 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
752 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
755 bp_sp->SetEnabled (false);
762 Target::EnableBreakpointByID (break_id_t break_id)
764 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
766 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
769 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
773 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
774 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
776 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
780 bp_sp->SetEnabled (true);
786 // The flag 'end_to_end', default to true, signifies that the operation is
787 // performed end to end, for both the debugger and the debuggee.
789 // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
790 // to end operations.
792 Target::RemoveAllWatchpoints (bool end_to_end)
794 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
796 log->Printf ("Target::%s\n", __FUNCTION__);
799 m_watchpoint_list.RemoveAll(true);
803 // Otherwise, it's an end to end operation.
805 if (!ProcessIsValid())
808 size_t num_watchpoints = m_watchpoint_list.GetSize();
809 for (size_t i = 0; i < num_watchpoints; ++i)
811 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
815 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
819 m_watchpoint_list.RemoveAll (true);
820 m_last_created_watchpoint.reset();
821 return true; // Success!
824 // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
827 Target::DisableAllWatchpoints (bool end_to_end)
829 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
831 log->Printf ("Target::%s\n", __FUNCTION__);
834 m_watchpoint_list.SetEnabledAll(false);
838 // Otherwise, it's an end to end operation.
840 if (!ProcessIsValid())
843 size_t num_watchpoints = m_watchpoint_list.GetSize();
844 for (size_t i = 0; i < num_watchpoints; ++i)
846 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
850 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
854 return true; // Success!
857 // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
860 Target::EnableAllWatchpoints (bool end_to_end)
862 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
864 log->Printf ("Target::%s\n", __FUNCTION__);
867 m_watchpoint_list.SetEnabledAll(true);
871 // Otherwise, it's an end to end operation.
873 if (!ProcessIsValid())
876 size_t num_watchpoints = m_watchpoint_list.GetSize();
877 for (size_t i = 0; i < num_watchpoints; ++i)
879 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
883 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
887 return true; // Success!
890 // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
892 Target::ClearAllWatchpointHitCounts ()
894 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
896 log->Printf ("Target::%s\n", __FUNCTION__);
898 size_t num_watchpoints = m_watchpoint_list.GetSize();
899 for (size_t i = 0; i < num_watchpoints; ++i)
901 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
905 wp_sp->ResetHitCount();
907 return true; // Success!
910 // Assumption: Caller holds the list mutex lock for m_watchpoint_list
911 // during these operations.
913 Target::IgnoreAllWatchpoints (uint32_t ignore_count)
915 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
917 log->Printf ("Target::%s\n", __FUNCTION__);
919 if (!ProcessIsValid())
922 size_t num_watchpoints = m_watchpoint_list.GetSize();
923 for (size_t i = 0; i < num_watchpoints; ++i)
925 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
929 wp_sp->SetIgnoreCount(ignore_count);
931 return true; // Success!
934 // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
936 Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
938 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
940 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
942 if (!ProcessIsValid())
945 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
948 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
952 // Else, fallthrough.
957 // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
959 Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
961 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
963 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
965 if (!ProcessIsValid())
968 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
971 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
975 // Else, fallthrough.
980 // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
982 Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
984 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
986 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
988 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
989 if (watch_to_remove_sp == m_last_created_watchpoint)
990 m_last_created_watchpoint.reset();
992 if (DisableWatchpointByID (watch_id))
994 m_watchpoint_list.Remove(watch_id, true);
1000 // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
1002 Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
1004 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
1006 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1008 if (!ProcessIsValid())
1011 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1014 wp_sp->SetIgnoreCount(ignore_count);
1021 Target::GetExecutableModule ()
1023 return m_images.GetModuleAtIndex(0);
1027 Target::GetExecutableModulePointer ()
1029 return m_images.GetModulePointerAtIndex(0);
1033 LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1036 StreamString feedback_stream;
1037 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
1039 if (error.AsCString())
1040 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
1041 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1044 if (feedback_stream.GetSize())
1045 target->GetDebugger().GetErrorFile()->Printf("%s\n",
1046 feedback_stream.GetData());
1050 Target::ClearModules(bool delete_locations)
1052 ModulesDidUnload (m_images, delete_locations);
1053 m_section_load_history.Clear();
1055 m_scratch_ast_context_ap.reset();
1056 m_scratch_ast_source_ap.reset();
1057 m_ast_importer_ap.reset();
1063 // When a process exec's we need to know about it so we can do some cleanup.
1064 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1065 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1069 Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1071 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
1072 ClearModules(false);
1074 if (executable_sp.get())
1076 Timer scoped_timer (__PRETTY_FUNCTION__,
1077 "Target::SetExecutableModule (executable = '%s')",
1078 executable_sp->GetFileSpec().GetPath().c_str());
1080 m_images.Append(executable_sp); // The first image is our executable file
1082 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
1083 if (!m_arch.IsValid())
1085 m_arch = executable_sp->GetArchitecture();
1087 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1090 FileSpecList dependent_files;
1091 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
1093 if (executable_objfile && get_dependent_files)
1095 executable_objfile->GetDependentModules(dependent_files);
1096 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1098 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1099 FileSpec platform_dependent_file_spec;
1101 m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
1103 platform_dependent_file_spec = dependent_file_spec;
1105 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1106 ModuleSP image_module_sp(GetSharedModule (module_spec));
1107 if (image_module_sp.get())
1109 ObjectFile *objfile = image_module_sp->GetObjectFile();
1111 objfile->GetDependentModules(dependent_files);
1120 Target::SetArchitecture (const ArchSpec &arch_spec)
1122 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
1123 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
1125 // If we haven't got a valid arch spec, or the architectures are
1126 // compatible, so just update the architecture. Architectures can be
1127 // equal, yet the triple OS and vendor might change, so we need to do
1128 // the assignment here just in case.
1131 log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
1136 // If we have an executable file, try to reset the executable to the desired architecture
1138 log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
1140 ModuleSP executable_sp = GetExecutableModule ();
1143 // Need to do something about unsetting breakpoints.
1148 log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
1149 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1150 Error error = ModuleList::GetSharedModule (module_spec,
1152 &GetExecutableSearchPaths(),
1156 if (!error.Fail() && executable_sp)
1158 SetExecutableModule (executable_sp, true);
1167 Target::WillClearList (const ModuleList& module_list)
1172 Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
1174 // A module is being added to this target for the first time
1177 ModuleList my_module_list;
1178 my_module_list.Append(module_sp);
1179 LoadScriptingResourceForModule(module_sp, this);
1180 ModulesDidLoad (my_module_list);
1185 Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
1187 // A module is being added to this target for the first time
1190 ModuleList my_module_list;
1191 my_module_list.Append(module_sp);
1192 ModulesDidUnload (my_module_list, false);
1197 Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
1199 // A module is replacing an already added module
1201 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
1205 Target::ModulesDidLoad (ModuleList &module_list)
1207 if (m_valid && module_list.GetSize())
1209 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
1212 m_process_sp->ModulesDidLoad (module_list);
1214 // TODO: make event data that packages up the module_list
1215 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1220 Target::SymbolsDidLoad (ModuleList &module_list)
1222 if (m_valid && module_list.GetSize())
1226 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1229 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1230 objc_runtime->SymbolsDidLoad(module_list);
1234 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
1235 BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL);
1240 Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
1242 if (m_valid && module_list.GetSize())
1244 UnloadModuleSections (module_list);
1245 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
1246 // TODO: make event data that packages up the module_list
1247 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1252 Target::ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_file_spec)
1254 if (GetBreakpointsConsultPlatformAvoidList())
1256 ModuleList matchingModules;
1257 ModuleSpec module_spec (module_file_spec);
1258 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
1260 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1262 if (num_modules > 0)
1264 for (size_t i = 0; i < num_modules; i++)
1266 if (!ModuleIsExcludedForUnconstrainedSearches (matchingModules.GetModuleAtIndex(i)))
1276 Target::ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp)
1278 if (GetBreakpointsConsultPlatformAvoidList())
1281 return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches (*this, module_sp);
1287 Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1289 SectionSP section_sp (addr.GetSection());
1292 // If the contents of this section are encrypted, the on-disk file is unusable. Read only from live memory.
1293 if (section_sp->IsEncrypted())
1295 error.SetErrorString("section is encrypted");
1298 ModuleSP module_sp (section_sp->GetModule());
1301 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1304 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1311 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1314 error.SetErrorString("address isn't from a object file");
1317 error.SetErrorString("address isn't in a module");
1320 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
1326 Target::ReadMemory (const Address& addr,
1327 bool prefer_file_cache,
1331 lldb::addr_t *load_addr_ptr)
1335 // if we end up reading this from process memory, we will fill this
1336 // with the actual load address
1338 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1340 size_t bytes_read = 0;
1342 addr_t load_addr = LLDB_INVALID_ADDRESS;
1343 addr_t file_addr = LLDB_INVALID_ADDRESS;
1344 Address resolved_addr;
1345 if (!addr.IsSectionOffset())
1347 SectionLoadList §ion_load_list = GetSectionLoadList();
1348 if (section_load_list.IsEmpty())
1350 // No sections are loaded, so we must assume we are not running
1351 // yet and anything we are given is a file address.
1352 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1353 m_images.ResolveFileAddress (file_addr, resolved_addr);
1357 // We have at least one section loaded. This can be because
1358 // we have manually loaded some sections with "target modules load ..."
1359 // or because we have have a live process that has sections loaded
1360 // through the dynamic loader
1361 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1362 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
1365 if (!resolved_addr.IsValid())
1366 resolved_addr = addr;
1369 if (prefer_file_cache)
1371 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1376 if (ProcessIsValid())
1378 if (load_addr == LLDB_INVALID_ADDRESS)
1379 load_addr = resolved_addr.GetLoadAddress (this);
1381 if (load_addr == LLDB_INVALID_ADDRESS)
1383 ModuleSP addr_module_sp (resolved_addr.GetModule());
1384 if (addr_module_sp && addr_module_sp->GetFileSpec())
1385 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
1386 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
1387 resolved_addr.GetFileAddress(),
1388 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknonw>"));
1390 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
1394 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
1395 if (bytes_read != dst_len)
1397 if (error.Success())
1399 if (bytes_read == 0)
1400 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
1402 error.SetErrorStringWithFormat("only %" PRIu64 " of %" PRIu64 " bytes were read from memory at 0x%" PRIx64, (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
1408 *load_addr_ptr = load_addr;
1411 // If the address is not section offset we have an address that
1412 // doesn't resolve to any address in any currently loaded shared
1413 // libraries and we failed to read memory so there isn't anything
1414 // more we can do. If it is section offset, we might be able to
1415 // read cached memory from the object file.
1416 if (!resolved_addr.IsSectionOffset())
1421 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
1423 // If we didn't already try and read from the object file cache, then
1424 // try it after failing to read from the process.
1425 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1431 Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1435 addr_t curr_addr = addr.GetLoadAddress(this);
1436 Address address(addr);
1439 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1442 out_str.append(buf, length);
1443 // If we got "length - 1" bytes, we didn't get the whole C string, we
1444 // need to read some more characters
1445 if (length == sizeof(buf) - 1)
1446 curr_addr += length;
1449 address = Address(curr_addr);
1451 return out_str.size();
1456 Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1458 size_t total_cstr_len = 0;
1459 if (dst && dst_max_len)
1461 result_error.Clear();
1462 // NULL out everything just to be safe
1463 memset (dst, 0, dst_max_len);
1465 addr_t curr_addr = addr.GetLoadAddress(this);
1466 Address address(addr);
1468 // We could call m_process_sp->GetMemoryCacheLineSize() but I don't
1469 // think this really needs to be tied to the memory cache subsystem's
1470 // cache line size, so leave this as a fixed constant.
1471 const size_t cache_line_size = 512;
1473 size_t bytes_left = dst_max_len - 1;
1474 char *curr_dst = dst;
1476 while (bytes_left > 0)
1478 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1479 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1480 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1482 if (bytes_read == 0)
1484 result_error = error;
1485 dst[total_cstr_len] = '\0';
1488 const size_t len = strlen(curr_dst);
1490 total_cstr_len += len;
1492 if (len < bytes_to_read)
1495 curr_dst += bytes_read;
1496 curr_addr += bytes_read;
1497 bytes_left -= bytes_read;
1498 address = Address(curr_addr);
1504 result_error.SetErrorString("invalid arguments");
1506 result_error.Clear();
1508 return total_cstr_len;
1512 Target::ReadScalarIntegerFromMemory (const Address& addr,
1513 bool prefer_file_cache,
1521 if (byte_size <= sizeof(uval))
1523 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1524 if (bytes_read == byte_size)
1526 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1527 lldb::offset_t offset = 0;
1529 scalar = data.GetMaxU32 (&offset, byte_size);
1531 scalar = data.GetMaxU64 (&offset, byte_size);
1534 scalar.SignExtend(byte_size * 8);
1540 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1546 Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1547 bool prefer_file_cache,
1548 size_t integer_byte_size,
1549 uint64_t fail_value,
1553 if (ReadScalarIntegerFromMemory (addr,
1559 return scalar.ULongLong(fail_value);
1564 Target::ReadPointerFromMemory (const Address& addr,
1565 bool prefer_file_cache,
1567 Address &pointer_addr)
1570 if (ReadScalarIntegerFromMemory (addr,
1572 m_arch.GetAddressByteSize(),
1577 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1578 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1580 SectionLoadList §ion_load_list = GetSectionLoadList();
1581 if (section_load_list.IsEmpty())
1583 // No sections are loaded, so we must assume we are not running
1584 // yet and anything we are given is a file address.
1585 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1589 // We have at least one section loaded. This can be because
1590 // we have manually loaded some sections with "target modules load ..."
1591 // or because we have have a live process that has sections loaded
1592 // through the dynamic loader
1593 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1595 // We weren't able to resolve the pointer value, so just return
1596 // an address with no section
1597 if (!pointer_addr.IsValid())
1598 pointer_addr.SetOffset (pointer_vm_addr);
1607 Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
1613 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1614 // to consult the shared modules list. But only do this if we are passed a UUID.
1616 if (module_spec.GetUUID().IsValid())
1617 module_sp = m_images.FindFirstModule(module_spec);
1621 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1622 bool did_create_module = false;
1624 // If there are image search path entries, try to use them first to acquire a suitable image.
1625 if (m_image_search_paths.GetSize())
1627 ModuleSpec transformed_spec (module_spec);
1628 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1630 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1631 error = ModuleList::GetSharedModule (transformed_spec,
1633 &GetExecutableSearchPaths(),
1635 &did_create_module);
1641 // If we have a UUID, we can check our global shared module list in case
1642 // we already have it. If we don't have a valid UUID, then we can't since
1643 // the path in "module_spec" will be a platform path, and we will need to
1644 // let the platform find that file. For example, we could be asking for
1645 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1646 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1647 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1649 if (module_spec.GetUUID().IsValid())
1651 // We have a UUID, it is OK to check the global module list...
1652 error = ModuleList::GetSharedModule (module_spec,
1654 &GetExecutableSearchPaths(),
1656 &did_create_module);
1661 // The platform is responsible for finding and caching an appropriate
1662 // module in the shared module cache.
1665 FileSpec platform_file_spec;
1666 error = m_platform_sp->GetSharedModule (module_spec,
1668 &GetExecutableSearchPaths(),
1670 &did_create_module);
1674 error.SetErrorString("no platform is currently set");
1679 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1680 // module in the list already, and if there was, let's remove it.
1683 ObjectFile *objfile = module_sp->GetObjectFile();
1686 switch (objfile->GetType())
1688 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1689 case ObjectFile::eTypeExecutable: /// A normal executable
1690 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1691 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1692 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1694 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1696 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1698 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1700 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1704 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1707 // GetSharedModule is not guaranteed to find the old shared module, for instance
1708 // in the common case where you pass in the UUID, it is only going to find the one
1709 // module matching the UUID. In fact, it has no good way to know what the "old module"
1710 // relevant to this target is, since there might be many copies of a module with this file spec
1711 // in various running debug sessions, but only one of them will belong to this target.
1712 // So let's remove the UUID from the module list, and look in the target's module list.
1713 // Only do this if there is SOMETHING else in the module spec...
1716 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
1718 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1719 module_spec_copy.GetUUID().Clear();
1721 ModuleList found_modules;
1722 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1725 old_module_sp = found_modules.GetModuleAtIndex(0);
1730 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1732 m_images.ReplaceModule(old_module_sp, module_sp);
1733 Module *old_module_ptr = old_module_sp.get();
1734 old_module_sp.reset();
1735 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1738 m_images.Append(module_sp);
1751 Target::CalculateTarget ()
1753 return shared_from_this();
1757 Target::CalculateProcess ()
1763 Target::CalculateThread ()
1769 Target::CalculateStackFrame ()
1771 return StackFrameSP();
1775 Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
1778 exe_ctx.SetTargetPtr(this);
1782 Target::GetImageSearchPathList ()
1784 return m_image_search_paths;
1788 Target::ImageSearchPathsChanged
1790 const PathMappingList &path_list,
1794 Target *target = (Target *)baton;
1795 ModuleSP exe_module_sp (target->GetExecutableModule());
1797 target->SetExecutableModule (exe_module_sp, true);
1801 Target::GetScratchClangASTContext(bool create_on_demand)
1803 // Now see if we know the target triple, and if so, create our scratch AST context:
1804 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
1806 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
1807 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
1808 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1809 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1810 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1812 return m_scratch_ast_context_ap.get();
1816 Target::GetClangASTImporter()
1818 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1822 ast_importer = new ClangASTImporter();
1823 m_ast_importer_ap.reset(ast_importer);
1826 return ast_importer;
1830 Target::SettingsInitialize ()
1832 Process::SettingsInitialize ();
1836 Target::SettingsTerminate ()
1838 Process::SettingsTerminate ();
1842 Target::GetDefaultExecutableSearchPaths ()
1844 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1846 return properties_sp->GetExecutableSearchPaths();
1847 return FileSpecList();
1851 Target::GetDefaultDebugFileSearchPaths ()
1853 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1855 return properties_sp->GetDebugFileSearchPaths();
1856 return FileSpecList();
1860 Target::GetDefaultArchitecture ()
1862 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1864 return properties_sp->GetDefaultArchitecture();
1869 Target::SetDefaultArchitecture (const ArchSpec &arch)
1871 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1874 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::SetDefaultArchitecture setting target's default architecture to %s (%s)", arch.GetArchitectureName(), arch.GetTriple().getTriple().c_str());
1875 return properties_sp->SetDefaultArchitecture(arch);
1880 Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1882 // The target can either exist in the "process" of ExecutionContext, or in
1883 // the "target_sp" member of SymbolContext. This accessor helper function
1884 // will get the target from one of these locations.
1886 Target *target = NULL;
1888 target = sc_ptr->target_sp.get();
1889 if (target == NULL && exe_ctx_ptr)
1890 target = exe_ctx_ptr->GetTargetPtr();
1895 Target::EvaluateExpression
1897 const char *expr_cstr,
1899 lldb::ValueObjectSP &result_valobj_sp,
1900 const EvaluateExpressionOptions& options
1903 result_valobj_sp.reset();
1905 ExpressionResults execution_results = eExpressionSetupError;
1907 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1908 return execution_results;
1910 // We shouldn't run stop hooks in expressions.
1911 // Be sure to reset this if you return anywhere within this function.
1912 bool old_suppress_value = m_suppress_stop_hooks;
1913 m_suppress_stop_hooks = true;
1915 ExecutionContext exe_ctx;
1919 frame->CalculateExecutionContext(exe_ctx);
1921 else if (m_process_sp)
1923 m_process_sp->CalculateExecutionContext(exe_ctx);
1927 CalculateExecutionContext(exe_ctx);
1930 // Make sure we aren't just trying to see the value of a persistent
1931 // variable (something like "$0")
1932 lldb::ClangExpressionVariableSP persistent_var_sp;
1933 // Only check for persistent variables the expression starts with a '$'
1934 if (expr_cstr[0] == '$')
1935 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1937 if (persistent_var_sp)
1939 result_valobj_sp = persistent_var_sp->GetValueObject ();
1940 execution_results = eExpressionCompleted;
1944 const char *prefix = GetExpressionPrefixContentsAsCString();
1946 execution_results = ClangUserExpression::Evaluate (exe_ctx,
1954 m_suppress_stop_hooks = old_suppress_value;
1956 return execution_results;
1960 Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1962 addr_t code_addr = load_addr;
1963 switch (m_arch.GetMachine())
1965 case llvm::Triple::arm:
1966 case llvm::Triple::thumb:
1969 case eAddressClassData:
1970 case eAddressClassDebug:
1971 return LLDB_INVALID_ADDRESS;
1973 case eAddressClassUnknown:
1974 case eAddressClassInvalid:
1975 case eAddressClassCode:
1976 case eAddressClassCodeAlternateISA:
1977 case eAddressClassRuntime:
1978 // Check if bit zero it no set?
1979 if ((code_addr & 1ull) == 0)
1981 // Bit zero isn't set, check if the address is a multiple of 2?
1982 if (code_addr & 2ull)
1984 // The address is a multiple of 2 so it must be thumb, set bit zero
1987 else if (addr_class == eAddressClassCodeAlternateISA)
1989 // We checked the address and the address claims to be the alternate ISA
1990 // which means thumb, so set bit zero.
2005 Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2007 addr_t opcode_addr = load_addr;
2008 switch (m_arch.GetMachine())
2010 case llvm::Triple::arm:
2011 case llvm::Triple::thumb:
2014 case eAddressClassData:
2015 case eAddressClassDebug:
2016 return LLDB_INVALID_ADDRESS;
2018 case eAddressClassInvalid:
2019 case eAddressClassUnknown:
2020 case eAddressClassCode:
2021 case eAddressClassCodeAlternateISA:
2022 case eAddressClassRuntime:
2023 opcode_addr &= ~(1ull);
2035 Target::GetSourceManager ()
2037 if (m_source_manager_ap.get() == NULL)
2038 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
2039 return *m_source_manager_ap;
2042 ClangModulesDeclVendor *
2043 Target::GetClangModulesDeclVendor ()
2045 static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
2048 Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
2050 if (!m_clang_modules_decl_vendor_ap)
2052 m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
2056 return m_clang_modules_decl_vendor_ap.get();
2060 Target::CreateStopHook ()
2062 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
2063 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2064 m_stop_hooks[new_uid] = stop_hook_sp;
2065 return stop_hook_sp;
2069 Target::RemoveStopHookByID (lldb::user_id_t user_id)
2072 num_removed = m_stop_hooks.erase (user_id);
2073 if (num_removed == 0)
2080 Target::RemoveAllStopHooks ()
2082 m_stop_hooks.clear();
2086 Target::GetStopHookByID (lldb::user_id_t user_id)
2088 StopHookSP found_hook;
2090 StopHookCollection::iterator specified_hook_iter;
2091 specified_hook_iter = m_stop_hooks.find (user_id);
2092 if (specified_hook_iter != m_stop_hooks.end())
2093 found_hook = (*specified_hook_iter).second;
2098 Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2100 StopHookCollection::iterator specified_hook_iter;
2101 specified_hook_iter = m_stop_hooks.find (user_id);
2102 if (specified_hook_iter == m_stop_hooks.end())
2105 (*specified_hook_iter).second->SetIsActive (active_state);
2110 Target::SetAllStopHooksActiveState (bool active_state)
2112 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2113 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2115 (*pos).second->SetIsActive (active_state);
2120 Target::RunStopHooks ()
2122 if (m_suppress_stop_hooks)
2128 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2129 // since in that case we do not want to run the stop-hooks
2130 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2133 if (m_stop_hooks.empty())
2136 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2138 // If there aren't any active stop hooks, don't bother either:
2139 bool any_active_hooks = false;
2140 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2142 if ((*pos).second->IsActive())
2144 any_active_hooks = true;
2148 if (!any_active_hooks)
2151 CommandReturnObject result;
2153 std::vector<ExecutionContext> exc_ctx_with_reasons;
2154 std::vector<SymbolContext> sym_ctx_with_reasons;
2156 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2157 size_t num_threads = cur_threadlist.GetSize();
2158 for (size_t i = 0; i < num_threads; i++)
2160 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2161 if (cur_thread_sp->ThreadStoppedForAReason())
2163 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
2164 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2165 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2169 // If no threads stopped for a reason, don't run the stop-hooks.
2170 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2171 if (num_exe_ctx == 0)
2174 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2175 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
2177 bool keep_going = true;
2178 bool hooks_ran = false;
2179 bool print_hook_header;
2180 bool print_thread_header;
2182 if (num_exe_ctx == 1)
2183 print_thread_header = false;
2185 print_thread_header = true;
2187 if (m_stop_hooks.size() == 1)
2188 print_hook_header = false;
2190 print_hook_header = true;
2192 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2195 StopHookSP cur_hook_sp = (*pos).second;
2196 if (!cur_hook_sp->IsActive())
2199 bool any_thread_matched = false;
2200 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2202 if ((cur_hook_sp->GetSpecifier () == NULL
2203 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2204 && (cur_hook_sp->GetThreadSpecifier() == NULL
2205 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
2211 if (print_hook_header && !any_thread_matched)
2213 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2214 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2217 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
2219 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
2220 any_thread_matched = true;
2223 if (print_thread_header)
2224 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
2226 CommandInterpreterRunOptions options;
2227 options.SetStopOnContinue (true);
2228 options.SetStopOnError (true);
2229 options.SetEchoCommands (false);
2230 options.SetPrintResults (true);
2231 options.SetAddToHistory (false);
2233 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
2234 &exc_ctx_with_reasons[i],
2238 // If the command started the target going again, we should bag out of
2239 // running the stop hooks.
2240 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2241 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
2243 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
2250 result.GetImmediateOutputStream()->Flush();
2251 result.GetImmediateErrorStream()->Flush();
2254 const TargetPropertiesSP &
2255 Target::GetGlobalProperties()
2257 static TargetPropertiesSP g_settings_sp;
2260 g_settings_sp.reset (new TargetProperties (NULL));
2262 return g_settings_sp;
2266 Target::Install (ProcessLaunchInfo *launch_info)
2269 PlatformSP platform_sp (GetPlatform());
2272 if (platform_sp->IsRemote())
2274 if (platform_sp->IsConnected())
2276 // Install all files that have an install path, and always install the
2277 // main executable when connected to a remote platform
2278 const ModuleList& modules = GetImages();
2279 const size_t num_images = modules.GetSize();
2280 for (size_t idx = 0; idx < num_images; ++idx)
2282 const bool is_main_executable = idx == 0;
2283 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2286 FileSpec local_file (module_sp->GetFileSpec());
2289 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2292 if (is_main_executable) // TODO: add setting for always installing main executable???
2294 // Always install the main executable
2295 remote_file.GetDirectory() = platform_sp->GetWorkingDirectory();
2296 remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename();
2301 error = platform_sp->Install(local_file, remote_file);
2302 if (error.Success())
2304 module_sp->SetPlatformFileSpec(remote_file);
2305 if (is_main_executable)
2308 launch_info->SetExecutableFile(remote_file, false);
2324 Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2326 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2330 Target::ResolveFileAddress (lldb::addr_t file_addr, Address &resolved_addr)
2332 return m_images.ResolveFileAddress(file_addr, resolved_addr);
2336 Target::SetSectionLoadAddress (const SectionSP §ion_sp, addr_t new_section_load_addr, bool warn_multiple)
2338 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2339 if (old_section_load_addr != new_section_load_addr)
2341 uint32_t stop_id = 0;
2342 ProcessSP process_sp(GetProcessSP());
2344 stop_id = process_sp->GetStopID();
2346 stop_id = m_section_load_history.GetLastStopID();
2347 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2348 return true; // Return true if the section load address was changed...
2350 return false; // Return false to indicate nothing changed
2355 Target::UnloadModuleSections (const ModuleList &module_list)
2357 size_t section_unload_count = 0;
2358 size_t num_modules = module_list.GetSize();
2359 for (size_t i=0; i<num_modules; ++i)
2361 section_unload_count += UnloadModuleSections (module_list.GetModuleAtIndex(i));
2363 return section_unload_count;
2367 Target::UnloadModuleSections (const lldb::ModuleSP &module_sp)
2369 uint32_t stop_id = 0;
2370 ProcessSP process_sp(GetProcessSP());
2372 stop_id = process_sp->GetStopID();
2374 stop_id = m_section_load_history.GetLastStopID();
2375 SectionList *sections = module_sp->GetSectionList();
2376 size_t section_unload_count = 0;
2379 const uint32_t num_sections = sections->GetNumSections(0);
2380 for (uint32_t i = 0; i < num_sections; ++i)
2382 section_unload_count += m_section_load_history.SetSectionUnloaded(stop_id, sections->GetSectionAtIndex(i));
2385 return section_unload_count;
2389 Target::SetSectionUnloaded (const lldb::SectionSP §ion_sp)
2391 uint32_t stop_id = 0;
2392 ProcessSP process_sp(GetProcessSP());
2394 stop_id = process_sp->GetStopID();
2396 stop_id = m_section_load_history.GetLastStopID();
2397 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2401 Target::SetSectionUnloaded (const lldb::SectionSP §ion_sp, addr_t load_addr)
2403 uint32_t stop_id = 0;
2404 ProcessSP process_sp(GetProcessSP());
2406 stop_id = process_sp->GetStopID();
2408 stop_id = m_section_load_history.GetLastStopID();
2409 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2413 Target::ClearAllLoadedSections ()
2415 m_section_load_history.Clear();
2420 Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
2423 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
2426 log->Printf ("Target::%s() called for %s", __FUNCTION__, launch_info.GetExecutableFile().GetPath().c_str ());
2428 StateType state = eStateInvalid;
2430 // Scope to temporarily get the process state in case someone has manually
2431 // remotely connected already to a process and we can skip the platform
2434 ProcessSP process_sp (GetProcessSP());
2438 state = process_sp->GetState();
2440 log->Printf ("Target::%s the process exists, and its current state is %s", __FUNCTION__, StateAsCString (state));
2445 log->Printf ("Target::%s the process instance doesn't currently exist.", __FUNCTION__);
2449 launch_info.GetFlags().Set (eLaunchFlagDebug);
2451 // Get the value of synchronous execution here. If you wait till after you have started to
2452 // run, then you could have hit a breakpoint, whose command might switch the value, and
2453 // then you'll pick up that incorrect value.
2454 Debugger &debugger = GetDebugger();
2455 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2457 PlatformSP platform_sp (GetPlatform());
2459 // Finalize the file actions, and if none were given, default to opening
2460 // up a pseudo terminal
2461 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
2463 log->Printf ("Target::%s have platform=%s, platform_sp->IsHost()=%s, default_to_use_pty=%s",
2465 platform_sp ? "true" : "false",
2466 platform_sp ? (platform_sp->IsHost () ? "true" : "false") : "n/a",
2467 default_to_use_pty ? "true" : "false");
2469 launch_info.FinalizeFileActions (this, default_to_use_pty);
2471 if (state == eStateConnected)
2473 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2475 error.SetErrorString("can't launch in tty when launching through a remote connection");
2480 if (!launch_info.GetArchitecture().IsValid())
2481 launch_info.GetArchitecture() = GetArchitecture();
2483 // If we're not already connected to the process, and if we have a platform that can launch a process for debugging, go ahead and do that here.
2484 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
2487 log->Printf ("Target::%s asking the platform to debug the process", __FUNCTION__);
2489 m_process_sp = GetPlatform()->DebugProcess (launch_info,
2497 log->Printf ("Target::%s the platform doesn't know how to debug a process, getting a process plugin to do this for us.", __FUNCTION__);
2499 if (state == eStateConnected)
2501 assert(m_process_sp);
2505 // Use a Process plugin to construct the process.
2506 const char *plugin_name = launch_info.GetProcessPluginName();
2507 CreateProcess (launch_info.GetListenerForProcess(debugger), plugin_name, NULL);
2510 // Since we didn't have a platform launch the process, launch it here.
2512 error = m_process_sp->Launch (launch_info);
2517 if (error.Success())
2518 error.SetErrorString("failed to launch or debug process");
2522 if (error.Success())
2524 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
2526 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
2528 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get(), NULL);
2530 if (state == eStateStopped)
2532 if (!synchronous_execution)
2533 m_process_sp->RestoreProcessEvents ();
2535 error = m_process_sp->PrivateResume();
2537 if (error.Success())
2539 // there is a race condition where this thread will return up the call stack to the main command
2540 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
2541 // a chance to call PushProcessIOHandler()
2542 m_process_sp->SyncIOHandler(2000);
2544 if (synchronous_execution)
2546 state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get(), stream);
2547 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2548 if (!StateIsStoppedState(state, must_be_alive))
2550 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
2557 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
2561 else if (state == eStateExited)
2563 bool with_shell = !!launch_info.GetShell();
2564 const int exit_status = m_process_sp->GetExitStatus();
2565 const char *exit_desc = m_process_sp->GetExitDescription();
2566 #define LAUNCH_SHELL_MESSAGE "\n'r' and 'run' are aliases that default to launching through a shell.\nTry launching without going through a shell by using 'process launch'."
2567 if (exit_desc && exit_desc[0])
2570 error.SetErrorStringWithFormat ("process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, exit_status, exit_desc);
2572 error.SetErrorStringWithFormat ("process exited with status %i (%s)", exit_status, exit_desc);
2577 error.SetErrorStringWithFormat ("process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
2579 error.SetErrorStringWithFormat ("process exited with status %i", exit_status);
2584 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2587 m_process_sp->RestoreProcessEvents ();
2592 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
2597 //--------------------------------------------------------------
2599 //--------------------------------------------------------------
2600 Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2602 m_target_sp (target_sp),
2610 Target::StopHook::StopHook (const StopHook &rhs) :
2611 UserID (rhs.GetID()),
2612 m_target_sp (rhs.m_target_sp),
2613 m_commands (rhs.m_commands),
2614 m_specifier_sp (rhs.m_specifier_sp),
2615 m_thread_spec_ap (),
2616 m_active (rhs.m_active)
2618 if (rhs.m_thread_spec_ap.get() != NULL)
2619 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2623 Target::StopHook::~StopHook ()
2628 Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2630 m_thread_spec_ap.reset (specifier);
2635 Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2637 int indent_level = s->GetIndentLevel();
2639 s->SetIndentLevel(indent_level + 2);
2641 s->Printf ("Hook: %" PRIu64 "\n", GetID());
2643 s->Indent ("State: enabled\n");
2645 s->Indent ("State: disabled\n");
2650 s->PutCString ("Specifier:\n");
2651 s->SetIndentLevel (indent_level + 4);
2652 m_specifier_sp->GetDescription (s, level);
2653 s->SetIndentLevel (indent_level + 2);
2656 if (m_thread_spec_ap.get() != NULL)
2659 s->Indent("Thread:\n");
2660 m_thread_spec_ap->GetDescription (&tmp, level);
2661 s->SetIndentLevel (indent_level + 4);
2662 s->Indent (tmp.GetData());
2663 s->PutCString ("\n");
2664 s->SetIndentLevel (indent_level + 2);
2667 s->Indent ("Commands: \n");
2668 s->SetIndentLevel (indent_level + 4);
2669 uint32_t num_commands = m_commands.GetSize();
2670 for (uint32_t i = 0; i < num_commands; i++)
2672 s->Indent(m_commands.GetStringAtIndex(i));
2673 s->PutCString ("\n");
2675 s->SetIndentLevel (indent_level);
2678 //--------------------------------------------------------------
2679 // class TargetProperties
2680 //--------------------------------------------------------------
2682 OptionEnumValueElement
2683 lldb_private::g_dynamic_value_types[] =
2685 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2686 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2687 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2691 static OptionEnumValueElement
2692 g_inline_breakpoint_enums[] =
2694 { eInlineBreakpointsNever, "never", "Never look for inline breakpoint locations (fastest). This setting should only be used if you know that no inlining occurs in your programs."},
2695 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2696 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2700 typedef enum x86DisassemblyFlavor
2702 eX86DisFlavorDefault,
2705 } x86DisassemblyFlavor;
2707 static OptionEnumValueElement
2708 g_x86_dis_flavor_value_types[] =
2710 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2711 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2712 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2716 static OptionEnumValueElement
2717 g_hex_immediate_style_values[] =
2719 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
2720 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
2724 static OptionEnumValueElement
2725 g_load_script_from_sym_file_values[] =
2727 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
2728 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
2729 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
2734 static OptionEnumValueElement
2735 g_memory_module_load_level_values[] =
2737 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
2738 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
2739 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
2743 static PropertyDefinition
2746 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2747 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2748 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eDynamicDontRunTarget , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2749 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2750 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2751 { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and "
2752 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2753 "some part (starting at the root) of the path to the file when it was built, "
2754 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2755 "Each element of the array is checked in order and the first one that results in a match wins." },
2756 { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
2757 { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating debug symbol files." },
2758 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2759 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
2760 { "max-memory-read-size" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of bytes that 'memory read' will fetch before --force must be specified." },
2761 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
2762 { "arg0" , OptionValue::eTypeString , false, 0 , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." },
2763 { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." },
2764 { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2765 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2766 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2767 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2768 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2769 { "detach-on-error" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "debugserver will detach (rather than killing) a process if it loses connection with lldb." },
2770 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2771 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" },
2772 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsAlways , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
2773 "Breakpoint locations can end up being inlined by the compiler, so that a compile unit 'a.c' might contain an inlined function from another source file. "
2774 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2775 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
2776 "Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers "
2777 "and find that setting breakpoints is slow, then you can change this setting to headers. "
2778 "This setting allows you to control exactly which strategy is used when setting "
2779 "file and line breakpoints." },
2780 // FIXME: This is the wrong way to do per-architecture settings, but we don't have a general per architecture settings system in place yet.
2781 { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, NULL, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." },
2782 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
2783 { "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, NULL, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." },
2784 { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." },
2785 { "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, eLoadScriptFromSymFileWarn, NULL, g_load_script_from_sym_file_values, "Allow LLDB to load scripting resources embedded in symbol files when available." },
2786 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
2787 "Loading modules from memory can be slow as reading the symbol tables and other data can take a long time depending on your connection to the debug target. "
2788 "This setting helps users control how much information gets loaded when loading modules from memory."
2789 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
2790 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
2791 "'minimal' is the fastest setting and will load section data with no symbols, but should rarely be used as stack frames in these memory regions will be inaccurate and not provide any context (fastest). " },
2792 { "display-expression-in-crashlogs" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "Expressions that crash will show up in crash logs if the host system supports executable specific crash log strings and this setting is set to true." },
2793 { "trap-handler-names" , OptionValue::eTypeArray , true, OptionValue::eTypeString, NULL, NULL, "A list of trap handler function names, e.g. a common Unix user process one is _sigtramp." },
2794 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2798 ePropertyDefaultArch,
2799 ePropertyExprPrefix,
2800 ePropertyPreferDynamic,
2801 ePropertyEnableSynthetic,
2802 ePropertySkipPrologue,
2804 ePropertyExecutableSearchPaths,
2805 ePropertyDebugFileSearchPaths,
2806 ePropertyMaxChildrenCount,
2807 ePropertyMaxSummaryLength,
2808 ePropertyMaxMemReadSize,
2809 ePropertyBreakpointUseAvoidList,
2813 ePropertyInheritEnv,
2815 ePropertyOutputPath,
2817 ePropertyDetachOnError,
2818 ePropertyDisableASLR,
2819 ePropertyDisableSTDIO,
2820 ePropertyInlineStrategy,
2821 ePropertyDisassemblyFlavor,
2822 ePropertyUseHexImmediates,
2823 ePropertyHexImmediateStyle,
2824 ePropertyUseFastStepping,
2825 ePropertyLoadScriptFromSymbolFile,
2826 ePropertyMemoryModuleLoadLevel,
2827 ePropertyDisplayExpressionsInCrashlogs,
2828 ePropertyTrapHandlerNames
2832 class TargetOptionValueProperties : public OptionValueProperties
2835 TargetOptionValueProperties (const ConstString &name) :
2836 OptionValueProperties (name),
2838 m_got_host_env (false)
2842 // This constructor is used when creating TargetOptionValueProperties when it
2843 // is part of a new lldb_private::Target instance. It will copy all current
2844 // global property values as needed
2845 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2846 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2848 m_got_host_env (false)
2852 virtual const Property *
2853 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2855 // When getting the value for a key from the target options, we will always
2856 // try and grab the setting from the current target if there is one. Else we just
2857 // use the one from this instance.
2858 if (idx == ePropertyEnvVars)
2859 GetHostEnvironmentIfNeeded ();
2863 Target *target = exe_ctx->GetTargetPtr();
2866 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2867 if (this != target_properties)
2868 return target_properties->ProtectedGetPropertyAtIndex (idx);
2871 return ProtectedGetPropertyAtIndex (idx);
2877 return m_target->shared_from_this();
2883 GetHostEnvironmentIfNeeded () const
2885 if (!m_got_host_env)
2889 m_got_host_env = true;
2890 const uint32_t idx = ePropertyInheritEnv;
2891 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2893 PlatformSP platform_sp (m_target->GetPlatform());
2897 if (platform_sp->GetEnvironment(env))
2899 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2902 const bool can_replace = false;
2903 const size_t envc = env.GetSize();
2904 for (size_t idx=0; idx<envc; idx++)
2906 const char *env_entry = env.GetStringAtIndex (idx);
2909 const char *equal_pos = ::strchr(env_entry, '=');
2911 // It is ok to have environment variables with no values
2912 const char *value = NULL;
2915 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2917 value = equal_pos + 1;
2921 key.SetCString(env_entry);
2923 // Don't allow existing keys to be replaced with ones we get from the platform environment
2924 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2935 mutable bool m_got_host_env;
2938 //----------------------------------------------------------------------
2940 //----------------------------------------------------------------------
2941 TargetProperties::TargetProperties (Target *target) :
2946 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
2950 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2951 m_collection_sp->Initialize(g_properties);
2952 m_collection_sp->AppendProperty(ConstString("process"),
2953 ConstString("Settings specify to processes."),
2955 Process::GetGlobalProperties()->GetValueProperties());
2959 TargetProperties::~TargetProperties ()
2963 TargetProperties::GetDefaultArchitecture () const
2965 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2967 return value->GetCurrentValue();
2972 TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2974 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2976 return value->SetCurrentValue(arch, true);
2979 lldb::DynamicValueType
2980 TargetProperties::GetPreferDynamicValue() const
2982 const uint32_t idx = ePropertyPreferDynamic;
2983 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2987 TargetProperties::GetDisableASLR () const
2989 const uint32_t idx = ePropertyDisableASLR;
2990 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2994 TargetProperties::SetDisableASLR (bool b)
2996 const uint32_t idx = ePropertyDisableASLR;
2997 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3001 TargetProperties::GetDetachOnError () const
3003 const uint32_t idx = ePropertyDetachOnError;
3004 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3008 TargetProperties::SetDetachOnError (bool b)
3010 const uint32_t idx = ePropertyDetachOnError;
3011 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3015 TargetProperties::GetDisableSTDIO () const
3017 const uint32_t idx = ePropertyDisableSTDIO;
3018 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3022 TargetProperties::SetDisableSTDIO (bool b)
3024 const uint32_t idx = ePropertyDisableSTDIO;
3025 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3029 TargetProperties::GetDisassemblyFlavor () const
3031 const uint32_t idx = ePropertyDisassemblyFlavor;
3032 const char *return_value;
3034 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3035 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
3036 return return_value;
3040 TargetProperties::GetInlineStrategy () const
3042 const uint32_t idx = ePropertyInlineStrategy;
3043 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3047 TargetProperties::GetArg0 () const
3049 const uint32_t idx = ePropertyArg0;
3050 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
3054 TargetProperties::SetArg0 (const char *arg)
3056 const uint32_t idx = ePropertyArg0;
3057 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
3061 TargetProperties::GetRunArguments (Args &args) const
3063 const uint32_t idx = ePropertyRunArgs;
3064 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3068 TargetProperties::SetRunArguments (const Args &args)
3070 const uint32_t idx = ePropertyRunArgs;
3071 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3075 TargetProperties::GetEnvironmentAsArgs (Args &env) const
3077 const uint32_t idx = ePropertyEnvVars;
3078 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
3082 TargetProperties::GetSkipPrologue() const
3084 const uint32_t idx = ePropertySkipPrologue;
3085 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3089 TargetProperties::GetSourcePathMap () const
3091 const uint32_t idx = ePropertySourceMap;
3092 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
3093 assert(option_value);
3094 return option_value->GetCurrentValue();
3098 TargetProperties::GetExecutableSearchPaths ()
3100 const uint32_t idx = ePropertyExecutableSearchPaths;
3101 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3102 assert(option_value);
3103 return option_value->GetCurrentValue();
3107 TargetProperties::GetDebugFileSearchPaths ()
3109 const uint32_t idx = ePropertyDebugFileSearchPaths;
3110 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3111 assert(option_value);
3112 return option_value->GetCurrentValue();
3116 TargetProperties::GetEnableSyntheticValue () const
3118 const uint32_t idx = ePropertyEnableSynthetic;
3119 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3123 TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
3125 const uint32_t idx = ePropertyMaxChildrenCount;
3126 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3130 TargetProperties::GetMaximumSizeOfStringSummary() const
3132 const uint32_t idx = ePropertyMaxSummaryLength;
3133 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3137 TargetProperties::GetMaximumMemReadSize () const
3139 const uint32_t idx = ePropertyMaxMemReadSize;
3140 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3144 TargetProperties::GetStandardInputPath () const
3146 const uint32_t idx = ePropertyInputPath;
3147 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3151 TargetProperties::SetStandardInputPath (const char *p)
3153 const uint32_t idx = ePropertyInputPath;
3154 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3158 TargetProperties::GetStandardOutputPath () const
3160 const uint32_t idx = ePropertyOutputPath;
3161 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3165 TargetProperties::SetStandardOutputPath (const char *p)
3167 const uint32_t idx = ePropertyOutputPath;
3168 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3172 TargetProperties::GetStandardErrorPath () const
3174 const uint32_t idx = ePropertyErrorPath;
3175 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
3179 TargetProperties::GetExpressionPrefixContentsAsCString ()
3181 const uint32_t idx = ePropertyExprPrefix;
3182 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3185 const bool null_terminate = true;
3186 DataBufferSP data_sp(file->GetFileContents(null_terminate));
3188 return (const char *) data_sp->GetBytes();
3194 TargetProperties::SetStandardErrorPath (const char *p)
3196 const uint32_t idx = ePropertyErrorPath;
3197 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3201 TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3203 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3204 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3208 TargetProperties::GetUseHexImmediates () const
3210 const uint32_t idx = ePropertyUseHexImmediates;
3211 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3215 TargetProperties::GetUseFastStepping () const
3217 const uint32_t idx = ePropertyUseFastStepping;
3218 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3222 TargetProperties::GetDisplayExpressionsInCrashlogs () const
3224 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3225 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3228 LoadScriptFromSymFile
3229 TargetProperties::GetLoadScriptFromSymbolFile () const
3231 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
3232 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3235 Disassembler::HexImmediateStyle
3236 TargetProperties::GetHexImmediateStyle () const
3238 const uint32_t idx = ePropertyHexImmediateStyle;
3239 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3242 MemoryModuleLoadLevel
3243 TargetProperties::GetMemoryModuleLoadLevel() const
3245 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3246 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3250 TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
3252 const uint32_t idx = ePropertyTrapHandlerNames;
3253 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3257 TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
3259 const uint32_t idx = ePropertyTrapHandlerNames;
3260 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3263 //----------------------------------------------------------------------
3264 // Target::TargetEventData
3265 //----------------------------------------------------------------------
3267 Target::TargetEventData::GetFlavorString ()
3269 static ConstString g_flavor ("Target::TargetEventData");
3274 Target::TargetEventData::GetFlavor () const
3276 return TargetEventData::GetFlavorString ();
3279 Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
3281 m_target_sp (new_target_sp)
3285 Target::TargetEventData::~TargetEventData()
3291 Target::TargetEventData::Dump (Stream *s) const
3297 Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
3301 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
3303 target_sp = data->m_target_sp;
3308 const Target::TargetEventData *
3309 Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3313 const EventData *event_data = event_ptr->GetData();
3314 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3315 return static_cast <const TargetEventData *> (event_ptr->GetData());