From: Alberto <al...@na...> - 2003-02-05 23:15:36
|
Hello, Months ago someone said on this list that he was receiving segmentation faults with GDB when using CreateWindowEx(). He never posted a minimal test example that showed this behaviour. Now I do: -------------------BUG.C--------------------------- #include <windows.h> WNDCLASSEX wc; HWND hwnd; MSG msg; LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ switch (iMsg){ case WM_CLOSE: PostQuitMessage(0); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){ wc.cbSize=sizeof(WNDCLASSEX); wc.lpfnWndProc=WndProc; wc.hInstance=hInstance; wc.hbrBackground=COLOR_WINDOW; wc.lpszClassName="TheClass"; if (RegisterClassEx(&wc)==0) return -1; hwnd=CreateWindowEx (0, "TheClass", "TheWindow", WS_OVERLAPPED|WS_VISIBLE|WS_SYSMENU, CW_USEDEFAULT, 0, 200, 200, NULL, NULL, hInstance, NULL); if (hwnd==NULL) return -1; ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, (HWND) NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } --------------------------------------------------------------- (Sorry about the indentation, I haven't got a copy of 'indent' available) This is a simple program that creates a window and displays it on the screen. I'm not getting the error at the CreateWindowEx() function but just when calling ShowWindow(): the window never gets displayed. Here is the proccess: 1- >gcc bug.c -g -o bug 2- >gdb bug $ gdb bug GNU gdb 5.2.1 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "mingw32"... [skipped code listing with 'list' command to locate the line...] (gdb) b 29 Breakpoint 1 at 0x40132b: file bug.c, line 29. (gdb) r Starting program: i:\abraham\nuevo\RepresentacionGrafica2/bug.exe Breakpoint 1, WinMain (hInstance=0x400000, hPrevInstance=0x0, lpCmdLine=0x81980608 "", nCmdShow=10) at bug.c:29 29 hwnd=CreateWindowEx (gdb) n 43 if (hwnd==NULL) return -1; (gdb) n 45 ShowWindow(hwnd,nCmdShow); (gdb) n Program received signal SIGSEGV, Segmentation fault. 0x0078f7cc in ?? () (gdb) Both 'next' and 'step' get the same error. As the GDB shows, I'm using the 5.2.1 version. OS: Windows 98 SE $ gcc -v Reading specs from h:/c/dev-c/bin/../lib/gcc-lib/mingw32/3.2/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared Thread model: win32 gcc version 3.2 (mingw special 20020817-1) Any advice or suggestion on this? Can you reproduce the crash? Thanks in advance, Alberto |
From: Luke D. <cod...@ho...> - 2003-02-06 02:33:44
|
----- Original Message ----- From: "Alberto" <al...@na...> To: <min...@li...> Sent: Thursday, February 06, 2003 7:14 AM Subject: [Mingw-users] GDB crashing on ShowWindow (was: Debugging) > Hello, > > Months ago someone said on this list that he was receiving segmentation > faults with GDB when using CreateWindowEx(). He never posted a minimal test > example that showed this behaviour. Now I do: I assume it works when run normally without GDB? > > -------------------BUG.C--------------------------- [snip] > --------------------------------------------------------------- > > (Sorry about the indentation, I haven't got a copy of 'indent' available) > > This is a simple program that creates a window and displays it on the screen. > I'm not getting the error at the CreateWindowEx() function but just when > calling ShowWindow(): the window never gets displayed. Here is the proccess: > > 1- >gcc bug.c -g -o bug > > 2- >gdb bug > > $ gdb bug > GNU gdb 5.2.1 > Copyright 2002 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and you are > welcome to change it and/or distribute copies of it under certain conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. Type "show warranty" for details. > This GDB was configured as "mingw32"... > > [skipped code listing with 'list' command to locate the line...] > > (gdb) b 29 > Breakpoint 1 at 0x40132b: file bug.c, line 29. > (gdb) r > Starting program: i:\abraham\nuevo\RepresentacionGrafica2/bug.exe > > Breakpoint 1, WinMain (hInstance=0x400000, hPrevInstance=0x0, > lpCmdLine=0x81980608 "", nCmdShow=10) at bug.c:29 > 29 hwnd=CreateWindowEx > (gdb) n > 43 if (hwnd==NULL) return -1; > (gdb) n > 45 ShowWindow(hwnd,nCmdShow); > (gdb) n > > Program received signal SIGSEGV, Segmentation fault. > 0x0078f7cc in ?? () > (gdb) > > > > Both 'next' and 'step' get the same error. As the GDB shows, I'm using the > 5.2.1 version. Maybe you could try a few other things to narrow it down like setting a breakpoint just after ShowWindow and using "continue"? And how about if you just "run" without setting any breakpoints? And what happens when you remove the ShowWindow() and step through it (because you used the WS_VISIBLE style anyway)? > > OS: Windows 98 SE > > $ gcc -v > Reading specs from h:/c/dev-c/bin/../lib/gcc-lib/mingw32/3.2/specs > Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as > --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads > --disable-nls --enable-languages=f77,c++,objc,ada --disable-win32-registry > --disable-shared > Thread model: win32 > gcc version 3.2 (mingw special 20020817-1) > > > > Any advice or suggestion on this? Can you reproduce the crash? > > Thanks in advance, > > Alberto No, it works fine for me on Win2K with the same GCC and GDB versions, so maybe it's a Windows 98 specific bug. I may be able to check this later but perhaps somebody else can try it too? Luke |
From: Alberto <al...@na...> - 2003-02-06 20:35:20
|
Hello, El Jue 06 Feb 2003 03:34, escribió: > > This is a simple program that creates a window and displays it on the > > screen. > I assume it works when run normally without GDB? Yes, it works well when not being debugged. > Maybe you could try a few other things to narrow it down like setting a > breakpoint just after ShowWindow and using "continue"? And how about if you > just "run" without setting any breakpoints? And what happens when you > remove the ShowWindow() and step through it (because you used the > WS_VISIBLE style anyway)? > 1- Setting a breakpoint after ShowWindow() and then using 'continue': When I run the program, it gets the SIGSEV before it reaches the line after ShowWindow: (gdb) l 45 40 hInstance, 41 NULL); 42 43 if (hwnd==NULL) return -1; 44 45 ShowWindow(hwnd,nCmdShow); 46 UpdateWindow(hwnd); 47 48 while (GetMessage(&msg, (HWND) NULL, 0, 0)) 49 (gdb) b 46 Breakpoint 2 at 0x401386: file bug.c, line 46. (gdb) run Starting program: i:\abraham\nuevo\RepresentacionGrafica2/bug.exe Program received signal SIGSEGV, Segmentation fault. 0x0078f7cc in ?? () (gdb) (I'm using "b 46" because GDB says that "UpdateWindow", "UpdateWindow@4" nor "_UpdateWindow" are not defined) If I set the breakpoint before it (b 44) and then 'continue', I get the same results (SIGSEV). 2- Running without any breakpoints: The program gets the same SIGSEV signal after typing "run". 3- Removing ShowWindow(): The program runs without errors, but the window doesn't show up. > > OS: Windows 98 SE > No, it works fine for me on Win2K with the same GCC and GDB versions, so > maybe it's a Windows 98 specific bug. I may be able to check this later but > perhaps somebody else can try it too? Thank you, Alberto |
From: Earnie B. <ear...@ya...> - 2003-02-06 21:21:35
|
Alberto wrote: > 3- Removing ShowWindow(): The program runs without errors, but the wind= ow=20 > doesn't show up. >=20 <quote reference=3D"old SDK Win32 API .hlp file"> Remarks The first time a program calls ShowWindow, it uses the WinMain=20 function=92s nCmdShow parameter as its nCmdShow parameter. Subsequent=20 calls to ShowWindow must use one of the values in the given list,=20 instead of the one specified by the WinMain function=92s nCmdShow paramet= er. As noted in the discussion of the nCmdShow parameter, the nCmdShow value = is ignored in the first call to ShowWindow if the program that launched=20 the application specifies startup information in the STARTUPINFO=20 structure. In this case, ShowWindow uses the information specified in=20 the STARTUPINFO structure to show the window. On subsequent calls, the=20 application must call ShowWindow with nCmdShow set to SW_SHOWDEFAULT to=20 use the startup information provided by the program that launched the=20 application. For example, Program Manager specifies that applications=20 start with a minimized main window. This behavior is designed for the=20 following situations: =B7 Applications create their main window by calling CreateWindow with th= e=20 WS_VISIBLE flag set. =B7 Applications create their main window by calling CreateWindow with th= e=20 WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag = set to make it visible. </quote> Try profiling the binary with depends.exe. Earnie. |
From: Alberto <al...@na...> - 2003-02-07 21:44:39
|
El Jue 06 Feb 2003 22:21, escribió: > Alberto wrote: > > 3- Removing ShowWindow(): The program runs without errors, but the window > > doesn't show up. Yes, it didn't showed up when not calling to ShowWindow(). > <quote reference="old SDK Win32 API .hlp file"> [snip] >On subsequent calls, the > application must call ShowWindow with nCmdShow set to SW_SHOWDEFAULT to > use the startup information provided by the program that launched the > application. For example, Program Manager specifies that applications > start with a minimized main window. This behavior is designed for the > following situations: > > · Applications create their main window by calling CreateWindow with the > WS_VISIBLE flag set. If I set WS_VISIBLE while creating the window and later call ShowWindow(hwnd, SW_SHOWDEFAULT), the program doesn't get a SIGSEV anymore when debugging. > · Applications create their main window by calling CreateWindow with the > WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag > set to make it visible. If I don't use the WS_VISIBLE flag while creating the window and then call ShowWindow(hwnd, nCmdShow) the application doesn't SIGSEV neither. > </quote> It turns out that I was using nCmdShow incorrectly as Earnie pointed with the API documentation, but I wonder why it worked for Luke on NT and why are a lot of programs that use WS_VISIBLE and ShowWindow(hwnd,nCmdShow) simultaneously (Maybe a popular "bad habit"?) Anyway, thank you all. > > Try profiling the binary with depends.exe. > Just for curiosity, I never used depends.exe nor I haven't it on my hard drive. What is it used for? Is it a sort of "Dependency Walker"? Alberto P.S.: I am subscribed to this list. |
From: Luke D. <cod...@ho...> - 2003-02-08 03:58:21
|
----- Original Message ----- From: "Alberto" <al...@na...> To: <min...@li...> Sent: Saturday, February 08, 2003 5:44 AM Subject: Re: [Mingw-users] GDB crashing on ShowWindow (was: Debugging) > El Jue 06 Feb 2003 22:21, escribió: [snip] > > > > Try profiling the binary with depends.exe. > > > > Just for curiosity, I never used depends.exe nor I haven't it on my hard > drive. What is it used for? Is it a sort of "Dependency Walker"? > Exactly. Get it from www.dependencywalker.com > > Alberto > > > P.S.: I am subscribed to this list. Luke |