gdb的file命令引導程式

2021-09-12 16:32:07 字數 3608 閱讀 6143

一 file命令引導程式

1 格式

file [可執行檔案]
2 實戰

2.1 新建test.cpp檔案

#include int main()

2.2 編譯並執行該程式

[root@localhost temp]# g++ -g test.cpp -o test

[root@localhost temp]# ./test

hello, boy

2.3 啟動gdb,然後載入可執行程式test

[root@localhost temp]# gdb

gnu gdb (gdb) red hat enterprise linux 7.6.1-100.el7_4.1

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:

.(gdb) file test

reading symbols from /root/c++/ch02/2.8/test/temp/test...done.

提示說明gdb成功讀取了可執行檔案test中的除錯資訊,已經準備好接受使用者具體的除錯命令了。

二 list命令顯示源**

1 編譯源**

#include using namespace std;

int main(int argc, char *ar**)

2 編譯

[root@localhost test]# g++ test1.cpp -g -o test1
3 輸入list命令或直接輸入l來顯示源**

[root@localhost test]# gdb

gnu gdb (gdb) red hat enterprise linux 7.6.1-100.el7_4.1

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:

.(gdb) file test1

reading symbols from /root/c++/ch02/2.5/test/test1...done.

(gdb) l

1 #include 2 using namespace std;

3 int main(int argc, char *ar**)

4 {

5 cout << "1 line!\n";

6 cout << "2 line!\n";

7 cout << "3 line!\n";

8 cout << "4 line!\n";

9 cout << "5 line!\n";

10 cout << "6 line!\n";

(gdb) q

4 顯示指定行前後的源**內容

(gdb) file test1

reading symbols from /root/c++/ch02/2.5/test/test1...done.

(gdb) list 6

1 #include 2 using namespace std;

3 int main(int argc, char *ar**)

4 {

5 cout << "1 line!\n";

6 cout << "2 line!\n";

7 cout << "3 line!\n";

8 cout << "4 line!\n";

9 cout << "5 line!\n";

10 cout << "6 line!\n";

5 list顯示始末行之間的源**內容

(gdb) list 1,15

1 #include 2 using namespace std;

3 int main(int argc, char *ar**)

4 {

5 cout << "1 line!\n";

6 cout << "2 line!\n";

7 cout << "3 line!\n";

8 cout << "4 line!\n";

9 cout << "5 line!\n";

10 cout << "6 line!\n";

11 cout << "7 line!\n";

12 cout << "8 line!\n";

13 cout << "9 line!\n";

14 cout << "10 line!\n";

15 return 0;

6 list顯示函式附件的源**內容

(gdb) list main

1 #include 2 using namespace std;

3 int main(int argc, char *ar**)

4 {

5 cout << "1 line!\n";

6 cout << "2 line!\n";

7 cout << "3 line!\n";

8 cout << "4 line!\n";

9 cout << "5 line!\n";

10 cout << "6 line!\n";

linux中的file命令

file命令用於檢視檔案型別,今天了解到了,自己動手測了一下,寫篇文章記錄一下。localhost staticlibrary ls a.out libtest.a libtest.so main.c test.c test.h test.o localhost staticlibrary file...

對Bootloader(引導引導程式)的幾點理解

1 在加電復位之後,大多數處理器都會從乙個預設的位址處獲取 比如mips結構的cpu會從0xbfc00000處取第一條指令,而arm結構的cpu則從位址0x00000000處取第一條指令。因此,在嵌入式開發板中,需要把儲存器件rom或flash等對映到這個預設的位址處,bootloader就存放在這...

linux c 小程式 gdb除錯命令 例子

1 除錯函式的一系列命令,源 如下main.c include int add range int low,int high int main void 結果為55 5015 與正確結果不同,除錯如下 1步驟 gcc g main.c o main linux下c原始檔編譯 含有源 可以除錯 gdb...