| @@ -358,81 +358,38 @@ nbsd_enable_proc_events (pid_t pid) | | | @@ -358,81 +358,38 @@ nbsd_enable_proc_events (pid_t pid) |
358 | #endif | | 358 | #endif |
359 | #endif | | 359 | #endif |
360 | } | | 360 | } |
361 | | | 361 | |
362 | /* Add threads for any new LWPs in a process. | | 362 | /* Add threads for any new LWPs in a process. |
363 | | | 363 | |
364 | When LWP events are used, this function is only used to detect existing | | 364 | When LWP events are used, this function is only used to detect existing |
365 | threads when attaching to a process. On older systems, this function is | | 365 | threads when attaching to a process. On older systems, this function is |
366 | called to discover new threads each time the thread list is updated. */ | | 366 | called to discover new threads each time the thread list is updated. */ |
367 | | | 367 | |
368 | static void | | 368 | static void |
369 | nbsd_add_threads (pid_t pid) | | 369 | nbsd_add_threads (pid_t pid) |
370 | { | | 370 | { |
371 | #ifdef PT_GETNUMLWPS | | | |
372 | struct cleanup *cleanup; | | | |
373 | lwpid_t *lwps; | | | |
374 | int i, nlwps; | | | |
375 | | | | |
376 | gdb_assert (!in_thread_list (pid_to_ptid (pid))); | | | |
377 | nlwps = ptrace (PT_GETNUMLWPS, pid, NULL, 0); | | | |
378 | if (nlwps == -1) | | | |
379 | perror_with_name (("ptrace")); | | | |
380 | | | | |
381 | lwps = XCNEWVEC (lwpid_t, nlwps); | | | |
382 | cleanup = make_cleanup (xfree, lwps); | | | |
383 | | | | |
384 | nlwps = ptrace (PT_GETLWPLIST, pid, (caddr_t) lwps, nlwps); | | | |
385 | if (nlwps == -1) | | | |
386 | perror_with_name (("ptrace")); | | | |
387 | | | | |
388 | for (i = 0; i < nlwps; i++) | | | |
389 | { | | | |
390 | ptid_t ptid = ptid_build (pid, lwps[i], 0); | | | |
391 | | | | |
392 | if (!in_thread_list (ptid)) | | | |
393 | { | | | |
394 | #ifdef PT_LWP_EVENTS | | | |
395 | struct ptrace_lwpinfo pl; | | | |
396 | | | | |
397 | /* Don't add exited threads. Note that this is only called | | | |
398 | when attaching to a multi-threaded process. */ | | | |
399 | if (ptrace (PT_LWPINFO, lwps[i], (caddr_t) &pl, sizeof pl) == -1) | | | |
400 | perror_with_name (("ptrace")); | | | |
401 | if (pl.pl_flags & PL_FLAG_EXITED) | | | |
402 | continue; | | | |
403 | #endif | | | |
404 | if (debug_nbsd_lwp) | | | |
405 | fprintf_unfiltered (gdb_stdlog, | | | |
406 | "FLWP: adding thread for LWP %u\n", | | | |
407 | lwps[i]); | | | |
408 | add_thread (ptid); | | | |
409 | } | | | |
410 | } | | | |
411 | do_cleanups (cleanup); | | | |
412 | #else | | | |
413 | int val; | | 371 | int val; |
414 | struct ptrace_lwpinfo pl; | | 372 | struct ptrace_lwpinfo pl; |
415 | | | 373 | |
416 | gdb_assert (!in_thread_list (pid_to_ptid (pid))); | | 374 | gdb_assert (!in_thread_list (pid_to_ptid (pid))); |
417 | pl.pl_lwpid = 0; | | 375 | pl.pl_lwpid = 0; |
418 | while ((val = ptrace (PT_LWPINFO, pid, (void *)&pl, sizeof(pl))) != -1 | | 376 | while ((val = ptrace (PT_LWPINFO, pid, (void *)&pl, sizeof(pl))) != -1 |
419 | && pl.pl_lwpid != 0) | | 377 | && pl.pl_lwpid != 0) |
420 | { | | 378 | { |
421 | ptid_t ptid = ptid_build (pid, pl.pl_lwpid, 0); | | 379 | ptid_t ptid = ptid_build (pid, pl.pl_lwpid, 0); |
422 | if (!in_thread_list (ptid)) | | 380 | if (!in_thread_list (ptid)) |
423 | add_thread (ptid); | | 381 | add_thread (ptid); |
424 | } | | 382 | } |
425 | #endif | | | |
426 | } | | 383 | } |
427 | | | 384 | |
428 | /* Implement the "to_update_thread_list" target_ops method. */ | | 385 | /* Implement the "to_update_thread_list" target_ops method. */ |
429 | | | 386 | |
430 | static void | | 387 | static void |
431 | nbsd_update_thread_list (struct target_ops *ops) | | 388 | nbsd_update_thread_list (struct target_ops *ops) |
432 | { | | 389 | { |
433 | #ifdef PT_LWP_EVENTS | | 390 | #ifdef PT_LWP_EVENTS |
434 | /* With support for thread events, threads are added/deleted from the | | 391 | /* With support for thread events, threads are added/deleted from the |
435 | list as events are reported, so just try deleting exited threads. */ | | 392 | list as events are reported, so just try deleting exited threads. */ |
436 | delete_exited_threads (); | | 393 | delete_exited_threads (); |
437 | #else | | 394 | #else |
438 | prune_threads (); | | 395 | prune_threads (); |
| @@ -584,27 +541,27 @@ nbsd_resume (struct target_ops *ops, | | | @@ -584,27 +541,27 @@ nbsd_resume (struct target_ops *ops, |
584 | pid_t pid; | | 541 | pid_t pid; |
585 | | | 542 | |
586 | /* Don't PT_CONTINUE a process which has a pending vfork done event. */ | | 543 | /* Don't PT_CONTINUE a process which has a pending vfork done event. */ |
587 | if (ptid_equal (minus_one_ptid, ptid)) | | 544 | if (ptid_equal (minus_one_ptid, ptid)) |
588 | pid = ptid_get_pid (inferior_ptid); | | 545 | pid = ptid_get_pid (inferior_ptid); |
589 | else | | 546 | else |
590 | pid = ptid_get_pid (ptid); | | 547 | pid = ptid_get_pid (ptid); |
591 | if (nbsd_is_vfork_done_pending (pid)) | | 548 | if (nbsd_is_vfork_done_pending (pid)) |
592 | return; | | 549 | return; |
593 | #endif | | 550 | #endif |
594 | | | 551 | |
595 | if (debug_nbsd_lwp) | | 552 | if (debug_nbsd_lwp) |
596 | fprintf_unfiltered (gdb_stdlog, | | 553 | fprintf_unfiltered (gdb_stdlog, |
597 | "FLWP: nbsd_resume for ptid (%d, %ld, %ld)\n", | | 554 | "NLWP: nbsd_resume for ptid (%d, %ld, %ld)\n", |
598 | ptid_get_pid (ptid), ptid_get_lwp (ptid), | | 555 | ptid_get_pid (ptid), ptid_get_lwp (ptid), |
599 | ptid_get_tid (ptid)); | | 556 | ptid_get_tid (ptid)); |
600 | if (ptid_lwp_p (ptid)) | | 557 | if (ptid_lwp_p (ptid)) |
601 | { | | 558 | { |
602 | /* If ptid is a specific LWP, suspend all other LWPs in the process. */ | | 559 | /* If ptid is a specific LWP, suspend all other LWPs in the process. */ |
603 | struct thread_info *tp; | | 560 | struct thread_info *tp; |
604 | int request; | | 561 | int request; |
605 | | | 562 | |
606 | ALL_NON_EXITED_THREADS (tp) | | 563 | ALL_NON_EXITED_THREADS (tp) |
607 | { | | 564 | { |
608 | if (ptid_get_pid (tp->ptid) != ptid_get_pid (ptid)) | | 565 | if (ptid_get_pid (tp->ptid) != ptid_get_pid (ptid)) |
609 | continue; | | 566 | continue; |
610 | | | 567 | |
| @@ -674,66 +631,66 @@ nbsd_wait (struct target_ops *ops, | | | @@ -674,66 +631,66 @@ nbsd_wait (struct target_ops *ops, |
674 | wptid = ptid_build (pid, pl.pl_lwpid, 0); | | 631 | wptid = ptid_build (pid, pl.pl_lwpid, 0); |
675 | | | 632 | |
676 | #ifdef PT_LWP_EVENTS | | 633 | #ifdef PT_LWP_EVENTS |
677 | if (pl.pl_flags & PL_FLAG_EXITED) | | 634 | if (pl.pl_flags & PL_FLAG_EXITED) |
678 | { | | 635 | { |
679 | /* If GDB attaches to a multi-threaded process, exiting | | 636 | /* If GDB attaches to a multi-threaded process, exiting |
680 | threads might be skipped during nbsd_post_attach that | | 637 | threads might be skipped during nbsd_post_attach that |
681 | have not yet reported their PL_FLAG_EXITED event. | | 638 | have not yet reported their PL_FLAG_EXITED event. |
682 | Ignore EXITED events for an unknown LWP. */ | | 639 | Ignore EXITED events for an unknown LWP. */ |
683 | if (in_thread_list (wptid)) | | 640 | if (in_thread_list (wptid)) |
684 | { | | 641 | { |
685 | if (debug_nbsd_lwp) | | 642 | if (debug_nbsd_lwp) |
686 | fprintf_unfiltered (gdb_stdlog, | | 643 | fprintf_unfiltered (gdb_stdlog, |
687 | "FLWP: deleting thread for LWP %u\n", | | 644 | "NLWP: deleting thread for LWP %u\n", |
688 | pl.pl_lwpid); | | 645 | pl.pl_lwpid); |
689 | if (print_thread_events) | | 646 | if (print_thread_events) |
690 | printf_unfiltered (_("[%s exited]\n"), target_pid_to_str | | 647 | printf_unfiltered (_("[%s exited]\n"), target_pid_to_str |
691 | (wptid)); | | 648 | (wptid)); |
692 | delete_thread (wptid); | | 649 | delete_thread (wptid); |
693 | } | | 650 | } |
694 | if (ptrace (PT_CONTINUE, pid, (caddr_t) 1, 0) == -1) | | 651 | if (ptrace (PT_CONTINUE, pid, (caddr_t) 1, 0) == -1) |
695 | perror_with_name (("ptrace")); | | 652 | perror_with_name (("ptrace")); |
696 | continue; | | 653 | continue; |
697 | } | | 654 | } |
698 | #endif | | 655 | #endif |
699 | | | 656 | |
700 | /* Switch to an LWP PTID on the first stop in a new process. | | 657 | /* Switch to an LWP PTID on the first stop in a new process. |
701 | This is done after handling PL_FLAG_EXITED to avoid | | 658 | This is done after handling PL_FLAG_EXITED to avoid |
702 | switching to an exited LWP. It is done before checking | | 659 | switching to an exited LWP. It is done before checking |
703 | PL_FLAG_BORN in case the first stop reported after | | 660 | PL_FLAG_BORN in case the first stop reported after |
704 | attaching to an existing process is a PL_FLAG_BORN | | 661 | attaching to an existing process is a PL_FLAG_BORN |
705 | event. */ | | 662 | event. */ |
706 | if (in_thread_list (pid_to_ptid (pid))) | | 663 | if (in_thread_list (pid_to_ptid (pid))) |
707 | { | | 664 | { |
708 | if (debug_nbsd_lwp) | | 665 | if (debug_nbsd_lwp) |
709 | fprintf_unfiltered (gdb_stdlog, | | 666 | fprintf_unfiltered (gdb_stdlog, |
710 | "FLWP: using LWP %u for first thread\n", | | 667 | "NLWP: using LWP %u for first thread\n", |
711 | pl.pl_lwpid); | | 668 | pl.pl_lwpid); |
712 | thread_change_ptid (pid_to_ptid (pid), wptid); | | 669 | thread_change_ptid (pid_to_ptid (pid), wptid); |
713 | } | | 670 | } |
714 | | | 671 | |
715 | #ifdef PT_LWP_EVENTS | | 672 | #ifdef PT_LWP_EVENTS |
716 | if (pl.pl_flags & PL_FLAG_BORN) | | 673 | if (pl.pl_flags & PL_FLAG_BORN) |
717 | { | | 674 | { |
718 | /* If GDB attaches to a multi-threaded process, newborn | | 675 | /* If GDB attaches to a multi-threaded process, newborn |
719 | threads might be added by nbsd_add_threads that have | | 676 | threads might be added by nbsd_add_threads that have |
720 | not yet reported their PL_FLAG_BORN event. Ignore | | 677 | not yet reported their PL_FLAG_BORN event. Ignore |
721 | BORN events for an already-known LWP. */ | | 678 | BORN events for an already-known LWP. */ |
722 | if (!in_thread_list (wptid)) | | 679 | if (!in_thread_list (wptid)) |
723 | { | | 680 | { |
724 | if (debug_nbsd_lwp) | | 681 | if (debug_nbsd_lwp) |
725 | fprintf_unfiltered (gdb_stdlog, | | 682 | fprintf_unfiltered (gdb_stdlog, |
726 | "FLWP: adding thread for LWP %u\n", | | 683 | "NLWP: adding thread for LWP %u\n", |
727 | pl.pl_lwpid); | | 684 | pl.pl_lwpid); |
728 | add_thread (wptid); | | 685 | add_thread (wptid); |
729 | } | | 686 | } |
730 | ourstatus->kind = TARGET_WAITKIND_SPURIOUS; | | 687 | ourstatus->kind = TARGET_WAITKIND_SPURIOUS; |
731 | return wptid; | | 688 | return wptid; |
732 | } | | 689 | } |
733 | #endif | | 690 | #endif |
734 | | | 691 | |
735 | #ifdef TDP_RFPPWAIT | | 692 | #ifdef TDP_RFPPWAIT |
736 | if (pl.pl_flags & PL_FLAG_FORKED) | | 693 | if (pl.pl_flags & PL_FLAG_FORKED) |
737 | { | | 694 | { |
738 | #ifndef PTRACE_VFORK | | 695 | #ifndef PTRACE_VFORK |
739 | struct kinfo_proc kp; | | 696 | struct kinfo_proc kp; |
| @@ -1013,21 +970,21 @@ nbsd_nat_add_target (struct target_ops * | | | @@ -1013,21 +970,21 @@ nbsd_nat_add_target (struct target_ops * |
1013 | #endif | | 970 | #endif |
1014 | add_target (t); | | 971 | add_target (t); |
1015 | } | | 972 | } |
1016 | | | 973 | |
1017 | /* Provide a prototype to silence -Wmissing-prototypes. */ | | 974 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
1018 | extern initialize_file_ftype _initialize_nbsd_nat; | | 975 | extern initialize_file_ftype _initialize_nbsd_nat; |
1019 | | | 976 | |
1020 | void | | 977 | void |
1021 | _initialize_nbsd_nat (void) | | 978 | _initialize_nbsd_nat (void) |
1022 | { | | 979 | { |
1023 | #ifdef PT_LWPINFO | | 980 | #ifdef PT_LWPINFO |
1024 | add_setshow_boolean_cmd ("nbsd-lwp", class_maintenance, | | 981 | add_setshow_boolean_cmd ("nbsd-lwp", class_maintenance, |
1025 | &debug_nbsd_lwp, _("\ | | 982 | &debug_nbsd_lwp, _("\ |
1026 | Set debugging of FreeBSD lwp module."), _("\ | | 983 | Set debugging of NetBSD lwp module."), _("\ |
1027 | Show debugging of FreeBSD lwp module."), _("\ | | 984 | Show debugging of NetBSD lwp module."), _("\ |
1028 | Enables printf debugging output."), | | 985 | Enables printf debugging output."), |
1029 | NULL, | | 986 | NULL, |
1030 | &show_nbsd_lwp_debug, | | 987 | &show_nbsd_lwp_debug, |
1031 | &setdebuglist, &showdebuglist); | | 988 | &setdebuglist, &showdebuglist); |
1032 | #endif | | 989 | #endif |
1033 | } | | 990 | } |