blob: 96dd11d034724b208249c7a5e1ed4b2d66690128 [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"
19#include "lldb/Breakpoint/BreakpointResolverName.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5920#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2421#include "lldb/Core/Event.h"
22#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:2423#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5924#include "lldb/Core/Timer.h"
25#include "lldb/Core/ValueObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2426#include "lldb/Host/Host.h"
27#include "lldb/lldb-private-log.h"
28#include "lldb/Symbol/ObjectFile.h"
29#include "lldb/Target/Process.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5930#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:2431
32using namespace lldb;
33using namespace lldb_private;
34
35//----------------------------------------------------------------------
36// Target constructor
37//----------------------------------------------------------------------
Greg Clayton66111032010-06-23 01:19:2938Target::Target(Debugger &debugger) :
Greg Claytoncfd1ace2010-10-31 03:01:0639 Broadcaster("lldb.target"),
Greg Claytondbe54502010-11-19 03:46:0140 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2941 m_debugger (debugger),
Greg Claytonaf67cec2010-12-20 20:49:2342 m_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner30fdc8d2010-06-08 16:52:2443 m_images(),
Greg Claytonf5e56de2010-09-14 23:36:4044 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2445 m_breakpoint_list (false),
46 m_internal_breakpoint_list (true),
47 m_process_sp(),
48 m_triple(),
49 m_search_filter_sp(),
50 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton8b2fe6d2010-12-14 02:59:5951 m_scratch_ast_context_ap (NULL),
52 m_persistent_variables ()
Chris Lattner30fdc8d2010-06-08 16:52:2453{
Greg Claytoncfd1ace2010-10-31 03:01:0654 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
55 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
56 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
57
Greg Clayton2d4edfb2010-11-06 01:53:3058 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2459 if (log)
60 log->Printf ("%p Target::Target()", this);
61}
62
63//----------------------------------------------------------------------
64// Destructor
65//----------------------------------------------------------------------
66Target::~Target()
67{
Greg Clayton2d4edfb2010-11-06 01:53:3068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2469 if (log)
70 log->Printf ("%p Target::~Target()", this);
71 DeleteCurrentProcess ();
72}
73
74void
Caroline Ticeceb6b132010-10-26 03:11:1375Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2476{
Greg Clayton89411422010-10-08 00:21:0577// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1378 if (description_level != lldb::eDescriptionLevelBrief)
79 {
80 s->Indent();
81 s->PutCString("Target\n");
82 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:3583 m_images.Dump(s);
84 m_breakpoint_list.Dump(s);
85 m_internal_breakpoint_list.Dump(s);
86 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:1387 }
88 else
89 {
Greg Clayton48381312010-10-30 04:51:4690 s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
Caroline Ticeceb6b132010-10-26 03:11:1391 }
Chris Lattner30fdc8d2010-06-08 16:52:2492}
93
94void
95Target::DeleteCurrentProcess ()
96{
97 if (m_process_sp.get())
98 {
Greg Clayton17f69202010-09-14 23:52:4399 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24100 if (m_process_sp->IsAlive())
101 m_process_sp->Destroy();
102 else
103 m_process_sp->Finalize();
104
105 // Do any cleanup of the target we need to do between process instances.
106 // NB It is better to do this before destroying the process in case the
107 // clean up needs some help from the process.
108 m_breakpoint_list.ClearAllBreakpointSites();
109 m_internal_breakpoint_list.ClearAllBreakpointSites();
110 m_process_sp.reset();
111 }
112}
113
114const lldb::ProcessSP &
115Target::CreateProcess (Listener &listener, const char *plugin_name)
116{
117 DeleteCurrentProcess ();
118 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
119 return m_process_sp;
120}
121
122const lldb::ProcessSP &
123Target::GetProcessSP () const
124{
125 return m_process_sp;
126}
127
128lldb::TargetSP
129Target::GetSP()
130{
Greg Clayton66111032010-06-23 01:19:29131 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24132}
133
134BreakpointList &
135Target::GetBreakpointList(bool internal)
136{
137 if (internal)
138 return m_internal_breakpoint_list;
139 else
140 return m_breakpoint_list;
141}
142
143const BreakpointList &
144Target::GetBreakpointList(bool internal) const
145{
146 if (internal)
147 return m_internal_breakpoint_list;
148 else
149 return m_breakpoint_list;
150}
151
152BreakpointSP
153Target::GetBreakpointByID (break_id_t break_id)
154{
155 BreakpointSP bp_sp;
156
157 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
158 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
159 else
160 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
161
162 return bp_sp;
163}
164
165BreakpointSP
166Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
167{
168 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
169 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
170 return CreateBreakpoint (filter_sp, resolver_sp, internal);
171}
172
173
174BreakpointSP
Greg Clayton1b72fcb2010-08-24 00:45:41175Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24176{
Chris Lattner30fdc8d2010-06-08 16:52:24177 Address so_addr;
178 // Attempt to resolve our load address if possible, though it is ok if
179 // it doesn't resolve to section/offset.
180
Greg Clayton1b72fcb2010-08-24 00:45:41181 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40182 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41183 if (!so_addr.IsValid())
184 {
185 // The address didn't resolve, so just set this as an absolute address
186 so_addr.SetOffset (addr);
187 }
188 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner30fdc8d2010-06-08 16:52:24189 return bp_sp;
190}
191
192BreakpointSP
193Target::CreateBreakpoint (Address &addr, bool internal)
194{
195 TargetSP target_sp = this->GetSP();
196 SearchFilterSP filter_sp(new SearchFilter (target_sp));
197 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
198 return CreateBreakpoint (filter_sp, resolver_sp, internal);
199}
200
201BreakpointSP
Greg Clayton0c5cd902010-06-28 21:30:43202Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24203{
Greg Clayton0c5cd902010-06-28 21:30:43204 BreakpointSP bp_sp;
205 if (func_name)
206 {
207 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
208 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
209 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
210 }
211 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24212}
213
214
215SearchFilterSP
216Target::GetSearchFilterForModule (const FileSpec *containingModule)
217{
218 SearchFilterSP filter_sp;
219 lldb::TargetSP target_sp = this->GetSP();
220 if (containingModule != NULL)
221 {
222 // TODO: We should look into sharing module based search filters
223 // across many breakpoints like we do for the simple target based one
224 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
225 }
226 else
227 {
228 if (m_search_filter_sp.get() == NULL)
229 m_search_filter_sp.reset (new SearchFilter (target_sp));
230 filter_sp = m_search_filter_sp;
231 }
232 return filter_sp;
233}
234
235BreakpointSP
236Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal)
237{
238 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
239 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
240
241 return CreateBreakpoint (filter_sp, resolver_sp, internal);
242}
243
244BreakpointSP
245Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
246{
247 BreakpointSP bp_sp;
248 if (filter_sp && resolver_sp)
249 {
250 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
251 resolver_sp->SetBreakpoint (bp_sp.get());
252
253 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17254 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24255 else
Greg Clayton9fed0d82010-07-23 23:33:17256 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24257
Greg Clayton2d4edfb2010-11-06 01:53:30258 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24259 if (log)
260 {
261 StreamString s;
262 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
263 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
264 }
265
Chris Lattner30fdc8d2010-06-08 16:52:24266 bp_sp->ResolveBreakpoint();
267 }
Jim Ingham36f3b362010-10-14 23:45:03268
269 if (!internal && bp_sp)
270 {
271 m_last_created_breakpoint = bp_sp;
272 }
273
Chris Lattner30fdc8d2010-06-08 16:52:24274 return bp_sp;
275}
276
277void
278Target::RemoveAllBreakpoints (bool internal_also)
279{
Greg Clayton2d4edfb2010-11-06 01:53:30280 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24281 if (log)
282 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
283
Greg Clayton9fed0d82010-07-23 23:33:17284 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24285 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17286 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03287
288 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24289}
290
291void
292Target::DisableAllBreakpoints (bool internal_also)
293{
Greg Clayton2d4edfb2010-11-06 01:53:30294 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24295 if (log)
296 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
297
298 m_breakpoint_list.SetEnabledAll (false);
299 if (internal_also)
300 m_internal_breakpoint_list.SetEnabledAll (false);
301}
302
303void
304Target::EnableAllBreakpoints (bool internal_also)
305{
Greg Clayton2d4edfb2010-11-06 01:53:30306 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24307 if (log)
308 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
309
310 m_breakpoint_list.SetEnabledAll (true);
311 if (internal_also)
312 m_internal_breakpoint_list.SetEnabledAll (true);
313}
314
315bool
316Target::RemoveBreakpointByID (break_id_t break_id)
317{
Greg Clayton2d4edfb2010-11-06 01:53:30318 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24319 if (log)
320 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
321
322 if (DisableBreakpointByID (break_id))
323 {
324 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17325 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24326 else
Jim Ingham36f3b362010-10-14 23:45:03327 {
Greg Claytonaa1c5872011-01-24 23:35:47328 if (m_last_created_breakpoint)
329 {
330 if (m_last_created_breakpoint->GetID() == break_id)
331 m_last_created_breakpoint.reset();
332 }
Greg Clayton9fed0d82010-07-23 23:33:17333 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03334 }
Chris Lattner30fdc8d2010-06-08 16:52:24335 return true;
336 }
337 return false;
338}
339
340bool
341Target::DisableBreakpointByID (break_id_t break_id)
342{
Greg Clayton2d4edfb2010-11-06 01:53:30343 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24344 if (log)
345 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
346
347 BreakpointSP bp_sp;
348
349 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
350 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
351 else
352 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
353 if (bp_sp)
354 {
355 bp_sp->SetEnabled (false);
356 return true;
357 }
358 return false;
359}
360
361bool
362Target::EnableBreakpointByID (break_id_t break_id)
363{
Greg Clayton2d4edfb2010-11-06 01:53:30364 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24365 if (log)
366 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
367 __FUNCTION__,
368 break_id,
369 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
370
371 BreakpointSP bp_sp;
372
373 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
374 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
375 else
376 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
377
378 if (bp_sp)
379 {
380 bp_sp->SetEnabled (true);
381 return true;
382 }
383 return false;
384}
385
386ModuleSP
387Target::GetExecutableModule ()
388{
389 ModuleSP executable_sp;
390 if (m_images.GetSize() > 0)
391 executable_sp = m_images.GetModuleAtIndex(0);
392 return executable_sp;
393}
394
395void
396Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
397{
398 m_images.Clear();
399 m_scratch_ast_context_ap.reset();
400
401 if (executable_sp.get())
402 {
403 Timer scoped_timer (__PRETTY_FUNCTION__,
404 "Target::SetExecutableModule (executable = '%s/%s')",
405 executable_sp->GetFileSpec().GetDirectory().AsCString(),
406 executable_sp->GetFileSpec().GetFilename().AsCString());
407
408 m_images.Append(executable_sp); // The first image is our exectuable file
409
410 ArchSpec exe_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02411 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
412 if (!m_arch_spec.IsValid())
413 m_arch_spec = exe_arch;
414
Chris Lattner30fdc8d2010-06-08 16:52:24415 FileSpecList dependent_files;
416 ObjectFile * executable_objfile = executable_sp->GetObjectFile();
417 if (executable_objfile == NULL)
418 {
419
420 FileSpec bundle_executable(executable_sp->GetFileSpec());
Greg Claytondd36def2010-10-17 22:03:32421 if (Host::ResolveExecutableInBundle (bundle_executable))
Chris Lattner30fdc8d2010-06-08 16:52:24422 {
423 ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable,
424 exe_arch));
425 SetExecutableModule (bundle_exe_module_sp, get_dependent_files);
426 if (bundle_exe_module_sp->GetObjectFile() != NULL)
427 executable_sp = bundle_exe_module_sp;
428 return;
429 }
430 }
431
432 if (executable_objfile)
433 {
434 executable_objfile->GetDependentModules(dependent_files);
435 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
436 {
437 ModuleSP image_module_sp(GetSharedModule(dependent_files.GetFileSpecPointerAtIndex(i),
438 exe_arch));
439 if (image_module_sp.get())
440 {
441 //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY
442 ObjectFile *objfile = image_module_sp->GetObjectFile();
443 if (objfile)
444 objfile->GetDependentModules(dependent_files);
445 }
446 }
447 }
448
449 // Now see if we know the target triple, and if so, create our scratch AST context:
450 ConstString target_triple;
451 if (GetTargetTriple(target_triple))
452 {
453 m_scratch_ast_context_ap.reset (new ClangASTContext(target_triple.GetCString()));
454 }
455 }
Caroline Tice1559a462010-09-27 00:30:10456
457 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24458}
459
460
461ModuleList&
462Target::GetImages ()
463{
464 return m_images;
465}
466
467ArchSpec
468Target::GetArchitecture () const
469{
Jim Ingham5aee1622010-08-09 23:31:02470 return m_arch_spec;
Chris Lattner30fdc8d2010-06-08 16:52:24471}
472
Jim Ingham5aee1622010-08-09 23:31:02473bool
474Target::SetArchitecture (const ArchSpec &arch_spec)
475{
476 if (m_arch_spec == arch_spec)
477 {
478 // If we're setting the architecture to our current architecture, we
479 // don't need to do anything.
480 return true;
481 }
482 else if (!m_arch_spec.IsValid())
483 {
484 // If we haven't got a valid arch spec, then we just need to set it.
485 m_arch_spec = arch_spec;
486 return true;
487 }
488 else
489 {
490 // If we have an executable file, try to reset the executable to the desired architecture
491 m_arch_spec = arch_spec;
492 ModuleSP executable_sp = GetExecutableModule ();
493 m_images.Clear();
494 m_scratch_ast_context_ap.reset();
495 m_triple.Clear();
496 // Need to do something about unsetting breakpoints.
497
498 if (executable_sp)
499 {
500 FileSpec exec_file_spec = executable_sp->GetFileSpec();
501 Error error = ModuleList::GetSharedModule(exec_file_spec,
502 arch_spec,
503 NULL,
504 NULL,
505 0,
506 executable_sp,
507 NULL,
508 NULL);
509
510 if (!error.Fail() && executable_sp)
511 {
512 SetExecutableModule (executable_sp, true);
513 return true;
514 }
515 else
516 {
517 return false;
518 }
519 }
520 else
521 {
522 return false;
523 }
524 }
525}
Chris Lattner30fdc8d2010-06-08 16:52:24526
527bool
528Target::GetTargetTriple(ConstString &triple)
529{
530 triple.Clear();
531
532 if (m_triple)
533 {
534 triple = m_triple;
535 }
536 else
537 {
538 Module *exe_module = GetExecutableModule().get();
539 if (exe_module)
540 {
541 ObjectFile *objfile = exe_module->GetObjectFile();
542 if (objfile)
543 {
544 objfile->GetTargetTriple(m_triple);
545 triple = m_triple;
546 }
547 }
548 }
549 return !triple.IsEmpty();
550}
551
552void
553Target::ModuleAdded (ModuleSP &module_sp)
554{
555 // A module is being added to this target for the first time
556 ModuleList module_list;
557 module_list.Append(module_sp);
558 ModulesDidLoad (module_list);
559}
560
561void
562Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
563{
564 // A module is being added to this target for the first time
565 ModuleList module_list;
566 module_list.Append (old_module_sp);
567 ModulesDidUnload (module_list);
568 module_list.Clear ();
569 module_list.Append (new_module_sp);
570 ModulesDidLoad (module_list);
571}
572
573void
574Target::ModulesDidLoad (ModuleList &module_list)
575{
576 m_breakpoint_list.UpdateBreakpoints (module_list, true);
577 // TODO: make event data that packages up the module_list
578 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
579}
580
581void
582Target::ModulesDidUnload (ModuleList &module_list)
583{
584 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Claytona4d78302010-12-06 23:51:26585
586 // Remove the images from the target image list
587 m_images.Remove(module_list);
588
Chris Lattner30fdc8d2010-06-08 16:52:24589 // TODO: make event data that packages up the module_list
590 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
591}
592
593size_t
Greg Claytondb598232011-01-07 01:57:07594Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
595{
596 const Section *section = addr.GetSection();
597 if (section && section->GetModule())
598 {
599 ObjectFile *objfile = section->GetModule()->GetObjectFile();
600 if (objfile)
601 {
602 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
603 addr.GetOffset(),
604 dst,
605 dst_len);
606 if (bytes_read > 0)
607 return bytes_read;
608 else
609 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
610 }
611 else
612 {
613 error.SetErrorString("address isn't from a object file");
614 }
615 }
616 else
617 {
618 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
619 }
620 return 0;
621}
622
623size_t
624Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size_t dst_len, Error &error)
Chris Lattner30fdc8d2010-06-08 16:52:24625{
Chris Lattner30fdc8d2010-06-08 16:52:24626 error.Clear();
Greg Claytondb598232011-01-07 01:57:07627
Greg Claytondda4f7b2010-06-30 23:03:03628 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
629
Greg Claytondb598232011-01-07 01:57:07630 size_t bytes_read = 0;
Greg Claytondda4f7b2010-06-30 23:03:03631 Address resolved_addr(addr);
632 if (!resolved_addr.IsSectionOffset())
633 {
634 if (process_is_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24635 {
Greg Claytonf5e56de2010-09-14 23:36:40636 m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
Greg Claytondda4f7b2010-06-30 23:03:03637 }
638 else
639 {
640 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
641 }
642 }
643
Greg Claytondb598232011-01-07 01:57:07644 if (prefer_file_cache)
645 {
646 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
647 if (bytes_read > 0)
648 return bytes_read;
649 }
Greg Claytondda4f7b2010-06-30 23:03:03650
651 if (process_is_valid)
652 {
Greg Claytonf5e56de2010-09-14 23:36:40653 lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this);
Greg Claytondda4f7b2010-06-30 23:03:03654 if (load_addr == LLDB_INVALID_ADDRESS)
655 {
656 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
657 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
658 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
659 resolved_addr.GetFileAddress());
660 else
661 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
662 }
663 else
664 {
Greg Claytondb598232011-01-07 01:57:07665 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24666 if (bytes_read != dst_len)
667 {
668 if (error.Success())
669 {
670 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03671 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24672 else
Greg Claytondda4f7b2010-06-30 23:03:03673 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24674 }
675 }
Greg Claytondda4f7b2010-06-30 23:03:03676 if (bytes_read)
677 return bytes_read;
678 // If the address is not section offset we have an address that
679 // doesn't resolve to any address in any currently loaded shared
680 // libaries and we failed to read memory so there isn't anything
681 // more we can do. If it is section offset, we might be able to
682 // read cached memory from the object file.
683 if (!resolved_addr.IsSectionOffset())
684 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24685 }
Chris Lattner30fdc8d2010-06-08 16:52:24686 }
Greg Claytondda4f7b2010-06-30 23:03:03687
Greg Claytondb598232011-01-07 01:57:07688 if (!prefer_file_cache)
Greg Claytondda4f7b2010-06-30 23:03:03689 {
Greg Claytondb598232011-01-07 01:57:07690 // If we didn't already try and read from the object file cache, then
691 // try it after failing to read from the process.
692 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03693 }
694 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24695}
696
697
698ModuleSP
699Target::GetSharedModule
700(
701 const FileSpec& file_spec,
702 const ArchSpec& arch,
703 const UUID *uuid_ptr,
704 const ConstString *object_name,
705 off_t object_offset,
706 Error *error_ptr
707)
708{
709 // Don't pass in the UUID so we can tell if we have a stale value in our list
710 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
711 bool did_create_module = false;
712 ModuleSP module_sp;
713
714 // If there are image search path entries, try to use them first to acquire a suitable image.
715
716 Error error;
717
718 if (m_image_search_paths.GetSize())
719 {
720 FileSpec transformed_spec;
721 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
722 {
723 transformed_spec.GetFilename() = file_spec.GetFilename();
724 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
725 }
726 }
727
728 // If a module hasn't been found yet, use the unmodified path.
729
730 if (!module_sp)
731 {
732 error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module));
733 }
734
735 if (module_sp)
736 {
737 m_images.Append (module_sp);
738 if (did_create_module)
739 {
740 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
741 ModuleUpdated(old_module_sp, module_sp);
742 else
743 ModuleAdded(module_sp);
744 }
745 }
746 if (error_ptr)
747 *error_ptr = error;
748 return module_sp;
749}
750
751
752Target *
753Target::CalculateTarget ()
754{
755 return this;
756}
757
758Process *
759Target::CalculateProcess ()
760{
761 return NULL;
762}
763
764Thread *
765Target::CalculateThread ()
766{
767 return NULL;
768}
769
770StackFrame *
771Target::CalculateStackFrame ()
772{
773 return NULL;
774}
775
776void
Greg Clayton0603aa92010-10-04 01:05:56777Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24778{
779 exe_ctx.target = this;
780 exe_ctx.process = NULL; // Do NOT fill in process...
781 exe_ctx.thread = NULL;
782 exe_ctx.frame = NULL;
783}
784
785PathMappingList &
786Target::GetImageSearchPathList ()
787{
788 return m_image_search_paths;
789}
790
791void
792Target::ImageSearchPathsChanged
793(
794 const PathMappingList &path_list,
795 void *baton
796)
797{
798 Target *target = (Target *)baton;
799 if (target->m_images.GetSize() > 1)
800 {
801 ModuleSP exe_module_sp (target->GetExecutableModule());
802 if (exe_module_sp)
803 {
804 target->m_images.Clear();
805 target->SetExecutableModule (exe_module_sp, true);
806 }
807 }
808}
809
810ClangASTContext *
811Target::GetScratchClangASTContext()
812{
813 return m_scratch_ast_context_ap.get();
814}
Caroline Ticedaccaa92010-09-20 20:44:43815
Greg Clayton99d0faf2010-11-18 23:32:35816void
817Target::Initialize ()
Caroline Ticedaccaa92010-09-20 20:44:43818{
Greg Clayton99d0faf2010-11-18 23:32:35819 UserSettingsControllerSP &usc = GetSettingsController();
820 usc.reset (new SettingsController);
821 UserSettingsController::InitializeSettingsController (usc,
822 SettingsController::global_settings_table,
823 SettingsController::instance_settings_table);
824}
Caroline Ticedaccaa92010-09-20 20:44:43825
Greg Clayton99d0faf2010-11-18 23:32:35826void
827Target::Terminate ()
828{
829 UserSettingsControllerSP &usc = GetSettingsController();
830 UserSettingsController::FinalizeSettingsController (usc);
831 usc.reset();
832}
Caroline Ticedaccaa92010-09-20 20:44:43833
Greg Clayton99d0faf2010-11-18 23:32:35834UserSettingsControllerSP &
835Target::GetSettingsController ()
836{
837 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:43838 return g_settings_controller;
839}
840
841ArchSpec
842Target::GetDefaultArchitecture ()
843{
Greg Claytondbe54502010-11-19 03:46:01844 lldb::UserSettingsControllerSP &settings_controller = GetSettingsController();
Caroline Ticedaccaa92010-09-20 20:44:43845 lldb::SettableVariableType var_type;
846 Error err;
847 StringList result = settings_controller->GetVariable ("target.default-arch", var_type, "[]", err);
848
849 const char *default_name = "";
850 if (result.GetSize() == 1 && err.Success())
851 default_name = result.GetStringAtIndex (0);
852
853 ArchSpec default_arch (default_name);
854 return default_arch;
855}
856
857void
858Target::SetDefaultArchitecture (ArchSpec new_arch)
859{
860 if (new_arch.IsValid())
Greg Claytondbe54502010-11-19 03:46:01861 GetSettingsController ()->SetVariable ("target.default-arch",
862 new_arch.AsCString(),
863 lldb::eVarSetOperationAssign,
864 false,
865 "[]");
Caroline Ticedaccaa92010-09-20 20:44:43866}
867
Greg Clayton0603aa92010-10-04 01:05:56868Target *
869Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
870{
871 // The target can either exist in the "process" of ExecutionContext, or in
872 // the "target_sp" member of SymbolContext. This accessor helper function
873 // will get the target from one of these locations.
874
875 Target *target = NULL;
876 if (sc_ptr != NULL)
877 target = sc_ptr->target_sp.get();
878 if (target == NULL)
879 {
880 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
881 target = &exe_ctx_ptr->process->GetTarget();
882 }
883 return target;
884}
885
886
Caroline Tice1559a462010-09-27 00:30:10887void
888Target::UpdateInstanceName ()
889{
890 StreamString sstr;
891
892 ModuleSP module_sp = GetExecutableModule();
893 if (module_sp)
894 {
Greg Clayton307de252010-10-27 02:06:37895 sstr.Printf ("%s_%s",
896 module_sp->GetFileSpec().GetFilename().AsCString(),
Caroline Tice1559a462010-09-27 00:30:10897 module_sp->GetArchitecture().AsCString());
Greg Claytondbe54502010-11-19 03:46:01898 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
899 sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:10900 }
901}
902
Sean Callanan322f5292010-10-29 00:29:03903const char *
904Target::GetExpressionPrefixContentsAsCString ()
905{
906 return m_expr_prefix_contents.c_str();
907}
908
Greg Clayton8b2fe6d2010-12-14 02:59:59909ExecutionResults
910Target::EvaluateExpression
911(
912 const char *expr_cstr,
913 StackFrame *frame,
914 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:35915 bool keep_in_memory,
Greg Clayton8b2fe6d2010-12-14 02:59:59916 lldb::ValueObjectSP &result_valobj_sp
917)
918{
919 ExecutionResults execution_results = eExecutionSetupError;
920
921 result_valobj_sp.reset();
922
923 ExecutionContext exe_ctx;
924 if (frame)
925 {
926 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:08927 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:18928 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
929 StackFrame::eExpressionPathOptionsNoFragileObjcIvar;
930 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, expr_path_options, error);
Greg Clayton8b2fe6d2010-12-14 02:59:59931 }
932 else if (m_process_sp)
933 {
934 m_process_sp->CalculateExecutionContext(exe_ctx);
935 }
936 else
937 {
938 CalculateExecutionContext(exe_ctx);
939 }
940
941 if (result_valobj_sp)
942 {
943 execution_results = eExecutionCompleted;
944 // We got a result from the frame variable expression path above...
945 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
946
947 lldb::ValueObjectSP const_valobj_sp;
948
949 // Check in case our value is already a constant value
950 if (result_valobj_sp->GetIsConstant())
951 {
952 const_valobj_sp = result_valobj_sp;
953 const_valobj_sp->SetName (persistent_variable_name);
954 }
955 else
956 const_valobj_sp = result_valobj_sp->CreateConstantValue (exe_ctx.GetBestExecutionContextScope(),
957 persistent_variable_name);
958
Sean Callanan92adcac2011-01-13 08:53:35959 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
960
Greg Clayton8b2fe6d2010-12-14 02:59:59961 result_valobj_sp = const_valobj_sp;
962
Sean Callanan92adcac2011-01-13 08:53:35963 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
964 assert (clang_expr_variable_sp.get());
965
966 // Set flags and live data as appropriate
967
968 const Value &result_value = live_valobj_sp->GetValue();
969
970 switch (result_value.GetValueType())
971 {
972 case Value::eValueTypeHostAddress:
973 case Value::eValueTypeFileAddress:
974 // we don't do anything with these for now
975 break;
976 case Value::eValueTypeScalar:
977 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
978 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
979 break;
980 case Value::eValueTypeLoadAddress:
981 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
982 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
983 break;
984 }
Greg Clayton8b2fe6d2010-12-14 02:59:59985 }
986 else
987 {
988 // Make sure we aren't just trying to see the value of a persistent
989 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:35990 lldb::ClangExpressionVariableSP persistent_var_sp;
991 // Only check for persistent variables the expression starts with a '$'
992 if (expr_cstr[0] == '$')
993 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
994
Greg Clayton8b2fe6d2010-12-14 02:59:59995 if (persistent_var_sp)
996 {
997 result_valobj_sp = persistent_var_sp->GetValueObject ();
998 execution_results = eExecutionCompleted;
999 }
1000 else
1001 {
1002 const char *prefix = GetExpressionPrefixContentsAsCString();
1003
1004 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan92adcac2011-01-13 08:53:351005 unwind_on_error,
1006 keep_in_memory,
Greg Clayton8b2fe6d2010-12-14 02:59:591007 expr_cstr,
1008 prefix,
1009 result_valobj_sp);
1010 }
1011 }
1012 return execution_results;
1013}
1014
Caroline Ticedaccaa92010-09-20 20:44:431015//--------------------------------------------------------------
1016// class Target::SettingsController
1017//--------------------------------------------------------------
1018
1019Target::SettingsController::SettingsController () :
1020 UserSettingsController ("target", Debugger::GetSettingsController()),
1021 m_default_architecture ()
1022{
1023 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1024 InstanceSettings::GetDefaultName().AsCString()));
1025}
1026
1027Target::SettingsController::~SettingsController ()
1028{
1029}
1030
1031lldb::InstanceSettingsSP
1032Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1033{
Greg Claytondbe54502010-11-19 03:46:011034 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1035 false,
1036 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:431037 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1038 return new_settings_sp;
1039}
1040
1041const ConstString &
1042Target::SettingsController::DefArchVarName ()
1043{
1044 static ConstString def_arch_var_name ("default-arch");
1045
1046 return def_arch_var_name;
1047}
1048
1049bool
1050Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1051 const char *index_value,
1052 const char *value,
1053 const SettingEntry &entry,
1054 const lldb::VarSetOperationType op,
1055 Error&err)
1056{
1057 if (var_name == DefArchVarName())
1058 {
1059 ArchSpec tmp_spec (value);
1060 if (tmp_spec.IsValid())
1061 m_default_architecture = tmp_spec;
1062 else
1063 err.SetErrorStringWithFormat ("'%s' is not a valid architecture.", value);
1064 }
1065 return true;
1066}
1067
1068
1069bool
1070Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1071 StringList &value,
1072 Error &err)
1073{
1074 if (var_name == DefArchVarName())
1075 {
Greg Clayton307de252010-10-27 02:06:371076 // If the arch is invalid (the default), don't show a string for it
1077 if (m_default_architecture.IsValid())
1078 value.AppendString (m_default_architecture.AsCString());
Caroline Ticedaccaa92010-09-20 20:44:431079 return true;
1080 }
1081 else
1082 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1083
1084 return false;
1085}
1086
1087//--------------------------------------------------------------
1088// class TargetInstanceSettings
1089//--------------------------------------------------------------
1090
Greg Clayton85851dd2010-12-04 00:10:171091TargetInstanceSettings::TargetInstanceSettings
1092(
1093 UserSettingsController &owner,
1094 bool live_instance,
1095 const char *name
1096) :
1097 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
Caroline Ticedaccaa92010-09-20 20:44:431098{
1099 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1100 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1101 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1102 // This is true for CreateInstanceName() too.
1103
1104 if (GetInstanceName () == InstanceSettings::InvalidName())
1105 {
1106 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1107 m_owner.RegisterInstanceSettings (this);
1108 }
1109
1110 if (live_instance)
1111 {
1112 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1113 CopyInstanceSettings (pending_settings,false);
1114 //m_owner.RemovePendingSettings (m_instance_name);
1115 }
1116}
1117
1118TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Claytondbe54502010-11-19 03:46:011119 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString())
Caroline Ticedaccaa92010-09-20 20:44:431120{
1121 if (m_instance_name != InstanceSettings::GetDefaultName())
1122 {
1123 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1124 CopyInstanceSettings (pending_settings,false);
1125 //m_owner.RemovePendingSettings (m_instance_name);
1126 }
1127}
1128
1129TargetInstanceSettings::~TargetInstanceSettings ()
1130{
1131}
1132
1133TargetInstanceSettings&
1134TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1135{
1136 if (this != &rhs)
1137 {
1138 }
1139
1140 return *this;
1141}
1142
Sean Callanan322f5292010-10-29 00:29:031143#define EXPR_PREFIX_STRING "expr-prefix"
Caroline Ticedaccaa92010-09-20 20:44:431144
1145void
1146TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1147 const char *index_value,
1148 const char *value,
1149 const ConstString &instance_name,
1150 const SettingEntry &entry,
1151 lldb::VarSetOperationType op,
1152 Error &err,
1153 bool pending)
1154{
Sean Callanan322f5292010-10-29 00:29:031155 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1156
1157 if (var_name == expr_prefix_str)
1158 {
1159 switch (op)
1160 {
1161 default:
1162 err.SetErrorToGenericError ();
1163 err.SetErrorString ("Unrecognized operation. Cannot update value.\n");
1164 return;
1165 case lldb::eVarSetOperationAssign:
1166 {
1167 FileSpec file_spec(value, true);
1168
1169 if (!file_spec.Exists())
1170 {
1171 err.SetErrorToGenericError ();
1172 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1173 return;
1174 }
1175
Greg Claytonc3f381b2011-02-03 17:47:471176 DataBufferSP data_sp (file_spec.ReadFileContents());
Sean Callanan322f5292010-10-29 00:29:031177
Greg Claytonc3f381b2011-02-03 17:47:471178 if (!data_sp && data_sp->GetByteSize() == 0)
Sean Callanan322f5292010-10-29 00:29:031179 {
1180 err.SetErrorToGenericError ();
Greg Claytonc3f381b2011-02-03 17:47:471181 err.SetErrorStringWithFormat ("Couldn't read from %s\n", value);
Sean Callanan322f5292010-10-29 00:29:031182 return;
1183 }
1184
1185 m_expr_prefix_path = value;
Greg Claytonc3f381b2011-02-03 17:47:471186 m_expr_prefix_contents.assign(reinterpret_cast<const char *>(data_sp->GetBytes()), data_sp->GetByteSize());
Sean Callanan322f5292010-10-29 00:29:031187 }
1188 return;
1189 case lldb::eVarSetOperationAppend:
1190 err.SetErrorToGenericError ();
1191 err.SetErrorString ("Cannot append to a path.\n");
1192 return;
1193 case lldb::eVarSetOperationClear:
1194 m_expr_prefix_path.clear ();
1195 m_expr_prefix_contents.clear ();
1196 return;
1197 }
1198 }
Caroline Ticedaccaa92010-09-20 20:44:431199}
1200
1201void
1202TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
Sean Callanan322f5292010-10-29 00:29:031203 bool pending)
Caroline Ticedaccaa92010-09-20 20:44:431204{
Sean Callanan322f5292010-10-29 00:29:031205 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1206
1207 if (!new_settings_ptr)
1208 return;
1209
1210 m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path;
1211 m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents;
Caroline Ticedaccaa92010-09-20 20:44:431212}
1213
Caroline Tice12cecd72010-09-20 21:37:421214bool
Caroline Ticedaccaa92010-09-20 20:44:431215TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1216 const ConstString &var_name,
1217 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:421218 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:431219{
Sean Callanan322f5292010-10-29 00:29:031220 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1221
1222 if (var_name == expr_prefix_str)
1223 {
1224 value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size());
1225 }
1226 else
1227 {
1228 if (err)
1229 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1230 return false;
1231 }
1232
1233 return true;
Caroline Ticedaccaa92010-09-20 20:44:431234}
1235
1236const ConstString
1237TargetInstanceSettings::CreateInstanceName ()
1238{
Caroline Ticedaccaa92010-09-20 20:44:431239 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:101240 static int instance_count = 1;
1241
Caroline Ticedaccaa92010-09-20 20:44:431242 sstr.Printf ("target_%d", instance_count);
1243 ++instance_count;
1244
1245 const ConstString ret_val (sstr.GetData());
1246 return ret_val;
1247}
1248
1249//--------------------------------------------------
1250// Target::SettingsController Variable Tables
1251//--------------------------------------------------
1252
1253SettingEntry
1254Target::SettingsController::global_settings_table[] =
1255{
Sean Callanan322f5292010-10-29 00:29:031256 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1257 { "default-arch", eSetVarTypeString, NULL, NULL, false, false, "Default architecture to choose, when there's a choice." },
Caroline Ticedaccaa92010-09-20 20:44:431258 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1259};
1260
1261SettingEntry
1262Target::SettingsController::instance_settings_table[] =
1263{
Sean Callanan322f5292010-10-29 00:29:031264 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1265 { EXPR_PREFIX_STRING, eSetVarTypeString, NULL, NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
Caroline Ticedaccaa92010-09-20 20:44:431266 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1267};