blob: 3a980251ef69d72f3c18cfef33003fe98907bdd5 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Target/Target.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Breakpoint/BreakpointResolver.h"
19#include "lldb/Breakpoint/BreakpointResolverAddress.h"
20#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham969795f2011-09-21 01:17:13 +000021#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chen01a67862011-10-14 00:42:25 +000023#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000024#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Event.h"
26#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/ModuleSpec.h"
29#include "lldb/Core/Section.h"
Greg Clayton9585fbf2013-03-19 00:20:55 +000030#include "lldb/Core/SourceManager.h"
Greg Claytonb09c5382013-12-13 17:20:18 +000031#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000032#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000034#include "lldb/Core/Timer.h"
35#include "lldb/Core/ValueObject.h"
Sean Callanan4bf80d52011-11-15 22:27:19 +000036#include "lldb/Expression/ClangASTSource.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000037#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:59 +000039#include "lldb/Interpreter/CommandInterpreter.h"
40#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chenb90827e2012-06-04 23:19:54 +000041#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000042#include "lldb/Interpreter/OptionValues.h"
43#include "lldb/Interpreter/Property.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/lldb-private-log.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000047#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000048#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000049#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000050#include "lldb/Target/Thread.h"
51#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052
53using namespace lldb;
54using namespace lldb_private;
55
Jim Ingham4bddaeb2012-02-16 06:50:00 +000056ConstString &
57Target::GetStaticBroadcasterClass ()
58{
59 static ConstString class_name ("lldb.target");
60 return class_name;
61}
62
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063//----------------------------------------------------------------------
64// Target constructor
65//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:51 +000066Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Greg Clayton67cc0632012-08-22 17:17:09 +000067 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +000068 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +000069 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +000070 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +000071 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +000072 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +000073 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +000074 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +000075 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 m_breakpoint_list (false),
77 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +000078 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +000079 m_process_sp (),
80 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Claytone01e07b2013-04-18 18:10:51 +000082 m_scratch_ast_context_ap (),
83 m_scratch_ast_source_ap (),
84 m_ast_importer_ap (),
Jim Ingham9575d842011-03-11 03:53:59 +000085 m_persistent_variables (),
Greg Clayton9585fbf2013-03-19 00:20:55 +000086 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +000087 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +000088 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +000089 m_valid (true),
Enrico Granata5d5f60c2013-09-24 22:58:37 +000090 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091{
Greg Claytoncfd1ace2010-10-31 03:01:06 +000092 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
93 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
94 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +000095 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +000096 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Jim Ingham4bddaeb2012-02-16 06:50:00 +000097
98 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +000099
Greg Clayton5160ce52013-03-27 23:08:40 +0000100 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101 if (log)
102 log->Printf ("%p Target::Target()", this);
Jason Molendae1b68ad2012-12-05 00:25:49 +0000103 if (m_arch.IsValid())
104 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000105 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 +0000106 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107}
108
109//----------------------------------------------------------------------
110// Destructor
111//----------------------------------------------------------------------
112Target::~Target()
113{
Greg Clayton5160ce52013-03-27 23:08:40 +0000114 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 if (log)
116 log->Printf ("%p Target::~Target()", this);
117 DeleteCurrentProcess ();
118}
119
120void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000121Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122{
Greg Clayton89411422010-10-08 00:21:05 +0000123// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000124 if (description_level != lldb::eDescriptionLevelBrief)
125 {
126 s->Indent();
127 s->PutCString("Target\n");
128 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000129 m_images.Dump(s);
130 m_breakpoint_list.Dump(s);
131 m_internal_breakpoint_list.Dump(s);
132 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000133 }
134 else
135 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000136 Module *exe_module = GetExecutableModulePointer();
137 if (exe_module)
138 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000139 else
140 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000141 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142}
143
144void
Greg Clayton90ba8112012-12-05 00:16:59 +0000145Target::CleanupProcess ()
146{
147 // Do any cleanup of the target we need to do between process instances.
148 // NB It is better to do this before destroying the process in case the
149 // clean up needs some help from the process.
150 m_breakpoint_list.ClearAllBreakpointSites();
151 m_internal_breakpoint_list.ClearAllBreakpointSites();
152 // Disable watchpoints just on the debugger side.
153 Mutex::Locker locker;
154 this->GetWatchpointList().GetListMutex(locker);
155 DisableAllWatchpoints(false);
156 ClearAllWatchpointHitCounts();
157}
158
159void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160Target::DeleteCurrentProcess ()
161{
162 if (m_process_sp.get())
163 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000164 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 if (m_process_sp->IsAlive())
166 m_process_sp->Destroy();
Jim Inghamd0a3e122011-02-16 17:54:55 +0000167
168 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169
Greg Clayton90ba8112012-12-05 00:16:59 +0000170 CleanupProcess ();
171
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172 m_process_sp.reset();
173 }
174}
175
176const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000177Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178{
179 DeleteCurrentProcess ();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000180 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 return m_process_sp;
182}
183
184const lldb::ProcessSP &
185Target::GetProcessSP () const
186{
187 return m_process_sp;
188}
189
Greg Clayton3418c852011-08-10 02:10:13 +0000190void
191Target::Destroy()
192{
193 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000194 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000195 DeleteCurrentProcess ();
196 m_platform_sp.reset();
197 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000198 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000199 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000200 const bool notify = false;
201 m_breakpoint_list.RemoveAll(notify);
202 m_internal_breakpoint_list.RemoveAll(notify);
203 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000204 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000205 m_search_filter_sp.reset();
206 m_image_search_paths.Clear(notify);
Greg Clayton3418c852011-08-10 02:10:13 +0000207 m_persistent_variables.Clear();
208 m_stop_hooks.clear();
209 m_stop_hook_next_id = 0;
210 m_suppress_stop_hooks = false;
211}
212
213
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214BreakpointList &
215Target::GetBreakpointList(bool internal)
216{
217 if (internal)
218 return m_internal_breakpoint_list;
219 else
220 return m_breakpoint_list;
221}
222
223const BreakpointList &
224Target::GetBreakpointList(bool internal) const
225{
226 if (internal)
227 return m_internal_breakpoint_list;
228 else
229 return m_breakpoint_list;
230}
231
232BreakpointSP
233Target::GetBreakpointByID (break_id_t break_id)
234{
235 BreakpointSP bp_sp;
236
237 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
238 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
239 else
240 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
241
242 return bp_sp;
243}
244
245BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000246Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000247 const FileSpecList *source_file_spec_list,
248 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000249 bool internal,
250 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251{
Jim Ingham87df91b2011-09-23 00:54:11 +0000252 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
253 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000254 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000255}
256
257
258BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000259Target::CreateBreakpoint (const FileSpecList *containingModules,
260 const FileSpec &file,
261 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000262 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000263 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000264 bool internal,
265 bool hardware)
Jim Ingham969795f2011-09-21 01:17:13 +0000266{
Greg Clayton1f746072012-08-29 21:13:06 +0000267 if (check_inlines == eLazyBoolCalculate)
268 {
269 const InlineStrategy inline_strategy = GetInlineStrategy();
270 switch (inline_strategy)
271 {
272 case eInlineBreakpointsNever:
273 check_inlines = eLazyBoolNo;
274 break;
275
276 case eInlineBreakpointsHeaders:
277 if (file.IsSourceImplementationFile())
278 check_inlines = eLazyBoolNo;
279 else
280 check_inlines = eLazyBoolYes;
281 break;
282
283 case eInlineBreakpointsAlways:
284 check_inlines = eLazyBoolYes;
285 break;
286 }
287 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000288 SearchFilterSP filter_sp;
289 if (check_inlines == eLazyBoolNo)
290 {
291 // Not checking for inlines, we are looking only for matching compile units
292 FileSpecList compile_unit_list;
293 compile_unit_list.Append (file);
294 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
295 }
296 else
297 {
298 filter_sp = GetSearchFilterForModuleList (containingModules);
299 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000300 if (skip_prologue == eLazyBoolCalculate)
301 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
302
Greg Clayton1f746072012-08-29 21:13:06 +0000303 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
304 file,
305 line_no,
306 check_inlines,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000307 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000308 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309}
310
311
312BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000313Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 Address so_addr;
316 // Attempt to resolve our load address if possible, though it is ok if
317 // it doesn't resolve to section/offset.
318
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000319 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000320 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000321 if (!so_addr.IsValid())
322 {
323 // The address didn't resolve, so just set this as an absolute address
324 so_addr.SetOffset (addr);
325 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000326 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327 return bp_sp;
328}
329
330BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000331Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000333 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000335 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336}
337
338BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000339Target::CreateBreakpoint (const FileSpecList *containingModules,
340 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000341 const char *func_name,
342 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000343 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000344 bool internal,
345 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000346{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000347 BreakpointSP bp_sp;
348 if (func_name)
349 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000350 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000351
352 if (skip_prologue == eLazyBoolCalculate)
353 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
354
Greg Claytond16e1e52011-07-12 17:06:17 +0000355 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
356 func_name,
357 func_name_type_mask,
358 Breakpoint::Exact,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000359 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000360 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000361 }
362 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
Jim Inghamfab10e82012-03-06 00:37:27 +0000365lldb::BreakpointSP
366Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000367 const FileSpecList *containingSourceFiles,
368 const std::vector<std::string> &func_names,
369 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000370 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000371 bool internal,
372 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000373{
374 BreakpointSP bp_sp;
375 size_t num_names = func_names.size();
376 if (num_names > 0)
377 {
378 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000379
380 if (skip_prologue == eLazyBoolCalculate)
381 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
382
383 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Inghamfab10e82012-03-06 00:37:27 +0000384 func_names,
385 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000386 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000387 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000388 }
389 return bp_sp;
390}
391
Jim Ingham133e0fb2012-03-03 02:05:11 +0000392BreakpointSP
393Target::CreateBreakpoint (const FileSpecList *containingModules,
394 const FileSpecList *containingSourceFiles,
395 const char *func_names[],
396 size_t num_names,
397 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000398 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000399 bool internal,
400 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000401{
402 BreakpointSP bp_sp;
403 if (num_names > 0)
404 {
405 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
406
Greg Clayton03da4cc2013-04-19 21:31:16 +0000407 if (skip_prologue == eLazyBoolCalculate)
408 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
409
410 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Ingham133e0fb2012-03-03 02:05:11 +0000411 func_names,
412 num_names,
Jim Inghamfab10e82012-03-06 00:37:27 +0000413 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000414 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000415 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000416 }
417 return bp_sp;
418}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419
420SearchFilterSP
421Target::GetSearchFilterForModule (const FileSpec *containingModule)
422{
423 SearchFilterSP filter_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 if (containingModule != NULL)
425 {
426 // TODO: We should look into sharing module based search filters
427 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000428 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 }
430 else
431 {
432 if (m_search_filter_sp.get() == NULL)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000433 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 filter_sp = m_search_filter_sp;
435 }
436 return filter_sp;
437}
438
Jim Ingham969795f2011-09-21 01:17:13 +0000439SearchFilterSP
440Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
441{
442 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000443 if (containingModules && containingModules->GetSize() != 0)
444 {
445 // TODO: We should look into sharing module based search filters
446 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000447 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000448 }
449 else
450 {
451 if (m_search_filter_sp.get() == NULL)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000452 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000453 filter_sp = m_search_filter_sp;
454 }
455 return filter_sp;
456}
457
Jim Ingham87df91b2011-09-23 00:54:11 +0000458SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000459Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
460 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000461{
462 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
463 return GetSearchFilterForModuleList(containingModules);
464
465 SearchFilterSP filter_sp;
Jim Ingham87df91b2011-09-23 00:54:11 +0000466 if (containingModules == NULL)
467 {
468 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
469 // but that will take a little reworking.
470
Greg Claytone1cd1be2012-01-29 20:56:30 +0000471 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000472 }
473 else
474 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000475 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000476 }
477 return filter_sp;
478}
479
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000481Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000482 const FileSpecList *containingSourceFiles,
483 RegularExpression &func_regex,
484 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000485 bool internal,
486 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Jim Ingham87df91b2011-09-23 00:54:11 +0000488 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Claytond16e1e52011-07-12 17:06:17 +0000489 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
490 func_regex,
491 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492
Jim Ingham1460e4b2014-01-10 23:46:59 +0000493 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494}
495
Jim Ingham219ba192012-03-05 04:47:34 +0000496lldb::BreakpointSP
497Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
498{
499 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
500}
501
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000503Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504{
505 BreakpointSP bp_sp;
506 if (filter_sp && resolver_sp)
507 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000508 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 resolver_sp->SetBreakpoint (bp_sp.get());
510
511 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000512 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 else
Greg Clayton9fed0d82010-07-23 23:33:17 +0000514 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515
Greg Clayton5160ce52013-03-27 23:08:40 +0000516 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 if (log)
518 {
519 StreamString s;
520 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
521 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
522 }
523
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 bp_sp->ResolveBreakpoint();
525 }
Jim Ingham36f3b362010-10-14 23:45:03 +0000526
527 if (!internal && bp_sp)
528 {
529 m_last_created_breakpoint = bp_sp;
530 }
531
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 return bp_sp;
533}
534
Johnny Chen86364b42011-09-20 23:28:55 +0000535bool
536Target::ProcessIsValid()
537{
538 return (m_process_sp && m_process_sp->IsAlive());
539}
540
Johnny Chenb90827e2012-06-04 23:19:54 +0000541static bool
542CheckIfWatchpointsExhausted(Target *target, Error &error)
543{
544 uint32_t num_supported_hardware_watchpoints;
545 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
546 if (rc.Success())
547 {
548 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
549 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
550 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
551 num_supported_hardware_watchpoints);
552 }
553 return false;
554}
555
Johnny Chen01a67862011-10-14 00:42:25 +0000556// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000557// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000558WatchpointSP
Jim Inghama7dfb662012-10-23 07:20:06 +0000559Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000560{
Greg Clayton5160ce52013-03-27 23:08:40 +0000561 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000562 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000563 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000564 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000565
Johnny Chen01a67862011-10-14 00:42:25 +0000566 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000567 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000568 {
569 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000570 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000571 }
Jim Inghamc6462312013-06-18 21:52:48 +0000572
Johnny Chen45e541f2011-09-14 22:20:15 +0000573 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000574 {
575 if (size == 0)
576 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
577 else
Daniel Malead01b2952012-11-29 21:49:15 +0000578 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000579 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000580 }
Jim Inghamc6462312013-06-18 21:52:48 +0000581
582 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
583 {
584 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
585 }
Johnny Chen7313a642011-09-13 01:15:36 +0000586
Johnny Chen01a67862011-10-14 00:42:25 +0000587 // Currently we only support one watchpoint per address, with total number
588 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000589
590 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000591 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 +0000592 Mutex::Locker locker;
593 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000594 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000595 if (matched_sp)
596 {
Johnny Chen0c406372011-09-14 20:23:45 +0000597 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000598 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000599 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
600 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000601 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000602 if (size == old_size && kind == old_type)
603 {
Johnny Chen01a67862011-10-14 00:42:25 +0000604 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000605 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000606 }
607 else
608 {
Johnny Chen01a67862011-10-14 00:42:25 +0000609 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000610 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
611 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000612 }
Johnny Chen3c532582011-09-13 23:29:31 +0000613 }
614
Jason Molenda727e3922012-12-05 23:07:34 +0000615 if (!wp_sp)
616 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000617 wp_sp.reset(new Watchpoint(*this, addr, size, type));
618 wp_sp->SetWatchpointType(kind, notify);
619 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000620 }
Johnny Chen0c406372011-09-14 20:23:45 +0000621
Jim Ingham1b5792e2012-12-18 02:03:49 +0000622 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000623 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000624 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
625 __FUNCTION__,
626 error.Success() ? "succeeded" : "failed",
627 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000628
Jason Molenda727e3922012-12-05 23:07:34 +0000629 if (error.Fail())
630 {
Johnny Chen41b77262012-03-26 22:00:10 +0000631 // Enabling the watchpoint on the device side failed.
632 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000633 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000634 // See if we could provide more helpful error message.
635 if (!CheckIfWatchpointsExhausted(this, error))
636 {
637 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Sylvestre Ledru779f9212013-10-31 23:55:19 +0000638 error.SetErrorStringWithFormat("watch size of %zu is not supported", size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000639 }
Johnny Chen01a67862011-10-14 00:42:25 +0000640 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000641 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000642 else
Johnny Chen01a67862011-10-14 00:42:25 +0000643 m_last_created_watchpoint = wp_sp;
644 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000645}
646
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000647void
648Target::RemoveAllBreakpoints (bool internal_also)
649{
Greg Clayton5160ce52013-03-27 23:08:40 +0000650 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651 if (log)
652 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
653
Greg Clayton9fed0d82010-07-23 23:33:17 +0000654 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000656 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000657
658 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659}
660
661void
662Target::DisableAllBreakpoints (bool internal_also)
663{
Greg Clayton5160ce52013-03-27 23:08:40 +0000664 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 if (log)
666 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
667
668 m_breakpoint_list.SetEnabledAll (false);
669 if (internal_also)
670 m_internal_breakpoint_list.SetEnabledAll (false);
671}
672
673void
674Target::EnableAllBreakpoints (bool internal_also)
675{
Greg Clayton5160ce52013-03-27 23:08:40 +0000676 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 if (log)
678 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
679
680 m_breakpoint_list.SetEnabledAll (true);
681 if (internal_also)
682 m_internal_breakpoint_list.SetEnabledAll (true);
683}
684
685bool
686Target::RemoveBreakpointByID (break_id_t break_id)
687{
Greg Clayton5160ce52013-03-27 23:08:40 +0000688 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 if (log)
690 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
691
692 if (DisableBreakpointByID (break_id))
693 {
694 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000695 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000697 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000698 if (m_last_created_breakpoint)
699 {
700 if (m_last_created_breakpoint->GetID() == break_id)
701 m_last_created_breakpoint.reset();
702 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000703 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000704 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 return true;
706 }
707 return false;
708}
709
710bool
711Target::DisableBreakpointByID (break_id_t break_id)
712{
Greg Clayton5160ce52013-03-27 23:08:40 +0000713 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 if (log)
715 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
716
717 BreakpointSP bp_sp;
718
719 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
720 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
721 else
722 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
723 if (bp_sp)
724 {
725 bp_sp->SetEnabled (false);
726 return true;
727 }
728 return false;
729}
730
731bool
732Target::EnableBreakpointByID (break_id_t break_id)
733{
Greg Clayton5160ce52013-03-27 23:08:40 +0000734 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 if (log)
736 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
737 __FUNCTION__,
738 break_id,
739 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
740
741 BreakpointSP bp_sp;
742
743 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
744 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
745 else
746 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
747
748 if (bp_sp)
749 {
750 bp_sp->SetEnabled (true);
751 return true;
752 }
753 return false;
754}
755
Johnny Chenedf50372011-09-23 21:21:43 +0000756// The flag 'end_to_end', default to true, signifies that the operation is
757// performed end to end, for both the debugger and the debuggee.
758
Johnny Chen01a67862011-10-14 00:42:25 +0000759// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
760// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000761bool
Johnny Chen01a67862011-10-14 00:42:25 +0000762Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000763{
Greg Clayton5160ce52013-03-27 23:08:40 +0000764 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000765 if (log)
766 log->Printf ("Target::%s\n", __FUNCTION__);
767
Johnny Chenedf50372011-09-23 21:21:43 +0000768 if (!end_to_end) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000769 m_watchpoint_list.RemoveAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000770 return true;
771 }
772
773 // Otherwise, it's an end to end operation.
774
Johnny Chen86364b42011-09-20 23:28:55 +0000775 if (!ProcessIsValid())
776 return false;
777
Johnny Chen01a67862011-10-14 00:42:25 +0000778 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000779 for (size_t i = 0; i < num_watchpoints; ++i)
780 {
Johnny Chen01a67862011-10-14 00:42:25 +0000781 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
782 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000783 return false;
784
Johnny Chen01a67862011-10-14 00:42:25 +0000785 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000786 if (rc.Fail())
787 return false;
788 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000789 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000790 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000791 return true; // Success!
792}
793
Johnny Chen01a67862011-10-14 00:42:25 +0000794// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
795// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000796bool
Johnny Chen01a67862011-10-14 00:42:25 +0000797Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000798{
Greg Clayton5160ce52013-03-27 23:08:40 +0000799 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000800 if (log)
801 log->Printf ("Target::%s\n", __FUNCTION__);
802
Johnny Chenedf50372011-09-23 21:21:43 +0000803 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000804 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000805 return true;
806 }
807
808 // Otherwise, it's an end to end operation.
809
Johnny Chen86364b42011-09-20 23:28:55 +0000810 if (!ProcessIsValid())
811 return false;
812
Johnny Chen01a67862011-10-14 00:42:25 +0000813 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000814 for (size_t i = 0; i < num_watchpoints; ++i)
815 {
Johnny Chen01a67862011-10-14 00:42:25 +0000816 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
817 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000818 return false;
819
Johnny Chen01a67862011-10-14 00:42:25 +0000820 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000821 if (rc.Fail())
822 return false;
823 }
Johnny Chen86364b42011-09-20 23:28:55 +0000824 return true; // Success!
825}
826
Johnny Chen01a67862011-10-14 00:42:25 +0000827// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
828// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000829bool
Johnny Chen01a67862011-10-14 00:42:25 +0000830Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000831{
Greg Clayton5160ce52013-03-27 23:08:40 +0000832 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000833 if (log)
834 log->Printf ("Target::%s\n", __FUNCTION__);
835
Johnny Chenedf50372011-09-23 21:21:43 +0000836 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000837 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000838 return true;
839 }
840
841 // Otherwise, it's an end to end operation.
842
Johnny Chen86364b42011-09-20 23:28:55 +0000843 if (!ProcessIsValid())
844 return false;
845
Johnny Chen01a67862011-10-14 00:42:25 +0000846 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000847 for (size_t i = 0; i < num_watchpoints; ++i)
848 {
Johnny Chen01a67862011-10-14 00:42:25 +0000849 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
850 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000851 return false;
852
Johnny Chen01a67862011-10-14 00:42:25 +0000853 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000854 if (rc.Fail())
855 return false;
856 }
Johnny Chen86364b42011-09-20 23:28:55 +0000857 return true; // Success!
858}
859
Johnny Chena4d6bc92012-02-25 06:44:30 +0000860// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
861bool
862Target::ClearAllWatchpointHitCounts ()
863{
Greg Clayton5160ce52013-03-27 23:08:40 +0000864 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +0000865 if (log)
866 log->Printf ("Target::%s\n", __FUNCTION__);
867
868 size_t num_watchpoints = m_watchpoint_list.GetSize();
869 for (size_t i = 0; i < num_watchpoints; ++i)
870 {
871 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
872 if (!wp_sp)
873 return false;
874
875 wp_sp->ResetHitCount();
876 }
877 return true; // Success!
878}
879
Johnny Chen01a67862011-10-14 00:42:25 +0000880// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +0000881// during these operations.
882bool
Johnny Chen01a67862011-10-14 00:42:25 +0000883Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000884{
Greg Clayton5160ce52013-03-27 23:08:40 +0000885 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000886 if (log)
887 log->Printf ("Target::%s\n", __FUNCTION__);
888
889 if (!ProcessIsValid())
890 return false;
891
Johnny Chen01a67862011-10-14 00:42:25 +0000892 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +0000893 for (size_t i = 0; i < num_watchpoints; ++i)
894 {
Johnny Chen01a67862011-10-14 00:42:25 +0000895 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
896 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000897 return false;
898
Johnny Chen01a67862011-10-14 00:42:25 +0000899 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000900 }
901 return true; // Success!
902}
903
Johnny Chen01a67862011-10-14 00:42:25 +0000904// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000905bool
Johnny Chen01a67862011-10-14 00:42:25 +0000906Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000907{
Greg Clayton5160ce52013-03-27 23:08:40 +0000908 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000909 if (log)
910 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
911
912 if (!ProcessIsValid())
913 return false;
914
Johnny Chen01a67862011-10-14 00:42:25 +0000915 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
916 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000917 {
Johnny Chen01a67862011-10-14 00:42:25 +0000918 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000919 if (rc.Success())
920 return true;
Johnny Chen86364b42011-09-20 23:28:55 +0000921
Johnny Chenf04ee932011-09-22 18:04:58 +0000922 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +0000923 }
924 return false;
925}
926
Johnny Chen01a67862011-10-14 00:42:25 +0000927// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000928bool
Johnny Chen01a67862011-10-14 00:42:25 +0000929Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000930{
Greg Clayton5160ce52013-03-27 23:08:40 +0000931 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000932 if (log)
933 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
934
935 if (!ProcessIsValid())
936 return false;
937
Johnny Chen01a67862011-10-14 00:42:25 +0000938 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
939 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000940 {
Johnny Chen01a67862011-10-14 00:42:25 +0000941 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000942 if (rc.Success())
943 return true;
Johnny Chen86364b42011-09-20 23:28:55 +0000944
Johnny Chenf04ee932011-09-22 18:04:58 +0000945 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +0000946 }
947 return false;
948}
949
Johnny Chen01a67862011-10-14 00:42:25 +0000950// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000951bool
Johnny Chen01a67862011-10-14 00:42:25 +0000952Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000953{
Greg Clayton5160ce52013-03-27 23:08:40 +0000954 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000955 if (log)
956 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
957
Jim Inghamb0b45132013-07-02 02:09:46 +0000958 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
959 if (watch_to_remove_sp == m_last_created_watchpoint)
960 m_last_created_watchpoint.reset();
961
Johnny Chen01a67862011-10-14 00:42:25 +0000962 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +0000963 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000964 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +0000965 return true;
966 }
967 return false;
968}
969
Johnny Chen01a67862011-10-14 00:42:25 +0000970// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +0000971bool
Johnny Chen01a67862011-10-14 00:42:25 +0000972Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000973{
Greg Clayton5160ce52013-03-27 23:08:40 +0000974 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000975 if (log)
976 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
977
978 if (!ProcessIsValid())
979 return false;
980
Johnny Chen01a67862011-10-14 00:42:25 +0000981 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
982 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000983 {
Johnny Chen01a67862011-10-14 00:42:25 +0000984 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000985 return true;
986 }
987 return false;
988}
989
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000990ModuleSP
991Target::GetExecutableModule ()
992{
Greg Claytonaa149cb2011-08-11 02:48:45 +0000993 return m_images.GetModuleAtIndex(0);
994}
995
996Module*
997Target::GetExecutableModulePointer ()
998{
999 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000}
1001
Enrico Granata17598482012-11-08 02:22:02 +00001002static void
1003LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1004{
1005 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001006 StreamString feedback_stream;
1007 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001008 {
Enrico Granata97303392013-05-21 00:00:30 +00001009 if (error.AsCString())
Greg Clayton44d93782014-01-27 23:43:24 +00001010 target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001011 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1012 error.AsCString());
1013 if (feedback_stream.GetSize())
Greg Clayton44d93782014-01-27 23:43:24 +00001014 target->GetDebugger().GetErrorFile()->Printf("%s\n",
Enrico Granata97303392013-05-21 00:00:30 +00001015 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001016 }
1017}
1018
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019void
Greg Claytonb35db632013-11-09 00:03:31 +00001020Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001021{
Greg Claytonb35db632013-11-09 00:03:31 +00001022 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001023 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 m_images.Clear();
1025 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19 +00001026 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47 +00001027 m_ast_importer_ap.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001028}
1029
1030void
Greg Claytonb35db632013-11-09 00:03:31 +00001031Target::DidExec ()
1032{
1033 // When a process exec's we need to know about it so we can do some cleanup.
1034 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1035 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1036}
1037
1038void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001039Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1040{
1041 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001042 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043
1044 if (executable_sp.get())
1045 {
1046 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001047 "Target::SetExecutableModule (executable = '%s')",
1048 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049
1050 m_images.Append(executable_sp); // The first image is our exectuable file
1051
Jim Ingham5aee1622010-08-09 23:31:02 +00001052 // 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 +00001053 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001054 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001055 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001056 if (log)
1057 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1058 }
1059
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001061 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001063 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064 {
1065 executable_objfile->GetDependentModules(dependent_files);
1066 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1067 {
Greg Claytonded470d2011-03-19 01:12:21 +00001068 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1069 FileSpec platform_dependent_file_spec;
1070 if (m_platform_sp)
Steve Puccifc995722014-01-17 18:18:31 +00001071 m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001072 else
1073 platform_dependent_file_spec = dependent_file_spec;
1074
Greg Claytonb9a01b32012-02-26 05:51:37 +00001075 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1076 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077 if (image_module_sp.get())
1078 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079 ObjectFile *objfile = image_module_sp->GetObjectFile();
1080 if (objfile)
1081 objfile->GetDependentModules(dependent_files);
1082 }
1083 }
1084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 }
1086}
1087
1088
Jim Ingham5aee1622010-08-09 23:31:02 +00001089bool
1090Target::SetArchitecture (const ArchSpec &arch_spec)
1091{
Greg Clayton5160ce52013-03-27 23:08:40 +00001092 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callananbf4b7be2012-12-13 22:07:14 +00001093 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001094 {
Greg Clayton70512312012-05-08 01:45:38 +00001095 // If we haven't got a valid arch spec, or the architectures are
1096 // compatible, so just update the architecture. Architectures can be
1097 // equal, yet the triple OS and vendor might change, so we need to do
1098 // the assignment here just in case.
Greg Clayton32e0a752011-03-30 18:16:51 +00001099 m_arch = arch_spec;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001100 if (log)
1101 log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +00001102 return true;
1103 }
1104 else
1105 {
1106 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molendae1b68ad2012-12-05 00:25:49 +00001107 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +00001108 log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Clayton32e0a752011-03-30 18:16:51 +00001109 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02 +00001110 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001111
Greg Claytonb35db632013-11-09 00:03:31 +00001112 ClearModules(true);
Jim Ingham5aee1622010-08-09 23:31:02 +00001113 // Need to do something about unsetting breakpoints.
1114
1115 if (executable_sp)
1116 {
Jason Molendae1b68ad2012-12-05 00:25:49 +00001117 if (log)
1118 log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Claytonb9a01b32012-02-26 05:51:37 +00001119 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1120 Error error = ModuleList::GetSharedModule (module_spec,
1121 executable_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001122 &GetExecutableSearchPaths(),
Greg Claytonb9a01b32012-02-26 05:51:37 +00001123 NULL,
1124 NULL);
Jim Ingham5aee1622010-08-09 23:31:02 +00001125
1126 if (!error.Fail() && executable_sp)
1127 {
1128 SetExecutableModule (executable_sp, true);
1129 return true;
1130 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001131 }
1132 }
Greg Clayton70512312012-05-08 01:45:38 +00001133 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001134}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136void
Enrico Granataefe637d2012-11-08 19:16:03 +00001137Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001138{
1139}
1140
1141void
Enrico Granataefe637d2012-11-08 19:16:03 +00001142Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143{
1144 // A module is being added to this target for the first time
Enrico Granataefe637d2012-11-08 19:16:03 +00001145 ModuleList my_module_list;
1146 my_module_list.Append(module_sp);
Enrico Granata17598482012-11-08 02:22:02 +00001147 LoadScriptingResourceForModule(module_sp, this);
Enrico Granataefe637d2012-11-08 19:16:03 +00001148 ModulesDidLoad (my_module_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149}
1150
1151void
Enrico Granataefe637d2012-11-08 19:16:03 +00001152Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001153{
1154 // A module is being added to this target for the first time
Enrico Granataefe637d2012-11-08 19:16:03 +00001155 ModuleList my_module_list;
1156 my_module_list.Append(module_sp);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001157 ModulesDidUnload (my_module_list, false);
Enrico Granata17598482012-11-08 02:22:02 +00001158}
1159
1160void
Enrico Granataefe637d2012-11-08 19:16:03 +00001161Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162{
Jim Inghame716ae02011-08-03 01:00:06 +00001163 // A module is replacing an already added module
Jim Ingham4a94c912012-05-17 18:38:42 +00001164 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165}
1166
1167void
1168Target::ModulesDidLoad (ModuleList &module_list)
1169{
Enrico Granata17598482012-11-08 02:22:02 +00001170 if (module_list.GetSize())
1171 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001172 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001173 if (m_process_sp)
1174 {
1175 SystemRuntime *sys_runtime = m_process_sp->GetSystemRuntime();
1176 if (sys_runtime)
1177 {
1178 sys_runtime->ModulesDidLoad (module_list);
1179 }
1180 }
Enrico Granata17598482012-11-08 02:22:02 +00001181 // TODO: make event data that packages up the module_list
1182 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1183 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184}
1185
1186void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001187Target::SymbolsDidLoad (ModuleList &module_list)
1188{
Jim Ingham31caf982013-06-04 23:01:35 +00001189 if (module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001190 {
Jim Ingham31caf982013-06-04 23:01:35 +00001191 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001192 {
Jim Ingham31caf982013-06-04 23:01:35 +00001193 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1194 if (runtime)
1195 {
1196 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1197 objc_runtime->SymbolsDidLoad(module_list);
1198 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001199 }
Jim Ingham31caf982013-06-04 23:01:35 +00001200
Greg Clayton095eeaa2013-11-05 23:28:00 +00001201 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jim Ingham31caf982013-06-04 23:01:35 +00001202 BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL);
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001203 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001204}
1205
1206void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001207Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208{
Enrico Granata17598482012-11-08 02:22:02 +00001209 if (module_list.GetSize())
1210 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001211 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Enrico Granata17598482012-11-08 02:22:02 +00001212 // TODO: make event data that packages up the module_list
1213 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215}
1216
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001217bool
Greg Claytonb9a01b32012-02-26 05:51:37 +00001218Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001219{
Greg Clayton67cc0632012-08-22 17:17:09 +00001220 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001221 {
1222 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001223 ModuleSpec module_spec (module_file_spec);
1224 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001225
1226 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1227 // black list.
1228 if (num_modules > 0)
1229 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001230 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001231 {
1232 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1233 return false;
1234 }
1235 return true;
1236 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001237 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001238 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001239}
1240
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001241bool
Jim Inghamc6674fd2011-10-28 23:14:11 +00001242Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1243{
Greg Clayton67cc0632012-08-22 17:17:09 +00001244 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001245 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001246 if (m_platform_sp)
1247 return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001248 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001249 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001250}
1251
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252size_t
Greg Claytondb598232011-01-07 01:57:07 +00001253Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1254{
Greg Claytone72dfb32012-02-24 01:59:29 +00001255 SectionSP section_sp (addr.GetSection());
1256 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001257 {
Jason Molenda216d91f2012-04-25 00:06:56 +00001258 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1259 if (section_sp->IsEncrypted())
1260 {
Greg Clayton57f06302012-05-25 17:05:55 +00001261 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001262 return 0;
1263 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001264 ModuleSP module_sp (section_sp->GetModule());
1265 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001266 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001267 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1268 if (objfile)
1269 {
1270 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1271 addr.GetOffset(),
1272 dst,
1273 dst_len);
1274 if (bytes_read > 0)
1275 return bytes_read;
1276 else
1277 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1278 }
Greg Claytondb598232011-01-07 01:57:07 +00001279 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001280 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001281 }
1282 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001283 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001284 }
1285 else
Greg Claytondb598232011-01-07 01:57:07 +00001286 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001287
Greg Claytondb598232011-01-07 01:57:07 +00001288 return 0;
1289}
1290
1291size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001292Target::ReadMemory (const Address& addr,
1293 bool prefer_file_cache,
1294 void *dst,
1295 size_t dst_len,
1296 Error &error,
1297 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001300
Enrico Granata9128ee22011-09-06 19:20:51 +00001301 // if we end up reading this from process memory, we will fill this
1302 // with the actual load address
1303 if (load_addr_ptr)
1304 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1305
Greg Claytondb598232011-01-07 01:57:07 +00001306 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001307
1308 addr_t load_addr = LLDB_INVALID_ADDRESS;
1309 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001310 Address resolved_addr;
1311 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001312 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001313 SectionLoadList &section_load_list = GetSectionLoadList();
1314 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001315 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001316 // No sections are loaded, so we must assume we are not running
1317 // yet and anything we are given is a file address.
1318 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1319 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001320 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001321 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001322 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001323 // We have at least one section loaded. This can be becuase
1324 // we have manually loaded some sections with "target modules load ..."
1325 // or because we have have a live process that has sections loaded
1326 // through the dynamic loader
1327 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001328 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001329 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001330 }
Greg Clayton357132e2011-03-26 19:14:58 +00001331 if (!resolved_addr.IsValid())
1332 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001333
Greg Claytonc749eb82011-07-11 05:12:02 +00001334
Greg Claytondb598232011-01-07 01:57:07 +00001335 if (prefer_file_cache)
1336 {
1337 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1338 if (bytes_read > 0)
1339 return bytes_read;
1340 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001341
Johnny Chen86364b42011-09-20 23:28:55 +00001342 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001343 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001344 if (load_addr == LLDB_INVALID_ADDRESS)
1345 load_addr = resolved_addr.GetLoadAddress (this);
1346
Greg Claytondda4f7b2010-06-30 23:03:03 +00001347 if (load_addr == LLDB_INVALID_ADDRESS)
1348 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001349 ModuleSP addr_module_sp (resolved_addr.GetModule());
1350 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001351 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Greg Claytone72dfb32012-02-24 01:59:29 +00001352 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda7e589a62011-09-20 00:26:08 +00001353 resolved_addr.GetFileAddress(),
Greg Claytone72dfb32012-02-24 01:59:29 +00001354 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001355 else
Daniel Malead01b2952012-11-29 21:49:15 +00001356 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001357 }
1358 else
1359 {
Greg Claytondb598232011-01-07 01:57:07 +00001360 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361 if (bytes_read != dst_len)
1362 {
1363 if (error.Success())
1364 {
1365 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001366 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 else
Daniel Malead01b2952012-11-29 21:49:15 +00001368 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 +00001369 }
1370 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001371 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001372 {
1373 if (load_addr_ptr)
1374 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001375 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001376 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001377 // If the address is not section offset we have an address that
1378 // doesn't resolve to any address in any currently loaded shared
1379 // libaries and we failed to read memory so there isn't anything
1380 // more we can do. If it is section offset, we might be able to
1381 // read cached memory from the object file.
1382 if (!resolved_addr.IsSectionOffset())
1383 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001385 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001386
Greg Claytonc749eb82011-07-11 05:12:02 +00001387 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001388 {
Greg Claytondb598232011-01-07 01:57:07 +00001389 // If we didn't already try and read from the object file cache, then
1390 // try it after failing to read from the process.
1391 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001392 }
1393 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394}
1395
Greg Claytond16e1e52011-07-12 17:06:17 +00001396size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001397Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1398{
1399 char buf[256];
1400 out_str.clear();
1401 addr_t curr_addr = addr.GetLoadAddress(this);
1402 Address address(addr);
1403 while (1)
1404 {
1405 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1406 if (length == 0)
1407 break;
1408 out_str.append(buf, length);
1409 // If we got "length - 1" bytes, we didn't get the whole C string, we
1410 // need to read some more characters
1411 if (length == sizeof(buf) - 1)
1412 curr_addr += length;
1413 else
1414 break;
1415 address = Address(curr_addr);
1416 }
1417 return out_str.size();
1418}
1419
1420
1421size_t
1422Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1423{
1424 size_t total_cstr_len = 0;
1425 if (dst && dst_max_len)
1426 {
1427 result_error.Clear();
1428 // NULL out everything just to be safe
1429 memset (dst, 0, dst_max_len);
1430 Error error;
1431 addr_t curr_addr = addr.GetLoadAddress(this);
1432 Address address(addr);
1433 const size_t cache_line_size = 512;
1434 size_t bytes_left = dst_max_len - 1;
1435 char *curr_dst = dst;
1436
1437 while (bytes_left > 0)
1438 {
1439 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1440 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1441 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1442
1443 if (bytes_read == 0)
1444 {
1445 result_error = error;
1446 dst[total_cstr_len] = '\0';
1447 break;
1448 }
1449 const size_t len = strlen(curr_dst);
1450
1451 total_cstr_len += len;
1452
1453 if (len < bytes_to_read)
1454 break;
1455
1456 curr_dst += bytes_read;
1457 curr_addr += bytes_read;
1458 bytes_left -= bytes_read;
1459 address = Address(curr_addr);
1460 }
1461 }
1462 else
1463 {
1464 if (dst == NULL)
1465 result_error.SetErrorString("invalid arguments");
1466 else
1467 result_error.Clear();
1468 }
1469 return total_cstr_len;
1470}
1471
1472size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001473Target::ReadScalarIntegerFromMemory (const Address& addr,
1474 bool prefer_file_cache,
1475 uint32_t byte_size,
1476 bool is_signed,
1477 Scalar &scalar,
1478 Error &error)
1479{
1480 uint64_t uval;
1481
1482 if (byte_size <= sizeof(uval))
1483 {
1484 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1485 if (bytes_read == byte_size)
1486 {
1487 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001488 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001489 if (byte_size <= 4)
1490 scalar = data.GetMaxU32 (&offset, byte_size);
1491 else
1492 scalar = data.GetMaxU64 (&offset, byte_size);
1493
1494 if (is_signed)
1495 scalar.SignExtend(byte_size * 8);
1496 return bytes_read;
1497 }
1498 }
1499 else
1500 {
1501 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1502 }
1503 return 0;
1504}
1505
1506uint64_t
1507Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1508 bool prefer_file_cache,
1509 size_t integer_byte_size,
1510 uint64_t fail_value,
1511 Error &error)
1512{
1513 Scalar scalar;
1514 if (ReadScalarIntegerFromMemory (addr,
1515 prefer_file_cache,
1516 integer_byte_size,
1517 false,
1518 scalar,
1519 error))
1520 return scalar.ULongLong(fail_value);
1521 return fail_value;
1522}
1523
1524bool
1525Target::ReadPointerFromMemory (const Address& addr,
1526 bool prefer_file_cache,
1527 Error &error,
1528 Address &pointer_addr)
1529{
1530 Scalar scalar;
1531 if (ReadScalarIntegerFromMemory (addr,
1532 prefer_file_cache,
1533 m_arch.GetAddressByteSize(),
1534 false,
1535 scalar,
1536 error))
1537 {
1538 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1539 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1540 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001541 SectionLoadList &section_load_list = GetSectionLoadList();
1542 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001543 {
1544 // No sections are loaded, so we must assume we are not running
1545 // yet and anything we are given is a file address.
1546 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1547 }
1548 else
1549 {
1550 // We have at least one section loaded. This can be becuase
1551 // we have manually loaded some sections with "target modules load ..."
1552 // or because we have have a live process that has sections loaded
1553 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001554 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001555 }
1556 // We weren't able to resolve the pointer value, so just return
1557 // an address with no section
1558 if (!pointer_addr.IsValid())
1559 pointer_addr.SetOffset (pointer_vm_addr);
1560 return true;
1561
1562 }
1563 }
1564 return false;
1565}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001566
1567ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001568Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001570 ModuleSP module_sp;
1571
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001572 Error error;
1573
Jim Ingham4a94c912012-05-17 18:38:42 +00001574 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1575 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001576
Jim Ingham4a94c912012-05-17 18:38:42 +00001577 if (module_spec.GetUUID().IsValid())
1578 module_sp = m_images.FindFirstModule(module_spec);
1579
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001580 if (!module_sp)
1581 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001582 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1583 bool did_create_module = false;
1584
1585 // If there are image search path entries, try to use them first to acquire a suitable image.
1586 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001587 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001588 ModuleSpec transformed_spec (module_spec);
1589 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1590 {
1591 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1592 error = ModuleList::GetSharedModule (transformed_spec,
1593 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001594 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001595 &old_module_sp,
1596 &did_create_module);
1597 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001598 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001599
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001600 if (!module_sp)
1601 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001602 // If we have a UUID, we can check our global shared module list in case
1603 // we already have it. If we don't have a valid UUID, then we can't since
1604 // the path in "module_spec" will be a platform path, and we will need to
1605 // let the platform find that file. For example, we could be asking for
1606 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1607 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1608 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1609 // cache.
1610 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001611 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001612 // We have a UUID, it is OK to check the global module list...
1613 error = ModuleList::GetSharedModule (module_spec,
1614 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001615 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001616 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001617 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001618 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001619
1620 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001621 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001622 // The platform is responsible for finding and caching an appropriate
1623 // module in the shared module cache.
1624 if (m_platform_sp)
1625 {
1626 FileSpec platform_file_spec;
1627 error = m_platform_sp->GetSharedModule (module_spec,
1628 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001629 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001630 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001631 &did_create_module);
1632 }
1633 else
1634 {
1635 error.SetErrorString("no platform is currently set");
1636 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001637 }
1638 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001639
Jim Ingham4a94c912012-05-17 18:38:42 +00001640 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1641 // module in the list already, and if there was, let's remove it.
1642 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001644 ObjectFile *objfile = module_sp->GetObjectFile();
1645 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001646 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001647 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001648 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001649 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1650 case ObjectFile::eTypeExecutable: /// A normal executable
1651 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1652 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1653 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1654 break;
1655 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1656 if (error_ptr)
1657 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1658 return ModuleSP();
1659 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1660 if (error_ptr)
1661 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1662 return ModuleSP();
1663 default:
1664 if (error_ptr)
1665 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1666 return ModuleSP();
1667 }
1668 // GetSharedModule is not guaranteed to find the old shared module, for instance
1669 // in the common case where you pass in the UUID, it is only going to find the one
1670 // module matching the UUID. In fact, it has no good way to know what the "old module"
1671 // relevant to this target is, since there might be many copies of a module with this file spec
1672 // in various running debug sessions, but only one of them will belong to this target.
1673 // So let's remove the UUID from the module list, and look in the target's module list.
1674 // Only do this if there is SOMETHING else in the module spec...
1675 if (!old_module_sp)
1676 {
1677 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001678 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001679 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1680 module_spec_copy.GetUUID().Clear();
1681
1682 ModuleList found_modules;
1683 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1684 if (num_found == 1)
1685 {
1686 old_module_sp = found_modules.GetModuleAtIndex(0);
1687 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001688 }
1689 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001690
1691 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1692 {
1693 m_images.ReplaceModule(old_module_sp, module_sp);
1694 Module *old_module_ptr = old_module_sp.get();
1695 old_module_sp.reset();
1696 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1697 }
1698 else
1699 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001700 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701 }
1702 }
1703 if (error_ptr)
1704 *error_ptr = error;
1705 return module_sp;
1706}
1707
1708
Greg Claytond9e416c2012-02-18 05:35:26 +00001709TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001710Target::CalculateTarget ()
1711{
Greg Claytond9e416c2012-02-18 05:35:26 +00001712 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713}
1714
Greg Claytond9e416c2012-02-18 05:35:26 +00001715ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716Target::CalculateProcess ()
1717{
Greg Claytond9e416c2012-02-18 05:35:26 +00001718 return ProcessSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719}
1720
Greg Claytond9e416c2012-02-18 05:35:26 +00001721ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722Target::CalculateThread ()
1723{
Greg Claytond9e416c2012-02-18 05:35:26 +00001724 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725}
1726
Jason Molendab57e4a12013-11-04 09:33:30 +00001727StackFrameSP
1728Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001729{
Jason Molendab57e4a12013-11-04 09:33:30 +00001730 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731}
1732
1733void
Greg Clayton0603aa92010-10-04 01:05:56 +00001734Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735{
Greg Claytonc14ee322011-09-22 04:58:26 +00001736 exe_ctx.Clear();
1737 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001738}
1739
1740PathMappingList &
1741Target::GetImageSearchPathList ()
1742{
1743 return m_image_search_paths;
1744}
1745
1746void
1747Target::ImageSearchPathsChanged
1748(
1749 const PathMappingList &path_list,
1750 void *baton
1751)
1752{
1753 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001754 ModuleSP exe_module_sp (target->GetExecutableModule());
1755 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001756 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001757}
1758
1759ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001760Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761{
Greg Clayton73da2442011-08-03 01:23:55 +00001762 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001763 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanan4bf80d52011-11-15 22:27:19 +00001764 {
Greg Clayton73da2442011-08-03 01:23:55 +00001765 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Claytone1cd1be2012-01-29 20:56:30 +00001766 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanan4bf80d52011-11-15 22:27:19 +00001767 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1768 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1769 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1770 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771 return m_scratch_ast_context_ap.get();
1772}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001773
Sean Callanan686b2312011-11-16 18:20:47 +00001774ClangASTImporter *
1775Target::GetClangASTImporter()
1776{
1777 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1778
1779 if (!ast_importer)
1780 {
1781 ast_importer = new ClangASTImporter();
1782 m_ast_importer_ap.reset(ast_importer);
1783 }
1784
1785 return ast_importer;
1786}
1787
Greg Clayton99d0faf2010-11-18 23:32:35 +00001788void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001789Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00001790{
Greg Clayton6920b522012-08-22 18:39:03 +00001791 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001792}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001793
Greg Clayton99d0faf2010-11-18 23:32:35 +00001794void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001795Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001796{
Greg Clayton6920b522012-08-22 18:39:03 +00001797 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001798}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001799
Greg Claytonc859e2d2012-02-13 23:10:39 +00001800FileSpecList
1801Target::GetDefaultExecutableSearchPaths ()
1802{
Greg Clayton67cc0632012-08-22 17:17:09 +00001803 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1804 if (properties_sp)
1805 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00001806 return FileSpecList();
1807}
1808
Michael Sartaina7499c92013-07-01 19:45:50 +00001809FileSpecList
1810Target::GetDefaultDebugFileSearchPaths ()
1811{
1812 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1813 if (properties_sp)
1814 return properties_sp->GetDebugFileSearchPaths();
1815 return FileSpecList();
1816}
1817
Caroline Ticedaccaa92010-09-20 20:44:43 +00001818ArchSpec
1819Target::GetDefaultArchitecture ()
1820{
Greg Clayton67cc0632012-08-22 17:17:09 +00001821 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1822 if (properties_sp)
1823 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00001824 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00001825}
1826
1827void
Greg Clayton67cc0632012-08-22 17:17:09 +00001828Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001829{
Greg Clayton67cc0632012-08-22 17:17:09 +00001830 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1831 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00001832 {
1833 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 +00001834 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00001835 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001836}
1837
Greg Clayton0603aa92010-10-04 01:05:56 +00001838Target *
1839Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1840{
1841 // The target can either exist in the "process" of ExecutionContext, or in
1842 // the "target_sp" member of SymbolContext. This accessor helper function
1843 // will get the target from one of these locations.
1844
1845 Target *target = NULL;
1846 if (sc_ptr != NULL)
1847 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:26 +00001848 if (target == NULL && exe_ctx_ptr)
1849 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00001850 return target;
1851}
1852
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001853ExecutionResults
1854Target::EvaluateExpression
1855(
1856 const char *expr_cstr,
Jason Molendab57e4a12013-11-04 09:33:30 +00001857 StackFrame *frame,
Enrico Granata3372f582012-07-16 23:10:35 +00001858 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad4439aa2012-09-05 20:41:26 +00001859 const EvaluateExpressionOptions& options
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001860)
1861{
Enrico Granata97fca502012-09-18 17:43:16 +00001862 result_valobj_sp.reset();
1863
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001864 ExecutionResults execution_results = eExecutionSetupError;
1865
Greg Claytond1767f02011-12-08 02:13:16 +00001866 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1867 return execution_results;
1868
Jim Ingham6026ca32011-05-12 02:06:14 +00001869 // We shouldn't run stop hooks in expressions.
1870 // Be sure to reset this if you return anywhere within this function.
1871 bool old_suppress_value = m_suppress_stop_hooks;
1872 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001873
1874 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001875
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001876 if (frame)
1877 {
1878 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001879 }
1880 else if (m_process_sp)
1881 {
1882 m_process_sp->CalculateExecutionContext(exe_ctx);
1883 }
1884 else
1885 {
1886 CalculateExecutionContext(exe_ctx);
1887 }
1888
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001889 // Make sure we aren't just trying to see the value of a persistent
1890 // variable (something like "$0")
1891 lldb::ClangExpressionVariableSP persistent_var_sp;
1892 // Only check for persistent variables the expression starts with a '$'
1893 if (expr_cstr[0] == '$')
1894 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1895
1896 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001897 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001898 result_valobj_sp = persistent_var_sp->GetValueObject ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001899 execution_results = eExecutionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001900 }
1901 else
1902 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001903 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00001904 Error error;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001905 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001906 options,
1907 expr_cstr,
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001908 prefix,
1909 result_valobj_sp,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001910 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001911 }
Jim Ingham6026ca32011-05-12 02:06:14 +00001912
1913 m_suppress_stop_hooks = old_suppress_value;
1914
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001915 return execution_results;
1916}
1917
Greg Claytonf3ef3d22011-05-22 22:46:53 +00001918lldb::addr_t
1919Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1920{
1921 addr_t code_addr = load_addr;
1922 switch (m_arch.GetMachine())
1923 {
1924 case llvm::Triple::arm:
1925 case llvm::Triple::thumb:
1926 switch (addr_class)
1927 {
1928 case eAddressClassData:
1929 case eAddressClassDebug:
1930 return LLDB_INVALID_ADDRESS;
1931
1932 case eAddressClassUnknown:
1933 case eAddressClassInvalid:
1934 case eAddressClassCode:
1935 case eAddressClassCodeAlternateISA:
1936 case eAddressClassRuntime:
1937 // Check if bit zero it no set?
1938 if ((code_addr & 1ull) == 0)
1939 {
1940 // Bit zero isn't set, check if the address is a multiple of 2?
1941 if (code_addr & 2ull)
1942 {
1943 // The address is a multiple of 2 so it must be thumb, set bit zero
1944 code_addr |= 1ull;
1945 }
1946 else if (addr_class == eAddressClassCodeAlternateISA)
1947 {
1948 // We checked the address and the address claims to be the alternate ISA
1949 // which means thumb, so set bit zero.
1950 code_addr |= 1ull;
1951 }
1952 }
1953 break;
1954 }
1955 break;
1956
1957 default:
1958 break;
1959 }
1960 return code_addr;
1961}
1962
1963lldb::addr_t
1964Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1965{
1966 addr_t opcode_addr = load_addr;
1967 switch (m_arch.GetMachine())
1968 {
1969 case llvm::Triple::arm:
1970 case llvm::Triple::thumb:
1971 switch (addr_class)
1972 {
1973 case eAddressClassData:
1974 case eAddressClassDebug:
1975 return LLDB_INVALID_ADDRESS;
1976
1977 case eAddressClassInvalid:
1978 case eAddressClassUnknown:
1979 case eAddressClassCode:
1980 case eAddressClassCodeAlternateISA:
1981 case eAddressClassRuntime:
1982 opcode_addr &= ~(1ull);
1983 break;
1984 }
1985 break;
1986
1987 default:
1988 break;
1989 }
1990 return opcode_addr;
1991}
1992
Greg Clayton9585fbf2013-03-19 00:20:55 +00001993SourceManager &
1994Target::GetSourceManager ()
1995{
1996 if (m_source_manager_ap.get() == NULL)
1997 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
1998 return *m_source_manager_ap;
1999}
2000
2001
Greg Clayton44d93782014-01-27 23:43:24 +00002002Target::StopHookSP
2003Target::CreateStopHook ()
Jim Ingham9575d842011-03-11 03:53:59 +00002004{
2005 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton44d93782014-01-27 23:43:24 +00002006 Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
2007 m_stop_hooks[new_uid] = stop_hook_sp;
2008 return stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00002009}
2010
2011bool
2012Target::RemoveStopHookByID (lldb::user_id_t user_id)
2013{
2014 size_t num_removed;
2015 num_removed = m_stop_hooks.erase (user_id);
2016 if (num_removed == 0)
2017 return false;
2018 else
2019 return true;
2020}
2021
2022void
2023Target::RemoveAllStopHooks ()
2024{
2025 m_stop_hooks.clear();
2026}
2027
2028Target::StopHookSP
2029Target::GetStopHookByID (lldb::user_id_t user_id)
2030{
2031 StopHookSP found_hook;
2032
2033 StopHookCollection::iterator specified_hook_iter;
2034 specified_hook_iter = m_stop_hooks.find (user_id);
2035 if (specified_hook_iter != m_stop_hooks.end())
2036 found_hook = (*specified_hook_iter).second;
2037 return found_hook;
2038}
2039
2040bool
2041Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2042{
2043 StopHookCollection::iterator specified_hook_iter;
2044 specified_hook_iter = m_stop_hooks.find (user_id);
2045 if (specified_hook_iter == m_stop_hooks.end())
2046 return false;
2047
2048 (*specified_hook_iter).second->SetIsActive (active_state);
2049 return true;
2050}
2051
2052void
2053Target::SetAllStopHooksActiveState (bool active_state)
2054{
2055 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2056 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2057 {
2058 (*pos).second->SetIsActive (active_state);
2059 }
2060}
2061
2062void
2063Target::RunStopHooks ()
2064{
Jim Ingham6026ca32011-05-12 02:06:14 +00002065 if (m_suppress_stop_hooks)
2066 return;
2067
Jim Ingham9575d842011-03-11 03:53:59 +00002068 if (!m_process_sp)
2069 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002070
2071 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2072 // since in that case we do not want to run the stop-hooks
2073 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2074 return;
2075
Jim Ingham9575d842011-03-11 03:53:59 +00002076 if (m_stop_hooks.empty())
2077 return;
2078
2079 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2080
2081 // If there aren't any active stop hooks, don't bother either:
2082 bool any_active_hooks = false;
2083 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2084 {
2085 if ((*pos).second->IsActive())
2086 {
2087 any_active_hooks = true;
2088 break;
2089 }
2090 }
2091 if (!any_active_hooks)
2092 return;
2093
2094 CommandReturnObject result;
2095
2096 std::vector<ExecutionContext> exc_ctx_with_reasons;
2097 std::vector<SymbolContext> sym_ctx_with_reasons;
2098
2099 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2100 size_t num_threads = cur_threadlist.GetSize();
2101 for (size_t i = 0; i < num_threads; i++)
2102 {
2103 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2104 if (cur_thread_sp->ThreadStoppedForAReason())
2105 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002106 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002107 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2108 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2109 }
2110 }
2111
2112 // If no threads stopped for a reason, don't run the stop-hooks.
2113 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2114 if (num_exe_ctx == 0)
2115 return;
2116
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002117 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2118 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002119
2120 bool keep_going = true;
2121 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:27 +00002122 bool print_hook_header;
2123 bool print_thread_header;
2124
2125 if (num_exe_ctx == 1)
2126 print_thread_header = false;
2127 else
2128 print_thread_header = true;
2129
2130 if (m_stop_hooks.size() == 1)
2131 print_hook_header = false;
2132 else
2133 print_hook_header = true;
2134
Jim Ingham9575d842011-03-11 03:53:59 +00002135 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2136 {
2137 // result.Clear();
2138 StopHookSP cur_hook_sp = (*pos).second;
2139 if (!cur_hook_sp->IsActive())
2140 continue;
2141
2142 bool any_thread_matched = false;
2143 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2144 {
2145 if ((cur_hook_sp->GetSpecifier () == NULL
2146 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2147 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Ingham3d902922012-03-07 22:03:04 +00002148 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002149 {
2150 if (!hooks_ran)
2151 {
Jim Ingham9575d842011-03-11 03:53:59 +00002152 hooks_ran = true;
2153 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002154 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002155 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002156 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2157 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2158 NULL);
2159 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002160 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002161 else
Daniel Malead01b2952012-11-29 21:49:15 +00002162 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002163 any_thread_matched = true;
2164 }
2165
Jim Ingham381e25b2011-03-22 01:47:27 +00002166 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002167 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:59 +00002168
2169 bool stop_on_continue = true;
2170 bool stop_on_error = true;
2171 bool echo_commands = false;
2172 bool print_results = true;
2173 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:51 +00002174 &exc_ctx_with_reasons[i],
2175 stop_on_continue,
2176 stop_on_error,
2177 echo_commands,
Enrico Granata5f5ab602012-05-31 01:09:06 +00002178 print_results,
2179 eLazyBoolNo,
Greg Clayton32e0a752011-03-30 18:16:51 +00002180 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002181
2182 // If the command started the target going again, we should bag out of
2183 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002184 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2185 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002186 {
Daniel Malead01b2952012-11-29 21:49:15 +00002187 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002188 keep_going = false;
2189 }
2190 }
2191 }
2192 }
Jason Molenda879cf772011-09-23 00:42:55 +00002193
Caroline Tice969ed3d2011-05-02 20:41:46 +00002194 result.GetImmediateOutputStream()->Flush();
2195 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002196}
2197
Greg Claytonfbb76342013-11-20 21:07:01 +00002198const TargetPropertiesSP &
2199Target::GetGlobalProperties()
2200{
2201 static TargetPropertiesSP g_settings_sp;
2202 if (!g_settings_sp)
2203 {
2204 g_settings_sp.reset (new TargetProperties (NULL));
2205 }
2206 return g_settings_sp;
2207}
2208
2209Error
2210Target::Install (ProcessLaunchInfo *launch_info)
2211{
2212 Error error;
2213 PlatformSP platform_sp (GetPlatform());
2214 if (platform_sp)
2215 {
2216 if (platform_sp->IsRemote())
2217 {
2218 if (platform_sp->IsConnected())
2219 {
2220 // Install all files that have an install path, and always install the
2221 // main executable when connected to a remote platform
2222 const ModuleList& modules = GetImages();
2223 const size_t num_images = modules.GetSize();
2224 for (size_t idx = 0; idx < num_images; ++idx)
2225 {
2226 const bool is_main_executable = idx == 0;
2227 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2228 if (module_sp)
2229 {
2230 FileSpec local_file (module_sp->GetFileSpec());
2231 if (local_file)
2232 {
2233 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2234 if (!remote_file)
2235 {
2236 if (is_main_executable) // TODO: add setting for always installing main executable???
2237 {
2238 // Always install the main executable
2239 remote_file.GetDirectory() = platform_sp->GetWorkingDirectory();
2240 remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename();
2241 }
2242 }
2243 if (remote_file)
2244 {
2245 error = platform_sp->Install(local_file, remote_file);
2246 if (error.Success())
2247 {
2248 module_sp->SetPlatformFileSpec(remote_file);
2249 if (is_main_executable)
2250 {
2251 if (launch_info)
2252 launch_info->SetExecutableFile(remote_file, false);
2253 }
2254 }
2255 else
2256 break;
2257 }
2258 }
2259 }
2260 }
2261 }
2262 }
2263 }
2264 return error;
2265}
Greg Clayton7b242382011-07-08 00:48:09 +00002266
Greg Claytond5944cd2013-12-06 01:12:00 +00002267bool
2268Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2269{
2270 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2271}
2272
2273bool
2274Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2275{
2276 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2277 if (old_section_load_addr != new_section_load_addr)
2278 {
2279 uint32_t stop_id = 0;
2280 ProcessSP process_sp(GetProcessSP());
2281 if (process_sp)
2282 stop_id = process_sp->GetStopID();
2283 else
2284 stop_id = m_section_load_history.GetLastStopID();
2285 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2286 return true; // Return true if the section load address was changed...
2287 }
2288 return false; // Return false to indicate nothing changed
2289
2290}
2291
2292bool
2293Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2294{
2295 uint32_t stop_id = 0;
2296 ProcessSP process_sp(GetProcessSP());
2297 if (process_sp)
2298 stop_id = process_sp->GetStopID();
2299 else
2300 stop_id = m_section_load_history.GetLastStopID();
2301 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2302}
2303
2304bool
2305Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2306{
2307 uint32_t stop_id = 0;
2308 ProcessSP process_sp(GetProcessSP());
2309 if (process_sp)
2310 stop_id = process_sp->GetStopID();
2311 else
2312 stop_id = m_section_load_history.GetLastStopID();
2313 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2314}
2315
2316void
2317Target::ClearAllLoadedSections ()
2318{
2319 m_section_load_history.Clear();
2320}
2321
Greg Claytonb09c5382013-12-13 17:20:18 +00002322
2323Error
2324Target::Launch (Listener &listener, ProcessLaunchInfo &launch_info)
2325{
2326 Error error;
Greg Claytonb09c5382013-12-13 17:20:18 +00002327
2328 StateType state = eStateInvalid;
2329
Greg Clayton6b32f1e2013-12-18 02:06:45 +00002330 // Scope to temporarily get the process state in case someone has manually
2331 // remotely connected already to a process and we can skip the platform
2332 // launching.
2333 {
2334 ProcessSP process_sp (GetProcessSP());
2335
2336 if (process_sp)
2337 state = process_sp->GetState();
2338 }
2339
Greg Claytonb09c5382013-12-13 17:20:18 +00002340 launch_info.GetFlags().Set (eLaunchFlagDebug);
2341
2342 // Get the value of synchronous execution here. If you wait till after you have started to
2343 // run, then you could have hit a breakpoint, whose command might switch the value, and
2344 // then you'll pick up that incorrect value.
2345 Debugger &debugger = GetDebugger();
2346 const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
2347
2348 PlatformSP platform_sp (GetPlatform());
2349
2350 // Finalize the file actions, and if none were given, default to opening
2351 // up a pseudo terminal
2352 const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
2353 launch_info.FinalizeFileActions (this, default_to_use_pty);
2354
2355 if (state == eStateConnected)
2356 {
2357 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
2358 {
2359 error.SetErrorString("can't launch in tty when launching through a remote connection");
2360 return error;
2361 }
2362 }
2363
2364 if (!launch_info.GetArchitecture().IsValid())
2365 launch_info.GetArchitecture() = GetArchitecture();
2366
2367 if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
2368 {
2369 m_process_sp = GetPlatform()->DebugProcess (launch_info,
2370 debugger,
2371 this,
2372 listener,
2373 error);
2374 }
2375 else
2376 {
2377 if (state == eStateConnected)
2378 {
2379 assert(m_process_sp);
2380 }
2381 else
2382 {
2383 const char *plugin_name = launch_info.GetProcessPluginName();
2384 CreateProcess (listener, plugin_name, NULL);
2385 }
2386
2387 if (m_process_sp)
2388 error = m_process_sp->Launch (launch_info);
2389 }
2390
2391 if (!m_process_sp)
2392 {
2393 if (error.Success())
2394 error.SetErrorString("failed to launch or debug process");
2395 return error;
2396 }
2397
2398 if (error.Success())
2399 {
2400 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
2401 {
Greg Clayton44d93782014-01-27 23:43:24 +00002402 ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
2403
2404 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get());
Greg Claytonb09c5382013-12-13 17:20:18 +00002405
2406 if (state == eStateStopped)
2407 {
Greg Clayton44d93782014-01-27 23:43:24 +00002408 if (!synchronous_execution)
2409 m_process_sp->RestoreProcessEvents ();
2410
2411 error = m_process_sp->PrivateResume();
2412
Greg Claytonb09c5382013-12-13 17:20:18 +00002413 if (error.Success())
2414 {
2415 if (synchronous_execution)
2416 {
Greg Clayton44d93782014-01-27 23:43:24 +00002417 state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get());
Greg Claytonb09c5382013-12-13 17:20:18 +00002418 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2419 if (!StateIsStoppedState(state, must_be_alive))
2420 {
Greg Clayton44d93782014-01-27 23:43:24 +00002421 error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
Greg Claytonb09c5382013-12-13 17:20:18 +00002422 }
2423 }
2424 }
2425 else
2426 {
Greg Clayton44d93782014-01-27 23:43:24 +00002427 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002428 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002429 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002430 }
2431 }
2432 else
2433 {
2434 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2435 }
2436 }
Greg Clayton44d93782014-01-27 23:43:24 +00002437 m_process_sp->RestoreProcessEvents ();
Greg Claytonb09c5382013-12-13 17:20:18 +00002438 }
2439 else
2440 {
Greg Clayton44d93782014-01-27 23:43:24 +00002441 Error error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002442 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
Greg Clayton44d93782014-01-27 23:43:24 +00002443 error = error2;
Greg Claytonb09c5382013-12-13 17:20:18 +00002444 }
2445 return error;
2446}
Jim Ingham9575d842011-03-11 03:53:59 +00002447//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00002448// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00002449//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00002450Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2451 UserID (uid),
2452 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00002453 m_commands (),
2454 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00002455 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002456 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00002457{
2458}
2459
2460Target::StopHook::StopHook (const StopHook &rhs) :
2461 UserID (rhs.GetID()),
2462 m_target_sp (rhs.m_target_sp),
2463 m_commands (rhs.m_commands),
2464 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00002465 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002466 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00002467{
2468 if (rhs.m_thread_spec_ap.get() != NULL)
2469 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2470}
2471
2472
2473Target::StopHook::~StopHook ()
2474{
2475}
2476
2477void
2478Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2479{
2480 m_thread_spec_ap.reset (specifier);
2481}
2482
2483
2484void
2485Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2486{
2487 int indent_level = s->GetIndentLevel();
2488
2489 s->SetIndentLevel(indent_level + 2);
2490
Daniel Malead01b2952012-11-29 21:49:15 +00002491 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002492 if (m_active)
2493 s->Indent ("State: enabled\n");
2494 else
2495 s->Indent ("State: disabled\n");
2496
2497 if (m_specifier_sp)
2498 {
2499 s->Indent();
2500 s->PutCString ("Specifier:\n");
2501 s->SetIndentLevel (indent_level + 4);
2502 m_specifier_sp->GetDescription (s, level);
2503 s->SetIndentLevel (indent_level + 2);
2504 }
2505
2506 if (m_thread_spec_ap.get() != NULL)
2507 {
2508 StreamString tmp;
2509 s->Indent("Thread:\n");
2510 m_thread_spec_ap->GetDescription (&tmp, level);
2511 s->SetIndentLevel (indent_level + 4);
2512 s->Indent (tmp.GetData());
2513 s->PutCString ("\n");
2514 s->SetIndentLevel (indent_level + 2);
2515 }
2516
2517 s->Indent ("Commands: \n");
2518 s->SetIndentLevel (indent_level + 4);
2519 uint32_t num_commands = m_commands.GetSize();
2520 for (uint32_t i = 0; i < num_commands; i++)
2521 {
2522 s->Indent(m_commands.GetStringAtIndex(i));
2523 s->PutCString ("\n");
2524 }
2525 s->SetIndentLevel (indent_level);
2526}
2527
Greg Clayton67cc0632012-08-22 17:17:09 +00002528//--------------------------------------------------------------
2529// class TargetProperties
2530//--------------------------------------------------------------
2531
2532OptionEnumValueElement
2533lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002534{
Greg Clayton67cc0632012-08-22 17:17:09 +00002535 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2536 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2537 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2538 { 0, NULL, NULL }
2539};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002540
Greg Clayton1f746072012-08-29 21:13:06 +00002541static OptionEnumValueElement
2542g_inline_breakpoint_enums[] =
2543{
2544 { 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."},
2545 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2546 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2547 { 0, NULL, NULL }
2548};
2549
Jim Ingham0f063ba2013-03-02 00:26:47 +00002550typedef enum x86DisassemblyFlavor
2551{
2552 eX86DisFlavorDefault,
2553 eX86DisFlavorIntel,
2554 eX86DisFlavorATT
2555} x86DisassemblyFlavor;
2556
2557static OptionEnumValueElement
2558g_x86_dis_flavor_value_types[] =
2559{
2560 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2561 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2562 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2563 { 0, NULL, NULL }
2564};
2565
Enrico Granata397ddd52013-05-21 20:13:34 +00002566static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00002567g_hex_immediate_style_values[] =
2568{
2569 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
2570 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
2571 { 0, NULL, NULL }
2572};
2573
2574static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00002575g_load_script_from_sym_file_values[] =
2576{
2577 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
2578 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
2579 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
2580 { 0, NULL, NULL }
2581};
2582
Greg Claytonfd814c52013-08-13 01:42:25 +00002583
2584static OptionEnumValueElement
2585g_memory_module_load_level_values[] =
2586{
Greg Clayton86eac942013-08-13 21:32:34 +00002587 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00002588 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
2589 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
2590 { 0, NULL, NULL }
2591};
2592
Greg Clayton67cc0632012-08-22 17:17:09 +00002593static PropertyDefinition
2594g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002595{
Greg Clayton67cc0632012-08-22 17:17:09 +00002596 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2597 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2598 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2599 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2600 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2601 { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and "
2602 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2603 "some part (starting at the root) of the path to the file when it was built, "
2604 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2605 "Each element of the array is checked in order and the first one that results in a match wins." },
2606 { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
Michael Sartaina7499c92013-07-01 19:45:50 +00002607 { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating debug symbol files." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002608 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2609 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
Enrico Granatad325bf92013-06-04 22:54:16 +00002610 { "max-memory-read-size" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of bytes that 'memory read' will fetch before --force must be specified." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002611 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Clayton45392552012-10-17 22:57:12 +00002612 { "arg0" , OptionValue::eTypeString , false, 0 , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." },
2613 { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002614 { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2615 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2616 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2617 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2618 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2619 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2620 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Greg Clayton1f746072012-08-29 21:13:06 +00002621 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
2622 "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. "
2623 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2624 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
2625 "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the "
2626 "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings "
2627 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00002628 // 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.
2629 { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, NULL, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." },
Daniel Malead79ae052013-08-07 21:54:09 +00002630 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
2631 { "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, NULL, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." },
Jim Ingham34951272013-04-04 01:38:54 +00002632 { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." },
Enrico Granata397ddd52013-05-21 20:13:34 +00002633 { "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, eLoadScriptFromSymFileWarn, NULL, g_load_script_from_sym_file_values, "Allow LLDB to load scripting resources embedded in symbol files when available." },
Greg Clayton86eac942013-08-13 21:32:34 +00002634 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
2635 "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. "
2636 "This setting helps users control how much information gets loaded when loading modules from memory."
2637 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
2638 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
2639 "'minimal' is the fastest setting and will load section data with no symbols, but should rarely be used as stack frames in these memory regions will be inaccurate and not provide any context (fastest). " },
Greg Claytonfb6621e2013-12-06 21:59:52 +00002640 { "display-expression-in-crashlogs" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "Expressions that crash will show up in crash logs if the host system supports executable specific crash log strings and this setting is set to true." },
Greg Clayton67cc0632012-08-22 17:17:09 +00002641 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2642};
2643enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00002644{
Greg Clayton67cc0632012-08-22 17:17:09 +00002645 ePropertyDefaultArch,
2646 ePropertyExprPrefix,
2647 ePropertyPreferDynamic,
2648 ePropertyEnableSynthetic,
2649 ePropertySkipPrologue,
2650 ePropertySourceMap,
2651 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00002652 ePropertyDebugFileSearchPaths,
Greg Clayton67cc0632012-08-22 17:17:09 +00002653 ePropertyMaxChildrenCount,
2654 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00002655 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00002656 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00002657 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00002658 ePropertyRunArgs,
2659 ePropertyEnvVars,
2660 ePropertyInheritEnv,
2661 ePropertyInputPath,
2662 ePropertyOutputPath,
2663 ePropertyErrorPath,
2664 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00002665 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002666 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00002667 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00002668 ePropertyUseHexImmediates,
2669 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00002670 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00002671 ePropertyLoadScriptFromSymbolFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00002672 ePropertyMemoryModuleLoadLevel,
2673 ePropertyDisplayExpressionsInCrashlogs
Greg Clayton67cc0632012-08-22 17:17:09 +00002674};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002675
Caroline Ticedaccaa92010-09-20 20:44:43 +00002676
Greg Clayton67cc0632012-08-22 17:17:09 +00002677class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00002678{
Greg Clayton67cc0632012-08-22 17:17:09 +00002679public:
2680 TargetOptionValueProperties (const ConstString &name) :
2681 OptionValueProperties (name),
2682 m_target (NULL),
2683 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002684 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00002685 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002686
Greg Clayton67cc0632012-08-22 17:17:09 +00002687 // This constructor is used when creating TargetOptionValueProperties when it
2688 // is part of a new lldb_private::Target instance. It will copy all current
2689 // global property values as needed
2690 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2691 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2692 m_target (target),
2693 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002694 {
Greg Clayton67cc0632012-08-22 17:17:09 +00002695 }
2696
2697 virtual const Property *
2698 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2699 {
2700 // When gettings the value for a key from the target options, we will always
2701 // try and grab the setting from the current target if there is one. Else we just
2702 // use the one from this instance.
2703 if (idx == ePropertyEnvVars)
2704 GetHostEnvironmentIfNeeded ();
2705
2706 if (exe_ctx)
2707 {
2708 Target *target = exe_ctx->GetTargetPtr();
2709 if (target)
2710 {
2711 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2712 if (this != target_properties)
2713 return target_properties->ProtectedGetPropertyAtIndex (idx);
2714 }
2715 }
2716 return ProtectedGetPropertyAtIndex (idx);
2717 }
Enrico Granata84a53df2013-05-20 22:29:23 +00002718
2719 lldb::TargetSP
2720 GetTargetSP ()
2721 {
2722 return m_target->shared_from_this();
2723 }
2724
Greg Clayton67cc0632012-08-22 17:17:09 +00002725protected:
2726
2727 void
2728 GetHostEnvironmentIfNeeded () const
2729 {
2730 if (!m_got_host_env)
2731 {
2732 if (m_target)
2733 {
2734 m_got_host_env = true;
2735 const uint32_t idx = ePropertyInheritEnv;
2736 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2737 {
2738 PlatformSP platform_sp (m_target->GetPlatform());
2739 if (platform_sp)
2740 {
2741 StringList env;
2742 if (platform_sp->GetEnvironment(env))
2743 {
2744 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2745 if (env_dict)
2746 {
2747 const bool can_replace = false;
2748 const size_t envc = env.GetSize();
2749 for (size_t idx=0; idx<envc; idx++)
2750 {
2751 const char *env_entry = env.GetStringAtIndex (idx);
2752 if (env_entry)
2753 {
2754 const char *equal_pos = ::strchr(env_entry, '=');
2755 ConstString key;
2756 // It is ok to have environment variables with no values
2757 const char *value = NULL;
2758 if (equal_pos)
2759 {
2760 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2761 if (equal_pos[1])
2762 value = equal_pos + 1;
2763 }
2764 else
2765 {
2766 key.SetCString(env_entry);
2767 }
2768 // Don't allow existing keys to be replaced with ones we get from the platform environment
2769 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2770 }
2771 }
2772 }
2773 }
2774 }
2775 }
2776 }
2777 }
2778 }
2779 Target *m_target;
2780 mutable bool m_got_host_env;
2781};
2782
Greg Claytonfbb76342013-11-20 21:07:01 +00002783//----------------------------------------------------------------------
2784// TargetProperties
2785//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00002786TargetProperties::TargetProperties (Target *target) :
2787 Properties ()
2788{
2789 if (target)
2790 {
2791 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Caroline Ticedaccaa92010-09-20 20:44:43 +00002792 }
2793 else
Greg Clayton67cc0632012-08-22 17:17:09 +00002794 {
2795 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2796 m_collection_sp->Initialize(g_properties);
2797 m_collection_sp->AppendProperty(ConstString("process"),
2798 ConstString("Settings specify to processes."),
2799 true,
2800 Process::GetGlobalProperties()->GetValueProperties());
2801 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002802}
2803
Greg Clayton67cc0632012-08-22 17:17:09 +00002804TargetProperties::~TargetProperties ()
2805{
2806}
2807ArchSpec
2808TargetProperties::GetDefaultArchitecture () const
2809{
2810 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2811 if (value)
2812 return value->GetCurrentValue();
2813 return ArchSpec();
2814}
2815
2816void
2817TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2818{
2819 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2820 if (value)
2821 return value->SetCurrentValue(arch, true);
2822}
2823
2824lldb::DynamicValueType
2825TargetProperties::GetPreferDynamicValue() const
2826{
2827 const uint32_t idx = ePropertyPreferDynamic;
2828 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2829}
2830
2831bool
2832TargetProperties::GetDisableASLR () const
2833{
2834 const uint32_t idx = ePropertyDisableASLR;
2835 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2836}
2837
2838void
2839TargetProperties::SetDisableASLR (bool b)
2840{
2841 const uint32_t idx = ePropertyDisableASLR;
2842 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2843}
2844
2845bool
2846TargetProperties::GetDisableSTDIO () const
2847{
2848 const uint32_t idx = ePropertyDisableSTDIO;
2849 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2850}
2851
2852void
2853TargetProperties::SetDisableSTDIO (bool b)
2854{
2855 const uint32_t idx = ePropertyDisableSTDIO;
2856 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2857}
2858
Jim Ingham0f063ba2013-03-02 00:26:47 +00002859const char *
2860TargetProperties::GetDisassemblyFlavor () const
2861{
2862 const uint32_t idx = ePropertyDisassemblyFlavor;
2863 const char *return_value;
2864
2865 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2866 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
2867 return return_value;
2868}
2869
Greg Clayton1f746072012-08-29 21:13:06 +00002870InlineStrategy
2871TargetProperties::GetInlineStrategy () const
2872{
2873 const uint32_t idx = ePropertyInlineStrategy;
2874 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2875}
2876
Greg Clayton45392552012-10-17 22:57:12 +00002877const char *
2878TargetProperties::GetArg0 () const
2879{
2880 const uint32_t idx = ePropertyArg0;
2881 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
2882}
2883
2884void
2885TargetProperties::SetArg0 (const char *arg)
2886{
2887 const uint32_t idx = ePropertyArg0;
2888 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
2889}
2890
Greg Clayton67cc0632012-08-22 17:17:09 +00002891bool
2892TargetProperties::GetRunArguments (Args &args) const
2893{
2894 const uint32_t idx = ePropertyRunArgs;
2895 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
2896}
2897
2898void
2899TargetProperties::SetRunArguments (const Args &args)
2900{
2901 const uint32_t idx = ePropertyRunArgs;
2902 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
2903}
2904
2905size_t
2906TargetProperties::GetEnvironmentAsArgs (Args &env) const
2907{
2908 const uint32_t idx = ePropertyEnvVars;
2909 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
2910}
2911
2912bool
2913TargetProperties::GetSkipPrologue() const
2914{
2915 const uint32_t idx = ePropertySkipPrologue;
2916 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2917}
2918
2919PathMappingList &
2920TargetProperties::GetSourcePathMap () const
2921{
2922 const uint32_t idx = ePropertySourceMap;
2923 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
2924 assert(option_value);
2925 return option_value->GetCurrentValue();
2926}
2927
2928FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00002929TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00002930{
2931 const uint32_t idx = ePropertyExecutableSearchPaths;
2932 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2933 assert(option_value);
2934 return option_value->GetCurrentValue();
2935}
2936
Michael Sartaina7499c92013-07-01 19:45:50 +00002937FileSpecList &
2938TargetProperties::GetDebugFileSearchPaths ()
2939{
2940 const uint32_t idx = ePropertyDebugFileSearchPaths;
2941 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2942 assert(option_value);
2943 return option_value->GetCurrentValue();
2944}
2945
Greg Clayton67cc0632012-08-22 17:17:09 +00002946bool
2947TargetProperties::GetEnableSyntheticValue () const
2948{
2949 const uint32_t idx = ePropertyEnableSynthetic;
2950 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2951}
2952
2953uint32_t
2954TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
2955{
2956 const uint32_t idx = ePropertyMaxChildrenCount;
2957 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2958}
2959
2960uint32_t
2961TargetProperties::GetMaximumSizeOfStringSummary() const
2962{
2963 const uint32_t idx = ePropertyMaxSummaryLength;
2964 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2965}
2966
Enrico Granatad325bf92013-06-04 22:54:16 +00002967uint32_t
2968TargetProperties::GetMaximumMemReadSize () const
2969{
2970 const uint32_t idx = ePropertyMaxMemReadSize;
2971 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2972}
2973
Greg Clayton67cc0632012-08-22 17:17:09 +00002974FileSpec
2975TargetProperties::GetStandardInputPath () const
2976{
2977 const uint32_t idx = ePropertyInputPath;
2978 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2979}
2980
2981void
2982TargetProperties::SetStandardInputPath (const char *p)
2983{
2984 const uint32_t idx = ePropertyInputPath;
2985 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2986}
2987
2988FileSpec
2989TargetProperties::GetStandardOutputPath () const
2990{
2991 const uint32_t idx = ePropertyOutputPath;
2992 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2993}
2994
2995void
2996TargetProperties::SetStandardOutputPath (const char *p)
2997{
2998 const uint32_t idx = ePropertyOutputPath;
2999 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3000}
3001
3002FileSpec
3003TargetProperties::GetStandardErrorPath () const
3004{
3005 const uint32_t idx = ePropertyErrorPath;
3006 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
3007}
3008
Greg Clayton6920b522012-08-22 18:39:03 +00003009const char *
3010TargetProperties::GetExpressionPrefixContentsAsCString ()
3011{
3012 const uint32_t idx = ePropertyExprPrefix;
3013 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3014 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003015 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003016 const bool null_terminate = true;
3017 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003018 if (data_sp)
3019 return (const char *) data_sp->GetBytes();
3020 }
Greg Clayton6920b522012-08-22 18:39:03 +00003021 return NULL;
3022}
3023
Greg Clayton67cc0632012-08-22 17:17:09 +00003024void
3025TargetProperties::SetStandardErrorPath (const char *p)
3026{
3027 const uint32_t idx = ePropertyErrorPath;
3028 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3029}
3030
3031bool
3032TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3033{
3034 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3035 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3036}
3037
Jim Ingham17d023f2013-03-13 17:58:04 +00003038bool
Daniel Malead79ae052013-08-07 21:54:09 +00003039TargetProperties::GetUseHexImmediates () const
3040{
3041 const uint32_t idx = ePropertyUseHexImmediates;
3042 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3043}
3044
3045bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003046TargetProperties::GetUseFastStepping () const
3047{
3048 const uint32_t idx = ePropertyUseFastStepping;
3049 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3050}
3051
Greg Claytonfb6621e2013-12-06 21:59:52 +00003052bool
3053TargetProperties::GetDisplayExpressionsInCrashlogs () const
3054{
3055 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3056 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3057}
3058
Enrico Granata397ddd52013-05-21 20:13:34 +00003059LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003060TargetProperties::GetLoadScriptFromSymbolFile () const
3061{
3062 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Enrico Granata397ddd52013-05-21 20:13:34 +00003063 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003064}
3065
Daniel Malead79ae052013-08-07 21:54:09 +00003066Disassembler::HexImmediateStyle
3067TargetProperties::GetHexImmediateStyle () const
3068{
3069 const uint32_t idx = ePropertyHexImmediateStyle;
3070 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3071}
3072
Greg Claytonfd814c52013-08-13 01:42:25 +00003073MemoryModuleLoadLevel
3074TargetProperties::GetMemoryModuleLoadLevel() const
3075{
3076 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3077 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3078}
3079
3080
Greg Clayton67cc0632012-08-22 17:17:09 +00003081
Greg Claytonfbb76342013-11-20 21:07:01 +00003082//----------------------------------------------------------------------
3083// Target::TargetEventData
3084//----------------------------------------------------------------------
Jim Ingham4bddaeb2012-02-16 06:50:00 +00003085const ConstString &
3086Target::TargetEventData::GetFlavorString ()
3087{
3088 static ConstString g_flavor ("Target::TargetEventData");
3089 return g_flavor;
3090}
3091
3092const ConstString &
3093Target::TargetEventData::GetFlavor () const
3094{
3095 return TargetEventData::GetFlavorString ();
3096}
3097
3098Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
3099 EventData(),
3100 m_target_sp (new_target_sp)
3101{
3102}
3103
3104Target::TargetEventData::~TargetEventData()
3105{
3106
3107}
3108
3109void
3110Target::TargetEventData::Dump (Stream *s) const
3111{
3112
3113}
3114
3115const TargetSP
3116Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
3117{
3118 TargetSP target_sp;
3119
3120 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
3121 if (data)
3122 target_sp = data->m_target_sp;
3123
3124 return target_sp;
3125}
3126
3127const Target::TargetEventData *
3128Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3129{
3130 if (event_ptr)
3131 {
3132 const EventData *event_data = event_ptr->GetData();
3133 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3134 return static_cast <const TargetEventData *> (event_ptr->GetData());
3135 }
3136 return NULL;
3137}
3138