https://habrahabr.ru/post/318142/
http://drmemory.org/ like Valgrind
http://blog.rplasil.name/2016/10/crafting-c-continuation_21.html
http://clang.llvm.org/docs/AddressSanitizer.html
https://news.ycombinator.com/item?id=10908042
Intel VTune
AMD CodeAnalyst
https://habrahabr.ru/company/first/blog/310164/
https://github.com/facebook/pfff/wiki/Main
https://www.youtube.com/watch?v=5v6o-VsLAew strace etc
http://locklessinc.com/articles/profiling/
http://habrahabr.ru/post/167837/ profiling of already running program
https://news.ycombinator.com/item?id=9337826
http://billiob.net/blog/20140330_vgdb.html
https://techtalk.intersec.com/2013/12/memory-part-5-debugging-tools/
http://www.knowledgezenforyou.blogspot.co.uk/2013/08/using-gdbtop-and-other-tools-to-debug.html
top -H
GDB:
info threads
http://www.openlogic.com/wazi/bid/336594/advanced-gdb-tips-and-tricks
http://vickychijwani.me/reverse-debugging-in-gdb/
https://blogs.oracle.com/ksplice/entry/8_gdb_tricks_you_should
http://enki-tech.blogspot.fr/2012/08/debugging-c-part-1-how-to-write-less.html
http://enki-tech.blogspot.fr/2012/08/debugging-c-part-2-valgrind-and-gdb.html
http://enki-tech.blogspot.fr/2012/08/debugging-c-part-3-dmesg.html
http://enki-tech.blogspot.fr/2012/08/debugging-c-part-4-print-method.html
http://maintainablecode.logdown.com/posts/245425-valgrind-is-not-a-leak-checker
https://code.google.com/p/address-sanitizer/
http://habrahabr.ru/post/140536/
https://github.com/yotamr/traces/wiki/Introduction Tracing
http://predef.sourceforge.net/precomp.html
http://www.keithschwarz.com/cs106l/spring2009/
macro assert
A good practice is to use the macro assert available in the header cassert.
This is a macro that evaluates its content and stops the program if its content is evaluated to false.
If you define NDEBUG (the common way is to pass the -DNDEBUG option to g++, -D allows to define a macro), the code inside the parenthesis of the macro isn't evaluated.
http://molecularmusings.wordpress.com/2011/07/22/an-improved-assert/
When you are developing, use the assert macro to detect errors as soon as they occur.
This macro is defined in the include file <assert.h>, and is used that way :
assert (expression) ;
If expression is false, program will stop indicating which assertion failed.
What is really nice with this macro, is that you can easily get rid of it for the production version of your code,
by declaring #define NDEBUG.
This is because the assert macro is defined as :
#ifndef NDEBUG
#define assert(THETEST) ...
#else
#define assert(THETEST) ((void)0)
#endif
http://www.reddit.com/r/cpp/comments/2xxbi0/a_small_library_of_useful_tools_for_those_of_us/
https://bitbucket.org/guyben/guylib
The assert debugging mechanism was designed to be *on* by default.
You must define NDEBUG to turn it off.
GDB
http://sourceware.org/gdb/onlinedocs/
Automating GDB session
http://stackoverflow.com/questions/10748501/automating-gdb-sessions
http://www.opennet.ru/tips/2722_gdb_debug_breakpoint.shtml
http://www.linuxforu.com/2011/11/gdb-logging-function-parameters-part-1/
http://www.linuxforu.com/2011/12/gdb-logging-function-parameters-part-2/
http://dept-info.labri.fr/~thibault/gdb.html.en
$ pgrep <program_name>
<pid>
$ gdb attach <pid>
(gdb) set var cond = false
(gdb) n
gdb -tui
GDB help
http://stackoverflow.com/questions/2588853/the-community-driven-gdb-primer
http://mainisusuallyafunction.blogspot.com/2012/01/embedding-gdb-breakpoints-in-c-source.html
gdb attach pid
gdb>c (continue)
gdb> bt (backtrace)
gdb>n (next)
gdb>s (step in)
Q: How to know where you are (file, next execution line)?
A: (gdb) f
Breakpoints
break my.cpp:64
break my.cpp:66 if strcmp(y,"hello") == 0
http://adrian.idv.hk/doku.php/notepad/code/gdb
(gdb) help
List of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands
Type "help" followed by a class name for a list of commands in that class.
Type "help all" for the list of all commands.
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
GDB Links
https://news.ycombinator.com/item?id=5492376
http://www.linuxjournal.com/article/1298
https://blogs.oracle.com/ksplice/entry/8_gdb_tricks_you_should
http://ivan-gandhi.livejournal.com/2064315.html#comments
ptrace
http://www.linuxjournal.com/article/6100
http://www.linuxjournal.com/article/6210
1) compile code with -g flag
2) ulimit -c unlimited
3) run application myapp ; segfault will generate the file: core.NNN
if file is not in current folder look here: http://linux.die.net/man/5/core
cat /proc/sys/kernel/core_pattern
4) run gdb -c core.NNN myapp
5) type backtrace
Analyzing coredump
$ gdb <prog> coredump
(gdb) info thread
(gdb) info shared
(gdb) info locals
(gdb) info files
(gdb) info variables
(gdb) help info
Смотрим состояние стека до падения
(gdb) backtrace 1
(gdb) backtrace 2
или просто (gdb) backtrace
Указываем номер фрейма который будем смотреть подробнее (показан как #N)
(gdb) frame 0
Смотрим состояние переменных (в примере - result)
(gdb) info locals
(gdb) print result
(gdb) whatis result
Как посмотреть какие функции системных библиотек используются в программе
nm "объектный или запускной файл" Для работы nm нужна таблица символов, т.е. нельзя использовать после утилиты strip или ключа "-s" в gcc.
nm --dynamic
Как узнать какие динамические библиотеки прилинкованы к программе
ldd файл
как узнать, какие проги в данный момент используют заданный файл
lsof | grep <имя_файла>
lsof | grep $PID
Как посмотреть какие файлы пытается открыть или выполнить программа
strace -f -o strace.txt -e execve программа
strace -f -o strace.txt -e open,ioctl программа
Tracing
http://techblog.rosedu.org/ltrace.html
https://news.ycombinator.com/item?id=9337826
http://mharrytemp.blogspot.com/2011/10/using-strace-and-lsof-to-track-down.html
lsof - shows list of resources using this file; shows list of files used by this process
lsof -p 2741
http://danielmiessler.com/study/lsof/
strace http://honglus.blogspot.com/2010/07/debugging-issues-with-strace-in-linux.html
http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/
https://news.ycombinator.com/item?id=7155799
http://techblog.rosedu.org/tracing-processes-for-fun-and-profit.html
Les say find command is running slowly; then in another window run:
$ pgrep find
2714
$ strace -p 2714