Created
November 21, 2014 20:57
-
-
Save takehiko/6990850b28d0c93871d6 to your computer and use it in GitHub Desktop.
How many times the value of inner loop's variable is changed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# auto_gdb_kuku.rb | |
# How many times the value of inner loop's variable is changed | |
# by takehikom | |
# ruby auto_gdb_kuku.rb | |
# ruby auto_gdb_kuku.rb | grep 'New value' | |
# ruby auto_gdb_kuku.rb | grep 'New value' | wc -l | |
# Thanks: | |
# http://takuya-1st.hatenablog.jp/entry/20110919/1316426672 | |
# http://futurismo.biz/archives/1286 | |
require "pty" | |
require "expect" | |
imax = (ARGV.shift || 9).to_i | |
jmax = (ARGV.shift || imax).to_i | |
ccode = DATA.read | |
if imax != 9 | |
ccode["i <= 9"] = "i <= #{imax}" | |
end | |
if jmax != 9 | |
ccode["j <= 9"] = "j <= #{jmax}" | |
end | |
puts "% cat kuku.c" | |
print ccode | |
open("kuku.c", "w") { |f_out| | |
f_out.print ccode | |
} | |
cmd = "gcc -g -O0 -o kuku kuku.c" | |
puts "% " + cmd | |
system cmd | |
input_lines = ["b 7", "r"] | |
input_lines << "watch j" | |
input_lines << "c" | |
input_lines += ["c"] * ((jmax + 1) * imax) | |
input_lines << "c" | |
input_lines << "q" | |
cmd = "gdb kuku" | |
puts "% " + cmd | |
PTY.getpty(cmd) do |i, o| | |
o.sync = true | |
$expect_verbose = true | |
until input_lines.empty? | |
i.expect("(gdb)", 1) { |line| | |
o.puts input_lines.shift | |
} | |
end | |
end | |
__END__ | |
#include <stdio.h> | |
int main(void) | |
{ | |
int i = 0, j = 0; | |
for (i = 1; i <= 9; i++) { | |
for (j = 1; j <= 9; j++) { | |
printf("%2d ", i * j); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment