Boost logo

Boost Users :

From: Fallon, David (dfallon_at_[hidden])
Date: 2004-11-25 12:32:04


I am having problems debugging an application under Linux using gdb and
the boost threads library. The problem I am basically having is the
stack trace is only going back to the join statement rather than to
point in the program that caused the crash. My application is
reasonable complicated so to reproduce it I have created a buggy version
of the helloword4 tutorial. The slightly modified the helloworld4
tutorial program to loop 7 times and then crash. The stack trace given
in gdb points back to the join statement rather than the source code
line that generated the error. Has anyone else come across this
problem?
 
// Copyright (C) 2001-2003
// William E. Kempf
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. William E. Kempf makes no
representations
// about the suitability of this software for any purpose.
// It is provided "as is" without express or implied warranty.
 
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <string.h>
 
void helloworld(const char* who)
{
 for(int i = 0 ; i < 10; i++ )
 {
  std::cout << who << "says, \"Hello World.\" " << i << std::endl;
  sleep(2);
  if(i > 7 )
  {
   std::cout << " will crash " << std::endl;
   char * p = NULL;
   strcpy(p,"abcde "); // CAUSES Segmentation FAULT here but gdb
 
  }
 }
}
 
int main()
{
    boost::thread thrd(boost::bind(&helloworld, "Bob"));
    thrd.join(); // Stack trace STOPS HERE
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net