From b70d97186c0df2469b3fdbee826e41df4a32dc8c Mon Sep 17 00:00:00 2001
From: Mitchel Humpherys <mitchelh@codeaurora.org>
Date: Fri, 4 Apr 2014 12:15:46 -0700
Subject: [PATCH] lrdp-v2: look for vmlinux in autodump dir when missing

It's not uncommon for the vmlinux file to live in the same directory as
the actual RAM dumps. If the users doesn't explicitly specify a vmlinux
image to use, look for it in the autodump dir. If we still can't find it
there, error out as usual.

Change-Id: I702c5584477e26912e0857dbd03b02491bd33c6c
---
 linux-ramdump-parser-v2/ramparse.py | 35 ++++++++++++++++-------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/linux-ramdump-parser-v2/ramparse.py b/linux-ramdump-parser-v2/ramparse.py
index 81adf2c..2708ac7 100755
--- a/linux-ramdump-parser-v2/ramparse.py
+++ b/linux-ramdump-parser-v2/ramparse.py
@@ -105,10 +105,6 @@ if __name__ == '__main__':
         set_outfile(options.outdir + '/' + options.outfile)
 
     print_out_str('Linux Ram Dump Parser Version %s' % VERSION)
-    if options.vmlinux is None:
-        print_out_str("No vmlinux given. I can't proceed!")
-        parser.print_usage()
-        sys.exit(1)
 
     args = ''
     for arg in sys.argv:
@@ -118,6 +114,24 @@ if __name__ == '__main__':
 
     system_type = parser_util.get_system_type()
 
+    if options.autodump is not None:
+        if os.path.exists(options.autodump):
+            print_out_str(
+                'Looking for Ram dumps in {0}'.format(options.autodump))
+        else:
+            print_out_str(
+                'Path {0} does not exist for Ram dumps. Exiting...'.format(options.autodump))
+            sys.exit(1)
+
+    if options.vmlinux is None:
+        autovm = os.path.join(options.autodump, 'vmlinux')
+        if os.path.isfile(autovm):
+            options.vmlinux = autovm
+        else:
+            print_out_str("No vmlinux given or found in autodump dir. I can't proceed!")
+            parser.print_usage()
+            sys.exit(1)
+
     if not os.path.exists(options.vmlinux):
         print_out_str(
             '{0} does not exist. Cannot proceed without vmlinux. Exiting...'.format(options.vmlinux))
@@ -126,8 +140,8 @@ if __name__ == '__main__':
         print_out_str(
             '{0} is not a file. Did you pass the ram file directory instead of the vmlinux?'.format(options.vmlinux))
         sys.exit(1)
-    else:
-        print_out_str('using vmlinx file {0}'.format(options.vmlinux))
+
+    print_out_str('using vmlinux file {0}'.format(options.vmlinux))
 
     if options.ram_addr is None and options.autodump is None:
         print_out_str('Need one of --auto-dump or at least one --ram-file')
@@ -143,15 +157,6 @@ if __name__ == '__main__':
                     'Ram file {0} does not exist. Exiting...'.format(a[0]))
                 sys.exit(1)
 
-    if options.autodump is not None:
-        if os.path.exists(options.autodump):
-            print_out_str(
-                'Looking for Ram dumps in {0}'.format(options.autodump))
-        else:
-            print_out_str(
-                'Path {0} does not exist for Ram dumps. Exiting...'.format(options.autodump))
-            sys.exit(1)
-
     gdb_path = options.gdb
     nm_path = options.nm
 
-- 
GitLab