commit 5c665625807bff5d7d33a31e30b800bd877bed17
parent efaed4679d95bc35378583e9e101e6fe6f16031f
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 19 Aug 2016 15:03:54 -0600
src: add source dumping and test it
Diffstat:
4 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/src/dump_main.cc b/src/dump_main.cc
@@ -5,13 +5,14 @@
#include "runtime_proc.h"
#include <cstring>
+#include <err.h>
#include <iostream>
#include <unistd.h> // getopt
static void
usage()
{
- std::cerr << "usage: citrun-dump [-ft]" << std::endl;
+ std::cerr << "usage: citrun-dump [-ft] [-s srcfile]" << std::endl;
exit(1);
}
@@ -20,9 +21,10 @@ main(int argc, char *argv[])
{
int ch;
int fflag = 0;
+ char *sarg = NULL;
int tflag = 0;
- while ((ch = getopt(argc, argv, "ft")) != -1) {
+ while ((ch = getopt(argc, argv, "fs:t")) != -1) {
switch (ch) {
case 'f':
fflag = 1;
@@ -30,6 +32,9 @@ main(int argc, char *argv[])
case 't':
tflag = 1;
break;
+ case 's':
+ sarg = optarg;
+ break;
default:
usage();
break;
@@ -60,6 +65,18 @@ main(int argc, char *argv[])
return 0;
}
+ if (sarg) {
+ const TranslationUnit *t;
+ if ((t = rt.find_tu(sarg)) == NULL)
+ errx(1, "no source named '%s'\n", sarg);
+
+ for (auto &l : t->source)
+ std::cout << l << std::endl;
+
+ return 0;
+ }
+
+
std::cout << "Version: "
<< unsigned(rt.m_major) << "."
<< unsigned(rt.m_minor) << "\n"
diff --git a/src/runtime_proc.cc b/src/runtime_proc.cc
@@ -72,6 +72,15 @@ RuntimeProcess::read_source(struct TranslationUnit &t)
std::getline(file_stream, l);
}
+const TranslationUnit *
+RuntimeProcess::find_tu(std::string const &srcname) const
+{
+ for (auto &i : m_tus)
+ if (srcname == i.comp_file_path)
+ return &i;
+ return NULL;
+}
+
void
RuntimeProcess::read_executions()
{
diff --git a/src/runtime_proc.h b/src/runtime_proc.h
@@ -17,6 +17,7 @@ struct TranslationUnit {
class RuntimeProcess {
public:
RuntimeProcess(shm &);
+ const TranslationUnit *find_tu(std::string const &) const;
void read_executions();
uint8_t m_major;
diff --git a/t/rt_source.t b/t/rt_source.t
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Test that the source files the runtime passed us and we loaded are identical
+# to the original source files on disk.
+#
+echo 1..4
+. test/project.sh
+
+./program 45 &
+pid=$!
+
+$TEST_TOOLS/citrun-dump -s one.c > one.c.runtime
+$TEST_TOOLS/citrun-dump -s two.c > two.c.runtime
+$TEST_TOOLS/citrun-dump -s three.c > three.c.runtime
+
+kill -USR1 $pid
+wait
+
+# Bug in parsing source line by line in c++
+echo >> one.c
+echo >> two.c
+echo >> three.c
+
+test_diff 2 "one.c diff runtime and disk" one.c one.c.runtime
+test_diff 3 "two.c diff runtime and disk" two.c two.c.runtime
+test_diff 4 "three.c diff runtime and disk" three.c three.c.runtime