Bug 857600 - Add a mach command for debugging using gdb; r=gps
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 03 Apr 2013 11:16:03 -0400
changeset 134854 36b8347bbdde31e58f88da1503be09808ec17068
parent 134853 456c148977b3372f7ba4d2684e4d9f20584f3b43
child 134855 ba80ed4de3439a76da257541a634eafd852c2dff
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs857600
milestone23.0a1
Bug 857600 - Add a mach command for debugging using gdb; r=gps
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -419,16 +419,44 @@ class RunProgram(MachCommandBase):
             print(e)
             return 1
         if params:
             args.extend(params)
         return self.run_process(args=args, ensure_exit_code=False,
             pass_thru=True)
 
 @CommandProvider
+class DebugProgram(MachCommandBase):
+    """Debug the compiled binary"""
+
+    @Command('debug', help='Debug the compiled program.', prefix_chars='+')
+    @CommandArgument('params', default=None, nargs='*',
+        help='Command-line arguments to pass to the program.')
+    def debug(self, params):
+        import which
+        try:
+            debugger = which.which('gdb')
+        except Exception as e:
+            print("You don't have gdb in your PATH")
+            print(e)
+            return 1
+        try:
+            args = [debugger, self.get_binary_path('app')]
+        except Exception as e:
+            print("It looks like your program isn't built.",
+                "You can run |mach build| to build it.")
+            print(e)
+            return 1
+        if params:
+            args.insert(1, '--args')
+            args.extend(params)
+        return self.run_process(args=args, ensure_exit_code=False,
+            pass_thru=True)
+
+@CommandProvider
 class Buildsymbols(MachCommandBase):
     """Produce a package of debug symbols suitable for use with Breakpad."""
 
     @Command('buildsymbols', help='Produce a package of Breakpad-format symbols.')
     def buildsymbols(self):
         return self._run_make(directory=".", target='buildsymbols', ensure_exit_code=False)
 
 @CommandProvider