Skip to content

Commit

Permalink
Handle absence of valgrind gracefully. Move valgrind from recommended…
Browse files Browse the repository at this point in the history
… to required in debian package
  • Loading branch information
andrew-taylor committed Jun 6, 2019
1 parent 5ff5e1f commit b12e7e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
14 changes: 9 additions & 5 deletions dcc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void __dcc_start(void) __attribute__((constructor)) NO_SANITIZE;
void __dcc_error_exit(void) NO_SANITIZE;
static void __dcc_signal_handler(int signum) NO_SANITIZE;
static void set_signals_default(void) NO_SANITIZE;
static int launch_valgrind(int argc, char *argv[], char *envp[]) NO_SANITIZE;
static void launch_valgrind(int argc, char *argv[], char *envp[]) NO_SANITIZE;
static void setenvd_int(char *n, int v) NO_SANITIZE;
static void setenvd(char *n, char *v) NO_SANITIZE;
static void putenvd(char *s) NO_SANITIZE;
Expand Down Expand Up @@ -193,12 +193,12 @@ static void __dcc_main_sanitizer2(int argc, char *argv[], char *envp[], char *sa

#if __SANITIZER_2__ != VALGRIND
execvp(sanitizer2_executable_pathname, argv);
debug_printf(1, "execvp failed");
exit(__real_main(argc, argv, envp));
debug_printf(1, "execvp %s failed", sanitizer2_executable_pathname);
#else
argv[0] = sanitizer2_executable_pathname;
exit(launch_valgrind(argc, argv, envp));
launch_valgrind(argc, argv, envp);
#endif
exit(1);
}
#endif
#endif
Expand All @@ -223,7 +223,11 @@ static int __dcc_run_sanitizer1(int argc, char *argv[], char *envp[]) {
debug_printf(2, "__real_main returning %d\n", r);
return r;
}
return launch_valgrind(argc, argv, envp);
launch_valgrind(argc, argv, envp);
// if exec fails run program directly
int r = __real_main(argc, argv, envp);
debug_printf(1, "__real_main returning %d\n", r);
return r;
#endif
}

10 changes: 4 additions & 6 deletions dcc_util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

static int launch_valgrind(int argc, char *argv[], char *envp[]) {
static void launch_valgrind(int argc, char *argv[], char *envp[]) {
debug_printf(2, "command=%s\n", "__MONITOR_VALGRIND__");
FILE *valgrind_error_pipe = popen("__MONITOR_VALGRIND__", "w");
int valgrind_error_fd = 2;
Expand All @@ -9,8 +9,8 @@ static int launch_valgrind(int argc, char *argv[], char *envp[]) {
setbuf(valgrind_error_pipe, NULL);
valgrind_error_fd = (int)fileno(valgrind_error_pipe);
} else {
debug_printf(2, "popen failed");
return __real_main(argc, argv, envp);
debug_printf(2, "popen __MONITOR_VALGRIND__ failed");
return;
}
setenvd("DCC_VALGRIND_RUNNING", "1");

Expand Down Expand Up @@ -42,9 +42,7 @@ static int launch_valgrind(int argc, char *argv[], char *envp[]) {
debug_printf(3, "valgrind_argv[%d] = %s\n", i, valgrind_argv[i]);

execvp("/usr/bin/valgrind", valgrind_argv);

debug_printf(2, "execvp failed");
return __real_main(argc, argv, envp);
debug_printf(1, "execvp of /usr/bin/valgrind failed");
}


Expand Down
10 changes: 9 additions & 1 deletion drive_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def explain_error(output_stream, color):
explain_asan_error(loc, output_stream, color)
elif 'DCC_UBSAN_ERROR_KIND' in os.environ:
explain_ubsan_error(loc, output_stream, color)
elif 'DCC_OUTPUT_ERROR' in os.environ:
explain_output_error(loc, output_stream, color)
elif os.environ.get('DCC_SANITIZER', '') == 'MEMORY':
if loc:
print("%s:%d" % (loc.filename, loc.line_number), end=' ', file=output_stream)
Expand Down Expand Up @@ -258,6 +260,12 @@ def explain_signal(signal_number):
else:
return "Execution terminated by signal %s" % signal_number

# Expect output has been supplied as an environment variable
# and the program has been stoped because the output was incorrect

def explain_output_error(loc, output_stream, color):
print("Incorrect output.\n", file=output_stream)

class Location():
def __init__(self, filename, line_number, column='', function='', params='', variable='', frame_number=''):
self.filename = filename
Expand Down Expand Up @@ -368,7 +376,7 @@ def parse_gdb_stack_frame(line):
debug_print(2, 'parse_gdb_stack_frame', m != None, line)
if m:
filename = m.group('filename')
if filename.startswith("/usr/") or filename.startswith("../sysdeps/"):
if filename.startswith("/usr/") or filename.startswith("../sysdeps/") or filename.endswith("libioP.h"):
m = None
if m:
return Location(m.group('filename'), m.group('line_number'), function=m.group('function'), params=m.group('params'), frame_number=m.group('frame_number'))
Expand Down
3 changes: 1 addition & 2 deletions packaging/debian/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Build-Depends: debhelper (>= 9)

Package: dcc
Architecture: all
Depends: python3 (>= 3.6), gdb(>= 7.12), clang(>= 4.0)
Recommends: valgrind(>= 1:3.13), clang(>= 7.0)
Depends: python3 (>= 3.6), gdb(>= 7.12), clang(>= 7.0), valgrind(>= 1:3.13)
Homepage: https://github.com/COMP1511UNSW/dcc
Description: compiler for novice C programmers
dcc compiles C programs using clang and adds explanations suitable
Expand Down

0 comments on commit b12e7e8

Please sign in to comment.