C_SOURCES := main.c
+all: a.out simple
+
include $(LEVEL)/Makefile.rules
+
+simple:
+ $(MAKE) VPATH=$(VPATH) -f $(SRCDIR)/simple.mk
+
+clean::
+ $(MAKE) -f $(SRCDIR)/simple.mk clean
\ No newline at end of file
from lldbsuite.test.lldbtest import *
import re
+file_index = 0
class JITLoaderGDBTestCase(TestBase):
self.assertEqual(process.GetState(), lldb.eStateExited)
self.assertEqual(process.GetExitStatus(), 0)
+
+ def gen_log_file(self):
+ global file_index
+ ++file_index
+ logfile = os.path.join(
+ self.getBuildDir(),
+ "jitintgdb-" + self.getArchitecture() + "-" +
+ str(file_index) + ".txt")
+
+ def cleanup():
+ if os.path.exists(logfile):
+ os.unlink(logfile)
+ self.addTearDownHook(cleanup)
+ return logfile
+
+ def test_jit_int_default(self):
+ self.expect("settings show plugin.jit-loader.gdb.enable",
+ substrs=["plugin.jit-loader.gdb.enable (enum) = default"])
+
+ def test_jit_int_on(self):
+ """Tests interface with 'enable' settings 'on'"""
+ self.build()
+ exe = self.getBuildArtifact("simple")
+
+ logfile = self.gen_log_file()
+ self.runCmd("log enable -f %s lldb jit" % (logfile))
+ self.runCmd("settings set plugin.jit-loader.gdb.enable on")
+ def cleanup():
+ self.runCmd("log disable lldb")
+ self.runCmd("settings set plugin.jit-loader.gdb.enable default")
+ self.addTearDownHook(cleanup)
+
+ # launch the process
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ self.assertEqual(process.GetState(), lldb.eStateExited)
+ self.assertEqual(process.GetExitStatus(), 0)
+
+ logcontent = ""
+ if os.path.exists(logfile):
+ logcontent = open(logfile).read()
+ self.assertIn(
+ "SetJITBreakpoint setting JIT breakpoint", logcontent)
+
+ def test_jit_int_off(self):
+ """Tests interface with 'enable' settings 'off'"""
+ self.build()
+ exe = self.getBuildArtifact("simple")
+
+ logfile = self.gen_log_file()
+ self.runCmd("log enable -f %s lldb jit" % (logfile))
+ self.runCmd("settings set plugin.jit-loader.gdb.enable off")
+ def cleanup():
+ self.runCmd("log disable lldb")
+ self.runCmd("settings set plugin.jit-loader.gdb.enable default")
+ self.addTearDownHook(cleanup)
+
+ # launch the process
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ self.assertEqual(process.GetState(), lldb.eStateExited)
+ self.assertEqual(process.GetExitStatus(), 0)
+
+ if os.path.exists(logfile):
+ logcontent = open(logfile).read()
+ self.assertNotIn(
+ "SetJITBreakpoint setting JIT breakpoint", logcontent)
+ else:
+ self.assertTrue(false)
--- /dev/null
+#include <inttypes.h>
+
+// GDB JIT interface stub
+struct
+{
+ uint32_t version;
+ uint32_t action_flag;
+ void* relevant_entry;
+ void* first_entry;
+} __jit_debug_descriptor = { 1, 0, 0, 0 };
+
+void __jit_debug_register_code()
+{
+}
+// end GDB JIT interface stub
+
+int main()
+{
+ return 0;
+}
--- /dev/null
+LEVEL = ../../make
+
+C_SOURCES := simple.c
+EXE = simple
+
+include $(LEVEL)/Makefile.rules
namespace {
+enum EnableJITLoaderGDB {
+ eEnableJITLoaderGDBDefault,
+ eEnableJITLoaderGDBOn,
+ eEnableJITLoaderGDBOff,
+};
+
+static constexpr OptionEnumValueElement g_enable_jit_loader_gdb_enumerators[] = {
+ {eEnableJITLoaderGDBDefault, "default", "Enable JIT compilation interface "
+ "for all platforms except macOS"},
+ {eEnableJITLoaderGDBOn, "on", "Enable JIT compilation interface"},
+ {eEnableJITLoaderGDBOff, "off", "Disable JIT compilation interface"}
+ };
+
static constexpr PropertyDefinition g_properties[] = {
- {"enable-jit-breakpoint", OptionValue::eTypeBoolean, true, true, nullptr,
- {}, "Enable breakpoint on __jit_debug_register_code."}};
+ {"enable", OptionValue::eTypeEnum, true,
+ eEnableJITLoaderGDBDefault, nullptr,
+ OptionEnumValues(g_enable_jit_loader_gdb_enumerators),
+ "Enable GDB's JIT compilation interface (default: enabled on "
+ "all platforms except macOS)"}};
-enum { ePropertyEnableJITBreakpoint };
+enum { ePropertyEnable, ePropertyEnableJITBreakpoint };
class PluginProperties : public Properties {
public:
m_collection_sp->Initialize(g_properties);
}
- bool GetEnableJITBreakpoint() const {
- return m_collection_sp->GetPropertyAtIndexAsBoolean(
- nullptr, ePropertyEnableJITBreakpoint,
- g_properties[ePropertyEnableJITBreakpoint].default_uint_value != 0);
+ EnableJITLoaderGDB GetEnable() const {
+ return (EnableJITLoaderGDB)m_collection_sp->GetPropertyAtIndexAsEnumeration(
+ nullptr, ePropertyEnable,
+ g_properties[ePropertyEnable].default_uint_value);
}
};
// Setup the JIT Breakpoint
//------------------------------------------------------------------
void JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list) {
- if (!GetGlobalPluginProperties()->GetEnableJITBreakpoint())
- return;
-
if (DidSetJITBreakpoint())
return;
JITLoaderSP JITLoaderGDB::CreateInstance(Process *process, bool force) {
JITLoaderSP jit_loader_sp;
- ArchSpec arch(process->GetTarget().GetArchitecture());
- if (arch.GetTriple().getVendor() != llvm::Triple::Apple)
+ bool enable;
+ switch (GetGlobalPluginProperties()->GetEnable()) {
+ case EnableJITLoaderGDB::eEnableJITLoaderGDBOn:
+ enable = true;
+ break;
+ case EnableJITLoaderGDB::eEnableJITLoaderGDBOff:
+ enable = false;
+ break;
+ case EnableJITLoaderGDB::eEnableJITLoaderGDBDefault:
+ ArchSpec arch(process->GetTarget().GetArchitecture());
+ enable = arch.GetTriple().getVendor() != llvm::Triple::Apple;
+ break;
+ }
+ if (enable)
jit_loader_sp = std::make_shared<JITLoaderGDB>(process);
return jit_loader_sp;
}