From: gmspro gmspro Date: 2012-06-23T10:34:03+09:00 Subject: Re: How to debug ruby source code using gdb?, can't print array content Ryan Davis wrote in post #1065745: > On Jun 22, 2012, at 00:35 , Sigurd wrote: > >> Ruby has GDB helpers. Take a look at > https://github.com/ruby/ruby/blob/trunk/.gdbinit >> Fo instance rp prints any ruby value. There are other handy helpers as well. > > FYI, this is a help vampire that we recently banned on IRC. He has a > long history of this. No, i have tried this, arr=Array.new(3) arr[0]=5 arr[1]=3 arr[2]=2 These lines should call this function, https://github.com/ruby/ruby/blob/trunk/array.c#L568 according to this, http://www.ruby-doc.org/core-1.9.3/Array.html So I have added couple of lines there to display the values of array. But i didn't get the expected result. else { memfill(RARRAY_PTR(ary), len, val); ARY_SET_LEN(ary, len); int i; int result; result = 0; VALUE *s_arr = RARRAY_PTR(ary); for(i = 0; i < len; i++) { result = LONG2NUM(s_arr[i]); printf("r: %d\n",result); } } I got the result like this: arr=Array.new(3) arr[0]=5 arr[1]=3 arr[2]=2 r: 9 r: 9 r: 9 Why is this result? Why 9? I have followed these to solve it: How to convert ruby array to C array with RubyInline? https://github.com/ruby/ruby/blob/trunk/README.EXT#L131 https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L708 https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L731 Also tried this, result = NUM2LONG(s_arr[i]); result = FIX2NUM(s_arr[i]); result = rb_long2int(s_arr[i]); nothing gets the expected result. Can anyone please help to display/printf the value of ruby array in C? Any reply/answer will be highly appreciated. Thanks in advanced. -- Posted via http://www.ruby-forum.com/.