summaryrefslogtreecommitdiff
path: root/rubystub.c
diff options
context:
space:
mode:
Diffstat (limited to 'rubystub.c')
-rw-r--r--rubystub.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/rubystub.c b/rubystub.c
new file mode 100644
index 0000000000..75aeca1869
--- /dev/null
+++ b/rubystub.c
@@ -0,0 +1,61 @@
+#include "internal.h"
+#include "internal/missing.h"
+#if defined HAVE_DLADDR
+#include <dlfcn.h>
+#endif
+#if defined HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+static void* stub_options(int argc, char **argv);
+#define ruby_options stub_options
+#include <main.c>
+#undef ruby_options
+
+void *
+stub_options(int argc, char **argv)
+{
+ char xflag[] = "-x";
+ char *xargv[4] = {NULL, xflag};
+ char *cmd = argv[0];
+ void *ret;
+
+#if defined __CYGWIN__ || defined _WIN32
+ /* GetCommandLineW should contain the accessible path,
+ * use argv[0] as is */
+#elif defined __linux__
+ {
+ char selfexe[MAXPATHLEN];
+ ssize_t len = readlink("/proc/self/exe", selfexe, sizeof(selfexe));
+ if (len < 0) {
+ perror("readlink(\"/proc/self/exe\")");
+ return NULL;
+ }
+ selfexe[len] = '\0';
+ cmd = selfexe;
+ }
+#elif defined HAVE_DLADDR
+ {
+ Dl_info dli;
+ if (!dladdr(stub_options, &dli)) {
+ perror("dladdr");
+ return NULL;
+ }
+ cmd = (char *)dli.dli_fname;
+ }
+#endif
+
+#ifndef HAVE_SETPROCTITLE
+ /* argc and argv must be the original */
+ ruby_init_setproctitle(argc, argv);
+#endif
+
+ /* set script with -x option */
+ /* xargv[0] is NULL not to re-initialize setproctitle again */
+ xargv[2] = cmd;
+ ret = ruby_options(3, xargv);
+
+ /* set all arguments to ARGV */
+ ruby_set_argv(argc - 1, argv + 1);
+
+ return ret;
+}
c?h=v3_2_10&id=9873af0b1a343dff6d1a8af4c813aa2c9ecc47d5'>`TracePoint.allow_reentry`Koichi Sasada 2021-12-01Rework tracing for blocks running as methodsAlan Wu 2021-11-22Avoid assert failure when NULL EC is expectedAlan Wu 2021-11-09Use valid `ec` for postponed job.Koichi Sasada 2021-10-26[Bug #18264] Fix memory leak in TracePointPeter Zhu 2021-10-20Put YJIT into a single compilation unitAlan Wu 2021-10-20filter out internal events. add comments. reorderAlan Wu 2021-10-20TracePoint supportAlan Wu 2021-09-29Refactor rb_add_event_hook functionS-H-GAMELINKS 2021-09-10include/ruby/debug.h: add doxygen卜部昌平 2021-08-29Support tracing of attr_reader and attr_writerJeremy Evans 2021-08-12Don't cancel JIT-ed code on TracePoint :classTakashi Kokubun 2021-08-12Print JIT cancel when all JIT-ed code is cancelledTakashi Kokubun 2021-08-02Using RBOOL macroS.H 2021-06-17Adjust styles [ci skip]Nobuyoshi Nakada 2021-04-26Document binding behavior for C call/return events for TracePoint/set_trace_funcJeremy Evans 2021-01-19Replace "iff" with "if and only if"Gannon McGibbon 2020-12-22separate rb_ractor_pub from rb_ractor_tKoichi Sasada 2020-12-22TracePoint.new(&block) should be ractor-localKoichi Sasada 2020-09-03Introduce Ractor mechanism for parallel executionKoichi Sasada 2020-08-06[Feature #16513] TracePoint#inspect returns "... file:line" (#3391)Nguyễn Quang Minh 2020-06-29tracepoint_inspect: do not goto into a branch卜部昌平