gn: fix debug symbols on Windows

Separate PDB generation from debug/release so that PDB is generated also
for release builds.

Thanks to ivberg@ for the inspiration behind the patch!

Fixes: https://github.com/google/perfetto/issues/631
Change-Id: I3a59fd03f4a9ce4996528239f34cacb4008321df
diff --git a/gn/standalone/BUILD.gn b/gn/standalone/BUILD.gn
index 19c8029..34f9ae1 100644
--- a/gn/standalone/BUILD.gn
+++ b/gn/standalone/BUILD.gn
@@ -319,9 +319,11 @@
     include_dirs = win_msvc_inc_dirs  # Defined in msvc.gni.
   }
 
+  if (is_win) {
+    cflags += [ "/Zi" ]
+  }
   if (is_debug) {
     if (is_win) {
-      cflags += [ "/Z7" ]
       if (is_clang) {
         # Required to see symbols in windbg when building with clang-cl.exe.
         cflags += [ "-gcodeview-ghash" ]
@@ -394,7 +396,7 @@
   }
 }
 
-config("debug_symbols") {
+config("debug_noopt") {
   cflags = []
   if (is_win) {
     cflags = [ "/Od" ]
diff --git a/gn/standalone/BUILDCONFIG.gn b/gn/standalone/BUILDCONFIG.gn
index 3a1119d..05ed548 100644
--- a/gn/standalone/BUILDCONFIG.gn
+++ b/gn/standalone/BUILDCONFIG.gn
@@ -63,7 +63,6 @@
       target_cpu != host_cpu || target_os != host_os || target_triplet != ""
 }
 default_configs = [
-  "//gn/standalone:debug_symbols",
   "//gn/standalone:default",
   "//gn/standalone:extra_warnings",
   "//gn/standalone:no_exceptions",
@@ -74,13 +73,14 @@
   "//gn/standalone:c++17",
 ]
 
-if (is_win) {
-  default_configs += [ "//gn/standalone:win32_lean_and_mean" ]
+if (is_debug) {
+  default_configs += [ "//gn/standalone:debug_noopt" ]
+} else {
+  default_configs += [ "//gn/standalone:release" ]
 }
 
-if (!is_debug) {
-  default_configs -= [ "//gn/standalone:debug_symbols" ]
-  default_configs += [ "//gn/standalone:release" ]
+if (is_win) {
+  default_configs += [ "//gn/standalone:win32_lean_and_mean" ]
 }
 
 set_defaults("source_set") {
diff --git a/gn/standalone/toolchain/BUILD.gn b/gn/standalone/toolchain/BUILD.gn
index e462bd5..236389c 100644
--- a/gn/standalone/toolchain/BUILD.gn
+++ b/gn/standalone/toolchain/BUILD.gn
@@ -490,8 +490,7 @@
     pdbname = "$exename.pdb"
     rspfile = "$exename.rsp"
 
-    command =
-        "$linker /nologo /OUT:$exename ${sys_lib_flags} /PDB:$pdbname @$rspfile"
+    command = "$linker /nologo /OUT:$exename ${sys_lib_flags} /DEBUG /PDB:$pdbname @$rspfile"
     default_output_extension = ".exe"
     default_output_dir = "{{root_out_dir}}"
     outputs = [ exename ]