Re: Use of valgrind with microthreading

Philippe Waroquiers <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <[email protected]>
On Fri, 2020-08-14 at 19:16 +0200, Mark Wielaard wrote:
> Hi Shachar,
> 
> On Fri, Aug 14, 2020 at 06:35:14PM +0300, Shachar Shemesh wrote:
> > I am writing my own C++ microthreading library. At the very first switch, I
> > get the following message from Valgrind:
> > 
> > ==15122== Warning: client switching stacks?  SP change: 0x1ffeffe788 -->
> > 0x75d0f80
> > ==15122==          to suppress, use: --max-stackframe=137298630664 or
> > greater
> > 
> > 
> > I understand that valgrind needs to know where the stack starts and ends. I
> > am wondering whether is any way I can tell it that information. Since I'm
> > writing the library, what I was thinking was compiling the library with a
> > special flag saying "you're running with valgrind", and then have my library
> > call a valgrind function that says "This is the new stack range, this is the
> > old one".
> >  
> > Is there such a thing? If so, how do I interface with it?
> 
> Yes, there is such a thing. The valgrind client request mechanism:
> https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq
> 
> It does have various VALGRIND_STACK_* macros to signal use of user
> threads/stacks. But note that the documentations says:
> Warning: Unfortunately, this client request is unreliable and best avoided.
> Unfortunately I don't know why that is, or what alternative mechanisms there are.

I also do not know what the 'unreliable' doc warning points at.
Searching in bugzilla, there are a few bugs that are related to such STACK requests:
Bug 202463 - VALGRIND_STACK_{REGISTER,DEREGISTER,CHANGE} are unreliable 
Bug 133154 - crash when using client requests to register/deregister stack

However, some years ago, I did various improvements to the stack handling code
in order to better support running valgrind under valgrind: the inner valgrind is
using such client requests to inform the outer valgrind about the inner stacks.

So, IMO, these requests should (could?) work reasonably well.

Philippe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.