| 378 | } |
| 379 | |
| 380 | void ProcessReaderLinux::InitializeThreads() { |
| 381 | DCHECK(threads_.empty()); |
| 382 | initialized_threads_ = true; |
| 383 | |
| 384 | pid_t pid = ProcessID(); |
| 385 | if (pid == getpid()) { |
| 386 | // TODO(jperaza): ptrace can't be used on threads in the same thread group. |
| 387 | // Using clone to create a new thread in it's own thread group doesn't work |
| 388 | // because glibc doesn't support threads it didn't create via pthreads. |
| 389 | // Fork a new process to snapshot us and copy the data back? |
| 390 | LOG(ERROR) << "not implemented"; |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | Thread main_thread; |
| 395 | main_thread.tid = pid; |
| 396 | if (main_thread.InitializePtrace(connection_)) { |
| 397 | main_thread.InitializeStack(this); |
| 398 | threads_.push_back(main_thread); |
| 399 | } else { |
| 400 | LOG(WARNING) << "Couldn't initialize main thread."; |
| 401 | } |
| 402 | |
| 403 | bool main_thread_found = false; |
| 404 | std::vector<pid_t> thread_ids; |
| 405 | bool result = connection_->Threads(&thread_ids); |
| 406 | DCHECK(result); |
| 407 | for (pid_t tid : thread_ids) { |
| 408 | if (tid == pid) { |
| 409 | DCHECK(!main_thread_found); |
| 410 | main_thread_found = true; |
| 411 | continue; |
| 412 | } |
| 413 | |
| 414 | Thread thread; |
| 415 | thread.tid = tid; |
| 416 | if (connection_->Attach(tid) && thread.InitializePtrace(connection_)) { |
| 417 | thread.InitializeStack(this); |
| 418 | threads_.push_back(thread); |
| 419 | } |
| 420 | } |
| 421 | DCHECK(main_thread_found); |
| 422 | } |
| 423 | |
| 424 | void ProcessReaderLinux::InitializeModules() { |
| 425 | INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
nothing calls this directly
no test coverage detected