[Insight-users] Problems to debug with (k)gdb
Martin Kavec
kavec at messi.uku.fi
Sat Sep 24 06:39:02 EDT 2005
Hi,
I am working on a filter, which compiles just fine and now I need to debug the
code, because it SEGFAULTS. I am on Gentoo linux with ITK-2.2.0. ITK is
compiled with -ggdb flag and the filter I am working as well. I can see the
flag in the compiler's output during compilation.
For the sake of reference, I have NeighborhoodIterators4.cxx (from
ITK/Examples) in the same CMakeList.txt. Compilation of both files goes fine.
If I load now the exetucable of NeighborhoodIterators4 to kdbg (the KDE
frontend for gdb), set the break points and start, execution stops where it
is suppose to and I can step, step in, step out, without problems.
This is not, however, the case for my filter. The execution stops at the
breakpoint, but it jumps around if I step to next, next ... line. I have
compiled all ITK, NeighborhoodIterators4, and my filter with -O2 -ggdb -pipe
-Wall flags and yet, this strange behavior.
Below is the code of my filter, with comments stripped. I would appreciate any
help. Thanks in advance.
Martin
******************************************************************************
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkFSLSusanImageFilter.h"
int main( int argc, char **argv ) {
char* inFileName = "2D_64.hdr";
char* outFileName = "2D_64_susan.hdr ";
double brightnessThreshold = 0.0;
unsigned int filterDimension = 2;
double variance = 2.0;
bool useMedianFilter = true;
bool spacing = false;
typedef unsigned short PixelType;
const unsigned int imageDimension = 2;
typedef itk::Image< PixelType, imageDimension > InputImageType;
typedef itk::Image< PixelType, imageDimension > OutputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( inFileName );
writer->SetFileName( outFileName );
typedef itk::FSLSusanImageFilter< InputImageType, OutputImageType >
SusanFilterType;
SusanFilterType::Pointer susanFilter = SusanFilterType::New();
susanFilter->SetFilterDimensionality( filterDimension );
susanFilter->SetVariance( variance );
susanFilter->SetUseMedianFilter( useMedianFilter );
susanFilter->SetUseImageSpacing( spacing );
susanFilter->SetInput( reader->GetOutput() );
try {
susanFilter->Update();
} catch ( itk::ExceptionObject& err ) {
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
writer->SetInput( susanFilter->GetOutput() );
try {
writer->Update();
} catch ( itk::ExceptionObject& err ) {
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return 0;
}
More information about the Insight-users
mailing list