Можно ли после ошибки интерпретатора Ruby получить обратную трассировку Ruby из corefile? - PullRequest
5 голосов
/ 04 марта 2011

Примечание: Я использую segfault, с которым я столкнулся, когда использовал gem libxml-ruby, чтобы проиллюстрировать вопрос, но с тех пор я исправил свою проблему с этим gem. На самом деле этот вопрос касается просмотра трассировки Ruby (то есть того, что интерпретатор печатает, когда код Ruby не может обработать исключение) из gdb с файлом core, в котором сам интерпретатор сталкивается с ошибкой сегментации.

Я получаю странный segfault при создании документа XML из всех вещей:

/railsroot/vendor/isolated/ruby-1.8/gems/libxml-ruby-1.1.2/lib/libxml/node.rb:123: [BUG] Segmentation fault
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

Aborted

Обновление 1: Этот сегмент также работает под ванильным рубином (MRI).

Я включил corefiles и взглянул на обратную трассировку в gdb (см. Конец вопроса). Я вижу, где происходит сбой интерпретатора, и поиск в Google приводит к многообещающим результатам . В дополнение к обратному следу интерпретатора я хотел бы видеть обратный след в самом коде Ruby (то есть обратный след с точки зрения интерпретатора).

Я надеюсь, что загрузка ядра в gdb позволит мне вызвать некоторую функцию интерпретатора, которая распечатывает стек интерпретируемого кода.

Есть идеи?

Вот ядро ​​и след, для любопытных:

: foo@bar; ulimit -c unlimited
: foo@bar; RAILS_ENV=production ./script/runner script/feeds/batchfeed.rb --config config/feeds/$feed.yml --timer /tmp/$feed.timer --gzip --output /tmp/$feed.xml.gz
/railsroot/vendor/isolated/ruby-1.8/gems/libxml-ruby-1.1.2/lib/libxml/node.rb:123: [BUG] Segmentation fault
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

Aborted
: foo@bar; ls -l core
-rw------- 1 rails rails 145301504 2011-03-04 08:34 core
: foo@bar; gdb `which ruby` core
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) bt
#0  0x00007f041c095a75 in raise () from /lib/libc.so.6
#1  0x00007f041c0995c0 in abort () from /lib/libc.so.6
#2  0x00000000004a3d59 in rb_bug (fmt=0x4bfc60 "Segmentation fault") at error.c:213
#3  0x0000000000477e75 in sigsegv (sig=) at signal.c:633
#4  
#5  0x000000000047ae79 in st_lookup (table=0x7f041867eda0, key=3031, value=0x7fff813ee288) at st.c:250
#6  0x0000000000413ddf in search_method (klass=132608000, id=3031, origin=0x7fff813ee2c8) at eval.c:510
#7  0x0000000000413e67 in rb_get_method_body (klassp=0x7fff813ee318, idp=0x7fff813ee320, noexp=0x7fff813ee32c) at eval.c:531
#8  0x000000000041c66b in rb_call (klass=132608000, recv=132608200, mid=3031, argc=0, argv=0x0, scope=0, self=132610480) at eval.c:6282
#9  0x0000000000427a38 in eval_call (self=132610480, node=0x1df0308) at eval.c:3381
#10 0x000000000041964c in rb_eval (self=132610480, node=0x1df02e0) at eval.c:4015
#11 0x000000000041c42b in rb_call0 (klass=37665480, recv=132610480, id=104367, oid=, argc=0, argv=0x0, body=0x1d42f28, flags=0)
    at eval.c:6211
#12 0x000000000041c733 in rb_call (klass=37665480, recv=132610480, mid=104367, argc=0, argv=0x0, scope=0, self=74960600) at eval.c:6308
#13 0x0000000000427a38 in eval_call (self=74960600, node=0x488f000) at eval.c:3381
#14 0x0000000000419bc4 in rb_eval (self=74960600, node=0x488efd8) at eval.c:3910
#15 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=75649, oid=, argc=0, argv=0x7fff813eead0, body=0x481e5d0, 
    flags=-2126583088) at eval.c:6211
#16 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=75649, argc=2, argv=0x7fff813eeac0, scope=1, self=74960600) at eval.c:6308
#17 0x0000000000427ccf in eval_fcall (self=74960600, node=0x48915d0) at eval.c:3396
#18 0x0000000000426cdb in eval_iter (self=74960600, node=0x4890fb8) at eval.c:3200
#19 0x00000000004279ef in eval_call (self=74960600, node=0x4890f68) at eval.c:3376
#20 0x000000000041aacb in rb_yield_0 (val=132724680, self=74960600, klass=, flags=, avalue=0) at eval.c:5239
#21 0x000000000048fd01 in rb_ary_each (ary=132624640) at array.c:1261
#22 0x000000000041c555 in rb_call0 (klass=21994320, recv=132624640, id=4001, oid=, argc=, 
    argv=, body=0x14f9308, flags=0) at eval.c:6058
#23 0x000000000041c733 in rb_call (klass=21994320, recv=132624640, mid=4001, argc=0, argv=0x0, scope=0, self=74960600) at eval.c:6308
#24 0x0000000000427a38 in eval_call (self=74960600, node=0x48921b0) at eval.c:3381
#25 0x0000000000426cdb in eval_iter (self=74960600, node=0x4890ef0) at eval.c:3200
#26 0x000000000041aacb in rb_yield_0 (val=132612040, self=74960600, klass=, flags=, avalue=0) at eval.c:5239
#27 0x000000000041958c in rb_eval (self=74960600, node=0x488f0f0) at eval.c:3858
#28 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=75649, oid=, argc=0, argv=0x7fff813efb48, body=0x481e5d0, 
    flags=-2126578872) at eval.c:6211
#29 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=75649, argc=1, argv=0x7fff813efb40, scope=1, self=74960600) at eval.c:6308
#30 0x0000000000427ccf in eval_fcall (self=74960600, node=0x4893830) at eval.c:3396
#31 0x0000000000426cdb in eval_iter (self=74960600, node=0x4890e78) at eval.c:3200
#32 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=149753, oid=, argc=0, argv=0x7fff813f0138, body=0x481e710, 
    flags=-2126577352) at eval.c:6211
#33 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=149753, argc=3, argv=0x7fff813f0120, scope=1, self=74960600) at eval.c:6308
#34 0x0000000000427ccf in eval_fcall (self=74960600, node=0x4893cb8) at eval.c:3396
#35 0x00000000004279ef in eval_call (self=74960600, node=0x4893c68) at eval.c:3376
#36 0x000000000041aacb in rb_yield_0 (val=132614040, self=74960600, klass=, flags=, avalue=0) at eval.c:5239
#37 0x000000000041958c in rb_eval (self=74960600, node=0x488f0f0) at eval.c:3858
#38 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=75649, oid=, argc=0, argv=0x7fff813f07e0, body=0x481e5d0, 
    flags=-2126575648) at eval.c:6211
#39 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=75649, argc=2, argv=0x7fff813f07d0, scope=1, self=74960600) at eval.c:6308
#40 0x0000000000427ccf in eval_fcall (self=74960600, node=0x488e7b8) at eval.c:3396
#41 0x000000000042687c in block_pass (self=, node=) at eval.c:9336
#42 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=95641, oid=, argc=0, argv=0x7fff813f0dc8, body=0x481e580, 
    flags=-2126574136) at eval.c:6211
#43 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=95641, argc=1, argv=0x7fff813f0dc0, scope=1, self=74960600) at eval.c:6308
#44 0x0000000000427ccf in eval_fcall (self=74960600, node=0x4895360) at eval.c:3396
#45 0x0000000000426cdb in eval_iter (self=74960600, node=0x4893bc8) at eval.c:3200
#46 0x00000000004279ef in eval_call (self=74960600, node=0x4893b78) at eval.c:3376
#47 0x000000000041aacb in rb_yield_0 (val=132618280, self=74960600, klass=, flags=, avalue=2) at eval.c:5239
#48 0x000000000041aacb in rb_yield_0 (val=70241560, self=74960600, klass=, flags=, avalue=0) at eval.c:5239
#49 0x000000000048fd01 in rb_ary_each (ary=132621000) at array.c:1261
#50 0x000000000041c555 in rb_call0 (klass=21994320, recv=132621000, id=4001, oid=, argc=, 
    argv=, body=0x14f9308, flags=0) at eval.c:6058
#51 0x000000000041c733 in rb_call (klass=21994320, recv=132621000, mid=4001, argc=0, argv=0x0, scope=0, self=74960600) at eval.c:6308
#52 0x0000000000427a38 in eval_call (self=74960600, node=0x48906d0) at eval.c:3381
#53 0x0000000000426cdb in eval_iter (self=74960600, node=0x488ffc8) at eval.c:3200
#54 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=149745, oid=, argc=0, argv=0x7fff813f1e18, body=0x481e6c0, 
    flags=-2126569960) at eval.c:6211
---Type  to continue, or q  to quit---
#55 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=149745, argc=1, argv=0x7fff813f1e10, scope=1, self=74960600) at eval.c:6308
#56 0x0000000000427ccf in eval_fcall (self=74960600, node=0x4898470) at eval.c:3396
#57 0x0000000000426cdb in eval_iter (self=74960600, node=0x4893ad8) at eval.c:3200
#58 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=149737, oid=, argc=0, argv=0x7fff813f2400, body=0x481e760, 
    flags=-2126568448) at eval.c:6211
#59 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=149737, argc=2, argv=0x7fff813f23f0, scope=1, self=74960600) at eval.c:6308
#60 0x0000000000427ccf in eval_fcall (self=74960600, node=0x48988a8) at eval.c:3396
#61 0x000000000041958c in rb_eval (self=74960600, node=0x4898858) at eval.c:3858
#62 0x000000000041c42b in rb_call0 (klass=75623080, recv=74960600, id=149633, oid=, argc=0, argv=0x7fff813f27f8, body=0x481e7b0, 
    flags=-2126567432) at eval.c:6211
#63 0x000000000041c733 in rb_call (klass=75623080, recv=74960600, mid=149633, argc=1, argv=0x7fff813f27f0, scope=3, self=6) at eval.c:6308
#64 0x00000000004191ec in rb_call_super (argc=, argv=) at eval.c:6476
#65 0x00000000004193b5 in eval_super (self=0, node=0x483ac08) at eval.c:3441
#66 0x00000000004267cc in block_pass (self=, node=) at eval.c:9316
#67 0x00000000004272f3 in eval_ensure (self=74960600, node=0x483aa28) at eval.c:3291
#68 0x000000000041aacb in rb_yield_0 (val=132629640, self=74960600, klass=, flags=, avalue=2) at eval.c:5239
#69 0x000000000041b416 in proc_invoke (proc=, args=, self=, klass=74960440) at eval.c:9038
#70 0x000000000041bf12 in rb_call0 (klass=74960440, recv=74960600, id=149633, oid=, argc=, 
    argv=, body=0x477cd70, flags=0) at eval.c:6092
#71 0x000000000041c733 in rb_call (klass=74960440, recv=74960600, mid=149633, argc=1, argv=0x7fff813f3340, scope=0, self=74975160) at eval.c:6308
#72 0x0000000000427a38 in eval_call (self=74975160, node=0x48b6b50) at eval.c:3381
#73 0x000000000041aacb in rb_yield_0 (val=135232920, self=74975160, klass=, flags=, avalue=0) at eval.c:5239
#74 0x000000000041aacb in rb_yield_0 (val=138467880, self=74975160, klass=, flags=, avalue=0) at eval.c:5239
#75 0x000000000041aacb in rb_yield_0 (val=138467880, self=74975160, klass=, flags=, avalue=0) at eval.c:5239
#76 0x000000000048fd01 in rb_ary_each (ary=138491800) at array.c:1261
#77 0x000000000041c555 in rb_call0 (klass=21994320, recv=138491800, id=4001, oid=, argc=, 
    argv=, body=0x14f9308, flags=0) at eval.c:6058
#78 0x000000000041c733 in rb_call (klass=21994320, recv=138491800, mid=4001, argc=0, argv=0x0, scope=0, self=74975160) at eval.c:6308
#79 0x0000000000427a38 in eval_call (self=74975160, node=0x48bb808) at eval.c:3381
#80 0x0000000000426cdb in eval_iter (self=74975160, node=0x48bb0b0) at eval.c:3200
#81 0x000000000041958c in rb_eval (self=74975160, node=0x48bb038) at eval.c:3858
#82 0x00000000004261b7 in eval_while (self=74975160, node=0x48bab88) at eval.c:3118
#83 0x000000000041c42b in rb_call0 (klass=75513520, recv=74975160, id=149601, oid=, argc=0, argv=0x7fff813f4438, body=0x47fd038, 
    flags=-2126560200) at eval.c:6211
#84 0x000000000041c733 in rb_call (klass=75513520, recv=74975160, mid=149601, argc=1, argv=0x7fff813f4430, scope=1, self=74975160) at eval.c:6308
#85 0x0000000000427ccf in eval_fcall (self=74975160, node=0x48b9788) at eval.c:3396
#86 0x0000000000426cdb in eval_iter (self=74975160, node=0x48b7578) at eval.c:3200
#87 0x000000000041c42b in rb_call0 (klass=75513520, recv=74975160, id=149617, oid=, argc=0, argv=0x7fff813f4a20, body=0x47fcf98, 
    flags=-2126558688) at eval.c:6211
#88 0x000000000041c733 in rb_call (klass=75513520, recv=74975160, mid=149617, argc=0, argv=0x7fff813f4a20, scope=3, self=6) at eval.c:6308
#89 0x00000000004191ec in rb_call_super (argc=, argv=) at eval.c:6476
#90 0x00000000004193b5 in eval_super (self=0, node=0x483ac08) at eval.c:3441
#91 0x00000000004266c1 in block_pass (self=, node=) at eval.c:9363
#92 0x00000000004272f3 in eval_ensure (self=74975160, node=0x483aa28) at eval.c:3291
#93 0x000000000041aacb in rb_yield_0 (val=74960080, self=74975160, klass=, flags=, avalue=2) at eval.c:5239
#94 0x000000000041b416 in proc_invoke (proc=, args=, self=, klass=74972880) at eval.c:9038
#95 0x000000000041bf12 in rb_call0 (klass=74972880, recv=74975160, id=149617, oid=, argc=, 
    argv=, body=0x477fe08, flags=0) at eval.c:6092
#96 0x000000000041c733 in rb_call (klass=74972880, recv=74975160, mid=149617, argc=0, argv=0x0, scope=1, self=74975160) at eval.c:6308
#97 0x0000000000427ccf in eval_fcall (self=74975160, node=0x48b6ab0) at eval.c:3396
#98 0x0000000000426cdb in eval_iter (self=74975160, node=0x48b6ad8) at eval.c:3200
#99 0x000000000041aacb in rb_yield_0 (val=74960600, self=74975160, klass=, flags=, avalue=0) at eval.c:5239
#100 0x000000000041958c in rb_eval (self=75623080, node=0x48a6c50) at eval.c:3858
#101 0x000000000041c42b in rb_call0 (klass=75623960, recv=75623080, id=149625, oid=, argc=0, argv=0x7fff813f5d70, body=0x481ed00, 
    flags=-2126553744) at eval.c:6211
#102 0x000000000041c733 in rb_call (klass=75623960, recv=75623080, mid=149625, argc=2, argv=0x7fff813f5d60, scope=0, self=74975160) at eval.c:6308
#103 0x0000000000427a38 in eval_call (self=74975160, node=0x48b6d80) at eval.c:3381
#104 0x0000000000426cdb in eval_iter (self=74975160, node=0x48b6a38) at eval.c:3200
#105 0x000000000041c42b in rb_call0 (klass=75513520, recv=74975160, id=148761, oid=, argc=0, argv=0x7fff813f6338, body=0x47fcf48, 
    flags=-2126552264) at eval.c:6211
#106 0x000000000041c733 in rb_call (klass=75513520, recv=74975160, mid=148761, argc=1, argv=0x7fff813f6330, scope=0, self=22049440) at eval.c:6308
#107 0x0000000000427a38 in eval_call (self=22049440, node=0x492d138) at eval.c:3381
#108 0x00000000004272f3 in eval_ensure (self=22049440, node=0x492cbc0) at eval.c:3291
#109 0x000000000041958c in rb_eval (self=22049440, node=0x492cb48) at eval.c:3858
---Type  to continue, or q  to quit---
#110 0x000000000042b27c in eval (self=, src=, scope=4, file=0x4a4426 "(eval)", line=)
    at eval.c:6711
#111 0x000000000042b69c in rb_f_eval (argc=, argv=, self=22049440) at eval.c:6832
#112 0x000000000041c555 in rb_call0 (klass=22059320, recv=22049440, id=4097, oid=, argc=, 
    argv=, body=0x1505e00, flags=0) at eval.c:6058
#113 0x000000000041c733 in rb_call (klass=22059320, recv=22049440, mid=4097, argc=1, argv=0x7fff813f6b00, scope=1, self=22049440) at eval.c:6308
#114 0x0000000000427ccf in eval_fcall (self=22049440, node=0x1b17be0) at eval.c:3396
#115 0x000000000042a2f6 in rb_load (fname=28463080, wrap=) at eval.c:7199
#116 0x000000000042aa9a in rb_require_safe (fname=21909440, safe=) at eval.c:7573
#117 0x000000000041c555 in rb_call0 (klass=22059360, recv=22049440, id=13521, oid=, argc=, 
    argv=, body=0x14e92f0, flags=0) at eval.c:6058
#118 0x000000000041c733 in rb_call (klass=22059360, recv=22049440, mid=13521, argc=1, argv=0x7fff813f7200, scope=1, self=22049440) at eval.c:6308
#119 0x0000000000427ccf in eval_fcall (self=22049440, node=0x18c1918) at eval.c:3396
#120 0x000000000042710c in eval_rescue (self=22049440, node=0x18c1300) at eval.c:3237
#121 0x0000000000419c43 in rb_eval (self=22049440, node=0x18c1300) at eval.c:3991
#122 0x000000000041c42b in rb_call0 (klass=22059320, recv=22049440, id=10105, oid=, argc=0, argv=0x7fff813f7728, body=0x18c0e28, 
    flags=-2126547160) at eval.c:6211
#123 0x000000000041c733 in rb_call (klass=22059320, recv=22049440, mid=10105, argc=1, argv=0x7fff813f7720, scope=1, self=22049440) at eval.c:6308
#124 0x0000000000427ccf in eval_fcall (self=22049440, node=0x14e4f70) at eval.c:3396
#125 0x0000000000429c69 in ruby_exec_internal () at eval.c:1685
#126 0x0000000000429cb5 in ruby_exec () at eval.c:1705
#127 0x0000000000429ce5 in ruby_run () at eval.c:1715
#128 0x00000000004106c1 in main (argc=10, argv=0x7fff813f7a28, envp=) at main.c:48

Ответы [ 2 ]

2 голосов
/ 07 сентября 2011

Когда вы видите что-то вроде этого: rb_call (klass = 37665480, recv = 132610480, mid = 104367, ...

Вы можете понять, что делает код ruby. У меня есть статья в блоге начто:

http://seclib.blogspot.com/2011/08/inspect-ruby-process-from-gdb.html

1 голос
/ 10 июня 2011

Похоже, вы используете старую версию libxml-ruby (1.1.2).Попробуйте обновить;segfault, возможно, был исправлен: https://rubygems.org/gems/libxml-ruby/versions

Обратите внимание, что это может включать обновление некоторых других драгоценных камней.

...