Author Topic: Debug pb  (Read 4862 times)

Offline syp

  • Single posting newcomer
  • *
  • Posts: 4
Debug pb
« on: May 25, 2021, 02:09:19 pm »
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;
}

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)
« Last Edit: May 25, 2021, 02:10:50 pm by syp »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Debug pb
« Reply #1 on: May 25, 2021, 05:19:00 pm »
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.

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.

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
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

Offline syp

  • Single posting newcomer
  • *
  • Posts: 4
Re: Debug pb
« Reply #2 on: May 25, 2021, 08:25:20 pm »
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


Offline syp

  • Single posting newcomer
  • *
  • Posts: 4
Re: Debug pb
« Reply #3 on: May 25, 2021, 09:40:55 pm »
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())

from so simple code, failed assert is always reported in debug mode and I should see it !


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Debug pb
« Reply #4 on: May 25, 2021, 09:53:46 pm »
Quote
I code in c++ for 40 years and fortunately I have found time to learn how assert and breakpoints work 
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?

Offline syp

  • Single posting newcomer
  • *
  • Posts: 4
Re: Debug pb
« Reply #5 on: May 26, 2021, 12:33:57 pm »
I didn't intend or feel rude. It's my bad and you'r right I should have clarified my experience.

Quote
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

step 1 to 5 is fine for me too. but step 5 my console closes.

Quote
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

step 1 to 6 is fine too, the debugger stops on the BP as expected, but continuing debug the console closes.

Quote
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

All is fine but step 8 there is no message.

Code
C:\Dev\cpp\test\bin\Debug>test
C:\Dev\cpp\test\bin\Debug>echo %errorlevel%
-1073741515

however it can be noted that the execution did not reach the 'return 0', as expected.

what makes me think that the problems come from CB is that they appeared right after a CB crash.
However we will never know what the problem is or its solution, I will take out the hammer and do a relatively recent restoration of my drive.

And I'll add a startup script to save the CB settings. But having reinstalled it all settings in %appdata%/codeblocks should have been reset, so pb is probably not from settings in this directory.
This sound as a side effect of the crash somewhere  :(

Thank you for your help

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Debug pb
« Reply #6 on: May 26, 2021, 01:44:55 pm »
Ok, now we know the problem and can work on a solution.

To see the output at the end of the execution of your program, codeblocks uses the "console runner". This is the black screen you see at the end of your program with the text. If the console runner is not used your program will exit without notice

Quote
step 1 to 5 is fine for me too. but step 5 my console closes.
this should not happen if you run it in codeblocks and the following option is set:
Project->Properties->Build targets->Check if Debug is selected on the left->Check the option "Pause when execution ends"
If this mark is set, and your console disappears, then there is some deeper problem.


Quote
step 1 to 6 is fine too, the debugger stops on the BP as expected, but continuing debug the console closes.
This is expected behavior. If your application is run in the debugger the "console runner" is not used and for this you will not see any output at the end of the execution

Code
C:\Dev\cpp\test\bin\Debug>test
C:\Dev\cpp\test\bin\Debug>echo %errorlevel%
-1073741515
This is strange... Can you please post a build log:
1) Run Build->Rebuild project
2) Post the content of the Build log tab at the bottom