diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-06-01 22:12:27 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-06-01 22:12:27 +0000 |
commit | 6a56f5f15487b36176bee60dac8296e38d7dde08 (patch) | |
tree | 329ae30add336413f454aee9a987f0c46c6bcf43 /utils | |
parent | 814222034b6791579e216e6c78bd98899f6a8bee (diff) | |
download | lldb-6a56f5f15487b36176bee60dac8296e38d7dde08.tar.gz |
Make 'run-until-faulted.py' script more interesting by modifying the example main.c program
to seg fault randomly instead of deterministically.
Example:
[15:10:43] johnny:/Volumes/data/lldb/svn/trunk/utils/test $ clang -g main.c
[15:10:46] johnny:/Volumes/data/lldb/svn/trunk/utils/test $ ./run-until-faulted.py -l $PWD/../../build/Debug/lldb -e a.out
lldb command: /Volumes/data/lldb/svn/trunk/utils/test/../../build/Debug/lldb
executable: a.out
executable options:
(lldb) sending 'file a.out' command...
file a.out
Current executable set to 'a.out' (x86_64).
(lldb) sending 'process launch -- ' command... (iteration: 0)
process launch --
Process 63630 launched: '/Volumes/data/lldb/svn/trunk/utils/test/a.out' (x86_64)
Hello, fault!
val=9
Better luck next time!
[KProcess 63630 exited with status = 0 (0x00000000)
(lldb) sending 'process launch -- ' command... (iteration: 1)
process launch --
Process 63633 launched: '/Volumes/data/lldb/svn/trunk/utils/test/a.out' (x86_64)
[KProcess 63633 exited with status = 0 (0x00000000)
sending 'process launch -- ' command... (iteration: 2)
[KHello, fault!
val=0
Better luck next time!
(lldb) process launch --
Process 63637 launched: '/Volumes/data/lldb/svn/trunk/utils/test/a.out' (x86_64)
Hello, fault!
val=15
Better luck next time!
[KProcess 63637 exited with status = 0 (0x00000000)
(lldb) sending 'process launch -- ' command... (iteration: 3)
process launch --
Process 63640 launched: '/Volumes/data/lldb/svn/trunk/utils/test/a.out' (x86_64)
Hello, fault!
val=2
Better luck next time!
[KProcess 63640 exited with status = 0 (0x00000000)
sending 'process launch -- ' command... (iteration: 4)
(lldb) process launch --
Process 63643 launched: '/Volumes/data/lldb/svn/trunk/utils/test/a.out' (x86_64)
[KProcess 63643 stopped
* thread #1: tid = 0x2d03, 0x0000000100000e93 a.out`main + 99 at main.c:11, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000100000e93 a.out`main + 99 at main.c:11
8 u_int32_t val = (arc4random() & 0x0f);
9 printf("val=%u\n", val);
10 if (val == 0x07) // Lucky 7 :-)
-> 11 printf("Now segfault %d\n", *null_ptr);
12 else
13 printf("Better luck next time!\n");
14 }
(lldb)
* thread #1: tid = 0x2d03, 0x0000000100000e93 a.out`main + 99 at main.c:11, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000100000e93 a.out`main + 99 at main.c:11
8 u_int32_t val = (arc4random() & 0x0f);
9 printf("val=%u\n", val);
10 if (val == 0x07) // Lucky 7 :-)
-> 11 printf("Now segfault %d\n", *null_ptr);
12 else
13 printf("Better luck next time!\n");
14 }
[KHello, fault!
val=7
(lldb)
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@132430 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/test/main.c | 8 | ||||
-rwxr-xr-x | utils/test/run-until-faulted.py | 19 |
2 files changed, 13 insertions, 14 deletions
diff --git a/utils/test/main.c b/utils/test/main.c index 9caf9d8c9..c0fe2f25a 100644 --- a/utils/test/main.c +++ b/utils/test/main.c @@ -1,8 +1,14 @@ #include <stdio.h> +#include <stdlib.h> int main(int argc, const char* argv[]) { int *null_ptr = 0; printf("Hello, fault!\n"); - printf("Now segfault %d\n", *null_ptr); + u_int32_t val = (arc4random() & 0x0f); + printf("val=%u\n", val); + if (val == 0x07) // Lucky 7 :-) + printf("Now segfault %d\n", *null_ptr); + else + printf("Better luck next time!\n"); } diff --git a/utils/test/run-until-faulted.py b/utils/test/run-until-faulted.py index f338d7bd9..93982037a 100755 --- a/utils/test/run-until-faulted.py +++ b/utils/test/run-until-faulted.py @@ -33,31 +33,25 @@ def do_lldb_launch_loop(lldb_command, exe, exe_options): prompt = "\(lldb\) " lldb = pexpect.spawn(lldb_command) # Turn on logging for what lldb sends back. - #lldb.logfile_read = sys.stdout + lldb.logfile_read = sys.stdout lldb.expect(prompt) # Now issue the file command. - print "sending file command...." + print "sending 'file %s' command..." % exe lldb.sendline('file %s' % exe) lldb.expect(prompt) - #print "lldb.buffer:--->", lldb.buffer, "<---" - #print "lldb.before:--->", lldb.before, "<---" - #print "lldb.after:--->", lldb.buffer, "<----" # Loop until it faults.... count = 0 #while True: # count = count + 1 - for i in range(10): + for i in range(100): count = i - print "sending process launch -- %s (iteration: %d)" % (exe_options, count) + print "sending 'process launch -- %s' command... (iteration: %d)" % (exe_options, count) lldb.sendline('process launch -- %s' % exe_options) index = lldb.expect(['Process .* exited with status', 'Process .* stopped', pexpect.TIMEOUT]) - #print "lldb.buffer:--->", lldb.buffer, "<---" - #print "lldb.before:--->", lldb.before, "<----" - #print "lldb.after:--->", lldb.buffer, "<----" if index == 0: # We'll try again later. time.sleep(3) @@ -78,10 +72,9 @@ def main(): sys.path.append(os.path.join(scriptPath, os.pardir, os.pardir, 'test', 'pexpect-2.4')) parser = OptionParser(usage="""\ +%prog [options] Run a program via lldb until it fails. -The lldb executable is located via your PATH env variable, if not specified. - -Usage: %prog [options] +The lldb executable is located via your PATH env variable, if not specified.\ """) parser.add_option('-l', '--lldb-command', type='string', action='store', metavar='LLDB_COMMAND', |