orccodemem: Mark exec mapping writable if debugging
authorDoug Nazar <nazard@nazar.ca>
Sun, 25 Aug 2019 18:27:23 +0000 (14:27 -0400)
committerSebastian Dröge <slomo@coaxion.net>
Sun, 8 Sep 2019 07:58:54 +0000 (07:58 +0000)
gdb needs the mapping to be writable to set breakpoints.

orc/orccodemem.c

index 58bc6d1..14aadbd 100644 (file)
@@ -200,6 +200,10 @@ orc_code_region_allocate_codemem_dual_map (OrcCodeRegion *region,
   int n;
   char *filename;
   mode_t mask;
+  int exec_prot = PROT_READ | PROT_EXEC;
+
+  if (_orc_compiler_flag_debug)
+    exec_prot |= PROT_WRITE;
 
   filename = malloc (strlen ("/orcexec..") +
       strlen (dir) + 6 + 1);
@@ -224,8 +228,7 @@ orc_code_region_allocate_codemem_dual_map (OrcCodeRegion *region,
     return FALSE;
   }
 
-  region->exec_ptr = mmap (NULL, SIZE, PROT_READ|PROT_EXEC,
-      MAP_SHARED, fd, 0);
+  region->exec_ptr = mmap (NULL, SIZE, exec_prot, MAP_SHARED, fd, 0);
   if (region->exec_ptr == MAP_FAILED) {
     ORC_WARNING("failed to create exec map");
     close (fd);