[C++] Add -d flag to make debugging slightly easier
diff --git a/dep.cc b/dep.cc
index 674ac0e..502ec47 100644
--- a/dep.cc
+++ b/dep.cc
@@ -215,6 +215,8 @@
       if (r == primary_rule)
         continue;
       FillDepNodeFromRule(output, r, n);
+      if (n->loc.filename == NULL)
+        n->loc = r->loc;
     }
   }
 };
diff --git a/flags.cc b/flags.cc
index 7a995a5..876e855 100644
--- a/flags.cc
+++ b/flags.cc
@@ -65,6 +65,8 @@
       is_dry_run = true;
     } else if (!strcmp(arg, "-s")) {
       is_silent_mode = true;
+    } else if (!strcmp(arg, "-d")) {
+      enable_debug = true;
     } else if (!strcmp(arg, "--kati_stats")) {
       enable_stat_logs = true;
     } else if (!strcmp(arg, "--warn")) {
diff --git a/flags.h b/flags.h
index 910acbf..a0c6a3b 100644
--- a/flags.h
+++ b/flags.h
@@ -27,6 +27,7 @@
   bool detect_android_echo;
   bool detect_depfiles;
   bool dump_kati_stamp;
+  bool enable_debug;
   bool enable_kati_warnings;
   bool enable_stat_logs;
   bool gen_all_targets;
diff --git a/ninja.cc b/ninja.cc
index 771ddd2..e45abe5 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -483,6 +483,8 @@
 
     string rule_name = "phony";
     bool use_local_pool = false;
+    if (g_flags.enable_debug)
+      *o << "# " << node->loc.filename << ':' << node->loc.lineno << "\n";
     if (!commands.empty()) {
       rule_name = StringPrintf("rule%d", nn->rule_id);
       *o << "rule " << rule_name << "\n";