From bb9c0db4de1688fabe35462aebee0ed914693816 Mon Sep 17 00:00:00 2001 From: Ivona Stojanovic Date: Wed, 6 Sep 2023 09:56:34 +0100 Subject: [PATCH] Prefer gdb over lldb on Linux Signed-off-by: Ivona Stojanovic --- news/449.bugfix.rst | 1 + src/memray/commands/attach.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 news/449.bugfix.rst diff --git a/news/449.bugfix.rst b/news/449.bugfix.rst new file mode 100644 index 0000000000..7fadda8fb3 --- /dev/null +++ b/news/449.bugfix.rst @@ -0,0 +1 @@ +Update ``memray attach`` on Linux to prefer GDB over LLDB for injecting itself into the process being attached to. We've had several reports of problems with the Linux LLDB, and hope this change will help give Linux users a better experience by default. You can still explicitly use LLDB on Linux even when GDB is detected by running ``memray attach --method=lldb``. diff --git a/src/memray/commands/attach.py b/src/memray/commands/attach.py index 03874c2f79..529dd5fd50 100644 --- a/src/memray/commands/attach.py +++ b/src/memray/commands/attach.py @@ -4,6 +4,7 @@ import contextlib import os import pathlib +import platform import shlex import shutil import signal @@ -298,10 +299,16 @@ def run(self, args: argparse.Namespace, parser: argparse.ArgumentParser) -> None verbose = args.verbose if args.method == "auto": - if debugger_available("lldb", verbose=verbose): - args.method = "lldb" - elif debugger_available("gdb", verbose=verbose): - args.method = "gdb" + # Prefer gdb on Linux but lldb on macOS + if platform.system() == "Linux": + debuggers = ("gdb", "lldb") + else: + debuggers = ("lldb", "gdb") + + for debugger in debuggers: + if debugger_available(debugger, verbose=verbose): + args.method = debugger + break else: raise MemrayCommandError( "Cannot find a supported lldb or gdb executable.",