u_debug_symbol: support getting a string without output
authorLuca Barbieri <luca@luca-barbieri.com>
Tue, 17 Aug 2010 22:38:19 +0000 (00:38 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Fri, 20 Aug 2010 16:18:28 +0000 (18:18 +0200)
src/gallium/auxiliary/util/u_debug_symbol.c
src/gallium/auxiliary/util/u_debug_symbol.h

index 6e250575d66756592a7cfc03aca502724e1685a6..7147bbc32b874a6ad7c5c6b9ed304bee04f5bad2 100644 (file)
@@ -33,6 +33,7 @@
  */
 
 #include "pipe/p_compiler.h"
+#include "u_string.h"
 
 #include "u_debug.h"
 #include "u_debug_symbol.h"
@@ -113,8 +114,8 @@ BOOL WINAPI j_SymGetSymFromAddr(HANDLE hProcess, DWORD Address, PDWORD Displacem
 }
 
 
-static INLINE boolean
-debug_symbol_print_imagehlp(const void *addr)
+static INLINE void
+debug_symbol_name_imagehlp(const void *addr, char* buf, unsigned size)
 {
    HANDLE hProcess;
    BYTE symbolBuffer[1024];
@@ -131,25 +132,34 @@ debug_symbol_print_imagehlp(const void *addr)
       if(j_SymInitialize(hProcess, NULL, TRUE))
          bSymInitialized = TRUE;
    }
-      
-   if(!j_SymGetSymFromAddr(hProcess, (DWORD)addr, &dwDisplacement, pSymbol))
-      return FALSE;
 
-   debug_printf("\t%s\n", pSymbol->Name);
-
-   return TRUE;
-   
+   if(!j_SymGetSymFromAddr(hProcess, (DWORD)addr, &dwDisplacement, pSymbol))
+      buf[0] = 0;
+   else
+   {
+      strncpy(buf, pSymbol->Name, size);
+      buf[size - 1] = 0;
+   }
 }
 #endif
 
-
 void
-debug_symbol_print(const void *addr)
+debug_symbol_name(const void *addr, char* buf, unsigned size)
 {
 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
-   if(debug_symbol_print_imagehlp(addr))
+   debug_symbol_name_imagehlp(addr, buf, size);
+   if(buf[0])
       return;
 #endif
-   
-   debug_printf("\t%p\n", addr);
+
+   util_snprintf(buf, size, "%p", addr);
+   buf[size - 1] = 0;
+}
+
+void
+debug_symbol_print(const void *addr)
+{
+   char buf[1024];
+   debug_symbol_name(addr, buf, sizeof(buf));
+   debug_printf("\t%s\n", buf);
 }
index 021586987b6d52504dfdc84d178541302f2ed642..5e283e5ba3fa1e2c1b3b591cfdb9a11de3b595e1 100644 (file)
@@ -42,6 +42,9 @@ extern "C" {
 #endif
 
 
+void
+debug_symbol_name(const void *addr, char* buf, unsigned size);
+
 void
 debug_symbol_print(const void *addr);