blob: 53e8ccfdac6928382a8a05b79ec8a8aef7137e47 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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 Ingham969795f2011-09-21 01:17:1319#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:2420#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chen01a67862011-10-14 00:42:2521#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5922#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2423#include "lldb/Core/Event.h"
24#include "lldb/Core/Log.h"
Caroline Tice969ed3d12011-05-02 20:41:4625#include "lldb/Core/StreamAsynchronousIO.h"
Chris Lattner30fdc8d2010-06-08 16:52:2426#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5927#include "lldb/Core/Timer.h"
28#include "lldb/Core/ValueObject.h"
Sean Callanan4bf80d52011-11-15 22:27:1929#include "lldb/Expression/ClangASTSource.h"
Greg Claytoneb0103f2011-04-07 22:46:3530#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:2431#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:5932#include "lldb/Interpreter/CommandInterpreter.h"
33#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2434#include "lldb/lldb-private-log.h"
35#include "lldb/Symbol/ObjectFile.h"
36#include "lldb/Target/Process.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5937#include "lldb/Target/StackFrame.h"
Jim Ingham9575d842011-03-11 03:53:5938#include "lldb/Target/Thread.h"
39#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:2440
41using namespace lldb;
42using namespace lldb_private;
43
44//----------------------------------------------------------------------
45// Target constructor
46//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:5147Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
48 Broadcaster ("lldb.target"),
49 ExecutionContextScope (),
Greg Claytondbe54502010-11-19 03:46:0150 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2951 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:5152 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:2353 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:5154 m_arch (target_arch),
55 m_images (),
Greg Claytonf5e56de2010-09-14 23:36:4056 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2457 m_breakpoint_list (false),
58 m_internal_breakpoint_list (true),
Johnny Chen01a67862011-10-14 00:42:2559 m_watchpoint_list (),
Greg Clayton32e0a752011-03-30 18:16:5160 m_process_sp (),
61 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:2462 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton8b2fe6d2010-12-14 02:59:5963 m_scratch_ast_context_ap (NULL),
Sean Callanan686b2312011-11-16 18:20:4764 m_scratch_ast_source_ap (NULL),
65 m_ast_importer_ap (NULL),
Jim Ingham9575d842011-03-11 03:53:5966 m_persistent_variables (),
Jim Inghame37d6052011-09-13 00:29:5667 m_source_manager(*this),
Greg Clayton32e0a752011-03-30 18:16:5168 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:1469 m_stop_hook_next_id (0),
70 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:2471{
Greg Claytoncfd1ace2010-10-31 03:01:0672 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
73 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
74 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
75
Greg Clayton2d4edfb2010-11-06 01:53:3076 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2477 if (log)
78 log->Printf ("%p Target::Target()", this);
79}
80
81//----------------------------------------------------------------------
82// Destructor
83//----------------------------------------------------------------------
84Target::~Target()
85{
Greg Clayton2d4edfb2010-11-06 01:53:3086 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2487 if (log)
88 log->Printf ("%p Target::~Target()", this);
89 DeleteCurrentProcess ();
90}
91
92void
Caroline Ticeceb6b132010-10-26 03:11:1393Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2494{
Greg Clayton89411422010-10-08 00:21:0595// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1396 if (description_level != lldb::eDescriptionLevelBrief)
97 {
98 s->Indent();
99 s->PutCString("Target\n");
100 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:35101 m_images.Dump(s);
102 m_breakpoint_list.Dump(s);
103 m_internal_breakpoint_list.Dump(s);
104 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13105 }
106 else
107 {
Greg Claytonaa149cb2011-08-11 02:48:45108 Module *exe_module = GetExecutableModulePointer();
109 if (exe_module)
110 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28111 else
112 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13113 }
Chris Lattner30fdc8d2010-06-08 16:52:24114}
115
116void
117Target::DeleteCurrentProcess ()
118{
119 if (m_process_sp.get())
120 {
Greg Clayton17f69202010-09-14 23:52:43121 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24122 if (m_process_sp->IsAlive())
123 m_process_sp->Destroy();
Jim Inghamd0a3e12b2011-02-16 17:54:55124
125 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24126
127 // Do any cleanup of the target we need to do between process instances.
128 // NB It is better to do this before destroying the process in case the
129 // clean up needs some help from the process.
130 m_breakpoint_list.ClearAllBreakpointSites();
131 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chen01a67862011-10-14 00:42:25132 // Disable watchpoints just on the debugger side.
133 DisableAllWatchpoints(false);
Chris Lattner30fdc8d2010-06-08 16:52:24134 m_process_sp.reset();
135 }
136}
137
138const lldb::ProcessSP &
139Target::CreateProcess (Listener &listener, const char *plugin_name)
140{
141 DeleteCurrentProcess ();
142 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
143 return m_process_sp;
144}
145
146const lldb::ProcessSP &
147Target::GetProcessSP () const
148{
149 return m_process_sp;
150}
151
152lldb::TargetSP
153Target::GetSP()
154{
Greg Clayton4d122c42011-09-17 08:33:22155 // This object contains an instrusive ref count base class so we can
156 // easily make a shared pointer to this object
157 return TargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24158}
159
Greg Clayton3418c852011-08-10 02:10:13160void
161Target::Destroy()
162{
163 Mutex::Locker locker (m_mutex);
164 DeleteCurrentProcess ();
165 m_platform_sp.reset();
166 m_arch.Clear();
167 m_images.Clear();
168 m_section_load_list.Clear();
169 const bool notify = false;
170 m_breakpoint_list.RemoveAll(notify);
171 m_internal_breakpoint_list.RemoveAll(notify);
172 m_last_created_breakpoint.reset();
Johnny Chen01a67862011-10-14 00:42:25173 m_last_created_watchpoint.reset();
Greg Clayton3418c852011-08-10 02:10:13174 m_search_filter_sp.reset();
175 m_image_search_paths.Clear(notify);
176 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19177 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47178 m_ast_importer_ap.reset();
Greg Clayton3418c852011-08-10 02:10:13179 m_persistent_variables.Clear();
180 m_stop_hooks.clear();
181 m_stop_hook_next_id = 0;
182 m_suppress_stop_hooks = false;
183}
184
185
Chris Lattner30fdc8d2010-06-08 16:52:24186BreakpointList &
187Target::GetBreakpointList(bool internal)
188{
189 if (internal)
190 return m_internal_breakpoint_list;
191 else
192 return m_breakpoint_list;
193}
194
195const BreakpointList &
196Target::GetBreakpointList(bool internal) const
197{
198 if (internal)
199 return m_internal_breakpoint_list;
200 else
201 return m_breakpoint_list;
202}
203
204BreakpointSP
205Target::GetBreakpointByID (break_id_t break_id)
206{
207 BreakpointSP bp_sp;
208
209 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
210 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
211 else
212 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
213
214 return bp_sp;
215}
216
217BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11218Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
219 const FileSpecList *source_file_spec_list,
Jim Ingham969795f2011-09-21 01:17:13220 RegularExpression &source_regex,
221 bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24222{
Jim Ingham87df91b2011-09-23 00:54:11223 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
224 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham969795f2011-09-21 01:17:13225 return CreateBreakpoint (filter_sp, resolver_sp, internal);
226}
227
228
229BreakpointSP
230Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
231{
232 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Chris Lattner30fdc8d2010-06-08 16:52:24233 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
234 return CreateBreakpoint (filter_sp, resolver_sp, internal);
235}
236
237
238BreakpointSP
Greg Clayton1b72fcb2010-08-24 00:45:41239Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24240{
Chris Lattner30fdc8d2010-06-08 16:52:24241 Address so_addr;
242 // Attempt to resolve our load address if possible, though it is ok if
243 // it doesn't resolve to section/offset.
244
Greg Clayton1b72fcb2010-08-24 00:45:41245 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40246 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41247 if (!so_addr.IsValid())
248 {
249 // The address didn't resolve, so just set this as an absolute address
250 so_addr.SetOffset (addr);
251 }
252 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner30fdc8d2010-06-08 16:52:24253 return bp_sp;
254}
255
256BreakpointSP
257Target::CreateBreakpoint (Address &addr, bool internal)
258{
259 TargetSP target_sp = this->GetSP();
Jim Inghamc6674fd2011-10-28 23:14:11260 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (target_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24261 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
262 return CreateBreakpoint (filter_sp, resolver_sp, internal);
263}
264
265BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11266Target::CreateBreakpoint (const FileSpecList *containingModules,
267 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17268 const char *func_name,
269 uint32_t func_name_type_mask,
270 bool internal,
271 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24272{
Greg Clayton0c5cd902010-06-28 21:30:43273 BreakpointSP bp_sp;
274 if (func_name)
275 {
Jim Ingham87df91b2011-09-23 00:54:11276 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Claytond16e1e52011-07-12 17:06:17277
278 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
279 func_name,
280 func_name_type_mask,
281 Breakpoint::Exact,
282 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton0c5cd902010-06-28 21:30:43283 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
284 }
285 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24286}
287
288
289SearchFilterSP
290Target::GetSearchFilterForModule (const FileSpec *containingModule)
291{
292 SearchFilterSP filter_sp;
293 lldb::TargetSP target_sp = this->GetSP();
294 if (containingModule != NULL)
295 {
296 // TODO: We should look into sharing module based search filters
297 // across many breakpoints like we do for the simple target based one
298 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
299 }
300 else
301 {
302 if (m_search_filter_sp.get() == NULL)
Jim Inghamc6674fd2011-10-28 23:14:11303 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24304 filter_sp = m_search_filter_sp;
305 }
306 return filter_sp;
307}
308
Jim Ingham969795f2011-09-21 01:17:13309SearchFilterSP
310Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
311{
312 SearchFilterSP filter_sp;
313 lldb::TargetSP target_sp = this->GetSP();
314 if (containingModules && containingModules->GetSize() != 0)
315 {
316 // TODO: We should look into sharing module based search filters
317 // across many breakpoints like we do for the simple target based one
318 filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules));
319 }
320 else
321 {
322 if (m_search_filter_sp.get() == NULL)
Jim Inghamc6674fd2011-10-28 23:14:11323 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
Jim Ingham969795f2011-09-21 01:17:13324 filter_sp = m_search_filter_sp;
325 }
326 return filter_sp;
327}
328
Jim Ingham87df91b2011-09-23 00:54:11329SearchFilterSP
330Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
331{
332 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
333 return GetSearchFilterForModuleList(containingModules);
334
335 SearchFilterSP filter_sp;
336 lldb::TargetSP target_sp = this->GetSP();
337 if (containingModules == NULL)
338 {
339 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
340 // but that will take a little reworking.
341
342 filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, FileSpecList(), *containingSourceFiles));
343 }
344 else
345 {
346 filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, *containingModules, *containingSourceFiles));
347 }
348 return filter_sp;
349}
350
Chris Lattner30fdc8d2010-06-08 16:52:24351BreakpointSP
Jim Ingham87df91b2011-09-23 00:54:11352Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
353 const FileSpecList *containingSourceFiles,
Greg Claytond16e1e52011-07-12 17:06:17354 RegularExpression &func_regex,
355 bool internal,
356 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24357{
Jim Ingham87df91b2011-09-23 00:54:11358 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Claytond16e1e52011-07-12 17:06:17359 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
360 func_regex,
361 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner30fdc8d2010-06-08 16:52:24362
363 return CreateBreakpoint (filter_sp, resolver_sp, internal);
364}
365
366BreakpointSP
367Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
368{
369 BreakpointSP bp_sp;
370 if (filter_sp && resolver_sp)
371 {
372 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
373 resolver_sp->SetBreakpoint (bp_sp.get());
374
375 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17376 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24377 else
Greg Clayton9fed0d82010-07-23 23:33:17378 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24379
Greg Clayton2d4edfb2010-11-06 01:53:30380 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24381 if (log)
382 {
383 StreamString s;
384 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
385 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
386 }
387
Chris Lattner30fdc8d2010-06-08 16:52:24388 bp_sp->ResolveBreakpoint();
389 }
Jim Ingham36f3b362010-10-14 23:45:03390
391 if (!internal && bp_sp)
392 {
393 m_last_created_breakpoint = bp_sp;
394 }
395
Chris Lattner30fdc8d2010-06-08 16:52:24396 return bp_sp;
397}
398
Johnny Chen86364b42011-09-20 23:28:55399bool
400Target::ProcessIsValid()
401{
402 return (m_process_sp && m_process_sp->IsAlive());
403}
404
Johnny Chen01a67862011-10-14 00:42:25405// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chenab9ee762011-09-14 00:26:03406// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen01a67862011-10-14 00:42:25407WatchpointSP
408Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen887062a2011-09-12 23:38:44409{
Johnny Chen0c406372011-09-14 20:23:45410 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
411 if (log)
412 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
413 __FUNCTION__, addr, size, type);
414
Johnny Chen01a67862011-10-14 00:42:25415 WatchpointSP wp_sp;
Johnny Chen86364b42011-09-20 23:28:55416 if (!ProcessIsValid())
Johnny Chen01a67862011-10-14 00:42:25417 return wp_sp;
Johnny Chen45e541f2011-09-14 22:20:15418 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen01a67862011-10-14 00:42:25419 return wp_sp;
Johnny Chen7313a642011-09-13 01:15:36420
Johnny Chen01a67862011-10-14 00:42:25421 // Currently we only support one watchpoint per address, with total number
422 // of watchpoints limited by the hardware which the inferior is running on.
423 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen3c532582011-09-13 23:29:31424 if (matched_sp)
425 {
Johnny Chen0c406372011-09-14 20:23:45426 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31427 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45428 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
429 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen01a67862011-10-14 00:42:25430 // Return the existing watchpoint if both size and type match.
Johnny Chen45e541f2011-09-14 22:20:15431 if (size == old_size && type == old_type) {
Johnny Chen01a67862011-10-14 00:42:25432 wp_sp = matched_sp;
433 wp_sp->SetEnabled(false);
Johnny Chen45e541f2011-09-14 22:20:15434 } else {
Johnny Chen01a67862011-10-14 00:42:25435 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen45e541f2011-09-14 22:20:15436 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chen01a67862011-10-14 00:42:25437 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen45e541f2011-09-14 22:20:15438 }
Johnny Chen3c532582011-09-13 23:29:31439 }
440
Johnny Chen01a67862011-10-14 00:42:25441 if (!wp_sp) {
442 Watchpoint *new_wp = new Watchpoint(addr, size);
443 if (!new_wp) {
444 printf("Watchpoint ctor failed, out of memory?\n");
445 return wp_sp;
Johnny Chen45e541f2011-09-14 22:20:15446 }
Johnny Chen01a67862011-10-14 00:42:25447 new_wp->SetWatchpointType(type);
448 new_wp->SetTarget(this);
449 wp_sp.reset(new_wp);
450 m_watchpoint_list.Add(wp_sp);
Johnny Chen45e541f2011-09-14 22:20:15451 }
Johnny Chen0c406372011-09-14 20:23:45452
Johnny Chen01a67862011-10-14 00:42:25453 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen0c406372011-09-14 20:23:45454 if (log)
455 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
456 __FUNCTION__,
457 rc.Success() ? "succeeded" : "failed",
Johnny Chen01a67862011-10-14 00:42:25458 wp_sp->GetID());
Johnny Chen0c406372011-09-14 20:23:45459
Johnny Chen9d954d82011-09-27 20:29:45460 if (rc.Fail())
Johnny Chen01a67862011-10-14 00:42:25461 wp_sp.reset();
Johnny Chen9d954d82011-09-27 20:29:45462 else
Johnny Chen01a67862011-10-14 00:42:25463 m_last_created_watchpoint = wp_sp;
464 return wp_sp;
Johnny Chen887062a2011-09-12 23:38:44465}
466
Chris Lattner30fdc8d2010-06-08 16:52:24467void
468Target::RemoveAllBreakpoints (bool internal_also)
469{
Greg Clayton2d4edfb2010-11-06 01:53:30470 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24471 if (log)
472 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
473
Greg Clayton9fed0d82010-07-23 23:33:17474 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24475 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17476 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03477
478 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24479}
480
481void
482Target::DisableAllBreakpoints (bool internal_also)
483{
Greg Clayton2d4edfb2010-11-06 01:53:30484 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24485 if (log)
486 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
487
488 m_breakpoint_list.SetEnabledAll (false);
489 if (internal_also)
490 m_internal_breakpoint_list.SetEnabledAll (false);
491}
492
493void
494Target::EnableAllBreakpoints (bool internal_also)
495{
Greg Clayton2d4edfb2010-11-06 01:53:30496 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24497 if (log)
498 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
499
500 m_breakpoint_list.SetEnabledAll (true);
501 if (internal_also)
502 m_internal_breakpoint_list.SetEnabledAll (true);
503}
504
505bool
506Target::RemoveBreakpointByID (break_id_t break_id)
507{
Greg Clayton2d4edfb2010-11-06 01:53:30508 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24509 if (log)
510 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
511
512 if (DisableBreakpointByID (break_id))
513 {
514 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17515 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24516 else
Jim Ingham36f3b362010-10-14 23:45:03517 {
Greg Claytonaa1c5872011-01-24 23:35:47518 if (m_last_created_breakpoint)
519 {
520 if (m_last_created_breakpoint->GetID() == break_id)
521 m_last_created_breakpoint.reset();
522 }
Greg Clayton9fed0d82010-07-23 23:33:17523 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03524 }
Chris Lattner30fdc8d2010-06-08 16:52:24525 return true;
526 }
527 return false;
528}
529
530bool
531Target::DisableBreakpointByID (break_id_t break_id)
532{
Greg Clayton2d4edfb2010-11-06 01:53:30533 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24534 if (log)
535 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
536
537 BreakpointSP bp_sp;
538
539 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
540 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
541 else
542 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
543 if (bp_sp)
544 {
545 bp_sp->SetEnabled (false);
546 return true;
547 }
548 return false;
549}
550
551bool
552Target::EnableBreakpointByID (break_id_t break_id)
553{
Greg Clayton2d4edfb2010-11-06 01:53:30554 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24555 if (log)
556 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
557 __FUNCTION__,
558 break_id,
559 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
560
561 BreakpointSP bp_sp;
562
563 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
564 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
565 else
566 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
567
568 if (bp_sp)
569 {
570 bp_sp->SetEnabled (true);
571 return true;
572 }
573 return false;
574}
575
Johnny Chenedf50372011-09-23 21:21:43576// The flag 'end_to_end', default to true, signifies that the operation is
577// performed end to end, for both the debugger and the debuggee.
578
Johnny Chen01a67862011-10-14 00:42:25579// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
580// to end operations.
Johnny Chen86364b42011-09-20 23:28:55581bool
Johnny Chen01a67862011-10-14 00:42:25582Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55583{
584 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
585 if (log)
586 log->Printf ("Target::%s\n", __FUNCTION__);
587
Johnny Chenedf50372011-09-23 21:21:43588 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25589 m_watchpoint_list.RemoveAll();
Johnny Chenedf50372011-09-23 21:21:43590 return true;
591 }
592
593 // Otherwise, it's an end to end operation.
594
Johnny Chen86364b42011-09-20 23:28:55595 if (!ProcessIsValid())
596 return false;
597
Johnny Chen01a67862011-10-14 00:42:25598 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55599 for (size_t i = 0; i < num_watchpoints; ++i)
600 {
Johnny Chen01a67862011-10-14 00:42:25601 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
602 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55603 return false;
604
Johnny Chen01a67862011-10-14 00:42:25605 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55606 if (rc.Fail())
607 return false;
608 }
Johnny Chen01a67862011-10-14 00:42:25609 m_watchpoint_list.RemoveAll ();
Johnny Chen86364b42011-09-20 23:28:55610 return true; // Success!
611}
612
Johnny Chen01a67862011-10-14 00:42:25613// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
614// end operations.
Johnny Chen86364b42011-09-20 23:28:55615bool
Johnny Chen01a67862011-10-14 00:42:25616Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55617{
618 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
619 if (log)
620 log->Printf ("Target::%s\n", __FUNCTION__);
621
Johnny Chenedf50372011-09-23 21:21:43622 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25623 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenedf50372011-09-23 21:21:43624 return true;
625 }
626
627 // Otherwise, it's an end to end operation.
628
Johnny Chen86364b42011-09-20 23:28:55629 if (!ProcessIsValid())
630 return false;
631
Johnny Chen01a67862011-10-14 00:42:25632 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55633 for (size_t i = 0; i < num_watchpoints; ++i)
634 {
Johnny Chen01a67862011-10-14 00:42:25635 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
636 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55637 return false;
638
Johnny Chen01a67862011-10-14 00:42:25639 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55640 if (rc.Fail())
641 return false;
642 }
Johnny Chen86364b42011-09-20 23:28:55643 return true; // Success!
644}
645
Johnny Chen01a67862011-10-14 00:42:25646// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
647// end operations.
Johnny Chen86364b42011-09-20 23:28:55648bool
Johnny Chen01a67862011-10-14 00:42:25649Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chen86364b42011-09-20 23:28:55650{
651 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
652 if (log)
653 log->Printf ("Target::%s\n", __FUNCTION__);
654
Johnny Chenedf50372011-09-23 21:21:43655 if (!end_to_end) {
Johnny Chen01a67862011-10-14 00:42:25656 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenedf50372011-09-23 21:21:43657 return true;
658 }
659
660 // Otherwise, it's an end to end operation.
661
Johnny Chen86364b42011-09-20 23:28:55662 if (!ProcessIsValid())
663 return false;
664
Johnny Chen01a67862011-10-14 00:42:25665 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen86364b42011-09-20 23:28:55666 for (size_t i = 0; i < num_watchpoints; ++i)
667 {
Johnny Chen01a67862011-10-14 00:42:25668 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
669 if (!wp_sp)
Johnny Chen86364b42011-09-20 23:28:55670 return false;
671
Johnny Chen01a67862011-10-14 00:42:25672 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen86364b42011-09-20 23:28:55673 if (rc.Fail())
674 return false;
675 }
Johnny Chen86364b42011-09-20 23:28:55676 return true; // Success!
677}
678
Johnny Chen01a67862011-10-14 00:42:25679// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chen6cc60e82011-10-05 21:35:46680// during these operations.
681bool
Johnny Chen01a67862011-10-14 00:42:25682Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46683{
684 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
685 if (log)
686 log->Printf ("Target::%s\n", __FUNCTION__);
687
688 if (!ProcessIsValid())
689 return false;
690
Johnny Chen01a67862011-10-14 00:42:25691 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chen6cc60e82011-10-05 21:35:46692 for (size_t i = 0; i < num_watchpoints; ++i)
693 {
Johnny Chen01a67862011-10-14 00:42:25694 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
695 if (!wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46696 return false;
697
Johnny Chen01a67862011-10-14 00:42:25698 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46699 }
700 return true; // Success!
701}
702
Johnny Chen01a67862011-10-14 00:42:25703// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55704bool
Johnny Chen01a67862011-10-14 00:42:25705Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55706{
707 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
708 if (log)
709 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
710
711 if (!ProcessIsValid())
712 return false;
713
Johnny Chen01a67862011-10-14 00:42:25714 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
715 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55716 {
Johnny Chen01a67862011-10-14 00:42:25717 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58718 if (rc.Success())
719 return true;
Johnny Chen86364b42011-09-20 23:28:55720
Johnny Chenf04ee932011-09-22 18:04:58721 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55722 }
723 return false;
724}
725
Johnny Chen01a67862011-10-14 00:42:25726// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55727bool
Johnny Chen01a67862011-10-14 00:42:25728Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55729{
730 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
731 if (log)
732 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
733
734 if (!ProcessIsValid())
735 return false;
736
Johnny Chen01a67862011-10-14 00:42:25737 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
738 if (wp_sp)
Johnny Chen86364b42011-09-20 23:28:55739 {
Johnny Chen01a67862011-10-14 00:42:25740 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58741 if (rc.Success())
742 return true;
Johnny Chen86364b42011-09-20 23:28:55743
Johnny Chenf04ee932011-09-22 18:04:58744 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55745 }
746 return false;
747}
748
Johnny Chen01a67862011-10-14 00:42:25749// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen86364b42011-09-20 23:28:55750bool
Johnny Chen01a67862011-10-14 00:42:25751Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chen86364b42011-09-20 23:28:55752{
753 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
754 if (log)
755 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
756
Johnny Chen01a67862011-10-14 00:42:25757 if (DisableWatchpointByID (watch_id))
Johnny Chen86364b42011-09-20 23:28:55758 {
Johnny Chen01a67862011-10-14 00:42:25759 m_watchpoint_list.Remove(watch_id);
Johnny Chen86364b42011-09-20 23:28:55760 return true;
761 }
762 return false;
763}
764
Johnny Chen01a67862011-10-14 00:42:25765// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chen6cc60e82011-10-05 21:35:46766bool
Johnny Chen01a67862011-10-14 00:42:25767Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chen6cc60e82011-10-05 21:35:46768{
769 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
770 if (log)
771 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
772
773 if (!ProcessIsValid())
774 return false;
775
Johnny Chen01a67862011-10-14 00:42:25776 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
777 if (wp_sp)
Johnny Chen6cc60e82011-10-05 21:35:46778 {
Johnny Chen01a67862011-10-14 00:42:25779 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chen6cc60e82011-10-05 21:35:46780 return true;
781 }
782 return false;
783}
784
Chris Lattner30fdc8d2010-06-08 16:52:24785ModuleSP
786Target::GetExecutableModule ()
787{
Greg Claytonaa149cb2011-08-11 02:48:45788 return m_images.GetModuleAtIndex(0);
789}
790
791Module*
792Target::GetExecutableModulePointer ()
793{
794 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24795}
796
797void
798Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
799{
800 m_images.Clear();
801 m_scratch_ast_context_ap.reset();
Sean Callanan4bf80d52011-11-15 22:27:19802 m_scratch_ast_source_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47803 m_ast_importer_ap.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24804
805 if (executable_sp.get())
806 {
807 Timer scoped_timer (__PRETTY_FUNCTION__,
808 "Target::SetExecutableModule (executable = '%s/%s')",
809 executable_sp->GetFileSpec().GetDirectory().AsCString(),
810 executable_sp->GetFileSpec().GetFilename().AsCString());
811
812 m_images.Append(executable_sp); // The first image is our exectuable file
813
Jim Ingham5aee1622010-08-09 23:31:02814 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton32e0a752011-03-30 18:16:51815 if (!m_arch.IsValid())
816 m_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02817
Chris Lattner30fdc8d2010-06-08 16:52:24818 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15819 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24820
Greg Claytoncac9c5f2011-09-24 00:52:29821 if (executable_objfile && get_dependent_files)
Chris Lattner30fdc8d2010-06-08 16:52:24822 {
823 executable_objfile->GetDependentModules(dependent_files);
824 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
825 {
Greg Claytonded470d2011-03-19 01:12:21826 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
827 FileSpec platform_dependent_file_spec;
828 if (m_platform_sp)
Greg Claytond314e812011-03-23 00:09:55829 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21830 else
831 platform_dependent_file_spec = dependent_file_spec;
832
833 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton32e0a752011-03-30 18:16:51834 m_arch));
Chris Lattner30fdc8d2010-06-08 16:52:24835 if (image_module_sp.get())
836 {
Chris Lattner30fdc8d2010-06-08 16:52:24837 ObjectFile *objfile = image_module_sp->GetObjectFile();
838 if (objfile)
839 objfile->GetDependentModules(dependent_files);
840 }
841 }
842 }
843
Sean Callanan686b2312011-11-16 18:20:47844 m_ast_importer_ap.reset(new ClangASTImporter());
Chris Lattner30fdc8d2010-06-08 16:52:24845 }
Caroline Tice1559a462010-09-27 00:30:10846
847 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24848}
849
850
Jim Ingham5aee1622010-08-09 23:31:02851bool
852Target::SetArchitecture (const ArchSpec &arch_spec)
853{
Greg Clayton32e0a752011-03-30 18:16:51854 if (m_arch == arch_spec)
Jim Ingham5aee1622010-08-09 23:31:02855 {
856 // If we're setting the architecture to our current architecture, we
857 // don't need to do anything.
858 return true;
859 }
Greg Clayton32e0a752011-03-30 18:16:51860 else if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02861 {
862 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton32e0a752011-03-30 18:16:51863 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02864 return true;
865 }
866 else
867 {
868 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton32e0a752011-03-30 18:16:51869 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02870 ModuleSP executable_sp = GetExecutableModule ();
871 m_images.Clear();
872 m_scratch_ast_context_ap.reset();
Sean Callanan686b2312011-11-16 18:20:47873 m_scratch_ast_source_ap.reset();
874 m_ast_importer_ap.reset();
Jim Ingham5aee1622010-08-09 23:31:02875 // Need to do something about unsetting breakpoints.
876
877 if (executable_sp)
878 {
879 FileSpec exec_file_spec = executable_sp->GetFileSpec();
880 Error error = ModuleList::GetSharedModule(exec_file_spec,
881 arch_spec,
882 NULL,
883 NULL,
884 0,
885 executable_sp,
886 NULL,
887 NULL);
888
889 if (!error.Fail() && executable_sp)
890 {
891 SetExecutableModule (executable_sp, true);
892 return true;
893 }
894 else
895 {
896 return false;
897 }
898 }
899 else
900 {
901 return false;
902 }
903 }
904}
Chris Lattner30fdc8d2010-06-08 16:52:24905
Chris Lattner30fdc8d2010-06-08 16:52:24906void
907Target::ModuleAdded (ModuleSP &module_sp)
908{
909 // A module is being added to this target for the first time
910 ModuleList module_list;
911 module_list.Append(module_sp);
912 ModulesDidLoad (module_list);
913}
914
915void
916Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
917{
Jim Inghame716ae02011-08-03 01:00:06918 // A module is replacing an already added module
Chris Lattner30fdc8d2010-06-08 16:52:24919 ModuleList module_list;
920 module_list.Append (old_module_sp);
921 ModulesDidUnload (module_list);
922 module_list.Clear ();
923 module_list.Append (new_module_sp);
924 ModulesDidLoad (module_list);
925}
926
927void
928Target::ModulesDidLoad (ModuleList &module_list)
929{
930 m_breakpoint_list.UpdateBreakpoints (module_list, true);
931 // TODO: make event data that packages up the module_list
932 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
933}
934
935void
936Target::ModulesDidUnload (ModuleList &module_list)
937{
938 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Claytona4d78302010-12-06 23:51:26939
940 // Remove the images from the target image list
941 m_images.Remove(module_list);
942
Chris Lattner30fdc8d2010-06-08 16:52:24943 // TODO: make event data that packages up the module_list
944 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
945}
946
Jim Inghamc6674fd2011-10-28 23:14:11947
Daniel Dunbarf9f70322011-10-31 22:50:37948bool
Jim Inghamc6674fd2011-10-28 23:14:11949Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec)
950{
951
952 if (!m_breakpoints_use_platform_avoid)
953 return false;
954 else
955 {
956 ModuleList matchingModules;
957 const ArchSpec *arch_ptr = NULL;
958 const lldb_private::UUID *uuid_ptr= NULL;
959 const ConstString *object_name = NULL;
960 size_t num_modules = GetImages().FindModules(&module_spec, arch_ptr, uuid_ptr, object_name, matchingModules);
961
962 // If there is more than one module for this file spec, only return true if ALL the modules are on the
963 // black list.
964 if (num_modules > 0)
965 {
966 for (int i = 0; i < num_modules; i++)
967 {
968 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
969 return false;
970 }
971 return true;
972 }
973 else
974 return false;
975 }
976}
977
Daniel Dunbarf9f70322011-10-31 22:50:37978bool
Jim Inghamc6674fd2011-10-28 23:14:11979Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
980{
981 if (!m_breakpoints_use_platform_avoid)
982 return false;
983 else if (GetPlatform())
984 {
985 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
986 }
987 else
988 return false;
989}
990
Chris Lattner30fdc8d2010-06-08 16:52:24991size_t
Greg Claytondb598232011-01-07 01:57:07992Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
993{
994 const Section *section = addr.GetSection();
995 if (section && section->GetModule())
996 {
997 ObjectFile *objfile = section->GetModule()->GetObjectFile();
998 if (objfile)
999 {
1000 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
1001 addr.GetOffset(),
1002 dst,
1003 dst_len);
1004 if (bytes_read > 0)
1005 return bytes_read;
1006 else
1007 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
1008 }
1009 else
1010 {
1011 error.SetErrorString("address isn't from a object file");
1012 }
1013 }
1014 else
1015 {
1016 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
1017 }
1018 return 0;
1019}
1020
1021size_t
Enrico Granata9128ee2f2011-09-06 19:20:511022Target::ReadMemory (const Address& addr,
1023 bool prefer_file_cache,
1024 void *dst,
1025 size_t dst_len,
1026 Error &error,
1027 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:241028{
Chris Lattner30fdc8d2010-06-08 16:52:241029 error.Clear();
Greg Claytondb598232011-01-07 01:57:071030
Enrico Granata9128ee2f2011-09-06 19:20:511031 // if we end up reading this from process memory, we will fill this
1032 // with the actual load address
1033 if (load_addr_ptr)
1034 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1035
Greg Claytondb598232011-01-07 01:57:071036 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:021037
1038 addr_t load_addr = LLDB_INVALID_ADDRESS;
1039 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:581040 Address resolved_addr;
1041 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:031042 {
Greg Claytond16e1e52011-07-12 17:06:171043 if (m_section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:021044 {
Greg Claytond16e1e52011-07-12 17:06:171045 // No sections are loaded, so we must assume we are not running
1046 // yet and anything we are given is a file address.
1047 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1048 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:021049 }
Greg Claytondda4f7b2010-06-30 23:03:031050 else
Greg Claytonc749eb82011-07-11 05:12:021051 {
Greg Claytond16e1e52011-07-12 17:06:171052 // We have at least one section loaded. This can be becuase
1053 // we have manually loaded some sections with "target modules load ..."
1054 // or because we have have a live process that has sections loaded
1055 // through the dynamic loader
1056 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1057 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:021058 }
Greg Claytondda4f7b2010-06-30 23:03:031059 }
Greg Clayton357132e2011-03-26 19:14:581060 if (!resolved_addr.IsValid())
1061 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:031062
Greg Claytonc749eb82011-07-11 05:12:021063
Greg Claytondb598232011-01-07 01:57:071064 if (prefer_file_cache)
1065 {
1066 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1067 if (bytes_read > 0)
1068 return bytes_read;
1069 }
Greg Claytondda4f7b2010-06-30 23:03:031070
Johnny Chen86364b42011-09-20 23:28:551071 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:031072 {
Greg Claytonc749eb82011-07-11 05:12:021073 if (load_addr == LLDB_INVALID_ADDRESS)
1074 load_addr = resolved_addr.GetLoadAddress (this);
1075
Greg Claytondda4f7b2010-06-30 23:03:031076 if (load_addr == LLDB_INVALID_ADDRESS)
1077 {
1078 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
Greg Clayton86edbf42011-10-26 00:56:271079 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Claytondda4f7b2010-06-30 23:03:031080 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
Jason Molenda7e589a62011-09-20 00:26:081081 resolved_addr.GetFileAddress(),
1082 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
Greg Claytondda4f7b2010-06-30 23:03:031083 else
Greg Clayton86edbf42011-10-26 00:56:271084 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Claytondda4f7b2010-06-30 23:03:031085 }
1086 else
1087 {
Greg Claytondb598232011-01-07 01:57:071088 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:241089 if (bytes_read != dst_len)
1090 {
1091 if (error.Success())
1092 {
1093 if (bytes_read == 0)
Greg Clayton86edbf42011-10-26 00:56:271094 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:241095 else
Greg Clayton86edbf42011-10-26 00:56:271096 error.SetErrorStringWithFormat("only %zu of %zu bytes were read from memory at 0x%llx", bytes_read, dst_len, load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:241097 }
1098 }
Greg Claytondda4f7b2010-06-30 23:03:031099 if (bytes_read)
Enrico Granata9128ee2f2011-09-06 19:20:511100 {
1101 if (load_addr_ptr)
1102 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:031103 return bytes_read;
Enrico Granata9128ee2f2011-09-06 19:20:511104 }
Greg Claytondda4f7b2010-06-30 23:03:031105 // If the address is not section offset we have an address that
1106 // doesn't resolve to any address in any currently loaded shared
1107 // libaries and we failed to read memory so there isn't anything
1108 // more we can do. If it is section offset, we might be able to
1109 // read cached memory from the object file.
1110 if (!resolved_addr.IsSectionOffset())
1111 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:241112 }
Chris Lattner30fdc8d2010-06-08 16:52:241113 }
Greg Claytondda4f7b2010-06-30 23:03:031114
Greg Claytonc749eb82011-07-11 05:12:021115 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:031116 {
Greg Claytondb598232011-01-07 01:57:071117 // If we didn't already try and read from the object file cache, then
1118 // try it after failing to read from the process.
1119 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:031120 }
1121 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:241122}
1123
Greg Claytond16e1e52011-07-12 17:06:171124size_t
1125Target::ReadScalarIntegerFromMemory (const Address& addr,
1126 bool prefer_file_cache,
1127 uint32_t byte_size,
1128 bool is_signed,
1129 Scalar &scalar,
1130 Error &error)
1131{
1132 uint64_t uval;
1133
1134 if (byte_size <= sizeof(uval))
1135 {
1136 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1137 if (bytes_read == byte_size)
1138 {
1139 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1140 uint32_t offset = 0;
1141 if (byte_size <= 4)
1142 scalar = data.GetMaxU32 (&offset, byte_size);
1143 else
1144 scalar = data.GetMaxU64 (&offset, byte_size);
1145
1146 if (is_signed)
1147 scalar.SignExtend(byte_size * 8);
1148 return bytes_read;
1149 }
1150 }
1151 else
1152 {
1153 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1154 }
1155 return 0;
1156}
1157
1158uint64_t
1159Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1160 bool prefer_file_cache,
1161 size_t integer_byte_size,
1162 uint64_t fail_value,
1163 Error &error)
1164{
1165 Scalar scalar;
1166 if (ReadScalarIntegerFromMemory (addr,
1167 prefer_file_cache,
1168 integer_byte_size,
1169 false,
1170 scalar,
1171 error))
1172 return scalar.ULongLong(fail_value);
1173 return fail_value;
1174}
1175
1176bool
1177Target::ReadPointerFromMemory (const Address& addr,
1178 bool prefer_file_cache,
1179 Error &error,
1180 Address &pointer_addr)
1181{
1182 Scalar scalar;
1183 if (ReadScalarIntegerFromMemory (addr,
1184 prefer_file_cache,
1185 m_arch.GetAddressByteSize(),
1186 false,
1187 scalar,
1188 error))
1189 {
1190 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1191 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1192 {
1193 if (m_section_load_list.IsEmpty())
1194 {
1195 // No sections are loaded, so we must assume we are not running
1196 // yet and anything we are given is a file address.
1197 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1198 }
1199 else
1200 {
1201 // We have at least one section loaded. This can be becuase
1202 // we have manually loaded some sections with "target modules load ..."
1203 // or because we have have a live process that has sections loaded
1204 // through the dynamic loader
1205 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1206 }
1207 // We weren't able to resolve the pointer value, so just return
1208 // an address with no section
1209 if (!pointer_addr.IsValid())
1210 pointer_addr.SetOffset (pointer_vm_addr);
1211 return true;
1212
1213 }
1214 }
1215 return false;
1216}
Chris Lattner30fdc8d2010-06-08 16:52:241217
1218ModuleSP
1219Target::GetSharedModule
1220(
1221 const FileSpec& file_spec,
1222 const ArchSpec& arch,
Greg Clayton60830262011-02-04 18:53:101223 const lldb_private::UUID *uuid_ptr,
Chris Lattner30fdc8d2010-06-08 16:52:241224 const ConstString *object_name,
1225 off_t object_offset,
1226 Error *error_ptr
1227)
1228{
1229 // Don't pass in the UUID so we can tell if we have a stale value in our list
1230 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1231 bool did_create_module = false;
1232 ModuleSP module_sp;
1233
Chris Lattner30fdc8d2010-06-08 16:52:241234 Error error;
1235
Greg Clayton32e0a752011-03-30 18:16:511236 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner30fdc8d2010-06-08 16:52:241237 if (m_image_search_paths.GetSize())
1238 {
1239 FileSpec transformed_spec;
1240 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
1241 {
1242 transformed_spec.GetFilename() = file_spec.GetFilename();
1243 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
1244 }
1245 }
1246
Greg Clayton32e0a752011-03-30 18:16:511247 // The platform is responsible for finding and caching an appropriate
1248 // module in the shared module cache.
1249 if (m_platform_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241250 {
Greg Clayton32e0a752011-03-30 18:16:511251 FileSpec platform_file_spec;
1252 error = m_platform_sp->GetSharedModule (file_spec,
1253 arch,
1254 uuid_ptr,
1255 object_name,
1256 object_offset,
1257 module_sp,
1258 &old_module_sp,
1259 &did_create_module);
1260 }
1261 else
1262 {
1263 error.SetErrorString("no platform is currently set");
Chris Lattner30fdc8d2010-06-08 16:52:241264 }
1265
Greg Clayton32e0a752011-03-30 18:16:511266 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner30fdc8d2010-06-08 16:52:241267 if (module_sp)
1268 {
1269 m_images.Append (module_sp);
1270 if (did_create_module)
1271 {
1272 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1273 ModuleUpdated(old_module_sp, module_sp);
1274 else
1275 ModuleAdded(module_sp);
1276 }
1277 }
1278 if (error_ptr)
1279 *error_ptr = error;
1280 return module_sp;
1281}
1282
1283
1284Target *
1285Target::CalculateTarget ()
1286{
1287 return this;
1288}
1289
1290Process *
1291Target::CalculateProcess ()
1292{
1293 return NULL;
1294}
1295
1296Thread *
1297Target::CalculateThread ()
1298{
1299 return NULL;
1300}
1301
1302StackFrame *
1303Target::CalculateStackFrame ()
1304{
1305 return NULL;
1306}
1307
1308void
Greg Clayton0603aa92010-10-04 01:05:561309Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:241310{
Greg Claytonc14ee322011-09-22 04:58:261311 exe_ctx.Clear();
1312 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:241313}
1314
1315PathMappingList &
1316Target::GetImageSearchPathList ()
1317{
1318 return m_image_search_paths;
1319}
1320
1321void
1322Target::ImageSearchPathsChanged
1323(
1324 const PathMappingList &path_list,
1325 void *baton
1326)
1327{
1328 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:451329 ModuleSP exe_module_sp (target->GetExecutableModule());
1330 if (exe_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241331 {
Greg Claytonaa149cb2011-08-11 02:48:451332 target->m_images.Clear();
1333 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:241334 }
1335}
1336
1337ClangASTContext *
1338Target::GetScratchClangASTContext()
1339{
Greg Clayton73da2442011-08-03 01:23:551340 // Now see if we know the target triple, and if so, create our scratch AST context:
1341 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
Sean Callanan4bf80d52011-11-15 22:27:191342 {
Greg Clayton73da2442011-08-03 01:23:551343 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Sean Callanan4bf80d52011-11-15 22:27:191344 m_scratch_ast_source_ap.reset (new ClangASTSource(GetSP()));
1345 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1346 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1347 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1348 }
Chris Lattner30fdc8d2010-06-08 16:52:241349 return m_scratch_ast_context_ap.get();
1350}
Caroline Ticedaccaa92010-09-20 20:44:431351
Sean Callanan686b2312011-11-16 18:20:471352ClangASTImporter *
1353Target::GetClangASTImporter()
1354{
1355 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1356
1357 if (!ast_importer)
1358 {
1359 ast_importer = new ClangASTImporter();
1360 m_ast_importer_ap.reset(ast_importer);
1361 }
1362
1363 return ast_importer;
1364}
1365
Greg Clayton99d0faf2010-11-18 23:32:351366void
Caroline Tice20bd37f2011-03-10 22:14:101367Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:431368{
Greg Clayton99d0faf2010-11-18 23:32:351369 UserSettingsControllerSP &usc = GetSettingsController();
1370 usc.reset (new SettingsController);
1371 UserSettingsController::InitializeSettingsController (usc,
1372 SettingsController::global_settings_table,
1373 SettingsController::instance_settings_table);
Caroline Tice20bd37f2011-03-10 22:14:101374
1375 // Now call SettingsInitialize() on each 'child' setting of Target
1376 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:351377}
Caroline Ticedaccaa92010-09-20 20:44:431378
Greg Clayton99d0faf2010-11-18 23:32:351379void
Caroline Tice20bd37f2011-03-10 22:14:101380Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:351381{
Caroline Tice20bd37f2011-03-10 22:14:101382
1383 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1384
1385 Process::SettingsTerminate ();
1386
1387 // Now terminate Target Settings.
1388
Greg Clayton99d0faf2010-11-18 23:32:351389 UserSettingsControllerSP &usc = GetSettingsController();
1390 UserSettingsController::FinalizeSettingsController (usc);
1391 usc.reset();
1392}
Caroline Ticedaccaa92010-09-20 20:44:431393
Greg Clayton99d0faf2010-11-18 23:32:351394UserSettingsControllerSP &
1395Target::GetSettingsController ()
1396{
1397 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:431398 return g_settings_controller;
1399}
1400
1401ArchSpec
1402Target::GetDefaultArchitecture ()
1403{
Greg Clayton64195a22011-02-23 00:35:021404 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1405
1406 if (settings_controller_sp)
1407 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1408 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:431409}
1410
1411void
Greg Clayton64195a22011-02-23 00:35:021412Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Ticedaccaa92010-09-20 20:44:431413{
Greg Clayton64195a22011-02-23 00:35:021414 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1415
1416 if (settings_controller_sp)
1417 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Ticedaccaa92010-09-20 20:44:431418}
1419
Greg Clayton0603aa92010-10-04 01:05:561420Target *
1421Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1422{
1423 // The target can either exist in the "process" of ExecutionContext, or in
1424 // the "target_sp" member of SymbolContext. This accessor helper function
1425 // will get the target from one of these locations.
1426
1427 Target *target = NULL;
1428 if (sc_ptr != NULL)
1429 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:261430 if (target == NULL && exe_ctx_ptr)
1431 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:561432 return target;
1433}
1434
1435
Caroline Tice1559a462010-09-27 00:30:101436void
1437Target::UpdateInstanceName ()
1438{
1439 StreamString sstr;
1440
Greg Claytonaa149cb2011-08-11 02:48:451441 Module *exe_module = GetExecutableModulePointer();
1442 if (exe_module)
Caroline Tice1559a462010-09-27 00:30:101443 {
Greg Clayton307de252010-10-27 02:06:371444 sstr.Printf ("%s_%s",
Greg Claytonaa149cb2011-08-11 02:48:451445 exe_module->GetFileSpec().GetFilename().AsCString(),
1446 exe_module->GetArchitecture().GetArchitectureName());
1447 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:101448 }
1449}
1450
Sean Callanan322f5292010-10-29 00:29:031451const char *
1452Target::GetExpressionPrefixContentsAsCString ()
1453{
Sean Callanan6d6acc82011-11-16 01:54:571454 if (!m_expr_prefix_contents.empty())
1455 return m_expr_prefix_contents.c_str();
Greg Clayton7e14f912011-04-23 02:04:551456 return NULL;
Sean Callanan322f5292010-10-29 00:29:031457}
1458
Greg Clayton8b2fe6d2010-12-14 02:59:591459ExecutionResults
1460Target::EvaluateExpression
1461(
1462 const char *expr_cstr,
1463 StackFrame *frame,
Sean Callanan3bfdaa22011-09-15 02:13:071464 lldb_private::ExecutionPolicy execution_policy,
Greg Clayton8b2fe6d2010-12-14 02:59:591465 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:351466 bool keep_in_memory,
Jim Ingham2837b762011-05-04 03:43:181467 lldb::DynamicValueType use_dynamic,
Greg Clayton8b2fe6d2010-12-14 02:59:591468 lldb::ValueObjectSP &result_valobj_sp
1469)
1470{
1471 ExecutionResults execution_results = eExecutionSetupError;
1472
1473 result_valobj_sp.reset();
Jim Ingham6026ca32011-05-12 02:06:141474
1475 // We shouldn't run stop hooks in expressions.
1476 // Be sure to reset this if you return anywhere within this function.
1477 bool old_suppress_value = m_suppress_stop_hooks;
1478 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:591479
1480 ExecutionContext exe_ctx;
1481 if (frame)
1482 {
1483 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:081484 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:181485 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granata27b625e2011-08-09 01:04:561486 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1487 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham2837b762011-05-04 03:43:181488 lldb::VariableSP var_sp;
1489 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1490 use_dynamic,
1491 expr_path_options,
1492 var_sp,
1493 error);
Greg Clayton8b2fe6d2010-12-14 02:59:591494 }
1495 else if (m_process_sp)
1496 {
1497 m_process_sp->CalculateExecutionContext(exe_ctx);
1498 }
1499 else
1500 {
1501 CalculateExecutionContext(exe_ctx);
1502 }
1503
1504 if (result_valobj_sp)
1505 {
1506 execution_results = eExecutionCompleted;
1507 // We got a result from the frame variable expression path above...
1508 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1509
1510 lldb::ValueObjectSP const_valobj_sp;
1511
1512 // Check in case our value is already a constant value
1513 if (result_valobj_sp->GetIsConstant())
1514 {
1515 const_valobj_sp = result_valobj_sp;
1516 const_valobj_sp->SetName (persistent_variable_name);
1517 }
1518 else
Jim Ingham78a685a2011-04-16 00:01:131519 {
Jim Ingham2837b762011-05-04 03:43:181520 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:131521 {
Jim Ingham2837b762011-05-04 03:43:181522 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:131523 if (dynamic_sp)
1524 result_valobj_sp = dynamic_sp;
1525 }
1526
Jim Ingham6035b672011-03-31 00:19:251527 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Ingham78a685a2011-04-16 00:01:131528 }
Greg Clayton8b2fe6d2010-12-14 02:59:591529
Sean Callanan92adcac2011-01-13 08:53:351530 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1531
Greg Clayton8b2fe6d2010-12-14 02:59:591532 result_valobj_sp = const_valobj_sp;
1533
Sean Callanan92adcac2011-01-13 08:53:351534 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1535 assert (clang_expr_variable_sp.get());
1536
1537 // Set flags and live data as appropriate
1538
1539 const Value &result_value = live_valobj_sp->GetValue();
1540
1541 switch (result_value.GetValueType())
1542 {
1543 case Value::eValueTypeHostAddress:
1544 case Value::eValueTypeFileAddress:
1545 // we don't do anything with these for now
1546 break;
1547 case Value::eValueTypeScalar:
1548 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1549 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1550 break;
1551 case Value::eValueTypeLoadAddress:
1552 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1553 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1554 break;
1555 }
Greg Clayton8b2fe6d2010-12-14 02:59:591556 }
1557 else
1558 {
1559 // Make sure we aren't just trying to see the value of a persistent
1560 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:351561 lldb::ClangExpressionVariableSP persistent_var_sp;
1562 // Only check for persistent variables the expression starts with a '$'
1563 if (expr_cstr[0] == '$')
1564 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1565
Greg Clayton8b2fe6d2010-12-14 02:59:591566 if (persistent_var_sp)
1567 {
1568 result_valobj_sp = persistent_var_sp->GetValueObject ();
1569 execution_results = eExecutionCompleted;
1570 }
1571 else
1572 {
1573 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan3bfdaa22011-09-15 02:13:071574
Greg Clayton8b2fe6d2010-12-14 02:59:591575 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan3bfdaa22011-09-15 02:13:071576 execution_policy,
Sean Callananc7b65062011-11-07 23:35:401577 lldb::eLanguageTypeUnknown,
Sean Callanan92adcac2011-01-13 08:53:351578 unwind_on_error,
Greg Clayton8b2fe6d2010-12-14 02:59:591579 expr_cstr,
1580 prefix,
1581 result_valobj_sp);
1582 }
1583 }
Jim Ingham6026ca32011-05-12 02:06:141584
1585 m_suppress_stop_hooks = old_suppress_value;
1586
Greg Clayton8b2fe6d2010-12-14 02:59:591587 return execution_results;
1588}
1589
Greg Claytonf3ef3d22011-05-22 22:46:531590lldb::addr_t
1591Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1592{
1593 addr_t code_addr = load_addr;
1594 switch (m_arch.GetMachine())
1595 {
1596 case llvm::Triple::arm:
1597 case llvm::Triple::thumb:
1598 switch (addr_class)
1599 {
1600 case eAddressClassData:
1601 case eAddressClassDebug:
1602 return LLDB_INVALID_ADDRESS;
1603
1604 case eAddressClassUnknown:
1605 case eAddressClassInvalid:
1606 case eAddressClassCode:
1607 case eAddressClassCodeAlternateISA:
1608 case eAddressClassRuntime:
1609 // Check if bit zero it no set?
1610 if ((code_addr & 1ull) == 0)
1611 {
1612 // Bit zero isn't set, check if the address is a multiple of 2?
1613 if (code_addr & 2ull)
1614 {
1615 // The address is a multiple of 2 so it must be thumb, set bit zero
1616 code_addr |= 1ull;
1617 }
1618 else if (addr_class == eAddressClassCodeAlternateISA)
1619 {
1620 // We checked the address and the address claims to be the alternate ISA
1621 // which means thumb, so set bit zero.
1622 code_addr |= 1ull;
1623 }
1624 }
1625 break;
1626 }
1627 break;
1628
1629 default:
1630 break;
1631 }
1632 return code_addr;
1633}
1634
1635lldb::addr_t
1636Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1637{
1638 addr_t opcode_addr = load_addr;
1639 switch (m_arch.GetMachine())
1640 {
1641 case llvm::Triple::arm:
1642 case llvm::Triple::thumb:
1643 switch (addr_class)
1644 {
1645 case eAddressClassData:
1646 case eAddressClassDebug:
1647 return LLDB_INVALID_ADDRESS;
1648
1649 case eAddressClassInvalid:
1650 case eAddressClassUnknown:
1651 case eAddressClassCode:
1652 case eAddressClassCodeAlternateISA:
1653 case eAddressClassRuntime:
1654 opcode_addr &= ~(1ull);
1655 break;
1656 }
1657 break;
1658
1659 default:
1660 break;
1661 }
1662 return opcode_addr;
1663}
1664
Jim Ingham9575d842011-03-11 03:53:591665lldb::user_id_t
1666Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1667{
1668 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1669 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1670 m_stop_hooks[new_uid] = new_hook_sp;
1671 return new_uid;
1672}
1673
1674bool
1675Target::RemoveStopHookByID (lldb::user_id_t user_id)
1676{
1677 size_t num_removed;
1678 num_removed = m_stop_hooks.erase (user_id);
1679 if (num_removed == 0)
1680 return false;
1681 else
1682 return true;
1683}
1684
1685void
1686Target::RemoveAllStopHooks ()
1687{
1688 m_stop_hooks.clear();
1689}
1690
1691Target::StopHookSP
1692Target::GetStopHookByID (lldb::user_id_t user_id)
1693{
1694 StopHookSP found_hook;
1695
1696 StopHookCollection::iterator specified_hook_iter;
1697 specified_hook_iter = m_stop_hooks.find (user_id);
1698 if (specified_hook_iter != m_stop_hooks.end())
1699 found_hook = (*specified_hook_iter).second;
1700 return found_hook;
1701}
1702
1703bool
1704Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1705{
1706 StopHookCollection::iterator specified_hook_iter;
1707 specified_hook_iter = m_stop_hooks.find (user_id);
1708 if (specified_hook_iter == m_stop_hooks.end())
1709 return false;
1710
1711 (*specified_hook_iter).second->SetIsActive (active_state);
1712 return true;
1713}
1714
1715void
1716Target::SetAllStopHooksActiveState (bool active_state)
1717{
1718 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1719 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1720 {
1721 (*pos).second->SetIsActive (active_state);
1722 }
1723}
1724
1725void
1726Target::RunStopHooks ()
1727{
Jim Ingham6026ca32011-05-12 02:06:141728 if (m_suppress_stop_hooks)
1729 return;
1730
Jim Ingham9575d842011-03-11 03:53:591731 if (!m_process_sp)
1732 return;
1733
1734 if (m_stop_hooks.empty())
1735 return;
1736
1737 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1738
1739 // If there aren't any active stop hooks, don't bother either:
1740 bool any_active_hooks = false;
1741 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1742 {
1743 if ((*pos).second->IsActive())
1744 {
1745 any_active_hooks = true;
1746 break;
1747 }
1748 }
1749 if (!any_active_hooks)
1750 return;
1751
1752 CommandReturnObject result;
1753
1754 std::vector<ExecutionContext> exc_ctx_with_reasons;
1755 std::vector<SymbolContext> sym_ctx_with_reasons;
1756
1757 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1758 size_t num_threads = cur_threadlist.GetSize();
1759 for (size_t i = 0; i < num_threads; i++)
1760 {
1761 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1762 if (cur_thread_sp->ThreadStoppedForAReason())
1763 {
1764 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1765 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1766 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1767 }
1768 }
1769
1770 // If no threads stopped for a reason, don't run the stop-hooks.
1771 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1772 if (num_exe_ctx == 0)
1773 return;
1774
Jim Ingham5b52f0c2011-06-02 23:58:261775 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1776 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:591777
1778 bool keep_going = true;
1779 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:271780 bool print_hook_header;
1781 bool print_thread_header;
1782
1783 if (num_exe_ctx == 1)
1784 print_thread_header = false;
1785 else
1786 print_thread_header = true;
1787
1788 if (m_stop_hooks.size() == 1)
1789 print_hook_header = false;
1790 else
1791 print_hook_header = true;
1792
Jim Ingham9575d842011-03-11 03:53:591793 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1794 {
1795 // result.Clear();
1796 StopHookSP cur_hook_sp = (*pos).second;
1797 if (!cur_hook_sp->IsActive())
1798 continue;
1799
1800 bool any_thread_matched = false;
1801 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1802 {
1803 if ((cur_hook_sp->GetSpecifier () == NULL
1804 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1805 && (cur_hook_sp->GetThreadSpecifier() == NULL
Greg Claytonc14ee322011-09-22 04:58:261806 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
Jim Ingham9575d842011-03-11 03:53:591807 {
1808 if (!hooks_ran)
1809 {
Jim Ingham9575d842011-03-11 03:53:591810 hooks_ran = true;
1811 }
Jim Ingham381e25b2011-03-22 01:47:271812 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:591813 {
Johnny Chenaeab25c2011-10-24 23:01:061814 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1815 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1816 NULL);
1817 if (cmd)
1818 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1819 else
1820 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:591821 any_thread_matched = true;
1822 }
1823
Jim Ingham381e25b2011-03-22 01:47:271824 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:261825 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:591826
1827 bool stop_on_continue = true;
1828 bool stop_on_error = true;
1829 bool echo_commands = false;
1830 bool print_results = true;
1831 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:511832 &exc_ctx_with_reasons[i],
1833 stop_on_continue,
1834 stop_on_error,
1835 echo_commands,
1836 print_results,
1837 result);
Jim Ingham9575d842011-03-11 03:53:591838
1839 // If the command started the target going again, we should bag out of
1840 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:511841 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1842 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:591843 {
Greg Clayton81c22f62011-10-19 18:09:391844 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:591845 keep_going = false;
1846 }
1847 }
1848 }
1849 }
Jason Molenda879cf772011-09-23 00:42:551850
Caroline Tice969ed3d12011-05-02 20:41:461851 result.GetImmediateOutputStream()->Flush();
1852 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:591853}
1854
Greg Clayton7b242382011-07-08 00:48:091855bool
1856Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1857{
1858 bool changed = false;
1859 if (module)
1860 {
1861 ObjectFile *object_file = module->GetObjectFile();
1862 if (object_file)
1863 {
1864 SectionList *section_list = object_file->GetSectionList ();
1865 if (section_list)
1866 {
1867 // All sections listed in the dyld image info structure will all
1868 // either be fixed up already, or they will all be off by a single
1869 // slide amount that is determined by finding the first segment
1870 // that is at file offset zero which also has bytes (a file size
1871 // that is greater than zero) in the object file.
1872
1873 // Determine the slide amount (if any)
1874 const size_t num_sections = section_list->GetSize();
1875 size_t sect_idx = 0;
1876 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1877 {
1878 // Iterate through the object file sections to find the
1879 // first section that starts of file offset zero and that
1880 // has bytes in the file...
1881 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1882 if (section)
1883 {
1884 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1885 changed = true;
1886 }
1887 }
1888 }
1889 }
1890 }
1891 return changed;
1892}
1893
1894
Jim Ingham9575d842011-03-11 03:53:591895//--------------------------------------------------------------
1896// class Target::StopHook
1897//--------------------------------------------------------------
1898
1899
1900Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1901 UserID (uid),
1902 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:591903 m_commands (),
1904 m_specifier_sp (),
Stephen Wilson71c21d12011-04-11 19:41:401905 m_thread_spec_ap(NULL),
1906 m_active (true)
Jim Ingham9575d842011-03-11 03:53:591907{
1908}
1909
1910Target::StopHook::StopHook (const StopHook &rhs) :
1911 UserID (rhs.GetID()),
1912 m_target_sp (rhs.m_target_sp),
1913 m_commands (rhs.m_commands),
1914 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilson71c21d12011-04-11 19:41:401915 m_thread_spec_ap (NULL),
1916 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:591917{
1918 if (rhs.m_thread_spec_ap.get() != NULL)
1919 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1920}
1921
1922
1923Target::StopHook::~StopHook ()
1924{
1925}
1926
1927void
1928Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1929{
1930 m_thread_spec_ap.reset (specifier);
1931}
1932
1933
1934void
1935Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1936{
1937 int indent_level = s->GetIndentLevel();
1938
1939 s->SetIndentLevel(indent_level + 2);
1940
Greg Clayton81c22f62011-10-19 18:09:391941 s->Printf ("Hook: %llu\n", GetID());
Jim Ingham9575d842011-03-11 03:53:591942 if (m_active)
1943 s->Indent ("State: enabled\n");
1944 else
1945 s->Indent ("State: disabled\n");
1946
1947 if (m_specifier_sp)
1948 {
1949 s->Indent();
1950 s->PutCString ("Specifier:\n");
1951 s->SetIndentLevel (indent_level + 4);
1952 m_specifier_sp->GetDescription (s, level);
1953 s->SetIndentLevel (indent_level + 2);
1954 }
1955
1956 if (m_thread_spec_ap.get() != NULL)
1957 {
1958 StreamString tmp;
1959 s->Indent("Thread:\n");
1960 m_thread_spec_ap->GetDescription (&tmp, level);
1961 s->SetIndentLevel (indent_level + 4);
1962 s->Indent (tmp.GetData());
1963 s->PutCString ("\n");
1964 s->SetIndentLevel (indent_level + 2);
1965 }
1966
1967 s->Indent ("Commands: \n");
1968 s->SetIndentLevel (indent_level + 4);
1969 uint32_t num_commands = m_commands.GetSize();
1970 for (uint32_t i = 0; i < num_commands; i++)
1971 {
1972 s->Indent(m_commands.GetStringAtIndex(i));
1973 s->PutCString ("\n");
1974 }
1975 s->SetIndentLevel (indent_level);
1976}
1977
1978
Caroline Ticedaccaa92010-09-20 20:44:431979//--------------------------------------------------------------
1980// class Target::SettingsController
1981//--------------------------------------------------------------
1982
1983Target::SettingsController::SettingsController () :
1984 UserSettingsController ("target", Debugger::GetSettingsController()),
1985 m_default_architecture ()
1986{
1987 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1988 InstanceSettings::GetDefaultName().AsCString()));
1989}
1990
1991Target::SettingsController::~SettingsController ()
1992{
1993}
1994
1995lldb::InstanceSettingsSP
1996Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1997{
Greg Claytondbe54502010-11-19 03:46:011998 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1999 false,
2000 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:432001 lldb::InstanceSettingsSP new_settings_sp (new_settings);
2002 return new_settings_sp;
2003}
2004
Caroline Ticedaccaa92010-09-20 20:44:432005
Greg Clayton1d885962011-11-08 02:43:132006#define TSC_DEFAULT_ARCH "default-arch"
2007#define TSC_EXPR_PREFIX "expr-prefix"
2008#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2009#define TSC_SKIP_PROLOGUE "skip-prologue"
2010#define TSC_SOURCE_MAP "source-map"
2011#define TSC_MAX_CHILDREN "max-children-count"
2012#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2013#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2014#define TSC_RUN_ARGS "run-args"
2015#define TSC_ENV_VARS "env-vars"
2016#define TSC_INHERIT_ENV "inherit-env"
2017#define TSC_STDIN_PATH "input-path"
2018#define TSC_STDOUT_PATH "output-path"
2019#define TSC_STDERR_PATH "error-path"
2020#define TSC_DISABLE_ASLR "disable-aslr"
2021#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytonbfe5f3b2011-02-18 01:44:252022
2023
2024static const ConstString &
2025GetSettingNameForDefaultArch ()
2026{
2027 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytonbfe5f3b2011-02-18 01:44:252028 return g_const_string;
Caroline Ticedaccaa92010-09-20 20:44:432029}
2030
Greg Claytonbfe5f3b2011-02-18 01:44:252031static const ConstString &
2032GetSettingNameForExpressionPrefix ()
2033{
2034 static ConstString g_const_string (TSC_EXPR_PREFIX);
2035 return g_const_string;
2036}
2037
2038static const ConstString &
Jim Ingham78a685a2011-04-16 00:01:132039GetSettingNameForPreferDynamicValue ()
2040{
2041 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2042 return g_const_string;
2043}
2044
Greg Clayton7e14f912011-04-23 02:04:552045static const ConstString &
2046GetSettingNameForSourcePathMap ()
2047{
2048 static ConstString g_const_string (TSC_SOURCE_MAP);
2049 return g_const_string;
2050}
Greg Claytonbfe5f3b2011-02-18 01:44:252051
Greg Clayton385aa282011-04-22 03:55:062052static const ConstString &
2053GetSettingNameForSkipPrologue ()
2054{
2055 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2056 return g_const_string;
2057}
2058
Enrico Granata22c55d12011-08-12 02:00:062059static const ConstString &
2060GetSettingNameForMaxChildren ()
2061{
2062 static ConstString g_const_string (TSC_MAX_CHILDREN);
2063 return g_const_string;
2064}
Greg Clayton385aa282011-04-22 03:55:062065
Enrico Granata9128ee2f2011-09-06 19:20:512066static const ConstString &
2067GetSettingNameForMaxStringSummaryLength ()
2068{
2069 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2070 return g_const_string;
2071}
Greg Clayton385aa282011-04-22 03:55:062072
Jim Inghamc6674fd2011-10-28 23:14:112073static const ConstString &
2074GetSettingNameForPlatformAvoid ()
2075{
2076 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2077 return g_const_string;
2078}
2079
Greg Clayton1d885962011-11-08 02:43:132080const ConstString &
2081GetSettingNameForRunArgs ()
2082{
2083 static ConstString g_const_string (TSC_RUN_ARGS);
2084 return g_const_string;
2085}
2086
2087const ConstString &
2088GetSettingNameForEnvVars ()
2089{
2090 static ConstString g_const_string (TSC_ENV_VARS);
2091 return g_const_string;
2092}
2093
2094const ConstString &
2095GetSettingNameForInheritHostEnv ()
2096{
2097 static ConstString g_const_string (TSC_INHERIT_ENV);
2098 return g_const_string;
2099}
2100
2101const ConstString &
2102GetSettingNameForInputPath ()
2103{
2104 static ConstString g_const_string (TSC_STDIN_PATH);
2105 return g_const_string;
2106}
2107
2108const ConstString &
2109GetSettingNameForOutputPath ()
2110{
2111 static ConstString g_const_string (TSC_STDOUT_PATH);
2112 return g_const_string;
2113}
2114
2115const ConstString &
2116GetSettingNameForErrorPath ()
2117{
2118 static ConstString g_const_string (TSC_STDERR_PATH);
2119 return g_const_string;
2120}
2121
2122const ConstString &
2123GetSettingNameForDisableASLR ()
2124{
2125 static ConstString g_const_string (TSC_DISABLE_ASLR);
2126 return g_const_string;
2127}
2128
2129const ConstString &
2130GetSettingNameForDisableSTDIO ()
2131{
2132 static ConstString g_const_string (TSC_DISABLE_STDIO);
2133 return g_const_string;
2134}
Jim Inghamc6674fd2011-10-28 23:14:112135
Caroline Ticedaccaa92010-09-20 20:44:432136bool
2137Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2138 const char *index_value,
2139 const char *value,
2140 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:542141 const VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:432142 Error&err)
2143{
Greg Claytonbfe5f3b2011-02-18 01:44:252144 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:432145 {
Greg Claytoneb0103f2011-04-07 22:46:352146 m_default_architecture.SetTriple (value, NULL);
Greg Clayton64195a22011-02-23 00:35:022147 if (!m_default_architecture.IsValid())
2148 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Ticedaccaa92010-09-20 20:44:432149 }
2150 return true;
2151}
2152
2153
2154bool
2155Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2156 StringList &value,
2157 Error &err)
2158{
Greg Claytonbfe5f3b2011-02-18 01:44:252159 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:432160 {
Greg Clayton307de252010-10-27 02:06:372161 // If the arch is invalid (the default), don't show a string for it
2162 if (m_default_architecture.IsValid())
Greg Clayton64195a22011-02-23 00:35:022163 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Ticedaccaa92010-09-20 20:44:432164 return true;
2165 }
2166 else
2167 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2168
2169 return false;
2170}
2171
2172//--------------------------------------------------------------
2173// class TargetInstanceSettings
2174//--------------------------------------------------------------
2175
Greg Clayton85851dd2010-12-04 00:10:172176TargetInstanceSettings::TargetInstanceSettings
2177(
2178 UserSettingsController &owner,
2179 bool live_instance,
2180 const char *name
2181) :
Greg Claytonbfe5f3b2011-02-18 01:44:252182 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Clayton7e14f912011-04-23 02:04:552183 m_expr_prefix_file (),
Sean Callanan6d6acc82011-11-16 01:54:572184 m_expr_prefix_contents (),
Jim Ingham2837b762011-05-04 03:43:182185 m_prefer_dynamic_value (2),
Greg Clayton7e14f912011-04-23 02:04:552186 m_skip_prologue (true, true),
Enrico Granata22c55d12011-08-12 02:00:062187 m_source_map (NULL, NULL),
Enrico Granata9128ee2f2011-09-06 19:20:512188 m_max_children_display(256),
Jim Inghamc6674fd2011-10-28 23:14:112189 m_max_strlen_length(1024),
Greg Clayton1d885962011-11-08 02:43:132190 m_breakpoints_use_platform_avoid (true, true),
2191 m_run_args (),
2192 m_env_vars (),
2193 m_input_path (),
2194 m_output_path (),
2195 m_error_path (),
2196 m_disable_aslr (true),
2197 m_disable_stdio (false),
2198 m_inherit_host_env (true),
2199 m_got_host_env (false)
Caroline Ticedaccaa92010-09-20 20:44:432200{
2201 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2202 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2203 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2204 // This is true for CreateInstanceName() too.
2205
2206 if (GetInstanceName () == InstanceSettings::InvalidName())
2207 {
2208 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2209 m_owner.RegisterInstanceSettings (this);
2210 }
2211
2212 if (live_instance)
2213 {
2214 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
2215 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:432216 }
2217}
2218
2219TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton7e14f912011-04-23 02:04:552220 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
2221 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanan6d6acc82011-11-16 01:54:572222 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Clayton7e14f912011-04-23 02:04:552223 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2224 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata22c55d12011-08-12 02:00:062225 m_source_map (rhs.m_source_map),
Greg Clayton1d885962011-11-08 02:43:132226 m_max_children_display (rhs.m_max_children_display),
2227 m_max_strlen_length (rhs.m_max_strlen_length),
2228 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2229 m_run_args (rhs.m_run_args),
2230 m_env_vars (rhs.m_env_vars),
2231 m_input_path (rhs.m_input_path),
2232 m_output_path (rhs.m_output_path),
2233 m_error_path (rhs.m_error_path),
2234 m_disable_aslr (rhs.m_disable_aslr),
2235 m_disable_stdio (rhs.m_disable_stdio),
2236 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Ticedaccaa92010-09-20 20:44:432237{
2238 if (m_instance_name != InstanceSettings::GetDefaultName())
2239 {
2240 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
2241 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:432242 }
2243}
2244
2245TargetInstanceSettings::~TargetInstanceSettings ()
2246{
2247}
2248
2249TargetInstanceSettings&
2250TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2251{
2252 if (this != &rhs)
2253 {
Greg Clayton1d885962011-11-08 02:43:132254 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanan6d6acc82011-11-16 01:54:572255 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Clayton1d885962011-11-08 02:43:132256 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2257 m_skip_prologue = rhs.m_skip_prologue;
2258 m_source_map = rhs.m_source_map;
2259 m_max_children_display = rhs.m_max_children_display;
2260 m_max_strlen_length = rhs.m_max_strlen_length;
2261 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2262 m_run_args = rhs.m_run_args;
2263 m_env_vars = rhs.m_env_vars;
2264 m_input_path = rhs.m_input_path;
2265 m_output_path = rhs.m_output_path;
2266 m_error_path = rhs.m_error_path;
2267 m_disable_aslr = rhs.m_disable_aslr;
2268 m_disable_stdio = rhs.m_disable_stdio;
2269 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Ticedaccaa92010-09-20 20:44:432270 }
2271
2272 return *this;
2273}
2274
Caroline Ticedaccaa92010-09-20 20:44:432275void
2276TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2277 const char *index_value,
2278 const char *value,
2279 const ConstString &instance_name,
2280 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:542281 VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:432282 Error &err,
2283 bool pending)
2284{
Greg Claytonbfe5f3b2011-02-18 01:44:252285 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032286 {
Greg Clayton7e14f912011-04-23 02:04:552287 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2288 if (err.Success())
Sean Callanan322f5292010-10-29 00:29:032289 {
Greg Clayton7e14f912011-04-23 02:04:552290 switch (op)
Sean Callanan322f5292010-10-29 00:29:032291 {
Greg Clayton7e14f912011-04-23 02:04:552292 default:
2293 break;
2294 case eVarSetOperationAssign:
2295 case eVarSetOperationAppend:
Sean Callanan322f5292010-10-29 00:29:032296 {
Greg Clayton7e14f912011-04-23 02:04:552297 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2298 {
2299 err.SetErrorToGenericError ();
Greg Clayton86edbf42011-10-26 00:56:272300 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Clayton7e14f912011-04-23 02:04:552301 return;
2302 }
2303
Sean Callanan6d6acc82011-11-16 01:54:572304 DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
2305
2306 if (!file_contents && file_contents->GetByteSize() == 0)
Greg Clayton7e14f912011-04-23 02:04:552307 {
Greg Clayton86edbf42011-10-26 00:56:272308 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
Sean Callanan6d6acc82011-11-16 01:54:572309 m_expr_prefix_contents.clear();
Greg Clayton7e14f912011-04-23 02:04:552310 }
Sean Callanan6d6acc82011-11-16 01:54:572311
2312 m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
Sean Callanan322f5292010-10-29 00:29:032313 }
Greg Clayton7e14f912011-04-23 02:04:552314 break;
2315 case eVarSetOperationClear:
Sean Callanan6d6acc82011-11-16 01:54:572316 m_expr_prefix_contents.clear();
Sean Callanan322f5292010-10-29 00:29:032317 }
Sean Callanan322f5292010-10-29 00:29:032318 }
2319 }
Jim Ingham78a685a2011-04-16 00:01:132320 else if (var_name == GetSettingNameForPreferDynamicValue())
2321 {
Jim Ingham2837b762011-05-04 03:43:182322 int new_value;
2323 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2324 if (err.Success())
2325 m_prefer_dynamic_value = new_value;
Greg Clayton385aa282011-04-22 03:55:062326 }
2327 else if (var_name == GetSettingNameForSkipPrologue())
2328 {
Greg Clayton7e14f912011-04-23 02:04:552329 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2330 }
Enrico Granata22c55d12011-08-12 02:00:062331 else if (var_name == GetSettingNameForMaxChildren())
2332 {
2333 bool ok;
2334 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2335 if (ok)
2336 m_max_children_display = new_value;
2337 }
Enrico Granata9128ee2f2011-09-06 19:20:512338 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2339 {
2340 bool ok;
2341 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2342 if (ok)
2343 m_max_strlen_length = new_value;
2344 }
Greg Clayton7e14f912011-04-23 02:04:552345 else if (var_name == GetSettingNameForSourcePathMap ())
2346 {
2347 switch (op)
2348 {
2349 case eVarSetOperationReplace:
2350 case eVarSetOperationInsertBefore:
2351 case eVarSetOperationInsertAfter:
2352 case eVarSetOperationRemove:
2353 default:
2354 break;
2355 case eVarSetOperationAssign:
2356 m_source_map.Clear(true);
2357 // Fall through to append....
2358 case eVarSetOperationAppend:
2359 {
2360 Args args(value);
2361 const uint32_t argc = args.GetArgumentCount();
2362 if (argc & 1 || argc == 0)
2363 {
2364 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2365 }
2366 else
2367 {
2368 char resolved_new_path[PATH_MAX];
2369 FileSpec file_spec;
2370 const char *old_path;
2371 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2372 {
2373 const char *new_path = args.GetArgumentAtIndex(idx+1);
2374 assert (new_path); // We have an even number of paths, this shouldn't happen!
2375
2376 file_spec.SetFile(new_path, true);
2377 if (file_spec.Exists())
2378 {
2379 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2380 {
2381 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2382 return;
2383 }
2384 }
2385 else
2386 {
2387 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2388 return;
2389 }
2390 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2391 }
2392 }
2393 }
2394 break;
2395
2396 case eVarSetOperationClear:
2397 m_source_map.Clear(true);
2398 break;
2399 }
Jim Ingham78a685a2011-04-16 00:01:132400 }
Jim Inghamc6674fd2011-10-28 23:14:112401 else if (var_name == GetSettingNameForPlatformAvoid ())
2402 {
2403 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2404 }
Greg Clayton1d885962011-11-08 02:43:132405 else if (var_name == GetSettingNameForRunArgs())
2406 {
2407 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2408 }
2409 else if (var_name == GetSettingNameForEnvVars())
2410 {
2411 // This is nice for local debugging, but it is isn't correct for
2412 // remote debugging. We need to stop process.env-vars from being
2413 // populated with the host environment and add this as a launch option
2414 // and get the correct environment from the Target's platform.
2415 // GetHostEnvironmentIfNeeded ();
2416 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2417 }
2418 else if (var_name == GetSettingNameForInputPath())
2419 {
2420 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2421 }
2422 else if (var_name == GetSettingNameForOutputPath())
2423 {
2424 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2425 }
2426 else if (var_name == GetSettingNameForErrorPath())
2427 {
2428 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2429 }
2430 else if (var_name == GetSettingNameForDisableASLR())
2431 {
2432 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2433 }
2434 else if (var_name == GetSettingNameForDisableSTDIO ())
2435 {
2436 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2437 }
Caroline Ticedaccaa92010-09-20 20:44:432438}
2439
2440void
Greg Claytonbfe5f3b2011-02-18 01:44:252441TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Ticedaccaa92010-09-20 20:44:432442{
Sean Callanan322f5292010-10-29 00:29:032443 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2444
2445 if (!new_settings_ptr)
2446 return;
2447
Greg Clayton1d885962011-11-08 02:43:132448 *this = *new_settings_ptr;
Caroline Ticedaccaa92010-09-20 20:44:432449}
2450
Caroline Tice12cecd72010-09-20 21:37:422451bool
Caroline Ticedaccaa92010-09-20 20:44:432452TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2453 const ConstString &var_name,
2454 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:422455 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:432456{
Greg Claytonbfe5f3b2011-02-18 01:44:252457 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032458 {
Greg Clayton7e14f912011-04-23 02:04:552459 char path[PATH_MAX];
2460 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2461 if (path_len > 0)
2462 value.AppendString (path, path_len);
Sean Callanan322f5292010-10-29 00:29:032463 }
Jim Ingham78a685a2011-04-16 00:01:132464 else if (var_name == GetSettingNameForPreferDynamicValue())
2465 {
Jim Ingham2837b762011-05-04 03:43:182466 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Ingham78a685a2011-04-16 00:01:132467 }
Greg Clayton385aa282011-04-22 03:55:062468 else if (var_name == GetSettingNameForSkipPrologue())
2469 {
2470 if (m_skip_prologue)
2471 value.AppendString ("true");
2472 else
2473 value.AppendString ("false");
2474 }
Greg Clayton7e14f912011-04-23 02:04:552475 else if (var_name == GetSettingNameForSourcePathMap ())
2476 {
2477 }
Enrico Granata22c55d12011-08-12 02:00:062478 else if (var_name == GetSettingNameForMaxChildren())
2479 {
2480 StreamString count_str;
2481 count_str.Printf ("%d", m_max_children_display);
2482 value.AppendString (count_str.GetData());
2483 }
Enrico Granata9128ee2f2011-09-06 19:20:512484 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2485 {
2486 StreamString count_str;
2487 count_str.Printf ("%d", m_max_strlen_length);
2488 value.AppendString (count_str.GetData());
2489 }
Jim Inghamc6674fd2011-10-28 23:14:112490 else if (var_name == GetSettingNameForPlatformAvoid())
2491 {
2492 if (m_breakpoints_use_platform_avoid)
2493 value.AppendString ("true");
2494 else
2495 value.AppendString ("false");
2496 }
Greg Clayton1d885962011-11-08 02:43:132497 else if (var_name == GetSettingNameForRunArgs())
2498 {
2499 if (m_run_args.GetArgumentCount() > 0)
2500 {
2501 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2502 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2503 }
2504 }
2505 else if (var_name == GetSettingNameForEnvVars())
2506 {
2507 GetHostEnvironmentIfNeeded ();
2508
2509 if (m_env_vars.size() > 0)
2510 {
2511 std::map<std::string, std::string>::iterator pos;
2512 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2513 {
2514 StreamString value_str;
2515 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2516 value.AppendString (value_str.GetData());
2517 }
2518 }
2519 }
2520 else if (var_name == GetSettingNameForInputPath())
2521 {
2522 value.AppendString (m_input_path.c_str());
2523 }
2524 else if (var_name == GetSettingNameForOutputPath())
2525 {
2526 value.AppendString (m_output_path.c_str());
2527 }
2528 else if (var_name == GetSettingNameForErrorPath())
2529 {
2530 value.AppendString (m_error_path.c_str());
2531 }
2532 else if (var_name == GetSettingNameForInheritHostEnv())
2533 {
2534 if (m_inherit_host_env)
2535 value.AppendString ("true");
2536 else
2537 value.AppendString ("false");
2538 }
2539 else if (var_name == GetSettingNameForDisableASLR())
2540 {
2541 if (m_disable_aslr)
2542 value.AppendString ("true");
2543 else
2544 value.AppendString ("false");
2545 }
2546 else if (var_name == GetSettingNameForDisableSTDIO())
2547 {
2548 if (m_disable_stdio)
2549 value.AppendString ("true");
2550 else
2551 value.AppendString ("false");
2552 }
Sean Callanan322f5292010-10-29 00:29:032553 else
2554 {
2555 if (err)
2556 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2557 return false;
2558 }
Sean Callanan322f5292010-10-29 00:29:032559 return true;
Caroline Ticedaccaa92010-09-20 20:44:432560}
2561
Greg Clayton1d885962011-11-08 02:43:132562void
2563Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2564{
2565 if (m_inherit_host_env && !m_got_host_env)
2566 {
2567 m_got_host_env = true;
2568 StringList host_env;
2569 const size_t host_env_count = Host::GetEnvironment (host_env);
2570 for (size_t idx=0; idx<host_env_count; idx++)
2571 {
2572 const char *env_entry = host_env.GetStringAtIndex (idx);
2573 if (env_entry)
2574 {
2575 const char *equal_pos = ::strchr(env_entry, '=');
2576 if (equal_pos)
2577 {
2578 std::string key (env_entry, equal_pos - env_entry);
2579 std::string value (equal_pos + 1);
2580 if (m_env_vars.find (key) == m_env_vars.end())
2581 m_env_vars[key] = value;
2582 }
2583 }
2584 }
2585 }
2586}
2587
2588
2589size_t
2590Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2591{
2592 GetHostEnvironmentIfNeeded ();
2593
2594 dictionary::const_iterator pos, end = m_env_vars.end();
2595 for (pos = m_env_vars.begin(); pos != end; ++pos)
2596 {
2597 std::string env_var_equal_value (pos->first);
2598 env_var_equal_value.append(1, '=');
2599 env_var_equal_value.append (pos->second);
2600 env.AppendArgument (env_var_equal_value.c_str());
2601 }
2602 return env.GetArgumentCount();
2603}
2604
2605
Caroline Ticedaccaa92010-09-20 20:44:432606const ConstString
2607TargetInstanceSettings::CreateInstanceName ()
2608{
Caroline Ticedaccaa92010-09-20 20:44:432609 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:102610 static int instance_count = 1;
2611
Caroline Ticedaccaa92010-09-20 20:44:432612 sstr.Printf ("target_%d", instance_count);
2613 ++instance_count;
2614
2615 const ConstString ret_val (sstr.GetData());
2616 return ret_val;
2617}
2618
2619//--------------------------------------------------
2620// Target::SettingsController Variable Tables
2621//--------------------------------------------------
Jim Ingham2837b762011-05-04 03:43:182622OptionEnumValueElement
2623TargetInstanceSettings::g_dynamic_value_types[] =
2624{
Greg Clayton5d2fbfe2011-05-30 00:39:482625{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2626{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2627{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham2837b762011-05-04 03:43:182628{ 0, NULL, NULL }
2629};
Caroline Ticedaccaa92010-09-20 20:44:432630
2631SettingEntry
2632Target::SettingsController::global_settings_table[] =
2633{
Greg Claytonbfe5f3b2011-02-18 01:44:252634 // var-name var-type default enum init'd hidden help-text
2635 // ================= ================== =========== ==== ====== ====== =========================================================================
2636 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2637 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2638};
2639
Caroline Ticedaccaa92010-09-20 20:44:432640SettingEntry
2641Target::SettingsController::instance_settings_table[] =
2642{
Enrico Granata9128ee2f2011-09-06 19:20:512643 // var-name var-type default enum init'd hidden help-text
2644 // ================= ================== =============== ======================= ====== ====== =========================================================================
2645 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2646 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2647 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2648 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
2649 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2650 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
Jim Inghamc6674fd2011-10-28 23:14:112651 { TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Clayton1d885962011-11-08 02:43:132652 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2653 { 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." },
2654 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2655 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2656 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2657 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2658// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2659 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2660 { TSC_DISABLE_STDIO , eSetVarTypeBoolean, "false" , NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Enrico Granata9128ee2f2011-09-06 19:20:512661 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Ticedaccaa92010-09-20 20:44:432662};