blob: 1bc32946ca5b62a253f8055d8a39cb00601ca8bf [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- TargetList.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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Broadcaster.h"
Greg Claytonded470d2011-03-19 01:12:21 +000017#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Event.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Core/Module.h"
Greg Claytonf4d6de62013-04-24 22:29:28 +000020#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/State.h"
22#include "lldb/Core/Timer.h"
23#include "lldb/Host/Host.h"
Greg Claytonb3a40ba2012-03-20 18:34:04 +000024#include "lldb/Interpreter/CommandInterpreter.h"
Greg Claytoncac9c5f2011-09-24 00:52:29 +000025#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Claytonf4d6de62013-04-24 22:29:28 +000026#include "lldb/Symbol/ObjectFile.h"
Greg Claytone996fd32011-03-08 22:40:15 +000027#include "lldb/Target/Platform.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/Process.h"
29#include "lldb/Target/TargetList.h"
30
31using namespace lldb;
32using namespace lldb_private;
33
Jim Ingham4bddaeb2012-02-16 06:50:00 +000034ConstString &
35TargetList::GetStaticBroadcasterClass ()
36{
37 static ConstString class_name ("lldb.targetList");
38 return class_name;
39}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040
41//----------------------------------------------------------------------
42// TargetList constructor
43//----------------------------------------------------------------------
Jim Ingham4bddaeb2012-02-16 06:50:00 +000044TargetList::TargetList(Debugger &debugger) :
Jim Ingham4f465cf2012-10-10 18:32:14 +000045 Broadcaster(&debugger, TargetList::GetStaticBroadcasterClass().AsCString()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 m_target_list(),
47 m_target_list_mutex (Mutex::eMutexTypeRecursive),
Jim Ingham2976d002010-08-26 21:32:51 +000048 m_selected_target_idx (0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049{
Jim Ingham4bddaeb2012-02-16 06:50:00 +000050 CheckInWithManager();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051}
52
53//----------------------------------------------------------------------
54// Destructor
55//----------------------------------------------------------------------
56TargetList::~TargetList()
57{
58 Mutex::Locker locker(m_target_list_mutex);
59 m_target_list.clear();
60}
61
62Error
Greg Claytoncac9c5f2011-09-24 00:52:29 +000063TargetList::CreateTarget (Debugger &debugger,
Greg Claytona0ca6602012-10-18 16:33:33 +000064 const char *user_exe_path,
Greg Claytoncac9c5f2011-09-24 00:52:29 +000065 const char *triple_cstr,
66 bool get_dependent_files,
67 const OptionGroupPlatform *platform_options,
68 TargetSP &target_sp)
69{
70 Error error;
71 PlatformSP platform_sp;
Greg Claytoncac9c5f2011-09-24 00:52:29 +000072
Johnny Chencdc21d42012-01-05 01:26:01 +000073 // This is purposely left empty unless it is specified by triple_cstr.
74 // If not initialized via triple_cstr, then the currently selected platform
75 // will set the architecture correctly.
Greg Clayton70512312012-05-08 01:45:38 +000076 const ArchSpec arch(triple_cstr);
77 if (triple_cstr && triple_cstr[0])
Greg Claytoncac9c5f2011-09-24 00:52:29 +000078 {
Greg Claytoncac9c5f2011-09-24 00:52:29 +000079 if (!arch.IsValid())
80 {
Greg Clayton86edbf42011-10-26 00:56:27 +000081 error.SetErrorStringWithFormat("invalid triple '%s'", triple_cstr);
Greg Claytoncac9c5f2011-09-24 00:52:29 +000082 return error;
83 }
84 }
Greg Claytonf4d6de62013-04-24 22:29:28 +000085
Greg Clayton70512312012-05-08 01:45:38 +000086 ArchSpec platform_arch(arch);
Greg Claytonf4d6de62013-04-24 22:29:28 +000087
88
89 if (user_exe_path && user_exe_path[0])
90 {
91 ModuleSpecList module_specs;
92 ModuleSpec module_spec;
93 module_spec.GetFileSpec().SetFile(user_exe_path, true);
94 lldb::offset_t file_offset = 0;
95 const size_t num_specs = ObjectFile::GetModuleSpecifications (module_spec.GetFileSpec(), file_offset, module_specs);
96 if (num_specs > 0)
97 {
98 ModuleSpec matching_module_spec;
99
100 if (num_specs == 1)
101 {
102 if (module_specs.GetModuleSpecAtIndex(0, matching_module_spec))
103 {
104 if (platform_arch.IsValid())
105 {
106 if (!platform_arch.IsCompatibleMatch(matching_module_spec.GetArchitecture()))
107 {
108 error.SetErrorStringWithFormat("the specified architecture '%s' is not compatible with '%s' in '%s%s%s'",
109 platform_arch.GetTriple().str().c_str(),
110 matching_module_spec.GetArchitecture().GetTriple().str().c_str(),
111 module_spec.GetFileSpec().GetDirectory() ? module_spec.GetFileSpec().GetDirectory().GetCString() : "",
112 module_spec.GetFileSpec().GetDirectory() ? "/" : "",
113 module_spec.GetFileSpec().GetFilename().GetCString());
114 return error;
115 }
116 }
117 else
118 {
119 // Only one arch and none was specified
120 platform_arch = matching_module_spec.GetArchitecture();
121 }
122 }
123 }
124 else
125 {
126 if (arch.IsValid())
127 {
128 module_spec.GetArchitecture() = arch;
129 if (module_specs.FindMatchingModuleSpec(module_spec, matching_module_spec))
130 {
131 platform_arch = matching_module_spec.GetArchitecture();
132 }
133 }
134 else
135 {
136 // No arch specified, select the first arch
137 if (module_specs.GetModuleSpecAtIndex(0, matching_module_spec))
138 {
139 platform_arch = matching_module_spec.GetArchitecture();
140 }
141 }
142 }
143 }
144 }
145
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000146 CommandInterpreter &interpreter = debugger.GetCommandInterpreter();
147 if (platform_options)
148 {
149 if (platform_options->PlatformWasSpecified ())
150 {
151 const bool select_platform = true;
152 platform_sp = platform_options->CreatePlatformWithOptions (interpreter,
153 arch,
154 select_platform,
Greg Clayton70512312012-05-08 01:45:38 +0000155 error,
156 platform_arch);
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000157 if (!platform_sp)
158 return error;
159 }
160 }
161
162 if (!platform_sp)
163 {
164 // Get the current platform and make sure it is compatible with the
165 // current architecture if we have a valid architecture.
166 platform_sp = debugger.GetPlatformList().GetSelectedPlatform ();
167
Greg Clayton1e0c8842013-01-11 20:49:54 +0000168 if (arch.IsValid() && !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch))
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000169 {
Greg Clayton70512312012-05-08 01:45:38 +0000170 platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch);
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000171 }
172 }
Greg Clayton70512312012-05-08 01:45:38 +0000173
174 if (!platform_arch.IsValid())
175 platform_arch = arch;
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000176
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000177 error = TargetList::CreateTarget (debugger,
Greg Claytona0ca6602012-10-18 16:33:33 +0000178 user_exe_path,
Greg Clayton70512312012-05-08 01:45:38 +0000179 platform_arch,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000180 get_dependent_files,
181 platform_sp,
182 target_sp);
183 return error;
184}
185
186Error
Greg Claytona0ca6602012-10-18 16:33:33 +0000187TargetList::CreateTarget (Debugger &debugger,
188 const char *user_exe_path,
189 const ArchSpec& specified_arch,
190 bool get_dependent_files,
191 PlatformSP &platform_sp,
192 TargetSP &target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193{
194 Timer scoped_timer (__PRETTY_FUNCTION__,
Greg Claytona0ca6602012-10-18 16:33:33 +0000195 "TargetList::CreateTarget (file = '%s', arch = '%s')",
196 user_exe_path,
Greg Clayton70512312012-05-08 01:45:38 +0000197 specified_arch.GetArchitectureName());
Jim Ingham5aee1622010-08-09 23:31:02 +0000198 Error error;
Greg Claytonded470d2011-03-19 01:12:21 +0000199
Greg Clayton70512312012-05-08 01:45:38 +0000200 ArchSpec arch(specified_arch);
201
202 if (platform_sp)
203 {
204 if (arch.IsValid())
205 {
Greg Clayton1e0c8842013-01-11 20:49:54 +0000206 if (!platform_sp->IsCompatibleArchitecture(arch, false, NULL))
Greg Clayton70512312012-05-08 01:45:38 +0000207 platform_sp = Platform::GetPlatformForArchitecture(specified_arch, &arch);
208 }
209 }
210 else if (arch.IsValid())
211 {
212 platform_sp = Platform::GetPlatformForArchitecture(specified_arch, &arch);
213 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000214
Greg Clayton70512312012-05-08 01:45:38 +0000215 if (!platform_sp)
216 platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
217
Greg Clayton8ae50eb2012-06-05 21:17:09 +0000218 if (!arch.IsValid())
219 arch = specified_arch;
Greg Clayton8ae50eb2012-06-05 21:17:09 +0000220
Jason Molendad26206b52013-04-19 22:38:50 +0000221 FileSpec file (user_exe_path, false);
222 if (!file.Exists() && user_exe_path && user_exe_path[0] == '~')
223 {
224 file = FileSpec(user_exe_path, true);
225 }
Greg Clayton82d79292012-10-25 22:45:35 +0000226 bool user_exe_path_is_bundle = false;
227 char resolved_bundle_exe_path[PATH_MAX];
228 resolved_bundle_exe_path[0] = '\0';
Greg Claytone996fd32011-03-08 22:40:15 +0000229 if (file)
Jim Ingham5aee1622010-08-09 23:31:02 +0000230 {
Greg Clayton82d79292012-10-25 22:45:35 +0000231 if (file.GetFileType() == FileSpec::eFileTypeDirectory)
232 user_exe_path_is_bundle = true;
233
Greg Claytona0ca6602012-10-18 16:33:33 +0000234 if (file.IsRelativeToCurrentWorkingDirectory())
235 {
236 // Ignore paths that start with "./" and "../"
237 if (!((user_exe_path[0] == '.' && user_exe_path[1] == '/') ||
238 (user_exe_path[0] == '.' && user_exe_path[1] == '.' && user_exe_path[2] == '/')))
239 {
240 char cwd[PATH_MAX];
241 if (getcwd (cwd, sizeof(cwd)))
242 {
243 std::string cwd_user_exe_path (cwd);
244 cwd_user_exe_path += '/';
245 cwd_user_exe_path += user_exe_path;
Greg Clayton9ff5aae2013-04-04 00:15:09 +0000246 FileSpec cwd_file (cwd_user_exe_path.c_str(), false);
247 if (cwd_file.Exists())
248 file = cwd_file;
Greg Claytona0ca6602012-10-18 16:33:33 +0000249 }
250 }
251 }
252
Jim Ingham5aee1622010-08-09 23:31:02 +0000253 ModuleSP exe_module_sp;
Greg Claytone996fd32011-03-08 22:40:15 +0000254 if (platform_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000255 {
256 FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
Greg Clayton70512312012-05-08 01:45:38 +0000257 error = platform_sp->ResolveExecutable (file,
258 arch,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000259 exe_module_sp,
260 executable_search_paths.GetSize() ? &executable_search_paths : NULL);
261 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262
Greg Claytone996fd32011-03-08 22:40:15 +0000263 if (error.Success() && exe_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Jim Ingham5aee1622010-08-09 23:31:02 +0000265 if (exe_module_sp->GetObjectFile() == NULL)
266 {
Greg Claytonbc5cad62010-12-08 04:55:11 +0000267 if (arch.IsValid())
268 {
269 error.SetErrorStringWithFormat("\"%s%s%s\" doesn't contain architecture %s",
270 file.GetDirectory().AsCString(),
271 file.GetDirectory() ? "/" : "",
272 file.GetFilename().AsCString(),
Greg Clayton64195a22011-02-23 00:35:02 +0000273 arch.GetArchitectureName());
Greg Claytonbc5cad62010-12-08 04:55:11 +0000274 }
275 else
276 {
277 error.SetErrorStringWithFormat("unsupported file type \"%s%s%s\"",
278 file.GetDirectory().AsCString(),
279 file.GetDirectory() ? "/" : "",
280 file.GetFilename().AsCString());
281 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000282 return error;
283 }
Greg Clayton32e0a752011-03-30 18:16:51 +0000284 target_sp.reset(new Target(debugger, arch, platform_sp));
Jim Ingham5aee1622010-08-09 23:31:02 +0000285 target_sp->SetExecutableModule (exe_module_sp, get_dependent_files);
Greg Clayton82d79292012-10-25 22:45:35 +0000286 if (user_exe_path_is_bundle)
287 exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path, sizeof(resolved_bundle_exe_path));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000289 }
Greg Claytone996fd32011-03-08 22:40:15 +0000290 else
Jim Ingham5aee1622010-08-09 23:31:02 +0000291 {
Greg Claytone996fd32011-03-08 22:40:15 +0000292 // No file was specified, just create an empty target with any arch
293 // if a valid arch was specified
Greg Clayton32e0a752011-03-30 18:16:51 +0000294 target_sp.reset(new Target(debugger, arch, platform_sp));
Greg Claytone996fd32011-03-08 22:40:15 +0000295 }
296
297 if (target_sp)
298 {
Greg Clayton82d79292012-10-25 22:45:35 +0000299 // Set argv0 with what the user typed, unless the user specified a
300 // directory. If the user specified a directory, then it is probably a
301 // bundle that was resolved and we need to use the resolved bundle path
Greg Claytona0ca6602012-10-18 16:33:33 +0000302 if (user_exe_path)
303 {
304 // Use exactly what the user typed as the first argument when we exec or posix_spawn
Greg Clayton82d79292012-10-25 22:45:35 +0000305 if (user_exe_path_is_bundle && resolved_bundle_exe_path[0])
306 {
307 target_sp->SetArg0 (resolved_bundle_exe_path);
308 }
309 else
310 {
311 // Just use what the user typed
312 target_sp->SetArg0 (user_exe_path);
313 }
Greg Claytona0ca6602012-10-18 16:33:33 +0000314 }
315 if (file.GetDirectory())
316 {
317 FileSpec file_dir;
318 file_dir.GetDirectory() = file.GetDirectory();
319 target_sp->GetExecutableSearchPaths ().Append (file_dir);
320 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000321 Mutex::Locker locker(m_target_list_mutex);
Jim Ingham2976d002010-08-26 21:32:51 +0000322 m_selected_target_idx = m_target_list.size();
Jim Ingham5aee1622010-08-09 23:31:02 +0000323 m_target_list.push_back(target_sp);
Greg Claytona0ca6602012-10-18 16:33:33 +0000324
325
Jim Ingham5aee1622010-08-09 23:31:02 +0000326 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 return error;
329}
330
331bool
332TargetList::DeleteTarget (TargetSP &target_sp)
333{
334 Mutex::Locker locker(m_target_list_mutex);
335 collection::iterator pos, end = m_target_list.end();
336
337 for (pos = m_target_list.begin(); pos != end; ++pos)
338 {
339 if (pos->get() == target_sp.get())
340 {
341 m_target_list.erase(pos);
342 return true;
343 }
344 }
345 return false;
346}
347
348
349TargetSP
350TargetList::FindTargetWithExecutableAndArchitecture
351(
352 const FileSpec &exe_file_spec,
353 const ArchSpec *exe_arch_ptr
354) const
355{
356 Mutex::Locker locker (m_target_list_mutex);
357 TargetSP target_sp;
358 bool full_match = exe_file_spec.GetDirectory();
359
360 collection::const_iterator pos, end = m_target_list.end();
361 for (pos = m_target_list.begin(); pos != end; ++pos)
362 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000363 Module *exe_module = (*pos)->GetExecutableModulePointer();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364
Greg Claytonaa149cb2011-08-11 02:48:45 +0000365 if (exe_module)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000367 if (FileSpec::Equal (exe_file_spec, exe_module->GetFileSpec(), full_match))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 {
369 if (exe_arch_ptr)
370 {
Sean Callananbf4b7be2012-12-13 22:07:14 +0000371 if (!exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 continue;
373 }
374 target_sp = *pos;
375 break;
376 }
377 }
378 }
379 return target_sp;
380}
381
382TargetSP
383TargetList::FindTargetWithProcessID (lldb::pid_t pid) const
384{
385 Mutex::Locker locker(m_target_list_mutex);
386 TargetSP target_sp;
387 collection::const_iterator pos, end = m_target_list.end();
388 for (pos = m_target_list.begin(); pos != end; ++pos)
389 {
390 Process* process = (*pos)->GetProcessSP().get();
391 if (process && process->GetID() == pid)
392 {
393 target_sp = *pos;
394 break;
395 }
396 }
397 return target_sp;
398}
399
400
401TargetSP
402TargetList::FindTargetWithProcess (Process *process) const
403{
404 TargetSP target_sp;
405 if (process)
406 {
407 Mutex::Locker locker(m_target_list_mutex);
408 collection::const_iterator pos, end = m_target_list.end();
409 for (pos = m_target_list.begin(); pos != end; ++pos)
410 {
411 if (process == (*pos)->GetProcessSP().get())
412 {
413 target_sp = *pos;
414 break;
415 }
416 }
417 }
418 return target_sp;
419}
420
421TargetSP
422TargetList::GetTargetSP (Target *target) const
423{
424 TargetSP target_sp;
425 if (target)
426 {
427 Mutex::Locker locker(m_target_list_mutex);
428 collection::const_iterator pos, end = m_target_list.end();
429 for (pos = m_target_list.begin(); pos != end; ++pos)
430 {
431 if (target == (*pos).get())
432 {
433 target_sp = *pos;
434 break;
435 }
436 }
437 }
438 return target_sp;
439}
440
441uint32_t
442TargetList::SendAsyncInterrupt (lldb::pid_t pid)
443{
444 uint32_t num_async_interrupts_sent = 0;
445
446 if (pid != LLDB_INVALID_PROCESS_ID)
447 {
448 TargetSP target_sp(FindTargetWithProcessID (pid));
449 if (target_sp.get())
450 {
451 Process* process = target_sp->GetProcessSP().get();
452 if (process)
453 {
Jim Inghamcfc09352012-07-27 23:57:19 +0000454 process->SendAsyncInterrupt();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 ++num_async_interrupts_sent;
456 }
457 }
458 }
459 else
460 {
461 // We don't have a valid pid to broadcast to, so broadcast to the target
462 // list's async broadcaster...
463 BroadcastEvent (Process::eBroadcastBitInterrupt, NULL);
464 }
465
466 return num_async_interrupts_sent;
467}
468
469uint32_t
470TargetList::SignalIfRunning (lldb::pid_t pid, int signo)
471{
472 uint32_t num_signals_sent = 0;
473 Process *process = NULL;
474 if (pid == LLDB_INVALID_PROCESS_ID)
475 {
476 // Signal all processes with signal
477 Mutex::Locker locker(m_target_list_mutex);
478 collection::iterator pos, end = m_target_list.end();
479 for (pos = m_target_list.begin(); pos != end; ++pos)
480 {
481 process = (*pos)->GetProcessSP().get();
482 if (process)
483 {
484 if (process->IsAlive())
485 {
486 ++num_signals_sent;
487 process->Signal (signo);
488 }
489 }
490 }
491 }
492 else
493 {
494 // Signal a specific process with signal
495 TargetSP target_sp(FindTargetWithProcessID (pid));
496 if (target_sp.get())
497 {
498 process = target_sp->GetProcessSP().get();
499 if (process)
500 {
501 if (process->IsAlive())
502 {
503 ++num_signals_sent;
504 process->Signal (signo);
505 }
506 }
507 }
508 }
509 return num_signals_sent;
510}
511
512int
513TargetList::GetNumTargets () const
514{
515 Mutex::Locker locker (m_target_list_mutex);
516 return m_target_list.size();
517}
518
519lldb::TargetSP
520TargetList::GetTargetAtIndex (uint32_t idx) const
521{
522 TargetSP target_sp;
523 Mutex::Locker locker (m_target_list_mutex);
524 if (idx < m_target_list.size())
525 target_sp = m_target_list[idx];
526 return target_sp;
527}
528
529uint32_t
Jim Ingham8499e1a2012-05-08 23:06:07 +0000530TargetList::GetIndexOfTarget (lldb::TargetSP target_sp) const
531{
532 Mutex::Locker locker (m_target_list_mutex);
533 size_t num_targets = m_target_list.size();
534 for (size_t idx = 0; idx < num_targets; idx++)
535 {
536 if (target_sp == m_target_list[idx])
537 return idx;
538 }
539 return UINT32_MAX;
540}
541
542uint32_t
Jim Ingham2976d002010-08-26 21:32:51 +0000543TargetList::SetSelectedTarget (Target* target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544{
545 Mutex::Locker locker (m_target_list_mutex);
546 collection::const_iterator pos,
547 begin = m_target_list.begin(),
548 end = m_target_list.end();
549 for (pos = begin; pos != end; ++pos)
550 {
551 if (pos->get() == target)
552 {
Jim Ingham2976d002010-08-26 21:32:51 +0000553 m_selected_target_idx = std::distance (begin, pos);
554 return m_selected_target_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 }
556 }
Jim Ingham2976d002010-08-26 21:32:51 +0000557 m_selected_target_idx = 0;
558 return m_selected_target_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559}
560
561lldb::TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000562TargetList::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563{
564 Mutex::Locker locker (m_target_list_mutex);
Jim Ingham2976d002010-08-26 21:32:51 +0000565 if (m_selected_target_idx >= m_target_list.size())
566 m_selected_target_idx = 0;
567 return GetTargetAtIndex (m_selected_target_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568}