First of all, I want to point that I have no C programming background so a more detailed answer will help me a lot. I downloaded a C mp3 decoder project from here and I need to debug it in order to understand some steps from the mp3 compression algorithm.
I've learned the basics of GDB from different tutorials so I started by compiling the project using the Makefile included, then I ran GDB for the compiled output like this:
gdb --args mp3decode test.mp3
But when trying to list the files to set a breakpoint I get this:
(gdb) list
init.c:1: No such file or directory.
Googling a little bit about above output, the more common mistake when compiling is not using the -g option however I made sure that option is in the Makefile.
CFLAGS = -g -O4 -funroll-loops -Wall -ansi -DOUTPUT_SOUND
OBJS = MP3_Bitstream.o MP3_Decoder.o MP3_Huffman.o MP3_Huffman_Table.o \
MP3_Main.o MP3_Synth_Table.o main.o remote_control.o audio.o debug.o
Then later:
mp3decode: $(OBJS)
$(CC) $(CFLAGS) -o mp3decode $(OBJS) -lm
What I want to achieve is to set a breakpoint on line 46 of main.c file and then step into the MPG_Get_Filepos() method on the same line, but the main.c is not listed in the GDB console.
I think the problem is in the compile command since creates a C object for all files (don't know if I'm wrong) and that's why I cannot debug the code.
What can I do to debug step by step in a project like this? Your help will be appreciated, thanks.
UPDATE:
This is the command I'm using to compile the program:
gcc -g -funroll-loops -Wall -ansi -DOUTPUT_SOUND -o mp3decode MP3_Bitstream.o MP3_Decoder.o MP3_Huffman.o MP3_Huffman_Table.o MP3_Main.o MP3_Synth_Table.o main.o remote_control.o audio.o debug.o -lm
Then I use GDB with tui to debug it:
$ gdb -tui --args mp3decode test2.mp3
(gdb) br main
Breakpoint 1 at 0x804ea2e
(gdb) run
Starting program: /home/jorge/Documents/mp3decoder/mp3decode test2.mp3
Breakpoint 1, 0x0804ea2e in main ()
(gdb) list
init.c:1: No such file or directory.
br main
thenrun
thenlist
. – n. 1.8e9-where's-my-share m.-O4
. Optimization produces assembly that can appear to be almost unrelated to the source files in the debugger. – AShellyrun
?init.c
is not a file you are supposed to see. It's a source file from the standard library. If gdb tries to list this file, the program is not stopped in your code. – n. 1.8e9-where's-my-share m.