diff --git a/src/dyld/dyld.cpp b/src/dyld/dyld.cpp
index 1c5e0fb69..6c8607be8 100644
--- a/src/dyld/dyld.cpp
+++ b/src/dyld/dyld.cpp
@@ -20,6 +20,7 @@ along with Darling. If not, see .
#include
#include
#include
+#include
#include
#include
#include
@@ -89,6 +90,9 @@ int main(int argc, char** argv, char** envp)
__prefix_set(path);
unprefixed_argv0 = __prefix_untranslate_path(argv[1], strlen(argv[1]));
}
+
+ if (getenv("DYLD_GDBJIT") != nullptr)
+ Darling::SetupGDBJIT();
if (isELF(argv[1]))
{
diff --git a/src/libdyld/CMakeLists.txt b/src/libdyld/CMakeLists.txt
index cf6236b69..edbcf6223 100644
--- a/src/libdyld/CMakeLists.txt
+++ b/src/libdyld/CMakeLists.txt
@@ -40,6 +40,7 @@ set(dyld_SRCS
environ.c
threads.cpp
VirtualPrefix.cpp
+ gdbjit.cpp
)
#if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
diff --git a/src/libdyld/eh/BufWriter.h b/src/libdyld/eh/BufWriter.h
index 492d0b297..cd3219277 100644
--- a/src/libdyld/eh/BufWriter.h
+++ b/src/libdyld/eh/BufWriter.h
@@ -28,7 +28,7 @@ class BufWriter
public:
BufWriter(void* mem, uintptr_t length);
- template void writeType(T t) { writeBlock(&t, sizeof(T)); }
+ template void writeType(const T& t) { writeBlock(&t, sizeof(T)); }
void writePtr(uintptr_t v) { return writeType(v); }
void writePtrS(intptr_t v) { return writeType(v); }
diff --git a/src/libdyld/gdbjit.cpp b/src/libdyld/gdbjit.cpp
new file mode 100644
index 000000000..b413606cc
--- /dev/null
+++ b/src/libdyld/gdbjit.cpp
@@ -0,0 +1,420 @@
+/*
+This file is part of Darling.
+
+Copyright (C) 2016 Lubos Dolezel
+
+Darling is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Darling is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Darling. If not, see .
+*/
+
+#include
+#include "MachOMgr.h"
+#include "MachOObject.h"
+#include "gdbjit.h"
+#include