commit 2c228c3f38dacffad87611c70e7abac43df0a085
parent 74d8ef602fcccb9e014f812b75178162b6e8508b
Author: Kyle Milz <kyle@0x30.net>
Date:   Mon,  8 Aug 2016 20:32:26 -0600
lib: send along the compiler file name at runtime too
Diffstat:
13 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/lib/runtime.c b/lib/runtime.c
@@ -48,7 +48,7 @@ citrun_node_add(uint8_t node_major, uint8_t node_minor, struct citrun_node *n)
 	if (node_major != citrun_major || node_minor != citrun_minor) {
 		warnx("libcitrun (v%i.%i): Node '%s' has mismatched version (v%i.%i)",
 			citrun_major, citrun_minor,
-			n->file_name, node_major, node_minor);
+			n->abs_file_path, node_major, node_minor);
 		warnx("libcitrun: Try cleaning all object files and reinstrumenting.");
 		return;
 	}
@@ -155,8 +155,10 @@ xwrite(int d, const void *buf, size_t bytes_total)
  * - length of current working directory
  * - current working directory
  * Sent for each instrumented translation unit:
- * - length of source file name
- * - source file name
+ * - length of compiler source file path
+ * - compiler source file path
+ * - length of absolute source file path
+ * - absolute source file path
  * - size of the execution counters
  */
 static void
@@ -197,10 +199,14 @@ send_static(int fd)
 
 	for (w = nodes_head, i = 0; w != NULL; w = w->next, i++) {
 		node = *w;
-		sz = strnlen(node.file_name, PATH_MAX);
 
+		sz = strnlen(node.comp_file_path, PATH_MAX);
 		xwrite(fd, &sz, sizeof(sz));
-		xwrite(fd, node.file_name, sz);
+		xwrite(fd, node.comp_file_path, sz);
+
+		sz = strnlen(node.abs_file_path, PATH_MAX);
+		xwrite(fd, &sz, sizeof(sz));
+		xwrite(fd, node.abs_file_path, sz);
 		xwrite(fd, &node.size, sizeof(node.size));
 	}
 	assert(i == nodes_total);
diff --git a/lib/runtime.h b/lib/runtime.h
@@ -1,10 +1,11 @@
 #include <stdint.h>
-static uint8_t citrun_major =	0;
-static uint8_t citrun_minor =	0;
+static uint8_t citrun_major =	 0;
+static uint8_t citrun_minor =	 0;
 struct citrun_node {
 	uint64_t		*lines_ptr;
 	uint32_t		 size;
-	const char		*file_name;
+	const char		*comp_file_path;
+	const char		*abs_file_path;
 	struct citrun_node	*next;
 	uint64_t		*old_lines;
 	uint32_t		*diffs;
diff --git a/src/inst_action.cc b/src/inst_action.cc
@@ -57,6 +57,7 @@ InstrumentAction::EndSourceFileAction()
 	ss << "static struct citrun_node _citrun_node = {" << std::endl
 		<< "	_citrun_lines," << std::endl
 		<< "	" << num_lines << "," << std::endl
+		<< "	\"" << m_compiler_file_name << "\"," << std::endl
 		<< "	\"" << file_name << "\"," << std::endl;
 	ss << "};" << std::endl;
 	ss << "__attribute__((constructor))" << std::endl
@@ -76,7 +77,7 @@ InstrumentAction::EndSourceFileAction()
 		return;
 	}
 
-	*m_log << m_pfx << "Instrumentation of '" << file_name << "' finished:\n";
+	*m_log << m_pfx << "Instrumentation of '" << m_compiler_file_name << "' finished:\n";
 	*m_log << m_pfx << "    " << num_lines << " Lines of source code\n";
 	*m_log << m_pfx << "    " << header_sz << " Lines of instrumentation header\n";
 
diff --git a/src/inst_action.h b/src/inst_action.h
@@ -28,10 +28,12 @@ private:
 // For each source file provided to the tool, a new FrontendAction is created.
 class InstrumentAction : public clang::ASTFrontendAction {
 public:
-	InstrumentAction(llvm::raw_fd_ostream *log, std::string const &pfx, bool citruninst) :
+	InstrumentAction(llvm::raw_fd_ostream *log, std::string const &pfx,
+			bool citruninst, std::string const &filename) :
 		m_log(log),
 		m_pfx(pfx),
-		m_is_citruninst(citruninst)
+		m_is_citruninst(citruninst),
+		m_compiler_file_name(filename)
 	{};
 
 	void EndSourceFileAction() override;
@@ -43,4 +45,5 @@ private:
 	llvm::raw_fd_ostream	*m_log;
 	std::string		 m_pfx;
 	bool			 m_is_citruninst;
+	std::string		 m_compiler_file_name;
 };
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -295,7 +295,7 @@ CitrunInst::instrument()
 	Tool.setDiagnosticConsumer(log);
 
 	std::unique_ptr<InstrumentActionFactory> f =
-		llvm::make_unique<InstrumentActionFactory>(&m_log, m_pfx, m_is_citruninst);
+		llvm::make_unique<InstrumentActionFactory>(&m_log, m_pfx, m_is_citruninst, m_source_files);
 
 	int ret = Tool.run(f.get());
 	m_log << m_pfx << "Instrumentation " << (ret ? "failed.\n" : "successful.\n");
diff --git a/src/inst_main.h b/src/inst_main.h
@@ -33,18 +33,23 @@ private:
 //
 class InstrumentActionFactory : public clang::tooling::FrontendActionFactory {
 public:
-	InstrumentActionFactory(llvm::raw_fd_ostream *log, std::string const &pfx, bool citruninst) :
+	InstrumentActionFactory(llvm::raw_fd_ostream *log, std::string const &pfx,
+			bool citruninst, std::vector<std::string> const &src_files) :
 		m_log(log),
 		m_pfx(pfx),
-		m_is_citruninst(citruninst)
+		m_is_citruninst(citruninst),
+		m_source_files(src_files),
+		m_i(0)
 	{};
 
 	clang::ASTFrontendAction *create() {
-		return new InstrumentAction(m_log, m_pfx, m_is_citruninst);
+		return new InstrumentAction(m_log, m_pfx, m_is_citruninst, m_source_files[m_i++]);
 	}
 
 private:
 	llvm::raw_fd_ostream	*m_log;
 	std::string		 m_pfx;
 	bool			 m_is_citruninst;
+	std::vector<std::string> m_source_files;
+	int			 m_i;
 };
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -39,7 +39,7 @@ Object arg = 0, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     11 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     4 Function definitions
     1 For statements
diff --git a/t/inst_if.t b/t/inst_if.t
@@ -53,7 +53,7 @@ Object arg = 0, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     18 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     4 Function definitions
     3 If statements
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -52,7 +52,7 @@ Object arg = 1, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     22 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     5 Function definitions
     2 If statements
diff --git a/t/inst_return.t b/t/inst_return.t
@@ -41,7 +41,7 @@ Object arg = 0, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     12 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     2 Function definitions
     4 Return statement values
diff --git a/t/inst_switch.t b/t/inst_switch.t
@@ -47,7 +47,7 @@ Object arg = 0, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     15 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     1 Function definitions
     1 Switch statements
diff --git a/t/inst_two_src_one_cmd.t b/t/inst_two_src_one_cmd.t
@@ -42,7 +42,7 @@ Link detected, adding '' to command line.
 Added clangtool argument ''.
 Instrumentation of '' finished:
     6 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     1 Function definitions
     1 Return statement values
@@ -50,7 +50,7 @@ Instrumentation of '' finished:
 Modified source written successfully.
 Instrumentation of '' finished:
     6 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Function definitions
     1 Return statement values
     3 Total statements
diff --git a/t/inst_while.t b/t/inst_while.t
@@ -37,7 +37,7 @@ Object arg = 0, compile arg = 1
 Added clangtool argument ''.
 Instrumentation of '' finished:
     10 Lines of source code
-    30 Lines of instrumentation header
+    32 Lines of instrumentation header
     1 Functions called ''
     1 Function definitions
     2 While statements