Skip to content

Commit 4263a7a

Browse files
Revert "Revert "Make the DWARF version configurable.""
1 parent 94317a7 commit 4263a7a

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

Sources/SwiftDriver/Driver/DebugInfo.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
}
4242
}
4343

44-
// The format of debug information.
44+
/// The format of debug information.
4545
public let format: Format
4646

47+
/// The DWARF standard version to be produced.
48+
public let dwarfVersion: UInt8
49+
4750
/// The level of debug information.
4851
public let level: Level?
4952

Sources/SwiftDriver/Driver/Driver.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,17 @@ extension Driver {
23082308
diagnosticsEngine.emit(.error_argument_not_allowed_with(arg: fullNotAllowedOption, other: levelOption.spelling))
23092309
}
23102310

2311-
return DebugInfo(format: format, level: level, shouldVerify: shouldVerify)
2311+
// Determine the DWARF version.
2312+
var dwarfVersion: UInt8 = 4
2313+
if let versionArg = parsedOptions.getLastArgument(.dwarfVersion) {
2314+
if let parsedVersion = UInt8(versionArg.asSingle), parsedVersion >= 2 && parsedVersion <= 5 {
2315+
dwarfVersion = parsedVersion
2316+
} else {
2317+
diagnosticsEngine.emit(.error_invalid_arg_value(arg: .dwarfVersion, value: versionArg.asSingle))
2318+
}
2319+
}
2320+
2321+
return DebugInfo(format: format, dwarfVersion: dwarfVersion, level: level, shouldVerify: shouldVerify)
23122322
}
23132323

23142324
/// Parses the set of `-sanitize={sanitizer}` arguments and returns all the

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ extension Driver {
193193
try commandLine.appendLast(.enablePrivateImports, from: &parsedOptions)
194194
try commandLine.appendLast(in: .g, from: &parsedOptions)
195195
try commandLine.appendLast(.debugInfoFormat, from: &parsedOptions)
196+
try commandLine.appendLast(.dwarfVersion, from: &parsedOptions)
196197
try commandLine.appendLast(.importUnderlyingModule, from: &parsedOptions)
197198
try commandLine.appendLast(.moduleCachePath, from: &parsedOptions)
198199
try commandLine.appendLast(.moduleLinkName, from: &parsedOptions)

Sources/SwiftOptions/Options.swift

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extension Option {
111111
public static let debugForbidTypecheckPrefix: Option = Option("-debug-forbid-typecheck-prefix", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Triggers llvm fatal_error if typechecker tries to typecheck a decl with the provided prefix name")
112112
public static let debugGenericSignatures: Option = Option("-debug-generic-signatures", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Debug generic signatures")
113113
public static let debugInfoFormat: Option = Option("-debug-info-format=", .joined, attributes: [.frontend], helpText: "Specify the debug info format type to either 'dwarf' or 'codeview'")
114+
public static let dwarfVersion: Option = Option("-dwarf-version=", .joined, attributes: [.frontend], helpText: "DWARF debug info version to produce if requested")
114115
public static let debugInfoStoreInvocation: Option = Option("-debug-info-store-invocation", .flag, attributes: [.frontend], helpText: "Emit the compiler invocation in the debug info.")
115116
public static let debugMapping: Option = Option("-debug-mapping", .flag, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
116117
public static let debugMapping_: Option = Option("--debug-mapping", .flag, alias: Option.debugMapping, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
@@ -928,6 +929,7 @@ extension Option {
928929
Option.debugForbidTypecheckPrefix,
929930
Option.debugGenericSignatures,
930931
Option.debugInfoFormat,
932+
Option.dwarfVersion,
931933
Option.debugInfoStoreInvocation,
932934
Option.debugMapping,
933935
Option.debugMapping_,

Tests/SwiftDriverTests/SwiftDriverTests.swift

+13
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,19 @@ final class SwiftDriverTests: XCTestCase {
574574
$1.expect(.error("argument '-debug-info-format=codeview' is not allowed with '-gdwarf-types'"))
575575
}
576576

577+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-dwarf-version=0") {
578+
$1.expect(.error("invalid value '0' in '-dwarf-version="))
579+
}
580+
581+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-dwarf-version=6") {
582+
$1.expect(.error("invalid value '6' in '-dwarf-version="))
583+
}
584+
585+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
586+
let jobs = try driver.planBuild()
587+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
588+
}
589+
577590
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-file-compilation-dir", ".") { driver in
578591
let jobs = try driver.planBuild()
579592
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))

0 commit comments

Comments
 (0)