blob: 73432876d679b6ee8e916c1d22419b59f0874735 [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"
Johnny Chen3f883492012-06-04 23:19:54 +000033#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000034#include "lldb/Interpreter/OptionValues.h"
35#include "lldb/Interpreter/Property.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036#include "lldb/lldb-private-log.h"
37#include "lldb/Symbol/ObjectFile.h"
38#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000039#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000040#include "lldb/Target/Thread.h"
41#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042
43using namespace lldb;
44using namespace lldb_private;
45
Jim Ingham5a15e692012-02-16 06:50:00 +000046ConstString &
47Target::GetStaticBroadcasterClass ()
48{
49 static ConstString class_name ("lldb.target");
50 return class_name;
51}
52
Chris Lattner24943d22010-06-08 16:52:24 +000053//----------------------------------------------------------------------
54// Target constructor
55//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000056Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Greg Clayton73844aa2012-08-22 17:17:09 +000057 TargetProperties (this),
Jim Ingham5a15e692012-02-16 06:50:00 +000058 Broadcaster (&debugger, "lldb.target"),
Greg Clayton73844aa2012-08-22 17:17:09 +000059//TargetInstanceSettings (GetSettingsController()),
Greg Clayton24bc5d92011-03-30 18:16:51 +000060 ExecutionContextScope (),
Greg Clayton63094e02010-06-23 01:19:29 +000061 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000062 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000063 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000064 m_arch (target_arch),
65 m_images (),
Greg Claytoneea26402010-09-14 23:36:40 +000066 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000067 m_breakpoint_list (false),
68 m_internal_breakpoint_list (true),
Johnny Chenecd4feb2011-10-14 00:42:25 +000069 m_watchpoint_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000070 m_process_sp (),
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +000071 m_valid (true),
Greg Clayton24bc5d92011-03-30 18:16:51 +000072 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000073 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000074 m_scratch_ast_context_ap (NULL),
Sean Callanan4938bd62011-11-16 18:20:47 +000075 m_scratch_ast_source_ap (NULL),
76 m_ast_importer_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000077 m_persistent_variables (),
Jim Inghamcc637462011-09-13 00:29:56 +000078 m_source_manager(*this),
Greg Clayton24bc5d92011-03-30 18:16:51 +000079 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000080 m_stop_hook_next_id (0),
Enrico Granatadba1de82012-03-27 02:35:13 +000081 m_suppress_stop_hooks (false),
82 m_suppress_synthetic_value(false)
Chris Lattner24943d22010-06-08 16:52:24 +000083{
Greg Clayton49ce6822010-10-31 03:01:06 +000084 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
85 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
86 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham5a15e692012-02-16 06:50:00 +000087
88 CheckInWithManager();
Greg Clayton49ce6822010-10-31 03:01:06 +000089
Greg Claytone005f2c2010-11-06 01:53:30 +000090 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000091 if (log)
92 log->Printf ("%p Target::Target()", this);
93}
94
95//----------------------------------------------------------------------
96// Destructor
97//----------------------------------------------------------------------
98Target::~Target()
99{
Greg Claytone005f2c2010-11-06 01:53:30 +0000100 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +0000101 if (log)
102 log->Printf ("%p Target::~Target()", this);
103 DeleteCurrentProcess ();
104}
105
106void
Caroline Tice7826c882010-10-26 03:11:13 +0000107Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +0000108{
Greg Clayton3fed8b92010-10-08 00:21:05 +0000109// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +0000110 if (description_level != lldb::eDescriptionLevelBrief)
111 {
112 s->Indent();
113 s->PutCString("Target\n");
114 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000115 m_images.Dump(s);
116 m_breakpoint_list.Dump(s);
117 m_internal_breakpoint_list.Dump(s);
118 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +0000119 }
120 else
121 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000122 Module *exe_module = GetExecutableModulePointer();
123 if (exe_module)
124 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000125 else
126 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000127 }
Chris Lattner24943d22010-06-08 16:52:24 +0000128}
129
130void
131Target::DeleteCurrentProcess ()
132{
133 if (m_process_sp.get())
134 {
Greg Clayton49480b12010-09-14 23:52:43 +0000135 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000136 if (m_process_sp->IsAlive())
137 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000138
139 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000140
141 // Do any cleanup of the target we need to do between process instances.
142 // NB It is better to do this before destroying the process in case the
143 // clean up needs some help from the process.
144 m_breakpoint_list.ClearAllBreakpointSites();
145 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000146 // Disable watchpoints just on the debugger side.
Johnny Chen116a5cd2012-02-25 06:44:30 +0000147 Mutex::Locker locker;
148 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000149 DisableAllWatchpoints(false);
Johnny Chen116a5cd2012-02-25 06:44:30 +0000150 ClearAllWatchpointHitCounts();
Chris Lattner24943d22010-06-08 16:52:24 +0000151 m_process_sp.reset();
152 }
153}
154
155const lldb::ProcessSP &
Greg Clayton46c9a352012-02-09 06:16:32 +0000156Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner24943d22010-06-08 16:52:24 +0000157{
158 DeleteCurrentProcess ();
Greg Clayton46c9a352012-02-09 06:16:32 +0000159 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner24943d22010-06-08 16:52:24 +0000160 return m_process_sp;
161}
162
163const lldb::ProcessSP &
164Target::GetProcessSP () const
165{
166 return m_process_sp;
167}
168
Greg Clayton153ccd72011-08-10 02:10:13 +0000169void
170Target::Destroy()
171{
172 Mutex::Locker locker (m_mutex);
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +0000173 m_valid = false;
Greg Clayton153ccd72011-08-10 02:10:13 +0000174 DeleteCurrentProcess ();
175 m_platform_sp.reset();
176 m_arch.Clear();
177 m_images.Clear();
178 m_section_load_list.Clear();
179 const bool notify = false;
180 m_breakpoint_list.RemoveAll(notify);
181 m_internal_breakpoint_list.RemoveAll(notify);
182 m_last_created_breakpoint.reset();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000183 m_last_created_watchpoint.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000184 m_search_filter_sp.reset();
185 m_image_search_paths.Clear(notify);
186 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000187 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000188 m_ast_importer_ap.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000189 m_persistent_variables.Clear();
190 m_stop_hooks.clear();
191 m_stop_hook_next_id = 0;
192 m_suppress_stop_hooks = false;
Enrico Granatadba1de82012-03-27 02:35:13 +0000193 m_suppress_synthetic_value = false;
Greg Clayton153ccd72011-08-10 02:10:13 +0000194}
195
196
Chris Lattner24943d22010-06-08 16:52:24 +0000197BreakpointList &
198Target::GetBreakpointList(bool internal)
199{
200 if (internal)
201 return m_internal_breakpoint_list;
202 else
203 return m_breakpoint_list;
204}
205
206const BreakpointList &
207Target::GetBreakpointList(bool internal) const
208{
209 if (internal)
210 return m_internal_breakpoint_list;
211 else
212 return m_breakpoint_list;
213}
214
215BreakpointSP
216Target::GetBreakpointByID (break_id_t break_id)
217{
218 BreakpointSP bp_sp;
219
220 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
221 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
222 else
223 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
224
225 return bp_sp;
226}
227
228BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000229Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
230 const FileSpecList *source_file_spec_list,
Jim Ingham03c8ee52011-09-21 01:17:13 +0000231 RegularExpression &source_regex,
232 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000233{
Jim Inghamd6d47972011-09-23 00:54:11 +0000234 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
235 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000236 return CreateBreakpoint (filter_sp, resolver_sp, internal);
237}
238
239
240BreakpointSP
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000241Target::CreateBreakpoint (const FileSpecList *containingModules,
242 const FileSpec &file,
243 uint32_t line_no,
244 bool check_inlines,
245 LazyBool skip_prologue,
246 bool internal)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000247{
248 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000249
250 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines,
251 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000252 return CreateBreakpoint (filter_sp, resolver_sp, internal);
253}
254
255
256BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000257Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000258{
Chris Lattner24943d22010-06-08 16:52:24 +0000259 Address so_addr;
260 // Attempt to resolve our load address if possible, though it is ok if
261 // it doesn't resolve to section/offset.
262
Greg Clayton33ed1702010-08-24 00:45:41 +0000263 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000264 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000265 if (!so_addr.IsValid())
266 {
267 // The address didn't resolve, so just set this as an absolute address
268 so_addr.SetOffset (addr);
269 }
270 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000271 return bp_sp;
272}
273
274BreakpointSP
275Target::CreateBreakpoint (Address &addr, bool internal)
276{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000277 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000278 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
279 return CreateBreakpoint (filter_sp, resolver_sp, internal);
280}
281
282BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000283Target::CreateBreakpoint (const FileSpecList *containingModules,
284 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000285 const char *func_name,
286 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000287 LazyBool skip_prologue,
288 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000289{
Greg Clayton12bec712010-06-28 21:30:43 +0000290 BreakpointSP bp_sp;
291 if (func_name)
292 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000293 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000294
295 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
296 func_name,
297 func_name_type_mask,
298 Breakpoint::Exact,
299 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton12bec712010-06-28 21:30:43 +0000300 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
301 }
302 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000303}
304
Jim Ingham4722b102012-03-06 00:37:27 +0000305lldb::BreakpointSP
306Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytonbd5c23d2012-05-15 02:33:01 +0000307 const FileSpecList *containingSourceFiles,
308 const std::vector<std::string> &func_names,
309 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000310 LazyBool skip_prologue,
311 bool internal)
Jim Ingham4722b102012-03-06 00:37:27 +0000312{
313 BreakpointSP bp_sp;
314 size_t num_names = func_names.size();
315 if (num_names > 0)
316 {
317 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
318
319 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
320 func_names,
321 func_name_type_mask,
322 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
323 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
324 }
325 return bp_sp;
326}
327
Jim Inghamc1053622012-03-03 02:05:11 +0000328BreakpointSP
329Target::CreateBreakpoint (const FileSpecList *containingModules,
330 const FileSpecList *containingSourceFiles,
331 const char *func_names[],
332 size_t num_names,
333 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000334 LazyBool skip_prologue,
335 bool internal)
Jim Inghamc1053622012-03-03 02:05:11 +0000336{
337 BreakpointSP bp_sp;
338 if (num_names > 0)
339 {
340 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
341
342 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
343 func_names,
344 num_names,
Jim Ingham4722b102012-03-06 00:37:27 +0000345 func_name_type_mask,
Jim Inghamc1053622012-03-03 02:05:11 +0000346 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
347 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
348 }
349 return bp_sp;
350}
Chris Lattner24943d22010-06-08 16:52:24 +0000351
352SearchFilterSP
353Target::GetSearchFilterForModule (const FileSpec *containingModule)
354{
355 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000356 if (containingModule != NULL)
357 {
358 // TODO: We should look into sharing module based search filters
359 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000360 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000361 }
362 else
363 {
364 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000365 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000366 filter_sp = m_search_filter_sp;
367 }
368 return filter_sp;
369}
370
Jim Ingham03c8ee52011-09-21 01:17:13 +0000371SearchFilterSP
372Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
373{
374 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000375 if (containingModules && containingModules->GetSize() != 0)
376 {
377 // TODO: We should look into sharing module based search filters
378 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000379 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000380 }
381 else
382 {
383 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000384 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000385 filter_sp = m_search_filter_sp;
386 }
387 return filter_sp;
388}
389
Jim Inghamd6d47972011-09-23 00:54:11 +0000390SearchFilterSP
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000391Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
392 const FileSpecList *containingSourceFiles)
Jim Inghamd6d47972011-09-23 00:54:11 +0000393{
394 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
395 return GetSearchFilterForModuleList(containingModules);
396
397 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000398 if (containingModules == NULL)
399 {
400 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
401 // but that will take a little reworking.
402
Greg Clayton13d24fb2012-01-29 20:56:30 +0000403 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000404 }
405 else
406 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000407 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000408 }
409 return filter_sp;
410}
411
Chris Lattner24943d22010-06-08 16:52:24 +0000412BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000413Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000414 const FileSpecList *containingSourceFiles,
415 RegularExpression &func_regex,
416 LazyBool skip_prologue,
417 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000418{
Jim Inghamd6d47972011-09-23 00:54:11 +0000419 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000420 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
421 func_regex,
422 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000423
424 return CreateBreakpoint (filter_sp, resolver_sp, internal);
425}
426
Jim Ingham3df164e2012-03-05 04:47:34 +0000427lldb::BreakpointSP
428Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
429{
430 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
431}
432
Chris Lattner24943d22010-06-08 16:52:24 +0000433BreakpointSP
434Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
435{
436 BreakpointSP bp_sp;
437 if (filter_sp && resolver_sp)
438 {
439 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
440 resolver_sp->SetBreakpoint (bp_sp.get());
441
442 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000443 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000444 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000445 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000446
Greg Claytone005f2c2010-11-06 01:53:30 +0000447 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000448 if (log)
449 {
450 StreamString s;
451 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
452 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
453 }
454
Chris Lattner24943d22010-06-08 16:52:24 +0000455 bp_sp->ResolveBreakpoint();
456 }
Jim Inghamd1686902010-10-14 23:45:03 +0000457
458 if (!internal && bp_sp)
459 {
460 m_last_created_breakpoint = bp_sp;
461 }
462
Chris Lattner24943d22010-06-08 16:52:24 +0000463 return bp_sp;
464}
465
Johnny Chenda5a8022011-09-20 23:28:55 +0000466bool
467Target::ProcessIsValid()
468{
469 return (m_process_sp && m_process_sp->IsAlive());
470}
471
Johnny Chen3f883492012-06-04 23:19:54 +0000472static bool
473CheckIfWatchpointsExhausted(Target *target, Error &error)
474{
475 uint32_t num_supported_hardware_watchpoints;
476 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
477 if (rc.Success())
478 {
479 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
480 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
481 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
482 num_supported_hardware_watchpoints);
483 }
484 return false;
485}
486
Johnny Chenecd4feb2011-10-14 00:42:25 +0000487// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000488// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000489WatchpointSP
Johnny Chen3f883492012-06-04 23:19:54 +0000490Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type, Error &error)
Johnny Chen34bbf852011-09-12 23:38:44 +0000491{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000492 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
493 if (log)
494 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
495 __FUNCTION__, addr, size, type);
496
Johnny Chenecd4feb2011-10-14 00:42:25 +0000497 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000498 if (!ProcessIsValid())
Johnny Chen3f883492012-06-04 23:19:54 +0000499 {
500 error.SetErrorString("process is not alive");
Johnny Chenecd4feb2011-10-14 00:42:25 +0000501 return wp_sp;
Johnny Chen3f883492012-06-04 23:19:54 +0000502 }
Johnny Chen22a56cc2011-09-14 22:20:15 +0000503 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen3f883492012-06-04 23:19:54 +0000504 {
505 if (size == 0)
506 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
507 else
508 error.SetErrorStringWithFormat("invalid watch address: %llu", addr);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000509 return wp_sp;
Johnny Chen3f883492012-06-04 23:19:54 +0000510 }
Johnny Chen9bf11992011-09-13 01:15:36 +0000511
Johnny Chenecd4feb2011-10-14 00:42:25 +0000512 // Currently we only support one watchpoint per address, with total number
513 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chenbbf6aa52012-05-31 22:56:36 +0000514
515 // Grab the list mutex while doing operations.
516 Mutex::Locker locker;
517 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000518 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000519 if (matched_sp)
520 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000521 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000522 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000523 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
524 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000525 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000526 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000527 wp_sp = matched_sp;
528 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000529 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000530 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000531 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000532 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000533 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000534 }
535
Johnny Chenecd4feb2011-10-14 00:42:25 +0000536 if (!wp_sp) {
537 Watchpoint *new_wp = new Watchpoint(addr, size);
538 if (!new_wp) {
539 printf("Watchpoint ctor failed, out of memory?\n");
540 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000541 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000542 new_wp->SetWatchpointType(type);
543 new_wp->SetTarget(this);
544 wp_sp.reset(new_wp);
545 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000546 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000547
Johnny Chen3f883492012-06-04 23:19:54 +0000548 error = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000549 if (log)
550 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
551 __FUNCTION__,
Johnny Chen3f883492012-06-04 23:19:54 +0000552 error.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000553 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000554
Johnny Chen3f883492012-06-04 23:19:54 +0000555 if (error.Fail()) {
Johnny Chen155599b2012-03-26 22:00:10 +0000556 // Enabling the watchpoint on the device side failed.
557 // Remove the said watchpoint from the list maintained by the target instance.
558 m_watchpoint_list.Remove(wp_sp->GetID());
Johnny Chen3f883492012-06-04 23:19:54 +0000559 // See if we could provide more helpful error message.
560 if (!CheckIfWatchpointsExhausted(this, error))
561 {
562 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
563 error.SetErrorStringWithFormat("watch size of %lu is not supported", size);
564 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000565 wp_sp.reset();
Johnny Chen155599b2012-03-26 22:00:10 +0000566 }
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000567 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000568 m_last_created_watchpoint = wp_sp;
569 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000570}
571
Chris Lattner24943d22010-06-08 16:52:24 +0000572void
573Target::RemoveAllBreakpoints (bool internal_also)
574{
Greg Claytone005f2c2010-11-06 01:53:30 +0000575 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000576 if (log)
577 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
578
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000579 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000580 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000581 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000582
583 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000584}
585
586void
587Target::DisableAllBreakpoints (bool internal_also)
588{
Greg Claytone005f2c2010-11-06 01:53:30 +0000589 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000590 if (log)
591 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
592
593 m_breakpoint_list.SetEnabledAll (false);
594 if (internal_also)
595 m_internal_breakpoint_list.SetEnabledAll (false);
596}
597
598void
599Target::EnableAllBreakpoints (bool internal_also)
600{
Greg Claytone005f2c2010-11-06 01:53:30 +0000601 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000602 if (log)
603 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
604
605 m_breakpoint_list.SetEnabledAll (true);
606 if (internal_also)
607 m_internal_breakpoint_list.SetEnabledAll (true);
608}
609
610bool
611Target::RemoveBreakpointByID (break_id_t break_id)
612{
Greg Claytone005f2c2010-11-06 01:53:30 +0000613 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000614 if (log)
615 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
616
617 if (DisableBreakpointByID (break_id))
618 {
619 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000620 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000621 else
Jim Inghamd1686902010-10-14 23:45:03 +0000622 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000623 if (m_last_created_breakpoint)
624 {
625 if (m_last_created_breakpoint->GetID() == break_id)
626 m_last_created_breakpoint.reset();
627 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000628 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000629 }
Chris Lattner24943d22010-06-08 16:52:24 +0000630 return true;
631 }
632 return false;
633}
634
635bool
636Target::DisableBreakpointByID (break_id_t break_id)
637{
Greg Claytone005f2c2010-11-06 01:53:30 +0000638 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000639 if (log)
640 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
641
642 BreakpointSP bp_sp;
643
644 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
645 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
646 else
647 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
648 if (bp_sp)
649 {
650 bp_sp->SetEnabled (false);
651 return true;
652 }
653 return false;
654}
655
656bool
657Target::EnableBreakpointByID (break_id_t break_id)
658{
Greg Claytone005f2c2010-11-06 01:53:30 +0000659 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000660 if (log)
661 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
662 __FUNCTION__,
663 break_id,
664 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
665
666 BreakpointSP bp_sp;
667
668 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
669 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
670 else
671 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
672
673 if (bp_sp)
674 {
675 bp_sp->SetEnabled (true);
676 return true;
677 }
678 return false;
679}
680
Johnny Chenc86582f2011-09-23 21:21:43 +0000681// The flag 'end_to_end', default to true, signifies that the operation is
682// performed end to end, for both the debugger and the debuggee.
683
Johnny Chenecd4feb2011-10-14 00:42:25 +0000684// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
685// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000686bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000687Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000688{
689 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
690 if (log)
691 log->Printf ("Target::%s\n", __FUNCTION__);
692
Johnny Chenc86582f2011-09-23 21:21:43 +0000693 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000694 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000695 return true;
696 }
697
698 // Otherwise, it's an end to end operation.
699
Johnny Chenda5a8022011-09-20 23:28:55 +0000700 if (!ProcessIsValid())
701 return false;
702
Johnny Chenecd4feb2011-10-14 00:42:25 +0000703 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000704 for (size_t i = 0; i < num_watchpoints; ++i)
705 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000706 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
707 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000708 return false;
709
Johnny Chenecd4feb2011-10-14 00:42:25 +0000710 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000711 if (rc.Fail())
712 return false;
713 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000714 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000715 return true; // Success!
716}
717
Johnny Chenecd4feb2011-10-14 00:42:25 +0000718// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
719// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000720bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000721Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000722{
723 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
724 if (log)
725 log->Printf ("Target::%s\n", __FUNCTION__);
726
Johnny Chenc86582f2011-09-23 21:21:43 +0000727 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000728 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000729 return true;
730 }
731
732 // Otherwise, it's an end to end operation.
733
Johnny Chenda5a8022011-09-20 23:28:55 +0000734 if (!ProcessIsValid())
735 return false;
736
Johnny Chenecd4feb2011-10-14 00:42:25 +0000737 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000738 for (size_t i = 0; i < num_watchpoints; ++i)
739 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000740 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
741 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000742 return false;
743
Johnny Chenecd4feb2011-10-14 00:42:25 +0000744 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000745 if (rc.Fail())
746 return false;
747 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000748 return true; // Success!
749}
750
Johnny Chenecd4feb2011-10-14 00:42:25 +0000751// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
752// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000753bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000754Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000755{
756 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
757 if (log)
758 log->Printf ("Target::%s\n", __FUNCTION__);
759
Johnny Chenc86582f2011-09-23 21:21:43 +0000760 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000761 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000762 return true;
763 }
764
765 // Otherwise, it's an end to end operation.
766
Johnny Chenda5a8022011-09-20 23:28:55 +0000767 if (!ProcessIsValid())
768 return false;
769
Johnny Chenecd4feb2011-10-14 00:42:25 +0000770 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000771 for (size_t i = 0; i < num_watchpoints; ++i)
772 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000773 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
774 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000775 return false;
776
Johnny Chenecd4feb2011-10-14 00:42:25 +0000777 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000778 if (rc.Fail())
779 return false;
780 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000781 return true; // Success!
782}
783
Johnny Chen116a5cd2012-02-25 06:44:30 +0000784// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
785bool
786Target::ClearAllWatchpointHitCounts ()
787{
788 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
789 if (log)
790 log->Printf ("Target::%s\n", __FUNCTION__);
791
792 size_t num_watchpoints = m_watchpoint_list.GetSize();
793 for (size_t i = 0; i < num_watchpoints; ++i)
794 {
795 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
796 if (!wp_sp)
797 return false;
798
799 wp_sp->ResetHitCount();
800 }
801 return true; // Success!
802}
803
Johnny Chenecd4feb2011-10-14 00:42:25 +0000804// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000805// during these operations.
806bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000807Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000808{
809 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
810 if (log)
811 log->Printf ("Target::%s\n", __FUNCTION__);
812
813 if (!ProcessIsValid())
814 return false;
815
Johnny Chenecd4feb2011-10-14 00:42:25 +0000816 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000817 for (size_t i = 0; i < num_watchpoints; ++i)
818 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000819 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
820 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000821 return false;
822
Johnny Chenecd4feb2011-10-14 00:42:25 +0000823 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000824 }
825 return true; // Success!
826}
827
Johnny Chenecd4feb2011-10-14 00:42:25 +0000828// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000829bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000830Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000831{
832 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
833 if (log)
834 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
835
836 if (!ProcessIsValid())
837 return false;
838
Johnny Chenecd4feb2011-10-14 00:42:25 +0000839 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
840 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000841 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000842 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000843 if (rc.Success())
844 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000845
Johnny Chen01acfa72011-09-22 18:04:58 +0000846 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000847 }
848 return false;
849}
850
Johnny Chenecd4feb2011-10-14 00:42:25 +0000851// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000852bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000853Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000854{
855 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
856 if (log)
857 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
858
859 if (!ProcessIsValid())
860 return false;
861
Johnny Chenecd4feb2011-10-14 00:42:25 +0000862 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
863 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000864 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000865 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000866 if (rc.Success())
867 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000868
Johnny Chen01acfa72011-09-22 18:04:58 +0000869 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000870 }
871 return false;
872}
873
Johnny Chenecd4feb2011-10-14 00:42:25 +0000874// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000875bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000876Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000877{
878 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
879 if (log)
880 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
881
Johnny Chenecd4feb2011-10-14 00:42:25 +0000882 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000883 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000884 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000885 return true;
886 }
887 return false;
888}
889
Johnny Chenecd4feb2011-10-14 00:42:25 +0000890// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000891bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000892Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000893{
894 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
895 if (log)
896 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
897
898 if (!ProcessIsValid())
899 return false;
900
Johnny Chenecd4feb2011-10-14 00:42:25 +0000901 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
902 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000903 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000904 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000905 return true;
906 }
907 return false;
908}
909
Chris Lattner24943d22010-06-08 16:52:24 +0000910ModuleSP
911Target::GetExecutableModule ()
912{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000913 return m_images.GetModuleAtIndex(0);
914}
915
916Module*
917Target::GetExecutableModulePointer ()
918{
919 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000920}
921
922void
923Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
924{
925 m_images.Clear();
926 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000927 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000928 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000929
930 if (executable_sp.get())
931 {
932 Timer scoped_timer (__PRETTY_FUNCTION__,
933 "Target::SetExecutableModule (executable = '%s/%s')",
934 executable_sp->GetFileSpec().GetDirectory().AsCString(),
935 executable_sp->GetFileSpec().GetFilename().AsCString());
936
937 m_images.Append(executable_sp); // The first image is our exectuable file
938
Jim Ingham7508e732010-08-09 23:31:02 +0000939 // 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 +0000940 if (!m_arch.IsValid())
941 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000942
Chris Lattner24943d22010-06-08 16:52:24 +0000943 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000944 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000945
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000946 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000947 {
948 executable_objfile->GetDependentModules(dependent_files);
949 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
950 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000951 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
952 FileSpec platform_dependent_file_spec;
953 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000954 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000955 else
956 platform_dependent_file_spec = dependent_file_spec;
957
Greg Clayton444fe992012-02-26 05:51:37 +0000958 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
959 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +0000960 if (image_module_sp.get())
961 {
Chris Lattner24943d22010-06-08 16:52:24 +0000962 ObjectFile *objfile = image_module_sp->GetObjectFile();
963 if (objfile)
964 objfile->GetDependentModules(dependent_files);
965 }
966 }
967 }
Chris Lattner24943d22010-06-08 16:52:24 +0000968 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000969
Greg Clayton73844aa2012-08-22 17:17:09 +0000970// UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000971}
972
973
Jim Ingham7508e732010-08-09 23:31:02 +0000974bool
975Target::SetArchitecture (const ArchSpec &arch_spec)
976{
Greg Claytonb170aee2012-05-08 01:45:38 +0000977 if (m_arch == arch_spec || !m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000978 {
Greg Claytonb170aee2012-05-08 01:45:38 +0000979 // If we haven't got a valid arch spec, or the architectures are
980 // compatible, so just update the architecture. Architectures can be
981 // equal, yet the triple OS and vendor might change, so we need to do
982 // the assignment here just in case.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000983 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000984 return true;
985 }
986 else
987 {
988 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000989 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000990 ModuleSP executable_sp = GetExecutableModule ();
991 m_images.Clear();
992 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000993 m_scratch_ast_source_ap.reset();
994 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000995 // Need to do something about unsetting breakpoints.
996
997 if (executable_sp)
998 {
Greg Clayton444fe992012-02-26 05:51:37 +0000999 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1000 Error error = ModuleList::GetSharedModule (module_spec,
1001 executable_sp,
Greg Clayton73844aa2012-08-22 17:17:09 +00001002 NULL, // &GetExecutableSearchPaths(), // TODO: SETTINGS
Greg Clayton444fe992012-02-26 05:51:37 +00001003 NULL,
1004 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +00001005
1006 if (!error.Fail() && executable_sp)
1007 {
1008 SetExecutableModule (executable_sp, true);
1009 return true;
1010 }
Jim Ingham7508e732010-08-09 23:31:02 +00001011 }
1012 }
Greg Claytonb170aee2012-05-08 01:45:38 +00001013 return false;
Jim Ingham7508e732010-08-09 23:31:02 +00001014}
Chris Lattner24943d22010-06-08 16:52:24 +00001015
Chris Lattner24943d22010-06-08 16:52:24 +00001016void
1017Target::ModuleAdded (ModuleSP &module_sp)
1018{
1019 // A module is being added to this target for the first time
1020 ModuleList module_list;
1021 module_list.Append(module_sp);
1022 ModulesDidLoad (module_list);
1023}
1024
1025void
1026Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
1027{
Jim Ingham3b8a6052011-08-03 01:00:06 +00001028 // A module is replacing an already added module
Jim Ingham03e5e512012-05-17 18:38:42 +00001029 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner24943d22010-06-08 16:52:24 +00001030}
1031
1032void
1033Target::ModulesDidLoad (ModuleList &module_list)
1034{
1035 m_breakpoint_list.UpdateBreakpoints (module_list, true);
1036 // TODO: make event data that packages up the module_list
1037 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1038}
1039
1040void
1041Target::ModulesDidUnload (ModuleList &module_list)
1042{
1043 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +00001044
1045 // Remove the images from the target image list
1046 m_images.Remove(module_list);
1047
Chris Lattner24943d22010-06-08 16:52:24 +00001048 // TODO: make event data that packages up the module_list
1049 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1050}
1051
Jim Ingham7089d8a2011-10-28 23:14:11 +00001052
Daniel Dunbar705a0982011-10-31 22:50:37 +00001053bool
Greg Clayton444fe992012-02-26 05:51:37 +00001054Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +00001055{
1056
Greg Clayton73844aa2012-08-22 17:17:09 +00001057 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001058 {
1059 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001060 ModuleSpec module_spec (module_file_spec);
1061 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001062
1063 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1064 // black list.
1065 if (num_modules > 0)
1066 {
1067 for (int i = 0; i < num_modules; i++)
1068 {
1069 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1070 return false;
1071 }
1072 return true;
1073 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00001074 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001075 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001076}
1077
Daniel Dunbar705a0982011-10-31 22:50:37 +00001078bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001079Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1080{
Greg Clayton73844aa2012-08-22 17:17:09 +00001081 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001082 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001083 if (m_platform_sp)
1084 return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001085 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001086 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001087}
1088
Chris Lattner24943d22010-06-08 16:52:24 +00001089size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001090Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1091{
Greg Clayton3508c382012-02-24 01:59:29 +00001092 SectionSP section_sp (addr.GetSection());
1093 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001094 {
Jason Molenda6b028d62012-04-25 00:06:56 +00001095 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1096 if (section_sp->IsEncrypted())
1097 {
Greg Clayton04e6ada2012-05-25 17:05:55 +00001098 error.SetErrorString("section is encrypted");
Jason Molenda6b028d62012-04-25 00:06:56 +00001099 return 0;
1100 }
Greg Clayton3508c382012-02-24 01:59:29 +00001101 ModuleSP module_sp (section_sp->GetModule());
1102 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001103 {
Greg Clayton3508c382012-02-24 01:59:29 +00001104 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1105 if (objfile)
1106 {
1107 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1108 addr.GetOffset(),
1109 dst,
1110 dst_len);
1111 if (bytes_read > 0)
1112 return bytes_read;
1113 else
1114 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1115 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001116 else
Greg Clayton3508c382012-02-24 01:59:29 +00001117 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001118 }
1119 else
Greg Clayton3508c382012-02-24 01:59:29 +00001120 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001121 }
1122 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001123 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001124
Greg Clayton26100dc2011-01-07 01:57:07 +00001125 return 0;
1126}
1127
1128size_t
Enrico Granata91544802011-09-06 19:20:51 +00001129Target::ReadMemory (const Address& addr,
1130 bool prefer_file_cache,
1131 void *dst,
1132 size_t dst_len,
1133 Error &error,
1134 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001135{
Chris Lattner24943d22010-06-08 16:52:24 +00001136 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001137
Enrico Granata91544802011-09-06 19:20:51 +00001138 // if we end up reading this from process memory, we will fill this
1139 // with the actual load address
1140 if (load_addr_ptr)
1141 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1142
Greg Clayton26100dc2011-01-07 01:57:07 +00001143 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001144
1145 addr_t load_addr = LLDB_INVALID_ADDRESS;
1146 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001147 Address resolved_addr;
1148 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001149 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001150 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001151 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001152 // No sections are loaded, so we must assume we are not running
1153 // yet and anything we are given is a file address.
1154 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1155 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001156 }
Greg Clayton70436352010-06-30 23:03:03 +00001157 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001158 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001159 // We have at least one section loaded. This can be becuase
1160 // we have manually loaded some sections with "target modules load ..."
1161 // or because we have have a live process that has sections loaded
1162 // through the dynamic loader
1163 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1164 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001165 }
Greg Clayton70436352010-06-30 23:03:03 +00001166 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001167 if (!resolved_addr.IsValid())
1168 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001169
Greg Clayton9b82f862011-07-11 05:12:02 +00001170
Greg Clayton26100dc2011-01-07 01:57:07 +00001171 if (prefer_file_cache)
1172 {
1173 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1174 if (bytes_read > 0)
1175 return bytes_read;
1176 }
Greg Clayton70436352010-06-30 23:03:03 +00001177
Johnny Chenda5a8022011-09-20 23:28:55 +00001178 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001179 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001180 if (load_addr == LLDB_INVALID_ADDRESS)
1181 load_addr = resolved_addr.GetLoadAddress (this);
1182
Greg Clayton70436352010-06-30 23:03:03 +00001183 if (load_addr == LLDB_INVALID_ADDRESS)
1184 {
Greg Clayton3508c382012-02-24 01:59:29 +00001185 ModuleSP addr_module_sp (resolved_addr.GetModule());
1186 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001187 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001188 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001189 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001190 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001191 else
Greg Clayton9c236732011-10-26 00:56:27 +00001192 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001193 }
1194 else
1195 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001196 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001197 if (bytes_read != dst_len)
1198 {
1199 if (error.Success())
1200 {
1201 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001202 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001203 else
Greg Clayton9c236732011-10-26 00:56:27 +00001204 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 +00001205 }
1206 }
Greg Clayton70436352010-06-30 23:03:03 +00001207 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001208 {
1209 if (load_addr_ptr)
1210 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001211 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001212 }
Greg Clayton70436352010-06-30 23:03:03 +00001213 // If the address is not section offset we have an address that
1214 // doesn't resolve to any address in any currently loaded shared
1215 // libaries and we failed to read memory so there isn't anything
1216 // more we can do. If it is section offset, we might be able to
1217 // read cached memory from the object file.
1218 if (!resolved_addr.IsSectionOffset())
1219 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001220 }
Chris Lattner24943d22010-06-08 16:52:24 +00001221 }
Greg Clayton70436352010-06-30 23:03:03 +00001222
Greg Clayton9b82f862011-07-11 05:12:02 +00001223 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001224 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001225 // If we didn't already try and read from the object file cache, then
1226 // try it after failing to read from the process.
1227 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001228 }
1229 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001230}
1231
Greg Clayton7dd98df2011-07-12 17:06:17 +00001232size_t
1233Target::ReadScalarIntegerFromMemory (const Address& addr,
1234 bool prefer_file_cache,
1235 uint32_t byte_size,
1236 bool is_signed,
1237 Scalar &scalar,
1238 Error &error)
1239{
1240 uint64_t uval;
1241
1242 if (byte_size <= sizeof(uval))
1243 {
1244 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1245 if (bytes_read == byte_size)
1246 {
1247 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1248 uint32_t offset = 0;
1249 if (byte_size <= 4)
1250 scalar = data.GetMaxU32 (&offset, byte_size);
1251 else
1252 scalar = data.GetMaxU64 (&offset, byte_size);
1253
1254 if (is_signed)
1255 scalar.SignExtend(byte_size * 8);
1256 return bytes_read;
1257 }
1258 }
1259 else
1260 {
1261 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1262 }
1263 return 0;
1264}
1265
1266uint64_t
1267Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1268 bool prefer_file_cache,
1269 size_t integer_byte_size,
1270 uint64_t fail_value,
1271 Error &error)
1272{
1273 Scalar scalar;
1274 if (ReadScalarIntegerFromMemory (addr,
1275 prefer_file_cache,
1276 integer_byte_size,
1277 false,
1278 scalar,
1279 error))
1280 return scalar.ULongLong(fail_value);
1281 return fail_value;
1282}
1283
1284bool
1285Target::ReadPointerFromMemory (const Address& addr,
1286 bool prefer_file_cache,
1287 Error &error,
1288 Address &pointer_addr)
1289{
1290 Scalar scalar;
1291 if (ReadScalarIntegerFromMemory (addr,
1292 prefer_file_cache,
1293 m_arch.GetAddressByteSize(),
1294 false,
1295 scalar,
1296 error))
1297 {
1298 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1299 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1300 {
1301 if (m_section_load_list.IsEmpty())
1302 {
1303 // No sections are loaded, so we must assume we are not running
1304 // yet and anything we are given is a file address.
1305 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1306 }
1307 else
1308 {
1309 // We have at least one section loaded. This can be becuase
1310 // we have manually loaded some sections with "target modules load ..."
1311 // or because we have have a live process that has sections loaded
1312 // through the dynamic loader
1313 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1314 }
1315 // We weren't able to resolve the pointer value, so just return
1316 // an address with no section
1317 if (!pointer_addr.IsValid())
1318 pointer_addr.SetOffset (pointer_vm_addr);
1319 return true;
1320
1321 }
1322 }
1323 return false;
1324}
Chris Lattner24943d22010-06-08 16:52:24 +00001325
1326ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001327Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001328{
Chris Lattner24943d22010-06-08 16:52:24 +00001329 ModuleSP module_sp;
1330
Chris Lattner24943d22010-06-08 16:52:24 +00001331 Error error;
1332
Jim Ingham03e5e512012-05-17 18:38:42 +00001333 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1334 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytone1ef1e32012-04-27 00:58:27 +00001335
Jim Ingham03e5e512012-05-17 18:38:42 +00001336 if (module_spec.GetUUID().IsValid())
1337 module_sp = m_images.FindFirstModule(module_spec);
1338
Greg Claytone1ef1e32012-04-27 00:58:27 +00001339 if (!module_sp)
1340 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001341 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1342 bool did_create_module = false;
1343
1344 // If there are image search path entries, try to use them first to acquire a suitable image.
1345 if (m_image_search_paths.GetSize())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001346 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001347 ModuleSpec transformed_spec (module_spec);
1348 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1349 {
1350 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1351 error = ModuleList::GetSharedModule (transformed_spec,
1352 module_sp,
Greg Clayton73844aa2012-08-22 17:17:09 +00001353 NULL, // TODO: SETTINGS &GetExecutableSearchPaths(),
Jim Ingham03e5e512012-05-17 18:38:42 +00001354 &old_module_sp,
1355 &did_create_module);
1356 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001357 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001358
Greg Claytone1ef1e32012-04-27 00:58:27 +00001359 if (!module_sp)
1360 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001361 // If we have a UUID, we can check our global shared module list in case
1362 // we already have it. If we don't have a valid UUID, then we can't since
1363 // the path in "module_spec" will be a platform path, and we will need to
1364 // let the platform find that file. For example, we could be asking for
1365 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1366 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1367 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1368 // cache.
1369 if (module_spec.GetUUID().IsValid())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001370 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001371 // We have a UUID, it is OK to check the global module list...
1372 error = ModuleList::GetSharedModule (module_spec,
1373 module_sp,
Greg Clayton73844aa2012-08-22 17:17:09 +00001374 NULL, // TODO: SETTINGS &GetExecutableSearchPaths(),
1375 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001376 &did_create_module);
Greg Claytone1ef1e32012-04-27 00:58:27 +00001377 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001378
1379 if (!module_sp)
Greg Claytone1ef1e32012-04-27 00:58:27 +00001380 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001381 // The platform is responsible for finding and caching an appropriate
1382 // module in the shared module cache.
1383 if (m_platform_sp)
1384 {
1385 FileSpec platform_file_spec;
1386 error = m_platform_sp->GetSharedModule (module_spec,
1387 module_sp,
Greg Clayton73844aa2012-08-22 17:17:09 +00001388 NULL, // TODO: SETTINGS &GetExecutableSearchPaths(),
1389 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001390 &did_create_module);
1391 }
1392 else
1393 {
1394 error.SetErrorString("no platform is currently set");
1395 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001396 }
1397 }
Chris Lattner24943d22010-06-08 16:52:24 +00001398
Jim Ingham03e5e512012-05-17 18:38:42 +00001399 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1400 // module in the list already, and if there was, let's remove it.
1401 if (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001402 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001403 // GetSharedModule is not guaranteed to find the old shared module, for instance
1404 // in the common case where you pass in the UUID, it is only going to find the one
1405 // module matching the UUID. In fact, it has no good way to know what the "old module"
1406 // relevant to this target is, since there might be many copies of a module with this file spec
1407 // in various running debug sessions, but only one of them will belong to this target.
1408 // So let's remove the UUID from the module list, and look in the target's module list.
1409 // Only do this if there is SOMETHING else in the module spec...
1410 if (!old_module_sp)
1411 {
1412 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
1413 {
1414 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1415 module_spec_copy.GetUUID().Clear();
1416
1417 ModuleList found_modules;
1418 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1419 if (num_found == 1)
1420 {
1421 old_module_sp = found_modules.GetModuleAtIndex(0);
1422 }
1423 }
1424 }
1425
1426 m_images.Append (module_sp);
Chris Lattner24943d22010-06-08 16:52:24 +00001427 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
Jim Ingham03e5e512012-05-17 18:38:42 +00001428 {
Chris Lattner24943d22010-06-08 16:52:24 +00001429 ModuleUpdated(old_module_sp, module_sp);
Jim Ingham03e5e512012-05-17 18:38:42 +00001430 m_images.Remove (old_module_sp);
1431 Module *old_module_ptr = old_module_sp.get();
1432 old_module_sp.reset();
1433 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1434 }
Chris Lattner24943d22010-06-08 16:52:24 +00001435 else
1436 ModuleAdded(module_sp);
1437 }
1438 }
1439 if (error_ptr)
1440 *error_ptr = error;
1441 return module_sp;
1442}
1443
1444
Greg Clayton289afcb2012-02-18 05:35:26 +00001445TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001446Target::CalculateTarget ()
1447{
Greg Clayton289afcb2012-02-18 05:35:26 +00001448 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001449}
1450
Greg Clayton289afcb2012-02-18 05:35:26 +00001451ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001452Target::CalculateProcess ()
1453{
Greg Clayton289afcb2012-02-18 05:35:26 +00001454 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001455}
1456
Greg Clayton289afcb2012-02-18 05:35:26 +00001457ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001458Target::CalculateThread ()
1459{
Greg Clayton289afcb2012-02-18 05:35:26 +00001460 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001461}
1462
Greg Clayton289afcb2012-02-18 05:35:26 +00001463StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001464Target::CalculateStackFrame ()
1465{
Greg Clayton289afcb2012-02-18 05:35:26 +00001466 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001467}
1468
1469void
Greg Claytona830adb2010-10-04 01:05:56 +00001470Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001471{
Greg Clayton567e7f32011-09-22 04:58:26 +00001472 exe_ctx.Clear();
1473 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001474}
1475
1476PathMappingList &
1477Target::GetImageSearchPathList ()
1478{
1479 return m_image_search_paths;
1480}
1481
1482void
1483Target::ImageSearchPathsChanged
1484(
1485 const PathMappingList &path_list,
1486 void *baton
1487)
1488{
1489 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001490 ModuleSP exe_module_sp (target->GetExecutableModule());
1491 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001492 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001493 target->m_images.Clear();
1494 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001495 }
1496}
1497
1498ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001499Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001500{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001501 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001502 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001503 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001504 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001505 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001506 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1507 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1508 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1509 }
Chris Lattner24943d22010-06-08 16:52:24 +00001510 return m_scratch_ast_context_ap.get();
1511}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001512
Sean Callanan4938bd62011-11-16 18:20:47 +00001513ClangASTImporter *
1514Target::GetClangASTImporter()
1515{
1516 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1517
1518 if (!ast_importer)
1519 {
1520 ast_importer = new ClangASTImporter();
1521 m_ast_importer_ap.reset(ast_importer);
1522 }
1523
1524 return ast_importer;
1525}
1526
Greg Clayton990de7b2010-11-18 23:32:35 +00001527void
Caroline Tice2a456812011-03-10 22:14:10 +00001528Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001529{
Greg Clayton73844aa2012-08-22 17:17:09 +00001530// UserSettingsController::InitializeSettingsController (GetSettingsController(),
1531// SettingsController::global_settings_table,
1532// SettingsController::instance_settings_table);
1533//
1534// // Now call SettingsInitialize() on each 'child' setting of Target
1535// Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001536}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001537
Greg Clayton990de7b2010-11-18 23:32:35 +00001538void
Caroline Tice2a456812011-03-10 22:14:10 +00001539Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001540{
Caroline Tice2a456812011-03-10 22:14:10 +00001541
1542 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
Greg Clayton73844aa2012-08-22 17:17:09 +00001543//
1544// Process::SettingsTerminate ();
1545//
1546// // Now terminate Target Settings.
1547//
1548// UserSettingsControllerSP &usc = GetSettingsController();
1549// UserSettingsController::FinalizeSettingsController (usc);
1550// usc.reset();
Greg Clayton990de7b2010-11-18 23:32:35 +00001551}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001552
Greg Clayton73844aa2012-08-22 17:17:09 +00001553//UserSettingsControllerSP &
1554//Target::GetSettingsController ()
1555//{
1556// static UserSettingsControllerSP g_settings_controller_sp;
1557// if (!g_settings_controller_sp)
1558// {
1559// g_settings_controller_sp.reset (new Target::SettingsController);
1560// // The first shared pointer to Target::SettingsController in
1561// // g_settings_controller_sp must be fully created above so that
1562// // the TargetInstanceSettings can use a weak_ptr to refer back
1563// // to the master setttings controller
1564// InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1565// false,
1566// InstanceSettings::GetDefaultName().AsCString()));
1567// g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1568// }
1569// return g_settings_controller_sp;
1570//}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001571
Greg Clayton9ce95382012-02-13 23:10:39 +00001572FileSpecList
1573Target::GetDefaultExecutableSearchPaths ()
1574{
Greg Clayton73844aa2012-08-22 17:17:09 +00001575 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1576 if (properties_sp)
1577 return properties_sp->GetExecutableSearchPaths();
Greg Clayton9ce95382012-02-13 23:10:39 +00001578 return FileSpecList();
1579}
1580
Caroline Tice5bc8c972010-09-20 20:44:43 +00001581ArchSpec
1582Target::GetDefaultArchitecture ()
1583{
Greg Clayton73844aa2012-08-22 17:17:09 +00001584 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1585 if (properties_sp)
1586 return properties_sp->GetDefaultArchitecture();
Greg Clayton469e08d2012-05-15 02:44:13 +00001587 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001588}
1589
1590void
Greg Clayton73844aa2012-08-22 17:17:09 +00001591Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001592{
Greg Clayton73844aa2012-08-22 17:17:09 +00001593 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1594 if (properties_sp)
1595 return properties_sp->SetDefaultArchitecture(arch);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001596}
1597
Greg Claytona830adb2010-10-04 01:05:56 +00001598Target *
1599Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1600{
1601 // The target can either exist in the "process" of ExecutionContext, or in
1602 // the "target_sp" member of SymbolContext. This accessor helper function
1603 // will get the target from one of these locations.
1604
1605 Target *target = NULL;
1606 if (sc_ptr != NULL)
1607 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001608 if (target == NULL && exe_ctx_ptr)
1609 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001610 return target;
1611}
1612
1613
Greg Clayton73844aa2012-08-22 17:17:09 +00001614//void
1615//Target::UpdateInstanceName ()
1616//{
1617// StreamString sstr;
1618//
1619// Module *exe_module = GetExecutableModulePointer();
1620// if (exe_module)
1621// {
1622// sstr.Printf ("%s_%s",
1623// exe_module->GetFileSpec().GetFilename().AsCString(),
1624// exe_module->GetArchitecture().GetArchitectureName());
1625// GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1626// }
1627//}
1628//
Sean Callanan77e93942010-10-29 00:29:03 +00001629const char *
1630Target::GetExpressionPrefixContentsAsCString ()
1631{
Greg Clayton73844aa2012-08-22 17:17:09 +00001632 // TODO: SETTINGS
1633// if (!m_expr_prefix_contents.empty())
1634// return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001635 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001636}
1637
Greg Clayton427f2902010-12-14 02:59:59 +00001638ExecutionResults
1639Target::EvaluateExpression
1640(
1641 const char *expr_cstr,
1642 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001643 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001644 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001645 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001646 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001647 lldb::DynamicValueType use_dynamic,
Enrico Granata6cca9692012-07-16 23:10:35 +00001648 lldb::ValueObjectSP &result_valobj_sp,
1649 uint32_t single_thread_timeout_usec
Greg Clayton427f2902010-12-14 02:59:59 +00001650)
1651{
1652 ExecutionResults execution_results = eExecutionSetupError;
1653
1654 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001655
1656 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1657 return execution_results;
1658
Jim Ingham3613ae12011-05-12 02:06:14 +00001659 // We shouldn't run stop hooks in expressions.
1660 // Be sure to reset this if you return anywhere within this function.
1661 bool old_suppress_value = m_suppress_stop_hooks;
1662 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001663
1664 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001665
1666 const size_t expr_cstr_len = ::strlen (expr_cstr);
1667
Greg Clayton427f2902010-12-14 02:59:59 +00001668 if (frame)
1669 {
1670 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001671 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001672 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001673 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1674 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001675 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001676
1677 // Make sure we don't have any things that we know a variable expression
1678 // won't be able to deal with before calling into it
1679 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1680 {
1681 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1682 use_dynamic,
1683 expr_path_options,
1684 var_sp,
1685 error);
Enrico Granata4d609c92012-04-24 22:15:37 +00001686 // if this expression results in a bitfield, we give up and let the IR handle it
1687 if (result_valobj_sp && result_valobj_sp->IsBitfield())
1688 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001689 }
Greg Clayton427f2902010-12-14 02:59:59 +00001690 }
1691 else if (m_process_sp)
1692 {
1693 m_process_sp->CalculateExecutionContext(exe_ctx);
1694 }
1695 else
1696 {
1697 CalculateExecutionContext(exe_ctx);
1698 }
1699
1700 if (result_valobj_sp)
1701 {
1702 execution_results = eExecutionCompleted;
1703 // We got a result from the frame variable expression path above...
1704 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1705
1706 lldb::ValueObjectSP const_valobj_sp;
1707
1708 // Check in case our value is already a constant value
1709 if (result_valobj_sp->GetIsConstant())
1710 {
1711 const_valobj_sp = result_valobj_sp;
1712 const_valobj_sp->SetName (persistent_variable_name);
1713 }
1714 else
Jim Inghame41494a2011-04-16 00:01:13 +00001715 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001716 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001717 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001718 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001719 if (dynamic_sp)
1720 result_valobj_sp = dynamic_sp;
1721 }
1722
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001723 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001724 }
Greg Clayton427f2902010-12-14 02:59:59 +00001725
Sean Callanan6a925532011-01-13 08:53:35 +00001726 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1727
Greg Clayton427f2902010-12-14 02:59:59 +00001728 result_valobj_sp = const_valobj_sp;
1729
Sean Callanan6a925532011-01-13 08:53:35 +00001730 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1731 assert (clang_expr_variable_sp.get());
1732
1733 // Set flags and live data as appropriate
1734
1735 const Value &result_value = live_valobj_sp->GetValue();
1736
1737 switch (result_value.GetValueType())
1738 {
1739 case Value::eValueTypeHostAddress:
1740 case Value::eValueTypeFileAddress:
1741 // we don't do anything with these for now
1742 break;
1743 case Value::eValueTypeScalar:
1744 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1745 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1746 break;
1747 case Value::eValueTypeLoadAddress:
1748 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1749 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1750 break;
1751 }
Greg Clayton427f2902010-12-14 02:59:59 +00001752 }
1753 else
1754 {
1755 // Make sure we aren't just trying to see the value of a persistent
1756 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001757 lldb::ClangExpressionVariableSP persistent_var_sp;
1758 // Only check for persistent variables the expression starts with a '$'
1759 if (expr_cstr[0] == '$')
1760 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1761
Greg Clayton427f2902010-12-14 02:59:59 +00001762 if (persistent_var_sp)
1763 {
1764 result_valobj_sp = persistent_var_sp->GetValueObject ();
1765 execution_results = eExecutionCompleted;
1766 }
1767 else
1768 {
1769 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001770
Greg Clayton427f2902010-12-14 02:59:59 +00001771 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001772 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001773 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001774 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001775 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001776 expr_cstr,
1777 prefix,
Enrico Granata6cca9692012-07-16 23:10:35 +00001778 result_valobj_sp,
1779 single_thread_timeout_usec);
Greg Clayton427f2902010-12-14 02:59:59 +00001780 }
1781 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001782
1783 m_suppress_stop_hooks = old_suppress_value;
1784
Greg Clayton427f2902010-12-14 02:59:59 +00001785 return execution_results;
1786}
1787
Greg Claytonc0fa5332011-05-22 22:46:53 +00001788lldb::addr_t
1789Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1790{
1791 addr_t code_addr = load_addr;
1792 switch (m_arch.GetMachine())
1793 {
1794 case llvm::Triple::arm:
1795 case llvm::Triple::thumb:
1796 switch (addr_class)
1797 {
1798 case eAddressClassData:
1799 case eAddressClassDebug:
1800 return LLDB_INVALID_ADDRESS;
1801
1802 case eAddressClassUnknown:
1803 case eAddressClassInvalid:
1804 case eAddressClassCode:
1805 case eAddressClassCodeAlternateISA:
1806 case eAddressClassRuntime:
1807 // Check if bit zero it no set?
1808 if ((code_addr & 1ull) == 0)
1809 {
1810 // Bit zero isn't set, check if the address is a multiple of 2?
1811 if (code_addr & 2ull)
1812 {
1813 // The address is a multiple of 2 so it must be thumb, set bit zero
1814 code_addr |= 1ull;
1815 }
1816 else if (addr_class == eAddressClassCodeAlternateISA)
1817 {
1818 // We checked the address and the address claims to be the alternate ISA
1819 // which means thumb, so set bit zero.
1820 code_addr |= 1ull;
1821 }
1822 }
1823 break;
1824 }
1825 break;
1826
1827 default:
1828 break;
1829 }
1830 return code_addr;
1831}
1832
1833lldb::addr_t
1834Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1835{
1836 addr_t opcode_addr = load_addr;
1837 switch (m_arch.GetMachine())
1838 {
1839 case llvm::Triple::arm:
1840 case llvm::Triple::thumb:
1841 switch (addr_class)
1842 {
1843 case eAddressClassData:
1844 case eAddressClassDebug:
1845 return LLDB_INVALID_ADDRESS;
1846
1847 case eAddressClassInvalid:
1848 case eAddressClassUnknown:
1849 case eAddressClassCode:
1850 case eAddressClassCodeAlternateISA:
1851 case eAddressClassRuntime:
1852 opcode_addr &= ~(1ull);
1853 break;
1854 }
1855 break;
1856
1857 default:
1858 break;
1859 }
1860 return opcode_addr;
1861}
1862
Jim Inghamd60d94a2011-03-11 03:53:59 +00001863lldb::user_id_t
1864Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1865{
1866 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001867 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001868 m_stop_hooks[new_uid] = new_hook_sp;
1869 return new_uid;
1870}
1871
1872bool
1873Target::RemoveStopHookByID (lldb::user_id_t user_id)
1874{
1875 size_t num_removed;
1876 num_removed = m_stop_hooks.erase (user_id);
1877 if (num_removed == 0)
1878 return false;
1879 else
1880 return true;
1881}
1882
1883void
1884Target::RemoveAllStopHooks ()
1885{
1886 m_stop_hooks.clear();
1887}
1888
1889Target::StopHookSP
1890Target::GetStopHookByID (lldb::user_id_t user_id)
1891{
1892 StopHookSP found_hook;
1893
1894 StopHookCollection::iterator specified_hook_iter;
1895 specified_hook_iter = m_stop_hooks.find (user_id);
1896 if (specified_hook_iter != m_stop_hooks.end())
1897 found_hook = (*specified_hook_iter).second;
1898 return found_hook;
1899}
1900
1901bool
1902Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1903{
1904 StopHookCollection::iterator specified_hook_iter;
1905 specified_hook_iter = m_stop_hooks.find (user_id);
1906 if (specified_hook_iter == m_stop_hooks.end())
1907 return false;
1908
1909 (*specified_hook_iter).second->SetIsActive (active_state);
1910 return true;
1911}
1912
1913void
1914Target::SetAllStopHooksActiveState (bool active_state)
1915{
1916 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1917 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1918 {
1919 (*pos).second->SetIsActive (active_state);
1920 }
1921}
1922
1923void
1924Target::RunStopHooks ()
1925{
Jim Ingham3613ae12011-05-12 02:06:14 +00001926 if (m_suppress_stop_hooks)
1927 return;
1928
Jim Inghamd60d94a2011-03-11 03:53:59 +00001929 if (!m_process_sp)
1930 return;
Enrico Granata5a60f5e2012-08-03 22:24:48 +00001931
1932 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
1933 // since in that case we do not want to run the stop-hooks
1934 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
1935 return;
1936
Jim Inghamd60d94a2011-03-11 03:53:59 +00001937 if (m_stop_hooks.empty())
1938 return;
1939
1940 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1941
1942 // If there aren't any active stop hooks, don't bother either:
1943 bool any_active_hooks = false;
1944 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1945 {
1946 if ((*pos).second->IsActive())
1947 {
1948 any_active_hooks = true;
1949 break;
1950 }
1951 }
1952 if (!any_active_hooks)
1953 return;
1954
1955 CommandReturnObject result;
1956
1957 std::vector<ExecutionContext> exc_ctx_with_reasons;
1958 std::vector<SymbolContext> sym_ctx_with_reasons;
1959
1960 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1961 size_t num_threads = cur_threadlist.GetSize();
1962 for (size_t i = 0; i < num_threads; i++)
1963 {
1964 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1965 if (cur_thread_sp->ThreadStoppedForAReason())
1966 {
1967 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1968 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1969 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1970 }
1971 }
1972
1973 // If no threads stopped for a reason, don't run the stop-hooks.
1974 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1975 if (num_exe_ctx == 0)
1976 return;
1977
Jim Inghame5ed8e92011-06-02 23:58:26 +00001978 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1979 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001980
1981 bool keep_going = true;
1982 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001983 bool print_hook_header;
1984 bool print_thread_header;
1985
1986 if (num_exe_ctx == 1)
1987 print_thread_header = false;
1988 else
1989 print_thread_header = true;
1990
1991 if (m_stop_hooks.size() == 1)
1992 print_hook_header = false;
1993 else
1994 print_hook_header = true;
1995
Jim Inghamd60d94a2011-03-11 03:53:59 +00001996 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1997 {
1998 // result.Clear();
1999 StopHookSP cur_hook_sp = (*pos).second;
2000 if (!cur_hook_sp->IsActive())
2001 continue;
2002
2003 bool any_thread_matched = false;
2004 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2005 {
2006 if ((cur_hook_sp->GetSpecifier () == NULL
2007 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2008 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Inghama2664912012-03-07 22:03:04 +00002009 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002010 {
2011 if (!hooks_ran)
2012 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00002013 hooks_ran = true;
2014 }
Jim Inghamc54840c2011-03-22 01:47:27 +00002015 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002016 {
Johnny Chen4d96a742011-10-24 23:01:06 +00002017 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2018 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2019 NULL);
2020 if (cmd)
2021 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
2022 else
2023 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002024 any_thread_matched = true;
2025 }
2026
Jim Inghamc54840c2011-03-22 01:47:27 +00002027 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00002028 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002029
2030 bool stop_on_continue = true;
2031 bool stop_on_error = true;
2032 bool echo_commands = false;
2033 bool print_results = true;
2034 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00002035 &exc_ctx_with_reasons[i],
2036 stop_on_continue,
2037 stop_on_error,
2038 echo_commands,
Enrico Granata01bc2d42012-05-31 01:09:06 +00002039 print_results,
2040 eLazyBoolNo,
Greg Clayton24bc5d92011-03-30 18:16:51 +00002041 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00002042
2043 // If the command started the target going again, we should bag out of
2044 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00002045 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2046 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002047 {
Greg Clayton444e35b2011-10-19 18:09:39 +00002048 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002049 keep_going = false;
2050 }
2051 }
2052 }
2053 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00002054
Caroline Tice4a348082011-05-02 20:41:46 +00002055 result.GetImmediateOutputStream()->Flush();
2056 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00002057}
2058
Greg Claytonbbea1332011-07-08 00:48:09 +00002059
Jim Inghamd60d94a2011-03-11 03:53:59 +00002060//--------------------------------------------------------------
2061// class Target::StopHook
2062//--------------------------------------------------------------
2063
2064
2065Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2066 UserID (uid),
2067 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00002068 m_commands (),
2069 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002070 m_thread_spec_ap(NULL),
2071 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002072{
2073}
2074
2075Target::StopHook::StopHook (const StopHook &rhs) :
2076 UserID (rhs.GetID()),
2077 m_target_sp (rhs.m_target_sp),
2078 m_commands (rhs.m_commands),
2079 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002080 m_thread_spec_ap (NULL),
2081 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002082{
2083 if (rhs.m_thread_spec_ap.get() != NULL)
2084 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2085}
2086
2087
2088Target::StopHook::~StopHook ()
2089{
2090}
2091
2092void
2093Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2094{
2095 m_thread_spec_ap.reset (specifier);
2096}
2097
2098
2099void
2100Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2101{
2102 int indent_level = s->GetIndentLevel();
2103
2104 s->SetIndentLevel(indent_level + 2);
2105
Greg Clayton444e35b2011-10-19 18:09:39 +00002106 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002107 if (m_active)
2108 s->Indent ("State: enabled\n");
2109 else
2110 s->Indent ("State: disabled\n");
2111
2112 if (m_specifier_sp)
2113 {
2114 s->Indent();
2115 s->PutCString ("Specifier:\n");
2116 s->SetIndentLevel (indent_level + 4);
2117 m_specifier_sp->GetDescription (s, level);
2118 s->SetIndentLevel (indent_level + 2);
2119 }
2120
2121 if (m_thread_spec_ap.get() != NULL)
2122 {
2123 StreamString tmp;
2124 s->Indent("Thread:\n");
2125 m_thread_spec_ap->GetDescription (&tmp, level);
2126 s->SetIndentLevel (indent_level + 4);
2127 s->Indent (tmp.GetData());
2128 s->PutCString ("\n");
2129 s->SetIndentLevel (indent_level + 2);
2130 }
2131
2132 s->Indent ("Commands: \n");
2133 s->SetIndentLevel (indent_level + 4);
2134 uint32_t num_commands = m_commands.GetSize();
2135 for (uint32_t i = 0; i < num_commands; i++)
2136 {
2137 s->Indent(m_commands.GetStringAtIndex(i));
2138 s->PutCString ("\n");
2139 }
2140 s->SetIndentLevel (indent_level);
2141}
2142
2143
Caroline Tice5bc8c972010-09-20 20:44:43 +00002144//--------------------------------------------------------------
2145// class Target::SettingsController
2146//--------------------------------------------------------------
2147
Greg Clayton73844aa2012-08-22 17:17:09 +00002148//Target::SettingsController::SettingsController () :
2149// UserSettingsController ("target", Debugger::GetSettingsController()),
2150// m_default_architecture ()
2151//{
2152//}
2153//
2154//Target::SettingsController::~SettingsController ()
2155//{
2156//}
2157//
2158//lldb::InstanceSettingsSP
2159//Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2160//{
2161// lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2162// false,
2163// instance_name));
2164// return new_settings_sp;
2165//}
2166//
2167//
2168//#define TSC_DEFAULT_ARCH "default-arch"
2169//#define TSC_EXPR_PREFIX "expr-prefix"
2170//#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2171//#define TSC_ENABLE_SYNTHETIC "enable-synthetic-value"
2172//#define TSC_SKIP_PROLOGUE "skip-prologue"
2173//#define TSC_SOURCE_MAP "source-map"
2174//#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
2175//#define TSC_MAX_CHILDREN "max-children-count"
2176//#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2177//#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2178//#define TSC_RUN_ARGS "run-args"
2179//#define TSC_ENV_VARS "env-vars"
2180//#define TSC_INHERIT_ENV "inherit-env"
2181//#define TSC_STDIN_PATH "input-path"
2182//#define TSC_STDOUT_PATH "output-path"
2183//#define TSC_STDERR_PATH "error-path"
2184//#define TSC_DISABLE_ASLR "disable-aslr"
2185//#define TSC_DISABLE_STDIO "disable-stdio"
2186//
2187//
2188//static const ConstString &
2189//GetSettingNameForDefaultArch ()
2190//{
2191// static ConstString g_const_string (TSC_DEFAULT_ARCH);
2192// return g_const_string;
2193//}
2194//
2195//static const ConstString &
2196//GetSettingNameForExpressionPrefix ()
2197//{
2198// static ConstString g_const_string (TSC_EXPR_PREFIX);
2199// return g_const_string;
2200//}
2201//
2202//static const ConstString &
2203//GetSettingNameForPreferDynamicValue ()
2204//{
2205// static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2206// return g_const_string;
2207//}
2208//
2209//static const ConstString &
2210//GetSettingNameForEnableSyntheticValue ()
2211//{
2212// static ConstString g_const_string (TSC_ENABLE_SYNTHETIC);
2213// return g_const_string;
2214//}
2215//
2216//static const ConstString &
2217//GetSettingNameForSourcePathMap ()
2218//{
2219// static ConstString g_const_string (TSC_SOURCE_MAP);
2220// return g_const_string;
2221//}
2222//
2223//static const ConstString &
2224//GetSettingNameForExecutableSearchPaths ()
2225//{
2226// static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2227// return g_const_string;
2228//}
2229//
2230//static const ConstString &
2231//GetSettingNameForSkipPrologue ()
2232//{
2233// static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2234// return g_const_string;
2235//}
2236//
2237//static const ConstString &
2238//GetSettingNameForMaxChildren ()
2239//{
2240// static ConstString g_const_string (TSC_MAX_CHILDREN);
2241// return g_const_string;
2242//}
2243//
2244//static const ConstString &
2245//GetSettingNameForMaxStringSummaryLength ()
2246//{
2247// static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2248// return g_const_string;
2249//}
2250//
2251//static const ConstString &
2252//GetSettingNameForPlatformAvoid ()
2253//{
2254// static ConstString g_const_string (TSC_PLATFORM_AVOID);
2255// return g_const_string;
2256//}
2257//
2258//const ConstString &
2259//GetSettingNameForRunArgs ()
2260//{
2261// static ConstString g_const_string (TSC_RUN_ARGS);
2262// return g_const_string;
2263//}
2264//
2265//const ConstString &
2266//GetSettingNameForEnvVars ()
2267//{
2268// static ConstString g_const_string (TSC_ENV_VARS);
2269// return g_const_string;
2270//}
2271//
2272//const ConstString &
2273//GetSettingNameForInheritHostEnv ()
2274//{
2275// static ConstString g_const_string (TSC_INHERIT_ENV);
2276// return g_const_string;
2277//}
2278//
2279//const ConstString &
2280//GetSettingNameForInputPath ()
2281//{
2282// static ConstString g_const_string (TSC_STDIN_PATH);
2283// return g_const_string;
2284//}
2285//
2286//const ConstString &
2287//GetSettingNameForOutputPath ()
2288//{
2289// static ConstString g_const_string (TSC_STDOUT_PATH);
2290// return g_const_string;
2291//}
2292//
2293//const ConstString &
2294//GetSettingNameForErrorPath ()
2295//{
2296// static ConstString g_const_string (TSC_STDERR_PATH);
2297// return g_const_string;
2298//}
2299//
2300//const ConstString &
2301//GetSettingNameForDisableASLR ()
2302//{
2303// static ConstString g_const_string (TSC_DISABLE_ASLR);
2304// return g_const_string;
2305//}
2306//
2307//const ConstString &
2308//GetSettingNameForDisableSTDIO ()
2309//{
2310// static ConstString g_const_string (TSC_DISABLE_STDIO);
2311// return g_const_string;
2312//}
2313//
2314//bool
2315//Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2316// const char *index_value,
2317// const char *value,
2318// const SettingEntry &entry,
2319// const VarSetOperationType op,
2320// Error&err)
2321//{
2322// if (var_name == GetSettingNameForDefaultArch())
2323// {
2324// m_default_architecture.SetTriple (value);
2325// if (!m_default_architecture.IsValid())
2326// err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
2327// }
2328// return true;
2329//}
2330//
2331//
2332//bool
2333//Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2334// StringList &value,
2335// Error &err)
2336//{
2337// if (var_name == GetSettingNameForDefaultArch())
2338// {
2339// // If the arch is invalid (the default), don't show a string for it
2340// if (m_default_architecture.IsValid())
2341// value.AppendString (m_default_architecture.GetArchitectureName());
2342// return true;
2343// }
2344// else
2345// err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2346//
2347// return false;
2348//}
2349
2350
2351//--------------------------------------------------------------
2352// class TargetProperties
2353//--------------------------------------------------------------
2354
2355OptionEnumValueElement
2356lldb_private::g_dynamic_value_types[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002357{
Greg Clayton73844aa2012-08-22 17:17:09 +00002358 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2359 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2360 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2361 { 0, NULL, NULL }
2362};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002363
Greg Clayton73844aa2012-08-22 17:17:09 +00002364static PropertyDefinition
2365g_properties[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002366{
Greg Clayton73844aa2012-08-22 17:17:09 +00002367 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2368 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2369 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2370 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2371 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2372 { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and "
2373 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2374 "some part (starting at the root) of the path to the file when it was built, "
2375 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2376 "Each element of the array is checked in order and the first one that results in a match wins." },
2377 { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
2378 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2379 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
2380 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
2381 { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run." },
2382 { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2383 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2384 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2385 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2386 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2387 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2388 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" },
2389 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2390};
2391enum
Caroline Tice5bc8c972010-09-20 20:44:43 +00002392{
Greg Clayton73844aa2012-08-22 17:17:09 +00002393 ePropertyDefaultArch,
2394 ePropertyExprPrefix,
2395 ePropertyPreferDynamic,
2396 ePropertyEnableSynthetic,
2397 ePropertySkipPrologue,
2398 ePropertySourceMap,
2399 ePropertyExecutableSearchPaths,
2400 ePropertyMaxChildrenCount,
2401 ePropertyMaxSummaryLength,
2402 ePropertyBreakpointUseAvoidList,
2403 ePropertyRunArgs,
2404 ePropertyEnvVars,
2405 ePropertyInheritEnv,
2406 ePropertyInputPath,
2407 ePropertyOutputPath,
2408 ePropertyErrorPath,
2409 ePropertyDisableASLR,
2410 ePropertyDisableSTDIO
2411};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002412
Caroline Tice5bc8c972010-09-20 20:44:43 +00002413
Greg Clayton73844aa2012-08-22 17:17:09 +00002414class TargetOptionValueProperties : public OptionValueProperties
Greg Claytond284b662011-02-18 01:44:25 +00002415{
Greg Clayton73844aa2012-08-22 17:17:09 +00002416public:
2417 TargetOptionValueProperties (const ConstString &name) :
2418 OptionValueProperties (name),
2419 m_target (NULL),
2420 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002421 {
Caroline Tice5bc8c972010-09-20 20:44:43 +00002422 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002423
Greg Clayton73844aa2012-08-22 17:17:09 +00002424 // This constructor is used when creating TargetOptionValueProperties when it
2425 // is part of a new lldb_private::Target instance. It will copy all current
2426 // global property values as needed
2427 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2428 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2429 m_target (target),
2430 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002431 {
Greg Clayton73844aa2012-08-22 17:17:09 +00002432 }
2433
2434 virtual const Property *
2435 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2436 {
2437 // When gettings the value for a key from the target options, we will always
2438 // try and grab the setting from the current target if there is one. Else we just
2439 // use the one from this instance.
2440 if (idx == ePropertyEnvVars)
2441 GetHostEnvironmentIfNeeded ();
2442
2443 if (exe_ctx)
2444 {
2445 Target *target = exe_ctx->GetTargetPtr();
2446 if (target)
2447 {
2448 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2449 if (this != target_properties)
2450 return target_properties->ProtectedGetPropertyAtIndex (idx);
2451 }
2452 }
2453 return ProtectedGetPropertyAtIndex (idx);
2454 }
2455protected:
2456
2457 void
2458 GetHostEnvironmentIfNeeded () const
2459 {
2460 if (!m_got_host_env)
2461 {
2462 if (m_target)
2463 {
2464 m_got_host_env = true;
2465 const uint32_t idx = ePropertyInheritEnv;
2466 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2467 {
2468 PlatformSP platform_sp (m_target->GetPlatform());
2469 if (platform_sp)
2470 {
2471 StringList env;
2472 if (platform_sp->GetEnvironment(env))
2473 {
2474 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2475 if (env_dict)
2476 {
2477 const bool can_replace = false;
2478 const size_t envc = env.GetSize();
2479 for (size_t idx=0; idx<envc; idx++)
2480 {
2481 const char *env_entry = env.GetStringAtIndex (idx);
2482 if (env_entry)
2483 {
2484 const char *equal_pos = ::strchr(env_entry, '=');
2485 ConstString key;
2486 // It is ok to have environment variables with no values
2487 const char *value = NULL;
2488 if (equal_pos)
2489 {
2490 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2491 if (equal_pos[1])
2492 value = equal_pos + 1;
2493 }
2494 else
2495 {
2496 key.SetCString(env_entry);
2497 }
2498 // Don't allow existing keys to be replaced with ones we get from the platform environment
2499 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2500 }
2501 }
2502 }
2503 }
2504 }
2505 }
2506 }
2507 }
2508 }
2509 Target *m_target;
2510 mutable bool m_got_host_env;
2511};
2512
2513TargetProperties::TargetProperties (Target *target) :
2514 Properties ()
2515{
2516 if (target)
2517 {
2518 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002519 }
2520 else
Greg Clayton73844aa2012-08-22 17:17:09 +00002521 {
2522 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2523 m_collection_sp->Initialize(g_properties);
2524 m_collection_sp->AppendProperty(ConstString("process"),
2525 ConstString("Settings specify to processes."),
2526 true,
2527 Process::GetGlobalProperties()->GetValueProperties());
2528 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002529}
2530
Greg Clayton73844aa2012-08-22 17:17:09 +00002531TargetProperties::~TargetProperties ()
2532{
2533}
2534ArchSpec
2535TargetProperties::GetDefaultArchitecture () const
2536{
2537 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2538 if (value)
2539 return value->GetCurrentValue();
2540 return ArchSpec();
2541}
2542
2543void
2544TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2545{
2546 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2547 if (value)
2548 return value->SetCurrentValue(arch, true);
2549}
2550
2551lldb::DynamicValueType
2552TargetProperties::GetPreferDynamicValue() const
2553{
2554 const uint32_t idx = ePropertyPreferDynamic;
2555 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2556}
2557
2558bool
2559TargetProperties::GetDisableASLR () const
2560{
2561 const uint32_t idx = ePropertyDisableASLR;
2562 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2563}
2564
2565void
2566TargetProperties::SetDisableASLR (bool b)
2567{
2568 const uint32_t idx = ePropertyDisableASLR;
2569 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2570}
2571
2572bool
2573TargetProperties::GetDisableSTDIO () const
2574{
2575 const uint32_t idx = ePropertyDisableSTDIO;
2576 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2577}
2578
2579void
2580TargetProperties::SetDisableSTDIO (bool b)
2581{
2582 const uint32_t idx = ePropertyDisableSTDIO;
2583 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2584}
2585
2586bool
2587TargetProperties::GetRunArguments (Args &args) const
2588{
2589 const uint32_t idx = ePropertyRunArgs;
2590 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
2591}
2592
2593void
2594TargetProperties::SetRunArguments (const Args &args)
2595{
2596 const uint32_t idx = ePropertyRunArgs;
2597 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
2598}
2599
2600size_t
2601TargetProperties::GetEnvironmentAsArgs (Args &env) const
2602{
2603 const uint32_t idx = ePropertyEnvVars;
2604 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
2605}
2606
2607bool
2608TargetProperties::GetSkipPrologue() const
2609{
2610 const uint32_t idx = ePropertySkipPrologue;
2611 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2612}
2613
2614PathMappingList &
2615TargetProperties::GetSourcePathMap () const
2616{
2617 const uint32_t idx = ePropertySourceMap;
2618 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
2619 assert(option_value);
2620 return option_value->GetCurrentValue();
2621}
2622
2623FileSpecList &
2624TargetProperties::GetExecutableSearchPaths () const
2625{
2626 const uint32_t idx = ePropertyExecutableSearchPaths;
2627 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2628 assert(option_value);
2629 return option_value->GetCurrentValue();
2630}
2631
2632bool
2633TargetProperties::GetEnableSyntheticValue () const
2634{
2635 const uint32_t idx = ePropertyEnableSynthetic;
2636 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2637}
2638
2639uint32_t
2640TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
2641{
2642 const uint32_t idx = ePropertyMaxChildrenCount;
2643 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2644}
2645
2646uint32_t
2647TargetProperties::GetMaximumSizeOfStringSummary() const
2648{
2649 const uint32_t idx = ePropertyMaxSummaryLength;
2650 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2651}
2652
2653FileSpec
2654TargetProperties::GetStandardInputPath () const
2655{
2656 const uint32_t idx = ePropertyInputPath;
2657 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2658}
2659
2660void
2661TargetProperties::SetStandardInputPath (const char *p)
2662{
2663 const uint32_t idx = ePropertyInputPath;
2664 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2665}
2666
2667FileSpec
2668TargetProperties::GetStandardOutputPath () const
2669{
2670 const uint32_t idx = ePropertyOutputPath;
2671 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2672}
2673
2674void
2675TargetProperties::SetStandardOutputPath (const char *p)
2676{
2677 const uint32_t idx = ePropertyOutputPath;
2678 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2679}
2680
2681FileSpec
2682TargetProperties::GetStandardErrorPath () const
2683{
2684 const uint32_t idx = ePropertyErrorPath;
2685 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
2686}
2687
2688void
2689TargetProperties::SetStandardErrorPath (const char *p)
2690{
2691 const uint32_t idx = ePropertyErrorPath;
2692 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2693}
2694
2695bool
2696TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
2697{
2698 const uint32_t idx = ePropertyBreakpointUseAvoidList;
2699 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2700}
2701
2702const TargetPropertiesSP &
2703Target::GetGlobalProperties()
2704{
2705 static TargetPropertiesSP g_settings_sp;
2706 if (!g_settings_sp)
2707 {
2708 g_settings_sp.reset (new TargetProperties (NULL));
2709 }
2710 return g_settings_sp;
2711}
2712
2713// TODO: SETTINGS
2714//bool
2715//TargetProperties::GetRunArguments (Args &args) const
2716//{
2717// if (m_run_args)
2718// {
2719// m_run_args->GetArgs(args);
2720// return true;
2721// }
2722// else if (m_parent_sp)
2723// {
2724// return m_parent_sp->GetRunArguments(args);
2725// }
2726// return false;
2727//}
2728//
2729//void
2730//TargetProperties::SetRunArguments (const Args &args)
2731//{
2732// // TODO: SETTINGS
2733//}
2734
2735
Caroline Tice5bc8c972010-09-20 20:44:43 +00002736//--------------------------------------------------------------
2737// class TargetInstanceSettings
2738//--------------------------------------------------------------
2739
Greg Clayton73844aa2012-08-22 17:17:09 +00002740//TargetInstanceSettings::TargetInstanceSettings
2741//(
2742// const lldb::UserSettingsControllerSP &owner_sp,
2743// bool live_instance,
2744// const char *name
2745//) :
2746// InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
2747// m_expr_prefix_file (),
2748// m_expr_prefix_contents (),
2749// m_prefer_dynamic_value (2),
2750// m_enable_synthetic_value(true, true),
2751// m_skip_prologue (true, true),
2752// m_source_map (NULL, NULL),
2753// m_exe_search_paths (),
2754// m_max_children_display(256),
2755// m_max_strlen_length(1024),
2756// m_breakpoints_use_platform_avoid (true, true),
2757// m_run_args (),
2758// m_env_vars (),
2759// m_input_path (),
2760// m_output_path (),
2761// m_error_path (),
2762// m_disable_aslr (true),
2763// m_disable_stdio (false),
2764// m_inherit_host_env (true),
2765// m_got_host_env (false)
2766//{
2767// // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2768// // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2769// // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2770// // This is true for CreateInstanceName() too.
2771//
2772// if (GetInstanceName () == InstanceSettings::InvalidName())
2773// {
2774// ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2775// owner_sp->RegisterInstanceSettings (this);
2776// }
2777//
2778// if (live_instance)
2779// {
2780// const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
2781// CopyInstanceSettings (pending_settings,false);
2782// }
2783//}
2784//
2785//TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
2786// InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
2787// m_expr_prefix_file (rhs.m_expr_prefix_file),
2788// m_expr_prefix_contents (rhs.m_expr_prefix_contents),
2789// m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2790// m_enable_synthetic_value(rhs.m_enable_synthetic_value),
2791// m_skip_prologue (rhs.m_skip_prologue),
2792// m_source_map (rhs.m_source_map),
2793// m_exe_search_paths (rhs.m_exe_search_paths),
2794// m_max_children_display (rhs.m_max_children_display),
2795// m_max_strlen_length (rhs.m_max_strlen_length),
2796// m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2797// m_run_args (rhs.m_run_args),
2798// m_env_vars (rhs.m_env_vars),
2799// m_input_path (rhs.m_input_path),
2800// m_output_path (rhs.m_output_path),
2801// m_error_path (rhs.m_error_path),
2802// m_disable_aslr (rhs.m_disable_aslr),
2803// m_disable_stdio (rhs.m_disable_stdio),
2804// m_inherit_host_env (rhs.m_inherit_host_env)
2805//{
2806// if (m_instance_name != InstanceSettings::GetDefaultName())
2807// {
2808// UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2809// if (owner_sp)
2810// CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
2811// }
2812//}
2813//
2814//TargetInstanceSettings::~TargetInstanceSettings ()
2815//{
2816//}
2817//
2818//TargetInstanceSettings&
2819//TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2820//{
2821// if (this != &rhs)
2822// {
2823// m_expr_prefix_file = rhs.m_expr_prefix_file;
2824// m_expr_prefix_contents = rhs.m_expr_prefix_contents;
2825// m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2826// m_enable_synthetic_value = rhs.m_enable_synthetic_value;
2827// m_skip_prologue = rhs.m_skip_prologue;
2828// m_source_map = rhs.m_source_map;
2829// m_exe_search_paths = rhs.m_exe_search_paths;
2830// m_max_children_display = rhs.m_max_children_display;
2831// m_max_strlen_length = rhs.m_max_strlen_length;
2832// m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2833// m_run_args = rhs.m_run_args;
2834// m_env_vars = rhs.m_env_vars;
2835// m_input_path = rhs.m_input_path;
2836// m_output_path = rhs.m_output_path;
2837// m_error_path = rhs.m_error_path;
2838// m_disable_aslr = rhs.m_disable_aslr;
2839// m_disable_stdio = rhs.m_disable_stdio;
2840// m_inherit_host_env = rhs.m_inherit_host_env;
2841// }
2842//
2843// return *this;
2844//}
2845//
2846//void
2847//TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2848// const char *index_value,
2849// const char *value,
2850// const ConstString &instance_name,
2851// const SettingEntry &entry,
2852// VarSetOperationType op,
2853// Error &err,
2854// bool pending)
2855//{
2856// if (var_name == GetSettingNameForExpressionPrefix ())
2857// {
2858// err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2859// if (err.Success())
2860// {
2861// switch (op)
2862// {
2863// default:
2864// break;
2865// case eVarSetOperationAssign:
2866// case eVarSetOperationAppend:
2867// {
2868// m_expr_prefix_contents.clear();
2869//
2870// if (!m_expr_prefix_file.GetCurrentValue().Exists())
2871// {
2872// err.SetErrorToGenericError ();
2873// err.SetErrorStringWithFormat ("%s does not exist", value);
2874// return;
2875// }
2876//
2877// DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
2878//
2879// if (err.Success())
2880// {
2881// if (file_data_sp && file_data_sp->GetByteSize() > 0)
2882// {
2883// m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2884// }
2885// else
2886// {
2887// err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2888// }
2889// }
2890// }
2891// break;
2892// case eVarSetOperationClear:
2893// m_expr_prefix_contents.clear();
2894// }
2895// }
2896// }
2897// else if (var_name == GetSettingNameForPreferDynamicValue())
2898// {
2899// int new_value;
2900// UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2901// if (err.Success())
2902// m_prefer_dynamic_value = new_value;
2903// }
2904// else if (var_name == GetSettingNameForEnableSyntheticValue())
2905// {
2906// bool ok;
2907// bool new_value = Args::StringToBoolean(value, true, &ok);
2908// if (ok)
2909// m_enable_synthetic_value.SetCurrentValue(new_value);
2910// }
2911// else if (var_name == GetSettingNameForSkipPrologue())
2912// {
2913// err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2914// }
2915// else if (var_name == GetSettingNameForMaxChildren())
2916// {
2917// bool ok;
2918// uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2919// if (ok)
2920// m_max_children_display = new_value;
2921// }
2922// else if (var_name == GetSettingNameForMaxStringSummaryLength())
2923// {
2924// bool ok;
2925// uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2926// if (ok)
2927// m_max_strlen_length = new_value;
2928// }
2929// else if (var_name == GetSettingNameForExecutableSearchPaths())
2930// {
2931// switch (op)
2932// {
2933// case eVarSetOperationReplace:
2934// case eVarSetOperationInsertBefore:
2935// case eVarSetOperationInsertAfter:
2936// case eVarSetOperationRemove:
2937// default:
2938// break;
2939// case eVarSetOperationAssign:
2940// m_exe_search_paths.Clear();
2941// // Fall through to append....
2942// case eVarSetOperationAppend:
2943// {
2944// Args args(value);
2945// const uint32_t argc = args.GetArgumentCount();
2946// if (argc > 0)
2947// {
2948// const char *exe_search_path_dir;
2949// for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2950// {
2951// FileSpec file_spec;
2952// file_spec.GetDirectory().SetCString(exe_search_path_dir);
2953// FileSpec::FileType file_type = file_spec.GetFileType();
2954// if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2955// {
2956// m_exe_search_paths.Append(file_spec);
2957// }
2958// else
2959// {
2960// err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2961// }
2962// }
2963// }
2964// }
2965// break;
2966//
2967// case eVarSetOperationClear:
2968// m_exe_search_paths.Clear();
2969// break;
2970// }
2971// }
2972// else if (var_name == GetSettingNameForSourcePathMap ())
2973// {
2974// switch (op)
2975// {
2976// case eVarSetOperationReplace:
2977// case eVarSetOperationInsertBefore:
2978// case eVarSetOperationInsertAfter:
2979// case eVarSetOperationRemove:
2980// default:
2981// break;
2982// case eVarSetOperationAssign:
2983// m_source_map.Clear(true);
2984// // Fall through to append....
2985// case eVarSetOperationAppend:
2986// {
2987// Args args(value);
2988// const uint32_t argc = args.GetArgumentCount();
2989// if (argc & 1 || argc == 0)
2990// {
2991// err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2992// }
2993// else
2994// {
2995// char resolved_new_path[PATH_MAX];
2996// FileSpec file_spec;
2997// const char *old_path;
2998// for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2999// {
3000// const char *new_path = args.GetArgumentAtIndex(idx+1);
3001// assert (new_path); // We have an even number of paths, this shouldn't happen!
3002//
3003// file_spec.SetFile(new_path, true);
3004// if (file_spec.Exists())
3005// {
3006// if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
3007// {
3008// err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
3009// return;
3010// }
3011// }
3012// else
3013// {
3014// err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
3015// return;
3016// }
3017// m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
3018// }
3019// }
3020// }
3021// break;
3022//
3023// case eVarSetOperationClear:
3024// m_source_map.Clear(true);
3025// break;
3026// }
3027// }
3028// else if (var_name == GetSettingNameForPlatformAvoid ())
3029// {
3030// err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
3031// }
3032// else if (var_name == GetSettingNameForRunArgs())
3033// {
3034// UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
3035// }
3036// else if (var_name == GetSettingNameForEnvVars())
3037// {
3038// // This is nice for local debugging, but it is isn't correct for
3039// // remote debugging. We need to stop process.env-vars from being
3040// // populated with the host environment and add this as a launch option
3041// // and get the correct environment from the Target's platform.
3042// // GetHostEnvironmentIfNeeded ();
3043// UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
3044// }
3045// else if (var_name == GetSettingNameForInputPath())
3046// {
3047// UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
3048// }
3049// else if (var_name == GetSettingNameForOutputPath())
3050// {
3051// UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
3052// }
3053// else if (var_name == GetSettingNameForErrorPath())
3054// {
3055// UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
3056// }
3057// else if (var_name == GetSettingNameForDisableASLR())
3058// {
3059// UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
3060// }
3061// else if (var_name == GetSettingNameForDisableSTDIO ())
3062// {
3063// UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
3064// }
3065//}
3066//
3067//void
3068//TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
3069//{
3070// TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
3071//
3072// if (!new_settings_ptr)
3073// return;
3074//
3075// *this = *new_settings_ptr;
3076//}
3077//
3078//bool
3079//TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
3080// const ConstString &var_name,
3081// StringList &value,
3082// Error *err)
3083//{
3084// if (var_name == GetSettingNameForExpressionPrefix ())
3085// {
3086// char path[PATH_MAX];
3087// const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
3088// if (path_len > 0)
3089// value.AppendString (path, path_len);
3090// }
3091// else if (var_name == GetSettingNameForPreferDynamicValue())
3092// {
3093// value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
3094// }
3095// else if (var_name == GetSettingNameForEnableSyntheticValue())
3096// {
3097// if (m_skip_prologue)
3098// value.AppendString ("true");
3099// else
3100// value.AppendString ("false");
3101// }
3102// else if (var_name == GetSettingNameForSkipPrologue())
3103// {
3104// if (m_skip_prologue)
3105// value.AppendString ("true");
3106// else
3107// value.AppendString ("false");
3108// }
3109// else if (var_name == GetSettingNameForExecutableSearchPaths())
3110// {
3111// if (m_exe_search_paths.GetSize())
3112// {
3113// for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
3114// {
3115// value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
3116// }
3117// }
3118// }
3119// else if (var_name == GetSettingNameForSourcePathMap ())
3120// {
3121// if (m_source_map.GetSize())
3122// {
3123// size_t i;
3124// for (i = 0; i < m_source_map.GetSize(); ++i) {
3125// StreamString sstr;
3126// m_source_map.Dump(&sstr, i);
3127// value.AppendString(sstr.GetData());
3128// }
3129// }
3130// }
3131// else if (var_name == GetSettingNameForMaxChildren())
3132// {
3133// StreamString count_str;
3134// count_str.Printf ("%d", m_max_children_display);
3135// value.AppendString (count_str.GetData());
3136// }
3137// else if (var_name == GetSettingNameForMaxStringSummaryLength())
3138// {
3139// StreamString count_str;
3140// count_str.Printf ("%d", m_max_strlen_length);
3141// value.AppendString (count_str.GetData());
3142// }
3143// else if (var_name == GetSettingNameForPlatformAvoid())
3144// {
3145// if (m_breakpoints_use_platform_avoid)
3146// value.AppendString ("true");
3147// else
3148// value.AppendString ("false");
3149// }
3150// else if (var_name == GetSettingNameForRunArgs())
3151// {
3152// if (m_run_args.GetArgumentCount() > 0)
3153// {
3154// for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
3155// value.AppendString (m_run_args.GetArgumentAtIndex (i));
3156// }
3157// }
3158// else if (var_name == GetSettingNameForEnvVars())
3159// {
3160// GetHostEnvironmentIfNeeded ();
3161//
3162// if (m_env_vars.size() > 0)
3163// {
3164// std::map<std::string, std::string>::iterator pos;
3165// for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
3166// {
3167// StreamString value_str;
3168// value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
3169// value.AppendString (value_str.GetData());
3170// }
3171// }
3172// }
3173// else if (var_name == GetSettingNameForInputPath())
3174// {
3175// value.AppendString (m_input_path.c_str());
3176// }
3177// else if (var_name == GetSettingNameForOutputPath())
3178// {
3179// value.AppendString (m_output_path.c_str());
3180// }
3181// else if (var_name == GetSettingNameForErrorPath())
3182// {
3183// value.AppendString (m_error_path.c_str());
3184// }
3185// else if (var_name == GetSettingNameForInheritHostEnv())
3186// {
3187// if (m_inherit_host_env)
3188// value.AppendString ("true");
3189// else
3190// value.AppendString ("false");
3191// }
3192// else if (var_name == GetSettingNameForDisableASLR())
3193// {
3194// if (m_disable_aslr)
3195// value.AppendString ("true");
3196// else
3197// value.AppendString ("false");
3198// }
3199// else if (var_name == GetSettingNameForDisableSTDIO())
3200// {
3201// if (m_disable_stdio)
3202// value.AppendString ("true");
3203// else
3204// value.AppendString ("false");
3205// }
3206// else
3207// {
3208// if (err)
3209// err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
3210// return false;
3211// }
3212// return true;
3213//}
3214//
3215//void
3216//Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
3217//{
3218// if (m_inherit_host_env && !m_got_host_env)
3219// {
3220// m_got_host_env = true;
3221// StringList host_env;
3222// const size_t host_env_count = Host::GetEnvironment (host_env);
3223// for (size_t idx=0; idx<host_env_count; idx++)
3224// {
3225// const char *env_entry = host_env.GetStringAtIndex (idx);
3226// if (env_entry)
3227// {
3228// const char *equal_pos = ::strchr(env_entry, '=');
3229// if (equal_pos)
3230// {
3231// std::string key (env_entry, equal_pos - env_entry);
3232// std::string value (equal_pos + 1);
3233// if (m_env_vars.find (key) == m_env_vars.end())
3234// m_env_vars[key] = value;
3235// }
3236// }
3237// }
3238// }
3239//}
3240//
3241//
3242//size_t
3243//Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
3244//{
3245// GetHostEnvironmentIfNeeded ();
3246//
3247// dictionary::const_iterator pos, end = m_env_vars.end();
3248// for (pos = m_env_vars.begin(); pos != end; ++pos)
3249// {
3250// std::string env_var_equal_value (pos->first);
3251// env_var_equal_value.append(1, '=');
3252// env_var_equal_value.append (pos->second);
3253// env.AppendArgument (env_var_equal_value.c_str());
3254// }
3255// return env.GetArgumentCount();
3256//}
3257//
3258//
3259//const ConstString
3260//TargetInstanceSettings::CreateInstanceName ()
3261//{
3262// StreamString sstr;
3263// static int instance_count = 1;
3264//
3265// sstr.Printf ("target_%d", instance_count);
3266// ++instance_count;
3267//
3268// const ConstString ret_val (sstr.GetData());
3269// return ret_val;
3270//}
3271//
3272////--------------------------------------------------
3273//// Target::SettingsController Variable Tables
3274////--------------------------------------------------
3275//
3276//
3277//SettingEntry
3278//Target::SettingsController::global_settings_table[] =
3279//{
3280// // var-name var-type default enum init'd hidden help-text
3281// // ================= ================== =========== ==== ====== ====== =========================================================================
3282// { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
3283// { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
3284//};
3285//
3286//SettingEntry
3287//Target::SettingsController::instance_settings_table[] =
3288//{
3289// // var-name var-type default enum init'd hidden help-text
3290// // ================= ================== =============== ======================= ====== ====== =========================================================================
3291// { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
3292// { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
3293// { TSC_ENABLE_SYNTHETIC , eSetVarTypeBoolean, "true" , NULL, false, false, "Should synthetic values be used by default whenever available." },
3294// { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
3295// { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings used to track the change of location between a source file when built, and "
3296// "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
3297// "some part (starting at the root) of the path to the file when it was built, "
3298// "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
3299// "Each element of the array is checked in order and the first one that results in a match wins." },
3300// { 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." },
3301// { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
3302// { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
3303// { TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
3304// { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
3305// { 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." },
3306// { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
3307// { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
3308// { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
3309// { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
3310//// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
3311// { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
3312// { TSC_DISABLE_STDIO , eSetVarTypeBoolean, "false" , NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
3313// { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
3314//};
3315//
Jim Ingham5a15e692012-02-16 06:50:00 +00003316const ConstString &
3317Target::TargetEventData::GetFlavorString ()
3318{
3319 static ConstString g_flavor ("Target::TargetEventData");
3320 return g_flavor;
3321}
3322
3323const ConstString &
3324Target::TargetEventData::GetFlavor () const
3325{
3326 return TargetEventData::GetFlavorString ();
3327}
3328
3329Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
3330 EventData(),
3331 m_target_sp (new_target_sp)
3332{
3333}
3334
3335Target::TargetEventData::~TargetEventData()
3336{
3337
3338}
3339
3340void
3341Target::TargetEventData::Dump (Stream *s) const
3342{
3343
3344}
3345
3346const TargetSP
3347Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
3348{
3349 TargetSP target_sp;
3350
3351 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
3352 if (data)
3353 target_sp = data->m_target_sp;
3354
3355 return target_sp;
3356}
3357
3358const Target::TargetEventData *
3359Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
3360{
3361 if (event_ptr)
3362 {
3363 const EventData *event_data = event_ptr->GetData();
3364 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
3365 return static_cast <const TargetEventData *> (event_ptr->GetData());
3366 }
3367 return NULL;
3368}
3369