c - Best way to print information when debugging a race condition -
i debugging application fix segmentation fault suspect caused race condition.
i'd put print statements in code, know experience adding calls printf not recommended since change behavior of threads , in case hide bug.
looking @ other options, have seen gdb possible use break points print , automatically continue execution:
break foo commands silent printf "called foo: x %d\n",x cont end is better putting printf in code?
i know gdb has tracepoints work gdbserver , additional level of complication prefer avoid @ moment.
additional information: application written in c , runs on linux.
is better putting printf in code?
no, it's much worse. every breakpoint hit in gdb triggers following chain of events:
- context switch running thread gdb
- gdb stops other threads (assuming default all-stop mode)
- gdb evaluates breakpoint commands
- gdb resumes threads (this complicated multi-step process, not go here).
this @ least order of magnitude more expensive , disruptive simple printf call, , hide whatever race trying debug.
the bottom line gdb in general completely unsuitable debugging data races.
i second threadsanitizer recommendation christopher ian stern.
the problem bug doing debug on production machine cannot install other sw.
first, threadsanitizer instruments existing program. has runtime library, statically linked binary. there nothing need install on production machine.
second, threadsanitizer detects data races when not cause visible behavior changes. may turn out don't need run on production machine @ all: running tests (you do have tests, right?) on development machine may prove sufficient.
Comments
Post a Comment