[commit: ghc] ghc-8.2: rts: Revert unintentional changes in Libdw.c (9410a4c)

git at git.haskell.org git at git.haskell.org
Tue May 23 23:47:44 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/9410a4c8a710fc59ad8b03b94302d7cb6b9c92f3/ghc

>---------------------------------------------------------------

commit 9410a4c8a710fc59ad8b03b94302d7cb6b9c92f3
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Tue May 23 19:46:24 2017 -0400

    rts: Revert unintentional changes in Libdw.c
    
    These snuck in to 66d5e8015bed91fd0e2091641fe855c433c24b6c.


>---------------------------------------------------------------

9410a4c8a710fc59ad8b03b94302d7cb6b9c92f3
 rts/Libdw.c | 83 ++++++++++---------------------------------------------------
 1 file changed, 13 insertions(+), 70 deletions(-)

diff --git a/rts/Libdw.c b/rts/Libdw.c
index d949217..a16ea59 100644
--- a/rts/Libdw.c
+++ b/rts/Libdw.c
@@ -18,8 +18,6 @@
 
 const int max_backtrace_depth = 5000;
 
-static bool set_initial_registers(Dwfl_Thread *thread, void *arg);
-
 static BacktraceChunk *backtraceAllocChunk(BacktraceChunk *next) {
     BacktraceChunk *chunk = stgMallocBytes(sizeof(BacktraceChunk),
                                            "backtraceAllocChunk");
@@ -61,13 +59,14 @@ void backtraceFree(Backtrace *bt) {
 
 struct LibdwSession_ {
     Dwfl *dwfl;
-    Dwfl_Thread_Callbacks thread_cbs;
 
     // The current backtrace we are collecting (if any)
     Backtrace *cur_bt;
     int max_depth;
 };
 
+static const Dwfl_Thread_Callbacks thread_cbs;
+
 void libdwFree(LibdwSession *session) {
     if (session == NULL)
         return;
@@ -112,7 +111,6 @@ LibdwSession *libdwInit() {
         goto fail;
     }
 
-
     pid_t pid = getpid();
     if (! dwfl_attach_state(session->dwfl, NULL, pid, &thread_cbs, NULL)) {
         sysErrorBelch("dwfl_attach_state failed: %s",
@@ -245,62 +243,11 @@ static int getBacktraceFrameCb(Dwfl_Frame *frame, void *arg) {
     }
 }
 
-static pid_t next_tso(Dwfl *dwfl, void *arg, void **thread_argp) {
-    /* there is only the current thread */
-    if (*thread_argp != NULL)
-        return 0;
-
-    *thread_argp = tso;
-    return dwfl_pid(dwfl);
-}
-
-int forEachHsThread(LibdwSession *session, int (*do_it)(StgTSO *)) {
-    tso_list *list = NULL;
-    for (int g = 0; g < RtsFlags.GcFlags.generations; g++) {
-        for (StgTSO *t = generations[g].threads; t != END_TSO_QUEUE; t = t->global_link) {
-            int ret = do_it(t);
-            if (ret) return ret;
-        }
-    }
-    return 0;
-}
-
-/* Collect a backtrace for the thread associated with the given TSO */
-Backtrace *libdwGetThreadBacktrace(LibdwSession *session, StgTSO *tso) {
-    if (session->cur_bt != NULL) {
-        sysErrorBelch("Already collecting backtrace. Uh oh.");
-        return NULL;
-    }
-
-    session->thread_cbs = {
-        .next_thread = dummy_next_thread,
-        .memory_read = memory_read,
-        .set_initial_registers = set_tso_initial_registers,
-    };
-
-    Backtrace *bt = backtraceAlloc();
-    session->cur_bt = bt;
-    session->max_depth = max_backtrace_depth;
-    int ret = dwfl_getthread_frames(session->dwfl, tso, getBacktraceFrameCb, session);
-    if (ret == -1)
-        sysErrorBelch("Failed to get stack frames of current process: %s",
-                      dwfl_errmsg(dwfl_errno()));
-
-    session->cur_bt = NULL;
-    return bt;
-}
-
-/* Collect a backtrace of the current execution stack */
 Backtrace *libdwGetBacktrace(LibdwSession *session) {
     if (session->cur_bt != NULL) {
         sysErrorBelch("Already collecting backtrace. Uh oh.");
         return NULL;
     }
-    session->thread_cbs = {
-        .next_thread = dummy_next_thread,
-        .memory_read = memory_read,
-        .set_initial_registers = set_current_initial_registers,
-    };
 
     Backtrace *bt = backtraceAlloc();
     session->cur_bt = bt;
@@ -317,9 +264,7 @@ Backtrace *libdwGetBacktrace(LibdwSession *session) {
     return bt;
 }
 
-/* the libdwfl next_thread callback for when we are collecting a backtrace for
-   the current thread */
-static pid_t dummy_next_thread(Dwfl *dwfl, void *arg, void **thread_argp) {
+static pid_t next_thread(Dwfl *dwfl, void *arg, void **thread_argp) {
     /* there is only the current thread */
     if (*thread_argp != NULL)
         return 0;
@@ -328,24 +273,17 @@ static pid_t dummy_next_thread(Dwfl *dwfl, void *arg, void **thread_argp) {
     return dwfl_pid(dwfl);
 }
 
-/* libdwfl memory_read callback to read from the current process */
 static bool memory_read(Dwfl *dwfl STG_UNUSED, Dwarf_Addr addr,
                         Dwarf_Word *result, void *arg STG_UNUSED) {
     *result = *(Dwarf_Word *) (uintptr_t) addr;
     return true;
 }
 
-#ifdef x86_64_HOST_ARCH
-static bool set_tso_initial_registers(Dwfl_Thread *thread, void *arg) {
-    StgTSO *tso = arg;
-    Dwarf_Word regs[17];
-    regs[6] = tso->stackobj->sp; // rbp
-    regs[16] = tso->stackobj->sp[0]; // rip
-    return dwfl_thread_state_registers(thread, 0, 17, regs);
-}
+static bool set_initial_registers(Dwfl_Thread *thread, void *arg);
 
-static bool set_current_initial_registers(Dwfl_Thread *thread,
-                                          void *arg STG_UNUSED) {
+#ifdef x86_64_HOST_ARCH
+static bool set_initial_registers(Dwfl_Thread *thread,
+                                  void *arg STG_UNUSED) {
     Dwarf_Word regs[17];
     __asm__ ("movq %%rax, 0x00(%0)\n\t"
              "movq %%rdx, 0x08(%0)\n\t"
@@ -371,7 +309,6 @@ static bool set_current_initial_registers(Dwfl_Thread *thread,
         );
     return dwfl_thread_state_registers(thread, 0, 17, regs);
 }
-
 #elif defined(i386_HOST_ARCH)
 static bool set_initial_registers(Dwfl_Thread *thread,
                                   void *arg STG_UNUSED) {
@@ -397,6 +334,12 @@ static bool set_initial_registers(Dwfl_Thread *thread,
 #    error "Please implement set_initial_registers() for your arch"
 #endif
 
+static const Dwfl_Thread_Callbacks thread_cbs = {
+    .next_thread = next_thread,
+    .memory_read = memory_read,
+    .set_initial_registers = set_initial_registers,
+};
+
 #else /* !USE_LIBDW */
 
 void backtraceFree(Backtrace *bt STG_UNUSED) { }



More information about the ghc-commits mailing list