blob: a34d53e88f8da904f9abca6e2ed397a032c5b9f6 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000033#include "lldb/Core/Timer.h"
34#include "lldb/Core/ValueObject.h"
Sean Callanan4bf80d52011-11-15 22:27:19 +000035#include "lldb/Expression/ClangASTSource.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000036#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:59 +000038#include "lldb/Interpreter/CommandInterpreter.h"
39#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chenb90827e2012-06-04 23:19:54 +000040#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000041#include "lldb/Interpreter/OptionValues.h"
42#include "lldb/Interpreter/Property.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/lldb-private-log.h"
44#include "lldb/Symbol/ObjectFile.h"
45#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000046#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000047#include "lldb/Target/StackFrame.h"
Jason Molendaeef51062013-11-05 03:57:19 +000048#include "lldb/Target/SystemRuntime.h"
Jim Ingham9575d842011-03-11 03:53:59 +000049#include "lldb/Target/Thread.h"
50#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
Jim Ingham4bddaeb2012-02-16 06:50:00 +000055ConstString &
56Target::GetStaticBroadcasterClass ()
57{
58 static ConstString class_name ("lldb.target");
59 return class_name;
60}
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062//----------------------------------------------------------------------
63// Target constructor
64//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:51 +000065Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Greg Clayton67cc0632012-08-22 17:17:09 +000066 TargetProperties (this),
Jim Ingham4f465cf2012-10-10 18:32:14 +000067 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton32e0a752011-03-30 18:16:51 +000068 ExecutionContextScope (),
Greg Clayton66111032010-06-23 01:19:29 +000069 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:51 +000070 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:23 +000071 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +000072 m_arch (target_arch),
Enrico Granata17598482012-11-08 02:22:02 +000073 m_images (this),
Greg Claytond5944cd2013-12-06 01:12:00 +000074 m_section_load_history (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 m_breakpoint_list (false),
76 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:25 +000077 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:51 +000078 m_process_sp (),
79 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Claytone01e07b2013-04-18 18:10:51 +000081 m_scratch_ast_context_ap (),
82 m_scratch_ast_source_ap (),
83 m_ast_importer_ap (),
Jim Ingham9575d842011-03-11 03:53:59 +000084 m_persistent_variables (),
Greg Clayton9585fbf2013-03-19 00:20:55 +000085 m_source_manager_ap(),
Greg Clayton32e0a752011-03-30 18:16:51 +000086 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:14 +000087 m_stop_hook_next_id (0),
Greg Claytond5944cd2013-12-06 01:12:00 +000088 m_valid (true),
Enrico Granata5d5f60c2013-09-24 22:58:37 +000089 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090{
Greg Claytoncfd1ace2010-10-31 03:01:06 +000091 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
92 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
93 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham1b5792e2012-12-18 02:03:49 +000094 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Enrico Granataf15ee4e2013-04-05 18:49:06 +000095 SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
Jim Ingham4bddaeb2012-02-16 06:50:00 +000096
97 CheckInWithManager();
Greg Claytoncfd1ace2010-10-31 03:01:06 +000098
Greg Clayton5160ce52013-03-27 23:08:40 +000099 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100 if (log)
101 log->Printf ("%p Target::Target()", this);
Jason Molendae1b68ad2012-12-05 00:25:49 +0000102 if (m_arch.IsValid())
103 {
Jason Molendaa3f24b32012-12-12 02:23:56 +0000104 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 +0000105 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106}
107
108//----------------------------------------------------------------------
109// Destructor
110//----------------------------------------------------------------------
111Target::~Target()
112{
Greg Clayton5160ce52013-03-27 23:08:40 +0000113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114 if (log)
115 log->Printf ("%p Target::~Target()", this);
116 DeleteCurrentProcess ();
117}
118
119void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121{
Greg Clayton89411422010-10-08 00:21:05 +0000122// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000123 if (description_level != lldb::eDescriptionLevelBrief)
124 {
125 s->Indent();
126 s->PutCString("Target\n");
127 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35 +0000128 m_images.Dump(s);
129 m_breakpoint_list.Dump(s);
130 m_internal_breakpoint_list.Dump(s);
131 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000132 }
133 else
134 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000135 Module *exe_module = GetExecutableModulePointer();
136 if (exe_module)
137 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28 +0000138 else
139 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000140 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141}
142
143void
Greg Clayton90ba8112012-12-05 00:16:59 +0000144Target::CleanupProcess ()
145{
146 // Do any cleanup of the target we need to do between process instances.
147 // NB It is better to do this before destroying the process in case the
148 // clean up needs some help from the process.
149 m_breakpoint_list.ClearAllBreakpointSites();
150 m_internal_breakpoint_list.ClearAllBreakpointSites();
151 // Disable watchpoints just on the debugger side.
152 Mutex::Locker locker;
153 this->GetWatchpointList().GetListMutex(locker);
154 DisableAllWatchpoints(false);
155 ClearAllWatchpointHitCounts();
156}
157
158void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159Target::DeleteCurrentProcess ()
160{
161 if (m_process_sp.get())
162 {
Greg Claytond5944cd2013-12-06 01:12:00 +0000163 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164 if (m_process_sp->IsAlive())
165 m_process_sp->Destroy();
Jim Inghamd0a3e122011-02-16 17:54:55 +0000166
167 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168
Greg Clayton90ba8112012-12-05 00:16:59 +0000169 CleanupProcess ();
170
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171 m_process_sp.reset();
172 }
173}
174
175const lldb::ProcessSP &
Greg Claytonc3776bf2012-02-09 06:16:32 +0000176Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177{
178 DeleteCurrentProcess ();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000179 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180 return m_process_sp;
181}
182
183const lldb::ProcessSP &
184Target::GetProcessSP () const
185{
186 return m_process_sp;
187}
188
Greg Clayton3418c852011-08-10 02:10:13 +0000189void
190Target::Destroy()
191{
192 Mutex::Locker locker (m_mutex);
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000193 m_valid = false;
Greg Clayton3418c852011-08-10 02:10:13 +0000194 DeleteCurrentProcess ();
195 m_platform_sp.reset();
196 m_arch.Clear();
Greg Claytonb35db632013-11-09 00:03:31 +0000197 ClearModules(true);
Greg Claytond5944cd2013-12-06 01:12:00 +0000198 m_section_load_history.Clear();
Greg Clayton3418c852011-08-10 02:10:13 +0000199 const bool notify = false;
200 m_breakpoint_list.RemoveAll(notify);
201 m_internal_breakpoint_list.RemoveAll(notify);
202 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25 +0000203 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13 +0000204 m_search_filter_sp.reset();
205 m_image_search_paths.Clear(notify);
Greg Clayton3418c852011-08-10 02:10:13 +0000206 m_persistent_variables.Clear();
207 m_stop_hooks.clear();
208 m_stop_hook_next_id = 0;
209 m_suppress_stop_hooks = false;
210}
211
212
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213BreakpointList &
214Target::GetBreakpointList(bool internal)
215{
216 if (internal)
217 return m_internal_breakpoint_list;
218 else
219 return m_breakpoint_list;
220}
221
222const BreakpointList &
223Target::GetBreakpointList(bool internal) const
224{
225 if (internal)
226 return m_internal_breakpoint_list;
227 else
228 return m_breakpoint_list;
229}
230
231BreakpointSP
232Target::GetBreakpointByID (break_id_t break_id)
233{
234 BreakpointSP bp_sp;
235
236 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
237 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
238 else
239 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
240
241 return bp_sp;
242}
243
244BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000245Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton1f746072012-08-29 21:13:06 +0000246 const FileSpecList *source_file_spec_list,
247 RegularExpression &source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000248 bool internal,
249 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250{
Jim Ingham87df91b2011-09-23 00:54:11 +0000251 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
252 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000253 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham969795f2011-09-21 01:17:13 +0000254}
255
256
257BreakpointSP
Jim Inghama8558b62012-05-22 00:12:20 +0000258Target::CreateBreakpoint (const FileSpecList *containingModules,
259 const FileSpec &file,
260 uint32_t line_no,
Greg Clayton1f746072012-08-29 21:13:06 +0000261 LazyBool check_inlines,
Jim Inghama8558b62012-05-22 00:12:20 +0000262 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000263 bool internal,
264 bool hardware)
Jim Ingham969795f2011-09-21 01:17:13 +0000265{
Greg Clayton1f746072012-08-29 21:13:06 +0000266 if (check_inlines == eLazyBoolCalculate)
267 {
268 const InlineStrategy inline_strategy = GetInlineStrategy();
269 switch (inline_strategy)
270 {
271 case eInlineBreakpointsNever:
272 check_inlines = eLazyBoolNo;
273 break;
274
275 case eInlineBreakpointsHeaders:
276 if (file.IsSourceImplementationFile())
277 check_inlines = eLazyBoolNo;
278 else
279 check_inlines = eLazyBoolYes;
280 break;
281
282 case eInlineBreakpointsAlways:
283 check_inlines = eLazyBoolYes;
284 break;
285 }
286 }
Greg Clayton93bfb292012-09-07 23:48:57 +0000287 SearchFilterSP filter_sp;
288 if (check_inlines == eLazyBoolNo)
289 {
290 // Not checking for inlines, we are looking only for matching compile units
291 FileSpecList compile_unit_list;
292 compile_unit_list.Append (file);
293 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
294 }
295 else
296 {
297 filter_sp = GetSearchFilterForModuleList (containingModules);
298 }
Greg Clayton03da4cc2013-04-19 21:31:16 +0000299 if (skip_prologue == eLazyBoolCalculate)
300 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
301
Greg Clayton1f746072012-08-29 21:13:06 +0000302 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
303 file,
304 line_no,
305 check_inlines,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000306 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000307 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308}
309
310
311BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000312Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314 Address so_addr;
315 // Attempt to resolve our load address if possible, though it is ok if
316 // it doesn't resolve to section/offset.
317
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000318 // Try and resolve as a load address if possible
Greg Claytond5944cd2013-12-06 01:12:00 +0000319 GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000320 if (!so_addr.IsValid())
321 {
322 // The address didn't resolve, so just set this as an absolute address
323 so_addr.SetOffset (addr);
324 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000325 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326 return bp_sp;
327}
328
329BreakpointSP
Greg Claytoneb023e72013-10-11 19:48:25 +0000330Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331{
Greg Claytone1cd1be2012-01-29 20:56:30 +0000332 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000334 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335}
336
337BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000338Target::CreateBreakpoint (const FileSpecList *containingModules,
339 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17 +0000340 const char *func_name,
341 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000342 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000343 bool internal,
344 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000345{
Greg Clayton0c5cd902010-06-28 21:30:43 +0000346 BreakpointSP bp_sp;
347 if (func_name)
348 {
Jim Ingham87df91b2011-09-23 00:54:11 +0000349 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000350
351 if (skip_prologue == eLazyBoolCalculate)
352 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
353
Greg Claytond16e1e52011-07-12 17:06:17 +0000354 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
355 func_name,
356 func_name_type_mask,
357 Breakpoint::Exact,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000358 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000359 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000360 }
361 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
Jim Inghamfab10e82012-03-06 00:37:27 +0000364lldb::BreakpointSP
365Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Clayton4116e932012-05-15 02:33:01 +0000366 const FileSpecList *containingSourceFiles,
367 const std::vector<std::string> &func_names,
368 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000369 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000370 bool internal,
371 bool hardware)
Jim Inghamfab10e82012-03-06 00:37:27 +0000372{
373 BreakpointSP bp_sp;
374 size_t num_names = func_names.size();
375 if (num_names > 0)
376 {
377 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton03da4cc2013-04-19 21:31:16 +0000378
379 if (skip_prologue == eLazyBoolCalculate)
380 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
381
382 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Inghamfab10e82012-03-06 00:37:27 +0000383 func_names,
384 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000385 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000386 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Inghamfab10e82012-03-06 00:37:27 +0000387 }
388 return bp_sp;
389}
390
Jim Ingham133e0fb2012-03-03 02:05:11 +0000391BreakpointSP
392Target::CreateBreakpoint (const FileSpecList *containingModules,
393 const FileSpecList *containingSourceFiles,
394 const char *func_names[],
395 size_t num_names,
396 uint32_t func_name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000397 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000398 bool internal,
399 bool hardware)
Jim Ingham133e0fb2012-03-03 02:05:11 +0000400{
401 BreakpointSP bp_sp;
402 if (num_names > 0)
403 {
404 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
405
Greg Clayton03da4cc2013-04-19 21:31:16 +0000406 if (skip_prologue == eLazyBoolCalculate)
407 skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
408
409 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
Jim Ingham133e0fb2012-03-03 02:05:11 +0000410 func_names,
411 num_names,
Jim Inghamfab10e82012-03-06 00:37:27 +0000412 func_name_type_mask,
Greg Clayton03da4cc2013-04-19 21:31:16 +0000413 skip_prologue));
Jim Ingham1460e4b2014-01-10 23:46:59 +0000414 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Jim Ingham133e0fb2012-03-03 02:05:11 +0000415 }
416 return bp_sp;
417}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418
419SearchFilterSP
420Target::GetSearchFilterForModule (const FileSpec *containingModule)
421{
422 SearchFilterSP filter_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 if (containingModule != NULL)
424 {
425 // TODO: We should look into sharing module based search filters
426 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000427 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 }
429 else
430 {
431 if (m_search_filter_sp.get() == NULL)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000432 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 filter_sp = m_search_filter_sp;
434 }
435 return filter_sp;
436}
437
Jim Ingham969795f2011-09-21 01:17:13 +0000438SearchFilterSP
439Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
440{
441 SearchFilterSP filter_sp;
Jim Ingham969795f2011-09-21 01:17:13 +0000442 if (containingModules && containingModules->GetSize() != 0)
443 {
444 // TODO: We should look into sharing module based search filters
445 // across many breakpoints like we do for the simple target based one
Greg Claytone1cd1be2012-01-29 20:56:30 +0000446 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham969795f2011-09-21 01:17:13 +0000447 }
448 else
449 {
450 if (m_search_filter_sp.get() == NULL)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000451 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham969795f2011-09-21 01:17:13 +0000452 filter_sp = m_search_filter_sp;
453 }
454 return filter_sp;
455}
456
Jim Ingham87df91b2011-09-23 00:54:11 +0000457SearchFilterSP
Jim Inghama8558b62012-05-22 00:12:20 +0000458Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
459 const FileSpecList *containingSourceFiles)
Jim Ingham87df91b2011-09-23 00:54:11 +0000460{
461 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
462 return GetSearchFilterForModuleList(containingModules);
463
464 SearchFilterSP filter_sp;
Jim Ingham87df91b2011-09-23 00:54:11 +0000465 if (containingModules == NULL)
466 {
467 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
468 // but that will take a little reworking.
469
Greg Claytone1cd1be2012-01-29 20:56:30 +0000470 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000471 }
472 else
473 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000474 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Ingham87df91b2011-09-23 00:54:11 +0000475 }
476 return filter_sp;
477}
478
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11 +0000480Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Inghama8558b62012-05-22 00:12:20 +0000481 const FileSpecList *containingSourceFiles,
482 RegularExpression &func_regex,
483 LazyBool skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000484 bool internal,
485 bool hardware)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486{
Jim Ingham87df91b2011-09-23 00:54:11 +0000487 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Claytond16e1e52011-07-12 17:06:17 +0000488 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
489 func_regex,
490 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491
Jim Ingham1460e4b2014-01-10 23:46:59 +0000492 return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
Jim Ingham219ba192012-03-05 04:47:34 +0000495lldb::BreakpointSP
496Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
497{
498 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
499}
500
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501BreakpointSP
Jim Ingham1460e4b2014-01-10 23:46:59 +0000502Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503{
504 BreakpointSP bp_sp;
505 if (filter_sp && resolver_sp)
506 {
Jim Ingham1460e4b2014-01-10 23:46:59 +0000507 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 resolver_sp->SetBreakpoint (bp_sp.get());
509
510 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000511 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 else
Greg Clayton9fed0d82010-07-23 23:33:17 +0000513 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514
Greg Clayton5160ce52013-03-27 23:08:40 +0000515 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 if (log)
517 {
518 StreamString s;
519 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
520 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
521 }
522
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 bp_sp->ResolveBreakpoint();
524 }
Jim Ingham36f3b362010-10-14 23:45:03 +0000525
526 if (!internal && bp_sp)
527 {
528 m_last_created_breakpoint = bp_sp;
529 }
530
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 return bp_sp;
532}
533
Johnny Chen86364b42011-09-20 23:28:55 +0000534bool
535Target::ProcessIsValid()
536{
537 return (m_process_sp && m_process_sp->IsAlive());
538}
539
Johnny Chenb90827e2012-06-04 23:19:54 +0000540static bool
541CheckIfWatchpointsExhausted(Target *target, Error &error)
542{
543 uint32_t num_supported_hardware_watchpoints;
544 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
545 if (rc.Success())
546 {
547 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
548 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
549 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
550 num_supported_hardware_watchpoints);
551 }
552 return false;
553}
554
Johnny Chen01a67862011-10-14 00:42:25 +0000555// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03 +0000556// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25 +0000557WatchpointSP
Jim Inghama7dfb662012-10-23 07:20:06 +0000558Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
Johnny Chen887062a2011-09-12 23:38:44 +0000559{
Greg Clayton5160ce52013-03-27 23:08:40 +0000560 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen0c406372011-09-14 20:23:45 +0000561 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000562 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Inghama7dfb662012-10-23 07:20:06 +0000563 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen0c406372011-09-14 20:23:45 +0000564
Johnny Chen01a67862011-10-14 00:42:25 +0000565 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55 +0000566 if (!ProcessIsValid())
Johnny Chenb90827e2012-06-04 23:19:54 +0000567 {
568 error.SetErrorString("process is not alive");
Johnny Chen01a67862011-10-14 00:42:25 +0000569 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000570 }
Jim Inghamc6462312013-06-18 21:52:48 +0000571
Johnny Chen45e541f2011-09-14 22:20:15 +0000572 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenb90827e2012-06-04 23:19:54 +0000573 {
574 if (size == 0)
575 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
576 else
Daniel Malead01b2952012-11-29 21:49:15 +0000577 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chen01a67862011-10-14 00:42:25 +0000578 return wp_sp;
Johnny Chenb90827e2012-06-04 23:19:54 +0000579 }
Jim Inghamc6462312013-06-18 21:52:48 +0000580
581 if (!LLDB_WATCH_TYPE_IS_VALID(kind))
582 {
583 error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
584 }
Johnny Chen7313a642011-09-13 01:15:36 +0000585
Johnny Chen01a67862011-10-14 00:42:25 +0000586 // Currently we only support one watchpoint per address, with total number
587 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chen7385a5a2012-05-31 22:56:36 +0000588
589 // Grab the list mutex while doing operations.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000590 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 +0000591 Mutex::Locker locker;
592 this->GetWatchpointList().GetListMutex(locker);
Johnny Chen01a67862011-10-14 00:42:25 +0000593 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31 +0000594 if (matched_sp)
595 {
Johnny Chen0c406372011-09-14 20:23:45 +0000596 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31 +0000597 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45 +0000598 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
599 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25 +0000600 // Return the existing watchpoint if both size and type match.
Jim Inghamc6462312013-06-18 21:52:48 +0000601 if (size == old_size && kind == old_type)
602 {
Johnny Chen01a67862011-10-14 00:42:25 +0000603 wp_sp = matched_sp;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000604 wp_sp->SetEnabled(false, notify);
Jim Inghamc6462312013-06-18 21:52:48 +0000605 }
606 else
607 {
Johnny Chen01a67862011-10-14 00:42:25 +0000608 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000609 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
610 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000611 }
Johnny Chen3c532582011-09-13 23:29:31 +0000612 }
613
Jason Molenda727e3922012-12-05 23:07:34 +0000614 if (!wp_sp)
615 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000616 wp_sp.reset(new Watchpoint(*this, addr, size, type));
617 wp_sp->SetWatchpointType(kind, notify);
618 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen45e541f2011-09-14 22:20:15 +0000619 }
Johnny Chen0c406372011-09-14 20:23:45 +0000620
Jim Ingham1b5792e2012-12-18 02:03:49 +0000621 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen0c406372011-09-14 20:23:45 +0000622 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +0000623 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
624 __FUNCTION__,
625 error.Success() ? "succeeded" : "failed",
626 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45 +0000627
Jason Molenda727e3922012-12-05 23:07:34 +0000628 if (error.Fail())
629 {
Johnny Chen41b77262012-03-26 22:00:10 +0000630 // Enabling the watchpoint on the device side failed.
631 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham1b5792e2012-12-18 02:03:49 +0000632 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chenb90827e2012-06-04 23:19:54 +0000633 // See if we could provide more helpful error message.
634 if (!CheckIfWatchpointsExhausted(this, error))
635 {
636 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
Sylvestre Ledru779f9212013-10-31 23:55:19 +0000637 error.SetErrorStringWithFormat("watch size of %zu is not supported", size);
Johnny Chenb90827e2012-06-04 23:19:54 +0000638 }
Johnny Chen01a67862011-10-14 00:42:25 +0000639 wp_sp.reset();
Johnny Chen41b77262012-03-26 22:00:10 +0000640 }
Johnny Chen9d954d82011-09-27 20:29:45 +0000641 else
Johnny Chen01a67862011-10-14 00:42:25 +0000642 m_last_created_watchpoint = wp_sp;
643 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44 +0000644}
645
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646void
647Target::RemoveAllBreakpoints (bool internal_also)
648{
Greg Clayton5160ce52013-03-27 23:08:40 +0000649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650 if (log)
651 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
652
Greg Clayton9fed0d82010-07-23 23:33:17 +0000653 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17 +0000655 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03 +0000656
657 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658}
659
660void
661Target::DisableAllBreakpoints (bool internal_also)
662{
Greg Clayton5160ce52013-03-27 23:08:40 +0000663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 if (log)
665 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
666
667 m_breakpoint_list.SetEnabledAll (false);
668 if (internal_also)
669 m_internal_breakpoint_list.SetEnabledAll (false);
670}
671
672void
673Target::EnableAllBreakpoints (bool internal_also)
674{
Greg Clayton5160ce52013-03-27 23:08:40 +0000675 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676 if (log)
677 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
678
679 m_breakpoint_list.SetEnabledAll (true);
680 if (internal_also)
681 m_internal_breakpoint_list.SetEnabledAll (true);
682}
683
684bool
685Target::RemoveBreakpointByID (break_id_t break_id)
686{
Greg Clayton5160ce52013-03-27 23:08:40 +0000687 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688 if (log)
689 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
690
691 if (DisableBreakpointByID (break_id))
692 {
693 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17 +0000694 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 else
Jim Ingham36f3b362010-10-14 23:45:03 +0000696 {
Greg Claytonaa1c5872011-01-24 23:35:47 +0000697 if (m_last_created_breakpoint)
698 {
699 if (m_last_created_breakpoint->GetID() == break_id)
700 m_last_created_breakpoint.reset();
701 }
Greg Clayton9fed0d82010-07-23 23:33:17 +0000702 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03 +0000703 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 return true;
705 }
706 return false;
707}
708
709bool
710Target::DisableBreakpointByID (break_id_t break_id)
711{
Greg Clayton5160ce52013-03-27 23:08:40 +0000712 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 if (log)
714 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
715
716 BreakpointSP bp_sp;
717
718 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
719 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
720 else
721 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
722 if (bp_sp)
723 {
724 bp_sp->SetEnabled (false);
725 return true;
726 }
727 return false;
728}
729
730bool
731Target::EnableBreakpointByID (break_id_t break_id)
732{
Greg Clayton5160ce52013-03-27 23:08:40 +0000733 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734 if (log)
735 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
736 __FUNCTION__,
737 break_id,
738 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
739
740 BreakpointSP bp_sp;
741
742 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
743 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
744 else
745 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
746
747 if (bp_sp)
748 {
749 bp_sp->SetEnabled (true);
750 return true;
751 }
752 return false;
753}
754
Johnny Chenedf50372011-09-23 21:21:43 +0000755// The flag 'end_to_end', default to true, signifies that the operation is
756// performed end to end, for both the debugger and the debuggee.
757
Johnny Chen01a67862011-10-14 00:42:25 +0000758// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
759// to end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000760bool
Johnny Chen01a67862011-10-14 00:42:25 +0000761Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000762{
Greg Clayton5160ce52013-03-27 23:08:40 +0000763 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000764 if (log)
765 log->Printf ("Target::%s\n", __FUNCTION__);
766
Johnny Chenedf50372011-09-23 21:21:43 +0000767 if (!end_to_end) {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000768 m_watchpoint_list.RemoveAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000769 return true;
770 }
771
772 // Otherwise, it's an end to end operation.
773
Johnny Chen86364b42011-09-20 23:28:55 +0000774 if (!ProcessIsValid())
775 return false;
776
Johnny Chen01a67862011-10-14 00:42:25 +0000777 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000778 for (size_t i = 0; i < num_watchpoints; ++i)
779 {
Johnny Chen01a67862011-10-14 00:42:25 +0000780 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
781 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000782 return false;
783
Johnny Chen01a67862011-10-14 00:42:25 +0000784 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000785 if (rc.Fail())
786 return false;
787 }
Jim Ingham1b5792e2012-12-18 02:03:49 +0000788 m_watchpoint_list.RemoveAll (true);
Jim Inghamb0b45132013-07-02 02:09:46 +0000789 m_last_created_watchpoint.reset();
Johnny Chen86364b42011-09-20 23:28:55 +0000790 return true; // Success!
791}
792
Johnny Chen01a67862011-10-14 00:42:25 +0000793// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
794// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000795bool
Johnny Chen01a67862011-10-14 00:42:25 +0000796Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000797{
Greg Clayton5160ce52013-03-27 23:08:40 +0000798 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000799 if (log)
800 log->Printf ("Target::%s\n", __FUNCTION__);
801
Johnny Chenedf50372011-09-23 21:21:43 +0000802 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000803 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43 +0000804 return true;
805 }
806
807 // Otherwise, it's an end to end operation.
808
Johnny Chen86364b42011-09-20 23:28:55 +0000809 if (!ProcessIsValid())
810 return false;
811
Johnny Chen01a67862011-10-14 00:42:25 +0000812 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000813 for (size_t i = 0; i < num_watchpoints; ++i)
814 {
Johnny Chen01a67862011-10-14 00:42:25 +0000815 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
816 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000817 return false;
818
Johnny Chen01a67862011-10-14 00:42:25 +0000819 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000820 if (rc.Fail())
821 return false;
822 }
Johnny Chen86364b42011-09-20 23:28:55 +0000823 return true; // Success!
824}
825
Johnny Chen01a67862011-10-14 00:42:25 +0000826// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
827// end operations.
Johnny Chen86364b42011-09-20 23:28:55 +0000828bool
Johnny Chen01a67862011-10-14 00:42:25 +0000829Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55 +0000830{
Greg Clayton5160ce52013-03-27 23:08:40 +0000831 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000832 if (log)
833 log->Printf ("Target::%s\n", __FUNCTION__);
834
Johnny Chenedf50372011-09-23 21:21:43 +0000835 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25 +0000836 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43 +0000837 return true;
838 }
839
840 // Otherwise, it's an end to end operation.
841
Johnny Chen86364b42011-09-20 23:28:55 +0000842 if (!ProcessIsValid())
843 return false;
844
Johnny Chen01a67862011-10-14 00:42:25 +0000845 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55 +0000846 for (size_t i = 0; i < num_watchpoints; ++i)
847 {
Johnny Chen01a67862011-10-14 00:42:25 +0000848 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
849 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000850 return false;
851
Johnny Chen01a67862011-10-14 00:42:25 +0000852 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55 +0000853 if (rc.Fail())
854 return false;
855 }
Johnny Chen86364b42011-09-20 23:28:55 +0000856 return true; // Success!
857}
858
Johnny Chena4d6bc92012-02-25 06:44:30 +0000859// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
860bool
861Target::ClearAllWatchpointHitCounts ()
862{
Greg Clayton5160ce52013-03-27 23:08:40 +0000863 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chena4d6bc92012-02-25 06:44:30 +0000864 if (log)
865 log->Printf ("Target::%s\n", __FUNCTION__);
866
867 size_t num_watchpoints = m_watchpoint_list.GetSize();
868 for (size_t i = 0; i < num_watchpoints; ++i)
869 {
870 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
871 if (!wp_sp)
872 return false;
873
874 wp_sp->ResetHitCount();
875 }
876 return true; // Success!
877}
878
Johnny Chen01a67862011-10-14 00:42:25 +0000879// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46 +0000880// during these operations.
881bool
Johnny Chen01a67862011-10-14 00:42:25 +0000882Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000883{
Greg Clayton5160ce52013-03-27 23:08:40 +0000884 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000885 if (log)
886 log->Printf ("Target::%s\n", __FUNCTION__);
887
888 if (!ProcessIsValid())
889 return false;
890
Johnny Chen01a67862011-10-14 00:42:25 +0000891 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46 +0000892 for (size_t i = 0; i < num_watchpoints; ++i)
893 {
Johnny Chen01a67862011-10-14 00:42:25 +0000894 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
895 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000896 return false;
897
Johnny Chen01a67862011-10-14 00:42:25 +0000898 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000899 }
900 return true; // Success!
901}
902
Johnny Chen01a67862011-10-14 00:42:25 +0000903// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000904bool
Johnny Chen01a67862011-10-14 00:42:25 +0000905Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000906{
Greg Clayton5160ce52013-03-27 23:08:40 +0000907 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000908 if (log)
909 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
910
911 if (!ProcessIsValid())
912 return false;
913
Johnny Chen01a67862011-10-14 00:42:25 +0000914 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
915 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000916 {
Johnny Chen01a67862011-10-14 00:42:25 +0000917 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000918 if (rc.Success())
919 return true;
Johnny Chen86364b42011-09-20 23:28:55 +0000920
Johnny Chenf04ee932011-09-22 18:04:58 +0000921 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +0000922 }
923 return false;
924}
925
Johnny Chen01a67862011-10-14 00:42:25 +0000926// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000927bool
Johnny Chen01a67862011-10-14 00:42:25 +0000928Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000929{
Greg Clayton5160ce52013-03-27 23:08:40 +0000930 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000931 if (log)
932 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
933
934 if (!ProcessIsValid())
935 return false;
936
Johnny Chen01a67862011-10-14 00:42:25 +0000937 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
938 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55 +0000939 {
Johnny Chen01a67862011-10-14 00:42:25 +0000940 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58 +0000941 if (rc.Success())
942 return true;
Johnny Chen86364b42011-09-20 23:28:55 +0000943
Johnny Chenf04ee932011-09-22 18:04:58 +0000944 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55 +0000945 }
946 return false;
947}
948
Johnny Chen01a67862011-10-14 00:42:25 +0000949// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55 +0000950bool
Johnny Chen01a67862011-10-14 00:42:25 +0000951Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55 +0000952{
Greg Clayton5160ce52013-03-27 23:08:40 +0000953 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen86364b42011-09-20 23:28:55 +0000954 if (log)
955 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
956
Jim Inghamb0b45132013-07-02 02:09:46 +0000957 WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
958 if (watch_to_remove_sp == m_last_created_watchpoint)
959 m_last_created_watchpoint.reset();
960
Johnny Chen01a67862011-10-14 00:42:25 +0000961 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55 +0000962 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000963 m_watchpoint_list.Remove(watch_id, true);
Johnny Chen86364b42011-09-20 23:28:55 +0000964 return true;
965 }
966 return false;
967}
968
Johnny Chen01a67862011-10-14 00:42:25 +0000969// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46 +0000970bool
Johnny Chen01a67862011-10-14 00:42:25 +0000971Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000972{
Greg Clayton5160ce52013-03-27 23:08:40 +0000973 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen6cc60e82011-10-05 21:35:46 +0000974 if (log)
975 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
976
977 if (!ProcessIsValid())
978 return false;
979
Johnny Chen01a67862011-10-14 00:42:25 +0000980 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
981 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46 +0000982 {
Johnny Chen01a67862011-10-14 00:42:25 +0000983 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46 +0000984 return true;
985 }
986 return false;
987}
988
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989ModuleSP
990Target::GetExecutableModule ()
991{
Greg Claytonaa149cb2011-08-11 02:48:45 +0000992 return m_images.GetModuleAtIndex(0);
993}
994
995Module*
996Target::GetExecutableModulePointer ()
997{
998 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999}
1000
Enrico Granata17598482012-11-08 02:22:02 +00001001static void
1002LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
1003{
1004 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00001005 StreamString feedback_stream;
1006 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
Enrico Granata17598482012-11-08 02:22:02 +00001007 {
Enrico Granata97303392013-05-21 00:00:30 +00001008 if (error.AsCString())
1009 target->GetDebugger().GetErrorStream().Printf("unable to load scripting data for module %s - error reported was %s\n",
1010 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1011 error.AsCString());
1012 if (feedback_stream.GetSize())
1013 target->GetDebugger().GetOutputStream().Printf("%s\n",
1014 feedback_stream.GetData());
Enrico Granata17598482012-11-08 02:22:02 +00001015 }
1016}
1017
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018void
Greg Claytonb35db632013-11-09 00:03:31 +00001019Target::ClearModules(bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020{
Greg Claytonb35db632013-11-09 00:03:31 +00001021 ModulesDidUnload (m_images, delete_locations);
Greg Claytond5944cd2013-12-06 01:12:00 +00001022 m_section_load_history.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 m_images.Clear();
1024 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19 +00001025 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47 +00001026 m_ast_importer_ap.reset();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001027}
1028
1029void
Greg Claytonb35db632013-11-09 00:03:31 +00001030Target::DidExec ()
1031{
1032 // When a process exec's we need to know about it so we can do some cleanup.
1033 m_breakpoint_list.RemoveInvalidLocations(m_arch);
1034 m_internal_breakpoint_list.RemoveInvalidLocations(m_arch);
1035}
1036
1037void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001038Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
1039{
1040 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb35db632013-11-09 00:03:31 +00001041 ClearModules(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042
1043 if (executable_sp.get())
1044 {
1045 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001046 "Target::SetExecutableModule (executable = '%s')",
1047 executable_sp->GetFileSpec().GetPath().c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048
1049 m_images.Append(executable_sp); // The first image is our exectuable file
1050
Jim Ingham5aee1622010-08-09 23:31:02 +00001051 // 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 +00001052 if (!m_arch.IsValid())
Jason Molendae1b68ad2012-12-05 00:25:49 +00001053 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001054 m_arch = executable_sp->GetArchitecture();
Jason Molendae1b68ad2012-12-05 00:25:49 +00001055 if (log)
1056 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1057 }
1058
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15 +00001060 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001062 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 {
1064 executable_objfile->GetDependentModules(dependent_files);
1065 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1066 {
Greg Claytonded470d2011-03-19 01:12:21 +00001067 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1068 FileSpec platform_dependent_file_spec;
1069 if (m_platform_sp)
Greg Claytond314e812011-03-23 00:09:55 +00001070 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21 +00001071 else
1072 platform_dependent_file_spec = dependent_file_spec;
1073
Greg Claytonb9a01b32012-02-26 05:51:37 +00001074 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1075 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001076 if (image_module_sp.get())
1077 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078 ObjectFile *objfile = image_module_sp->GetObjectFile();
1079 if (objfile)
1080 objfile->GetDependentModules(dependent_files);
1081 }
1082 }
1083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 }
1085}
1086
1087
Jim Ingham5aee1622010-08-09 23:31:02 +00001088bool
1089Target::SetArchitecture (const ArchSpec &arch_spec)
1090{
Greg Clayton5160ce52013-03-27 23:08:40 +00001091 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callananbf4b7be2012-12-13 22:07:14 +00001092 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +00001093 {
Greg Clayton70512312012-05-08 01:45:38 +00001094 // If we haven't got a valid arch spec, or the architectures are
1095 // compatible, so just update the architecture. Architectures can be
1096 // equal, yet the triple OS and vendor might change, so we need to do
1097 // the assignment here just in case.
Greg Clayton32e0a752011-03-30 18:16:51 +00001098 m_arch = arch_spec;
Jason Molendae1b68ad2012-12-05 00:25:49 +00001099 if (log)
1100 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 +00001101 return true;
1102 }
1103 else
1104 {
1105 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molendae1b68ad2012-12-05 00:25:49 +00001106 if (log)
Jason Molenda727e3922012-12-05 23:07:34 +00001107 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 +00001108 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02 +00001109 ModuleSP executable_sp = GetExecutableModule ();
Greg Clayton095eeaa2013-11-05 23:28:00 +00001110
Greg Claytonb35db632013-11-09 00:03:31 +00001111 ClearModules(true);
Jim Ingham5aee1622010-08-09 23:31:02 +00001112 // Need to do something about unsetting breakpoints.
1113
1114 if (executable_sp)
1115 {
Jason Molendae1b68ad2012-12-05 00:25:49 +00001116 if (log)
1117 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 +00001118 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1119 Error error = ModuleList::GetSharedModule (module_spec,
1120 executable_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001121 &GetExecutableSearchPaths(),
Greg Claytonb9a01b32012-02-26 05:51:37 +00001122 NULL,
1123 NULL);
Jim Ingham5aee1622010-08-09 23:31:02 +00001124
1125 if (!error.Fail() && executable_sp)
1126 {
1127 SetExecutableModule (executable_sp, true);
1128 return true;
1129 }
Jim Ingham5aee1622010-08-09 23:31:02 +00001130 }
1131 }
Greg Clayton70512312012-05-08 01:45:38 +00001132 return false;
Jim Ingham5aee1622010-08-09 23:31:02 +00001133}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135void
Enrico Granataefe637d2012-11-08 19:16:03 +00001136Target::WillClearList (const ModuleList& module_list)
Enrico Granata17598482012-11-08 02:22:02 +00001137{
1138}
1139
1140void
Enrico Granataefe637d2012-11-08 19:16:03 +00001141Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142{
1143 // A module is being added to this target for the first time
Enrico Granataefe637d2012-11-08 19:16:03 +00001144 ModuleList my_module_list;
1145 my_module_list.Append(module_sp);
Enrico Granata17598482012-11-08 02:22:02 +00001146 LoadScriptingResourceForModule(module_sp, this);
Enrico Granataefe637d2012-11-08 19:16:03 +00001147 ModulesDidLoad (my_module_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148}
1149
1150void
Enrico Granataefe637d2012-11-08 19:16:03 +00001151Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata17598482012-11-08 02:22:02 +00001152{
1153 // A module is being added to this target for the first time
Enrico Granataefe637d2012-11-08 19:16:03 +00001154 ModuleList my_module_list;
1155 my_module_list.Append(module_sp);
Greg Clayton095eeaa2013-11-05 23:28:00 +00001156 ModulesDidUnload (my_module_list, false);
Enrico Granata17598482012-11-08 02:22:02 +00001157}
1158
1159void
Enrico Granataefe637d2012-11-08 19:16:03 +00001160Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161{
Jim Inghame716ae02011-08-03 01:00:06 +00001162 // A module is replacing an already added module
Jim Ingham4a94c912012-05-17 18:38:42 +00001163 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164}
1165
1166void
1167Target::ModulesDidLoad (ModuleList &module_list)
1168{
Enrico Granata17598482012-11-08 02:22:02 +00001169 if (module_list.GetSize())
1170 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001171 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jason Molendaeef51062013-11-05 03:57:19 +00001172 if (m_process_sp)
1173 {
1174 SystemRuntime *sys_runtime = m_process_sp->GetSystemRuntime();
1175 if (sys_runtime)
1176 {
1177 sys_runtime->ModulesDidLoad (module_list);
1178 }
1179 }
Enrico Granata17598482012-11-08 02:22:02 +00001180 // TODO: make event data that packages up the module_list
1181 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1182 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001183}
1184
1185void
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001186Target::SymbolsDidLoad (ModuleList &module_list)
1187{
Jim Ingham31caf982013-06-04 23:01:35 +00001188 if (module_list.GetSize())
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001189 {
Jim Ingham31caf982013-06-04 23:01:35 +00001190 if (m_process_sp)
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001191 {
Jim Ingham31caf982013-06-04 23:01:35 +00001192 LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
1193 if (runtime)
1194 {
1195 ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
1196 objc_runtime->SymbolsDidLoad(module_list);
1197 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001198 }
Jim Ingham31caf982013-06-04 23:01:35 +00001199
Greg Clayton095eeaa2013-11-05 23:28:00 +00001200 m_breakpoint_list.UpdateBreakpoints (module_list, true, false);
Jim Ingham31caf982013-06-04 23:01:35 +00001201 BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL);
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001202 }
Enrico Granataf15ee4e2013-04-05 18:49:06 +00001203}
1204
1205void
Greg Clayton095eeaa2013-11-05 23:28:00 +00001206Target::ModulesDidUnload (ModuleList &module_list, bool delete_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207{
Enrico Granata17598482012-11-08 02:22:02 +00001208 if (module_list.GetSize())
1209 {
Greg Clayton095eeaa2013-11-05 23:28:00 +00001210 m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations);
Enrico Granata17598482012-11-08 02:22:02 +00001211 // TODO: make event data that packages up the module_list
1212 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214}
1215
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001216bool
Greg Claytonb9a01b32012-02-26 05:51:37 +00001217Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001218{
Greg Clayton67cc0632012-08-22 17:17:09 +00001219 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001220 {
1221 ModuleList matchingModules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00001222 ModuleSpec module_spec (module_file_spec);
1223 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001224
1225 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1226 // black list.
1227 if (num_modules > 0)
1228 {
Andy Gibbsa297a972013-06-19 19:04:53 +00001229 for (size_t i = 0; i < num_modules; i++)
Jim Inghamc6674fd2011-10-28 23:14:11 +00001230 {
1231 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1232 return false;
1233 }
1234 return true;
1235 }
Jim Inghamc6674fd2011-10-28 23:14:11 +00001236 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001237 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001238}
1239
Daniel Dunbarf9f70322011-10-31 22:50:37 +00001240bool
Jim Inghamc6674fd2011-10-28 23:14:11 +00001241Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1242{
Greg Clayton67cc0632012-08-22 17:17:09 +00001243 if (GetBreakpointsConsultPlatformAvoidList())
Jim Inghamc6674fd2011-10-28 23:14:11 +00001244 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001245 if (m_platform_sp)
1246 return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
Jim Inghamc6674fd2011-10-28 23:14:11 +00001247 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001248 return false;
Jim Inghamc6674fd2011-10-28 23:14:11 +00001249}
1250
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251size_t
Greg Claytondb598232011-01-07 01:57:07 +00001252Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1253{
Greg Claytone72dfb32012-02-24 01:59:29 +00001254 SectionSP section_sp (addr.GetSection());
1255 if (section_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001256 {
Jason Molenda216d91f2012-04-25 00:06:56 +00001257 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1258 if (section_sp->IsEncrypted())
1259 {
Greg Clayton57f06302012-05-25 17:05:55 +00001260 error.SetErrorString("section is encrypted");
Jason Molenda216d91f2012-04-25 00:06:56 +00001261 return 0;
1262 }
Greg Claytone72dfb32012-02-24 01:59:29 +00001263 ModuleSP module_sp (section_sp->GetModule());
1264 if (module_sp)
Greg Claytondb598232011-01-07 01:57:07 +00001265 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001266 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1267 if (objfile)
1268 {
1269 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1270 addr.GetOffset(),
1271 dst,
1272 dst_len);
1273 if (bytes_read > 0)
1274 return bytes_read;
1275 else
1276 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1277 }
Greg Claytondb598232011-01-07 01:57:07 +00001278 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001279 error.SetErrorString("address isn't from a object file");
Greg Claytondb598232011-01-07 01:57:07 +00001280 }
1281 else
Greg Claytone72dfb32012-02-24 01:59:29 +00001282 error.SetErrorString("address isn't in a module");
Greg Claytondb598232011-01-07 01:57:07 +00001283 }
1284 else
Greg Claytondb598232011-01-07 01:57:07 +00001285 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Claytone72dfb32012-02-24 01:59:29 +00001286
Greg Claytondb598232011-01-07 01:57:07 +00001287 return 0;
1288}
1289
1290size_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001291Target::ReadMemory (const Address& addr,
1292 bool prefer_file_cache,
1293 void *dst,
1294 size_t dst_len,
1295 Error &error,
1296 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 error.Clear();
Greg Claytondb598232011-01-07 01:57:07 +00001299
Enrico Granata9128ee22011-09-06 19:20:51 +00001300 // if we end up reading this from process memory, we will fill this
1301 // with the actual load address
1302 if (load_addr_ptr)
1303 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1304
Greg Claytondb598232011-01-07 01:57:07 +00001305 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001306
1307 addr_t load_addr = LLDB_INVALID_ADDRESS;
1308 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58 +00001309 Address resolved_addr;
1310 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001311 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001312 SectionLoadList &section_load_list = GetSectionLoadList();
1313 if (section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02 +00001314 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001315 // No sections are loaded, so we must assume we are not running
1316 // yet and anything we are given is a file address.
1317 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1318 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001319 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001320 else
Greg Claytonc749eb82011-07-11 05:12:02 +00001321 {
Greg Claytond16e1e52011-07-12 17:06:17 +00001322 // We have at least one section loaded. This can be becuase
1323 // we have manually loaded some sections with "target modules load ..."
1324 // or because we have have a live process that has sections loaded
1325 // through the dynamic loader
1326 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
Greg Claytond5944cd2013-12-06 01:12:00 +00001327 section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02 +00001328 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001329 }
Greg Clayton357132e2011-03-26 19:14:58 +00001330 if (!resolved_addr.IsValid())
1331 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001332
Greg Claytonc749eb82011-07-11 05:12:02 +00001333
Greg Claytondb598232011-01-07 01:57:07 +00001334 if (prefer_file_cache)
1335 {
1336 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1337 if (bytes_read > 0)
1338 return bytes_read;
1339 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001340
Johnny Chen86364b42011-09-20 23:28:55 +00001341 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001342 {
Greg Claytonc749eb82011-07-11 05:12:02 +00001343 if (load_addr == LLDB_INVALID_ADDRESS)
1344 load_addr = resolved_addr.GetLoadAddress (this);
1345
Greg Claytondda4f7b2010-06-30 23:03:03 +00001346 if (load_addr == LLDB_INVALID_ADDRESS)
1347 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001348 ModuleSP addr_module_sp (resolved_addr.GetModule());
1349 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malead01b2952012-11-29 21:49:15 +00001350 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Greg Claytone72dfb32012-02-24 01:59:29 +00001351 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda7e589a62011-09-20 00:26:08 +00001352 resolved_addr.GetFileAddress(),
Greg Claytone72dfb32012-02-24 01:59:29 +00001353 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001354 else
Daniel Malead01b2952012-11-29 21:49:15 +00001355 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:03 +00001356 }
1357 else
1358 {
Greg Claytondb598232011-01-07 01:57:07 +00001359 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 if (bytes_read != dst_len)
1361 {
1362 if (error.Success())
1363 {
1364 if (bytes_read == 0)
Daniel Malead01b2952012-11-29 21:49:15 +00001365 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 else
Daniel Malead01b2952012-11-29 21:49:15 +00001367 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 +00001368 }
1369 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001370 if (bytes_read)
Enrico Granata9128ee22011-09-06 19:20:51 +00001371 {
1372 if (load_addr_ptr)
1373 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03 +00001374 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001375 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001376 // If the address is not section offset we have an address that
1377 // doesn't resolve to any address in any currently loaded shared
1378 // libaries and we failed to read memory so there isn't anything
1379 // more we can do. If it is section offset, we might be able to
1380 // read cached memory from the object file.
1381 if (!resolved_addr.IsSectionOffset())
1382 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001383 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 }
Greg Claytondda4f7b2010-06-30 23:03:03 +00001385
Greg Claytonc749eb82011-07-11 05:12:02 +00001386 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03 +00001387 {
Greg Claytondb598232011-01-07 01:57:07 +00001388 // If we didn't already try and read from the object file cache, then
1389 // try it after failing to read from the process.
1390 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03 +00001391 }
1392 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001393}
1394
Greg Claytond16e1e52011-07-12 17:06:17 +00001395size_t
Enrico Granata6b4ddc62013-01-21 19:20:50 +00001396Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1397{
1398 char buf[256];
1399 out_str.clear();
1400 addr_t curr_addr = addr.GetLoadAddress(this);
1401 Address address(addr);
1402 while (1)
1403 {
1404 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1405 if (length == 0)
1406 break;
1407 out_str.append(buf, length);
1408 // If we got "length - 1" bytes, we didn't get the whole C string, we
1409 // need to read some more characters
1410 if (length == sizeof(buf) - 1)
1411 curr_addr += length;
1412 else
1413 break;
1414 address = Address(curr_addr);
1415 }
1416 return out_str.size();
1417}
1418
1419
1420size_t
1421Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1422{
1423 size_t total_cstr_len = 0;
1424 if (dst && dst_max_len)
1425 {
1426 result_error.Clear();
1427 // NULL out everything just to be safe
1428 memset (dst, 0, dst_max_len);
1429 Error error;
1430 addr_t curr_addr = addr.GetLoadAddress(this);
1431 Address address(addr);
1432 const size_t cache_line_size = 512;
1433 size_t bytes_left = dst_max_len - 1;
1434 char *curr_dst = dst;
1435
1436 while (bytes_left > 0)
1437 {
1438 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1439 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1440 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1441
1442 if (bytes_read == 0)
1443 {
1444 result_error = error;
1445 dst[total_cstr_len] = '\0';
1446 break;
1447 }
1448 const size_t len = strlen(curr_dst);
1449
1450 total_cstr_len += len;
1451
1452 if (len < bytes_to_read)
1453 break;
1454
1455 curr_dst += bytes_read;
1456 curr_addr += bytes_read;
1457 bytes_left -= bytes_read;
1458 address = Address(curr_addr);
1459 }
1460 }
1461 else
1462 {
1463 if (dst == NULL)
1464 result_error.SetErrorString("invalid arguments");
1465 else
1466 result_error.Clear();
1467 }
1468 return total_cstr_len;
1469}
1470
1471size_t
Greg Claytond16e1e52011-07-12 17:06:17 +00001472Target::ReadScalarIntegerFromMemory (const Address& addr,
1473 bool prefer_file_cache,
1474 uint32_t byte_size,
1475 bool is_signed,
1476 Scalar &scalar,
1477 Error &error)
1478{
1479 uint64_t uval;
1480
1481 if (byte_size <= sizeof(uval))
1482 {
1483 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1484 if (bytes_read == byte_size)
1485 {
1486 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Claytonc7bece562013-01-25 18:06:21 +00001487 lldb::offset_t offset = 0;
Greg Claytond16e1e52011-07-12 17:06:17 +00001488 if (byte_size <= 4)
1489 scalar = data.GetMaxU32 (&offset, byte_size);
1490 else
1491 scalar = data.GetMaxU64 (&offset, byte_size);
1492
1493 if (is_signed)
1494 scalar.SignExtend(byte_size * 8);
1495 return bytes_read;
1496 }
1497 }
1498 else
1499 {
1500 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1501 }
1502 return 0;
1503}
1504
1505uint64_t
1506Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1507 bool prefer_file_cache,
1508 size_t integer_byte_size,
1509 uint64_t fail_value,
1510 Error &error)
1511{
1512 Scalar scalar;
1513 if (ReadScalarIntegerFromMemory (addr,
1514 prefer_file_cache,
1515 integer_byte_size,
1516 false,
1517 scalar,
1518 error))
1519 return scalar.ULongLong(fail_value);
1520 return fail_value;
1521}
1522
1523bool
1524Target::ReadPointerFromMemory (const Address& addr,
1525 bool prefer_file_cache,
1526 Error &error,
1527 Address &pointer_addr)
1528{
1529 Scalar scalar;
1530 if (ReadScalarIntegerFromMemory (addr,
1531 prefer_file_cache,
1532 m_arch.GetAddressByteSize(),
1533 false,
1534 scalar,
1535 error))
1536 {
1537 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1538 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1539 {
Greg Claytond5944cd2013-12-06 01:12:00 +00001540 SectionLoadList &section_load_list = GetSectionLoadList();
1541 if (section_load_list.IsEmpty())
Greg Claytond16e1e52011-07-12 17:06:17 +00001542 {
1543 // No sections are loaded, so we must assume we are not running
1544 // yet and anything we are given is a file address.
1545 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1546 }
1547 else
1548 {
1549 // We have at least one section loaded. This can be becuase
1550 // we have manually loaded some sections with "target modules load ..."
1551 // or because we have have a live process that has sections loaded
1552 // through the dynamic loader
Greg Claytond5944cd2013-12-06 01:12:00 +00001553 section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
Greg Claytond16e1e52011-07-12 17:06:17 +00001554 }
1555 // We weren't able to resolve the pointer value, so just return
1556 // an address with no section
1557 if (!pointer_addr.IsValid())
1558 pointer_addr.SetOffset (pointer_vm_addr);
1559 return true;
1560
1561 }
1562 }
1563 return false;
1564}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001565
1566ModuleSP
Greg Claytonb9a01b32012-02-26 05:51:37 +00001567Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001568{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569 ModuleSP module_sp;
1570
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571 Error error;
1572
Jim Ingham4a94c912012-05-17 18:38:42 +00001573 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1574 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001575
Jim Ingham4a94c912012-05-17 18:38:42 +00001576 if (module_spec.GetUUID().IsValid())
1577 module_sp = m_images.FindFirstModule(module_spec);
1578
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001579 if (!module_sp)
1580 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001581 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1582 bool did_create_module = false;
1583
1584 // If there are image search path entries, try to use them first to acquire a suitable image.
1585 if (m_image_search_paths.GetSize())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001586 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001587 ModuleSpec transformed_spec (module_spec);
1588 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1589 {
1590 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1591 error = ModuleList::GetSharedModule (transformed_spec,
1592 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001593 &GetExecutableSearchPaths(),
Jim Ingham4a94c912012-05-17 18:38:42 +00001594 &old_module_sp,
1595 &did_create_module);
1596 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001597 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001598
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001599 if (!module_sp)
1600 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001601 // If we have a UUID, we can check our global shared module list in case
1602 // we already have it. If we don't have a valid UUID, then we can't since
1603 // the path in "module_spec" will be a platform path, and we will need to
1604 // let the platform find that file. For example, we could be asking for
1605 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1606 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1607 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1608 // cache.
1609 if (module_spec.GetUUID().IsValid())
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001610 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001611 // We have a UUID, it is OK to check the global module list...
1612 error = ModuleList::GetSharedModule (module_spec,
1613 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001614 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001615 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001616 &did_create_module);
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001617 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001618
1619 if (!module_sp)
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001620 {
Jim Ingham4a94c912012-05-17 18:38:42 +00001621 // The platform is responsible for finding and caching an appropriate
1622 // module in the shared module cache.
1623 if (m_platform_sp)
1624 {
1625 FileSpec platform_file_spec;
1626 error = m_platform_sp->GetSharedModule (module_spec,
1627 module_sp,
Greg Clayton6920b522012-08-22 18:39:03 +00001628 &GetExecutableSearchPaths(),
Greg Clayton67cc0632012-08-22 17:17:09 +00001629 &old_module_sp,
Jim Ingham4a94c912012-05-17 18:38:42 +00001630 &did_create_module);
1631 }
1632 else
1633 {
1634 error.SetErrorString("no platform is currently set");
1635 }
Greg Claytonb69bb2e2012-04-27 00:58:27 +00001636 }
1637 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638
Jim Ingham4a94c912012-05-17 18:38:42 +00001639 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1640 // module in the list already, and if there was, let's remove it.
1641 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001643 ObjectFile *objfile = module_sp->GetObjectFile();
1644 if (objfile)
Jim Ingham4a94c912012-05-17 18:38:42 +00001645 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001646 switch (objfile->GetType())
Jim Ingham4a94c912012-05-17 18:38:42 +00001647 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001648 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1649 case ObjectFile::eTypeExecutable: /// A normal executable
1650 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1651 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1652 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1653 break;
1654 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1655 if (error_ptr)
1656 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1657 return ModuleSP();
1658 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1659 if (error_ptr)
1660 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1661 return ModuleSP();
1662 default:
1663 if (error_ptr)
1664 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1665 return ModuleSP();
1666 }
1667 // GetSharedModule is not guaranteed to find the old shared module, for instance
1668 // in the common case where you pass in the UUID, it is only going to find the one
1669 // module matching the UUID. In fact, it has no good way to know what the "old module"
1670 // relevant to this target is, since there might be many copies of a module with this file spec
1671 // in various running debug sessions, but only one of them will belong to this target.
1672 // So let's remove the UUID from the module list, and look in the target's module list.
1673 // Only do this if there is SOMETHING else in the module spec...
1674 if (!old_module_sp)
1675 {
1676 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham4a94c912012-05-17 18:38:42 +00001677 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00001678 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1679 module_spec_copy.GetUUID().Clear();
1680
1681 ModuleList found_modules;
1682 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1683 if (num_found == 1)
1684 {
1685 old_module_sp = found_modules.GetModuleAtIndex(0);
1686 }
Jim Ingham4a94c912012-05-17 18:38:42 +00001687 }
1688 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00001689
1690 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1691 {
1692 m_images.ReplaceModule(old_module_sp, module_sp);
1693 Module *old_module_ptr = old_module_sp.get();
1694 old_module_sp.reset();
1695 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1696 }
1697 else
1698 m_images.Append(module_sp);
Jim Ingham4a94c912012-05-17 18:38:42 +00001699 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700 }
1701 }
1702 if (error_ptr)
1703 *error_ptr = error;
1704 return module_sp;
1705}
1706
1707
Greg Claytond9e416c2012-02-18 05:35:26 +00001708TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001709Target::CalculateTarget ()
1710{
Greg Claytond9e416c2012-02-18 05:35:26 +00001711 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001712}
1713
Greg Claytond9e416c2012-02-18 05:35:26 +00001714ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715Target::CalculateProcess ()
1716{
Greg Claytond9e416c2012-02-18 05:35:26 +00001717 return ProcessSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001718}
1719
Greg Claytond9e416c2012-02-18 05:35:26 +00001720ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001721Target::CalculateThread ()
1722{
Greg Claytond9e416c2012-02-18 05:35:26 +00001723 return ThreadSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724}
1725
Jason Molendab57e4a12013-11-04 09:33:30 +00001726StackFrameSP
1727Target::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728{
Jason Molendab57e4a12013-11-04 09:33:30 +00001729 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730}
1731
1732void
Greg Clayton0603aa92010-10-04 01:05:56 +00001733Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734{
Greg Claytonc14ee322011-09-22 04:58:26 +00001735 exe_ctx.Clear();
1736 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737}
1738
1739PathMappingList &
1740Target::GetImageSearchPathList ()
1741{
1742 return m_image_search_paths;
1743}
1744
1745void
1746Target::ImageSearchPathsChanged
1747(
1748 const PathMappingList &path_list,
1749 void *baton
1750)
1751{
1752 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:45 +00001753 ModuleSP exe_module_sp (target->GetExecutableModule());
1754 if (exe_module_sp)
Greg Claytonaa149cb2011-08-11 02:48:45 +00001755 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001756}
1757
1758ClangASTContext *
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001759Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760{
Greg Clayton73da2442011-08-03 01:23:55 +00001761 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chen60e2c6a2011-11-30 23:18:53 +00001762 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanan4bf80d52011-11-15 22:27:19 +00001763 {
Greg Clayton73da2442011-08-03 01:23:55 +00001764 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Claytone1cd1be2012-01-29 20:56:30 +00001765 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanan4bf80d52011-11-15 22:27:19 +00001766 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1767 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1768 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770 return m_scratch_ast_context_ap.get();
1771}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001772
Sean Callanan686b2312011-11-16 18:20:47 +00001773ClangASTImporter *
1774Target::GetClangASTImporter()
1775{
1776 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1777
1778 if (!ast_importer)
1779 {
1780 ast_importer = new ClangASTImporter();
1781 m_ast_importer_ap.reset(ast_importer);
1782 }
1783
1784 return ast_importer;
1785}
1786
Greg Clayton99d0faf2010-11-18 23:32:35 +00001787void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001788Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43 +00001789{
Greg Clayton6920b522012-08-22 18:39:03 +00001790 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001791}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001792
Greg Clayton99d0faf2010-11-18 23:32:35 +00001793void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001794Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001795{
Greg Clayton6920b522012-08-22 18:39:03 +00001796 Process::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +00001797}
Caroline Ticedaccaa92010-09-20 20:44:43 +00001798
Greg Claytonc859e2d2012-02-13 23:10:39 +00001799FileSpecList
1800Target::GetDefaultExecutableSearchPaths ()
1801{
Greg Clayton67cc0632012-08-22 17:17:09 +00001802 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1803 if (properties_sp)
1804 return properties_sp->GetExecutableSearchPaths();
Greg Claytonc859e2d2012-02-13 23:10:39 +00001805 return FileSpecList();
1806}
1807
Michael Sartaina7499c92013-07-01 19:45:50 +00001808FileSpecList
1809Target::GetDefaultDebugFileSearchPaths ()
1810{
1811 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1812 if (properties_sp)
1813 return properties_sp->GetDebugFileSearchPaths();
1814 return FileSpecList();
1815}
1816
Caroline Ticedaccaa92010-09-20 20:44:43 +00001817ArchSpec
1818Target::GetDefaultArchitecture ()
1819{
Greg Clayton67cc0632012-08-22 17:17:09 +00001820 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1821 if (properties_sp)
1822 return properties_sp->GetDefaultArchitecture();
Greg Clayton8910c902012-05-15 02:44:13 +00001823 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43 +00001824}
1825
1826void
Greg Clayton67cc0632012-08-22 17:17:09 +00001827Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001828{
Greg Clayton67cc0632012-08-22 17:17:09 +00001829 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1830 if (properties_sp)
Jason Molendaa3f24b32012-12-12 02:23:56 +00001831 {
1832 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 +00001833 return properties_sp->SetDefaultArchitecture(arch);
Jason Molendaa3f24b32012-12-12 02:23:56 +00001834 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001835}
1836
Greg Clayton0603aa92010-10-04 01:05:56 +00001837Target *
1838Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1839{
1840 // The target can either exist in the "process" of ExecutionContext, or in
1841 // the "target_sp" member of SymbolContext. This accessor helper function
1842 // will get the target from one of these locations.
1843
1844 Target *target = NULL;
1845 if (sc_ptr != NULL)
1846 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:26 +00001847 if (target == NULL && exe_ctx_ptr)
1848 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:56 +00001849 return target;
1850}
1851
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001852ExecutionResults
1853Target::EvaluateExpression
1854(
1855 const char *expr_cstr,
Jason Molendab57e4a12013-11-04 09:33:30 +00001856 StackFrame *frame,
Enrico Granata3372f582012-07-16 23:10:35 +00001857 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad4439aa2012-09-05 20:41:26 +00001858 const EvaluateExpressionOptions& options
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001859)
1860{
Enrico Granata97fca502012-09-18 17:43:16 +00001861 result_valobj_sp.reset();
1862
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001863 ExecutionResults execution_results = eExecutionSetupError;
1864
Greg Claytond1767f02011-12-08 02:13:16 +00001865 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1866 return execution_results;
1867
Jim Ingham6026ca32011-05-12 02:06:14 +00001868 // We shouldn't run stop hooks in expressions.
1869 // Be sure to reset this if you return anywhere within this function.
1870 bool old_suppress_value = m_suppress_stop_hooks;
1871 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001872
1873 ExecutionContext exe_ctx;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001874
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001875 if (frame)
1876 {
1877 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001878 }
1879 else if (m_process_sp)
1880 {
1881 m_process_sp->CalculateExecutionContext(exe_ctx);
1882 }
1883 else
1884 {
1885 CalculateExecutionContext(exe_ctx);
1886 }
1887
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001888 // Make sure we aren't just trying to see the value of a persistent
1889 // variable (something like "$0")
1890 lldb::ClangExpressionVariableSP persistent_var_sp;
1891 // Only check for persistent variables the expression starts with a '$'
1892 if (expr_cstr[0] == '$')
1893 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1894
1895 if (persistent_var_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001896 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001897 result_valobj_sp = persistent_var_sp->GetValueObject ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001898 execution_results = eExecutionCompleted;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001899 }
1900 else
1901 {
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001902 const char *prefix = GetExpressionPrefixContentsAsCString();
Greg Clayton62afb9f2013-11-04 19:35:17 +00001903 Error error;
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001904 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001905 options,
1906 expr_cstr,
Sean Callanan0bf0baf2013-01-12 02:04:23 +00001907 prefix,
1908 result_valobj_sp,
Greg Clayton62afb9f2013-11-04 19:35:17 +00001909 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001910 }
Jim Ingham6026ca32011-05-12 02:06:14 +00001911
1912 m_suppress_stop_hooks = old_suppress_value;
1913
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001914 return execution_results;
1915}
1916
Greg Claytonf3ef3d22011-05-22 22:46:53 +00001917lldb::addr_t
1918Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1919{
1920 addr_t code_addr = load_addr;
1921 switch (m_arch.GetMachine())
1922 {
1923 case llvm::Triple::arm:
1924 case llvm::Triple::thumb:
1925 switch (addr_class)
1926 {
1927 case eAddressClassData:
1928 case eAddressClassDebug:
1929 return LLDB_INVALID_ADDRESS;
1930
1931 case eAddressClassUnknown:
1932 case eAddressClassInvalid:
1933 case eAddressClassCode:
1934 case eAddressClassCodeAlternateISA:
1935 case eAddressClassRuntime:
1936 // Check if bit zero it no set?
1937 if ((code_addr & 1ull) == 0)
1938 {
1939 // Bit zero isn't set, check if the address is a multiple of 2?
1940 if (code_addr & 2ull)
1941 {
1942 // The address is a multiple of 2 so it must be thumb, set bit zero
1943 code_addr |= 1ull;
1944 }
1945 else if (addr_class == eAddressClassCodeAlternateISA)
1946 {
1947 // We checked the address and the address claims to be the alternate ISA
1948 // which means thumb, so set bit zero.
1949 code_addr |= 1ull;
1950 }
1951 }
1952 break;
1953 }
1954 break;
1955
1956 default:
1957 break;
1958 }
1959 return code_addr;
1960}
1961
1962lldb::addr_t
1963Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1964{
1965 addr_t opcode_addr = load_addr;
1966 switch (m_arch.GetMachine())
1967 {
1968 case llvm::Triple::arm:
1969 case llvm::Triple::thumb:
1970 switch (addr_class)
1971 {
1972 case eAddressClassData:
1973 case eAddressClassDebug:
1974 return LLDB_INVALID_ADDRESS;
1975
1976 case eAddressClassInvalid:
1977 case eAddressClassUnknown:
1978 case eAddressClassCode:
1979 case eAddressClassCodeAlternateISA:
1980 case eAddressClassRuntime:
1981 opcode_addr &= ~(1ull);
1982 break;
1983 }
1984 break;
1985
1986 default:
1987 break;
1988 }
1989 return opcode_addr;
1990}
1991
Greg Clayton9585fbf2013-03-19 00:20:55 +00001992SourceManager &
1993Target::GetSourceManager ()
1994{
1995 if (m_source_manager_ap.get() == NULL)
1996 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
1997 return *m_source_manager_ap;
1998}
1999
2000
Jim Ingham9575d842011-03-11 03:53:59 +00002001lldb::user_id_t
2002Target::AddStopHook (Target::StopHookSP &new_hook_sp)
2003{
2004 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Claytone1cd1be2012-01-29 20:56:30 +00002005 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Ingham9575d842011-03-11 03:53:59 +00002006 m_stop_hooks[new_uid] = new_hook_sp;
2007 return new_uid;
2008}
2009
2010bool
2011Target::RemoveStopHookByID (lldb::user_id_t user_id)
2012{
2013 size_t num_removed;
2014 num_removed = m_stop_hooks.erase (user_id);
2015 if (num_removed == 0)
2016 return false;
2017 else
2018 return true;
2019}
2020
2021void
2022Target::RemoveAllStopHooks ()
2023{
2024 m_stop_hooks.clear();
2025}
2026
2027Target::StopHookSP
2028Target::GetStopHookByID (lldb::user_id_t user_id)
2029{
2030 StopHookSP found_hook;
2031
2032 StopHookCollection::iterator specified_hook_iter;
2033 specified_hook_iter = m_stop_hooks.find (user_id);
2034 if (specified_hook_iter != m_stop_hooks.end())
2035 found_hook = (*specified_hook_iter).second;
2036 return found_hook;
2037}
2038
2039bool
2040Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
2041{
2042 StopHookCollection::iterator specified_hook_iter;
2043 specified_hook_iter = m_stop_hooks.find (user_id);
2044 if (specified_hook_iter == m_stop_hooks.end())
2045 return false;
2046
2047 (*specified_hook_iter).second->SetIsActive (active_state);
2048 return true;
2049}
2050
2051void
2052Target::SetAllStopHooksActiveState (bool active_state)
2053{
2054 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2055 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2056 {
2057 (*pos).second->SetIsActive (active_state);
2058 }
2059}
2060
2061void
2062Target::RunStopHooks ()
2063{
Jim Ingham6026ca32011-05-12 02:06:14 +00002064 if (m_suppress_stop_hooks)
2065 return;
2066
Jim Ingham9575d842011-03-11 03:53:59 +00002067 if (!m_process_sp)
2068 return;
Enrico Granatae2e091b2012-08-03 22:24:48 +00002069
2070 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
2071 // since in that case we do not want to run the stop-hooks
2072 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
2073 return;
2074
Jim Ingham9575d842011-03-11 03:53:59 +00002075 if (m_stop_hooks.empty())
2076 return;
2077
2078 StopHookCollection::iterator pos, end = m_stop_hooks.end();
2079
2080 // If there aren't any active stop hooks, don't bother either:
2081 bool any_active_hooks = false;
2082 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2083 {
2084 if ((*pos).second->IsActive())
2085 {
2086 any_active_hooks = true;
2087 break;
2088 }
2089 }
2090 if (!any_active_hooks)
2091 return;
2092
2093 CommandReturnObject result;
2094
2095 std::vector<ExecutionContext> exc_ctx_with_reasons;
2096 std::vector<SymbolContext> sym_ctx_with_reasons;
2097
2098 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2099 size_t num_threads = cur_threadlist.GetSize();
2100 for (size_t i = 0; i < num_threads; i++)
2101 {
2102 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2103 if (cur_thread_sp->ThreadStoppedForAReason())
2104 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002105 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
Jim Ingham9575d842011-03-11 03:53:59 +00002106 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2107 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2108 }
2109 }
2110
2111 // If no threads stopped for a reason, don't run the stop-hooks.
2112 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2113 if (num_exe_ctx == 0)
2114 return;
2115
Jim Ingham5b52f0c2011-06-02 23:58:26 +00002116 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2117 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:59 +00002118
2119 bool keep_going = true;
2120 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:27 +00002121 bool print_hook_header;
2122 bool print_thread_header;
2123
2124 if (num_exe_ctx == 1)
2125 print_thread_header = false;
2126 else
2127 print_thread_header = true;
2128
2129 if (m_stop_hooks.size() == 1)
2130 print_hook_header = false;
2131 else
2132 print_hook_header = true;
2133
Jim Ingham9575d842011-03-11 03:53:59 +00002134 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2135 {
2136 // result.Clear();
2137 StopHookSP cur_hook_sp = (*pos).second;
2138 if (!cur_hook_sp->IsActive())
2139 continue;
2140
2141 bool any_thread_matched = false;
2142 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2143 {
2144 if ((cur_hook_sp->GetSpecifier () == NULL
2145 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2146 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Ingham3d902922012-03-07 22:03:04 +00002147 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Ingham9575d842011-03-11 03:53:59 +00002148 {
2149 if (!hooks_ran)
2150 {
Jim Ingham9575d842011-03-11 03:53:59 +00002151 hooks_ran = true;
2152 }
Jim Ingham381e25b2011-03-22 01:47:27 +00002153 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:59 +00002154 {
Johnny Chenaeab25c2011-10-24 23:01:06 +00002155 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2156 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2157 NULL);
2158 if (cmd)
Daniel Malead01b2952012-11-29 21:49:15 +00002159 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chenaeab25c2011-10-24 23:01:06 +00002160 else
Daniel Malead01b2952012-11-29 21:49:15 +00002161 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002162 any_thread_matched = true;
2163 }
2164
Jim Ingham381e25b2011-03-22 01:47:27 +00002165 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:26 +00002166 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:59 +00002167
2168 bool stop_on_continue = true;
2169 bool stop_on_error = true;
2170 bool echo_commands = false;
2171 bool print_results = true;
2172 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:51 +00002173 &exc_ctx_with_reasons[i],
2174 stop_on_continue,
2175 stop_on_error,
2176 echo_commands,
Enrico Granata5f5ab602012-05-31 01:09:06 +00002177 print_results,
2178 eLazyBoolNo,
Greg Clayton32e0a752011-03-30 18:16:51 +00002179 result);
Jim Ingham9575d842011-03-11 03:53:59 +00002180
2181 // If the command started the target going again, we should bag out of
2182 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:51 +00002183 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2184 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:59 +00002185 {
Daniel Malead01b2952012-11-29 21:49:15 +00002186 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002187 keep_going = false;
2188 }
2189 }
2190 }
2191 }
Jason Molenda879cf772011-09-23 00:42:55 +00002192
Caroline Tice969ed3d2011-05-02 20:41:46 +00002193 result.GetImmediateOutputStream()->Flush();
2194 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:59 +00002195}
2196
Greg Claytonfbb76342013-11-20 21:07:01 +00002197const TargetPropertiesSP &
2198Target::GetGlobalProperties()
2199{
2200 static TargetPropertiesSP g_settings_sp;
2201 if (!g_settings_sp)
2202 {
2203 g_settings_sp.reset (new TargetProperties (NULL));
2204 }
2205 return g_settings_sp;
2206}
2207
2208Error
2209Target::Install (ProcessLaunchInfo *launch_info)
2210{
2211 Error error;
2212 PlatformSP platform_sp (GetPlatform());
2213 if (platform_sp)
2214 {
2215 if (platform_sp->IsRemote())
2216 {
2217 if (platform_sp->IsConnected())
2218 {
2219 // Install all files that have an install path, and always install the
2220 // main executable when connected to a remote platform
2221 const ModuleList& modules = GetImages();
2222 const size_t num_images = modules.GetSize();
2223 for (size_t idx = 0; idx < num_images; ++idx)
2224 {
2225 const bool is_main_executable = idx == 0;
2226 ModuleSP module_sp(modules.GetModuleAtIndex(idx));
2227 if (module_sp)
2228 {
2229 FileSpec local_file (module_sp->GetFileSpec());
2230 if (local_file)
2231 {
2232 FileSpec remote_file (module_sp->GetRemoteInstallFileSpec());
2233 if (!remote_file)
2234 {
2235 if (is_main_executable) // TODO: add setting for always installing main executable???
2236 {
2237 // Always install the main executable
2238 remote_file.GetDirectory() = platform_sp->GetWorkingDirectory();
2239 remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename();
2240 }
2241 }
2242 if (remote_file)
2243 {
2244 error = platform_sp->Install(local_file, remote_file);
2245 if (error.Success())
2246 {
2247 module_sp->SetPlatformFileSpec(remote_file);
2248 if (is_main_executable)
2249 {
2250 if (launch_info)
2251 launch_info->SetExecutableFile(remote_file, false);
2252 }
2253 }
2254 else
2255 break;
2256 }
2257 }
2258 }
2259 }
2260 }
2261 }
2262 }
2263 return error;
2264}
Greg Clayton7b242382011-07-08 00:48:09 +00002265
Greg Claytond5944cd2013-12-06 01:12:00 +00002266bool
2267Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
2268{
2269 return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
2270}
2271
2272bool
2273Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
2274{
2275 const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
2276 if (old_section_load_addr != new_section_load_addr)
2277 {
2278 uint32_t stop_id = 0;
2279 ProcessSP process_sp(GetProcessSP());
2280 if (process_sp)
2281 stop_id = process_sp->GetStopID();
2282 else
2283 stop_id = m_section_load_history.GetLastStopID();
2284 if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
2285 return true; // Return true if the section load address was changed...
2286 }
2287 return false; // Return false to indicate nothing changed
2288
2289}
2290
2291bool
2292Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
2293{
2294 uint32_t stop_id = 0;
2295 ProcessSP process_sp(GetProcessSP());
2296 if (process_sp)
2297 stop_id = process_sp->GetStopID();
2298 else
2299 stop_id = m_section_load_history.GetLastStopID();
2300 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
2301}
2302
2303bool
2304Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
2305{
2306 uint32_t stop_id = 0;
2307 ProcessSP process_sp(GetProcessSP());
2308 if (process_sp)
2309 stop_id = process_sp->GetStopID();
2310 else
2311 stop_id = m_section_load_history.GetLastStopID();
2312 return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
2313}
2314
2315void
2316Target::ClearAllLoadedSections ()
2317{
2318 m_section_load_history.Clear();
2319}
2320
Greg Claytonb09c5382013-12-13 17:20:18 +00002321
2322Error
2323Target::Launch (Listener &listener, ProcessLaunchInfo &launch_info)
2324{
2325 Error error;
2326 Error error2;
2327
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 {
2402 StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false);
2403
2404 if (state == eStateStopped)
2405 {
2406 error = m_process_sp->Resume();
2407 if (error.Success())
2408 {
2409 if (synchronous_execution)
2410 {
2411 state = m_process_sp->WaitForProcessToStop (NULL);
2412 const bool must_be_alive = false; // eStateExited is ok, so this must be false
2413 if (!StateIsStoppedState(state, must_be_alive))
2414 {
2415 error2.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
2416 return error2;
2417 }
2418 }
2419 }
2420 else
2421 {
2422 error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
2423 return error2;
2424 }
2425 }
2426 else
2427 {
2428 error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
2429 }
2430 }
2431 }
2432 else
2433 {
2434 error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
2435 return error2;
2436 }
2437 return error;
2438}
Jim Ingham9575d842011-03-11 03:53:59 +00002439//--------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +00002440// Target::StopHook
Jim Ingham9575d842011-03-11 03:53:59 +00002441//--------------------------------------------------------------
Jim Ingham9575d842011-03-11 03:53:59 +00002442Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2443 UserID (uid),
2444 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:59 +00002445 m_commands (),
2446 m_specifier_sp (),
Greg Claytone01e07b2013-04-18 18:10:51 +00002447 m_thread_spec_ap(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002448 m_active (true)
Jim Ingham9575d842011-03-11 03:53:59 +00002449{
2450}
2451
2452Target::StopHook::StopHook (const StopHook &rhs) :
2453 UserID (rhs.GetID()),
2454 m_target_sp (rhs.m_target_sp),
2455 m_commands (rhs.m_commands),
2456 m_specifier_sp (rhs.m_specifier_sp),
Greg Claytone01e07b2013-04-18 18:10:51 +00002457 m_thread_spec_ap (),
Stephen Wilson71c21d12011-04-11 19:41:40 +00002458 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:59 +00002459{
2460 if (rhs.m_thread_spec_ap.get() != NULL)
2461 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2462}
2463
2464
2465Target::StopHook::~StopHook ()
2466{
2467}
2468
2469void
2470Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2471{
2472 m_thread_spec_ap.reset (specifier);
2473}
2474
2475
2476void
2477Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2478{
2479 int indent_level = s->GetIndentLevel();
2480
2481 s->SetIndentLevel(indent_level + 2);
2482
Daniel Malead01b2952012-11-29 21:49:15 +00002483 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00002484 if (m_active)
2485 s->Indent ("State: enabled\n");
2486 else
2487 s->Indent ("State: disabled\n");
2488
2489 if (m_specifier_sp)
2490 {
2491 s->Indent();
2492 s->PutCString ("Specifier:\n");
2493 s->SetIndentLevel (indent_level + 4);
2494 m_specifier_sp->GetDescription (s, level);
2495 s->SetIndentLevel (indent_level + 2);
2496 }
2497
2498 if (m_thread_spec_ap.get() != NULL)
2499 {
2500 StreamString tmp;
2501 s->Indent("Thread:\n");
2502 m_thread_spec_ap->GetDescription (&tmp, level);
2503 s->SetIndentLevel (indent_level + 4);
2504 s->Indent (tmp.GetData());
2505 s->PutCString ("\n");
2506 s->SetIndentLevel (indent_level + 2);
2507 }
2508
2509 s->Indent ("Commands: \n");
2510 s->SetIndentLevel (indent_level + 4);
2511 uint32_t num_commands = m_commands.GetSize();
2512 for (uint32_t i = 0; i < num_commands; i++)
2513 {
2514 s->Indent(m_commands.GetStringAtIndex(i));
2515 s->PutCString ("\n");
2516 }
2517 s->SetIndentLevel (indent_level);
2518}
2519
Greg Clayton67cc0632012-08-22 17:17:09 +00002520//--------------------------------------------------------------
2521// class TargetProperties
2522//--------------------------------------------------------------
2523
2524OptionEnumValueElement
2525lldb_private::g_dynamic_value_types[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002526{
Greg Clayton67cc0632012-08-22 17:17:09 +00002527 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2528 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2529 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2530 { 0, NULL, NULL }
2531};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002532
Greg Clayton1f746072012-08-29 21:13:06 +00002533static OptionEnumValueElement
2534g_inline_breakpoint_enums[] =
2535{
2536 { 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."},
2537 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2538 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2539 { 0, NULL, NULL }
2540};
2541
Jim Ingham0f063ba2013-03-02 00:26:47 +00002542typedef enum x86DisassemblyFlavor
2543{
2544 eX86DisFlavorDefault,
2545 eX86DisFlavorIntel,
2546 eX86DisFlavorATT
2547} x86DisassemblyFlavor;
2548
2549static OptionEnumValueElement
2550g_x86_dis_flavor_value_types[] =
2551{
2552 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2553 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2554 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2555 { 0, NULL, NULL }
2556};
2557
Enrico Granata397ddd52013-05-21 20:13:34 +00002558static OptionEnumValueElement
Daniel Malead79ae052013-08-07 21:54:09 +00002559g_hex_immediate_style_values[] =
2560{
2561 { Disassembler::eHexStyleC, "c", "C-style (0xffff)."},
2562 { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."},
2563 { 0, NULL, NULL }
2564};
2565
2566static OptionEnumValueElement
Enrico Granata397ddd52013-05-21 20:13:34 +00002567g_load_script_from_sym_file_values[] =
2568{
2569 { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"},
2570 { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."},
2571 { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."},
2572 { 0, NULL, NULL }
2573};
2574
Greg Claytonfd814c52013-08-13 01:42:25 +00002575
2576static OptionEnumValueElement
2577g_memory_module_load_level_values[] =
2578{
Greg Clayton86eac942013-08-13 21:32:34 +00002579 { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
Greg Claytonfd814c52013-08-13 01:42:25 +00002580 { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."},
2581 { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."},
2582 { 0, NULL, NULL }
2583};
2584
Greg Clayton67cc0632012-08-22 17:17:09 +00002585static PropertyDefinition
2586g_properties[] =
Caroline Ticedaccaa92010-09-20 20:44:43 +00002587{
Greg Clayton67cc0632012-08-22 17:17:09 +00002588 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2589 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2590 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2591 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2592 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2593 { "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 "
2594 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2595 "some part (starting at the root) of the path to the file when it was built, "
2596 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2597 "Each element of the array is checked in order and the first one that results in a match wins." },
2598 { "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 +00002599 { "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 +00002600 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2601 { "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 +00002602 { "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 +00002603 { "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 +00002604 { "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." },
2605 { "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 +00002606 { "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." },
2607 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2608 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2609 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2610 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2611 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2612 { "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 +00002613 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
2614 "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. "
2615 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2616 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
2617 "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the "
2618 "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings "
2619 "file and line breakpoints." },
Jim Ingham0f063ba2013-03-02 00:26:47 +00002620 // 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.
2621 { "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 +00002622 { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." },
2623 { "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 +00002624 { "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 +00002625 { "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 +00002626 { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values,
2627 "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. "
2628 "This setting helps users control how much information gets loaded when loading modules from memory."
2629 "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
2630 "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
2631 "'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 +00002632 { "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 +00002633 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2634};
2635enum
Caroline Ticedaccaa92010-09-20 20:44:43 +00002636{
Greg Clayton67cc0632012-08-22 17:17:09 +00002637 ePropertyDefaultArch,
2638 ePropertyExprPrefix,
2639 ePropertyPreferDynamic,
2640 ePropertyEnableSynthetic,
2641 ePropertySkipPrologue,
2642 ePropertySourceMap,
2643 ePropertyExecutableSearchPaths,
Michael Sartaina7499c92013-07-01 19:45:50 +00002644 ePropertyDebugFileSearchPaths,
Greg Clayton67cc0632012-08-22 17:17:09 +00002645 ePropertyMaxChildrenCount,
2646 ePropertyMaxSummaryLength,
Enrico Granatad325bf92013-06-04 22:54:16 +00002647 ePropertyMaxMemReadSize,
Greg Clayton67cc0632012-08-22 17:17:09 +00002648 ePropertyBreakpointUseAvoidList,
Greg Clayton45392552012-10-17 22:57:12 +00002649 ePropertyArg0,
Greg Clayton67cc0632012-08-22 17:17:09 +00002650 ePropertyRunArgs,
2651 ePropertyEnvVars,
2652 ePropertyInheritEnv,
2653 ePropertyInputPath,
2654 ePropertyOutputPath,
2655 ePropertyErrorPath,
2656 ePropertyDisableASLR,
Greg Clayton1f746072012-08-29 21:13:06 +00002657 ePropertyDisableSTDIO,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002658 ePropertyInlineStrategy,
Jim Ingham17d023f2013-03-13 17:58:04 +00002659 ePropertyDisassemblyFlavor,
Daniel Malead79ae052013-08-07 21:54:09 +00002660 ePropertyUseHexImmediates,
2661 ePropertyHexImmediateStyle,
Enrico Granata2ea43cd2013-05-13 17:03:52 +00002662 ePropertyUseFastStepping,
Enrico Granata97303392013-05-21 00:00:30 +00002663 ePropertyLoadScriptFromSymbolFile,
Greg Claytonfb6621e2013-12-06 21:59:52 +00002664 ePropertyMemoryModuleLoadLevel,
2665 ePropertyDisplayExpressionsInCrashlogs
Greg Clayton67cc0632012-08-22 17:17:09 +00002666};
Caroline Ticedaccaa92010-09-20 20:44:43 +00002667
Caroline Ticedaccaa92010-09-20 20:44:43 +00002668
Greg Clayton67cc0632012-08-22 17:17:09 +00002669class TargetOptionValueProperties : public OptionValueProperties
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00002670{
Greg Clayton67cc0632012-08-22 17:17:09 +00002671public:
2672 TargetOptionValueProperties (const ConstString &name) :
2673 OptionValueProperties (name),
2674 m_target (NULL),
2675 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002676 {
Caroline Ticedaccaa92010-09-20 20:44:43 +00002677 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002678
Greg Clayton67cc0632012-08-22 17:17:09 +00002679 // This constructor is used when creating TargetOptionValueProperties when it
2680 // is part of a new lldb_private::Target instance. It will copy all current
2681 // global property values as needed
2682 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2683 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2684 m_target (target),
2685 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:43 +00002686 {
Greg Clayton67cc0632012-08-22 17:17:09 +00002687 }
2688
2689 virtual const Property *
2690 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2691 {
2692 // When gettings the value for a key from the target options, we will always
2693 // try and grab the setting from the current target if there is one. Else we just
2694 // use the one from this instance.
2695 if (idx == ePropertyEnvVars)
2696 GetHostEnvironmentIfNeeded ();
2697
2698 if (exe_ctx)
2699 {
2700 Target *target = exe_ctx->GetTargetPtr();
2701 if (target)
2702 {
2703 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2704 if (this != target_properties)
2705 return target_properties->ProtectedGetPropertyAtIndex (idx);
2706 }
2707 }
2708 return ProtectedGetPropertyAtIndex (idx);
2709 }
Enrico Granata84a53df2013-05-20 22:29:23 +00002710
2711 lldb::TargetSP
2712 GetTargetSP ()
2713 {
2714 return m_target->shared_from_this();
2715 }
2716
Greg Clayton67cc0632012-08-22 17:17:09 +00002717protected:
2718
2719 void
2720 GetHostEnvironmentIfNeeded () const
2721 {
2722 if (!m_got_host_env)
2723 {
2724 if (m_target)
2725 {
2726 m_got_host_env = true;
2727 const uint32_t idx = ePropertyInheritEnv;
2728 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2729 {
2730 PlatformSP platform_sp (m_target->GetPlatform());
2731 if (platform_sp)
2732 {
2733 StringList env;
2734 if (platform_sp->GetEnvironment(env))
2735 {
2736 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2737 if (env_dict)
2738 {
2739 const bool can_replace = false;
2740 const size_t envc = env.GetSize();
2741 for (size_t idx=0; idx<envc; idx++)
2742 {
2743 const char *env_entry = env.GetStringAtIndex (idx);
2744 if (env_entry)
2745 {
2746 const char *equal_pos = ::strchr(env_entry, '=');
2747 ConstString key;
2748 // It is ok to have environment variables with no values
2749 const char *value = NULL;
2750 if (equal_pos)
2751 {
2752 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2753 if (equal_pos[1])
2754 value = equal_pos + 1;
2755 }
2756 else
2757 {
2758 key.SetCString(env_entry);
2759 }
2760 // Don't allow existing keys to be replaced with ones we get from the platform environment
2761 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2762 }
2763 }
2764 }
2765 }
2766 }
2767 }
2768 }
2769 }
2770 }
2771 Target *m_target;
2772 mutable bool m_got_host_env;
2773};
2774
Greg Claytonfbb76342013-11-20 21:07:01 +00002775//----------------------------------------------------------------------
2776// TargetProperties
2777//----------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +00002778TargetProperties::TargetProperties (Target *target) :
2779 Properties ()
2780{
2781 if (target)
2782 {
2783 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Caroline Ticedaccaa92010-09-20 20:44:43 +00002784 }
2785 else
Greg Clayton67cc0632012-08-22 17:17:09 +00002786 {
2787 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2788 m_collection_sp->Initialize(g_properties);
2789 m_collection_sp->AppendProperty(ConstString("process"),
2790 ConstString("Settings specify to processes."),
2791 true,
2792 Process::GetGlobalProperties()->GetValueProperties());
2793 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002794}
2795
Greg Clayton67cc0632012-08-22 17:17:09 +00002796TargetProperties::~TargetProperties ()
2797{
2798}
2799ArchSpec
2800TargetProperties::GetDefaultArchitecture () const
2801{
2802 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2803 if (value)
2804 return value->GetCurrentValue();
2805 return ArchSpec();
2806}
2807
2808void
2809TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2810{
2811 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2812 if (value)
2813 return value->SetCurrentValue(arch, true);
2814}
2815
2816lldb::DynamicValueType
2817TargetProperties::GetPreferDynamicValue() const
2818{
2819 const uint32_t idx = ePropertyPreferDynamic;
2820 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2821}
2822
2823bool
2824TargetProperties::GetDisableASLR () const
2825{
2826 const uint32_t idx = ePropertyDisableASLR;
2827 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2828}
2829
2830void
2831TargetProperties::SetDisableASLR (bool b)
2832{
2833 const uint32_t idx = ePropertyDisableASLR;
2834 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2835}
2836
2837bool
2838TargetProperties::GetDisableSTDIO () const
2839{
2840 const uint32_t idx = ePropertyDisableSTDIO;
2841 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2842}
2843
2844void
2845TargetProperties::SetDisableSTDIO (bool b)
2846{
2847 const uint32_t idx = ePropertyDisableSTDIO;
2848 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2849}
2850
Jim Ingham0f063ba2013-03-02 00:26:47 +00002851const char *
2852TargetProperties::GetDisassemblyFlavor () const
2853{
2854 const uint32_t idx = ePropertyDisassemblyFlavor;
2855 const char *return_value;
2856
2857 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2858 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
2859 return return_value;
2860}
2861
Greg Clayton1f746072012-08-29 21:13:06 +00002862InlineStrategy
2863TargetProperties::GetInlineStrategy () const
2864{
2865 const uint32_t idx = ePropertyInlineStrategy;
2866 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2867}
2868
Greg Clayton45392552012-10-17 22:57:12 +00002869const char *
2870TargetProperties::GetArg0 () const
2871{
2872 const uint32_t idx = ePropertyArg0;
2873 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
2874}
2875
2876void
2877TargetProperties::SetArg0 (const char *arg)
2878{
2879 const uint32_t idx = ePropertyArg0;
2880 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
2881}
2882
Greg Clayton67cc0632012-08-22 17:17:09 +00002883bool
2884TargetProperties::GetRunArguments (Args &args) const
2885{
2886 const uint32_t idx = ePropertyRunArgs;
2887 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
2888}
2889
2890void
2891TargetProperties::SetRunArguments (const Args &args)
2892{
2893 const uint32_t idx = ePropertyRunArgs;
2894 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
2895}
2896
2897size_t
2898TargetProperties::GetEnvironmentAsArgs (Args &env) const
2899{
2900 const uint32_t idx = ePropertyEnvVars;
2901 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
2902}
2903
2904bool
2905TargetProperties::GetSkipPrologue() const
2906{
2907 const uint32_t idx = ePropertySkipPrologue;
2908 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2909}
2910
2911PathMappingList &
2912TargetProperties::GetSourcePathMap () const
2913{
2914 const uint32_t idx = ePropertySourceMap;
2915 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
2916 assert(option_value);
2917 return option_value->GetCurrentValue();
2918}
2919
2920FileSpecList &
Greg Clayton6920b522012-08-22 18:39:03 +00002921TargetProperties::GetExecutableSearchPaths ()
Greg Clayton67cc0632012-08-22 17:17:09 +00002922{
2923 const uint32_t idx = ePropertyExecutableSearchPaths;
2924 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2925 assert(option_value);
2926 return option_value->GetCurrentValue();
2927}
2928
Michael Sartaina7499c92013-07-01 19:45:50 +00002929FileSpecList &
2930TargetProperties::GetDebugFileSearchPaths ()
2931{
2932 const uint32_t idx = ePropertyDebugFileSearchPaths;
2933 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2934 assert(option_value);
2935 return option_value->GetCurrentValue();
2936}
2937
Greg Clayton67cc0632012-08-22 17:17:09 +00002938bool
2939TargetProperties::GetEnableSyntheticValue () const
2940{
2941 const uint32_t idx = ePropertyEnableSynthetic;
2942 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2943}
2944
2945uint32_t
2946TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
2947{
2948 const uint32_t idx = ePropertyMaxChildrenCount;
2949 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2950}
2951
2952uint32_t
2953TargetProperties::GetMaximumSizeOfStringSummary() const
2954{
2955 const uint32_t idx = ePropertyMaxSummaryLength;
2956 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2957}
2958
Enrico Granatad325bf92013-06-04 22:54:16 +00002959uint32_t
2960TargetProperties::GetMaximumMemReadSize () const
2961{
2962 const uint32_t idx = ePropertyMaxMemReadSize;
2963 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2964}
2965
Greg Clayton67cc0632012-08-22 17:17:09 +00002966FileSpec
2967TargetProperties::GetStandardInputPath () const
2968{
2969 const uint32_t idx = ePropertyInputPath;
2970 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2971}
2972
2973void
2974TargetProperties::SetStandardInputPath (const char *p)
2975{
2976 const uint32_t idx = ePropertyInputPath;
2977 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2978}
2979
2980FileSpec
2981TargetProperties::GetStandardOutputPath () const
2982{
2983 const uint32_t idx = ePropertyOutputPath;
2984 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2985}
2986
2987void
2988TargetProperties::SetStandardOutputPath (const char *p)
2989{
2990 const uint32_t idx = ePropertyOutputPath;
2991 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2992}
2993
2994FileSpec
2995TargetProperties::GetStandardErrorPath () const
2996{
2997 const uint32_t idx = ePropertyErrorPath;
2998 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
2999}
3000
Greg Clayton6920b522012-08-22 18:39:03 +00003001const char *
3002TargetProperties::GetExpressionPrefixContentsAsCString ()
3003{
3004 const uint32_t idx = ePropertyExprPrefix;
3005 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
3006 if (file)
Jim Ingham1e4f4252012-08-22 21:21:16 +00003007 {
Greg Clayton0b0b5122012-08-30 18:15:10 +00003008 const bool null_terminate = true;
3009 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham1e4f4252012-08-22 21:21:16 +00003010 if (data_sp)
3011 return (const char *) data_sp->GetBytes();
3012 }
Greg Clayton6920b522012-08-22 18:39:03 +00003013 return NULL;
3014}
3015
Greg Clayton67cc0632012-08-22 17:17:09 +00003016void
3017TargetProperties::SetStandardErrorPath (const char *p)
3018{
3019 const uint32_t idx = ePropertyErrorPath;
3020 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
3021}
3022
3023bool
3024TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
3025{
3026 const uint32_t idx = ePropertyBreakpointUseAvoidList;
3027 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3028}
3029
Jim Ingham17d023f2013-03-13 17:58:04 +00003030bool
Daniel Malead79ae052013-08-07 21:54:09 +00003031TargetProperties::GetUseHexImmediates () const
3032{
3033 const uint32_t idx = ePropertyUseHexImmediates;
3034 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3035}
3036
3037bool
Jim Ingham17d023f2013-03-13 17:58:04 +00003038TargetProperties::GetUseFastStepping () const
3039{
3040 const uint32_t idx = ePropertyUseFastStepping;
3041 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3042}
3043
Greg Claytonfb6621e2013-12-06 21:59:52 +00003044bool
3045TargetProperties::GetDisplayExpressionsInCrashlogs () const
3046{
3047 const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
3048 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
3049}
3050
Enrico Granata397ddd52013-05-21 20:13:34 +00003051LoadScriptFromSymFile
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003052TargetProperties::GetLoadScriptFromSymbolFile () const
3053{
3054 const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
Enrico Granata397ddd52013-05-21 20:13:34 +00003055 return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
Enrico Granata2ea43cd2013-05-13 17:03:52 +00003056}
3057
Daniel Malead79ae052013-08-07 21:54:09 +00003058Disassembler::HexImmediateStyle
3059TargetProperties::GetHexImmediateStyle () const
3060{
3061 const uint32_t idx = ePropertyHexImmediateStyle;
3062 return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3063}
3064
Greg Claytonfd814c52013-08-13 01:42:25 +00003065MemoryModuleLoadLevel
3066TargetProperties::GetMemoryModuleLoadLevel() const
3067{
3068 const uint32_t idx = ePropertyMemoryModuleLoadLevel;
3069 return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
3070}
3071
3072
Greg Clayton67cc0632012-08-22 17:17:09 +00003073
Greg Claytonfbb76342013-11-20 21:07:01 +00003074//----------------------------------------------------------------------
3075// Target::TargetEventData
3076//----------------------------------------------------------------------
Jim Ingham4bddaeb2012-02-16 06:50:00 +00003077const ConstString &
3078Target::TargetEventData::GetFlavorString ()
3079{
3080 static ConstString g_flavor ("Target::TargetEventData");
3081 return g_flavor;
3082}
3083
3084const ConstString &
3085Target::TargetEventData::GetFlavor () const
3086{
3087 return TargetEventData::GetFlavorString ();
3088}
3089
3090Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
3091 EventData(),
3092 m_target_sp (new_target_sp)
3093{
3094}
3095
3096Target::TargetEventData::~TargetEventData()
3097{
3098
3099}
3100
3101void
3102Target::TargetEventData::Dump (Stream *s) const
3103{
3104
3105}
3106
3107const TargetSP
3108Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
3109{
3110 TargetSP target_sp;
3111
3112 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
3113 if (data)
3114 target_sp = data->m_target_sp;
3115
3116 return target_sp;
3117}
3118
3119const Target::TargetEventData *
3120Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3121{
3122 if (event_ptr)
3123 {
3124 const EventData *event_data = event_ptr->GetData();
3125 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3126 return static_cast <const TargetEventData *> (event_ptr->GetData());
3127 }
3128 return NULL;
3129}
3130