From 2f7e7bfa3c6327793cdcdcb5c770b93cecd49bd0 Mon Sep 17 00:00:00 2001
From: Mark Harmstone <mark@harmstone.com>
Date: Tue, 18 Apr 2023 13:55:35 -0600
Subject: [PATCH] Add -gcodeview option

gcc/
	* common.opt (gcodeview): Add new option.
	* gcc.cc (driver_handle_option); Handle OPT_gcodeview.
	* opts.cc (command_handle_option): Similarly.
	* doc/invoke.texi: Add documentation for -gcodeview.
---
 gcc/common.opt      | 4 ++++
 gcc/doc/invoke.texi | 7 +++++++
 gcc/gcc.cc          | 4 ++++
 gcc/opts.cc         | 3 +++
 4 files changed, 18 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index 862c474d3c8f..a28ca13385a2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3318,6 +3318,10 @@ gas-locview-support
 Common Driver Var(dwarf2out_as_locview_support)
 Assume assembler support for view in (DWARF2+) .loc directives.
 
+gcodeview
+Common Driver JoinedOrMissing
+Generate debug information in CodeView format.
+
 gcoff
 Common Driver WarnRemoved
 Does nothing.  Preserved for backward compatibility.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a38547f53e53..aae6bc729dbd 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -509,6 +509,7 @@ Objective-C and Objective-C++ Dialects}.
 -gstrict-dwarf  -gno-strict-dwarf
 -gas-loc-support  -gno-as-loc-support
 -gas-locview-support  -gno-as-locview-support
+-gcodeview @gol
 -gcolumn-info  -gno-column-info  -gdwarf32  -gdwarf64
 -gstatement-frontiers  -gno-statement-frontiers
 -gvariable-location-views  -gno-variable-location-views
@@ -11328,6 +11329,12 @@ at file-scope or global-scope only.
 Produce debugging information in Alpha/VMS debug format (if that is
 supported).  This is the format used by DEBUG on Alpha/VMS systems.
 
+@item -gcodeview
+@opindex gcodeview
+Produce debugging information in CodeView debug format (if that is
+supported).  This is the format used by Microsoft Visual C++ on
+Windows.
+
 @item -g@var{level}
 @itemx -ggdb@var{level}
 @itemx -gvms@var{level}
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 16bb07f2cdc5..39a44fa486da 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -4572,6 +4572,10 @@ driver_handle_option (struct gcc_options *opts,
       do_save = false;
       break;
 
+    case OPT_gcodeview:
+      add_infile ("--pdb=", "*");
+      break;
+
     default:
       /* Various driver options need no special processing at this
 	 point, having been handled in a prescan above or being
diff --git a/gcc/opts.cc b/gcc/opts.cc
index fb2e5388ab19..86b94d62b588 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -3134,6 +3134,9 @@ common_handle_option (struct gcc_options *opts,
                        loc);
       break;
 
+    case OPT_gcodeview:
+      break;
+
     case OPT_gbtf:
       set_debug_level (BTF_DEBUG, false, arg, opts, opts_set, loc);
       /* set the debug level to level 2, but if already at level 3,
-- 
2.39.3

