2

I am trying to debug my project, which consists of 5 files. I built the project using a Makefiles-system. My Makefile looks as the following:

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

My executable file is named db. So I run on my terminal the following command:

gdb db

Then I type the following command on gdb:

list main.c

I get the following error: main.c not defined I try to type the following command:

list main.c

I get the following error: main.c: not in executable format:file not recognized

To ensure that my gdb is 64-bit-program, I typed the following command:

(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

And this is some informations about my executable:

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

I do not know, what is the problem. Any idea?

6
  • Your Makefile is grossly wrong; see this Commented Oct 11, 2015 at 14:29
  • why is my Makefile wrong? Commented Oct 11, 2015 at 14:32
  • In particular, because you compile explicitly header files. And you should use -Wall -g as your compilation flags. Commented Oct 11, 2015 at 15:06
  • -Wall: Why should I use it. What does it do? Commented Oct 11, 2015 at 16:57
  • 1
    @amitakCs -Wall activates "all" warnings (well, not all, but many of them, the most important, the one that almost 100% sure shows a programming mistake). You want -Wall . Always. Do use it. -Wall is your friend. -Wall will save you a considerable time in debugging. Commented Oct 11, 2015 at 17:07

2 Answers 2

2

What you want to do is list main.c:1

list is not made to list a file the way you use it. From gdb help:

(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.

Sign up to request clarification or add additional context in comments.

Comments

1

I do not know, what is the problem.

You likely want list main instead.

Explanation: there are four forms of list command, none take filename as an argument.

1 Comment

Well, on my gdb 7.10, there are 2: FILE:LINENUM, to list around that line in that file and FILE:FUNCTION, to distinguish among like-named static functions. The doc does not seem up to date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.