crashpad - 如何从小型转储文件中获取崩溃的进程 ID
问题描述
我的应用程序是使用 Electron(v11.1.1) 开发的,它使用 crashpad 来捕获来自每个进程的所有崩溃 dmp 文件。如何从小型转储文件中获取崩溃的进程 ID 或其他元数据
解决方案
我发现我们可以直接从dmp文件中解析一些字段
async function parseProcessDetailFromDump(dumpPath) {
return new Promise((ok, fail) => {
const readStream = fs.createReadStream(dumpPath)
let ptype = null
let pid = null
readStream.on("data", (chunk) => {
const text = chunk.toString(`utf-8`)
const lines = text.split(path.sep)
for (const line of lines) {
const found = line.match(/ptype/)
if (found != null && found.length > 0) {
const regPtype = /(?<=ptype[^0-9a-zA-Z]+)[0-9a-zA-Z]+/gu
const regPid = /(?<=pid[^0-9a-zA-Z]+)[0-9a-zA-Z]+/gu
ptype = line.match(regPtype)[0]
pid = line.match(regPid)[0]
}
}
})
readStream.on("error" , () => {
rejects()
})
readStream.on("end", () => {
ok({pid, ptype})
})
})
}
推荐阅读
- javascript - 如何在其他组件中使用 item.key 而不是警报
- angular - 在Angular中将数字四舍五入到最接近的10
- python - 如何使用 Python 仅读取括号/括号内的单词(在 .txt 文件中)
- visual-studio - Android 应用程序从 google play store 下载后立即崩溃
- java - 如何在 Spring 中为 GraphQL 实现异常处理程序
- javascript - 从 Flask API 获取“请求的资源上不存在‘Access-Control-Allow-Origin’标头”
- java - JEE:POI 和 docx 在 IDE 中工作正常,而不是从生成的 WAR
- android - xml 文件中的注释对齐错误
- java - system.input.read() != -1 循环永不停止
- java - 为什么测试需要永远执行