Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
debug.h
Go to the documentation of this file.
1 #ifndef RB_DEBUG_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RB_DEBUG_H 1
17 #include "ruby/internal/event.h"
18 #include "ruby/internal/value.h"
19 
21 
22 /* Note: This file contains experimental APIs. */
23 /* APIs can be replaced at Ruby 2.0.1 or later */
24 
25 
52 int rb_profile_frames(int start, int limit, VALUE *buff, int *lines);
53 
71 int rb_profile_thread_frames(VALUE thread, int start, int limit, VALUE *buff, int *lines);
72 
81 
94 
107 
133 
150 
160 
169 
178 
187 
197 
208 
218 typedef VALUE (*rb_debug_inspector_func_t)(const rb_debug_inspector_t *dc, void *data);
219 
228 
239 
249 
259 
269 
282 
295 
296 // A macro to recognize `rb_debug_inspector_frame_depth()` is available or not
297 #define RB_DEBUG_INSPECTOR_FRAME_DEPTH(dc, index) rb_debug_inspector_frame_depth(dc, index)
298 
305 
314 /* duplicated def of include/ruby/ruby.h */
315 #include "ruby/internal/event.h"
316 
329 
341 
356 
372 
423 VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data);
424 
436 
445 
454 
465 typedef struct rb_trace_arg_struct rb_trace_arg_t;
466 
481 
490 
500 
510 
520 
530 
541 
553 
568 
577 
587 
597 
607 
608 
617 /*
618  * Postponed Job API
619  *
620  * This API is designed to be called from contexts where it is not safe to run Ruby
621  * code (e.g. because they do not hold the GVL or because GC is in progress), and
622  * defer a callback to run in a context where it _is_ safe. The primary intended
623  * users of this API is for sampling profilers like the "stackprof" gem; these work
624  * by scheduling the periodic delivery of a SIGPROF signal, and inside the C-level
625  * signal handler, deferring a job to collect a Ruby backtrace when it is next safe
626  * to do so.
627  *
628  * Ruby maintains a small, fixed-size postponed job table. An extension using this
629  * API should first call `rb_postponed_job_preregister` to register a callback
630  * function in this table and obtain a handle of type `rb_postponed_job_handle_t`
631  * to it. Subsequently, the callback can be triggered by calling
632  * `rb_postponed_job_trigger` with that handle, or the `data` associated with the
633  * callback function can be changed by calling `rb_postponed_job_preregister` again.
634  *
635  * Because the postponed job table is quite small (it only has 32 entries on most
636  * common systems), extensions should generally only preregister one or two `func`
637  * values.
638  *
639  * Historically, this API provided two functions `rb_postponed_job_register` and
640  * `rb_postponed_job_register_one`, which claimed to be fully async-signal-safe and
641  * would call back the provided `func` and `data` at an appropriate time. However,
642  * these functions were subject to race conditions which could cause crashes when
643  * racing with Ruby's internal use of them. These two functions are still present,
644  * but are marked as deprecated and have slightly changed semantics:
645  *
646  * * rb_postponed_job_register now works like rb_postponed_job_register_one i.e.
647  * `func` will only be executed at most one time each time Ruby checks for
648  * interrupts, no matter how many times it is registered
649  * * They are also called with the last `data` to be registered, not the first
650  * (which is how rb_postponed_job_register_one previously worked)
651  */
652 
653 
659 typedef void (*rb_postponed_job_func_t)(void *arg);
660 
665 typedef unsigned int rb_postponed_job_handle_t;
666 #define POSTPONED_JOB_HANDLE_INVALID ((rb_postponed_job_handle_t)UINT_MAX)
667 
702 
718 
754  RBIMPL_ATTR_DEPRECATED(("use rb_postponed_job_preregister and rb_postponed_job_trigger"))
755 int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data);
756 
770 int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data);
771 
781 /* undocumented advanced tracing APIs */
782 
783 typedef enum {
784  RUBY_EVENT_HOOK_FLAG_SAFE = 0x01,
785  RUBY_EVENT_HOOK_FLAG_DELETED = 0x02,
786  RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04
787 } rb_event_hook_flag_t;
788 
789 void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag);
790 void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag);
791 
795 
796 #endif /* RUBY_DEBUG_H */
int rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
Queries mysterious "frame"s of the given range.
unsigned int rb_postponed_job_handle_t
The type of a handle returned from rb_postponed_job_preregister and passed to rb_postponed_job_trigge...
Definition: debug.h:665
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg)
Creates a binding object of the point where the trace is at.
Definition: vm_trace.c:981
VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index)
Queries the instruction sequence of the passed context's upper frame.
void rb_postponed_job_trigger(rb_postponed_job_handle_t h)
Triggers a pre-registered job registered with rb_postponed_job_preregister, scheduling it for executi...
Definition: vm_trace.c:1786
VALUE rb_debug_inspector_current_depth(void)
Return current frmae depth.
VALUE rb_tracepoint_enabled_p(VALUE tpval)
Queries if the passed TracePoint is up and running.
Definition: vm_trace.c:1446
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg)
Queries the allocated/deallocated object that the trace represents.
Definition: vm_trace.c:1087
VALUE rb_tracearg_callee_id(rb_trace_arg_t *trace_arg)
Identical to rb_tracearg_method_id(), except it returns callee id like rb_frame_callee().
Definition: vm_trace.c:967
VALUE rb_profile_frame_method_name(VALUE frame)
Queries the name of the method of the passed frame.
VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg)
Queries the class that defines the method that the passed trace is at.
Definition: vm_trace.c:974
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void(*func)(VALUE, void *), void *data)
Creates a tracepoint by registering a callback function for one or more tracepoint events.
Definition: vm_trace.c:1476
rb_trace_arg_t * rb_tracearg_from_tracepoint(VALUE tpval)
Queries the current event of the passed tracepoint.
Definition: vm_trace.c:856
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
Queries the raised exception that the trace represents.
Definition: vm_trace.c:1021
VALUE rb_debug_inspector_frame_depth(const rb_debug_inspector_t *dc, long index)
Queries the depth of the passed context's upper frame.
void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
Identical to rb_add_event_hook(), except its effect is limited to the passed thread.
Definition: vm_trace.c:201
rb_postponed_job_handle_t rb_postponed_job_preregister(unsigned int flags, rb_postponed_job_func_t func, void *data)
Pre-registers a func in Ruby's postponed job preregistration table, returning an opaque handle which ...
Definition: vm_trace.c:1752
VALUE rb_profile_frame_qualified_method_name(VALUE frame)
Identical to rb_profile_frame_method_name(), except it "qualifies" the return value with its defining...
VALUE rb_profile_frame_label(VALUE frame)
Queries human-readable "label" string.
VALUE rb_tracepoint_disable(VALUE tpval)
Stops (disables) an already running instance of TracePoint.
Definition: vm_trace.c:1320
VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg)
Queries the receiver of the point trace is at.
Definition: vm_trace.c:1000
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func)
Identical to rb_remove_event_hook(), except it additionally takes a thread argument.
Definition: vm_trace.c:303
VALUE rb_profile_frame_singleton_method_p(VALUE frame)
Queries if the method of the passed frame is a singleton class.
VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc)
Queries the backtrace object of the context.
VALUE rb_profile_frame_absolute_path(VALUE frame)
Identical to rb_profile_frame_path(), except it tries to expand the returning path.
int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
Identical to rb_postponed_job_register
Definition: vm_trace.c:1816
VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data)
Prepares, executes, then cleans up a debug session.
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg)
Queries the return value that the trace represents.
Definition: vm_trace.c:1006
rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg)
Queries the event of the passed trace.
Definition: vm_trace.c:862
VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, long index)
Queries the current receiver of the passed context's upper frame.
VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg)
Queries the file name of the point where the trace is at.
Definition: vm_trace.c:888
int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data)
Identical to rb_thread_remove_event_hook(), except it additionally takes the data argument.
Definition: vm_trace.c:309
VALUE rb_tracepoint_enable(VALUE tpval)
Starts (enables) trace(s) defined by the passed object.
Definition: vm_trace.c:1194
VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, long index)
Queries the binding of the passed context's upper frame.
int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
Schedules the given func to be called with data when Ruby next checks for interrupts.
Definition: vm_trace.c:1810
VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg)
Queries the method name of the point where the trace is at.
Definition: vm_trace.c:960
VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, long index)
Queries the current class of the passed context's upper frame.
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data)
Identical to rb_remove_event_hook(), except it additionally takes the data argument.
Definition: vm_trace.c:321
VALUE rb_profile_frame_classpath(VALUE frame)
Queries the class path of the method that the passed frame represents.
VALUE rb_profile_frame_path(VALUE frame)
Queries the path of the passed backtrace.
VALUE rb_profile_frame_first_lineno(VALUE frame)
Queries the first line of the method of the passed frame pointer.
VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg)
Queries the line of the point where the trace is at.
Definition: vm_trace.c:882
int rb_profile_thread_frames(VALUE thread, int start, int limit, VALUE *buff, int *lines)
Queries mysterious "frame"s of the given range.
void(* rb_postponed_job_func_t)(void *arg)
Type of postponed jobs.
Definition: debug.h:659
VALUE(* rb_debug_inspector_func_t)(const rb_debug_inspector_t *dc, void *data)
Type of the callback function passed to rb_debug_inspector_open().
Definition: debug.h:218
VALUE rb_profile_frame_base_label(VALUE frame)
Identical to rb_profile_frame_label(), except it does not "qualify" the result.
VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg)
Identical to rb_tracearg_event_flag(), except it returns the name of the event in Ruby's symbol.
Definition: vm_trace.c:868
Defines RBIMPL_ATTR_DEPRECATED.
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]]
Definition: deprecated.h:36
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
Debugging and tracing APIs.
void(* rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
Type of event hooks.
Definition: event.h:120
uint32_t rb_event_flag_t
Represents event(s).
Definition: event.h:108
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Defines RBIMPL_ATTR_RETURNS_NONNULL.
#define RBIMPL_ATTR_RETURNS_NONNULL()
Wraps (or simulates) __attribute__((returns_nonnull))
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40