Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I got a segfault when running my program. Then I googled my question and tried to follow steps from https://www.gnu.org/software/gcc/bugs/segfault.html.
I did not configure GCC with --enable-checking then my first question is -
1) is it necessary to configure it and compile with -v -da -Q ?
But I always do compile with flags such as -g -o0. After running the program in GDB with arguments I get this:
2) I can not print variables after segfault, is it okay ?
3) How to figure out the line of my source code where segfault happens ?
Then I googled my question and tried to follow steps from > https://www.gnu.org/software/gcc/bugs/segfault.html.
These are the steps for GCC developers to follow when GCC itself crashes while compiling your program.
These are not the steps you should follow when debugging a crash in the program itself.
Instead, read this.
How to figure out the line of my source code where segfault happens ?
GDB told you the line: it's common/search.cpp line 172.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
I have project, that builds and runs inside of docker container on my machine, and it works without any errors. I work with video and everything works as expected. But when I build it with fsanitize, it throws:
ERROR: CUDA initialization failure with error 2. Please check your CUDA installation: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Flags that use:
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
CUDA is installed both on host computer and inside of container. Any ideas?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am coding using gedit in ubuntu and running program in terminal. While working in windows using Turboc or netbeans we can debug code line by line. How can we do it in ubuntu terminal? or any other option?
gdb (The Gnu debugger) is best choice
apt-get install gdb
man gdb
1. cc -g file.c // compile your program ,this will generate a.out file with required debugging information
2. gdb a.out // start with gdb
3. b main // to set break point at main
4. run // run now , and it will stop at break point main
5. s // option s is to step single line and even step into functions
6. n // option n is to execute next line and step over functions
7. p variable name // to print the value of variable at that particular instance very helpful
man gdb will give more info
All useful gdb commands and an example with simple cpp program are given Here
GDB Documentation
I find GDB (Gnu DeBugger) to be the best tool for c/c++. It's probably already installed on your system if you have gcc installed.
To use it, make sure you compile your program with the -g flag:
gcc -g myprog.c -o myprog
And then launch the debugger with
gdb ./myprog
Here are some basic commands to get you going:
b lineno - set a break point at line 'lineno'
b srcfile:lineno - set a break point in source file 'srcfile' at line 'lineno'
r - run the program
s - step through the next line of code
c - continue execution up to the next breakpoint
p varname - print the value of the variable 'varname'
You can use gdb for this.
Install gdb if it isn't already installed.
sudo apt-get install gdb
Then you can debug the executable of choice as follows
gdb <executable name>
You get a complete interactive debug session.
You can use an IDE(http://en.wikipedia.org/wiki/Integrated_development_environment) which provides code management, highlighting, debugging facilities. You may try any of these.
QTCreator(http://qt-project.org/wiki/Category:Tools::QtCreator)
KDevelop(http://www.kdevelop.org/)
Eclipse(http://www.eclipse.org/)
or you may choose to use gdb(https://www.gnu.org/software/gdb/) directly from the command line.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Can someone tell me how to debug segmentation fault in linux VIA AFS. I would appreciate if someone could refer me command. I am able to run my code via compiler but not on when i give command g++ -o file1 file2.cpp----> ./file----->segmentation fault
Compile the program with the -g option
g++ -g -o file1 file2.cpp
Then execute the executable created with gdb.
gdb file1
Once you see the seg fault issue bt, this will give you the stack.
frame <frame number> you can see the details about the particular stack.
Happy debugging.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am coding using gedit in ubuntu and running program in terminal. While working in windows using Turboc or netbeans we can debug code line by line. How can we do it in ubuntu terminal? or any other option?
gdb (The Gnu debugger) is best choice
apt-get install gdb
man gdb
1. cc -g file.c // compile your program ,this will generate a.out file with required debugging information
2. gdb a.out // start with gdb
3. b main // to set break point at main
4. run // run now , and it will stop at break point main
5. s // option s is to step single line and even step into functions
6. n // option n is to execute next line and step over functions
7. p variable name // to print the value of variable at that particular instance very helpful
man gdb will give more info
All useful gdb commands and an example with simple cpp program are given Here
GDB Documentation
I find GDB (Gnu DeBugger) to be the best tool for c/c++. It's probably already installed on your system if you have gcc installed.
To use it, make sure you compile your program with the -g flag:
gcc -g myprog.c -o myprog
And then launch the debugger with
gdb ./myprog
Here are some basic commands to get you going:
b lineno - set a break point at line 'lineno'
b srcfile:lineno - set a break point in source file 'srcfile' at line 'lineno'
r - run the program
s - step through the next line of code
c - continue execution up to the next breakpoint
p varname - print the value of the variable 'varname'
You can use gdb for this.
Install gdb if it isn't already installed.
sudo apt-get install gdb
Then you can debug the executable of choice as follows
gdb <executable name>
You get a complete interactive debug session.
You can use an IDE(http://en.wikipedia.org/wiki/Integrated_development_environment) which provides code management, highlighting, debugging facilities. You may try any of these.
QTCreator(http://qt-project.org/wiki/Category:Tools::QtCreator)
KDevelop(http://www.kdevelop.org/)
Eclipse(http://www.eclipse.org/)
or you may choose to use gdb(https://www.gnu.org/software/gdb/) directly from the command line.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have compiled C++ project using cmake utility on Red hat Linux 4.1.2.
gcc version: 4.1
When I try to run object file using following command I got an exception:
./GCVMP ../../dat/settlingsUnix/MPSettings.xml
exception : Fatal Error: æ¹¥åSä
I am not able to understand root cause.
Please help me in this regard.
I suspect that the "Fatal Error:" portion is something printed by your code. It's supposed to be followed by a message explaining the error, but the message passed is corrupted, and so junk is printed.
Have you tried compiling the program with -ggdb running it under gdb? Here's a good starter on how to use the debugger: http://www.ibm.com/developerworks/library/l-gdb/