Skip to content

Commit 15ef19f

Browse files
committed
Modify awk script to make it work with older versions
1 parent b1d229a commit 15ef19f

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

bolt/test/Inputs/process-debug-line.sh

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,44 @@ BEGIN {
2323
cu_count = 0
2424
current_cu_file = ""
2525
# Initialize file names array
26-
for (i = 0; i < 100; i++) current_file_names[i] = ""
26+
for (i = 0; i < 100; i++) {
27+
current_file_names[i] = ""
28+
}
2729
}
2830
2931
# Track debug_line sections (new CU)
3032
/^debug_line\[/ {
3133
cu_count++
3234
current_cu_file = ""
3335
# Clear file names array for new CU
34-
for (i = 0; i < 100; i++) current_file_names[i] = ""
36+
for (i = 0; i < 100; i++) {
37+
current_file_names[i] = ""
38+
}
3539
next
3640
}
3741
3842
# Capture file names and their indices
3943
/^file_names\[.*\]:/ {
40-
# Extract file index using more portable regex
41-
if (match($0, /file_names\[[[:space:]]*([0-9]+)\]:/, arr)) {
42-
file_index = arr[1]
43-
} else {
44-
# Fallback parsing
45-
gsub(/file_names\[/, "", $0)
46-
gsub(/\]:.*/, "", $0)
47-
gsub(/[[:space:]]/, "", $0)
48-
file_index = $0
49-
}
44+
# Extract file index using simple string operations
45+
line_copy = $0
46+
gsub(/file_names\[/, "", line_copy)
47+
gsub(/\]:.*/, "", line_copy)
48+
gsub(/[ \t]/, "", line_copy)
49+
file_index = line_copy
5050
5151
getline # Read the next line which contains the actual filename
52-
if (match($0, /name:[[:space:]]*"([^"]*)"/, name_arr)) {
53-
filename = name_arr[1]
52+
# Extract filename from name: "filename" format
53+
if (match($0, /name:[ \t]*"/)) {
54+
filename = $0
55+
gsub(/.*name:[ \t]*"/, "", filename)
56+
gsub(/".*/, "", filename)
5457
current_file_names[file_index] = filename
5558
5659
# Extract basename for main CU file (first .c/.cpp/.cc file we see)
57-
if (current_cu_file == "" && match(filename, /([^\/]*\.(c|cpp|cc))$/, cu_arr)) {
58-
current_cu_file = cu_arr[1]
60+
if (current_cu_file == "" && match(filename, /\.(c|cpp|cc)$/)) {
61+
cu_filename = filename
62+
gsub(/.*\//, "", cu_filename)
63+
current_cu_file = cu_filename
5964
}
6065
}
6166
next
@@ -74,19 +79,18 @@ BEGIN {
7479
if (filename == "") {
7580
filename = "UNKNOWN_FILE_" file_index
7681
} else {
77-
# Extract just the basename using portable method
78-
if (match(filename, /([^\/]*)$/, basename_arr)) {
79-
filename = basename_arr[1]
80-
} else {
81-
# Fallback: use gsub
82-
gsub(/.*\//, "", filename)
83-
}
82+
# Extract just the basename
83+
basename = filename
84+
gsub(/.*\//, "", basename)
85+
filename = basename
8486
}
8587
8688
# Build additional info (flags, etc.)
8789
additional_info = ""
8890
for (i = 8; i <= NF; i++) {
89-
if (additional_info != "") additional_info = additional_info " "
91+
if (additional_info != "") {
92+
additional_info = additional_info " "
93+
}
9094
additional_info = additional_info $i
9195
}
9296

0 commit comments

Comments
 (0)