On Thu, Mar 16, 2023 at 02:36:27PM -0400, Andrew Piskorski wrote:
> > >   Debug Error!
> > >   Program:  C:\web\ns-fork-pub\naviserver\nsd\libnsd.dll
> > >   Run-Time Check Failure #2 - Stack around the variable 'filter' was 
> > > corrupted.

> I put the same code that the ns_config-7.4.1 test runs into a simple
> *.tcl page like this:
> 
>   set xx [ns_set array [ns_configsection -filter "unread" ns/testconfig]]
>   ns_return 200 {text/plain} "Result:  $xx"

I found this helpful article on trying to find the source of stack
corruption via memory access breakpoints:
 
  https://www.timdbg.com/posts/debugger-lies-part-1/#memory-access-breakpoints

Below is my attempt to do that; I got stuck without clear results.
My memory access breakpoint fired, but the stack trace said we were
still in NsTclConfigSectionObjCmd(), seemingly still at the beginning
of that function, with just this cryptic (to me) output:

  (41d0.f7c): Break instruction exception - code 80000003 (first chance)
  libnsd!failwithmessage+0x234:
  00007ff8`c7101364 cc              int     3

I'm not very skilled at using WinDbg, so it's likely I missed or
misinterpreted something.


Here's what I did to get that far:
------------------------------------------------------------
## I downloaded and installed Windows SDK 10.0.22621:
https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/

## That gave me WinDbg installed here:
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe

## Build NaviServer on Windows my usual way:
"C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
z: & cd Z:\src\web\ns-fork-pub\naviserver
nmake -f Makefile.win32 clean-core clean-mod
nmake -f Makefile.win32 all-core all-mod
# Fix permissions if necessary!  e.g.:
#   find . -type f \( -name "*.exe" -o -name "*.dll" \) -print | sudo xargs 
chmod 775
nmake -f Makefile.win32 _install
nmake -f Makefile.win32 _test

## Start up nsd.exe under WinDbg:
"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe" -g 
C:\P\nsd\nsd-fp_2023-03-15-2\bin\nsd.exe -t 
Z:/src/web/ns-fork-pub/naviserver/tests/test.nscfg

## Tell WinDbg about my Naviserver code:
.srcpath Z:\src\web\ns-fork-pub\naviserver
.sympath 
C:\P\nsd\nsd-fp_2023-03-15-2\lib;C:\P\Tcl-64-8.6.12\lib;SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols
!sym noisy
lml
.reload libnsd.dll
.reload nsd.exe

## Set breakpoint 0 on NsTclConfigSectionObjCmd():
bp NsTclConfigSectionObjCmd
g

## Trigger the bug.  I like to use Cygwin like so:
wget -O - -q http://localhost:8000/atp-crash.tcl

## Now in WinDbg were are in NsTclConfigSectionObjCmd().
## Show stack:
k
## Show current stack pointer:
dx @$csp
## Set memory access breakpoint 1 on the stack pointer:
ba w 8 @$csp
bl
g

## This is the cryptic output I got:
(41d0.f7c): Break instruction exception - code 80000003 (first chance)
libnsd!failwithmessage+0x234:
00007ff8`c7101364 cc              int     3

## Disable the stack pointer breakpoint:
bd 1
------------------------------------------------------------

-- 
Andrew Piskorski <a...@piskorski.com>


_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to