From: André Hentschel Subject: [1/3] winedbg: Remove unused debug menu (try 3) Message-Id: <4EF35FAF.5050809@dawncrow.de> Date: Thu, 22 Dec 2011 17:49:51 +0100 --- programs/winedbg/crashdlg.c | 29 ++++------------------------- programs/winedbg/debugger.h | 2 +- programs/winedbg/resource.h | 4 ---- programs/winedbg/tgt_active.c | 6 +----- programs/winedbg/winedbg.rc | 8 -------- 5 files changed, 6 insertions(+), 43 deletions(-) diff --git a/programs/winedbg/crashdlg.c b/programs/winedbg/crashdlg.c index ebf2ca1..89082b4 100644 --- a/programs/winedbg/crashdlg.c +++ b/programs/winedbg/crashdlg.c @@ -84,7 +84,6 @@ static WCHAR *get_program_name(HANDLE hProcess) static LPWSTR g_ProgramName; static HFONT g_hBoldFont; -static HMENU g_hDebugMenu = NULL; static void set_bold_font(HWND hDlg) { @@ -128,18 +127,6 @@ static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } - case WM_RBUTTONDOWN: - { - POINT mousePos; - if (!(wParam & MK_SHIFT)) - return FALSE; - if (g_hDebugMenu == NULL) - g_hDebugMenu = LoadMenuW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDM_DEBUG_POPUP)); - GetCursorPos(&mousePos); - TrackPopupMenu(GetSubMenu(g_hDebugMenu, 0), TPM_RIGHTBUTTON, mousePos.x, mousePos.y, - 0, hwnd, NULL); - return TRUE; - } case WM_NOTIFY: switch (((NMHDR *)lParam)->code) { @@ -156,7 +143,6 @@ static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { case IDOK: case IDCANCEL: - case ID_DEBUG: EndDialog(hwnd, LOWORD(wParam)); return TRUE; } @@ -165,27 +151,20 @@ static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } -BOOL display_crash_dialog(void) +void display_crash_dialog(void) { static const WCHAR winedeviceW[] = {'w','i','n','e','d','e','v','i','c','e','.','e','x','e',0}; static const INITCOMMONCONTROLSEX init = { sizeof(init), ICC_LINK_CLASS }; - INT_PTR result; /* dbg_curr_process->handle is not set */ HANDLE hProcess; - if (!DBG_IVAR(ShowCrashDialog)) - return TRUE; + if (!DBG_IVAR(ShowCrashDialog)) return; hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dbg_curr_pid); g_ProgramName = get_program_name(hProcess); CloseHandle(hProcess); - if (!strcmpW( g_ProgramName, winedeviceW )) return TRUE; + if (!strcmpW( g_ProgramName, winedeviceW )) return; InitCommonControlsEx( &init ); - result = DialogBoxW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDD_CRASH_DLG), NULL, DlgProc); - if (result == ID_DEBUG) { - AllocConsole(); - return FALSE; - } - return TRUE; + DialogBoxW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDD_CRASH_DLG), NULL, DlgProc); } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index 9c72916..fc3aada 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -308,7 +308,7 @@ extern void break_restart_execution(int count); extern int break_add_condition(int bpnum, struct expr* exp); /* crashdlg.c */ -extern BOOL display_crash_dialog(void); +extern void display_crash_dialog(void); extern int msgbox_res_id(HWND hwnd, UINT textId, UINT captionId, UINT uType); /* dbg.y */ diff --git a/programs/winedbg/resource.h b/programs/winedbg/resource.h index 11c2cb9..fcf0416 100644 --- a/programs/winedbg/resource.h +++ b/programs/winedbg/resource.h @@ -27,10 +27,6 @@ #define IDC_STATIC_TXT1 101 #define IDC_STATIC_TXT2 102 -#define IDM_DEBUG_POPUP 100 - -#define ID_DEBUG 200 - #define IDS_AUTO_CAPTION 16 #define IDS_INVALID_PARAMS 17 #define IDS_UNIDENTIFIED 18 diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index 376ee22..099b353 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -766,11 +766,7 @@ enum dbg_start dbg_active_auto(int argc, char* argv[]) msgbox_res_id(NULL, IDS_INVALID_PARAMS, IDS_AUTO_CAPTION, MB_OK); return ds; } - if (!display_crash_dialog()) { - dbg_init_console(); - dbg_start_interactive(INVALID_HANDLE_VALUE); - return start_ok; - } + display_crash_dialog(); hFile = parser_generate_command_file("echo Modules:", "info share", "echo Threads:", "info threads", diff --git a/programs/winedbg/winedbg.rc b/programs/winedbg/winedbg.rc index 6f3d8a6..539fdcb 100644 --- a/programs/winedbg/winedbg.rc +++ b/programs/winedbg/winedbg.rc @@ -22,14 +22,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT -IDM_DEBUG_POPUP MENU -BEGIN - POPUP "" - BEGIN - MENUITEM "&Debug", ID_DEBUG - END -END - STRINGTABLE BEGIN IDS_AUTO_CAPTION "Wine program crash" -- Best Regards, André Hentschel diff --git a/programs/winedbg/crashdlg.c b/programs/winedbg/crashdlg.c index 89082b4..ede5d2c 100644 --- a/programs/winedbg/crashdlg.c +++ b/programs/winedbg/crashdlg.c @@ -2,6 +2,7 @@ * The dialog that displays after a crash * * Copyright 2008 Mikolaj Zalewski + * Copyright 2011 André Hentschel * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,6 +22,7 @@ #include "debugger.h" #include "wingdi.h" #include "winuser.h" +#include "commdlg.h" #include "commctrl.h" #include "shellapi.h" #include "psapi.h" @@ -32,6 +34,19 @@ #define MAX_PROGRAM_NAME_LENGTH 80 +static HINSTANCE hInstance; +static LPWSTR g_ProgramName; +static HFONT g_hBoldFont; +static HWND hEdit; +static HANDLE hFile; +static WCHAR filename[MAX_PATH]; + +enum output_targets +{ + TO_EDIT_CONTROL, + TO_STD_ERROR_HANDLE, +}; + int msgbox_res_id(HWND hwnd, UINT textId, UINT captionId, UINT uType) { WCHAR caption[256]; @@ -82,9 +97,6 @@ static WCHAR *get_program_name(HANDLE hProcess) return output; } -static LPWSTR g_ProgramName; -static HFONT g_hBoldFont; - static void set_bold_font(HWND hDlg) { HFONT hNormalFont = (HFONT)SendDlgItemMessageW(hDlg, IDC_STATIC_TXT1, @@ -96,6 +108,103 @@ static void set_bold_font(HWND hDlg) SendDlgItemMessageW(hDlg, IDC_STATIC_TXT1, WM_SETFONT, (WPARAM)g_hBoldFont, TRUE); } +void report_save_to_tmp(void) +{ + WCHAR path[MAX_PATH]; + + if (!GetTempPathW(MAX_PATH, path)) return; + if (!GetTempFileNameW(path, NULL, 0, filename)) return; + hFile = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + if (hFile == INVALID_HANDLE_VALUE) return; + else dbg_houtput = hFile; +} + +static void report_output(HWND hDlg, enum output_targets target) +{ + LPSTR pTemp; + DWORD size; + DWORD dwNumRead; + int lenW; + HANDLE myfile; + + if (dbg_houtput != hFile) return; + CloseHandle(hFile); + + myfile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (myfile == INVALID_HANDLE_VALUE) return; + + size = GetFileSize(myfile, NULL); + if (size == INVALID_FILE_SIZE) + { + CloseHandle(myfile); + return; + } + + /* Extra memory for (WCHAR)'\0'-termination. */ + pTemp = HeapAlloc(GetProcessHeap(), 0, size+2); + if (!pTemp) + { + CloseHandle(myfile); + return; + } + + if (!ReadFile(myfile, pTemp, size, &dwNumRead, NULL)) + { + CloseHandle(myfile); + HeapFree(GetProcessHeap(), 0, pTemp); + return; + } + + CloseHandle(myfile); + + lenW = dwNumRead/sizeof(WCHAR); + + switch(target) + { + case TO_EDIT_CONTROL: + SetWindowTextA(hEdit, pTemp); + break; + case TO_STD_ERROR_HANDLE: + WriteFile(GetStdHandle(STD_ERROR_HANDLE), pTemp, size, NULL, NULL); + DeleteFileW(filename); + break; + } + HeapFree(GetProcessHeap(), 0, pTemp); +} + +static LRESULT WINAPI report_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_CREATE: + { + static const WCHAR editW[] = { 'e','d','i','t',0 }; + DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_READONLY | + ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL | WS_HSCROLL | ES_AUTOHSCROLL; + RECT rc; + GetClientRect(hwnd, &rc); + + hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, editW, NULL, + dwStyle, 0, 0, rc.right, rc.bottom, hwnd, + NULL, NULL, NULL); + break; + } + + case WM_SIZE: + SetWindowPos(hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), + SWP_NOOWNERZORDER | SWP_NOZORDER); + break; + + case WM_DESTROY: + hEdit = NULL; + /* fall through */ + default: + return DefWindowProcW(hwnd, msg, wParam, lParam); + } + return 0; +} + static void set_message_with_filename(HWND hDlg) { WCHAR originalText[1000]; @@ -109,11 +218,22 @@ static void set_message_with_filename(HWND hDlg) static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + static const WCHAR className[] = {'B','a','c','k','t','r','a','c','e',0}; static const WCHAR openW[] = {'o','p','e','n',0}; switch (msg) { case WM_INITDIALOG: { + WNDCLASSEXW class; + hInstance = (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE); + ZeroMemory(&class, sizeof(class)); + class.cbSize = sizeof(class); + class.lpfnWndProc = report_WndProc; + class.hInstance = hInstance; + class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + class.lpszClassName = className; + if (!RegisterClassExW(&class)) return FALSE; + set_bold_font(hwnd); set_message_with_filename(hwnd); return TRUE; @@ -141,8 +261,34 @@ static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { - case IDOK: - case IDCANCEL: + case ID_SHOWDETAILS: + { + RECT dlg; + LPWSTR name; + INT len; + + if (hEdit) + { + SetFocus(hEdit); + return TRUE; + } + + len = GetWindowTextLengthW(hwnd) + 1; + name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + if (name) + GetWindowTextW(hwnd, name, len); + + GetWindowRect(hwnd, &dlg); + CreateWindowW(className, name, WS_VISIBLE | WS_OVERLAPPEDWINDOW, + dlg.right, dlg.top, 2*(dlg.right-dlg.left), 2*(dlg.bottom-dlg.top), + hwnd, NULL, hInstance, NULL); + HeapFree(GetProcessHeap(), 0, name); + report_output(hwnd, TO_EDIT_CONTROL); + return TRUE; + } + case IDOK: + case IDCANCEL: + report_output(hwnd, TO_STD_ERROR_HANDLE); EndDialog(hwnd, LOWORD(wParam)); return TRUE; } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index fc3aada..91a6790 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -309,6 +309,7 @@ extern int break_add_condition(int bpnum, struct expr* exp); /* crashdlg.c */ extern void display_crash_dialog(void); +extern void report_save_to_tmp(void); extern int msgbox_res_id(HWND hwnd, UINT textId, UINT captionId, UINT uType); /* dbg.y */ @@ -446,6 +447,7 @@ extern struct dbg_type types_find_type(unsigned long linear, const char* name, /* winedbg.c */ extern void dbg_outputW(const WCHAR* buffer, int len); extern const char* dbg_W2A(const WCHAR* buffer, unsigned len); +extern HANDLE dbg_houtput; #ifdef __GNUC__ extern int dbg_printf(const char* format, ...) __attribute__((format (printf,1,2))); #else diff --git a/programs/winedbg/resource.h b/programs/winedbg/resource.h index fcf0416..6563a53 100644 --- a/programs/winedbg/resource.h +++ b/programs/winedbg/resource.h @@ -26,6 +26,9 @@ #define IDC_STATIC_BG 100 #define IDC_STATIC_TXT1 101 #define IDC_STATIC_TXT2 102 +#define IDC_CRASHLOG 103 + +#define ID_SHOWDETAILS 200 #define IDS_AUTO_CAPTION 16 #define IDS_INVALID_PARAMS 17 diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index 099b353..913740b 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -766,7 +766,8 @@ enum dbg_start dbg_active_auto(int argc, char* argv[]) msgbox_res_id(NULL, IDS_INVALID_PARAMS, IDS_AUTO_CAPTION, MB_OK); return ds; } - display_crash_dialog(); + + report_save_to_tmp(); hFile = parser_generate_command_file("echo Modules:", "info share", "echo Threads:", "info threads", diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index a3a9f16..7f8a407 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -88,12 +88,12 @@ struct dbg_thread* dbg_curr_thread = NULL; DWORD_PTR dbg_curr_tid = 0; DWORD_PTR dbg_curr_pid = 0; CONTEXT dbg_context; +HANDLE dbg_houtput; BOOL dbg_interactiveP = FALSE; static struct list dbg_process_list = LIST_INIT(dbg_process_list); struct dbg_internal_var dbg_internal_vars[DBG_IV_LAST]; -static HANDLE dbg_houtput; static void dbg_outputA(const char* buffer, int len) { @@ -675,7 +675,9 @@ int main(int argc, char** argv) dbg_houtput = GetStdHandle(STD_ERROR_HANDLE); switch (dbg_active_auto(argc, argv)) { - case start_ok: return 0; + case start_ok: + display_crash_dialog(); + return 0; case start_error_parse: return dbg_winedbg_usage(FALSE); case start_error_init: return -1; } diff --git a/programs/winedbg/winedbg.rc b/programs/winedbg/winedbg.rc index 539fdcb..fbd1410 100644 --- a/programs/winedbg/winedbg.rc +++ b/programs/winedbg/winedbg.rc @@ -43,5 +43,6 @@ BEGIN this application.\n\n\ If this problem is not present under Windows and has not been reported \ yet, you can file a bug report.",IDC_STATIC_TXT2,"SysLink",0,27,60,224,100 + PUSHBUTTON "Show Details", ID_SHOWDETAILS, 140, 151, 60, 16 DEFPUSHBUTTON "Close", IDOK, 205, 151, 60, 16, WS_TABSTOP END