I'm currently building on Windows 7 and am trying to get my debugger to step through my code. The problem is that, while I have my build configuration set to debug, and my CONFIG variable to set to debug in my QMake file, it still doesn't work.
Here is my QMake file:
TEMPLATE = app
CONFIG += console debug
CONFIG -= qt
QMAKE_CXXFLAGS += -g -gdb
SOURCES += main.c \
Triangle.c \
GlutTesting.c
HEADERS += \
Triangle.h \
Includes.h \
GlutTesting.h
LIBS += -lSDL -lopengl32 -lfreeglut
Note that it's actually written in C and compiled as such (all of the files are native C code, compiled with MinGW).
The issue is that everytime I start, even if I set a breakpoint, the code literally just zooms through it to the end of the applications current setting and stops there. It's almost impossible to actually debug my applications now.
What is wrong here? Everytime I Google I just find something about "adding debugging symbols", which is easy to do in Linux, but in Qt Creator it seems quite the PITA to get done properly (unless I'm just missing something totally simple).
Faced the similar problem on Linux (Fedora 16) using Qt Creator 2.5.0
It turned out that gdb started in my home directory and could not (I don't know why) load debugging symbols of a library being debugged. Whenever I force gdb to start from directory where the library binary file is placed (in Qt Creator it is done through additional debugger startup commands in Tools->Options->Debugger->Additional Startup Commands: just make "cd" to the directory with binary file) everything works fine.
One more solution is to set the environment variable LD_LIBRARY_PATH to contain full path to the directory with binary. In Qt Creator it is done in Project->Run Settings->Run Environment.
In order to check that debugging symbols have been loaded properly open gdb log via Window->Views->Debugger Log and type the command "info shared".
This worked for me under Linux, and I'm not sure if it'll work under Windows but here it goes anyway:
in the .pro file, I added the line:
CONFIG += debug
This enabled debugging within the QT system. Then i added the following:
QMAKE_CXXFLAGS += -O0 -g -ggdb
The -ggdb is for the gdb support. And the O (letter O) 0 (number zero) to be no optimisation - to prevent the compiler from optimising out variables. This gives me the backtraces i need with all the symbols when debugging under Linux. This is a fairly standard debugging compiling option across the board with gdb. But it may already be covered by the debug option in CONFIG.
Under Linux i rebuilt the project too:
make clean
make
But for Windows, if you're using Visual Studio, you might need to do a rebuild. I don't know what your compilation toolchain is.
I know you're using Windows, and it might be worth trying these things in case it works under Windows too. However, even if it doesn't work under Windows, it could be useful for someone searching for how to do this under Linux, so I think this is a valid answer, even though it may not specifically answer this particular question.
Related
How can I build and install a C program with debugging symbols on OS X?
I'm trying to build something (mutt) with debugging symbols on OS X, to help me track down a crash. I'm basically following the Homebrew formula for mutt in my build process. But no matter what I try, the resulting binary has no debugging symbols. I build it with CFLAGS='-g -O0' (after having also tried the default '-g -O2' in the Makefile). I can see when I see the make output go by that it is using these flags as it should be, and I don't see any strip or install -s invocations; but the resulting binary has no debugging symbols, as seen by trying to run it in gdb or lldb, or running dsymutil on it.
I'm trying to understand the Valgrind instructions on the matter; basically, they say that the linker on OS X doesn't actually put debug symbols that exist in the object files into the linked result -- I read that as saying you have to run dsymutil on the linked result, but I'm a little unsure as to whether that automatically pulls in the symbols from the object files, or if there's some way I need to specify them.
And even if I knew exactly how to use dsymutil here, I don't see that there are any debug symbols in any of the .o files.
Finally, I'm wondering if a "proper" installation, once I got the debugging symbols into the binary, would copy that .dSYM directory into /usr/local/bin along with mutt; or if it would go somewhere else. I know in Debian-based systems you can install specifically debuggable versions of libraries using the package manager, but I don't know if it's a best practice (or even a practice that's common) to actually install things with debug symbols in OS X. If nothing else, I can probably just run the debuggable binary from its build directory, so this doesn't seem like a big deal.
I've tried building with gcc and clang, with the same disappointing results.
I'm trying to debug a new Janus plugin using Netbeans IDE 8.0.1. It hits my breakpoints OK but when trying to step through the code it's jumping all over the place and I'm frequently seeing 'optimized out' when trying to inspect variables. I'm fairly sure this is because the code has been built with optimization enabled.
Assuming this is the problem, how do I rebuild it with optimizations disabled please? I've tried running configure with 'CFLAG=-O0 -g' followed by a clean & build, but I'm still getting the same problem. The Janus configure file has a couple of promising looking environment variables, JANUS_CFLAGS and PLUGINS_CFLAGS. However, when I try to set these to '-O0 -g', clean and make I get a compilation error:
fatal error glib.h: No such file or directory
Any suggestions would be appreciated.
If you change the compilation from the make file(not from the command line), it should work to make the non-optimamized.
Specifically, the line CFLAGS = -g -O2 should be changed to CFLAGS = -g -O0. I know this works with GDB(and consequently eclipse) and SHOULD work with any other debugger.
I just started coding in C, and ran someone else's Makefile with the default C compiler set to gcc. I am on Mac OSX 10.8 Mountain Lion and I believe I installed the compiler with "XCode Command Line Tools." After running "make" on command line, I get these annoying .dSYM files for each program. I read that these are debug files, but are they really necessary? Is there any way to prevent them from being generated from command line?
The -g flag to GCC will generate debug symbols. You may simply remove that flag from CFLAGS.
Yes, the dSYM files are necessary. Specifically, they contain the symbol tables that are included within Xcode debug builds; release builds put the symbols in this separate file. If you ever need to analyze a stack trace from a release build you will need this. And make sure you don't lose the files, because doing the build again, even if the source is absolutely the same, won't produce a usable dSYM file. Each build is given a UUID and that changes with each build, even if the source has not changed. (I guess it includes a timestamp or even a random number.)
If you throw away the dSYM files, then if you suddenly find your app crashing a lot, you may be sorry.
They're only necessary if you need to interpret locations in stack traces within a crash report.
I am asked to debug a C code containing a number of .c files and is complied using a Makefile on a Redhat Linux system. I want to debug that whole code. How to go about it? What changes do i need to make in the Makefile?
I am using gcc as the compiler.
If you're using GCC as compiler add to the CFLAGS variable the -g option. Then you'll be able to debug the resulting executable using the gdb command.
First you need to add the flag "-g" during compilation(make this change in the makefile.if already present then no need). this will open up the symbols for debugging the code.
use the debugging tools available like gdb, dbx, mdb which ever is available in your system.
many resources are available for debugging. one of them is here
Add -g option in your makefile in order to invoke gdb debugger in the future.The way you debug on gdb is like : gdb yourprogram,then you will be redirected to another interface.type "run yourarguments" to start off debugging
C.Vim works, as evidenced by the commands I've been using, syntax highlighting, and template. But I use \rc and nothing happens. \rr tells me that there is no .exe, and an Everything search tells me that it's not a directory issue.
In all the resources I've read, I don't see anything that says I need to point it to a specific compiler, though I've installed Visual Studio 2010.
How do I get C.vim to compile my code? I'm a relative beginner with Vim and C.
Edit: I've set the Windows Environment Variable to C:/cygwin/bin where I've downloaded and installed the GCC packages, but am still getting the same error.
Edit2: I've downloaded Msys and Mingw as well. I tried setting up Eclipse as well, following the instructions here. Running make from the command line tells me that GNU Make 3.81 is running. Running :make in Vim tells me:
shell returned 2
(1 of 1) : make *** No targets specified and no makefile found
Trying Eclipse, I get another make error:
make: *** No rule to make target `all'; Stop.
Edit3: I got Code::Blocks running, which is what I used to run. (It's been a while since I programmed, and even then I was a beginner.) I didn't really have to configure it at all, though I would still prefer to use Vim, so help is still much appreciated.
Edit4: running make vimFirst (vimFirst.c is my file) compiles! Running the program with :! vimFirst.exe works as expected. Now returning to the original question, how to do it with C.vim? It would be so much more convinient to type \rc and have the program compile and run, which is about 1/10 of the typing of the other method.
Edit4: running make vimFirst (vimFirst.c is my file) compiles! Running the program with :! vimFirst.exe works as expected. Now returning to the original question, ... type \rc and have the program compile and run...
Check your maps for \rc and \rr:
:map \rc
:map \rr
If no mapping exists, you might have no_plugin_maps or something similar set in your vimrc.
I think you'll get what you want if you set them up like this:
nmap \rc :make %<<CR>
nmap \rr :! %<.exe<CR>
If you're really familiar with Visual Studio and want to use nmake to build your code, you should check out the :compiler option. :compiler msvc will setup your makeprg and errorformat for nmake and Visual Studio's compiler.
I'm not sure what make is currently using to build your code, so I don't know what compiler setting you'd want.