一、 X86模拟器环境下调试
1. qtopia的打印输出能否和gdb的输出分开?
有两种方法解决: 1)输出重定向
我们打开两个终端(一个用来使用gdb,另一个用来显示所调试程序的输出),这两个终端是什么是无所谓的(可以是xterm,rxvt,konsole,或者virtual consoles),但是应该不能是一个多页面终端的两个tab,因为我在konsole实验的时个那样会提示找不到/dev/pts/x文件。
然后我们先切换到第一个终端,运行gdb filename,filename就是要调试的文件的名称(这个应该不会不知道吧...),进入gdb。接着切换到第二个终端,看看它的设备名称
$ tty /dev/pts/2
上面的说明第二个终端的设备名是/dev/pts/2,之后再切回到第一个终端,然后
(gdb) tty /dev/pts/2 (gdb)
2) 先将qpe在一个终端上运行起来, 然后将GDB ATTACH到相关的进程号上。注意attach后
会自动将qpe暂停, 需要在gdb上运行continue。
2. 当主程序运行到 initApplication 里的 a.exec()后, QPE陷入循环。GDB上无法操作。
二。 开发板上远程调试
GDB Manual 17 2
來自 ChinaUnix Wiki
17.2 Using the gdbserver program
17.2 使用gdbserver
gdbserver is a control program for Unix-like systems, which allows you to connect your program with a remote GDB via target remote---but without linking in the usual debugging stub.
gdbserver 是一個針對 Unix 類型系統的控製程序,它允許你通過 target remote 連接你的程式到一個遠程 gdb,但是並不鏈接通常的調試 stub。
gdbserver is not a complete replacement for the debugging stubs, because it requires essentially the same operating-system facilities that GDB itself does. In fact, a system that can run gdbserver to connect to a remote GDB could also run GDB locally! gdbserver is sometimes useful nevertheless, because it is a much smaller program than GDB itself. It is also easier to port than all of GDB, so you may be able to get started more quickly on a new system by using gdbserver. Finally, if you develop code for real-time systems, you may find that the tradeoffs involved in real-time operation make it more convenient to do as much development work as possible on another system, for example by cross-compiling. You can use gdbserver to make a similar choice for debugging.
gdbserver 並不是一個完全的針對調試 stub 的替代品,因為它需要同樣的操作系統實體(gdb 自己所做)。事實上,一個能夠運行 gdbserver 連接到遠程 gdb 的系統也可以在本地運行 gdb!gdbserver 有時候是很有用的,因為它與 gdb 相比是一個小得多的程式。而且它比所有的 gdb 移植要更簡單,所以你如果在一個新的系統上使用 gdbserver,將可能更快地啟動。最後,如果你開發實時系統的代碼,你可能發現包含在實時操作中的這一權衡使便利地在另一個系統上進行更多的開發工作成為可能,比如在交叉編譯中.你可以使用 gdbserver 作為調試的一種選擇。
GDB and gdbserver communicate via either a serial line or a TCP connection, using the standard GDB remote serial protocol.
gdb 和 gdbserver 通過一根串口線和一個 TCP 連接通訊,使用標準的 gdb 遠程串口協議。
On the target machine,
you need to have a copy of the program you want to debug. gdbserver does not need your program's symbol table, so you can strip the program if necessary to save space. GDB on the host system does all the symbol handling. To use the server, you must tell it how to communicate with GDB; the name of your program; and the arguments for your program. The usual syntax is:
在目標機上,
你需要有一份要調試的程式的拷貝。gdbserver 不需要程式的符號表,所以你能 strip 程式以節省空間。宿主機上的 gdb 做所有的符號表處理。要使用這一伺服器,你必須告訴他怎麼同 gdb 通訊;程式的名稱;程式的參數。常用的語法是:
target> gdbserver comm program [ args ... ]
comm is either a device name (to use a serial line) or a TCP hostname and portnumber. For example, to debug Emacs with the argument `foo.txt' and communicate with GDB over the serial port `/dev/com1':
comm可以是一個設備名(使用串口線)或者一個 TCP 主機名和埠號。比如,使用參數 "foo.txt" 調試 emacs,並且通過串口 "/dev/com1" 同 gdb 通訊:
target> gdbserver /dev/com1 emacs foo.txt
gdbserver waits passively for the host GDB to communicate with it.
gdbserver 被動等待宿主機的 gdb 與它通訊。
To use a TCP connection instead of a serial line:
使用 TCP 連接代替串口線:
target> gdbserver host:2345 emacs foo.txt
The only difference from the previous example is the first argument, specifying that you are communicating with the host GDB via TCP. The `host:2345' argument means that gdbserver is to expect a TCP connection from machine `host' to local TCP port 2345. (Currently, the `host' part is ignored.) You can choose any number you want for the port number as long as it does not conflict with any TCP ports already in use on the target system (for example, 23 is reserved for telnet).(7) You must use the same port number with the host GDB target remote command.
On some targets, gdbserver can also attach to running programs. This is accomplished via the --attach argument. The syntax is:
與前一個例子不同的是第一個參數,它指定與宿主機通過 TCP 通訊。參數 "host:2345" 的含義是 gdbserver 希望從 host 到本地 TCP 埠 2345 建立 TCP 連接(當前,host 部分是被忽略的)。你可以選擇任意的埠號,只要它與目標系統中使用的 TCP 埠不起衝突即可(比如,23 是 telnet 的保留埠號)。你必須與宿主機的 target remote 命令使用同一個埠號。
在某些目標機上,gdbserver 可以依附在某些運行中的程式上。這可以通過 --attach 參數來完成。語法是:
target> gdbserver comm --attach pid
pid is the process ID of a currently running process. It isn't necessary to point gdbserver at a binary for the running process.
pid是當前運行的進程的 ID 號。這樣可以不需要對 gdbserver 指出運行進程的二進位文件。
You can debug processes by name instead of process ID if your target has the pidof utility:
如果你的目標機有 pidof 程式,那麼你可以使用程式名代替 ID 號來調試程式。
target> gdbserver comm --attach `pidof 程式`
In case more than one copy of PROGRAM is running, or PROGRAM has multiple threads, most versions of pidof support the -s option to only return the first process ID.
如果有多個同一程式的映像在運行,或者程式有多個線程,在這種情況下,許多版本的 pidof 支持 -s 選項,這將只返回第一個進程的 ID 號。
On the host machine,
connect to your target (see section Connecting to a remote target). For TCP connections, you must start up gdbserver prior to using the target remote command. Otherwise you may get an error whose text depends on the host system, but which usually looks something like `Connection refused'. You don't need to use the load command in GDB when using gdbserver, since the program is already on the target. However, if you want to load the symbols (as you normally would), do that with the file command, and issue it before connecting to the server; otherwise, you will get an error message saying "Program is already running", since the program is considered running after the connection.
在宿主機上,
連接到目標機(請看段 "連接到遠程目標")。對 TCP 連接來說,你必須在 target remote 命令之前啟動 gdbserver。否則你可能收到依賴於宿主機的錯誤信息,通常類似 "連接被拒絕"。當使用 gdbserver 的時候,你不需要在 gdb 中使用 load 命令,因為程式已經在目標機上了。然而,如果你想載入符號表(就像你通常所做的),那麼可以使用 file 命令來做這些事情,並且在連接到伺服器之前執行它;否則,你將得到一條錯誤信息:程式已經運行(因為程式被認為是在連接之後運行的)。
05-03-14, 22:49 | 第 2 帖 | |
|
GDBServer可以调试多线程的,
先运行程序, 再用ps查看要调试的线程/进程的ID 在控制台上输入: gdbserver 192.168.0.1:1234 --attach XXX 就可以调试了 XXX是进程的ID号 |