调用 Perl 脚本时跟踪段错误(mytop 工具和类似工具)

调用 Perl 脚本时跟踪段错误(mytop 工具和类似工具)

在我的 gentoo 机器上,mytop 1.9.1 在调用时退出并显示以下输出:

# mytop
Useless use of private variable in void context at /usr/bin/mytop line 1001.
"my" variable $data masks earlier declaration in same scope at /usr/bin/mytop line 1035.
Errore di segmentazione

据我所知,mytop 是一个 Perl 脚本(该工具可以通过命令 vi /usr/bin/mytop 有效读取),所以我尝试更新所有 perl 子依赖项(如上所述)https://wiki.gentoo.org/wiki/Perl),但这并没有解决问题。

然后我也尝试过:

  • 降级到 mytop 1.6-r4(据报告在 portage 上稳定),结果相同:分段错误
  • 安装innotop 1.12.0(这是一个类似的工具),相同的结果:分段错误

由于使用两种不同的工具会出现相同的问题,因此在注释中建议使用特定工具,我通过 gdb 运行 perl,然后启动 mytop 使用 bt 回溯输出,输出如下:

# gdb /usr/bin/perl
GNU gdb (Gentoo 8.1 p1) 8.1
Copyright (C) 2018 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 "i686-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/perl...(no debugging symbols found)...done.
(gdb) run /usr/bin/mytop
Starting program: /usr/bin/perl /usr/bin/mytop
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Useless use of private variable in void context at /usr/bin/mytop line 1001.
"my" variable $data masks earlier declaration in same scope at /usr/bin/mytop line 1035.

Program received signal SIGSEGV, Segmentation fault.
0xb731511c in EVP_CIPHER_CTX_init () from /usr/lib/libcrypto.so.1.0.0
(gdb) bt
#0  0xb731511c in EVP_CIPHER_CTX_init () from /usr/lib/libcrypto.so.1.0.0
#1  0xb75563f6 in my_aes_decrypt () from /usr/lib/libmysqlclient.so.18
#2  0xb75521eb in ?? () from /usr/lib/libmysqlclient.so.18
#3  0xb75527c4 in ?? () from /usr/lib/libmysqlclient.so.18
#4  0xb75529ec in my_search_option_files () from /usr/lib/libmysqlclient.so.18
#5  0xb7553406 in my_load_defaults () from /usr/lib/libmysqlclient.so.18
#6  0xb7512e14 in mysql_read_default_options () from /usr/lib/libmysqlclient.so.18
#7  0xb751a56d in mysql_real_connect () from /usr/lib/libmysqlclient.so.18
#8  0xb78a013c in mysql_dr_connect () from /usr/lib/perl5/vendor_perl/5.24.3/i686-linux/auto/DBD/mysql/mysql.so
#9  0xb78a25ea in ?? () from /usr/lib/perl5/vendor_perl/5.24.3/i686-linux/auto/DBD/mysql/mysql.so
#10 0xb78a26c7 in mysql_db_login () from /usr/lib/perl5/vendor_perl/5.24.3/i686-linux/auto/DBD/mysql/mysql.so
#11 0xb78ade8c in ?? () from /usr/lib/perl5/vendor_perl/5.24.3/i686-linux/auto/DBD/mysql/mysql.so
#12 0xb7e92b04 in Perl_pp_entersub () from /usr/lib/libperl.so.5.24
#13 0xb7e8b043 in Perl_runops_standard () from /usr/lib/libperl.so.5.24
#14 0xb7e12a02 in Perl_call_sv () from /usr/lib/libperl.so.5.24
#15 0xb78cfd13 in XS_DBI_dispatch () from /usr/lib/perl5/vendor_perl/5.24.3/i686-linux/auto/DBI/DBI.so
#16 0xb7e92b04 in Perl_pp_entersub () from /usr/lib/libperl.so.5.24
#17 0xb7e8b043 in Perl_runops_standard () from /usr/lib/libperl.so.5.24
#18 0xb7e1a6cb in perl_run () from /usr/lib/libperl.so.5.24
#19 0x00400a67 in main ()
(gdb) 

以同样的方式调试 innotop 时几乎得到了精确的输出,所以根据 gentoo 论坛上一位朋友的建议,我尝试从头开始重建 perl、mysql 和 openssl(它们似乎都以某种方式涉及段错误),但这并没有'也无济于事。

我认为通过 gdb 的输出进行调试可能是解决问题的,但我真的不知道如何继续(以前从未处理过它)

答案1

如果我下载mytop 的源代码,解压缩 tarball 并测试它的可编译性和 Perl 警告...

perl -cw mytop

我得到:

在 mytop 第 994 行的 void 上下文中无用地使用私有变量。
“my”变量 $data 屏蔽了 mytop 第 1028 行相同范围内的早期声明。
mytop 语法正常

对源代码的检查证实了这些警告。在第 994 行我们有:

分段浏览_第 994 章

粗箭头运算符('=>')应该是数值相等比较运算符('==')。

同一范围内有两个 $data 声明:

分段浏览_第 1020 章
...
分段浏览_第 1028 章

所以源代码是次优的 Perl 5 代码。

我没有 Gentoo,但是,鉴于行号,我怀疑 Gentoo 软件包未能纠正这些问题。 (我有 Ubuntu;Debian/Ubuntu 版本我的顶部不会抛出这些警告,并且与源代码有很大差异。)

尽管有警告,源代码仍然可以编译。因此,源版本引发的警告可能无法解释您所看到的段错误。但我认为你需要向维护者提出这个问题我的顶部对于 Gentoo 来说。

相关内容