X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b713f8919c649822292f04bb7095291585d96550..6759ff7d4de5817b4b93f10e0b697700f5a18467:/samples/console/console.cpp?ds=sidebyside diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 8c748f841c..1ad703cabd 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -74,6 +74,7 @@ #define TEST_SCOPEGUARD #define TEST_SNGLINST // #define TEST_SOCKETS --FIXME! (RN) + #define TEST_STACKWALKER #define TEST_STDPATHS #define TEST_STREAMS #define TEST_TEXTSTREAM @@ -84,7 +85,7 @@ #define TEST_WCHAR #define TEST_ZIP #else // #if TEST_ALL - #define TEST_STDPATHS + #define TEST_STACKWALKER #endif // some tests are interactive, define this to run them @@ -382,13 +383,13 @@ static void TestDllLoad() static const wxChar *FUNC_NAME = _T("lstrlenA"); #elif defined(__UNIX__) // weird: using just libc.so does *not* work! - static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so"); + static const wxChar *LIB_NAME = _T("/lib/libc.so.6"); static const wxChar *FUNC_NAME = _T("strlen"); #else #error "don't know how to test wxDllLoader on this platform" #endif - wxPuts(_T("*** testing wxDllLoader ***\n")); + wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n")); wxDynamicLibrary lib(LIB_NAME); if ( !lib.IsLoaded() ) @@ -406,6 +407,9 @@ static void TestDllLoad() } else { + wxPrintf(_T("Calling %s dynamically loaded from %s "), + FUNC_NAME, LIB_NAME); + if ( pfnStrlen("foo") != 3 ) { wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n")); @@ -418,6 +422,34 @@ static void TestDllLoad() } } +#if defined(__WXMSW__) || defined(__UNIX__) + +static void TestDllListLoaded() +{ + wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n")); + + puts("\nLoaded modules:"); + wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded(); + const size_t count = dlls.GetCount(); + for ( size_t n = 0; n < count; ++n ) + { + const wxDynamicLibraryDetails& details = dlls[n]; + printf("%-45s", details.GetPath().mb_str()); + + void *addr; + size_t len; + if ( details.GetAddress(&addr, &len) ) + { + printf(" %08lx:%08lx", + (unsigned long)addr, (unsigned long)((char *)addr + len)); + } + + printf(" %s\n", details.GetVersion().mb_str()); + } +} + +#endif + #endif // TEST_DLLLOADER // ---------------------------------------------------------------------------- @@ -2598,6 +2630,71 @@ static void TestFtpUpload() #endif // TEST_FTP +// ---------------------------------------------------------------------------- +// stack backtrace +// ---------------------------------------------------------------------------- + +#ifdef TEST_STACKWALKER + +#include "wx/stackwalk.h" + +class StackDump : public wxStackWalker +{ +public: + StackDump(const char *argv0) + : wxStackWalker(argv0) + { + } + + virtual void Walk() + { + wxPuts(_T("Stack dump:")); + + wxStackWalker::Walk(); + } + +protected: + virtual void OnStackFrame(const wxStackFrame& frame) + { + printf("[%2d] ", frame.GetLevel()); + + wxString name = frame.GetName(); + if ( !name.empty() ) + { + printf("%-20.40s", name.mb_str()); + } + else + { + printf("0x%08lx", (unsigned long)frame.GetAddress()); + } + + if ( frame.HasSourceLocation() ) + { + printf("\t%s:%d", + frame.GetFileName().mb_str(), + frame.GetLine()); + } + + puts(""); + + wxString type, val; + for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ ) + { + printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str()); + } + } +}; + +static void TestStackWalk(const char *argv0) +{ + wxPuts(_T("*** Testing wxStackWalker ***\n")); + + StackDump dump(argv0); + dump.Walk(); +} + +#endif // TEST_STACKWALKER + // ---------------------------------------------------------------------------- // standard paths // ---------------------------------------------------------------------------- @@ -4093,6 +4190,7 @@ int main(int argc, char **argv) #ifdef TEST_DLLLOADER TestDllLoad(); + TestDllListLoaded(); #endif // TEST_DLLLOADER #ifdef TEST_ENVIRON @@ -4300,6 +4398,10 @@ int main(int argc, char **argv) TestScopeGuard(); #endif +#ifdef TEST_STACKWALKER + TestStackWalk(argv[0]); +#endif // TEST_STACKWALKER + #ifdef TEST_STDPATHS TestStandardPaths(); #endif