[Git][ghc/ghc][master] [linker] Adds void printLoadedObjects(void);

Marge Bot gitlab at gitlab.haskell.org
Fri Jun 5 07:18:18 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00
[linker] Adds void printLoadedObjects(void);

This allows us to dump in-memory object code locations for debugging.

Fixup printLoadedObjects prototype

- - - - -


2 changed files:

- rts/Linker.c
- rts/LinkerInternals.h


Changes:

=====================================
rts/Linker.c
=====================================
@@ -873,8 +873,9 @@ SymbolAddr* lookupSymbol_ (SymbolName* lbl)
  * Symbol name only used for diagnostics output.
  */
 SymbolAddr* loadSymbol(SymbolName *lbl, RtsSymbolInfo *pinfo) {
-    IF_DEBUG(linker, debugBelch("lookupSymbol: value of %s is %p\n", lbl,
-                                pinfo->value));
+    IF_DEBUG(linker, debugBelch("lookupSymbol: value of %s is %p, owned by %s\n", lbl,
+                                pinfo->value,
+                                pinfo->owner ? OC_INFORMATIVE_FILENAME(pinfo->owner) : "No owner, probably built-in."));
     ObjectCode* oc = pinfo->owner;
 
     /* Symbol can be found during linking, but hasn't been relocated. Do so now.
@@ -898,6 +899,27 @@ SymbolAddr* loadSymbol(SymbolName *lbl, RtsSymbolInfo *pinfo) {
     return pinfo->value;
 }
 
+void
+printLoadedObjects() {
+    ObjectCode* oc;
+    for (oc = objects; oc; oc = oc->next) {
+        if (oc->sections != NULL) {
+            int i;
+            printf("%s\n", OC_INFORMATIVE_FILENAME(oc));
+            for (i=0; i < oc->n_sections; i++) {
+                if(oc->sections[i].mapped_start != NULL || oc->sections[i].start != NULL) {
+                    printf("\tsec %2d[alloc: %d; kind: %d]: %p - %p; mmaped: %p - %p\n",
+                        i, oc->sections[i].alloc, oc->sections[i].kind,
+                        oc->sections[i].start,
+                        (void*)((uintptr_t)(oc->sections[i].start) + oc->sections[i].size),
+                        oc->sections[i].mapped_start,
+                        (void*)((uintptr_t)(oc->sections[i].mapped_start) + oc->sections[i].mapped_size));
+                }
+            }
+        }
+   }
+}
+
 SymbolAddr* lookupSymbol( SymbolName* lbl )
 {
     ACQUIRE_LOCK(&linker_mutex);
@@ -905,6 +927,7 @@ SymbolAddr* lookupSymbol( SymbolName* lbl )
     if (!r) {
         errorBelch("^^ Could not load '%s', dependency unresolved. "
                    "See top entry above.\n", lbl);
+        IF_DEBUG(linker, printLoadedObjects());
         fflush(stderr);
     }
     RELEASE_LOCK(&linker_mutex);
@@ -1720,6 +1743,9 @@ static HsInt resolveObjs_ (void)
         r = ocTryLoad(oc);
         if (!r)
         {
+            errorBelch("Could not load Object Code %s.\n", OC_INFORMATIVE_FILENAME(oc));
+            IF_DEBUG(linker, printLoadedObjects());
+            fflush(stderr);
             return r;
         }
     }


=====================================
rts/LinkerInternals.h
=====================================
@@ -16,6 +16,8 @@
 #include <sys/mman.h>
 #endif
 
+void printLoadedObjects(void);
+
 #include "BeginPrivate.h"
 
 typedef void SymbolAddr;



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a4098a4bb89b3d30cca26d82b82724913062536

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a4098a4bb89b3d30cca26d82b82724913062536
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200605/61257474/attachment-0001.html>


More information about the ghc-commits mailing list