blob: 410d76ff9e6e5698ec5fad13e0c4b879e1fa3304 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham03c8ee52011-09-21 01:17:13 +000019#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton427f2902010-12-14 02:59:59 +000022#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Event.h"
24#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000026#include "lldb/Core/Timer.h"
27#include "lldb/Core/ValueObject.h"
Sean Callanandcf03f82011-11-15 22:27:19 +000028#include "lldb/Expression/ClangASTSource.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000029#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000031#include "lldb/Interpreter/CommandInterpreter.h"
32#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/lldb-private-log.h"
34#include "lldb/Symbol/ObjectFile.h"
35#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000036#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000037#include "lldb/Target/Thread.h"
38#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
Jim Ingham5a15e692012-02-16 06:50:00 +000043ConstString &
44Target::GetStaticBroadcasterClass ()
45{
46 static ConstString class_name ("lldb.target");
47 return class_name;
48}
49
Chris Lattner24943d22010-06-08 16:52:24 +000050//----------------------------------------------------------------------
51// Target constructor
52//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000053Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Jim Ingham5a15e692012-02-16 06:50:00 +000054 Broadcaster (&debugger, "lldb.target"),
Greg Clayton24bc5d92011-03-30 18:16:51 +000055 ExecutionContextScope (),
Greg Clayton334d33a2012-01-30 07:41:31 +000056 TargetInstanceSettings (GetSettingsController()),
Greg Clayton63094e02010-06-23 01:19:29 +000057 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000058 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000059 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000060 m_arch (target_arch),
61 m_images (),
Greg Claytoneea26402010-09-14 23:36:40 +000062 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000063 m_breakpoint_list (false),
64 m_internal_breakpoint_list (true),
Johnny Chenecd4feb2011-10-14 00:42:25 +000065 m_watchpoint_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000066 m_process_sp (),
67 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000068 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000069 m_scratch_ast_context_ap (NULL),
Sean Callanan4938bd62011-11-16 18:20:47 +000070 m_scratch_ast_source_ap (NULL),
71 m_ast_importer_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000072 m_persistent_variables (),
Jim Inghamcc637462011-09-13 00:29:56 +000073 m_source_manager(*this),
Greg Clayton24bc5d92011-03-30 18:16:51 +000074 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000075 m_stop_hook_next_id (0),
Enrico Granatadba1de82012-03-27 02:35:13 +000076 m_suppress_stop_hooks (false),
77 m_suppress_synthetic_value(false)
Chris Lattner24943d22010-06-08 16:52:24 +000078{
Greg Clayton49ce6822010-10-31 03:01:06 +000079 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
80 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
81 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham5a15e692012-02-16 06:50:00 +000082
83 CheckInWithManager();
Greg Clayton49ce6822010-10-31 03:01:06 +000084
Greg Claytone005f2c2010-11-06 01:53:30 +000085 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000086 if (log)
87 log->Printf ("%p Target::Target()", this);
88}
89
90//----------------------------------------------------------------------
91// Destructor
92//----------------------------------------------------------------------
93Target::~Target()
94{
Greg Claytone005f2c2010-11-06 01:53:30 +000095 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000096 if (log)
97 log->Printf ("%p Target::~Target()", this);
98 DeleteCurrentProcess ();
99}
100
101void
Caroline Tice7826c882010-10-26 03:11:13 +0000102Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +0000103{
Greg Clayton3fed8b92010-10-08 00:21:05 +0000104// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +0000105 if (description_level != lldb::eDescriptionLevelBrief)
106 {
107 s->Indent();
108 s->PutCString("Target\n");
109 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000110 m_images.Dump(s);
111 m_breakpoint_list.Dump(s);
112 m_internal_breakpoint_list.Dump(s);
113 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +0000114 }
115 else
116 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000117 Module *exe_module = GetExecutableModulePointer();
118 if (exe_module)
119 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000120 else
121 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000122 }
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125void
126Target::DeleteCurrentProcess ()
127{
128 if (m_process_sp.get())
129 {
Greg Clayton49480b12010-09-14 23:52:43 +0000130 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000131 if (m_process_sp->IsAlive())
132 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000133
134 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000135
136 // Do any cleanup of the target we need to do between process instances.
137 // NB It is better to do this before destroying the process in case the
138 // clean up needs some help from the process.
139 m_breakpoint_list.ClearAllBreakpointSites();
140 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000141 // Disable watchpoints just on the debugger side.
Johnny Chen116a5cd2012-02-25 06:44:30 +0000142 Mutex::Locker locker;
143 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000144 DisableAllWatchpoints(false);
Johnny Chen116a5cd2012-02-25 06:44:30 +0000145 ClearAllWatchpointHitCounts();
Chris Lattner24943d22010-06-08 16:52:24 +0000146 m_process_sp.reset();
147 }
148}
149
150const lldb::ProcessSP &
Greg Clayton46c9a352012-02-09 06:16:32 +0000151Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner24943d22010-06-08 16:52:24 +0000152{
153 DeleteCurrentProcess ();
Greg Clayton46c9a352012-02-09 06:16:32 +0000154 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner24943d22010-06-08 16:52:24 +0000155 return m_process_sp;
156}
157
158const lldb::ProcessSP &
159Target::GetProcessSP () const
160{
161 return m_process_sp;
162}
163
Greg Clayton153ccd72011-08-10 02:10:13 +0000164void
165Target::Destroy()
166{
167 Mutex::Locker locker (m_mutex);
168 DeleteCurrentProcess ();
169 m_platform_sp.reset();
170 m_arch.Clear();
171 m_images.Clear();
172 m_section_load_list.Clear();
173 const bool notify = false;
174 m_breakpoint_list.RemoveAll(notify);
175 m_internal_breakpoint_list.RemoveAll(notify);
176 m_last_created_breakpoint.reset();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000177 m_last_created_watchpoint.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000178 m_search_filter_sp.reset();
179 m_image_search_paths.Clear(notify);
180 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000181 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000182 m_ast_importer_ap.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000183 m_persistent_variables.Clear();
184 m_stop_hooks.clear();
185 m_stop_hook_next_id = 0;
186 m_suppress_stop_hooks = false;
Enrico Granatadba1de82012-03-27 02:35:13 +0000187 m_suppress_synthetic_value = false;
Greg Clayton153ccd72011-08-10 02:10:13 +0000188}
189
190
Chris Lattner24943d22010-06-08 16:52:24 +0000191BreakpointList &
192Target::GetBreakpointList(bool internal)
193{
194 if (internal)
195 return m_internal_breakpoint_list;
196 else
197 return m_breakpoint_list;
198}
199
200const BreakpointList &
201Target::GetBreakpointList(bool internal) const
202{
203 if (internal)
204 return m_internal_breakpoint_list;
205 else
206 return m_breakpoint_list;
207}
208
209BreakpointSP
210Target::GetBreakpointByID (break_id_t break_id)
211{
212 BreakpointSP bp_sp;
213
214 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
215 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
216 else
217 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
218
219 return bp_sp;
220}
221
222BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000223Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
224 const FileSpecList *source_file_spec_list,
Jim Ingham03c8ee52011-09-21 01:17:13 +0000225 RegularExpression &source_regex,
226 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000227{
Jim Inghamd6d47972011-09-23 00:54:11 +0000228 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
229 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000230 return CreateBreakpoint (filter_sp, resolver_sp, internal);
231}
232
233
234BreakpointSP
235Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
236{
237 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Chris Lattner24943d22010-06-08 16:52:24 +0000238 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
239 return CreateBreakpoint (filter_sp, resolver_sp, internal);
240}
241
242
243BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000244Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000245{
Chris Lattner24943d22010-06-08 16:52:24 +0000246 Address so_addr;
247 // Attempt to resolve our load address if possible, though it is ok if
248 // it doesn't resolve to section/offset.
249
Greg Clayton33ed1702010-08-24 00:45:41 +0000250 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000251 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000252 if (!so_addr.IsValid())
253 {
254 // The address didn't resolve, so just set this as an absolute address
255 so_addr.SetOffset (addr);
256 }
257 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000258 return bp_sp;
259}
260
261BreakpointSP
262Target::CreateBreakpoint (Address &addr, bool internal)
263{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000264 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000265 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
266 return CreateBreakpoint (filter_sp, resolver_sp, internal);
267}
268
269BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000270Target::CreateBreakpoint (const FileSpecList *containingModules,
271 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000272 const char *func_name,
273 uint32_t func_name_type_mask,
274 bool internal,
275 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000276{
Greg Clayton12bec712010-06-28 21:30:43 +0000277 BreakpointSP bp_sp;
278 if (func_name)
279 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000280 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000281
282 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
283 func_name,
284 func_name_type_mask,
285 Breakpoint::Exact,
286 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton12bec712010-06-28 21:30:43 +0000287 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
288 }
289 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000290}
291
Jim Ingham4722b102012-03-06 00:37:27 +0000292lldb::BreakpointSP
293Target::CreateBreakpoint (const FileSpecList *containingModules,
294 const FileSpecList *containingSourceFiles,
295 std::vector<std::string> func_names,
296 uint32_t func_name_type_mask,
297 bool internal,
298 LazyBool skip_prologue)
299{
300 BreakpointSP bp_sp;
301 size_t num_names = func_names.size();
302 if (num_names > 0)
303 {
304 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
305
306 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
307 func_names,
308 func_name_type_mask,
309 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
310 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
311 }
312 return bp_sp;
313}
314
Jim Inghamc1053622012-03-03 02:05:11 +0000315BreakpointSP
316Target::CreateBreakpoint (const FileSpecList *containingModules,
317 const FileSpecList *containingSourceFiles,
318 const char *func_names[],
319 size_t num_names,
320 uint32_t func_name_type_mask,
321 bool internal,
322 LazyBool skip_prologue)
323{
324 BreakpointSP bp_sp;
325 if (num_names > 0)
326 {
327 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
328
329 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
330 func_names,
331 num_names,
Jim Ingham4722b102012-03-06 00:37:27 +0000332 func_name_type_mask,
Jim Inghamc1053622012-03-03 02:05:11 +0000333 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
334 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
335 }
336 return bp_sp;
337}
Chris Lattner24943d22010-06-08 16:52:24 +0000338
339SearchFilterSP
340Target::GetSearchFilterForModule (const FileSpec *containingModule)
341{
342 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000343 if (containingModule != NULL)
344 {
345 // TODO: We should look into sharing module based search filters
346 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000347 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000348 }
349 else
350 {
351 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000352 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000353 filter_sp = m_search_filter_sp;
354 }
355 return filter_sp;
356}
357
Jim Ingham03c8ee52011-09-21 01:17:13 +0000358SearchFilterSP
359Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
360{
361 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000362 if (containingModules && containingModules->GetSize() != 0)
363 {
364 // TODO: We should look into sharing module based search filters
365 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000366 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000367 }
368 else
369 {
370 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000371 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000372 filter_sp = m_search_filter_sp;
373 }
374 return filter_sp;
375}
376
Jim Inghamd6d47972011-09-23 00:54:11 +0000377SearchFilterSP
378Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
379{
380 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
381 return GetSearchFilterForModuleList(containingModules);
382
383 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000384 if (containingModules == NULL)
385 {
386 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
387 // but that will take a little reworking.
388
Greg Clayton13d24fb2012-01-29 20:56:30 +0000389 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000390 }
391 else
392 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000393 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000394 }
395 return filter_sp;
396}
397
Chris Lattner24943d22010-06-08 16:52:24 +0000398BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000399Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
400 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000401 RegularExpression &func_regex,
402 bool internal,
403 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000404{
Jim Inghamd6d47972011-09-23 00:54:11 +0000405 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000406 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
407 func_regex,
408 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000409
410 return CreateBreakpoint (filter_sp, resolver_sp, internal);
411}
412
Jim Ingham3df164e2012-03-05 04:47:34 +0000413lldb::BreakpointSP
414Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
415{
416 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
417}
418
Chris Lattner24943d22010-06-08 16:52:24 +0000419BreakpointSP
420Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
421{
422 BreakpointSP bp_sp;
423 if (filter_sp && resolver_sp)
424 {
425 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
426 resolver_sp->SetBreakpoint (bp_sp.get());
427
428 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000429 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000430 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000431 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000432
Greg Claytone005f2c2010-11-06 01:53:30 +0000433 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000434 if (log)
435 {
436 StreamString s;
437 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
438 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
439 }
440
Chris Lattner24943d22010-06-08 16:52:24 +0000441 bp_sp->ResolveBreakpoint();
442 }
Jim Inghamd1686902010-10-14 23:45:03 +0000443
444 if (!internal && bp_sp)
445 {
446 m_last_created_breakpoint = bp_sp;
447 }
448
Chris Lattner24943d22010-06-08 16:52:24 +0000449 return bp_sp;
450}
451
Johnny Chenda5a8022011-09-20 23:28:55 +0000452bool
453Target::ProcessIsValid()
454{
455 return (m_process_sp && m_process_sp->IsAlive());
456}
457
Johnny Chenecd4feb2011-10-14 00:42:25 +0000458// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000459// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000460WatchpointSP
461Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen34bbf852011-09-12 23:38:44 +0000462{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000463 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
464 if (log)
465 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
466 __FUNCTION__, addr, size, type);
467
Johnny Chenecd4feb2011-10-14 00:42:25 +0000468 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000469 if (!ProcessIsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000470 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000471 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenecd4feb2011-10-14 00:42:25 +0000472 return wp_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000473
Johnny Chenecd4feb2011-10-14 00:42:25 +0000474 // Currently we only support one watchpoint per address, with total number
475 // of watchpoints limited by the hardware which the inferior is running on.
476 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000477 if (matched_sp)
478 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000479 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000480 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000481 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
482 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000483 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000484 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000485 wp_sp = matched_sp;
486 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000487 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000488 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000489 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000490 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000491 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000492 }
493
Johnny Chenecd4feb2011-10-14 00:42:25 +0000494 if (!wp_sp) {
495 Watchpoint *new_wp = new Watchpoint(addr, size);
496 if (!new_wp) {
497 printf("Watchpoint ctor failed, out of memory?\n");
498 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000499 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000500 new_wp->SetWatchpointType(type);
501 new_wp->SetTarget(this);
502 wp_sp.reset(new_wp);
503 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000504 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000505
Johnny Chenecd4feb2011-10-14 00:42:25 +0000506 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000507 if (log)
508 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
509 __FUNCTION__,
510 rc.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000511 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000512
Johnny Chen155599b2012-03-26 22:00:10 +0000513 if (rc.Fail()) {
514 // Enabling the watchpoint on the device side failed.
515 // Remove the said watchpoint from the list maintained by the target instance.
516 m_watchpoint_list.Remove(wp_sp->GetID());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000517 wp_sp.reset();
Johnny Chen155599b2012-03-26 22:00:10 +0000518 }
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000519 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000520 m_last_created_watchpoint = wp_sp;
521 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000522}
523
Chris Lattner24943d22010-06-08 16:52:24 +0000524void
525Target::RemoveAllBreakpoints (bool internal_also)
526{
Greg Claytone005f2c2010-11-06 01:53:30 +0000527 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000528 if (log)
529 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
530
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000531 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000532 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000533 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000534
535 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000536}
537
538void
539Target::DisableAllBreakpoints (bool internal_also)
540{
Greg Claytone005f2c2010-11-06 01:53:30 +0000541 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000542 if (log)
543 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
544
545 m_breakpoint_list.SetEnabledAll (false);
546 if (internal_also)
547 m_internal_breakpoint_list.SetEnabledAll (false);
548}
549
550void
551Target::EnableAllBreakpoints (bool internal_also)
552{
Greg Claytone005f2c2010-11-06 01:53:30 +0000553 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000554 if (log)
555 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
556
557 m_breakpoint_list.SetEnabledAll (true);
558 if (internal_also)
559 m_internal_breakpoint_list.SetEnabledAll (true);
560}
561
562bool
563Target::RemoveBreakpointByID (break_id_t break_id)
564{
Greg Claytone005f2c2010-11-06 01:53:30 +0000565 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000566 if (log)
567 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
568
569 if (DisableBreakpointByID (break_id))
570 {
571 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000572 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000573 else
Jim Inghamd1686902010-10-14 23:45:03 +0000574 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000575 if (m_last_created_breakpoint)
576 {
577 if (m_last_created_breakpoint->GetID() == break_id)
578 m_last_created_breakpoint.reset();
579 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000580 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000581 }
Chris Lattner24943d22010-06-08 16:52:24 +0000582 return true;
583 }
584 return false;
585}
586
587bool
588Target::DisableBreakpointByID (break_id_t break_id)
589{
Greg Claytone005f2c2010-11-06 01:53:30 +0000590 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000591 if (log)
592 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
593
594 BreakpointSP bp_sp;
595
596 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
597 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
598 else
599 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
600 if (bp_sp)
601 {
602 bp_sp->SetEnabled (false);
603 return true;
604 }
605 return false;
606}
607
608bool
609Target::EnableBreakpointByID (break_id_t break_id)
610{
Greg Claytone005f2c2010-11-06 01:53:30 +0000611 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000612 if (log)
613 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
614 __FUNCTION__,
615 break_id,
616 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
617
618 BreakpointSP bp_sp;
619
620 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
621 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
622 else
623 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
624
625 if (bp_sp)
626 {
627 bp_sp->SetEnabled (true);
628 return true;
629 }
630 return false;
631}
632
Johnny Chenc86582f2011-09-23 21:21:43 +0000633// The flag 'end_to_end', default to true, signifies that the operation is
634// performed end to end, for both the debugger and the debuggee.
635
Johnny Chenecd4feb2011-10-14 00:42:25 +0000636// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
637// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000638bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000639Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000640{
641 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
642 if (log)
643 log->Printf ("Target::%s\n", __FUNCTION__);
644
Johnny Chenc86582f2011-09-23 21:21:43 +0000645 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000646 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000647 return true;
648 }
649
650 // Otherwise, it's an end to end operation.
651
Johnny Chenda5a8022011-09-20 23:28:55 +0000652 if (!ProcessIsValid())
653 return false;
654
Johnny Chenecd4feb2011-10-14 00:42:25 +0000655 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000656 for (size_t i = 0; i < num_watchpoints; ++i)
657 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000658 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
659 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000660 return false;
661
Johnny Chenecd4feb2011-10-14 00:42:25 +0000662 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000663 if (rc.Fail())
664 return false;
665 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000666 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000667 return true; // Success!
668}
669
Johnny Chenecd4feb2011-10-14 00:42:25 +0000670// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
671// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000672bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000673Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000674{
675 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
676 if (log)
677 log->Printf ("Target::%s\n", __FUNCTION__);
678
Johnny Chenc86582f2011-09-23 21:21:43 +0000679 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000680 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000681 return true;
682 }
683
684 // Otherwise, it's an end to end operation.
685
Johnny Chenda5a8022011-09-20 23:28:55 +0000686 if (!ProcessIsValid())
687 return false;
688
Johnny Chenecd4feb2011-10-14 00:42:25 +0000689 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000690 for (size_t i = 0; i < num_watchpoints; ++i)
691 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000692 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
693 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000694 return false;
695
Johnny Chenecd4feb2011-10-14 00:42:25 +0000696 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000697 if (rc.Fail())
698 return false;
699 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000700 return true; // Success!
701}
702
Johnny Chenecd4feb2011-10-14 00:42:25 +0000703// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
704// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000705bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000706Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000707{
708 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
709 if (log)
710 log->Printf ("Target::%s\n", __FUNCTION__);
711
Johnny Chenc86582f2011-09-23 21:21:43 +0000712 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000713 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000714 return true;
715 }
716
717 // Otherwise, it's an end to end operation.
718
Johnny Chenda5a8022011-09-20 23:28:55 +0000719 if (!ProcessIsValid())
720 return false;
721
Johnny Chenecd4feb2011-10-14 00:42:25 +0000722 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000723 for (size_t i = 0; i < num_watchpoints; ++i)
724 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000725 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
726 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000727 return false;
728
Johnny Chenecd4feb2011-10-14 00:42:25 +0000729 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000730 if (rc.Fail())
731 return false;
732 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000733 return true; // Success!
734}
735
Johnny Chen116a5cd2012-02-25 06:44:30 +0000736// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
737bool
738Target::ClearAllWatchpointHitCounts ()
739{
740 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
741 if (log)
742 log->Printf ("Target::%s\n", __FUNCTION__);
743
744 size_t num_watchpoints = m_watchpoint_list.GetSize();
745 for (size_t i = 0; i < num_watchpoints; ++i)
746 {
747 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
748 if (!wp_sp)
749 return false;
750
751 wp_sp->ResetHitCount();
752 }
753 return true; // Success!
754}
755
Johnny Chenecd4feb2011-10-14 00:42:25 +0000756// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000757// during these operations.
758bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000759Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000760{
761 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
762 if (log)
763 log->Printf ("Target::%s\n", __FUNCTION__);
764
765 if (!ProcessIsValid())
766 return false;
767
Johnny Chenecd4feb2011-10-14 00:42:25 +0000768 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000769 for (size_t i = 0; i < num_watchpoints; ++i)
770 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000771 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
772 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000773 return false;
774
Johnny Chenecd4feb2011-10-14 00:42:25 +0000775 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000776 }
777 return true; // Success!
778}
779
Johnny Chenecd4feb2011-10-14 00:42:25 +0000780// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000781bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000782Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000783{
784 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
785 if (log)
786 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
787
788 if (!ProcessIsValid())
789 return false;
790
Johnny Chenecd4feb2011-10-14 00:42:25 +0000791 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
792 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000793 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000794 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000795 if (rc.Success())
796 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000797
Johnny Chen01acfa72011-09-22 18:04:58 +0000798 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000799 }
800 return false;
801}
802
Johnny Chenecd4feb2011-10-14 00:42:25 +0000803// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000804bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000805Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000806{
807 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
808 if (log)
809 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
810
811 if (!ProcessIsValid())
812 return false;
813
Johnny Chenecd4feb2011-10-14 00:42:25 +0000814 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
815 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000816 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000817 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000818 if (rc.Success())
819 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000820
Johnny Chen01acfa72011-09-22 18:04:58 +0000821 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000822 }
823 return false;
824}
825
Johnny Chenecd4feb2011-10-14 00:42:25 +0000826// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000827bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000828Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000829{
830 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
831 if (log)
832 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
833
Johnny Chenecd4feb2011-10-14 00:42:25 +0000834 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000835 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000836 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000837 return true;
838 }
839 return false;
840}
841
Johnny Chenecd4feb2011-10-14 00:42:25 +0000842// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000843bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000844Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000845{
846 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
847 if (log)
848 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
849
850 if (!ProcessIsValid())
851 return false;
852
Johnny Chenecd4feb2011-10-14 00:42:25 +0000853 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
854 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000855 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000856 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000857 return true;
858 }
859 return false;
860}
861
Chris Lattner24943d22010-06-08 16:52:24 +0000862ModuleSP
863Target::GetExecutableModule ()
864{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000865 return m_images.GetModuleAtIndex(0);
866}
867
868Module*
869Target::GetExecutableModulePointer ()
870{
871 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000872}
873
874void
875Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
876{
877 m_images.Clear();
878 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000879 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000880 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000881
882 if (executable_sp.get())
883 {
884 Timer scoped_timer (__PRETTY_FUNCTION__,
885 "Target::SetExecutableModule (executable = '%s/%s')",
886 executable_sp->GetFileSpec().GetDirectory().AsCString(),
887 executable_sp->GetFileSpec().GetFilename().AsCString());
888
889 m_images.Append(executable_sp); // The first image is our exectuable file
890
Jim Ingham7508e732010-08-09 23:31:02 +0000891 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000892 if (!m_arch.IsValid())
893 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000894
Chris Lattner24943d22010-06-08 16:52:24 +0000895 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000896 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000897
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000898 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000899 {
900 executable_objfile->GetDependentModules(dependent_files);
901 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
902 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000903 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
904 FileSpec platform_dependent_file_spec;
905 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000906 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000907 else
908 platform_dependent_file_spec = dependent_file_spec;
909
Greg Clayton444fe992012-02-26 05:51:37 +0000910 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
911 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +0000912 if (image_module_sp.get())
913 {
Chris Lattner24943d22010-06-08 16:52:24 +0000914 ObjectFile *objfile = image_module_sp->GetObjectFile();
915 if (objfile)
916 objfile->GetDependentModules(dependent_files);
917 }
918 }
919 }
Chris Lattner24943d22010-06-08 16:52:24 +0000920 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000921
922 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000923}
924
925
Jim Ingham7508e732010-08-09 23:31:02 +0000926bool
927Target::SetArchitecture (const ArchSpec &arch_spec)
928{
Greg Claytonb170aee2012-05-08 01:45:38 +0000929 if (m_arch == arch_spec || !m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000930 {
Greg Claytonb170aee2012-05-08 01:45:38 +0000931 // If we haven't got a valid arch spec, or the architectures are
932 // compatible, so just update the architecture. Architectures can be
933 // equal, yet the triple OS and vendor might change, so we need to do
934 // the assignment here just in case.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000935 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000936 return true;
937 }
938 else
939 {
940 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000941 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000942 ModuleSP executable_sp = GetExecutableModule ();
943 m_images.Clear();
944 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000945 m_scratch_ast_source_ap.reset();
946 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000947 // Need to do something about unsetting breakpoints.
948
949 if (executable_sp)
950 {
Greg Clayton444fe992012-02-26 05:51:37 +0000951 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
952 Error error = ModuleList::GetSharedModule (module_spec,
953 executable_sp,
954 &GetExecutableSearchPaths(),
955 NULL,
956 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +0000957
958 if (!error.Fail() && executable_sp)
959 {
960 SetExecutableModule (executable_sp, true);
961 return true;
962 }
Jim Ingham7508e732010-08-09 23:31:02 +0000963 }
964 }
Greg Claytonb170aee2012-05-08 01:45:38 +0000965 return false;
Jim Ingham7508e732010-08-09 23:31:02 +0000966}
Chris Lattner24943d22010-06-08 16:52:24 +0000967
Chris Lattner24943d22010-06-08 16:52:24 +0000968void
969Target::ModuleAdded (ModuleSP &module_sp)
970{
971 // A module is being added to this target for the first time
972 ModuleList module_list;
973 module_list.Append(module_sp);
974 ModulesDidLoad (module_list);
975}
976
977void
978Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
979{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000980 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000981 ModuleList module_list;
982 module_list.Append (old_module_sp);
983 ModulesDidUnload (module_list);
984 module_list.Clear ();
985 module_list.Append (new_module_sp);
986 ModulesDidLoad (module_list);
987}
988
989void
990Target::ModulesDidLoad (ModuleList &module_list)
991{
992 m_breakpoint_list.UpdateBreakpoints (module_list, true);
993 // TODO: make event data that packages up the module_list
994 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
995}
996
997void
998Target::ModulesDidUnload (ModuleList &module_list)
999{
1000 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +00001001
1002 // Remove the images from the target image list
1003 m_images.Remove(module_list);
1004
Chris Lattner24943d22010-06-08 16:52:24 +00001005 // TODO: make event data that packages up the module_list
1006 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1007}
1008
Jim Ingham7089d8a2011-10-28 23:14:11 +00001009
Daniel Dunbar705a0982011-10-31 22:50:37 +00001010bool
Greg Clayton444fe992012-02-26 05:51:37 +00001011Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +00001012{
1013
1014 if (!m_breakpoints_use_platform_avoid)
1015 return false;
1016 else
1017 {
1018 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001019 ModuleSpec module_spec (module_file_spec);
1020 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001021
1022 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1023 // black list.
1024 if (num_modules > 0)
1025 {
1026 for (int i = 0; i < num_modules; i++)
1027 {
1028 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1029 return false;
1030 }
1031 return true;
1032 }
1033 else
1034 return false;
1035 }
1036}
1037
Daniel Dunbar705a0982011-10-31 22:50:37 +00001038bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001039Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1040{
1041 if (!m_breakpoints_use_platform_avoid)
1042 return false;
1043 else if (GetPlatform())
1044 {
1045 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
1046 }
1047 else
1048 return false;
1049}
1050
Chris Lattner24943d22010-06-08 16:52:24 +00001051size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001052Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1053{
Greg Clayton3508c382012-02-24 01:59:29 +00001054 SectionSP section_sp (addr.GetSection());
1055 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001056 {
Jason Molenda6b028d62012-04-25 00:06:56 +00001057 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1058 if (section_sp->IsEncrypted())
1059 {
1060 return 0;
1061 }
Greg Clayton3508c382012-02-24 01:59:29 +00001062 ModuleSP module_sp (section_sp->GetModule());
1063 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001064 {
Greg Clayton3508c382012-02-24 01:59:29 +00001065 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1066 if (objfile)
1067 {
1068 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1069 addr.GetOffset(),
1070 dst,
1071 dst_len);
1072 if (bytes_read > 0)
1073 return bytes_read;
1074 else
1075 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1076 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001077 else
Greg Clayton3508c382012-02-24 01:59:29 +00001078 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001079 }
1080 else
Greg Clayton3508c382012-02-24 01:59:29 +00001081 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001082 }
1083 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001084 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001085
Greg Clayton26100dc2011-01-07 01:57:07 +00001086 return 0;
1087}
1088
1089size_t
Enrico Granata91544802011-09-06 19:20:51 +00001090Target::ReadMemory (const Address& addr,
1091 bool prefer_file_cache,
1092 void *dst,
1093 size_t dst_len,
1094 Error &error,
1095 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001096{
Chris Lattner24943d22010-06-08 16:52:24 +00001097 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001098
Enrico Granata91544802011-09-06 19:20:51 +00001099 // if we end up reading this from process memory, we will fill this
1100 // with the actual load address
1101 if (load_addr_ptr)
1102 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1103
Greg Clayton26100dc2011-01-07 01:57:07 +00001104 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001105
1106 addr_t load_addr = LLDB_INVALID_ADDRESS;
1107 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001108 Address resolved_addr;
1109 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001110 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001111 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001112 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001113 // No sections are loaded, so we must assume we are not running
1114 // yet and anything we are given is a file address.
1115 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1116 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001117 }
Greg Clayton70436352010-06-30 23:03:03 +00001118 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001119 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001120 // We have at least one section loaded. This can be becuase
1121 // we have manually loaded some sections with "target modules load ..."
1122 // or because we have have a live process that has sections loaded
1123 // through the dynamic loader
1124 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1125 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001126 }
Greg Clayton70436352010-06-30 23:03:03 +00001127 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001128 if (!resolved_addr.IsValid())
1129 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001130
Greg Clayton9b82f862011-07-11 05:12:02 +00001131
Greg Clayton26100dc2011-01-07 01:57:07 +00001132 if (prefer_file_cache)
1133 {
1134 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1135 if (bytes_read > 0)
1136 return bytes_read;
1137 }
Greg Clayton70436352010-06-30 23:03:03 +00001138
Johnny Chenda5a8022011-09-20 23:28:55 +00001139 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001140 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001141 if (load_addr == LLDB_INVALID_ADDRESS)
1142 load_addr = resolved_addr.GetLoadAddress (this);
1143
Greg Clayton70436352010-06-30 23:03:03 +00001144 if (load_addr == LLDB_INVALID_ADDRESS)
1145 {
Greg Clayton3508c382012-02-24 01:59:29 +00001146 ModuleSP addr_module_sp (resolved_addr.GetModule());
1147 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001148 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001149 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001150 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001151 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001152 else
Greg Clayton9c236732011-10-26 00:56:27 +00001153 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001154 }
1155 else
1156 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001157 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001158 if (bytes_read != dst_len)
1159 {
1160 if (error.Success())
1161 {
1162 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001163 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001164 else
Greg Clayton9c236732011-10-26 00:56:27 +00001165 error.SetErrorStringWithFormat("only %zu of %zu bytes were read from memory at 0x%llx", bytes_read, dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001166 }
1167 }
Greg Clayton70436352010-06-30 23:03:03 +00001168 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001169 {
1170 if (load_addr_ptr)
1171 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001172 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001173 }
Greg Clayton70436352010-06-30 23:03:03 +00001174 // If the address is not section offset we have an address that
1175 // doesn't resolve to any address in any currently loaded shared
1176 // libaries and we failed to read memory so there isn't anything
1177 // more we can do. If it is section offset, we might be able to
1178 // read cached memory from the object file.
1179 if (!resolved_addr.IsSectionOffset())
1180 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001181 }
Chris Lattner24943d22010-06-08 16:52:24 +00001182 }
Greg Clayton70436352010-06-30 23:03:03 +00001183
Greg Clayton9b82f862011-07-11 05:12:02 +00001184 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001185 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001186 // If we didn't already try and read from the object file cache, then
1187 // try it after failing to read from the process.
1188 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001189 }
1190 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001191}
1192
Greg Clayton7dd98df2011-07-12 17:06:17 +00001193size_t
1194Target::ReadScalarIntegerFromMemory (const Address& addr,
1195 bool prefer_file_cache,
1196 uint32_t byte_size,
1197 bool is_signed,
1198 Scalar &scalar,
1199 Error &error)
1200{
1201 uint64_t uval;
1202
1203 if (byte_size <= sizeof(uval))
1204 {
1205 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1206 if (bytes_read == byte_size)
1207 {
1208 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1209 uint32_t offset = 0;
1210 if (byte_size <= 4)
1211 scalar = data.GetMaxU32 (&offset, byte_size);
1212 else
1213 scalar = data.GetMaxU64 (&offset, byte_size);
1214
1215 if (is_signed)
1216 scalar.SignExtend(byte_size * 8);
1217 return bytes_read;
1218 }
1219 }
1220 else
1221 {
1222 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1223 }
1224 return 0;
1225}
1226
1227uint64_t
1228Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1229 bool prefer_file_cache,
1230 size_t integer_byte_size,
1231 uint64_t fail_value,
1232 Error &error)
1233{
1234 Scalar scalar;
1235 if (ReadScalarIntegerFromMemory (addr,
1236 prefer_file_cache,
1237 integer_byte_size,
1238 false,
1239 scalar,
1240 error))
1241 return scalar.ULongLong(fail_value);
1242 return fail_value;
1243}
1244
1245bool
1246Target::ReadPointerFromMemory (const Address& addr,
1247 bool prefer_file_cache,
1248 Error &error,
1249 Address &pointer_addr)
1250{
1251 Scalar scalar;
1252 if (ReadScalarIntegerFromMemory (addr,
1253 prefer_file_cache,
1254 m_arch.GetAddressByteSize(),
1255 false,
1256 scalar,
1257 error))
1258 {
1259 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1260 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1261 {
1262 if (m_section_load_list.IsEmpty())
1263 {
1264 // No sections are loaded, so we must assume we are not running
1265 // yet and anything we are given is a file address.
1266 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1267 }
1268 else
1269 {
1270 // We have at least one section loaded. This can be becuase
1271 // we have manually loaded some sections with "target modules load ..."
1272 // or because we have have a live process that has sections loaded
1273 // through the dynamic loader
1274 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1275 }
1276 // We weren't able to resolve the pointer value, so just return
1277 // an address with no section
1278 if (!pointer_addr.IsValid())
1279 pointer_addr.SetOffset (pointer_vm_addr);
1280 return true;
1281
1282 }
1283 }
1284 return false;
1285}
Chris Lattner24943d22010-06-08 16:52:24 +00001286
1287ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001288Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001289{
1290 // Don't pass in the UUID so we can tell if we have a stale value in our list
1291 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1292 bool did_create_module = false;
1293 ModuleSP module_sp;
1294
Chris Lattner24943d22010-06-08 16:52:24 +00001295 Error error;
1296
Greg Clayton24bc5d92011-03-30 18:16:51 +00001297 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +00001298 if (m_image_search_paths.GetSize())
1299 {
Greg Clayton444fe992012-02-26 05:51:37 +00001300 ModuleSpec transformed_spec (module_spec);
1301 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
Chris Lattner24943d22010-06-08 16:52:24 +00001302 {
Greg Clayton444fe992012-02-26 05:51:37 +00001303 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
Greg Clayton9ce95382012-02-13 23:10:39 +00001304 error = ModuleList::GetSharedModule (transformed_spec,
Greg Clayton9ce95382012-02-13 23:10:39 +00001305 module_sp,
1306 &GetExecutableSearchPaths(),
1307 &old_module_sp,
1308 &did_create_module);
Chris Lattner24943d22010-06-08 16:52:24 +00001309 }
1310 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001311
1312 if (!module_sp)
1313 {
1314 // If we have a UUID, we can check our global shared module list in case
1315 // we already have it. If we don't have a valid UUID, then we can't since
1316 // the path in "module_spec" will be a platform path, and we will need to
1317 // let the platform find that file. For example, we could be asking for
1318 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1319 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1320 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1321 // cache.
1322 if (module_spec.GetUUID().IsValid())
1323 {
1324 // We have a UUID, it is OK to check the global module list...
1325 error = ModuleList::GetSharedModule (module_spec,
1326 module_sp,
1327 &GetExecutableSearchPaths(),
1328 &old_module_sp,
1329 &did_create_module);
1330 }
Chris Lattner24943d22010-06-08 16:52:24 +00001331
Greg Claytone1ef1e32012-04-27 00:58:27 +00001332 if (!module_sp)
1333 {
1334 // The platform is responsible for finding and caching an appropriate
1335 // module in the shared module cache.
1336 if (m_platform_sp)
1337 {
1338 FileSpec platform_file_spec;
1339 error = m_platform_sp->GetSharedModule (module_spec,
1340 module_sp,
1341 &GetExecutableSearchPaths(),
1342 &old_module_sp,
1343 &did_create_module);
1344 }
1345 else
1346 {
1347 error.SetErrorString("no platform is currently set");
1348 }
1349 }
Chris Lattner24943d22010-06-08 16:52:24 +00001350 }
1351
Greg Clayton24bc5d92011-03-30 18:16:51 +00001352 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +00001353 if (module_sp)
1354 {
1355 m_images.Append (module_sp);
1356 if (did_create_module)
1357 {
1358 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1359 ModuleUpdated(old_module_sp, module_sp);
1360 else
1361 ModuleAdded(module_sp);
1362 }
1363 }
1364 if (error_ptr)
1365 *error_ptr = error;
1366 return module_sp;
1367}
1368
1369
Greg Clayton289afcb2012-02-18 05:35:26 +00001370TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001371Target::CalculateTarget ()
1372{
Greg Clayton289afcb2012-02-18 05:35:26 +00001373 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001374}
1375
Greg Clayton289afcb2012-02-18 05:35:26 +00001376ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001377Target::CalculateProcess ()
1378{
Greg Clayton289afcb2012-02-18 05:35:26 +00001379 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001380}
1381
Greg Clayton289afcb2012-02-18 05:35:26 +00001382ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001383Target::CalculateThread ()
1384{
Greg Clayton289afcb2012-02-18 05:35:26 +00001385 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001386}
1387
Greg Clayton289afcb2012-02-18 05:35:26 +00001388StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001389Target::CalculateStackFrame ()
1390{
Greg Clayton289afcb2012-02-18 05:35:26 +00001391 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001392}
1393
1394void
Greg Claytona830adb2010-10-04 01:05:56 +00001395Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001396{
Greg Clayton567e7f32011-09-22 04:58:26 +00001397 exe_ctx.Clear();
1398 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001399}
1400
1401PathMappingList &
1402Target::GetImageSearchPathList ()
1403{
1404 return m_image_search_paths;
1405}
1406
1407void
1408Target::ImageSearchPathsChanged
1409(
1410 const PathMappingList &path_list,
1411 void *baton
1412)
1413{
1414 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001415 ModuleSP exe_module_sp (target->GetExecutableModule());
1416 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001417 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001418 target->m_images.Clear();
1419 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001420 }
1421}
1422
1423ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001424Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001425{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001426 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001427 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001428 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001429 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001430 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001431 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1432 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1433 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1434 }
Chris Lattner24943d22010-06-08 16:52:24 +00001435 return m_scratch_ast_context_ap.get();
1436}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001437
Sean Callanan4938bd62011-11-16 18:20:47 +00001438ClangASTImporter *
1439Target::GetClangASTImporter()
1440{
1441 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1442
1443 if (!ast_importer)
1444 {
1445 ast_importer = new ClangASTImporter();
1446 m_ast_importer_ap.reset(ast_importer);
1447 }
1448
1449 return ast_importer;
1450}
1451
Greg Clayton990de7b2010-11-18 23:32:35 +00001452void
Caroline Tice2a456812011-03-10 22:14:10 +00001453Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001454{
Greg Clayton334d33a2012-01-30 07:41:31 +00001455 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001456 SettingsController::global_settings_table,
1457 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001458
1459 // Now call SettingsInitialize() on each 'child' setting of Target
1460 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001461}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001462
Greg Clayton990de7b2010-11-18 23:32:35 +00001463void
Caroline Tice2a456812011-03-10 22:14:10 +00001464Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001465{
Caroline Tice2a456812011-03-10 22:14:10 +00001466
1467 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1468
1469 Process::SettingsTerminate ();
1470
1471 // Now terminate Target Settings.
1472
Greg Clayton990de7b2010-11-18 23:32:35 +00001473 UserSettingsControllerSP &usc = GetSettingsController();
1474 UserSettingsController::FinalizeSettingsController (usc);
1475 usc.reset();
1476}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001477
Greg Clayton990de7b2010-11-18 23:32:35 +00001478UserSettingsControllerSP &
1479Target::GetSettingsController ()
1480{
Greg Clayton334d33a2012-01-30 07:41:31 +00001481 static UserSettingsControllerSP g_settings_controller_sp;
1482 if (!g_settings_controller_sp)
1483 {
1484 g_settings_controller_sp.reset (new Target::SettingsController);
1485 // The first shared pointer to Target::SettingsController in
1486 // g_settings_controller_sp must be fully created above so that
1487 // the TargetInstanceSettings can use a weak_ptr to refer back
1488 // to the master setttings controller
1489 InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1490 false,
1491 InstanceSettings::GetDefaultName().AsCString()));
1492 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1493 }
1494 return g_settings_controller_sp;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001495}
1496
Greg Clayton9ce95382012-02-13 23:10:39 +00001497FileSpecList
1498Target::GetDefaultExecutableSearchPaths ()
1499{
1500 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1501 if (settings_controller_sp)
1502 {
1503 lldb::InstanceSettingsSP instance_settings_sp (settings_controller_sp->GetDefaultInstanceSettings ());
1504 if (instance_settings_sp)
1505 return static_cast<TargetInstanceSettings *>(instance_settings_sp.get())->GetExecutableSearchPaths ();
1506 }
1507 return FileSpecList();
1508}
1509
1510
Caroline Tice5bc8c972010-09-20 20:44:43 +00001511ArchSpec
1512Target::GetDefaultArchitecture ()
1513{
Greg Clayton940b1032011-02-23 00:35:02 +00001514 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
Greg Claytonca0761b2012-05-12 00:26:42 +00001515 ArchSpec default_arch;
Greg Clayton940b1032011-02-23 00:35:02 +00001516 if (settings_controller_sp)
Greg Claytonca0761b2012-05-12 00:26:42 +00001517 default_arch = static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1518 if (!default_arch.IsValid())
1519 default_arch = Host::GetArchitecture ();
1520 return default_arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001521}
1522
1523void
Greg Clayton940b1032011-02-23 00:35:02 +00001524Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001525{
Greg Clayton940b1032011-02-23 00:35:02 +00001526 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1527
1528 if (settings_controller_sp)
1529 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001530}
1531
Greg Claytona830adb2010-10-04 01:05:56 +00001532Target *
1533Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1534{
1535 // The target can either exist in the "process" of ExecutionContext, or in
1536 // the "target_sp" member of SymbolContext. This accessor helper function
1537 // will get the target from one of these locations.
1538
1539 Target *target = NULL;
1540 if (sc_ptr != NULL)
1541 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001542 if (target == NULL && exe_ctx_ptr)
1543 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001544 return target;
1545}
1546
1547
Caroline Tice1ebef442010-09-27 00:30:10 +00001548void
1549Target::UpdateInstanceName ()
1550{
1551 StreamString sstr;
1552
Greg Clayton5beb99d2011-08-11 02:48:45 +00001553 Module *exe_module = GetExecutableModulePointer();
1554 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001555 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001556 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001557 exe_module->GetFileSpec().GetFilename().AsCString(),
1558 exe_module->GetArchitecture().GetArchitectureName());
1559 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001560 }
1561}
1562
Sean Callanan77e93942010-10-29 00:29:03 +00001563const char *
1564Target::GetExpressionPrefixContentsAsCString ()
1565{
Sean Callanane0b7f942011-11-16 01:54:57 +00001566 if (!m_expr_prefix_contents.empty())
1567 return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001568 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001569}
1570
Greg Clayton427f2902010-12-14 02:59:59 +00001571ExecutionResults
1572Target::EvaluateExpression
1573(
1574 const char *expr_cstr,
1575 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001576 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001577 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001578 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001579 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001580 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001581 lldb::ValueObjectSP &result_valobj_sp
1582)
1583{
1584 ExecutionResults execution_results = eExecutionSetupError;
1585
1586 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001587
1588 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1589 return execution_results;
1590
Jim Ingham3613ae12011-05-12 02:06:14 +00001591 // We shouldn't run stop hooks in expressions.
1592 // Be sure to reset this if you return anywhere within this function.
1593 bool old_suppress_value = m_suppress_stop_hooks;
1594 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001595
1596 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001597
1598 const size_t expr_cstr_len = ::strlen (expr_cstr);
1599
Greg Clayton427f2902010-12-14 02:59:59 +00001600 if (frame)
1601 {
1602 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001603 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001604 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001605 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1606 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001607 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001608
1609 // Make sure we don't have any things that we know a variable expression
1610 // won't be able to deal with before calling into it
1611 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1612 {
1613 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1614 use_dynamic,
1615 expr_path_options,
1616 var_sp,
1617 error);
Enrico Granata4d609c92012-04-24 22:15:37 +00001618 // if this expression results in a bitfield, we give up and let the IR handle it
1619 if (result_valobj_sp && result_valobj_sp->IsBitfield())
1620 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001621 }
Greg Clayton427f2902010-12-14 02:59:59 +00001622 }
1623 else if (m_process_sp)
1624 {
1625 m_process_sp->CalculateExecutionContext(exe_ctx);
1626 }
1627 else
1628 {
1629 CalculateExecutionContext(exe_ctx);
1630 }
1631
1632 if (result_valobj_sp)
1633 {
1634 execution_results = eExecutionCompleted;
1635 // We got a result from the frame variable expression path above...
1636 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1637
1638 lldb::ValueObjectSP const_valobj_sp;
1639
1640 // Check in case our value is already a constant value
1641 if (result_valobj_sp->GetIsConstant())
1642 {
1643 const_valobj_sp = result_valobj_sp;
1644 const_valobj_sp->SetName (persistent_variable_name);
1645 }
1646 else
Jim Inghame41494a2011-04-16 00:01:13 +00001647 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001648 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001649 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001650 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001651 if (dynamic_sp)
1652 result_valobj_sp = dynamic_sp;
1653 }
1654
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001655 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001656 }
Greg Clayton427f2902010-12-14 02:59:59 +00001657
Sean Callanan6a925532011-01-13 08:53:35 +00001658 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1659
Greg Clayton427f2902010-12-14 02:59:59 +00001660 result_valobj_sp = const_valobj_sp;
1661
Sean Callanan6a925532011-01-13 08:53:35 +00001662 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1663 assert (clang_expr_variable_sp.get());
1664
1665 // Set flags and live data as appropriate
1666
1667 const Value &result_value = live_valobj_sp->GetValue();
1668
1669 switch (result_value.GetValueType())
1670 {
1671 case Value::eValueTypeHostAddress:
1672 case Value::eValueTypeFileAddress:
1673 // we don't do anything with these for now
1674 break;
1675 case Value::eValueTypeScalar:
1676 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1677 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1678 break;
1679 case Value::eValueTypeLoadAddress:
1680 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1681 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1682 break;
1683 }
Greg Clayton427f2902010-12-14 02:59:59 +00001684 }
1685 else
1686 {
1687 // Make sure we aren't just trying to see the value of a persistent
1688 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001689 lldb::ClangExpressionVariableSP persistent_var_sp;
1690 // Only check for persistent variables the expression starts with a '$'
1691 if (expr_cstr[0] == '$')
1692 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1693
Greg Clayton427f2902010-12-14 02:59:59 +00001694 if (persistent_var_sp)
1695 {
1696 result_valobj_sp = persistent_var_sp->GetValueObject ();
1697 execution_results = eExecutionCompleted;
1698 }
1699 else
1700 {
1701 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001702
Greg Clayton427f2902010-12-14 02:59:59 +00001703 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001704 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001705 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001706 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001707 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001708 expr_cstr,
1709 prefix,
1710 result_valobj_sp);
1711 }
1712 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001713
1714 m_suppress_stop_hooks = old_suppress_value;
1715
Greg Clayton427f2902010-12-14 02:59:59 +00001716 return execution_results;
1717}
1718
Greg Claytonc0fa5332011-05-22 22:46:53 +00001719lldb::addr_t
1720Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1721{
1722 addr_t code_addr = load_addr;
1723 switch (m_arch.GetMachine())
1724 {
1725 case llvm::Triple::arm:
1726 case llvm::Triple::thumb:
1727 switch (addr_class)
1728 {
1729 case eAddressClassData:
1730 case eAddressClassDebug:
1731 return LLDB_INVALID_ADDRESS;
1732
1733 case eAddressClassUnknown:
1734 case eAddressClassInvalid:
1735 case eAddressClassCode:
1736 case eAddressClassCodeAlternateISA:
1737 case eAddressClassRuntime:
1738 // Check if bit zero it no set?
1739 if ((code_addr & 1ull) == 0)
1740 {
1741 // Bit zero isn't set, check if the address is a multiple of 2?
1742 if (code_addr & 2ull)
1743 {
1744 // The address is a multiple of 2 so it must be thumb, set bit zero
1745 code_addr |= 1ull;
1746 }
1747 else if (addr_class == eAddressClassCodeAlternateISA)
1748 {
1749 // We checked the address and the address claims to be the alternate ISA
1750 // which means thumb, so set bit zero.
1751 code_addr |= 1ull;
1752 }
1753 }
1754 break;
1755 }
1756 break;
1757
1758 default:
1759 break;
1760 }
1761 return code_addr;
1762}
1763
1764lldb::addr_t
1765Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1766{
1767 addr_t opcode_addr = load_addr;
1768 switch (m_arch.GetMachine())
1769 {
1770 case llvm::Triple::arm:
1771 case llvm::Triple::thumb:
1772 switch (addr_class)
1773 {
1774 case eAddressClassData:
1775 case eAddressClassDebug:
1776 return LLDB_INVALID_ADDRESS;
1777
1778 case eAddressClassInvalid:
1779 case eAddressClassUnknown:
1780 case eAddressClassCode:
1781 case eAddressClassCodeAlternateISA:
1782 case eAddressClassRuntime:
1783 opcode_addr &= ~(1ull);
1784 break;
1785 }
1786 break;
1787
1788 default:
1789 break;
1790 }
1791 return opcode_addr;
1792}
1793
Jim Inghamd60d94a2011-03-11 03:53:59 +00001794lldb::user_id_t
1795Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1796{
1797 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001798 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001799 m_stop_hooks[new_uid] = new_hook_sp;
1800 return new_uid;
1801}
1802
1803bool
1804Target::RemoveStopHookByID (lldb::user_id_t user_id)
1805{
1806 size_t num_removed;
1807 num_removed = m_stop_hooks.erase (user_id);
1808 if (num_removed == 0)
1809 return false;
1810 else
1811 return true;
1812}
1813
1814void
1815Target::RemoveAllStopHooks ()
1816{
1817 m_stop_hooks.clear();
1818}
1819
1820Target::StopHookSP
1821Target::GetStopHookByID (lldb::user_id_t user_id)
1822{
1823 StopHookSP found_hook;
1824
1825 StopHookCollection::iterator specified_hook_iter;
1826 specified_hook_iter = m_stop_hooks.find (user_id);
1827 if (specified_hook_iter != m_stop_hooks.end())
1828 found_hook = (*specified_hook_iter).second;
1829 return found_hook;
1830}
1831
1832bool
1833Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1834{
1835 StopHookCollection::iterator specified_hook_iter;
1836 specified_hook_iter = m_stop_hooks.find (user_id);
1837 if (specified_hook_iter == m_stop_hooks.end())
1838 return false;
1839
1840 (*specified_hook_iter).second->SetIsActive (active_state);
1841 return true;
1842}
1843
1844void
1845Target::SetAllStopHooksActiveState (bool active_state)
1846{
1847 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1848 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1849 {
1850 (*pos).second->SetIsActive (active_state);
1851 }
1852}
1853
1854void
1855Target::RunStopHooks ()
1856{
Jim Ingham3613ae12011-05-12 02:06:14 +00001857 if (m_suppress_stop_hooks)
1858 return;
1859
Jim Inghamd60d94a2011-03-11 03:53:59 +00001860 if (!m_process_sp)
1861 return;
1862
1863 if (m_stop_hooks.empty())
1864 return;
1865
1866 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1867
1868 // If there aren't any active stop hooks, don't bother either:
1869 bool any_active_hooks = false;
1870 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1871 {
1872 if ((*pos).second->IsActive())
1873 {
1874 any_active_hooks = true;
1875 break;
1876 }
1877 }
1878 if (!any_active_hooks)
1879 return;
1880
1881 CommandReturnObject result;
1882
1883 std::vector<ExecutionContext> exc_ctx_with_reasons;
1884 std::vector<SymbolContext> sym_ctx_with_reasons;
1885
1886 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1887 size_t num_threads = cur_threadlist.GetSize();
1888 for (size_t i = 0; i < num_threads; i++)
1889 {
1890 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1891 if (cur_thread_sp->ThreadStoppedForAReason())
1892 {
1893 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1894 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1895 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1896 }
1897 }
1898
1899 // If no threads stopped for a reason, don't run the stop-hooks.
1900 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1901 if (num_exe_ctx == 0)
1902 return;
1903
Jim Inghame5ed8e92011-06-02 23:58:26 +00001904 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1905 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001906
1907 bool keep_going = true;
1908 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001909 bool print_hook_header;
1910 bool print_thread_header;
1911
1912 if (num_exe_ctx == 1)
1913 print_thread_header = false;
1914 else
1915 print_thread_header = true;
1916
1917 if (m_stop_hooks.size() == 1)
1918 print_hook_header = false;
1919 else
1920 print_hook_header = true;
1921
Jim Inghamd60d94a2011-03-11 03:53:59 +00001922 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1923 {
1924 // result.Clear();
1925 StopHookSP cur_hook_sp = (*pos).second;
1926 if (!cur_hook_sp->IsActive())
1927 continue;
1928
1929 bool any_thread_matched = false;
1930 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1931 {
1932 if ((cur_hook_sp->GetSpecifier () == NULL
1933 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1934 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Inghama2664912012-03-07 22:03:04 +00001935 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001936 {
1937 if (!hooks_ran)
1938 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00001939 hooks_ran = true;
1940 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001941 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001942 {
Johnny Chen4d96a742011-10-24 23:01:06 +00001943 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1944 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1945 NULL);
1946 if (cmd)
1947 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1948 else
1949 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001950 any_thread_matched = true;
1951 }
1952
Jim Inghamc54840c2011-03-22 01:47:27 +00001953 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00001954 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001955
1956 bool stop_on_continue = true;
1957 bool stop_on_error = true;
1958 bool echo_commands = false;
1959 bool print_results = true;
1960 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001961 &exc_ctx_with_reasons[i],
1962 stop_on_continue,
1963 stop_on_error,
1964 echo_commands,
1965 print_results,
1966 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001967
1968 // If the command started the target going again, we should bag out of
1969 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001970 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1971 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001972 {
Greg Clayton444e35b2011-10-19 18:09:39 +00001973 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001974 keep_going = false;
1975 }
1976 }
1977 }
1978 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00001979
Caroline Tice4a348082011-05-02 20:41:46 +00001980 result.GetImmediateOutputStream()->Flush();
1981 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001982}
1983
Greg Claytonbbea1332011-07-08 00:48:09 +00001984
Jim Inghamd60d94a2011-03-11 03:53:59 +00001985//--------------------------------------------------------------
1986// class Target::StopHook
1987//--------------------------------------------------------------
1988
1989
1990Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1991 UserID (uid),
1992 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001993 m_commands (),
1994 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001995 m_thread_spec_ap(NULL),
1996 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001997{
1998}
1999
2000Target::StopHook::StopHook (const StopHook &rhs) :
2001 UserID (rhs.GetID()),
2002 m_target_sp (rhs.m_target_sp),
2003 m_commands (rhs.m_commands),
2004 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002005 m_thread_spec_ap (NULL),
2006 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002007{
2008 if (rhs.m_thread_spec_ap.get() != NULL)
2009 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2010}
2011
2012
2013Target::StopHook::~StopHook ()
2014{
2015}
2016
2017void
2018Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2019{
2020 m_thread_spec_ap.reset (specifier);
2021}
2022
2023
2024void
2025Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2026{
2027 int indent_level = s->GetIndentLevel();
2028
2029 s->SetIndentLevel(indent_level + 2);
2030
Greg Clayton444e35b2011-10-19 18:09:39 +00002031 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002032 if (m_active)
2033 s->Indent ("State: enabled\n");
2034 else
2035 s->Indent ("State: disabled\n");
2036
2037 if (m_specifier_sp)
2038 {
2039 s->Indent();
2040 s->PutCString ("Specifier:\n");
2041 s->SetIndentLevel (indent_level + 4);
2042 m_specifier_sp->GetDescription (s, level);
2043 s->SetIndentLevel (indent_level + 2);
2044 }
2045
2046 if (m_thread_spec_ap.get() != NULL)
2047 {
2048 StreamString tmp;
2049 s->Indent("Thread:\n");
2050 m_thread_spec_ap->GetDescription (&tmp, level);
2051 s->SetIndentLevel (indent_level + 4);
2052 s->Indent (tmp.GetData());
2053 s->PutCString ("\n");
2054 s->SetIndentLevel (indent_level + 2);
2055 }
2056
2057 s->Indent ("Commands: \n");
2058 s->SetIndentLevel (indent_level + 4);
2059 uint32_t num_commands = m_commands.GetSize();
2060 for (uint32_t i = 0; i < num_commands; i++)
2061 {
2062 s->Indent(m_commands.GetStringAtIndex(i));
2063 s->PutCString ("\n");
2064 }
2065 s->SetIndentLevel (indent_level);
2066}
2067
2068
Caroline Tice5bc8c972010-09-20 20:44:43 +00002069//--------------------------------------------------------------
2070// class Target::SettingsController
2071//--------------------------------------------------------------
2072
2073Target::SettingsController::SettingsController () :
2074 UserSettingsController ("target", Debugger::GetSettingsController()),
2075 m_default_architecture ()
2076{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002077}
2078
2079Target::SettingsController::~SettingsController ()
2080{
2081}
2082
2083lldb::InstanceSettingsSP
2084Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2085{
Greg Clayton334d33a2012-01-30 07:41:31 +00002086 lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2087 false,
2088 instance_name));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002089 return new_settings_sp;
2090}
2091
Caroline Tice5bc8c972010-09-20 20:44:43 +00002092
Greg Claytonabb33022011-11-08 02:43:13 +00002093#define TSC_DEFAULT_ARCH "default-arch"
2094#define TSC_EXPR_PREFIX "expr-prefix"
2095#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Enrico Granatadba1de82012-03-27 02:35:13 +00002096#define TSC_ENABLE_SYNTHETIC "enable-synthetic-value"
Greg Claytonabb33022011-11-08 02:43:13 +00002097#define TSC_SKIP_PROLOGUE "skip-prologue"
2098#define TSC_SOURCE_MAP "source-map"
Greg Clayton9ce95382012-02-13 23:10:39 +00002099#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
Greg Claytonabb33022011-11-08 02:43:13 +00002100#define TSC_MAX_CHILDREN "max-children-count"
2101#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2102#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2103#define TSC_RUN_ARGS "run-args"
2104#define TSC_ENV_VARS "env-vars"
2105#define TSC_INHERIT_ENV "inherit-env"
2106#define TSC_STDIN_PATH "input-path"
2107#define TSC_STDOUT_PATH "output-path"
2108#define TSC_STDERR_PATH "error-path"
2109#define TSC_DISABLE_ASLR "disable-aslr"
2110#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytond284b662011-02-18 01:44:25 +00002111
2112
2113static const ConstString &
2114GetSettingNameForDefaultArch ()
2115{
2116 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00002117 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002118}
2119
Greg Claytond284b662011-02-18 01:44:25 +00002120static const ConstString &
2121GetSettingNameForExpressionPrefix ()
2122{
2123 static ConstString g_const_string (TSC_EXPR_PREFIX);
2124 return g_const_string;
2125}
2126
2127static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00002128GetSettingNameForPreferDynamicValue ()
2129{
2130 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2131 return g_const_string;
2132}
2133
Greg Claytonff44ab42011-04-23 02:04:55 +00002134static const ConstString &
Enrico Granatadba1de82012-03-27 02:35:13 +00002135GetSettingNameForEnableSyntheticValue ()
2136{
2137 static ConstString g_const_string (TSC_ENABLE_SYNTHETIC);
2138 return g_const_string;
2139}
2140
2141static const ConstString &
Greg Claytonff44ab42011-04-23 02:04:55 +00002142GetSettingNameForSourcePathMap ()
2143{
2144 static ConstString g_const_string (TSC_SOURCE_MAP);
2145 return g_const_string;
2146}
Greg Claytond284b662011-02-18 01:44:25 +00002147
Greg Clayton17cd9952011-04-22 03:55:06 +00002148static const ConstString &
Greg Clayton9ce95382012-02-13 23:10:39 +00002149GetSettingNameForExecutableSearchPaths ()
2150{
2151 static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2152 return g_const_string;
2153}
2154
2155static const ConstString &
Greg Clayton17cd9952011-04-22 03:55:06 +00002156GetSettingNameForSkipPrologue ()
2157{
2158 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2159 return g_const_string;
2160}
2161
Enrico Granata018921d2011-08-12 02:00:06 +00002162static const ConstString &
2163GetSettingNameForMaxChildren ()
2164{
2165 static ConstString g_const_string (TSC_MAX_CHILDREN);
2166 return g_const_string;
2167}
Greg Clayton17cd9952011-04-22 03:55:06 +00002168
Enrico Granata91544802011-09-06 19:20:51 +00002169static const ConstString &
2170GetSettingNameForMaxStringSummaryLength ()
2171{
2172 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2173 return g_const_string;
2174}
Greg Clayton17cd9952011-04-22 03:55:06 +00002175
Jim Ingham7089d8a2011-10-28 23:14:11 +00002176static const ConstString &
2177GetSettingNameForPlatformAvoid ()
2178{
2179 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2180 return g_const_string;
2181}
2182
Greg Claytonabb33022011-11-08 02:43:13 +00002183const ConstString &
2184GetSettingNameForRunArgs ()
2185{
2186 static ConstString g_const_string (TSC_RUN_ARGS);
2187 return g_const_string;
2188}
2189
2190const ConstString &
2191GetSettingNameForEnvVars ()
2192{
2193 static ConstString g_const_string (TSC_ENV_VARS);
2194 return g_const_string;
2195}
2196
2197const ConstString &
2198GetSettingNameForInheritHostEnv ()
2199{
2200 static ConstString g_const_string (TSC_INHERIT_ENV);
2201 return g_const_string;
2202}
2203
2204const ConstString &
2205GetSettingNameForInputPath ()
2206{
2207 static ConstString g_const_string (TSC_STDIN_PATH);
2208 return g_const_string;
2209}
2210
2211const ConstString &
2212GetSettingNameForOutputPath ()
2213{
2214 static ConstString g_const_string (TSC_STDOUT_PATH);
2215 return g_const_string;
2216}
2217
2218const ConstString &
2219GetSettingNameForErrorPath ()
2220{
2221 static ConstString g_const_string (TSC_STDERR_PATH);
2222 return g_const_string;
2223}
2224
2225const ConstString &
2226GetSettingNameForDisableASLR ()
2227{
2228 static ConstString g_const_string (TSC_DISABLE_ASLR);
2229 return g_const_string;
2230}
2231
2232const ConstString &
2233GetSettingNameForDisableSTDIO ()
2234{
2235 static ConstString g_const_string (TSC_DISABLE_STDIO);
2236 return g_const_string;
2237}
Jim Ingham7089d8a2011-10-28 23:14:11 +00002238
Caroline Tice5bc8c972010-09-20 20:44:43 +00002239bool
2240Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2241 const char *index_value,
2242 const char *value,
2243 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002244 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002245 Error&err)
2246{
Greg Claytond284b662011-02-18 01:44:25 +00002247 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002248 {
Greg Claytonb170aee2012-05-08 01:45:38 +00002249 m_default_architecture.SetTriple (value);
Greg Clayton940b1032011-02-23 00:35:02 +00002250 if (!m_default_architecture.IsValid())
2251 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002252 }
2253 return true;
2254}
2255
2256
2257bool
2258Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2259 StringList &value,
2260 Error &err)
2261{
Greg Claytond284b662011-02-18 01:44:25 +00002262 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002263 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00002264 // If the arch is invalid (the default), don't show a string for it
2265 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00002266 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00002267 return true;
2268 }
2269 else
2270 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2271
2272 return false;
2273}
2274
2275//--------------------------------------------------------------
2276// class TargetInstanceSettings
2277//--------------------------------------------------------------
2278
Greg Clayton638351a2010-12-04 00:10:17 +00002279TargetInstanceSettings::TargetInstanceSettings
2280(
Greg Clayton334d33a2012-01-30 07:41:31 +00002281 const lldb::UserSettingsControllerSP &owner_sp,
Greg Clayton638351a2010-12-04 00:10:17 +00002282 bool live_instance,
2283 const char *name
2284) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002285 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00002286 m_expr_prefix_file (),
Sean Callanane0b7f942011-11-16 01:54:57 +00002287 m_expr_prefix_contents (),
Jim Ingham10de7d12011-05-04 03:43:18 +00002288 m_prefer_dynamic_value (2),
Enrico Granatadba1de82012-03-27 02:35:13 +00002289 m_enable_synthetic_value(true, true),
Greg Claytonff44ab42011-04-23 02:04:55 +00002290 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00002291 m_source_map (NULL, NULL),
Greg Clayton9ce95382012-02-13 23:10:39 +00002292 m_exe_search_paths (),
Enrico Granata91544802011-09-06 19:20:51 +00002293 m_max_children_display(256),
Jim Ingham7089d8a2011-10-28 23:14:11 +00002294 m_max_strlen_length(1024),
Greg Claytonabb33022011-11-08 02:43:13 +00002295 m_breakpoints_use_platform_avoid (true, true),
2296 m_run_args (),
2297 m_env_vars (),
2298 m_input_path (),
2299 m_output_path (),
2300 m_error_path (),
2301 m_disable_aslr (true),
2302 m_disable_stdio (false),
2303 m_inherit_host_env (true),
2304 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002305{
2306 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2307 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2308 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2309 // This is true for CreateInstanceName() too.
2310
2311 if (GetInstanceName () == InstanceSettings::InvalidName())
2312 {
2313 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00002314 owner_sp->RegisterInstanceSettings (this);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002315 }
2316
2317 if (live_instance)
2318 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002319 const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002320 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002321 }
2322}
2323
2324TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002325 InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
Greg Claytonff44ab42011-04-23 02:04:55 +00002326 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanane0b7f942011-11-16 01:54:57 +00002327 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Claytonff44ab42011-04-23 02:04:55 +00002328 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
Enrico Granatadba1de82012-03-27 02:35:13 +00002329 m_enable_synthetic_value(rhs.m_enable_synthetic_value),
Greg Claytonff44ab42011-04-23 02:04:55 +00002330 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00002331 m_source_map (rhs.m_source_map),
Greg Clayton9ce95382012-02-13 23:10:39 +00002332 m_exe_search_paths (rhs.m_exe_search_paths),
Greg Claytonabb33022011-11-08 02:43:13 +00002333 m_max_children_display (rhs.m_max_children_display),
2334 m_max_strlen_length (rhs.m_max_strlen_length),
2335 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2336 m_run_args (rhs.m_run_args),
2337 m_env_vars (rhs.m_env_vars),
2338 m_input_path (rhs.m_input_path),
2339 m_output_path (rhs.m_output_path),
2340 m_error_path (rhs.m_error_path),
2341 m_disable_aslr (rhs.m_disable_aslr),
2342 m_disable_stdio (rhs.m_disable_stdio),
2343 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002344{
2345 if (m_instance_name != InstanceSettings::GetDefaultName())
2346 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002347 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2348 if (owner_sp)
2349 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002350 }
2351}
2352
2353TargetInstanceSettings::~TargetInstanceSettings ()
2354{
2355}
2356
2357TargetInstanceSettings&
2358TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2359{
2360 if (this != &rhs)
2361 {
Greg Claytonabb33022011-11-08 02:43:13 +00002362 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanane0b7f942011-11-16 01:54:57 +00002363 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Claytonabb33022011-11-08 02:43:13 +00002364 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
Enrico Granatadba1de82012-03-27 02:35:13 +00002365 m_enable_synthetic_value = rhs.m_enable_synthetic_value;
Greg Claytonabb33022011-11-08 02:43:13 +00002366 m_skip_prologue = rhs.m_skip_prologue;
2367 m_source_map = rhs.m_source_map;
Greg Clayton9ce95382012-02-13 23:10:39 +00002368 m_exe_search_paths = rhs.m_exe_search_paths;
Greg Claytonabb33022011-11-08 02:43:13 +00002369 m_max_children_display = rhs.m_max_children_display;
2370 m_max_strlen_length = rhs.m_max_strlen_length;
2371 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2372 m_run_args = rhs.m_run_args;
2373 m_env_vars = rhs.m_env_vars;
2374 m_input_path = rhs.m_input_path;
2375 m_output_path = rhs.m_output_path;
2376 m_error_path = rhs.m_error_path;
2377 m_disable_aslr = rhs.m_disable_aslr;
2378 m_disable_stdio = rhs.m_disable_stdio;
2379 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002380 }
2381
2382 return *this;
2383}
2384
Caroline Tice5bc8c972010-09-20 20:44:43 +00002385void
2386TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2387 const char *index_value,
2388 const char *value,
2389 const ConstString &instance_name,
2390 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002391 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002392 Error &err,
2393 bool pending)
2394{
Greg Claytond284b662011-02-18 01:44:25 +00002395 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002396 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002397 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2398 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00002399 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002400 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00002401 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002402 default:
2403 break;
2404 case eVarSetOperationAssign:
2405 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00002406 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002407 m_expr_prefix_contents.clear();
2408
Greg Claytonff44ab42011-04-23 02:04:55 +00002409 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2410 {
2411 err.SetErrorToGenericError ();
Greg Clayton9c236732011-10-26 00:56:27 +00002412 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Claytonff44ab42011-04-23 02:04:55 +00002413 return;
2414 }
2415
Greg Clayton4b23ab32012-01-06 02:01:06 +00002416 DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
Sean Callanane0b7f942011-11-16 01:54:57 +00002417
Greg Clayton4b23ab32012-01-06 02:01:06 +00002418 if (err.Success())
Greg Claytonff44ab42011-04-23 02:04:55 +00002419 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002420 if (file_data_sp && file_data_sp->GetByteSize() > 0)
2421 {
2422 m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2423 }
2424 else
2425 {
2426 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2427 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002428 }
Sean Callanan77e93942010-10-29 00:29:03 +00002429 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002430 break;
2431 case eVarSetOperationClear:
Sean Callanane0b7f942011-11-16 01:54:57 +00002432 m_expr_prefix_contents.clear();
Sean Callanan77e93942010-10-29 00:29:03 +00002433 }
Sean Callanan77e93942010-10-29 00:29:03 +00002434 }
2435 }
Jim Inghame41494a2011-04-16 00:01:13 +00002436 else if (var_name == GetSettingNameForPreferDynamicValue())
2437 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002438 int new_value;
2439 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2440 if (err.Success())
2441 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00002442 }
Enrico Granatadba1de82012-03-27 02:35:13 +00002443 else if (var_name == GetSettingNameForEnableSyntheticValue())
2444 {
2445 bool ok;
2446 bool new_value = Args::StringToBoolean(value, true, &ok);
2447 if (ok)
2448 m_enable_synthetic_value.SetCurrentValue(new_value);
2449 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002450 else if (var_name == GetSettingNameForSkipPrologue())
2451 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002452 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2453 }
Enrico Granata018921d2011-08-12 02:00:06 +00002454 else if (var_name == GetSettingNameForMaxChildren())
2455 {
2456 bool ok;
2457 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2458 if (ok)
2459 m_max_children_display = new_value;
2460 }
Enrico Granata91544802011-09-06 19:20:51 +00002461 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2462 {
2463 bool ok;
2464 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2465 if (ok)
2466 m_max_strlen_length = new_value;
2467 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002468 else if (var_name == GetSettingNameForExecutableSearchPaths())
2469 {
2470 switch (op)
2471 {
2472 case eVarSetOperationReplace:
2473 case eVarSetOperationInsertBefore:
2474 case eVarSetOperationInsertAfter:
2475 case eVarSetOperationRemove:
2476 default:
2477 break;
2478 case eVarSetOperationAssign:
2479 m_exe_search_paths.Clear();
2480 // Fall through to append....
2481 case eVarSetOperationAppend:
2482 {
2483 Args args(value);
2484 const uint32_t argc = args.GetArgumentCount();
2485 if (argc > 0)
2486 {
2487 const char *exe_search_path_dir;
2488 for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2489 {
2490 FileSpec file_spec;
2491 file_spec.GetDirectory().SetCString(exe_search_path_dir);
2492 FileSpec::FileType file_type = file_spec.GetFileType();
2493 if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2494 {
2495 m_exe_search_paths.Append(file_spec);
2496 }
2497 else
2498 {
2499 err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2500 }
2501 }
2502 }
2503 }
2504 break;
2505
2506 case eVarSetOperationClear:
2507 m_exe_search_paths.Clear();
2508 break;
2509 }
2510 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002511 else if (var_name == GetSettingNameForSourcePathMap ())
2512 {
2513 switch (op)
2514 {
2515 case eVarSetOperationReplace:
2516 case eVarSetOperationInsertBefore:
2517 case eVarSetOperationInsertAfter:
2518 case eVarSetOperationRemove:
2519 default:
2520 break;
2521 case eVarSetOperationAssign:
2522 m_source_map.Clear(true);
2523 // Fall through to append....
2524 case eVarSetOperationAppend:
2525 {
2526 Args args(value);
2527 const uint32_t argc = args.GetArgumentCount();
2528 if (argc & 1 || argc == 0)
2529 {
2530 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2531 }
2532 else
2533 {
2534 char resolved_new_path[PATH_MAX];
2535 FileSpec file_spec;
2536 const char *old_path;
2537 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2538 {
2539 const char *new_path = args.GetArgumentAtIndex(idx+1);
2540 assert (new_path); // We have an even number of paths, this shouldn't happen!
2541
2542 file_spec.SetFile(new_path, true);
2543 if (file_spec.Exists())
2544 {
2545 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2546 {
2547 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2548 return;
2549 }
2550 }
2551 else
2552 {
2553 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2554 return;
2555 }
2556 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2557 }
2558 }
2559 }
2560 break;
2561
2562 case eVarSetOperationClear:
2563 m_source_map.Clear(true);
2564 break;
2565 }
Jim Inghame41494a2011-04-16 00:01:13 +00002566 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002567 else if (var_name == GetSettingNameForPlatformAvoid ())
2568 {
2569 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2570 }
Greg Claytonabb33022011-11-08 02:43:13 +00002571 else if (var_name == GetSettingNameForRunArgs())
2572 {
2573 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2574 }
2575 else if (var_name == GetSettingNameForEnvVars())
2576 {
2577 // This is nice for local debugging, but it is isn't correct for
2578 // remote debugging. We need to stop process.env-vars from being
2579 // populated with the host environment and add this as a launch option
2580 // and get the correct environment from the Target's platform.
2581 // GetHostEnvironmentIfNeeded ();
2582 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2583 }
2584 else if (var_name == GetSettingNameForInputPath())
2585 {
2586 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2587 }
2588 else if (var_name == GetSettingNameForOutputPath())
2589 {
2590 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2591 }
2592 else if (var_name == GetSettingNameForErrorPath())
2593 {
2594 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2595 }
2596 else if (var_name == GetSettingNameForDisableASLR())
2597 {
2598 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2599 }
2600 else if (var_name == GetSettingNameForDisableSTDIO ())
2601 {
2602 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2603 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002604}
2605
2606void
Greg Claytond284b662011-02-18 01:44:25 +00002607TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002608{
Sean Callanan77e93942010-10-29 00:29:03 +00002609 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2610
2611 if (!new_settings_ptr)
2612 return;
2613
Greg Claytonabb33022011-11-08 02:43:13 +00002614 *this = *new_settings_ptr;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002615}
2616
Caroline Ticebcb5b452010-09-20 21:37:42 +00002617bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00002618TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2619 const ConstString &var_name,
2620 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00002621 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002622{
Greg Claytond284b662011-02-18 01:44:25 +00002623 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002624 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002625 char path[PATH_MAX];
2626 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2627 if (path_len > 0)
2628 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00002629 }
Jim Inghame41494a2011-04-16 00:01:13 +00002630 else if (var_name == GetSettingNameForPreferDynamicValue())
2631 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002632 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00002633 }
Enrico Granatadba1de82012-03-27 02:35:13 +00002634 else if (var_name == GetSettingNameForEnableSyntheticValue())
2635 {
2636 if (m_skip_prologue)
2637 value.AppendString ("true");
2638 else
2639 value.AppendString ("false");
2640 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002641 else if (var_name == GetSettingNameForSkipPrologue())
2642 {
2643 if (m_skip_prologue)
2644 value.AppendString ("true");
2645 else
2646 value.AppendString ("false");
2647 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002648 else if (var_name == GetSettingNameForExecutableSearchPaths())
2649 {
2650 if (m_exe_search_paths.GetSize())
2651 {
2652 for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
2653 {
2654 value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
2655 }
2656 }
2657 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002658 else if (var_name == GetSettingNameForSourcePathMap ())
2659 {
Johnny Chen931449e2011-12-12 21:59:28 +00002660 if (m_source_map.GetSize())
2661 {
2662 size_t i;
2663 for (i = 0; i < m_source_map.GetSize(); ++i) {
2664 StreamString sstr;
2665 m_source_map.Dump(&sstr, i);
2666 value.AppendString(sstr.GetData());
2667 }
2668 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002669 }
Enrico Granata018921d2011-08-12 02:00:06 +00002670 else if (var_name == GetSettingNameForMaxChildren())
2671 {
2672 StreamString count_str;
2673 count_str.Printf ("%d", m_max_children_display);
2674 value.AppendString (count_str.GetData());
2675 }
Enrico Granata91544802011-09-06 19:20:51 +00002676 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2677 {
2678 StreamString count_str;
2679 count_str.Printf ("%d", m_max_strlen_length);
2680 value.AppendString (count_str.GetData());
2681 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002682 else if (var_name == GetSettingNameForPlatformAvoid())
2683 {
2684 if (m_breakpoints_use_platform_avoid)
2685 value.AppendString ("true");
2686 else
2687 value.AppendString ("false");
2688 }
Greg Claytonabb33022011-11-08 02:43:13 +00002689 else if (var_name == GetSettingNameForRunArgs())
2690 {
2691 if (m_run_args.GetArgumentCount() > 0)
2692 {
2693 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2694 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2695 }
2696 }
2697 else if (var_name == GetSettingNameForEnvVars())
2698 {
2699 GetHostEnvironmentIfNeeded ();
2700
2701 if (m_env_vars.size() > 0)
2702 {
2703 std::map<std::string, std::string>::iterator pos;
2704 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2705 {
2706 StreamString value_str;
2707 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2708 value.AppendString (value_str.GetData());
2709 }
2710 }
2711 }
2712 else if (var_name == GetSettingNameForInputPath())
2713 {
2714 value.AppendString (m_input_path.c_str());
2715 }
2716 else if (var_name == GetSettingNameForOutputPath())
2717 {
2718 value.AppendString (m_output_path.c_str());
2719 }
2720 else if (var_name == GetSettingNameForErrorPath())
2721 {
2722 value.AppendString (m_error_path.c_str());
2723 }
2724 else if (var_name == GetSettingNameForInheritHostEnv())
2725 {
2726 if (m_inherit_host_env)
2727 value.AppendString ("true");
2728 else
2729 value.AppendString ("false");
2730 }
2731 else if (var_name == GetSettingNameForDisableASLR())
2732 {
2733 if (m_disable_aslr)
2734 value.AppendString ("true");
2735 else
2736 value.AppendString ("false");
2737 }
2738 else if (var_name == GetSettingNameForDisableSTDIO())
2739 {
2740 if (m_disable_stdio)
2741 value.AppendString ("true");
2742 else
2743 value.AppendString ("false");
2744 }
Sean Callanan77e93942010-10-29 00:29:03 +00002745 else
2746 {
2747 if (err)
2748 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2749 return false;
2750 }
Sean Callanan77e93942010-10-29 00:29:03 +00002751 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002752}
2753
Greg Claytonabb33022011-11-08 02:43:13 +00002754void
2755Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2756{
2757 if (m_inherit_host_env && !m_got_host_env)
2758 {
2759 m_got_host_env = true;
2760 StringList host_env;
2761 const size_t host_env_count = Host::GetEnvironment (host_env);
2762 for (size_t idx=0; idx<host_env_count; idx++)
2763 {
2764 const char *env_entry = host_env.GetStringAtIndex (idx);
2765 if (env_entry)
2766 {
2767 const char *equal_pos = ::strchr(env_entry, '=');
2768 if (equal_pos)
2769 {
2770 std::string key (env_entry, equal_pos - env_entry);
2771 std::string value (equal_pos + 1);
2772 if (m_env_vars.find (key) == m_env_vars.end())
2773 m_env_vars[key] = value;
2774 }
2775 }
2776 }
2777 }
2778}
2779
2780
2781size_t
2782Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2783{
2784 GetHostEnvironmentIfNeeded ();
2785
2786 dictionary::const_iterator pos, end = m_env_vars.end();
2787 for (pos = m_env_vars.begin(); pos != end; ++pos)
2788 {
2789 std::string env_var_equal_value (pos->first);
2790 env_var_equal_value.append(1, '=');
2791 env_var_equal_value.append (pos->second);
2792 env.AppendArgument (env_var_equal_value.c_str());
2793 }
2794 return env.GetArgumentCount();
2795}
2796
2797
Caroline Tice5bc8c972010-09-20 20:44:43 +00002798const ConstString
2799TargetInstanceSettings::CreateInstanceName ()
2800{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002801 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002802 static int instance_count = 1;
2803
Caroline Tice5bc8c972010-09-20 20:44:43 +00002804 sstr.Printf ("target_%d", instance_count);
2805 ++instance_count;
2806
2807 const ConstString ret_val (sstr.GetData());
2808 return ret_val;
2809}
2810
2811//--------------------------------------------------
2812// Target::SettingsController Variable Tables
2813//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002814OptionEnumValueElement
2815TargetInstanceSettings::g_dynamic_value_types[] =
2816{
Greg Clayton577fbc32011-05-30 00:39:48 +00002817{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2818{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2819{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002820{ 0, NULL, NULL }
2821};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002822
2823SettingEntry
2824Target::SettingsController::global_settings_table[] =
2825{
Greg Claytond284b662011-02-18 01:44:25 +00002826 // var-name var-type default enum init'd hidden help-text
2827 // ================= ================== =========== ==== ====== ====== =========================================================================
2828 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2829 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2830};
2831
Caroline Tice5bc8c972010-09-20 20:44:43 +00002832SettingEntry
2833Target::SettingsController::instance_settings_table[] =
2834{
Enrico Granata91544802011-09-06 19:20:51 +00002835 // var-name var-type default enum init'd hidden help-text
2836 // ================= ================== =============== ======================= ====== ====== =========================================================================
2837 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2838 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
Enrico Granatadba1de82012-03-27 02:35:13 +00002839 { TSC_ENABLE_SYNTHETIC , eSetVarTypeBoolean, "true" , NULL, false, false, "Should synthetic values be used by default whenever available." },
Enrico Granata91544802011-09-06 19:20:51 +00002840 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2841 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
Greg Clayton9ce95382012-02-13 23:10:39 +00002842 { TSC_EXE_SEARCH_PATHS , eSetVarTypeArray , NULL , NULL, false, false, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
Enrico Granata91544802011-09-06 19:20:51 +00002843 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2844 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
Jim Ingham7089d8a2011-10-28 23:14:11 +00002845 { TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Claytonabb33022011-11-08 02:43:13 +00002846 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2847 { TSC_ENV_VARS , eSetVarTypeDictionary, NULL , NULL, false, false, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2848 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2849 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2850 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2851 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2852// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2853 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2854 { TSC_DISABLE_STDIO , eSetVarTypeBoolean, "false" , NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Enrico Granata91544802011-09-06 19:20:51 +00002855 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002856};
Jim Ingham5a15e692012-02-16 06:50:00 +00002857
2858const ConstString &
2859Target::TargetEventData::GetFlavorString ()
2860{
2861 static ConstString g_flavor ("Target::TargetEventData");
2862 return g_flavor;
2863}
2864
2865const ConstString &
2866Target::TargetEventData::GetFlavor () const
2867{
2868 return TargetEventData::GetFlavorString ();
2869}
2870
2871Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2872 EventData(),
2873 m_target_sp (new_target_sp)
2874{
2875}
2876
2877Target::TargetEventData::~TargetEventData()
2878{
2879
2880}
2881
2882void
2883Target::TargetEventData::Dump (Stream *s) const
2884{
2885
2886}
2887
2888const TargetSP
2889Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2890{
2891 TargetSP target_sp;
2892
2893 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2894 if (data)
2895 target_sp = data->m_target_sp;
2896
2897 return target_sp;
2898}
2899
2900const Target::TargetEventData *
2901Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2902{
2903 if (event_ptr)
2904 {
2905 const EventData *event_data = event_ptr->GetData();
2906 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2907 return static_cast <const TargetEventData *> (event_ptr->GetData());
2908 }
2909 return NULL;
2910}
2911