valgrind_help.cpp

00001 /*<std-header orig-src='shore' incl-file-exclusion='W_BASE_H'>
00002 
00003  $Id: valgrind_help.cpp,v 1.2 2010/05/26 01:20:22 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #include "w_defines.h"
00031 
00032 /*  -- do not edit anything above this line --   </std-header>*/
00033 
00034 #ifdef USING_VALGRIND
00035 #include "valgrind_help.h"
00036 
00037 static valgrind_check VGC;
00038 
00039 #include <assert.h>
00040 #include <stdio.h>
00041 #include <signal.h>
00042 #include <unistd.h>
00043 #include <sys/stat.h>
00044 #include <fcntl.h>
00045 
00046 void stop_on_vg_err() { 
00047     // core dump
00048     (void) kill(getpid(), SIGABRT);
00049 }
00050 
00051 /* If you've got reproducible errors reported by valgrind,
00052  * you have to insert calls to this method somewhere near but
00053  * after the suspected place, so you can create a core dump there.
00054  * Then rebuild & rerun.
00055  */
00056 void check_valgrind_errors(int /*line*/, const char * /*file*/) { 
00057     VGC.check();
00058     /*
00059     fprintf(stderr, "check_valgrind_errors: more %s diff %d curr %d line %d file %s\n",
00060             (const char *)(VGC.more()?"true":"false"),
00061             VGC.diff(), VGC.curr(), line, file );
00062     */
00063     if(VGC.more()) stop_on_vg_err();
00064 }
00065 
00066 class dummyfile {
00067     int _fd;
00068 public:
00069     // I'm using /tmp for the benefit of tmpfs
00070     dummyfile() { _fd = open("/tmp/vgdummy", O_CREAT|O_TRUNC|O_RDWR, S_IRWXU);
00071                    assert(_fd>0);
00072                 }
00073     ~dummyfile() { close(_fd); _fd=0; }
00074     int        fd() { return _fd; }
00075 };
00076 
00077 void check_definedness(void *v, size_t len)
00078 {
00079     // Valgrind doesn't check for defined-ness until
00080     // the program behavior would be affected by it, so
00081     // what we have to do here is write to a dummy file.
00082     // We used to cause a branch based on the value in each char,
00083     // but valgrind doesn't report that with the address of the
00084     // datum in question.
00085     //
00086     static dummyfile D;
00087     lseek( D.fd(), 0, SEEK_SET);
00088     write( D.fd(), v, len);
00089 }
00090 #endif

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7