How to terminate gdbserver?

♀尐吖头ヾ 提交于 2019-12-04 17:02:44

问题


I am trying to debug with gdbserver. after I terminat the gdb client on the host I see that the gdbserver is still listening :

Remote side has terminated connection.  GDBserver will reopen the connection.
Listening on port 5004

I tried to exit gdbserver with everything I have found anywhere no luck: quit,exit,q, monitor exit,Esc,Cnt+c... nothing kills it. Moreover, when I opened another terminal and looked for the process running gdbserver (with the commands ps,top) I couldn't find it there... my question is - How to terminate gdbserver ?


回答1:


Give command

monitor exit

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




回答2:


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.)




回答3:


on linux write:

ps -ef |grep gdbserver

Now find the pid of the gdbserver process and then

kill -9 <pid>



回答4:


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.




回答5:


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.




回答6:


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"



回答7:


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.



来源:https://stackoverflow.com/questions/20870338/how-to-terminate-gdbserver

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