gdb除錯linux可執行程式

2021-07-07 04:43:39 字數 4936 閱讀 5686

gdb除錯程式例子:

[root@localhost cswapserver_dist]# gdb cswapserver

gnu gdb (gdb) red hat enterprise linux (7.2-83.el6)

license gplv3+: gnu gpl version 3 or later

this is free software: you are free to change and redistribute it.

there is no warranty, to the extent permitted by law.  type "show copying"

and "show warranty" for details.

this gdb was configured as "x86_64-redhat-linux-gnu".

for bug reporting instructions, please see:

...reading symbols from /home/artogrid/workspace/deploy/cswapserver_dist/cswapserver...done.

(gdb) l

11#include "service/send_service.h"

12#include "service/service_manager.h"

13#include "service/publish_manager.h"

14#include "engine/qpid_engine.h"

15#include "config.h"

16#include

1718

int main( int argc, char * argv )

1939

40bool servicemanager::init(sdbus::connection *conn)

4146

(gdb) finish

run till exit from #0  servicemanager::init (this=0xc1a8e0, conn=0xc042e0) at service_manager.cpp:42

[new thread 0x7fffe2bfd700 (lwp 27464)]

[new thread 0x7fffe21fc700 (lwp 27465)]

[new thread 0x7fffe17fb700 (lwp 27466)]

[new thread 0x7fffe0dfa700 (lwp 27467)]

[new thread 0x7fffc7fff700 (lwp 27468)]

[new thread 0x7fffc75fe700 (lwp 27469)]

[new thread 0x7fffc6bfd700 (lwp 27470)]

[new thread 0x7fffc61fc700 (lwp 27471)]

[new thread 0x7fffc57fb700 (lwp 27472)]

[new thread 0x7fffc4dfa700 (lwp 27473)]

2015-11-13 18:15:36,729 [0x7fffe21fc700] info  bcbond.service - ignore 1 message.

2015-11-13 18:15:36,729 [0x7fffe21fc700] info  bcbond.service - ignore 2 message.

2015-11-13 18:15:36,730 [0x7fffe21fc700] info  bcbond.service - ignore 1 message.

2015-11-13 18:15:36,730 [0x7fffe21fc700] info  bcbond.service - ignore 1 message.

2015-11-13 18:15:36,730 [0x7fffe21fc700] info  bcbond.service - ignore 1 message.

2015-11-13 18:15:36,730 [0x7fffe21fc700] info  bcbond.service - ignore 1 message.

[new thread 0x7fffc43f9700 (lwp 27474)]

[new thread 0x7fffc39f8700 (lwp 27475)]

0x000000000042d1ea in main (argc=1, argv=0x7fffffffe498) at main.cpp:59

59if (!service_manager->init(conn)) {

value returned is $2 = true

(gdb) bt

#0  0x000000000042d1ea in main (argc=1, argv=0x7fffffffe498) at main.cpp:59

(gdb) q

a debugging session is active.

inferior 1 [process 27452] will be killed.

quit anyway? (y or n) y

[root@localhost cswapserver_dist]# 

二. 指令解釋

from:

file [filename]

裝入想要除錯的可執行檔案

kill [filename]

終止正在除錯的程式

break [file:]function

在(file檔案的)function函式中設定乙個斷點

clear

刪除乙個斷點,這個命令需要指定**行或者函式名作為引數

run [arglist]

執行您的程式 (如果指定了arglist,則將arglist作為引數執行程式)

bt backtrace: 顯示程式堆疊資訊

print expr

列印表示式的值

continue

繼續執行您的程式 (在停止之後,比如在乙個斷點之後)

list

列出產生執行檔案的源**的一部分

next

單步執行 (在停止之後); 跳過函式呼叫

nexti

執行下一行的源**中的一條彙編指令

set

設定變數的值。例如:set nval=54 將把54儲存到nval變數中

step

單步執行 (在停止之後); 進入函式呼叫

stepi

繼續執行程式下一行源**中的彙編指令。如果是函式呼叫,這個命令將進入函式的內部,單步執行函式中的彙編**

watch

使你能監視乙個變數的值而不管它何時被改變

rwatch

指定乙個變數,如果這個變數被讀,則暫停程式執行,在偵錯程式中顯示資訊,並等待下乙個除錯命令。參考rwatch和watch命令

awatch

指定乙個變數,如果這個變數被讀或者被寫,則暫停程式執行,在偵錯程式中顯示資訊,並等待下乙個除錯命令。參考rwatch和watch命令

ctrl-c

在當前位置停止執行正在執行的程式,斷點在當前行

disable

禁止斷點功能,這個命令需要禁止的斷點在斷點列表索引值作為引數

display

在斷點的停止的地方,顯示指定的表示式的值。(顯示變數)

undisplay

刪除乙個display設定的變數顯示。這個命令需要將display list中的索引做引數

enable

允許斷點功能,這個命令需要允許的斷點在斷點列表索引值作為引數

finish

繼續執行,直到當前函式返回

ignore

忽略某個斷點制定的次數。例:ignore 4 23 忽略斷點4的23次執行,在第24次的時候中斷

info [name]

檢視name資訊

load

動態載入乙個可執行檔案到偵錯程式

xbreak

在當前函式的退出的點上設定乙個斷點

whatis

顯示變數的值和型別

ptype

顯示變數的型別

return

強制從當前函式返回

txbreak

在當前函式的退出的點上設定乙個臨時的斷點(只可使用一次)

make

使你能不退出 gdb 就可以重新產生可執行檔案

shell

使你能不離開 gdb 就執行 unix shell 命令

help [name]

顯示gdb命令的資訊,或者顯示如何使用gdb的總體資訊

quit

退出gdb.

建立linux可執行程式

1.在vendor rockchip目錄下建立工程目錄loopread 2.目錄結構如下 loopread.mk sepolicy file contexts loopread.te src android.mk etc init.loopread.rc loopread.c3.下面逐步解讀工程檔案...

Linux 呼叫可執行程式

3.使用execl 常用方法 二 system函式 在c c 程式中,經常需要呼叫其它的程式來先成某項任務,例如其它的c c 程式 作業系統命令或shell指令碼,c c 提供了exec函式族和system函式來實現這個功能。exec函式族提供了乙個在程序中啟動另乙個程式執行的方法。它可以根據指定的...

python 執行可執行程式

python do exe.pyw coding utf 8 import os exe dir c program files q dir exe file q dir.exe def do cmd dir,file if os.access dir,os.f ok os.chdir dir if...