blob: ba97e0e3619efc019fd1c5164ee06e5dcd6f0db2 [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"
Zachary Turneraf0f45f2015-03-03 21:05:17 +000037#include "lldb/Expression/ClangPersistentVariables.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000038#include "lldb/Expression/ClangUserExpression.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000039#include "lldb/Expression/ClangModulesDeclVendor.h"
Zachary Turner10687b02014-10-20 17:46:43 +000040#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:59 +000042#include "lldb/Interpreter/CommandInterpreter.h"
43#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chenb90827e2012-06-04 23:19:54 +000044#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000045#include "lldb/Interpreter/OptionValues.h"
46#include "lldb/Interpreter/Property.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "lldb/lldb-private-log.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000048#include "lldb/Symbol/ClangASTContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Symbol/ObjectFile.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000050#include "lldb/Target/LanguageRuntime.h"
51#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000053#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000054#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000055#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000056#include "lldb/Target/Thread.h"
57#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59using namespace lldb;
60using namespace lldb_private;
61
Jim Ingham4bddaeb2012-02-16 06:50:00 +000062ConstString &
63Target::GetStaticBroadcasterClass ()
64{
65 static ConstString class_name ("lldb.target");
66 return class_name;
67}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069//----------------------------------------------------------------------
70// Target constructor
71//----------------------------------------------------------------------
Jim Ingham893c9322014-11-22 01:42:44 +000072Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp, bool is_dummy_target) :
Greg Clayton67cc0632012-08-22 17:17:09 +000073 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +000074 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +000075 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +000076 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +000077 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +000078 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +000079 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +000080 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +000081 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 m_breakpoint_list (false),
83 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +000084 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +000085 m_process_sp (),
86 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Claytone01e07b2013-04-18 18:10:51 +000088 m_scratch_ast_context_ap (),
89 m_scratch_ast_source_ap (),
90 m_ast_importer_ap (),
Zachary Turner32abc6e2015-03-03 19:23:09 +000091 m_persistent_variables (new ClangPersistentVariables),
Greg Clayton9585fbf2013-03-19 00:20:55 +000092 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +000093 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +000094 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +000095 m_valid (true),
Jim Ingham893c9322014-11-22 01:42:44 +000096 m_suppress_stop_hooks (false),
97 m_is_dummy_target(is_dummy_target)
98
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000100 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
101 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
102 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +0000103 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +0000104 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000105
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000106 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000107
Greg Clayton5160ce52013-03-27 23:08:40 +0000108 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000110 log->Printf ("%p Target::Target()", static_cast<void*>(this));
Jason Molendae1b68ad2012-12-05 00:25:49 +0000111 if (m_arch.IsValid())
112 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000113 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 +0000114 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115}
116
Jim Ingham893c9322014-11-22 01:42:44 +0000117void
118Target::PrimeFromDummyTarget(Target *target)
119{
120 if (!target)
121 return;
122
123 m_stop_hooks = target->m_stop_hooks;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000124
125 for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints())
126 {
127 if (breakpoint_sp->IsInternal())
128 continue;
129
130 BreakpointSP new_bp (new Breakpoint (*this, *breakpoint_sp.get()));
131 AddBreakpoint (new_bp, false);
132 }
Jim Ingham893c9322014-11-22 01:42:44 +0000133}
134
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135//----------------------------------------------------------------------
136// Destructor
137//----------------------------------------------------------------------
138Target::~Target()
139{
Greg Clayton5160ce52013-03-27 23:08:40 +0000140 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000142 log->Printf ("%p Target::~Target()", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 DeleteCurrentProcess ();
144}
145
146void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000147Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148{
Greg Clayton89411422010-10-08 00:21:05 +0000149// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000150 if (description_level != lldb::eDescriptionLevelBrief)
151 {
152 s->Indent();
153 s->PutCString("Target\n");
154 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000155 m_images.Dump(s);
156 m_breakpoint_list.Dump(s);
157 m_internal_breakpoint_list.Dump(s);
158 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000159 }
160 else
161 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000162 Module *exe_module = GetExecutableModulePointer();
163 if (exe_module)
164 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000165 else
166 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000167 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
170void
Greg Clayton90ba8112012-12-05 00:16:59 +0000171Target::CleanupProcess ()
172{
173 // Do any cleanup of the target we need to do between process instances.
174 // NB It is better to do this before destroying the process in case the
175 // clean up needs some help from the process.
176 m_breakpoint_list.ClearAllBreakpointSites();
177 m_internal_breakpoint_list.ClearAllBreakpointSites();
178 // Disable watchpoints just on the debugger side.
179 Mutex::Locker locker;
180 this->GetWatchpointList().GetListMutex(locker);
181 DisableAllWatchpoints(false);
182 ClearAllWatchpointHitCounts();
Enrico Granata5e3fe042015-02-11 00:37:54 +0000183 ClearAllWatchpointHistoricValues();
Greg Clayton90ba8112012-12-05 00:16:59 +0000184}
185
186void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187Target::DeleteCurrentProcess ()
188{
189 if (m_process_sp.get())
190 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000191 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 if (m_process_sp->IsAlive())
193 m_process_sp->Destroy();
Jim Inghamd0a3e122011-02-16 17:54:55 +0000194
195 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196
Greg Clayton90ba8112012-12-05 00:16:59 +0000197 CleanupProcess ();
198
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 m_process_sp.reset();
200 }
201}
202
203const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000204Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205{
206 DeleteCurrentProcess ();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000207 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 return m_process_sp;
209}
210
211const lldb::ProcessSP &
212Target::GetProcessSP () const
213{
214 return m_process_sp;
215}
216
Greg Clayton3418c852011-08-10 02:10:13 +0000217void
218Target::Destroy()
219{
220 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000221 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000222 DeleteCurrentProcess ();
223 m_platform_sp.reset();
224 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000225 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000226 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000227 const bool notify = false;
228 m_breakpoint_list.RemoveAll(notify);
229 m_internal_breakpoint_list.RemoveAll(notify);
230 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000231 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000232 m_search_filter_sp.reset();
233 m_image_search_paths.Clear(notify);
Zachary Turner32abc6e2015-03-03 19:23:09 +0000234 m_persistent_variables->Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000235 m_stop_hooks.clear();
236 m_stop_hook_next_id = 0;
237 m_suppress_stop_hooks = false;
238}
239
240
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241BreakpointList &
242Target::GetBreakpointList(bool internal)
243{
244 if (internal)
245 return m_internal_breakpoint_list;
246 else
247 return m_breakpoint_list;
248}
249
250const BreakpointList &
251Target::GetBreakpointList(bool internal) const
252{
253 if (internal)
254 return m_internal_breakpoint_list;
255 else
256 return m_breakpoint_list;
257}
258
259BreakpointSP
260Target::GetBreakpointByID (break_id_t break_id)
261{
262 BreakpointSP bp_sp;
263
264 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
265 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
266 else
267 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
268
269 return bp_sp;
270}
271
272BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000273Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000274 const FileSpecList *source_file_spec_list,
275 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000276 bool internal,
277 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278{
Jim Ingham87df91b2011-09-23 00:54:11 +0000279 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
280 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000281 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000282}
283
284
285BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000286Target::CreateBreakpoint (const FileSpecList *containingModules,
287 const FileSpec &file,
288 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000289 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000290 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000291 bool internal,
292 bool hardware)
Jim Ingham969795f2011-09-21 01:17:13 +0000293{
Greg Clayton1f746072012-08-29 21:13:06 +0000294 if (check_inlines == eLazyBoolCalculate)
295 {
296 const InlineStrategy inline_strategy = GetInlineStrategy();
297 switch (inline_strategy)
298 {
299 case eInlineBreakpointsNever:
300 check_inlines = eLazyBoolNo;
301 break;
302
303 case eInlineBreakpointsHeaders:
304 if (file.IsSourceImplementationFile())
305 check_inlines = eLazyBoolNo;
306 else
307 check_inlines = eLazyBoolYes;
308 break;
309
310 case eInlineBreakpointsAlways:
311 check_inlines = eLazyBoolYes;
312 break;
313 }
314 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000315 SearchFilterSP filter_sp;
316 if (check_inlines == eLazyBoolNo)
317 {
318 // Not checking for inlines, we are looking only for matching compile units
319 FileSpecList compile_unit_list;
320 compile_unit_list.Append (file);
321 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
322 }
323 else
324 {
325 filter_sp = GetSearchFilterForModuleList (containingModules);
326 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000327 if (skip_prologue == eLazyBoolCalculate)
328 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
329
Greg Clayton1f746072012-08-29 21:13:06 +0000330 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
331 file,
332 line_no,
333 check_inlines,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000334 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000335 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336}
337
338
339BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000340Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342 Address so_addr;
343 // Attempt to resolve our load address if possible, though it is ok if
344 // it doesn't resolve to section/offset.
345
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000346 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000347 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000348 if (!so_addr.IsValid())
349 {
350 // The address didn't resolve, so just set this as an absolute address
351 so_addr.SetOffset (addr);
352 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000353 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 return bp_sp;
355}
356
357BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000358Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359{
Jim Ingham33df7cd2014-12-06 01:28:03 +0000360 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000362 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000366Target::CreateBreakpoint (const FileSpecList *containingModules,
367 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000368 const char *func_name,
369 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000370 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000371 bool internal,
372 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000374 BreakpointSP bp_sp;
375 if (func_name)
376 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000377 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000378
379 if (skip_prologue == eLazyBoolCalculate)
380 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
381
Greg Claytond16e1e52011-07-12 17:06:17 +0000382 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
383 func_name,
384 func_name_type_mask,
385 Breakpoint::Exact,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000386 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000387 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000388 }
389 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390}
391
Jim Inghamfab10e82012-03-06 00:37:27 +0000392lldb::BreakpointSP
393Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000394 const FileSpecList *containingSourceFiles,
395 const std::vector<std::string> &func_names,
396 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000397 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000398 bool internal,
399 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000400{
401 BreakpointSP bp_sp;
402 size_t num_names = func_names.size();
403 if (num_names > 0)
404 {
405 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000406
407 if (skip_prologue == eLazyBoolCalculate)
408 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
409
410 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Inghamfab10e82012-03-06 00:37:27 +0000411 func_names,
412 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000413 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000414 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000415 }
416 return bp_sp;
417}
418
Jim Ingham133e0fb2012-03-03 02:05:11 +0000419BreakpointSP
420Target::CreateBreakpoint (const FileSpecList *containingModules,
421 const FileSpecList *containingSourceFiles,
422 const char *func_names[],
423 size_t num_names,
424 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000425 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000426 bool internal,
427 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000428{
429 BreakpointSP bp_sp;
430 if (num_names > 0)
431 {
432 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
433
Greg Clayton03da4cc2013-04-19 21:31:16 +0000434 if (skip_prologue == eLazyBoolCalculate)
435 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
436
437 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Ingham133e0fb2012-03-03 02:05:11 +0000438 func_names,
439 num_names,
Jim Inghamfab10e82012-03-06 00:37:27 +0000440 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000441 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000442 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000443 }
444 return bp_sp;
445}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446
447SearchFilterSP
448Target::GetSearchFilterForModule (const FileSpec *containingModule)
449{
450 SearchFilterSP filter_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 if (containingModule != NULL)
452 {
453 // TODO: We should look into sharing module based search filters
454 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000455 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 }
457 else
458 {
459 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000460 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461 filter_sp = m_search_filter_sp;
462 }
463 return filter_sp;
464}
465
Jim Ingham969795f2011-09-21 01:17:13 +0000466SearchFilterSP
467Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
468{
469 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000470 if (containingModules && containingModules->GetSize() != 0)
471 {
472 // TODO: We should look into sharing module based search filters
473 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000474 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000475 }
476 else
477 {
478 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000479 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000480 filter_sp = m_search_filter_sp;
481 }
482 return filter_sp;
483}
484
Jim Ingham87df91b2011-09-23 00:54:11 +0000485SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000486Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
487 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000488{
489 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
490 return GetSearchFilterForModuleList(containingModules);
491
492 SearchFilterSP filter_sp;
Jim Ingham87df91b2011-09-23 00:54:11 +0000493 if (containingModules == NULL)
494 {
495 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
496 // but that will take a little reworking.
497
Greg Claytone1cd1be2012-01-29 20:56:30 +0000498 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000499 }
500 else
501 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000502 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000503 }
504 return filter_sp;
505}
506
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000508Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000509 const FileSpecList *containingSourceFiles,
510 RegularExpression &func_regex,
511 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000512 bool internal,
513 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514{
Jim Ingham87df91b2011-09-23 00:54:11 +0000515 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000516 bool skip =
517 (skip_prologue == eLazyBoolCalculate) ? GetSkipPrologue()
518 : static_cast<bool>(skip_prologue);
Greg Claytond16e1e52011-07-12 17:06:17 +0000519 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
520 func_regex,
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000521 skip));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522
Jim Ingham1460e4b2014-01-10 23:46:59 +0000523 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524}
525
Jim Ingham219ba192012-03-05 04:47:34 +0000526lldb::BreakpointSP
527Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
528{
529 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
530}
531
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000533Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534{
535 BreakpointSP bp_sp;
536 if (filter_sp && resolver_sp)
537 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000538 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539 resolver_sp->SetBreakpoint (bp_sp.get());
Jim Ingham33df7cd2014-12-06 01:28:03 +0000540 AddBreakpoint (bp_sp, internal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 }
Jim Ingham33df7cd2014-12-06 01:28:03 +0000542 return bp_sp;
543}
544
545void
546Target::AddBreakpoint (lldb::BreakpointSP bp_sp, bool internal)
547{
548 if (!bp_sp)
549 return;
550 if (internal)
551 m_internal_breakpoint_list.Add (bp_sp, false);
552 else
553 m_breakpoint_list.Add (bp_sp, true);
554
555 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
556 if (log)
557 {
558 StreamString s;
559 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
560 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
561 }
562
563 bp_sp->ResolveBreakpoint();
564
565 if (!internal)
Jim Ingham36f3b362010-10-14 23:45:03 +0000566 {
567 m_last_created_breakpoint = bp_sp;
568 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569}
570
Johnny Chen86364b42011-09-20 23:28:55 +0000571bool
572Target::ProcessIsValid()
573{
574 return (m_process_sp && m_process_sp->IsAlive());
575}
576
Johnny Chenb90827e2012-06-04 23:19:54 +0000577static bool
578CheckIfWatchpointsExhausted(Target *target, Error &error)
579{
580 uint32_t num_supported_hardware_watchpoints;
581 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
582 if (rc.Success())
583 {
584 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
585 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
586 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
587 num_supported_hardware_watchpoints);
588 }
589 return false;
590}
591
Johnny Chen01a67862011-10-14 00:42:25 +0000592// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000593// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000594WatchpointSP
Jim Inghama7dfb662012-10-23 07:20:06 +0000595Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000596{
Greg Clayton5160ce52013-03-27 23:08:40 +0000597 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000598 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000599 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000600 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000601
Johnny Chen01a67862011-10-14 00:42:25 +0000602 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000603 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000604 {
605 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000606 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000607 }
Jim Inghamc6462312013-06-18 21:52:48 +0000608
Johnny Chen45e541f2011-09-14 22:20:15 +0000609 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000610 {
611 if (size == 0)
612 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
613 else
Daniel Malead01b2952012-11-29 21:49:15 +0000614 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000615 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000616 }
Jim Inghamc6462312013-06-18 21:52:48 +0000617
618 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
619 {
620 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
621 }
Johnny Chen7313a642011-09-13 01:15:36 +0000622
Johnny Chen01a67862011-10-14 00:42:25 +0000623 // Currently we only support one watchpoint per address, with total number
624 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000625
626 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000627 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 +0000628 Mutex::Locker locker;
629 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000630 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000631 if (matched_sp)
632 {
Johnny Chen0c406372011-09-14 20:23:45 +0000633 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000634 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000635 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
636 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000637 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000638 if (size == old_size && kind == old_type)
639 {
Johnny Chen01a67862011-10-14 00:42:25 +0000640 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000641 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000642 }
643 else
644 {
Johnny Chen01a67862011-10-14 00:42:25 +0000645 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000646 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
647 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000648 }
Johnny Chen3c532582011-09-13 23:29:31 +0000649 }
650
Jason Molenda727e3922012-12-05 23:07:34 +0000651 if (!wp_sp)
652 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000653 wp_sp.reset(new Watchpoint(*this, addr, size, type));
654 wp_sp->SetWatchpointType(kind, notify);
655 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000656 }
Johnny Chen0c406372011-09-14 20:23:45 +0000657
Jim Ingham1b5792e2012-12-18 02:03:49 +0000658 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000659 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000660 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
661 __FUNCTION__,
662 error.Success() ? "succeeded" : "failed",
663 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000664
Jason Molenda727e3922012-12-05 23:07:34 +0000665 if (error.Fail())
666 {
Johnny Chen41b77262012-03-26 22:00:10 +0000667 // Enabling the watchpoint on the device side failed.
668 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000669 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000670 // See if we could provide more helpful error message.
671 if (!CheckIfWatchpointsExhausted(this, error))
672 {
673 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Greg Clayton6fea17e2014-03-03 19:15:20 +0000674 error.SetErrorStringWithFormat("watch size of %" PRIu64 " is not supported", (uint64_t)size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000675 }
Johnny Chen01a67862011-10-14 00:42:25 +0000676 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000677 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000678 else
Johnny Chen01a67862011-10-14 00:42:25 +0000679 m_last_created_watchpoint = wp_sp;
680 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000681}
682
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683void
684Target::RemoveAllBreakpoints (bool internal_also)
685{
Greg Clayton5160ce52013-03-27 23:08:40 +0000686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 if (log)
688 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
689
Greg Clayton9fed0d82010-07-23 23:33:17 +0000690 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000692 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000693
694 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695}
696
697void
698Target::DisableAllBreakpoints (bool internal_also)
699{
Greg Clayton5160ce52013-03-27 23:08:40 +0000700 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701 if (log)
702 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
703
704 m_breakpoint_list.SetEnabledAll (false);
705 if (internal_also)
706 m_internal_breakpoint_list.SetEnabledAll (false);
707}
708
709void
710Target::EnableAllBreakpoints (bool internal_also)
711{
Greg Clayton5160ce52013-03-27 23:08:40 +0000712 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 if (log)
714 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
715
716 m_breakpoint_list.SetEnabledAll (true);
717 if (internal_also)
718 m_internal_breakpoint_list.SetEnabledAll (true);
719}
720
721bool
722Target::RemoveBreakpointByID (break_id_t break_id)
723{
Greg Clayton5160ce52013-03-27 23:08:40 +0000724 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 if (log)
726 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
727
728 if (DisableBreakpointByID (break_id))
729 {
730 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000731 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000733 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000734 if (m_last_created_breakpoint)
735 {
736 if (m_last_created_breakpoint->GetID() == break_id)
737 m_last_created_breakpoint.reset();
738 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000739 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000740 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 return true;
742 }
743 return false;
744}
745
746bool
747Target::DisableBreakpointByID (break_id_t break_id)
748{
Greg Clayton5160ce52013-03-27 23:08:40 +0000749 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 if (log)
751 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
752
753 BreakpointSP bp_sp;
754
755 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
756 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
757 else
758 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
759 if (bp_sp)
760 {
761 bp_sp->SetEnabled (false);
762 return true;
763 }
764 return false;
765}
766
767bool
768Target::EnableBreakpointByID (break_id_t break_id)
769{
Greg Clayton5160ce52013-03-27 23:08:40 +0000770 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 if (log)
772 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
773 __FUNCTION__,
774 break_id,
775 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
776
777 BreakpointSP bp_sp;
778
779 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
780 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
781 else
782 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
783
784 if (bp_sp)
785 {
786 bp_sp->SetEnabled (true);
787 return true;
788 }
789 return false;
790}
791
Johnny Chenedf50372011-09-23 21:21:43 +0000792// The flag 'end_to_end', default to true, signifies that the operation is
793// performed end to end, for both the debugger and the debuggee.
794
Johnny Chen01a67862011-10-14 00:42:25 +0000795// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
796// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000797bool
Johnny Chen01a67862011-10-14 00:42:25 +0000798Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000799{
Greg Clayton5160ce52013-03-27 23:08:40 +0000800 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000801 if (log)
802 log->Printf ("Target::%s\n", __FUNCTION__);
803
Johnny Chenedf50372011-09-23 21:21:43 +0000804 if (!end_to_end) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000805 m_watchpoint_list.RemoveAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000806 return true;
807 }
808
809 // Otherwise, it's an end to end operation.
810
Johnny Chen86364b42011-09-20 23:28:55 +0000811 if (!ProcessIsValid())
812 return false;
813
Johnny Chen01a67862011-10-14 00:42:25 +0000814 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000815 for (size_t i = 0; i < num_watchpoints; ++i)
816 {
Johnny Chen01a67862011-10-14 00:42:25 +0000817 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
818 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000819 return false;
820
Johnny Chen01a67862011-10-14 00:42:25 +0000821 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000822 if (rc.Fail())
823 return false;
824 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000825 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000826 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000827 return true; // Success!
828}
829
Johnny Chen01a67862011-10-14 00:42:25 +0000830// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
831// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000832bool
Johnny Chen01a67862011-10-14 00:42:25 +0000833Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000834{
Greg Clayton5160ce52013-03-27 23:08:40 +0000835 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000836 if (log)
837 log->Printf ("Target::%s\n", __FUNCTION__);
838
Johnny Chenedf50372011-09-23 21:21:43 +0000839 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000840 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000841 return true;
842 }
843
844 // Otherwise, it's an end to end operation.
845
Johnny Chen86364b42011-09-20 23:28:55 +0000846 if (!ProcessIsValid())
847 return false;
848
Johnny Chen01a67862011-10-14 00:42:25 +0000849 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000850 for (size_t i = 0; i < num_watchpoints; ++i)
851 {
Johnny Chen01a67862011-10-14 00:42:25 +0000852 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
853 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000854 return false;
855
Johnny Chen01a67862011-10-14 00:42:25 +0000856 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000857 if (rc.Fail())
858 return false;
859 }
Johnny Chen86364b42011-09-20 23:28:55 +0000860 return true; // Success!
861}
862
Johnny Chen01a67862011-10-14 00:42:25 +0000863// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
864// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000865bool
Johnny Chen01a67862011-10-14 00:42:25 +0000866Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000867{
Greg Clayton5160ce52013-03-27 23:08:40 +0000868 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000869 if (log)
870 log->Printf ("Target::%s\n", __FUNCTION__);
871
Johnny Chenedf50372011-09-23 21:21:43 +0000872 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000873 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000874 return true;
875 }
876
877 // Otherwise, it's an end to end operation.
878
Johnny Chen86364b42011-09-20 23:28:55 +0000879 if (!ProcessIsValid())
880 return false;
881
Johnny Chen01a67862011-10-14 00:42:25 +0000882 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000883 for (size_t i = 0; i < num_watchpoints; ++i)
884 {
Johnny Chen01a67862011-10-14 00:42:25 +0000885 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
886 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000887 return false;
888
Johnny Chen01a67862011-10-14 00:42:25 +0000889 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000890 if (rc.Fail())
891 return false;
892 }
Johnny Chen86364b42011-09-20 23:28:55 +0000893 return true; // Success!
894}
895
Johnny Chena4d6bc92012-02-25 06:44:30 +0000896// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
897bool
898Target::ClearAllWatchpointHitCounts ()
899{
Greg Clayton5160ce52013-03-27 23:08:40 +0000900 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +0000901 if (log)
902 log->Printf ("Target::%s\n", __FUNCTION__);
903
904 size_t num_watchpoints = m_watchpoint_list.GetSize();
905 for (size_t i = 0; i < num_watchpoints; ++i)
906 {
907 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
908 if (!wp_sp)
909 return false;
910
911 wp_sp->ResetHitCount();
912 }
913 return true; // Success!
914}
915
Enrico Granata5e3fe042015-02-11 00:37:54 +0000916// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
917bool
918Target::ClearAllWatchpointHistoricValues ()
919{
920 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
921 if (log)
922 log->Printf ("Target::%s\n", __FUNCTION__);
923
924 size_t num_watchpoints = m_watchpoint_list.GetSize();
925 for (size_t i = 0; i < num_watchpoints; ++i)
926 {
927 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
928 if (!wp_sp)
929 return false;
930
931 wp_sp->ResetHistoricValues();
932 }
933 return true; // Success!
934}
935
Johnny Chen01a67862011-10-14 00:42:25 +0000936// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +0000937// during these operations.
938bool
Johnny Chen01a67862011-10-14 00:42:25 +0000939Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000940{
Greg Clayton5160ce52013-03-27 23:08:40 +0000941 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000942 if (log)
943 log->Printf ("Target::%s\n", __FUNCTION__);
944
945 if (!ProcessIsValid())
946 return false;
947
Johnny Chen01a67862011-10-14 00:42:25 +0000948 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +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 Chen6cc60e82011-10-05 21:35:46 +0000953 return false;
954
Johnny Chen01a67862011-10-14 00:42:25 +0000955 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000956 }
957 return true; // Success!
958}
959
Johnny Chen01a67862011-10-14 00:42:25 +0000960// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000961bool
Johnny Chen01a67862011-10-14 00:42:25 +0000962Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000963{
Greg Clayton5160ce52013-03-27 23:08:40 +0000964 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000965 if (log)
966 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
967
968 if (!ProcessIsValid())
969 return false;
970
Johnny Chen01a67862011-10-14 00:42:25 +0000971 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
972 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000973 {
Johnny Chen01a67862011-10-14 00:42:25 +0000974 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000975 if (rc.Success())
976 return true;
Johnny Chen86364b42011-09-20 23:28:55 +0000977
Johnny Chenf04ee932011-09-22 18:04:58 +0000978 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +0000979 }
980 return false;
981}
982
Johnny Chen01a67862011-10-14 00:42:25 +0000983// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000984bool
Johnny Chen01a67862011-10-14 00:42:25 +0000985Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000986{
Greg Clayton5160ce52013-03-27 23:08:40 +0000987 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000988 if (log)
989 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
990
991 if (!ProcessIsValid())
992 return false;
993
Johnny Chen01a67862011-10-14 00:42:25 +0000994 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
995 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000996 {
Johnny Chen01a67862011-10-14 00:42:25 +0000997 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000998 if (rc.Success())
999 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001000
Johnny Chenf04ee932011-09-22 18:04:58 +00001001 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001002 }
1003 return false;
1004}
1005
Johnny Chen01a67862011-10-14 00:42:25 +00001006// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001007bool
Johnny Chen01a67862011-10-14 00:42:25 +00001008Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001009{
Greg Clayton5160ce52013-03-27 23:08:40 +00001010 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001011 if (log)
1012 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1013
Jim Inghamb0b45132013-07-02 02:09:46 +00001014 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
1015 if (watch_to_remove_sp == m_last_created_watchpoint)
1016 m_last_created_watchpoint.reset();
1017
Johnny Chen01a67862011-10-14 00:42:25 +00001018 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +00001019 {
Jim Ingham1b5792e2012-12-18 02:03:49 +00001020 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +00001021 return true;
1022 }
1023 return false;
1024}
1025
Johnny Chen01a67862011-10-14 00:42:25 +00001026// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +00001027bool
Johnny Chen01a67862011-10-14 00:42:25 +00001028Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001029{
Greg Clayton5160ce52013-03-27 23:08:40 +00001030 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +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 Chen6cc60e82011-10-05 21:35:46 +00001039 {
Johnny Chen01a67862011-10-14 00:42:25 +00001040 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001041 return true;
1042 }
1043 return false;
1044}
1045
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046ModuleSP
1047Target::GetExecutableModule ()
1048{
Greg Claytonaa149cb2011-08-11 02:48:45 +00001049 return m_images.GetModuleAtIndex(0);
1050}
1051
1052Module*
1053Target::GetExecutableModulePointer ()
1054{
1055 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056}
1057
Enrico Granata17598482012-11-08 02:22:02 +00001058static void
1059LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1060{
1061 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001062 StreamString feedback_stream;
1063 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001064 {
Enrico Granata97303392013-05-21 00:00:30 +00001065 if (error.AsCString())
Greg Clayton44d93782014-01-27 23:43:24 +00001066 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001067 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1068 error.AsCString());
Enrico Granata17598482012-11-08 02:22:02 +00001069 }
Enrico Granatafe7295d2014-08-16 00:32:58 +00001070 if (feedback_stream.GetSize())
1071 target->GetDebugger().GetErrorFile()->Printf("%s\n",
1072 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001073}
1074
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075void
Greg Claytonb35db632013-11-09 00:03:31 +00001076Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077{
Greg Claytonb35db632013-11-09 00:03:31 +00001078 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001079 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080 m_images.Clear();
1081 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19 +00001082 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47 +00001083 m_ast_importer_ap.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001084}
1085
1086void
Greg Claytonb35db632013-11-09 00:03:31 +00001087Target::DidExec ()
1088{
1089 // When a process exec's we need to know about it so we can do some cleanup.
1090 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1091 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1092}
1093
1094void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001095Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1096{
1097 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001098 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099
1100 if (executable_sp.get())
1101 {
1102 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001103 "Target::SetExecutableModule (executable = '%s')",
1104 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001105
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001106 m_images.Append(executable_sp); // The first image is our executable file
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107
Jim Ingham5aee1622010-08-09 23:31:02 +00001108 // 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 +00001109 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001110 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001111 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001112 if (log)
1113 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1114 }
1115
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001117 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001118
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001119 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120 {
1121 executable_objfile->GetDependentModules(dependent_files);
1122 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1123 {
Greg Claytonded470d2011-03-19 01:12:21 +00001124 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1125 FileSpec platform_dependent_file_spec;
1126 if (m_platform_sp)
Steve Puccifc995722014-01-17 18:18:31 +00001127 m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001128 else
1129 platform_dependent_file_spec = dependent_file_spec;
1130
Greg Claytonb9a01b32012-02-26 05:51:37 +00001131 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1132 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133 if (image_module_sp.get())
1134 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 ObjectFile *objfile = image_module_sp->GetObjectFile();
1136 if (objfile)
1137 objfile->GetDependentModules(dependent_files);
1138 }
1139 }
1140 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001141 }
1142}
1143
1144
Jim Ingham5aee1622010-08-09 23:31:02 +00001145bool
1146Target::SetArchitecture (const ArchSpec &arch_spec)
1147{
Greg Clayton5160ce52013-03-27 23:08:40 +00001148 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callananbf4b7be2012-12-13 22:07:14 +00001149 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001150 {
Greg Clayton70512312012-05-08 01:45:38 +00001151 // If we haven't got a valid arch spec, or the architectures are
1152 // compatible, so just update the architecture. Architectures can be
1153 // equal, yet the triple OS and vendor might change, so we need to do
1154 // the assignment here just in case.
Greg Clayton32e0a752011-03-30 18:16:51 +00001155 m_arch = arch_spec;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001156 if (log)
1157 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 +00001158 return true;
1159 }
1160 else
1161 {
1162 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molendae1b68ad2012-12-05 00:25:49 +00001163 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +00001164 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 +00001165 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02 +00001166 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001167
Greg Claytonb35db632013-11-09 00:03:31 +00001168 ClearModules(true);
Jim Ingham5aee1622010-08-09 23:31:02 +00001169 // Need to do something about unsetting breakpoints.
1170
1171 if (executable_sp)
1172 {
Jason Molendae1b68ad2012-12-05 00:25:49 +00001173 if (log)
1174 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 +00001175 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1176 Error error = ModuleList::GetSharedModule (module_spec,
1177 executable_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001178 &GetExecutableSearchPaths(),
Greg Claytonb9a01b32012-02-26 05:51:37 +00001179 NULL,
1180 NULL);
Jim Ingham5aee1622010-08-09 23:31:02 +00001181
1182 if (!error.Fail() && executable_sp)
1183 {
1184 SetExecutableModule (executable_sp, true);
1185 return true;
1186 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001187 }
1188 }
Greg Clayton70512312012-05-08 01:45:38 +00001189 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001190}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192void
Enrico Granataefe637d2012-11-08 19:16:03 +00001193Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001194{
1195}
1196
1197void
Enrico Granataefe637d2012-11-08 19:16:03 +00001198Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199{
1200 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001201 if (m_valid)
1202 {
1203 ModuleList my_module_list;
1204 my_module_list.Append(module_sp);
1205 LoadScriptingResourceForModule(module_sp, this);
1206 ModulesDidLoad (my_module_list);
1207 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208}
1209
1210void
Enrico Granataefe637d2012-11-08 19:16:03 +00001211Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001212{
1213 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001214 if (m_valid)
1215 {
1216 ModuleList my_module_list;
1217 my_module_list.Append(module_sp);
1218 ModulesDidUnload (my_module_list, false);
1219 }
Enrico Granata17598482012-11-08 02:22:02 +00001220}
1221
1222void
Enrico Granataefe637d2012-11-08 19:16:03 +00001223Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224{
Jim Inghame716ae02011-08-03 01:00:06 +00001225 // A module is replacing an already added module
Greg Clayton23f8c952014-03-24 23:10:19 +00001226 if (m_valid)
1227 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228}
1229
1230void
1231Target::ModulesDidLoad (ModuleList &module_list)
1232{
Greg Clayton23f8c952014-03-24 23:10:19 +00001233 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001234 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001235 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001236 if (m_process_sp)
1237 {
Andrew MacPhersoneb4d0602014-03-13 09:37:02 +00001238 m_process_sp->ModulesDidLoad (module_list);
Jason Molendaeef51062013-11-05 03:57:19 +00001239 }
Ilia Keb2c19a2015-03-10 21:59:55 +00001240 BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242}
1243
1244void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001245Target::SymbolsDidLoad (ModuleList &module_list)
1246{
Greg Clayton23f8c952014-03-24 23:10:19 +00001247 if (m_valid && module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001248 {
Jim Ingham31caf982013-06-04 23:01:35 +00001249 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001250 {
Jim Ingham31caf982013-06-04 23:01:35 +00001251 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1252 if (runtime)
1253 {
1254 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1255 objc_runtime->SymbolsDidLoad(module_list);
1256 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001257 }
Jim Ingham31caf982013-06-04 23:01:35 +00001258
Greg Clayton095eeaa2013-11-05 23:28:00 +00001259 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Ilia Keb2c19a2015-03-10 21:59:55 +00001260 BroadcastEvent (eBroadcastBitSymbolsLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001261 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001262}
1263
1264void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001265Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266{
Greg Clayton23f8c952014-03-24 23:10:19 +00001267 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001268 {
Greg Clayton8012cad2014-11-17 19:39:20 +00001269 UnloadModuleSections (module_list);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001270 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Ilia Keb2c19a2015-03-10 21:59:55 +00001271 BroadcastEvent (eBroadcastBitModulesUnloaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001272 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273}
1274
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001275bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001276Target::ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001277{
Greg Clayton67cc0632012-08-22 17:17:09 +00001278 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001279 {
1280 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001281 ModuleSpec module_spec (module_file_spec);
1282 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001283
1284 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1285 // black list.
1286 if (num_modules > 0)
1287 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001288 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001289 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001290 if (!ModuleIsExcludedForUnconstrainedSearches (matchingModules.GetModuleAtIndex(i)))
Jim Inghamc6674fd2011-10-28 23:14:11 +00001291 return false;
1292 }
1293 return true;
1294 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001295 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001296 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001297}
1298
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001299bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001300Target::ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001301{
Greg Clayton67cc0632012-08-22 17:17:09 +00001302 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001303 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001304 if (m_platform_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +00001305 return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001306 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001307 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001308}
1309
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310size_t
Greg Claytondb598232011-01-07 01:57:07 +00001311Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1312{
Greg Claytone72dfb32012-02-24 01:59:29 +00001313 SectionSP section_sp (addr.GetSection());
1314 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001315 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001316 // 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 +00001317 if (section_sp->IsEncrypted())
1318 {
Greg Clayton57f06302012-05-25 17:05:55 +00001319 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001320 return 0;
1321 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001322 ModuleSP module_sp (section_sp->GetModule());
1323 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001324 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001325 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1326 if (objfile)
1327 {
1328 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1329 addr.GetOffset(),
1330 dst,
1331 dst_len);
1332 if (bytes_read > 0)
1333 return bytes_read;
1334 else
1335 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1336 }
Greg Claytondb598232011-01-07 01:57:07 +00001337 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001338 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001339 }
1340 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001341 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001342 }
1343 else
Greg Claytondb598232011-01-07 01:57:07 +00001344 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001345
Greg Claytondb598232011-01-07 01:57:07 +00001346 return 0;
1347}
1348
1349size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001350Target::ReadMemory (const Address& addr,
1351 bool prefer_file_cache,
1352 void *dst,
1353 size_t dst_len,
1354 Error &error,
1355 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001358
Enrico Granata9128ee22011-09-06 19:20:51 +00001359 // if we end up reading this from process memory, we will fill this
1360 // with the actual load address
1361 if (load_addr_ptr)
1362 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1363
Greg Claytondb598232011-01-07 01:57:07 +00001364 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001365
1366 addr_t load_addr = LLDB_INVALID_ADDRESS;
1367 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001368 Address resolved_addr;
1369 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001370 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001371 SectionLoadList &section_load_list = GetSectionLoadList();
1372 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001373 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001374 // No sections are loaded, so we must assume we are not running
1375 // yet and anything we are given is a file address.
1376 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1377 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001378 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001379 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001380 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001381 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001382 // we have manually loaded some sections with "target modules load ..."
1383 // or because we have have a live process that has sections loaded
1384 // through the dynamic loader
1385 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001386 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001387 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001388 }
Greg Clayton357132e2011-03-26 19:14:58 +00001389 if (!resolved_addr.IsValid())
1390 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001391
Greg Claytonc749eb82011-07-11 05:12:02 +00001392
Greg Claytondb598232011-01-07 01:57:07 +00001393 if (prefer_file_cache)
1394 {
1395 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1396 if (bytes_read > 0)
1397 return bytes_read;
1398 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001399
Johnny Chen86364b42011-09-20 23:28:55 +00001400 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001401 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001402 if (load_addr == LLDB_INVALID_ADDRESS)
1403 load_addr = resolved_addr.GetLoadAddress (this);
1404
Greg Claytondda4f7b2010-06-30 23:03:03 +00001405 if (load_addr == LLDB_INVALID_ADDRESS)
1406 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001407 ModuleSP addr_module_sp (resolved_addr.GetModule());
1408 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001409 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Jim Ingham4af59612014-12-19 19:20:44 +00001410 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Jason Molenda7e589a62011-09-20 00:26:08 +00001411 resolved_addr.GetFileAddress(),
Jim Ingham4af59612014-12-19 19:20:44 +00001412 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknonw>"));
Greg Claytondda4f7b2010-06-30 23:03:03 +00001413 else
Daniel Malead01b2952012-11-29 21:49:15 +00001414 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001415 }
1416 else
1417 {
Greg Claytondb598232011-01-07 01:57:07 +00001418 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 if (bytes_read != dst_len)
1420 {
1421 if (error.Success())
1422 {
1423 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001424 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 else
Daniel Malead01b2952012-11-29 21:49:15 +00001426 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 +00001427 }
1428 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001429 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001430 {
1431 if (load_addr_ptr)
1432 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001433 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001434 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001435 // If the address is not section offset we have an address that
1436 // doesn't resolve to any address in any currently loaded shared
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001437 // libraries and we failed to read memory so there isn't anything
Greg Claytondda4f7b2010-06-30 23:03:03 +00001438 // more we can do. If it is section offset, we might be able to
1439 // read cached memory from the object file.
1440 if (!resolved_addr.IsSectionOffset())
1441 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001444
Greg Claytonc749eb82011-07-11 05:12:02 +00001445 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001446 {
Greg Claytondb598232011-01-07 01:57:07 +00001447 // If we didn't already try and read from the object file cache, then
1448 // try it after failing to read from the process.
1449 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001450 }
1451 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452}
1453
Greg Claytond16e1e52011-07-12 17:06:17 +00001454size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001455Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1456{
1457 char buf[256];
1458 out_str.clear();
1459 addr_t curr_addr = addr.GetLoadAddress(this);
1460 Address address(addr);
1461 while (1)
1462 {
1463 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1464 if (length == 0)
1465 break;
1466 out_str.append(buf, length);
1467 // If we got "length - 1" bytes, we didn't get the whole C string, we
1468 // need to read some more characters
1469 if (length == sizeof(buf) - 1)
1470 curr_addr += length;
1471 else
1472 break;
1473 address = Address(curr_addr);
1474 }
1475 return out_str.size();
1476}
1477
1478
1479size_t
1480Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1481{
1482 size_t total_cstr_len = 0;
1483 if (dst && dst_max_len)
1484 {
1485 result_error.Clear();
1486 // NULL out everything just to be safe
1487 memset (dst, 0, dst_max_len);
1488 Error error;
1489 addr_t curr_addr = addr.GetLoadAddress(this);
1490 Address address(addr);
Jason Molendaf0340c92014-09-03 22:30:54 +00001491
1492 // We could call m_process_sp->GetMemoryCacheLineSize() but I don't
1493 // think this really needs to be tied to the memory cache subsystem's
1494 // cache line size, so leave this as a fixed constant.
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001495 const size_t cache_line_size = 512;
Jason Molendaf0340c92014-09-03 22:30:54 +00001496
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001497 size_t bytes_left = dst_max_len - 1;
1498 char *curr_dst = dst;
1499
1500 while (bytes_left > 0)
1501 {
1502 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1503 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1504 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1505
1506 if (bytes_read == 0)
1507 {
1508 result_error = error;
1509 dst[total_cstr_len] = '\0';
1510 break;
1511 }
1512 const size_t len = strlen(curr_dst);
1513
1514 total_cstr_len += len;
1515
1516 if (len < bytes_to_read)
1517 break;
1518
1519 curr_dst += bytes_read;
1520 curr_addr += bytes_read;
1521 bytes_left -= bytes_read;
1522 address = Address(curr_addr);
1523 }
1524 }
1525 else
1526 {
1527 if (dst == NULL)
1528 result_error.SetErrorString("invalid arguments");
1529 else
1530 result_error.Clear();
1531 }
1532 return total_cstr_len;
1533}
1534
1535size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001536Target::ReadScalarIntegerFromMemory (const Address& addr,
1537 bool prefer_file_cache,
1538 uint32_t byte_size,
1539 bool is_signed,
1540 Scalar &scalar,
1541 Error &error)
1542{
1543 uint64_t uval;
1544
1545 if (byte_size <= sizeof(uval))
1546 {
1547 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1548 if (bytes_read == byte_size)
1549 {
1550 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001551 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001552 if (byte_size <= 4)
1553 scalar = data.GetMaxU32 (&offset, byte_size);
1554 else
1555 scalar = data.GetMaxU64 (&offset, byte_size);
1556
1557 if (is_signed)
1558 scalar.SignExtend(byte_size * 8);
1559 return bytes_read;
1560 }
1561 }
1562 else
1563 {
1564 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1565 }
1566 return 0;
1567}
1568
1569uint64_t
1570Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1571 bool prefer_file_cache,
1572 size_t integer_byte_size,
1573 uint64_t fail_value,
1574 Error &error)
1575{
1576 Scalar scalar;
1577 if (ReadScalarIntegerFromMemory (addr,
1578 prefer_file_cache,
1579 integer_byte_size,
1580 false,
1581 scalar,
1582 error))
1583 return scalar.ULongLong(fail_value);
1584 return fail_value;
1585}
1586
1587bool
1588Target::ReadPointerFromMemory (const Address& addr,
1589 bool prefer_file_cache,
1590 Error &error,
1591 Address &pointer_addr)
1592{
1593 Scalar scalar;
1594 if (ReadScalarIntegerFromMemory (addr,
1595 prefer_file_cache,
1596 m_arch.GetAddressByteSize(),
1597 false,
1598 scalar,
1599 error))
1600 {
1601 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1602 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1603 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001604 SectionLoadList &section_load_list = GetSectionLoadList();
1605 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001606 {
1607 // No sections are loaded, so we must assume we are not running
1608 // yet and anything we are given is a file address.
1609 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1610 }
1611 else
1612 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001613 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001614 // we have manually loaded some sections with "target modules load ..."
1615 // or because we have have a live process that has sections loaded
1616 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001617 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001618 }
1619 // We weren't able to resolve the pointer value, so just return
1620 // an address with no section
1621 if (!pointer_addr.IsValid())
1622 pointer_addr.SetOffset (pointer_vm_addr);
1623 return true;
1624
1625 }
1626 }
1627 return false;
1628}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001629
1630ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001631Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001632{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001633 ModuleSP module_sp;
1634
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635 Error error;
1636
Jim Ingham4a94c912012-05-17 18:38:42 +00001637 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1638 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001639
Jim Ingham4a94c912012-05-17 18:38:42 +00001640 if (module_spec.GetUUID().IsValid())
1641 module_sp = m_images.FindFirstModule(module_spec);
1642
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001643 if (!module_sp)
1644 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001645 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1646 bool did_create_module = false;
1647
1648 // If there are image search path entries, try to use them first to acquire a suitable image.
1649 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001650 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001651 ModuleSpec transformed_spec (module_spec);
1652 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1653 {
1654 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1655 error = ModuleList::GetSharedModule (transformed_spec,
1656 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001657 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001658 &old_module_sp,
1659 &did_create_module);
1660 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001661 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001662
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001663 if (!module_sp)
1664 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001665 // If we have a UUID, we can check our global shared module list in case
1666 // we already have it. If we don't have a valid UUID, then we can't since
1667 // the path in "module_spec" will be a platform path, and we will need to
1668 // let the platform find that file. For example, we could be asking for
1669 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1670 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1671 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1672 // cache.
1673 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001674 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001675 // We have a UUID, it is OK to check the global module list...
1676 error = ModuleList::GetSharedModule (module_spec,
1677 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001678 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001679 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001680 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001681 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001682
1683 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001684 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001685 // The platform is responsible for finding and caching an appropriate
1686 // module in the shared module cache.
1687 if (m_platform_sp)
1688 {
1689 FileSpec platform_file_spec;
1690 error = m_platform_sp->GetSharedModule (module_spec,
1691 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001692 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001693 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001694 &did_create_module);
1695 }
1696 else
1697 {
1698 error.SetErrorString("no platform is currently set");
1699 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001700 }
1701 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702
Jim Ingham4a94c912012-05-17 18:38:42 +00001703 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1704 // module in the list already, and if there was, let's remove it.
1705 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001707 ObjectFile *objfile = module_sp->GetObjectFile();
1708 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001709 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001710 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001711 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001712 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1713 case ObjectFile::eTypeExecutable: /// A normal executable
1714 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1715 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1716 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1717 break;
1718 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1719 if (error_ptr)
1720 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1721 return ModuleSP();
1722 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1723 if (error_ptr)
1724 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1725 return ModuleSP();
1726 default:
1727 if (error_ptr)
1728 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1729 return ModuleSP();
1730 }
1731 // GetSharedModule is not guaranteed to find the old shared module, for instance
1732 // in the common case where you pass in the UUID, it is only going to find the one
1733 // module matching the UUID. In fact, it has no good way to know what the "old module"
1734 // relevant to this target is, since there might be many copies of a module with this file spec
1735 // in various running debug sessions, but only one of them will belong to this target.
1736 // So let's remove the UUID from the module list, and look in the target's module list.
1737 // Only do this if there is SOMETHING else in the module spec...
1738 if (!old_module_sp)
1739 {
1740 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001741 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001742 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1743 module_spec_copy.GetUUID().Clear();
1744
1745 ModuleList found_modules;
1746 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1747 if (num_found == 1)
1748 {
1749 old_module_sp = found_modules.GetModuleAtIndex(0);
1750 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001751 }
1752 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001753
1754 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1755 {
1756 m_images.ReplaceModule(old_module_sp, module_sp);
1757 Module *old_module_ptr = old_module_sp.get();
1758 old_module_sp.reset();
1759 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1760 }
1761 else
1762 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001763 }
Greg Clayton86e70cb2014-04-07 23:50:17 +00001764 else
1765 module_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001766 }
1767 }
1768 if (error_ptr)
1769 *error_ptr = error;
1770 return module_sp;
1771}
1772
1773
Greg Claytond9e416c2012-02-18 05:35:26 +00001774TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001775Target::CalculateTarget ()
1776{
Greg Claytond9e416c2012-02-18 05:35:26 +00001777 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001778}
1779
Greg Claytond9e416c2012-02-18 05:35:26 +00001780ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001781Target::CalculateProcess ()
1782{
Greg Claytond9e416c2012-02-18 05:35:26 +00001783 return ProcessSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001784}
1785
Greg Claytond9e416c2012-02-18 05:35:26 +00001786ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001787Target::CalculateThread ()
1788{
Greg Claytond9e416c2012-02-18 05:35:26 +00001789 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790}
1791
Jason Molendab57e4a12013-11-04 09:33:30 +00001792StackFrameSP
1793Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794{
Jason Molendab57e4a12013-11-04 09:33:30 +00001795 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796}
1797
1798void
Greg Clayton0603aa92010-10-04 01:05:56 +00001799Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800{
Greg Claytonc14ee322011-09-22 04:58:26 +00001801 exe_ctx.Clear();
1802 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803}
1804
1805PathMappingList &
1806Target::GetImageSearchPathList ()
1807{
1808 return m_image_search_paths;
1809}
1810
1811void
1812Target::ImageSearchPathsChanged
1813(
1814 const PathMappingList &path_list,
1815 void *baton
1816)
1817{
1818 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001819 ModuleSP exe_module_sp (target->GetExecutableModule());
1820 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001821 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001822}
1823
1824ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001825Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826{
Greg Clayton73da2442011-08-03 01:23:55 +00001827 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001828 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanan4bf80d52011-11-15 22:27:19 +00001829 {
Greg Clayton73da2442011-08-03 01:23:55 +00001830 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Claytone1cd1be2012-01-29 20:56:30 +00001831 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanan4bf80d52011-11-15 22:27:19 +00001832 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
Todd Fiala955fe6f2014-02-27 17:18:23 +00001833 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
Sean Callanan4bf80d52011-11-15 22:27:19 +00001834 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1835 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001836 return m_scratch_ast_context_ap.get();
1837}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001838
Sean Callanan686b2312011-11-16 18:20:47 +00001839ClangASTImporter *
1840Target::GetClangASTImporter()
1841{
1842 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1843
1844 if (!ast_importer)
1845 {
1846 ast_importer = new ClangASTImporter();
1847 m_ast_importer_ap.reset(ast_importer);
1848 }
1849
1850 return ast_importer;
1851}
1852
Greg Clayton99d0faf2010-11-18 23:32:35 +00001853void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001854Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00001855{
Greg Clayton6920b522012-08-22 18:39:03 +00001856 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001857}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001858
Greg Clayton99d0faf2010-11-18 23:32:35 +00001859void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001860Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001861{
Greg Clayton6920b522012-08-22 18:39:03 +00001862 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001863}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001864
Greg Claytonc859e2d2012-02-13 23:10:39 +00001865FileSpecList
1866Target::GetDefaultExecutableSearchPaths ()
1867{
Greg Clayton67cc0632012-08-22 17:17:09 +00001868 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1869 if (properties_sp)
1870 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00001871 return FileSpecList();
1872}
1873
Michael Sartaina7499c92013-07-01 19:45:50 +00001874FileSpecList
1875Target::GetDefaultDebugFileSearchPaths ()
1876{
1877 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1878 if (properties_sp)
1879 return properties_sp->GetDebugFileSearchPaths();
1880 return FileSpecList();
1881}
1882
Caroline Ticedaccaa92010-09-20 20:44:43 +00001883ArchSpec
1884Target::GetDefaultArchitecture ()
1885{
Greg Clayton67cc0632012-08-22 17:17:09 +00001886 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1887 if (properties_sp)
1888 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00001889 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00001890}
1891
1892void
Greg Clayton67cc0632012-08-22 17:17:09 +00001893Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001894{
Greg Clayton67cc0632012-08-22 17:17:09 +00001895 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1896 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00001897 {
1898 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 +00001899 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00001900 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001901}
1902
Greg Clayton0603aa92010-10-04 01:05:56 +00001903Target *
1904Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1905{
1906 // The target can either exist in the "process" of ExecutionContext, or in
1907 // the "target_sp" member of SymbolContext. This accessor helper function
1908 // will get the target from one of these locations.
1909
1910 Target *target = NULL;
1911 if (sc_ptr != NULL)
1912 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:26 +00001913 if (target == NULL && exe_ctx_ptr)
1914 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00001915 return target;
1916}
1917
Jim Ingham1624a2d2014-05-05 02:26:40 +00001918ExpressionResults
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001919Target::EvaluateExpression
1920(
1921 const char *expr_cstr,
Jason Molendab57e4a12013-11-04 09:33:30 +00001922 StackFrame *frame,
Enrico Granata3372f582012-07-16 23:10:35 +00001923 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad4439aa2012-09-05 20:41:26 +00001924 const EvaluateExpressionOptions& options
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001925)
1926{
Enrico Granata97fca502012-09-18 17:43:16 +00001927 result_valobj_sp.reset();
1928
Jim Ingham8646d3c2014-05-05 02:47:44 +00001929 ExpressionResults execution_results = eExpressionSetupError;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001930
Greg Claytond1767f02011-12-08 02:13:16 +00001931 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1932 return execution_results;
1933
Jim Ingham6026ca32011-05-12 02:06:14 +00001934 // We shouldn't run stop hooks in expressions.
1935 // Be sure to reset this if you return anywhere within this function.
1936 bool old_suppress_value = m_suppress_stop_hooks;
1937 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001938
1939 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001940
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001941 if (frame)
1942 {
1943 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001944 }
1945 else if (m_process_sp)
1946 {
1947 m_process_sp->CalculateExecutionContext(exe_ctx);
1948 }
1949 else
1950 {
1951 CalculateExecutionContext(exe_ctx);
1952 }
1953
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001954 // Make sure we aren't just trying to see the value of a persistent
1955 // variable (something like "$0")
1956 lldb::ClangExpressionVariableSP persistent_var_sp;
1957 // Only check for persistent variables the expression starts with a '$'
1958 if (expr_cstr[0] == '$')
Zachary Turner32abc6e2015-03-03 19:23:09 +00001959 persistent_var_sp = m_persistent_variables->GetVariable (expr_cstr);
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001960
1961 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001962 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001963 result_valobj_sp = persistent_var_sp->GetValueObject ();
Jim Ingham8646d3c2014-05-05 02:47:44 +00001964 execution_results = eExpressionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001965 }
1966 else
1967 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001968 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00001969 Error error;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001970 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001971 options,
1972 expr_cstr,
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001973 prefix,
1974 result_valobj_sp,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001975 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001976 }
Jim Ingham6026ca32011-05-12 02:06:14 +00001977
1978 m_suppress_stop_hooks = old_suppress_value;
1979
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001980 return execution_results;
1981}
1982
Zachary Turner32abc6e2015-03-03 19:23:09 +00001983ClangPersistentVariables &
1984Target::GetPersistentVariables()
1985{
1986 return *m_persistent_variables;
1987}
1988
Greg Claytonf3ef3d22011-05-22 22:46:53 +00001989lldb::addr_t
1990Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1991{
1992 addr_t code_addr = load_addr;
1993 switch (m_arch.GetMachine())
1994 {
1995 case llvm::Triple::arm:
1996 case llvm::Triple::thumb:
1997 switch (addr_class)
1998 {
1999 case eAddressClassData:
2000 case eAddressClassDebug:
2001 return LLDB_INVALID_ADDRESS;
2002
2003 case eAddressClassUnknown:
2004 case eAddressClassInvalid:
2005 case eAddressClassCode:
2006 case eAddressClassCodeAlternateISA:
2007 case eAddressClassRuntime:
2008 // Check if bit zero it no set?
2009 if ((code_addr & 1ull) == 0)
2010 {
2011 // Bit zero isn't set, check if the address is a multiple of 2?
2012 if (code_addr & 2ull)
2013 {
2014 // The address is a multiple of 2 so it must be thumb, set bit zero
2015 code_addr |= 1ull;
2016 }
2017 else if (addr_class == eAddressClassCodeAlternateISA)
2018 {
2019 // We checked the address and the address claims to be the alternate ISA
2020 // which means thumb, so set bit zero.
2021 code_addr |= 1ull;
2022 }
2023 }
2024 break;
2025 }
2026 break;
2027
2028 default:
2029 break;
2030 }
2031 return code_addr;
2032}
2033
2034lldb::addr_t
2035Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2036{
2037 addr_t opcode_addr = load_addr;
2038 switch (m_arch.GetMachine())
2039 {
2040 case llvm::Triple::arm:
2041 case llvm::Triple::thumb:
2042 switch (addr_class)
2043 {
2044 case eAddressClassData:
2045 case eAddressClassDebug:
2046 return LLDB_INVALID_ADDRESS;
2047
2048 case eAddressClassInvalid:
2049 case eAddressClassUnknown:
2050 case eAddressClassCode:
2051 case eAddressClassCodeAlternateISA:
2052 case eAddressClassRuntime:
2053 opcode_addr &= ~(1ull);
2054 break;
2055 }
2056 break;
2057
2058 default:
2059 break;
2060 }
2061 return opcode_addr;
2062}
2063
Greg Clayton9585fbf2013-03-19 00:20:55 +00002064SourceManager &
2065Target::GetSourceManager ()
2066{
2067 if (m_source_manager_ap.get() == NULL)
2068 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
2069 return *m_source_manager_ap;
2070}
2071
Sean Callanan9998acd2014-12-05 01:21:59 +00002072ClangModulesDeclVendor *
2073Target::GetClangModulesDeclVendor ()
2074{
2075 static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
2076
2077 {
2078 Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
2079
2080 if (!m_clang_modules_decl_vendor_ap)
2081 {
2082 m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
2083 }
2084 }
2085
2086 return m_clang_modules_decl_vendor_ap.get();
2087}
Greg Clayton9585fbf2013-03-19 00:20:55 +00002088
Greg Clayton44d93782014-01-27 23:43:24 +00002089Target::StopHookSP
2090Target::CreateStopHook ()
Jim Ingham9575d842011-03-11 03:53:59 +00002091{
2092 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton44d93782014-01-27 23:43:24 +00002093 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2094 m_stop_hooks[new_uid] = stop_hook_sp;
2095 return stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00002096}
2097
2098bool
2099Target::RemoveStopHookByID (lldb::user_id_t user_id)
2100{
2101 size_t num_removed;
2102 num_removed = m_stop_hooks.erase (user_id);
2103 if (num_removed == 0)
2104 return false;
2105 else
2106 return true;
2107}
2108
2109void
2110Target::RemoveAllStopHooks ()
2111{
2112 m_stop_hooks.clear();
2113}
2114
2115Target::StopHookSP
2116Target::GetStopHookByID (lldb::user_id_t user_id)
2117{
2118 StopHookSP found_hook;
2119
2120 StopHookCollection::iterator specified_hook_iter;
2121 specified_hook_iter = m_stop_hooks.find (user_id);
2122 if (specified_hook_iter != m_stop_hooks.end())
2123 found_hook = (*specified_hook_iter).second;
2124 return found_hook;
2125}
2126
2127bool
2128Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2129{
2130 StopHookCollection::iterator specified_hook_iter;
2131 specified_hook_iter = m_stop_hooks.find (user_id);
2132 if (specified_hook_iter == m_stop_hooks.end())
2133 return false;
2134
2135 (*specified_hook_iter).second->SetIsActive (active_state);
2136 return true;
2137}
2138
2139void
2140Target::SetAllStopHooksActiveState (bool active_state)
2141{
2142 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2143 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2144 {
2145 (*pos).second->SetIsActive (active_state);
2146 }
2147}
2148
2149void
2150Target::RunStopHooks ()
2151{
Jim Ingham6026ca32011-05-12 02:06:14 +00002152 if (m_suppress_stop_hooks)
2153 return;
2154
Jim Ingham9575d842011-03-11 03:53:59 +00002155 if (!m_process_sp)
2156 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002157
2158 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2159 // since in that case we do not want to run the stop-hooks
2160 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2161 return;
2162
Jim Ingham9575d842011-03-11 03:53:59 +00002163 if (m_stop_hooks.empty())
2164 return;
2165
2166 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2167
2168 // If there aren't any active stop hooks, don't bother either:
2169 bool any_active_hooks = false;
2170 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2171 {
2172 if ((*pos).second->IsActive())
2173 {
2174 any_active_hooks = true;
2175 break;
2176 }
2177 }
2178 if (!any_active_hooks)
2179 return;
2180
2181 CommandReturnObject result;
2182
2183 std::vector<ExecutionContext> exc_ctx_with_reasons;
2184 std::vector<SymbolContext> sym_ctx_with_reasons;
2185
2186 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2187 size_t num_threads = cur_threadlist.GetSize();
2188 for (size_t i = 0; i < num_threads; i++)
2189 {
2190 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2191 if (cur_thread_sp->ThreadStoppedForAReason())
2192 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002193 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002194 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2195 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2196 }
2197 }
2198
2199 // If no threads stopped for a reason, don't run the stop-hooks.
2200 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2201 if (num_exe_ctx == 0)
2202 return;
2203
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002204 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2205 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002206
2207 bool keep_going = true;
2208 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:27 +00002209 bool print_hook_header;
2210 bool print_thread_header;
2211
2212 if (num_exe_ctx == 1)
2213 print_thread_header = false;
2214 else
2215 print_thread_header = true;
2216
2217 if (m_stop_hooks.size() == 1)
2218 print_hook_header = false;
2219 else
2220 print_hook_header = true;
2221
Jim Ingham9575d842011-03-11 03:53:59 +00002222 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2223 {
2224 // result.Clear();
2225 StopHookSP cur_hook_sp = (*pos).second;
2226 if (!cur_hook_sp->IsActive())
2227 continue;
2228
2229 bool any_thread_matched = false;
2230 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2231 {
2232 if ((cur_hook_sp->GetSpecifier () == NULL
2233 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2234 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Ingham3d902922012-03-07 22:03:04 +00002235 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002236 {
2237 if (!hooks_ran)
2238 {
Jim Ingham9575d842011-03-11 03:53:59 +00002239 hooks_ran = true;
2240 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002241 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002242 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002243 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2244 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2245 NULL);
2246 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002247 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002248 else
Daniel Malead01b2952012-11-29 21:49:15 +00002249 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002250 any_thread_matched = true;
2251 }
2252
Jim Ingham381e25b2011-03-22 01:47:27 +00002253 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002254 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham26c7bf92014-10-11 00:38:27 +00002255
2256 CommandInterpreterRunOptions options;
2257 options.SetStopOnContinue (true);
2258 options.SetStopOnError (true);
2259 options.SetEchoCommands (false);
2260 options.SetPrintResults (true);
2261 options.SetAddToHistory (false);
2262
2263 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
2264 &exc_ctx_with_reasons[i],
2265 options,
Greg Clayton32e0a752011-03-30 18:16:51 +00002266 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002267
2268 // If the command started the target going again, we should bag out of
2269 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002270 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2271 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002272 {
Daniel Malead01b2952012-11-29 21:49:15 +00002273 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002274 keep_going = false;
2275 }
2276 }
2277 }
2278 }
Jason Molenda879cf772011-09-23 00:42:55 +00002279
Caroline Tice969ed3d2011-05-02 20:41:46 +00002280 result.GetImmediateOutputStream()->Flush();
2281 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002282}
2283
Greg Claytonfbb76342013-11-20 21:07:01 +00002284const TargetPropertiesSP &
2285Target::GetGlobalProperties()
2286{
2287 static TargetPropertiesSP g_settings_sp;
2288 if (!g_settings_sp)
2289 {
2290 g_settings_sp.reset (new TargetProperties (NULL));
2291 }
2292 return g_settings_sp;
2293}
2294
2295Error
2296Target::Install (ProcessLaunchInfo *launch_info)
2297{
2298 Error error;
2299 PlatformSP platform_sp (GetPlatform());
2300 if (platform_sp)
2301 {
2302 if (platform_sp->IsRemote())
2303 {
2304 if (platform_sp->IsConnected())
2305 {
2306 // Install all files that have an install path, and always install the
2307 // main executable when connected to a remote platform
2308 const ModuleList& modules = GetImages();
2309 const size_t num_images = modules.GetSize();
2310 for (size_t idx = 0; idx < num_images; ++idx)
2311 {
2312 const bool is_main_executable = idx == 0;
2313 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2314 if (module_sp)
2315 {
2316 FileSpec local_file (module_sp->GetFileSpec());
2317 if (local_file)
2318 {
2319 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2320 if (!remote_file)
2321 {
2322 if (is_main_executable) // TODO: add setting for always installing main executable???
2323 {
2324 // Always install the main executable
2325 remote_file.GetDirectory() = platform_sp->GetWorkingDirectory();
2326 remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename();
2327 }
2328 }
2329 if (remote_file)
2330 {
2331 error = platform_sp->Install(local_file, remote_file);
2332 if (error.Success())
2333 {
2334 module_sp->SetPlatformFileSpec(remote_file);
2335 if (is_main_executable)
2336 {
2337 if (launch_info)
2338 launch_info->SetExecutableFile(remote_file, false);
2339 }
2340 }
2341 else
2342 break;
2343 }
2344 }
2345 }
2346 }
2347 }
2348 }
2349 }
2350 return error;
2351}
Greg Clayton7b242382011-07-08 00:48:09 +00002352
Greg Claytond5944cd2013-12-06 01:12:00 +00002353bool
2354Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2355{
2356 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2357}
2358
2359bool
Matthew Gardinerc928de32014-10-22 07:22:56 +00002360Target::ResolveFileAddress (lldb::addr_t file_addr, Address &resolved_addr)
2361{
2362 return m_images.ResolveFileAddress(file_addr, resolved_addr);
2363}
2364
2365bool
Greg Claytond5944cd2013-12-06 01:12:00 +00002366Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2367{
2368 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2369 if (old_section_load_addr != new_section_load_addr)
2370 {
2371 uint32_t stop_id = 0;
2372 ProcessSP process_sp(GetProcessSP());
2373 if (process_sp)
2374 stop_id = process_sp->GetStopID();
2375 else
2376 stop_id = m_section_load_history.GetLastStopID();
2377 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2378 return true; // Return true if the section load address was changed...
2379 }
2380 return false; // Return false to indicate nothing changed
2381
2382}
2383
Greg Clayton8012cad2014-11-17 19:39:20 +00002384size_t
2385Target::UnloadModuleSections (const ModuleList &module_list)
2386{
2387 size_t section_unload_count = 0;
2388 size_t num_modules = module_list.GetSize();
2389 for (size_t i=0; i<num_modules; ++i)
2390 {
2391 section_unload_count += UnloadModuleSections (module_list.GetModuleAtIndex(i));
2392 }
2393 return section_unload_count;
2394}
2395
2396size_t
2397Target::UnloadModuleSections (const lldb::ModuleSP &module_sp)
2398{
2399 uint32_t stop_id = 0;
2400 ProcessSP process_sp(GetProcessSP());
2401 if (process_sp)
2402 stop_id = process_sp->GetStopID();
2403 else
2404 stop_id = m_section_load_history.GetLastStopID();
2405 SectionList *sections = module_sp->GetSectionList();
2406 size_t section_unload_count = 0;
2407 if (sections)
2408 {
2409 const uint32_t num_sections = sections->GetNumSections(0);
2410 for (uint32_t i = 0; i < num_sections; ++i)
2411 {
2412 section_unload_count += m_section_load_history.SetSectionUnloaded(stop_id, sections->GetSectionAtIndex(i));
2413 }
2414 }
2415 return section_unload_count;
2416}
2417
Greg Claytond5944cd2013-12-06 01:12:00 +00002418bool
2419Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2420{
2421 uint32_t stop_id = 0;
2422 ProcessSP process_sp(GetProcessSP());
2423 if (process_sp)
2424 stop_id = process_sp->GetStopID();
2425 else
2426 stop_id = m_section_load_history.GetLastStopID();
2427 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2428}
2429
2430bool
2431Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2432{
2433 uint32_t stop_id = 0;
2434 ProcessSP process_sp(GetProcessSP());
2435 if (process_sp)
2436 stop_id = process_sp->GetStopID();
2437 else
2438 stop_id = m_section_load_history.GetLastStopID();
2439 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2440}
2441
2442void
2443Target::ClearAllLoadedSections ()
2444{
2445 m_section_load_history.Clear();
2446}
2447
Greg Claytonb09c5382013-12-13 17:20:18 +00002448
2449Error
Greg Clayton8012cad2014-11-17 19:39:20 +00002450Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
Greg Claytonb09c5382013-12-13 17:20:18 +00002451{
2452 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00002453 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
2454
2455 if (log)
2456 log->Printf ("Target::%s() called for %s", __FUNCTION__, launch_info.GetExecutableFile().GetPath().c_str ());
2457
Greg Claytonb09c5382013-12-13 17:20:18 +00002458 StateType state = eStateInvalid;
2459
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002460 // Scope to temporarily get the process state in case someone has manually
2461 // remotely connected already to a process and we can skip the platform
2462 // launching.
2463 {
2464 ProcessSP process_sp (GetProcessSP());
2465
2466 if (process_sp)
Todd Fialaac33cc92014-10-09 01:02:08 +00002467 {
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002468 state = process_sp->GetState();
Todd Fialaac33cc92014-10-09 01:02:08 +00002469 if (log)
2470 log->Printf ("Target::%s the process exists, and its current state is %s", __FUNCTION__, StateAsCString (state));
2471 }
2472 else
2473 {
2474 if (log)
2475 log->Printf ("Target::%s the process instance doesn't currently exist.", __FUNCTION__);
2476 }
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002477 }
2478
Greg Claytonb09c5382013-12-13 17:20:18 +00002479 launch_info.GetFlags().Set (eLaunchFlagDebug);
2480
2481 // Get the value of synchronous execution here. If you wait till after you have started to
2482 // run, then you could have hit a breakpoint, whose command might switch the value, and
2483 // then you'll pick up that incorrect value.
2484 Debugger &debugger = GetDebugger();
2485 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2486
2487 PlatformSP platform_sp (GetPlatform());
2488
2489 // Finalize the file actions, and if none were given, default to opening
2490 // up a pseudo terminal
2491 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
Todd Fiala75f47c32014-10-11 21:42:09 +00002492 if (log)
2493 log->Printf ("Target::%s have platform=%s, platform_sp->IsHost()=%s, default_to_use_pty=%s",
2494 __FUNCTION__,
2495 platform_sp ? "true" : "false",
2496 platform_sp ? (platform_sp->IsHost () ? "true" : "false") : "n/a",
2497 default_to_use_pty ? "true" : "false");
2498
Greg Claytonb09c5382013-12-13 17:20:18 +00002499 launch_info.FinalizeFileActions (this, default_to_use_pty);
2500
2501 if (state == eStateConnected)
2502 {
2503 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2504 {
2505 error.SetErrorString("can't launch in tty when launching through a remote connection");
2506 return error;
2507 }
2508 }
2509
2510 if (!launch_info.GetArchitecture().IsValid())
2511 launch_info.GetArchitecture() = GetArchitecture();
Todd Fiala015d8182014-07-22 23:41:36 +00002512
2513 // 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 +00002514 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
2515 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002516 if (log)
2517 log->Printf ("Target::%s asking the platform to debug the process", __FUNCTION__);
2518
Greg Claytonb09c5382013-12-13 17:20:18 +00002519 m_process_sp = GetPlatform()->DebugProcess (launch_info,
2520 debugger,
2521 this,
Greg Claytonb09c5382013-12-13 17:20:18 +00002522 error);
2523 }
2524 else
2525 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002526 if (log)
2527 log->Printf ("Target::%s the platform doesn't know how to debug a process, getting a process plugin to do this for us.", __FUNCTION__);
2528
Greg Claytonb09c5382013-12-13 17:20:18 +00002529 if (state == eStateConnected)
2530 {
2531 assert(m_process_sp);
2532 }
2533 else
2534 {
Todd Fiala015d8182014-07-22 23:41:36 +00002535 // Use a Process plugin to construct the process.
Greg Claytonb09c5382013-12-13 17:20:18 +00002536 const char *plugin_name = launch_info.GetProcessPluginName();
Greg Clayton8012cad2014-11-17 19:39:20 +00002537 CreateProcess (launch_info.GetListenerForProcess(debugger), plugin_name, NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002538 }
Todd Fiala015d8182014-07-22 23:41:36 +00002539
2540 // Since we didn't have a platform launch the process, launch it here.
Greg Claytonb09c5382013-12-13 17:20:18 +00002541 if (m_process_sp)
2542 error = m_process_sp->Launch (launch_info);
2543 }
2544
2545 if (!m_process_sp)
2546 {
2547 if (error.Success())
2548 error.SetErrorString("failed to launch or debug process");
2549 return error;
2550 }
2551
2552 if (error.Success())
2553 {
2554 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
2555 {
Greg Clayton44d93782014-01-27 23:43:24 +00002556 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
Todd Fialaac33cc92014-10-09 01:02:08 +00002557
Greg Claytondc6224e2014-10-21 01:00:42 +00002558 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get(), NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002559
2560 if (state == eStateStopped)
2561 {
Greg Clayton44d93782014-01-27 23:43:24 +00002562 if (!synchronous_execution)
2563 m_process_sp->RestoreProcessEvents ();
2564
2565 error = m_process_sp->PrivateResume();
Todd Fialaa3b89e22014-08-12 14:33:19 +00002566
Greg Claytonb09c5382013-12-13 17:20:18 +00002567 if (error.Success())
2568 {
Todd Fialaa3b89e22014-08-12 14:33:19 +00002569 // there is a race condition where this thread will return up the call stack to the main command
2570 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
2571 // a chance to call PushProcessIOHandler()
2572 m_process_sp->SyncIOHandler(2000);
2573
Greg Claytonb09c5382013-12-13 17:20:18 +00002574 if (synchronous_execution)
2575 {
Greg Claytondc6224e2014-10-21 01:00:42 +00002576 state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get(), stream);
Greg Claytonb09c5382013-12-13 17:20:18 +00002577 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2578 if (!StateIsStoppedState(state, must_be_alive))
2579 {
Greg Clayton44d93782014-01-27 23:43:24 +00002580 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
Greg Claytonb09c5382013-12-13 17:20:18 +00002581 }
2582 }
2583 }
2584 else
2585 {
Greg Clayton44d93782014-01-27 23:43:24 +00002586 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002587 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002588 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002589 }
2590 }
Greg Clayton40286e02014-04-30 20:29:09 +00002591 else if (state == eStateExited)
2592 {
Zachary Turner10687b02014-10-20 17:46:43 +00002593 bool with_shell = !!launch_info.GetShell();
Greg Clayton40286e02014-04-30 20:29:09 +00002594 const int exit_status = m_process_sp->GetExitStatus();
2595 const char *exit_desc = m_process_sp->GetExitDescription();
2596#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'."
2597 if (exit_desc && exit_desc[0])
2598 {
2599 if (with_shell)
2600 error.SetErrorStringWithFormat ("process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, exit_status, exit_desc);
2601 else
2602 error.SetErrorStringWithFormat ("process exited with status %i (%s)", exit_status, exit_desc);
2603 }
2604 else
2605 {
2606 if (with_shell)
2607 error.SetErrorStringWithFormat ("process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
2608 else
2609 error.SetErrorStringWithFormat ("process exited with status %i", exit_status);
2610 }
2611 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002612 else
2613 {
2614 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2615 }
2616 }
Greg Clayton44d93782014-01-27 23:43:24 +00002617 m_process_sp->RestoreProcessEvents ();
Greg Claytonb09c5382013-12-13 17:20:18 +00002618 }
2619 else
2620 {
Greg Clayton44d93782014-01-27 23:43:24 +00002621 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002622 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002623 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002624 }
2625 return error;
2626}
Oleksiy Vyalov37386142015-02-10 22:49:57 +00002627
2628Error
2629Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
2630{
2631 auto state = eStateInvalid;
2632 auto process_sp = GetProcessSP ();
2633 if (process_sp)
2634 {
2635 state = process_sp->GetState ();
2636 if (process_sp->IsAlive () && state != eStateConnected)
2637 {
2638 if (state == eStateAttaching)
2639 return Error ("process attach is in progress");
2640 return Error ("a process is already being debugged");
2641 }
2642 }
2643
2644 ListenerSP hijack_listener_sp (new Listener ("lldb.Target.Attach.attach.hijack"));
2645 attach_info.SetHijackListener (hijack_listener_sp);
2646
2647 const ModuleSP old_exec_module_sp = GetExecutableModule ();
2648
2649 // If no process info was specified, then use the target executable
2650 // name as the process to attach to by default
2651 if (!attach_info.ProcessInfoSpecified ())
2652 {
2653 if (old_exec_module_sp)
2654 attach_info.GetExecutableFile ().GetFilename () = old_exec_module_sp->GetPlatformFileSpec ().GetFilename ();
2655
2656 if (!attach_info.ProcessInfoSpecified ())
2657 {
2658 return Error ("no process specified, create a target with a file, or specify the --pid or --name");
2659 }
2660 }
2661
2662 const auto platform_sp = GetDebugger ().GetPlatformList ().GetSelectedPlatform ();
2663
2664 Error error;
2665 if (state != eStateConnected && platform_sp != nullptr && platform_sp->CanDebugProcess ())
2666 {
2667 SetPlatform (platform_sp);
2668 process_sp = platform_sp->Attach (attach_info, GetDebugger (), this, error);
2669 }
2670 else
2671 {
2672 if (state != eStateConnected)
2673 {
2674 const char *plugin_name = attach_info.GetProcessPluginName ();
2675 process_sp = CreateProcess (attach_info.GetListenerForProcess (GetDebugger ()), plugin_name, nullptr);
2676 if (process_sp == nullptr)
2677 {
2678 error.SetErrorStringWithFormat ("failed to create process using plugin %s", (plugin_name) ? plugin_name : "null");
2679 return error;
2680 }
2681 }
2682 process_sp->HijackProcessEvents (hijack_listener_sp.get ());
2683 error = process_sp->Attach (attach_info);
2684 }
2685
2686 if (error.Success () && process_sp)
2687 {
2688 state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener ().get (), stream);
2689 process_sp->RestoreProcessEvents ();
2690
2691 if (state != eStateStopped)
2692 {
2693 const char *exit_desc = process_sp->GetExitDescription ();
2694 if (exit_desc)
2695 error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);
2696 else
2697 error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");
2698 process_sp->Destroy ();
2699 }
2700 }
2701 return error;
2702}
2703
Jim Ingham9575d842011-03-11 03:53:59 +00002704//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00002705// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00002706//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00002707Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2708 UserID (uid),
2709 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00002710 m_commands (),
2711 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00002712 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002713 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00002714{
2715}
2716
2717Target::StopHook::StopHook (const StopHook &rhs) :
2718 UserID (rhs.GetID()),
2719 m_target_sp (rhs.m_target_sp),
2720 m_commands (rhs.m_commands),
2721 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00002722 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002723 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00002724{
2725 if (rhs.m_thread_spec_ap.get() != NULL)
2726 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2727}
2728
2729
2730Target::StopHook::~StopHook ()
2731{
2732}
2733
2734void
Zachary Turner32abc6e2015-03-03 19:23:09 +00002735Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier)
2736{
2737 m_specifier_sp.reset(specifier);
2738}
2739
2740void
Jim Ingham9575d842011-03-11 03:53:59 +00002741Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2742{
2743 m_thread_spec_ap.reset (specifier);
2744}
2745
2746
2747void
2748Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2749{
2750 int indent_level = s->GetIndentLevel();
2751
2752 s->SetIndentLevel(indent_level + 2);
2753
Daniel Malead01b2952012-11-29 21:49:15 +00002754 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002755 if (m_active)
2756 s->Indent ("State: enabled\n");
2757 else
2758 s->Indent ("State: disabled\n");
2759
2760 if (m_specifier_sp)
2761 {
2762 s->Indent();
2763 s->PutCString ("Specifier:\n");
2764 s->SetIndentLevel (indent_level + 4);
2765 m_specifier_sp->GetDescription (s, level);
2766 s->SetIndentLevel (indent_level + 2);
2767 }
2768
2769 if (m_thread_spec_ap.get() != NULL)
2770 {
2771 StreamString tmp;
2772 s->Indent("Thread:\n");
2773 m_thread_spec_ap->GetDescription (&tmp, level);
2774 s->SetIndentLevel (indent_level + 4);
2775 s->Indent (tmp.GetData());
2776 s->PutCString ("\n");
2777 s->SetIndentLevel (indent_level + 2);
2778 }
2779
2780 s->Indent ("Commands: \n");
2781 s->SetIndentLevel (indent_level + 4);
2782 uint32_t num_commands = m_commands.GetSize();
2783 for (uint32_t i = 0; i < num_commands; i++)
2784 {
2785 s->Indent(m_commands.GetStringAtIndex(i));
2786 s->PutCString ("\n");
2787 }
2788 s->SetIndentLevel (indent_level);
2789}
2790
Greg Clayton67cc0632012-08-22 17:17:09 +00002791//--------------------------------------------------------------
2792// class TargetProperties
2793//--------------------------------------------------------------
2794
2795OptionEnumValueElement
2796lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002797{
Greg Clayton67cc0632012-08-22 17:17:09 +00002798 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2799 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2800 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2801 { 0, NULL, NULL }
2802};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002803
Greg Clayton1f746072012-08-29 21:13:06 +00002804static OptionEnumValueElement
2805g_inline_breakpoint_enums[] =
2806{
2807 { 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."},
2808 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2809 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2810 { 0, NULL, NULL }
2811};
2812
Jim Ingham0f063ba2013-03-02 00:26:47 +00002813typedef enum x86DisassemblyFlavor
2814{
2815 eX86DisFlavorDefault,
2816 eX86DisFlavorIntel,
2817 eX86DisFlavorATT
2818} x86DisassemblyFlavor;
2819
2820static OptionEnumValueElement
2821g_x86_dis_flavor_value_types[] =
2822{
2823 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2824 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2825 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2826 { 0, NULL, NULL }
2827};
2828
Enrico Granata397ddd52013-05-21 20:13:34 +00002829static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00002830g_hex_immediate_style_values[] =
2831{
2832 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
2833 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
2834 { 0, NULL, NULL }
2835};
2836
2837static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00002838g_load_script_from_sym_file_values[] =
2839{
2840 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
2841 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
2842 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
2843 { 0, NULL, NULL }
2844};
2845
Greg Claytonfd814c52013-08-13 01:42:25 +00002846
2847static OptionEnumValueElement
2848g_memory_module_load_level_values[] =
2849{
Greg Clayton86eac942013-08-13 21:32:34 +00002850 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00002851 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
2852 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
2853 { 0, NULL, NULL }
2854};
2855
Greg Clayton67cc0632012-08-22 17:17:09 +00002856static PropertyDefinition
2857g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002858{
Greg Clayton67cc0632012-08-22 17:17:09 +00002859 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2860 { "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 +00002861 { "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 +00002862 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2863 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2864 { "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 "
2865 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2866 "some part (starting at the root) of the path to the file when it was built, "
2867 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2868 "Each element of the array is checked in order and the first one that results in a match wins." },
2869 { "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 +00002870 { "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 +00002871 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2872 { "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 +00002873 { "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 +00002874 { "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 +00002875 { "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." },
2876 { "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 +00002877 { "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." },
2878 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2879 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2880 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2881 { "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 +00002882 { "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 +00002883 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2884 { "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 +00002885 { "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 +00002886 "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. "
2887 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2888 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
Todd Fialaad6eee62014-09-24 19:59:13 +00002889 "Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers "
2890 "and find that setting breakpoints is slow, then you can change this setting to headers. "
2891 "This setting allows you to control exactly which strategy is used when setting "
Greg Clayton1f746072012-08-29 21:13:06 +00002892 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00002893 // 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.
2894 { "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 +00002895 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
2896 { "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 +00002897 { "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 +00002898 { "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 +00002899 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
2900 "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. "
2901 "This setting helps users control how much information gets loaded when loading modules from memory."
2902 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
2903 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
2904 "'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 +00002905 { "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 +00002906 { "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 +00002907 { "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 +00002908 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2909};
Enrico Granata560558e2015-02-11 02:35:39 +00002910
Greg Clayton67cc0632012-08-22 17:17:09 +00002911enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00002912{
Greg Clayton67cc0632012-08-22 17:17:09 +00002913 ePropertyDefaultArch,
2914 ePropertyExprPrefix,
2915 ePropertyPreferDynamic,
2916 ePropertyEnableSynthetic,
2917 ePropertySkipPrologue,
2918 ePropertySourceMap,
2919 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00002920 ePropertyDebugFileSearchPaths,
Greg Clayton67cc0632012-08-22 17:17:09 +00002921 ePropertyMaxChildrenCount,
2922 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00002923 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00002924 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00002925 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00002926 ePropertyRunArgs,
2927 ePropertyEnvVars,
2928 ePropertyInheritEnv,
2929 ePropertyInputPath,
2930 ePropertyOutputPath,
2931 ePropertyErrorPath,
Jim Ingham106d0282014-06-25 02:32:56 +00002932 ePropertyDetachOnError,
Greg Clayton67cc0632012-08-22 17:17:09 +00002933 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00002934 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002935 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00002936 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00002937 ePropertyUseHexImmediates,
2938 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00002939 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00002940 ePropertyLoadScriptFromSymbolFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00002941 ePropertyMemoryModuleLoadLevel,
Jason Molendaa4bea722014-02-14 05:06:49 +00002942 ePropertyDisplayExpressionsInCrashlogs,
Enrico Granata560558e2015-02-11 02:35:39 +00002943 ePropertyTrapHandlerNames,
2944 ePropertyDisplayRuntimeSupportValues
Greg Clayton67cc0632012-08-22 17:17:09 +00002945};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002946
Caroline Ticedaccaa92010-09-20 20:44:43 +00002947
Greg Clayton67cc0632012-08-22 17:17:09 +00002948class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00002949{
Greg Clayton67cc0632012-08-22 17:17:09 +00002950public:
2951 TargetOptionValueProperties (const ConstString &name) :
2952 OptionValueProperties (name),
2953 m_target (NULL),
2954 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002955 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00002956 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002957
Greg Clayton67cc0632012-08-22 17:17:09 +00002958 // This constructor is used when creating TargetOptionValueProperties when it
2959 // is part of a new lldb_private::Target instance. It will copy all current
2960 // global property values as needed
2961 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2962 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2963 m_target (target),
2964 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002965 {
Greg Clayton67cc0632012-08-22 17:17:09 +00002966 }
2967
2968 virtual const Property *
2969 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2970 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002971 // When getting the value for a key from the target options, we will always
Greg Clayton67cc0632012-08-22 17:17:09 +00002972 // try and grab the setting from the current target if there is one. Else we just
2973 // use the one from this instance.
2974 if (idx == ePropertyEnvVars)
2975 GetHostEnvironmentIfNeeded ();
2976
2977 if (exe_ctx)
2978 {
2979 Target *target = exe_ctx->GetTargetPtr();
2980 if (target)
2981 {
2982 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2983 if (this != target_properties)
2984 return target_properties->ProtectedGetPropertyAtIndex (idx);
2985 }
2986 }
2987 return ProtectedGetPropertyAtIndex (idx);
2988 }
Enrico Granata84a53df2013-05-20 22:29:23 +00002989
2990 lldb::TargetSP
2991 GetTargetSP ()
2992 {
2993 return m_target->shared_from_this();
2994 }
2995
Greg Clayton67cc0632012-08-22 17:17:09 +00002996protected:
2997
2998 void
2999 GetHostEnvironmentIfNeeded () const
3000 {
3001 if (!m_got_host_env)
3002 {
3003 if (m_target)
3004 {
3005 m_got_host_env = true;
3006 const uint32_t idx = ePropertyInheritEnv;
3007 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
3008 {
3009 PlatformSP platform_sp (m_target->GetPlatform());
3010 if (platform_sp)
3011 {
3012 StringList env;
3013 if (platform_sp->GetEnvironment(env))
3014 {
3015 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
3016 if (env_dict)
3017 {
3018 const bool can_replace = false;
3019 const size_t envc = env.GetSize();
3020 for (size_t idx=0; idx<envc; idx++)
3021 {
3022 const char *env_entry = env.GetStringAtIndex (idx);
3023 if (env_entry)
3024 {
3025 const char *equal_pos = ::strchr(env_entry, '=');
3026 ConstString key;
3027 // It is ok to have environment variables with no values
3028 const char *value = NULL;
3029 if (equal_pos)
3030 {
3031 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
3032 if (equal_pos[1])
3033 value = equal_pos + 1;
3034 }
3035 else
3036 {
3037 key.SetCString(env_entry);
3038 }
3039 // Don't allow existing keys to be replaced with ones we get from the platform environment
3040 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
3041 }
3042 }
3043 }
3044 }
3045 }
3046 }
3047 }
3048 }
3049 }
3050 Target *m_target;
3051 mutable bool m_got_host_env;
3052};
3053
Greg Claytonfbb76342013-11-20 21:07:01 +00003054//----------------------------------------------------------------------
3055// TargetProperties
3056//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00003057TargetProperties::TargetProperties (Target *target) :
Ilia K8f37ca52015-02-13 14:31:06 +00003058 Properties (),
3059 m_launch_info ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003060{
3061 if (target)
3062 {
3063 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Ilia K8f37ca52015-02-13 14:31:06 +00003064
3065 // Set callbacks to update launch_info whenever "settins set" updated any of these properties
3066 m_collection_sp->SetValueChangedCallback(ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this);
3067 m_collection_sp->SetValueChangedCallback(ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this);
3068 m_collection_sp->SetValueChangedCallback(ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this);
3069 m_collection_sp->SetValueChangedCallback(ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, this);
3070 m_collection_sp->SetValueChangedCallback(ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, this);
3071 m_collection_sp->SetValueChangedCallback(ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, this);
3072 m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, TargetProperties::DetachOnErrorValueChangedCallback, this);
3073 m_collection_sp->SetValueChangedCallback(ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, this);
3074 m_collection_sp->SetValueChangedCallback(ePropertyDisableSTDIO, TargetProperties::DisableSTDIOValueChangedCallback, this);
3075
3076 // Update m_launch_info once it was created
3077 Arg0ValueChangedCallback(this, NULL);
3078 RunArgsValueChangedCallback(this, NULL);
3079 //EnvVarsValueChangedCallback(this, NULL); // FIXME: cause segfault in Target::GetPlatform()
3080 InputPathValueChangedCallback(this, NULL);
3081 OutputPathValueChangedCallback(this, NULL);
3082 ErrorPathValueChangedCallback(this, NULL);
3083 DetachOnErrorValueChangedCallback(this, NULL);
3084 DisableASLRValueChangedCallback(this, NULL);
3085 DisableSTDIOValueChangedCallback(this, NULL);
Caroline Ticedaccaa92010-09-20 20:44:43 +00003086 }
3087 else
Greg Clayton67cc0632012-08-22 17:17:09 +00003088 {
3089 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
3090 m_collection_sp->Initialize(g_properties);
3091 m_collection_sp->AppendProperty(ConstString("process"),
3092 ConstString("Settings specify to processes."),
3093 true,
3094 Process::GetGlobalProperties()->GetValueProperties());
3095 }
Ilia K8f37ca52015-02-13 14:31:06 +00003096
Caroline Ticedaccaa92010-09-20 20:44:43 +00003097}
3098
Greg Clayton67cc0632012-08-22 17:17:09 +00003099TargetProperties::~TargetProperties ()
3100{
3101}
3102ArchSpec
3103TargetProperties::GetDefaultArchitecture () const
3104{
3105 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3106 if (value)
3107 return value->GetCurrentValue();
3108 return ArchSpec();
3109}
3110
3111void
3112TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
3113{
3114 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3115 if (value)
3116 return value->SetCurrentValue(arch, true);
3117}
3118
3119lldb::DynamicValueType
3120TargetProperties::GetPreferDynamicValue() const
3121{
3122 const uint32_t idx = ePropertyPreferDynamic;
3123 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3124}
3125
3126bool
3127TargetProperties::GetDisableASLR () const
3128{
3129 const uint32_t idx = ePropertyDisableASLR;
3130 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3131}
3132
3133void
3134TargetProperties::SetDisableASLR (bool b)
3135{
3136 const uint32_t idx = ePropertyDisableASLR;
3137 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3138}
3139
3140bool
Jim Ingham106d0282014-06-25 02:32:56 +00003141TargetProperties::GetDetachOnError () const
3142{
3143 const uint32_t idx = ePropertyDetachOnError;
3144 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3145}
3146
3147void
3148TargetProperties::SetDetachOnError (bool b)
3149{
3150 const uint32_t idx = ePropertyDetachOnError;
3151 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3152}
3153
3154bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003155TargetProperties::GetDisableSTDIO () const
3156{
3157 const uint32_t idx = ePropertyDisableSTDIO;
3158 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3159}
3160
3161void
3162TargetProperties::SetDisableSTDIO (bool b)
3163{
3164 const uint32_t idx = ePropertyDisableSTDIO;
3165 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3166}
3167
Jim Ingham0f063ba2013-03-02 00:26:47 +00003168const char *
3169TargetProperties::GetDisassemblyFlavor () const
3170{
3171 const uint32_t idx = ePropertyDisassemblyFlavor;
3172 const char *return_value;
3173
3174 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3175 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
3176 return return_value;
3177}
3178
Greg Clayton1f746072012-08-29 21:13:06 +00003179InlineStrategy
3180TargetProperties::GetInlineStrategy () const
3181{
3182 const uint32_t idx = ePropertyInlineStrategy;
3183 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3184}
3185
Greg Clayton45392552012-10-17 22:57:12 +00003186const char *
3187TargetProperties::GetArg0 () const
3188{
3189 const uint32_t idx = ePropertyArg0;
3190 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
3191}
3192
3193void
3194TargetProperties::SetArg0 (const char *arg)
3195{
3196 const uint32_t idx = ePropertyArg0;
3197 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
3198}
3199
Greg Clayton67cc0632012-08-22 17:17:09 +00003200bool
3201TargetProperties::GetRunArguments (Args &args) const
3202{
3203 const uint32_t idx = ePropertyRunArgs;
3204 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3205}
3206
3207void
3208TargetProperties::SetRunArguments (const Args &args)
3209{
3210 const uint32_t idx = ePropertyRunArgs;
3211 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3212}
3213
3214size_t
3215TargetProperties::GetEnvironmentAsArgs (Args &env) const
3216{
3217 const uint32_t idx = ePropertyEnvVars;
3218 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
3219}
3220
Ilia K8f37ca52015-02-13 14:31:06 +00003221void
3222TargetProperties::SetEnvironmentFromArgs (const Args &env)
3223{
3224 const uint32_t idx = ePropertyEnvVars;
3225 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, env);
3226}
3227
Greg Clayton67cc0632012-08-22 17:17:09 +00003228bool
3229TargetProperties::GetSkipPrologue() const
3230{
3231 const uint32_t idx = ePropertySkipPrologue;
3232 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3233}
3234
3235PathMappingList &
3236TargetProperties::GetSourcePathMap () const
3237{
3238 const uint32_t idx = ePropertySourceMap;
3239 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
3240 assert(option_value);
3241 return option_value->GetCurrentValue();
3242}
3243
3244FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00003245TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003246{
3247 const uint32_t idx = ePropertyExecutableSearchPaths;
3248 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3249 assert(option_value);
3250 return option_value->GetCurrentValue();
3251}
3252
Michael Sartaina7499c92013-07-01 19:45:50 +00003253FileSpecList &
3254TargetProperties::GetDebugFileSearchPaths ()
3255{
3256 const uint32_t idx = ePropertyDebugFileSearchPaths;
3257 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3258 assert(option_value);
3259 return option_value->GetCurrentValue();
3260}
3261
Greg Clayton67cc0632012-08-22 17:17:09 +00003262bool
3263TargetProperties::GetEnableSyntheticValue () const
3264{
3265 const uint32_t idx = ePropertyEnableSynthetic;
3266 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3267}
3268
3269uint32_t
3270TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
3271{
3272 const uint32_t idx = ePropertyMaxChildrenCount;
3273 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3274}
3275
3276uint32_t
3277TargetProperties::GetMaximumSizeOfStringSummary() const
3278{
3279 const uint32_t idx = ePropertyMaxSummaryLength;
3280 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3281}
3282
Enrico Granatad325bf92013-06-04 22:54:16 +00003283uint32_t
3284TargetProperties::GetMaximumMemReadSize () const
3285{
3286 const uint32_t idx = ePropertyMaxMemReadSize;
3287 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3288}
3289
Greg Clayton67cc0632012-08-22 17:17:09 +00003290FileSpec
3291TargetProperties::GetStandardInputPath () const
3292{
3293 const uint32_t idx = ePropertyInputPath;
3294 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3295}
3296
3297void
3298TargetProperties::SetStandardInputPath (const char *p)
3299{
3300 const uint32_t idx = ePropertyInputPath;
3301 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3302}
3303
3304FileSpec
3305TargetProperties::GetStandardOutputPath () const
3306{
3307 const uint32_t idx = ePropertyOutputPath;
3308 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3309}
3310
3311void
3312TargetProperties::SetStandardOutputPath (const char *p)
3313{
3314 const uint32_t idx = ePropertyOutputPath;
3315 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3316}
3317
3318FileSpec
3319TargetProperties::GetStandardErrorPath () const
3320{
3321 const uint32_t idx = ePropertyErrorPath;
3322 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
3323}
3324
Greg Clayton6920b522012-08-22 18:39:03 +00003325const char *
3326TargetProperties::GetExpressionPrefixContentsAsCString ()
3327{
3328 const uint32_t idx = ePropertyExprPrefix;
3329 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3330 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003331 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003332 const bool null_terminate = true;
3333 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003334 if (data_sp)
3335 return (const char *) data_sp->GetBytes();
3336 }
Greg Clayton6920b522012-08-22 18:39:03 +00003337 return NULL;
3338}
3339
Greg Clayton67cc0632012-08-22 17:17:09 +00003340void
3341TargetProperties::SetStandardErrorPath (const char *p)
3342{
3343 const uint32_t idx = ePropertyErrorPath;
3344 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3345}
3346
3347bool
3348TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3349{
3350 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3351 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3352}
3353
Jim Ingham17d023f2013-03-13 17:58:04 +00003354bool
Daniel Malead79ae052013-08-07 21:54:09 +00003355TargetProperties::GetUseHexImmediates () const
3356{
3357 const uint32_t idx = ePropertyUseHexImmediates;
3358 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3359}
3360
3361bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003362TargetProperties::GetUseFastStepping () const
3363{
3364 const uint32_t idx = ePropertyUseFastStepping;
3365 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3366}
3367
Greg Claytonfb6621e2013-12-06 21:59:52 +00003368bool
3369TargetProperties::GetDisplayExpressionsInCrashlogs () const
3370{
3371 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3372 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3373}
3374
Enrico Granata397ddd52013-05-21 20:13:34 +00003375LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003376TargetProperties::GetLoadScriptFromSymbolFile () const
3377{
3378 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Enrico Granata397ddd52013-05-21 20:13:34 +00003379 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003380}
3381
Daniel Malead79ae052013-08-07 21:54:09 +00003382Disassembler::HexImmediateStyle
3383TargetProperties::GetHexImmediateStyle () const
3384{
3385 const uint32_t idx = ePropertyHexImmediateStyle;
3386 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3387}
3388
Greg Claytonfd814c52013-08-13 01:42:25 +00003389MemoryModuleLoadLevel
3390TargetProperties::GetMemoryModuleLoadLevel() const
3391{
3392 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3393 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3394}
3395
Jason Molendaa4bea722014-02-14 05:06:49 +00003396bool
3397TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
3398{
3399 const uint32_t idx = ePropertyTrapHandlerNames;
3400 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3401}
Greg Claytonfd814c52013-08-13 01:42:25 +00003402
Jason Molendaa4bea722014-02-14 05:06:49 +00003403void
3404TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
3405{
3406 const uint32_t idx = ePropertyTrapHandlerNames;
3407 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3408}
Greg Clayton67cc0632012-08-22 17:17:09 +00003409
Enrico Granata560558e2015-02-11 02:35:39 +00003410bool
3411TargetProperties::GetDisplayRuntimeSupportValues () const
3412{
3413 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3414 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, false);
3415}
3416
3417void
3418TargetProperties::SetDisplayRuntimeSupportValues (bool b)
3419{
3420 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3421 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3422}
3423
Ilia K8f37ca52015-02-13 14:31:06 +00003424const ProcessLaunchInfo &
Ilia Kcc39d3f2015-02-13 17:07:55 +00003425TargetProperties::GetProcessLaunchInfo ()
Ilia K8f37ca52015-02-13 14:31:06 +00003426{
Ilia Kcc39d3f2015-02-13 17:07:55 +00003427 m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work
Ilia K8f37ca52015-02-13 14:31:06 +00003428 return m_launch_info;
3429}
3430
3431void
3432TargetProperties::SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
3433{
3434 m_launch_info = launch_info;
3435 SetArg0(launch_info.GetArg0());
3436 SetRunArguments(launch_info.GetArguments());
3437 SetEnvironmentFromArgs(launch_info.GetEnvironmentEntries());
3438 const FileAction *input_file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
3439 if (input_file_action)
3440 {
3441 const char *input_path = input_file_action->GetPath();
3442 if (input_path)
3443 SetStandardInputPath(input_path);
3444 }
3445 const FileAction *output_file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
3446 if (output_file_action)
3447 {
3448 const char *output_path = output_file_action->GetPath();
3449 if (output_path)
3450 SetStandardOutputPath(output_path);
3451 }
3452 const FileAction *error_file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
3453 if (error_file_action)
3454 {
3455 const char *error_path = error_file_action->GetPath();
3456 if (error_path)
3457 SetStandardErrorPath(error_path);
3458 }
3459 SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
3460 SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
3461 SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO));
3462}
3463
3464void
3465TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *)
3466{
3467 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3468 this_->m_launch_info.SetArg0(this_->GetArg0());
3469}
3470
3471void
3472TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *)
3473{
3474 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3475 Args args;
3476 if (this_->GetRunArguments(args))
3477 this_->m_launch_info.GetArguments() = args;
3478}
3479
3480void
3481TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *)
3482{
3483 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3484 Args args;
3485 if (this_->GetEnvironmentAsArgs(args))
3486 this_->m_launch_info.GetEnvironmentEntries() = args;
3487}
3488
3489void
3490TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3491{
3492 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3493 this_->m_launch_info.AppendOpenFileAction(STDIN_FILENO, this_->GetStandardInputPath().GetPath().c_str(), true, false);
3494}
3495
3496void
3497TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3498{
3499 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3500 this_->m_launch_info.AppendOpenFileAction(STDOUT_FILENO, this_->GetStandardOutputPath().GetPath().c_str(), false, true);
3501}
3502
3503void
3504TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3505{
3506 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3507 this_->m_launch_info.AppendOpenFileAction(STDERR_FILENO, this_->GetStandardErrorPath().GetPath().c_str(), false, true);
3508}
3509
3510void
3511TargetProperties::DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *)
3512{
3513 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3514 if (this_->GetDetachOnError())
3515 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError);
3516 else
3517 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError);
3518}
3519
3520void
3521TargetProperties::DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *)
3522{
3523 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3524 if (this_->GetDisableASLR())
3525 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR);
3526 else
3527 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR);
3528}
3529
3530void
3531TargetProperties::DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *)
3532{
3533 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3534 if (this_->GetDisableSTDIO())
3535 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO);
3536 else
3537 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO);
3538}
Ilia Keb2c19a2015-03-10 21:59:55 +00003539
3540//----------------------------------------------------------------------
3541// Target::TargetEventData
3542//----------------------------------------------------------------------
3543
3544Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp) :
3545 EventData (),
3546 m_target_sp (target_sp),
3547 m_module_list ()
3548{
3549}
3550
3551Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp, const ModuleList &module_list) :
3552 EventData (),
3553 m_target_sp (target_sp),
3554 m_module_list (module_list)
3555{
3556}
3557
3558Target::TargetEventData::~TargetEventData()
3559{
3560}
3561
3562const ConstString &
3563Target::TargetEventData::GetFlavorString ()
3564{
3565 static ConstString g_flavor ("Target::TargetEventData");
3566 return g_flavor;
3567}
3568
3569void
3570Target::TargetEventData::Dump (Stream *s) const
3571{
3572}
3573
3574const Target::TargetEventData *
3575Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3576{
3577 if (event_ptr)
3578 {
3579 const EventData *event_data = event_ptr->GetData();
3580 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3581 return static_cast <const TargetEventData *> (event_ptr->GetData());
3582 }
3583 return NULL;
3584}
3585
3586TargetSP
3587Target::TargetEventData::GetTargetFromEvent (const Event *event_ptr)
3588{
3589 TargetSP target_sp;
3590 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
3591 if (event_data)
3592 target_sp = event_data->m_target_sp;
3593 return target_sp;
3594}
3595
3596ModuleList
3597Target::TargetEventData::GetModuleListFromEvent (const Event *event_ptr)
3598{
3599 ModuleList module_list;
3600 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
3601 if (event_data)
3602 module_list = event_data->m_module_list;
3603 return module_list;
3604}