Ignore:
Timestamp:
2010-03-27T09:22:17Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
36a75a2
Parents:
cd82bb1 (diff), eaf22d4 (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:

Merge mainline changes.

File:
1 edited

Legend:

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

    rcd82bb1 r371bd7d  
    4646#include <errno.h>
    4747#include <print.h>
     48#include <str.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/**
     
    7880static int _thread_op_begin(thread_t *t, bool being_go)
    7981{
    80         task_id_t taskid;
    8182        ipl_t ipl;
    82 
    83         taskid = TASK->taskid;
    8483
    8584        mutex_lock(&TASK->udebug.lock);
     
    208207
    209208                mutex_lock(&t->udebug.lock);
    210                 if ((t->flags & THREAD_FLAG_USPACE) != 0)
     209                if ((t->flags & THREAD_FLAG_USPACE) != 0) {
    211210                        t->udebug.active = true;
    212                 mutex_unlock(&t->udebug.lock);
     211                        mutex_unlock(&t->udebug.lock);
     212                        condvar_broadcast(&t->udebug.active_cv);
     213                } else {
     214                        mutex_unlock(&t->udebug.lock);
     215                }
    213216        }
    214217
     
    354357 *
    355358 * 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.
     359 * as can fit are copied. The number of bytes copied is stored in @a stored.
     360 * The total number of thread bytes that could have been saved had there been
     361 * enough space is stored in @a needed.
    358362 *
    359363 * The rationale for having @a buf_size is that this function is only
     
    363367 * @param buffer        The buffer for storing thread hashes.
    364368 * @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)
     369 * @param stored        The actual number of bytes copied will be stored here.
     370 * @param needed        Total number of hashes that could have been saved.
     371 */
     372int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored,
     373    size_t *needed)
    368374{
    369375        thread_t *t;
    370376        link_t *cur;
    371377        unative_t tid;
    372         unsigned copied_ids;
     378        size_t copied_ids;
     379        size_t extra_ids;
    373380        ipl_t ipl;
    374381        unative_t *id_buffer;
     
    379386
    380387        /* Allocate a buffer to hold thread IDs */
    381         id_buffer = malloc(buf_size, 0);
     388        id_buffer = malloc(buf_size + 1, 0);
    382389
    383390        mutex_lock(&TASK->udebug.lock);
     
    395402        max_ids = buf_size / sizeof(unative_t);
    396403        copied_ids = 0;
     404        extra_ids = 0;
    397405
    398406        /* FIXME: make sure the thread isn't past debug shutdown... */
    399407        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 
    403408                t = list_get_instance(cur, thread_t, th_link);
    404409
     
    408413
    409414                /* Not interested in kernel threads. */
    410                 if ((flags & THREAD_FLAG_USPACE) != 0) {
     415                if ((flags & THREAD_FLAG_USPACE) == 0)
     416                        continue;
     417
     418                if (copied_ids < max_ids) {
    411419                        /* Using thread struct pointer as identification hash */
    412420                        tid = (unative_t) t;
    413421                        id_buffer[copied_ids++] = tid;
     422                } else {
     423                        extra_ids++;
    414424                }
    415425        }
     
    421431
    422432        *buffer = id_buffer;
    423         *n = copied_ids * sizeof(unative_t);
     433        *stored = copied_ids * sizeof(unative_t);
     434        *needed = (copied_ids + extra_ids) * sizeof(unative_t);
     435
     436        return 0;
     437}
     438
     439/** Read task name.
     440 *
     441 * Returns task name as non-terminated string in a newly allocated buffer.
     442 * Also returns the size of the data.
     443 *
     444 * @param data          Place to store pointer to newly allocated block.
     445 * @param data_size     Place to store size of the data.
     446 *
     447 * @returns             EOK.
     448 */
     449int udebug_name_read(char **data, size_t *data_size)
     450{
     451        size_t name_size;
     452
     453        name_size = str_size(TASK->name) + 1;
     454        *data = malloc(name_size, 0);
     455        *data_size = name_size;
     456
     457        memcpy(*data, TASK->name, name_size);
    424458
    425459        return 0;
     
    436470 * this function will fail with an EINVAL error code.
    437471 *
    438  * @param buffer        The buffer for storing thread hashes.
     472 * @param t             Thread where call arguments are to be read.
     473 * @param buffer        Place to store pointer to new buffer.
     474 * @return              EOK on success, ENOENT if @a t is invalid, EINVAL
     475 *                      if thread state is not valid for this operation.
    439476 */
    440477int udebug_args_read(thread_t *t, void **buffer)
     
    468505}
    469506
     507/** Read the register state of the thread.
     508 *
     509 * The contents of the thread's istate structure are copied to a newly
     510 * allocated buffer and a pointer to it is written to @a buffer. The size of
     511 * the buffer will be sizeof(istate_t).
     512 *
     513 * Currently register state cannot be read if the thread is inside a system
     514 * call (as opposed to an exception). This is an implementation limit.
     515 *
     516 * @param t             Thread whose state is to be read.
     517 * @param buffer        Place to store pointer to new buffer.
     518 * @return              EOK on success, ENOENT if @a t is invalid, EINVAL
     519 *                      if thread is not in valid state, EBUSY if istate
     520 *                      is not available.
     521 */
     522int udebug_regs_read(thread_t *t, void **buffer)
     523{
     524        istate_t *state, *state_buf;
     525        int rc;
     526
     527        /* Prepare a buffer to hold the data. */
     528        state_buf = malloc(sizeof(istate_t), 0);
     529
     530        /* On success, this will lock t->udebug.lock */
     531        rc = _thread_op_begin(t, false);
     532        if (rc != EOK) {
     533                return rc;
     534        }
     535
     536        state = t->udebug.uspace_state;
     537        if (state == NULL) {
     538                _thread_op_end(t);
     539                return EBUSY;
     540        }
     541
     542        /* Copy to the allocated buffer */
     543        memcpy(state_buf, state, sizeof(istate_t));
     544
     545        _thread_op_end(t);
     546
     547        *buffer = (void *) state_buf;
     548        return 0;
     549}
     550
    470551/** Read the memory of the debugged task.
    471552 *
Note: See TracChangeset for help on using the changeset viewer.