tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

prdump.c (2954B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "primpl.h"
      7 
      8 #if defined(WIN95)
      9 /*
     10 ** Some local variables report warnings on Win95 because the code paths
     11 ** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
     12 ** The pragma suppresses the warning.
     13 **
     14 */
     15 #  pragma warning(disable : 4101)
     16 #endif
     17 
     18 /* XXX use unbuffered nspr stdio */
     19 
     20 PRFileDesc* _pr_dumpOut;
     21 
     22 PRUint32 _PR_DumpPrintf(PRFileDesc* fd, const char* fmt, ...) {
     23  char buf[100];
     24  PRUint32 nb;
     25  va_list ap;
     26 
     27  va_start(ap, fmt);
     28  nb = PR_vsnprintf(buf, sizeof(buf), fmt, ap);
     29  va_end(ap);
     30  PR_Write(fd, buf, nb);
     31 
     32  return nb;
     33 }
     34 
     35 void _PR_DumpThread(PRFileDesc* fd, PRThread* thread) {
     36 #ifndef _PR_GLOBAL_THREADS_ONLY
     37  _PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x", thread->id, thread,
     38                 thread->priority, thread->flags);
     39  switch (thread->state) {
     40    case _PR_RUNNABLE:
     41    case _PR_RUNNING:
     42      break;
     43    case _PR_LOCK_WAIT:
     44      _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
     45      break;
     46    case _PR_COND_WAIT:
     47      _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms", thread->wait.cvar,
     48                     thread->sleep);
     49      break;
     50    case _PR_SUSPENDED:
     51      _PR_DumpPrintf(fd, " suspended");
     52      break;
     53  }
     54  PR_Write(fd, "\n", 1);
     55 #endif
     56 
     57  /* Now call dump routine */
     58  if (thread->dump) {
     59    thread->dump(fd, thread, thread->dumpArg);
     60  }
     61 }
     62 
     63 static void DumpThreadQueue(PRFileDesc* fd, PRCList* list) {
     64 #ifndef _PR_GLOBAL_THREADS_ONLY
     65  PRCList* q;
     66 
     67  q = list->next;
     68  while (q != list) {
     69    PRThread* t = _PR_THREAD_PTR(q);
     70    _PR_DumpThread(fd, t);
     71    q = q->next;
     72  }
     73 #endif
     74 }
     75 
     76 void _PR_DumpThreads(PRFileDesc* fd) {
     77  PRThread* t;
     78  PRIntn i;
     79 
     80  _PR_DumpPrintf(fd, "Current Thread:\n");
     81  t = _PR_MD_CURRENT_THREAD();
     82  _PR_DumpThread(fd, t);
     83 
     84  _PR_DumpPrintf(fd, "Runnable Threads:\n");
     85  for (i = 0; i < PR_ARRAY_SIZE(_PR_RUNQ(t->cpu)); i++) {
     86    DumpThreadQueue(fd, &_PR_RUNQ(t->cpu)[i]);
     87  }
     88 
     89  _PR_DumpPrintf(fd, "CondVar timed wait Threads:\n");
     90  DumpThreadQueue(fd, &_PR_SLEEPQ(t->cpu));
     91 
     92  _PR_DumpPrintf(fd, "CondVar wait Threads:\n");
     93  DumpThreadQueue(fd, &_PR_PAUSEQ(t->cpu));
     94 
     95  _PR_DumpPrintf(fd, "Suspended Threads:\n");
     96  DumpThreadQueue(fd, &_PR_SUSPENDQ(t->cpu));
     97 }
     98 
     99 PR_IMPLEMENT(void) PR_ShowStatus(void) {
    100  PRIntn is;
    101 
    102  if (_PR_MD_CURRENT_THREAD() &&
    103      !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
    104    _PR_INTSOFF(is);
    105  }
    106  _pr_dumpOut = _pr_stderr;
    107  _PR_DumpThreads(_pr_dumpOut);
    108  if (_PR_MD_CURRENT_THREAD() &&
    109      !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
    110    _PR_FAST_INTSON(is);
    111  }
    112 }
    113 
    114 PR_IMPLEMENT(void)
    115 PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void* arg) {
    116  thread->dump = dump;
    117  thread->dumpArg = arg;
    118 }