"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBreakpadSym = parseBreakpadSym;
exports.resolveBreakpadAddress = resolveBreakpadAddress;
function parseBreakpadSym(text) {
    const module = { functions: [] };
    for (const line of text.replace(/\r\n?/g, '\n').split('\n')) {
        const moduleMatch = line.match(/^MODULE\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/);
        if (moduleMatch) {
            module.os = moduleMatch[1];
            module.arch = moduleMatch[2];
            module.buildId = moduleMatch[3];
            module.moduleName = moduleMatch[4].trim();
            continue;
        }
        const funcMatch = line.match(/^FUNC\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(.+)$/);
        if (!funcMatch)
            continue;
        module.functions.push({
            address: BigInt(`0x${funcMatch[1]}`),
            size: BigInt(`0x${funcMatch[2]}`),
            parameterSize: BigInt(`0x${funcMatch[3]}`),
            name: funcMatch[4].trim(),
        });
    }
    module.functions.sort((a, b) => a.address < b.address ? -1 : a.address > b.address ? 1 : 0);
    return module;
}
function resolveBreakpadAddress(module, address) {
    for (const func of module.functions) {
        if (address >= func.address && address < func.address + func.size) {
            return { func, offset: address - func.address };
        }
    }
    return undefined;
}
//# sourceMappingURL=breakpadSymParser.js.map