gdb错误:不是可执行格式:文件无法识别

时间:2015-10-11 14:15:19

标签: c linux gdb

我正在尝试调试我的项目,该项目由5个文件组成。我使用Makefiles系统构建了项目。我的Makefile如下所示:

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位LSB可执行文件,x86-64,版本1(SYSV),动态链接(使用共享库),用于GNU / Linux 2.6.24,BuildID [sha1] = 25731950b7f76cf428eeca5fcc534555d677f3dc,未剥离

我不知道,问题是什么。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

您要做的是list main.c:1

list不会按照您使用它的方式列出文件。来自gdb help:

  

(gdb)帮助列表

     

列出指定的功能或行。

     

如果没有参数,请在之前或之前列出十多行   列表。

     

" list - "列出前十行列表前的十行。

     

一个参数指定一条线,并在其周围列出十条线   线。两个带逗号的参数指定开始和结束   要列出的行。可以通过以下方式指定行:

     

LINENUM,列出当前文件中的那一行,

     

FILE:LINENUM,列出该文件中的那一行,

     

FUNCTION,列出该函数的开头,

     

FILE:FUNCTION,用于区分同名的静态函数。

     

* ADDRESS,列出包含该地址的行。

     

如果一个是空的,则有两个箭头,它代表十条线   其他arg。

答案 1 :(得分:1)

  

我不知道,问题是什么。

您可能需要list main

说明:list Using System.Diagnostics; int count; private void Form1_Load(object sender, EventArgs e) { Random num = new Random(); count = num.Next(1, 101); // remove your break point on this line Debug.WriteLine(count); // put your break point here } 命令,没有文件名作为参数。