1 //===-- MachThread.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 //  Created by Greg Clayton on 6/19/07.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MachThread.h"
15 #include "MachProcess.h"
16 #include "DNBLog.h"
17 #include "DNB.h"
18 
19 static uint32_t
20 GetSequenceID()
21 {
22     static uint32_t g_nextID = 0;
23     return ++g_nextID;
24 }
25 
26 MachThread::MachThread (MachProcess *process, thread_t tid) :
27     m_process (process),
28     m_tid (tid),
29     m_seq_id (GetSequenceID()),
30     m_state (eStateUnloaded),
31     m_state_mutex (PTHREAD_MUTEX_RECURSIVE),
32     m_break_id (INVALID_NUB_BREAK_ID),
33     m_suspend_count (0),
34     m_stop_exception (),
35     m_arch_ap (DNBArchProtocol::Create (this)),
36     m_reg_sets (NULL),
37     m_num_reg_sets (0)
38 #ifdef THREAD_IDENTIFIER_INFO_COUNT
39     , m_ident_info(),
40     m_proc_threadinfo(),
41     m_dispatch_queue_name()
42 #endif
43 {
44     nub_size_t num_reg_sets = 0;
45     m_reg_sets = m_arch_ap->GetRegisterSetInfo (&num_reg_sets);
46     m_num_reg_sets = num_reg_sets;
47 
48     // Get the thread state so we know if a thread is in a state where we can't
49     // muck with it and also so we get the suspend count correct in case it was
50     // already suspended
51     GetBasicInfo();
52     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::MachThread ( process = %p, tid = 0x%4.4x, seq_id = %u )", &m_process, m_tid, m_seq_id);
53 }
54 
55 MachThread::~MachThread()
56 {
57     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::~MachThread() for tid = 0x%4.4x (%u)", m_tid, m_seq_id);
58 }
59 
60 
61 
62 void
63 MachThread::Suspend()
64 {
65     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
66     if (ThreadIDIsValid(m_tid))
67     {
68         DNBError err(::thread_suspend (m_tid), DNBError::MachKernel);
69         if (err.Success())
70             m_suspend_count++;
71         if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
72             err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
73     }
74 }
75 
76 void
77 MachThread::Resume(bool others_stopped)
78 {
79     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
80     if (ThreadIDIsValid(m_tid))
81     {
82         SetSuspendCountBeforeResume(others_stopped);
83     }
84 }
85 
86 bool
87 MachThread::SetSuspendCountBeforeResume(bool others_stopped)
88 {
89     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
90     DNBError err;
91     if (ThreadIDIsValid(m_tid) == false)
92         return false;
93 
94     size_t times_to_resume;
95 
96     if (others_stopped)
97     {
98         if (GetBasicInfo())
99         {
100             times_to_resume = m_basic_info.suspend_count;
101             m_suspend_count = - (times_to_resume - m_suspend_count);
102         }
103         else
104             times_to_resume = 0;
105     }
106     else
107     {
108         times_to_resume = m_suspend_count;
109         m_suspend_count = 0;
110     }
111 
112     if (times_to_resume > 0)
113     {
114         while (times_to_resume > 0)
115         {
116             err = ::thread_resume (m_tid);
117             if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
118                 err.LogThreaded("::thread_resume (%4.4x)", m_tid);
119             if (err.Success())
120                 --times_to_resume;
121             else
122             {
123                 if (GetBasicInfo())
124                     times_to_resume = m_basic_info.suspend_count;
125                 else
126                     times_to_resume = 0;
127             }
128         }
129     }
130     return true;
131 }
132 
133 bool
134 MachThread::RestoreSuspendCountAfterStop ()
135 {
136     DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
137     DNBError err;
138     if (ThreadIDIsValid(m_tid) == false)
139         return false;
140 
141     if (m_suspend_count > 0)
142     {
143         while (m_suspend_count > 0)
144         {
145             err = ::thread_resume (m_tid);
146             if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
147                 err.LogThreaded("::thread_resume (%4.4x)", m_tid);
148             if (err.Success())
149                 --m_suspend_count;
150             else
151             {
152                 if (GetBasicInfo())
153                     m_suspend_count = m_basic_info.suspend_count;
154                 else
155                     m_suspend_count = 0;
156                 return false; // ???
157             }
158         }
159     }
160     else if (m_suspend_count < 0)
161     {
162         while (m_suspend_count < 0)
163         {
164             err = ::thread_suspend (m_tid);
165             if (err.Success())
166                 ++m_suspend_count;
167             if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
168             {
169                 err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
170                 return false;
171             }
172         }
173     }
174     return true;
175 }
176 
177 
178 const char *
179 MachThread::GetBasicInfoAsString () const
180 {
181     static char g_basic_info_string[1024];
182     struct thread_basic_info basicInfo;
183 
184     if (GetBasicInfo(m_tid, &basicInfo))
185     {
186 
187 //        char run_state_str[32];
188 //        size_t run_state_str_size = sizeof(run_state_str);
189 //        switch (basicInfo.run_state)
190 //        {
191 //        case TH_STATE_RUNNING:          strncpy(run_state_str, "running", run_state_str_size); break;
192 //        case TH_STATE_STOPPED:          strncpy(run_state_str, "stopped", run_state_str_size); break;
193 //        case TH_STATE_WAITING:          strncpy(run_state_str, "waiting", run_state_str_size); break;
194 //        case TH_STATE_UNINTERRUPTIBLE:  strncpy(run_state_str, "uninterruptible", run_state_str_size); break;
195 //        case TH_STATE_HALTED:           strncpy(run_state_str, "halted", run_state_str_size); break;
196 //        default:                        snprintf(run_state_str, run_state_str_size, "%d", basicInfo.run_state); break;    // ???
197 //        }
198         float user = (float)basicInfo.user_time.seconds + (float)basicInfo.user_time.microseconds / 1000000.0f;
199         float system = (float)basicInfo.user_time.seconds + (float)basicInfo.user_time.microseconds / 1000000.0f;
200         snprintf(g_basic_info_string, sizeof(g_basic_info_string), "Thread 0x%4.4x: user=%f system=%f cpu=%d sleep_time=%d",
201             InferiorThreadID(),
202             user,
203             system,
204             basicInfo.cpu_usage,
205             basicInfo.sleep_time);
206 
207         return g_basic_info_string;
208     }
209     return NULL;
210 }
211 
212 thread_t
213 MachThread::InferiorThreadID() const
214 {
215     mach_msg_type_number_t i;
216     mach_port_name_array_t names;
217     mach_port_type_array_t types;
218     mach_msg_type_number_t ncount, tcount;
219     thread_t inferior_tid = INVALID_NUB_THREAD;
220     task_t my_task = ::mach_task_self();
221     task_t task = m_process->Task().TaskPort();
222 
223     kern_return_t kret = ::mach_port_names (task, &names, &ncount, &types, &tcount);
224     if (kret == KERN_SUCCESS)
225     {
226 
227         for (i = 0; i < ncount; i++)
228         {
229             mach_port_t my_name;
230             mach_msg_type_name_t my_type;
231 
232             kret = ::mach_port_extract_right (task, names[i], MACH_MSG_TYPE_COPY_SEND, &my_name, &my_type);
233             if (kret == KERN_SUCCESS)
234             {
235                 ::mach_port_deallocate (my_task, my_name);
236                 if (my_name == m_tid)
237                 {
238                     inferior_tid = names[i];
239                     break;
240                 }
241             }
242         }
243         // Free up the names and types
244         ::vm_deallocate (my_task, (vm_address_t) names, ncount * sizeof (mach_port_name_t));
245         ::vm_deallocate (my_task, (vm_address_t) types, tcount * sizeof (mach_port_type_t));
246     }
247     return inferior_tid;
248 }
249 
250 bool
251 MachThread::IsUserReady()
252 {
253     if (m_basic_info.run_state == 0)
254         GetBasicInfo ();
255 
256     switch (m_basic_info.run_state)
257     {
258     default:
259     case TH_STATE_UNINTERRUPTIBLE:
260         break;
261 
262     case TH_STATE_RUNNING:
263     case TH_STATE_STOPPED:
264     case TH_STATE_WAITING:
265     case TH_STATE_HALTED:
266         return true;
267     }
268     return false;
269 }
270 
271 struct thread_basic_info *
272 MachThread::GetBasicInfo ()
273 {
274     if (MachThread::GetBasicInfo(m_tid, &m_basic_info))
275         return &m_basic_info;
276     return NULL;
277 }
278 
279 
280 bool
281 MachThread::GetBasicInfo(thread_t thread, struct thread_basic_info *basicInfoPtr)
282 {
283     if (ThreadIDIsValid(thread))
284     {
285         unsigned int info_count = THREAD_BASIC_INFO_COUNT;
286         kern_return_t err = ::thread_info (thread, THREAD_BASIC_INFO, (thread_info_t) basicInfoPtr, &info_count);
287         if (err == KERN_SUCCESS)
288             return true;
289     }
290     ::memset (basicInfoPtr, 0, sizeof (struct thread_basic_info));
291     return false;
292 }
293 
294 
295 bool
296 MachThread::ThreadIDIsValid(thread_t thread)
297 {
298     return thread != THREAD_NULL;
299 }
300 
301 bool
302 MachThread::GetRegisterState(int flavor, bool force)
303 {
304     return m_arch_ap->GetRegisterState(flavor, force) == KERN_SUCCESS;
305 }
306 
307 bool
308 MachThread::SetRegisterState(int flavor)
309 {
310     return m_arch_ap->SetRegisterState(flavor) == KERN_SUCCESS;
311 }
312 
313 uint64_t
314 MachThread::GetPC(uint64_t failValue)
315 {
316     // Get program counter
317     return m_arch_ap->GetPC(failValue);
318 }
319 
320 bool
321 MachThread::SetPC(uint64_t value)
322 {
323     // Set program counter
324     return m_arch_ap->SetPC(value);
325 }
326 
327 uint64_t
328 MachThread::GetSP(uint64_t failValue)
329 {
330     // Get stack pointer
331     return m_arch_ap->GetSP(failValue);
332 }
333 
334 nub_process_t
335 MachThread::ProcessID() const
336 {
337     if (m_process)
338         return m_process->ProcessID();
339     return INVALID_NUB_PROCESS;
340 }
341 
342 void
343 MachThread::Dump(uint32_t index)
344 {
345     const char * thread_run_state = NULL;
346 
347     switch (m_basic_info.run_state)
348     {
349     case TH_STATE_RUNNING:          thread_run_state = "running"; break;    // 1 thread is running normally
350     case TH_STATE_STOPPED:          thread_run_state = "stopped"; break;    // 2 thread is stopped
351     case TH_STATE_WAITING:          thread_run_state = "waiting"; break;    // 3 thread is waiting normally
352     case TH_STATE_UNINTERRUPTIBLE:  thread_run_state = "uninter"; break;    // 4 thread is in an uninterruptible wait
353     case TH_STATE_HALTED:           thread_run_state = "halted "; break;     // 5 thread is halted at a
354     default:                        thread_run_state = "???"; break;
355     }
356 
357     DNBLogThreaded("[%3u] #%3u tid: 0x%4.4x, pc: 0x%16.16llx, sp: 0x%16.16llx, breakID: %3d, user: %d.%6.6d, system: %d.%6.6d, cpu: %2d, policy: %2d, run_state: %2d (%s), flags: %2d, suspend_count: %2d (current %2d), sleep_time: %d",
358         index,
359         m_seq_id,
360         m_tid,
361         GetPC(INVALID_NUB_ADDRESS),
362         GetSP(INVALID_NUB_ADDRESS),
363         m_break_id,
364         m_basic_info.user_time.seconds,      m_basic_info.user_time.microseconds,
365         m_basic_info.system_time.seconds,    m_basic_info.system_time.microseconds,
366         m_basic_info.cpu_usage,
367         m_basic_info.policy,
368         m_basic_info.run_state,
369         thread_run_state,
370         m_basic_info.flags,
371         m_basic_info.suspend_count, m_suspend_count,
372         m_basic_info.sleep_time);
373     //DumpRegisterState(0);
374 }
375 
376 void
377 MachThread::ThreadWillResume(const DNBThreadResumeAction *thread_action, bool others_stopped)
378 {
379     if (thread_action->addr != INVALID_NUB_ADDRESS)
380         SetPC (thread_action->addr);
381 
382     SetState (thread_action->state);
383     switch (thread_action->state)
384     {
385     case eStateStopped:
386     case eStateSuspended:
387         assert (others_stopped == false);
388         Suspend();
389         break;
390 
391     case eStateRunning:
392     case eStateStepping:
393         Resume(others_stopped);
394         break;
395     default:
396         break;
397     }
398     m_arch_ap->ThreadWillResume();
399     m_stop_exception.Clear();
400 }
401 
402 nub_break_t
403 MachThread::CurrentBreakpoint()
404 {
405     return m_process->Breakpoints().FindIDByAddress(GetPC());
406 }
407 
408 bool
409 MachThread::ShouldStop(bool &step_more)
410 {
411     // See if this thread is at a breakpoint?
412     nub_break_t breakID = CurrentBreakpoint();
413 
414     if (NUB_BREAK_ID_IS_VALID(breakID))
415     {
416         // This thread is sitting at a breakpoint, ask the breakpoint
417         // if we should be stopping here.
418         if (Process()->Breakpoints().ShouldStop(ProcessID(), ThreadID(), breakID))
419             return true;
420         else
421         {
422             // The breakpoint said we shouldn't stop, but we may have gotten
423             // a signal or the user may have requested to stop in some other
424             // way. Stop if we have a valid exception (this thread won't if
425             // another thread was the reason this process stopped) and that
426             // exception, is NOT a breakpoint exception (a common case would
427             // be a SIGINT signal).
428             if (GetStopException().IsValid() && !GetStopException().IsBreakpoint())
429                 return true;
430         }
431     }
432     else
433     {
434         if (m_arch_ap->StepNotComplete())
435         {
436             step_more = true;
437             return false;
438         }
439         // The thread state is used to let us know what the thread was
440         // trying to do. MachThread::ThreadWillResume() will set the
441         // thread state to various values depending if the thread was
442         // the current thread and if it was to be single stepped, or
443         // resumed.
444         if (GetState() == eStateRunning)
445         {
446             // If our state is running, then we should continue as we are in
447             // the process of stepping over a breakpoint.
448             return false;
449         }
450         else
451         {
452             // Stop if we have any kind of valid exception for this
453             // thread.
454             if (GetStopException().IsValid())
455                 return true;
456         }
457     }
458     return false;
459 }
460 bool
461 MachThread::IsStepping()
462 {
463 #if ENABLE_AUTO_STEPPING_OVER_BP
464     // Return true if this thread is currently being stepped.
465     // MachThread::ThreadWillResume currently determines this by looking if we
466     // have been asked to single step, or if we are at a breakpoint instruction
467     // and have been asked to resume. In the latter case we need to disable the
468     // breakpoint we are at, single step, re-enable and continue.
469     nub_state_t state = GetState();
470     return ((state == eStateStepping) ||
471             (state == eStateRunning && NUB_BREAK_ID_IS_VALID(CurrentBreakpoint())));
472 #else
473     return GetState() == eStateStepping;
474 #endif
475 }
476 
477 
478 bool
479 MachThread::ThreadDidStop()
480 {
481     // This thread has existed prior to resuming under debug nub control,
482     // and has just been stopped. Do any cleanup that needs to be done
483     // after running.
484 
485     // The thread state and breakpoint will still have the same values
486     // as they had prior to resuming the thread, so it makes it easy to check
487     // if we were trying to step a thread, or we tried to resume while being
488     // at a breakpoint.
489 
490     // When this method gets called, the process state is still in the
491     // state it was in while running so we can act accordingly.
492     m_arch_ap->ThreadDidStop();
493 
494 
495     // We may have suspended this thread so the primary thread could step
496     // without worrying about race conditions, so lets restore our suspend
497     // count.
498     RestoreSuspendCountAfterStop();
499 
500     // Update the basic information for a thread
501     MachThread::GetBasicInfo(m_tid, &m_basic_info);
502 
503 #if ENABLE_AUTO_STEPPING_OVER_BP
504     // See if we were at a breakpoint when we last resumed that we disabled,
505     // re-enable it.
506     nub_break_t breakID = CurrentBreakpoint();
507 
508     if (NUB_BREAK_ID_IS_VALID(breakID))
509     {
510         m_process->EnableBreakpoint(breakID);
511         if (m_basic_info.suspend_count > 0)
512         {
513             SetState(eStateSuspended);
514         }
515         else
516         {
517             // If we last were at a breakpoint and we single stepped, our state
518             // will be "running" to indicate we need to continue after stepping
519             // over the breakpoint instruction. If we step over a breakpoint
520             // instruction, we need to stop.
521             if (GetState() == eStateRunning)
522             {
523                 // Leave state set to running so we will continue automatically
524                 // from this breakpoint
525             }
526             else
527             {
528                 SetState(eStateStopped);
529             }
530         }
531     }
532     else
533     {
534         if (m_basic_info.suspend_count > 0)
535         {
536             SetState(eStateSuspended);
537         }
538         else
539         {
540             SetState(eStateStopped);
541         }
542     }
543 #else
544     if (m_basic_info.suspend_count > 0)
545         SetState(eStateSuspended);
546     else
547         SetState(eStateStopped);
548 #endif
549     return true;
550 }
551 
552 bool
553 MachThread::NotifyException(MachException::Data& exc)
554 {
555     // Allow the arch specific protocol to process (MachException::Data &)exc
556     // first before possible reassignment of m_stop_exception with exc.
557     // See also MachThread::GetStopException().
558     bool handled = m_arch_ap->NotifyException(exc);
559 
560     if (m_stop_exception.IsValid())
561     {
562         // We may have more than one exception for a thread, but we need to
563         // only remember the one that we will say is the reason we stopped.
564         // We may have been single stepping and also gotten a signal exception,
565         // so just remember the most pertinent one.
566         if (m_stop_exception.IsBreakpoint())
567             m_stop_exception = exc;
568     }
569     else
570     {
571         m_stop_exception = exc;
572     }
573 
574     return handled;
575 }
576 
577 
578 nub_state_t
579 MachThread::GetState()
580 {
581     // If any other threads access this we will need a mutex for it
582     PTHREAD_MUTEX_LOCKER (locker, m_state_mutex);
583     return m_state;
584 }
585 
586 void
587 MachThread::SetState(nub_state_t state)
588 {
589     PTHREAD_MUTEX_LOCKER (locker, m_state_mutex);
590     m_state = state;
591     DNBLogThreadedIf(LOG_THREAD, "MachThread::SetState ( %s ) for tid = 0x%4.4x", DNBStateAsString(state), m_tid);
592 }
593 
594 uint32_t
595 MachThread::GetNumRegistersInSet(int regSet) const
596 {
597     if (regSet < m_num_reg_sets)
598         return m_reg_sets[regSet].num_registers;
599     return 0;
600 }
601 
602 const char *
603 MachThread::GetRegisterSetName(int regSet) const
604 {
605     if (regSet < m_num_reg_sets)
606         return m_reg_sets[regSet].name;
607     return NULL;
608 }
609 
610 const DNBRegisterInfo *
611 MachThread::GetRegisterInfo(int regSet, int regIndex) const
612 {
613     if (regSet < m_num_reg_sets)
614         if (regIndex < m_reg_sets[regSet].num_registers)
615             return &m_reg_sets[regSet].registers[regIndex];
616     return NULL;
617 }
618 void
619 MachThread::DumpRegisterState(int regSet)
620 {
621     if (regSet == REGISTER_SET_ALL)
622     {
623         for (regSet = 1; regSet < m_num_reg_sets; regSet++)
624             DumpRegisterState(regSet);
625     }
626     else
627     {
628         if (m_arch_ap->RegisterSetStateIsValid(regSet))
629         {
630             const size_t numRegisters = GetNumRegistersInSet(regSet);
631             size_t regIndex = 0;
632             DNBRegisterValueClass reg;
633             for (regIndex = 0; regIndex < numRegisters; ++regIndex)
634             {
635                 if (m_arch_ap->GetRegisterValue(regSet, regIndex, &reg))
636                 {
637                     reg.Dump(NULL, NULL);
638                 }
639             }
640         }
641         else
642         {
643             DNBLog("%s: registers are not currently valid.", GetRegisterSetName(regSet));
644         }
645     }
646 }
647 
648 const DNBRegisterSetInfo *
649 MachThread::GetRegisterSetInfo(nub_size_t *num_reg_sets ) const
650 {
651     *num_reg_sets = m_num_reg_sets;
652     return &m_reg_sets[0];
653 }
654 
655 bool
656 MachThread::GetRegisterValue ( uint32_t set, uint32_t reg, DNBRegisterValue *value )
657 {
658     return m_arch_ap->GetRegisterValue(set, reg, value);
659 }
660 
661 bool
662 MachThread::SetRegisterValue ( uint32_t set, uint32_t reg, const DNBRegisterValue *value )
663 {
664     return m_arch_ap->SetRegisterValue(set, reg, value);
665 }
666 
667 nub_size_t
668 MachThread::GetRegisterContext (void *buf, nub_size_t buf_len)
669 {
670     return m_arch_ap->GetRegisterContext(buf, buf_len);
671 }
672 
673 nub_size_t
674 MachThread::SetRegisterContext (const void *buf, nub_size_t buf_len)
675 {
676     return m_arch_ap->SetRegisterContext(buf, buf_len);
677 }
678 
679 uint32_t
680 MachThread::EnableHardwareBreakpoint (const DNBBreakpoint *bp)
681 {
682     if (bp != NULL && bp->IsBreakpoint())
683         return m_arch_ap->EnableHardwareBreakpoint(bp->Address(), bp->ByteSize());
684     return INVALID_NUB_HW_INDEX;
685 }
686 
687 uint32_t
688 MachThread::EnableHardwareWatchpoint (const DNBBreakpoint *wp)
689 {
690     if (wp != NULL && wp->IsWatchpoint())
691         return m_arch_ap->EnableHardwareWatchpoint(wp->Address(), wp->ByteSize(), wp->WatchpointRead(), wp->WatchpointWrite());
692     return INVALID_NUB_HW_INDEX;
693 }
694 
695 // Provide a chance to update the global view of the hardware watchpoint state.
696 void
697 MachThread::HardwareWatchpointStateChanged ()
698 {
699     m_arch_ap->HardwareWatchpointStateChanged();
700 }
701 
702 bool
703 MachThread::DisableHardwareBreakpoint (const DNBBreakpoint *bp)
704 {
705     if (bp != NULL && bp->IsHardware())
706         return m_arch_ap->DisableHardwareBreakpoint(bp->GetHardwareIndex());
707     return false;
708 }
709 
710 bool
711 MachThread::DisableHardwareWatchpoint (const DNBBreakpoint *wp)
712 {
713     if (wp != NULL && wp->IsHardware())
714         return m_arch_ap->DisableHardwareWatchpoint(wp->GetHardwareIndex());
715     return false;
716 }
717 
718 bool
719 MachThread::GetIdentifierInfo ()
720 {
721 #ifdef THREAD_IDENTIFIER_INFO_COUNT
722         // Don't try to get the thread info once and cache it for the life of the thread.  It changes over time, for instance
723         // if the thread name changes, then the thread_handle also changes...  So you have to refetch it every time.
724         mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
725         kern_return_t kret = ::thread_info (ThreadID(), THREAD_IDENTIFIER_INFO, (thread_info_t) &m_ident_info, &count);
726         return kret == KERN_SUCCESS;
727 #endif
728 
729     return false;
730 }
731 
732 
733 const char *
734 MachThread::GetName ()
735 {
736     if (GetIdentifierInfo ())
737     {
738         int len = ::proc_pidinfo (m_process->ProcessID(), PROC_PIDTHREADINFO, m_ident_info.thread_handle, &m_proc_threadinfo, sizeof (m_proc_threadinfo));
739 
740         if (len && m_proc_threadinfo.pth_name[0])
741             return m_proc_threadinfo.pth_name;
742     }
743     return NULL;
744 }
745 
746