c - gdb错误: not in executable format: file not recognized

标签 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-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=25731950b7f76cf428eeca5fcc534555d677f3dc, not stripped

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

最佳答案

你想要做的是列出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.

关于c - gdb错误: not in executable format: file not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33066019/

相关文章:

c - C中使用指针的两个数组的总和

linux - 如何在已安装的 RPM 包中进行多重搜索?

linux - 交叉编译器ldd

c++ - 使用 C++ 运行一个进程,过滤输出并获取结果代码并获取系统错误,全部一起

gdb - 核心转储注释部分

是否可以使用 gdb 或其他工具来检测复杂程序的某些部分(例如循环),这些部分的目标优化时间比预期的要长?

C++ 内存错误 : free(): invalid next size (fast)

c - 等待所有子进程退出

c - 使用参数运行程序而不是填充值

c - 内存映射文件无法在不取消映射的情况下关闭,因为它仍然被引用