|
First check whether the source debugging is turned on or not. Also try configuring the source search path from File Menu.
Also try with the following commands
.lines enable source line information<br />
bp main set initial breakpoint<br />
l+t stepping will be done by source line<br />
l+s source lines will be displayed at prompt<br />
g run program until "main" is entered<br />
pr execute one source line, and toggle register display off<br />
p execute one source line
Please check WinDBG help file and confirm the steps specified under "Debugging in Source Mode"
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks Sarath,
I have tried to type .lines and WinDbg displayed "Line number information will be loaded". Seems I enabled source code debugging, correct?
Here is my code, does it because it is managed code, and WinDbg has no ability to show managed code line number?
namespace TestDebug
{
class Program
{
static void foo()
{
int a = 100;
throw new Exception ("Hello Exception Debug");
}
static void Main(string[] args)
{
foo();
}
}
}
regards,
George
|
|
|
|
|
This is C#. This forum is for C++/MFC.
Steve
|
|
|
|
|
Thanks Steve,
I met with the same issue when using C++ code. When first chance or second chance exception occurs, then I press k to display the stack trace, in the stack trace, there is not my own code. Any ideas?
(my purpose is simple, to display the exception call stack and including source code line number.)
#include <iostream>
using namespace std;
void foo()
{
throw "Hello World";
}
int main()
{
int a = 100;
a = a + 100;
foo();
return 0;
}
regards,
George
|
|
|
|
|
First off some questions (regarding the C++ version):
- What IDE are you using?
- What debugger are you using?
- What does the stack trace you're getting look like?
Steve
|
|
|
|
|
Thanks Steve!
I am using Visual Studio 2008 to build the code into a debug version. I am using WinDbg as debugger. I want to see th stack trace like,
foo (@ line 7)
main
any ideas?
regards,
George
|
|
|
|
|
Follow these steps:
- Open program the in WinDBG.
- When loader breakpoint is hit select "Debug"->"Event Filters" from the menu.
- Find "Visual C++ exception" in the list.
- Remember the settings in the radio buttons in case you wish to put them back later.
- Select "Enabled" and "Not Handled" in the radio buttons.
- Press "Close".
- Continue execution.
Steve
|
|
|
|
|
Sure, Steve!
I followed your steps and here is my output (I pressed g when both first chance and second chance exception occured). But still no stack trace for my own code. Any ideas?
(670.ab4): WOW64 breakpoint - code 4000001f (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
ntdll32!DbgBreakPoint:
00000000`7d61002d cc int 3
0:000:x86> g
(670.ab4): C++ EH exception - code e06d7363 (first chance)
(670.ab4): C++ EH exception - code e06d7363 (!!! second chance !!!)
wow64!Wow64NotifyDebugger+0x9:
00000000`6b006369 b001 mov al,1
regards,
George
|
|
|
|
|
Is your program 64-bit or 32-bit? What about your version of Windows?
Steve
|
|
|
|
|
Thanks Steve!
My OS is Windows Server 2003, x64. I build the code into x86 binary. Any ideas?
regards,
George
|
|
|
|
|
Hi Steve,
1.
Your reply gives me some hints and I have made more experiments, here are the results for x64 binary runs on x64 platform. It looks fine. Does it because of x86 code is not supported to print out stack trace on x64?
0:000> g
(730.4f8): C++ EH exception - code e06d7363 (first chance)
(730.4f8): C++ EH exception - code e06d7363 (!!! second chance !!!)
kernel32!RaiseException+0x5c:
00000000`77d4dd10 4881c4c8000000 add rsp,0C8h
0:000> k
Child-SP RetAddr Call Site
00000000`0012fd00 00000000`1029bedc kernel32!RaiseException+0x5c
00000000`0012fdd0 00000001`40001057 MSVCR90D!CxxThrowException+0xac
00000000`0012fe60 00000001`400010a2 TestDebugSource!foo+0x37 [d:\visual studio 2008\projects\testdebugsource\testdebugsource\main.cpp @ 8]
00000000`0012fea0 00000001`400014c2 TestDebugSource!main+0x32 [d:\visual studio 2008\projects\testdebugsource\testdebugsource\main.cpp @ 18]
2.
What is the function of Handled or Not Handled in Event Filter dialog?
(I always set Execution option, but ignore the Continue option before.)
regards,
George
|
|
|
|
|
George_George wrote: It looks fine. Does it because of x86 code is not supported to print out stack trace on x64?
Try using the !wow64exts.sw command.
Steve
|
|
|
|
|
Thanks Steve,
I have tried, the stack with my own code could be printed out, but the line number is not correct (but in x64 binary it is correct).
Any comments to this question I asked before?
--------------------
What is the function of Handled or Not Handled in Event Filter dialog?
(I always set Execution option, but ignore the Continue option before.)
--------------------
regards,
George
|
|
|
|
|
George_George wrote: What is the function of Handled or Not Handled in Event Filter dialog?
(I always set Execution option, but ignore the Continue option before.)
Do a search on "Controlling Exceptions and Events" in WinDBG's help file. I have quoted from this below.
The radio buttons in the "Execution" group control the "Break Status":
- Enabled : "When this exception occurs, the target immediately breaks into the debugger. This break in occurs before any other error handlers are activated. This method is called first-chance handling."
- Disabled : "The debugger does not break in for this kind of first-chance exception (although a message is displayed). If other error handlers cannot address this exception, execution stops and the target break into the debugger. This method is called second-chance handling."
- Notify : "When this exception occurs, the target application does not break into the debugger at all. However, a message is displayed that informs the user of this exception."
- Ignore : "When this exception occurs, the target application does not break into the debugger, and no message is displayed."
The buttons in the "Continue" group control the "Handling Status":
- Handled : "The event is considered handled when execution resumes."
- Not Handled : "The event is considered not handled when execution resumes."
Steve
|
|
|
|
|
Thanks Steve,
I think the question for C++ exception is solved. For the managed code, why the line number could not be displayed when using !pe command, I am not sure whether it is supported in managed code to print the line number along with !pe command output. Any comments?
regards,
George
|
|
|
|
|
Sorry, I can't really help you there. I try to steer clear of managed code: it simply doesn't interest me.
Steve
|
|
|
|
|
It is ok, Steve!
I am trying to find help for command !wow64exts.sw in debugger.chm, but failed. Do you have any documents for this command?
regards,
George
|
|
|
|
|
Not really. Try typing !wow64exts.help
Steve
|
|
|
|
|
Thanks Stephen!
Cool! I find it.
regards,
George
|
|
|
|
|
What is the simplest way to change font of MDI? For example I want a menu with bold, Arial, size 10 font.
Create a menu and use SetFont() function seem to be a official way, but actually it doesn't work.
I found some articles by Google but not help much.
??
|
|
|
|
|
Setting Fonts for Menu-Item Text Strings
This topic contains an example from an application that uses owner-drawn menu items in a menu. The menu contains items that set the attributes of the current font, and the items are displayed using the appropriate font attribute.
Here is how the menu is defined in the resource-definition file. Note that the strings for the Regular, Bold, Italic, and Underline menu items are assigned at run time, so their strings are empty in the resource-definition file.
MainMenu MENU
BEGIN
POPUP "&Character"
BEGIN
MENUITEM "", IDM_REGULAR
MENUITEM SEPARATOR
MENUITEM "", IDM_BOLD
MENUITEM "", IDM_ITALIC
MENUITEM "", IDM_ULINE
END
END
The application's window procedure processes the messages involved in using owner-drawn menu items. The application uses the WM_CREATE message to do the following:
Set the MF_OWNERDRAW flag for the menu items.
Set the text strings for the menu items.
Obtain handles of the fonts used to draw the items.
Obtain the text and background color values for selected menu items.
The text strings and font handles are stored in an array of application-defined MYITEM structures. The application-defined GetAFont function creates a font that corresponds to the specified font attribute and returns a handle to the font. The handles are destroyed during the processing of the WM_DESTROY message.
During the processing of the WM_MEASUREITEM message, the example gets the width and height of a menu-item string and copies these values into the MEASUREITEMSTRUCT structure. The system uses the width and height values to calculate the size of the menu.
During the processing of the WM_DRAWITEM message, the menu item's string is drawn with room left next to the string for the check-mark bitmap. If the user selects the item, the selected text and background colors are used to draw the item.
Top
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
typedef struct _MYITEM
{
HFONT hfont;
LPSTR psz;
} MYITEM; // structure for item font and string
MYITEM *pmyitem; // pointer to item's font and string
static MYITEM myitem[CITEMS]; // array of MYITEMS
static HMENU hmenu; // handle to main menu
static COLORREF crSelText; // text color of selected item
static COLORREF crSelBkgnd; // background color of selected item
COLORREF crText; // text color of unselected item
COLORREF crBkgnd; // background color unselected item
LPMEASUREITEMSTRUCT lpmis; // pointer to item of data
LPDRAWITEMSTRUCT lpdis; // pointer to item drawing data
HDC hdc; // handle to screen DC
SIZE size; // menu-item text extents
WORD wCheckX; // check-mark width
int nTextX; // width of menu item
int nTextY; // height of menu item
int i; // loop counter
HFONT hfontOld; // handle to old font
BOOL fSelected = FALSE; // menu-item selection flag
size_t * pcch;
HRESULT hResult;
switch (uMsg)
{
case WM_CREATE:
// Modify the Regular, Bold, Italic, and Underline
// menu items to make them owner-drawn items. Associate
// a MYITEM structure with each item to contain the
// string and font handle for each item.
hmenu = GetMenu(hwnd);
ModifyMenu(hmenu, IDM_REGULAR, MF_BYCOMMAND |
MF_CHECKED | MF_OWNERDRAW, IDM_REGULAR,
(LPTSTR) &myitem[REGULAR]);
ModifyMenu(hmenu, IDM_BOLD, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_BOLD, (LPTSTR) &myitem[BOLD]);
ModifyMenu(hmenu, IDM_ITALIC, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_ITALIC,
(LPTSTR) &myitem[ITALIC]);
ModifyMenu(hmenu, IDM_ULINE, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_ULINE, (LPTSTR) &myitem[ULINE]);
// Retrieve each item's font handle and copy it into
// the hfont member of each item's MYITEM structure.
// Also, copy each item's string into the structures.
myitem[REGULAR].hfont = GetAFont(REGULAR);
myitem[REGULAR].psz = "Regular";
myitem[BOLD].hfont = GetAFont(BOLD);
myitem[BOLD].psz = "Bold";
myitem[ITALIC].hfont = GetAFont(ITALIC);
myitem[ITALIC].psz = "Italic";
myitem[ULINE].hfont = GetAFont(ULINE);
myitem[ULINE].psz = "Underline";
// Retrieve the text and background colors of the
// selected menu text.
crSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
crSelBkgnd = GetSysColor(COLOR_HIGHLIGHT);
return 0;
case WM_MEASUREITEM:
// Retrieve a device context for the main window.
hdc = GetDC(hwnd);
// Retrieve pointers to the menu item's
// MEASUREITEMSTRUCT structure and MYITEM structure.
lpmis = (LPMEASUREITEMSTRUCT) lParam;
pmyitem = (MYITEM *) lpmis->itemData;
// Select the font associated with the item into
// the main window's device context.
hfontOld = SelectObject(hdc, pmyitem->hfont);
// Retrieve the width and height of the item's string,
// and then copy the width and height into the
// MEASUREITEMSTRUCT structure's itemWidth and
// itemHeight members.
hResult = StringCchLength(pmyitem->psz,STRSAFE_MAX_CCH, pcch);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
GetTextExtentPoint32(hdc, pmyitem->psz,
*pcch, &size);
lpmis->itemWidth = size.cx;
lpmis->itemHeight = size.cy;
// Select the old font back into the device context,
// and then release the device context.
SelectObject(hdc, hfontOld);
ReleaseDC(hwnd, hdc);
return TRUE;
break;
case WM_DRAWITEM:
// Get pointers to the menu item's DRAWITEMSTRUCT
// structure and MYITEM structure.
lpdis = (LPDRAWITEMSTRUCT) lParam;
pmyitem = (MYITEM *) lpdis->itemData;
// If the user has selected the item, use the selected
// text and background colors to display the item.
if (lpdis->itemState & ODS_SELECTED)
{
crText = SetTextColor(lpdis->hDC, crSelText);
crBkgnd = SetBkColor(lpdis->hDC, crSelBkgnd);
fSelected = TRUE;
}
// Remember to leave space in the menu item for the
// check-mark bitmap. Retrieve the width of the bitmap
// and add it to the width of the menu item.
wCheckX = GetSystemMetrics(SM_CXMENUCHECK);
nTextX = wCheckX + lpdis->rcItem.left;
nTextY = lpdis->rcItem.top;
// Select the font associated with the item into the
// item's device context, and then draw the string.
hfontOld = SelectObject(lpdis->hDC, pmyitem->hfont);
hResult = StringCchLength(pmyitem->psz,STRSAFE_MAX_CCH, pcch);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
ExtTextOut(lpdis->hDC, nTextX, nTextY, ETO_OPAQUE,
&lpdis->rcItem, pmyitem->psz,
*pcch, NULL);
// Select the previous font back into the device
// context.
SelectObject(lpdis->hDC, hfontOld);
// Return the text and background colors to their
// normal state (not selected).
if (fSelected)
{
SetTextColor(lpdis->hDC, crText);
SetBkColor(lpdis->hDC, crBkgnd);
}
return TRUE;
// Process other messages.
case WM_DESTROY:
// Destroy the menu items' font handles.
for (i = 0; i < CITEMS; i++)
DeleteObject(myitem[i].hfont);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return NULL;
}
HFONT GetAFont(int fnFont)
{
static LOGFONT lf; // structure for font information
// Get a handle to the ANSI fixed-pitch font, and copy
// information about the font to a LOGFONT structure.
GetObject(GetStockObject(ANSI_FIXED_FONT), sizeof(LOGFONT),
&lf);
// Set the font attributes, as appropriate.
if (fnFont == BOLD)
lf.lfWeight = FW_BOLD;
else
lf.lfWeight = FW_NORMAL;
lf.lfItalic = (fnFont == ITALIC);
lf.lfItalic = (fnFont == ULINE);
// Create the font, and then return its handle.
return CreateFont(lf.lfHeight, lf.lfWidth,
lf.lfEscapement, lf.lfOrientation, lf.lfWeight,
lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet,
lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
lf.lfPitchAndFamily, lf.lfFaceName);
}
|
|
|
|
|
It seem to be not very easy. I'll try it later.
Thank you very much, halibobo.
|
|
|
|
|
I am a Chinese girl.My English is not very good. I wish we can advance together.
|
|
|
|
|
There is no easy way. The menu is part of the non-client area, and windows is kindly handling for you.
The idea is that a user can pick a font / size she likes, and all her software will use it. You'd better have a damn good reason to override her preferences, so it's fine for it to be hard for you.
There are several good owner drawn menu articles here on codeproject for you to dig through, or look at halibobo's reply.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
sorry all, I tried to use another solution: codejock software.
it's ok now, thank you friends!
|
|
|
|
|