Debugging not starting at breakpoint - c++

I made a program in Qt creator for c++ using opencv libraries.But i want to debug it and have set a breakpoint at the desired line. However no matter where I set the breakpoint the debug mode always starts at the first line of the main() program.How can I solve this?

I solved this problem by deleting *.pro.user file and restarting IDE.

Related

Can gdb set a breakpoint on a tsan-detected race condition? [duplicate]

There is a similar question for address sanitizers, but for thread sanitizers, it doesn't work, I have tried to break on __sanitizer_print_stack_trace, which doesn't work either.
Run the program under GDB, set breakpoints on exit and _exit. On Linux, also set catch syscall exit_group.
set halt_on_error=1 in TSAN_OPTIONS to ask thread sanitizer to exit on first error:
(gdb) set env TSAN_OPTIONS=halt_on_error=1
(gdb) run
... error should be reported and one of the breakpoints should fire.
Profit.
P.S. When the breakpoint is hit, use GDB where command to see how the error is reported. Setting a breakpoint on some kind of __tsan_report_error that is likely on the stack will probably work even without setting halt_on_error.
The first time I enabled Thread Sanitizer on my project, Xcode helpfully added a breakpoint for me in the Breakpoint Navigator. But I deleted it when I was done testing. Now I need it again and Xcode didn't create it for me when I enabled Thread Sanitizer again.
Note that I am using Xcode 11.0 here.
To manually re-create this breakpoint, you need to have the Breakpoint Navigator open. Then click the plus button (+) at the bottom-left of the navigator and select Runtime Issue Breakpoint from the pop-up menu. This adds the breakpoint to the navigator, and a window appears.
From the Type drop-down list, select Thread Sanitizer.
There you go! Silly that this option is buried way down there. But I also found it helpful to note that there are more options for different kinds of breakpoints available from that plus button menu than there are from the main Xcode drop-down menu Debug > Breakpoints.

Visual Studio 2015 does not break on assert in gtest [duplicate]

I recently discovered the Failures into Break-Points - option from googletest using the command line option gtest_break_on_failure or by defining the GTEST_BREAK_ON_FAILURE environment variable.
I gave it a try using gtest_break_on_failure. From command line, I saw no effect (to be honest I had the glimpse of hope that VS2010 would be registered as debugger and somehow magically would pop up and point to the error source).
Using it in the VS environment as command line argument a failed assertion triggered a break but the call stack did not include the test method that caused the failure. I found the work around to step (F10) until I reached my test code, but that does not really seem to be convenient.
Is it somehow possible to use the option from command line ?
Has anybody a recommendation how to get the correct call stack in the environment?
From VS, you can add --gtest_break_on_failure to the Command Args in the target's Property Pages, then just run the exe without stepping over.
From the command line, you should be able to run the Debug executable with the flags --gtest_break_on_failure --gtest_catch_exceptions=0 and this should allow you to break into the MSVC debugger when the test fails.

How to make QtCreator show "normal" code while debugging instead of assembly?

I am using QtCreator 3.6.1 on Ubuntu 14.04 with gcc as my main compiler.
My Qt project is being built in debug mode. However, whenever I press F5, to try to step into the code by setting break points, my code crashes (since the code is buggy) but instead of stopping at the breakpoint, it shows me assembly output!
Here is a screen shot. The code seems to have crashed at where you see the yellow arrow, but I just don't know where in the source code it is!!!
In fact, I have set my breakpoint at a cout statement as you can see here.
Not even the cout statement is executing. The code seems to be crashing before main is executed. I don't know if this is QtCReator problem or something else. I have added -O0 and -g option
to the QMAKE_CXXFLAGS option just to be sure, that debugging symbols are being added, yet I get this problem.
EDIT:
My stack trace looks like this
Also I am not sure if this helps, but when I run the program through the terminal with LD_DEBUG in front of the program's name, I get a huge amount of output.
The last three lines are
.
.
.
7934: symbol=_ZN11QMetaObject8addGuardEPP7QObject; lookup in file=/usr/lib/x86_64-linux-gnu/libQtGui.so.4 [0]
7934: symbol=_ZN11QMetaObject8addGuardEPP7QObject; lookup in file=/usr/lib/x86_64-linux-gnu/libQtCore.so.4 [0]
7934: binding file /usr/lib/x86_64-linux-gnu/libQtGui.so.4 [0] to /usr/lib/x86_64-linux-gnu/libQtCore.so.4 [0]: normal symbol `_ZN11QMetaObject8addGuardEPP7QObject'
[1] 7934 segmentation fault (core dumped) LD_DEBUG=all ./CGALQT_Fix_MainWindow
for this, your application has to link to debug libraries. To investigate where your app crashes, you don't usually need this because you can see all of your own methods in function stack.

Debugging C++ in Netbeans

I am very new to work c++ Programs with Netbeans IDE in Ubuntu. I wrote a simple Hello World Program and tried to debug it using step Into. When I Click Step Into Option From Debug Menu I got new window opened in the name of " Diassembly(main) " . The Debug process didn't reach my source code line at any way. I repeatedly click Step Into Function At last the process got end Without Tracing my source code line. But In the Debug output window I got the Correct Result.
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello";
cout<<"World";
}
Why This process Control goes to the Diassembly (main) window ? How to rectify this problem ?
You must compile with -g option, otherwise the debugger won't be able to stop on a breakpoint. As for disassembling window - I can't reproduce that (I'm on Netbeans 7.4 in Ubuntu 13). You should just close the window if you don't need it.
First, you have to toggle a break point in your code by clicking on the line number of the line you want to stop in source window, if you did not. Then hit Debug.
Don't step into function that you not build from source, just step over it.
Pehaps that there is an answer here (i can't comment sorry)
"No source available for main()" error when debugging simple C++ in Eclipse with gdb

How do I use the MinGW gdb debugger to debug a C++ program in Windows?

I have looked for documentation on this and found nothing. I have MinGW installed and it works great. I just don't know how to use the debugger.
Given some simple code, say in a file called "mycode.cpp":
int main()
{
int temp = 0;
for (int i = 0; i < 5; ++i)
temp += i;
return 0;
}
...how would I debug this. What are the commands that I use to debug code with MinGW and GDB in windows? Can I step through the code via the command line like in Visual Studio? If so what commands do I use to do that?
Are there any tutorials for using GDB out there? I couldn't find any, but if anyone could direct me to one that would be great too. I'm tired of writing tons of std::cout statements to debug complex code.
The first step is to compile your program with -g to include debugging information within the executable:
g++ -g -o myprog.exe mycode.cpp
Then the program can be loaded into gdb:
gdb myprog.exe
A few commands to get you started:
break main will cause the debugger to break when main is called. You can also break on lines of code with break FILENAME:LINENO. For example, break mycode.cpp:4 breaks execution whenever the program reaches line 4 of mycode.cpp.
start starts the program. In your case, you need to set breakpoints before starting the program because it exits quickly.
At a breakpoint:
print VARNAME. That's how you print values of variables, whether local, static, or global. For example, at the for loop, you can type print temp to print out the value of the temp variable.
step This is equivalent to "step into".
next or adv +1 Advance to the next line (like "step over"). You can also advance to a specific line of a specific file with, for example, adv mycode.cpp:8.
bt Print a backtrace. This is a stack trace, essentially.
continue Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.
The best thing to read is the GDB users' manual.
There are a few gdb guis for windows in this question windows version of the GDB frontend DDD
Although DDD hasn't been ported