Setting a breakpoint on calling abort() - c++

I am debugging an application and for some reason (which I'm not quite sure), when closing my application abort() is called. I'd like to try and find the reason for this, so I want to place a breakpoint on abort() so I can see the stack trace and hopefully discover the reason it was called instead of a graceful exit.
I am using Microsoft Visual Studio 2012 (Update 3) and only have the declaration for the abort() function (in stdlib.h) and so I can't set a breakpoint. Is there any way to get around this?

You don't need to do anything special. abort call from C/C++ program built by Visual Studio produces the following message:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Error!
Program: ...
R6010
- abort() has been called
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
Pressing Retry opens debugger with full call stack. This functionality is available both for Debug and Release configurations, when program runs in standalone mode and under debugger. In Release configuration the dialog is different, it contains Break button, which opens debugger, like Retry in Debug configuration.

I had the same problem and found this answer which works for me: Press CTRL+B and enter 'abort' in the text field.

Just for debug, you may overrides abort function and set a breakpoint inside.
void abort()
{
std::cout << "aborting" << std::endl; // put break here...
exit(-1);
}

In case of linux gdb, upon hitting abort, you could see easily stack trace with command bt. No need to add extra break point.

Related

Debug a Qt assert in Visual Studio

I am getting an assert that generates a dialog from Qt to abort, retry, or ignore. Unfortunately, when I retry, it always just goes to app.exec() so I cannot see where the error is coming from, or what inputs may be contributing.
When I debug, I can see all my code and moc code, and all variables and pointers are set appropriately. But when I step into Qt code, I get Qt5Cored.pdb not loaded. I cannot seem to locate the PDB files in my Qt installation either.
The error happens after emitting a signal and all (my) slots have completed successfully.
The error from Qt is so deep in the weeds, it is not helpful:
Debug Error!
Program: Qt5Cored.dll
Module: 5.14.2
File: painting\qoutlinemapper.cpp
Line: 105
ASSERT: '!path.isEmpty()' in file painting\qoutlinemapper.cpp, line 105
(Press Retry to debug the process)
I inspected the source code for the error, but that wasn't terribly helpful, and the debugger will not provide the caller.
I don't know what is the problem since I can't debug, so I can't provide a minimal working example either. All of my code is working as expected, but I am sure I am providing Qt with something inappropriate, but I just do not know what. Any help on how to better debug this issue so I can determine what is causing it would be appreciated.
Interestingly, if I run in release and the assert is bypassed, the applications works exactly as expected with no obvious side effects (I do realize that could just be luck).

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.

Cannot debug my STM32 CubeIDE project anymore, but code works without J-Link

I somehow have fallen in the state where I cannot start in debug mode my project in CubeIDE and J-Link. The code compiles, flash is written, but then instead of stopping on the first instruction in my main function in main.c, I get stuck in the Disassembly part of the project.
In title bar it says "Source not found" and in working window it says:
Break at address "0x20011b88" with no debug information available, or outside of program code.
Disassembly on this address shows:
20011b88: bkpt 0x0000
but step into pops up the window with:
Failed to execute MI command: -exec-step 1 Error message from debugger back end; Cannot find bounds of current function
I must be missing something obvious here, and will appreciate any guidance.
Also some pointers, where to study, how project debuging is started in details, will be welcomed.

VS debugger skips breakpoints within same scope

I'm debugging ASP.NET application
I have two breakpoints in this method:
private void Load()
{
Stopwatch t = Stopwatch.StartNew(); //breakpoint A
...
LoadStuff(blah); //breakpoint B
}
When I launch LocalIIS(GoogleChrome) in VS, debugger stops at breakpoint B. Previous Call Stack calls Load(). Moreover, I have a breakpoint from where Load() is being called, it doesn't stop there either. Why it skips breakpoint A? Is there a way not to skip it?
Moreover, I have a breakpoint from where Load() is being called, it
doesn't stop there either. Why it skips breakpoint A?
It seems that breakpoint A is invalid on your side due to some reasons. One possibility is that the referenced DLL is out of sync with the version of the code you are debugging or you changed the code and it is inconsistent with the pdb symbol debugging file.
In first of all, please enable Just my code option in case VS ignores breakpoint A.
Solutions
Make sure optimizations are disabled (this is the defaut for the Debug configuration, but they are enabled in Release configuration). Compiler optimizations can mess with the debugger
Besides, try these steps to generate the latest pdb files from server to match your project.
1.clean the solution
2.Tools-->Options-->Debugging-->Symbols
First empty the old pdb symbol files and remember to choose "Load all modules,unless excluded" from Microsoft Symbol Servers and NuGet.org.Symbol Server.
3.Load all symbols from servers which provides for debugging project
4.Rebuild your project which generates the DLL that matches your project.
You can refer to this for more information. Hope it could help you.

Using Netbeans IDE 7.0.1 for C++, how to enable more debugging information (i.e. as with "-g3" with gdb)

As mentioned in the title, I am using NetBeans IDE 7.0.1 for C++ (for the assignments at the university). I was using gedit and terminal, but I would like to try my hand at IDEs.
I tried Eclipse but I seem to prefer Netbeans interface.
(All the above->with my laptop, running Ubuntu 11.10).
Well, I have some questions,
Is there any way to "enrich" the "RUN FAILED (exit value 1, total time: 470ms)" message with a "Segmentation fault", as well? (or this is how the IDEs work, run and if you get a "run failed" go to debug mode?)
Also, at debug mode, when I get a segmentation fault I get a new window saying "Signal Caught" and then this:
Signal received: SIGSEGV (?) with sigcode ? (?)
From process: ?
For program testing_netbeans, pid 15,211
You may discard the signal or forward it and you may continue or pause the process
To control which signals are caught or ignored use Debug->Dbx Configure
with three options available ("Discard and Pause", "Discard and Continue", "Forward and Continue"). What do each of the above options do?
How is it possible to get the line where the error occurs? (in example with gdb I would compile with -g3 option and then run with gdb. But now how can I do that by default?
What I did like about eclipse is the fact that it would have a default breakpoint at the 1st line of the main function, is there any way to do that by default?
Thank you for your time!
The compiler flag is -ggdb. It allows you to use breakpoints, know the values of variables and etc.
If you are just building in "debug mode", you will get minimal information, such as line of crash by opening the "call stack" page.
Eclipse is a bit better for debugging, but as an editor, I much prefer Netbeans over it for C++, while I prefer Eclipse for Java
EDIT: Also, you have to have setupped GDB as the debugger in Netbeans, but I'm pretty that's done by default.