diff options
author | José Fonseca <jfonseca@vmware.com> | 2014-09-05 11:53:11 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-09-05 18:53:06 +0100 |
commit | 64add5f1d9058e35b29f6a26f1cad0298cb03706 (patch) | |
tree | 139b792152ac42a7eb2939bd38a78abb4cfa04c4 | |
parent | 2d42429985b77df4bb001dbdd2802518aa86b713 (diff) |
d3dretrace: Move HRESULT message lookup code into its own function.
Instead of duplicating it on every generated function.
-rw-r--r-- | retrace/retrace.cpp | 26 | ||||
-rw-r--r-- | retrace/retrace.hpp | 8 | ||||
-rw-r--r-- | retrace/retrace.py | 3 |
3 files changed, 35 insertions, 2 deletions
diff --git a/retrace/retrace.cpp b/retrace/retrace.cpp index cb2c3adc..aafd8112 100644 --- a/retrace/retrace.cpp +++ b/retrace/retrace.cpp @@ -59,6 +59,32 @@ std::ostream &warning(trace::Call &call) { } +#ifdef _WIN32 +void +failed(trace::Call &call, HRESULT hr) +{ + std::ostream &os = warning(call); + + os << "failed with 0x" << std::hex << hr << std::dec; + + LPSTR lpszMessageBuffer = NULL; + DWORD dwWritten; + dwWritten = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + hr, + 0, + (LPSTR)&lpszMessageBuffer, 0, + NULL); + if (dwWritten) { + os << ": " << lpszMessageBuffer; + } + LocalFree(lpszMessageBuffer); + + os << "\n"; +} +#endif /* _WIN32 */ + + void ignore(trace::Call &call) { (void)call; } diff --git a/retrace/retrace.hpp b/retrace/retrace.hpp index 8f92d1c2..09cad737 100644 --- a/retrace/retrace.hpp +++ b/retrace/retrace.hpp @@ -35,6 +35,10 @@ #include <map> #include <ostream> +#ifdef _WIN32 +#include <windows.h> +#endif + #include "trace_model.hpp" #include "trace_parser.hpp" #include "trace_profiler.hpp" @@ -131,6 +135,10 @@ extern trace::DumpFlags dumpFlags; std::ostream &warning(trace::Call &call); +#ifdef _WIN32 +void failed(trace::Call &call, HRESULT hr); +#endif + void ignore(trace::Call &call); void unsupported(trace::Call &call); diff --git a/retrace/retrace.py b/retrace/retrace.py index d6c4788d..03a4617b 100644 --- a/retrace/retrace.py +++ b/retrace/retrace.py @@ -496,8 +496,7 @@ class Retracer: def checkResult(self, resultType): if str(resultType) == 'HRESULT': print r' if (FAILED(_result)) {' - print ' static char szMessageBuffer[128];' - print r' retrace::warning(call) << "call returned 0x" << std::hex << _result << std::dec << ": " << (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, _result, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), szMessageBuffer, sizeof szMessageBuffer, NULL) ? szMessageBuffer : "???") << "\n";' + print r' retrace::failed(call, _result);' print r' }' def filterFunction(self, function): |