brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 44cbcd1 Raw
106 lines · plain
1#!/bin/sh2 3# Script to process llvm-dwarfdump --debug-line output and create a normalized table4# Usage: process-debug-line.sh <debug-line.txt>5#6# Output format: CU_FILE LINE COLUMN FILE_NAME [additional_info]7# This strips addresses to make rows unique and adds context about which CU and file each line belongs to8 9if [ $# -ne 1 ]; then10    echo "Usage: $0 <debug-line.txt>" >&211    exit 112fi13 14debug_line_file="$1"15 16if [ ! -f "$debug_line_file" ]; then17    echo "Error: File '$debug_line_file' not found" >&218    exit 119fi20 21awk '22BEGIN {23    cu_count = 024    current_cu_file = ""25    # Initialize file names array26    for (i = 0; i < 100; i++) {27        current_file_names[i] = ""28    }29}30 31# Track debug_line sections (new CU)32/^debug_line\[/ {33    cu_count++34    current_cu_file = ""35    # Clear file names array for new CU36    for (i = 0; i < 100; i++) {37        current_file_names[i] = ""38    }39    next40}41 42# Capture file names and their indices43/^file_names\[.*\]:/ {44    # Extract file index using simple string operations45    line_copy = $046    gsub(/file_names\[/, "", line_copy)47    gsub(/\]:.*/, "", line_copy)48    gsub(/[ \t]/, "", line_copy)49    file_index = line_copy50 51    getline  # Read the next line which contains the actual filename52    # Extract filename from name: "filename" format53    if (match($0, /name:[ \t]*"/)) {54        filename = $055        gsub(/.*name:[ \t]*"/, "", filename)56        gsub(/".*/, "", filename)57        current_file_names[file_index] = filename58 59        # Extract basename for main CU file (first .c/.cpp/.cc file we see)60        if (current_cu_file == "" && match(filename, /\.(c|cpp|cc)$/)) {61            cu_filename = filename62            gsub(/.*\//, "", cu_filename)63            current_cu_file = cu_filename64        }65    }66    next67}68 69# Process line table entries70/^0x[0-9a-f]+/ {71    # Parse the line entry: Address Line Column File ISA Discriminator OpIndex Flags72    if (NF >= 4) {73        line = $274        column = $375        file_index = $476 77        # Get the filename for this file index78        filename = current_file_names[file_index]79        if (filename == "") {80            filename = "UNKNOWN_FILE_" file_index81        } else {82            # Extract just the basename83            basename = filename84            gsub(/.*\//, "", basename)85            filename = basename86        }87 88        # Build additional info (flags, etc.)89        additional_info = ""90        for (i = 8; i <= NF; i++) {91            if (additional_info != "") {92                additional_info = additional_info " "93            }94            additional_info = additional_info $i95        }96 97        # Output normalized row: CU_FILE LINE COLUMN FILE_NAME [additional_info]98        printf "%s %s %s %s", current_cu_file, line, column, filename99        if (additional_info != "") {100            printf " %s", additional_info101        }102        printf "\n"103    }104}105' "$debug_line_file"106