Note that there are some explanatory texts on larger screens.

plurals
  1. POTools for Isolating a Stack smashing bug
    text
    copied!<p>To put it mildly I have a small memory issue and am running out of tools and ideas to isolate the cause. </p> <p>I have a highly multi-threaded (pthreads) C/C++ program that has developed a stack smashing issue under optimized compiles with GCC after 4.4.4 and prior to 4.7.1.</p> <p>The symptom is that during the creation of one of the threads, I get a full stack smash, not just %RIP, but all parent frames and most of the registers are 0x00 or other non-sense address. Which thread causes the issue is seemingly random, however judging by log messages it seems to be isolated to the same Hunk of code, and seems to come at a semi repeatable point in the creation of the new thread. </p> <p>This has made it very hard to trap and isolate the offending code more narrowly than to a single compilation unit of may thousand lines, since print()'s with in the offending file have so far proved unreliable in trying to narrow down the active section. </p> <p>The thread creation that leads off the thread that eventually smashes the stack is:</p> <pre><code> extern "C" { static ThreadReturnVal ThreadAPI WriterThread(void *act) { Recorder *rec = reinterpret_cast (act); xuint64 writebytes; LoggerHandle m_logger = XXGetLogger("WriterThread"); if (SetThreadAffinity(rec->m_cpu_mask)) { ... } SetThreadPrio((xint32)rec->m_thread_priority); while (true) { ... poll a ring buffer ... Hard Spin 100% use on a single core, this is that sort of crazy code. } } </code></pre> <p>I have tried a debug build, but the symptom is only present in optimized builds, -O2 or better. I have tried Valgrind/memcheck and DRD but both fail to find any issue before the stack is blown away ( and takes about 12hr's to reach the failure ) </p> <p>A compile with -O2 -Wstack-protector sees nothing wrong, however a build with -fstack-protector-all does protect me from the bug, but emits no errors. </p> <p>Electric-Fence also traps, but only after the stack is gone. </p> <p><strong>Question:</strong> What other tools or techniques would be useful in narrowing down the offending section ?</p> <p>Many thanks, --Bill </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload