1

我的应用程序是使用 Electron(v11.1.1) 开发的,它使用 crashpad 来捕获来自每个进程的所有崩溃 dmp 文件。如何从小型转储文件中获取崩溃的进程 ID 或其他元数据

4

1 回答 1

0

我发现我们可以直接从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})
    })
  })
}
于 2021-04-13T16:08:18.463 回答