diff --git a/docs/GDBSERVER.md b/docs/GDBSERVER.md index 2f4e2f65..78ba87df 100644 --- a/docs/GDBSERVER.md +++ b/docs/GDBSERVER.md @@ -1,36 +1,35 @@ # Qiling Gdbserver -Qiling has supported **Gdb remote debugging** now (x86, x86-64 for now) by Qiling Gdbserver. +Qiling supports **Gdb remote debugging**, which listens at default port **9999** if enable. ## Usage ```python from qiling import * - def test_gdb(path, rootfs): ql = Qiling(path, rootfs, output="off") - # ql.gdb = True # enable gdbserver at default port - # ql.gdb = ":9999" # Listening to 0.0.0.0:9999 - ql.gdb = "127.0.0.1:9999" # Listening to 127.0.0.1:9999 + ql.gdb = True # enable gdbserver at default port 9999 + # You can also customize address & port of GDB server + # ql.gdb = ":9999" # GDB server listens to 0.0.0.0:9999 + # ql.gdb = "127.0.0.1:9999" # GDB server listens to 127.0.0.1:9999 ql.run() - if __name__ == "__main__": - test_gdb(["../examples/rootfs/x86_linux/bin/x86_hello"], "../examples/rootfs/x86_linux") + test_gdb(["../examples/rootfs/x8664_linux/bin/x8664_hello_static"], "../examples/rootfs/x8664_linux") ``` Run gdb and `set architecture i386:intel` for x86 or `set architecture i386:x86-64` for x86-64 Then `target remote ip:port` and run the python script. -Currently supported features include `si`,`ni`,`c` ,read register,read memory,add/remove breakpoint +Currently supported features include `si`, `ni`, `c`, `k`, read register, read memory, add/remove breakpoints. --- ## Example -In x86-64, for example +Below is an example on how we use gdb to debug an x86-64 binary in Qiling. **set arch** ```bash @@ -40,8 +39,8 @@ The target architecture is assumed to be i386:x86-64 **connect** ```bash -(gdb) target remote 192.168.0.105:9999 -Remote debugging using 192.168.0.105:9999 +(gdb) target remote localhost:9999 +Remote debugging using localhost:9999 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x00000000004014e0 in ?? () diff --git a/docs/GDBSERVER_CN.md b/docs/GDBSERVER_CN.md index 34591245..f43de2d7 100644 --- a/docs/GDBSERVER_CN.md +++ b/docs/GDBSERVER_CN.md @@ -7,24 +7,23 @@ Qiling已通过Qiling Gdbserver支持**Gdb远程调试**(目前支持x86, x86- ```python from qiling import * - def test_gdb(path, rootfs): ql = Qiling(path, rootfs, output="off") - # ql.gdb = True # enable gdbserver at default port + ql.gdb = True # enable gdbserver at default port 9999 + # You can also customize address & port of GDB server # ql.gdb = ":9999" # Listening to 0.0.0.0:9999 - ql.gdb = "127.0.0.1:9999" # Listening to 127.0.0.1:9999 + # ql.gdb = "127.0.0.1:9999" # Listening to 127.0.0.1:9999 ql.run() - if __name__ == "__main__": - test_gdb(["../examples/rootfs/x86_linux/bin/x86_hello"], "../examples/rootfs/x86_linux") + test_gdb(["../examples/rootfs/x8664_linux/bin/x8664_hello_static"], "../examples/rootfs/x8664_linux") ``` 运行gdb并为所需架构进行设置,x86输入命令`set architecture i386:intel`,x86-64输入命令`set architecture i386:x86-64` 然后输入命令`target remote ip:port` 并执行python脚本 -当前支持的命令有 `si`,`ni`,`c`,读寄存器,读内存,插入或删除断点 +当前支持的命令有 `si`, `ni`, `c`, `k`, 读寄存器, 读内存, 插入或删除断点 --- @@ -40,8 +39,8 @@ The target architecture is assumed to be i386:x86-64 **connect** ```bash -(gdb) target remote 192.168.0.105:9999 -Remote debugging using 192.168.0.105:9999 +(gdb) target remote localhost:9999 +Remote debugging using localhost:9999 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x00000000004014e0 in ?? () diff --git a/qiling/core.py b/qiling/core.py index 647c6c1e..d6f5c75c 100644 --- a/qiling/core.py +++ b/qiling/core.py @@ -218,6 +218,7 @@ class Qiling: self.gdbserver(ip, port) except: print("Error ip or port") + self.gdbsession.close() exit(1) self.__enable_bin_patch() @@ -707,7 +708,7 @@ class Qiling: exit(1) if ip is None: - ip = '' + ip = 'localhost' if port is None: port = 9999 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/qiling/gdbserver/qldbg.py b/qiling/gdbserver/qldbg.py index faa0dc99..1e38d39b 100644 --- a/qiling/gdbserver/qldbg.py +++ b/qiling/gdbserver/qldbg.py @@ -32,9 +32,7 @@ class Qldbg(object): Modified this function for qiling.gdbserver by kabeor from https://github.com/iGio90/uDdbg """ try: - print(self.mapping) self.mapping.append([hex(address), size]) - self.current_address = address hit_soft_bp = False