使用 google_breakpad 分析 Electron 崩溃日志文件

google_breakpad.001.jpeg

前置信息

本机(MacBook Pro)上 Electron 的路径:/usr/local/lib/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron

本机 Electron 数据文件路径:/Users/bianchengsanmei/Library/Application Support/Electron

本地 dump_sysm 路径:/Users/bianchengsanmei/Library/Developer/Xcode/DerivedData/Breakpad-ebqwamwdejfpicartmwratdgdbnc/Build/Products/Release/dump_syms

minidumps_stackwalk 路径 /Users/bianchengsanmei/Public/CODE/google_breakpad/breakpad/src/processor/minidump_stackwalk

构建 google_breakpad

  1. 下载 google_breakpad 源码;
    git clone https://github.com/google/breakpad.git
    
  2. 编译 google_breakpad
    ./configure && make
    
  3. 安装构建的库
    make install
    

生成 Electron 崩溃日志

// main.js
import { app, crashReporter } from "electron";
import * as path from "path";
crashReporter.start({
    uploadToServer: false
});
app.setPath("crashDumps", process.cwd() + "/crash");

这样当渲染进程崩溃后,我们可在安装目录下的 crash 文件夹下找到一份 dump 文件,这就是崩溃日志文件。

需要注意,在 electron@7.1.4 中,是没有 crashDumps 路径的,统一存在 temp 路径下。

解析 dump 文件

直接打开查看 dump 文件,为 16 进制数据:

image.png
需要把该文件转换为可读、可分析的文件,使用工具为 google_breakpad 中的 minidumps_stackwalk:

$ /Users/bianchengsanmei/Public/CODE/google_breakpad/breakpad/src/processor/minidump_stackwalk ./crash/test.dump > ./crash/test.info

打开查看 test.info:

image.png
其中最需要注意的是 Crash reason ,是导致崩溃的原因描述。

学习有趣的知识,结识有趣的朋友,塑造有趣的灵魂!

大家好,我是〖编程三昧〗的作者 隐逸王,我的公众号是『编程三昧』,欢迎关注,希望大家多多指教!

你来,怀揣期望,我有墨香相迎! 你归,无论得失,唯以余韵相赠!

知识与技能并重,内力和外功兼修,理论和实践两手都要抓、两手都要硬!

posted @ 2022-01-18 22:08  隐逸王  阅读(249)  评论(0编辑  收藏  举报