How to terminate gdbserver?

亡梦爱人 提交于 2019-12-03 10:05:59

Give command

monitor exit

from your host gdb before terminating the client. If you have already terminated it, just attach with another one.

gdbserver runs on the target, not the host.

Terminating it is target dependent. For example, if your target is UNIX-ish, you could remote login and use ps and kill from a target shell.

For any type of target, rebooting should kill gdbserver.

(If this isn't enough to answer your question, include more information about the target in the question.)

on linux write:

ps -ef |grep gdbserver

Now find the pid of the gdbserver process and then

kill -9 <pid>

monitor exit step-by-step

https://stackoverflow.com/a/23647002/895245 mentions it, but this is the full setup you need.

Remote:

# pwd contains cross-compiled ./myexec
gdbserver --multi :1234

Local:

# pwd also contains the same cross-compiled ./myexec
gdb -ex 'target extended-remote 192.168.0.1:1234' \
    -ex 'set remote exec-file ./myexec' \
    --args ./myexec arg1
(gdb) r
[Inferior 1 (process 1234) exited normally]
(gdb) monitor exit

Tested in Ubuntu 14.04.

quit [expression]


q To exit GDB, use the quit command (abbreviated q), or type an end-of-file character (usually C-d). If you do not supply expression, GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.

Here is a script which I'm using to start gdb server via ssh and kill it when necessary with ctrl+c

#!/usr/bin/env bash

trap stop_gdb_server INT

function stop_gdb_server {
    ssh remote-srv-name "pkill gdbserver"
    echo "GDB server killed"
}

ssh remote-srv-name "cd /path/to/project/dir/ && gdbserver localhost:6789 my-executable"

gdbserver should exit when your target exits. The question is how your target is exiting: does it

  1. do nothing: just fall through
  2. return 0 in main
  3. exit(0) in main

From the debug sessions I've been running, in the first case, gdbserver will not exit. It will just hang around forever and you have to kill it. In the latter two cases, gdbserver will exit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!