2015-10-11 108 views
1

我正在嘗試調試我的項目,其中包含5個文件。我使用Makefiles系統構建了該項目。我的Makefile如下所示:gdb錯誤:無法執行格式:文件未被識別

CC=gcc 

CFLAGS= -g -c 

all: main.o io_ops.o rw_ops.o help_functions.o 
    $(CC) -o db main.o io_ops.o rw_ops.o help_functions.o 
io_ops.o:io_ops.c db_ops.h 
    $(CC) $(CFLAGS) io_ops.c db_ops.h 
rw_ops.o: rw_ops_c db_ops.h 
    $(CC) $(CFLAGS) rw_ops.c db_ops.h 
help_functions.o: help_functions.c 
    $(CC) $(CFLAGS) help_functions.c 
clean: 
    rm *.o db 

我的可執行文件名爲db。所以,我在我的終端上運行下面的命令:

gdb db 

然後我就GDB鍵入以下命令:

list main.c 

我得到以下錯誤:沒有定義的main.c 我試着鍵入以下命令:

list main.c 

我得到以下錯誤: 的main.c:不可執行文件格式:文件無法識別

爲了確保我的GDB是64位的程序,我輸入以下命令:

(gdb) show configuration 
This GDB was configured as follows: 
configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu 
     --with-auto-load-dir=$debugdir:$datadir/auto-load 
     --with-auto-load-safe-path=$debugdir:$datadir/auto-load 
     --with-expat 
     --with-gdb-datadir=/usr/share/gdb (relocatable) 
     --with-jit-reader-dir=/usr/lib/gdb (relocatable) 
     --without-libunwind-ia64 
     --with-lzma 
     --with-python=/usr (relocatable) 
     --with-separate-debug-dir=/usr/lib/debug (relocatable) 
     --with-system-gdbinit=/etc/gdb/gdbinit 
     --with-zlib 
     --without-babeltrace 

這是我的可執行的一些信息:

db: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=25731950b7f76cf428eeca5fcc534555d677f3dc, not stripped

我不知道,是什麼問題。任何想法?

+0

你的'Makefile'是非常錯誤的;看[這](http://stackoverflow.com/a/16751650/841108) –

+0

爲什麼我的Makefile錯了? – amitakCs

+0

尤其是,因爲您明確地編譯了頭文件。你應該使用'-Wall -g'作爲你的編譯標誌。 –

回答

2

你想要做什麼是list main.c:1

list沒有作出列表中的文件,你使用它的方式。從GDB的幫助:

(gdb) help list

List specified function or line.

With no argument, lists ten more lines after or around previous listing.

"list -" lists the ten lines before a previous ten-line listing.

One argument specifies a line, and ten lines are listed around that line. Two arguments with comma between specify starting and ending lines to list. Lines can be specified in these ways:

LINENUM, to list around that line in current file,

FILE:LINENUM, to list around that line in that file,

FUNCTION, to list around beginning of that function,

FILE:FUNCTION, to distinguish among like-named static functions.

*ADDRESS, to list around the line containing that address.

With two args if one is empty it stands for ten lines away from the other arg.

1

I do not know, what is the problem.

你可能想list main代替。

說明:有命令的four forms命令,沒有將文件名作爲參數。

+0

那麼,在我的gdb 7.10上,有2個:'FILE:LINENUM,列出該文件中的那行'和'FILE:FUNCTION,以區分類似命名的靜態functions'。該文檔似乎不是最新的。 – jbm

相關問題