什么会导致 Perl 转储核心?

发布于 2024-07-12 00:28:07 字数 2950 浏览 5 评论 0原文

运行 Perl 脚本时出现此错误的最常见原因是什么:

Memory fault(coredump)

我事先运行了两个 SQL 命令,每个命令仅存储约 1500 行,每行有 6 个字段。 SQL 在脚本中运行良好,所以我认为我没有从中得到错误。 我的一半代码在它收到炸弹并给我这个错误之前运行。

那么导致此错误的最常见原因是什么?我的原因可能是什么?

编辑 - 这是有效的代码

my $i;
$i = 0;    
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
            if ($i == 1)
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 2)
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 10)
            {
                $rowfetch = $DBS->{Row}->GetCharValue("meetdays");
                $rowfetch =~ s/-//gi;
                printline($rowfetch);
                $i++;
            }
            if ($i == 12)
            {
                $rowfetch = $DBS->{Row}->GetCharValue("fullname");
                my ($lname, $fname) = split /,\s*/, $rowfetch;
                $rowfetch = $fname;
                printline($rowfetch);
                $rowfetch = $lname;
                printline($rowfetch);
                $i=$i+2;
            }
            else
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                printline($rowfetch);
                $i++;
            }
        }
        $i=0;   
        printf $fh "\n";
    }

这是无效的代码 - 所做的只是优化 sql fetch 命令

my $i;
$i = 0;      
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
            if ($i == 1)
            {
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 2)
            {
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 10)
            {
                $rowfetch =~ s/-//gi;
                printline($rowfetch);
                $i++;
            }
            if ($i == 12)
            {
                my ($lname, $fname) = split /,\s*/, $rowfetch;
                $rowfetch = $fname;
                printline($rowfetch);
                $rowfetch = $lname;
                printline($rowfetch);
                $i=$i+2;
            }
            else
            {
                printline($rowfetch);
                $i++;
            }
        }
        $i=0;   
        printf $fh "\n";
    }

哦,顺便说一句,在此 while 循环开始执行之前有一个功能正常的 SQL 语句..我只是不想浪费空间。

What are the most common reasons that I would be getting this error from running a Perl script:

Memory fault(coredump)

I am running two SQL commands beforehand that only store ~1500 rows each with 6 fields. The SQL works fine out of the script, so I don't think I'm getting the error from that. And half of my code runs before it takes a bomb and gives me that error.

So what are the most common reasons for this error and what might my reason be?

EDIT - heres the code that works

my $i;
$i = 0;    
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
            if ($i == 1)
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 2)
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 10)
            {
                $rowfetch = $DBS->{Row}->GetCharValue("meetdays");
                $rowfetch =~ s/-//gi;
                printline($rowfetch);
                $i++;
            }
            if ($i == 12)
            {
                $rowfetch = $DBS->{Row}->GetCharValue("fullname");
                my ($lname, $fname) = split /,\s*/, $rowfetch;
                $rowfetch = $fname;
                printline($rowfetch);
                $rowfetch = $lname;
                printline($rowfetch);
                $i=$i+2;
            }
            else
            {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
                printline($rowfetch);
                $i++;
            }
        }
        $i=0;   
        printf $fh "\n";
    }

Heres the code that doesnt work - All that was done was optimizing the sql fetch command

my $i;
$i = 0;      
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
            if ($i == 1)
            {
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 2)
            {
                $rowfetch =~ s/(?=..$)/:/;
                printline($rowfetch);
                $i++;       
            }
            if ($i == 10)
            {
                $rowfetch =~ s/-//gi;
                printline($rowfetch);
                $i++;
            }
            if ($i == 12)
            {
                my ($lname, $fname) = split /,\s*/, $rowfetch;
                $rowfetch = $fname;
                printline($rowfetch);
                $rowfetch = $lname;
                printline($rowfetch);
                $i=$i+2;
            }
            else
            {
                printline($rowfetch);
                $i++;
            }
        }
        $i=0;   
        printf $fh "\n";
    }

Oh and by the way, there is a functioning SQL statement before this while loop goes into action.. I just didnt want to waste space.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

李不 2024-07-19 00:28:07

您正在解决 Perl 解释器或其 C 模块之一中的错误。 如果您的 Perl 二进制文件没有调试符号,请编译一个有调试符号的版本并进行核心转储。 将核心转储加载到 gdb 中并进行回溯。 找到错误,查看它是否在最新版本中,如果不是,则提交修复它的补丁。

You're tickling a bug in the Perl interpreter or one of its C modules. If your Perl binary doesn't have debugging symbols, compile a version that does and make a core dump. Load the core dump into gdb and do a back trace. Find the bug, see if it's in the latest version, and if it isn't, then submit a patch that fixes it.

柠檬色的秋千 2024-07-19 00:28:07

您能否将有问题的脚本简化为显示相同错误的简短脚本? 它在脚本中的哪个位置转储核心?

我的第一个怀疑是您正在使用的模块之一有一个无法正常运行的 XS 组件。 找出脚本崩溃的地方,然后开始调查那里的部分。 不断地削减部分,直到你能想出重现问题的最小脚本。

Can you reduce the problematic script to something short that shows the same error? Where in the script does it dump core?

My first suspect would be one of the modules you are using has an XS component that isn't playing nicely. Find out where the script blows up, then start investigating the parts around there. Keep cutting out parts until you can come up with the smallest script which reproduces the problem.

瘫痪情歌 2024-07-19 00:28:07

在代码更改之前,您在检查 $i 是否是您想要的值后调用了 GetCharValue。 更改后,即使它不是 1,2,10,12,您也可以调用它。 除了这 4 个值之外,是否有可能 $i 的值导致了问题?

Before the code change, you called GetCharValue after checking if $i was as value you wanted. After the change, you call it even if it's not 1,2,10,12. Is it possible that the values for $i other than those 4 is causing the issue?

蓝海似她心 2024-07-19 00:28:07

当针对与系统当前版本不同的共享库版本编译 DBD 驱动程序时,我看到过类似的事件。 (比如有MySQL4,然后升级到MySQL5而不重新编译DBD的情况)

I have seen similar events when the DBD driver is compiled against a different version of the shared library than is currently on the system. (Such as would be the case of having MySQL4, and then upgrading to MySQL5 without recompiling the DBD)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文