blob: aca6605f2afab66b01590a9ca1470c9f1db3d06a [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
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham969795f2011-09-21 01:17:13 +000019#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chen01a67862011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000022#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Event.h"
24#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Core/Module.h"
26#include "lldb/Core/ModuleSpec.h"
27#include "lldb/Core/Section.h"
Greg Clayton9585fbf2013-03-19 00:20:55 +000028#include "lldb/Core/SourceManager.h"
Greg Claytonb09c5382013-12-13 17:20:18 +000029#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000030#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000032#include "lldb/Core/Timer.h"
33#include "lldb/Core/ValueObject.h"
Sean Callanan4bf80d52011-11-15 22:27:19 +000034#include "lldb/Expression/ClangASTSource.h"
Zachary Turneraf0f45f2015-03-03 21:05:17 +000035#include "lldb/Expression/ClangPersistentVariables.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000036#include "lldb/Expression/ClangUserExpression.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000037#include "lldb/Expression/ClangModulesDeclVendor.h"
Zachary Turner10687b02014-10-20 17:46:43 +000038#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:59 +000040#include "lldb/Interpreter/CommandInterpreter.h"
41#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chenb90827e2012-06-04 23:19:54 +000042#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000043#include "lldb/Interpreter/OptionValues.h"
44#include "lldb/Interpreter/Property.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000045#include "lldb/Symbol/ClangASTContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Symbol/ObjectFile.h"
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +000047#include "lldb/Symbol/Function.h"
48#include "lldb/Symbol/Symbol.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000049#include "lldb/Target/LanguageRuntime.h"
50#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000052#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000053#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000054#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000055#include "lldb/Target/Thread.h"
56#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58using namespace lldb;
59using namespace lldb_private;
60
Jim Ingham4bddaeb2012-02-16 06:50:00 +000061ConstString &
62Target::GetStaticBroadcasterClass ()
63{
64 static ConstString class_name ("lldb.target");
65 return class_name;
66}
67
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068//----------------------------------------------------------------------
69// Target constructor
70//----------------------------------------------------------------------
Jim Ingham893c9322014-11-22 01:42:44 +000071Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp, bool is_dummy_target) :
Greg Clayton67cc0632012-08-22 17:17:09 +000072 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +000073 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +000074 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +000075 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +000076 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +000077 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +000078 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +000079 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +000080 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081 m_breakpoint_list (false),
82 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +000083 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +000084 m_process_sp (),
85 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Claytone01e07b2013-04-18 18:10:51 +000087 m_scratch_ast_context_ap (),
88 m_scratch_ast_source_ap (),
89 m_ast_importer_ap (),
Zachary Turner32abc6e2015-03-03 19:23:09 +000090 m_persistent_variables (new ClangPersistentVariables),
Greg Clayton9585fbf2013-03-19 00:20:55 +000091 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +000092 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +000093 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +000094 m_valid (true),
Jim Ingham893c9322014-11-22 01:42:44 +000095 m_suppress_stop_hooks (false),
96 m_is_dummy_target(is_dummy_target)
97
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098{
Greg Claytoncfd1ace2010-10-31 03:01:06 +000099 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
100 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
101 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +0000102 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +0000103 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000104
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000105 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000106
Greg Clayton5160ce52013-03-27 23:08:40 +0000107 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000109 log->Printf ("%p Target::Target()", static_cast<void*>(this));
Jason Molendae1b68ad2012-12-05 00:25:49 +0000110 if (m_arch.IsValid())
111 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000112 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 +0000113 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114}
115
Jim Ingham893c9322014-11-22 01:42:44 +0000116void
117Target::PrimeFromDummyTarget(Target *target)
118{
119 if (!target)
120 return;
121
122 m_stop_hooks = target->m_stop_hooks;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000123
124 for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints())
125 {
126 if (breakpoint_sp->IsInternal())
127 continue;
128
129 BreakpointSP new_bp (new Breakpoint (*this, *breakpoint_sp.get()));
130 AddBreakpoint (new_bp, false);
131 }
Jim Ingham893c9322014-11-22 01:42:44 +0000132}
133
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134//----------------------------------------------------------------------
135// Destructor
136//----------------------------------------------------------------------
137Target::~Target()
138{
Greg Clayton5160ce52013-03-27 23:08:40 +0000139 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000141 log->Printf ("%p Target::~Target()", static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142 DeleteCurrentProcess ();
143}
144
145void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000146Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147{
Greg Clayton89411422010-10-08 00:21:05 +0000148// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000149 if (description_level != lldb::eDescriptionLevelBrief)
150 {
151 s->Indent();
152 s->PutCString("Target\n");
153 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000154 m_images.Dump(s);
155 m_breakpoint_list.Dump(s);
156 m_internal_breakpoint_list.Dump(s);
157 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000158 }
159 else
160 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000161 Module *exe_module = GetExecutableModulePointer();
162 if (exe_module)
163 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000164 else
165 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000166 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169void
Greg Clayton90ba8112012-12-05 00:16:59 +0000170Target::CleanupProcess ()
171{
172 // Do any cleanup of the target we need to do between process instances.
173 // NB It is better to do this before destroying the process in case the
174 // clean up needs some help from the process.
175 m_breakpoint_list.ClearAllBreakpointSites();
176 m_internal_breakpoint_list.ClearAllBreakpointSites();
177 // Disable watchpoints just on the debugger side.
178 Mutex::Locker locker;
179 this->GetWatchpointList().GetListMutex(locker);
180 DisableAllWatchpoints(false);
181 ClearAllWatchpointHitCounts();
Enrico Granata5e3fe042015-02-11 00:37:54 +0000182 ClearAllWatchpointHistoricValues();
Greg Clayton90ba8112012-12-05 00:16:59 +0000183}
184
185void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186Target::DeleteCurrentProcess ()
187{
188 if (m_process_sp.get())
189 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000190 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 if (m_process_sp->IsAlive())
Jason Molendaede31932015-04-17 05:01:58 +0000192 m_process_sp->Destroy(false);
Jim Inghamd0a3e122011-02-16 17:54:55 +0000193
194 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195
Greg Clayton90ba8112012-12-05 00:16:59 +0000196 CleanupProcess ();
197
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 m_process_sp.reset();
199 }
200}
201
202const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000203Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204{
205 DeleteCurrentProcess ();
Zachary Turner7529df92015-09-01 20:02:29 +0000206 m_process_sp = Process::FindPlugin(shared_from_this(), plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 return m_process_sp;
208}
209
210const lldb::ProcessSP &
211Target::GetProcessSP () const
212{
213 return m_process_sp;
214}
215
Greg Clayton3418c852011-08-10 02:10:13 +0000216void
217Target::Destroy()
218{
219 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000220 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000221 DeleteCurrentProcess ();
222 m_platform_sp.reset();
223 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000224 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000225 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000226 const bool notify = false;
227 m_breakpoint_list.RemoveAll(notify);
228 m_internal_breakpoint_list.RemoveAll(notify);
229 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000230 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000231 m_search_filter_sp.reset();
232 m_image_search_paths.Clear(notify);
Zachary Turner32abc6e2015-03-03 19:23:09 +0000233 m_persistent_variables->Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000234 m_stop_hooks.clear();
235 m_stop_hook_next_id = 0;
236 m_suppress_stop_hooks = false;
237}
238
239
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240BreakpointList &
241Target::GetBreakpointList(bool internal)
242{
243 if (internal)
244 return m_internal_breakpoint_list;
245 else
246 return m_breakpoint_list;
247}
248
249const BreakpointList &
250Target::GetBreakpointList(bool internal) const
251{
252 if (internal)
253 return m_internal_breakpoint_list;
254 else
255 return m_breakpoint_list;
256}
257
258BreakpointSP
259Target::GetBreakpointByID (break_id_t break_id)
260{
261 BreakpointSP bp_sp;
262
263 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
264 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
265 else
266 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
267
268 return bp_sp;
269}
270
271BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000272Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000273 const FileSpecList *source_file_spec_list,
274 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000275 bool internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000276 bool hardware,
277 LazyBool move_to_nearest_code)
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));
Ilia K055ad9b2015-05-18 13:41:01 +0000280 if (move_to_nearest_code == eLazyBoolCalculate)
281 move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
282 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex, !static_cast<bool>(move_to_nearest_code)));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000283 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000284}
285
286
287BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000288Target::CreateBreakpoint (const FileSpecList *containingModules,
289 const FileSpec &file,
290 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000291 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000292 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000293 bool internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000294 bool hardware,
295 LazyBool move_to_nearest_code)
Jim Ingham969795f2011-09-21 01:17:13 +0000296{
Greg Clayton1f746072012-08-29 21:13:06 +0000297 if (check_inlines == eLazyBoolCalculate)
298 {
299 const InlineStrategy inline_strategy = GetInlineStrategy();
300 switch (inline_strategy)
301 {
302 case eInlineBreakpointsNever:
303 check_inlines = eLazyBoolNo;
304 break;
305
306 case eInlineBreakpointsHeaders:
307 if (file.IsSourceImplementationFile())
308 check_inlines = eLazyBoolNo;
309 else
310 check_inlines = eLazyBoolYes;
311 break;
312
313 case eInlineBreakpointsAlways:
314 check_inlines = eLazyBoolYes;
315 break;
316 }
317 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000318 SearchFilterSP filter_sp;
319 if (check_inlines == eLazyBoolNo)
320 {
321 // Not checking for inlines, we are looking only for matching compile units
322 FileSpecList compile_unit_list;
323 compile_unit_list.Append (file);
324 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
325 }
326 else
327 {
328 filter_sp = GetSearchFilterForModuleList (containingModules);
329 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000330 if (skip_prologue == eLazyBoolCalculate)
331 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Ilia K055ad9b2015-05-18 13:41:01 +0000332 if (move_to_nearest_code == eLazyBoolCalculate)
333 move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
Greg Clayton03da4cc2013-04-19 21:31:16 +0000334
Greg Clayton1f746072012-08-29 21:13:06 +0000335 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
336 file,
337 line_no,
338 check_inlines,
Ilia K055ad9b2015-05-18 13:41:01 +0000339 skip_prologue,
340 !static_cast<bool>(move_to_nearest_code)));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000341 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342}
343
344
345BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000346Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 Address so_addr;
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +0000349
350 // Check for any reason we want to move this breakpoint to other address.
351 addr = GetBreakableLoadAddress(addr);
352
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353 // Attempt to resolve our load address if possible, though it is ok if
354 // it doesn't resolve to section/offset.
355
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000356 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000357 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000358 if (!so_addr.IsValid())
359 {
360 // The address didn't resolve, so just set this as an absolute address
361 so_addr.SetOffset (addr);
362 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000363 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364 return bp_sp;
365}
366
367BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000368Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369{
Jim Ingham33df7cd2014-12-06 01:28:03 +0000370 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000372 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373}
374
375BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000376Target::CreateBreakpoint (const FileSpecList *containingModules,
377 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000378 const char *func_name,
379 uint32_t func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000380 LanguageType language,
Jim Inghama8558b62012-05-22 00:12:20 +0000381 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000382 bool internal,
383 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000385 BreakpointSP bp_sp;
386 if (func_name)
387 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000388 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000389
390 if (skip_prologue == eLazyBoolCalculate)
391 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000392 if (language == lldb::eLanguageTypeUnknown)
393 language = GetLanguage();
Greg Clayton03da4cc2013-04-19 21:31:16 +0000394
Greg Claytond16e1e52011-07-12 17:06:17 +0000395 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
396 func_name,
397 func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000398 language,
Greg Claytond16e1e52011-07-12 17:06:17 +0000399 Breakpoint::Exact,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000400 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000401 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000402 }
403 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404}
405
Jim Inghamfab10e82012-03-06 00:37:27 +0000406lldb::BreakpointSP
407Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000408 const FileSpecList *containingSourceFiles,
409 const std::vector<std::string> &func_names,
410 uint32_t func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000411 LanguageType language,
Jim Inghama8558b62012-05-22 00:12:20 +0000412 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000413 bool internal,
414 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000415{
416 BreakpointSP bp_sp;
417 size_t num_names = func_names.size();
418 if (num_names > 0)
419 {
420 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000421
422 if (skip_prologue == eLazyBoolCalculate)
423 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000424 if (language == lldb::eLanguageTypeUnknown)
425 language = GetLanguage();
Greg Clayton03da4cc2013-04-19 21:31:16 +0000426
427 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Inghamfab10e82012-03-06 00:37:27 +0000428 func_names,
429 func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000430 language,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000431 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000432 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000433 }
434 return bp_sp;
435}
436
Jim Ingham133e0fb2012-03-03 02:05:11 +0000437BreakpointSP
438Target::CreateBreakpoint (const FileSpecList *containingModules,
439 const FileSpecList *containingSourceFiles,
440 const char *func_names[],
441 size_t num_names,
442 uint32_t func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000443 LanguageType language,
Jim Inghama8558b62012-05-22 00:12:20 +0000444 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000445 bool internal,
446 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000447{
448 BreakpointSP bp_sp;
449 if (num_names > 0)
450 {
451 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
452
Greg Clayton03da4cc2013-04-19 21:31:16 +0000453 if (skip_prologue == eLazyBoolCalculate)
454 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000455 if (language == lldb::eLanguageTypeUnknown)
456 language = GetLanguage();
457
Greg Clayton03da4cc2013-04-19 21:31:16 +0000458
459 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Ingham133e0fb2012-03-03 02:05:11 +0000460 func_names,
461 num_names,
Jim Inghamfab10e82012-03-06 00:37:27 +0000462 func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000463 language,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000464 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000465 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000466 }
467 return bp_sp;
468}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469
470SearchFilterSP
471Target::GetSearchFilterForModule (const FileSpec *containingModule)
472{
473 SearchFilterSP filter_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474 if (containingModule != NULL)
475 {
476 // TODO: We should look into sharing module based search filters
477 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000478 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 }
480 else
481 {
482 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000483 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 filter_sp = m_search_filter_sp;
485 }
486 return filter_sp;
487}
488
Jim Ingham969795f2011-09-21 01:17:13 +0000489SearchFilterSP
490Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
491{
492 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000493 if (containingModules && containingModules->GetSize() != 0)
494 {
495 // TODO: We should look into sharing module based search filters
496 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000497 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000498 }
499 else
500 {
501 if (m_search_filter_sp.get() == NULL)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000502 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000503 filter_sp = m_search_filter_sp;
504 }
505 return filter_sp;
506}
507
Jim Ingham87df91b2011-09-23 00:54:11 +0000508SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000509Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
510 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000511{
512 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
513 return GetSearchFilterForModuleList(containingModules);
514
515 SearchFilterSP filter_sp;
Jim Ingham87df91b2011-09-23 00:54:11 +0000516 if (containingModules == NULL)
517 {
518 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
519 // but that will take a little reworking.
520
Greg Claytone1cd1be2012-01-29 20:56:30 +0000521 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000522 }
523 else
524 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000525 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000526 }
527 return filter_sp;
528}
529
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000531Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000532 const FileSpecList *containingSourceFiles,
533 RegularExpression &func_regex,
534 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000535 bool internal,
536 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537{
Jim Ingham87df91b2011-09-23 00:54:11 +0000538 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000539 bool skip =
540 (skip_prologue == eLazyBoolCalculate) ? GetSkipPrologue()
541 : static_cast<bool>(skip_prologue);
Greg Claytond16e1e52011-07-12 17:06:17 +0000542 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
543 func_regex,
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000544 skip));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545
Jim Ingham1460e4b2014-01-10 23:46:59 +0000546 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547}
548
Jim Ingham219ba192012-03-05 04:47:34 +0000549lldb::BreakpointSP
Jim Inghama72b31c2015-04-22 19:42:18 +0000550Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal, Args *additional_args, Error *error)
Jim Ingham219ba192012-03-05 04:47:34 +0000551{
Jim Inghama72b31c2015-04-22 19:42:18 +0000552 BreakpointSP exc_bkpt_sp = LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
553 if (exc_bkpt_sp && additional_args)
554 {
555 Breakpoint::BreakpointPreconditionSP precondition_sp = exc_bkpt_sp->GetPrecondition();
556 if (precondition_sp && additional_args)
557 {
558 if (error)
559 *error = precondition_sp->ConfigurePrecondition(*additional_args);
560 else
561 precondition_sp->ConfigurePrecondition(*additional_args);
562 }
563 }
564 return exc_bkpt_sp;
Jim Ingham219ba192012-03-05 04:47:34 +0000565}
Jim Inghama72b31c2015-04-22 19:42:18 +0000566
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000568Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569{
570 BreakpointSP bp_sp;
571 if (filter_sp && resolver_sp)
572 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000573 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 resolver_sp->SetBreakpoint (bp_sp.get());
Jim Ingham33df7cd2014-12-06 01:28:03 +0000575 AddBreakpoint (bp_sp, internal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 }
Jim Ingham33df7cd2014-12-06 01:28:03 +0000577 return bp_sp;
578}
579
580void
581Target::AddBreakpoint (lldb::BreakpointSP bp_sp, bool internal)
582{
583 if (!bp_sp)
584 return;
585 if (internal)
586 m_internal_breakpoint_list.Add (bp_sp, false);
587 else
588 m_breakpoint_list.Add (bp_sp, true);
589
590 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
591 if (log)
592 {
593 StreamString s;
594 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
595 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
596 }
597
598 bp_sp->ResolveBreakpoint();
599
600 if (!internal)
Jim Ingham36f3b362010-10-14 23:45:03 +0000601 {
602 m_last_created_breakpoint = bp_sp;
603 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604}
605
Johnny Chen86364b42011-09-20 23:28:55 +0000606bool
607Target::ProcessIsValid()
608{
609 return (m_process_sp && m_process_sp->IsAlive());
610}
611
Johnny Chenb90827e2012-06-04 23:19:54 +0000612static bool
613CheckIfWatchpointsExhausted(Target *target, Error &error)
614{
615 uint32_t num_supported_hardware_watchpoints;
616 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
617 if (rc.Success())
618 {
619 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
620 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
621 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
622 num_supported_hardware_watchpoints);
623 }
624 return false;
625}
626
Johnny Chen01a67862011-10-14 00:42:25 +0000627// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000628// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000629WatchpointSP
Greg Claytona1e5dc82015-08-11 22:53:00 +0000630Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const CompilerType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000631{
Greg Clayton5160ce52013-03-27 23:08:40 +0000632 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000633 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000634 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000635 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000636
Johnny Chen01a67862011-10-14 00:42:25 +0000637 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000638 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000639 {
640 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000641 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000642 }
Jim Inghamc6462312013-06-18 21:52:48 +0000643
Johnny Chen45e541f2011-09-14 22:20:15 +0000644 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000645 {
646 if (size == 0)
647 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
648 else
Daniel Malead01b2952012-11-29 21:49:15 +0000649 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000650 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000651 }
Jim Inghamc6462312013-06-18 21:52:48 +0000652
653 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
654 {
655 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
656 }
Johnny Chen7313a642011-09-13 01:15:36 +0000657
Johnny Chen01a67862011-10-14 00:42:25 +0000658 // Currently we only support one watchpoint per address, with total number
659 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000660
661 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000662 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 +0000663 Mutex::Locker locker;
664 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000665 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000666 if (matched_sp)
667 {
Johnny Chen0c406372011-09-14 20:23:45 +0000668 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000669 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000670 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
671 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000672 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000673 if (size == old_size && kind == old_type)
674 {
Johnny Chen01a67862011-10-14 00:42:25 +0000675 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000676 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000677 }
678 else
679 {
Johnny Chen01a67862011-10-14 00:42:25 +0000680 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000681 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
682 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000683 }
Johnny Chen3c532582011-09-13 23:29:31 +0000684 }
685
Jason Molenda727e3922012-12-05 23:07:34 +0000686 if (!wp_sp)
687 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000688 wp_sp.reset(new Watchpoint(*this, addr, size, type));
689 wp_sp->SetWatchpointType(kind, notify);
690 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000691 }
Johnny Chen0c406372011-09-14 20:23:45 +0000692
Jim Ingham1b5792e2012-12-18 02:03:49 +0000693 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000694 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000695 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
696 __FUNCTION__,
697 error.Success() ? "succeeded" : "failed",
698 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000699
Jason Molenda727e3922012-12-05 23:07:34 +0000700 if (error.Fail())
701 {
Johnny Chen41b77262012-03-26 22:00:10 +0000702 // Enabling the watchpoint on the device side failed.
703 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000704 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000705 // See if we could provide more helpful error message.
706 if (!CheckIfWatchpointsExhausted(this, error))
707 {
708 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Greg Clayton6fea17e2014-03-03 19:15:20 +0000709 error.SetErrorStringWithFormat("watch size of %" PRIu64 " is not supported", (uint64_t)size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000710 }
Johnny Chen01a67862011-10-14 00:42:25 +0000711 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000712 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000713 else
Johnny Chen01a67862011-10-14 00:42:25 +0000714 m_last_created_watchpoint = wp_sp;
715 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000716}
717
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718void
719Target::RemoveAllBreakpoints (bool internal_also)
720{
Greg Clayton5160ce52013-03-27 23:08:40 +0000721 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 if (log)
723 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
724
Greg Clayton9fed0d82010-07-23 23:33:17 +0000725 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000727 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000728
729 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000730}
731
732void
733Target::DisableAllBreakpoints (bool internal_also)
734{
Greg Clayton5160ce52013-03-27 23:08:40 +0000735 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000736 if (log)
737 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
738
739 m_breakpoint_list.SetEnabledAll (false);
740 if (internal_also)
741 m_internal_breakpoint_list.SetEnabledAll (false);
742}
743
744void
745Target::EnableAllBreakpoints (bool internal_also)
746{
Greg Clayton5160ce52013-03-27 23:08:40 +0000747 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748 if (log)
749 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
750
751 m_breakpoint_list.SetEnabledAll (true);
752 if (internal_also)
753 m_internal_breakpoint_list.SetEnabledAll (true);
754}
755
756bool
757Target::RemoveBreakpointByID (break_id_t break_id)
758{
Greg Clayton5160ce52013-03-27 23:08:40 +0000759 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 if (log)
761 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
762
763 if (DisableBreakpointByID (break_id))
764 {
765 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000766 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000768 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000769 if (m_last_created_breakpoint)
770 {
771 if (m_last_created_breakpoint->GetID() == break_id)
772 m_last_created_breakpoint.reset();
773 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000774 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000775 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776 return true;
777 }
778 return false;
779}
780
781bool
782Target::DisableBreakpointByID (break_id_t break_id)
783{
Greg Clayton5160ce52013-03-27 23:08:40 +0000784 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 if (log)
786 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
787
788 BreakpointSP bp_sp;
789
790 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
791 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
792 else
793 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
794 if (bp_sp)
795 {
796 bp_sp->SetEnabled (false);
797 return true;
798 }
799 return false;
800}
801
802bool
803Target::EnableBreakpointByID (break_id_t break_id)
804{
Greg Clayton5160ce52013-03-27 23:08:40 +0000805 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806 if (log)
807 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
808 __FUNCTION__,
809 break_id,
810 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
811
812 BreakpointSP bp_sp;
813
814 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
815 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
816 else
817 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
818
819 if (bp_sp)
820 {
821 bp_sp->SetEnabled (true);
822 return true;
823 }
824 return false;
825}
826
Johnny Chenedf50372011-09-23 21:21:43 +0000827// The flag 'end_to_end', default to true, signifies that the operation is
828// performed end to end, for both the debugger and the debuggee.
829
Johnny Chen01a67862011-10-14 00:42:25 +0000830// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
831// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000832bool
Johnny Chen01a67862011-10-14 00:42:25 +0000833Target::RemoveAllWatchpoints (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) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000840 m_watchpoint_list.RemoveAll(true);
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 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000860 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000861 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000862 return true; // Success!
863}
864
Johnny Chen01a67862011-10-14 00:42:25 +0000865// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
866// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000867bool
Johnny Chen01a67862011-10-14 00:42:25 +0000868Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000869{
Greg Clayton5160ce52013-03-27 23:08:40 +0000870 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000871 if (log)
872 log->Printf ("Target::%s\n", __FUNCTION__);
873
Johnny Chenedf50372011-09-23 21:21:43 +0000874 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000875 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000876 return true;
877 }
878
879 // Otherwise, it's an end to end operation.
880
Johnny Chen86364b42011-09-20 23:28:55 +0000881 if (!ProcessIsValid())
882 return false;
883
Johnny Chen01a67862011-10-14 00:42:25 +0000884 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000885 for (size_t i = 0; i < num_watchpoints; ++i)
886 {
Johnny Chen01a67862011-10-14 00:42:25 +0000887 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
888 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000889 return false;
890
Johnny Chen01a67862011-10-14 00:42:25 +0000891 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000892 if (rc.Fail())
893 return false;
894 }
Johnny Chen86364b42011-09-20 23:28:55 +0000895 return true; // Success!
896}
897
Johnny Chen01a67862011-10-14 00:42:25 +0000898// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
899// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000900bool
Johnny Chen01a67862011-10-14 00:42:25 +0000901Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000902{
Greg Clayton5160ce52013-03-27 23:08:40 +0000903 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000904 if (log)
905 log->Printf ("Target::%s\n", __FUNCTION__);
906
Johnny Chenedf50372011-09-23 21:21:43 +0000907 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000908 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000909 return true;
910 }
911
912 // Otherwise, it's an end to end operation.
913
Johnny Chen86364b42011-09-20 23:28:55 +0000914 if (!ProcessIsValid())
915 return false;
916
Johnny Chen01a67862011-10-14 00:42:25 +0000917 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000918 for (size_t i = 0; i < num_watchpoints; ++i)
919 {
Johnny Chen01a67862011-10-14 00:42:25 +0000920 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
921 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000922 return false;
923
Johnny Chen01a67862011-10-14 00:42:25 +0000924 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000925 if (rc.Fail())
926 return false;
927 }
Johnny Chen86364b42011-09-20 23:28:55 +0000928 return true; // Success!
929}
930
Johnny Chena4d6bc92012-02-25 06:44:30 +0000931// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
932bool
933Target::ClearAllWatchpointHitCounts ()
934{
Greg Clayton5160ce52013-03-27 23:08:40 +0000935 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +0000936 if (log)
937 log->Printf ("Target::%s\n", __FUNCTION__);
938
939 size_t num_watchpoints = m_watchpoint_list.GetSize();
940 for (size_t i = 0; i < num_watchpoints; ++i)
941 {
942 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
943 if (!wp_sp)
944 return false;
945
946 wp_sp->ResetHitCount();
947 }
948 return true; // Success!
949}
950
Enrico Granata5e3fe042015-02-11 00:37:54 +0000951// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
952bool
953Target::ClearAllWatchpointHistoricValues ()
954{
955 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
956 if (log)
957 log->Printf ("Target::%s\n", __FUNCTION__);
958
959 size_t num_watchpoints = m_watchpoint_list.GetSize();
960 for (size_t i = 0; i < num_watchpoints; ++i)
961 {
962 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
963 if (!wp_sp)
964 return false;
965
966 wp_sp->ResetHistoricValues();
967 }
968 return true; // Success!
969}
970
Johnny Chen01a67862011-10-14 00:42:25 +0000971// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +0000972// during these operations.
973bool
Johnny Chen01a67862011-10-14 00:42:25 +0000974Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000975{
Greg Clayton5160ce52013-03-27 23:08:40 +0000976 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000977 if (log)
978 log->Printf ("Target::%s\n", __FUNCTION__);
979
980 if (!ProcessIsValid())
981 return false;
982
Johnny Chen01a67862011-10-14 00:42:25 +0000983 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +0000984 for (size_t i = 0; i < num_watchpoints; ++i)
985 {
Johnny Chen01a67862011-10-14 00:42:25 +0000986 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
987 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000988 return false;
989
Johnny Chen01a67862011-10-14 00:42:25 +0000990 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000991 }
992 return true; // Success!
993}
994
Johnny Chen01a67862011-10-14 00:42:25 +0000995// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000996bool
Johnny Chen01a67862011-10-14 00:42:25 +0000997Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000998{
Greg Clayton5160ce52013-03-27 23:08:40 +0000999 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001000 if (log)
1001 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1002
1003 if (!ProcessIsValid())
1004 return false;
1005
Johnny Chen01a67862011-10-14 00:42:25 +00001006 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1007 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001008 {
Johnny Chen01a67862011-10-14 00:42:25 +00001009 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001010 if (rc.Success())
1011 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001012
Johnny Chenf04ee932011-09-22 18:04:58 +00001013 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001014 }
1015 return false;
1016}
1017
Johnny Chen01a67862011-10-14 00:42:25 +00001018// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001019bool
Johnny Chen01a67862011-10-14 00:42:25 +00001020Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001021{
Greg Clayton5160ce52013-03-27 23:08:40 +00001022 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001023 if (log)
1024 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1025
1026 if (!ProcessIsValid())
1027 return false;
1028
Johnny Chen01a67862011-10-14 00:42:25 +00001029 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1030 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001031 {
Johnny Chen01a67862011-10-14 00:42:25 +00001032 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001033 if (rc.Success())
1034 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001035
Johnny Chenf04ee932011-09-22 18:04:58 +00001036 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001037 }
1038 return false;
1039}
1040
Johnny Chen01a67862011-10-14 00:42:25 +00001041// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001042bool
Johnny Chen01a67862011-10-14 00:42:25 +00001043Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001044{
Greg Clayton5160ce52013-03-27 23:08:40 +00001045 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001046 if (log)
1047 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1048
Jim Inghamb0b45132013-07-02 02:09:46 +00001049 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
1050 if (watch_to_remove_sp == m_last_created_watchpoint)
1051 m_last_created_watchpoint.reset();
1052
Johnny Chen01a67862011-10-14 00:42:25 +00001053 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +00001054 {
Jim Ingham1b5792e2012-12-18 02:03:49 +00001055 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +00001056 return true;
1057 }
1058 return false;
1059}
1060
Johnny Chen01a67862011-10-14 00:42:25 +00001061// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +00001062bool
Johnny Chen01a67862011-10-14 00:42:25 +00001063Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001064{
Greg Clayton5160ce52013-03-27 23:08:40 +00001065 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +00001066 if (log)
1067 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1068
1069 if (!ProcessIsValid())
1070 return false;
1071
Johnny Chen01a67862011-10-14 00:42:25 +00001072 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1073 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001074 {
Johnny Chen01a67862011-10-14 00:42:25 +00001075 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001076 return true;
1077 }
1078 return false;
1079}
1080
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081ModuleSP
1082Target::GetExecutableModule ()
1083{
Aidan Doddsc0c83852015-05-08 09:36:31 +00001084 // search for the first executable in the module list
1085 for (size_t i = 0; i < m_images.GetSize(); ++i)
1086 {
1087 ModuleSP module_sp = m_images.GetModuleAtIndex (i);
1088 lldb_private::ObjectFile * obj = module_sp->GetObjectFile();
1089 if (obj == nullptr)
1090 continue;
1091 if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
1092 return module_sp;
1093 }
1094 // as fall back return the first module loaded
1095 return m_images.GetModuleAtIndex (0);
Greg Claytonaa149cb2011-08-11 02:48:45 +00001096}
1097
1098Module*
1099Target::GetExecutableModulePointer ()
1100{
Aidan Doddsc0c83852015-05-08 09:36:31 +00001101 return GetExecutableModule().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102}
1103
Enrico Granata17598482012-11-08 02:22:02 +00001104static void
1105LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1106{
1107 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001108 StreamString feedback_stream;
1109 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001110 {
Enrico Granata97303392013-05-21 00:00:30 +00001111 if (error.AsCString())
Greg Clayton44d93782014-01-27 23:43:24 +00001112 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001113 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1114 error.AsCString());
Enrico Granata17598482012-11-08 02:22:02 +00001115 }
Enrico Granatafe7295d2014-08-16 00:32:58 +00001116 if (feedback_stream.GetSize())
1117 target->GetDebugger().GetErrorFile()->Printf("%s\n",
1118 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001119}
1120
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001121void
Greg Claytonb35db632013-11-09 00:03:31 +00001122Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001123{
Greg Claytonb35db632013-11-09 00:03:31 +00001124 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001125 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126 m_images.Clear();
1127 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19 +00001128 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47 +00001129 m_ast_importer_ap.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001130}
1131
1132void
Greg Claytonb35db632013-11-09 00:03:31 +00001133Target::DidExec ()
1134{
1135 // When a process exec's we need to know about it so we can do some cleanup.
1136 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1137 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1138}
1139
1140void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001141Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1142{
1143 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001144 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145
1146 if (executable_sp.get())
1147 {
1148 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001149 "Target::SetExecutableModule (executable = '%s')",
1150 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001152 m_images.Append(executable_sp); // The first image is our executable file
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153
Jim Ingham5aee1622010-08-09 23:31:02 +00001154 // 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 +00001155 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001156 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001157 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001158 if (log)
1159 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1160 }
1161
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001163 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001165 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166 {
1167 executable_objfile->GetDependentModules(dependent_files);
1168 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1169 {
Greg Claytonded470d2011-03-19 01:12:21 +00001170 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1171 FileSpec platform_dependent_file_spec;
1172 if (m_platform_sp)
Steve Puccifc995722014-01-17 18:18:31 +00001173 m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001174 else
1175 platform_dependent_file_spec = dependent_file_spec;
1176
Greg Claytonb9a01b32012-02-26 05:51:37 +00001177 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1178 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179 if (image_module_sp.get())
1180 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 ObjectFile *objfile = image_module_sp->GetObjectFile();
1182 if (objfile)
1183 objfile->GetDependentModules(dependent_files);
1184 }
1185 }
1186 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 }
1188}
1189
1190
Jim Ingham5aee1622010-08-09 23:31:02 +00001191bool
1192Target::SetArchitecture (const ArchSpec &arch_spec)
1193{
Greg Clayton5160ce52013-03-27 23:08:40 +00001194 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callananbf4b7be2012-12-13 22:07:14 +00001195 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001196 {
Greg Clayton70512312012-05-08 01:45:38 +00001197 // If we haven't got a valid arch spec, or the architectures are
1198 // compatible, so just update the architecture. Architectures can be
1199 // equal, yet the triple OS and vendor might change, so we need to do
1200 // the assignment here just in case.
Greg Clayton32e0a752011-03-30 18:16:51 +00001201 m_arch = arch_spec;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001202 if (log)
1203 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 +00001204 return true;
1205 }
1206 else
1207 {
1208 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molendae1b68ad2012-12-05 00:25:49 +00001209 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +00001210 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 +00001211 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02 +00001212 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001213
Greg Claytonb35db632013-11-09 00:03:31 +00001214 ClearModules(true);
Jim Ingham5aee1622010-08-09 23:31:02 +00001215 // Need to do something about unsetting breakpoints.
1216
1217 if (executable_sp)
1218 {
Jason Molendae1b68ad2012-12-05 00:25:49 +00001219 if (log)
1220 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 +00001221 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1222 Error error = ModuleList::GetSharedModule (module_spec,
1223 executable_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001224 &GetExecutableSearchPaths(),
Greg Claytonb9a01b32012-02-26 05:51:37 +00001225 NULL,
1226 NULL);
Jim Ingham5aee1622010-08-09 23:31:02 +00001227
1228 if (!error.Fail() && executable_sp)
1229 {
1230 SetExecutableModule (executable_sp, true);
1231 return true;
1232 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001233 }
1234 }
Greg Clayton70512312012-05-08 01:45:38 +00001235 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001236}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001237
Tamas Berghammere9f4dfe2015-03-13 10:32:42 +00001238bool
1239Target::MergeArchitecture (const ArchSpec &arch_spec)
1240{
1241 if (arch_spec.IsValid())
1242 {
1243 if (m_arch.IsCompatibleMatch(arch_spec))
1244 {
1245 // The current target arch is compatible with "arch_spec", see if we
1246 // can improve our current architecture using bits from "arch_spec"
1247
1248 // Merge bits from arch_spec into "merged_arch" and set our architecture
1249 ArchSpec merged_arch (m_arch);
1250 merged_arch.MergeFrom (arch_spec);
1251 return SetArchitecture(merged_arch);
1252 }
1253 else
1254 {
1255 // The new architecture is different, we just need to replace it
1256 return SetArchitecture(arch_spec);
1257 }
1258 }
1259 return false;
1260}
1261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262void
Enrico Granataefe637d2012-11-08 19:16:03 +00001263Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001264{
1265}
1266
1267void
Enrico Granataefe637d2012-11-08 19:16:03 +00001268Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269{
1270 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001271 if (m_valid)
1272 {
1273 ModuleList my_module_list;
1274 my_module_list.Append(module_sp);
1275 LoadScriptingResourceForModule(module_sp, this);
1276 ModulesDidLoad (my_module_list);
1277 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278}
1279
1280void
Enrico Granataefe637d2012-11-08 19:16:03 +00001281Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001282{
1283 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001284 if (m_valid)
1285 {
1286 ModuleList my_module_list;
1287 my_module_list.Append(module_sp);
1288 ModulesDidUnload (my_module_list, false);
1289 }
Enrico Granata17598482012-11-08 02:22:02 +00001290}
1291
1292void
Enrico Granataefe637d2012-11-08 19:16:03 +00001293Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294{
Jim Inghame716ae02011-08-03 01:00:06 +00001295 // A module is replacing an already added module
Greg Clayton23f8c952014-03-24 23:10:19 +00001296 if (m_valid)
1297 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298}
1299
1300void
1301Target::ModulesDidLoad (ModuleList &module_list)
1302{
Greg Clayton23f8c952014-03-24 23:10:19 +00001303 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001304 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001305 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001306 if (m_process_sp)
1307 {
Andrew MacPhersoneb4d0602014-03-13 09:37:02 +00001308 m_process_sp->ModulesDidLoad (module_list);
Jason Molendaeef51062013-11-05 03:57:19 +00001309 }
Ilia Keb2c19a2015-03-10 21:59:55 +00001310 BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001311 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312}
1313
1314void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001315Target::SymbolsDidLoad (ModuleList &module_list)
1316{
Greg Clayton23f8c952014-03-24 23:10:19 +00001317 if (m_valid && module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001318 {
Jim Ingham31caf982013-06-04 23:01:35 +00001319 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001320 {
Jim Ingham31caf982013-06-04 23:01:35 +00001321 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1322 if (runtime)
1323 {
1324 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1325 objc_runtime->SymbolsDidLoad(module_list);
1326 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001327 }
Jim Ingham31caf982013-06-04 23:01:35 +00001328
Greg Clayton095eeaa2013-11-05 23:28:00 +00001329 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Ilia Keb2c19a2015-03-10 21:59:55 +00001330 BroadcastEvent (eBroadcastBitSymbolsLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001331 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001332}
1333
1334void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001335Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336{
Greg Clayton23f8c952014-03-24 23:10:19 +00001337 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001338 {
Greg Clayton8012cad2014-11-17 19:39:20 +00001339 UnloadModuleSections (module_list);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001340 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Ilia Keb2c19a2015-03-10 21:59:55 +00001341 BroadcastEvent (eBroadcastBitModulesUnloaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001342 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343}
1344
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001345bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001346Target::ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001347{
Greg Clayton67cc0632012-08-22 17:17:09 +00001348 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001349 {
1350 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001351 ModuleSpec module_spec (module_file_spec);
1352 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001353
1354 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1355 // black list.
1356 if (num_modules > 0)
1357 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001358 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001359 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001360 if (!ModuleIsExcludedForUnconstrainedSearches (matchingModules.GetModuleAtIndex(i)))
Jim Inghamc6674fd2011-10-28 23:14:11 +00001361 return false;
1362 }
1363 return true;
1364 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001365 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001366 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001367}
1368
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001369bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001370Target::ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001371{
Greg Clayton67cc0632012-08-22 17:17:09 +00001372 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001373 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001374 if (m_platform_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +00001375 return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001376 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001377 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001378}
1379
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380size_t
Greg Claytondb598232011-01-07 01:57:07 +00001381Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1382{
Greg Claytone72dfb32012-02-24 01:59:29 +00001383 SectionSP section_sp (addr.GetSection());
1384 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001385 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001386 // 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 +00001387 if (section_sp->IsEncrypted())
1388 {
Greg Clayton57f06302012-05-25 17:05:55 +00001389 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001390 return 0;
1391 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001392 ModuleSP module_sp (section_sp->GetModule());
1393 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001394 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001395 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1396 if (objfile)
1397 {
1398 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1399 addr.GetOffset(),
1400 dst,
1401 dst_len);
1402 if (bytes_read > 0)
1403 return bytes_read;
1404 else
1405 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1406 }
Greg Claytondb598232011-01-07 01:57:07 +00001407 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001408 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001409 }
1410 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001411 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001412 }
1413 else
Greg Claytondb598232011-01-07 01:57:07 +00001414 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001415
Greg Claytondb598232011-01-07 01:57:07 +00001416 return 0;
1417}
1418
1419size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001420Target::ReadMemory (const Address& addr,
1421 bool prefer_file_cache,
1422 void *dst,
1423 size_t dst_len,
1424 Error &error,
1425 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001428
Enrico Granata9128ee22011-09-06 19:20:51 +00001429 // if we end up reading this from process memory, we will fill this
1430 // with the actual load address
1431 if (load_addr_ptr)
1432 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1433
Greg Claytondb598232011-01-07 01:57:07 +00001434 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001435
1436 addr_t load_addr = LLDB_INVALID_ADDRESS;
1437 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001438 Address resolved_addr;
1439 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001440 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001441 SectionLoadList &section_load_list = GetSectionLoadList();
1442 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001443 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001444 // No sections are loaded, so we must assume we are not running
1445 // yet and anything we are given is a file address.
1446 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1447 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001448 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001449 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001450 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001451 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001452 // we have manually loaded some sections with "target modules load ..."
1453 // or because we have have a live process that has sections loaded
1454 // through the dynamic loader
1455 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001456 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001457 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001458 }
Greg Clayton357132e2011-03-26 19:14:58 +00001459 if (!resolved_addr.IsValid())
1460 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001461
Greg Claytonc749eb82011-07-11 05:12:02 +00001462
Greg Claytondb598232011-01-07 01:57:07 +00001463 if (prefer_file_cache)
1464 {
1465 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1466 if (bytes_read > 0)
1467 return bytes_read;
1468 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001469
Johnny Chen86364b42011-09-20 23:28:55 +00001470 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001471 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001472 if (load_addr == LLDB_INVALID_ADDRESS)
1473 load_addr = resolved_addr.GetLoadAddress (this);
1474
Greg Claytondda4f7b2010-06-30 23:03:03 +00001475 if (load_addr == LLDB_INVALID_ADDRESS)
1476 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001477 ModuleSP addr_module_sp (resolved_addr.GetModule());
1478 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001479 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Jim Ingham4af59612014-12-19 19:20:44 +00001480 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Jason Molenda7e589a62011-09-20 00:26:08 +00001481 resolved_addr.GetFileAddress(),
Jim Ingham4af59612014-12-19 19:20:44 +00001482 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknonw>"));
Greg Claytondda4f7b2010-06-30 23:03:03 +00001483 else
Daniel Malead01b2952012-11-29 21:49:15 +00001484 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001485 }
1486 else
1487 {
Greg Claytondb598232011-01-07 01:57:07 +00001488 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489 if (bytes_read != dst_len)
1490 {
1491 if (error.Success())
1492 {
1493 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001494 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001495 else
Daniel Malead01b2952012-11-29 21:49:15 +00001496 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 +00001497 }
1498 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001499 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001500 {
1501 if (load_addr_ptr)
1502 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001503 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001504 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001505 // If the address is not section offset we have an address that
1506 // doesn't resolve to any address in any currently loaded shared
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001507 // libraries and we failed to read memory so there isn't anything
Greg Claytondda4f7b2010-06-30 23:03:03 +00001508 // more we can do. If it is section offset, we might be able to
1509 // read cached memory from the object file.
1510 if (!resolved_addr.IsSectionOffset())
1511 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001512 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001513 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001514
Greg Claytonc749eb82011-07-11 05:12:02 +00001515 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001516 {
Greg Claytondb598232011-01-07 01:57:07 +00001517 // If we didn't already try and read from the object file cache, then
1518 // try it after failing to read from the process.
1519 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001520 }
1521 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001522}
1523
Greg Claytond16e1e52011-07-12 17:06:17 +00001524size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001525Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1526{
1527 char buf[256];
1528 out_str.clear();
1529 addr_t curr_addr = addr.GetLoadAddress(this);
1530 Address address(addr);
1531 while (1)
1532 {
1533 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1534 if (length == 0)
1535 break;
1536 out_str.append(buf, length);
1537 // If we got "length - 1" bytes, we didn't get the whole C string, we
1538 // need to read some more characters
1539 if (length == sizeof(buf) - 1)
1540 curr_addr += length;
1541 else
1542 break;
1543 address = Address(curr_addr);
1544 }
1545 return out_str.size();
1546}
1547
1548
1549size_t
1550Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1551{
1552 size_t total_cstr_len = 0;
1553 if (dst && dst_max_len)
1554 {
1555 result_error.Clear();
1556 // NULL out everything just to be safe
1557 memset (dst, 0, dst_max_len);
1558 Error error;
1559 addr_t curr_addr = addr.GetLoadAddress(this);
1560 Address address(addr);
Jason Molendaf0340c92014-09-03 22:30:54 +00001561
1562 // We could call m_process_sp->GetMemoryCacheLineSize() but I don't
1563 // think this really needs to be tied to the memory cache subsystem's
1564 // cache line size, so leave this as a fixed constant.
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001565 const size_t cache_line_size = 512;
Jason Molendaf0340c92014-09-03 22:30:54 +00001566
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001567 size_t bytes_left = dst_max_len - 1;
1568 char *curr_dst = dst;
1569
1570 while (bytes_left > 0)
1571 {
1572 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1573 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1574 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1575
1576 if (bytes_read == 0)
1577 {
1578 result_error = error;
1579 dst[total_cstr_len] = '\0';
1580 break;
1581 }
1582 const size_t len = strlen(curr_dst);
1583
1584 total_cstr_len += len;
1585
1586 if (len < bytes_to_read)
1587 break;
1588
1589 curr_dst += bytes_read;
1590 curr_addr += bytes_read;
1591 bytes_left -= bytes_read;
1592 address = Address(curr_addr);
1593 }
1594 }
1595 else
1596 {
1597 if (dst == NULL)
1598 result_error.SetErrorString("invalid arguments");
1599 else
1600 result_error.Clear();
1601 }
1602 return total_cstr_len;
1603}
1604
1605size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001606Target::ReadScalarIntegerFromMemory (const Address& addr,
1607 bool prefer_file_cache,
1608 uint32_t byte_size,
1609 bool is_signed,
1610 Scalar &scalar,
1611 Error &error)
1612{
1613 uint64_t uval;
1614
1615 if (byte_size <= sizeof(uval))
1616 {
1617 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1618 if (bytes_read == byte_size)
1619 {
1620 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001621 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001622 if (byte_size <= 4)
1623 scalar = data.GetMaxU32 (&offset, byte_size);
1624 else
1625 scalar = data.GetMaxU64 (&offset, byte_size);
1626
1627 if (is_signed)
1628 scalar.SignExtend(byte_size * 8);
1629 return bytes_read;
1630 }
1631 }
1632 else
1633 {
1634 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1635 }
1636 return 0;
1637}
1638
1639uint64_t
1640Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1641 bool prefer_file_cache,
1642 size_t integer_byte_size,
1643 uint64_t fail_value,
1644 Error &error)
1645{
1646 Scalar scalar;
1647 if (ReadScalarIntegerFromMemory (addr,
1648 prefer_file_cache,
1649 integer_byte_size,
1650 false,
1651 scalar,
1652 error))
1653 return scalar.ULongLong(fail_value);
1654 return fail_value;
1655}
1656
1657bool
1658Target::ReadPointerFromMemory (const Address& addr,
1659 bool prefer_file_cache,
1660 Error &error,
1661 Address &pointer_addr)
1662{
1663 Scalar scalar;
1664 if (ReadScalarIntegerFromMemory (addr,
1665 prefer_file_cache,
1666 m_arch.GetAddressByteSize(),
1667 false,
1668 scalar,
1669 error))
1670 {
1671 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1672 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1673 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001674 SectionLoadList &section_load_list = GetSectionLoadList();
1675 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001676 {
1677 // No sections are loaded, so we must assume we are not running
1678 // yet and anything we are given is a file address.
1679 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1680 }
1681 else
1682 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001683 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001684 // we have manually loaded some sections with "target modules load ..."
1685 // or because we have have a live process that has sections loaded
1686 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001687 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001688 }
1689 // We weren't able to resolve the pointer value, so just return
1690 // an address with no section
1691 if (!pointer_addr.IsValid())
1692 pointer_addr.SetOffset (pointer_vm_addr);
1693 return true;
1694
1695 }
1696 }
1697 return false;
1698}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699
1700ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001701Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001703 ModuleSP module_sp;
1704
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705 Error error;
1706
Jim Ingham4a94c912012-05-17 18:38:42 +00001707 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1708 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001709
Jim Ingham4a94c912012-05-17 18:38:42 +00001710 if (module_spec.GetUUID().IsValid())
1711 module_sp = m_images.FindFirstModule(module_spec);
1712
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001713 if (!module_sp)
1714 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001715 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1716 bool did_create_module = false;
1717
1718 // If there are image search path entries, try to use them first to acquire a suitable image.
1719 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001720 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001721 ModuleSpec transformed_spec (module_spec);
1722 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1723 {
1724 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1725 error = ModuleList::GetSharedModule (transformed_spec,
1726 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001727 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001728 &old_module_sp,
1729 &did_create_module);
1730 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001731 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001732
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001733 if (!module_sp)
1734 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001735 // If we have a UUID, we can check our global shared module list in case
1736 // we already have it. If we don't have a valid UUID, then we can't since
1737 // the path in "module_spec" will be a platform path, and we will need to
1738 // let the platform find that file. For example, we could be asking for
1739 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1740 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1741 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1742 // cache.
1743 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001744 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001745 // We have a UUID, it is OK to check the global module list...
1746 error = ModuleList::GetSharedModule (module_spec,
1747 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001748 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001749 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001750 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001751 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001752
1753 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001754 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001755 // The platform is responsible for finding and caching an appropriate
1756 // module in the shared module cache.
1757 if (m_platform_sp)
1758 {
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001759 error = m_platform_sp->GetSharedModule (module_spec,
1760 m_process_sp.get(),
1761 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001762 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001763 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001764 &did_create_module);
1765 }
1766 else
1767 {
1768 error.SetErrorString("no platform is currently set");
1769 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001770 }
1771 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772
Jim Ingham4a94c912012-05-17 18:38:42 +00001773 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1774 // module in the list already, and if there was, let's remove it.
1775 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001777 ObjectFile *objfile = module_sp->GetObjectFile();
1778 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001779 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001780 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001781 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001782 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1783 case ObjectFile::eTypeExecutable: /// A normal executable
1784 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1785 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1786 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1787 break;
1788 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1789 if (error_ptr)
1790 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1791 return ModuleSP();
1792 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1793 if (error_ptr)
1794 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1795 return ModuleSP();
1796 default:
1797 if (error_ptr)
1798 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1799 return ModuleSP();
1800 }
1801 // GetSharedModule is not guaranteed to find the old shared module, for instance
1802 // in the common case where you pass in the UUID, it is only going to find the one
1803 // module matching the UUID. In fact, it has no good way to know what the "old module"
1804 // relevant to this target is, since there might be many copies of a module with this file spec
1805 // in various running debug sessions, but only one of them will belong to this target.
1806 // So let's remove the UUID from the module list, and look in the target's module list.
1807 // Only do this if there is SOMETHING else in the module spec...
1808 if (!old_module_sp)
1809 {
1810 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001811 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001812 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1813 module_spec_copy.GetUUID().Clear();
1814
1815 ModuleList found_modules;
1816 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1817 if (num_found == 1)
1818 {
1819 old_module_sp = found_modules.GetModuleAtIndex(0);
1820 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001821 }
1822 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001823
1824 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1825 {
1826 m_images.ReplaceModule(old_module_sp, module_sp);
1827 Module *old_module_ptr = old_module_sp.get();
1828 old_module_sp.reset();
1829 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1830 }
1831 else
1832 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001833 }
Greg Clayton86e70cb2014-04-07 23:50:17 +00001834 else
1835 module_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001836 }
1837 }
1838 if (error_ptr)
1839 *error_ptr = error;
1840 return module_sp;
1841}
1842
1843
Greg Claytond9e416c2012-02-18 05:35:26 +00001844TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001845Target::CalculateTarget ()
1846{
Greg Claytond9e416c2012-02-18 05:35:26 +00001847 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848}
1849
Greg Claytond9e416c2012-02-18 05:35:26 +00001850ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851Target::CalculateProcess ()
1852{
Greg Claytond9e416c2012-02-18 05:35:26 +00001853 return ProcessSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854}
1855
Greg Claytond9e416c2012-02-18 05:35:26 +00001856ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857Target::CalculateThread ()
1858{
Greg Claytond9e416c2012-02-18 05:35:26 +00001859 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860}
1861
Jason Molendab57e4a12013-11-04 09:33:30 +00001862StackFrameSP
1863Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864{
Jason Molendab57e4a12013-11-04 09:33:30 +00001865 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866}
1867
1868void
Greg Clayton0603aa92010-10-04 01:05:56 +00001869Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870{
Greg Claytonc14ee322011-09-22 04:58:26 +00001871 exe_ctx.Clear();
1872 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873}
1874
1875PathMappingList &
1876Target::GetImageSearchPathList ()
1877{
1878 return m_image_search_paths;
1879}
1880
1881void
1882Target::ImageSearchPathsChanged
1883(
1884 const PathMappingList &path_list,
1885 void *baton
1886)
1887{
1888 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001889 ModuleSP exe_module_sp (target->GetExecutableModule());
1890 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001891 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892}
1893
1894ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001895Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001896{
Greg Clayton73da2442011-08-03 01:23:55 +00001897 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001898 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanan4bf80d52011-11-15 22:27:19 +00001899 {
Greg Clayton73da2442011-08-03 01:23:55 +00001900 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Claytone1cd1be2012-01-29 20:56:30 +00001901 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanan4bf80d52011-11-15 22:27:19 +00001902 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
Todd Fiala955fe6f2014-02-27 17:18:23 +00001903 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
Sean Callanan4bf80d52011-11-15 22:27:19 +00001904 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1905 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906 return m_scratch_ast_context_ap.get();
1907}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001908
Enrico Granatab5be2ff2015-09-08 22:09:19 +00001909TypeSystem*
1910Target::GetTypeSystemForLanguage (lldb::LanguageType language)
1911{
1912 switch (language)
1913 {
1914 case lldb::eLanguageTypeC:
1915 case lldb::eLanguageTypeC11:
1916 case lldb::eLanguageTypeC89:
1917 case lldb::eLanguageTypeC99:
1918 case lldb::eLanguageTypeC_plus_plus:
1919 case lldb::eLanguageTypeC_plus_plus_03:
1920 case lldb::eLanguageTypeC_plus_plus_11:
1921 case lldb::eLanguageTypeC_plus_plus_14:
1922 case lldb::eLanguageTypeObjC:
1923 case lldb::eLanguageTypeObjC_plus_plus:
1924 return GetScratchClangASTContext(true);
1925 default:
1926 return nullptr;
1927 }
1928}
1929
Sean Callanan686b2312011-11-16 18:20:47 +00001930ClangASTImporter *
1931Target::GetClangASTImporter()
1932{
1933 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1934
1935 if (!ast_importer)
1936 {
1937 ast_importer = new ClangASTImporter();
1938 m_ast_importer_ap.reset(ast_importer);
1939 }
1940
1941 return ast_importer;
1942}
1943
Greg Clayton99d0faf2010-11-18 23:32:35 +00001944void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001945Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00001946{
Greg Clayton6920b522012-08-22 18:39:03 +00001947 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001948}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001949
Greg Clayton99d0faf2010-11-18 23:32:35 +00001950void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001951Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001952{
Greg Clayton6920b522012-08-22 18:39:03 +00001953 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001954}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001955
Greg Claytonc859e2d2012-02-13 23:10:39 +00001956FileSpecList
1957Target::GetDefaultExecutableSearchPaths ()
1958{
Greg Clayton67cc0632012-08-22 17:17:09 +00001959 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1960 if (properties_sp)
1961 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00001962 return FileSpecList();
1963}
1964
Michael Sartaina7499c92013-07-01 19:45:50 +00001965FileSpecList
1966Target::GetDefaultDebugFileSearchPaths ()
1967{
1968 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1969 if (properties_sp)
1970 return properties_sp->GetDebugFileSearchPaths();
1971 return FileSpecList();
1972}
1973
Sean Callanan85054342015-04-03 15:39:47 +00001974FileSpecList
1975Target::GetDefaultClangModuleSearchPaths ()
1976{
1977 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1978 if (properties_sp)
1979 return properties_sp->GetClangModuleSearchPaths();
1980 return FileSpecList();
1981}
1982
Caroline Ticedaccaa92010-09-20 20:44:43 +00001983ArchSpec
1984Target::GetDefaultArchitecture ()
1985{
Greg Clayton67cc0632012-08-22 17:17:09 +00001986 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1987 if (properties_sp)
1988 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00001989 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00001990}
1991
1992void
Greg Clayton67cc0632012-08-22 17:17:09 +00001993Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001994{
Greg Clayton67cc0632012-08-22 17:17:09 +00001995 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1996 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00001997 {
1998 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 +00001999 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00002000 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002001}
2002
Greg Clayton0603aa92010-10-04 01:05:56 +00002003Target *
2004Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
2005{
2006 // The target can either exist in the "process" of ExecutionContext, or in
2007 // the "target_sp" member of SymbolContext. This accessor helper function
2008 // will get the target from one of these locations.
2009
2010 Target *target = NULL;
2011 if (sc_ptr != NULL)
2012 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:26 +00002013 if (target == NULL && exe_ctx_ptr)
2014 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00002015 return target;
2016}
2017
Jim Ingham1624a2d2014-05-05 02:26:40 +00002018ExpressionResults
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002019Target::EvaluateExpression
2020(
2021 const char *expr_cstr,
Jason Molendab57e4a12013-11-04 09:33:30 +00002022 StackFrame *frame,
Enrico Granata3372f582012-07-16 23:10:35 +00002023 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad4439aa2012-09-05 20:41:26 +00002024 const EvaluateExpressionOptions& options
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002025)
2026{
Enrico Granata97fca502012-09-18 17:43:16 +00002027 result_valobj_sp.reset();
2028
Jim Ingham8646d3c2014-05-05 02:47:44 +00002029 ExpressionResults execution_results = eExpressionSetupError;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002030
Greg Claytond1767f02011-12-08 02:13:16 +00002031 if (expr_cstr == NULL || expr_cstr[0] == '\0')
2032 return execution_results;
2033
Jim Ingham6026ca32011-05-12 02:06:14 +00002034 // We shouldn't run stop hooks in expressions.
2035 // Be sure to reset this if you return anywhere within this function.
2036 bool old_suppress_value = m_suppress_stop_hooks;
2037 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002038
2039 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002040
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002041 if (frame)
2042 {
2043 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002044 }
2045 else if (m_process_sp)
2046 {
2047 m_process_sp->CalculateExecutionContext(exe_ctx);
2048 }
2049 else
2050 {
2051 CalculateExecutionContext(exe_ctx);
2052 }
2053
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002054 // Make sure we aren't just trying to see the value of a persistent
2055 // variable (something like "$0")
Sean Callananbc8ac342015-09-04 20:49:51 +00002056 lldb::ExpressionVariableSP persistent_var_sp;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002057 // Only check for persistent variables the expression starts with a '$'
2058 if (expr_cstr[0] == '$')
Zachary Turner32abc6e2015-03-03 19:23:09 +00002059 persistent_var_sp = m_persistent_variables->GetVariable (expr_cstr);
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002060
2061 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002062 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002063 result_valobj_sp = persistent_var_sp->GetValueObject ();
Jim Ingham8646d3c2014-05-05 02:47:44 +00002064 execution_results = eExpressionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002065 }
2066 else
2067 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002068 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00002069 Error error;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002070 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Greg Clayton62afb9f2013-11-04 19:35:17 +00002071 options,
2072 expr_cstr,
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002073 prefix,
2074 result_valobj_sp,
Greg Clayton62afb9f2013-11-04 19:35:17 +00002075 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002076 }
Jim Ingham6026ca32011-05-12 02:06:14 +00002077
2078 m_suppress_stop_hooks = old_suppress_value;
2079
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002080 return execution_results;
2081}
2082
Zachary Turner32abc6e2015-03-03 19:23:09 +00002083ClangPersistentVariables &
2084Target::GetPersistentVariables()
2085{
2086 return *m_persistent_variables;
2087}
2088
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002089lldb::addr_t
2090Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2091{
2092 addr_t code_addr = load_addr;
2093 switch (m_arch.GetMachine())
2094 {
2095 case llvm::Triple::arm:
2096 case llvm::Triple::thumb:
2097 switch (addr_class)
2098 {
2099 case eAddressClassData:
2100 case eAddressClassDebug:
2101 return LLDB_INVALID_ADDRESS;
2102
2103 case eAddressClassUnknown:
2104 case eAddressClassInvalid:
2105 case eAddressClassCode:
2106 case eAddressClassCodeAlternateISA:
2107 case eAddressClassRuntime:
2108 // Check if bit zero it no set?
2109 if ((code_addr & 1ull) == 0)
2110 {
2111 // Bit zero isn't set, check if the address is a multiple of 2?
2112 if (code_addr & 2ull)
2113 {
2114 // The address is a multiple of 2 so it must be thumb, set bit zero
2115 code_addr |= 1ull;
2116 }
2117 else if (addr_class == eAddressClassCodeAlternateISA)
2118 {
2119 // We checked the address and the address claims to be the alternate ISA
2120 // which means thumb, so set bit zero.
2121 code_addr |= 1ull;
2122 }
2123 }
2124 break;
2125 }
2126 break;
2127
2128 default:
2129 break;
2130 }
2131 return code_addr;
2132}
2133
2134lldb::addr_t
2135Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2136{
2137 addr_t opcode_addr = load_addr;
2138 switch (m_arch.GetMachine())
2139 {
2140 case llvm::Triple::arm:
2141 case llvm::Triple::thumb:
2142 switch (addr_class)
2143 {
2144 case eAddressClassData:
2145 case eAddressClassDebug:
2146 return LLDB_INVALID_ADDRESS;
2147
2148 case eAddressClassInvalid:
2149 case eAddressClassUnknown:
2150 case eAddressClassCode:
2151 case eAddressClassCodeAlternateISA:
2152 case eAddressClassRuntime:
2153 opcode_addr &= ~(1ull);
2154 break;
2155 }
2156 break;
2157
2158 default:
2159 break;
2160 }
2161 return opcode_addr;
2162}
2163
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002164lldb::addr_t
2165Target::GetBreakableLoadAddress (lldb::addr_t addr)
2166{
2167 addr_t breakable_addr = addr;
2168 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
2169
2170 switch (m_arch.GetMachine())
2171 {
2172 default:
2173 break;
2174 case llvm::Triple::mips:
2175 case llvm::Triple::mipsel:
2176 case llvm::Triple::mips64:
2177 case llvm::Triple::mips64el:
2178 {
2179 addr_t function_start = 0;
2180 addr_t current_offset = 0;
2181 uint32_t loop_count = 0;
2182 Address resolved_addr;
2183 uint32_t arch_flags = m_arch.GetFlags ();
2184 bool IsMips16 = arch_flags & ArchSpec::eMIPSAse_mips16;
2185 bool IsMicromips = arch_flags & ArchSpec::eMIPSAse_micromips;
2186 SectionLoadList &section_load_list = GetSectionLoadList();
2187
2188 if (section_load_list.IsEmpty())
2189 // No sections are loaded, so we must assume we are not running yet
2190 // and need to operate only on file address.
2191 m_images.ResolveFileAddress (addr, resolved_addr);
2192 else
2193 section_load_list.ResolveLoadAddress(addr, resolved_addr);
2194
2195 // Get the function boundaries to make sure we don't scan back before the beginning of the current function.
2196 ModuleSP temp_addr_module_sp (resolved_addr.GetModule());
2197 if (temp_addr_module_sp)
2198 {
2199 SymbolContext sc;
2200 uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;
Greg Clayton6071e6f2015-08-26 22:57:51 +00002201 temp_addr_module_sp->ResolveSymbolContextForAddress(resolved_addr, resolve_scope, sc);
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002202 if (sc.function)
2203 {
2204 function_start = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(this);
2205 if (function_start == LLDB_INVALID_ADDRESS)
2206 function_start = sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
2207 }
2208 else if (sc.symbol)
2209 {
2210 Address sym_addr = sc.symbol->GetAddress();
2211 function_start = sym_addr.GetFileAddress();
2212 }
2213 current_offset = addr - function_start;
2214 }
2215
2216 // If breakpoint address is start of function then we dont have to do anything.
2217 if (current_offset == 0)
2218 return breakable_addr;
2219 else
2220 loop_count = current_offset / 2;
2221
2222 if (loop_count > 3)
2223 {
2224 // Scan previous 6 bytes
2225 if (IsMips16 | IsMicromips)
2226 loop_count = 3;
2227 // For mips-only, instructions are always 4 bytes, so scan previous 4 bytes only.
2228 else
2229 loop_count = 2;
2230 }
2231
2232 // Create Disassembler Instance
2233 lldb::DisassemblerSP disasm_sp (Disassembler::FindPlugin(m_arch, NULL, NULL));
2234
2235 ExecutionContext exe_ctx;
2236 CalculateExecutionContext(exe_ctx);
2237 InstructionList instruction_list;
2238 InstructionSP prev_insn;
2239 bool prefer_file_cache = true; // Read from file
2240 uint32_t inst_to_choose = 0;
2241
2242 for (uint32_t i = 1; i <= loop_count; i++)
2243 {
2244 // Adjust the address to read from.
2245 resolved_addr.Slide (-2);
2246 AddressRange range(resolved_addr, i*2);
2247 uint32_t insn_size = 0;
2248
Greg Clayton6071e6f2015-08-26 22:57:51 +00002249 disasm_sp->ParseInstructions (&exe_ctx, range, NULL, prefer_file_cache);
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002250
2251 uint32_t num_insns = disasm_sp->GetInstructionList().GetSize();
2252 if (num_insns)
2253 {
2254 prev_insn = disasm_sp->GetInstructionList().GetInstructionAtIndex(0);
2255 insn_size = prev_insn->GetOpcode().GetByteSize();
2256 if (i == 1 && insn_size == 2)
2257 {
2258 // This looks like a valid 2-byte instruction (but it could be a part of upper 4 byte instruction).
2259 instruction_list.Append(prev_insn);
2260 inst_to_choose = 1;
2261 }
2262 else if (i == 2)
2263 {
2264 // Here we may get one 4-byte instruction or two 2-byte instructions.
2265 if (num_insns == 2)
2266 {
2267 // Looks like there are two 2-byte instructions above our breakpoint target address.
2268 // Now the upper 2-byte instruction is either a valid 2-byte instruction or could be a part of it's upper 4-byte instruction.
2269 // In both cases we don't care because in this case lower 2-byte instruction is definitely a valid instruction
2270 // and whatever i=1 iteration has found out is true.
2271 inst_to_choose = 1;
2272 break;
2273 }
2274 else if (insn_size == 4)
2275 {
2276 // This instruction claims its a valid 4-byte instruction. But it could be a part of it's upper 4-byte instruction.
2277 // Lets try scanning upper 2 bytes to verify this.
2278 instruction_list.Append(prev_insn);
2279 inst_to_choose = 2;
2280 }
2281 }
2282 else if (i == 3)
2283 {
2284 if (insn_size == 4)
2285 // FIXME: We reached here that means instruction at [target - 4] has already claimed to be a 4-byte instruction,
2286 // and now instruction at [target - 6] is also claiming that it's a 4-byte instruction. This can not be true.
2287 // In this case we can not decide the valid previous instruction so we let lldb set the breakpoint at the address given by user.
2288 inst_to_choose = 0;
2289 else
2290 // This is straight-forward
2291 inst_to_choose = 2;
2292 break;
2293 }
2294 }
2295 else
2296 {
2297 // Decode failed, bytes do not form a valid instruction. So whatever previous iteration has found out is true.
2298 if (i > 1)
2299 {
2300 inst_to_choose = i - 1;
2301 break;
2302 }
2303 }
2304 }
2305
2306 // Check if we are able to find any valid instruction.
2307 if (inst_to_choose)
2308 {
2309 if (inst_to_choose > instruction_list.GetSize())
2310 inst_to_choose--;
2311 prev_insn = instruction_list.GetInstructionAtIndex(inst_to_choose - 1);
2312
2313 if (prev_insn->HasDelaySlot())
2314 {
2315 uint32_t shift_size = prev_insn->GetOpcode().GetByteSize();
2316 // Adjust the breakable address
2317 breakable_addr = addr - shift_size;
2318 if (log)
2319 log->Printf ("Target::%s Breakpoint at 0x%8.8" PRIx64 " is adjusted to 0x%8.8" PRIx64 " due to delay slot\n", __FUNCTION__, addr, breakable_addr);
2320 }
2321 }
2322 break;
2323 }
2324 }
2325 return breakable_addr;
2326}
2327
Greg Clayton9585fbf2013-03-19 00:20:55 +00002328SourceManager &
2329Target::GetSourceManager ()
2330{
2331 if (m_source_manager_ap.get() == NULL)
2332 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
2333 return *m_source_manager_ap;
2334}
2335
Sean Callanan9998acd2014-12-05 01:21:59 +00002336ClangModulesDeclVendor *
2337Target::GetClangModulesDeclVendor ()
2338{
2339 static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
2340
2341 {
2342 Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
2343
2344 if (!m_clang_modules_decl_vendor_ap)
2345 {
2346 m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
2347 }
2348 }
2349
2350 return m_clang_modules_decl_vendor_ap.get();
2351}
Greg Clayton9585fbf2013-03-19 00:20:55 +00002352
Greg Clayton44d93782014-01-27 23:43:24 +00002353Target::StopHookSP
2354Target::CreateStopHook ()
Jim Ingham9575d842011-03-11 03:53:59 +00002355{
2356 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton44d93782014-01-27 23:43:24 +00002357 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2358 m_stop_hooks[new_uid] = stop_hook_sp;
2359 return stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00002360}
2361
2362bool
2363Target::RemoveStopHookByID (lldb::user_id_t user_id)
2364{
2365 size_t num_removed;
2366 num_removed = m_stop_hooks.erase (user_id);
2367 if (num_removed == 0)
2368 return false;
2369 else
2370 return true;
2371}
2372
2373void
2374Target::RemoveAllStopHooks ()
2375{
2376 m_stop_hooks.clear();
2377}
2378
2379Target::StopHookSP
2380Target::GetStopHookByID (lldb::user_id_t user_id)
2381{
2382 StopHookSP found_hook;
2383
2384 StopHookCollection::iterator specified_hook_iter;
2385 specified_hook_iter = m_stop_hooks.find (user_id);
2386 if (specified_hook_iter != m_stop_hooks.end())
2387 found_hook = (*specified_hook_iter).second;
2388 return found_hook;
2389}
2390
2391bool
2392Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2393{
2394 StopHookCollection::iterator specified_hook_iter;
2395 specified_hook_iter = m_stop_hooks.find (user_id);
2396 if (specified_hook_iter == m_stop_hooks.end())
2397 return false;
2398
2399 (*specified_hook_iter).second->SetIsActive (active_state);
2400 return true;
2401}
2402
2403void
2404Target::SetAllStopHooksActiveState (bool active_state)
2405{
2406 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2407 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2408 {
2409 (*pos).second->SetIsActive (active_state);
2410 }
2411}
2412
2413void
2414Target::RunStopHooks ()
2415{
Jim Ingham6026ca32011-05-12 02:06:14 +00002416 if (m_suppress_stop_hooks)
2417 return;
2418
Jim Ingham9575d842011-03-11 03:53:59 +00002419 if (!m_process_sp)
2420 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002421
2422 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2423 // since in that case we do not want to run the stop-hooks
2424 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2425 return;
2426
Jim Ingham9575d842011-03-11 03:53:59 +00002427 if (m_stop_hooks.empty())
2428 return;
2429
2430 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2431
2432 // If there aren't any active stop hooks, don't bother either:
2433 bool any_active_hooks = false;
2434 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2435 {
2436 if ((*pos).second->IsActive())
2437 {
2438 any_active_hooks = true;
2439 break;
2440 }
2441 }
2442 if (!any_active_hooks)
2443 return;
2444
2445 CommandReturnObject result;
2446
2447 std::vector<ExecutionContext> exc_ctx_with_reasons;
2448 std::vector<SymbolContext> sym_ctx_with_reasons;
2449
2450 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2451 size_t num_threads = cur_threadlist.GetSize();
2452 for (size_t i = 0; i < num_threads; i++)
2453 {
2454 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2455 if (cur_thread_sp->ThreadStoppedForAReason())
2456 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002457 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002458 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2459 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2460 }
2461 }
2462
2463 // If no threads stopped for a reason, don't run the stop-hooks.
2464 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2465 if (num_exe_ctx == 0)
2466 return;
2467
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002468 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2469 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002470
2471 bool keep_going = true;
2472 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:27 +00002473 bool print_hook_header;
2474 bool print_thread_header;
2475
2476 if (num_exe_ctx == 1)
2477 print_thread_header = false;
2478 else
2479 print_thread_header = true;
2480
2481 if (m_stop_hooks.size() == 1)
2482 print_hook_header = false;
2483 else
2484 print_hook_header = true;
2485
Jim Ingham9575d842011-03-11 03:53:59 +00002486 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2487 {
2488 // result.Clear();
2489 StopHookSP cur_hook_sp = (*pos).second;
2490 if (!cur_hook_sp->IsActive())
2491 continue;
2492
2493 bool any_thread_matched = false;
2494 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2495 {
2496 if ((cur_hook_sp->GetSpecifier () == NULL
2497 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2498 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Ingham3d902922012-03-07 22:03:04 +00002499 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002500 {
2501 if (!hooks_ran)
2502 {
Jim Ingham9575d842011-03-11 03:53:59 +00002503 hooks_ran = true;
2504 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002505 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002506 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002507 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2508 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2509 NULL);
2510 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002511 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002512 else
Daniel Malead01b2952012-11-29 21:49:15 +00002513 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002514 any_thread_matched = true;
2515 }
2516
Jim Ingham381e25b2011-03-22 01:47:27 +00002517 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002518 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham26c7bf92014-10-11 00:38:27 +00002519
2520 CommandInterpreterRunOptions options;
2521 options.SetStopOnContinue (true);
2522 options.SetStopOnError (true);
2523 options.SetEchoCommands (false);
2524 options.SetPrintResults (true);
2525 options.SetAddToHistory (false);
2526
2527 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
2528 &exc_ctx_with_reasons[i],
2529 options,
Greg Clayton32e0a752011-03-30 18:16:51 +00002530 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002531
2532 // If the command started the target going again, we should bag out of
2533 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002534 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2535 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002536 {
Daniel Malead01b2952012-11-29 21:49:15 +00002537 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002538 keep_going = false;
2539 }
2540 }
2541 }
2542 }
Jason Molenda879cf772011-09-23 00:42:55 +00002543
Caroline Tice969ed3d2011-05-02 20:41:46 +00002544 result.GetImmediateOutputStream()->Flush();
2545 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002546}
2547
Greg Claytonfbb76342013-11-20 21:07:01 +00002548const TargetPropertiesSP &
2549Target::GetGlobalProperties()
2550{
2551 static TargetPropertiesSP g_settings_sp;
2552 if (!g_settings_sp)
2553 {
2554 g_settings_sp.reset (new TargetProperties (NULL));
2555 }
2556 return g_settings_sp;
2557}
2558
2559Error
2560Target::Install (ProcessLaunchInfo *launch_info)
2561{
2562 Error error;
2563 PlatformSP platform_sp (GetPlatform());
2564 if (platform_sp)
2565 {
2566 if (platform_sp->IsRemote())
2567 {
2568 if (platform_sp->IsConnected())
2569 {
2570 // Install all files that have an install path, and always install the
2571 // main executable when connected to a remote platform
2572 const ModuleList& modules = GetImages();
2573 const size_t num_images = modules.GetSize();
2574 for (size_t idx = 0; idx < num_images; ++idx)
2575 {
2576 const bool is_main_executable = idx == 0;
2577 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2578 if (module_sp)
2579 {
2580 FileSpec local_file (module_sp->GetFileSpec());
2581 if (local_file)
2582 {
2583 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2584 if (!remote_file)
2585 {
2586 if (is_main_executable) // TODO: add setting for always installing main executable???
2587 {
2588 // Always install the main executable
Chaoren Lind3173f32015-05-29 19:52:29 +00002589 remote_file = platform_sp->GetRemoteWorkingDirectory();
2590 remote_file.AppendPathComponent(module_sp->GetFileSpec().GetFilename().GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +00002591 }
2592 }
2593 if (remote_file)
2594 {
2595 error = platform_sp->Install(local_file, remote_file);
2596 if (error.Success())
2597 {
2598 module_sp->SetPlatformFileSpec(remote_file);
2599 if (is_main_executable)
2600 {
Chaoren Lind3173f32015-05-29 19:52:29 +00002601 platform_sp->SetFilePermissions(remote_file, 0700);
Greg Claytonfbb76342013-11-20 21:07:01 +00002602 if (launch_info)
2603 launch_info->SetExecutableFile(remote_file, false);
2604 }
2605 }
2606 else
2607 break;
2608 }
2609 }
2610 }
2611 }
2612 }
2613 }
2614 }
2615 return error;
2616}
Greg Clayton7b242382011-07-08 00:48:09 +00002617
Greg Claytond5944cd2013-12-06 01:12:00 +00002618bool
2619Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2620{
2621 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2622}
2623
2624bool
Matthew Gardinerc928de32014-10-22 07:22:56 +00002625Target::ResolveFileAddress (lldb::addr_t file_addr, Address &resolved_addr)
2626{
2627 return m_images.ResolveFileAddress(file_addr, resolved_addr);
2628}
2629
2630bool
Greg Claytond5944cd2013-12-06 01:12:00 +00002631Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2632{
2633 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2634 if (old_section_load_addr != new_section_load_addr)
2635 {
2636 uint32_t stop_id = 0;
2637 ProcessSP process_sp(GetProcessSP());
2638 if (process_sp)
2639 stop_id = process_sp->GetStopID();
2640 else
2641 stop_id = m_section_load_history.GetLastStopID();
2642 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2643 return true; // Return true if the section load address was changed...
2644 }
2645 return false; // Return false to indicate nothing changed
2646
2647}
2648
Greg Clayton8012cad2014-11-17 19:39:20 +00002649size_t
2650Target::UnloadModuleSections (const ModuleList &module_list)
2651{
2652 size_t section_unload_count = 0;
2653 size_t num_modules = module_list.GetSize();
2654 for (size_t i=0; i<num_modules; ++i)
2655 {
2656 section_unload_count += UnloadModuleSections (module_list.GetModuleAtIndex(i));
2657 }
2658 return section_unload_count;
2659}
2660
2661size_t
2662Target::UnloadModuleSections (const lldb::ModuleSP &module_sp)
2663{
2664 uint32_t stop_id = 0;
2665 ProcessSP process_sp(GetProcessSP());
2666 if (process_sp)
2667 stop_id = process_sp->GetStopID();
2668 else
2669 stop_id = m_section_load_history.GetLastStopID();
2670 SectionList *sections = module_sp->GetSectionList();
2671 size_t section_unload_count = 0;
2672 if (sections)
2673 {
2674 const uint32_t num_sections = sections->GetNumSections(0);
2675 for (uint32_t i = 0; i < num_sections; ++i)
2676 {
2677 section_unload_count += m_section_load_history.SetSectionUnloaded(stop_id, sections->GetSectionAtIndex(i));
2678 }
2679 }
2680 return section_unload_count;
2681}
2682
Greg Claytond5944cd2013-12-06 01:12:00 +00002683bool
2684Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2685{
2686 uint32_t stop_id = 0;
2687 ProcessSP process_sp(GetProcessSP());
2688 if (process_sp)
2689 stop_id = process_sp->GetStopID();
2690 else
2691 stop_id = m_section_load_history.GetLastStopID();
2692 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2693}
2694
2695bool
2696Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2697{
2698 uint32_t stop_id = 0;
2699 ProcessSP process_sp(GetProcessSP());
2700 if (process_sp)
2701 stop_id = process_sp->GetStopID();
2702 else
2703 stop_id = m_section_load_history.GetLastStopID();
2704 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2705}
2706
2707void
2708Target::ClearAllLoadedSections ()
2709{
2710 m_section_load_history.Clear();
2711}
2712
Greg Claytonb09c5382013-12-13 17:20:18 +00002713
2714Error
Greg Clayton8012cad2014-11-17 19:39:20 +00002715Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
Greg Claytonb09c5382013-12-13 17:20:18 +00002716{
2717 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00002718 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
2719
2720 if (log)
2721 log->Printf ("Target::%s() called for %s", __FUNCTION__, launch_info.GetExecutableFile().GetPath().c_str ());
2722
Greg Claytonb09c5382013-12-13 17:20:18 +00002723 StateType state = eStateInvalid;
2724
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002725 // Scope to temporarily get the process state in case someone has manually
2726 // remotely connected already to a process and we can skip the platform
2727 // launching.
2728 {
2729 ProcessSP process_sp (GetProcessSP());
2730
2731 if (process_sp)
Todd Fialaac33cc92014-10-09 01:02:08 +00002732 {
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002733 state = process_sp->GetState();
Todd Fialaac33cc92014-10-09 01:02:08 +00002734 if (log)
2735 log->Printf ("Target::%s the process exists, and its current state is %s", __FUNCTION__, StateAsCString (state));
2736 }
2737 else
2738 {
2739 if (log)
2740 log->Printf ("Target::%s the process instance doesn't currently exist.", __FUNCTION__);
2741 }
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002742 }
2743
Greg Claytonb09c5382013-12-13 17:20:18 +00002744 launch_info.GetFlags().Set (eLaunchFlagDebug);
2745
2746 // Get the value of synchronous execution here. If you wait till after you have started to
2747 // run, then you could have hit a breakpoint, whose command might switch the value, and
2748 // then you'll pick up that incorrect value.
2749 Debugger &debugger = GetDebugger();
2750 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2751
2752 PlatformSP platform_sp (GetPlatform());
2753
2754 // Finalize the file actions, and if none were given, default to opening
2755 // up a pseudo terminal
2756 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
Todd Fiala75f47c32014-10-11 21:42:09 +00002757 if (log)
2758 log->Printf ("Target::%s have platform=%s, platform_sp->IsHost()=%s, default_to_use_pty=%s",
2759 __FUNCTION__,
2760 platform_sp ? "true" : "false",
2761 platform_sp ? (platform_sp->IsHost () ? "true" : "false") : "n/a",
2762 default_to_use_pty ? "true" : "false");
2763
Greg Claytonb09c5382013-12-13 17:20:18 +00002764 launch_info.FinalizeFileActions (this, default_to_use_pty);
2765
2766 if (state == eStateConnected)
2767 {
2768 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2769 {
2770 error.SetErrorString("can't launch in tty when launching through a remote connection");
2771 return error;
2772 }
2773 }
2774
2775 if (!launch_info.GetArchitecture().IsValid())
2776 launch_info.GetArchitecture() = GetArchitecture();
Todd Fiala015d8182014-07-22 23:41:36 +00002777
2778 // 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 +00002779 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
2780 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002781 if (log)
2782 log->Printf ("Target::%s asking the platform to debug the process", __FUNCTION__);
2783
Greg Clayton5df78fa2015-05-23 03:54:53 +00002784 // Get a weak pointer to the previous process if we have one
2785 ProcessWP process_wp;
2786 if (m_process_sp)
2787 process_wp = m_process_sp;
Greg Claytonb09c5382013-12-13 17:20:18 +00002788 m_process_sp = GetPlatform()->DebugProcess (launch_info,
2789 debugger,
2790 this,
Greg Claytonb09c5382013-12-13 17:20:18 +00002791 error);
Greg Clayton5df78fa2015-05-23 03:54:53 +00002792
2793 // Cleanup the old process since someone might still have a strong
2794 // reference to this process and we would like to allow it to cleanup
2795 // as much as it can without the object being destroyed. We try to
2796 // lock the shared pointer and if that works, then someone else still
2797 // has a strong reference to the process.
2798
2799 ProcessSP old_process_sp(process_wp.lock());
2800 if (old_process_sp)
2801 old_process_sp->Finalize();
Greg Claytonb09c5382013-12-13 17:20:18 +00002802 }
2803 else
2804 {
Todd Fialaac33cc92014-10-09 01:02:08 +00002805 if (log)
2806 log->Printf ("Target::%s the platform doesn't know how to debug a process, getting a process plugin to do this for us.", __FUNCTION__);
2807
Greg Claytonb09c5382013-12-13 17:20:18 +00002808 if (state == eStateConnected)
2809 {
2810 assert(m_process_sp);
2811 }
2812 else
2813 {
Todd Fiala015d8182014-07-22 23:41:36 +00002814 // Use a Process plugin to construct the process.
Greg Claytonb09c5382013-12-13 17:20:18 +00002815 const char *plugin_name = launch_info.GetProcessPluginName();
Greg Clayton8012cad2014-11-17 19:39:20 +00002816 CreateProcess (launch_info.GetListenerForProcess(debugger), plugin_name, NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002817 }
Todd Fiala015d8182014-07-22 23:41:36 +00002818
2819 // Since we didn't have a platform launch the process, launch it here.
Greg Claytonb09c5382013-12-13 17:20:18 +00002820 if (m_process_sp)
2821 error = m_process_sp->Launch (launch_info);
2822 }
2823
2824 if (!m_process_sp)
2825 {
2826 if (error.Success())
2827 error.SetErrorString("failed to launch or debug process");
2828 return error;
2829 }
2830
2831 if (error.Success())
2832 {
Ilia K064e69f2015-03-23 21:16:25 +00002833 if (synchronous_execution || launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
Greg Claytonb09c5382013-12-13 17:20:18 +00002834 {
Greg Clayton44d93782014-01-27 23:43:24 +00002835 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
Zachary Turnere6d213a2015-03-26 20:41:14 +00002836 if (!hijack_listener_sp)
2837 {
2838 hijack_listener_sp.reset(new Listener("lldb.Target.Launch.hijack"));
2839 launch_info.SetHijackListener(hijack_listener_sp);
2840 m_process_sp->HijackProcessEvents(hijack_listener_sp.get());
2841 }
Todd Fialaac33cc92014-10-09 01:02:08 +00002842
Ilia K38810f42015-05-20 10:15:47 +00002843 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get(), NULL);
Greg Claytonb09c5382013-12-13 17:20:18 +00002844
2845 if (state == eStateStopped)
2846 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00002847 if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Claytonb09c5382013-12-13 17:20:18 +00002848 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00002849 if (synchronous_execution)
Greg Claytonb09c5382013-12-13 17:20:18 +00002850 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00002851 error = m_process_sp->PrivateResume();
2852 if (error.Success())
Greg Claytonb09c5382013-12-13 17:20:18 +00002853 {
Ilia K064e69f2015-03-23 21:16:25 +00002854 state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get(), stream);
2855 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2856 if (!StateIsStoppedState(state, must_be_alive))
2857 {
2858 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
2859 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002860 }
2861 }
Ilia K064e69f2015-03-23 21:16:25 +00002862 else
2863 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00002864 m_process_sp->RestoreProcessEvents();
2865 error = m_process_sp->PrivateResume();
Zachary Turnere6d213a2015-03-26 20:41:14 +00002866 }
2867 if (!error.Success())
2868 {
Ilia K064e69f2015-03-23 21:16:25 +00002869 Error error2;
2870 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
2871 error = error2;
2872 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002873 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002874 }
Greg Clayton40286e02014-04-30 20:29:09 +00002875 else if (state == eStateExited)
2876 {
Zachary Turner10687b02014-10-20 17:46:43 +00002877 bool with_shell = !!launch_info.GetShell();
Greg Clayton40286e02014-04-30 20:29:09 +00002878 const int exit_status = m_process_sp->GetExitStatus();
2879 const char *exit_desc = m_process_sp->GetExitDescription();
2880#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'."
2881 if (exit_desc && exit_desc[0])
2882 {
2883 if (with_shell)
2884 error.SetErrorStringWithFormat ("process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, exit_status, exit_desc);
2885 else
2886 error.SetErrorStringWithFormat ("process exited with status %i (%s)", exit_status, exit_desc);
2887 }
2888 else
2889 {
2890 if (with_shell)
2891 error.SetErrorStringWithFormat ("process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
2892 else
2893 error.SetErrorStringWithFormat ("process exited with status %i", exit_status);
2894 }
2895 }
Greg Claytonb09c5382013-12-13 17:20:18 +00002896 else
2897 {
2898 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2899 }
2900 }
Greg Clayton44d93782014-01-27 23:43:24 +00002901 m_process_sp->RestoreProcessEvents ();
Greg Claytonb09c5382013-12-13 17:20:18 +00002902 }
2903 else
2904 {
Greg Clayton44d93782014-01-27 23:43:24 +00002905 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002906 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002907 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002908 }
2909 return error;
2910}
Oleksiy Vyalov37386142015-02-10 22:49:57 +00002911
2912Error
2913Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
2914{
2915 auto state = eStateInvalid;
2916 auto process_sp = GetProcessSP ();
2917 if (process_sp)
2918 {
2919 state = process_sp->GetState ();
2920 if (process_sp->IsAlive () && state != eStateConnected)
2921 {
2922 if (state == eStateAttaching)
2923 return Error ("process attach is in progress");
2924 return Error ("a process is already being debugged");
2925 }
2926 }
2927
2928 ListenerSP hijack_listener_sp (new Listener ("lldb.Target.Attach.attach.hijack"));
2929 attach_info.SetHijackListener (hijack_listener_sp);
2930
2931 const ModuleSP old_exec_module_sp = GetExecutableModule ();
2932
2933 // If no process info was specified, then use the target executable
2934 // name as the process to attach to by default
2935 if (!attach_info.ProcessInfoSpecified ())
2936 {
2937 if (old_exec_module_sp)
2938 attach_info.GetExecutableFile ().GetFilename () = old_exec_module_sp->GetPlatformFileSpec ().GetFilename ();
2939
2940 if (!attach_info.ProcessInfoSpecified ())
2941 {
2942 return Error ("no process specified, create a target with a file, or specify the --pid or --name");
2943 }
2944 }
2945
2946 const auto platform_sp = GetDebugger ().GetPlatformList ().GetSelectedPlatform ();
2947
2948 Error error;
2949 if (state != eStateConnected && platform_sp != nullptr && platform_sp->CanDebugProcess ())
2950 {
2951 SetPlatform (platform_sp);
2952 process_sp = platform_sp->Attach (attach_info, GetDebugger (), this, error);
2953 }
2954 else
2955 {
2956 if (state != eStateConnected)
2957 {
2958 const char *plugin_name = attach_info.GetProcessPluginName ();
2959 process_sp = CreateProcess (attach_info.GetListenerForProcess (GetDebugger ()), plugin_name, nullptr);
2960 if (process_sp == nullptr)
2961 {
2962 error.SetErrorStringWithFormat ("failed to create process using plugin %s", (plugin_name) ? plugin_name : "null");
2963 return error;
2964 }
2965 }
2966 process_sp->HijackProcessEvents (hijack_listener_sp.get ());
2967 error = process_sp->Attach (attach_info);
2968 }
2969
2970 if (error.Success () && process_sp)
2971 {
2972 state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener ().get (), stream);
2973 process_sp->RestoreProcessEvents ();
2974
2975 if (state != eStateStopped)
2976 {
2977 const char *exit_desc = process_sp->GetExitDescription ();
2978 if (exit_desc)
2979 error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);
2980 else
2981 error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");
Jason Molendaede31932015-04-17 05:01:58 +00002982 process_sp->Destroy (false);
Oleksiy Vyalov37386142015-02-10 22:49:57 +00002983 }
2984 }
2985 return error;
2986}
2987
Jim Ingham9575d842011-03-11 03:53:59 +00002988//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00002989// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00002990//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00002991Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2992 UserID (uid),
2993 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00002994 m_commands (),
2995 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00002996 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002997 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00002998{
2999}
3000
3001Target::StopHook::StopHook (const StopHook &rhs) :
3002 UserID (rhs.GetID()),
3003 m_target_sp (rhs.m_target_sp),
3004 m_commands (rhs.m_commands),
3005 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00003006 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003007 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00003008{
3009 if (rhs.m_thread_spec_ap.get() != NULL)
3010 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
3011}
3012
3013
3014Target::StopHook::~StopHook ()
3015{
3016}
3017
3018void
Zachary Turner32abc6e2015-03-03 19:23:09 +00003019Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier)
3020{
3021 m_specifier_sp.reset(specifier);
3022}
3023
3024void
Jim Ingham9575d842011-03-11 03:53:59 +00003025Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
3026{
3027 m_thread_spec_ap.reset (specifier);
3028}
3029
3030
3031void
3032Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
3033{
3034 int indent_level = s->GetIndentLevel();
3035
3036 s->SetIndentLevel(indent_level + 2);
3037
Daniel Malead01b2952012-11-29 21:49:15 +00003038 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00003039 if (m_active)
3040 s->Indent ("State: enabled\n");
3041 else
3042 s->Indent ("State: disabled\n");
3043
3044 if (m_specifier_sp)
3045 {
3046 s->Indent();
3047 s->PutCString ("Specifier:\n");
3048 s->SetIndentLevel (indent_level + 4);
3049 m_specifier_sp->GetDescription (s, level);
3050 s->SetIndentLevel (indent_level + 2);
3051 }
3052
3053 if (m_thread_spec_ap.get() != NULL)
3054 {
3055 StreamString tmp;
3056 s->Indent("Thread:\n");
3057 m_thread_spec_ap->GetDescription (&tmp, level);
3058 s->SetIndentLevel (indent_level + 4);
3059 s->Indent (tmp.GetData());
3060 s->PutCString ("\n");
3061 s->SetIndentLevel (indent_level + 2);
3062 }
3063
3064 s->Indent ("Commands: \n");
3065 s->SetIndentLevel (indent_level + 4);
3066 uint32_t num_commands = m_commands.GetSize();
3067 for (uint32_t i = 0; i < num_commands; i++)
3068 {
3069 s->Indent(m_commands.GetStringAtIndex(i));
3070 s->PutCString ("\n");
3071 }
3072 s->SetIndentLevel (indent_level);
3073}
3074
Greg Clayton67cc0632012-08-22 17:17:09 +00003075//--------------------------------------------------------------
3076// class TargetProperties
3077//--------------------------------------------------------------
3078
3079OptionEnumValueElement
3080lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00003081{
Greg Clayton67cc0632012-08-22 17:17:09 +00003082 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
3083 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
3084 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
3085 { 0, NULL, NULL }
3086};
Caroline Ticedaccaa92010-09-20 20:44:43 +00003087
Greg Clayton1f746072012-08-29 21:13:06 +00003088static OptionEnumValueElement
3089g_inline_breakpoint_enums[] =
3090{
3091 { 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."},
3092 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
3093 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
3094 { 0, NULL, NULL }
3095};
3096
Jim Ingham0f063ba2013-03-02 00:26:47 +00003097typedef enum x86DisassemblyFlavor
3098{
3099 eX86DisFlavorDefault,
3100 eX86DisFlavorIntel,
3101 eX86DisFlavorATT
3102} x86DisassemblyFlavor;
3103
3104static OptionEnumValueElement
3105g_x86_dis_flavor_value_types[] =
3106{
3107 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
3108 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
3109 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
3110 { 0, NULL, NULL }
3111};
3112
Enrico Granata397ddd52013-05-21 20:13:34 +00003113static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00003114g_hex_immediate_style_values[] =
3115{
3116 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
3117 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
3118 { 0, NULL, NULL }
3119};
3120
3121static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00003122g_load_script_from_sym_file_values[] =
3123{
3124 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
3125 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
3126 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
3127 { 0, NULL, NULL }
3128};
3129
Greg Claytonfd814c52013-08-13 01:42:25 +00003130
3131static OptionEnumValueElement
3132g_memory_module_load_level_values[] =
3133{
Greg Clayton86eac942013-08-13 21:32:34 +00003134 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00003135 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
3136 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
3137 { 0, NULL, NULL }
3138};
3139
Greg Clayton67cc0632012-08-22 17:17:09 +00003140static PropertyDefinition
3141g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00003142{
Greg Clayton67cc0632012-08-22 17:17:09 +00003143 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
Ilia K055ad9b2015-05-18 13:41:01 +00003144 { "move-to-nearest-code" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Move breakpoints to nearest code." },
Dawn Perchike0c96ac2015-07-30 22:10:08 +00003145 { "language" , OptionValue::eTypeLanguage , false, eLanguageTypeUnknown , NULL, NULL, "The language to use when interpreting expressions entered in commands." },
Greg Clayton67cc0632012-08-22 17:17:09 +00003146 { "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 +00003147 { "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 +00003148 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
3149 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
Jim Ingham0ca778e2015-09-15 18:03:00 +00003150 { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings are used to track the change of location between a source file when built, and "
Greg Clayton67cc0632012-08-22 17:17:09 +00003151 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
3152 "some part (starting at the root) of the path to the file when it was built, "
3153 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
3154 "Each element of the array is checked in order and the first one that results in a match wins." },
3155 { "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 +00003156 { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating debug symbol files." },
Sean Callanan85054342015-04-03 15:39:47 +00003157 { "clang-module-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating modules for Clang." },
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003158 { "auto-import-clang-modules" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Automatically load Clang modules referred to by the program." },
Greg Clayton67cc0632012-08-22 17:17:09 +00003159 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
3160 { "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 +00003161 { "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 +00003162 { "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 +00003163 { "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." },
3164 { "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 +00003165 { "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." },
3166 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
3167 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
3168 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
3169 { "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 +00003170 { "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 +00003171 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
3172 { "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 +00003173 { "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 +00003174 "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. "
Jim Ingham63733852015-06-16 21:39:56 +00003175 "Usually this is limited to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
Greg Clayton1f746072012-08-29 21:13:06 +00003176 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
Todd Fialaad6eee62014-09-24 19:59:13 +00003177 "Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers "
3178 "and find that setting breakpoints is slow, then you can change this setting to headers. "
3179 "This setting allows you to control exactly which strategy is used when setting "
Greg Clayton1f746072012-08-29 21:13:06 +00003180 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00003181 // 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.
3182 { "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 +00003183 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
3184 { "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 +00003185 { "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 +00003186 { "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 +00003187 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
3188 "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. "
3189 "This setting helps users control how much information gets loaded when loading modules from memory."
3190 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
3191 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
3192 "'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 +00003193 { "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 +00003194 { "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 +00003195 { "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." },
Ewan Crawford78baa192015-05-13 09:18:18 +00003196 { "non-stop-mode" , OptionValue::eTypeBoolean , false, 0, NULL, NULL, "Disable lock-step debugging, instead control threads independently." },
Greg Clayton67cc0632012-08-22 17:17:09 +00003197 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
3198};
Enrico Granata560558e2015-02-11 02:35:39 +00003199
Greg Clayton67cc0632012-08-22 17:17:09 +00003200enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00003201{
Greg Clayton67cc0632012-08-22 17:17:09 +00003202 ePropertyDefaultArch,
Ilia K055ad9b2015-05-18 13:41:01 +00003203 ePropertyMoveToNearestCode,
Dawn Perchik23b1dec2015-07-21 22:05:07 +00003204 ePropertyLanguage,
Greg Clayton67cc0632012-08-22 17:17:09 +00003205 ePropertyExprPrefix,
3206 ePropertyPreferDynamic,
3207 ePropertyEnableSynthetic,
3208 ePropertySkipPrologue,
3209 ePropertySourceMap,
3210 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00003211 ePropertyDebugFileSearchPaths,
Sean Callanan85054342015-04-03 15:39:47 +00003212 ePropertyClangModuleSearchPaths,
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003213 ePropertyAutoImportClangModules,
Greg Clayton67cc0632012-08-22 17:17:09 +00003214 ePropertyMaxChildrenCount,
3215 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00003216 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00003217 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00003218 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00003219 ePropertyRunArgs,
3220 ePropertyEnvVars,
3221 ePropertyInheritEnv,
3222 ePropertyInputPath,
3223 ePropertyOutputPath,
3224 ePropertyErrorPath,
Jim Ingham106d0282014-06-25 02:32:56 +00003225 ePropertyDetachOnError,
Greg Clayton67cc0632012-08-22 17:17:09 +00003226 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00003227 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00003228 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00003229 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00003230 ePropertyUseHexImmediates,
3231 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003232 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00003233 ePropertyLoadScriptFromSymbolFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00003234 ePropertyMemoryModuleLoadLevel,
Jason Molendaa4bea722014-02-14 05:06:49 +00003235 ePropertyDisplayExpressionsInCrashlogs,
Enrico Granata560558e2015-02-11 02:35:39 +00003236 ePropertyTrapHandlerNames,
Ewan Crawford78baa192015-05-13 09:18:18 +00003237 ePropertyDisplayRuntimeSupportValues,
3238 ePropertyNonStopModeEnabled
Greg Clayton67cc0632012-08-22 17:17:09 +00003239};
Caroline Ticedaccaa92010-09-20 20:44:43 +00003240
Caroline Ticedaccaa92010-09-20 20:44:43 +00003241
Greg Clayton67cc0632012-08-22 17:17:09 +00003242class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00003243{
Greg Clayton67cc0632012-08-22 17:17:09 +00003244public:
3245 TargetOptionValueProperties (const ConstString &name) :
3246 OptionValueProperties (name),
3247 m_target (NULL),
3248 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003249 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00003250 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00003251
Greg Clayton67cc0632012-08-22 17:17:09 +00003252 // This constructor is used when creating TargetOptionValueProperties when it
3253 // is part of a new lldb_private::Target instance. It will copy all current
3254 // global property values as needed
3255 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
3256 OptionValueProperties(*target_properties_sp->GetValueProperties()),
3257 m_target (target),
3258 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003259 {
Greg Clayton67cc0632012-08-22 17:17:09 +00003260 }
3261
3262 virtual const Property *
3263 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
3264 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003265 // When getting the value for a key from the target options, we will always
Greg Clayton67cc0632012-08-22 17:17:09 +00003266 // try and grab the setting from the current target if there is one. Else we just
3267 // use the one from this instance.
3268 if (idx == ePropertyEnvVars)
3269 GetHostEnvironmentIfNeeded ();
3270
3271 if (exe_ctx)
3272 {
3273 Target *target = exe_ctx->GetTargetPtr();
3274 if (target)
3275 {
3276 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
3277 if (this != target_properties)
3278 return target_properties->ProtectedGetPropertyAtIndex (idx);
3279 }
3280 }
3281 return ProtectedGetPropertyAtIndex (idx);
3282 }
Enrico Granata84a53df2013-05-20 22:29:23 +00003283
3284 lldb::TargetSP
3285 GetTargetSP ()
3286 {
3287 return m_target->shared_from_this();
3288 }
3289
Greg Clayton67cc0632012-08-22 17:17:09 +00003290protected:
3291
3292 void
3293 GetHostEnvironmentIfNeeded () const
3294 {
3295 if (!m_got_host_env)
3296 {
3297 if (m_target)
3298 {
3299 m_got_host_env = true;
3300 const uint32_t idx = ePropertyInheritEnv;
3301 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
3302 {
3303 PlatformSP platform_sp (m_target->GetPlatform());
3304 if (platform_sp)
3305 {
3306 StringList env;
3307 if (platform_sp->GetEnvironment(env))
3308 {
3309 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
3310 if (env_dict)
3311 {
3312 const bool can_replace = false;
3313 const size_t envc = env.GetSize();
3314 for (size_t idx=0; idx<envc; idx++)
3315 {
3316 const char *env_entry = env.GetStringAtIndex (idx);
3317 if (env_entry)
3318 {
3319 const char *equal_pos = ::strchr(env_entry, '=');
3320 ConstString key;
3321 // It is ok to have environment variables with no values
3322 const char *value = NULL;
3323 if (equal_pos)
3324 {
3325 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
3326 if (equal_pos[1])
3327 value = equal_pos + 1;
3328 }
3329 else
3330 {
3331 key.SetCString(env_entry);
3332 }
3333 // Don't allow existing keys to be replaced with ones we get from the platform environment
3334 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
3335 }
3336 }
3337 }
3338 }
3339 }
3340 }
3341 }
3342 }
3343 }
3344 Target *m_target;
3345 mutable bool m_got_host_env;
3346};
3347
Greg Claytonfbb76342013-11-20 21:07:01 +00003348//----------------------------------------------------------------------
3349// TargetProperties
3350//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00003351TargetProperties::TargetProperties (Target *target) :
Ilia K8f37ca52015-02-13 14:31:06 +00003352 Properties (),
3353 m_launch_info ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003354{
3355 if (target)
3356 {
3357 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Ilia K8f37ca52015-02-13 14:31:06 +00003358
3359 // Set callbacks to update launch_info whenever "settins set" updated any of these properties
3360 m_collection_sp->SetValueChangedCallback(ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this);
3361 m_collection_sp->SetValueChangedCallback(ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this);
3362 m_collection_sp->SetValueChangedCallback(ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this);
3363 m_collection_sp->SetValueChangedCallback(ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, this);
3364 m_collection_sp->SetValueChangedCallback(ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, this);
3365 m_collection_sp->SetValueChangedCallback(ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, this);
3366 m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, TargetProperties::DetachOnErrorValueChangedCallback, this);
3367 m_collection_sp->SetValueChangedCallback(ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, this);
3368 m_collection_sp->SetValueChangedCallback(ePropertyDisableSTDIO, TargetProperties::DisableSTDIOValueChangedCallback, this);
3369
3370 // Update m_launch_info once it was created
3371 Arg0ValueChangedCallback(this, NULL);
3372 RunArgsValueChangedCallback(this, NULL);
3373 //EnvVarsValueChangedCallback(this, NULL); // FIXME: cause segfault in Target::GetPlatform()
3374 InputPathValueChangedCallback(this, NULL);
3375 OutputPathValueChangedCallback(this, NULL);
3376 ErrorPathValueChangedCallback(this, NULL);
3377 DetachOnErrorValueChangedCallback(this, NULL);
3378 DisableASLRValueChangedCallback(this, NULL);
3379 DisableSTDIOValueChangedCallback(this, NULL);
Caroline Ticedaccaa92010-09-20 20:44:43 +00003380 }
3381 else
Greg Clayton67cc0632012-08-22 17:17:09 +00003382 {
3383 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
3384 m_collection_sp->Initialize(g_properties);
3385 m_collection_sp->AppendProperty(ConstString("process"),
3386 ConstString("Settings specify to processes."),
3387 true,
3388 Process::GetGlobalProperties()->GetValueProperties());
3389 }
Ilia K8f37ca52015-02-13 14:31:06 +00003390
Caroline Ticedaccaa92010-09-20 20:44:43 +00003391}
3392
Greg Clayton67cc0632012-08-22 17:17:09 +00003393TargetProperties::~TargetProperties ()
3394{
3395}
3396ArchSpec
3397TargetProperties::GetDefaultArchitecture () const
3398{
3399 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3400 if (value)
3401 return value->GetCurrentValue();
3402 return ArchSpec();
3403}
3404
3405void
3406TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
3407{
3408 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
3409 if (value)
3410 return value->SetCurrentValue(arch, true);
3411}
3412
Ilia K055ad9b2015-05-18 13:41:01 +00003413bool
3414TargetProperties::GetMoveToNearestCode() const
3415{
3416 const uint32_t idx = ePropertyMoveToNearestCode;
3417 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3418}
3419
Greg Clayton67cc0632012-08-22 17:17:09 +00003420lldb::DynamicValueType
3421TargetProperties::GetPreferDynamicValue() const
3422{
3423 const uint32_t idx = ePropertyPreferDynamic;
3424 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3425}
3426
3427bool
Greg Clayton15484402015-05-15 18:40:24 +00003428TargetProperties::SetPreferDynamicValue (lldb::DynamicValueType d)
3429{
3430 const uint32_t idx = ePropertyPreferDynamic;
3431 return m_collection_sp->SetPropertyAtIndexAsEnumeration(NULL, idx, d);
3432}
3433
3434
3435bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003436TargetProperties::GetDisableASLR () const
3437{
3438 const uint32_t idx = ePropertyDisableASLR;
3439 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3440}
3441
3442void
3443TargetProperties::SetDisableASLR (bool b)
3444{
3445 const uint32_t idx = ePropertyDisableASLR;
3446 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3447}
3448
3449bool
Jim Ingham106d0282014-06-25 02:32:56 +00003450TargetProperties::GetDetachOnError () const
3451{
3452 const uint32_t idx = ePropertyDetachOnError;
3453 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3454}
3455
3456void
3457TargetProperties::SetDetachOnError (bool b)
3458{
3459 const uint32_t idx = ePropertyDetachOnError;
3460 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3461}
3462
3463bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003464TargetProperties::GetDisableSTDIO () const
3465{
3466 const uint32_t idx = ePropertyDisableSTDIO;
3467 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3468}
3469
3470void
3471TargetProperties::SetDisableSTDIO (bool b)
3472{
3473 const uint32_t idx = ePropertyDisableSTDIO;
3474 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3475}
3476
Jim Ingham0f063ba2013-03-02 00:26:47 +00003477const char *
3478TargetProperties::GetDisassemblyFlavor () const
3479{
3480 const uint32_t idx = ePropertyDisassemblyFlavor;
3481 const char *return_value;
3482
3483 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3484 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
3485 return return_value;
3486}
3487
Greg Clayton1f746072012-08-29 21:13:06 +00003488InlineStrategy
3489TargetProperties::GetInlineStrategy () const
3490{
3491 const uint32_t idx = ePropertyInlineStrategy;
3492 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
3493}
3494
Greg Clayton45392552012-10-17 22:57:12 +00003495const char *
3496TargetProperties::GetArg0 () const
3497{
3498 const uint32_t idx = ePropertyArg0;
3499 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
3500}
3501
3502void
3503TargetProperties::SetArg0 (const char *arg)
3504{
3505 const uint32_t idx = ePropertyArg0;
3506 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003507 m_launch_info.SetArg0(arg);
Greg Clayton45392552012-10-17 22:57:12 +00003508}
3509
Greg Clayton67cc0632012-08-22 17:17:09 +00003510bool
3511TargetProperties::GetRunArguments (Args &args) const
3512{
3513 const uint32_t idx = ePropertyRunArgs;
3514 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3515}
3516
3517void
3518TargetProperties::SetRunArguments (const Args &args)
3519{
3520 const uint32_t idx = ePropertyRunArgs;
3521 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003522 m_launch_info.GetArguments() = args;
Greg Clayton67cc0632012-08-22 17:17:09 +00003523}
3524
3525size_t
3526TargetProperties::GetEnvironmentAsArgs (Args &env) const
3527{
3528 const uint32_t idx = ePropertyEnvVars;
3529 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
3530}
3531
Ilia K8f37ca52015-02-13 14:31:06 +00003532void
3533TargetProperties::SetEnvironmentFromArgs (const Args &env)
3534{
3535 const uint32_t idx = ePropertyEnvVars;
3536 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, env);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003537 m_launch_info.GetEnvironmentEntries() = env;
Ilia K8f37ca52015-02-13 14:31:06 +00003538}
3539
Greg Clayton67cc0632012-08-22 17:17:09 +00003540bool
3541TargetProperties::GetSkipPrologue() const
3542{
3543 const uint32_t idx = ePropertySkipPrologue;
3544 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3545}
3546
3547PathMappingList &
3548TargetProperties::GetSourcePathMap () const
3549{
3550 const uint32_t idx = ePropertySourceMap;
3551 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
3552 assert(option_value);
3553 return option_value->GetCurrentValue();
3554}
3555
3556FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00003557TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003558{
3559 const uint32_t idx = ePropertyExecutableSearchPaths;
3560 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3561 assert(option_value);
3562 return option_value->GetCurrentValue();
3563}
3564
Michael Sartaina7499c92013-07-01 19:45:50 +00003565FileSpecList &
3566TargetProperties::GetDebugFileSearchPaths ()
3567{
3568 const uint32_t idx = ePropertyDebugFileSearchPaths;
3569 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3570 assert(option_value);
3571 return option_value->GetCurrentValue();
3572}
3573
Sean Callanan85054342015-04-03 15:39:47 +00003574FileSpecList &
3575TargetProperties::GetClangModuleSearchPaths ()
3576{
3577 const uint32_t idx = ePropertyClangModuleSearchPaths;
3578 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
3579 assert(option_value);
3580 return option_value->GetCurrentValue();
3581}
3582
Greg Clayton67cc0632012-08-22 17:17:09 +00003583bool
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003584TargetProperties::GetEnableAutoImportClangModules() const
3585{
3586 const uint32_t idx = ePropertyAutoImportClangModules;
3587 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3588}
3589
3590bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003591TargetProperties::GetEnableSyntheticValue () const
3592{
3593 const uint32_t idx = ePropertyEnableSynthetic;
3594 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3595}
3596
3597uint32_t
3598TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
3599{
3600 const uint32_t idx = ePropertyMaxChildrenCount;
3601 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3602}
3603
3604uint32_t
3605TargetProperties::GetMaximumSizeOfStringSummary() const
3606{
3607 const uint32_t idx = ePropertyMaxSummaryLength;
3608 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3609}
3610
Enrico Granatad325bf92013-06-04 22:54:16 +00003611uint32_t
3612TargetProperties::GetMaximumMemReadSize () const
3613{
3614 const uint32_t idx = ePropertyMaxMemReadSize;
3615 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
3616}
3617
Greg Clayton67cc0632012-08-22 17:17:09 +00003618FileSpec
3619TargetProperties::GetStandardInputPath () const
3620{
3621 const uint32_t idx = ePropertyInputPath;
3622 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3623}
3624
3625void
3626TargetProperties::SetStandardInputPath (const char *p)
3627{
3628 const uint32_t idx = ePropertyInputPath;
3629 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3630}
3631
3632FileSpec
3633TargetProperties::GetStandardOutputPath () const
3634{
3635 const uint32_t idx = ePropertyOutputPath;
3636 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
3637}
3638
3639void
3640TargetProperties::SetStandardOutputPath (const char *p)
3641{
3642 const uint32_t idx = ePropertyOutputPath;
3643 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3644}
3645
3646FileSpec
3647TargetProperties::GetStandardErrorPath () const
3648{
3649 const uint32_t idx = ePropertyErrorPath;
3650 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
3651}
3652
Dawn Perchik23b1dec2015-07-21 22:05:07 +00003653LanguageType
3654TargetProperties::GetLanguage () const
3655{
3656 OptionValueLanguage *value = m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage (NULL, ePropertyLanguage);
3657 if (value)
3658 return value->GetCurrentValue();
3659 return LanguageType();
3660}
3661
Greg Clayton6920b522012-08-22 18:39:03 +00003662const char *
3663TargetProperties::GetExpressionPrefixContentsAsCString ()
3664{
3665 const uint32_t idx = ePropertyExprPrefix;
3666 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3667 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003668 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003669 const bool null_terminate = true;
3670 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003671 if (data_sp)
3672 return (const char *) data_sp->GetBytes();
3673 }
Greg Clayton6920b522012-08-22 18:39:03 +00003674 return NULL;
3675}
3676
Greg Clayton67cc0632012-08-22 17:17:09 +00003677void
3678TargetProperties::SetStandardErrorPath (const char *p)
3679{
3680 const uint32_t idx = ePropertyErrorPath;
3681 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3682}
3683
3684bool
3685TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3686{
3687 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3688 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3689}
3690
Jim Ingham17d023f2013-03-13 17:58:04 +00003691bool
Daniel Malead79ae052013-08-07 21:54:09 +00003692TargetProperties::GetUseHexImmediates () const
3693{
3694 const uint32_t idx = ePropertyUseHexImmediates;
3695 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3696}
3697
3698bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003699TargetProperties::GetUseFastStepping () const
3700{
3701 const uint32_t idx = ePropertyUseFastStepping;
3702 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3703}
3704
Greg Claytonfb6621e2013-12-06 21:59:52 +00003705bool
3706TargetProperties::GetDisplayExpressionsInCrashlogs () const
3707{
3708 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3709 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3710}
3711
Enrico Granata397ddd52013-05-21 20:13:34 +00003712LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003713TargetProperties::GetLoadScriptFromSymbolFile () const
3714{
3715 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Enrico Granata397ddd52013-05-21 20:13:34 +00003716 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003717}
3718
Daniel Malead79ae052013-08-07 21:54:09 +00003719Disassembler::HexImmediateStyle
3720TargetProperties::GetHexImmediateStyle () const
3721{
3722 const uint32_t idx = ePropertyHexImmediateStyle;
3723 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3724}
3725
Greg Claytonfd814c52013-08-13 01:42:25 +00003726MemoryModuleLoadLevel
3727TargetProperties::GetMemoryModuleLoadLevel() const
3728{
3729 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3730 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3731}
3732
Jason Molendaa4bea722014-02-14 05:06:49 +00003733bool
3734TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
3735{
3736 const uint32_t idx = ePropertyTrapHandlerNames;
3737 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
3738}
Greg Claytonfd814c52013-08-13 01:42:25 +00003739
Jason Molendaa4bea722014-02-14 05:06:49 +00003740void
3741TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
3742{
3743 const uint32_t idx = ePropertyTrapHandlerNames;
3744 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
3745}
Greg Clayton67cc0632012-08-22 17:17:09 +00003746
Enrico Granata560558e2015-02-11 02:35:39 +00003747bool
3748TargetProperties::GetDisplayRuntimeSupportValues () const
3749{
3750 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3751 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, false);
3752}
3753
3754void
3755TargetProperties::SetDisplayRuntimeSupportValues (bool b)
3756{
3757 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
3758 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3759}
3760
Ewan Crawford78baa192015-05-13 09:18:18 +00003761bool
3762TargetProperties::GetNonStopModeEnabled () const
3763{
3764 const uint32_t idx = ePropertyNonStopModeEnabled;
3765 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, false);
3766}
3767
Ewan Crawfordaa7eda72015-06-24 15:14:26 +00003768void
3769TargetProperties::SetNonStopModeEnabled (bool b)
3770{
3771 const uint32_t idx = ePropertyNonStopModeEnabled;
3772 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
3773}
3774
Ilia K8f37ca52015-02-13 14:31:06 +00003775const ProcessLaunchInfo &
Ilia Kcc39d3f2015-02-13 17:07:55 +00003776TargetProperties::GetProcessLaunchInfo ()
Ilia K8f37ca52015-02-13 14:31:06 +00003777{
Ilia Kcc39d3f2015-02-13 17:07:55 +00003778 m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work
Ilia K8f37ca52015-02-13 14:31:06 +00003779 return m_launch_info;
3780}
3781
3782void
3783TargetProperties::SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
3784{
3785 m_launch_info = launch_info;
3786 SetArg0(launch_info.GetArg0());
3787 SetRunArguments(launch_info.GetArguments());
3788 SetEnvironmentFromArgs(launch_info.GetEnvironmentEntries());
3789 const FileAction *input_file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
3790 if (input_file_action)
3791 {
3792 const char *input_path = input_file_action->GetPath();
3793 if (input_path)
3794 SetStandardInputPath(input_path);
3795 }
3796 const FileAction *output_file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
3797 if (output_file_action)
3798 {
3799 const char *output_path = output_file_action->GetPath();
3800 if (output_path)
3801 SetStandardOutputPath(output_path);
3802 }
3803 const FileAction *error_file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
3804 if (error_file_action)
3805 {
3806 const char *error_path = error_file_action->GetPath();
3807 if (error_path)
3808 SetStandardErrorPath(error_path);
3809 }
3810 SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
3811 SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
3812 SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO));
3813}
3814
3815void
3816TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *)
3817{
3818 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3819 this_->m_launch_info.SetArg0(this_->GetArg0());
3820}
3821
3822void
3823TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *)
3824{
3825 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3826 Args args;
3827 if (this_->GetRunArguments(args))
3828 this_->m_launch_info.GetArguments() = args;
3829}
3830
3831void
3832TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *)
3833{
3834 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3835 Args args;
3836 if (this_->GetEnvironmentAsArgs(args))
3837 this_->m_launch_info.GetEnvironmentEntries() = args;
3838}
3839
3840void
3841TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3842{
3843 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00003844 this_->m_launch_info.AppendOpenFileAction(STDIN_FILENO, this_->GetStandardInputPath(), true, false);
Ilia K8f37ca52015-02-13 14:31:06 +00003845}
3846
3847void
3848TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3849{
3850 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00003851 this_->m_launch_info.AppendOpenFileAction(STDOUT_FILENO, this_->GetStandardOutputPath(), false, true);
Ilia K8f37ca52015-02-13 14:31:06 +00003852}
3853
3854void
3855TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *)
3856{
3857 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00003858 this_->m_launch_info.AppendOpenFileAction(STDERR_FILENO, this_->GetStandardErrorPath(), false, true);
Ilia K8f37ca52015-02-13 14:31:06 +00003859}
3860
3861void
3862TargetProperties::DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *)
3863{
3864 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3865 if (this_->GetDetachOnError())
3866 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError);
3867 else
3868 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError);
3869}
3870
3871void
3872TargetProperties::DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *)
3873{
3874 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3875 if (this_->GetDisableASLR())
3876 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR);
3877 else
3878 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR);
3879}
3880
3881void
3882TargetProperties::DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *)
3883{
3884 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
3885 if (this_->GetDisableSTDIO())
3886 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO);
3887 else
3888 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO);
3889}
Ilia Keb2c19a2015-03-10 21:59:55 +00003890
3891//----------------------------------------------------------------------
3892// Target::TargetEventData
3893//----------------------------------------------------------------------
3894
3895Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp) :
3896 EventData (),
3897 m_target_sp (target_sp),
3898 m_module_list ()
3899{
3900}
3901
3902Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp, const ModuleList &module_list) :
3903 EventData (),
3904 m_target_sp (target_sp),
3905 m_module_list (module_list)
3906{
3907}
3908
3909Target::TargetEventData::~TargetEventData()
3910{
3911}
3912
3913const ConstString &
3914Target::TargetEventData::GetFlavorString ()
3915{
3916 static ConstString g_flavor ("Target::TargetEventData");
3917 return g_flavor;
3918}
3919
3920void
3921Target::TargetEventData::Dump (Stream *s) const
3922{
3923}
3924
3925const Target::TargetEventData *
3926Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3927{
3928 if (event_ptr)
3929 {
3930 const EventData *event_data = event_ptr->GetData();
3931 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3932 return static_cast <const TargetEventData *> (event_ptr->GetData());
3933 }
3934 return NULL;
3935}
3936
3937TargetSP
3938Target::TargetEventData::GetTargetFromEvent (const Event *event_ptr)
3939{
3940 TargetSP target_sp;
3941 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
3942 if (event_data)
3943 target_sp = event_data->m_target_sp;
3944 return target_sp;
3945}
3946
3947ModuleList
3948Target::TargetEventData::GetModuleListFromEvent (const Event *event_ptr)
3949{
3950 ModuleList module_list;
3951 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
3952 if (event_data)
3953 module_list = event_data->m_module_list;
3954 return module_list;
3955}