Changeset a35b458 in mainline for kernel/generic/src/udebug/udebug.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/udebug/udebug.c
r3061bc1 ra35b458 75 75 waitq_initialize(&ut->go_wq); 76 76 condvar_initialize(&ut->active_cv); 77 77 78 78 ut->go_call = NULL; 79 79 ut->uspace_state = NULL; … … 96 96 { 97 97 ipl_t ipl = waitq_sleep_prepare(wq); 98 98 99 99 wq->missed_wakeups = 0; /* Enforce blocking. */ 100 100 bool blocked; … … 119 119 assert(THREAD); 120 120 assert(TASK); 121 121 122 122 mutex_lock(&TASK->udebug.lock); 123 123 124 124 int nsc = --TASK->udebug.not_stoppable_count; 125 125 126 126 /* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */ 127 127 mutex_lock(&THREAD->udebug.lock); 128 128 assert(THREAD->udebug.stoppable == false); 129 129 THREAD->udebug.stoppable = true; 130 130 131 131 if ((TASK->udebug.dt_state == UDEBUG_TS_BEGINNING) && (nsc == 0)) { 132 132 /* … … 135 135 * 136 136 */ 137 137 138 138 call_t *db_call = TASK->udebug.begin_call; 139 139 assert(db_call); 140 140 141 141 TASK->udebug.dt_state = UDEBUG_TS_ACTIVE; 142 142 TASK->udebug.begin_call = NULL; 143 143 144 144 IPC_SET_RETVAL(db_call->data, 0); 145 145 ipc_answer(&TASK->answerbox, db_call); … … 148 148 * Active debugging session 149 149 */ 150 150 151 151 if (THREAD->udebug.active == true && 152 152 THREAD->udebug.go == false) { … … 155 155 * 156 156 */ 157 157 158 158 /* Make sure nobody takes this call away from us */ 159 159 call_t *go_call = THREAD->udebug.go_call; 160 160 THREAD->udebug.go_call = NULL; 161 161 assert(go_call); 162 162 163 163 IPC_SET_RETVAL(go_call->data, 0); 164 164 IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP); 165 165 166 166 THREAD->udebug.cur_event = UDEBUG_EVENT_STOP; 167 167 ipc_answer(&TASK->answerbox, go_call); 168 168 } 169 169 } 170 170 171 171 mutex_unlock(&THREAD->udebug.lock); 172 172 mutex_unlock(&TASK->udebug.lock); … … 185 185 mutex_lock(&TASK->udebug.lock); 186 186 mutex_lock(&THREAD->udebug.lock); 187 187 188 188 if ((THREAD->udebug.active) && (THREAD->udebug.go == false)) { 189 189 mutex_unlock(&THREAD->udebug.lock); 190 190 mutex_unlock(&TASK->udebug.lock); 191 191 192 192 udebug_wait_for_go(&THREAD->udebug.go_wq); 193 193 194 194 goto restart; 195 195 /* Must try again - have to lose stoppability atomically. */ … … 198 198 assert(THREAD->udebug.stoppable == true); 199 199 THREAD->udebug.stoppable = false; 200 200 201 201 mutex_unlock(&THREAD->udebug.lock); 202 202 mutex_unlock(&TASK->udebug.lock); … … 228 228 udebug_event_t etype = 229 229 end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B; 230 230 231 231 mutex_lock(&TASK->udebug.lock); 232 232 mutex_lock(&THREAD->udebug.lock); 233 233 234 234 /* Must only generate events when in debugging session and is go. */ 235 235 if (THREAD->udebug.active != true || THREAD->udebug.go == false || … … 239 239 return; 240 240 } 241 241 242 242 /* Fill in the GO response. */ 243 243 call_t *call = THREAD->udebug.go_call; 244 244 THREAD->udebug.go_call = NULL; 245 245 246 246 IPC_SET_RETVAL(call->data, 0); 247 247 IPC_SET_ARG1(call->data, etype); 248 248 IPC_SET_ARG2(call->data, id); 249 249 IPC_SET_ARG3(call->data, rc); 250 250 251 251 THREAD->udebug.syscall_args[0] = a1; 252 252 THREAD->udebug.syscall_args[1] = a2; … … 255 255 THREAD->udebug.syscall_args[4] = a5; 256 256 THREAD->udebug.syscall_args[5] = a6; 257 257 258 258 /* 259 259 * Make sure udebug.go is false when going to sleep … … 264 264 THREAD->udebug.go = false; 265 265 THREAD->udebug.cur_event = etype; 266 266 267 267 ipc_answer(&TASK->answerbox, call); 268 268 269 269 mutex_unlock(&THREAD->udebug.lock); 270 270 mutex_unlock(&TASK->udebug.lock); 271 271 272 272 udebug_wait_for_go(&THREAD->udebug.go_wq); 273 273 } … … 294 294 mutex_lock(&TASK->udebug.lock); 295 295 mutex_lock(&THREAD->udebug.lock); 296 296 297 297 thread_attach(thread, task); 298 298 299 299 LOG("Check state"); 300 300 301 301 /* Must only generate events when in debugging session */ 302 302 if (THREAD->udebug.active != true) { … … 304 304 THREAD->udebug.active ? "Yes(+)" : "No", 305 305 THREAD->udebug.go ? "Yes(-)" : "No"); 306 306 307 307 mutex_unlock(&THREAD->udebug.lock); 308 308 mutex_unlock(&TASK->udebug.lock); 309 309 return; 310 310 } 311 311 312 312 LOG("Trigger event"); 313 313 314 314 call_t *call = THREAD->udebug.go_call; 315 315 316 316 THREAD->udebug.go_call = NULL; 317 317 IPC_SET_RETVAL(call->data, 0); 318 318 IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B); 319 319 IPC_SET_ARG2(call->data, (sysarg_t) thread); 320 320 321 321 /* 322 322 * Make sure udebug.go is false when going to sleep … … 327 327 THREAD->udebug.go = false; 328 328 THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B; 329 329 330 330 ipc_answer(&TASK->answerbox, call); 331 331 332 332 mutex_unlock(&THREAD->udebug.lock); 333 333 mutex_unlock(&TASK->udebug.lock); 334 334 335 335 LOG("Wait for Go"); 336 336 udebug_wait_for_go(&THREAD->udebug.go_wq); … … 347 347 mutex_lock(&TASK->udebug.lock); 348 348 mutex_lock(&THREAD->udebug.lock); 349 349 350 350 LOG("Check state"); 351 351 352 352 /* Must only generate events when in debugging session. */ 353 353 if (THREAD->udebug.active != true) { … … 355 355 THREAD->udebug.active ? "Yes" : "No", 356 356 THREAD->udebug.go ? "Yes" : "No"); 357 357 358 358 mutex_unlock(&THREAD->udebug.lock); 359 359 mutex_unlock(&TASK->udebug.lock); 360 360 return; 361 361 } 362 362 363 363 LOG("Trigger event"); 364 364 365 365 call_t *call = THREAD->udebug.go_call; 366 366 367 367 THREAD->udebug.go_call = NULL; 368 368 IPC_SET_RETVAL(call->data, 0); 369 369 IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E); 370 370 371 371 /* Prevent any further debug activity in thread. */ 372 372 THREAD->udebug.active = false; 373 373 THREAD->udebug.cur_event = 0; /* None */ 374 374 THREAD->udebug.go = false; /* Set to initial value */ 375 375 376 376 ipc_answer(&TASK->answerbox, call); 377 377 378 378 mutex_unlock(&THREAD->udebug.lock); 379 379 mutex_unlock(&TASK->udebug.lock); 380 380 381 381 /* 382 382 * This event does not sleep - debugging has finished … … 405 405 return EINVAL; 406 406 } 407 407 408 408 LOG("Task %" PRIu64, task->taskid); 409 409 410 410 /* Finish debugging of all userspace threads */ 411 411 list_foreach(task->threads, th_link, thread_t, thread) { 412 412 mutex_lock(&thread->udebug.lock); 413 413 414 414 /* Only process userspace threads. */ 415 415 if (thread->uspace) { … … 417 417 thread->udebug.active = false; 418 418 thread->udebug.cur_event = 0; /* None */ 419 419 420 420 /* Is the thread still go? */ 421 421 if (thread->udebug.go == true) { … … 426 426 */ 427 427 thread->udebug.go = false; 428 428 429 429 /* Answer GO call */ 430 430 LOG("Answer GO call with EVENT_FINISHED."); 431 431 432 432 IPC_SET_RETVAL(thread->udebug.go_call->data, 0); 433 433 IPC_SET_ARG1(thread->udebug.go_call->data, 434 434 UDEBUG_EVENT_FINISHED); 435 435 436 436 ipc_answer(&task->answerbox, thread->udebug.go_call); 437 437 thread->udebug.go_call = NULL; … … 442 442 * 443 443 */ 444 444 445 445 /* 446 446 * thread's lock must not be held when calling … … 450 450 waitq_wakeup(&thread->udebug.go_wq, WAKEUP_FIRST); 451 451 } 452 452 453 453 mutex_unlock(&thread->udebug.lock); 454 454 condvar_broadcast(&thread->udebug.active_cv); … … 456 456 mutex_unlock(&thread->udebug.lock); 457 457 } 458 458 459 459 task->udebug.dt_state = UDEBUG_TS_INACTIVE; 460 460 task->udebug.debugger = NULL; 461 461 462 462 return 0; 463 463 } … … 474 474 { 475 475 udebug_stoppable_begin(); 476 476 477 477 /* Wait until a debugger attends to us. */ 478 478 mutex_lock(&THREAD->udebug.lock); … … 480 480 condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock); 481 481 mutex_unlock(&THREAD->udebug.lock); 482 482 483 483 /* Make sure the debugging session is over before proceeding. */ 484 484 mutex_lock(&THREAD->udebug.lock); … … 486 486 condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock); 487 487 mutex_unlock(&THREAD->udebug.lock); 488 488 489 489 udebug_stoppable_end(); 490 490 }
Note:
See TracChangeset
for help on using the changeset viewer.