Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: "No symbol table is loaded"

Tags:

c

gdb

I keep getting this error mesage when trying to add a breakpoint in gdb.

I've used these commands to compile:

gcc -g main.c utmpib2.c -o main.o
and:
cc -g main.c utmpib2.c -o main.o
and also:
g++ -g main.c utmpib2.c -o main.o

I also tried "-ggdb" instead of "-g" and I still get that error message.

I then execute gdb:

$gdb

In gdb:

(gdb)exec-file main.o
(gdb)break 59
No symbol table is loaded. Use the "file" command.
like image 305
user994165 Avatar asked Feb 12 '12 01:02

user994165


People also ask

What is GDB symbol table?

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like: Program instruction ⇒ item name, item type, original file, line number defined.

How do I remove a breakpoint in GDB?

With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers.

How do I quit GDB?

Quitting GDB To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.


3 Answers

You have to add extra parameter -g, which generates source level debug information. It will look like:

gcc -g prog.c

After that you can use gdb in common way.

like image 151
alxndr Avatar answered Sep 22 '22 03:09

alxndr


First of all, what you have is a fully compiled program, not an object file, so drop the .o extension. Now, pay attention to what the error message says, it tells you exactly how to fix your problem: "No symbol table is loaded. Use the "file" command."

(gdb) exec-file test
(gdb) b 2
No symbol table is loaded.  Use the "file" command.
(gdb) file test
Reading symbols from /home/user/test/test...done.
(gdb) b 2
Breakpoint 1 at 0x80483ea: file test.c, line 2.
(gdb) 

Or just pass the program on the command line.

$ gdb test
GNU gdb (GDB) 7.4
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[...]
Reading symbols from /home/user/test/test...done.
(gdb) b 2
Breakpoint 1 at 0x80483ea: file test.c, line 2.
(gdb) 
like image 25
Kevin Avatar answered Sep 22 '22 03:09

Kevin


I have the same problem and I followed this Post, it solved my problem.

Follow the following 2 steps:

  1. Make sure the optimization level is -O0
  2. Add -ggdb flag when compiling your program

Good luck!

like image 23
Charles Chow Avatar answered Sep 22 '22 03:09

Charles Chow