blob: c8ed3c568c40c78c5f789dc686a381d0cf10d120 [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"
20#include "lldb/Core/Event.h"
21#include "lldb/Core/Log.h"
22#include "lldb/Core/Timer.h"
23#include "lldb/Core/StreamString.h"
24#include "lldb/Host/Host.h"
25#include "lldb/lldb-private-log.h"
26#include "lldb/Symbol/ObjectFile.h"
27#include "lldb/Target/Process.h"
28#include "lldb/Core/Debugger.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33//----------------------------------------------------------------------
34// Target constructor
35//----------------------------------------------------------------------
Greg Clayton66111032010-06-23 01:19:2936Target::Target(Debugger &debugger) :
Chris Lattner30fdc8d2010-06-08 16:52:2437 Broadcaster("Target"),
Greg Clayton66111032010-06-23 01:19:2938 m_debugger (debugger),
Chris Lattner30fdc8d2010-06-08 16:52:2439 m_images(),
40 m_breakpoint_list (false),
41 m_internal_breakpoint_list (true),
42 m_process_sp(),
43 m_triple(),
44 m_search_filter_sp(),
45 m_image_search_paths (ImageSearchPathsChanged, this),
46 m_scratch_ast_context_ap(NULL)
47{
48 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT);
49 if (log)
50 log->Printf ("%p Target::Target()", this);
51}
52
53//----------------------------------------------------------------------
54// Destructor
55//----------------------------------------------------------------------
56Target::~Target()
57{
58 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT);
59 if (log)
60 log->Printf ("%p Target::~Target()", this);
61 DeleteCurrentProcess ();
62}
63
64void
65Target::Dump (Stream *s)
66{
67 s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
68 s->Indent();
69 s->PutCString("Target\n");
70 s->IndentMore();
71 m_images.Dump(s);
72 m_breakpoint_list.Dump(s);
73 m_internal_breakpoint_list.Dump(s);
74// if (m_process_sp.get())
75// m_process_sp->Dump(s);
76 s->IndentLess();
77}
78
79void
80Target::DeleteCurrentProcess ()
81{
82 if (m_process_sp.get())
83 {
84 if (m_process_sp->IsAlive())
85 m_process_sp->Destroy();
86 else
87 m_process_sp->Finalize();
88
89 // Do any cleanup of the target we need to do between process instances.
90 // NB It is better to do this before destroying the process in case the
91 // clean up needs some help from the process.
92 m_breakpoint_list.ClearAllBreakpointSites();
93 m_internal_breakpoint_list.ClearAllBreakpointSites();
94 m_process_sp.reset();
95 }
96}
97
98const lldb::ProcessSP &
99Target::CreateProcess (Listener &listener, const char *plugin_name)
100{
101 DeleteCurrentProcess ();
102 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
103 return m_process_sp;
104}
105
106const lldb::ProcessSP &
107Target::GetProcessSP () const
108{
109 return m_process_sp;
110}
111
112lldb::TargetSP
113Target::GetSP()
114{
Greg Clayton66111032010-06-23 01:19:29115 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24116}
117
118BreakpointList &
119Target::GetBreakpointList(bool internal)
120{
121 if (internal)
122 return m_internal_breakpoint_list;
123 else
124 return m_breakpoint_list;
125}
126
127const BreakpointList &
128Target::GetBreakpointList(bool internal) const
129{
130 if (internal)
131 return m_internal_breakpoint_list;
132 else
133 return m_breakpoint_list;
134}
135
136BreakpointSP
137Target::GetBreakpointByID (break_id_t break_id)
138{
139 BreakpointSP bp_sp;
140
141 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
142 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
143 else
144 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
145
146 return bp_sp;
147}
148
149BreakpointSP
150Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
151{
152 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
153 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
154 return CreateBreakpoint (filter_sp, resolver_sp, internal);
155}
156
157
158BreakpointSP
159Target::CreateBreakpoint (lldb::addr_t load_addr, bool internal)
160{
161 BreakpointSP bp_sp;
162 Address so_addr;
163 // Attempt to resolve our load address if possible, though it is ok if
164 // it doesn't resolve to section/offset.
165
166 Process *process = GetProcessSP().get();
167 if (process && process->ResolveLoadAddress(load_addr, so_addr))
168 bp_sp = CreateBreakpoint(so_addr, internal);
169 return bp_sp;
170}
171
172BreakpointSP
173Target::CreateBreakpoint (Address &addr, bool internal)
174{
175 TargetSP target_sp = this->GetSP();
176 SearchFilterSP filter_sp(new SearchFilter (target_sp));
177 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
178 return CreateBreakpoint (filter_sp, resolver_sp, internal);
179}
180
181BreakpointSP
Greg Clayton0c5cd902010-06-28 21:30:43182Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24183{
Greg Clayton0c5cd902010-06-28 21:30:43184 BreakpointSP bp_sp;
185 if (func_name)
186 {
187 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
188 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
189 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
190 }
191 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24192}
193
194
195SearchFilterSP
196Target::GetSearchFilterForModule (const FileSpec *containingModule)
197{
198 SearchFilterSP filter_sp;
199 lldb::TargetSP target_sp = this->GetSP();
200 if (containingModule != NULL)
201 {
202 // TODO: We should look into sharing module based search filters
203 // across many breakpoints like we do for the simple target based one
204 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
205 }
206 else
207 {
208 if (m_search_filter_sp.get() == NULL)
209 m_search_filter_sp.reset (new SearchFilter (target_sp));
210 filter_sp = m_search_filter_sp;
211 }
212 return filter_sp;
213}
214
215BreakpointSP
216Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal)
217{
218 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
219 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
220
221 return CreateBreakpoint (filter_sp, resolver_sp, internal);
222}
223
224BreakpointSP
225Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
226{
227 BreakpointSP bp_sp;
228 if (filter_sp && resolver_sp)
229 {
230 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
231 resolver_sp->SetBreakpoint (bp_sp.get());
232
233 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17234 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24235 else
Greg Clayton9fed0d82010-07-23 23:33:17236 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24237
238 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
239 if (log)
240 {
241 StreamString s;
242 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
243 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
244 }
245
Chris Lattner30fdc8d2010-06-08 16:52:24246 bp_sp->ResolveBreakpoint();
247 }
248 return bp_sp;
249}
250
251void
252Target::RemoveAllBreakpoints (bool internal_also)
253{
254 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
255 if (log)
256 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
257
Greg Clayton9fed0d82010-07-23 23:33:17258 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24259 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17260 m_internal_breakpoint_list.RemoveAll (false);
Chris Lattner30fdc8d2010-06-08 16:52:24261}
262
263void
264Target::DisableAllBreakpoints (bool internal_also)
265{
266 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
267 if (log)
268 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
269
270 m_breakpoint_list.SetEnabledAll (false);
271 if (internal_also)
272 m_internal_breakpoint_list.SetEnabledAll (false);
273}
274
275void
276Target::EnableAllBreakpoints (bool internal_also)
277{
278 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
279 if (log)
280 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
281
282 m_breakpoint_list.SetEnabledAll (true);
283 if (internal_also)
284 m_internal_breakpoint_list.SetEnabledAll (true);
285}
286
287bool
288Target::RemoveBreakpointByID (break_id_t break_id)
289{
290 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
291 if (log)
292 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
293
294 if (DisableBreakpointByID (break_id))
295 {
296 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17297 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24298 else
Greg Clayton9fed0d82010-07-23 23:33:17299 m_breakpoint_list.Remove(break_id, true);
Chris Lattner30fdc8d2010-06-08 16:52:24300 return true;
301 }
302 return false;
303}
304
305bool
306Target::DisableBreakpointByID (break_id_t break_id)
307{
308 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
309 if (log)
310 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
311
312 BreakpointSP bp_sp;
313
314 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
315 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
316 else
317 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
318 if (bp_sp)
319 {
320 bp_sp->SetEnabled (false);
321 return true;
322 }
323 return false;
324}
325
326bool
327Target::EnableBreakpointByID (break_id_t break_id)
328{
329 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
330 if (log)
331 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
332 __FUNCTION__,
333 break_id,
334 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
335
336 BreakpointSP bp_sp;
337
338 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
339 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
340 else
341 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
342
343 if (bp_sp)
344 {
345 bp_sp->SetEnabled (true);
346 return true;
347 }
348 return false;
349}
350
351ModuleSP
352Target::GetExecutableModule ()
353{
354 ModuleSP executable_sp;
355 if (m_images.GetSize() > 0)
356 executable_sp = m_images.GetModuleAtIndex(0);
357 return executable_sp;
358}
359
360void
361Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
362{
363 m_images.Clear();
364 m_scratch_ast_context_ap.reset();
365
366 if (executable_sp.get())
367 {
368 Timer scoped_timer (__PRETTY_FUNCTION__,
369 "Target::SetExecutableModule (executable = '%s/%s')",
370 executable_sp->GetFileSpec().GetDirectory().AsCString(),
371 executable_sp->GetFileSpec().GetFilename().AsCString());
372
373 m_images.Append(executable_sp); // The first image is our exectuable file
374
375 ArchSpec exe_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02376 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
377 if (!m_arch_spec.IsValid())
378 m_arch_spec = exe_arch;
379
Chris Lattner30fdc8d2010-06-08 16:52:24380 FileSpecList dependent_files;
381 ObjectFile * executable_objfile = executable_sp->GetObjectFile();
382 if (executable_objfile == NULL)
383 {
384
385 FileSpec bundle_executable(executable_sp->GetFileSpec());
386 if (Host::ResolveExecutableInBundle (&bundle_executable))
387 {
388 ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable,
389 exe_arch));
390 SetExecutableModule (bundle_exe_module_sp, get_dependent_files);
391 if (bundle_exe_module_sp->GetObjectFile() != NULL)
392 executable_sp = bundle_exe_module_sp;
393 return;
394 }
395 }
396
397 if (executable_objfile)
398 {
399 executable_objfile->GetDependentModules(dependent_files);
400 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
401 {
402 ModuleSP image_module_sp(GetSharedModule(dependent_files.GetFileSpecPointerAtIndex(i),
403 exe_arch));
404 if (image_module_sp.get())
405 {
406 //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY
407 ObjectFile *objfile = image_module_sp->GetObjectFile();
408 if (objfile)
409 objfile->GetDependentModules(dependent_files);
410 }
411 }
412 }
413
414 // Now see if we know the target triple, and if so, create our scratch AST context:
415 ConstString target_triple;
416 if (GetTargetTriple(target_triple))
417 {
418 m_scratch_ast_context_ap.reset (new ClangASTContext(target_triple.GetCString()));
419 }
420 }
421}
422
423
424ModuleList&
425Target::GetImages ()
426{
427 return m_images;
428}
429
430ArchSpec
431Target::GetArchitecture () const
432{
Jim Ingham5aee1622010-08-09 23:31:02433 return m_arch_spec;
Chris Lattner30fdc8d2010-06-08 16:52:24434}
435
Jim Ingham5aee1622010-08-09 23:31:02436bool
437Target::SetArchitecture (const ArchSpec &arch_spec)
438{
439 if (m_arch_spec == arch_spec)
440 {
441 // If we're setting the architecture to our current architecture, we
442 // don't need to do anything.
443 return true;
444 }
445 else if (!m_arch_spec.IsValid())
446 {
447 // If we haven't got a valid arch spec, then we just need to set it.
448 m_arch_spec = arch_spec;
449 return true;
450 }
451 else
452 {
453 // If we have an executable file, try to reset the executable to the desired architecture
454 m_arch_spec = arch_spec;
455 ModuleSP executable_sp = GetExecutableModule ();
456 m_images.Clear();
457 m_scratch_ast_context_ap.reset();
458 m_triple.Clear();
459 // Need to do something about unsetting breakpoints.
460
461 if (executable_sp)
462 {
463 FileSpec exec_file_spec = executable_sp->GetFileSpec();
464 Error error = ModuleList::GetSharedModule(exec_file_spec,
465 arch_spec,
466 NULL,
467 NULL,
468 0,
469 executable_sp,
470 NULL,
471 NULL);
472
473 if (!error.Fail() && executable_sp)
474 {
475 SetExecutableModule (executable_sp, true);
476 return true;
477 }
478 else
479 {
480 return false;
481 }
482 }
483 else
484 {
485 return false;
486 }
487 }
488}
Chris Lattner30fdc8d2010-06-08 16:52:24489
490bool
491Target::GetTargetTriple(ConstString &triple)
492{
493 triple.Clear();
494
495 if (m_triple)
496 {
497 triple = m_triple;
498 }
499 else
500 {
501 Module *exe_module = GetExecutableModule().get();
502 if (exe_module)
503 {
504 ObjectFile *objfile = exe_module->GetObjectFile();
505 if (objfile)
506 {
507 objfile->GetTargetTriple(m_triple);
508 triple = m_triple;
509 }
510 }
511 }
512 return !triple.IsEmpty();
513}
514
515void
516Target::ModuleAdded (ModuleSP &module_sp)
517{
518 // A module is being added to this target for the first time
519 ModuleList module_list;
520 module_list.Append(module_sp);
521 ModulesDidLoad (module_list);
522}
523
524void
525Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
526{
527 // A module is being added to this target for the first time
528 ModuleList module_list;
529 module_list.Append (old_module_sp);
530 ModulesDidUnload (module_list);
531 module_list.Clear ();
532 module_list.Append (new_module_sp);
533 ModulesDidLoad (module_list);
534}
535
536void
537Target::ModulesDidLoad (ModuleList &module_list)
538{
539 m_breakpoint_list.UpdateBreakpoints (module_list, true);
540 // TODO: make event data that packages up the module_list
541 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
542}
543
544void
545Target::ModulesDidUnload (ModuleList &module_list)
546{
547 m_breakpoint_list.UpdateBreakpoints (module_list, false);
548 // TODO: make event data that packages up the module_list
549 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
550}
551
Chris Lattner30fdc8d2010-06-08 16:52:24552size_t
Greg Clayton35f3dd22010-06-30 23:04:24553Target::ReadMemory (const Address& addr, void *dst, size_t dst_len, Error &error)
Chris Lattner30fdc8d2010-06-08 16:52:24554{
Chris Lattner30fdc8d2010-06-08 16:52:24555 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24556
Greg Claytondda4f7b2010-06-30 23:03:03557 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
558
559 Address resolved_addr(addr);
560 if (!resolved_addr.IsSectionOffset())
561 {
562 if (process_is_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24563 {
Greg Claytondda4f7b2010-06-30 23:03:03564 m_process_sp->ResolveLoadAddress (addr.GetOffset(), resolved_addr);
565 }
566 else
567 {
568 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
569 }
570 }
571
572
573 if (process_is_valid)
574 {
575 lldb::addr_t load_addr = resolved_addr.GetLoadAddress(m_process_sp.get());
576 if (load_addr == LLDB_INVALID_ADDRESS)
577 {
578 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
579 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
580 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
581 resolved_addr.GetFileAddress());
582 else
583 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
584 }
585 else
586 {
587 size_t bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24588 if (bytes_read != dst_len)
589 {
590 if (error.Success())
591 {
592 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03593 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24594 else
Greg Claytondda4f7b2010-06-30 23:03:03595 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:24596 }
597 }
Greg Claytondda4f7b2010-06-30 23:03:03598 if (bytes_read)
599 return bytes_read;
600 // If the address is not section offset we have an address that
601 // doesn't resolve to any address in any currently loaded shared
602 // libaries and we failed to read memory so there isn't anything
603 // more we can do. If it is section offset, we might be able to
604 // read cached memory from the object file.
605 if (!resolved_addr.IsSectionOffset())
606 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24607 }
Chris Lattner30fdc8d2010-06-08 16:52:24608 }
Greg Claytondda4f7b2010-06-30 23:03:03609
610 const Section *section = resolved_addr.GetSection();
611 if (section && section->GetModule())
612 {
613 ObjectFile *objfile = section->GetModule()->GetObjectFile();
614 return section->ReadSectionDataFromObjectFile (objfile,
615 resolved_addr.GetOffset(),
616 dst,
617 dst_len);
618 }
619 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24620}
621
622
623ModuleSP
624Target::GetSharedModule
625(
626 const FileSpec& file_spec,
627 const ArchSpec& arch,
628 const UUID *uuid_ptr,
629 const ConstString *object_name,
630 off_t object_offset,
631 Error *error_ptr
632)
633{
634 // Don't pass in the UUID so we can tell if we have a stale value in our list
635 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
636 bool did_create_module = false;
637 ModuleSP module_sp;
638
639 // If there are image search path entries, try to use them first to acquire a suitable image.
640
641 Error error;
642
643 if (m_image_search_paths.GetSize())
644 {
645 FileSpec transformed_spec;
646 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
647 {
648 transformed_spec.GetFilename() = file_spec.GetFilename();
649 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
650 }
651 }
652
653 // If a module hasn't been found yet, use the unmodified path.
654
655 if (!module_sp)
656 {
657 error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module));
658 }
659
660 if (module_sp)
661 {
662 m_images.Append (module_sp);
663 if (did_create_module)
664 {
665 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
666 ModuleUpdated(old_module_sp, module_sp);
667 else
668 ModuleAdded(module_sp);
669 }
670 }
671 if (error_ptr)
672 *error_ptr = error;
673 return module_sp;
674}
675
676
677Target *
678Target::CalculateTarget ()
679{
680 return this;
681}
682
683Process *
684Target::CalculateProcess ()
685{
686 return NULL;
687}
688
689Thread *
690Target::CalculateThread ()
691{
692 return NULL;
693}
694
695StackFrame *
696Target::CalculateStackFrame ()
697{
698 return NULL;
699}
700
701void
702Target::Calculate (ExecutionContext &exe_ctx)
703{
704 exe_ctx.target = this;
705 exe_ctx.process = NULL; // Do NOT fill in process...
706 exe_ctx.thread = NULL;
707 exe_ctx.frame = NULL;
708}
709
710PathMappingList &
711Target::GetImageSearchPathList ()
712{
713 return m_image_search_paths;
714}
715
716void
717Target::ImageSearchPathsChanged
718(
719 const PathMappingList &path_list,
720 void *baton
721)
722{
723 Target *target = (Target *)baton;
724 if (target->m_images.GetSize() > 1)
725 {
726 ModuleSP exe_module_sp (target->GetExecutableModule());
727 if (exe_module_sp)
728 {
729 target->m_images.Clear();
730 target->SetExecutableModule (exe_module_sp, true);
731 }
732 }
733}
734
735ClangASTContext *
736Target::GetScratchClangASTContext()
737{
738 return m_scratch_ast_context_ap.get();
739}