Add printing functions for models to ease debugging
[centaur.git] / src / printing / sections.c
index 6241a733a7b396240c0a6559b54b9672a052beb7..ec0ff439aac42bd412c09bb6bf6c19729caff8ef 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdio.h>
 
-#include <libelf.h>
-#include <gelf.h>
+#include <libelf/libelf.h>
+#include <libelf/gelf.h>
 
 #include <libelfu/libelfu.h>
 #include "printing.h"
 void printSegmentsWithSection(Elf *e, Elf_Scn *scn)
 {
   GElf_Phdr phdr;
+  GElf_Shdr shdr;
   int i;
   size_t n;
 
 
+  if (gelf_getshdr(scn, &shdr) != &shdr) {
+    fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
+    return;
+  }
+
   if (elf_getphdrnum(e, &n)) {
     fprintf(stderr, "elf_getphdrnum() failed: %s\n", elf_errmsg(-1));
     return;
   }
 
   for (i = 0; i < n; i++) {
-    ELFU_BOOL isInSeg;
-
     if (gelf_getphdr(e, i, &phdr) != &phdr) {
       fprintf(stderr, "getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
       continue;
     }
 
-    isInSeg = elfu_segmentContainsSection(&phdr, scn);
-    if (isInSeg == ELFU_TRUE) {
+    if (PHDR_CONTAINS_SCN_IN_MEMORY(&phdr, &shdr)) {
       printf("     %d %s\n", i, segmentTypeStr(phdr.p_type));
     }
   }
@@ -39,7 +42,7 @@ void printSection(Elf *e, Elf_Scn *scn)
 {
   printf("  %jd: %s\n",
           (uintmax_t) elf_ndxscn(scn),
-          elfu_sectionName(e, scn));
+          elfu_eScnName(e, scn));
 }