Lines Matching defs:thread

29 #include <thread.h>
60 // a profiling timer for each CPU -- used when a profiled thread is running
64 static void schedule_profiling_timer(Thread* thread, bigtime_t interval);
83 TRACE(("debugger_write(): thread: %" B_PRId32 ", team %" B_PRId32 ", "
132 /*! Updates the thread::flags field according to what user debugger flags are
133 set for the thread.
134 Interrupts must be disabled and the thread's debug info lock must be held.
137 update_thread_user_debug_flag(Thread* thread)
139 if ((atomic_get(&thread->debug_info.flags) & B_THREAD_DEBUG_STOP) != 0)
140 atomic_or(&thread->flags, THREAD_FLAGS_DEBUG_THREAD);
142 atomic_and(&thread->flags, ~THREAD_FLAGS_DEBUG_THREAD);
146 /*! Updates the thread::flags THREAD_FLAGS_BREAKPOINTS_DEFINED bit of the
147 given thread.
148 Interrupts must be disabled and the thread debug info lock must be held.
151 update_thread_breakpoints_flag(Thread* thread)
153 Team* team = thread->team;
156 atomic_or(&thread->flags, THREAD_FLAGS_BREAKPOINTS_DEFINED);
158 atomic_and(&thread->flags, ~THREAD_FLAGS_BREAKPOINTS_DEFINED);
172 Thread* thread = team->thread_list;
175 for (; thread != NULL; thread = thread->team_next)
176 atomic_or(&thread->flags, THREAD_FLAGS_BREAKPOINTS_DEFINED);
178 for (; thread != NULL; thread = thread->team_next)
179 atomic_and(&thread->flags, ~THREAD_FLAGS_BREAKPOINTS_DEFINED);
184 /*! Updates the thread::flags B_TEAM_DEBUG_DEBUGGER_INSTALLED bit of the
185 given thread, which must be the current thread.
188 update_thread_debugger_installed_flag(Thread* thread)
190 Team* team = thread->team;
193 atomic_or(&thread->flags, THREAD_FLAGS_DEBUGGER_INSTALLED);
195 atomic_and(&thread->flags, ~THREAD_FLAGS_DEBUGGER_INSTALLED);
199 /*! Updates the thread::flags THREAD_FLAGS_DEBUGGER_INSTALLED bit of all
206 Thread* thread = team->thread_list;
209 for (; thread != NULL; thread = thread->team_next)
210 atomic_or(&thread->flags, THREAD_FLAGS_DEBUGGER_INSTALLED);
212 for (; thread != NULL; thread = thread->team_next)
213 atomic_and(&thread->flags, ~THREAD_FLAGS_DEBUGGER_INSTALLED);
220 * set to \c true. If it would be possible that another thread accesses the
280 // wait for the nub thread
317 /*! Clears the debug info for the current thread.
318 Invoked with thread debug info lock being held.
453 Thread *thread = thread_get_current_thread();
454 Team *team = thread->team;
456 // If a debugger is installed for the team and the thread debug stuff
457 // initialized, change the ownership of the debug port for the thread
464 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
466 if ((thread->debug_info.flags & B_THREAD_DEBUG_INITIALIZED) != 0)
467 debugPort = thread->debug_info.debug_port;
481 Thread *thread = thread_get_current_thread();
482 Team *team = thread->team;
484 // If a debugger is installed for the team and the thread debug stuff
485 // initialized for this thread, change the ownership of its debug port
491 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
493 if (thread->debug_info.flags & B_THREAD_DEBUG_INITIALIZED)
494 debugPort = thread->debug_info.debug_port;
517 Thread *thread = thread_get_current_thread();
520 GRAB_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info);
522 memcpy(&teamDebugInfo, &thread->team->debug_info, sizeof(team_debug_info));
524 RELEASE_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info);
534 Thread *thread = thread_get_current_thread();
536 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", event: %" B_PRIu32
537 ", message: %p, size: %" B_PRId32 "\n", thread->id, (uint32)event,
541 bool setPort = !(atomic_get(&thread->debug_info.flags)
548 snprintf(nameBuffer, sizeof(nameBuffer), "nub to thread %" B_PRId32,
549 thread->id);
560 // the thread's debug port, and update the thread's debug flags
566 GRAB_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info);
567 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
569 uint32 threadFlags = thread->debug_info.flags;
572 = (thread->team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED);
573 if (thread->id == thread->team->debug_info.nub_thread) {
574 // Ugh, we're the nub thread. We shouldn't be here.
575 TRACE(("thread_hit_debug_event(): Misdirected nub thread: %" B_PRId32
576 "\n", thread->id));
581 debuggerPort = thread->team->debug_info.debugger_port;
582 nubPort = thread->team->debug_info.nub_port;
589 port = thread->debug_info.debug_port;
591 thread->debug_info.debug_port = port;
597 port = thread->debug_info.debug_port;
609 atomic_set(&thread->debug_info.flags, threadFlags);
611 update_thread_user_debug_flag(thread);
614 RELEASE_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info);
622 TRACE(("thread_hit_debug_event() error: thread: %" B_PRId32 ", error: "
623 "%" B_PRIx32 "\n", thread->id, error));
631 origin->thread = thread->id;
632 origin->team = thread->team->id;
635 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", sending "
636 "message to debugger port %" B_PRId32 "\n", thread->id,
657 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", failed "
659 thread->id, port, error));
665 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ": "
667 thread->id));
676 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ": "
678 thread->id));
719 // debugger is gone: continue the thread normally
729 TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", failed to send "
731 thread->id, debuggerPort, error));
734 // update the thread debug info
742 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
746 atomic_or(&thread->debug_info.flags,
748 atomic_or(&thread->flags, THREAD_FLAGS_SINGLE_STEP);
750 atomic_and(&thread->debug_info.flags,
755 atomic_and(&thread->debug_info.flags, ~B_THREAD_DEBUG_STOPPED);
757 update_thread_user_debug_flag(thread);
761 threadDebugInfo = thread->debug_info;
762 clear_thread_debug_info(&thread->debug_info, false);
819 Thread *thread = thread_get_current_thread();
821 "thread: %" B_PRId32 " (%s): %s\n", thread->id, thread->name,
835 Thread *thread = thread_get_current_thread();
836 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
840 // check whether pre-syscall tracing is enabled for team or thread
841 int32 threadDebugFlags = atomic_get(&thread->debug_info.flags);
867 Thread *thread = thread_get_current_thread();
868 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
872 // check whether post-syscall tracing is enabled for team or thread
873 int32 threadDebugFlags = atomic_get(&thread->debug_info.flags);
935 Thread *thread = thread_get_current_thread();
936 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
959 Thread* thread = thread_get_current_thread();
960 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
963 if ((atomic_and(&thread->debug_info.flags,
986 Thread *thread = thread_get_current_thread();
987 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
1010 message.origin.thread = -1;
1024 Thread *thread = thread_get_current_thread();
1025 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
1033 message.image_event = atomic_add(&thread->team->debug_info.image_event, 1)
1041 /*! Called by a new userland thread to update the debugging related flags of
1042 \c Thread::flags before the thread first enters userland.
1043 \param thread The calling thread.
1046 user_debug_update_new_thread_flags(Thread* thread)
1049 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1051 update_thread_user_debug_flag(thread);
1052 update_thread_breakpoints_flag(thread);
1053 update_thread_debugger_installed_flag(thread);
1060 // check, if a debugger is installed and is interested in thread events
1061 Thread *thread = thread_get_current_thread();
1062 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
1080 // Things are a bit complicated here, since this thread no longer belongs to
1097 // check, if a debugger is installed and is interested in thread events
1121 message.origin.thread = threadID;
1134 /*! Called for a thread that is about to die, cleaning up all user debug
1135 facilities installed for the thread.
1136 \param thread The current thread, the one that is going to die.
1139 user_debug_thread_exiting(Thread* thread)
1141 // thread is the current thread, so using team is safe
1142 Team* team = thread->team;
1159 // detach the profile info and mark the thread dying
1160 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1162 thread_debug_info& threadDebugInfo = thread->debug_info;
1183 message.origin.thread = thread->id;
1184 message.origin.team = thread->team->id;
1209 Thread *thread = thread_get_current_thread();
1210 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
1219 message.image_event = atomic_add(&thread->team->debug_info.image_event, 1)
1231 Thread *thread = thread_get_current_thread();
1232 int32 teamDebugFlags = atomic_get(&thread->team->debug_info.flags);
1241 message.image_event = atomic_add(&thread->team->debug_info.image_event, 1)
1276 // clear the single-step thread flag
1277 Thread* thread = thread_get_current_thread();
1278 atomic_and(&thread->flags, ~(int32)THREAD_FLAGS_SINGLE_STEP);
1289 /*! Schedules the profiling timer for the current thread.
1290 The caller must hold the thread's debug info lock.
1291 \param thread The current thread.
1295 schedule_profiling_timer(Thread* thread, bigtime_t interval)
1297 struct timer* timer = &sProfilingTimers[thread->cpu->cpu_num];
1298 thread->debug_info.profile.installed_timer = timer;
1299 thread->debug_info.profile.timer_end = system_time() + interval;
1304 /*! Samples the current thread's instruction pointer/stack trace.
1305 The caller must hold the current thread's debug info lock.
1312 Thread* thread = thread_get_current_thread();
1313 thread_debug_info& debugInfo = thread->debug_info;
1323 int32 imageEvent = thread->team->debug_info.image_event;
1394 Thread* thread = thread_get_current_thread();
1395 thread_debug_info& debugInfo = thread->debug_info;
1428 // do the sampling and reschedule timer, if still profiling this thread
1432 schedule_profiling_timer(thread, debugInfo.profile.interval);
1447 Thread* thread = thread_get_current_thread();
1448 thread_debug_info& debugInfo = thread->debug_info;
1459 thread->post_interrupt_callback = profiling_buffer_full;
1463 schedule_profiling_timer(thread, debugInfo.profile.interval);
1471 /*! Called by the scheduler when a debugged thread has been unscheduled.
1475 user_debug_thread_unscheduled(Thread* thread)
1477 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1480 struct timer* timer = thread->debug_info.profile.installed_timer;
1483 bigtime_t left = thread->debug_info.profile.timer_end - system_time();
1484 thread->debug_info.profile.interval_left = max_c(left, 0);
1485 thread->debug_info.profile.installed_timer = NULL;
1497 /*! Called by the scheduler when a debugged thread has been scheduled.
1501 user_debug_thread_scheduled(Thread* thread)
1503 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1505 if (thread->debug_info.profile.samples != NULL
1506 && !thread->debug_info.profile.buffer_full) {
1508 schedule_profiling_timer(thread,
1509 thread->debug_info.profile.interval_left);
1514 /*! \brief Called by the debug nub thread of a team to broadcast a message to
1527 // get the thread and lock it
1528 Thread* thread = Thread::GetAndLock(threadInfo.thread);
1529 if (thread == NULL)
1532 BReference<Thread> threadReference(thread, true);
1533 ThreadLocker threadLocker(thread, true);
1535 // get the thread's debug port
1536 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1539 if (thread && thread != nubThread && thread->team == nubThread->team
1540 && (thread->debug_info.flags & B_THREAD_DEBUG_INITIALIZED) != 0
1541 && (thread->debug_info.flags & B_THREAD_DEBUG_STOPPED) != 0) {
1542 threadDebugPort = thread->debug_info.debug_port;
1548 // send the message to the thread
1554 "message to thread %" B_PRId32 ": %" B_PRIx32 "\n",
1555 thread->id, error));
1589 // update the thread::flags fields
1611 /** \brief Debug nub thread helper function that returns the debug port of
1612 * a thread of the same team.
1620 // get the thread
1621 Thread* thread = Thread::GetAndLock(threadID);
1622 if (thread == NULL)
1624 BReference<Thread> threadReference(thread, true);
1625 ThreadLocker threadLocker(thread, true);
1628 InterruptsSpinLocker threadDebugInfoLocker(thread->debug_info.lock);
1630 if (thread->team != nubThread->team)
1632 if ((thread->debug_info.flags & B_THREAD_DEBUG_STOPPED) == 0)
1635 threadDebugPort = thread->debug_info.debug_port;
1651 // check, if we're still the current nub thread and get our port
1669 TRACE(("debug_nub_thread() thread: %" B_PRId32 ", team %" B_PRId32 ", nub "
1686 // thread, we need to update that.
1689 TRACE(("nub thread %" B_PRId32 ": terminating: %lx\n",
1735 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_READ_MEMORY: "
1771 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_WRITE_MEMORY: "
1788 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_TEAM_FLAGS"
1809 thread_id threadID = message.set_thread_flags.thread;
1813 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_THREAD_FLAGS"
1814 ": thread: %" B_PRId32 ", flags: %" B_PRIx32 "\n",
1818 Thread* thread = Thread::GetAndLock(threadID);
1819 if (thread == NULL)
1821 BReference<Thread> threadReference(thread, true);
1822 ThreadLocker threadLocker(thread, true);
1825 thread->debug_info.lock);
1827 if (thread->team == thread_get_current_thread()->team) {
1828 flags |= thread->debug_info.flags
1830 atomic_set(&thread->debug_info.flags, flags);
1843 threadID = message.continue_thread.thread;
1847 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CONTINUE_THREAD"
1848 ": thread: %" B_PRId32 ", handle event: %" B_PRIu32 ", "
1852 // find the thread and get its debug port
1857 // send a message to the debugged thread
1867 Thread* thread = Thread::GetAndLock(threadID);
1868 if (thread == NULL)
1871 BReference<Thread> threadReference(thread, true);
1872 ThreadLocker threadLocker(thread, true);
1873 if (thread->state == B_THREAD_SUSPENDED) {
1886 thread_id threadID = message.set_cpu_state.thread;
1890 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_CPU_STATE"
1891 ": thread: %" B_PRId32 "\n", nubThread->id, threadID));
1893 // find the thread and get its debug port
1898 // send a message to the debugged thread
1914 thread_id threadID = message.get_cpu_state.thread;
1917 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_CPU_STATE"
1918 ": thread: %" B_PRId32 "\n", nubThread->id, threadID));
1920 // find the thread and get its debug port
1925 // send a message to the debugged thread
1950 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_BREAKPOINT"
1980 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CLEAR_BREAKPOINT"
2008 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_WATCHPOINT"
2043 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CLEAR_WATCHPOINT"
2066 thread_id threadID = message.set_signal_masks.thread;
2072 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_SIGNAL_MASKS"
2073 ": thread: %" B_PRId32 ", ignore: %" B_PRIx64 " (op: %"
2079 Thread* thread = Thread::GetAndLock(threadID);
2080 if (thread == NULL)
2082 BReference<Thread> threadReference(thread, true);
2083 ThreadLocker threadLocker(thread, true);
2086 thread->debug_info.lock);
2088 if (thread->team == thread_get_current_thread()->team) {
2089 thread_debug_info &threadDebugInfo = thread->debug_info;
2124 thread_id threadID = message.get_signal_masks.thread;
2131 Thread* thread = Thread::GetAndLock(threadID);
2132 if (thread != NULL) {
2133 BReference<Thread> threadReference(thread, true);
2134 ThreadLocker threadLocker(thread, true);
2137 thread->debug_info.lock);
2139 ignore = thread->debug_info.ignore_signals;
2140 ignoreOnce = thread->debug_info.ignore_signals_once;
2144 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_SIGNAL_MASKS"
2145 ": reply port: %" B_PRId32 ", thread: %" B_PRId32 ", "
2165 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_SIGNAL_HANDLER"
2188 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_SIGNAL_HANDLER"
2202 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_PREPARE_HANDOVER"
2208 // have set the B_TEAM_DEBUG_DEBUGGER_HANDOVER flag, no thread
2249 thread_id threadID = message.start_profiler.thread;
2259 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_START_PROFILER: "
2260 "thread: %" B_PRId32 ", sample area: %" B_PRId32 "\n",
2297 // get the thread and set the profile info
2300 Thread* thread = Thread::GetAndLock(threadID);
2301 BReference<Thread> threadReference(thread, true);
2302 ThreadLocker threadLocker(thread, true);
2304 if (thread != NULL && thread->team == nubThread->team) {
2305 thread_debug_info &threadDebugInfo = thread->debug_info;
2359 thread_id threadID = message.stop_profiler.thread;
2363 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_STOP_PROFILER: "
2364 "thread: %" B_PRId32 "\n", nubThread->id, threadID));
2374 // get the thread and detach the profile info
2375 Thread* thread = Thread::GetAndLock(threadID);
2376 BReference<Thread> threadReference(thread, true);
2377 ThreadLocker threadLocker(thread, true);
2379 if (thread && thread->team == nubThread->team) {
2380 thread_debug_info &threadDebugInfo = thread->debug_info;
2407 reply.profiler_update.origin.thread = threadID;
2416 reply.profiler_update.origin.thread = result;
2439 TRACE(("nub thread %" B_PRId32 ": B_DEBUG_WRITE_CORE_FILE"
2462 TRACE(("nub thread %" B_PRId32 ": failed to send reply to port "
2475 and thread debug infos.
2479 The function also clears the arch specific team and thread debug infos
2499 for (Thread *thread = team->thread_list; thread;
2500 thread = thread->team_next) {
2501 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
2503 if (thread->id == nubThread) {
2504 atomic_set(&thread->debug_info.flags, B_THREAD_DEBUG_NUB_THREAD);
2506 int32 flags = thread->debug_info.flags
2508 atomic_set(&thread->debug_info.flags,
2510 thread->debug_info.ignore_signals = 0;
2511 thread->debug_info.ignore_signals_once = 0;
2513 arch_clear_thread_debug_info(&thread->debug_info.arch_info);
2517 // update the thread::flags fields
2634 notification.origin.thread = -1;
2663 // notify the nub thread
2723 // spawn the nub thread
2751 // if everything went fine, resume the nub thread, otherwise clean up
2755 // delete port and terminate thread
2904 // Delete the nub port -- this will cause the nub thread to terminate and
2911 // wait for the nub thread
2925 // get the thread
2926 Thread* thread = Thread::GetAndLock(threadID);
2927 if (thread == NULL)
2929 BReference<Thread> threadReference(thread, true);
2930 ThreadLocker threadLocker(thread, true);
2933 if (thread->team == team_get_kernel_team())
2937 SpinLocker threadDebugInfoLocker(thread->debug_info.lock);
2939 // If the thread is already dying, it's too late to debug it.
2940 if ((thread->debug_info.flags & B_THREAD_DEBUG_DYING) != 0)
2943 // don't debug the nub thread
2944 if ((thread->debug_info.flags & B_THREAD_DEBUG_NUB_THREAD) != 0)
2948 if ((thread->debug_info.flags
2953 // set the flag that tells the thread to stop as soon as possible
2954 atomic_or(&thread->debug_info.flags, B_THREAD_DEBUG_STOP);
2956 update_thread_user_debug_flag(thread);
2958 // send the thread a SIGNAL_DEBUG_THREAD, so it is interrupted (or
2961 ReadSpinLocker teamLocker(thread->team_lock);
2962 SpinLocker locker(thread->team->signal_lock);
2964 send_signal_to_thread_locked(thread, SIGNAL_DEBUG_THREAD, NULL, 0);