Ignore:
Timestamp:
2010-02-05T10:57:50Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0358da0
Parents:
3f085132 (diff), b4cbef1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merged with head

File:
1 edited

Legend:

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

    r3f085132 r3b3e776  
    4646#include <errno.h>
    4747#include <print.h>
     48#include <string.h>
    4849#include <syscall/copy.h>
    4950#include <ipc/ipc.h>
    5051#include <udebug/udebug.h>
    5152#include <udebug/udebug_ops.h>
     53#include <memstr.h>
    5254
    5355/**
     
    208210
    209211                mutex_lock(&t->udebug.lock);
    210                 if ((t->flags & THREAD_FLAG_USPACE) != 0)
     212                if ((t->flags & THREAD_FLAG_USPACE) != 0) {
    211213                        t->udebug.active = true;
    212                 mutex_unlock(&t->udebug.lock);
     214                        mutex_unlock(&t->udebug.lock);
     215                        condvar_broadcast(&t->udebug.active_cv);
     216                } else {
     217                        mutex_unlock(&t->udebug.lock);
     218                }
    213219        }
    214220
     
    354360 *
    355361 * If the sequence is longer than @a buf_size bytes, only as much hashes
    356  * as can fit are copied. The number of thread hashes copied is stored
    357  * in @a n.
     362 * as can fit are copied. The number of bytes copied is stored in @a stored.
     363 * The total number of thread bytes that could have been saved had there been
     364 * enough space is stored in @a needed.
    358365 *
    359366 * The rationale for having @a buf_size is that this function is only
     
    363370 * @param buffer        The buffer for storing thread hashes.
    364371 * @param buf_size      Buffer size in bytes.
    365  * @param n             The actual number of hashes copied will be stored here.
    366  */
    367 int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
     372 * @param stored        The actual number of bytes copied will be stored here.
     373 * @param needed        Total number of hashes that could have been saved.
     374 */
     375int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored,
     376    size_t *needed)
    368377{
    369378        thread_t *t;
    370379        link_t *cur;
    371380        unative_t tid;
    372         unsigned copied_ids;
     381        size_t copied_ids;
     382        size_t extra_ids;
    373383        ipl_t ipl;
    374384        unative_t *id_buffer;
     
    379389
    380390        /* Allocate a buffer to hold thread IDs */
    381         id_buffer = malloc(buf_size, 0);
     391        id_buffer = malloc(buf_size + 1, 0);
    382392
    383393        mutex_lock(&TASK->udebug.lock);
     
    395405        max_ids = buf_size / sizeof(unative_t);
    396406        copied_ids = 0;
     407        extra_ids = 0;
    397408
    398409        /* FIXME: make sure the thread isn't past debug shutdown... */
    399410        for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
    400                 /* Do not write past end of buffer */
    401                 if (copied_ids >= max_ids) break;
    402 
    403411                t = list_get_instance(cur, thread_t, th_link);
    404412
     
    408416
    409417                /* Not interested in kernel threads. */
    410                 if ((flags & THREAD_FLAG_USPACE) != 0) {
     418                if ((flags & THREAD_FLAG_USPACE) == 0)
     419                        continue;
     420
     421                if (copied_ids < max_ids) {
    411422                        /* Using thread struct pointer as identification hash */
    412423                        tid = (unative_t) t;
    413424                        id_buffer[copied_ids++] = tid;
     425                } else {
     426                        extra_ids++;
    414427                }
    415428        }
     
    421434
    422435        *buffer = id_buffer;
    423         *n = copied_ids * sizeof(unative_t);
     436        *stored = copied_ids * sizeof(unative_t);
     437        *needed = (copied_ids + extra_ids) * sizeof(unative_t);
     438
     439        return 0;
     440}
     441
     442/** Read task name.
     443 *
     444 * Returns task name as non-terminated string in a newly allocated buffer.
     445 * Also returns the size of the data.
     446 *
     447 * @param data          Place to store pointer to newly allocated block.
     448 * @param data_size     Place to store size of the data.
     449 *
     450 * @returns             EOK.
     451 */
     452int udebug_name_read(char **data, size_t *data_size)
     453{
     454        size_t name_size;
     455
     456        name_size = str_size(TASK->name) + 1;
     457        *data = malloc(name_size, 0);
     458        *data_size = name_size;
     459
     460        memcpy(*data, TASK->name, name_size);
    424461
    425462        return 0;
     
    436473 * this function will fail with an EINVAL error code.
    437474 *
    438  * @param buffer        The buffer for storing thread hashes.
     475 * @param t             Thread where call arguments are to be read.
     476 * @param buffer        Place to store pointer to new buffer.
     477 * @return              EOK on success, ENOENT if @a t is invalid, EINVAL
     478 *                      if thread state is not valid for this operation.
    439479 */
    440480int udebug_args_read(thread_t *t, void **buffer)
     
    468508}
    469509
     510/** Read the register state of the thread.
     511 *
     512 * The contents of the thread's istate structure are copied to a newly
     513 * allocated buffer and a pointer to it is written to @a buffer. The size of
     514 * the buffer will be sizeof(istate_t).
     515 *
     516 * Currently register state cannot be read if the thread is inside a system
     517 * call (as opposed to an exception). This is an implementation limit.
     518 *
     519 * @param t             Thread whose state is to be read.
     520 * @param buffer        Place to store pointer to new buffer.
     521 * @return              EOK on success, ENOENT if @a t is invalid, EINVAL
     522 *                      if thread is not in valid state, EBUSY if istate
     523 *                      is not available.
     524 */
     525int udebug_regs_read(thread_t *t, void **buffer)
     526{
     527        istate_t *state, *state_buf;
     528        int rc;
     529
     530        /* Prepare a buffer to hold the data. */
     531        state_buf = malloc(sizeof(istate_t), 0);
     532
     533        /* On success, this will lock t->udebug.lock */
     534        rc = _thread_op_begin(t, false);
     535        if (rc != EOK) {
     536                return rc;
     537        }
     538
     539        state = t->udebug.uspace_state;
     540        if (state == NULL) {
     541                _thread_op_end(t);
     542                return EBUSY;
     543        }
     544
     545        /* Copy to the allocated buffer */
     546        memcpy(state_buf, state, sizeof(istate_t));
     547
     548        _thread_op_end(t);
     549
     550        *buffer = (void *) state_buf;
     551        return 0;
     552}
     553
    470554/** Read the memory of the debugged task.
    471555 *
Note: See TracChangeset for help on using the changeset viewer.