blob: 7d3543cd52487414cc96e1336343ad4ff747990c [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenko8f30a652015-10-23 18:39:37 +000014#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Breakpoint/BreakpointResolver.h"
16#include "lldb/Breakpoint/BreakpointResolverAddress.h"
17#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham969795f2011-09-21 01:17:13 +000018#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chen01a67862011-10-14 00:42:25 +000020#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000021#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Event.h"
23#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Core/Module.h"
25#include "lldb/Core/ModuleSpec.h"
26#include "lldb/Core/Section.h"
Greg Clayton9585fbf2013-03-19 00:20:55 +000027#include "lldb/Core/SourceManager.h"
Greg Claytonb09c5382013-12-13 17:20:18 +000028#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000029#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000031#include "lldb/Core/Timer.h"
32#include "lldb/Core/ValueObject.h"
Sean Callanan66810412015-10-19 23:11:07 +000033#include "lldb/Expression/REPL.h"
Jim Ingham151c0322015-09-15 21:13:50 +000034#include "lldb/Expression/UserExpression.h"
Sean Callanan4dbb2712015-09-25 20:35:58 +000035#include "Plugins/ExpressionParser/Clang/ClangASTSource.h"
36#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
37#include "Plugins/ExpressionParser/Clang/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"
Jim Ingham151c0322015-09-15 21:13:50 +000049#include "lldb/Target/Language.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000050#include "lldb/Target/LanguageRuntime.h"
51#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000053#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000054#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000055#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000056#include "lldb/Target/Thread.h"
57#include "lldb/Target/ThreadSpec.h"
Sean Callanan9a6940c2015-10-21 00:36:34 +000058#include "lldb/Utility/LLDBAssert.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
60using namespace lldb;
61using namespace lldb_private;
62
Jim Ingham4bddaeb2012-02-16 06:50:00 +000063ConstString &
64Target::GetStaticBroadcasterClass ()
65{
66 static ConstString class_name ("lldb.target");
67 return class_name;
68}
69
Jim Ingham893c9322014-11-22 01:42:44 +000070Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp, bool is_dummy_target) :
Greg Clayton67cc0632012-08-22 17:17:09 +000071 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +000072 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +000073 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +000074 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +000075 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +000076 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +000077 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +000078 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +000079 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 m_breakpoint_list (false),
81 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +000082 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +000083 m_process_sp (),
84 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 m_image_search_paths (ImageSearchPathsChanged, this),
Sean Callanana3444ff2015-11-10 22:54:42 +000086 m_ast_importer_sp (),
Greg Clayton9585fbf2013-03-19 00:20:55 +000087 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +000088 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +000089 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +000090 m_valid (true),
Jim Ingham893c9322014-11-22 01:42:44 +000091 m_suppress_stop_hooks (false),
92 m_is_dummy_target(is_dummy_target)
93
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094{
Greg Claytoncfd1ace2010-10-31 03:01:06 +000095 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
96 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
97 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +000098 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +000099 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000100
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000101 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000102
Greg Clayton5160ce52013-03-27 23:08:40 +0000103 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000105 log->Printf ("%p Target::Target()", static_cast<void*>(this));
Jason Molendae1b68ad2012-12-05 00:25:49 +0000106 if (m_arch.IsValid())
107 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000108 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 +0000109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
Eugene Zelenko8f30a652015-10-23 18:39:37 +0000112Target::~Target()
113{
114 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
115 if (log)
116 log->Printf ("%p Target::~Target()", static_cast<void*>(this));
117 DeleteCurrentProcess ();
118}
119
Jim Ingham893c9322014-11-22 01:42:44 +0000120void
121Target::PrimeFromDummyTarget(Target *target)
122{
123 if (!target)
124 return;
125
126 m_stop_hooks = target->m_stop_hooks;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000127
128 for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints())
129 {
130 if (breakpoint_sp->IsInternal())
131 continue;
132
133 BreakpointSP new_bp (new Breakpoint (*this, *breakpoint_sp.get()));
134 AddBreakpoint (new_bp, false);
135 }
Jim Ingham893c9322014-11-22 01:42:44 +0000136}
137
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000139Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140{
Greg Clayton89411422010-10-08 00:21:05 +0000141// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000142 if (description_level != lldb::eDescriptionLevelBrief)
143 {
144 s->Indent();
145 s->PutCString("Target\n");
146 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000147 m_images.Dump(s);
148 m_breakpoint_list.Dump(s);
149 m_internal_breakpoint_list.Dump(s);
150 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000151 }
152 else
153 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000154 Module *exe_module = GetExecutableModulePointer();
155 if (exe_module)
156 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000157 else
158 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000159 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160}
161
162void
Greg Clayton90ba8112012-12-05 00:16:59 +0000163Target::CleanupProcess ()
164{
165 // Do any cleanup of the target we need to do between process instances.
166 // NB It is better to do this before destroying the process in case the
167 // clean up needs some help from the process.
168 m_breakpoint_list.ClearAllBreakpointSites();
169 m_internal_breakpoint_list.ClearAllBreakpointSites();
170 // Disable watchpoints just on the debugger side.
171 Mutex::Locker locker;
172 this->GetWatchpointList().GetListMutex(locker);
173 DisableAllWatchpoints(false);
174 ClearAllWatchpointHitCounts();
Enrico Granata5e3fe042015-02-11 00:37:54 +0000175 ClearAllWatchpointHistoricValues();
Greg Clayton90ba8112012-12-05 00:16:59 +0000176}
177
178void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179Target::DeleteCurrentProcess ()
180{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000181 if (m_process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000183 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 if (m_process_sp->IsAlive())
Jason Molendaede31932015-04-17 05:01:58 +0000185 m_process_sp->Destroy(false);
Jim Inghamd0a3e122011-02-16 17:54:55 +0000186
187 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188
Greg Clayton90ba8112012-12-05 00:16:59 +0000189 CleanupProcess ();
190
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 m_process_sp.reset();
192 }
193}
194
195const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000196Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197{
198 DeleteCurrentProcess ();
Zachary Turner7529df92015-09-01 20:02:29 +0000199 m_process_sp = Process::FindPlugin(shared_from_this(), plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 return m_process_sp;
201}
202
203const lldb::ProcessSP &
204Target::GetProcessSP () const
205{
206 return m_process_sp;
207}
208
Sean Callanan66810412015-10-19 23:11:07 +0000209lldb::REPLSP
Sean Callanan3e7e9152015-10-20 00:23:46 +0000210Target::GetREPL (Error &err, lldb::LanguageType language, const char *repl_options, bool can_create)
Sean Callanan66810412015-10-19 23:11:07 +0000211{
212 if (language == eLanguageTypeUnknown)
213 {
Sean Callanan93c0b002015-10-21 19:14:33 +0000214 std::set<LanguageType> repl_languages;
215
216 Language::GetLanguagesSupportingREPLs(repl_languages);
217
218 if (repl_languages.size() == 1)
219 {
220 language = *repl_languages.begin();
221 }
Sean Callanan97f84e82015-10-21 19:31:17 +0000222 else if (repl_languages.size() == 0)
223 {
224 err.SetErrorStringWithFormat("LLDB isn't configured with support support for any REPLs.");
225 return REPLSP();
226 }
Sean Callanan93c0b002015-10-21 19:14:33 +0000227 else
228 {
229 err.SetErrorStringWithFormat("Multiple possible REPL languages. Please specify a language.");
Sean Callanan97f84e82015-10-21 19:31:17 +0000230 return REPLSP();
Sean Callanan93c0b002015-10-21 19:14:33 +0000231 }
Sean Callanan66810412015-10-19 23:11:07 +0000232 }
233
234 REPLMap::iterator pos = m_repl_map.find(language);
235
236 if (pos != m_repl_map.end())
237 {
238 return pos->second;
239 }
240
241 if (!can_create)
242 {
Sean Callanan3e7e9152015-10-20 00:23:46 +0000243 err.SetErrorStringWithFormat("Couldn't find an existing REPL for %s, and can't create a new one", Language::GetNameForLanguageType(language));
Sean Callanan66810412015-10-19 23:11:07 +0000244 return lldb::REPLSP();
245 }
246
Sean Callanan3b682de2015-10-21 00:28:44 +0000247 Debugger *const debugger = nullptr;
248 lldb::REPLSP ret = REPL::Create(err, language, debugger, this, repl_options);
Sean Callanan66810412015-10-19 23:11:07 +0000249
250 if (ret)
251 {
252 m_repl_map[language] = ret;
253 return m_repl_map[language];
254 }
255
Sean Callanan3e7e9152015-10-20 00:23:46 +0000256 if (err.Success())
257 {
258 err.SetErrorStringWithFormat("Couldn't create a REPL for %s", Language::GetNameForLanguageType(language));
259 }
260
261 return lldb::REPLSP();
Sean Callanan66810412015-10-19 23:11:07 +0000262}
263
Greg Clayton3418c852011-08-10 02:10:13 +0000264void
Sean Callanan9a6940c2015-10-21 00:36:34 +0000265Target::SetREPL (lldb::LanguageType language, lldb::REPLSP repl_sp)
266{
267 lldbassert(!m_repl_map.count(language));
268
269 m_repl_map[language] = repl_sp;
270}
271
272void
Greg Clayton3418c852011-08-10 02:10:13 +0000273Target::Destroy()
274{
275 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000276 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000277 DeleteCurrentProcess ();
278 m_platform_sp.reset();
279 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000280 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000281 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000282 const bool notify = false;
283 m_breakpoint_list.RemoveAll(notify);
284 m_internal_breakpoint_list.RemoveAll(notify);
285 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000286 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000287 m_search_filter_sp.reset();
288 m_image_search_paths.Clear(notify);
Greg Clayton3418c852011-08-10 02:10:13 +0000289 m_stop_hooks.clear();
290 m_stop_hook_next_id = 0;
291 m_suppress_stop_hooks = false;
292}
293
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294BreakpointList &
295Target::GetBreakpointList(bool internal)
296{
297 if (internal)
298 return m_internal_breakpoint_list;
299 else
300 return m_breakpoint_list;
301}
302
303const BreakpointList &
304Target::GetBreakpointList(bool internal) const
305{
306 if (internal)
307 return m_internal_breakpoint_list;
308 else
309 return m_breakpoint_list;
310}
311
312BreakpointSP
313Target::GetBreakpointByID (break_id_t break_id)
314{
315 BreakpointSP bp_sp;
316
317 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
318 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
319 else
320 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
321
322 return bp_sp;
323}
324
325BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000326Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000327 const FileSpecList *source_file_spec_list,
328 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000329 bool internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000330 bool hardware,
331 LazyBool move_to_nearest_code)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332{
Jim Ingham87df91b2011-09-23 00:54:11 +0000333 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
Ilia K055ad9b2015-05-18 13:41:01 +0000334 if (move_to_nearest_code == eLazyBoolCalculate)
335 move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000336 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex(nullptr, source_regex, !static_cast<bool>(move_to_nearest_code)));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000337 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000338}
339
Jim Ingham969795f2011-09-21 01:17:13 +0000340BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000341Target::CreateBreakpoint (const FileSpecList *containingModules,
342 const FileSpec &file,
343 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000344 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000345 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000346 bool internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000347 bool hardware,
348 LazyBool move_to_nearest_code)
Jim Ingham969795f2011-09-21 01:17:13 +0000349{
Greg Clayton1f746072012-08-29 21:13:06 +0000350 if (check_inlines == eLazyBoolCalculate)
351 {
352 const InlineStrategy inline_strategy = GetInlineStrategy();
353 switch (inline_strategy)
354 {
355 case eInlineBreakpointsNever:
356 check_inlines = eLazyBoolNo;
357 break;
358
359 case eInlineBreakpointsHeaders:
360 if (file.IsSourceImplementationFile())
361 check_inlines = eLazyBoolNo;
362 else
363 check_inlines = eLazyBoolYes;
364 break;
365
366 case eInlineBreakpointsAlways:
367 check_inlines = eLazyBoolYes;
368 break;
369 }
370 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000371 SearchFilterSP filter_sp;
372 if (check_inlines == eLazyBoolNo)
373 {
374 // Not checking for inlines, we are looking only for matching compile units
375 FileSpecList compile_unit_list;
376 compile_unit_list.Append (file);
377 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
378 }
379 else
380 {
381 filter_sp = GetSearchFilterForModuleList (containingModules);
382 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000383 if (skip_prologue == eLazyBoolCalculate)
384 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Ilia K055ad9b2015-05-18 13:41:01 +0000385 if (move_to_nearest_code == eLazyBoolCalculate)
386 move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
Greg Clayton03da4cc2013-04-19 21:31:16 +0000387
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000388 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine(nullptr,
389 file,
390 line_no,
391 check_inlines,
392 skip_prologue,
393 !static_cast<bool>(move_to_nearest_code)));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000394 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395}
396
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000398Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 Address so_addr;
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +0000401
402 // Check for any reason we want to move this breakpoint to other address.
403 addr = GetBreakableLoadAddress(addr);
404
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 // Attempt to resolve our load address if possible, though it is ok if
406 // it doesn't resolve to section/offset.
407
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000408 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000409 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000410 if (!so_addr.IsValid())
411 {
412 // The address didn't resolve, so just set this as an absolute address
413 so_addr.SetOffset (addr);
414 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000415 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 return bp_sp;
417}
418
419BreakpointSP
Jim Ingham055a08a2015-11-17 03:39:13 +0000420Target::CreateBreakpoint (const Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421{
Jim Ingham33df7cd2014-12-06 01:28:03 +0000422 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000423 BreakpointResolverSP resolver_sp(new BreakpointResolverAddress(nullptr, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000424 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425}
426
Jim Ingham055a08a2015-11-17 03:39:13 +0000427lldb::BreakpointSP
428Target::CreateAddressInModuleBreakpoint (lldb::addr_t file_addr,
429 bool internal,
430 const FileSpec *file_spec,
431 bool request_hardware)
432{
433 SearchFilterSP filter_sp(new SearchFilterForUnconstrainedSearches (shared_from_this()));
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000434 BreakpointResolverSP resolver_sp(new BreakpointResolverAddress(nullptr, file_addr, file_spec));
Jim Ingham055a08a2015-11-17 03:39:13 +0000435 return CreateBreakpoint (filter_sp, resolver_sp, internal, request_hardware, false);
436}
437
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000439Target::CreateBreakpoint (const FileSpecList *containingModules,
440 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000441 const char *func_name,
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)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000448 BreakpointSP bp_sp;
449 if (func_name)
450 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000451 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000452
453 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();
Greg Clayton03da4cc2013-04-19 21:31:16 +0000457
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000458 BreakpointResolverSP resolver_sp(new BreakpointResolverName(nullptr,
459 func_name,
460 func_name_type_mask,
461 language,
462 Breakpoint::Exact,
463 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000464 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000465 }
466 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467}
468
Jim Inghamfab10e82012-03-06 00:37:27 +0000469lldb::BreakpointSP
470Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000471 const FileSpecList *containingSourceFiles,
472 const std::vector<std::string> &func_names,
473 uint32_t func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000474 LanguageType language,
Jim Inghama8558b62012-05-22 00:12:20 +0000475 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000476 bool internal,
477 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000478{
479 BreakpointSP bp_sp;
480 size_t num_names = func_names.size();
481 if (num_names > 0)
482 {
483 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000484
485 if (skip_prologue == eLazyBoolCalculate)
486 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000487 if (language == lldb::eLanguageTypeUnknown)
488 language = GetLanguage();
Greg Clayton03da4cc2013-04-19 21:31:16 +0000489
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000490 BreakpointResolverSP resolver_sp(new BreakpointResolverName(nullptr,
491 func_names,
492 func_name_type_mask,
493 language,
494 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000495 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000496 }
497 return bp_sp;
498}
499
Jim Ingham133e0fb2012-03-03 02:05:11 +0000500BreakpointSP
501Target::CreateBreakpoint (const FileSpecList *containingModules,
502 const FileSpecList *containingSourceFiles,
503 const char *func_names[],
504 size_t num_names,
505 uint32_t func_name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000506 LanguageType language,
Jim Inghama8558b62012-05-22 00:12:20 +0000507 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000508 bool internal,
509 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000510{
511 BreakpointSP bp_sp;
512 if (num_names > 0)
513 {
514 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
515
Greg Clayton03da4cc2013-04-19 21:31:16 +0000516 if (skip_prologue == eLazyBoolCalculate)
517 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000518 if (language == lldb::eLanguageTypeUnknown)
519 language = GetLanguage();
520
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000521 BreakpointResolverSP resolver_sp(new BreakpointResolverName(nullptr,
522 func_names,
523 num_names,
524 func_name_type_mask,
525 language,
526 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000527 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000528 }
529 return bp_sp;
530}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531
532SearchFilterSP
533Target::GetSearchFilterForModule (const FileSpec *containingModule)
534{
535 SearchFilterSP filter_sp;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000536 if (containingModule != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 {
538 // TODO: We should look into sharing module based search filters
539 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000540 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 }
542 else
543 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000544 if (!m_search_filter_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000545 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546 filter_sp = m_search_filter_sp;
547 }
548 return filter_sp;
549}
550
Jim Ingham969795f2011-09-21 01:17:13 +0000551SearchFilterSP
552Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
553{
554 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000555 if (containingModules && containingModules->GetSize() != 0)
556 {
557 // TODO: We should look into sharing module based search filters
558 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000559 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000560 }
561 else
562 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000563 if (!m_search_filter_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +0000564 m_search_filter_sp.reset (new SearchFilterForUnconstrainedSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000565 filter_sp = m_search_filter_sp;
566 }
567 return filter_sp;
568}
569
Jim Ingham87df91b2011-09-23 00:54:11 +0000570SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000571Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
572 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000573{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000574 if (containingSourceFiles == nullptr || containingSourceFiles->GetSize() == 0)
Jim Ingham87df91b2011-09-23 00:54:11 +0000575 return GetSearchFilterForModuleList(containingModules);
576
577 SearchFilterSP filter_sp;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000578 if (containingModules == nullptr)
Jim Ingham87df91b2011-09-23 00:54:11 +0000579 {
580 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
581 // but that will take a little reworking.
582
Greg Claytone1cd1be2012-01-29 20:56:30 +0000583 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000584 }
585 else
586 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000587 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000588 }
589 return filter_sp;
590}
591
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000593Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000594 const FileSpecList *containingSourceFiles,
595 RegularExpression &func_regex,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000596 lldb::LanguageType requested_language,
Jim Inghama8558b62012-05-22 00:12:20 +0000597 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000598 bool internal,
599 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600{
Jim Ingham87df91b2011-09-23 00:54:11 +0000601 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Saleem Abdulrasoolb5c128b2014-07-23 01:53:52 +0000602 bool skip =
603 (skip_prologue == eLazyBoolCalculate) ? GetSkipPrologue()
604 : static_cast<bool>(skip_prologue);
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +0000605 BreakpointResolverSP resolver_sp(new BreakpointResolverName(nullptr,
606 func_regex,
607 requested_language,
608 skip));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609
Jim Ingham1460e4b2014-01-10 23:46:59 +0000610 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611}
612
Jim Ingham219ba192012-03-05 04:47:34 +0000613lldb::BreakpointSP
Jim Inghama72b31c2015-04-22 19:42:18 +0000614Target::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 +0000615{
Jim Inghama72b31c2015-04-22 19:42:18 +0000616 BreakpointSP exc_bkpt_sp = LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
617 if (exc_bkpt_sp && additional_args)
618 {
619 Breakpoint::BreakpointPreconditionSP precondition_sp = exc_bkpt_sp->GetPrecondition();
620 if (precondition_sp && additional_args)
621 {
622 if (error)
623 *error = precondition_sp->ConfigurePrecondition(*additional_args);
624 else
625 precondition_sp->ConfigurePrecondition(*additional_args);
626 }
627 }
628 return exc_bkpt_sp;
Jim Ingham219ba192012-03-05 04:47:34 +0000629}
Jim Inghama72b31c2015-04-22 19:42:18 +0000630
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000632Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633{
634 BreakpointSP bp_sp;
635 if (filter_sp && resolver_sp)
636 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000637 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 resolver_sp->SetBreakpoint (bp_sp.get());
Jim Ingham33df7cd2014-12-06 01:28:03 +0000639 AddBreakpoint (bp_sp, internal);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 }
Jim Ingham33df7cd2014-12-06 01:28:03 +0000641 return bp_sp;
642}
643
644void
645Target::AddBreakpoint (lldb::BreakpointSP bp_sp, bool internal)
646{
647 if (!bp_sp)
648 return;
649 if (internal)
650 m_internal_breakpoint_list.Add (bp_sp, false);
651 else
652 m_breakpoint_list.Add (bp_sp, true);
653
654 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
655 if (log)
656 {
657 StreamString s;
658 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
659 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
660 }
661
662 bp_sp->ResolveBreakpoint();
663
664 if (!internal)
Jim Ingham36f3b362010-10-14 23:45:03 +0000665 {
666 m_last_created_breakpoint = bp_sp;
667 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668}
669
Johnny Chen86364b42011-09-20 23:28:55 +0000670bool
671Target::ProcessIsValid()
672{
673 return (m_process_sp && m_process_sp->IsAlive());
674}
675
Johnny Chenb90827e2012-06-04 23:19:54 +0000676static bool
677CheckIfWatchpointsExhausted(Target *target, Error &error)
678{
679 uint32_t num_supported_hardware_watchpoints;
680 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
681 if (rc.Success())
682 {
683 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
684 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
685 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
686 num_supported_hardware_watchpoints);
687 }
688 return false;
689}
690
Johnny Chen01a67862011-10-14 00:42:25 +0000691// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000692// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000693WatchpointSP
Greg Claytona1e5dc82015-08-11 22:53:00 +0000694Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const CompilerType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000695{
Greg Clayton5160ce52013-03-27 23:08:40 +0000696 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000697 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000698 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000699 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000700
Johnny Chen01a67862011-10-14 00:42:25 +0000701 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000702 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000703 {
704 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000705 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000706 }
Jim Inghamc6462312013-06-18 21:52:48 +0000707
Johnny Chen45e541f2011-09-14 22:20:15 +0000708 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000709 {
710 if (size == 0)
711 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
712 else
Daniel Malead01b2952012-11-29 21:49:15 +0000713 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000714 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000715 }
Jim Inghamc6462312013-06-18 21:52:48 +0000716
717 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
718 {
719 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
720 }
Johnny Chen7313a642011-09-13 01:15:36 +0000721
Johnny Chen01a67862011-10-14 00:42:25 +0000722 // Currently we only support one watchpoint per address, with total number
723 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000724
725 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000726 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 +0000727 Mutex::Locker locker;
728 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000729 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000730 if (matched_sp)
731 {
Johnny Chen0c406372011-09-14 20:23:45 +0000732 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000733 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000734 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
735 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000736 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000737 if (size == old_size && kind == old_type)
738 {
Johnny Chen01a67862011-10-14 00:42:25 +0000739 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000740 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000741 }
742 else
743 {
Johnny Chen01a67862011-10-14 00:42:25 +0000744 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000745 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
746 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000747 }
Johnny Chen3c532582011-09-13 23:29:31 +0000748 }
749
Jason Molenda727e3922012-12-05 23:07:34 +0000750 if (!wp_sp)
751 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000752 wp_sp.reset(new Watchpoint(*this, addr, size, type));
753 wp_sp->SetWatchpointType(kind, notify);
754 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000755 }
Johnny Chen0c406372011-09-14 20:23:45 +0000756
Jim Ingham1b5792e2012-12-18 02:03:49 +0000757 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000758 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000759 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
760 __FUNCTION__,
761 error.Success() ? "succeeded" : "failed",
762 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000763
Jason Molenda727e3922012-12-05 23:07:34 +0000764 if (error.Fail())
765 {
Johnny Chen41b77262012-03-26 22:00:10 +0000766 // Enabling the watchpoint on the device side failed.
767 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000768 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000769 // See if we could provide more helpful error message.
770 if (!CheckIfWatchpointsExhausted(this, error))
771 {
772 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Greg Clayton6fea17e2014-03-03 19:15:20 +0000773 error.SetErrorStringWithFormat("watch size of %" PRIu64 " is not supported", (uint64_t)size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000774 }
Johnny Chen01a67862011-10-14 00:42:25 +0000775 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000776 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000777 else
Johnny Chen01a67862011-10-14 00:42:25 +0000778 m_last_created_watchpoint = wp_sp;
779 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000780}
781
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782void
783Target::RemoveAllBreakpoints (bool internal_also)
784{
Greg Clayton5160ce52013-03-27 23:08:40 +0000785 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000786 if (log)
787 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
788
Greg Clayton9fed0d82010-07-23 23:33:17 +0000789 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000791 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000792
793 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794}
795
796void
797Target::DisableAllBreakpoints (bool internal_also)
798{
Greg Clayton5160ce52013-03-27 23:08:40 +0000799 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 if (log)
801 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
802
803 m_breakpoint_list.SetEnabledAll (false);
804 if (internal_also)
805 m_internal_breakpoint_list.SetEnabledAll (false);
806}
807
808void
809Target::EnableAllBreakpoints (bool internal_also)
810{
Greg Clayton5160ce52013-03-27 23:08:40 +0000811 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812 if (log)
813 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
814
815 m_breakpoint_list.SetEnabledAll (true);
816 if (internal_also)
817 m_internal_breakpoint_list.SetEnabledAll (true);
818}
819
820bool
821Target::RemoveBreakpointByID (break_id_t break_id)
822{
Greg Clayton5160ce52013-03-27 23:08:40 +0000823 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 if (log)
825 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
826
827 if (DisableBreakpointByID (break_id))
828 {
829 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000830 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000831 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000832 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000833 if (m_last_created_breakpoint)
834 {
835 if (m_last_created_breakpoint->GetID() == break_id)
836 m_last_created_breakpoint.reset();
837 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000838 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000839 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840 return true;
841 }
842 return false;
843}
844
845bool
846Target::DisableBreakpointByID (break_id_t break_id)
847{
Greg Clayton5160ce52013-03-27 23:08:40 +0000848 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849 if (log)
850 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
851
852 BreakpointSP bp_sp;
853
854 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
855 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
856 else
857 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
858 if (bp_sp)
859 {
860 bp_sp->SetEnabled (false);
861 return true;
862 }
863 return false;
864}
865
866bool
867Target::EnableBreakpointByID (break_id_t break_id)
868{
Greg Clayton5160ce52013-03-27 23:08:40 +0000869 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 if (log)
871 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
872 __FUNCTION__,
873 break_id,
874 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
875
876 BreakpointSP bp_sp;
877
878 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
879 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
880 else
881 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
882
883 if (bp_sp)
884 {
885 bp_sp->SetEnabled (true);
886 return true;
887 }
888 return false;
889}
890
Johnny Chenedf50372011-09-23 21:21:43 +0000891// The flag 'end_to_end', default to true, signifies that the operation is
892// performed end to end, for both the debugger and the debuggee.
893
Johnny Chen01a67862011-10-14 00:42:25 +0000894// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
895// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000896bool
Johnny Chen01a67862011-10-14 00:42:25 +0000897Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000898{
Greg Clayton5160ce52013-03-27 23:08:40 +0000899 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000900 if (log)
901 log->Printf ("Target::%s\n", __FUNCTION__);
902
Johnny Chenedf50372011-09-23 21:21:43 +0000903 if (!end_to_end) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000904 m_watchpoint_list.RemoveAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000905 return true;
906 }
907
908 // Otherwise, it's an end to end operation.
909
Johnny Chen86364b42011-09-20 23:28:55 +0000910 if (!ProcessIsValid())
911 return false;
912
Johnny Chen01a67862011-10-14 00:42:25 +0000913 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000914 for (size_t i = 0; i < num_watchpoints; ++i)
915 {
Johnny Chen01a67862011-10-14 00:42:25 +0000916 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
917 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000918 return false;
919
Johnny Chen01a67862011-10-14 00:42:25 +0000920 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000921 if (rc.Fail())
922 return false;
923 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000924 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000925 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000926 return true; // Success!
927}
928
Johnny Chen01a67862011-10-14 00:42:25 +0000929// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
930// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000931bool
Johnny Chen01a67862011-10-14 00:42:25 +0000932Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000933{
Greg Clayton5160ce52013-03-27 23:08:40 +0000934 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000935 if (log)
936 log->Printf ("Target::%s\n", __FUNCTION__);
937
Johnny Chenedf50372011-09-23 21:21:43 +0000938 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000939 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000940 return true;
941 }
942
943 // Otherwise, it's an end to end operation.
944
Johnny Chen86364b42011-09-20 23:28:55 +0000945 if (!ProcessIsValid())
946 return false;
947
Johnny Chen01a67862011-10-14 00:42:25 +0000948 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000949 for (size_t i = 0; i < num_watchpoints; ++i)
950 {
Johnny Chen01a67862011-10-14 00:42:25 +0000951 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
952 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000953 return false;
954
Johnny Chen01a67862011-10-14 00:42:25 +0000955 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000956 if (rc.Fail())
957 return false;
958 }
Johnny Chen86364b42011-09-20 23:28:55 +0000959 return true; // Success!
960}
961
Johnny Chen01a67862011-10-14 00:42:25 +0000962// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
963// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000964bool
Johnny Chen01a67862011-10-14 00:42:25 +0000965Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000966{
Greg Clayton5160ce52013-03-27 23:08:40 +0000967 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000968 if (log)
969 log->Printf ("Target::%s\n", __FUNCTION__);
970
Johnny Chenedf50372011-09-23 21:21:43 +0000971 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000972 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000973 return true;
974 }
975
976 // Otherwise, it's an end to end operation.
977
Johnny Chen86364b42011-09-20 23:28:55 +0000978 if (!ProcessIsValid())
979 return false;
980
Johnny Chen01a67862011-10-14 00:42:25 +0000981 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000982 for (size_t i = 0; i < num_watchpoints; ++i)
983 {
Johnny Chen01a67862011-10-14 00:42:25 +0000984 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
985 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000986 return false;
987
Johnny Chen01a67862011-10-14 00:42:25 +0000988 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000989 if (rc.Fail())
990 return false;
991 }
Johnny Chen86364b42011-09-20 23:28:55 +0000992 return true; // Success!
993}
994
Johnny Chena4d6bc92012-02-25 06:44:30 +0000995// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
996bool
997Target::ClearAllWatchpointHitCounts ()
998{
Greg Clayton5160ce52013-03-27 23:08:40 +0000999 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +00001000 if (log)
1001 log->Printf ("Target::%s\n", __FUNCTION__);
1002
1003 size_t num_watchpoints = m_watchpoint_list.GetSize();
1004 for (size_t i = 0; i < num_watchpoints; ++i)
1005 {
1006 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
1007 if (!wp_sp)
1008 return false;
1009
1010 wp_sp->ResetHitCount();
1011 }
1012 return true; // Success!
1013}
1014
Enrico Granata5e3fe042015-02-11 00:37:54 +00001015// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
1016bool
1017Target::ClearAllWatchpointHistoricValues ()
1018{
1019 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
1020 if (log)
1021 log->Printf ("Target::%s\n", __FUNCTION__);
1022
1023 size_t num_watchpoints = m_watchpoint_list.GetSize();
1024 for (size_t i = 0; i < num_watchpoints; ++i)
1025 {
1026 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
1027 if (!wp_sp)
1028 return false;
1029
1030 wp_sp->ResetHistoricValues();
1031 }
1032 return true; // Success!
1033}
1034
Johnny Chen01a67862011-10-14 00:42:25 +00001035// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +00001036// during these operations.
1037bool
Johnny Chen01a67862011-10-14 00:42:25 +00001038Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001039{
Greg Clayton5160ce52013-03-27 23:08:40 +00001040 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +00001041 if (log)
1042 log->Printf ("Target::%s\n", __FUNCTION__);
1043
1044 if (!ProcessIsValid())
1045 return false;
1046
Johnny Chen01a67862011-10-14 00:42:25 +00001047 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +00001048 for (size_t i = 0; i < num_watchpoints; ++i)
1049 {
Johnny Chen01a67862011-10-14 00:42:25 +00001050 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
1051 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001052 return false;
1053
Johnny Chen01a67862011-10-14 00:42:25 +00001054 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001055 }
1056 return true; // Success!
1057}
1058
Johnny Chen01a67862011-10-14 00:42:25 +00001059// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001060bool
Johnny Chen01a67862011-10-14 00:42:25 +00001061Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001062{
Greg Clayton5160ce52013-03-27 23:08:40 +00001063 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001064 if (log)
1065 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1066
1067 if (!ProcessIsValid())
1068 return false;
1069
Johnny Chen01a67862011-10-14 00:42:25 +00001070 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1071 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001072 {
Johnny Chen01a67862011-10-14 00:42:25 +00001073 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001074 if (rc.Success())
1075 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001076
Johnny Chenf04ee932011-09-22 18:04:58 +00001077 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001078 }
1079 return false;
1080}
1081
Johnny Chen01a67862011-10-14 00:42:25 +00001082// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001083bool
Johnny Chen01a67862011-10-14 00:42:25 +00001084Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001085{
Greg Clayton5160ce52013-03-27 23:08:40 +00001086 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001087 if (log)
1088 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1089
1090 if (!ProcessIsValid())
1091 return false;
1092
Johnny Chen01a67862011-10-14 00:42:25 +00001093 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1094 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +00001095 {
Johnny Chen01a67862011-10-14 00:42:25 +00001096 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +00001097 if (rc.Success())
1098 return true;
Johnny Chen86364b42011-09-20 23:28:55 +00001099
Johnny Chenf04ee932011-09-22 18:04:58 +00001100 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +00001101 }
1102 return false;
1103}
1104
Johnny Chen01a67862011-10-14 00:42:25 +00001105// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +00001106bool
Johnny Chen01a67862011-10-14 00:42:25 +00001107Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +00001108{
Greg Clayton5160ce52013-03-27 23:08:40 +00001109 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +00001110 if (log)
1111 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1112
Jim Inghamb0b45132013-07-02 02:09:46 +00001113 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
1114 if (watch_to_remove_sp == m_last_created_watchpoint)
1115 m_last_created_watchpoint.reset();
1116
Johnny Chen01a67862011-10-14 00:42:25 +00001117 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +00001118 {
Jim Ingham1b5792e2012-12-18 02:03:49 +00001119 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +00001120 return true;
1121 }
1122 return false;
1123}
1124
Johnny Chen01a67862011-10-14 00:42:25 +00001125// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +00001126bool
Johnny Chen01a67862011-10-14 00:42:25 +00001127Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001128{
Greg Clayton5160ce52013-03-27 23:08:40 +00001129 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +00001130 if (log)
1131 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
1132
1133 if (!ProcessIsValid())
1134 return false;
1135
Johnny Chen01a67862011-10-14 00:42:25 +00001136 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
1137 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +00001138 {
Johnny Chen01a67862011-10-14 00:42:25 +00001139 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +00001140 return true;
1141 }
1142 return false;
1143}
1144
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145ModuleSP
1146Target::GetExecutableModule ()
1147{
Aidan Doddsc0c83852015-05-08 09:36:31 +00001148 // search for the first executable in the module list
1149 for (size_t i = 0; i < m_images.GetSize(); ++i)
1150 {
1151 ModuleSP module_sp = m_images.GetModuleAtIndex (i);
1152 lldb_private::ObjectFile * obj = module_sp->GetObjectFile();
1153 if (obj == nullptr)
1154 continue;
1155 if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
1156 return module_sp;
1157 }
1158 // as fall back return the first module loaded
1159 return m_images.GetModuleAtIndex (0);
Greg Claytonaa149cb2011-08-11 02:48:45 +00001160}
1161
1162Module*
1163Target::GetExecutableModulePointer ()
1164{
Aidan Doddsc0c83852015-05-08 09:36:31 +00001165 return GetExecutableModule().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166}
1167
Enrico Granata17598482012-11-08 02:22:02 +00001168static void
1169LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1170{
1171 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001172 StreamString feedback_stream;
1173 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001174 {
Enrico Granata97303392013-05-21 00:00:30 +00001175 if (error.AsCString())
Greg Clayton44d93782014-01-27 23:43:24 +00001176 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001177 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1178 error.AsCString());
Enrico Granata17598482012-11-08 02:22:02 +00001179 }
Enrico Granatafe7295d2014-08-16 00:32:58 +00001180 if (feedback_stream.GetSize())
1181 target->GetDebugger().GetErrorFile()->Printf("%s\n",
1182 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001183}
1184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185void
Greg Claytonb35db632013-11-09 00:03:31 +00001186Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187{
Greg Claytonb35db632013-11-09 00:03:31 +00001188 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001189 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 m_images.Clear();
Greg Clayton5beec212015-10-08 21:04:34 +00001191 m_scratch_type_system_map.Clear();
Sean Callanana3444ff2015-11-10 22:54:42 +00001192 m_ast_importer_sp.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001193}
1194
1195void
Greg Claytonb35db632013-11-09 00:03:31 +00001196Target::DidExec ()
1197{
1198 // When a process exec's we need to know about it so we can do some cleanup.
1199 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1200 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1201}
1202
1203void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001204Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1205{
1206 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001207 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001209 if (executable_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 {
1211 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001212 "Target::SetExecutableModule (executable = '%s')",
1213 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001215 m_images.Append(executable_sp); // The first image is our executable file
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216
Jim Ingham5aee1622010-08-09 23:31:02 +00001217 // 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 +00001218 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001219 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001220 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001221 if (log)
1222 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1223 }
1224
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001226 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001228 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 {
1230 executable_objfile->GetDependentModules(dependent_files);
1231 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1232 {
Greg Claytonded470d2011-03-19 01:12:21 +00001233 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1234 FileSpec platform_dependent_file_spec;
1235 if (m_platform_sp)
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001236 m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001237 else
1238 platform_dependent_file_spec = dependent_file_spec;
1239
Greg Claytonb9a01b32012-02-26 05:51:37 +00001240 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1241 ModuleSP image_module_sp(GetSharedModule (module_spec));
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001242 if (image_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244 ObjectFile *objfile = image_module_sp->GetObjectFile();
1245 if (objfile)
1246 objfile->GetDependentModules(dependent_files);
1247 }
1248 }
1249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 }
1251}
1252
Jim Ingham5aee1622010-08-09 23:31:02 +00001253bool
1254Target::SetArchitecture (const ArchSpec &arch_spec)
1255{
Greg Clayton5160ce52013-03-27 23:08:40 +00001256 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001257 bool missing_local_arch = !m_arch.IsValid();
Jason Molendadad8af42015-11-10 04:11:37 +00001258 bool replace_local_arch = true;
1259 bool compatible_local_arch = false;
1260 ArchSpec other(arch_spec);
1261
1262 if (!missing_local_arch)
Jim Ingham5aee1622010-08-09 23:31:02 +00001263 {
Jason Molendadad8af42015-11-10 04:11:37 +00001264 if (m_arch.IsCompatibleMatch(arch_spec))
1265 {
1266 other.MergeFrom(m_arch);
1267
1268 if (m_arch.IsCompatibleMatch(other))
1269 {
1270 compatible_local_arch = true;
1271 bool arch_changed, vendor_changed, os_changed, os_ver_changed, env_changed;
1272
1273 m_arch.PiecewiseTripleCompare(other,
1274 arch_changed,
1275 vendor_changed,
1276 os_changed,
1277 os_ver_changed,
1278 env_changed);
1279
1280 if (!arch_changed && !vendor_changed && !os_changed)
1281 replace_local_arch = false;
1282 }
1283 }
1284 }
1285
1286 if (compatible_local_arch || missing_local_arch)
1287 {
1288 // If we haven't got a valid arch spec, or the architectures are compatible
1289 // update the architecture, unless the one we already have is more specified
1290 if (replace_local_arch)
1291 m_arch = other;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001292 if (log)
Jason Molendadad8af42015-11-10 04:11:37 +00001293 log->Printf ("Target::SetArchitecture set architecture to %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +00001294 return true;
1295 }
Jason Molendadad8af42015-11-10 04:11:37 +00001296
1297 // If we have an executable file, try to reset the executable to the desired architecture
1298 if (log)
1299 log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
1300 m_arch = other;
1301 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001302
Jason Molendadad8af42015-11-10 04:11:37 +00001303 ClearModules(true);
1304 // Need to do something about unsetting breakpoints.
1305
1306 if (executable_sp)
1307 {
1308 if (log)
1309 log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
1310 ModuleSpec module_spec (executable_sp->GetFileSpec(), other);
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001311 Error error = ModuleList::GetSharedModule(module_spec,
1312 executable_sp,
1313 &GetExecutableSearchPaths(),
1314 nullptr,
1315 nullptr);
Jason Molendadad8af42015-11-10 04:11:37 +00001316
1317 if (!error.Fail() && executable_sp)
Jim Ingham5aee1622010-08-09 23:31:02 +00001318 {
Jason Molendadad8af42015-11-10 04:11:37 +00001319 SetExecutableModule (executable_sp, true);
1320 return true;
Jim Ingham5aee1622010-08-09 23:31:02 +00001321 }
1322 }
Greg Clayton70512312012-05-08 01:45:38 +00001323 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001324}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325
Tamas Berghammere9f4dfe2015-03-13 10:32:42 +00001326bool
1327Target::MergeArchitecture (const ArchSpec &arch_spec)
1328{
1329 if (arch_spec.IsValid())
1330 {
1331 if (m_arch.IsCompatibleMatch(arch_spec))
1332 {
1333 // The current target arch is compatible with "arch_spec", see if we
1334 // can improve our current architecture using bits from "arch_spec"
1335
1336 // Merge bits from arch_spec into "merged_arch" and set our architecture
1337 ArchSpec merged_arch (m_arch);
1338 merged_arch.MergeFrom (arch_spec);
1339 return SetArchitecture(merged_arch);
1340 }
1341 else
1342 {
1343 // The new architecture is different, we just need to replace it
1344 return SetArchitecture(arch_spec);
1345 }
1346 }
1347 return false;
1348}
1349
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001350void
Enrico Granataefe637d2012-11-08 19:16:03 +00001351Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001352{
1353}
1354
1355void
Enrico Granataefe637d2012-11-08 19:16:03 +00001356Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357{
1358 // A module is being added to this target for the first time
Greg Clayton23f8c952014-03-24 23:10:19 +00001359 if (m_valid)
1360 {
1361 ModuleList my_module_list;
1362 my_module_list.Append(module_sp);
1363 LoadScriptingResourceForModule(module_sp, this);
1364 ModulesDidLoad (my_module_list);
1365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366}
1367
1368void
Enrico Granataefe637d2012-11-08 19:16:03 +00001369Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001370{
Adrian McCarthy6ecdbc82015-10-15 22:39:55 +00001371 // A module is being removed from this target.
Greg Clayton23f8c952014-03-24 23:10:19 +00001372 if (m_valid)
1373 {
1374 ModuleList my_module_list;
1375 my_module_list.Append(module_sp);
1376 ModulesDidUnload (my_module_list, false);
1377 }
Enrico Granata17598482012-11-08 02:22:02 +00001378}
1379
1380void
Enrico Granataefe637d2012-11-08 19:16:03 +00001381Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382{
Jim Inghame716ae02011-08-03 01:00:06 +00001383 // A module is replacing an already added module
Greg Clayton23f8c952014-03-24 23:10:19 +00001384 if (m_valid)
Jason Molendad91c3fd2015-11-10 04:18:12 +00001385 {
Greg Clayton23f8c952014-03-24 23:10:19 +00001386 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Jason Molendad91c3fd2015-11-10 04:18:12 +00001387 m_internal_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
1388 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001389}
1390
1391void
1392Target::ModulesDidLoad (ModuleList &module_list)
1393{
Greg Clayton23f8c952014-03-24 23:10:19 +00001394 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001395 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001396 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendad91c3fd2015-11-10 04:18:12 +00001397 m_internal_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001398 if (m_process_sp)
1399 {
Andrew MacPhersoneb4d0602014-03-13 09:37:02 +00001400 m_process_sp->ModulesDidLoad (module_list);
Jason Molendaeef51062013-11-05 03:57:19 +00001401 }
Ilia Keb2c19a2015-03-10 21:59:55 +00001402 BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001403 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404}
1405
1406void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001407Target::SymbolsDidLoad (ModuleList &module_list)
1408{
Greg Clayton23f8c952014-03-24 23:10:19 +00001409 if (m_valid && module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001410 {
Jim Ingham31caf982013-06-04 23:01:35 +00001411 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001412 {
Jim Ingham31caf982013-06-04 23:01:35 +00001413 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1414 if (runtime)
1415 {
1416 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1417 objc_runtime->SymbolsDidLoad(module_list);
1418 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001419 }
Jim Ingham31caf982013-06-04 23:01:35 +00001420
Greg Clayton095eeaa2013-11-05 23:28:00 +00001421 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendad91c3fd2015-11-10 04:18:12 +00001422 m_internal_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Ilia Keb2c19a2015-03-10 21:59:55 +00001423 BroadcastEvent (eBroadcastBitSymbolsLoaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001424 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001425}
1426
1427void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001428Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429{
Greg Clayton23f8c952014-03-24 23:10:19 +00001430 if (m_valid && module_list.GetSize())
Enrico Granata17598482012-11-08 02:22:02 +00001431 {
Greg Clayton8012cad2014-11-17 19:39:20 +00001432 UnloadModuleSections (module_list);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001433 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Jason Molendad91c3fd2015-11-10 04:18:12 +00001434 m_internal_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Ilia Keb2c19a2015-03-10 21:59:55 +00001435 BroadcastEvent (eBroadcastBitModulesUnloaded, new TargetEventData (this->shared_from_this(), module_list));
Enrico Granata17598482012-11-08 02:22:02 +00001436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437}
1438
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001439bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001440Target::ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001441{
Greg Clayton67cc0632012-08-22 17:17:09 +00001442 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001443 {
1444 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001445 ModuleSpec module_spec (module_file_spec);
1446 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001447
1448 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1449 // black list.
1450 if (num_modules > 0)
1451 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001452 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001453 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001454 if (!ModuleIsExcludedForUnconstrainedSearches (matchingModules.GetModuleAtIndex(i)))
Jim Inghamc6674fd2011-10-28 23:14:11 +00001455 return false;
1456 }
1457 return true;
1458 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001459 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001460 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001461}
1462
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001463bool
Jim Ingham33df7cd2014-12-06 01:28:03 +00001464Target::ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001465{
Greg Clayton67cc0632012-08-22 17:17:09 +00001466 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001467 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001468 if (m_platform_sp)
Jim Ingham33df7cd2014-12-06 01:28:03 +00001469 return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001470 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001471 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001472}
1473
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474size_t
Greg Claytondb598232011-01-07 01:57:07 +00001475Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1476{
Greg Claytone72dfb32012-02-24 01:59:29 +00001477 SectionSP section_sp (addr.GetSection());
1478 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001479 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001480 // 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 +00001481 if (section_sp->IsEncrypted())
1482 {
Greg Clayton57f06302012-05-25 17:05:55 +00001483 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001484 return 0;
1485 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001486 ModuleSP module_sp (section_sp->GetModule());
1487 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001488 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001489 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1490 if (objfile)
1491 {
1492 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1493 addr.GetOffset(),
1494 dst,
1495 dst_len);
1496 if (bytes_read > 0)
1497 return bytes_read;
1498 else
1499 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1500 }
Greg Claytondb598232011-01-07 01:57:07 +00001501 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001502 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001503 }
1504 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001505 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001506 }
1507 else
Greg Claytondb598232011-01-07 01:57:07 +00001508 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001509
Greg Claytondb598232011-01-07 01:57:07 +00001510 return 0;
1511}
1512
1513size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001514Target::ReadMemory (const Address& addr,
1515 bool prefer_file_cache,
1516 void *dst,
1517 size_t dst_len,
1518 Error &error,
1519 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001521 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001522
Enrico Granata9128ee22011-09-06 19:20:51 +00001523 // if we end up reading this from process memory, we will fill this
1524 // with the actual load address
1525 if (load_addr_ptr)
1526 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1527
Greg Claytondb598232011-01-07 01:57:07 +00001528 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001529
1530 addr_t load_addr = LLDB_INVALID_ADDRESS;
1531 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001532 Address resolved_addr;
1533 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001534 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001535 SectionLoadList &section_load_list = GetSectionLoadList();
1536 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001537 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001538 // No sections are loaded, so we must assume we are not running
1539 // yet and anything we are given is a file address.
1540 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1541 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001542 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001543 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001544 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001545 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001546 // we have manually loaded some sections with "target modules load ..."
1547 // or because we have have a live process that has sections loaded
1548 // through the dynamic loader
1549 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001550 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001551 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001552 }
Greg Clayton357132e2011-03-26 19:14:58 +00001553 if (!resolved_addr.IsValid())
1554 resolved_addr = addr;
Greg Claytonc749eb82011-07-11 05:12:02 +00001555
Greg Claytondb598232011-01-07 01:57:07 +00001556 if (prefer_file_cache)
1557 {
1558 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1559 if (bytes_read > 0)
1560 return bytes_read;
1561 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001562
Johnny Chen86364b42011-09-20 23:28:55 +00001563 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001564 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001565 if (load_addr == LLDB_INVALID_ADDRESS)
1566 load_addr = resolved_addr.GetLoadAddress (this);
1567
Greg Claytondda4f7b2010-06-30 23:03:03 +00001568 if (load_addr == LLDB_INVALID_ADDRESS)
1569 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001570 ModuleSP addr_module_sp (resolved_addr.GetModule());
1571 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001572 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Jim Ingham4af59612014-12-19 19:20:44 +00001573 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Jason Molenda7e589a62011-09-20 00:26:08 +00001574 resolved_addr.GetFileAddress(),
Jim Ingham4af59612014-12-19 19:20:44 +00001575 addr_module_sp->GetFileSpec().GetFilename().AsCString("<Unknonw>"));
Greg Claytondda4f7b2010-06-30 23:03:03 +00001576 else
Daniel Malead01b2952012-11-29 21:49:15 +00001577 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001578 }
1579 else
1580 {
Greg Claytondb598232011-01-07 01:57:07 +00001581 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582 if (bytes_read != dst_len)
1583 {
1584 if (error.Success())
1585 {
1586 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001587 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588 else
Daniel Malead01b2952012-11-29 21:49:15 +00001589 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 +00001590 }
1591 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001592 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001593 {
1594 if (load_addr_ptr)
1595 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001596 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001597 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001598 // If the address is not section offset we have an address that
1599 // doesn't resolve to any address in any currently loaded shared
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001600 // libraries and we failed to read memory so there isn't anything
Greg Claytondda4f7b2010-06-30 23:03:03 +00001601 // more we can do. If it is section offset, we might be able to
1602 // read cached memory from the object file.
1603 if (!resolved_addr.IsSectionOffset())
1604 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001606 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001607
Greg Claytonc749eb82011-07-11 05:12:02 +00001608 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001609 {
Greg Claytondb598232011-01-07 01:57:07 +00001610 // If we didn't already try and read from the object file cache, then
1611 // try it after failing to read from the process.
1612 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001613 }
1614 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615}
1616
Greg Claytond16e1e52011-07-12 17:06:17 +00001617size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001618Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1619{
1620 char buf[256];
1621 out_str.clear();
1622 addr_t curr_addr = addr.GetLoadAddress(this);
1623 Address address(addr);
1624 while (1)
1625 {
1626 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1627 if (length == 0)
1628 break;
1629 out_str.append(buf, length);
1630 // If we got "length - 1" bytes, we didn't get the whole C string, we
1631 // need to read some more characters
1632 if (length == sizeof(buf) - 1)
1633 curr_addr += length;
1634 else
1635 break;
1636 address = Address(curr_addr);
1637 }
1638 return out_str.size();
1639}
1640
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001641size_t
1642Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1643{
1644 size_t total_cstr_len = 0;
1645 if (dst && dst_max_len)
1646 {
1647 result_error.Clear();
1648 // NULL out everything just to be safe
1649 memset (dst, 0, dst_max_len);
1650 Error error;
1651 addr_t curr_addr = addr.GetLoadAddress(this);
1652 Address address(addr);
Jason Molendaf0340c92014-09-03 22:30:54 +00001653
1654 // We could call m_process_sp->GetMemoryCacheLineSize() but I don't
1655 // think this really needs to be tied to the memory cache subsystem's
1656 // cache line size, so leave this as a fixed constant.
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001657 const size_t cache_line_size = 512;
Jason Molendaf0340c92014-09-03 22:30:54 +00001658
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001659 size_t bytes_left = dst_max_len - 1;
1660 char *curr_dst = dst;
1661
1662 while (bytes_left > 0)
1663 {
1664 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1665 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1666 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1667
1668 if (bytes_read == 0)
1669 {
1670 result_error = error;
1671 dst[total_cstr_len] = '\0';
1672 break;
1673 }
1674 const size_t len = strlen(curr_dst);
1675
1676 total_cstr_len += len;
1677
1678 if (len < bytes_to_read)
1679 break;
1680
1681 curr_dst += bytes_read;
1682 curr_addr += bytes_read;
1683 bytes_left -= bytes_read;
1684 address = Address(curr_addr);
1685 }
1686 }
1687 else
1688 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00001689 if (dst == nullptr)
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001690 result_error.SetErrorString("invalid arguments");
1691 else
1692 result_error.Clear();
1693 }
1694 return total_cstr_len;
1695}
1696
1697size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001698Target::ReadScalarIntegerFromMemory (const Address& addr,
1699 bool prefer_file_cache,
1700 uint32_t byte_size,
1701 bool is_signed,
1702 Scalar &scalar,
1703 Error &error)
1704{
1705 uint64_t uval;
1706
1707 if (byte_size <= sizeof(uval))
1708 {
1709 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1710 if (bytes_read == byte_size)
1711 {
1712 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001713 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001714 if (byte_size <= 4)
1715 scalar = data.GetMaxU32 (&offset, byte_size);
1716 else
1717 scalar = data.GetMaxU64 (&offset, byte_size);
1718
1719 if (is_signed)
1720 scalar.SignExtend(byte_size * 8);
1721 return bytes_read;
1722 }
1723 }
1724 else
1725 {
1726 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1727 }
1728 return 0;
1729}
1730
1731uint64_t
1732Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1733 bool prefer_file_cache,
1734 size_t integer_byte_size,
1735 uint64_t fail_value,
1736 Error &error)
1737{
1738 Scalar scalar;
1739 if (ReadScalarIntegerFromMemory (addr,
1740 prefer_file_cache,
1741 integer_byte_size,
1742 false,
1743 scalar,
1744 error))
1745 return scalar.ULongLong(fail_value);
1746 return fail_value;
1747}
1748
1749bool
1750Target::ReadPointerFromMemory (const Address& addr,
1751 bool prefer_file_cache,
1752 Error &error,
1753 Address &pointer_addr)
1754{
1755 Scalar scalar;
1756 if (ReadScalarIntegerFromMemory (addr,
1757 prefer_file_cache,
1758 m_arch.GetAddressByteSize(),
1759 false,
1760 scalar,
1761 error))
1762 {
1763 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1764 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1765 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001766 SectionLoadList &section_load_list = GetSectionLoadList();
1767 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001768 {
1769 // No sections are loaded, so we must assume we are not running
1770 // yet and anything we are given is a file address.
1771 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1772 }
1773 else
1774 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001775 // We have at least one section loaded. This can be because
Greg Claytond16e1e52011-07-12 17:06:17 +00001776 // we have manually loaded some sections with "target modules load ..."
1777 // or because we have have a live process that has sections loaded
1778 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001779 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001780 }
1781 // We weren't able to resolve the pointer value, so just return
1782 // an address with no section
1783 if (!pointer_addr.IsValid())
1784 pointer_addr.SetOffset (pointer_vm_addr);
1785 return true;
1786
1787 }
1788 }
1789 return false;
1790}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791
1792ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001793Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 ModuleSP module_sp;
1796
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001797 Error error;
1798
Jim Ingham4a94c912012-05-17 18:38:42 +00001799 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1800 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001801
Jim Ingham4a94c912012-05-17 18:38:42 +00001802 if (module_spec.GetUUID().IsValid())
1803 module_sp = m_images.FindFirstModule(module_spec);
1804
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001805 if (!module_sp)
1806 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001807 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1808 bool did_create_module = false;
1809
1810 // If there are image search path entries, try to use them first to acquire a suitable image.
1811 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001812 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001813 ModuleSpec transformed_spec (module_spec);
1814 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1815 {
1816 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1817 error = ModuleList::GetSharedModule (transformed_spec,
1818 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001819 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001820 &old_module_sp,
1821 &did_create_module);
1822 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001823 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001824
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001825 if (!module_sp)
1826 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001827 // If we have a UUID, we can check our global shared module list in case
1828 // we already have it. If we don't have a valid UUID, then we can't since
1829 // the path in "module_spec" will be a platform path, and we will need to
1830 // let the platform find that file. For example, we could be asking for
1831 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1832 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1833 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1834 // cache.
1835 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001836 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001837 // We have a UUID, it is OK to check the global module list...
1838 error = ModuleList::GetSharedModule (module_spec,
1839 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001840 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001841 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001842 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001843 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001844
1845 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001846 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001847 // The platform is responsible for finding and caching an appropriate
1848 // module in the shared module cache.
1849 if (m_platform_sp)
1850 {
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001851 error = m_platform_sp->GetSharedModule (module_spec,
1852 m_process_sp.get(),
1853 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001854 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001855 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001856 &did_create_module);
1857 }
1858 else
1859 {
1860 error.SetErrorString("no platform is currently set");
1861 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001862 }
1863 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864
Jim Ingham4a94c912012-05-17 18:38:42 +00001865 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1866 // module in the list already, and if there was, let's remove it.
1867 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001869 ObjectFile *objfile = module_sp->GetObjectFile();
1870 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001871 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001872 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001873 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001874 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1875 case ObjectFile::eTypeExecutable: /// A normal executable
1876 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1877 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1878 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1879 break;
1880 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1881 if (error_ptr)
1882 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1883 return ModuleSP();
1884 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1885 if (error_ptr)
1886 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1887 return ModuleSP();
1888 default:
1889 if (error_ptr)
1890 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1891 return ModuleSP();
1892 }
1893 // GetSharedModule is not guaranteed to find the old shared module, for instance
1894 // in the common case where you pass in the UUID, it is only going to find the one
1895 // module matching the UUID. In fact, it has no good way to know what the "old module"
1896 // relevant to this target is, since there might be many copies of a module with this file spec
1897 // in various running debug sessions, but only one of them will belong to this target.
1898 // So let's remove the UUID from the module list, and look in the target's module list.
1899 // Only do this if there is SOMETHING else in the module spec...
1900 if (!old_module_sp)
1901 {
1902 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001903 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001904 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1905 module_spec_copy.GetUUID().Clear();
1906
1907 ModuleList found_modules;
1908 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1909 if (num_found == 1)
1910 {
1911 old_module_sp = found_modules.GetModuleAtIndex(0);
1912 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001913 }
1914 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001915
1916 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1917 {
1918 m_images.ReplaceModule(old_module_sp, module_sp);
1919 Module *old_module_ptr = old_module_sp.get();
1920 old_module_sp.reset();
1921 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1922 }
1923 else
1924 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001925 }
Greg Clayton86e70cb2014-04-07 23:50:17 +00001926 else
1927 module_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001928 }
1929 }
1930 if (error_ptr)
1931 *error_ptr = error;
1932 return module_sp;
1933}
1934
Greg Claytond9e416c2012-02-18 05:35:26 +00001935TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936Target::CalculateTarget ()
1937{
Greg Claytond9e416c2012-02-18 05:35:26 +00001938 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001939}
1940
Greg Claytond9e416c2012-02-18 05:35:26 +00001941ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942Target::CalculateProcess ()
1943{
Sean Callanan92734d12016-02-12 19:45:31 +00001944 return m_process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945}
1946
Greg Claytond9e416c2012-02-18 05:35:26 +00001947ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948Target::CalculateThread ()
1949{
Greg Claytond9e416c2012-02-18 05:35:26 +00001950 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001951}
1952
Jason Molendab57e4a12013-11-04 09:33:30 +00001953StackFrameSP
1954Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001955{
Jason Molendab57e4a12013-11-04 09:33:30 +00001956 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001957}
1958
1959void
Greg Clayton0603aa92010-10-04 01:05:56 +00001960Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001961{
Greg Claytonc14ee322011-09-22 04:58:26 +00001962 exe_ctx.Clear();
1963 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001964}
1965
1966PathMappingList &
1967Target::GetImageSearchPathList ()
1968{
1969 return m_image_search_paths;
1970}
1971
1972void
Eugene Zelenko8f30a652015-10-23 18:39:37 +00001973Target::ImageSearchPathsChanged(const PathMappingList &path_list,
1974 void *baton)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975{
1976 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001977 ModuleSP exe_module_sp (target->GetExecutableModule());
1978 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001979 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001980}
1981
Jim Ingham151c0322015-09-15 21:13:50 +00001982TypeSystem *
Sean Callanana994b0b2015-10-02 18:40:30 +00001983Target::GetScratchTypeSystemForLanguage (Error *error, lldb::LanguageType language, bool create_on_demand)
Jim Ingham151c0322015-09-15 21:13:50 +00001984{
Greg Clayton5beec212015-10-08 21:04:34 +00001985 if (!m_valid)
1986 return nullptr;
1987
Sean Callanana994b0b2015-10-02 18:40:30 +00001988 if (error)
1989 {
1990 error->Clear();
1991 }
1992
Sean Callananb92bd752015-10-01 16:28:02 +00001993 if (language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all assembly code
Sean Callanana994b0b2015-10-02 18:40:30 +00001994 || language == eLanguageTypeUnknown)
1995 {
Sean Callananc7b054a2015-10-09 18:01:10 +00001996 std::set<lldb::LanguageType> languages_for_types;
1997 std::set<lldb::LanguageType> languages_for_expressions;
1998
1999 Language::GetLanguagesSupportingTypeSystems(languages_for_types, languages_for_expressions);
2000
2001 if (languages_for_expressions.count(eLanguageTypeC))
2002 {
2003 language = eLanguageTypeC; // LLDB's default. Override by setting the target language.
2004 }
2005 else
2006 {
2007 if (languages_for_expressions.empty())
2008 {
2009 return nullptr;
2010 }
2011 else
2012 {
2013 language = *languages_for_expressions.begin();
2014 }
2015 }
Sean Callananb92bd752015-10-01 16:28:02 +00002016 }
Sean Callananb92bd752015-10-01 16:28:02 +00002017
Greg Clayton5beec212015-10-08 21:04:34 +00002018 return m_scratch_type_system_map.GetTypeSystemForLanguage(language, this, create_on_demand);
Sean Callananb92bd752015-10-01 16:28:02 +00002019}
2020
2021PersistentExpressionState *
2022Target::GetPersistentExpressionStateForLanguage (lldb::LanguageType language)
2023{
Sean Callanana994b0b2015-10-02 18:40:30 +00002024 TypeSystem *type_system = GetScratchTypeSystemForLanguage(nullptr, language, true);
Sean Callananb92bd752015-10-01 16:28:02 +00002025
2026 if (type_system)
2027 {
2028 return type_system->GetPersistentExpressionState();
2029 }
Jim Ingham151c0322015-09-15 21:13:50 +00002030 else
Sean Callananb92bd752015-10-01 16:28:02 +00002031 {
2032 return nullptr;
2033 }
Jim Ingham151c0322015-09-15 21:13:50 +00002034}
2035
2036UserExpression *
2037Target::GetUserExpressionForLanguage(const char *expr,
Sean Callanana994b0b2015-10-02 18:40:30 +00002038 const char *expr_prefix,
2039 lldb::LanguageType language,
2040 Expression::ResultType desired_type,
Jim Ingham19a63fc2015-11-03 02:11:24 +00002041 const EvaluateExpressionOptions &options,
Sean Callanana994b0b2015-10-02 18:40:30 +00002042 Error &error)
Jim Ingham151c0322015-09-15 21:13:50 +00002043{
Sean Callanana994b0b2015-10-02 18:40:30 +00002044 Error type_system_error;
2045
2046 TypeSystem *type_system = GetScratchTypeSystemForLanguage (&type_system_error, language);
Jim Ingham151c0322015-09-15 21:13:50 +00002047 UserExpression *user_expr = nullptr;
2048
2049 if (!type_system)
2050 {
Sean Callanana994b0b2015-10-02 18:40:30 +00002051 error.SetErrorStringWithFormat("Could not find type system for language %s: %s", Language::GetNameForLanguageType(language), type_system_error.AsCString());
Jim Ingham151c0322015-09-15 21:13:50 +00002052 return nullptr;
2053 }
2054
Jim Ingham19a63fc2015-11-03 02:11:24 +00002055 user_expr = type_system->GetUserExpression(expr, expr_prefix, language, desired_type, options);
Jim Ingham151c0322015-09-15 21:13:50 +00002056 if (!user_expr)
2057 error.SetErrorStringWithFormat("Could not create an expression for language %s", Language::GetNameForLanguageType(language));
2058
2059 return user_expr;
2060}
2061
2062FunctionCaller *
2063Target::GetFunctionCallerForLanguage (lldb::LanguageType language,
2064 const CompilerType &return_type,
2065 const Address& function_address,
2066 const ValueList &arg_value_list,
2067 const char *name,
2068 Error &error)
2069{
Sean Callanana994b0b2015-10-02 18:40:30 +00002070 Error type_system_error;
2071 TypeSystem *type_system = GetScratchTypeSystemForLanguage (&type_system_error, language);
Jim Ingham151c0322015-09-15 21:13:50 +00002072 FunctionCaller *persistent_fn = nullptr;
2073
2074 if (!type_system)
2075 {
Sean Callanana994b0b2015-10-02 18:40:30 +00002076 error.SetErrorStringWithFormat("Could not find type system for language %s: %s", Language::GetNameForLanguageType(language), type_system_error.AsCString());
Jim Ingham151c0322015-09-15 21:13:50 +00002077 return persistent_fn;
2078 }
2079
2080 persistent_fn = type_system->GetFunctionCaller (return_type, function_address, arg_value_list, name);
2081 if (!persistent_fn)
2082 error.SetErrorStringWithFormat("Could not create an expression for language %s", Language::GetNameForLanguageType(language));
2083
2084 return persistent_fn;
2085}
2086
2087UtilityFunction *
2088Target::GetUtilityFunctionForLanguage (const char *text,
2089 lldb::LanguageType language,
2090 const char *name,
2091 Error &error)
2092{
Sean Callanana994b0b2015-10-02 18:40:30 +00002093 Error type_system_error;
2094 TypeSystem *type_system = GetScratchTypeSystemForLanguage (&type_system_error, language);
Jim Ingham151c0322015-09-15 21:13:50 +00002095 UtilityFunction *utility_fn = nullptr;
2096
2097 if (!type_system)
2098 {
Sean Callanana994b0b2015-10-02 18:40:30 +00002099 error.SetErrorStringWithFormat("Could not find type system for language %s: %s", Language::GetNameForLanguageType(language), type_system_error.AsCString());
Jim Ingham151c0322015-09-15 21:13:50 +00002100 return utility_fn;
2101 }
2102
2103 utility_fn = type_system->GetUtilityFunction (text, name);
2104 if (!utility_fn)
2105 error.SetErrorStringWithFormat("Could not create an expression for language %s", Language::GetNameForLanguageType(language));
2106
2107 return utility_fn;
2108}
2109
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002110ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00002111Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002112{
Greg Clayton5beec212015-10-08 21:04:34 +00002113 if (m_valid)
Sean Callanan4bf80d52011-11-15 22:27:19 +00002114 {
Greg Clayton5beec212015-10-08 21:04:34 +00002115 if (TypeSystem* type_system = GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC, create_on_demand))
2116 return llvm::dyn_cast<ClangASTContext>(type_system);
Sean Callanan4bf80d52011-11-15 22:27:19 +00002117 }
Greg Clayton5beec212015-10-08 21:04:34 +00002118 return nullptr;
Sean Callananb92bd752015-10-01 16:28:02 +00002119}
2120
Sean Callanana3444ff2015-11-10 22:54:42 +00002121ClangASTImporterSP
Sean Callanan686b2312011-11-16 18:20:47 +00002122Target::GetClangASTImporter()
2123{
Greg Clayton5beec212015-10-08 21:04:34 +00002124 if (m_valid)
Sean Callanan686b2312011-11-16 18:20:47 +00002125 {
Sean Callanana3444ff2015-11-10 22:54:42 +00002126 if (!m_ast_importer_sp)
Greg Clayton5beec212015-10-08 21:04:34 +00002127 {
Sean Callanana3444ff2015-11-10 22:54:42 +00002128 m_ast_importer_sp.reset(new ClangASTImporter());
Greg Clayton5beec212015-10-08 21:04:34 +00002129 }
Sean Callanana3444ff2015-11-10 22:54:42 +00002130 return m_ast_importer_sp;
Sean Callanan686b2312011-11-16 18:20:47 +00002131 }
Sean Callanana3444ff2015-11-10 22:54:42 +00002132 return ClangASTImporterSP();
Sean Callanan686b2312011-11-16 18:20:47 +00002133}
2134
Greg Clayton99d0faf2010-11-18 23:32:35 +00002135void
Caroline Tice20bd37f2011-03-10 22:14:10 +00002136Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00002137{
Greg Clayton6920b522012-08-22 18:39:03 +00002138 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00002139}
Caroline Ticedaccaa92010-09-20 20:44:43 +00002140
Greg Clayton99d0faf2010-11-18 23:32:35 +00002141void
Caroline Tice20bd37f2011-03-10 22:14:10 +00002142Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00002143{
Greg Clayton6920b522012-08-22 18:39:03 +00002144 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00002145}
Caroline Ticedaccaa92010-09-20 20:44:43 +00002146
Greg Claytonc859e2d2012-02-13 23:10:39 +00002147FileSpecList
2148Target::GetDefaultExecutableSearchPaths ()
2149{
Greg Clayton67cc0632012-08-22 17:17:09 +00002150 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
2151 if (properties_sp)
2152 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00002153 return FileSpecList();
2154}
2155
Michael Sartaina7499c92013-07-01 19:45:50 +00002156FileSpecList
2157Target::GetDefaultDebugFileSearchPaths ()
2158{
2159 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
2160 if (properties_sp)
2161 return properties_sp->GetDebugFileSearchPaths();
2162 return FileSpecList();
2163}
2164
Sean Callanan85054342015-04-03 15:39:47 +00002165FileSpecList
2166Target::GetDefaultClangModuleSearchPaths ()
2167{
2168 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
2169 if (properties_sp)
2170 return properties_sp->GetClangModuleSearchPaths();
2171 return FileSpecList();
2172}
2173
Caroline Ticedaccaa92010-09-20 20:44:43 +00002174ArchSpec
2175Target::GetDefaultArchitecture ()
2176{
Greg Clayton67cc0632012-08-22 17:17:09 +00002177 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
2178 if (properties_sp)
2179 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00002180 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00002181}
2182
2183void
Greg Clayton67cc0632012-08-22 17:17:09 +00002184Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002185{
Greg Clayton67cc0632012-08-22 17:17:09 +00002186 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
2187 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00002188 {
2189 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 +00002190 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00002191 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002192}
2193
Greg Clayton0603aa92010-10-04 01:05:56 +00002194Target *
2195Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
2196{
2197 // The target can either exist in the "process" of ExecutionContext, or in
2198 // the "target_sp" member of SymbolContext. This accessor helper function
2199 // will get the target from one of these locations.
2200
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002201 Target *target = nullptr;
2202 if (sc_ptr != nullptr)
Greg Clayton0603aa92010-10-04 01:05:56 +00002203 target = sc_ptr->target_sp.get();
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002204 if (target == nullptr && exe_ctx_ptr)
Greg Claytonc14ee322011-09-22 04:58:26 +00002205 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00002206 return target;
2207}
2208
Jim Ingham1624a2d2014-05-05 02:26:40 +00002209ExpressionResults
Eugene Zelenko8f30a652015-10-23 18:39:37 +00002210Target::EvaluateExpression(const char *expr_cstr,
Jim Inghama309efe2015-10-28 22:23:17 +00002211 ExecutionContextScope *exe_scope,
Eugene Zelenko8f30a652015-10-23 18:39:37 +00002212 lldb::ValueObjectSP &result_valobj_sp,
2213 const EvaluateExpressionOptions& options)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002214{
Enrico Granata97fca502012-09-18 17:43:16 +00002215 result_valobj_sp.reset();
2216
Jim Ingham8646d3c2014-05-05 02:47:44 +00002217 ExpressionResults execution_results = eExpressionSetupError;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002218
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002219 if (expr_cstr == nullptr || expr_cstr[0] == '\0')
Greg Claytond1767f02011-12-08 02:13:16 +00002220 return execution_results;
2221
Jim Ingham6026ca32011-05-12 02:06:14 +00002222 // We shouldn't run stop hooks in expressions.
2223 // Be sure to reset this if you return anywhere within this function.
2224 bool old_suppress_value = m_suppress_stop_hooks;
2225 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002226
2227 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002228
Jim Inghama309efe2015-10-28 22:23:17 +00002229 if (exe_scope)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002230 {
Jim Inghama309efe2015-10-28 22:23:17 +00002231 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002232 }
2233 else if (m_process_sp)
2234 {
2235 m_process_sp->CalculateExecutionContext(exe_ctx);
2236 }
2237 else
2238 {
2239 CalculateExecutionContext(exe_ctx);
2240 }
2241
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002242 // Make sure we aren't just trying to see the value of a persistent
2243 // variable (something like "$0")
Sean Callananbc8ac342015-09-04 20:49:51 +00002244 lldb::ExpressionVariableSP persistent_var_sp;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002245 // Only check for persistent variables the expression starts with a '$'
2246 if (expr_cstr[0] == '$')
Sean Callanana994b0b2015-10-02 18:40:30 +00002247 persistent_var_sp = GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC)->GetPersistentExpressionState()->GetVariable (expr_cstr);
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002248
2249 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002250 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002251 result_valobj_sp = persistent_var_sp->GetValueObject ();
Jim Ingham8646d3c2014-05-05 02:47:44 +00002252 execution_results = eExpressionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002253 }
2254 else
2255 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00002256 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00002257 Error error;
Jim Ingham151c0322015-09-15 21:13:50 +00002258 execution_results = UserExpression::Evaluate (exe_ctx,
2259 options,
2260 expr_cstr,
2261 prefix,
2262 result_valobj_sp,
2263 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002264 }
Jim Ingham6026ca32011-05-12 02:06:14 +00002265
2266 m_suppress_stop_hooks = old_suppress_value;
2267
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002268 return execution_results;
2269}
2270
Sean Callanan8f1f9a12015-09-30 19:57:57 +00002271lldb::ExpressionVariableSP
2272Target::GetPersistentVariable(const ConstString &name)
Zachary Turner32abc6e2015-03-03 19:23:09 +00002273{
Greg Clayton5beec212015-10-08 21:04:34 +00002274 lldb::ExpressionVariableSP variable_sp;
2275 m_scratch_type_system_map.ForEach([this, name, &variable_sp](TypeSystem *type_system) -> bool
Sean Callanan8f1f9a12015-09-30 19:57:57 +00002276 {
Greg Clayton5beec212015-10-08 21:04:34 +00002277 if (PersistentExpressionState *persistent_state = type_system->GetPersistentExpressionState())
Sean Callanan8f1f9a12015-09-30 19:57:57 +00002278 {
Greg Clayton5beec212015-10-08 21:04:34 +00002279 variable_sp = persistent_state->GetVariable(name);
2280
2281 if (variable_sp)
2282 return false; // Stop iterating the ForEach
Sean Callanan8f1f9a12015-09-30 19:57:57 +00002283 }
Greg Clayton5beec212015-10-08 21:04:34 +00002284 return true; // Keep iterating the ForEach
2285 });
2286 return variable_sp;
Zachary Turner32abc6e2015-03-03 19:23:09 +00002287}
2288
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002289lldb::addr_t
Sean Callananb92bd752015-10-01 16:28:02 +00002290Target::GetPersistentSymbol(const ConstString &name)
2291{
Greg Clayton5beec212015-10-08 21:04:34 +00002292 lldb::addr_t address = LLDB_INVALID_ADDRESS;
Sean Callananb92bd752015-10-01 16:28:02 +00002293
Greg Clayton5beec212015-10-08 21:04:34 +00002294 m_scratch_type_system_map.ForEach([this, name, &address](TypeSystem *type_system) -> bool
Sean Callananb92bd752015-10-01 16:28:02 +00002295 {
Greg Clayton5beec212015-10-08 21:04:34 +00002296 if (PersistentExpressionState *persistent_state = type_system->GetPersistentExpressionState())
Sean Callananb92bd752015-10-01 16:28:02 +00002297 {
Greg Clayton5beec212015-10-08 21:04:34 +00002298 address = persistent_state->LookupSymbol(name);
2299 if (address != LLDB_INVALID_ADDRESS)
2300 return false; // Stop iterating the ForEach
Sean Callananb92bd752015-10-01 16:28:02 +00002301 }
Greg Clayton5beec212015-10-08 21:04:34 +00002302 return true; // Keep iterating the ForEach
2303 });
2304 return address;
Sean Callananb92bd752015-10-01 16:28:02 +00002305}
2306
2307lldb::addr_t
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002308Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2309{
2310 addr_t code_addr = load_addr;
2311 switch (m_arch.GetMachine())
2312 {
Jaydeep Patil44d07fc2015-09-22 06:36:56 +00002313 case llvm::Triple::mips:
2314 case llvm::Triple::mipsel:
2315 case llvm::Triple::mips64:
2316 case llvm::Triple::mips64el:
2317 switch (addr_class)
2318 {
2319 case eAddressClassData:
2320 case eAddressClassDebug:
2321 return LLDB_INVALID_ADDRESS;
2322
2323 case eAddressClassUnknown:
2324 case eAddressClassInvalid:
2325 case eAddressClassCode:
2326 case eAddressClassCodeAlternateISA:
2327 case eAddressClassRuntime:
2328 if ((code_addr & 2ull) || (addr_class == eAddressClassCodeAlternateISA))
2329 code_addr |= 1ull;
2330 break;
2331 }
2332 break;
2333
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002334 case llvm::Triple::arm:
2335 case llvm::Triple::thumb:
2336 switch (addr_class)
2337 {
2338 case eAddressClassData:
2339 case eAddressClassDebug:
2340 return LLDB_INVALID_ADDRESS;
2341
2342 case eAddressClassUnknown:
2343 case eAddressClassInvalid:
2344 case eAddressClassCode:
2345 case eAddressClassCodeAlternateISA:
2346 case eAddressClassRuntime:
2347 // Check if bit zero it no set?
2348 if ((code_addr & 1ull) == 0)
2349 {
2350 // Bit zero isn't set, check if the address is a multiple of 2?
2351 if (code_addr & 2ull)
2352 {
2353 // The address is a multiple of 2 so it must be thumb, set bit zero
2354 code_addr |= 1ull;
2355 }
2356 else if (addr_class == eAddressClassCodeAlternateISA)
2357 {
2358 // We checked the address and the address claims to be the alternate ISA
2359 // which means thumb, so set bit zero.
2360 code_addr |= 1ull;
2361 }
2362 }
2363 break;
2364 }
2365 break;
2366
2367 default:
2368 break;
2369 }
2370 return code_addr;
2371}
2372
2373lldb::addr_t
2374Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
2375{
2376 addr_t opcode_addr = load_addr;
2377 switch (m_arch.GetMachine())
2378 {
Jaydeep Patil44d07fc2015-09-22 06:36:56 +00002379 case llvm::Triple::mips:
2380 case llvm::Triple::mipsel:
2381 case llvm::Triple::mips64:
2382 case llvm::Triple::mips64el:
Greg Claytonf3ef3d22011-05-22 22:46:53 +00002383 case llvm::Triple::arm:
2384 case llvm::Triple::thumb:
2385 switch (addr_class)
2386 {
2387 case eAddressClassData:
2388 case eAddressClassDebug:
2389 return LLDB_INVALID_ADDRESS;
2390
2391 case eAddressClassInvalid:
2392 case eAddressClassUnknown:
2393 case eAddressClassCode:
2394 case eAddressClassCodeAlternateISA:
2395 case eAddressClassRuntime:
2396 opcode_addr &= ~(1ull);
2397 break;
2398 }
2399 break;
2400
2401 default:
2402 break;
2403 }
2404 return opcode_addr;
2405}
2406
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002407lldb::addr_t
2408Target::GetBreakableLoadAddress (lldb::addr_t addr)
2409{
2410 addr_t breakable_addr = addr;
2411 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
2412
2413 switch (m_arch.GetMachine())
2414 {
2415 default:
2416 break;
2417 case llvm::Triple::mips:
2418 case llvm::Triple::mipsel:
2419 case llvm::Triple::mips64:
2420 case llvm::Triple::mips64el:
2421 {
2422 addr_t function_start = 0;
2423 addr_t current_offset = 0;
2424 uint32_t loop_count = 0;
2425 Address resolved_addr;
2426 uint32_t arch_flags = m_arch.GetFlags ();
2427 bool IsMips16 = arch_flags & ArchSpec::eMIPSAse_mips16;
2428 bool IsMicromips = arch_flags & ArchSpec::eMIPSAse_micromips;
2429 SectionLoadList &section_load_list = GetSectionLoadList();
2430
2431 if (section_load_list.IsEmpty())
2432 // No sections are loaded, so we must assume we are not running yet
2433 // and need to operate only on file address.
2434 m_images.ResolveFileAddress (addr, resolved_addr);
2435 else
2436 section_load_list.ResolveLoadAddress(addr, resolved_addr);
2437
2438 // Get the function boundaries to make sure we don't scan back before the beginning of the current function.
2439 ModuleSP temp_addr_module_sp (resolved_addr.GetModule());
2440 if (temp_addr_module_sp)
2441 {
2442 SymbolContext sc;
2443 uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;
Greg Clayton6071e6f2015-08-26 22:57:51 +00002444 temp_addr_module_sp->ResolveSymbolContextForAddress(resolved_addr, resolve_scope, sc);
Bhushan D. Attardedf5f0b42016-01-27 10:16:30 +00002445 Address sym_addr;
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002446 if (sc.function)
Bhushan D. Attardedf5f0b42016-01-27 10:16:30 +00002447 sym_addr = sc.function->GetAddressRange().GetBaseAddress();
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002448 else if (sc.symbol)
Bhushan D. Attardedf5f0b42016-01-27 10:16:30 +00002449 sym_addr = sc.symbol->GetAddress();
2450
2451 function_start = sym_addr.GetLoadAddress(this);
2452 if (function_start == LLDB_INVALID_ADDRESS)
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002453 function_start = sym_addr.GetFileAddress();
Bhushan D. Attardedf5f0b42016-01-27 10:16:30 +00002454
2455 if (function_start)
2456 current_offset = addr - function_start;
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002457 }
2458
2459 // If breakpoint address is start of function then we dont have to do anything.
2460 if (current_offset == 0)
2461 return breakable_addr;
2462 else
2463 loop_count = current_offset / 2;
2464
2465 if (loop_count > 3)
2466 {
2467 // Scan previous 6 bytes
2468 if (IsMips16 | IsMicromips)
2469 loop_count = 3;
2470 // For mips-only, instructions are always 4 bytes, so scan previous 4 bytes only.
2471 else
2472 loop_count = 2;
2473 }
2474
2475 // Create Disassembler Instance
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002476 lldb::DisassemblerSP disasm_sp(Disassembler::FindPlugin(m_arch, nullptr, nullptr));
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002477
2478 ExecutionContext exe_ctx;
2479 CalculateExecutionContext(exe_ctx);
2480 InstructionList instruction_list;
2481 InstructionSP prev_insn;
2482 bool prefer_file_cache = true; // Read from file
2483 uint32_t inst_to_choose = 0;
2484
2485 for (uint32_t i = 1; i <= loop_count; i++)
2486 {
2487 // Adjust the address to read from.
2488 resolved_addr.Slide (-2);
2489 AddressRange range(resolved_addr, i*2);
2490 uint32_t insn_size = 0;
2491
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002492 disasm_sp->ParseInstructions(&exe_ctx, range, nullptr, prefer_file_cache);
Bhushan D. Attarde7f3daed2015-08-26 06:04:54 +00002493
2494 uint32_t num_insns = disasm_sp->GetInstructionList().GetSize();
2495 if (num_insns)
2496 {
2497 prev_insn = disasm_sp->GetInstructionList().GetInstructionAtIndex(0);
2498 insn_size = prev_insn->GetOpcode().GetByteSize();
2499 if (i == 1 && insn_size == 2)
2500 {
2501 // This looks like a valid 2-byte instruction (but it could be a part of upper 4 byte instruction).
2502 instruction_list.Append(prev_insn);
2503 inst_to_choose = 1;
2504 }
2505 else if (i == 2)
2506 {
2507 // Here we may get one 4-byte instruction or two 2-byte instructions.
2508 if (num_insns == 2)
2509 {
2510 // Looks like there are two 2-byte instructions above our breakpoint target address.
2511 // 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.
2512 // In both cases we don't care because in this case lower 2-byte instruction is definitely a valid instruction
2513 // and whatever i=1 iteration has found out is true.
2514 inst_to_choose = 1;
2515 break;
2516 }
2517 else if (insn_size == 4)
2518 {
2519 // This instruction claims its a valid 4-byte instruction. But it could be a part of it's upper 4-byte instruction.
2520 // Lets try scanning upper 2 bytes to verify this.
2521 instruction_list.Append(prev_insn);
2522 inst_to_choose = 2;
2523 }
2524 }
2525 else if (i == 3)
2526 {
2527 if (insn_size == 4)
2528 // FIXME: We reached here that means instruction at [target - 4] has already claimed to be a 4-byte instruction,
2529 // and now instruction at [target - 6] is also claiming that it's a 4-byte instruction. This can not be true.
2530 // In this case we can not decide the valid previous instruction so we let lldb set the breakpoint at the address given by user.
2531 inst_to_choose = 0;
2532 else
2533 // This is straight-forward
2534 inst_to_choose = 2;
2535 break;
2536 }
2537 }
2538 else
2539 {
2540 // Decode failed, bytes do not form a valid instruction. So whatever previous iteration has found out is true.
2541 if (i > 1)
2542 {
2543 inst_to_choose = i - 1;
2544 break;
2545 }
2546 }
2547 }
2548
2549 // Check if we are able to find any valid instruction.
2550 if (inst_to_choose)
2551 {
2552 if (inst_to_choose > instruction_list.GetSize())
2553 inst_to_choose--;
2554 prev_insn = instruction_list.GetInstructionAtIndex(inst_to_choose - 1);
2555
2556 if (prev_insn->HasDelaySlot())
2557 {
2558 uint32_t shift_size = prev_insn->GetOpcode().GetByteSize();
2559 // Adjust the breakable address
2560 breakable_addr = addr - shift_size;
2561 if (log)
2562 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);
2563 }
2564 }
2565 break;
2566 }
2567 }
2568 return breakable_addr;
2569}
2570
Greg Clayton9585fbf2013-03-19 00:20:55 +00002571SourceManager &
2572Target::GetSourceManager ()
2573{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002574 if (!m_source_manager_ap)
Greg Clayton9585fbf2013-03-19 00:20:55 +00002575 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
2576 return *m_source_manager_ap;
2577}
2578
Sean Callanan9998acd2014-12-05 01:21:59 +00002579ClangModulesDeclVendor *
2580Target::GetClangModulesDeclVendor ()
2581{
2582 static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
2583
2584 {
2585 Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
2586
2587 if (!m_clang_modules_decl_vendor_ap)
2588 {
2589 m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
2590 }
2591 }
2592
2593 return m_clang_modules_decl_vendor_ap.get();
2594}
Greg Clayton9585fbf2013-03-19 00:20:55 +00002595
Greg Clayton44d93782014-01-27 23:43:24 +00002596Target::StopHookSP
2597Target::CreateStopHook ()
Jim Ingham9575d842011-03-11 03:53:59 +00002598{
2599 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton44d93782014-01-27 23:43:24 +00002600 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2601 m_stop_hooks[new_uid] = stop_hook_sp;
2602 return stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00002603}
2604
2605bool
2606Target::RemoveStopHookByID (lldb::user_id_t user_id)
2607{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002608 size_t num_removed = m_stop_hooks.erase(user_id);
2609 return (num_removed != 0);
Jim Ingham9575d842011-03-11 03:53:59 +00002610}
2611
2612void
2613Target::RemoveAllStopHooks ()
2614{
2615 m_stop_hooks.clear();
2616}
2617
2618Target::StopHookSP
2619Target::GetStopHookByID (lldb::user_id_t user_id)
2620{
2621 StopHookSP found_hook;
2622
2623 StopHookCollection::iterator specified_hook_iter;
2624 specified_hook_iter = m_stop_hooks.find (user_id);
2625 if (specified_hook_iter != m_stop_hooks.end())
2626 found_hook = (*specified_hook_iter).second;
2627 return found_hook;
2628}
2629
2630bool
2631Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2632{
2633 StopHookCollection::iterator specified_hook_iter;
2634 specified_hook_iter = m_stop_hooks.find (user_id);
2635 if (specified_hook_iter == m_stop_hooks.end())
2636 return false;
2637
2638 (*specified_hook_iter).second->SetIsActive (active_state);
2639 return true;
2640}
2641
2642void
2643Target::SetAllStopHooksActiveState (bool active_state)
2644{
2645 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2646 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2647 {
2648 (*pos).second->SetIsActive (active_state);
2649 }
2650}
2651
2652void
2653Target::RunStopHooks ()
2654{
Jim Ingham6026ca32011-05-12 02:06:14 +00002655 if (m_suppress_stop_hooks)
2656 return;
2657
Jim Ingham9575d842011-03-11 03:53:59 +00002658 if (!m_process_sp)
2659 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002660
2661 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2662 // since in that case we do not want to run the stop-hooks
2663 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2664 return;
2665
Jim Ingham9575d842011-03-11 03:53:59 +00002666 if (m_stop_hooks.empty())
2667 return;
2668
2669 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2670
2671 // If there aren't any active stop hooks, don't bother either:
2672 bool any_active_hooks = false;
2673 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2674 {
2675 if ((*pos).second->IsActive())
2676 {
2677 any_active_hooks = true;
2678 break;
2679 }
2680 }
2681 if (!any_active_hooks)
2682 return;
2683
2684 CommandReturnObject result;
2685
2686 std::vector<ExecutionContext> exc_ctx_with_reasons;
2687 std::vector<SymbolContext> sym_ctx_with_reasons;
2688
2689 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2690 size_t num_threads = cur_threadlist.GetSize();
2691 for (size_t i = 0; i < num_threads; i++)
2692 {
2693 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2694 if (cur_thread_sp->ThreadStoppedForAReason())
2695 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002696 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002697 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2698 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2699 }
2700 }
2701
2702 // If no threads stopped for a reason, don't run the stop-hooks.
2703 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2704 if (num_exe_ctx == 0)
2705 return;
2706
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002707 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2708 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002709
2710 bool keep_going = true;
2711 bool hooks_ran = false;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002712 bool print_hook_header = (m_stop_hooks.size() != 1);
2713 bool print_thread_header = (num_exe_ctx != 1);
Jim Ingham381e25b2011-03-22 01:47:27 +00002714
Jim Ingham9575d842011-03-11 03:53:59 +00002715 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2716 {
2717 // result.Clear();
2718 StopHookSP cur_hook_sp = (*pos).second;
2719 if (!cur_hook_sp->IsActive())
2720 continue;
2721
2722 bool any_thread_matched = false;
2723 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2724 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002725 if ((cur_hook_sp->GetSpecifier() == nullptr
Jim Ingham9575d842011-03-11 03:53:59 +00002726 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002727 && (cur_hook_sp->GetThreadSpecifier() == nullptr
Jim Ingham3d902922012-03-07 22:03:04 +00002728 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002729 {
2730 if (!hooks_ran)
2731 {
Jim Ingham9575d842011-03-11 03:53:59 +00002732 hooks_ran = true;
2733 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002734 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002735 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002736 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2737 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002738 nullptr);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002739 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002740 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002741 else
Daniel Malead01b2952012-11-29 21:49:15 +00002742 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002743 any_thread_matched = true;
2744 }
2745
Jim Ingham381e25b2011-03-22 01:47:27 +00002746 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002747 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham26c7bf92014-10-11 00:38:27 +00002748
2749 CommandInterpreterRunOptions options;
2750 options.SetStopOnContinue (true);
2751 options.SetStopOnError (true);
2752 options.SetEchoCommands (false);
2753 options.SetPrintResults (true);
2754 options.SetAddToHistory (false);
2755
2756 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
2757 &exc_ctx_with_reasons[i],
2758 options,
Greg Clayton32e0a752011-03-30 18:16:51 +00002759 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002760
2761 // If the command started the target going again, we should bag out of
2762 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002763 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2764 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002765 {
Daniel Malead01b2952012-11-29 21:49:15 +00002766 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002767 keep_going = false;
2768 }
2769 }
2770 }
2771 }
Jason Molenda879cf772011-09-23 00:42:55 +00002772
Caroline Tice969ed3d2011-05-02 20:41:46 +00002773 result.GetImmediateOutputStream()->Flush();
2774 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002775}
2776
Greg Claytonfbb76342013-11-20 21:07:01 +00002777const TargetPropertiesSP &
2778Target::GetGlobalProperties()
2779{
2780 static TargetPropertiesSP g_settings_sp;
2781 if (!g_settings_sp)
2782 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00002783 g_settings_sp.reset(new TargetProperties(nullptr));
Greg Claytonfbb76342013-11-20 21:07:01 +00002784 }
2785 return g_settings_sp;
2786}
2787
2788Error
2789Target::Install (ProcessLaunchInfo *launch_info)
2790{
2791 Error error;
2792 PlatformSP platform_sp (GetPlatform());
2793 if (platform_sp)
2794 {
2795 if (platform_sp->IsRemote())
2796 {
2797 if (platform_sp->IsConnected())
2798 {
2799 // Install all files that have an install path, and always install the
2800 // main executable when connected to a remote platform
2801 const ModuleList& modules = GetImages();
2802 const size_t num_images = modules.GetSize();
2803 for (size_t idx = 0; idx < num_images; ++idx)
2804 {
2805 const bool is_main_executable = idx == 0;
2806 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2807 if (module_sp)
2808 {
2809 FileSpec local_file (module_sp->GetFileSpec());
2810 if (local_file)
2811 {
2812 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2813 if (!remote_file)
2814 {
2815 if (is_main_executable) // TODO: add setting for always installing main executable???
2816 {
2817 // Always install the main executable
Chaoren Lind3173f32015-05-29 19:52:29 +00002818 remote_file = platform_sp->GetRemoteWorkingDirectory();
2819 remote_file.AppendPathComponent(module_sp->GetFileSpec().GetFilename().GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +00002820 }
2821 }
2822 if (remote_file)
2823 {
2824 error = platform_sp->Install(local_file, remote_file);
2825 if (error.Success())
2826 {
2827 module_sp->SetPlatformFileSpec(remote_file);
2828 if (is_main_executable)
2829 {
Chaoren Lind3173f32015-05-29 19:52:29 +00002830 platform_sp->SetFilePermissions(remote_file, 0700);
Greg Claytonfbb76342013-11-20 21:07:01 +00002831 if (launch_info)
2832 launch_info->SetExecutableFile(remote_file, false);
2833 }
2834 }
2835 else
2836 break;
2837 }
2838 }
2839 }
2840 }
2841 }
2842 }
2843 }
2844 return error;
2845}
Greg Clayton7b242382011-07-08 00:48:09 +00002846
Greg Claytond5944cd2013-12-06 01:12:00 +00002847bool
2848Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2849{
2850 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2851}
2852
2853bool
Matthew Gardinerc928de32014-10-22 07:22:56 +00002854Target::ResolveFileAddress (lldb::addr_t file_addr, Address &resolved_addr)
2855{
2856 return m_images.ResolveFileAddress(file_addr, resolved_addr);
2857}
2858
2859bool
Greg Claytond5944cd2013-12-06 01:12:00 +00002860Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2861{
2862 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2863 if (old_section_load_addr != new_section_load_addr)
2864 {
2865 uint32_t stop_id = 0;
2866 ProcessSP process_sp(GetProcessSP());
2867 if (process_sp)
2868 stop_id = process_sp->GetStopID();
2869 else
2870 stop_id = m_section_load_history.GetLastStopID();
2871 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2872 return true; // Return true if the section load address was changed...
2873 }
2874 return false; // Return false to indicate nothing changed
Greg Claytond5944cd2013-12-06 01:12:00 +00002875}
2876
Greg Clayton8012cad2014-11-17 19:39:20 +00002877size_t
2878Target::UnloadModuleSections (const ModuleList &module_list)
2879{
2880 size_t section_unload_count = 0;
2881 size_t num_modules = module_list.GetSize();
2882 for (size_t i=0; i<num_modules; ++i)
2883 {
2884 section_unload_count += UnloadModuleSections (module_list.GetModuleAtIndex(i));
2885 }
2886 return section_unload_count;
2887}
2888
2889size_t
2890Target::UnloadModuleSections (const lldb::ModuleSP &module_sp)
2891{
2892 uint32_t stop_id = 0;
2893 ProcessSP process_sp(GetProcessSP());
2894 if (process_sp)
2895 stop_id = process_sp->GetStopID();
2896 else
2897 stop_id = m_section_load_history.GetLastStopID();
2898 SectionList *sections = module_sp->GetSectionList();
2899 size_t section_unload_count = 0;
2900 if (sections)
2901 {
2902 const uint32_t num_sections = sections->GetNumSections(0);
2903 for (uint32_t i = 0; i < num_sections; ++i)
2904 {
2905 section_unload_count += m_section_load_history.SetSectionUnloaded(stop_id, sections->GetSectionAtIndex(i));
2906 }
2907 }
2908 return section_unload_count;
2909}
2910
Greg Claytond5944cd2013-12-06 01:12:00 +00002911bool
2912Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2913{
2914 uint32_t stop_id = 0;
2915 ProcessSP process_sp(GetProcessSP());
2916 if (process_sp)
2917 stop_id = process_sp->GetStopID();
2918 else
2919 stop_id = m_section_load_history.GetLastStopID();
2920 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2921}
2922
2923bool
2924Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2925{
2926 uint32_t stop_id = 0;
2927 ProcessSP process_sp(GetProcessSP());
2928 if (process_sp)
2929 stop_id = process_sp->GetStopID();
2930 else
2931 stop_id = m_section_load_history.GetLastStopID();
2932 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2933}
2934
2935void
2936Target::ClearAllLoadedSections ()
2937{
2938 m_section_load_history.Clear();
2939}
2940
Greg Claytonb09c5382013-12-13 17:20:18 +00002941Error
Greg Clayton8012cad2014-11-17 19:39:20 +00002942Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
Greg Claytonb09c5382013-12-13 17:20:18 +00002943{
2944 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00002945 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
2946
2947 if (log)
2948 log->Printf ("Target::%s() called for %s", __FUNCTION__, launch_info.GetExecutableFile().GetPath().c_str ());
2949
Greg Claytonb09c5382013-12-13 17:20:18 +00002950 StateType state = eStateInvalid;
2951
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002952 // Scope to temporarily get the process state in case someone has manually
2953 // remotely connected already to a process and we can skip the platform
2954 // launching.
2955 {
2956 ProcessSP process_sp (GetProcessSP());
2957
2958 if (process_sp)
Todd Fialaac33cc92014-10-09 01:02:08 +00002959 {
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002960 state = process_sp->GetState();
Todd Fialaac33cc92014-10-09 01:02:08 +00002961 if (log)
2962 log->Printf ("Target::%s the process exists, and its current state is %s", __FUNCTION__, StateAsCString (state));
2963 }
2964 else
2965 {
2966 if (log)
2967 log->Printf ("Target::%s the process instance doesn't currently exist.", __FUNCTION__);
2968 }
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002969 }
2970
Greg Claytonb09c5382013-12-13 17:20:18 +00002971 launch_info.GetFlags().Set (eLaunchFlagDebug);
2972
2973 // Get the value of synchronous execution here. If you wait till after you have started to
2974 // run, then you could have hit a breakpoint, whose command might switch the value, and
2975 // then you'll pick up that incorrect value.
2976 Debugger &debugger = GetDebugger();
2977 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2978
2979 PlatformSP platform_sp (GetPlatform());
2980
2981 // Finalize the file actions, and if none were given, default to opening
2982 // up a pseudo terminal
2983 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
Todd Fiala75f47c32014-10-11 21:42:09 +00002984 if (log)
2985 log->Printf ("Target::%s have platform=%s, platform_sp->IsHost()=%s, default_to_use_pty=%s",
2986 __FUNCTION__,
2987 platform_sp ? "true" : "false",
2988 platform_sp ? (platform_sp->IsHost () ? "true" : "false") : "n/a",
2989 default_to_use_pty ? "true" : "false");
2990
Greg Claytonb09c5382013-12-13 17:20:18 +00002991 launch_info.FinalizeFileActions (this, default_to_use_pty);
2992
2993 if (state == eStateConnected)
2994 {
2995 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2996 {
2997 error.SetErrorString("can't launch in tty when launching through a remote connection");
2998 return error;
2999 }
3000 }
3001
3002 if (!launch_info.GetArchitecture().IsValid())
3003 launch_info.GetArchitecture() = GetArchitecture();
Todd Fiala015d8182014-07-22 23:41:36 +00003004
3005 // 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 +00003006 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
3007 {
Todd Fialaac33cc92014-10-09 01:02:08 +00003008 if (log)
3009 log->Printf ("Target::%s asking the platform to debug the process", __FUNCTION__);
3010
Greg Clayton5df78fa2015-05-23 03:54:53 +00003011 // Get a weak pointer to the previous process if we have one
3012 ProcessWP process_wp;
3013 if (m_process_sp)
3014 process_wp = m_process_sp;
Greg Claytonb09c5382013-12-13 17:20:18 +00003015 m_process_sp = GetPlatform()->DebugProcess (launch_info,
3016 debugger,
3017 this,
Greg Claytonb09c5382013-12-13 17:20:18 +00003018 error);
Greg Clayton5df78fa2015-05-23 03:54:53 +00003019
3020 // Cleanup the old process since someone might still have a strong
3021 // reference to this process and we would like to allow it to cleanup
3022 // as much as it can without the object being destroyed. We try to
3023 // lock the shared pointer and if that works, then someone else still
3024 // has a strong reference to the process.
3025
3026 ProcessSP old_process_sp(process_wp.lock());
3027 if (old_process_sp)
3028 old_process_sp->Finalize();
Greg Claytonb09c5382013-12-13 17:20:18 +00003029 }
3030 else
3031 {
Todd Fialaac33cc92014-10-09 01:02:08 +00003032 if (log)
3033 log->Printf ("Target::%s the platform doesn't know how to debug a process, getting a process plugin to do this for us.", __FUNCTION__);
3034
Greg Claytonb09c5382013-12-13 17:20:18 +00003035 if (state == eStateConnected)
3036 {
3037 assert(m_process_sp);
3038 }
3039 else
3040 {
Todd Fiala015d8182014-07-22 23:41:36 +00003041 // Use a Process plugin to construct the process.
Greg Claytonb09c5382013-12-13 17:20:18 +00003042 const char *plugin_name = launch_info.GetProcessPluginName();
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003043 CreateProcess(launch_info.GetListenerForProcess(debugger), plugin_name, nullptr);
Greg Claytonb09c5382013-12-13 17:20:18 +00003044 }
Todd Fiala015d8182014-07-22 23:41:36 +00003045
3046 // Since we didn't have a platform launch the process, launch it here.
Greg Claytonb09c5382013-12-13 17:20:18 +00003047 if (m_process_sp)
3048 error = m_process_sp->Launch (launch_info);
3049 }
3050
3051 if (!m_process_sp)
3052 {
3053 if (error.Success())
3054 error.SetErrorString("failed to launch or debug process");
3055 return error;
3056 }
3057
3058 if (error.Success())
3059 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003060 if (synchronous_execution || !launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Claytonb09c5382013-12-13 17:20:18 +00003061 {
Greg Clayton44d93782014-01-27 23:43:24 +00003062 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
Zachary Turnere6d213a2015-03-26 20:41:14 +00003063 if (!hijack_listener_sp)
3064 {
3065 hijack_listener_sp.reset(new Listener("lldb.Target.Launch.hijack"));
3066 launch_info.SetHijackListener(hijack_listener_sp);
3067 m_process_sp->HijackProcessEvents(hijack_listener_sp.get());
3068 }
Todd Fialaac33cc92014-10-09 01:02:08 +00003069
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003070 StateType state = m_process_sp->WaitForProcessToStop(nullptr, nullptr, false, hijack_listener_sp.get(), nullptr);
Greg Claytonb09c5382013-12-13 17:20:18 +00003071
3072 if (state == eStateStopped)
3073 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00003074 if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Claytonb09c5382013-12-13 17:20:18 +00003075 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00003076 if (synchronous_execution)
Greg Claytonb09c5382013-12-13 17:20:18 +00003077 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00003078 error = m_process_sp->PrivateResume();
3079 if (error.Success())
Greg Claytonb09c5382013-12-13 17:20:18 +00003080 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003081 state = m_process_sp->WaitForProcessToStop(nullptr, nullptr, true, hijack_listener_sp.get(), stream);
Ilia K064e69f2015-03-23 21:16:25 +00003082 const bool must_be_alive = false; // eStateExited is ok, so this must be false
3083 if (!StateIsStoppedState(state, must_be_alive))
3084 {
3085 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
3086 }
Greg Claytonb09c5382013-12-13 17:20:18 +00003087 }
3088 }
Ilia K064e69f2015-03-23 21:16:25 +00003089 else
3090 {
Zachary Turnere6d213a2015-03-26 20:41:14 +00003091 m_process_sp->RestoreProcessEvents();
3092 error = m_process_sp->PrivateResume();
Zachary Turnere6d213a2015-03-26 20:41:14 +00003093 }
3094 if (!error.Success())
3095 {
Ilia K064e69f2015-03-23 21:16:25 +00003096 Error error2;
3097 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
3098 error = error2;
3099 }
Greg Claytonb09c5382013-12-13 17:20:18 +00003100 }
Greg Claytonb09c5382013-12-13 17:20:18 +00003101 }
Greg Clayton40286e02014-04-30 20:29:09 +00003102 else if (state == eStateExited)
3103 {
Zachary Turner10687b02014-10-20 17:46:43 +00003104 bool with_shell = !!launch_info.GetShell();
Greg Clayton40286e02014-04-30 20:29:09 +00003105 const int exit_status = m_process_sp->GetExitStatus();
3106 const char *exit_desc = m_process_sp->GetExitDescription();
3107#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'."
3108 if (exit_desc && exit_desc[0])
3109 {
3110 if (with_shell)
3111 error.SetErrorStringWithFormat ("process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, exit_status, exit_desc);
3112 else
3113 error.SetErrorStringWithFormat ("process exited with status %i (%s)", exit_status, exit_desc);
3114 }
3115 else
3116 {
3117 if (with_shell)
3118 error.SetErrorStringWithFormat ("process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
3119 else
3120 error.SetErrorStringWithFormat ("process exited with status %i", exit_status);
3121 }
3122 }
Greg Claytonb09c5382013-12-13 17:20:18 +00003123 else
3124 {
3125 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
3126 }
3127 }
Greg Clayton44d93782014-01-27 23:43:24 +00003128 m_process_sp->RestoreProcessEvents ();
Greg Claytonb09c5382013-12-13 17:20:18 +00003129 }
3130 else
3131 {
Greg Clayton44d93782014-01-27 23:43:24 +00003132 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00003133 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00003134 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00003135 }
3136 return error;
3137}
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003138
3139Error
3140Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
3141{
3142 auto state = eStateInvalid;
3143 auto process_sp = GetProcessSP ();
3144 if (process_sp)
3145 {
3146 state = process_sp->GetState ();
3147 if (process_sp->IsAlive () && state != eStateConnected)
3148 {
3149 if (state == eStateAttaching)
3150 return Error ("process attach is in progress");
3151 return Error ("a process is already being debugged");
3152 }
3153 }
3154
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003155 const ModuleSP old_exec_module_sp = GetExecutableModule ();
3156
3157 // If no process info was specified, then use the target executable
3158 // name as the process to attach to by default
3159 if (!attach_info.ProcessInfoSpecified ())
3160 {
3161 if (old_exec_module_sp)
3162 attach_info.GetExecutableFile ().GetFilename () = old_exec_module_sp->GetPlatformFileSpec ().GetFilename ();
3163
3164 if (!attach_info.ProcessInfoSpecified ())
3165 {
3166 return Error ("no process specified, create a target with a file, or specify the --pid or --name");
3167 }
3168 }
3169
3170 const auto platform_sp = GetDebugger ().GetPlatformList ().GetSelectedPlatform ();
Greg Claytonb3788ea2015-10-05 22:58:37 +00003171 ListenerSP hijack_listener_sp;
3172 const bool async = attach_info.GetAsync();
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003173 if (!async)
Greg Claytonb3788ea2015-10-05 22:58:37 +00003174 {
3175 hijack_listener_sp.reset (new Listener ("lldb.Target.Attach.attach.hijack"));
3176 attach_info.SetHijackListener (hijack_listener_sp);
3177 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003178
3179 Error error;
3180 if (state != eStateConnected && platform_sp != nullptr && platform_sp->CanDebugProcess ())
3181 {
3182 SetPlatform (platform_sp);
3183 process_sp = platform_sp->Attach (attach_info, GetDebugger (), this, error);
3184 }
3185 else
3186 {
3187 if (state != eStateConnected)
3188 {
3189 const char *plugin_name = attach_info.GetProcessPluginName ();
3190 process_sp = CreateProcess (attach_info.GetListenerForProcess (GetDebugger ()), plugin_name, nullptr);
3191 if (process_sp == nullptr)
3192 {
3193 error.SetErrorStringWithFormat ("failed to create process using plugin %s", (plugin_name) ? plugin_name : "null");
3194 return error;
3195 }
3196 }
Greg Claytonb3788ea2015-10-05 22:58:37 +00003197 if (hijack_listener_sp)
3198 process_sp->HijackProcessEvents (hijack_listener_sp.get ());
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003199 error = process_sp->Attach (attach_info);
3200 }
3201
Greg Claytone75e5d82015-10-20 00:14:20 +00003202 if (error.Success () && process_sp)
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003203 {
Greg Claytone75e5d82015-10-20 00:14:20 +00003204 if (async)
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003205 {
Greg Claytone75e5d82015-10-20 00:14:20 +00003206 process_sp->RestoreProcessEvents ();
3207 }
3208 else
3209 {
3210 state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener ().get (), stream);
3211 process_sp->RestoreProcessEvents ();
3212
3213 if (state != eStateStopped)
3214 {
3215 const char *exit_desc = process_sp->GetExitDescription ();
3216 if (exit_desc)
3217 error.SetErrorStringWithFormat ("%s", exit_desc);
3218 else
3219 error.SetErrorString ("process did not stop (no such process or permission problem?)");
3220 process_sp->Destroy (false);
3221 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +00003222 }
3223 }
3224 return error;
3225}
3226
Jim Ingham9575d842011-03-11 03:53:59 +00003227//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00003228// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00003229//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00003230Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
3231 UserID (uid),
3232 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00003233 m_commands (),
3234 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00003235 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003236 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00003237{
3238}
3239
3240Target::StopHook::StopHook (const StopHook &rhs) :
3241 UserID (rhs.GetID()),
3242 m_target_sp (rhs.m_target_sp),
3243 m_commands (rhs.m_commands),
3244 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00003245 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003246 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00003247{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003248 if (rhs.m_thread_spec_ap)
Jim Ingham9575d842011-03-11 03:53:59 +00003249 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
3250}
3251
Eugene Zelenko8f30a652015-10-23 18:39:37 +00003252Target::StopHook::~StopHook() = default;
Jim Ingham9575d842011-03-11 03:53:59 +00003253
3254void
Zachary Turner32abc6e2015-03-03 19:23:09 +00003255Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier)
3256{
3257 m_specifier_sp.reset(specifier);
3258}
3259
3260void
Jim Ingham9575d842011-03-11 03:53:59 +00003261Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
3262{
3263 m_thread_spec_ap.reset (specifier);
3264}
Jim Ingham9575d842011-03-11 03:53:59 +00003265
3266void
3267Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
3268{
3269 int indent_level = s->GetIndentLevel();
3270
3271 s->SetIndentLevel(indent_level + 2);
3272
Daniel Malead01b2952012-11-29 21:49:15 +00003273 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00003274 if (m_active)
3275 s->Indent ("State: enabled\n");
3276 else
3277 s->Indent ("State: disabled\n");
3278
3279 if (m_specifier_sp)
3280 {
3281 s->Indent();
3282 s->PutCString ("Specifier:\n");
3283 s->SetIndentLevel (indent_level + 4);
3284 m_specifier_sp->GetDescription (s, level);
3285 s->SetIndentLevel (indent_level + 2);
3286 }
3287
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003288 if (m_thread_spec_ap)
Jim Ingham9575d842011-03-11 03:53:59 +00003289 {
3290 StreamString tmp;
3291 s->Indent("Thread:\n");
3292 m_thread_spec_ap->GetDescription (&tmp, level);
3293 s->SetIndentLevel (indent_level + 4);
3294 s->Indent (tmp.GetData());
3295 s->PutCString ("\n");
3296 s->SetIndentLevel (indent_level + 2);
3297 }
3298
3299 s->Indent ("Commands: \n");
3300 s->SetIndentLevel (indent_level + 4);
3301 uint32_t num_commands = m_commands.GetSize();
3302 for (uint32_t i = 0; i < num_commands; i++)
3303 {
3304 s->Indent(m_commands.GetStringAtIndex(i));
3305 s->PutCString ("\n");
3306 }
3307 s->SetIndentLevel (indent_level);
3308}
3309
Greg Clayton67cc0632012-08-22 17:17:09 +00003310//--------------------------------------------------------------
3311// class TargetProperties
3312//--------------------------------------------------------------
3313
3314OptionEnumValueElement
3315lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00003316{
Greg Clayton67cc0632012-08-22 17:17:09 +00003317 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
3318 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
3319 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003320 { 0, nullptr, nullptr }
Greg Clayton67cc0632012-08-22 17:17:09 +00003321};
Caroline Ticedaccaa92010-09-20 20:44:43 +00003322
Greg Clayton1f746072012-08-29 21:13:06 +00003323static OptionEnumValueElement
3324g_inline_breakpoint_enums[] =
3325{
3326 { 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."},
3327 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
3328 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003329 { 0, nullptr, nullptr }
Greg Clayton1f746072012-08-29 21:13:06 +00003330};
3331
Jim Ingham0f063ba2013-03-02 00:26:47 +00003332typedef enum x86DisassemblyFlavor
3333{
3334 eX86DisFlavorDefault,
3335 eX86DisFlavorIntel,
3336 eX86DisFlavorATT
3337} x86DisassemblyFlavor;
3338
3339static OptionEnumValueElement
3340g_x86_dis_flavor_value_types[] =
3341{
3342 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
3343 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
3344 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003345 { 0, nullptr, nullptr }
Jim Ingham0f063ba2013-03-02 00:26:47 +00003346};
3347
Enrico Granata397ddd52013-05-21 20:13:34 +00003348static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00003349g_hex_immediate_style_values[] =
3350{
3351 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
3352 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003353 { 0, nullptr, nullptr }
Daniel Malead79ae052013-08-07 21:54:09 +00003354};
3355
3356static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00003357g_load_script_from_sym_file_values[] =
3358{
3359 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
3360 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
3361 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003362 { 0, nullptr, nullptr }
Enrico Granata397ddd52013-05-21 20:13:34 +00003363};
3364
Greg Claytonfd814c52013-08-13 01:42:25 +00003365static OptionEnumValueElement
Jason Molenda878ae012016-02-19 00:05:17 +00003366g_load_current_working_dir_lldbinit_values[] =
3367{
3368 { eLoadCWDlldbinitTrue, "true", "Load .lldbinit files from current directory"},
3369 { eLoadCWDlldbinitFalse, "false", "Do not load .lldbinit files from current directory"},
3370 { eLoadCWDlldbinitWarn, "warn", "Warn about loading .lldbinit files from current directory"},
3371 { 0, nullptr, nullptr }
3372};
3373
3374static OptionEnumValueElement
Greg Claytonfd814c52013-08-13 01:42:25 +00003375g_memory_module_load_level_values[] =
3376{
Greg Clayton86eac942013-08-13 21:32:34 +00003377 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00003378 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
3379 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003380 { 0, nullptr, nullptr }
Greg Claytonfd814c52013-08-13 01:42:25 +00003381};
3382
Greg Clayton67cc0632012-08-22 17:17:09 +00003383static PropertyDefinition
3384g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00003385{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003386 { "default-arch" , OptionValue::eTypeArch , true , 0 , nullptr, nullptr, "Default architecture to choose, when there's a choice." },
3387 { "move-to-nearest-code" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Move breakpoints to nearest code." },
3388 { "language" , OptionValue::eTypeLanguage , false, eLanguageTypeUnknown , nullptr, nullptr, "The language to use when interpreting expressions entered in commands." },
3389 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , nullptr, nullptr, "Path to a file containing expressions to be prepended to all expressions." },
3390 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eDynamicDontRunTarget , nullptr, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
3391 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Should synthetic values be used by default whenever available." },
3392 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Skip function prologues when setting breakpoints by name." },
3393 { "source-map" , OptionValue::eTypePathMap , false, 0 , nullptr, nullptr, "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 +00003394 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
3395 "some part (starting at the root) of the path to the file when it was built, "
3396 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
3397 "Each element of the array is checked in order and the first one that results in a match wins." },
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003398 { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , nullptr, nullptr, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
3399 { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , nullptr, nullptr, "List of directories to be searched when locating debug symbol files." },
3400 { "clang-module-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , nullptr, nullptr, "List of directories to be searched when locating modules for Clang." },
Sean Callananb0300a42016-01-14 21:46:09 +00003401 { "auto-import-clang-modules" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Automatically load Clang modules referred to by the program." },
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003402 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , nullptr, nullptr, "Maximum number of children to expand in any level of depth." },
3403 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , nullptr, nullptr, "Maximum number of characters to show when using %s in summary strings." },
3404 { "max-memory-read-size" , OptionValue::eTypeSInt64 , false, 1024 , nullptr, nullptr, "Maximum number of bytes that 'memory read' will fetch before --force must be specified." },
3405 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Consult the platform module avoid list when setting non-module specific breakpoints." },
3406 { "arg0" , OptionValue::eTypeString , false, 0 , nullptr, nullptr, "The first argument passed to the program in the argument array which can be different from the executable itself." },
3407 { "run-args" , OptionValue::eTypeArgs , false, 0 , nullptr, nullptr, "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." },
3408 { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , nullptr, nullptr, "A list of all the environment variables to be passed to the executable's environment, and their values." },
3409 { "inherit-env" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Inherit the environment from the process that is running LLDB." },
3410 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , nullptr, nullptr, "The file/path to be used by the executable program for reading its standard input." },
3411 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , nullptr, nullptr, "The file/path to be used by the executable program for writing its standard output." },
3412 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , nullptr, nullptr, "The file/path to be used by the executable program for writing its standard error." },
3413 { "detach-on-error" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "debugserver will detach (rather than killing) a process if it loses connection with lldb." },
3414 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , nullptr, nullptr, "Disable Address Space Layout Randomization (ASLR)" },
3415 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , nullptr, nullptr, "Disable stdin/stdout for process (e.g. for a GUI application)" },
3416 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsAlways , nullptr, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
Greg Clayton1f746072012-08-29 21:13:06 +00003417 "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 +00003418 "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 +00003419 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
Todd Fialaad6eee62014-09-24 19:59:13 +00003420 "Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers "
3421 "and find that setting breakpoints is slow, then you can change this setting to headers. "
3422 "This setting allows you to control exactly which strategy is used when setting "
Greg Clayton1f746072012-08-29 21:13:06 +00003423 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00003424 // 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.
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003425 { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, nullptr, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." },
3426 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, nullptr, nullptr, "Show immediates in disassembly as hexadecimal." },
3427 { "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, nullptr, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." },
3428 { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, nullptr, nullptr, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." },
3429 { "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, eLoadScriptFromSymFileWarn, nullptr, g_load_script_from_sym_file_values, "Allow LLDB to load scripting resources embedded in symbol files when available." },
Jason Molenda878ae012016-02-19 00:05:17 +00003430 { "load-cwd-lldbinit" , OptionValue::eTypeEnum , false, eLoadCWDlldbinitWarn, nullptr, g_load_current_working_dir_lldbinit_values, "Allow LLDB to .lldbinit files from the current directory automatically." },
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003431 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, nullptr, g_memory_module_load_level_values,
Greg Clayton86eac942013-08-13 21:32:34 +00003432 "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. "
3433 "This setting helps users control how much information gets loaded when loading modules from memory."
3434 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
3435 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
3436 "'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). " },
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003437 { "display-expression-in-crashlogs" , OptionValue::eTypeBoolean , false, false, nullptr, nullptr, "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." },
3438 { "trap-handler-names" , OptionValue::eTypeArray , true, OptionValue::eTypeString, nullptr, nullptr, "A list of trap handler function names, e.g. a common Unix user process one is _sigtramp." },
3439 { "display-runtime-support-values" , OptionValue::eTypeBoolean , false, false, nullptr, nullptr, "If true, LLDB will show variables that are meant to support the operation of a language's runtime support." },
3440 { "non-stop-mode" , OptionValue::eTypeBoolean , false, 0, nullptr, nullptr, "Disable lock-step debugging, instead control threads independently." },
3441 { nullptr , OptionValue::eTypeInvalid , false, 0 , nullptr, nullptr, nullptr }
Greg Clayton67cc0632012-08-22 17:17:09 +00003442};
Enrico Granata560558e2015-02-11 02:35:39 +00003443
Greg Clayton67cc0632012-08-22 17:17:09 +00003444enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00003445{
Greg Clayton67cc0632012-08-22 17:17:09 +00003446 ePropertyDefaultArch,
Ilia K055ad9b2015-05-18 13:41:01 +00003447 ePropertyMoveToNearestCode,
Dawn Perchik23b1dec2015-07-21 22:05:07 +00003448 ePropertyLanguage,
Greg Clayton67cc0632012-08-22 17:17:09 +00003449 ePropertyExprPrefix,
3450 ePropertyPreferDynamic,
3451 ePropertyEnableSynthetic,
3452 ePropertySkipPrologue,
3453 ePropertySourceMap,
3454 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00003455 ePropertyDebugFileSearchPaths,
Sean Callanan85054342015-04-03 15:39:47 +00003456 ePropertyClangModuleSearchPaths,
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003457 ePropertyAutoImportClangModules,
Greg Clayton67cc0632012-08-22 17:17:09 +00003458 ePropertyMaxChildrenCount,
3459 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00003460 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00003461 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00003462 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00003463 ePropertyRunArgs,
3464 ePropertyEnvVars,
3465 ePropertyInheritEnv,
3466 ePropertyInputPath,
3467 ePropertyOutputPath,
3468 ePropertyErrorPath,
Jim Ingham106d0282014-06-25 02:32:56 +00003469 ePropertyDetachOnError,
Greg Clayton67cc0632012-08-22 17:17:09 +00003470 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00003471 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00003472 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00003473 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00003474 ePropertyUseHexImmediates,
3475 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003476 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00003477 ePropertyLoadScriptFromSymbolFile,
Jason Molenda878ae012016-02-19 00:05:17 +00003478 ePropertyLoadCWDlldbinitFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00003479 ePropertyMemoryModuleLoadLevel,
Jason Molendaa4bea722014-02-14 05:06:49 +00003480 ePropertyDisplayExpressionsInCrashlogs,
Enrico Granata560558e2015-02-11 02:35:39 +00003481 ePropertyTrapHandlerNames,
Ewan Crawford78baa192015-05-13 09:18:18 +00003482 ePropertyDisplayRuntimeSupportValues,
3483 ePropertyNonStopModeEnabled
Greg Clayton67cc0632012-08-22 17:17:09 +00003484};
Caroline Ticedaccaa92010-09-20 20:44:43 +00003485
Greg Clayton67cc0632012-08-22 17:17:09 +00003486class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00003487{
Greg Clayton67cc0632012-08-22 17:17:09 +00003488public:
3489 TargetOptionValueProperties (const ConstString &name) :
3490 OptionValueProperties (name),
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003491 m_target(nullptr),
Greg Clayton67cc0632012-08-22 17:17:09 +00003492 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003493 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00003494 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00003495
Greg Clayton67cc0632012-08-22 17:17:09 +00003496 // This constructor is used when creating TargetOptionValueProperties when it
3497 // is part of a new lldb_private::Target instance. It will copy all current
3498 // global property values as needed
3499 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
3500 OptionValueProperties(*target_properties_sp->GetValueProperties()),
3501 m_target (target),
3502 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00003503 {
Greg Clayton67cc0632012-08-22 17:17:09 +00003504 }
3505
Eugene Zelenko8f30a652015-10-23 18:39:37 +00003506 const Property *
3507 GetPropertyAtIndex(const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const override
Greg Clayton67cc0632012-08-22 17:17:09 +00003508 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003509 // When getting the value for a key from the target options, we will always
Greg Clayton67cc0632012-08-22 17:17:09 +00003510 // try and grab the setting from the current target if there is one. Else we just
3511 // use the one from this instance.
3512 if (idx == ePropertyEnvVars)
3513 GetHostEnvironmentIfNeeded ();
3514
3515 if (exe_ctx)
3516 {
3517 Target *target = exe_ctx->GetTargetPtr();
3518 if (target)
3519 {
3520 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
3521 if (this != target_properties)
3522 return target_properties->ProtectedGetPropertyAtIndex (idx);
3523 }
3524 }
3525 return ProtectedGetPropertyAtIndex (idx);
3526 }
Enrico Granata84a53df2013-05-20 22:29:23 +00003527
3528 lldb::TargetSP
3529 GetTargetSP ()
3530 {
3531 return m_target->shared_from_this();
3532 }
3533
Greg Clayton67cc0632012-08-22 17:17:09 +00003534protected:
Greg Clayton67cc0632012-08-22 17:17:09 +00003535 void
3536 GetHostEnvironmentIfNeeded () const
3537 {
3538 if (!m_got_host_env)
3539 {
3540 if (m_target)
3541 {
3542 m_got_host_env = true;
3543 const uint32_t idx = ePropertyInheritEnv;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003544 if (GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0))
Greg Clayton67cc0632012-08-22 17:17:09 +00003545 {
3546 PlatformSP platform_sp (m_target->GetPlatform());
3547 if (platform_sp)
3548 {
3549 StringList env;
3550 if (platform_sp->GetEnvironment(env))
3551 {
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003552 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary(nullptr, ePropertyEnvVars);
Greg Clayton67cc0632012-08-22 17:17:09 +00003553 if (env_dict)
3554 {
3555 const bool can_replace = false;
3556 const size_t envc = env.GetSize();
3557 for (size_t idx=0; idx<envc; idx++)
3558 {
3559 const char *env_entry = env.GetStringAtIndex (idx);
3560 if (env_entry)
3561 {
3562 const char *equal_pos = ::strchr(env_entry, '=');
3563 ConstString key;
3564 // It is ok to have environment variables with no values
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003565 const char *value = nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +00003566 if (equal_pos)
3567 {
3568 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
3569 if (equal_pos[1])
3570 value = equal_pos + 1;
3571 }
3572 else
3573 {
3574 key.SetCString(env_entry);
3575 }
3576 // Don't allow existing keys to be replaced with ones we get from the platform environment
3577 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
3578 }
3579 }
3580 }
3581 }
3582 }
3583 }
3584 }
3585 }
3586 }
3587 Target *m_target;
3588 mutable bool m_got_host_env;
3589};
3590
Greg Claytonfbb76342013-11-20 21:07:01 +00003591//----------------------------------------------------------------------
3592// TargetProperties
3593//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00003594TargetProperties::TargetProperties (Target *target) :
Ilia K8f37ca52015-02-13 14:31:06 +00003595 Properties (),
3596 m_launch_info ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003597{
3598 if (target)
3599 {
3600 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Ilia K8f37ca52015-02-13 14:31:06 +00003601
3602 // Set callbacks to update launch_info whenever "settins set" updated any of these properties
3603 m_collection_sp->SetValueChangedCallback(ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this);
3604 m_collection_sp->SetValueChangedCallback(ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this);
3605 m_collection_sp->SetValueChangedCallback(ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this);
3606 m_collection_sp->SetValueChangedCallback(ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, this);
3607 m_collection_sp->SetValueChangedCallback(ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, this);
3608 m_collection_sp->SetValueChangedCallback(ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, this);
3609 m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, TargetProperties::DetachOnErrorValueChangedCallback, this);
3610 m_collection_sp->SetValueChangedCallback(ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, this);
3611 m_collection_sp->SetValueChangedCallback(ePropertyDisableSTDIO, TargetProperties::DisableSTDIOValueChangedCallback, this);
3612
3613 // Update m_launch_info once it was created
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003614 Arg0ValueChangedCallback(this, nullptr);
3615 RunArgsValueChangedCallback(this, nullptr);
3616 //EnvVarsValueChangedCallback(this, nullptr); // FIXME: cause segfault in Target::GetPlatform()
3617 InputPathValueChangedCallback(this, nullptr);
3618 OutputPathValueChangedCallback(this, nullptr);
3619 ErrorPathValueChangedCallback(this, nullptr);
3620 DetachOnErrorValueChangedCallback(this, nullptr);
3621 DisableASLRValueChangedCallback(this, nullptr);
3622 DisableSTDIOValueChangedCallback(this, nullptr);
Caroline Ticedaccaa92010-09-20 20:44:43 +00003623 }
3624 else
Greg Clayton67cc0632012-08-22 17:17:09 +00003625 {
3626 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
3627 m_collection_sp->Initialize(g_properties);
3628 m_collection_sp->AppendProperty(ConstString("process"),
3629 ConstString("Settings specify to processes."),
3630 true,
3631 Process::GetGlobalProperties()->GetValueProperties());
3632 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00003633}
3634
Eugene Zelenko8f30a652015-10-23 18:39:37 +00003635TargetProperties::~TargetProperties() = default;
3636
Greg Clayton67cc0632012-08-22 17:17:09 +00003637ArchSpec
3638TargetProperties::GetDefaultArchitecture () const
3639{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003640 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(nullptr, ePropertyDefaultArch);
Greg Clayton67cc0632012-08-22 17:17:09 +00003641 if (value)
3642 return value->GetCurrentValue();
3643 return ArchSpec();
3644}
3645
3646void
3647TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
3648{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003649 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(nullptr, ePropertyDefaultArch);
Greg Clayton67cc0632012-08-22 17:17:09 +00003650 if (value)
3651 return value->SetCurrentValue(arch, true);
3652}
3653
Ilia K055ad9b2015-05-18 13:41:01 +00003654bool
3655TargetProperties::GetMoveToNearestCode() const
3656{
3657 const uint32_t idx = ePropertyMoveToNearestCode;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003658 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Ilia K055ad9b2015-05-18 13:41:01 +00003659}
3660
Greg Clayton67cc0632012-08-22 17:17:09 +00003661lldb::DynamicValueType
3662TargetProperties::GetPreferDynamicValue() const
3663{
3664 const uint32_t idx = ePropertyPreferDynamic;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003665 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +00003666}
3667
3668bool
Greg Clayton15484402015-05-15 18:40:24 +00003669TargetProperties::SetPreferDynamicValue (lldb::DynamicValueType d)
3670{
3671 const uint32_t idx = ePropertyPreferDynamic;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003672 return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx, d);
Greg Clayton15484402015-05-15 18:40:24 +00003673}
3674
Greg Clayton15484402015-05-15 18:40:24 +00003675bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003676TargetProperties::GetDisableASLR () const
3677{
3678 const uint32_t idx = ePropertyDisableASLR;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003679 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +00003680}
3681
3682void
3683TargetProperties::SetDisableASLR (bool b)
3684{
3685 const uint32_t idx = ePropertyDisableASLR;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003686 m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
Greg Clayton67cc0632012-08-22 17:17:09 +00003687}
3688
3689bool
Jim Ingham106d0282014-06-25 02:32:56 +00003690TargetProperties::GetDetachOnError () const
3691{
3692 const uint32_t idx = ePropertyDetachOnError;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003693 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Jim Ingham106d0282014-06-25 02:32:56 +00003694}
3695
3696void
3697TargetProperties::SetDetachOnError (bool b)
3698{
3699 const uint32_t idx = ePropertyDetachOnError;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003700 m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
Jim Ingham106d0282014-06-25 02:32:56 +00003701}
3702
3703bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003704TargetProperties::GetDisableSTDIO () const
3705{
3706 const uint32_t idx = ePropertyDisableSTDIO;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003707 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +00003708}
3709
3710void
3711TargetProperties::SetDisableSTDIO (bool b)
3712{
3713 const uint32_t idx = ePropertyDisableSTDIO;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003714 m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
Greg Clayton67cc0632012-08-22 17:17:09 +00003715}
3716
Jim Ingham0f063ba2013-03-02 00:26:47 +00003717const char *
3718TargetProperties::GetDisassemblyFlavor () const
3719{
3720 const uint32_t idx = ePropertyDisassemblyFlavor;
3721 const char *return_value;
3722
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003723 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Jim Ingham0f063ba2013-03-02 00:26:47 +00003724 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
3725 return return_value;
3726}
3727
Greg Clayton1f746072012-08-29 21:13:06 +00003728InlineStrategy
3729TargetProperties::GetInlineStrategy () const
3730{
3731 const uint32_t idx = ePropertyInlineStrategy;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003732 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Greg Clayton1f746072012-08-29 21:13:06 +00003733}
3734
Greg Clayton45392552012-10-17 22:57:12 +00003735const char *
3736TargetProperties::GetArg0 () const
3737{
3738 const uint32_t idx = ePropertyArg0;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003739 return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, nullptr);
Greg Clayton45392552012-10-17 22:57:12 +00003740}
3741
3742void
3743TargetProperties::SetArg0 (const char *arg)
3744{
3745 const uint32_t idx = ePropertyArg0;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003746 m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, arg);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003747 m_launch_info.SetArg0(arg);
Greg Clayton45392552012-10-17 22:57:12 +00003748}
3749
Greg Clayton67cc0632012-08-22 17:17:09 +00003750bool
3751TargetProperties::GetRunArguments (Args &args) const
3752{
3753 const uint32_t idx = ePropertyRunArgs;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003754 return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args);
Greg Clayton67cc0632012-08-22 17:17:09 +00003755}
3756
3757void
3758TargetProperties::SetRunArguments (const Args &args)
3759{
3760 const uint32_t idx = ePropertyRunArgs;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003761 m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003762 m_launch_info.GetArguments() = args;
Greg Clayton67cc0632012-08-22 17:17:09 +00003763}
3764
3765size_t
3766TargetProperties::GetEnvironmentAsArgs (Args &env) const
3767{
3768 const uint32_t idx = ePropertyEnvVars;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003769 return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, env);
Greg Clayton67cc0632012-08-22 17:17:09 +00003770}
3771
Ilia K8f37ca52015-02-13 14:31:06 +00003772void
3773TargetProperties::SetEnvironmentFromArgs (const Args &env)
3774{
3775 const uint32_t idx = ePropertyEnvVars;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003776 m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, env);
Greg Clayton896e0ec2015-03-26 00:15:24 +00003777 m_launch_info.GetEnvironmentEntries() = env;
Ilia K8f37ca52015-02-13 14:31:06 +00003778}
3779
Greg Clayton67cc0632012-08-22 17:17:09 +00003780bool
3781TargetProperties::GetSkipPrologue() const
3782{
3783 const uint32_t idx = ePropertySkipPrologue;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003784 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +00003785}
3786
3787PathMappingList &
3788TargetProperties::GetSourcePathMap () const
3789{
3790 const uint32_t idx = ePropertySourceMap;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003791 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(nullptr, false, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +00003792 assert(option_value);
3793 return option_value->GetCurrentValue();
3794}
3795
3796FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00003797TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00003798{
3799 const uint32_t idx = ePropertyExecutableSearchPaths;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003800 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, false, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +00003801 assert(option_value);
3802 return option_value->GetCurrentValue();
3803}
3804
Michael Sartaina7499c92013-07-01 19:45:50 +00003805FileSpecList &
3806TargetProperties::GetDebugFileSearchPaths ()
3807{
3808 const uint32_t idx = ePropertyDebugFileSearchPaths;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003809 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, false, idx);
Michael Sartaina7499c92013-07-01 19:45:50 +00003810 assert(option_value);
3811 return option_value->GetCurrentValue();
3812}
3813
Sean Callanan85054342015-04-03 15:39:47 +00003814FileSpecList &
3815TargetProperties::GetClangModuleSearchPaths ()
3816{
3817 const uint32_t idx = ePropertyClangModuleSearchPaths;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003818 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, false, idx);
Sean Callanan85054342015-04-03 15:39:47 +00003819 assert(option_value);
3820 return option_value->GetCurrentValue();
3821}
3822
Greg Clayton67cc0632012-08-22 17:17:09 +00003823bool
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003824TargetProperties::GetEnableAutoImportClangModules() const
3825{
3826 const uint32_t idx = ePropertyAutoImportClangModules;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003827 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003828}
3829
3830bool
Greg Clayton67cc0632012-08-22 17:17:09 +00003831TargetProperties::GetEnableSyntheticValue () const
3832{
3833 const uint32_t idx = ePropertyEnableSynthetic;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003834 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +00003835}
3836
3837uint32_t
3838TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
3839{
3840 const uint32_t idx = ePropertyMaxChildrenCount;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003841 return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +00003842}
3843
3844uint32_t
3845TargetProperties::GetMaximumSizeOfStringSummary() const
3846{
3847 const uint32_t idx = ePropertyMaxSummaryLength;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003848 return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +00003849}
3850
Enrico Granatad325bf92013-06-04 22:54:16 +00003851uint32_t
3852TargetProperties::GetMaximumMemReadSize () const
3853{
3854 const uint32_t idx = ePropertyMaxMemReadSize;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003855 return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
Enrico Granatad325bf92013-06-04 22:54:16 +00003856}
3857
Greg Clayton67cc0632012-08-22 17:17:09 +00003858FileSpec
3859TargetProperties::GetStandardInputPath () const
3860{
3861 const uint32_t idx = ePropertyInputPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003862 return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +00003863}
3864
3865void
3866TargetProperties::SetStandardInputPath (const char *p)
3867{
3868 const uint32_t idx = ePropertyInputPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003869 m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p);
Greg Clayton67cc0632012-08-22 17:17:09 +00003870}
3871
3872FileSpec
3873TargetProperties::GetStandardOutputPath () const
3874{
3875 const uint32_t idx = ePropertyOutputPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003876 return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +00003877}
3878
3879void
3880TargetProperties::SetStandardOutputPath (const char *p)
3881{
3882 const uint32_t idx = ePropertyOutputPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003883 m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p);
Greg Clayton67cc0632012-08-22 17:17:09 +00003884}
3885
3886FileSpec
3887TargetProperties::GetStandardErrorPath () const
3888{
3889 const uint32_t idx = ePropertyErrorPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003890 return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +00003891}
3892
Dawn Perchik23b1dec2015-07-21 22:05:07 +00003893LanguageType
3894TargetProperties::GetLanguage () const
3895{
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003896 OptionValueLanguage *value = m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage(nullptr, ePropertyLanguage);
Dawn Perchik23b1dec2015-07-21 22:05:07 +00003897 if (value)
3898 return value->GetCurrentValue();
3899 return LanguageType();
3900}
3901
Greg Clayton6920b522012-08-22 18:39:03 +00003902const char *
3903TargetProperties::GetExpressionPrefixContentsAsCString ()
3904{
3905 const uint32_t idx = ePropertyExprPrefix;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003906 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false, idx);
Greg Clayton6920b522012-08-22 18:39:03 +00003907 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003908 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003909 const bool null_terminate = true;
3910 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003911 if (data_sp)
3912 return (const char *) data_sp->GetBytes();
3913 }
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003914 return nullptr;
Greg Clayton6920b522012-08-22 18:39:03 +00003915}
3916
Greg Clayton67cc0632012-08-22 17:17:09 +00003917void
3918TargetProperties::SetStandardErrorPath (const char *p)
3919{
3920 const uint32_t idx = ePropertyErrorPath;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003921 m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p);
Greg Clayton67cc0632012-08-22 17:17:09 +00003922}
3923
3924bool
3925TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3926{
3927 const uint32_t idx = ePropertyBreakpointUseAvoidList;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003928 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +00003929}
3930
Jim Ingham17d023f2013-03-13 17:58:04 +00003931bool
Daniel Malead79ae052013-08-07 21:54:09 +00003932TargetProperties::GetUseHexImmediates () const
3933{
3934 const uint32_t idx = ePropertyUseHexImmediates;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003935 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Daniel Malead79ae052013-08-07 21:54:09 +00003936}
3937
3938bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003939TargetProperties::GetUseFastStepping () const
3940{
3941 const uint32_t idx = ePropertyUseFastStepping;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003942 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Jim Ingham17d023f2013-03-13 17:58:04 +00003943}
3944
Greg Claytonfb6621e2013-12-06 21:59:52 +00003945bool
3946TargetProperties::GetDisplayExpressionsInCrashlogs () const
3947{
3948 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003949 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
Greg Claytonfb6621e2013-12-06 21:59:52 +00003950}
3951
Enrico Granata397ddd52013-05-21 20:13:34 +00003952LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003953TargetProperties::GetLoadScriptFromSymbolFile () const
3954{
3955 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003956 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003957}
3958
Jason Molenda878ae012016-02-19 00:05:17 +00003959LoadCWDlldbinitFile
3960TargetProperties::GetLoadCWDlldbinitFile () const
3961{
3962 const uint32_t idx = ePropertyLoadCWDlldbinitFile;
3963 return (LoadCWDlldbinitFile) m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
3964}
3965
Daniel Malead79ae052013-08-07 21:54:09 +00003966Disassembler::HexImmediateStyle
3967TargetProperties::GetHexImmediateStyle () const
3968{
3969 const uint32_t idx = ePropertyHexImmediateStyle;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003970 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Daniel Malead79ae052013-08-07 21:54:09 +00003971}
3972
Greg Claytonfd814c52013-08-13 01:42:25 +00003973MemoryModuleLoadLevel
3974TargetProperties::GetMemoryModuleLoadLevel() const
3975{
3976 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003977 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
Greg Claytonfd814c52013-08-13 01:42:25 +00003978}
3979
Jason Molendaa4bea722014-02-14 05:06:49 +00003980bool
3981TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
3982{
3983 const uint32_t idx = ePropertyTrapHandlerNames;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003984 return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args);
Jason Molendaa4bea722014-02-14 05:06:49 +00003985}
Greg Claytonfd814c52013-08-13 01:42:25 +00003986
Jason Molendaa4bea722014-02-14 05:06:49 +00003987void
3988TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
3989{
3990 const uint32_t idx = ePropertyTrapHandlerNames;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003991 m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
Jason Molendaa4bea722014-02-14 05:06:49 +00003992}
Greg Clayton67cc0632012-08-22 17:17:09 +00003993
Enrico Granata560558e2015-02-11 02:35:39 +00003994bool
3995TargetProperties::GetDisplayRuntimeSupportValues () const
3996{
3997 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00003998 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false);
Enrico Granata560558e2015-02-11 02:35:39 +00003999}
4000
4001void
4002TargetProperties::SetDisplayRuntimeSupportValues (bool b)
4003{
4004 const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00004005 m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
Enrico Granata560558e2015-02-11 02:35:39 +00004006}
4007
Ewan Crawford78baa192015-05-13 09:18:18 +00004008bool
4009TargetProperties::GetNonStopModeEnabled () const
4010{
4011 const uint32_t idx = ePropertyNonStopModeEnabled;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00004012 return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false);
Ewan Crawford78baa192015-05-13 09:18:18 +00004013}
4014
Ewan Crawfordaa7eda72015-06-24 15:14:26 +00004015void
4016TargetProperties::SetNonStopModeEnabled (bool b)
4017{
4018 const uint32_t idx = ePropertyNonStopModeEnabled;
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00004019 m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
Ewan Crawfordaa7eda72015-06-24 15:14:26 +00004020}
4021
Ilia K8f37ca52015-02-13 14:31:06 +00004022const ProcessLaunchInfo &
Ilia Kcc39d3f2015-02-13 17:07:55 +00004023TargetProperties::GetProcessLaunchInfo ()
Ilia K8f37ca52015-02-13 14:31:06 +00004024{
Ilia Kcc39d3f2015-02-13 17:07:55 +00004025 m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work
Ilia K8f37ca52015-02-13 14:31:06 +00004026 return m_launch_info;
4027}
4028
4029void
4030TargetProperties::SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info)
4031{
4032 m_launch_info = launch_info;
4033 SetArg0(launch_info.GetArg0());
4034 SetRunArguments(launch_info.GetArguments());
4035 SetEnvironmentFromArgs(launch_info.GetEnvironmentEntries());
4036 const FileAction *input_file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
4037 if (input_file_action)
4038 {
4039 const char *input_path = input_file_action->GetPath();
4040 if (input_path)
4041 SetStandardInputPath(input_path);
4042 }
4043 const FileAction *output_file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
4044 if (output_file_action)
4045 {
4046 const char *output_path = output_file_action->GetPath();
4047 if (output_path)
4048 SetStandardOutputPath(output_path);
4049 }
4050 const FileAction *error_file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
4051 if (error_file_action)
4052 {
4053 const char *error_path = error_file_action->GetPath();
4054 if (error_path)
4055 SetStandardErrorPath(error_path);
4056 }
4057 SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
4058 SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
4059 SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO));
4060}
4061
4062void
4063TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *)
4064{
4065 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4066 this_->m_launch_info.SetArg0(this_->GetArg0());
4067}
4068
4069void
4070TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *)
4071{
4072 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4073 Args args;
4074 if (this_->GetRunArguments(args))
4075 this_->m_launch_info.GetArguments() = args;
4076}
4077
4078void
4079TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *)
4080{
4081 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4082 Args args;
4083 if (this_->GetEnvironmentAsArgs(args))
4084 this_->m_launch_info.GetEnvironmentEntries() = args;
4085}
4086
4087void
4088TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
4089{
4090 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00004091 this_->m_launch_info.AppendOpenFileAction(STDIN_FILENO, this_->GetStandardInputPath(), true, false);
Ilia K8f37ca52015-02-13 14:31:06 +00004092}
4093
4094void
4095TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *)
4096{
4097 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00004098 this_->m_launch_info.AppendOpenFileAction(STDOUT_FILENO, this_->GetStandardOutputPath(), false, true);
Ilia K8f37ca52015-02-13 14:31:06 +00004099}
4100
4101void
4102TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *)
4103{
4104 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
Chaoren Lind3173f32015-05-29 19:52:29 +00004105 this_->m_launch_info.AppendOpenFileAction(STDERR_FILENO, this_->GetStandardErrorPath(), false, true);
Ilia K8f37ca52015-02-13 14:31:06 +00004106}
4107
4108void
4109TargetProperties::DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *)
4110{
4111 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4112 if (this_->GetDetachOnError())
4113 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError);
4114 else
4115 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError);
4116}
4117
4118void
4119TargetProperties::DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *)
4120{
4121 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4122 if (this_->GetDisableASLR())
4123 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR);
4124 else
4125 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR);
4126}
4127
4128void
4129TargetProperties::DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *)
4130{
4131 TargetProperties *this_ = reinterpret_cast<TargetProperties *>(target_property_ptr);
4132 if (this_->GetDisableSTDIO())
4133 this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO);
4134 else
4135 this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO);
4136}
Ilia Keb2c19a2015-03-10 21:59:55 +00004137
4138//----------------------------------------------------------------------
4139// Target::TargetEventData
4140//----------------------------------------------------------------------
4141
4142Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp) :
4143 EventData (),
4144 m_target_sp (target_sp),
4145 m_module_list ()
4146{
4147}
4148
4149Target::TargetEventData::TargetEventData (const lldb::TargetSP &target_sp, const ModuleList &module_list) :
4150 EventData (),
4151 m_target_sp (target_sp),
4152 m_module_list (module_list)
4153{
4154}
4155
Eugene Zelenko8f30a652015-10-23 18:39:37 +00004156Target::TargetEventData::~TargetEventData() = default;
Ilia Keb2c19a2015-03-10 21:59:55 +00004157
4158const ConstString &
4159Target::TargetEventData::GetFlavorString ()
4160{
4161 static ConstString g_flavor ("Target::TargetEventData");
4162 return g_flavor;
4163}
4164
4165void
4166Target::TargetEventData::Dump (Stream *s) const
4167{
Oleksiy Vyalov8b85b032016-01-19 17:54:47 +00004168 for (size_t i = 0; i < m_module_list.GetSize(); ++i)
4169 {
4170 if (i != 0)
4171 *s << ", ";
4172 m_module_list.GetModuleAtIndex(i)->GetDescription(s, lldb::eDescriptionLevelBrief);
4173 }
Ilia Keb2c19a2015-03-10 21:59:55 +00004174}
4175
4176const Target::TargetEventData *
4177Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
4178{
4179 if (event_ptr)
4180 {
4181 const EventData *event_data = event_ptr->GetData();
4182 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
4183 return static_cast <const TargetEventData *> (event_ptr->GetData());
4184 }
Eugene Zelenkoe2ccd332015-12-11 19:52:15 +00004185 return nullptr;
Ilia Keb2c19a2015-03-10 21:59:55 +00004186}
4187
4188TargetSP
4189Target::TargetEventData::GetTargetFromEvent (const Event *event_ptr)
4190{
4191 TargetSP target_sp;
4192 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
4193 if (event_data)
4194 target_sp = event_data->m_target_sp;
4195 return target_sp;
4196}
4197
4198ModuleList
4199Target::TargetEventData::GetModuleListFromEvent (const Event *event_ptr)
4200{
4201 ModuleList module_list;
4202 const TargetEventData *event_data = GetEventDataFromEvent (event_ptr);
4203 if (event_data)
4204 module_list = event_data->m_module_list;
4205 return module_list;
4206}