gallium: Switch u_debug_stack/symbol.c to util/hash_table.h
[mesa.git] / src / gallium / auxiliary / util / u_debug_stack.c
index 7013807b6b226e4d715cb8b2df35a5e5d2a57fc6..21f0371d3c13f99466566ed5fd9bf6c70ba76e38 100644 (file)
  * @author Jose Fonseca <jfonseca@vmware.com>
  */
 
-#include "u_debug.h"
+#include "util/u_debug.h"
 #include "u_debug_symbol.h"
 #include "u_debug_stack.h"
+#include "pipe/p_config.h"
 
 #if defined(HAVE_LIBUNWIND)
 
 #include <dlfcn.h>
 
 #include "os/os_thread.h"
-#include "u_hash_table.h"
+#include "util/hash_table.h"
 
-struct util_hash_table* symbols_hash;
+static struct hash_table* symbols_hash;
 static mtx_t symbols_mutex = _MTX_INITIALIZER_NP;
 
-static unsigned hash_ptr(void* p)
-{
-   return (unsigned)(uintptr_t)p;
-}
-
-static int compare_ptr(void* a, void* b)
-{
-   if(a == b)
-      return 0;
-   else if(a < b)
-      return -1;
-   else
-      return 1;
-}
-
 /* TODO with some refactoring we might be able to re-use debug_symbol_name_cached()
  * instead.. otoh if using libunwind I think u_debug_symbol could just be excluded
  * from build?
@@ -76,10 +62,9 @@ symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
 
    mtx_lock(&symbols_mutex);
    if(!symbols_hash)
-      symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
-   name = util_hash_table_get(symbols_hash, addr);
-   if(!name)
-   {
+      symbols_hash = _mesa_pointer_hash_table_create(NULL);
+   struct hash_entry *entry = _mesa_hash_table_search(symbols_hash, addr);
+   if (!entry) {
       char procname[256];
       unw_word_t off;
       int ret;
@@ -90,13 +75,13 @@ symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
          procname[1] = 0;
       }
 
-      asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "");
-
-      util_hash_table_set(symbols_hash, addr, (void*)name);
+      if (asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "") == -1) 
+         name = "??";
+      entry = _mesa_hash_table_insert(symbols_hash, addr, (void*)name);
    }
    mtx_unlock(&symbols_mutex);
 
-   return name;
+   return entry->data;
 }
 
 void
@@ -193,7 +178,8 @@ debug_backtrace_print(FILE *f,
             frame_ip(&backtrace[i]));
    }
 }
-
+#elif defined(ANDROID)
+   /* Not implemented here; see u_debug_stack_android.cpp */
 #else /* ! HAVE_LIBUNWIND */
 
 #if defined(PIPE_OS_WINDOWS)
@@ -264,8 +250,11 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
    }
 #endif
 
-#if defined(PIPE_CC_GCC)
+#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION > 404) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wframe-address"
    frame_pointer = ((const void **)__builtin_frame_address(1));
+#pragma GCC diagnostic pop
 #elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
    __asm {
       mov frame_pointer, ebp