Problem: GDB "attach pid" command shows error message "Couldn't get registers: Device busy" because of which below gdb tests fail. Cause: On FreeBSD ptrace() syscall requires LWP id to fetch info from the inferior process. The current implementation is every command is executed completely and then it wait's for asynchronous events. When attach command is executed it calls inf_ptrace_attach() function which is currently doing just the ptrace(PT_ATTACH), it does not wait for the process to stop to fetch LWP info. The fbsd_wait() function is the one which fetches LWP info which is being called after the command completes. Command execution code flow - gdb_do_one_event() => .. => handle_file_event() => .. => execute_command() => check_frame_language_change() The async event handling code flow where LWP info gets updated - gdb_one_event() => check_async_event_handlers() => .. ->do_target_wait() => .. => fbsd_wait() The check, if the frame language changed via check_frame_language_change() function is trying to read registers using ptrace(pid) which fails because LWP id is not fetched. The purposed patch tries to avoid this situation by avoiding calling check_frame_language_change() function just for the "attach" command. Tests: FAIL: gdb.base/attach.exp: attach1, after setting file FAIL: gdb.base/attach.exp: attach2, with no file FAIL: gdb.base/attach.exp: load file manually, after attach2 (re-read) (got interactive prompt) FAIL: gdb.base/attach.exp: attach when process' a.out not in cwd FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=gdb dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=call dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=on ds=agent dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=gdb dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=call dd=off: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=on: re-attach to inferior FAIL: gdb.base/dprintf-detach.exp: bai=off ds=agent dd=off: re-attach to inferior These above currently failing tests will pass with this fix. gdb/ChangeLog: 2018-04-20 Rajendra SY PR gdb/23077 * gdb/top.c (execute_command):