[Flatpak SDK] Crash post-mortem debugging is broken
https://bugs.webkit.org/show_bug.cgi?id=209537

Reviewed by Žan Doberšek.

webkit-flatpak --gdb now properly launches gdb to inspect the last
crash reported to coredumpctl. The -m argument can be used to
select another crash dump.

* flatpak/flatpakutils.py:
(WebkitFlatpak.clean_args):
(WebkitFlatpak.run_in_sandbox):
(WebkitFlatpak.run_gdb):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259038 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 578cde3..1c0a5b4 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,19 @@
+2020-03-26  Philippe Normand  <pnormand@igalia.com>
+
+        [Flatpak SDK] Crash post-mortem debugging is broken
+        https://bugs.webkit.org/show_bug.cgi?id=209537
+
+        Reviewed by Žan Doberšek.
+
+        webkit-flatpak --gdb now properly launches gdb to inspect the last
+        crash reported to coredumpctl. The -m argument can be used to
+        select another crash dump.
+
+        * flatpak/flatpakutils.py:
+        (WebkitFlatpak.clean_args):
+        (WebkitFlatpak.run_in_sandbox):
+        (WebkitFlatpak.run_gdb):
+
 2020-03-25  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win] lld-link: error: /manifestdependency: is not allowed in .drectve
diff --git a/Tools/flatpak/flatpakutils.py b/Tools/flatpak/flatpakutils.py
index e78d5b6..52a0bfb 100644
--- a/Tools/flatpak/flatpakutils.py
+++ b/Tools/flatpak/flatpakutils.py
@@ -472,7 +472,7 @@
         self.platform = self.platform.upper()
 
         if self.gdb is None and '--gdb' in sys.argv:
-            self.gdb = ""
+            self.gdb = True
 
         self.command = "%s %s %s" % (os.path.join(self.sandbox_source_root,
                                                   "Tools/Scripts/run-minibrowser"),
@@ -565,7 +565,9 @@
                 args[0] = command.replace(self.source_root, self.sandbox_source_root)
             if args[0].endswith("build-webkit"):
                 args.append("--prefix=/app")
-        building = os.path.basename(args[0]).startswith("build")
+            building = os.path.basename(args[0]).startswith("build")
+        else:
+            building = False
 
         sandbox_build_path = os.path.join(self.sandbox_source_root, "WebKitBuild", self.build_type)
         # FIXME: Using the `run` flatpak command would be better, but it doesn't
@@ -833,7 +835,9 @@
                 executable, = re.findall(".*Executable: (.*)", stderr)
 
                 if self.gdb:
-                    bargs = ["gdb", executable, "/run/host/%s" % coredump.name] + shlex.split(self.gdb)
+                    bargs = ["gdb", executable, "/run/host/%s" % coredump.name]
+                    if type(self.gdb) != bool:
+                        bargs.extend(shlex.split(self.gdb))
                 elif self.gdb_stack_trace:
                     bargs = ["gdb", '-ex', "thread apply all backtrace", '--batch', executable, "/run/host/%s" % coredump.name]