diff options
| -rw-r--r-- | md/notes/undefined_c/titles.md | 87 | 
1 files changed, 86 insertions, 1 deletions
diff --git a/md/notes/undefined_c/titles.md b/md/notes/undefined_c/titles.md index ec8f0b5..3c6daa9 100644 --- a/md/notes/undefined_c/titles.md +++ b/md/notes/undefined_c/titles.md @@ -5,7 +5,9 @@ keywords:c,linux,asm  There is possible to run piece of code inside online c compiler like https://www.onlinegdb.com/online_c_compiler  Or run locally. With base check is done with gcc compiler. There are many small tricks around running C code -in practice that aren't covered in any generic tutorials. +in practice that aren't covered in any generic tutorials, so here is list of topics that may arise while +coding real C code outside of tutorials. For each case there is just small example, each of those could +take whole chapter on its own.  ## Compile @@ -1210,11 +1212,94 @@ valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./memleak2  ### Code coverage + +Compile file with extra flags and generate gcov file output. +Ther is only one branch not used. Coverage should show with part isnt used. + +```c +#include <stdio.h> + +int fun1(int a) { +	if (a < 0) { +		printf("Smaller then zero\n"); +	}  +	if (a==0) { +		printf("Equails to zero\n"); +	} +	if (a>0) { +		printf("Bigger then zero\n"); +	} +} + +int main() { + +	printf("Start\n"); +	fun1(0); +	fun1(1); + +	return 0; +} +``` + +``` +$ gcc -fprofile-arcs -ftest-coverage coverage.c -o coverage +$ gcov ./coverage +File 'coverage.c' +Lines executed:92.31% of 13 +Creating 'coverage.c.gcov' + +Lines executed:92.31% of 13 + +``` + +Gcov file content. So we scant see with line wasnt executed.  + +```c +        -:    0:Source:coverage.c +        -:    0:Graph:coverage.gcno +        -:    0:Data:coverage.gcda +        -:    0:Runs:1 +        -:    1:#include <stdio.h> +        -:    2: +        2:    3:int fun1(int a) { +        2:    4:	if (a < 0) { +    #####:    5:		printf("Smaller then zero\n"); +        -:    6:	}  +        2:    7:	if (a==0) { +        1:    8:		printf("Equails to zero\n"); +        -:    9:	} +        2:   10:	if (a>0) { +        1:   11:		printf("Bigger then zero\n"); +        -:   12:	} +        2:   13:} +        -:   14: +        1:   15:int main() { +        -:   16: +        1:   17:	printf("Start\n"); +        1:   18:	fun1(0); +        1:   19:	fun1(1); +        -:   20: +        1:   21:	return 0; +        -:   22:} +``` +  ### Profiling + + + +  ### Canary + +  ### Atomic + +  ### Multithreading + +  ### Write plugins + +  ### Preload library  | 
