(gdb) backtrace
#0 pthread_cond_wait@@GLIBC_2.3.2 () at
../nptl/sysdeps/unix/sysv/...:185
#1 0x00007f131f343b03 in
native_cond_wait(mutex=0x7f131fcdf5,
cond=0x7f131fcdf558) at
thread_pthread.c:338
#2 lock_func (timeout_ms=0, mutex=0x7f,
th=0x7f131f8c46) at thread.c:4268
#3 rb_mutex_lock (self=139720114712880)
at thread.c:4342
#4 0x00007f131f31c9ee in
vm_call_cfunc_with_frame (ci=0x0,
reg_cfp=0x7f131f1a7f70,
th=0x7f131f8c46e0)
at vm_insnhelper.c:1380
Slide 15
Slide 15 text
(gdb) backtrace
#0 pthread_cond_wait@@GLIBC_2.3.2 () at
../nptl/sysdeps/unix/sysv/...:185
#1 0x00007f131f343b03 in
native_cond_wait(mutex=0x7f131fcdf5,
cond=0x7f131fcdf558) at
thread_pthread.c:338
#2 lock_func (timeout_ms=0, mutex=0x7f,
th=0x7f131f8c46) at thread.c:4268
#3 rb_mutex_lock (self=139720114712880)
at thread.c:4342
#4 0x00007f131f31c9ee in
vm_call_cfunc_with_frame (ci=0x0,
reg_cfp=0x7f131f1a7f70,
th=0x7f131f8c46e0)
at vm_insnhelper.c:1380
Slide 16
Slide 16 text
(gdb) backtrace
#0 pthread_cond_wait@@GLIBC_2.3.2 () at
../nptl/sysdeps/unix/sysv/...:185
#1 0x00007f131f343b03 in
native_cond_wait(mutex=0x7f131fcdf5,
cond=0x7f131fcdf558) at
thread_pthread.c:338
#2 lock_func (timeout_ms=0, mutex=0x7f,
th=0x7f131f8c46) at thread.c:4268
#3 rb_mutex_lock (self=139720114712880)
at thread.c:4342
#4 0x00007f131f31c9ee in
vm_call_cfunc_with_frame (ci=0x0,
reg_cfp=0x7f131f1a7f70,
th=0x7f131f8c46e0)
at vm_insnhelper.c:1380
Slide 17
Slide 17 text
(gdb) backtrace
#0 pthread_cond_wait@@GLIBC_2.3.2 () at
../nptl/sysdeps/unix/sysv/...:185
#1 0x00007f131f343b03 in
native_cond_wait(mutex=0x7f131fcdf5,
cond=0x7f131fcdf558) at
thread_pthread.c:338
#2 lock_func (timeout_ms=0, mutex=0x7f,
th=0x7f131f8c46) at thread.c:4268
#3 rb_mutex_lock (self=139720114712880)
at thread.c:4342
#4 0x00007f131f31c9ee in
vm_call_cfunc_with_frame (ci=0x0,
reg_cfp=0x7f131f1a7f70,
th=0x7f131f8c46e0)
at vm_insnhelper.c:1380
Slide 18
Slide 18 text
18
(gdb) info threads
Id Target Id Frame
4 Thread 0x7f131f1b4700 (LWP 11)
"ruby-timer-thr" in poll ()
at ../sysdeps/unix/syscall-temp...
3 Thread 0x7f131db8a700 (LWP 12)
“service.rb:6"
pthread_cond_wait@@GLIBC_2.3.2 ()
2 Thread 0x7f131d988700 (LWP 13)
“service.rb:12"
vm_exec_core (th=0x7f131d989058...
* 1 Thread 0x7f131f1aa700 (LWP 10)
"ruby" pthread_cond_wait@@GLIBC...
>>
Slide 19
Slide 19 text
19
(gdb) info threads
Id Target Id Frame
4 Thread 0x7f131f1b4700 (LWP 11)
"ruby-timer-thr" in poll ()
at ../sysdeps/unix/syscall-temp...
3 Thread 0x7f131db8a700 (LWP 12)
“service.rb:6"
pthread_cond_wait@@GLIBC_2.3.2 ()
2 Thread 0x7f131d988700 (LWP 13)
“service.rb:12"
vm_exec_core (th=0x7f131d989058...
* 1 Thread 0x7f131f1aa700 (LWP 10)
"ruby" pthread_cond_wait@@GLIBC...
Slide 20
Slide 20 text
20
(gdb) info threads
Id Target Id Frame
4 Thread 0x7f131f1b4700 (LWP 11)
"ruby-timer-thr" in poll ()
at ../sysdeps/unix/syscall-temp...
3 Thread 0x7f131db8a700 (LWP 12)
“service.rb:6"
pthread_cond_wait@@GLIBC_2.3.2 ()
2 Thread 0x7f131d988700 (LWP 13)
“service.rb:12"
vm_exec_core (th=0x7f131d989058...
* 1 Thread 0x7f131f1aa700 (LWP 10)
"ruby" pthread_cond_wait@@GLIBC...
Slide 21
Slide 21 text
21
(gdb) thread apply all backtrace
Thread 3 (Thread 0x7f131db8a700 (LWP 12)):
#0 pthread_cond_wait@@GLIBC_2.3.2 () at ..
#1 0x00007f131f343b03 in native_cond_wait
#2 lock_func (timeout_ms=0, mutex=0x7f131f
#3 rb_mutex_lock (self=139720114712840) at
#4 0x00007f131f31c9ee in vm_call_cfunc_wit
#5 vm_call_cfunc (th=th@entry=0x7f131fcdda
#6 0x00007f131f32c82e in vm_call_method (t
#7 0x00007f131f32108b in vm_exec_core (th=
#8 0x00007f131f3255d8 in vm_exec (th=0x7f1
#9 0x00007f131f32be0c in invoke_block_from
#10 0x00007f131f32bfa0 in vm_invoke_proc (t
>>
Slide 22
Slide 22 text
22
(gdb) thread apply all backtrace
Thread 3 (Thread 0x7f131db8a700 (LWP 12)):
#0 pthread_cond_wait@@GLIBC_2.3.2 () at ..
#1 0x00007f131f343b03 in native_cond_wait
#2 lock_func (timeout_ms=0, mutex=0x7f131f
#3 rb_mutex_lock (self=139720114712840) at
#4 0x00007f131f31c9ee in vm_call_cfunc_wit
#5 vm_call_cfunc (th=th@entry=0x7f131fcdda
#6 0x00007f131f32c82e in vm_call_method (t
#7 0x00007f131f32108b in vm_exec_core (th=
#8 0x00007f131f3255d8 in vm_exec (th=0x7f1
#9 0x00007f131f32be0c in invoke_block_from
>>
Slide 23
Slide 23 text
23
---Type to continue, or q
Thread 1 (Thread 0x7f131f1aa700 (LWP 10)):
#0 pthread_cond_wait@@GLIBC_2.3.2 () at ..
#1 0x00007f131f343b03 in native_cond_wait
#2 lock_func (timeout_ms=0, mutex=0x7f131f
#3 rb_mutex_lock (self=139720114712880) at
#4 0x00007f131f31c9ee in vm_call_cfunc_wit
#5 vm_call_cfunc (th=th@entry=0x7f131f8c46
#6 0x00007f131f32c82e in vm_call_method (t
#7 0x00007f131f32108b in vm_exec_core (th=
#8 0x00007f131f3255d8 in vm_exec (th=th@en
#9 0x00007f131f33319f in rb_iseq_eval_main
>>
32
$ cat snowflake.rb
p [1,1,2,3].uniq!
p [1,2,3].uniq!
Slide 33
Slide 33 text
33
$ cat snowflake.rb
p [1,1,2,3].uniq!
p [1,2,3].uniq!
$ ruby snowflake.rb
[1, 2, 3]
nil
Slide 34
Slide 34 text
34
$ gdb --args ruby snowflake.rb
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software
Foundation, Inc.
License GPLv3+: GNU GPL version 3 or
later
...
For help, type "help".
Type "apropos word" to search for
commands related to "word".
(gdb)
>>
58
(gdb) list
4157 *
4158 */
4159
4160 static VALUE
4161 rb_ary_uniq_bang(VALUE ary)
4162 {
4163 VALUE hash;
4164 long hash_size;
4165
4166 rb_ary_modify_check(ary);
>>
Slide 59
Slide 59 text
59
(gdb) display ary
1: ary = 93825000955160
>>
Slide 60
Slide 60 text
Eeeeeeek!
https://flic.kr/p/nkwswv
Slide 61
Slide 61 text
61
struct Data
{
int value;
}
Slide 62
Slide 62 text
62
struct Data
{
int value;
}
value
0xC001C0DE
Slide 63
Slide 63 text
63
struct ValuableData
{
Data data;
int priority;
}
value
priority
0xC001C0DE
Slide 64
Slide 64 text
64
struct RBasic {
VALUE flags;
const VALUE klass;
}
flags
klass
0xBAADC0DE
Slide 65
Slide 65 text
struct RArray {
struct RBasic basic;
union {
struct {
long len;
union {
long capa;
VALUE shared;
} aux;
const VALUE *ptr;
} heap;
const VALUE ary[RARRAY_EMBED_LEN_MAX];
} as;
};
65
flags
klass
len
capa
...
78
(gdb) call rb_backtrace()
from :1:in `'
from :1:in `require'
from rubygems.rb:115:in `'
from rubygems.rb:1210:in `'
from rubygems.rb:1210:in `require'
from rubygems/specification.rb:37:in `’
from rubygems/specification.rb:146:in `’
from rubygems/requirement.rb:74:in `default'
from rubygems/requirement.rb:74:in `new'
from rubygems/requirement.rb:125:in `initialize'
from rubygems/requirement.rb:125:in `uniq!'
>>
Slide 79
Slide 79 text
79
(gdb) call rb_backtrace()
from :1:in `'
from :1:in `require'
from rubygems.rb:115:in `'
from rubygems.rb:1210:in `'
from rubygems.rb:1210:in `require'
from rubygems/specification.rb:37:in `’
from rubygems/specification.rb:146:in `’
from rubygems/requirement.rb:74:in `default'
from rubygems/requirement.rb:74:in `new'
from rubygems/requirement.rb:125:in `initialize'
from rubygems/requirement.rb:125:in `uniq!'
>>
Slide 80
Slide 80 text
80
$ ruby --disable-gems snowflake.rb
Slide 81
Slide 81 text
Move It!
https://flic.kr/p/mAst2V
Slide 82
Slide 82 text
82
(gdb) list
4157 *
4158 */
4159
4160 static VALUE
4161 rb_ary_uniq_bang(VALUE ary)
4162 {
4163 VALUE hash;
4164 long hash_size;
4165
4166 rb_ary_modify_check(ary);
>>
Slide 83
Slide 83 text
83
(gdb) next
4166 rb_ary_modify_check(ary);
>>
Slide 84
Slide 84 text
84
(gdb) step
rb_ary_modify_check (ary=9382499768664)
at array.c:312
312 rb_check_frozen(ary);
>>
98
$ gdb --batch -x gdb_script
...
Thread 2 (Thread 0x7f09a71d070 (LWP 108)):
#0 0x00007f09a638e50d in poll () at
../sysdeps/unix/syscall-template.S:81
#1 0x00007f09a735d in timer_thread_sleep
at thread_pthread.c:1442
#2 thread_timer (p=0x7f09a9466018) at
thread_pthread.c:1549
#3 0x00007f09a6d9e0a4 in start_thread
at pthread_create.c:309
Inferior 1 [process 10] will be detached.
$
>>
Slide 99
Slide 99 text
99
$ gem install newrelic_rpm
$ nrdebug 1234
Are you sure you want to attach to PID
1234 ('ruby -e loop do end')}?
Extracting debug information from this
process may cause it to hang, crash,
or otherwise malfunction...
To continue, type 'continue':
Generated 'nrdebug-1234-1447787527.log'