From: Paul Floyd Date: Fri, 29 Sep 2023 06:57:42 +0000 (+0200) Subject: README / comments: update debugging advice X-Git-Tag: VALGRIND_3_22_0~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57dc8fd6d89e9f5de483583c695c217d01743f78;p=thirdparty%2Fvalgrind.git README / comments: update debugging advice And add an explanation for the odd FreeBSD amd64 startup stack alignment. --- diff --git a/README_DEVELOPERS b/README_DEVELOPERS index 5b93b1c870..6cefd0faa9 100644 --- a/README_DEVELOPERS +++ b/README_DEVELOPERS @@ -172,6 +172,13 @@ A different and possibly easier way is as follows: will continue as normal. Note that comment (3) above re passing signals applies here too. +The default build of Valgrind uses "-g -O2". This is OK most of the +time, but with sophisticated optimization it can be difficult to +see the contents of variables. A quick way to get to see function +variables is to temporarily add "__attribute__((optnone))" before +the function definition and rebuild. Alternatively modify +Makefile.all.am and remove -O2 from AM_CFLAGS_BASE. That will +require you to reconfigure and rebuild Valgrind. Self-hosting ~~~~~~~~~~~~ diff --git a/coregrind/m_main.c b/coregrind/m_main.c index b8751341a0..9087aafb02 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -3419,6 +3419,11 @@ asm("\n" // // Maybe on FreeBSD the pointer to argc is 16byte aligned and can be 8 bytes above the // start of the stack? +// +// Some answers to this mystery here +// https://forums.freebsd.org/threads/stack-alignment-argc-location-in-assembled-binaries.89302/#post-613119 +// and here +// https://github.com/freebsd/freebsd-src/blob/releng/5.1/sys/amd64/amd64/machdep.c#LL487C1-L488C42 asm("\n" ".text\n" diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 3efb64a43f..ce50566698 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -130,7 +130,21 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) ------------------------------------------------------------------ */ /* Run a thread all the way to the end, then do appropriate exit actions - (this is the last-one-out-turn-off-the-lights bit). */ + * (this is the last-one-out-turn-off-the-lights bit). + * + * This is marked as __attribute__((noreturn)). That has the effect of + * making clang++ no longer emit the function prologue and epilogue + * to save the base pointer. + * + * As far as I can tell clang -O2 does not include -fomit-frame-pointer + * However, since from here on the saved base pointer values are + * junk tools like FreeBSD pstack that only rely on base pointer + * walking will not work. FreeBSD bstack does work, based on GDB and + * reading debuginfo. + * + * If you really need a working base pointer modify Makefile.all.am + * and add -fno-omit-frame-pointer to AM_CFLAGS_BASE. + */ __attribute__((noreturn)) static void run_a_thread_NORETURN ( Word tidW ) {