2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
13 #include "native_client/src/include/nacl_scoped_ptr.h"
14 #include "native_client/src/shared/platform/nacl_check.h"
15 #include "native_client/src/shared/platform/nacl_log.h"
16 #include "native_client/src/trusted/debug_stub/abi.h"
17 #include "native_client/src/trusted/debug_stub/packet.h"
18 #include "native_client/src/trusted/debug_stub/platform.h"
19 #include "native_client/src/trusted/debug_stub/session.h"
20 #include "native_client/src/trusted/debug_stub/target.h"
21 #include "native_client/src/trusted/debug_stub/thread.h"
22 #include "native_client/src/trusted/debug_stub/util.h"
23 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
24 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
25 #include "native_client/src/trusted/service_runtime/thread_suspension.h"
28 #define snprintf sprintf_s
33 using port::IPlatform;
35 using port::MutexLock;
40 Target::Target(struct NaClApp *nap, const Abi* abi)
44 initial_breakpoint_addr_(0),
49 step_over_breakpoint_thread_(0) {
50 if (NULL == abi_) abi_ = Abi::Get();
58 string targ_xml = "l<target><architecture>";
60 targ_xml += abi_->GetName();
61 targ_xml += "</architecture><osabi>NaCl</osabi>";
62 targ_xml += abi_->GetTargetXml();
63 targ_xml += "</target>";
65 // Set a more specific result which won't change.
66 properties_["target.xml"] = targ_xml;
67 properties_["Supported"] =
68 "PacketSize=1000;qXfer:features:read+";
70 NaClXMutexCtor(&mutex_);
71 ctx_ = new uint8_t[abi_->GetContextSize()];
73 initial_breakpoint_addr_ = (uint32_t) nap_->initial_entry_pt;
74 if (!AddBreakpoint(initial_breakpoint_addr_))
79 void Target::Destroy() {
80 NaClMutexDtor(&mutex_);
85 bool Target::AddBreakpoint(uint32_t user_address) {
86 const Abi::BPDef *bp = abi_->GetBreakpointDef();
88 // If we already have a breakpoint here then don't add it
89 if (breakpoint_map_.find(user_address) != breakpoint_map_.end())
92 uintptr_t sysaddr = NaClUserToSysAddrRange(nap_, user_address, bp->size_);
93 if (sysaddr == kNaClBadAddress)
95 // We allow setting breakpoints in the code area but not the data area.
96 if (user_address + bp->size_ > nap_->dynamic_text_end)
99 // We add the breakpoint by overwriting the start of an instruction
100 // with a breakpoint instruction. (At least, we assume that we have
101 // been given the address of the start of an instruction.) In order
102 // to be able to remove the breakpoint later, we save a copy of the
103 // locations we are overwriting into breakpoint_map_.
104 uint8_t *data = new uint8_t[bp->size_];
106 // Copy the old code from here
107 if (!IPlatform::GetMemory(sysaddr, bp->size_, data)) {
111 if (!IPlatform::SetMemory(nap_, sysaddr, bp->size_, bp->code_)) {
116 breakpoint_map_[user_address] = data;
120 bool Target::RemoveBreakpoint(uint32_t user_address) {
121 const Abi::BPDef *bp_def = abi_->GetBreakpointDef();
123 BreakpointMap_t::iterator iter = breakpoint_map_.find(user_address);
124 if (iter == breakpoint_map_.end())
127 uintptr_t sysaddr = NaClUserToSys(nap_, user_address);
128 uint8_t *data = iter->second;
129 // Copy back the old code, and free the data
130 if (!IPlatform::SetMemory(nap_, sysaddr, bp_def->size_, data)) {
131 NaClLog(LOG_ERROR, "Failed to undo breakpoint.\n");
135 breakpoint_map_.erase(iter);
139 void Target::CopyFaultSignalFromAppThread(IThread *thread) {
140 if (thread->GetFaultSignal() == 0 && thread->HasThreadFaulted()) {
142 IThread::ExceptionToSignal(thread->GetAppThread()->fault_signal);
143 // If a thread hits a breakpoint, we want to ensure that it is
144 // reported as SIGTRAP rather than SIGSEGV. This is necessary
145 // because we use HLT (which produces SIGSEGV) rather than the
146 // more usual INT3 (which produces SIGTRAP) on x86, in order to
147 // work around a Mac OS X bug.
149 // We need to check each thread to see whether it hit a
150 // breakpoint. We record this on the thread object because:
151 // * We need to check the threads before accepting any commands
152 // from GDB which might remove breakpoints from
153 // breakpoint_map_, which would remove our ability to tell
154 // whether a thread hit a breakpoint.
155 // * Although we deliver fault events to GDB one by one, we might
156 // have multiple threads that have hit breakpoints.
157 if (signal == NACL_ABI_SIGSEGV) {
158 // Casting to uint32_t is necessary to drop the top 32 bits of
160 uint32_t prog_ctr = (uint32_t) thread->GetContext()->prog_ctr;
161 if (breakpoint_map_.find(prog_ctr) != breakpoint_map_.end()) {
162 signal = NACL_ABI_SIGTRAP;
165 thread->SetFaultSignal(signal);
169 void Target::RemoveInitialBreakpoint() {
170 if (initial_breakpoint_addr_ != 0) {
171 if (!RemoveBreakpoint(initial_breakpoint_addr_)) {
173 "RemoveInitialBreakpoint: Failed to remove breakpoint\n");
175 initial_breakpoint_addr_ = 0;
179 // When the debugger reads memory, we want to report the original
180 // memory contents without the modifications we made to add
181 // breakpoints. This function undoes the modifications from a copy of
183 void Target::EraseBreakpointsFromCopyOfMemory(uint32_t user_address,
184 uint8_t *data, uint32_t size) {
185 uint32_t user_end = user_address + size;
186 const Abi::BPDef *bp = abi_->GetBreakpointDef();
187 for (BreakpointMap_t::iterator iter = breakpoint_map_.begin();
188 iter != breakpoint_map_.end();
190 uint32_t breakpoint_address = iter->first;
191 uint32_t breakpoint_end = breakpoint_address + bp->size_;
192 uint8_t *original_data = iter->second;
194 uint32_t overlap_start = std::max(user_address, breakpoint_address);
195 uint32_t overlap_end = std::min(user_end, breakpoint_end);
196 if (overlap_start < overlap_end) {
197 uint8_t *dest = data + (overlap_start - user_address);
198 uint8_t *src = original_data + (overlap_start - breakpoint_address);
199 size_t copy_size = overlap_end - overlap_start;
200 // Sanity check: do some bounds checks.
201 CHECK(data <= dest && dest + copy_size <= data + size);
202 CHECK(original_data <= src
203 && src + copy_size <= original_data + bp->size_);
204 memcpy(dest, src, copy_size);
209 void Target::Run(Session *ses) {
210 bool initial_breakpoint_seen = false;
211 NaClXMutexLock(&mutex_);
213 NaClXMutexUnlock(&mutex_);
215 bool ignore_input_from_gdb = step_over_breakpoint_thread_ != 0 ||
216 !initial_breakpoint_seen;
217 ses->WaitForDebugStubEvent(nap_, ignore_input_from_gdb);
219 // Lock to prevent anyone else from modifying threads
220 // or updating the signal information.
221 MutexLock lock(&mutex_);
224 if (step_over_breakpoint_thread_ != 0) {
225 // We are waiting for a specific thread to fault while all other
226 // threads are suspended. Note that faulted_thread_count might
227 // be >1, because multiple threads can fault simultaneously
228 // before the debug stub gets a chance to suspend all threads.
229 // This is why we must check the status of a specific thread --
230 // we cannot call UnqueueAnyFaultedThread() and expect it to
231 // return step_over_breakpoint_thread_.
232 IThread *thread = threads_[step_over_breakpoint_thread_];
233 if (!thread->HasThreadFaulted()) {
234 // The thread has not faulted. Nothing to do, so try again.
235 // Note that we do not respond to input from GDB while in this
237 // TODO(mseaborn): We should allow GDB to interrupt execution.
240 // All threads but one are already suspended. We only need to
241 // suspend the single thread that we allowed to run.
242 thread->SuspendThread();
243 CopyFaultSignalFromAppThread(thread);
244 cur_signal_ = thread->GetFaultSignal();
245 thread->UnqueueFaultedThread();
246 sig_thread_ = step_over_breakpoint_thread_;
247 reg_thread_ = step_over_breakpoint_thread_;
248 step_over_breakpoint_thread_ = 0;
249 } else if (nap_->faulted_thread_count != 0) {
250 // At least one untrusted thread has got an exception. First we
251 // need to ensure that all threads are suspended. Then we can
252 // retrieve a thread from the set of faulted threads.
254 UnqueueAnyFaultedThread(&sig_thread_, &cur_signal_);
255 reg_thread_ = sig_thread_;
257 // Otherwise look for messages from GDB. To fix a potential
258 // race condition, we don't do this on the first run, because in
259 // that case we are waiting for the initial breakpoint to be
260 // reached. We don't want GDB to observe states where the
261 // (internal) initial breakpoint is still registered or where
262 // the initial thread is suspended in NaClStartThreadInApp()
263 // before executing its first untrusted instruction.
264 if (!initial_breakpoint_seen || !ses->IsDataAvailable()) {
265 // No input from GDB. Nothing to do, so try again.
268 // GDB should have tried to interrupt the target.
269 // See http://sourceware.org/gdb/current/onlinedocs/gdb/Interrupts.html
270 // TODO(eaeltsin): should we verify the interrupt sequence?
272 // Indicate we have no current thread.
273 // TODO(eaeltsin): or pick any thread? Add a test.
274 // See http://code.google.com/p/nativeclient/issues/detail?id=2743
279 if (sig_thread_ != 0) {
280 // Reset single stepping.
281 threads_[sig_thread_]->SetStep(false);
282 RemoveInitialBreakpoint();
285 // Next update the current thread info
287 snprintf(tmp, sizeof(tmp), "QC%x", sig_thread_);
288 properties_["C"] = tmp;
290 if (!initial_breakpoint_seen) {
291 // First time on a connection, we don't send the signal
292 initial_breakpoint_seen = true;
294 // All other times, send the signal that triggered us
296 SetStopReply(&pktOut);
297 ses->SendPacketOnly(&pktOut);
300 // Now we are ready to process commands
301 // Loop through packets until we process a continue
304 if (ses->GetPacket(&recv)) {
306 if (ProcessPacket(&recv, &reply)) {
307 // If this is a continue command, break out of this loop
310 // Othwerise send the reponse
311 ses->SendPacket(&reply);
314 } while (ses->Connected());
316 // Reset the signal value
319 // TODO(eaeltsin): it might make sense to resume signaled thread before
320 // others, though it is not required by GDB docs.
321 if (step_over_breakpoint_thread_ == 0) {
324 // Resume one thread while leaving all others suspended.
325 threads_[step_over_breakpoint_thread_]->ResumeThread();
328 // Continue running until the connection is lost.
329 } while (ses->Connected());
330 NaClXMutexLock(&mutex_);
332 NaClXMutexUnlock(&mutex_);
336 void Target::SetStopReply(Packet *pktOut) const {
337 pktOut->AddRawChar('T');
338 pktOut->AddWord8(cur_signal_);
340 // gdbserver handles GDB interrupt by sending SIGINT to the debuggee, thus
341 // GDB interrupt is also a case of a signalled thread.
342 // At the moment we handle GDB interrupt differently, without using a signal,
343 // so in this case sig_thread_ is 0.
344 // This might seem weird to GDB, so at least avoid reporting tid 0.
345 // TODO(eaeltsin): http://code.google.com/p/nativeclient/issues/detail?id=2743
346 if (sig_thread_ != 0) {
347 // Add 'thread:<tid>;' pair. Note terminating ';' is required.
348 pktOut->AddString("thread:");
349 pktOut->AddNumberSep(sig_thread_, ';');
354 bool Target::GetFirstThreadId(uint32_t *id) {
355 threadItr_ = threads_.begin();
356 return GetNextThreadId(id);
359 bool Target::GetNextThreadId(uint32_t *id) {
360 if (threadItr_ == threads_.end()) return false;
362 *id = (*threadItr_).first;
369 uint64_t Target::AdjustUserAddr(uint64_t addr) {
370 // On x86-64, GDB sometimes uses memory addresses with the %r15
371 // sandbox base included, so we must accept these addresses.
372 // TODO(eaeltsin): Fix GDB to not use addresses with %r15 added.
373 if (NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64 &&
374 NaClIsUserAddr(nap_, (uintptr_t) addr)) {
375 return NaClSysToUser(nap_, (uintptr_t) addr);
377 // Otherwise, we expect an untrusted address.
381 bool Target::ProcessPacket(Packet* pktIn, Packet* pktOut) {
386 // Clear the outbound message
389 // Pull out the sequence.
390 pktIn->GetSequence(&seq);
391 if (seq != -1) pktOut->SetSequence(seq);
394 pktIn->GetRawChar(&cmd);
400 SetStopReply(pktOut);
415 IThread *thread = GetRegThread();
416 if (NULL == thread) {
421 // Copy OS preserved registers to GDB payload
422 for (uint32_t a = 0; a < abi_->GetRegisterCount(); a++) {
423 const Abi::RegDef *def = abi_->GetRegisterDef(a);
424 thread->GetRegister(a, &ctx_[def->offset_], def->bytes_);
427 pktOut->AddBlock(ctx_, abi_->GetContextSize());
434 IThread *thread = GetRegThread();
435 if (NULL == thread) {
440 pktIn->GetBlock(ctx_, abi_->GetContextSize());
442 // GDB payload to OS registers
443 for (uint32_t a = 0; a < abi_->GetRegisterCount(); a++) {
444 const Abi::RegDef *def = abi_->GetRegisterDef(a);
445 thread->SetRegister(a, &ctx_[def->offset_], def->bytes_);
448 pktOut->AddString("OK");
452 // IN : $H(c/g)(-1,0,xxxx)
458 if (!pktIn->GetRawChar(&type)) {
462 if (!pktIn->GetNumberSep(&id, 0)) {
467 if (threads_.begin() == threads_.end()) {
472 // If we are using "any" get the first thread
473 if (id == static_cast<uint64_t>(-1)) id = threads_.begin()->first;
475 // Verify that we have the thread
476 if (threads_.find(static_cast<uint32_t>(id)) == threads_.end()) {
481 pktOut->AddString("OK");
484 reg_thread_ = static_cast<uint32_t>(id);
488 // 'c' is deprecated in favor of vCont.
502 if (!pktIn->GetNumberSep(&user_addr, 0)) {
506 if (!pktIn->GetNumberSep(&wlen, 0)) {
510 user_addr = AdjustUserAddr(user_addr);
511 uint64_t sys_addr = NaClUserToSysAddrRange(nap_, (uintptr_t) user_addr,
513 if (sys_addr == kNaClBadAddress) {
518 len = static_cast<uint32_t>(wlen);
519 nacl::scoped_array<uint8_t> block(new uint8_t[len]);
520 if (!port::IPlatform::GetMemory(sys_addr, len, block.get())) {
524 EraseBreakpointsFromCopyOfMemory((uint32_t) user_addr,
527 pktOut->AddBlock(block.get(), len);
531 // IN : $Maaaa,llll:xx..xx
538 if (!pktIn->GetNumberSep(&user_addr, 0)) {
542 if (!pktIn->GetNumberSep(&wlen, 0)) {
546 user_addr = AdjustUserAddr(user_addr);
547 uint64_t sys_addr = NaClUserToSysAddrRange(nap_, (uintptr_t) user_addr,
549 if (sys_addr == kNaClBadAddress) {
553 len = static_cast<uint32_t>(wlen);
554 // We disallow the debugger from modifying code.
555 if (user_addr < nap_->dynamic_text_end) {
560 nacl::scoped_array<uint8_t> block(new uint8_t[len]);
561 pktIn->GetBlock(block.get(), len);
563 if (!port::IPlatform::SetMemory(nap_, sys_addr, len, block.get())) {
568 pktOut->AddString("OK");
574 const char *str = &pktIn->GetPayload()[1];
575 stringvec toks = StringSplit(str, ":;");
576 PropertyMap_t::const_iterator itr = properties_.find(toks[0]);
578 // If this is a thread query
579 if (!strcmp(str, "fThreadInfo") || !strcmp(str, "sThreadInfo")) {
583 more = GetFirstThreadId(&curr);
585 more = GetNextThreadId(&curr);
589 pktOut->AddString("l");
591 pktOut->AddString("m");
592 pktOut->AddNumberSep(curr, 0);
597 // Check for architecture query
598 tmp = "Xfer:features:read:target.xml";
599 if (!strncmp(str, tmp.data(), tmp.length())) {
600 stringvec args = StringSplit(&str[tmp.length()+1], ",");
601 if (args.size() != 2) break;
603 const char *out = properties_["target.xml"].data();
604 int offs = strtol(args[0].data(), NULL, 16);
605 int max = strtol(args[1].data(), NULL, 16) + offs;
606 int len = static_cast<int>(strlen(out));
608 if (max >= len) max = len;
611 pktOut->AddRawChar(out[offs]);
617 // Check the property cache
618 if (itr != properties_.end()) {
619 pktOut->AddString(itr->second.data());
625 IThread *thread = GetRunThread();
626 if (thread) thread->SetStep(true);
632 if (!pktIn->GetNumberSep(&id, 0)) {
637 if (GetThread(static_cast<uint32_t>(id)) == NULL) {
642 pktOut->AddString("OK");
647 const char *str = pktIn->GetPayload() + 1;
649 if (strncmp(str, "Cont", 4) == 0) {
651 const char *subcommand = str + 4;
653 if (strcmp(subcommand, "?") == 0) {
654 // Report supported vCont actions. These 4 are required.
655 pktOut->AddString("vCont;s;S;c;C");
659 if (strcmp(subcommand, ";c") == 0) {
660 // Continue all threads.
664 if (strncmp(subcommand, ";s:", 3) == 0) {
665 // Single step one thread and optionally continue all other threads.
667 uint32_t thread_id = static_cast<uint32_t>(
668 strtol(subcommand + 3, &end, 16));
669 if (end == subcommand + 3) {
674 ThreadMap_t::iterator it = threads_.find(thread_id);
675 if (it == threads_.end()) {
681 // Single step one thread and keep other threads stopped.
682 // GDB uses this to continue from a breakpoint, which works by:
683 // - replacing trap instruction with the original instruction;
684 // - single-stepping through the original instruction. Other threads
685 // must remain stopped, otherwise they might execute the code at
686 // the same address and thus miss the breakpoint;
687 // - replacing the original instruction with trap instruction;
688 // - continuing all threads;
689 if (thread_id != sig_thread_) {
693 step_over_breakpoint_thread_ = sig_thread_;
694 } else if (strcmp(end, ";c") == 0) {
695 // Single step one thread and continue all other threads.
697 // Unsupported combination of single step and other args.
702 it->second->SetStep(true);
706 // Continue one thread and keep other threads stopped.
708 // GDB sends this for software single step, which is used:
709 // - on Win64 to step over rsp modification and subsequent rsp
710 // sandboxing at once. For details, see:
711 // http://code.google.com/p/nativeclient/issues/detail?id=2903
712 // - TODO: on ARM, which has no hardware support for single step
713 // - TODO: to step over syscalls
715 // Unfortunately, we can't make this just Win-specific. We might
716 // use Linux GDB to connect to Win debug stub, so even Linux GDB
717 // should send software single step. Vice versa, software single
718 // step-enabled Win GDB might be connected to Linux debug stub,
719 // so even Linux debug stub should accept software single step.
720 if (strncmp(subcommand, ";c:", 3) == 0) {
722 uint32_t thread_id = static_cast<uint32_t>(
723 strtol(subcommand + 3, &end, 16));
724 if (end != subcommand + 3 && *end == 0) {
725 if (thread_id == sig_thread_) {
726 step_over_breakpoint_thread_ = sig_thread_;
735 // Unsupported form of vCont.
740 NaClLog(LOG_ERROR, "Unknown command: %s\n", pktIn->GetPayload());
745 uint64_t breakpoint_type;
746 uint64_t breakpoint_address;
747 uint64_t breakpoint_kind;
748 if (!pktIn->GetNumberSep(&breakpoint_type, 0) ||
749 breakpoint_type != 0 ||
750 !pktIn->GetNumberSep(&breakpoint_address, 0) ||
751 !pktIn->GetNumberSep(&breakpoint_kind, 0)) {
755 if (breakpoint_address != (uint32_t) breakpoint_address ||
756 !AddBreakpoint((uint32_t) breakpoint_address)) {
760 pktOut->AddString("OK");
765 uint64_t breakpoint_type;
766 uint64_t breakpoint_address;
767 uint64_t breakpoint_kind;
768 if (!pktIn->GetNumberSep(&breakpoint_type, 0) ||
769 breakpoint_type != 0 ||
770 !pktIn->GetNumberSep(&breakpoint_address, 0) ||
771 !pktIn->GetNumberSep(&breakpoint_kind, 0)) {
775 if (breakpoint_address != (uint32_t) breakpoint_address ||
776 !RemoveBreakpoint((uint32_t) breakpoint_address)) {
780 pktOut->AddString("OK");
785 // If the command is not recognzied, ignore it by sending an
788 pktIn->GetString(&str);
789 NaClLog(LOG_ERROR, "Unknown command: %s\n", pktIn->GetPayload());
794 // If there is an error, return the error code instead of a payload
797 pktOut->AddRawChar('E');
798 pktOut->AddWord8(err);
804 void Target::TrackThread(struct NaClAppThread *natp) {
805 // natp->thread_num values are 0-based indexes, but we treat 0 as
806 // "not a thread ID", so we add 1.
807 uint32_t id = natp->thread_num + 1;
808 MutexLock lock(&mutex_);
809 CHECK(threads_[id] == 0);
810 threads_[id] = IThread::Create(id, natp);
813 void Target::IgnoreThread(struct NaClAppThread *natp) {
814 uint32_t id = natp->thread_num + 1;
815 MutexLock lock(&mutex_);
816 ThreadMap_t::iterator iter = threads_.find(id);
817 CHECK(iter != threads_.end());
819 threads_.erase(iter);
822 void Target::Exit() {
823 MutexLock lock(&mutex_);
824 if (session_ != NULL) {
826 if (NACL_ABI_WIFSIGNALED(nap_->exit_status)) {
827 exit_packet.AddRawChar('X');
828 exit_packet.AddWord8(NACL_ABI_WTERMSIG(nap_->exit_status));
830 exit_packet.AddRawChar('W');
831 exit_packet.AddWord8(NACL_ABI_WEXITSTATUS(nap_->exit_status));
833 session_->SendPacket(&exit_packet);
837 void Target::Detach() {
838 NaClLog(LOG_INFO, "Requested Detach.\n");
842 IThread* Target::GetRegThread() {
843 ThreadMap_t::const_iterator itr;
845 switch (reg_thread_) {
846 // If we want "any" then try the signal'd thread first
849 itr = threads_.begin();
853 itr = threads_.find(reg_thread_);
857 if (itr == threads_.end()) return 0;
862 IThread* Target::GetRunThread() {
863 // This is used to select a thread for "s" (step) command only.
864 // For multi-threaded targets, "s" is deprecated in favor of "vCont", which
865 // always specifies the thread explicitly when needed. However, we want
866 // to keep backward compatibility here, as using "s" when debugging
867 // a single-threaded program might be a popular use case.
868 if (threads_.size() == 1) {
869 return threads_.begin()->second;
874 IThread* Target::GetThread(uint32_t id) {
875 ThreadMap_t::const_iterator itr;
876 itr = threads_.find(id);
877 if (itr != threads_.end()) return itr->second;
882 void Target::SuspendAllThreads() {
883 NaClUntrustedThreadsSuspendAll(nap_, /* save_registers= */ 1);
884 for (ThreadMap_t::const_iterator iter = threads_.begin();
885 iter != threads_.end();
887 IThread *thread = iter->second;
888 thread->CopyRegistersFromAppThread();
889 CopyFaultSignalFromAppThread(thread);
893 void Target::ResumeAllThreads() {
894 for (ThreadMap_t::const_iterator iter = threads_.begin();
895 iter != threads_.end();
897 iter->second->CopyRegistersToAppThread();
899 NaClUntrustedThreadsResumeAll(nap_);
902 // UnqueueAnyFaultedThread() picks a thread that has been blocked as a
903 // result of faulting and unblocks it. It returns the thread's ID via
904 // |thread_id| and the type of fault via |signal|. As a precondition,
905 // all threads must be currently suspended.
906 void Target::UnqueueAnyFaultedThread(uint32_t *thread_id, int8_t *signal) {
907 for (ThreadMap_t::const_iterator iter = threads_.begin();
908 iter != threads_.end();
910 IThread *thread = iter->second;
911 if (thread->GetFaultSignal() != 0) {
912 *signal = thread->GetFaultSignal();
913 *thread_id = thread->GetId();
914 thread->UnqueueFaultedThread();
918 NaClLog(LOG_FATAL, "UnqueueAnyFaultedThread: No threads queued\n");
921 } // namespace gdb_rsp