Changeset 371bd7d in mainline for kernel/generic/src/udebug/udebug_ops.c
- Timestamp:
- 2010-03-27T09:22:17Z (16 years ago)
- 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. - File:
-
- 1 edited
-
kernel/generic/src/udebug/udebug_ops.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/udebug/udebug_ops.c
rcd82bb1 r371bd7d 46 46 #include <errno.h> 47 47 #include <print.h> 48 #include <str.h> 48 49 #include <syscall/copy.h> 49 50 #include <ipc/ipc.h> 50 51 #include <udebug/udebug.h> 51 52 #include <udebug/udebug_ops.h> 53 #include <memstr.h> 52 54 53 55 /** … … 78 80 static int _thread_op_begin(thread_t *t, bool being_go) 79 81 { 80 task_id_t taskid;81 82 ipl_t ipl; 82 83 taskid = TASK->taskid;84 83 85 84 mutex_lock(&TASK->udebug.lock); … … 208 207 209 208 mutex_lock(&t->udebug.lock); 210 if ((t->flags & THREAD_FLAG_USPACE) != 0) 209 if ((t->flags & THREAD_FLAG_USPACE) != 0) { 211 210 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 } 213 216 } 214 217 … … 354 357 * 355 358 * 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. 358 362 * 359 363 * The rationale for having @a buf_size is that this function is only … … 363 367 * @param buffer The buffer for storing thread hashes. 364 368 * @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 */ 372 int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored, 373 size_t *needed) 368 374 { 369 375 thread_t *t; 370 376 link_t *cur; 371 377 unative_t tid; 372 unsigned copied_ids; 378 size_t copied_ids; 379 size_t extra_ids; 373 380 ipl_t ipl; 374 381 unative_t *id_buffer; … … 379 386 380 387 /* Allocate a buffer to hold thread IDs */ 381 id_buffer = malloc(buf_size , 0);388 id_buffer = malloc(buf_size + 1, 0); 382 389 383 390 mutex_lock(&TASK->udebug.lock); … … 395 402 max_ids = buf_size / sizeof(unative_t); 396 403 copied_ids = 0; 404 extra_ids = 0; 397 405 398 406 /* FIXME: make sure the thread isn't past debug shutdown... */ 399 407 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 403 408 t = list_get_instance(cur, thread_t, th_link); 404 409 … … 408 413 409 414 /* 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) { 411 419 /* Using thread struct pointer as identification hash */ 412 420 tid = (unative_t) t; 413 421 id_buffer[copied_ids++] = tid; 422 } else { 423 extra_ids++; 414 424 } 415 425 } … … 421 431 422 432 *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 */ 449 int 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); 424 458 425 459 return 0; … … 436 470 * this function will fail with an EINVAL error code. 437 471 * 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. 439 476 */ 440 477 int udebug_args_read(thread_t *t, void **buffer) … … 468 505 } 469 506 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 */ 522 int 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 470 551 /** Read the memory of the debugged task. 471 552 *
Note:
See TracChangeset
for help on using the changeset viewer.
