Context Trace Outputs for Exceptions

svn path=/trunk/; revision=6765
This commit is contained in:
Martin Fuchs 2003-11-23 14:23:55 +00:00
parent e79ee7d5e6
commit 5a5723bad2
9 changed files with 146 additions and 36 deletions

View file

@ -50,7 +50,7 @@ extern struct ExplorerGlobals
#define LOG(x) \
{ \
if (g_Globals._log) _ftprintf(g_Globals._log, TEXT("%s\n"), (LPCTSTR)(x)); \
OutputDebugString(x); \
OutputDebugString(FmtString(TEXT("%s\n"), (LPCTSTR)(x))); \
}

View file

@ -102,6 +102,8 @@ Entry::~Entry()
// read directory tree and expand to the given location
Entry* Entry::read_tree(const void* path, SORT_ORDER sortOrder)
{
CONTEXT("Entry::read_tree()");
HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
Entry* entry = this;
@ -126,6 +128,8 @@ Entry* Entry::read_tree(const void* path, SORT_ORDER sortOrder)
void Entry::read_directory(SORT_ORDER sortOrder)
{
CONTEXT("Entry::read_directory(SORT_ORDER)");
// call into subclass
read_directory();
@ -282,6 +286,8 @@ void Entry::sort_directory(SORT_ORDER sortOrder)
void Entry::smart_scan()
{
CONTEXT("Entry::smart_scan()");
if (!_scanned) {
free_subentries();
read_directory(SORT_NAME); // we could use IShellFolder2::GetDefaultColumn to determine sort order

View file

@ -439,6 +439,8 @@ void FileChildWindow::activate_entry(Pane* pane, HWND hwnd)
void FileChildWindow::scan_entry(Entry* entry, HWND hwnd)
{
CONTEXT("FileChildWindow::scan_entry()");
int idx = ListBox_GetCurSel(_left_hwnd);
HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));

View file

@ -72,6 +72,8 @@ ShellBrowserChild::~ShellBrowserChild()
LRESULT ShellBrowserChild::Init(LPCREATESTRUCT pcs)
{
CONTEXT("ShellBrowserChild::Init()");
if (super::Init(pcs))
return 1;
@ -105,6 +107,8 @@ LRESULT ShellBrowserChild::Init(LPCREATESTRUCT pcs)
void ShellBrowserChild::InitializeTree()
{
CONTEXT("ShellBrowserChild::InitializeTree()");
TreeView_SetImageList(_left_hwnd, _himlSmall, TVSIL_NORMAL);
TreeView_SetScrollTime(_left_hwnd, 100);
@ -150,6 +154,8 @@ void ShellBrowserChild::InitializeTree()
bool ShellBrowserChild::InitDragDrop()
{
CONTEXT("ShellBrowserChild::InitDragDrop()");
_pDropTarget = new TreeDropTarget(_left_hwnd);
if (!_pDropTarget)
@ -180,6 +186,8 @@ bool ShellBrowserChild::InitDragDrop()
void ShellBrowserChild::OnTreeItemRClick(int idCtrl, LPNMHDR pnmh)
{
CONTEXT("ShellBrowserChild::OnTreeItemRClick()");
TVHITTESTINFO tvhti;
GetCursorPos(&tvhti.pt);
@ -196,6 +204,8 @@ void ShellBrowserChild::OnTreeItemRClick(int idCtrl, LPNMHDR pnmh)
void ShellBrowserChild::Tree_DoItemMenu(HWND hwndTreeView, HTREEITEM hItem, LPPOINT pptScreen)
{
CONTEXT("ShellBrowserChild::Tree_DoItemMenu()");
LPARAM itemData = TreeView_GetItemData(hwndTreeView, hItem);
if (itemData) {
@ -273,6 +283,8 @@ void ShellBrowserChild::Tree_DoItemMenu(HWND hwndTreeView, HTREEITEM hItem, LPPO
void ShellBrowserChild::OnTreeGetDispInfo(int idCtrl, LPNMHDR pnmh)
{
CONTEXT("ShellBrowserChild::OnTreeGetDispInfo()");
LPNMTVDISPINFO lpdi = (LPNMTVDISPINFO)pnmh;
ShellEntry* entry = (ShellEntry*)lpdi->item.lParam;
@ -307,6 +319,8 @@ void ShellBrowserChild::OnTreeGetDispInfo(int idCtrl, LPNMHDR pnmh)
void ShellBrowserChild::OnTreeItemExpanding(int idCtrl, LPNMTREEVIEW pnmtv)
{
CONTEXT("ShellBrowserChild::OnTreeItemExpanding()");
if (pnmtv->action == TVE_COLLAPSE)
TreeView_Expand(_left_hwnd, pnmtv->itemNew.hItem, TVE_COLLAPSE|TVE_COLLAPSERESET);
else if (pnmtv->action == TVE_EXPAND) {
@ -330,6 +344,8 @@ void ShellBrowserChild::OnTreeItemExpanding(int idCtrl, LPNMTREEVIEW pnmtv)
int ShellBrowserChild::InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder)
{
CONTEXT("ShellBrowserChild::InsertSubitems()");
WaitCursor wait;
int cnt = 0;
@ -381,6 +397,8 @@ int ShellBrowserChild::InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShel
void ShellBrowserChild::OnTreeItemSelected(int idCtrl, LPNMTREEVIEW pnmtv)
{
CONTEXT("ShellBrowserChild::OnTreeItemSelected()");
ShellEntry* entry = (ShellEntry*)pnmtv->itemNew.lParam;
_last_sel = pnmtv->itemNew.hItem;
@ -402,6 +420,8 @@ void ShellBrowserChild::OnTreeItemSelected(int idCtrl, LPNMTREEVIEW pnmtv)
void ShellBrowserChild::UpdateFolderView(IShellFolder* folder)
{
CONTEXT("ShellBrowserChild::UpdateFolderView()");
FOLDERSETTINGS fs;
IShellView* pLastShellView = _pShellView;
@ -467,6 +487,8 @@ int ShellBrowserChild::Notify(int id, NMHDR* pnmh)
HRESULT ShellBrowserChild::OnDefaultCommand(LPIDA pIDList)
{
CONTEXT("ShellBrowserChild::OnDefaultCommand()");
if (pIDList->cidl>=1) {
if (_left_hwnd) { // explorer mode
if (_last_sel) {
@ -506,6 +528,8 @@ HRESULT ShellBrowserChild::OnDefaultCommand(LPIDA pIDList)
bool ShellBrowserChild::expand_folder(ShellDirectory* entry)
{
CONTEXT("ShellBrowserChild::expand_folder()");
//HTREEITEM hitem_sel = TreeView_GetSelection(_left_hwnd);
if (!_last_sel)
return false;

View file

@ -37,6 +37,8 @@
bool ShellDirectory::fill_w32fdata_shell(LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* pw32fdata, BY_HANDLE_FILE_INFORMATION* pbhfi, bool do_access)
{
CONTEXT("ShellDirectory::fill_w32fdata_shell()");
bool bhfi_valid = false;
if (do_access && !( (attribs&SFGAO_FILESYSTEM) && SUCCEEDED(
@ -107,6 +109,8 @@ bool ShellDirectory::fill_w32fdata_shell(LPCITEMIDLIST pidl, SFGAOF attribs, WIN
ShellPath ShellEntry::create_absolute_pidl() const
{
CONTEXT("ShellEntry::create_absolute_pidl()");
if (_up/* && _up->_etype==ET_SHELL*/) {
ShellDirectory* dir = static_cast<ShellDirectory*>(_up);
@ -130,6 +134,8 @@ void ShellEntry::get_path(PTSTR path) const
// get full path of a shell folder
void ShellDirectory::get_path(PTSTR path) const
{
CONTEXT("ShellDirectory::get_path()");
path[0] = TEXT('\0');
SFGAOF attribs = 0;
@ -174,6 +180,8 @@ BOOL ShellEntry::launch_entry(HWND hwnd, UINT nCmdShow)
static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
{
CONTEXT("extract_icon()");
IExtractIcon* pExtract;
if (SUCCEEDED(folder->GetUIObjectOf(0, 1, (LPCITEMIDLIST*)&pidl, IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
@ -229,6 +237,8 @@ static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
void ShellDirectory::read_directory()
{
CONTEXT("ShellDirectory::read_directory()");
int level = _level + 1;
Entry* first_entry = NULL;

View file

@ -62,36 +62,47 @@ LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
}
Context Context::s_main(TEXT("-NO-CONTEXT-"));
Context Context::s_main("-NO-CONTEXT-");
Context* Context::s_current = &Context::s_main;
String Context::toString() const
{
FmtString str(TEXT("%hs"), _ctx);
if (!_obj.empty())
str.appendf(TEXT("\nObject: %s"), (LPCTSTR)_obj);
return str;
}
String Context::getStackTrace() const
{
// evtl. besser ostringstream verwenden
String str = TEXT("Context Trace:\n");
for(const Context*p=this; p!=&s_main; p=p->_last)
str.appendf(TEXT("ctx=%hs obj=%s\n"), p->_ctx, (LPCTSTR)p->_obj);
return str;
}
// Exception Handler for COM exceptions
String COMException::toString() const
{
TCHAR msg[4*BUFFER_LEN];
LPTSTR p = msg;
p += _stprintf(p, TEXT("%s"), super::ErrorMessage());
if (_ctx)
p += _stprintf(p, TEXT("\nContext: %s"), _ctx);
if (!_obj.empty())
p += _stprintf(p, TEXT("\nObject: %s"), (LPCTSTR)_obj);
p += _stprintf(p, TEXT("%s\nContext: %s"), super::ErrorMessage(), (LPCTSTR)_ctx.toString());
if (_file)
#ifdef UNICODE
p += _stprintf(p, TEXT("\nLocation: %hs(%d)"), _file, _line);
#else
p += _stprintf(p, TEXT("\nLocation: %s, line %d"), _file, _line);
#endif
return msg;
}
/// Exception Handler for COM exceptions
void HandleException(COMException& e, HWND hwnd)
{
String msg = e.toString();

View file

@ -102,45 +102,44 @@ struct COMException : public COMExceptionBase
COMException(HRESULT hr)
: super(hr),
_ctx(Context::current()._ctx),
_obj(Context::current()._obj),
_ctx(CURRENT_CONTEXT),
_file(NULL), _line(0)
{
LOG(toString());
LOG(CURRENT_CONTEXT.getStackTrace());
}
COMException(HRESULT hr, const char* file, int line)
: super(hr),
_ctx(Context::current()._ctx),
_obj(Context::current()._obj),
_ctx(CURRENT_CONTEXT),
_file(file), _line(line)
{
LOG(toString());
LOG(CURRENT_CONTEXT.getStackTrace());
}
COMException(HRESULT hr, const String& obj)
: super(hr),
_ctx(Context::current()._ctx),
_obj(obj),
_ctx(CURRENT_CONTEXT),
_file(NULL), _line(0)
{
_ctx = Context::current()._ctx;
_ctx = CURRENT_CONTEXT;
LOG(toString());
LOG(CURRENT_CONTEXT.getStackTrace());
}
COMException(HRESULT hr, const String& obj, const char* file, int line)
: super(hr),
_ctx(Context::current()._ctx),
_obj(obj),
_ctx(CURRENT_CONTEXT),
_file(file), _line(line)
{
LOG(toString());
LOG(CURRENT_CONTEXT.getStackTrace());
}
String toString() const;
LPCTSTR _ctx;
String _obj;
Context _ctx;
const char* _file;
int _line;

View file

@ -93,17 +93,17 @@ void MoveVisible(HWND hwnd)
}
void display_error(HWND hwnd, DWORD error) //@@ CONTEXT mit ausgeben
void display_error(HWND hwnd, DWORD error) //@@ CONTEXT mit ausgeben -> display_error(HWND hwnd, const Exception& e)
{
PTSTR msg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) {
LOG(msg);
LOG(FmtString(TEXT("display_error(%#x): %s"), error, msg));
MessageBox(hwnd, msg, TEXT("ROS Explorer"), MB_OK);
} else {
LOG(TEXT("display_error: Unknown Error"));
MessageBox(hwnd, TEXT("Unknown Error"), TEXT("ROS Explorer"), MB_OK);
LOG(FmtString(TEXT("Unknown Error %#x"), error));
MessageBox(hwnd, FmtString(TEXT("Unknown Error %#x"), error), TEXT("ROS Explorer"), MB_OK);
}
LocalFree(msg);

View file

@ -85,7 +85,7 @@ using namespace _com_util;
#define BUFFER_LEN 1024
#define LOG(x) OutputDebugString(x)
#define LOG(x) OutputDebugString(FmtString(TEXT("%s\n"), (LPCTSTR)(x)));
/// initialization of windows common controls
@ -510,6 +510,60 @@ struct String
String& operator=(const super& s) {super::assign(s); return *this;}
operator LPCTSTR() const {return c_str();}
String& printf(LPCTSTR fmt, ...)
{
va_list l;
TCHAR b[BUFFER_LEN];
va_start(l, fmt);
super::assign(b, _vstprintf(b, fmt, l));
va_end(l);
return *this;
}
String& vprintf(LPCTSTR fmt, va_list l)
{
TCHAR b[BUFFER_LEN];
super::assign(b, _vstprintf(b, fmt, l));
return *this;
}
String& appendf(LPCTSTR fmt, ...)
{
va_list l;
TCHAR b[BUFFER_LEN];
va_start(l, fmt);
super::append(b, _vstprintf(b, fmt, l));
va_end(l);
return *this;
}
String& vappendf(LPCTSTR fmt, va_list l)
{
TCHAR b[BUFFER_LEN];
super::append(b, _vstprintf(b, fmt, l));
return *this;
}
};
struct FmtString : public String
{
FmtString(LPCTSTR fmt, ...)
{
va_list l;
va_start(l, fmt);
vprintf(fmt, l);
va_end(l);
}
};
@ -571,14 +625,14 @@ protected:
struct Context
{
Context(LPCTSTR ctx)
Context(const char* ctx)
: _ctx(ctx)
{
_last = s_current;
s_current = this;
}
Context(LPCTSTR ctx, LPCSTR obj)
Context(const char* ctx, LPCSTR obj)
: _ctx(ctx),
_obj(obj)
{
@ -586,7 +640,7 @@ struct Context
s_current = this;
}
Context(LPCTSTR ctx, LPCWSTR obj)
Context(const char* ctx, LPCWSTR obj)
: _ctx(ctx),
_obj(obj)
{
@ -599,7 +653,10 @@ struct Context
s_current = _last;
}
LPCTSTR _ctx;
String toString() const;
String getStackTrace() const;
const char* _ctx;
String _obj;
static Context current() {return *s_current;}
@ -612,8 +669,9 @@ protected:
};
#define CONTEXT_OBJ __ctx__._obj
#define CONTEXT(c) Context __ctx__(TEXT(c))
#define OBJ_CONTEXT(c, o) Context __ctx__(TEXT(c), o);
#define CONTEXT(c) Context __ctx__(c)
#define CURRENT_CONTEXT Context::current()
#define OBJ_CONTEXT(c, o) Context __ctx__(c, o);
#endif // __cplusplus