Ignore:
Timestamp:
2010-01-23T14:25:32Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a074b4f
Parents:
9d3133d
Message:

Fix THREAD_READ, add AREAS_READ Udebug method. Add task dump utility.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/udebug/udebug_ops.c

    r9d3133d r336db295  
    355355 *
    356356 * If the sequence is longer than @a buf_size bytes, only as much hashes
    357  * as can fit are copied. The number of thread hashes copied is stored
    358  * in @a n.
     357 * as can fit are copied. The number of bytes copied is stored in @a stored.
     358 * The total number of thread bytes that could have been saved had there been
     359 * enough space is stored in @a needed.
    359360 *
    360361 * The rationale for having @a buf_size is that this function is only
     
    364365 * @param buffer        The buffer for storing thread hashes.
    365366 * @param buf_size      Buffer size in bytes.
    366  * @param n             The actual number of hashes copied will be stored here.
    367  */
    368 int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
     367 * @param stored        The actual number of bytes copied will be stored here.
     368 * @param needed        Total number of hashes that could have been saved.
     369 */
     370int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored,
     371    size_t *needed)
    369372{
    370373        thread_t *t;
    371374        link_t *cur;
    372375        unative_t tid;
    373         unsigned copied_ids;
     376        size_t copied_ids;
     377        size_t extra_ids;
    374378        ipl_t ipl;
    375379        unative_t *id_buffer;
     
    380384
    381385        /* Allocate a buffer to hold thread IDs */
    382         id_buffer = malloc(buf_size, 0);
     386        id_buffer = malloc(buf_size + 1, 0);
    383387
    384388        mutex_lock(&TASK->udebug.lock);
     
    396400        max_ids = buf_size / sizeof(unative_t);
    397401        copied_ids = 0;
     402        extra_ids = 0;
    398403
    399404        /* FIXME: make sure the thread isn't past debug shutdown... */
    400405        for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
    401                 /* Do not write past end of buffer */
    402                 if (copied_ids >= max_ids) break;
    403 
    404406                t = list_get_instance(cur, thread_t, th_link);
    405407
     
    409411
    410412                /* Not interested in kernel threads. */
    411                 if ((flags & THREAD_FLAG_USPACE) != 0) {
     413                if ((flags & THREAD_FLAG_USPACE) == 0)
     414                        continue;
     415
     416                if (copied_ids < max_ids) {
    412417                        /* Using thread struct pointer as identification hash */
    413418                        tid = (unative_t) t;
    414419                        id_buffer[copied_ids++] = tid;
     420                } else {
     421                        extra_ids++;
    415422                }
    416423        }
     
    422429
    423430        *buffer = id_buffer;
    424         *n = copied_ids * sizeof(unative_t);
     431        *stored = copied_ids * sizeof(unative_t);
     432        *needed = (copied_ids + extra_ids) * sizeof(unative_t);
    425433
    426434        return 0;
Note: See TracChangeset for help on using the changeset viewer.