File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ fn main() {
77
77
// From encindex.h
78
78
. allowlist_type ( "ruby_preserved_encindex" )
79
79
80
+ // From include/ruby/ruby.h
81
+ . allowlist_function ( "rb_class2name" )
82
+
80
83
// This struct is public to Ruby C extensions
81
84
// From include/ruby/internal/core/rbasic.h
82
85
. allowlist_type ( "RBasic" )
@@ -202,6 +205,7 @@ fn main() {
202
205
// From include/ruby/internal/symbol.h
203
206
. allowlist_function ( "rb_intern" )
204
207
. allowlist_function ( "rb_id2sym" )
208
+ . allowlist_function ( "rb_id2name" )
205
209
. allowlist_function ( "rb_sym2id" )
206
210
. allowlist_function ( "rb_str_intern" )
207
211
Original file line number Diff line number Diff line change @@ -5668,9 +5668,6 @@ fn gen_send_iseq(
5668
5668
} ,
5669
5669
) ;
5670
5670
5671
- //print_str(cb, "calling Ruby func:");
5672
- //print_str(cb, rb_id2name(vm_ci_mid(ci)));
5673
-
5674
5671
// Directly jump to the entry point of the callee
5675
5672
gen_direct_jump (
5676
5673
jit,
@@ -5831,6 +5828,19 @@ fn gen_send_general(
5831
5828
let comptime_recv = jit_peek_at_stack ( jit, ctx, recv_idx as isize ) ;
5832
5829
let comptime_recv_klass = comptime_recv. class_of ( ) ;
5833
5830
5831
+ // Log the name of the method we're calling to
5832
+ #[ cfg( feature = "disasm" ) ]
5833
+ {
5834
+ let class_name = unsafe { cstr_to_rust_string ( rb_class2name ( comptime_recv_klass) ) } ;
5835
+ let method_name = unsafe { cstr_to_rust_string ( rb_id2name ( mid) ) } ;
5836
+ match ( class_name, method_name) {
5837
+ ( Some ( class_name) , Some ( method_name) ) => {
5838
+ asm. comment ( & format ! ( "call to {}#{}" , class_name, method_name) )
5839
+ }
5840
+ _ => { }
5841
+ }
5842
+ }
5843
+
5834
5844
// Guard that the receiver has the same class as the one from compile time
5835
5845
let side_exit = get_side_exit ( jit, ocb, ctx) ;
5836
5846
Original file line number Diff line number Diff line change @@ -564,10 +564,23 @@ pub fn rust_str_to_ruby(str: &str) -> VALUE {
564
564
pub fn rust_str_to_sym ( str : & str ) -> VALUE {
565
565
let c_str = CString :: new ( str) . unwrap ( ) ;
566
566
let c_ptr: * const c_char = c_str. as_ptr ( ) ;
567
-
568
567
unsafe { rb_id2sym ( rb_intern ( c_ptr) ) }
569
568
}
570
569
570
+ /// Produce an owned Rust String from a C char pointer
571
+ #[ cfg( feature = "disasm" ) ]
572
+ pub fn cstr_to_rust_string ( c_char_ptr : * const c_char ) -> Option < String > {
573
+ assert ! ( c_char_ptr != std:: ptr:: null( ) ) ;
574
+
575
+ use std:: ffi:: CStr ;
576
+ let c_str: & CStr = unsafe { CStr :: from_ptr ( c_char_ptr) } ;
577
+
578
+ match c_str. to_str ( ) {
579
+ Ok ( rust_str) => Some ( rust_str. to_string ( ) ) ,
580
+ Err ( _) => None
581
+ }
582
+ }
583
+
571
584
/// A location in Rust code for integrating with debugging facilities defined in C.
572
585
/// Use the [src_loc!] macro to crate an instance.
573
586
pub struct SourceLocation {
Original file line number Diff line number Diff line change @@ -1101,6 +1101,8 @@ extern "C" {
1101
1101
pub fn rb_sym2id ( obj : VALUE ) -> ID ;
1102
1102
pub fn rb_id2sym ( id : ID ) -> VALUE ;
1103
1103
pub fn rb_intern ( name : * const :: std:: os:: raw:: c_char ) -> ID ;
1104
+ pub fn rb_id2name ( id : ID ) -> * const :: std:: os:: raw:: c_char ;
1105
+ pub fn rb_class2name ( klass : VALUE ) -> * const :: std:: os:: raw:: c_char ;
1104
1106
pub fn rb_gc_mark ( obj : VALUE ) ;
1105
1107
pub fn rb_gc_mark_movable ( obj : VALUE ) ;
1106
1108
pub fn rb_gc_location ( obj : VALUE ) -> VALUE ;
You can’t perform that action at this time.
0 commit comments