No debugging information found from gdb - gdb

I'm working on a single C file project. Here is the make command:
gcc -std=c99 -ggdb picaca.c -o aca -lm
It has segmentation fault. I used gdb to backtrace the segmentation, but it could not find debugging information:
Program received signal SIGSEGV, Segmentation fault.
0x0000000200419a77 in ?? ()
I double checked to have -g in gcc command, and set ulimit to unlimited. How do I fix this error?

Do you have core files enabled? Try 'ulimit -c unlimited' on the command line if you don't see a core file in the execution directory.

Related

Debugger error: not in executable format: File format not recognized

I've written a program, saved it on the desktop under the name 'Swap.cpp' and when I run gdb (the first time), I get the error:
"/Users/myname/Desktop/Swap": not in executable format: File format
not recognized.
I have no idea what I'm doing wrong. Any help will be appreciated.
Sorry I should've given more information:
I am using Mac OS.
I've already compiled the program and have the Swap.o file that I can see on my desktop.And here are the commands that I enter while trying to run the debugger from bash:
$ clang++ -g Swap.cpp -o Swap
$ ./Swap
this runs Swap and then I try to access the debugger using:
$ gdb Swap
that then gives me the aforesaid message. I tried doing what Rakholiya Jenish suggested but to no avail.
To run gdb on windows:
path_to_gdb.exe program_to_debug
If the compilation was not proper, either compile it with your IDE (if you are using) or with g++ using cmd.exe as:
g++ -g Swap.cpp -o output -lm
I figured out how to use lldb instead of gdb. lldb works just fine. Here is what I did:
$ clang++ -g -o Swap Swap.cpp
$ lldb Swap
Thank you all for your help.

GDB hangs on GNU Fortran stack frame

I have a large, mixed C++ and Fortran code base that I'm trying to debug.
The program is built with GCC and GNU Fortran version 4.8. The Fortran code is built with -c -g -cpp -ffixed-line-length-none -ffree-line-length-none -fcoarray=single -fno-underscoring -fPIC and the C++ code is built with -g -Wall -Wno-reorder -Wno-parentheses -std=c++11 -Wno-unknown-pragmas -fPIC. The program is linked with g++ -g ... -lgfortran.
When I run the program in GDB, I can set a break point in the Fortran code using break my_func.f90:35. However, when the program hits that breakpoint, the debugger appears to go into an infinite loop trying to print out the stack trace. If I press Ctrl+C at this point, I get a truncated stack trace, like this:
^CBreakpoint 2, my_func (accinfile=Quit
(gdb)
So the program has hit the breakpoint, it seems something is going wrong with the stack trace. If it breaks in C++ code but with a Fortran function in the stack trace, I get the stack trace up to the Fortran part, but again a hang at that point.
I've confirmed that GDB works with a very simple C++/Fortran program.
Has anyone come across this behaviour? Is there a known solution?

gdb not debugging mingw32-g++ compiled code well, but works with g++

I have a simple c++ program I'd like to debug with gdb. When I compile it with
g++ -g main.cpp -o main.exe
I can use gdb just fine with the resulting executable. But when I use
mingw32-g++ -g main.cpp -o main.exe
gdb says things such as
in ?? ()
and functionality is limited; I seem to be able to set break points and run the program, but stepping and such yields the message
Cannot find bounds of current function
As I said, this only happens when compiling with the mingw32-g++ executable, and not with the plain g++ one.
Why is this, and how can I debug executables created with migw32-g++? Both executables run without issue.
Extra info:
Am on Windows 7.
g++ version: 4.8.2
mingw32-g++ version: 4.8.1
gdb version: 7.6.50.[lots of numbers]-cvs
If there's any other info I can provide to help find the issue, just let me know.

gdb core file missing

I used to use GDB to debug my C/C++ program. But after the server crashed and reinstalled, the GDB is not working properly. After the program reports a 'core dumped', actually the core file is not found. My flags to compile is:
CFLAGS= -ggdb -g -pg -Wall -O2 $(shell pkg-config --libs glib-2.0 gthread-2.0 --cflags glib-2.0)
And I also set this:
ulimit -c unlimited
I already remove all object/executable files and recompile. But the core file is simply missing. Could anybody tell what is other probable reason? Thanks.
On my machine (Ubuntu 12.04), the file /proc/sys/kernel/core_pattern pipes the core dumped result to /usr/share/apport/apport:
|/usr/share/apport/apport %p %s %c
So changed to pattern:
sudo bash -c 'echo core.%e.%p > /proc/sys/kernel/core_pattern'
It works.
Reference: Unable to create a core file for my crashed program

Debug argument based C program with gdb

I have c++ program which I run by passing string with it.
g++ -o a main.cpp -lpthread
and execute it with ./a "Good nice"
But how I debug it with gdb?
main.cpp calling functions from other files which are included in it.
gdb ./a "Good nice"
takes "--" as files and says no such file!
I want to debug line by line!
Use the --args option of gdb:
gdb --args ./a "Good nice"
Also add the -g option to your compiler call, because otherwise gdb won't be able to connect your executable with your source code:
g++ -g -o a main.cpp -lpthread
Use gdb without argument
gdb ./a
Then in gdb, before running the program
set args "Good nice"
And you can see what arguments you set, use
show args
See here for detail.
gdb ./prog -> set args string -> run.
Anther choice is provide argument after run
$gdb ./a
run "Good nice"