Is there any difference in the source code for releasing and debugging the compiled program? [C / C ++]

Recently, I fit more into C ++ programming and continue to work in all compiled versions of "debug vs release". Now I feel that I have a pretty decent understanding of some of the differences between released and debugged versions of compiled code. For the debug version of the code, the compiler does not try to optimize the code so that you can run the debugger and execute your program sequentially. In fact, the compiled code is very similar to your source code in the way it is executed. When compiling in release mode, the compiler tries to optimize the program so that it has the same functionality, but is more efficient.

However, I am curious if there are instances where the source code between the release and debug version may differ. That is, when we refer to debug vs release, are we always just talking about compiled code, or can there be differences in the source code?

This question arises because I work in a proprietary programming language in which a formal step-by-step debugger does not exist, but serial monitors exist. Thus, our "debug" vs "release" code is implemented using #defines, which look something like this:

#ifdef _DEBUG

    check that error didn't occur...

    SerialPrint("Error occurred")

#endif

, , , , ? , , ? vs debug ?

!

+4
3

?

, . , .

" " assert. , NDEBUG . Asserts , . , . , , . , , if .

, . : , . , , ...

Posix assert , abort. , , , , assert. " " . C/++. , , ( C/++).

Posix assert - , assert, SIGTRAP Linux DebugBreak Windows. ., , trap.h. Posix assert assert, , , , ( , ).

, , ISC BIND (DNS-, ) DoS ( , Posix assert). CVE BIND DoS. DoS'ing , " ".

Microsoft Foundation Classs (MFC) - 16 000 20 000 , . 1990- 2000- . , .

APIs

API-, " " . API-, .

( ) - Logging DebugPrint API. Apple FileVault. . os x filevault debug print.

( ) Windows IsBadReadPointer IsBadWritePointer. , . , .

, / ; , . , . .

, . Linux Microsoft CRT , API. .

, . Glib++ -D_GLIBCXX_DEBUG . - , define -D_GLIBCXX_CONCEPT_CHECKS. Boost , . .

, , - Release, NDEBUG define. Debian Ubuntu . NSA, GHCQ 3- , (, ), ( ), ( Windows, Apport Error ..).

, . , . Microsoft; . 0xCD, 0xDD .. malloc/free/new/delete? GCC , , - .

, DLL Microsoft bcause. , DLL Debug. , , DLL Release , . Adobe ( , Adobe , , Apple Microsoft).


#ifdef _DEBUG

    check that error didn't occur...

    SerialPrint("Error occurred")

#endif

, 2016 . GDB (?) Aarch64, X32 S/390, printf .

+4

++ assert, , NDEBUG . , . , , <assert.h> <cassert> , , , assert NDEBUG.

.

, . _DEBUG, , Visual ++, (debug library) /MTd /MDd.

0

IDE, , . , IDE (, MS Visual Studio) , CMake add _DEBUG , , , . , _DEBUG , MY_PROJECT_DEBUG - .

, . , #ifdef _DEBUG ( #ifndef _DEBUG), , , .

, , , . assert, ; :

#ifdef NDEBUG
    #define assert(x) ((void)0)
#else
    #define assert(x) ((x) ? (void)0 : abort())
#endif

, assert x ( , NDEBUG ). , , , , - :

#include <assert.h>

int main()
{
    int x = 5;
    assert(x-- == 5);
    return x; // returns 5 in release mode, 4 in debug mode
}

, , . , . assert(SomeFunctionCall()) ..

Please note that statements may not be the best example, although, as some people like, they are included even in release builds.

0
source

Source: https://habr.com/ru/post/1652548/


All Articles