零星的崩溃,回溯在奇怪的行显示析构函数调用

如何解决零星的崩溃,回溯在奇怪的行显示析构函数调用

我有一个通常可以正常运行的程序,但今天它在启动时崩溃了。之后立即再次运行它就可以了,所以不幸的是我无法给出一个简单的例子。但是,代码看起来像这样:

    #include "Configuration.hpp"
    #include "Program.hpp"
  
    int main()
      {
         ConfigurationReader confReader; // this is line 6,where gdb indicates a 
                                         // segfault in the *destructor* of 
                                         // ConfigurationReader

         confReader.readConf();
         Conf & conf = confReader.getConf();
         Program program(conf);
         program.run();
 
        return 0;
     }

该程序报告了一个段错误,并在gdb中显示了该内核,它表示该段错误发生在上述代码示例的第6行中,位于ConfigurationReader destructor 中。

当然,在这里调用析构函数是没有意义的,因为只有ConfigurationReader的一个实例在周围徘徊,并且在{{ 1}}。即使进行了激进的优化,也无法在main之前对其进行破坏,因为program被赋予了对存在于program内部的内容的引用。

问题:这里发生了(或可能发生了什么)?我没有看到一些未定义的行为吗? confReader的堆栈跟踪是否非常错误?我应该怀疑构建过程出了什么问题吗?

注意:我知道,最好不要让gdb拥有其读入的ConfigurationReader实例,但这可能不是更好的选择问题是关于。请不要仅告诉我不要解决实际问题就回答。

更新:正如约翰在评论中指出的那样,我还应该在此处提供有关Conf的一些信息:

ConfigurationReader::getConf

更新2:我删除了行号以使代码示例可复制,并仅添加了一个注释,指示class ConfigurationReader { private: Conf conf; public: // ... Conf & getConf() { return conf; } } 处显示了被调用的析构函数。

注释2:如我最初所说,很遗憾,我无法提供最小的可复制示例。我无法在玩具程序中重现此问题。我什至无法在 real 程序中重现此问题;这次崩溃只有一次。

解决方法

我实际上能够在这里解决自己的问题,部分是为了回应PaulMcKenzie在评论中提出的问题。为了说明,这是一个玩具程序:

class C { };

class D
{
  public:

    ~D()
    {
      int * p = nullptr;
      int x = *p;
    }
};

class E { };

class F { };

int main(int,char **)
{
  C c;
  D d; // this is line 21
  E e;
  F f;

  return 0;
}

这当然会在main()被破坏时在d的结尾崩溃,因为我故意在破坏器中放置了段错误。

如果我使用调试符号构建它,然后在gdb中运行它,则会得到以下回溯:

#0  0x00005555555546cc in D::~D (this=0x7fffffffde67,__in_chrg=<optimized out>) at program.cpp:10
#1  0x000055555555469a in main () at program.cpp:21

请注意它在堆栈帧1中报告的行号。当然,实际上,第22、23、24、25和26行已经完成,我们可以根据需要通过登录来证明。

显然gdb(或工具中负责将行号与编译器输出相关联的任何部分)已决定,当对象超出范围时,析构函数调用应与最终导致实际执行的代码行相关联它们,即构造对象的线。

因此,大概我的程序中发生的事情是程序已完成,并且崩溃实际上在运行中比指示的发生得晚得多。 (这是它自己的问题,因为program.run()是一个没有退出条件的无限循环。由于ConfigurationReader的析构函数不是可到达的,并且从未运行过,所以它没有无法正常工作。)

,

仅使用您发布的代码无法找出实际的问题是什么。因此,这不是您问题的答案,而是一种使用gdb帮助您自己找到解决方案的方法。不过,要发表评论有点大。

在gdb中运行程序,并在df.sort_values(by="name",key=lambda col: col.str.len()) id name 0 1 a 3 4 on 4 5 lnjjn 5 6 kmlkm 1 2 nkjnkj 8 9 ghkghgj 9 10 ihkjhkj 2 3 oijhoiuh 7 8 kljkljhlh 6 7 molijoijoij 的开始处停止。您可以为此使用 bool notlastColumn = true; protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg,System.Windows.Forms.Keys keyData) { int icolumn = dgvReceDet.CurrentCell.ColumnIndex; int irow = dgvReceDet.CurrentCell.RowIndex; int i = irow; if (keyData == Keys.Enter) { if (icolumn == dgvReceDet.Columns.Count - 1) { //dataGridView1.Rows.Add(); if (notlastColumn == true) { dgvReceDet.CurrentCell = dgvReceDet.Rows[i].Cells[0]; } dgvReceDet.CurrentCell = dgvReceDet[0,irow + 1]; } else { // to pass hidden cell,because will fire exception //exception: Current cell cannot be set to an invisible cell // the do while loop will enable you to pass any hidden cell do { icolumn++; } while (icolumn <= dgvReceDet.Columns.Count - 1 && !dgvReceDet[icolumn,irow].Visible); if (icolumn <= dgvReceDet.Columns.Count - 1) { dgvReceDet.CurrentCell = dgvReceDet[icolumn,irow]; } else { SendKeys.Send("{DOWN}"); SendKeys.Send("{HOME}"); } } return true; } else if (keyData == Keys.Escape) { this.Close(); return true; } //below is for escape key return return base.ProcessCmdKey(ref msg,keyData); } 命令。现在,在程序的最后一条指令处添加一个断点。您可以使用main在gdb中执行此操作。如果未发生问题,则您的程序应到达此断点。在gdb中添加断点时,您会得到一个标识该断点的数字。假设start中的断点是断点2。您可以在gdb中添加“命令”,当命中某个特定的断点时应自动运行该命令。使用b _exit将命令添加到断点2,然后键入_exit(添加commands 2命令),按Enter,然后键入run(最终确定输入的命令)。现在,键入run开始运行程序。

使用此程序,您的程序将在gdb中运行,如果未发生错误,则在遇到最后一条指令时将从头开始再次运行。当错误最终发生时,gdb将停止执行,您可以通过实际进程(而不是仅通过核心转储)来研究问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-