|
From: Philippe W. <phi...@so...> - 2018-07-30 21:56:25
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=400e0e2afe156c2b51f8851c7ae598c06850d8e5 commit 400e0e2afe156c2b51f8851c7ae598c06850d8e5 Author: Philippe Waroquiers <phi...@sk...> Date: Mon Jul 30 22:28:48 2018 +0200 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. Diff: --- 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 bbfe19d..95c8dd3 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 5afe1ce..2792f6d 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 67ec528..2d80119 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 |