blob: 40f6bdf4015f2fdd680c3626458c5ab3a8117034 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Target/Target.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Breakpoint/BreakpointResolver.h"
19#include "lldb/Breakpoint/BreakpointResolverAddress.h"
20#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham969795f2011-09-21 01:17:13 +000021#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chen01a67862011-10-14 00:42:25 +000023#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000024#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Event.h"
26#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/ModuleSpec.h"
29#include "lldb/Core/Section.h"
Greg Clayton9585fbf2013-03-19 00:20:55 +000030#include "lldb/Core/SourceManager.h"
Greg Claytonb09c5382013-12-13 17:20:18 +000031#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000032#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000034#include "lldb/Core/Timer.h"
35#include "lldb/Core/ValueObject.h"
Sean Callanan4bf80d52011-11-15 22:27:19 +000036#include "lldb/Expression/ClangASTSource.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000037#include "lldb/Expression/ClangUserExpression.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000038#include "lldb/Expression/ClangModulesDeclVendor.h"
Zachary Turner10687b02014-10-20 17:46:43 +000039#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:59 +000041#include "lldb/Interpreter/CommandInterpreter.h"
42#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chenb90827e2012-06-04 23:19:54 +000043#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000044#include "lldb/Interpreter/OptionValues.h"
45#include "lldb/Interpreter/Property.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/lldb-private-log.h"
47#include "lldb/Symbol/ObjectFile.h"
48#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000049#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000050#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000051#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000052#include "lldb/Target/Thread.h"
53#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
57
Zachary Turner32abc6e2015-03-03 19:23:09 +000058namespace {
59// This event data class is for use by the TargetList to broadcast new target notifications.
60class TargetEventData : public EventData
61{
62public:
63 TargetEventData(const lldb::TargetSP &new_target_sp)
64 : EventData()
65 , m_target_sp(new_target_sp)
66 {
67 }
68
69 virtual ~TargetEventData()
70 {
71 }
72
73 static const ConstString &
74 GetFlavorString()
75 {
76 static ConstString g_flavor("Target::TargetEventData");
77 return g_flavor;
78 }
79
80 virtual const ConstString &
81 GetFlavor() const
82 {
83 return GetFlavorString();
84 }
85
86 lldb::TargetSP &
87 GetTarget()
88 {
89 return m_target_sp;
90 }
91
92 virtual void
93 Dump(Stream *s) const
94 {
95 }
96
97 static const lldb::TargetSP
98 GetTargetFromEvent(const lldb::EventSP &event_sp)
99 {
100 TargetSP target_sp;
101
102 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
103 if (data)
104 target_sp = data->m_target_sp;
105
106 return target_sp;
107 }
108
109 static const TargetEventData *
110 GetEventDataFromEvent(const Event *event_ptr)
111 {
112 if (event_ptr)
113 {
114 const EventData *event_data = event_ptr->GetData();
115 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
116 return static_cast <const TargetEventData *> (event_ptr->GetData());
117 }
118 return nullptr;
119 }
120
121private:
122 lldb::TargetSP m_target_sp;
123
124 DISALLOW_COPY_AND_ASSIGN (TargetEventData);
125};
126}
127
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000128ConstString &
129Target::GetStaticBroadcasterClass ()
130{
131 static ConstString class_name ("lldb.target");
132 return class_name;
133}
134
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135//----------------------------------------------------------------------
136// Target constructor
137//----------------------------------------------------------------------
Jim Ingham893c9322014-11-22 01:42:44 +0000138Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp, bool is_dummy_target) :
Greg Clayton67cc0632012-08-22 17:17:09 +0000139 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +0000140 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +0000141 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +0000142 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +0000143 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +0000144 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +0000145 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +0000146 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +0000147 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148 m_breakpoint_list (false),
149 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +0000150 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +0000151 m_process_sp (),
152 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Claytone01e07b2013-04-18 18:10:51 +0000154 m_scratch_ast_context_ap (),
155 m_scratch_ast_source_ap (),
156 m_ast_importer_ap (),
Zachary Turner32abc6e2015-03-03 19:23:09 +0000157 m_persistent_variables (new ClangPersistentVariables),
Greg Clayton9585fbf2013-03-19 00:20:55 +0000158 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +0000159 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +0000160 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +0000161 m_valid (true),
Jim Ingham893c9322014-11-22 01:42:44 +0000162 m_suppress_stop_hooks (false),
163 m_is_dummy_target(is_dummy_target)
164
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000166 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
167 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
168 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +0000169 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +0000170 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000171
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000172 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000173
Greg Clayton5160ce52013-03-27 23:08:40 +0000174 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000176 log->Printf ("%p Target::Target()", static_cast<void*>(this));
Jason Molendae1b68ad2012-12-05 00:25:49 +0000177 if (m_arch.IsValid())
178 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000179 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::Target created with architecture %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
Jason Molendae1b68ad2012-12-05 00:25:49 +0000180 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181}
182
Jim Ingham893c9322014-11-22 01:42:44 +0000183void
184Target::PrimeFromDummyTarget(Target *target)
185{
186 if (!target)
187 return;
188
189 m_stop_hooks = target->m_stop_hooks;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000190
191 for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints())
192 {
193 if (breakpoint_sp->IsInternal())
194 continue;
195
196 BreakpointSP new_bp (new Breakpoint (*this, *breakpoint_sp.get()));
197 AddBreakpoint (new_bp, false);
198 }
Jim Ingham893c9322014-11-22 01:42:44 +0000199}
200
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201//----------------------------------------------------------------------
202// Destructor
203//----------------------------------------------------------------------
204Target::~Target()
205{
Greg Clayton5160ce52013-03-27 23:08:40 +0000206 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000208 log->Printf ("%p Target::~Target()", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209 DeleteCurrentProcess ();
210}
211
212void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000213Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214{
Greg Clayton89411422010-10-08 00:21:05 +0000215// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000216 if (description_level != lldb::eDescriptionLevelBrief)
217 {
218 s->Indent();
219 s->PutCString("Target\n");
220 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000221 m_images.Dump(s);
222 m_breakpoint_list.Dump(s);
223 m_internal_breakpoint_list.Dump(s);
224 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000225 }
226 else
227 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000228 Module *exe_module = GetExecutableModulePointer();
229 if (exe_module)
230 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000231 else
232 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234}
235
236void
Greg Clayton90ba8112012-12-05 00:16:59 +0000237Target::CleanupProcess ()
238{
239 // Do any cleanup of the target we need to do between process instances.
240 // NB It is better to do this before destroying the process in case the
241 // clean up needs some help from the process.
242 m_breakpoint_list.ClearAllBreakpointSites();
243 m_internal_breakpoint_list.ClearAllBreakpointSites();
244 // Disable watchpoints just on the debugger side.
245 Mutex::Locker locker;
246 this->GetWatchpointList().GetListMutex(locker);
247 DisableAllWatchpoints(false);
248 ClearAllWatchpointHitCounts();
Enrico Granata5e3fe042015-02-11 00:37:54 +0000249 ClearAllWatchpointHistoricValues();
Greg Clayton90ba8112012-12-05 00:16:59 +0000250}
251
252void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253Target::DeleteCurrentProcess ()
254{
255 if (m_process_sp.get())
256 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000257 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 if (m_process_sp->IsAlive())
259 m_process_sp->Destroy();
Jim Inghamd0a3e122011-02-16 17:54:55 +0000260
261 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262
Greg Clayton90ba8112012-12-05 00:16:59 +0000263 CleanupProcess ();
264
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 m_process_sp.reset();
266 }
267}
268
269const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000270Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271{
272 DeleteCurrentProcess ();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000273 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 return m_process_sp;
275}
276
277const lldb::ProcessSP &
278Target::GetProcessSP () const
279{
280 return m_process_sp;
281}
282
Greg Clayton3418c852011-08-10 02:10:13 +0000283void
284Target::Destroy()
285{
286 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000287 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000288 DeleteCurrentProcess ();
289 m_platform_sp.reset();
290 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000291 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000292 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000293 const bool notify = false;
294 m_breakpoint_list.RemoveAll(notify);
295 m_internal_breakpoint_list.RemoveAll(notify);
296 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000297 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000298 m_search_filter_sp.reset();
299 m_image_search_paths.Clear(notify);
Zachary Turner32abc6e2015-03-03 19:23:09 +0000300 m_persistent_variables->Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000301 m_stop_hooks.clear();
302 m_stop_hook_next_id = 0;
303 m_suppress_stop_hooks = false;
304}
305
306
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307BreakpointList &
308Target::GetBreakpointList(bool internal)
309{
310 if (internal)
311 return m_internal_breakpoint_list;
312 else
313 return m_breakpoint_list;
314}
315
316const BreakpointList &
317Target::GetBreakpointList(bool internal) const
318{
319 if (internal)
320 return m_internal_breakpoint_list;
321 else
322 return m_breakpoint_list;
323}
324
325BreakpointSP
326Target::GetBreakpointByID (break_id_t break_id)
327{
328 BreakpointSP bp_sp;
329
330 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
331 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
332 else
333 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
334
335 return bp_sp;
336}
337
338BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000339Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000340 const FileSpecList *source_file_spec_list,
341 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000342 bool internal,
343 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344{
Jim Ingham87df91b2011-09-23 00:54:11 +0000345 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
346 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000347 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000348}
349
350
351BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000352Target::CreateBreakpoint (const FileSpecList *containingModules,
353 const FileSpec &file,
354 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000355 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000356 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000357 bool internal,
358 bool hardware)
Jim Ingham969795f2011-09-21 01:17:13 +0000359{
Greg Clayton1f746072012-08-29 21:13:06 +0000360 if (check_inlines == eLazyBoolCalculate)
361 {
362 const InlineStrategy inline_strategy = GetInlineStrategy();
363 switch (inline_strategy)
364 {
365 case eInlineBreakpointsNever:
366 check_inlines = eLazyBoolNo;
367 break;
368
369 case eInlineBreakpointsHeaders:
370 if (file.IsSourceImplementationFile())
371 check_inlines = eLazyBoolNo;
372 else
373 check_inlines = eLazyBoolYes;
374 break;
375
376 case eInlineBreakpointsAlways:
377 check_inlines = eLazyBoolYes;
378 break;
379 }
380 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000381 SearchFilterSP filter_sp;
382 if (check_inlines == eLazyBoolNo)
383 {
384 // Not checking for inlines, we are looking only for matching compile units
385 FileSpecList compile_unit_list;
386 compile_unit_list.Append (file);
387 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
388 }
389 else
390 {
391 filter_sp = GetSearchFilterForModuleList (containingModules);
392 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000393 if (skip_prologue == eLazyBoolCalculate)
394 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
395
Greg Clayton1f746072012-08-29 21:13:06 +0000396 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
397 file,
398 line_no,
399 check_inlines,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000400 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000401 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402}
403
404
405BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000406Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 Address so_addr;
409 // Attempt to resolve our load address if possible, though it is ok if
410 // it doesn't resolve to section/offset.
411
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000412 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000413 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000414 if (!so_addr.IsValid())
415 {
416 // The address didn't resolve, so just set this as an absolute address
417 so_addr.SetOffset (addr);
418 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000419 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 return bp_sp;
421}
422
423BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000424Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425{
Jim Ingham33df7cd2014-12-06 01:28:03 +0000426 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000428 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429}
430
431BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000432Target::CreateBreakpoint (const FileSpecList *containingModules,
433 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000434 const char *func_name,
435 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000436 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000437 bool internal,
438 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000440 BreakpointSP bp_sp;
441 if (func_name)
442 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000443 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000444
445 if (skip_prologue == eLazyBoolCalculate)
446 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
447
Greg Claytond16e1e52011-07-12 17:06:17 +0000448 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
449 func_name,
450 func_name_type_mask,
451 Breakpoint::Exact,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000452 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000453 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000454 }
455 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456}
457
Jim Inghamfab10e82012-03-06 00:37:27 +0000458lldb::BreakpointSP
459Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000460 const FileSpecList *containingSourceFiles,
461 const std::vector<std::string> &func_names,
462 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000463 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000464 bool internal,
465 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000466{
467 BreakpointSP bp_sp;
468 size_t num_names = func_names.size();
469 if (num_names > 0)
470 {
471 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000472
473 if (skip_prologue == eLazyBoolCalculate)
474 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
475
476 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Inghamfab10e82012-03-06 00:37:27 +0000477 func_names,
478 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000479 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000480 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000481 }
482 return bp_sp;
483}
484
Jim Ingham133e0fb2012-03-03 02:05:11 +0000485BreakpointSP
486Target::CreateBreakpoint (const FileSpecList *containingModules,
487 const FileSpecList *containingSourceFiles,
488 const char *func_names[],
489 size_t num_names,
490 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000491 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000492 bool internal,
493 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000494{
495 BreakpointSP bp_sp;
496 if (num_names > 0)
497 {
498 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
499
Greg Clayton03da4cc2013-04-19 21:31:16 +0000500 if (skip_prologue == eLazyBoolCalculate)
501 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
502
503 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Ingham133e0fb2012-03-03 02:05:11 +0000504 func_names,
505 num_names,
Jim Inghamfab10e82012-03-06 00:37:27 +0000506 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000507 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000508 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000509 }
510 return bp_sp;
511}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512
513SearchFilterSP
514Target::GetSearchFilterForModule (const FileSpec *containingModule)
515{
516 SearchFilterSP filter_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 if (containingModule != NULL)
518 {
519 // TODO: We should look into sharing module based search filters
520 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000521 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 }
523 else
524 {
525 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000526 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 filter_sp = m_search_filter_sp;
528 }
529 return filter_sp;
530}
531
Jim Ingham969795f2011-09-21 01:17:13 +0000532SearchFilterSP
533Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
534{
535 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000536 if (containingModules && containingModules->GetSize() != 0)
537 {
538 // TODO: We should look into sharing module based search filters
539 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000540 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000541 }
542 else
543 {
544 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000545 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000546 filter_sp = m_search_filter_sp;
547 }
548 return filter_sp;
549}
550
Jim Ingham87df91b2011-09-23 00:54:11 +0000551SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000552Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
553 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000554{
555 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
556 return GetSearchFilterForModuleList(containingModules);
557
558 SearchFilterSP filter_sp;
Jim Ingham87df91b2011-09-23 00:54:11 +0000559 if (containingModules == NULL)
560 {
561 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
562 // but that will take a little reworking.
563
Greg Claytone1cd1be2012-01-29 20:56:30 +0000564 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000565 }
566 else
567 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000568 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000569 }
570 return filter_sp;
571}
572
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000574Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000575 const FileSpecList *containingSourceFiles,
576 RegularExpression &func_regex,
577 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000578 bool internal,
579 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580{
Jim Ingham87df91b2011-09-23 00:54:11 +0000581 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000582 bool skip =
583 (skip_prologue == eLazyBoolCalculate) ? GetSkipPrologue()
584 : static_cast<bool>(skip_prologue);
Greg Claytond16e1e52011-07-12 17:06:17 +0000585 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
586 func_regex,
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000587 skip));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588
Jim Ingham1460e4b2014-01-10 23:46:59 +0000589 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590}
591
Jim Ingham219ba192012-03-05 04:47:34 +0000592lldb::BreakpointSP
593Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
594{
595 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
596}
597
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000599Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600{
601 BreakpointSP bp_sp;
602 if (filter_sp && resolver_sp)
603 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000604 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605 resolver_sp->SetBreakpoint (bp_sp.get());
Jim Ingham33df7cd2014-12-06 01:28:03 +0000606 AddBreakpoint (bp_sp, internal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 }
Jim Ingham33df7cd2014-12-06 01:28:03 +0000608 return bp_sp;
609}
610
611void
612Target::AddBreakpoint (lldb::BreakpointSP bp_sp, bool internal)
613{
614 if (!bp_sp)
615 return;
616 if (internal)
617 m_internal_breakpoint_list.Add (bp_sp, false);
618 else
619 m_breakpoint_list.Add (bp_sp, true);
620
621 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
622 if (log)
623 {
624 StreamString s;
625 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
626 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
627 }
628
629 bp_sp->ResolveBreakpoint();
630
631 if (!internal)
Jim Ingham36f3b362010-10-14 23:45:03 +0000632 {
633 m_last_created_breakpoint = bp_sp;
634 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635}
636
Johnny Chen86364b42011-09-20 23:28:55 +0000637bool
638Target::ProcessIsValid()
639{
640 return (m_process_sp && m_process_sp->IsAlive());
641}
642
Johnny Chenb90827e2012-06-04 23:19:54 +0000643static bool
644CheckIfWatchpointsExhausted(Target *target, Error &error)
645{
646 uint32_t num_supported_hardware_watchpoints;
647 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
648 if (rc.Success())
649 {
650 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
651 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
652 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
653 num_supported_hardware_watchpoints);
654 }
655 return false;
656}
657
Johnny Chen01a67862011-10-14 00:42:25 +0000658// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000659// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000660WatchpointSP
Jim Inghama7dfb662012-10-23 07:20:06 +0000661Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000662{
Greg Clayton5160ce52013-03-27 23:08:40 +0000663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000664 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000665 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000666 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000667
Johnny Chen01a67862011-10-14 00:42:25 +0000668 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000669 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000670 {
671 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000672 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000673 }
Jim Inghamc6462312013-06-18 21:52:48 +0000674
Johnny Chen45e541f2011-09-14 22:20:15 +0000675 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000676 {
677 if (size == 0)
678 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
679 else
Daniel Malead01b2952012-11-29 21:49:15 +0000680 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000681 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000682 }
Jim Inghamc6462312013-06-18 21:52:48 +0000683
684 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
685 {
686 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
687 }
Johnny Chen7313a642011-09-13 01:15:36 +0000688
Johnny Chen01a67862011-10-14 00:42:25 +0000689 // Currently we only support one watchpoint per address, with total number
690 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000691
692 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000693 const bool notify = false; // Don't notify about all the state changes we do on creating the watchpoint.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000694 Mutex::Locker locker;
695 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000696 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000697 if (matched_sp)
698 {
Johnny Chen0c406372011-09-14 20:23:45 +0000699 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000700 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000701 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
702 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000703 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000704 if (size == old_size && kind == old_type)
705 {
Johnny Chen01a67862011-10-14 00:42:25 +0000706 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000707 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000708 }
709 else
710 {
Johnny Chen01a67862011-10-14 00:42:25 +0000711 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000712 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
713 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000714 }
Johnny Chen3c532582011-09-13 23:29:31 +0000715 }
716
Jason Molenda727e3922012-12-05 23:07:34 +0000717 if (!wp_sp)
718 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000719 wp_sp.reset(new Watchpoint(*this, addr, size, type));
720 wp_sp->SetWatchpointType(kind, notify);
721 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000722 }
Johnny Chen0c406372011-09-14 20:23:45 +0000723
Jim Ingham1b5792e2012-12-18 02:03:49 +0000724 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000725 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000726 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
727 __FUNCTION__,
728 error.Success() ? "succeeded" : "failed",
729 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000730
Jason Molenda727e3922012-12-05 23:07:34 +0000731 if (error.Fail())
732 {
Johnny Chen41b77262012-03-26 22:00:10 +0000733 // Enabling the watchpoint on the device side failed.
734 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000735 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000736 // See if we could provide more helpful error message.
737 if (!CheckIfWatchpointsExhausted(this, error))
738 {
739 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Greg Clayton6fea17e2014-03-03 19:15:20 +0000740 error.SetErrorStringWithFormat("watch size of %" PRIu64 " is not supported", (uint64_t)size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000741 }
Johnny Chen01a67862011-10-14 00:42:25 +0000742 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000743 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000744 else
Johnny Chen01a67862011-10-14 00:42:25 +0000745 m_last_created_watchpoint = wp_sp;
746 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000747}
748
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749void
750Target::RemoveAllBreakpoints (bool internal_also)
751{
Greg Clayton5160ce52013-03-27 23:08:40 +0000752 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 if (log)
754 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
755
Greg Clayton9fed0d82010-07-23 23:33:17 +0000756 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000758 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000759
760 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761}
762
763void
764Target::DisableAllBreakpoints (bool internal_also)
765{
Greg Clayton5160ce52013-03-27 23:08:40 +0000766 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767 if (log)
768 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
769
770 m_breakpoint_list.SetEnabledAll (false);
771 if (internal_also)
772 m_internal_breakpoint_list.SetEnabledAll (false);
773}
774
775void
776Target::EnableAllBreakpoints (bool internal_also)
777{
Greg Clayton5160ce52013-03-27 23:08:40 +0000778 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 if (log)
780 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
781
782 m_breakpoint_list.SetEnabledAll (true);
783 if (internal_also)
784 m_internal_breakpoint_list.SetEnabledAll (true);
785}
786
787bool
788Target::RemoveBreakpointByID (break_id_t break_id)
789{
Greg Clayton5160ce52013-03-27 23:08:40 +0000790 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 if (log)
792 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
793
794 if (DisableBreakpointByID (break_id))
795 {
796 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000797 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000799 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000800 if (m_last_created_breakpoint)
801 {
802 if (m_last_created_breakpoint->GetID() == break_id)
803 m_last_created_breakpoint.reset();
804 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000805 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000806 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807 return true;
808 }
809 return false;
810}
811
812bool
813Target::DisableBreakpointByID (break_id_t break_id)
814{
Greg Clayton5160ce52013-03-27 23:08:40 +0000815 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816 if (log)
817 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
818
819 BreakpointSP bp_sp;
820
821 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
822 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
823 else
824 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
825 if (bp_sp)
826 {
827 bp_sp->SetEnabled (false);
828 return true;
829 }
830 return false;
831}
832
833bool
834Target::EnableBreakpointByID (break_id_t break_id)
835{
Greg Clayton5160ce52013-03-27 23:08:40 +0000836 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837 if (log)
838 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
839 __FUNCTION__,
840 break_id,
841 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
842
843 BreakpointSP bp_sp;
844
845 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
846 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
847 else
848 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
849
850 if (bp_sp)
851 {
852 bp_sp->SetEnabled (true);
853 return true;
854 }
855 return false;
856}
857
Johnny Chenedf50372011-09-23 21:21:43 +0000858// The flag 'end_to_end', default to true, signifies that the operation is
859// performed end to end, for both the debugger and the debuggee.
860
Johnny Chen01a67862011-10-14 00:42:25 +0000861// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
862// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000863bool
Johnny Chen01a67862011-10-14 00:42:25 +0000864Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000865{
Greg Clayton5160ce52013-03-27 23:08:40 +0000866 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000867 if (log)
868 log->Printf ("Target::%s\n", __FUNCTION__);
869
Johnny Chenedf50372011-09-23 21:21:43 +0000870 if (!end_to_end) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000871 m_watchpoint_list.RemoveAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000872 return true;
873 }
874
875 // Otherwise, it's an end to end operation.
876
Johnny Chen86364b42011-09-20 23:28:55 +0000877 if (!ProcessIsValid())
878 return false;
879
Johnny Chen01a67862011-10-14 00:42:25 +0000880 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000881 for (size_t i = 0; i < num_watchpoints; ++i)
882 {
Johnny Chen01a67862011-10-14 00:42:25 +0000883 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
884 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000885 return false;
886
Johnny Chen01a67862011-10-14 00:42:25 +0000887 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000888 if (rc.Fail())
889 return false;
890 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000891 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000892 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000893 return true; // Success!
894}
895
Johnny Chen01a67862011-10-14 00:42:25 +0000896// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
897// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000898bool
Johnny Chen01a67862011-10-14 00:42:25 +0000899Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000900{
Greg Clayton5160ce52013-03-27 23:08:40 +0000901 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000902 if (log)
903 log->Printf ("Target::%s\n", __FUNCTION__);
904
Johnny Chenedf50372011-09-23 21:21:43 +0000905 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000906 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000907 return true;
908 }
909
910 // Otherwise, it's an end to end operation.
911
Johnny Chen86364b42011-09-20 23:28:55 +0000912 if (!ProcessIsValid())
913 return false;
914
Johnny Chen01a67862011-10-14 00:42:25 +0000915 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000916 for (size_t i = 0; i < num_watchpoints; ++i)
917 {
Johnny Chen01a67862011-10-14 00:42:25 +0000918 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
919 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000920 return false;
921
Johnny Chen01a67862011-10-14 00:42:25 +0000922 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000923 if (rc.Fail())
924 return false;
925 }
Johnny Chen86364b42011-09-20 23:28:55 +0000926 return true; // Success!
927}
928
Johnny Chen01a67862011-10-14 00:42:25 +0000929// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
930// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000931bool
Johnny Chen01a67862011-10-14 00:42:25 +0000932Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000933{
Greg Clayton5160ce52013-03-27 23:08:40 +0000934 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000935 if (log)
936 log->Printf ("Target::%s\n", __FUNCTION__);
937
Johnny Chenedf50372011-09-23 21:21:43 +0000938 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000939 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000940 return true;
941 }
942
943 // Otherwise, it's an end to end operation.
944
Johnny Chen86364b42011-09-20 23:28:55 +0000945 if (!ProcessIsValid())
946 return false;
947
Johnny Chen01a67862011-10-14 00:42:25 +0000948 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000949 for (size_t i = 0; i < num_watchpoints; ++i)
950 {
Johnny Chen01a67862011-10-14 00:42:25 +0000951 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
952 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000953 return false;
954
Johnny Chen01a67862011-10-14 00:42:25 +0000955 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000956 if (rc.Fail())
957 return false;
958 }
Johnny Chen86364b42011-09-20 23:28:55 +0000959 return true; // Success!
960}
961
Johnny Chena4d6bc92012-02-25 06:44:30 +0000962// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
963bool
964Target::ClearAllWatchpointHitCounts ()
965{
Greg Clayton5160ce52013-03-27 23:08:40 +0000966 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +0000967 if (log)
968 log->Printf ("Target::%s\n", __FUNCTION__);
969
970 size_t num_watchpoints = m_watchpoint_list.GetSize();
971 for (size_t i = 0; i < num_watchpoints; ++i)
972 {
973 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
974 if (!wp_sp)
975 return false;
976
977 wp_sp->ResetHitCount();
978 }
979 return true; // Success!
980}
981
Enrico Granata5e3fe042015-02-11 00:37:54 +0000982// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
983bool
984Target::ClearAllWatchpointHistoricValues ()
985{
986 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
987 if (log)
988 log->Printf ("Target::%s\n", __FUNCTION__);
989
990 size_t num_watchpoints = m_watchpoint_list.GetSize();
991 for (size_t i = 0; i < num_watchpoints; ++i)
992 {
993 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
994 if (!wp_sp)
995 return false;
996
997 wp_sp->ResetHistoricValues();
998 }
999 return true; // Success!
1000}
1001
Johnny Chen01a67862011-10-14 00:42:25 +00001002// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +00001003// during these operations.
1004bool
Johnny Chen01a67862011-10-14 00:42:25 +00001005Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001006{
Greg Clayton5160ce52013-03-27 23:08:40 +00001007 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +00001008 if (log)
1009 log->Printf ("Target::%s\n", __FUNCTION__);
1010
1011 if (!ProcessIsValid())
1012 return false;
1013
Johnny Chen01a67862011-10-14 00:42:25 +00001014 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +00001015 for (size_t i = 0; i < num_watchpoints; ++i)
1016 {
Johnny Chen01a67862011-10-14 00:42:25 +00001017 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
1018 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001019 return false;
1020
Johnny Chen01a67862011-10-14 00:42:25 +00001021 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001022 }
1023 return true; // Success!
1024}
1025
Johnny Chen01a67862011-10-14 00:42:25 +00001026// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001027bool
Johnny Chen01a67862011-10-14 00:42:25 +00001028Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001029{
Greg Clayton5160ce52013-03-27 23:08:40 +00001030 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001031 if (log)
1032 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1033
1034 if (!ProcessIsValid())
1035 return false;
1036
Johnny Chen01a67862011-10-14 00:42:25 +00001037 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1038 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001039 {
Johnny Chen01a67862011-10-14 00:42:25 +00001040 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001041 if (rc.Success())
1042 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001043
Johnny Chenf04ee932011-09-22 18:04:58 +00001044 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001045 }
1046 return false;
1047}
1048
Johnny Chen01a67862011-10-14 00:42:25 +00001049// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001050bool
Johnny Chen01a67862011-10-14 00:42:25 +00001051Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001052{
Greg Clayton5160ce52013-03-27 23:08:40 +00001053 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001054 if (log)
1055 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1056
1057 if (!ProcessIsValid())
1058 return false;
1059
Johnny Chen01a67862011-10-14 00:42:25 +00001060 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1061 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001062 {
Johnny Chen01a67862011-10-14 00:42:25 +00001063 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001064 if (rc.Success())
1065 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001066
Johnny Chenf04ee932011-09-22 18:04:58 +00001067 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001068 }
1069 return false;
1070}
1071
Johnny Chen01a67862011-10-14 00:42:25 +00001072// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001073bool
Johnny Chen01a67862011-10-14 00:42:25 +00001074Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001075{
Greg Clayton5160ce52013-03-27 23:08:40 +00001076 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001077 if (log)
1078 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1079
Jim Inghamb0b45132013-07-02 02:09:46 +00001080 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
1081 if (watch_to_remove_sp == m_last_created_watchpoint)
1082 m_last_created_watchpoint.reset();
1083
Johnny Chen01a67862011-10-14 00:42:25 +00001084 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +00001085 {
Jim Ingham1b5792e2012-12-18 02:03:49 +00001086 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +00001087 return true;
1088 }
1089 return false;
1090}
1091
Johnny Chen01a67862011-10-14 00:42:25 +00001092// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +00001093bool
Johnny Chen01a67862011-10-14 00:42:25 +00001094Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001095{
Greg Clayton5160ce52013-03-27 23:08:40 +00001096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +00001097 if (log)
1098 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1099
1100 if (!ProcessIsValid())
1101 return false;
1102
Johnny Chen01a67862011-10-14 00:42:25 +00001103 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1104 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001105 {
Johnny Chen01a67862011-10-14 00:42:25 +00001106 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001107 return true;
1108 }
1109 return false;
1110}
1111
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112ModuleSP
1113Target::GetExecutableModule ()
1114{
Greg Claytonaa149cb2011-08-11 02:48:45 +00001115 return m_images.GetModuleAtIndex(0);
1116}
1117
1118Module*
1119Target::GetExecutableModulePointer ()
1120{
1121 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122}
1123
Enrico Granata17598482012-11-08 02:22:02 +00001124static void
1125LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1126{
1127 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001128 StreamString feedback_stream;
1129 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001130 {
Enrico Granata97303392013-05-21 00:00:30 +00001131 if (error.AsCString())
Greg Clayton44d93782014-01-27 23:43:24 +00001132 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001133 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1134 error.AsCString());
Enrico Granata17598482012-11-08 02:22:02 +00001135 }
Enrico Granatafe7295d2014-08-16 00:32:58 +00001136 if (feedback_stream.GetSize())
1137 target->GetDebugger().GetErrorFile()->Printf("%s\n",
1138 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001139}
1140
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001141void
Greg Claytonb35db632013-11-09 00:03:31 +00001142Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143{
Greg Claytonb35db632013-11-09 00:03:31 +00001144 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001145 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 m_images.Clear();
1147 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19 +00001148 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47 +00001149 m_ast_importer_ap.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001150}
1151
1152void
Greg Claytonb35db632013-11-09 00:03:31 +00001153Target::DidExec ()
1154{
1155 // When a process exec's we need to know about it so we can do some cleanup.
1156 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1157 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1158}
1159
1160void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001161Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1162{
1163 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001164 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165
1166 if (executable_sp.get())
1167 {
1168 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001169 "Target::SetExecutableModule (executable = '%s')",
1170 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001172 m_images.Append(executable_sp); // The first image is our executable file
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173
Jim Ingham5aee1622010-08-09 23:31:02 +00001174 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton32e0a752011-03-30 18:16:51 +00001175 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001176 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001177 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001178 if (log)
1179 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1180 }
1181
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001183 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001185 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 {
1187 executable_objfile->GetDependentModules(dependent_files);
1188 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1189 {
Greg Claytonded470d2011-03-19 01:12:21 +00001190 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1191 FileSpec platform_dependent_file_spec;
1192 if (m_platform_sp)
Steve Puccifc995722014-01-17 18:18:31 +00001193 m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001194 else
1195 platform_dependent_file_spec = dependent_file_spec;
1196
Greg Claytonb9a01b32012-02-26 05:51:37 +00001197 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1198 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199 if (image_module_sp.get())
1200 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201 ObjectFile *objfile = image_module_sp->GetObjectFile();
1202 if (objfile)
1203 objfile->GetDependentModules(dependent_files);
1204 }
1205 }
1206 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207 }
1208}
1209
1210
Jim Ingham5aee1622010-08-09 23:31:02 +00001211bool
1212Target::SetArchitecture (const ArchSpec &arch_spec)
1213{
Greg Clayton5160ce52013-03-27 23:08:40 +00001214 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callananbf4b7be2012-12-13 22:07:14 +00001215 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001216 {
Greg Clayton70512312012-05-08 01:45:38 +00001217 // If we haven't got a valid arch spec, or the architectures are
1218 // compatible, so just update the architecture. Architectures can be
1219 // equal, yet the triple OS and vendor might change, so we need to do
1220 // the assignment here just in case.
Greg Clayton32e0a752011-03-30 18:16:51 +00001221 m_arch = arch_spec;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001222 if (log)
1223 log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +00001224 return true;
1225 }
1226 else
1227 {
1228 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molendae1b68ad2012-12-05 00:25:49 +00001229 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +00001230 log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Clayton32e0a752011-03-30 18:16:51 +00001231 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02 +00001232 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001233
Greg Claytonb35db632013-11-09 00:03:31 +00001234 ClearModules(true);
Jim Ingham5aee1622010-08-09 23:31:02 +00001235 // Need to do something about unsetting breakpoints.
1236
1237 if (executable_sp)
1238 {
Jason Molendae1b68ad2012-12-05 00:25:49 +00001239 if (log)
1240 log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Claytonb9a01b32012-02-26 05:51:37 +00001241 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1242 Error error = ModuleList::GetSharedModule (module_spec,
1243 executable_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001244 &GetExecutableSearchPaths(),
Greg Claytonb9a01b32012-02-26 05:51:37 +00001245 NULL,
1246 NULL);
Jim Ingham5aee1622010-08-09 23:31:02 +00001247
1248 if (!error.Fail() && executable_sp)
1249 {
1250 SetExecutableModule (executable_sp, true);
1251 return true;
1252 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001253 }
1254 }
Greg Clayton70512312012-05-08 01:45:38 +00001255 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001256}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258void
Enrico Granataefe637d2012-11-08 19:16:03 +00001259Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001260{
1261}
1262
1263void
Enrico Granataefe637d2012-11-08 19:16:03 +00001264Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265{
1266 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001267 if (m_valid)
1268 {
1269 ModuleList my_module_list;
1270 my_module_list.Append(module_sp);
1271 LoadScriptingResourceForModule(module_sp, this);
1272 ModulesDidLoad (my_module_list);
1273 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274}
1275
1276void
Enrico Granataefe637d2012-11-08 19:16:03 +00001277Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001278{
1279 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001280 if (m_valid)
1281 {
1282 ModuleList my_module_list;
1283 my_module_list.Append(module_sp);
1284 ModulesDidUnload (my_module_list, false);
1285 }
Enrico Granata17598482012-11-08 02:22:02 +00001286}
1287
1288void
Enrico Granataefe637d2012-11-08 19:16:03 +00001289Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290{
Jim Inghame716ae02011-08-03 01:00:06 +00001291 // A module is replacing an already added module
Greg Clayton23f8c952014-03-24 23:10:19 +00001292 if (m_valid)
1293 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294}
1295
1296void
1297Target::ModulesDidLoad (ModuleList &module_list)
1298{
Greg Clayton23f8c952014-03-24 23:10:19 +00001299 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001300 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001301 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001302 if (m_process_sp)
1303 {
Andrew MacPhersoneb4d0602014-03-13 09:37:02 +00001304 m_process_sp->ModulesDidLoad (module_list);
Jason Molendaeef51062013-11-05 03:57:19 +00001305 }
Enrico Granata17598482012-11-08 02:22:02 +00001306 // TODO: make event data that packages up the module_list
1307 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1308 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309}
1310
1311void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001312Target::SymbolsDidLoad (ModuleList &module_list)
1313{
Greg Clayton23f8c952014-03-24 23:10:19 +00001314 if (m_valid && module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001315 {
Jim Ingham31caf982013-06-04 23:01:35 +00001316 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001317 {
Jim Ingham31caf982013-06-04 23:01:35 +00001318 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1319 if (runtime)
1320 {
1321 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1322 objc_runtime->SymbolsDidLoad(module_list);
1323 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001324 }
Jim Ingham31caf982013-06-04 23:01:35 +00001325
Greg Clayton095eeaa2013-11-05 23:28:00 +00001326 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jim Ingham31caf982013-06-04 23:01:35 +00001327 BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL);
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001328 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001329}
1330
1331void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001332Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333{
Greg Clayton23f8c952014-03-24 23:10:19 +00001334 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001335 {
Greg Clayton8012cad2014-11-17 19:39:20 +00001336 UnloadModuleSections (module_list);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001337 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Enrico Granata17598482012-11-08 02:22:02 +00001338 // TODO: make event data that packages up the module_list
1339 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1340 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341}
1342
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001343bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001344Target::ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001345{
Greg Clayton67cc0632012-08-22 17:17:09 +00001346 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001347 {
1348 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001349 ModuleSpec module_spec (module_file_spec);
1350 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001351
1352 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1353 // black list.
1354 if (num_modules > 0)
1355 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001356 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001357 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001358 if (!ModuleIsExcludedForUnconstrainedSearches (matchingModules.GetModuleAtIndex(i)))
Jim Inghamc6674fd2011-10-28 23:14:11 +00001359 return false;
1360 }
1361 return true;
1362 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001363 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001364 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001365}
1366
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001367bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001368Target::ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001369{
Greg Clayton67cc0632012-08-22 17:17:09 +00001370 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001371 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001372 if (m_platform_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +00001373 return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001374 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001375 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001376}
1377
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378size_t
Greg Claytondb598232011-01-07 01:57:07 +00001379Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1380{
Greg Claytone72dfb32012-02-24 01:59:29 +00001381 SectionSP section_sp (addr.GetSection());
1382 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001383 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001384 // If the contents of this section are encrypted, the on-disk file is unusable. Read only from live memory.
Jason Molenda216d91f2012-04-25 00:06:56 +00001385 if (section_sp->IsEncrypted())
1386 {
Greg Clayton57f06302012-05-25 17:05:55 +00001387 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001388 return 0;
1389 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001390 ModuleSP module_sp (section_sp->GetModule());
1391 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001392 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001393 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1394 if (objfile)
1395 {
1396 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1397 addr.GetOffset(),
1398 dst,
1399 dst_len);
1400 if (bytes_read > 0)
1401 return bytes_read;
1402 else
1403 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1404 }
Greg Claytondb598232011-01-07 01:57:07 +00001405 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001406 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001407 }
1408 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001409 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001410 }
1411 else
Greg Claytondb598232011-01-07 01:57:07 +00001412 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001413
Greg Claytondb598232011-01-07 01:57:07 +00001414 return 0;
1415}
1416
1417size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001418Target::ReadMemory (const Address& addr,
1419 bool prefer_file_cache,
1420 void *dst,
1421 size_t dst_len,
1422 Error &error,
1423 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001426
Enrico Granata9128ee22011-09-06 19:20:51 +00001427 // if we end up reading this from process memory, we will fill this
1428 // with the actual load address
1429 if (load_addr_ptr)
1430 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1431
Greg Claytondb598232011-01-07 01:57:07 +00001432 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001433
1434 addr_t load_addr = LLDB_INVALID_ADDRESS;
1435 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001436 Address resolved_addr;
1437 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001438 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001439 SectionLoadList &section_load_list = GetSectionLoadList();
1440 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001441 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001442 // No sections are loaded, so we must assume we are not running
1443 // yet and anything we are given is a file address.
1444 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1445 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001446 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001447 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001448 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001449 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001450 // we have manually loaded some sections with "target modules load ..."
1451 // or because we have have a live process that has sections loaded
1452 // through the dynamic loader
1453 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001454 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001455 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001456 }
Greg Clayton357132e2011-03-26 19:14:58 +00001457 if (!resolved_addr.IsValid())
1458 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001459
Greg Claytonc749eb82011-07-11 05:12:02 +00001460
Greg Claytondb598232011-01-07 01:57:07 +00001461 if (prefer_file_cache)
1462 {
1463 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1464 if (bytes_read > 0)
1465 return bytes_read;
1466 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001467
Johnny Chen86364b42011-09-20 23:28:55 +00001468 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001469 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001470 if (load_addr == LLDB_INVALID_ADDRESS)
1471 load_addr = resolved_addr.GetLoadAddress (this);
1472
Greg Claytondda4f7b2010-06-30 23:03:03 +00001473 if (load_addr == LLDB_INVALID_ADDRESS)
1474 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001475 ModuleSP addr_module_sp (resolved_addr.GetModule());
1476 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001477 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Jim Ingham4af59612014-12-19 19:20:44 +00001478 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Jason Molenda7e589a62011-09-20 00:26:08 +00001479 resolved_addr.GetFileAddress(),
Jim Ingham4af59612014-12-19 19:20:44 +00001480 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknonw>"));
Greg Claytondda4f7b2010-06-30 23:03:03 +00001481 else
Daniel Malead01b2952012-11-29 21:49:15 +00001482 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001483 }
1484 else
1485 {
Greg Claytondb598232011-01-07 01:57:07 +00001486 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001487 if (bytes_read != dst_len)
1488 {
1489 if (error.Success())
1490 {
1491 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001492 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493 else
Daniel Malead01b2952012-11-29 21:49:15 +00001494 error.SetErrorStringWithFormat("only %" PRIu64 " of %" PRIu64 " bytes were read from memory at 0x%" PRIx64, (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001495 }
1496 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001497 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001498 {
1499 if (load_addr_ptr)
1500 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001501 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001502 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001503 // If the address is not section offset we have an address that
1504 // doesn't resolve to any address in any currently loaded shared
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001505 // libraries and we failed to read memory so there isn't anything
Greg Claytondda4f7b2010-06-30 23:03:03 +00001506 // more we can do. If it is section offset, we might be able to
1507 // read cached memory from the object file.
1508 if (!resolved_addr.IsSectionOffset())
1509 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001511 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001512
Greg Claytonc749eb82011-07-11 05:12:02 +00001513 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001514 {
Greg Claytondb598232011-01-07 01:57:07 +00001515 // If we didn't already try and read from the object file cache, then
1516 // try it after failing to read from the process.
1517 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001518 }
1519 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520}
1521
Greg Claytond16e1e52011-07-12 17:06:17 +00001522size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001523Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1524{
1525 char buf[256];
1526 out_str.clear();
1527 addr_t curr_addr = addr.GetLoadAddress(this);
1528 Address address(addr);
1529 while (1)
1530 {
1531 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1532 if (length == 0)
1533 break;
1534 out_str.append(buf, length);
1535 // If we got "length - 1" bytes, we didn't get the whole C string, we
1536 // need to read some more characters
1537 if (length == sizeof(buf) - 1)
1538 curr_addr += length;
1539 else
1540 break;
1541 address = Address(curr_addr);
1542 }
1543 return out_str.size();
1544}
1545
1546
1547size_t
1548Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1549{
1550 size_t total_cstr_len = 0;
1551 if (dst && dst_max_len)
1552 {
1553 result_error.Clear();
1554 // NULL out everything just to be safe
1555 memset (dst, 0, dst_max_len);
1556 Error error;
1557 addr_t curr_addr = addr.GetLoadAddress(this);
1558 Address address(addr);
Jason Molendaf0340c92014-09-03 22:30:54 +00001559
1560 // We could call m_process_sp->GetMemoryCacheLineSize() but I don't
1561 // think this really needs to be tied to the memory cache subsystem's
1562 // cache line size, so leave this as a fixed constant.
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001563 const size_t cache_line_size = 512;
Jason Molendaf0340c92014-09-03 22:30:54 +00001564
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001565 size_t bytes_left = dst_max_len - 1;
1566 char *curr_dst = dst;
1567
1568 while (bytes_left > 0)
1569 {
1570 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1571 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1572 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1573
1574 if (bytes_read == 0)
1575 {
1576 result_error = error;
1577 dst[total_cstr_len] = '\0';
1578 break;
1579 }
1580 const size_t len = strlen(curr_dst);
1581
1582 total_cstr_len += len;
1583
1584 if (len < bytes_to_read)
1585 break;
1586
1587 curr_dst += bytes_read;
1588 curr_addr += bytes_read;
1589 bytes_left -= bytes_read;
1590 address = Address(curr_addr);
1591 }
1592 }
1593 else
1594 {
1595 if (dst == NULL)
1596 result_error.SetErrorString("invalid arguments");
1597 else
1598 result_error.Clear();
1599 }
1600 return total_cstr_len;
1601}
1602
1603size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001604Target::ReadScalarIntegerFromMemory (const Address& addr,
1605 bool prefer_file_cache,
1606 uint32_t byte_size,
1607 bool is_signed,
1608 Scalar &scalar,
1609 Error &error)
1610{
1611 uint64_t uval;
1612
1613 if (byte_size <= sizeof(uval))
1614 {
1615 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1616 if (bytes_read == byte_size)
1617 {
1618 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001619 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001620 if (byte_size <= 4)
1621 scalar = data.GetMaxU32 (&offset, byte_size);
1622 else
1623 scalar = data.GetMaxU64 (&offset, byte_size);
1624
1625 if (is_signed)
1626 scalar.SignExtend(byte_size * 8);
1627 return bytes_read;
1628 }
1629 }
1630 else
1631 {
1632 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1633 }
1634 return 0;
1635}
1636
1637uint64_t
1638Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1639 bool prefer_file_cache,
1640 size_t integer_byte_size,
1641 uint64_t fail_value,
1642 Error &error)
1643{
1644 Scalar scalar;
1645 if (ReadScalarIntegerFromMemory (addr,
1646 prefer_file_cache,
1647 integer_byte_size,
1648 false,
1649 scalar,
1650 error))
1651 return scalar.ULongLong(fail_value);
1652 return fail_value;
1653}
1654
1655bool
1656Target::ReadPointerFromMemory (const Address& addr,
1657 bool prefer_file_cache,
1658 Error &error,
1659 Address &pointer_addr)
1660{
1661 Scalar scalar;
1662 if (ReadScalarIntegerFromMemory (addr,
1663 prefer_file_cache,
1664 m_arch.GetAddressByteSize(),
1665 false,
1666 scalar,
1667 error))
1668 {
1669 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1670 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1671 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001672 SectionLoadList &section_load_list = GetSectionLoadList();
1673 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001674 {
1675 // No sections are loaded, so we must assume we are not running
1676 // yet and anything we are given is a file address.
1677 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1678 }
1679 else
1680 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001681 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001682 // we have manually loaded some sections with "target modules load ..."
1683 // or because we have have a live process that has sections loaded
1684 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001685 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001686 }
1687 // We weren't able to resolve the pointer value, so just return
1688 // an address with no section
1689 if (!pointer_addr.IsValid())
1690 pointer_addr.SetOffset (pointer_vm_addr);
1691 return true;
1692
1693 }
1694 }
1695 return false;
1696}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001697
1698ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001699Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701 ModuleSP module_sp;
1702
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001703 Error error;
1704
Jim Ingham4a94c912012-05-17 18:38:42 +00001705 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1706 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001707
Jim Ingham4a94c912012-05-17 18:38:42 +00001708 if (module_spec.GetUUID().IsValid())
1709 module_sp = m_images.FindFirstModule(module_spec);
1710
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001711 if (!module_sp)
1712 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001713 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1714 bool did_create_module = false;
1715
1716 // If there are image search path entries, try to use them first to acquire a suitable image.
1717 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001718 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001719 ModuleSpec transformed_spec (module_spec);
1720 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1721 {
1722 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1723 error = ModuleList::GetSharedModule (transformed_spec,
1724 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001725 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001726 &old_module_sp,
1727 &did_create_module);
1728 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001729 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001730
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001731 if (!module_sp)
1732 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001733 // If we have a UUID, we can check our global shared module list in case
1734 // we already have it. If we don't have a valid UUID, then we can't since
1735 // the path in "module_spec" will be a platform path, and we will need to
1736 // let the platform find that file. For example, we could be asking for
1737 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1738 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1739 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1740 // cache.
1741 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001742 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001743 // We have a UUID, it is OK to check the global module list...
1744 error = ModuleList::GetSharedModule (module_spec,
1745 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001746 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001747 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001748 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001749 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001750
1751 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001752 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001753 // The platform is responsible for finding and caching an appropriate
1754 // module in the shared module cache.
1755 if (m_platform_sp)
1756 {
1757 FileSpec platform_file_spec;
1758 error = m_platform_sp->GetSharedModule (module_spec,
1759 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001760 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001761 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001762 &did_create_module);
1763 }
1764 else
1765 {
1766 error.SetErrorString("no platform is currently set");
1767 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001768 }
1769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770
Jim Ingham4a94c912012-05-17 18:38:42 +00001771 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1772 // module in the list already, and if there was, let's remove it.
1773 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001774 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001775 ObjectFile *objfile = module_sp->GetObjectFile();
1776 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001777 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001778 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001779 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001780 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1781 case ObjectFile::eTypeExecutable: /// A normal executable
1782 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1783 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1784 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1785 break;
1786 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1787 if (error_ptr)
1788 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1789 return ModuleSP();
1790 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1791 if (error_ptr)
1792 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1793 return ModuleSP();
1794 default:
1795 if (error_ptr)
1796 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1797 return ModuleSP();
1798 }
1799 // GetSharedModule is not guaranteed to find the old shared module, for instance
1800 // in the common case where you pass in the UUID, it is only going to find the one
1801 // module matching the UUID. In fact, it has no good way to know what the "old module"
1802 // relevant to this target is, since there might be many copies of a module with this file spec
1803 // in various running debug sessions, but only one of them will belong to this target.
1804 // So let's remove the UUID from the module list, and look in the target's module list.
1805 // Only do this if there is SOMETHING else in the module spec...
1806 if (!old_module_sp)
1807 {
1808 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001809 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001810 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1811 module_spec_copy.GetUUID().Clear();
1812
1813 ModuleList found_modules;
1814 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1815 if (num_found == 1)
1816 {
1817 old_module_sp = found_modules.GetModuleAtIndex(0);
1818 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001819 }
1820 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001821
1822 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1823 {
1824 m_images.ReplaceModule(old_module_sp, module_sp);
1825 Module *old_module_ptr = old_module_sp.get();
1826 old_module_sp.reset();
1827 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1828 }
1829 else
1830 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001831 }
Greg Clayton86e70cb2014-04-07 23:50:17 +00001832 else
1833 module_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001834 }
1835 }
1836 if (error_ptr)
1837 *error_ptr = error;
1838 return module_sp;
1839}
1840
1841
Greg Claytond9e416c2012-02-18 05:35:26 +00001842TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843Target::CalculateTarget ()
1844{
Greg Claytond9e416c2012-02-18 05:35:26 +00001845 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846}
1847
Greg Claytond9e416c2012-02-18 05:35:26 +00001848ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849Target::CalculateProcess ()
1850{
Greg Claytond9e416c2012-02-18 05:35:26 +00001851 return ProcessSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852}
1853
Greg Claytond9e416c2012-02-18 05:35:26 +00001854ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855Target::CalculateThread ()
1856{
Greg Claytond9e416c2012-02-18 05:35:26 +00001857 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858}
1859
Jason Molendab57e4a12013-11-04 09:33:30 +00001860StackFrameSP
1861Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862{
Jason Molendab57e4a12013-11-04 09:33:30 +00001863 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864}
1865
1866void
Greg Clayton0603aa92010-10-04 01:05:56 +00001867Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868{
Greg Claytonc14ee322011-09-22 04:58:26 +00001869 exe_ctx.Clear();
1870 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001871}
1872
1873PathMappingList &
1874Target::GetImageSearchPathList ()
1875{
1876 return m_image_search_paths;
1877}
1878
1879void
1880Target::ImageSearchPathsChanged
1881(
1882 const PathMappingList &path_list,
1883 void *baton
1884)
1885{
1886 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001887 ModuleSP exe_module_sp (target->GetExecutableModule());
1888 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001889 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890}
1891
1892ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001893Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001894{
Greg Clayton73da2442011-08-03 01:23:55 +00001895 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001896 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanan4bf80d52011-11-15 22:27:19 +00001897 {
Greg Clayton73da2442011-08-03 01:23:55 +00001898 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Claytone1cd1be2012-01-29 20:56:30 +00001899 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanan4bf80d52011-11-15 22:27:19 +00001900 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
Todd Fiala955fe6f2014-02-27 17:18:23 +00001901 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
Sean Callanan4bf80d52011-11-15 22:27:19 +00001902 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1903 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001904 return m_scratch_ast_context_ap.get();
1905}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001906
Sean Callanan686b2312011-11-16 18:20:47 +00001907ClangASTImporter *
1908Target::GetClangASTImporter()
1909{
1910 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1911
1912 if (!ast_importer)
1913 {
1914 ast_importer = new ClangASTImporter();
1915 m_ast_importer_ap.reset(ast_importer);
1916 }
1917
1918 return ast_importer;
1919}
1920
Greg Clayton99d0faf2010-11-18 23:32:35 +00001921void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001922Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00001923{
Greg Clayton6920b522012-08-22 18:39:03 +00001924 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001925}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001926
Greg Clayton99d0faf2010-11-18 23:32:35 +00001927void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001928Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001929{
Greg Clayton6920b522012-08-22 18:39:03 +00001930 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001931}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001932
Greg Claytonc859e2d2012-02-13 23:10:39 +00001933FileSpecList
1934Target::GetDefaultExecutableSearchPaths ()
1935{
Greg Clayton67cc0632012-08-22 17:17:09 +00001936 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1937 if (properties_sp)
1938 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00001939 return FileSpecList();
1940}
1941
Michael Sartaina7499c92013-07-01 19:45:50 +00001942FileSpecList
1943Target::GetDefaultDebugFileSearchPaths ()
1944{
1945 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1946 if (properties_sp)
1947 return properties_sp->GetDebugFileSearchPaths();
1948 return FileSpecList();
1949}
1950
Caroline Ticedaccaa92010-09-20 20:44:43 +00001951ArchSpec
1952Target::GetDefaultArchitecture ()
1953{
Greg Clayton67cc0632012-08-22 17:17:09 +00001954 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1955 if (properties_sp)
1956 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00001957 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00001958}
1959
1960void
Greg Clayton67cc0632012-08-22 17:17:09 +00001961Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001962{
Greg Clayton67cc0632012-08-22 17:17:09 +00001963 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1964 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00001965 {
1966 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::SetDefaultArchitecture setting target's default architecture to %s (%s)", arch.GetArchitectureName(), arch.GetTriple().getTriple().c_str());
Greg Clayton67cc0632012-08-22 17:17:09 +00001967 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00001968 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001969}
1970
Greg Clayton0603aa92010-10-04 01:05:56 +00001971Target *
1972Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1973{
1974 // The target can either exist in the "process" of ExecutionContext, or in
1975 // the "target_sp" member of SymbolContext. This accessor helper function
1976 // will get the target from one of these locations.
1977
1978 Target *target = NULL;
1979 if (sc_ptr != NULL)
1980 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:26 +00001981 if (target == NULL && exe_ctx_ptr)
1982 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00001983 return target;
1984}
1985
Jim Ingham1624a2d2014-05-05 02:26:40 +00001986ExpressionResults
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001987Target::EvaluateExpression
1988(
1989 const char *expr_cstr,
Jason Molendab57e4a12013-11-04 09:33:30 +00001990 StackFrame *frame,
Enrico Granata3372f582012-07-16 23:10:35 +00001991 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad4439aa2012-09-05 20:41:26 +00001992 const EvaluateExpressionOptions& options
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001993)
1994{
Enrico Granata97fca502012-09-18 17:43:16 +00001995 result_valobj_sp.reset();
1996
Jim Ingham8646d3c2014-05-05 02:47:44 +00001997 ExpressionResults execution_results = eExpressionSetupError;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001998
Greg Claytond1767f02011-12-08 02:13:16 +00001999 if (expr_cstr == NULL || expr_cstr[0] == '\0')
2000 return execution_results;
2001
Jim Ingham6026ca32011-05-12 02:06:14 +00002002 // We shouldn't run stop hooks in expressions.
2003 // Be sure to reset this if you return anywhere within this function.
2004 bool old_suppress_value = m_suppress_stop_hooks;
2005 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002006
2007 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002008
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002009 if (frame)
2010 {
2011 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002012 }
2013 else if (m_process_sp)
2014 {
2015 m_process_sp->CalculateExecutionContext(exe_ctx);
2016 }
2017 else
2018 {
2019 CalculateExecutionContext(exe_ctx);
2020 }
2021
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002022 // Make sure we aren't just trying to see the value of a persistent
2023 // variable (something like "$0")
2024 lldb::ClangExpressionVariableSP persistent_var_sp;
2025 // Only check for persistent variables the expression starts with a '$'
2026 if (expr_cstr[0] == '$')
Zachary Turner32abc6e2015-03-03 19:23:09 +00002027 persistent_var_sp = m_persistent_variables->GetVariable (expr_cstr);
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002028
2029 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002030 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002031 result_valobj_sp = persistent_var_sp->GetValueObject ();
Jim Ingham8646d3c2014-05-05 02:47:44 +00002032 execution_results = eExpressionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002033 }
2034 else
2035 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002036 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00002037 Error error;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002038 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Greg Clayton62afb9f2013-11-04 19:35:17 +00002039 options,
2040 expr_cstr,
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002041 prefix,
2042 result_valobj_sp,
Greg Clayton62afb9f2013-11-04 19:35:17 +00002043 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002044 }
Jim Ingham6026ca32011-05-12 02:06:14 +00002045
2046 m_suppress_stop_hooks = old_suppress_value;
2047
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002048 return execution_results;
2049}
2050
Zachary Turner32abc6e2015-03-03 19:23:09 +00002051ClangPersistentVariables &
2052Target::GetPersistentVariables()
2053{
2054 return *m_persistent_variables;
2055}
2056
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002057lldb::addr_t
2058Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2059{
2060 addr_t code_addr = load_addr;
2061 switch (m_arch.GetMachine())
2062 {
2063 case llvm::Triple::arm:
2064 case llvm::Triple::thumb:
2065 switch (addr_class)
2066 {
2067 case eAddressClassData:
2068 case eAddressClassDebug:
2069 return LLDB_INVALID_ADDRESS;
2070
2071 case eAddressClassUnknown:
2072 case eAddressClassInvalid:
2073 case eAddressClassCode:
2074 case eAddressClassCodeAlternateISA:
2075 case eAddressClassRuntime:
2076 // Check if bit zero it no set?
2077 if ((code_addr & 1ull) == 0)
2078 {
2079 // Bit zero isn't set, check if the address is a multiple of 2?
2080 if (code_addr & 2ull)
2081 {
2082 // The address is a multiple of 2 so it must be thumb, set bit zero
2083 code_addr |= 1ull;
2084 }
2085 else if (addr_class == eAddressClassCodeAlternateISA)
2086 {
2087 // We checked the address and the address claims to be the alternate ISA
2088 // which means thumb, so set bit zero.
2089 code_addr |= 1ull;
2090 }
2091 }
2092 break;
2093 }
2094 break;
2095
2096 default:
2097 break;
2098 }
2099 return code_addr;
2100}
2101
2102lldb::addr_t
2103Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2104{
2105 addr_t opcode_addr = load_addr;
2106 switch (m_arch.GetMachine())
2107 {
2108 case llvm::Triple::arm:
2109 case llvm::Triple::thumb:
2110 switch (addr_class)
2111 {
2112 case eAddressClassData:
2113 case eAddressClassDebug:
2114 return LLDB_INVALID_ADDRESS;
2115
2116 case eAddressClassInvalid:
2117 case eAddressClassUnknown:
2118 case eAddressClassCode:
2119 case eAddressClassCodeAlternateISA:
2120 case eAddressClassRuntime:
2121 opcode_addr &= ~(1ull);
2122 break;
2123 }
2124 break;
2125
2126 default:
2127 break;
2128 }
2129 return opcode_addr;
2130}
2131
Greg Clayton9585fbf2013-03-19 00:20:55 +00002132SourceManager &
2133Target::GetSourceManager ()
2134{
2135 if (m_source_manager_ap.get() == NULL)
2136 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
2137 return *m_source_manager_ap;
2138}
2139
Sean Callanan9998acd2014-12-05 01:21:59 +00002140ClangModulesDeclVendor *
2141Target::GetClangModulesDeclVendor ()
2142{
2143 static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
2144
2145 {
2146 Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
2147
2148 if (!m_clang_modules_decl_vendor_ap)
2149 {
2150 m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
2151 }
2152 }
2153
2154 return m_clang_modules_decl_vendor_ap.get();
2155}
Greg Clayton9585fbf2013-03-19 00:20:55 +00002156
Greg Clayton44d93782014-01-27 23:43:24 +00002157Target::StopHookSP
2158Target::CreateStopHook ()
Jim Ingham9575d842011-03-11 03:53:59 +00002159{
2160 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton44d93782014-01-27 23:43:24 +00002161 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2162 m_stop_hooks[new_uid] = stop_hook_sp;
2163 return stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00002164}
2165
2166bool
2167Target::RemoveStopHookByID (lldb::user_id_t user_id)
2168{
2169 size_t num_removed;
2170 num_removed = m_stop_hooks.erase (user_id);
2171 if (num_removed == 0)
2172 return false;
2173 else
2174 return true;
2175}
2176
2177void
2178Target::RemoveAllStopHooks ()
2179{
2180 m_stop_hooks.clear();
2181}
2182
2183Target::StopHookSP
2184Target::GetStopHookByID (lldb::user_id_t user_id)
2185{
2186 StopHookSP found_hook;
2187
2188 StopHookCollection::iterator specified_hook_iter;
2189 specified_hook_iter = m_stop_hooks.find (user_id);
2190 if (specified_hook_iter != m_stop_hooks.end())
2191 found_hook = (*specified_hook_iter).second;
2192 return found_hook;
2193}
2194
2195bool
2196Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2197{
2198 StopHookCollection::iterator specified_hook_iter;
2199 specified_hook_iter = m_stop_hooks.find (user_id);
2200 if (specified_hook_iter == m_stop_hooks.end())
2201 return false;
2202
2203 (*specified_hook_iter).second->SetIsActive (active_state);
2204 return true;
2205}
2206
2207void
2208Target::SetAllStopHooksActiveState (bool active_state)
2209{
2210 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2211 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2212 {
2213 (*pos).second->SetIsActive (active_state);
2214 }
2215}
2216
2217void
2218Target::RunStopHooks ()
2219{
Jim Ingham6026ca32011-05-12 02:06:14 +00002220 if (m_suppress_stop_hooks)
2221 return;
2222
Jim Ingham9575d842011-03-11 03:53:59 +00002223 if (!m_process_sp)
2224 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002225
2226 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2227 // since in that case we do not want to run the stop-hooks
2228 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2229 return;
2230
Jim Ingham9575d842011-03-11 03:53:59 +00002231 if (m_stop_hooks.empty())
2232 return;
2233
2234 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2235
2236 // If there aren't any active stop hooks, don't bother either:
2237 bool any_active_hooks = false;
2238 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2239 {
2240 if ((*pos).second->IsActive())
2241 {
2242 any_active_hooks = true;
2243 break;
2244 }
2245 }
2246 if (!any_active_hooks)
2247 return;
2248
2249 CommandReturnObject result;
2250
2251 std::vector<ExecutionContext> exc_ctx_with_reasons;
2252 std::vector<SymbolContext> sym_ctx_with_reasons;
2253
2254 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2255 size_t num_threads = cur_threadlist.GetSize();
2256 for (size_t i = 0; i < num_threads; i++)
2257 {
2258 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2259 if (cur_thread_sp->ThreadStoppedForAReason())
2260 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002261 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002262 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2263 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2264 }
2265 }
2266
2267 // If no threads stopped for a reason, don't run the stop-hooks.
2268 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2269 if (num_exe_ctx == 0)
2270 return;
2271
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002272 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2273 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002274
2275 bool keep_going = true;
2276 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:27 +00002277 bool print_hook_header;
2278 bool print_thread_header;
2279
2280 if (num_exe_ctx == 1)
2281 print_thread_header = false;
2282 else
2283 print_thread_header = true;
2284
2285 if (m_stop_hooks.size() == 1)
2286 print_hook_header = false;
2287 else
2288 print_hook_header = true;
2289
Jim Ingham9575d842011-03-11 03:53:59 +00002290 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2291 {
2292 // result.Clear();
2293 StopHookSP cur_hook_sp = (*pos).second;
2294 if (!cur_hook_sp->IsActive())
2295 continue;
2296
2297 bool any_thread_matched = false;
2298 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2299 {
2300 if ((cur_hook_sp->GetSpecifier () == NULL
2301 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2302 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Ingham3d902922012-03-07 22:03:04 +00002303 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002304 {
2305 if (!hooks_ran)
2306 {
Jim Ingham9575d842011-03-11 03:53:59 +00002307 hooks_ran = true;
2308 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002309 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002310 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002311 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2312 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2313 NULL);
2314 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002315 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002316 else
Daniel Malead01b2952012-11-29 21:49:15 +00002317 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002318 any_thread_matched = true;
2319 }
2320
Jim Ingham381e25b2011-03-22 01:47:27 +00002321 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002322 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham26c7bf92014-10-11 00:38:27 +00002323
2324 CommandInterpreterRunOptions options;
2325 options.SetStopOnContinue (true);
2326 options.SetStopOnError (true);
2327 options.SetEchoCommands (false);
2328 options.SetPrintResults (true);
2329 options.SetAddToHistory (false);
2330
2331 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
2332 &exc_ctx_with_reasons[i],
2333 options,
Greg Clayton32e0a752011-03-30 18:16:51 +00002334 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002335
2336 // If the command started the target going again, we should bag out of
2337 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002338 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2339 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002340 {
Daniel Malead01b2952012-11-29 21:49:15 +00002341 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002342 keep_going = false;
2343 }
2344 }
2345 }
2346 }
Jason Molenda879cf772011-09-23 00:42:55 +00002347
Caroline Tice969ed3d2011-05-02 20:41:46 +00002348 result.GetImmediateOutputStream()->Flush();
2349 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002350}
2351
Greg Claytonfbb76342013-11-20 21:07:01 +00002352const TargetPropertiesSP &
2353Target::GetGlobalProperties()
2354{
2355 static TargetPropertiesSP g_settings_sp;
2356 if (!g_settings_sp)
2357 {
2358 g_settings_sp.reset (new TargetProperties (NULL));
2359 }
2360 return g_settings_sp;
2361}
2362
2363Error
2364Target::Install (ProcessLaunchInfo *launch_info)
2365{
2366 Error error;
2367 PlatformSP platform_sp (GetPlatform());
2368 if (platform_sp)
2369 {
2370 if (platform_sp->IsRemote())
2371 {
2372 if (platform_sp->IsConnected())
2373 {
2374 // Install all files that have an install path, and always install the
2375 // main executable when connected to a remote platform
2376 const ModuleList& modules = GetImages();
2377 const size_t num_images = modules.GetSize();
2378 for (size_t idx = 0; idx < num_images; ++idx)
2379 {
2380 const bool is_main_executable = idx == 0;
2381 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2382 if (module_sp)
2383 {
2384 FileSpec local_file (module_sp->GetFileSpec());
2385 if (local_file)
2386 {
2387 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2388 if (!remote_file)
2389 {
2390 if (is_main_executable) // TODO: add setting for always installing main executable???
2391 {
2392 // Always install the main executable
2393 remote_file.GetDirectory() = platform_sp->GetWorkingDirectory();
2394 remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename();
2395 }
2396 }
2397 if (remote_file)
2398 {
2399 error = platform_sp->Install(local_file, remote_file);
2400 if (error.Success())
2401 {
2402 module_sp->SetPlatformFileSpec(remote_file);
2403 if (is_main_executable)
2404 {
2405 if (launch_info)
2406 launch_info->SetExecutableFile(remote_file, false);
2407 }
2408 }
2409 else
2410 break;
2411 }
2412 }
2413 }
2414 }
2415 }
2416 }
2417 }
2418 return error;
2419}
Greg Clayton7b242382011-07-08 00:48:09 +00002420
Greg Claytond5944cd2013-12-06 01:12:00 +00002421bool
2422Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2423{
2424 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2425}
2426
2427bool
Matthew Gardinerc928de32014-10-22 07:22:56 +00002428Target::ResolveFileAddress (lldb::addr_t file_addr, Address &resolved_addr)
2429{
2430 return m_images.ResolveFileAddress(file_addr, resolved_addr);
2431}
2432
2433bool
Greg Claytond5944cd2013-12-06 01:12:00 +00002434Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2435{
2436 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2437 if (old_section_load_addr != new_section_load_addr)
2438 {
2439 uint32_t stop_id = 0;
2440 ProcessSP process_sp(GetProcessSP());
2441 if (process_sp)
2442 stop_id = process_sp->GetStopID();
2443 else
2444 stop_id = m_section_load_history.GetLastStopID();
2445 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2446 return true; // Return true if the section load address was changed...
2447 }
2448 return false; // Return false to indicate nothing changed
2449
2450}
2451
Greg Clayton8012cad2014-11-17 19:39:20 +00002452size_t
2453Target::UnloadModuleSections (const ModuleList &module_list)
2454{
2455 size_t section_unload_count = 0;
2456 size_t num_modules = module_list.GetSize();
2457 for (size_t i=0; i<num_modules; ++i)
2458 {
2459 section_unload_count += UnloadModuleSections (module_list.GetModuleAtIndex(i));
2460 }
2461 return section_unload_count;
2462}
2463
2464size_t
2465Target::UnloadModuleSections (const lldb::ModuleSP &module_sp)
2466{
2467 uint32_t stop_id = 0;
2468 ProcessSP process_sp(GetProcessSP());
2469 if (process_sp)
2470 stop_id = process_sp->GetStopID();
2471 else
2472 stop_id = m_section_load_history.GetLastStopID();
2473 SectionList *sections = module_sp->GetSectionList();
2474 size_t section_unload_count = 0;
2475 if (sections)
2476 {
2477 const uint32_t num_sections = sections->GetNumSections(0);
2478 for (uint32_t i = 0; i < num_sections; ++i)
2479 {
2480 section_unload_count += m_section_load_history.SetSectionUnloaded(stop_id, sections->GetSectionAtIndex(i));
2481 }
2482 }
2483 return section_unload_count;
2484}
2485
Greg Claytond5944cd2013-12-06 01:12:00 +00002486bool
2487Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2488{
2489 uint32_t stop_id = 0;
2490 ProcessSP process_sp(GetProcessSP());
2491 if (process_sp)
2492 stop_id = process_sp->GetStopID();
2493 else
2494 stop_id = m_section_load_history.GetLastStopID();
2495 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2496}
2497
2498bool
2499Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2500{
2501 uint32_t stop_id = 0;
2502 ProcessSP process_sp(GetProcessSP());
2503 if (process_sp)
2504 stop_id = process_sp->GetStopID();
2505 else
2506 stop_id = m_section_load_history.GetLastStopID();
2507 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2508}
2509
2510void
2511Target::ClearAllLoadedSections ()
2512{
2513 m_section_load_history.Clear();
2514}
2515
Greg Claytonb09c5382013-12-13 17:20:18 +00002516
2517Error
Greg Clayton8012cad2014-11-17 19:39:20 +00002518Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
Greg Claytonb09c5382013-12-13 17:20:18 +00002519{
2520 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00002521 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
2522
2523 if (log)
2524 log->Printf ("Target::%s() called for %s", __FUNCTION__, launch_info.GetExecutableFile().GetPath().c_str ());
2525
Greg Claytonb09c5382013-12-13 17:20:18 +00002526 StateType state = eStateInvalid;
2527
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002528 // Scope to temporarily get the process state in case someone has manually
2529 // remotely connected already to a process and we can skip the platform
2530 // launching.
2531 {
2532 ProcessSP process_sp (GetProcessSP());
2533
2534 if (process_sp)
Todd Fialaac33cc92014-10-09 01:02:08 +00002535 {
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002536 state = process_sp->GetState();
Todd Fialaac33cc92014-10-09 01:02:08 +00002537 if (log)
2538 log->Printf ("Target::%s the process exists, and its current state is %s", __FUNCTION__, StateAsCString (state));
2539 }
2540 else
2541 {
2542 if (log)
2543 log->Printf ("Target::%s the process instance doesn't currently exist.", __FUNCTION__);
2544 }
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002545 }
2546
Greg Claytonb09c5382013-12-13 17:20:18 +00002547 launch_info.GetFlags().Set (eLaunchFlagDebug);
2548
2549 // Get the value of synchronous execution here. If you wait till after you have started to
2550 // run, then you could have hit a breakpoint, whose command might switch the value, and
2551 // then you'll pick up that incorrect value.
2552 Debugger &debugger = GetDebugger();
2553 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2554
2555 PlatformSP platform_sp (GetPlatform());
2556
2557 // Finalize the file actions, and if none were given, default to opening
2558 // up a pseudo terminal
2559 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
Todd Fiala75f47c32014-10-11 21:42:09 +00002560 if (log)
2561 log->Printf ("Target::%s have platform=%s, platform_sp->IsHost()=%s, default_to_use_pty=%s",
2562 __FUNCTION__,
2563 platform_sp ? "true" : "false",
2564 platform_sp ? (platform_sp->IsHost () ? "true" : "false") : "n/a",
2565 default_to_use_pty ? "true" : "false");
2566
Greg Claytonb09c5382013-12-13 17:20:18 +00002567 launch_info.FinalizeFileActions (this, default_to_use_pty);
2568
2569 if (state == eStateConnected)
2570 {
2571 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2572 {
2573 error.SetErrorString("can't launch in tty when launching through a remote connection");
2574 return error;
2575 }
2576 }
2577
2578 if (!launch_info.GetArchitecture().IsValid())
2579 launch_info.GetArchitecture() = GetArchitecture();
Todd Fiala015d8182014-07-22 23:41:36 +00002580
2581 // 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.
Greg Claytonb09c5382013-12-13 17:20:18 +00002582 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
2583 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002584 if (log)
2585 log->Printf ("Target::%s asking the platform to debug the process", __FUNCTION__);
2586
Greg Claytonb09c5382013-12-13 17:20:18 +00002587 m_process_sp = GetPlatform()->DebugProcess (launch_info,
2588 debugger,
2589 this,
Greg Claytonb09c5382013-12-13 17:20:18 +00002590 error);
2591 }
2592 else
2593 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002594 if (log)
2595 log->Printf ("Target::%s the platform doesn't know how to debug a process, getting a process plugin to do this for us.", __FUNCTION__);
2596
Greg Claytonb09c5382013-12-13 17:20:18 +00002597 if (state == eStateConnected)
2598 {
2599 assert(m_process_sp);
2600 }
2601 else
2602 {
Todd Fiala015d8182014-07-22 23:41:36 +00002603 // Use a Process plugin to construct the process.
Greg Claytonb09c5382013-12-13 17:20:18 +00002604 const char *plugin_name = launch_info.GetProcessPluginName();
Greg Clayton8012cad2014-11-17 19:39:20 +00002605 CreateProcess (launch_info.GetListenerForProcess(debugger), plugin_name, NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002606 }
Todd Fiala015d8182014-07-22 23:41:36 +00002607
2608 // Since we didn't have a platform launch the process, launch it here.
Greg Claytonb09c5382013-12-13 17:20:18 +00002609 if (m_process_sp)
2610 error = m_process_sp->Launch (launch_info);
2611 }
2612
2613 if (!m_process_sp)
2614 {
2615 if (error.Success())
2616 error.SetErrorString("failed to launch or debug process");
2617 return error;
2618 }
2619
2620 if (error.Success())
2621 {
2622 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
2623 {
Greg Clayton44d93782014-01-27 23:43:24 +00002624 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
Todd Fialaac33cc92014-10-09 01:02:08 +00002625
Greg Claytondc6224e2014-10-21 01:00:42 +00002626 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get(), NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002627
2628 if (state == eStateStopped)
2629 {
Greg Clayton44d93782014-01-27 23:43:24 +00002630 if (!synchronous_execution)
2631 m_process_sp->RestoreProcessEvents ();
2632
2633 error = m_process_sp->PrivateResume();
Todd Fialaa3b89e22014-08-12 14:33:19 +00002634
Greg Claytonb09c5382013-12-13 17:20:18 +00002635 if (error.Success())
2636 {
Todd Fialaa3b89e22014-08-12 14:33:19 +00002637 // there is a race condition where this thread will return up the call stack to the main command
2638 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
2639 // a chance to call PushProcessIOHandler()
2640 m_process_sp->SyncIOHandler(2000);
2641
Greg Claytonb09c5382013-12-13 17:20:18 +00002642 if (synchronous_execution)
2643 {
Greg Claytondc6224e2014-10-21 01:00:42 +00002644 state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get(), stream);
Greg Claytonb09c5382013-12-13 17:20:18 +00002645 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2646 if (!StateIsStoppedState(state, must_be_alive))
2647 {
Greg Clayton44d93782014-01-27 23:43:24 +00002648 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
Greg Claytonb09c5382013-12-13 17:20:18 +00002649 }
2650 }
2651 }
2652 else
2653 {
Greg Clayton44d93782014-01-27 23:43:24 +00002654 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002655 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002656 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002657 }
2658 }
Greg Clayton40286e02014-04-30 20:29:09 +00002659 else if (state == eStateExited)
2660 {
Zachary Turner10687b02014-10-20 17:46:43 +00002661 bool with_shell = !!launch_info.GetShell();
Greg Clayton40286e02014-04-30 20:29:09 +00002662 const int exit_status = m_process_sp->GetExitStatus();
2663 const char *exit_desc = m_process_sp->GetExitDescription();
2664#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'."
2665 if (exit_desc && exit_desc[0])
2666 {
2667 if (with_shell)
2668 error.SetErrorStringWithFormat ("process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, exit_status, exit_desc);
2669 else
2670 error.SetErrorStringWithFormat ("process exited with status %i (%s)", exit_status, exit_desc);
2671 }
2672 else
2673 {
2674 if (with_shell)
2675 error.SetErrorStringWithFormat ("process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
2676 else
2677 error.SetErrorStringWithFormat ("process exited with status %i", exit_status);
2678 }
2679 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002680 else
2681 {
2682 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2683 }
2684 }
Greg Clayton44d93782014-01-27 23:43:24 +00002685 m_process_sp->RestoreProcessEvents ();
Greg Claytonb09c5382013-12-13 17:20:18 +00002686 }
2687 else
2688 {
Greg Clayton44d93782014-01-27 23:43:24 +00002689 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002690 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002691 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002692 }
2693 return error;
2694}
Oleksiy Vyalov37386142015-02-10 22:49:57 +00002695
2696Error
2697Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
2698{
2699 auto state = eStateInvalid;
2700 auto process_sp = GetProcessSP ();
2701 if (process_sp)
2702 {
2703 state = process_sp->GetState ();
2704 if (process_sp->IsAlive () && state != eStateConnected)
2705 {
2706 if (state == eStateAttaching)
2707 return Error ("process attach is in progress");
2708 return Error ("a process is already being debugged");
2709 }
2710 }
2711
2712 ListenerSP hijack_listener_sp (new Listener ("lldb.Target.Attach.attach.hijack"));
2713 attach_info.SetHijackListener (hijack_listener_sp);
2714
2715 const ModuleSP old_exec_module_sp = GetExecutableModule ();
2716
2717 // If no process info was specified, then use the target executable
2718 // name as the process to attach to by default
2719 if (!attach_info.ProcessInfoSpecified ())
2720 {
2721 if (old_exec_module_sp)
2722 attach_info.GetExecutableFile ().GetFilename () = old_exec_module_sp->GetPlatformFileSpec ().GetFilename ();
2723
2724 if (!attach_info.ProcessInfoSpecified ())
2725 {
2726 return Error ("no process specified, create a target with a file, or specify the --pid or --name");
2727 }
2728 }
2729
2730 const auto platform_sp = GetDebugger ().GetPlatformList ().GetSelectedPlatform ();
2731
2732 Error error;
2733 if (state != eStateConnected && platform_sp != nullptr && platform_sp->CanDebugProcess ())
2734 {
2735 SetPlatform (platform_sp);
2736 process_sp = platform_sp->Attach (attach_info, GetDebugger (), this, error);
2737 }
2738 else
2739 {
2740 if (state != eStateConnected)
2741 {
2742 const char *plugin_name = attach_info.GetProcessPluginName ();
2743 process_sp = CreateProcess (attach_info.GetListenerForProcess (GetDebugger ()), plugin_name, nullptr);
2744 if (process_sp == nullptr)
2745 {
2746 error.SetErrorStringWithFormat ("failed to create process using plugin %s", (plugin_name) ? plugin_name : "null");
2747 return error;
2748 }
2749 }
2750 process_sp->HijackProcessEvents (hijack_listener_sp.get ());
2751 error = process_sp->Attach (attach_info);
2752 }
2753
2754 if (error.Success () && process_sp)
2755 {
2756 state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener ().get (), stream);
2757 process_sp->RestoreProcessEvents ();
2758
2759 if (state != eStateStopped)
2760 {
2761 const char *exit_desc = process_sp->GetExitDescription ();
2762 if (exit_desc)
2763 error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);
2764 else
2765 error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");
2766 process_sp->Destroy ();
2767 }
2768 }
2769 return error;
2770}
2771
Jim Ingham9575d842011-03-11 03:53:59 +00002772//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00002773// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00002774//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00002775Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2776 UserID (uid),
2777 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00002778 m_commands (),
2779 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00002780 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002781 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00002782{
2783}
2784
2785Target::StopHook::StopHook (const StopHook &rhs) :
2786 UserID (rhs.GetID()),
2787 m_target_sp (rhs.m_target_sp),
2788 m_commands (rhs.m_commands),
2789 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00002790 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002791 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00002792{
2793 if (rhs.m_thread_spec_ap.get() != NULL)
2794 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2795}
2796
2797
2798Target::StopHook::~StopHook ()
2799{
2800}
2801
2802void
Zachary Turner32abc6e2015-03-03 19:23:09 +00002803Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier)
2804{
2805 m_specifier_sp.reset(specifier);
2806}
2807
2808void
Jim Ingham9575d842011-03-11 03:53:59 +00002809Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2810{
2811 m_thread_spec_ap.reset (specifier);
2812}
2813
2814
2815void
2816Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2817{
2818 int indent_level = s->GetIndentLevel();
2819
2820 s->SetIndentLevel(indent_level + 2);
2821
Daniel Malead01b2952012-11-29 21:49:15 +00002822 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002823 if (m_active)
2824 s->Indent ("State: enabled\n");
2825 else
2826 s->Indent ("State: disabled\n");
2827
2828 if (m_specifier_sp)
2829 {
2830 s->Indent();
2831 s->PutCString ("Specifier:\n");
2832 s->SetIndentLevel (indent_level + 4);
2833 m_specifier_sp->GetDescription (s, level);
2834 s->SetIndentLevel (indent_level + 2);
2835 }
2836
2837 if (m_thread_spec_ap.get() != NULL)
2838 {
2839 StreamString tmp;
2840 s->Indent("Thread:\n");
2841 m_thread_spec_ap->GetDescription (&tmp, level);
2842 s->SetIndentLevel (indent_level + 4);
2843 s->Indent (tmp.GetData());
2844 s->PutCString ("\n");
2845 s->SetIndentLevel (indent_level + 2);
2846 }
2847
2848 s->Indent ("Commands: \n");
2849 s->SetIndentLevel (indent_level + 4);
2850 uint32_t num_commands = m_commands.GetSize();
2851 for (uint32_t i = 0; i < num_commands; i++)
2852 {
2853 s->Indent(m_commands.GetStringAtIndex(i));
2854 s->PutCString ("\n");
2855 }
2856 s->SetIndentLevel (indent_level);
2857}
2858
Greg Clayton67cc0632012-08-22 17:17:09 +00002859//--------------------------------------------------------------
2860// class TargetProperties
2861//--------------------------------------------------------------
2862
2863OptionEnumValueElement
2864lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002865{
Greg Clayton67cc0632012-08-22 17:17:09 +00002866 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2867 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2868 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2869 { 0, NULL, NULL }
2870};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002871
Greg Clayton1f746072012-08-29 21:13:06 +00002872static OptionEnumValueElement
2873g_inline_breakpoint_enums[] =
2874{
2875 { 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."},
2876 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2877 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2878 { 0, NULL, NULL }
2879};
2880
Jim Ingham0f063ba2013-03-02 00:26:47 +00002881typedef enum x86DisassemblyFlavor
2882{
2883 eX86DisFlavorDefault,
2884 eX86DisFlavorIntel,
2885 eX86DisFlavorATT
2886} x86DisassemblyFlavor;
2887
2888static OptionEnumValueElement
2889g_x86_dis_flavor_value_types[] =
2890{
2891 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2892 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2893 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2894 { 0, NULL, NULL }
2895};
2896
Enrico Granata397ddd52013-05-21 20:13:34 +00002897static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00002898g_hex_immediate_style_values[] =
2899{
2900 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
2901 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
2902 { 0, NULL, NULL }
2903};
2904
2905static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00002906g_load_script_from_sym_file_values[] =
2907{
2908 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
2909 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
2910 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
2911 { 0, NULL, NULL }
2912};
2913
Greg Claytonfd814c52013-08-13 01:42:25 +00002914
2915static OptionEnumValueElement
2916g_memory_module_load_level_values[] =
2917{
Greg Clayton86eac942013-08-13 21:32:34 +00002918 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00002919 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
2920 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
2921 { 0, NULL, NULL }
2922};
2923
Greg Clayton67cc0632012-08-22 17:17:09 +00002924static PropertyDefinition
2925g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002926{
Greg Clayton67cc0632012-08-22 17:17:09 +00002927 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2928 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
Enrico Granata9aa7e8e2015-01-09 00:47:24 +00002929 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eDynamicDontRunTarget , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002930 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2931 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2932 { "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 "
2933 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2934 "some part (starting at the root) of the path to the file when it was built, "
2935 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2936 "Each element of the array is checked in order and the first one that results in a match wins." },
2937 { "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." },
Michael Sartaina7499c92013-07-01 19:45:50 +00002938 { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating debug symbol files." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002939 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2940 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
Enrico Granatad325bf92013-06-04 22:54:16 +00002941 { "max-memory-read-size" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of bytes that 'memory read' will fetch before --force must be specified." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002942 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Clayton45392552012-10-17 22:57:12 +00002943 { "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." },
2944 { "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." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002945 { "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." },
2946 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2947 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2948 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2949 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
Jim Ingham106d0282014-06-25 02:32:56 +00002950 { "detach-on-error" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "debugserver will detach (rather than killing) a process if it loses connection with lldb." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002951 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2952 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Todd Fialaad6eee62014-09-24 19:59:13 +00002953 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsAlways , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
Greg Clayton1f746072012-08-29 21:13:06 +00002954 "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. "
2955 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2956 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
Todd Fialaad6eee62014-09-24 19:59:13 +00002957 "Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers "
2958 "and find that setting breakpoints is slow, then you can change this setting to headers. "
2959 "This setting allows you to control exactly which strategy is used when setting "
Greg Clayton1f746072012-08-29 21:13:06 +00002960 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00002961 // 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.
2962 { "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." },
Daniel Malead79ae052013-08-07 21:54:09 +00002963 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
2964 { "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, NULL, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." },
Jim Ingham34951272013-04-04 01:38:54 +00002965 { "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." },
Enrico Granata397ddd52013-05-21 20:13:34 +00002966 { "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." },
Greg Clayton86eac942013-08-13 21:32:34 +00002967 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
2968 "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. "
2969 "This setting helps users control how much information gets loaded when loading modules from memory."
2970 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
2971 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
2972 "'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). " },
Greg Claytonfb6621e2013-12-06 21:59:52 +00002973 { "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." },
Jason Molendaa4bea722014-02-14 05:06:49 +00002974 { "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." },
Enrico Granata560558e2015-02-11 02:35:39 +00002975 { "display-runtime-support-values" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "If true, LLDB will show variables that are meant to support the operation of a language's runtime support." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002976 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2977};
Enrico Granata560558e2015-02-11 02:35:39 +00002978
Greg Clayton67cc0632012-08-22 17:17:09 +00002979enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00002980{
Greg Clayton67cc0632012-08-22 17:17:09 +00002981 ePropertyDefaultArch,
2982 ePropertyExprPrefix,
2983 ePropertyPreferDynamic,
2984 ePropertyEnableSynthetic,
2985 ePropertySkipPrologue,
2986 ePropertySourceMap,
2987 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00002988 ePropertyDebugFileSearchPaths,
Greg Clayton67cc0632012-08-22 17:17:09 +00002989 ePropertyMaxChildrenCount,
2990 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00002991 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00002992 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00002993 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00002994 ePropertyRunArgs,
2995 ePropertyEnvVars,
2996 ePropertyInheritEnv,
2997 ePropertyInputPath,
2998 ePropertyOutputPath,
2999 ePropertyErrorPath,
Jim Ingham106d0282014-06-25 02:32:56 +00003000 ePropertyDetachOnError,
Greg Clayton67cc0632012-08-22 17:17:09 +00003001 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00003002 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00003003 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00003004 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00003005 ePropertyUseHexImmediates,
3006 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003007 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00003008 ePropertyLoadScriptFromSymbolFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00003009 ePropertyMemoryModuleLoadLevel,
Jason Molendaa4bea722014-02-14 05:06:49 +00003010 ePropertyDisplayExpressionsInCrashlogs,
Enrico Granata560558e2015-02-11 02:35:39 +00003011 ePropertyTrapHandlerNames,
3012 ePropertyDisplayRuntimeSupportValues
Greg Clayton67cc0632012-08-22 17:17:09 +00003013};
Caroline Ticedaccaa92010-09-20 20:44:43 +00003014
Caroline Ticedaccaa92010-09-20 20:44:43 +00003015
Greg Clayton67cc0632012-08-22 17:17:09 +00003016class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00003017{
Greg Clayton67cc0632012-08-22 17:17:09 +00003018public:
3019 TargetOptionValueProperties (const ConstString &name) :
3020 OptionValueProperties (name),
3021 m_target (NULL),
3022 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003023 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00003024 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00003025
Greg Clayton67cc0632012-08-22 17:17:09 +00003026 // This constructor is used when creating TargetOptionValueProperties when it
3027 // is part of a new lldb_private::Target instance. It will copy all current
3028 // global property values as needed
3029 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
3030 OptionValueProperties(*target_properties_sp->GetValueProperties()),
3031 m_target (target),
3032 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003033 {
Greg Clayton67cc0632012-08-22 17:17:09 +00003034 }
3035
3036 virtual const Property *
3037 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
3038 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003039 // When getting the value for a key from the target options, we will always
Greg Clayton67cc0632012-08-22 17:17:09 +00003040 // try and grab the setting from the current target if there is one. Else we just
3041 // use the one from this instance.
3042 if (idx == ePropertyEnvVars)
3043 GetHostEnvironmentIfNeeded ();
3044
3045 if (exe_ctx)
3046 {
3047 Target *target = exe_ctx->GetTargetPtr();
3048 if (target)
3049 {
3050 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
3051 if (this != target_properties)
3052 return target_properties->ProtectedGetPropertyAtIndex (idx);
3053 }
3054 }
3055 return ProtectedGetPropertyAtIndex (idx);
3056 }
Enrico Granata84a53df2013-05-20 22:29:23 +00003057
3058 lldb::TargetSP
3059 GetTargetSP ()
3060 {
3061 return m_target->shared_from_this();
3062 }
3063
Greg Clayton67cc0632012-08-22 17:17:09 +00003064protected:
3065
3066 void
3067 GetHostEnvironmentIfNeeded () const
3068 {
3069 if (!m_got_host_env)
3070 {
3071 if (m_target)
3072 {
3073 m_got_host_env = true;
3074 const uint32_t idx = ePropertyInheritEnv;
3075 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
3076 {
3077 PlatformSP platform_sp (m_target->GetPlatform());
3078 if (platform_sp)
3079 {
3080 StringList env;
3081 if (platform_sp->GetEnvironment(env))
3082 {
3083 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
3084 if (env_dict)
3085 {
3086 const bool can_replace = false;
3087 const size_t envc = env.GetSize();
3088 for (size_t idx=0; idx<envc; idx++)
3089 {
3090 const char *env_entry = env.GetStringAtIndex (idx);
3091 if (env_entry)
3092 {
3093 const char *equal_pos = ::strchr(env_entry, '=');
3094 ConstString key;
3095 // It is ok to have environment variables with no values
3096 const char *value = NULL;
3097 if (equal_pos)
3098 {
3099 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
3100 if (equal_pos[1])
3101 value = equal_pos + 1;
3102 }
3103 else
3104 {
3105 key.SetCString(env_entry);
3106 }
3107 // Don't allow existing keys to be replaced with ones we get from the platform environment
3108 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
3109 }
3110 }
3111 }
3112 }
3113 }
3114 }
3115 }
3116 }
3117 }
3118 Target *m_target;
3119 mutable bool m_got_host_env;
3120};
3121
Greg Claytonfbb76342013-11-20 21:07:01 +00003122//----------------------------------------------------------------------
3123// TargetProperties
3124//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00003125TargetProperties::TargetProperties (Target *target) :
Ilia K8f37ca52015-02-13 14:31:06 +00003126 Properties (),
3127 m_launch_info ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003128{
3129 if (target)
3130 {
3131 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Ilia K8f37ca52015-02-13 14:31:06 +00003132
3133 // Set callbacks to update launch_info whenever "settins set" updated any of these properties
3134 m_collection_sp->SetValueChangedCallback(ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this);
3135 m_collection_sp->SetValueChangedCallback(ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this);
3136 m_collection_sp->SetValueChangedCallback(ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this);
3137 m_collection_sp->SetValueChangedCallback(ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, this);
3138 m_collection_sp->SetValueChangedCallback(ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, this);
3139 m_collection_sp->SetValueChangedCallback(ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, this);
3140 m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, TargetProperties::DetachOnErrorValueChangedCallback, this);
3141 m_collection_sp->SetValueChangedCallback(ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, this);
3142 m_collection_sp->SetValueChangedCallback(ePropertyDisableSTDIO, TargetProperties::DisableSTDIOValueChangedCallback, this);
3143
3144 // Update m_launch_info once it was created
3145 Arg0ValueChangedCallback(this, NULL);
3146 RunArgsValueChangedCallback(this, NULL);
3147 //EnvVarsValueChangedCallback(this, NULL); // FIXME: cause segfault in Target::GetPlatform()
3148 InputPathValueChangedCallback(this, NULL);
3149 OutputPathValueChangedCallback(this, NULL);
3150 ErrorPathValueChangedCallback(this, NULL);
3151 DetachOnErrorValueChangedCallback(this, NULL);
3152 DisableASLRValueChangedCallback(this, NULL);
3153 DisableSTDIOValueChangedCallback(this, NULL);
Caroline Ticedaccaa92010-09-20 20:44:43 +00003154 }
3155 else
Greg Clayton67cc0632012-08-22 17:17:09 +00003156 {
3157 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
3158 m_collection_sp->Initialize(g_properties);
3159 m_collection_sp->AppendProperty(ConstString("process"),
3160 ConstString("Settings specify to processes."),
3161 true,
3162 Process::GetGlobalProperties()->GetValueProperties());
3163 }
Ilia K8f37ca52015-02-13 14:31:06 +00003164
Caroline Ticedaccaa92010-09-20 20:44:43 +00003165}
3166
Greg Clayton67cc0632012-08-22 17:17:09 +00003167TargetProperties::~TargetProperties ()
3168{
3169}
3170ArchSpec
3171TargetProperties::GetDefaultArchitecture () const
3172{
3173 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3174 if (value)
3175 return value->GetCurrentValue();
3176 return ArchSpec();
3177}
3178
3179void
3180TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
3181{
3182 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3183 if (value)
3184 return value->SetCurrentValue(arch, true);
3185}
3186
3187lldb::DynamicValueType
3188TargetProperties::GetPreferDynamicValue() const
3189{
3190 const uint32_t idx = ePropertyPreferDynamic;
3191 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3192}
3193
3194bool
3195TargetProperties::GetDisableASLR () const
3196{
3197 const uint32_t idx = ePropertyDisableASLR;
3198 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3199}
3200
3201void
3202TargetProperties::SetDisableASLR (bool b)
3203{
3204 const uint32_t idx = ePropertyDisableASLR;
3205 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3206}
3207
3208bool
Jim Ingham106d0282014-06-25 02:32:56 +00003209TargetProperties::GetDetachOnError () const
3210{
3211 const uint32_t idx = ePropertyDetachOnError;
3212 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3213}
3214
3215void
3216TargetProperties::SetDetachOnError (bool b)
3217{
3218 const uint32_t idx = ePropertyDetachOnError;
3219 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3220}
3221
3222bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003223TargetProperties::GetDisableSTDIO () const
3224{
3225 const uint32_t idx = ePropertyDisableSTDIO;
3226 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3227}
3228
3229void
3230TargetProperties::SetDisableSTDIO (bool b)
3231{
3232 const uint32_t idx = ePropertyDisableSTDIO;
3233 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3234}
3235
Jim Ingham0f063ba2013-03-02 00:26:47 +00003236const char *
3237TargetProperties::GetDisassemblyFlavor () const
3238{
3239 const uint32_t idx = ePropertyDisassemblyFlavor;
3240 const char *return_value;
3241
3242 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3243 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
3244 return return_value;
3245}
3246
Greg Clayton1f746072012-08-29 21:13:06 +00003247InlineStrategy
3248TargetProperties::GetInlineStrategy () const
3249{
3250 const uint32_t idx = ePropertyInlineStrategy;
3251 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3252}
3253
Greg Clayton45392552012-10-17 22:57:12 +00003254const char *
3255TargetProperties::GetArg0 () const
3256{
3257 const uint32_t idx = ePropertyArg0;
3258 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
3259}
3260
3261void
3262TargetProperties::SetArg0 (const char *arg)
3263{
3264 const uint32_t idx = ePropertyArg0;
3265 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
3266}
3267
Greg Clayton67cc0632012-08-22 17:17:09 +00003268bool
3269TargetProperties::GetRunArguments (Args &args) const
3270{
3271 const uint32_t idx = ePropertyRunArgs;
3272 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3273}
3274
3275void
3276TargetProperties::SetRunArguments (const Args &args)
3277{
3278 const uint32_t idx = ePropertyRunArgs;
3279 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3280}
3281
3282size_t
3283TargetProperties::GetEnvironmentAsArgs (Args &env) const
3284{
3285 const uint32_t idx = ePropertyEnvVars;
3286 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
3287}
3288
Ilia K8f37ca52015-02-13 14:31:06 +00003289void
3290TargetProperties::SetEnvironmentFromArgs (const Args &env)
3291{
3292 const uint32_t idx = ePropertyEnvVars;
3293 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, env);
3294}
3295
Greg Clayton67cc0632012-08-22 17:17:09 +00003296bool
3297TargetProperties::GetSkipPrologue() const
3298{
3299 const uint32_t idx = ePropertySkipPrologue;
3300 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3301}
3302
3303PathMappingList &
3304TargetProperties::GetSourcePathMap () const
3305{
3306 const uint32_t idx = ePropertySourceMap;
3307 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
3308 assert(option_value);
3309 return option_value->GetCurrentValue();
3310}
3311
3312FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00003313TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003314{
3315 const uint32_t idx = ePropertyExecutableSearchPaths;
3316 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3317 assert(option_value);
3318 return option_value->GetCurrentValue();
3319}
3320
Michael Sartaina7499c92013-07-01 19:45:50 +00003321FileSpecList &
3322TargetProperties::GetDebugFileSearchPaths ()
3323{
3324 const uint32_t idx = ePropertyDebugFileSearchPaths;
3325 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3326 assert(option_value);
3327 return option_value->GetCurrentValue();
3328}
3329
Greg Clayton67cc0632012-08-22 17:17:09 +00003330bool
3331TargetProperties::GetEnableSyntheticValue () const
3332{
3333 const uint32_t idx = ePropertyEnableSynthetic;
3334 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3335}
3336
3337uint32_t
3338TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
3339{
3340 const uint32_t idx = ePropertyMaxChildrenCount;
3341 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3342}
3343
3344uint32_t
3345TargetProperties::GetMaximumSizeOfStringSummary() const
3346{
3347 const uint32_t idx = ePropertyMaxSummaryLength;
3348 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3349}
3350
Enrico Granatad325bf92013-06-04 22:54:16 +00003351uint32_t
3352TargetProperties::GetMaximumMemReadSize () const
3353{
3354 const uint32_t idx = ePropertyMaxMemReadSize;
3355 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3356}
3357
Greg Clayton67cc0632012-08-22 17:17:09 +00003358FileSpec
3359TargetProperties::GetStandardInputPath () const
3360{
3361 const uint32_t idx = ePropertyInputPath;
3362 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3363}
3364
3365void
3366TargetProperties::SetStandardInputPath (const char *p)
3367{
3368 const uint32_t idx = ePropertyInputPath;
3369 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3370}
3371
3372FileSpec
3373TargetProperties::GetStandardOutputPath () const
3374{
3375 const uint32_t idx = ePropertyOutputPath;
3376 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3377}
3378
3379void
3380TargetProperties::SetStandardOutputPath (const char *p)
3381{
3382 const uint32_t idx = ePropertyOutputPath;
3383 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3384}
3385
3386FileSpec
3387TargetProperties::GetStandardErrorPath () const
3388{
3389 const uint32_t idx = ePropertyErrorPath;
3390 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
3391}
3392
Greg Clayton6920b522012-08-22 18:39:03 +00003393const char *
3394TargetProperties::GetExpressionPrefixContentsAsCString ()
3395{
3396 const uint32_t idx = ePropertyExprPrefix;
3397 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3398 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003399 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003400 const bool null_terminate = true;
3401 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003402 if (data_sp)
3403 return (const char *) data_sp->GetBytes();
3404 }
Greg Clayton6920b522012-08-22 18:39:03 +00003405 return NULL;
3406}
3407
Greg Clayton67cc0632012-08-22 17:17:09 +00003408void
3409TargetProperties::SetStandardErrorPath (const char *p)
3410{
3411 const uint32_t idx = ePropertyErrorPath;
3412 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3413}
3414
3415bool
3416TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3417{
3418 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3419 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3420}
3421
Jim Ingham17d023f2013-03-13 17:58:04 +00003422bool
Daniel Malead79ae052013-08-07 21:54:09 +00003423TargetProperties::GetUseHexImmediates () const
3424{
3425 const uint32_t idx = ePropertyUseHexImmediates;
3426 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3427}
3428
3429bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003430TargetProperties::GetUseFastStepping () const
3431{
3432 const uint32_t idx = ePropertyUseFastStepping;
3433 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3434}
3435
Greg Claytonfb6621e2013-12-06 21:59:52 +00003436bool
3437TargetProperties::GetDisplayExpressionsInCrashlogs () const
3438{
3439 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3440 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3441}
3442
Enrico Granata397ddd52013-05-21 20:13:34 +00003443LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003444TargetProperties::GetLoadScriptFromSymbolFile () const
3445{
3446 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Enrico Granata397ddd52013-05-21 20:13:34 +00003447 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003448}
3449
Daniel Malead79ae052013-08-07 21:54:09 +00003450Disassembler::HexImmediateStyle
3451TargetProperties::GetHexImmediateStyle () const
3452{
3453 const uint32_t idx = ePropertyHexImmediateStyle;
3454 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3455}
3456
Greg Claytonfd814c52013-08-13 01:42:25 +00003457MemoryModuleLoadLevel
3458TargetProperties::GetMemoryModuleLoadLevel() const
3459{
3460 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3461 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3462}
3463
Jason Molendaa4bea722014-02-14 05:06:49 +00003464bool
3465TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
3466{
3467 const uint32_t idx = ePropertyTrapHandlerNames;
3468 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3469}
Greg Claytonfd814c52013-08-13 01:42:25 +00003470
Jason Molendaa4bea722014-02-14 05:06:49 +00003471void
3472TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
3473{
3474 const uint32_t idx = ePropertyTrapHandlerNames;
3475 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3476}
Greg Clayton67cc0632012-08-22 17:17:09 +00003477
Enrico Granata560558e2015-02-11 02:35:39 +00003478bool
3479TargetProperties::GetDisplayRuntimeSupportValues () const
3480{
3481 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3482 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, false);
3483}
3484
3485void
3486TargetProperties::SetDisplayRuntimeSupportValues (bool b)
3487{
3488 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3489 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3490}
3491
Ilia K8f37ca52015-02-13 14:31:06 +00003492const ProcessLaunchInfo &
Ilia Kcc39d3f2015-02-13 17:07:55 +00003493TargetProperties::GetProcessLaunchInfo ()
Ilia K8f37ca52015-02-13 14:31:06 +00003494{
Ilia Kcc39d3f2015-02-13 17:07:55 +00003495 m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work
Ilia K8f37ca52015-02-13 14:31:06 +00003496 return m_launch_info;
3497}
3498
3499void
3500TargetProperties::SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
3501{
3502 m_launch_info = launch_info;
3503 SetArg0(launch_info.GetArg0());
3504 SetRunArguments(launch_info.GetArguments());
3505 SetEnvironmentFromArgs(launch_info.GetEnvironmentEntries());
3506 const FileAction *input_file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
3507 if (input_file_action)
3508 {
3509 const char *input_path = input_file_action->GetPath();
3510 if (input_path)
3511 SetStandardInputPath(input_path);
3512 }
3513 const FileAction *output_file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
3514 if (output_file_action)
3515 {
3516 const char *output_path = output_file_action->GetPath();
3517 if (output_path)
3518 SetStandardOutputPath(output_path);
3519 }
3520 const FileAction *error_file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
3521 if (error_file_action)
3522 {
3523 const char *error_path = error_file_action->GetPath();
3524 if (error_path)
3525 SetStandardErrorPath(error_path);
3526 }
3527 SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
3528 SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
3529 SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO));
3530}
3531
3532void
3533TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *)
3534{
3535 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3536 this_->m_launch_info.SetArg0(this_->GetArg0());
3537}
3538
3539void
3540TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *)
3541{
3542 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3543 Args args;
3544 if (this_->GetRunArguments(args))
3545 this_->m_launch_info.GetArguments() = args;
3546}
3547
3548void
3549TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *)
3550{
3551 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3552 Args args;
3553 if (this_->GetEnvironmentAsArgs(args))
3554 this_->m_launch_info.GetEnvironmentEntries() = args;
3555}
3556
3557void
3558TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3559{
3560 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3561 this_->m_launch_info.AppendOpenFileAction(STDIN_FILENO, this_->GetStandardInputPath().GetPath().c_str(), true, false);
3562}
3563
3564void
3565TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3566{
3567 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3568 this_->m_launch_info.AppendOpenFileAction(STDOUT_FILENO, this_->GetStandardOutputPath().GetPath().c_str(), false, true);
3569}
3570
3571void
3572TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3573{
3574 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3575 this_->m_launch_info.AppendOpenFileAction(STDERR_FILENO, this_->GetStandardErrorPath().GetPath().c_str(), false, true);
3576}
3577
3578void
3579TargetProperties::DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *)
3580{
3581 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3582 if (this_->GetDetachOnError())
3583 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError);
3584 else
3585 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError);
3586}
3587
3588void
3589TargetProperties::DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *)
3590{
3591 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3592 if (this_->GetDisableASLR())
3593 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR);
3594 else
3595 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR);
3596}
3597
3598void
3599TargetProperties::DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *)
3600{
3601 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3602 if (this_->GetDisableSTDIO())
3603 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO);
3604 else
3605 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO);
3606}