Bug 240488 - Callgrind segfaults upon call of some boost::spirit routines
Summary: Callgrind segfaults upon call of some boost::spirit routines
Status: RESOLVED DUPLICATE of bug 197988
Alias: None
Product: valgrind
Classification: Developer tools
Component: callgrind (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Josef Weidendorfer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-02 18:44 UTC by Sebastian Steiger
Modified: 2021-05-10 23:39 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Steiger 2010-06-02 18:44:54 UTC
Hello

I am trying to use your wonderful tool to profile our code. We are using the boost::spirit library to parse some input file. Callgrind segfaults during the parsing. Valgrind (Memcheck) is fine and I can also run the program in normal mode. I have tried my best to create a small testcase, see below.

Platform: Kubuntu 10.04 64-bit with boost packages installed.

========================================================

// compile using: g++ -o boost_test.bin boost_test.cpp -lboost_system

#include <boost/spirit/include/classic.hpp>
#include <boost/spirit/include/classic_actor.hpp>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_grammar.hpp>
using namespace boost::spirit::classic;

#include "boost/filesystem.hpp"   
using namespace boost::filesystem;  

#include <iostream>
using namespace std;

typedef file_iterator<char> iterator_t;
typedef scanner<iterator_t> scanner_t;
typedef rule<scanner_t>     rule_t;
  
string _tag; // variable name
string _value; // variable value
   
void insert_pair(iterator_t first, iterator_t last) { }

struct InputGrammar: grammar<InputGrammar>
{
	template <typename ScannerT>
	struct definition
	{
		rule<ScannerT>  block_content; // simple block between "{" and "}"
		rule<ScannerT>  my_block;
		
		definition(InputGrammar const& self)  
		{ 
			block_content =   *(space_p) >>  ch_p('{') >>  *(space_p) >> 
			*( 
				( 
					(+(alnum_p | ch_p('_') | ch_p(':') |ch_p('*') |ch_p('-') ))[assign_a(_tag)] 
					>> 
					'=' 
					>> 
					(+(graph_p-'}'))[assign_a(_value)]  
				)
				[&insert_pair] 
				>> *(space_p)  
			)  >> *(space_p)  >> ch_p('}') >>  *(space_p) ;

			my_block =  *(space_p);
		} // definition

		rule<ScannerT> const& start() const  { return my_block; }
		
	}; // definition
}; // InputGrammar

InputGrammar _grammar;

int main() 
{
	iterator_t first("boost_test.in"); // boost_test.in can be empty
	iterator_t last = first.make_end();
	
	std::cout << "parsing...";
	parse_info<file_iterator<char> > info = 
		boost::spirit::classic::parse(first, last, _grammar, 
			comment_p("/*", "*/")  | blank_p );
	std::cout << " done." << std::endl;
	
	return 0;
}
Comment 1 Sebastian Steiger 2010-06-02 18:46:48 UTC
I forgot to mention that an empty file "boost_test.in" must be present in order for the test case to run.
Comment 2 Julian Seward 2010-06-02 18:55:34 UTC
Possibly the same bug as 197988.  Sebastian, try out the fix
at https://bugs.kde.org/show_bug.cgi?id=197988#c44
Comment 3 Sebastian Steiger 2010-06-02 19:34:08 UTC
Thanks for the quick reply. Indeed this bug is a duplicate of 197988.

I was using the Kubuntu repository package for valgrind before, so I now downloaded and installed valgrind-3.5.0 to be able and modify the source code. I checked that without modifications the segfault is still there. Then I changed coregrind/pub_core_aspacemgr.h:

# define VG_STACK_ACTIVE_SZB (4096 * 512) // 2Mb

I recompiled and ran the test again, and now it works! Am I going to see this fix in one of the later Kubuntu repository packages?

Two side notes:
- I needed to modify the 3.5.0 configure script because Kubuntu 10.04 has glibc 2.11 which is not yet handled in it.
- When I try to use the current SVN version of valgrind, it immediately aborts with the following message:

valgrind: mmap(0x400000, 114688) failed in UME with error 22 (Invalid argument).

This happens even when valgrinding the simplest "Hello World" program.

Sebastian
Comment 4 Julian Seward 2010-06-02 23:27:54 UTC
(In reply to comment #3)
> I recompiled and ran the test again, and now it works! Am I going to see this
> fix in one of the later Kubuntu repository packages?

This fix will be in the next release (3.6.0).

> - When I try to use the current SVN version of valgrind, it immediately aborts
> with the following message:
> 
> valgrind: mmap(0x400000, 114688) failed in UME with error 22 (Invalid
> argument).

Yes.  This is due to a very recent change (r11141).  Am still trying
to figure out how to fix it.  See 
https://bugs.kde.org/show_bug.cgi?id=193413#c18
for the gory details.
Comment 5 Julian Seward 2010-06-03 16:23:38 UTC
(In reply to comment #4)
> > - When I try to use the current SVN version of valgrind, it immediately aborts
> > with the following message:
> > 
> > valgrind: mmap(0x400000, 114688) failed in UME with error 22 (Invalid
> > argument).
> 
> Yes.  This is due to a very recent change (r11141).  Am still trying
> to figure out how to fix it.  See 
> https://bugs.kde.org/show_bug.cgi?id=193413#c18
> for the gory details.

Possibly fixed now by r11146.  Give it a try.
Comment 6 Sebastian Steiger 2010-06-03 16:45:36 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > > - When I try to use the current SVN version of valgrind, it immediately aborts
> > > with the following message:
> > > 
> > > valgrind: mmap(0x400000, 114688) failed in UME with error 22 (Invalid
> > > argument).
> > 
> > Yes.  This is due to a very recent change (r11141).  Am still trying
> > to figure out how to fix it.  See 
> > https://bugs.kde.org/show_bug.cgi?id=193413#c18
> > for the gory details.
> 
> Possibly fixed now by r11146.  Give it a try.

Yes, it seems to be fixed. Also the glibc-2.11 issue is fixed I believe. Thanks!

I performed the following:
svn update
./autogen.sh
./configure
make clean
make --prefix=$PWD
make install
Comment 7 Julian Seward 2010-07-21 12:59:01 UTC
*** This bug has been marked as a duplicate of bug 197988 ***
Comment 8 Karmaqtrp 2021-05-08 15:16:05 UTC
| CLOSES
Comment 9 Karmaqtrp 2021-05-08 15:35:34 UTC
CLOSES