From 3713bf59d4d4ef43e528a8b6095a9bdca2fed734 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Sat, 1 Mar 2025 11:56:42 +0000 Subject: [PATCH] gdb: add load-libthread-db-quietly option Setting that option disables the "Thread debugging using libthread_db enabled" and "Using host libthread_db library..." messages. --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 8 ++++++++ gdb/linux-thread-db.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index f5dbf5c3350..4e10d58642f 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -40,6 +40,9 @@ show riscv numeric-register-names (e.g 'x1') or their abi names (e.g. 'ra'). Defaults to 'off', matching the old behaviour (abi names). +set load-libthread-db-quietly on|off + Controls whether GDB displays messages when loading libthread_db. + * Python API ** New class gdb.Color for dealing with colors. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 29c0118dda2..4b752a15c42 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -4073,6 +4073,14 @@ only on some platforms. @item show libthread-db-search-path Display current libthread_db search path. +@kindex set load-libthread-db-quietly +@kindex show load-libthread-db-quietly +@item set load-libthread-db-quietly +@itemx show load-libthread-db-quietly +Turns on or off quiet loading of @code{libthread_db}. When +@code{on}, @value{GDBN} loads @code{libthread_db} quietly, without +any messages. The default is @code{off}. + @kindex set debug libthread-db @kindex show debug libthread-db @cindex debugging @code{libthread_db} diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 9d84187a9ad..d042d51c5fd 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -120,6 +120,9 @@ static bool auto_load_thread_db = true; by the "maintenance set check-libthread-db" command. */ static bool check_thread_db_on_load = false; +/* Set to true if loading libthread_db happens quietly. */ +static bool load_libthread_db_quiet = false; + /* "show" command for the auto_load_thread_db configuration variable. */ static void @@ -150,6 +153,15 @@ show_libthread_db_debug (struct ui_file *file, int from_tty, gdb_printf (file, _("libthread-db debugging is %s.\n"), value); } +/* "show" command for the load_libthread_db_quiet configuration variable. */ + +static void +show_load_libthread_db_quiet (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char* value) +{ + gdb_printf (file, _("Loading libthread_db quietly is %s.\n"), value); +} + /* If we're running on GNU/Linux, we must explicitly attach to any new threads. */ @@ -936,7 +948,8 @@ try_thread_db_load_1 (struct thread_db_info *info) return false; } - gdb_printf (_("[Thread debugging using libthread_db enabled]\n")); + if (!load_libthread_db_quiet) + gdb_printf (_("[Thread debugging using libthread_db enabled]\n")); if (!libthread_db_search_path.empty () || libthread_db_debug) { @@ -946,8 +959,9 @@ try_thread_db_load_1 (struct thread_db_info *info) if (library == NULL) library = LIBTHREAD_DB_SO; - gdb_printf (_("Using host libthread_db library \"%ps\".\n"), - styled_string (file_name_style.style (), library)); + if (!load_libthread_db_quiet) + gdb_printf (_("Using host libthread_db library \"%ps\".\n"), + styled_string (file_name_style.style (), library)); } /* The thread library was detected. Activate the thread_db target @@ -2050,6 +2064,15 @@ as they are loaded."), &maintenance_set_cmdlist, &maintenance_show_cmdlist); + add_setshow_boolean_cmd ("load-libthread-db-quietly", class_support, + &load_libthread_db_quiet, _("\ +Set whether GDB should load libthread_db quietly."), _("\ +Show whether GDB should start load libthread_db quietly."), _("\ +If enabled, GDB will load libthread_db without printing messages."), + NULL, + show_load_libthread_db_quiet, + &setlist, &showlist); + /* Add ourselves to objfile event chain. */ gdb::observers::new_objfile.attach (thread_db_new_objfile, "linux-thread-db"); -- 2.39.2