User forums > Help
Debug pb
syp:
First I apologize for my english, im french.
I have a big pb with debugging.
config: win10, cb 20.03, mingw from cb, language c++
my problem can be reduced to :
--- Code: ---#include <cassert>
int main() {
assert(true);
assert(false);
return 0;
}
--- End code ---
Compiled in debug mode the console does not show assert error and exits directly not stopping.
Debuggers window tells :
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.8
Child process PID: 20048
[Inferior 1 (process 20048) exited with code 03]
Debugger finished with status 0
I have tried with other debuggers (lastest mingw, tdm gcc), uninstalled/reinstalled CB, tried CB nightly build, uninstalled/removed all cb occurrences from registry and disk/reinstalled etc.
No change: the console close and asserts are not shown.
Note that previously it was same with c++ exceptions but now they are shown. juste the console does not stop too.
If someone can help...
(Edit: No answer found on the forum too)
BlueHazzard:
from https://www.cplusplus.com/reference/cassert/assert/
--- Quote ---macro
<cassert>
assert
void assert (int expression);
Evaluate assertion
If the argument expression of this macro with functional form compares equal to zero (i.e., the expression is false), a message is written to the standard error device and abort is called, terminating the program execution.
--- End quote ---
and for abort :
--- Quote ---The function raises the SIGABRT signal (as if raise(SIGABRT) was called). This, if uncaught, causes the program to terminate returning a platform-dependent unsuccessful termination error code to the host environment.
--- End quote ---
So the console should close immediately... Have you tried it to run in cmd, there you should see the output, because it only closes the process, but not the console window
The debugger will only stop if you add a breakpoint, or if you use c++, throw an exception and enable halt on exception...
i do not know if it is possible to halt on SIGABRT on windows....
https://stackoverflow.com/questions/33646862/what-is-the-proper-way-to-break-on-failed-asserts-in-gdb/40594011
--- Quote --- exited with code 03
--- End quote ---
I do not know the exit code of the gcc clib on windows for SIGABRT is, but i think the normal execution should terminate with 0 or 1, so you definitely hit the assert and consequently the abort
syp:
Thank you for the answer.
I code in c++ for 40 years and fortunately I have found time to learn how assert and breakpoints work :)
My problem is : running in debug mode the console usually report the exception or assert, waiting the user to hit a key then closing. But now the console 1) does not report asserts (but finally report std exceptions) 2) exits directly
syp:
more, checking various implementations, assert is nothing more than :
if (!value)
print(value)
abort()
here a gnu excerpt :
--- Code: ---__BEGIN_DECLS
#ifndef __cplusplus
void abort(void) __dead2;
#endif /* !__cplusplus */
int printf(const char * __restrict, ...);
__END_DECLS
#define assert(e) \
((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__)))
#define __assert(e, file, line) \
((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())
--- End code ---
from so simple code, failed assert is always reported in debug mode and I should see it !
BlueHazzard:
--- Quote ---I code in c++ for 40 years and fortunately I have found time to learn how assert and breakpoints work
--- End quote ---
From where should i know that you program for 40 years? In this forum are 90% beginners, so i do not expect anyone with this much experience here....
Still, you do not describe in detail what the problem is...
Can you make a step by step description?
1) Open codeblocks
2) Create new project
3) Paste the code from top
4) Hit compile and run
5) Console window pops up but closes immediately. I expect that it remains open...
for me step 1 to 5 work without problems, in step 5 the console stays open
1) Open codeblocks
2) Create new project
3) Paste code form the top
4) place a breakpoint in line 3
5) Hit debug
6) Program exits, but it should stop in line 3
Also this works for me for step 1 to 6. But on step 6 for me the debugger stops and whaits for next instruction
1) Open codeblocks
2) Create new project
3) Paste code from the top
4) Hit compile and run
5) close codeblocks
6) go to the project bin folder
7) Double click my program
8) Black window pops up for a short time. But i expect to read some assert text
Again steps 1-8 work for me and step 8 should be the black window poping up but closing fast
So what from this is not working for you?
Navigation
[0] Message Index
[#] Next page
Go to full version