c programming
clang compiler
This is supposedly a faster compiler, but i cannot detect that. For a test run on the backend (debug + release + test + profile) gcc took 14 second and clang took 18 seconds.
However some tools like libFuzz and maybe more work better wit clang/llvm so at least know how to use it.
For now here is the errorformat for clang because that took annoyingly long to find. One for errors and one for warnings.
| errorformat | |
|---|---|
valgrind new version
Options like --db-attach are gone !! To stop inside the debugger at first error you need to use the option:
| valgrind | |
|---|---|
Then you will be told what to do, basically start gdb separately and attach. Then start the program in gdb !
More difficult, but it works.
suppressions
To keep the number of suppressions down a bit. You will notice when letting valgrind print suppressions they all look alike, but slightly different and so they won't match. there are some details here : https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto
But a working example for libglib is these short entries to be found in klopt.supp in the backend sources :
| suppressions | |
|---|---|
So you provide a name, then the type of Mem check which cannot be wildcarded. And then the ld file that is causing the problems, according to the documentation you CAN use wildcards in that filename.
The third one still seemed to be necessary, the ... ellipses in this section are stack wildcards, and so mean any stack trace that contains that ld file, and also all functions that have alloc in their name.
unused functions and warnings
Sometimes you just want a function to be temporarily unused without the compiler bitching about it. Here is a way of fixing that:
| unused functions | |
|---|---|
stacktrace dump
You can't always run from the debugger, for one it is slower with debugging info, and another you might want the program to be restarted and not hang in the debugger waiting for you attention.
stacktrace() from execinfo.h
One solution for this is the backtrace() function, which you could use :
This is a complete program, it will crash and than print :
| output | |
|---|---|
Not very descriptive i hear you say, so try compiling it with -rdynamic :
| -rdynamic | |
|---|---|
You will get another stacktrace :
It will give you the functions names on the stack, but also an address which you can translate with :
| addr2line | |
|---|---|
For this the -g option is needed, or it won't show you anything, but otherwise :
Very handy. Of course you need to get down the stack a little because the top entry gives :
| top entry | |
|---|---|
So.. the handler itself, and the second one is from libc so probably the signal handling function. It is pretty clear you need the third line anyway.
catchsegv
To be done, .... since it used to start the program, you could also use gdb directly, though this does give you the chance to restart again.