From 87b2adb6a1fa69b5d0b92a9437dd08ea990ee30d Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 12 Nov 2020 18:49:49 -0500 Subject: [PATCH] With --debug, turn off address space layout randomization. --- bin/verilator | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/verilator b/bin/verilator index 3f921dc02..213d90e34 100755 --- a/bin/verilator +++ b/bin/verilator @@ -76,7 +76,8 @@ if ($opt_gdbbt && !gdb_works()) { my @quoted_sw = map {sh_escape($_)} @Opt_Verilator_Sw; if ($opt_gdb) { # Generic GDB interactive - run (($ENV{VERILATOR_GDB}||"gdb") + run (aslr_off() + .($ENV{VERILATOR_GDB}||"gdb") ." ".verilator_bin() # Note, uncomment to set breakpoints before running: # ." -ex 'break main'" @@ -91,16 +92,22 @@ if ($opt_gdb) { ." -ex 'bt'"); } elsif ($opt_rr) { # Record with rr - run ("rr record ".verilator_bin() + run (aslr_off() + ."rr record ".verilator_bin() ." ".join(' ', @quoted_sw)); } elsif ($opt_gdbbt && $Debug) { # Run under GDB to get gdbbt - run ("gdb" + run (aslr_off() + ."gdb" ." ".verilator_bin() ." --batch --quiet --return-child-result" ." -ex \"run ".join(' ', @quoted_sw)."\"" ." -ex 'set width 0'" ." -ex 'bt' -ex 'quit'"); +} elsif ($Debug) { + # Debug + run(aslr_off() + .verilator_bin()." ".join(' ',@quoted_sw)); } else { # Normal, non gdb run(verilator_bin()." ".join(' ',@quoted_sw)); @@ -165,6 +172,15 @@ sub gdb_works { return $status==0; } +sub aslr_off { + my $ok = `setarch --addr-no-randomize echo ok 2>/dev/null` || ""; + if ($ok =~ /ok/) { + return "setarch --addr-no-randomize "; + } else { + return ""; + } +} + sub run { # Run command, check errors my $command = shift;