From 400e0e2afe156c2b51f8851c7ae598c06850d8e5 Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Mon, 30 Jul 2018 22:28:48 +0200 Subject: [PATCH] Fix wrong stack range output by commit 7daa08611 (more info in scheduler state) The stack base starts at the beginning of the protection page/zone, so we need to add VG_STACK_GUARD_SZB to get the real lowest usable byte. As the VgStack is an opaque type, add a function in aspacemgr to return the Addr of the first lowest usable byte. --- coregrind/m_aspacemgr/aspacemgr-common.c | 4 ++++ coregrind/m_libcassert.c | 8 ++++++-- coregrind/pub_core_aspacemgr.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/coregrind/m_aspacemgr/aspacemgr-common.c b/coregrind/m_aspacemgr/aspacemgr-common.c index bbfe19d5e1..95c8dd3db3 100644 --- a/coregrind/m_aspacemgr/aspacemgr-common.c +++ b/coregrind/m_aspacemgr/aspacemgr-common.c @@ -505,6 +505,10 @@ SizeT VG_(am_get_VgStack_unused_szB)( const VgStack* stack, SizeT limit ) return i * sizeof(UInt); } +Addr VG_(am_valgrind_stack_low_addr)( const VgStack* stack) +{ + return (Addr)&stack->bytes[VG_STACK_GUARD_SZB]; +} /*--------------------------------------------------------------------*/ /*--- end ---*/ diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c index 5afe1ce275..2792f6da24 100644 --- a/coregrind/m_libcassert.c +++ b/coregrind/m_libcassert.c @@ -329,15 +329,19 @@ static void print_thread_state (Bool stack_usage, prefix, (void*)VG_(get_SP)(i)); } - if (stack_usage && stack != 0) + if (stack_usage && stack != 0) { + Addr stack_low_addr = VG_(am_valgrind_stack_low_addr) (stack); + VG_(printf) ("%svalgrind stack range: [%p %p] top usage: %lu of %lu\n", prefix, - (void*)stack, (void*)((Addr)stack + VG_(clo_valgrind_stacksize) - 1), + (void*)stack_low_addr, + (void*)((Addr)stack_low_addr + VG_(clo_valgrind_stacksize) - 1), VG_(clo_valgrind_stacksize) - VG_(am_get_VgStack_unused_szB) (stack, VG_(clo_valgrind_stacksize)), (SizeT) VG_(clo_valgrind_stacksize)); + } } // Print the scheduler status. diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h index 67ec52825e..2d80119c4c 100644 --- a/coregrind/pub_core_aspacemgr.h +++ b/coregrind/pub_core_aspacemgr.h @@ -361,6 +361,9 @@ extern VgStack* VG_(am_alloc_VgStack)( /*OUT*/Addr* initial_sp ); extern SizeT VG_(am_get_VgStack_unused_szB)( const VgStack* stack, SizeT limit ); +/* Returns the Addr of the lowest usable byte of stack. */ +extern Addr VG_(am_valgrind_stack_low_addr)( const VgStack* stack); + // DDD: this is ugly #if defined(VGO_darwin) typedef -- 2.47.2