Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probably-false uninit reports on StackWalk64 #567

Open
derekbruening opened this issue Nov 28, 2014 · 7 comments
Open

Probably-false uninit reports on StackWalk64 #567

derekbruening opened this issue Nov 28, 2014 · 7 comments

Comments

@derekbruening
Copy link
Contributor

From timurrrr@google.com on August 26, 2011 10:23:09

As of r481 :

#include <windows.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")

#include <stdio.h>
#include

long WINAPI SDEF(EXCEPTION_POINTERS *ep) {
STACKFRAME64 stack_frame;
memset(&stack_frame, 0, sizeof(stack_frame));
stack_frame.AddrPC.Offset = ep->ContextRecord->Eip;
stack_frame.AddrFrame.Offset = ep->ContextRecord->Ebp;
stack_frame.AddrStack.Offset = ep->ContextRecord->Esp;
stack_frame.AddrPC.Mode = AddrModeFlat;
stack_frame.AddrFrame.Mode = AddrModeFlat;
stack_frame.AddrStack.Mode = AddrModeFlat;
while (StackWalk64(IMAGE_FILE_MACHINE_I386, GetCurrentProcess(),
GetCurrentThread(), &stack_frame,
ep->ContextRecord, NULL,
&SymFunctionTableAccess64, &SymGetModuleBase64, NULL)) {
printf("Frame: 0x%08X\n", stack_frame.AddrPC.Offset);
}
return 1;
}

int main() {
SetUnhandledExceptionFilter(&SDEF);
throw std::exception("Woo");
}

Error #1: UNINITIALIZED READ: reading 0x0018ea2c-0x0018ea2d 1 byte(s)
@0:00:02.162 in thread 4972
Note: instruction: test 0xffffffb4(%ebp) $0x01
0x73f94c40 <dbghelp.dll+0x14c40> dbghelp.dll!SymFromAddrW
0x73f94916 <dbghelp.dll+0x14916> dbghelp.dll!SymFromAddrW
0x73f94f0f <dbghelp.dll+0x14f0f> dbghelp.dll!SymFromAddrW
0x73f965b1 <dbghelp.dll+0x165b1> dbghelp.dll!StackWalk64
0x73f964c8 <dbghelp.dll+0x164c8> dbghelp.dll!StackWalk64
0x004010e4 <test.exe+0x10e4> test.exe!SDEF
c:\sandbox\stackwalk\test.cpp:20

Original issue: http://code.google.com/p/drmemory/issues/detail?id=567

@derekbruening
Copy link
Contributor Author

From timurrrr@google.com on August 26, 2011 07:24:52

Leaks on a similar program:

#include <windows.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")

#include <stdio.h>

int main() {
STACKFRAME64 stack_frame;
memset(&stack_frame, 0, sizeof(stack_frame));
CONTEXT cxt;
memset(&cxt, 0, sizeof(cxt));
stack_frame.AddrPC.Mode = AddrModeFlat;
stack_frame.AddrFrame.Mode = AddrModeFlat;
stack_frame.AddrStack.Mode = AddrModeFlat;
while (StackWalk64(IMAGE_FILE_MACHINE_I386, GetCurrentProcess(),
GetCurrentThread(), &stack_frame,
&cxt, NULL,
&SymFunctionTableAccess64, &SymGetModuleBase64, NULL)) {
printf("Frame: 0x%08X\n", stack_frame.AddrPC.Offset);
}
}

Error #1: LEAK 896 direct bytes 0x002307e0-0x00230b60 + 0 indirect bytes
0x73f8d92e <dbghelp.dll+0xd92e> dbghelp.dll!SymGetModuleInfoW64
0x73f94fce <dbghelp.dll+0x14fce> dbghelp.dll!SymFromAddrW
0x73f964c8 <dbghelp.dll+0x164c8> dbghelp.dll!StackWalk64
0x004010a5 <test.exe+0x10a5> test.exe!main
c:\sandbox\stackwalk\test.cpp:18

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on August 26, 2011 07:30:50

don't you need to call SymInitialize and SymCleanup? does the leak go away if you do that?

@derekbruening
Copy link
Contributor Author

From timurrrr@google.com on August 26, 2011 07:35:33

MSDN says nothing about it on the StackWalk64 page.

The leak is still there if I call these guys.

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on August 26, 2011 07:42:29

The MSDN page is terrible: it doesn't do a good job of telling you how to initialize the frame (your sample does it incorrectly: my understanding is that you need to fill in the values of PC, Frame, and Stack). But for the function pointers it says you could use the dbghelp ones, which to me implies only if you've set up dbghelp already. I've tried using StackWalk64 and it did not work well for me unless I loaded the module symbols up front w/ SymIninitialize(,,TRUE). Xref issue #563 .

@derekbruening
Copy link
Contributor Author

From timurrrr@google.com on August 26, 2011 07:47:46

With (,,TRUE) it gives 400+ uninits like this:
Error #X: UNINITIALIZED READ
...
0x73f997c8 <dbghelp.dll+0x197c8> dbghelp.dll!StackWalk64
0x73fb9646 <dbghelp.dll+0x39646> dbghelp.dll!FindExecutableImage
0x73fb98ea <dbghelp.dll+0x398ea> dbghelp.dll!FindExecutableImage
0x73f98563 <dbghelp.dll+0x18563> dbghelp.dll!StackWalk64
0x73fb58d0 <dbghelp.dll+0x358d0> dbghelp.dll!SymInitialize
0x00416a74 <test.exe+0x16a74> test.exe!main
c:\sandbox\stackwalk\test.cpp:8

and the leak is still there! :)

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on August 26, 2011 07:50:07

(in general) can you include the "Note: instruction:" which can provide a hint as to whether bit granularity is the issue

@derekbruening
Copy link
Contributor Author

From timurrrr@google.com on August 26, 2011 07:59:41

Sure,
$ grep "Note: ins" results.txt | sort | uniq -c | sort
2 Note: instruction: cmp %eax $0x00000003
2 Note: instruction: test %esi %esi
2 Note: instruction: test 0xfffffffc(%ebp) $0x00000100
2 Note: instruction: test 0xfffffffc(%ebp) $0x20
8 Note: instruction: test %bl $0x10
12 Note: instruction: cmp %edi $0x00000001
14 Note: instruction: test %eax $0x00000400
14 Note: instruction: test 0x04(%esi) $0x0f
50 Note: instruction: test %ecx %ecx
308 Note: instruction: test %eax %eax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant