Commit cfa489d2 authored by Thibault Saunier's avatar Thibault Saunier Committed by Alexandru Băluț

flatpak: Add a way to easily run gdb inside the sandbox

parent e8a29d05
Pipeline #26879 passed with stages
in 75 minutes and 23 seconds
......@@ -22,6 +22,7 @@ import configparser
import json
import os
import re
import shlex
import shutil
import subprocess
import sys
......@@ -400,6 +401,9 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
finally:
devnull.close()
self.coredumpgdb = None
self.coredumpctl_matches = ""
@staticmethod
def check_flatpak(verbose=True):
for app, required_version in FLATPAK_REQ:
......@@ -451,6 +455,9 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
"org.gnome.Sdk", sdk_branch, self.sdk_repo, "x86_64")
self.packs = [self.runtime, self.locale, self.sdk]
if self.coredumpgdb is None and "--coredumpgdb" in sys.argv or "-gdb" in sys.argv:
self.coredumpgdb = ""
if self.bundle:
self.build = True
......@@ -479,6 +486,10 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
Colors.FAIL, __file__, Colors.ENDC)
exit(1)
if self.coredumpgdb is not None:
self.run_gdb()
return
if self.check:
self.run_in_sandbox("gst-validate-launcher",
os.path.join(
......@@ -565,6 +576,29 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
self.run_in_sandbox(*ninja_args, exit_on_failure=True,
cwd=self.topdir)
def run_gdb(self):
if not shutil.which("coredumpctl"):
Console.message("%s'coredumpctl' not present on the system, can't run.%s"
% (Colors.WARNING, Colors.ENDC))
sys.exit(1)
# We need access to the host from the sandbox to run.
with tempfile.NamedTemporaryFile() as coredump:
with tempfile.NamedTemporaryFile() as stderr:
subprocess.check_call(["coredumpctl", "dump"] + shlex.split(self.coredumpctl_matches),
stdout=coredump, stderr=stderr)
with open(stderr.name, 'r') as stderrf:
stderr = stderrf.read()
executable, = re.findall(".*Executable: (.*)", stderr)
if not executable.startswith("/newroot"):
print("Executable %s doesn't seem to be a flatpaked application." % executable,
file=sys.stderr)
executable = executable.replace("/newroot", "")
args = ["gdb", executable, coredump.name] + shlex.split(self.coredumpgdb)
self.run_in_sandbox(*args, mount_tmp=True)
def install_development_tools(self):
venv_path = os.path.join(self.scriptdir, "pyvenv")
Console.message(
......@@ -590,7 +624,7 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
self.run_in_sandbox("pip3", "install", "-q", "-U", "--user", *pip_modules,
exit_on_failure=True)
def run_in_sandbox(self, *args, exit_on_failure=False, cwd=None):
def run_in_sandbox(self, *args, exit_on_failure=False, cwd=None, mount_tmp=False):
if not args:
return
......@@ -601,11 +635,13 @@ class PitiviFlatpak: # pylint: disable=too-many-instance-attributes
"--env=PYTHONUSERBASE=/app/",
"--env=CC=ccache gcc",
"--env=CXX=ccache g++", "--device=dri"]
if mount_tmp:
flatpak_command.append("--filesystem=/tmp/")
# The forwarded environment variables.
forwarded = {}
for envvar, value in os.environ.items():
if envvar.split("_")[0] in ("GDK", "GST", "GTK", "PITIVI", "LC", "G") or \
if envvar.split("_")[0] in ("G", "GDK", "GST", "GTK", "LC", "PITIVI") or \
envvar in ["DISPLAY", "LANG"]:
forwarded[envvar] = value
......@@ -679,6 +715,12 @@ if __name__ == "__main__":
action="store_true",
help="Clean previous builds and restart from scratch")
debug_options = parser.add_argument_group("Debugging")
debug_options.add_argument("-gdb", "--coredumpgdb", nargs="?",
help="Activate gdb, passing extra args to it if wanted.")
debug_options.add_argument("-m", "--coredumpctl-matches", default="",
help="Arguments to pass to gdb.")
bundling = parser.add_argument_group("Building bundle for distribution")
bundling.add_argument("--bundle", dest="bundle",
action="store_true",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment