From patchwork Mon Nov 21 19:36:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 60943 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C87B2384F48E for ; Mon, 21 Nov 2022 19:37:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C87B2384F48E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669059430; bh=BxRq1STGKCMbxCcL+EaIuBbRSRVmmf26Bce8s1y/Phs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OmerN8AtobAYJMeDJ3PF6m1tqjcUNW7E7k8uZ0m91NbMPNQ5fw8rqCJosxjpFSH4q +axzC35+uGSmwHfIuplvL2CmW/XxgEEe30XioW8mfsbupLsbEuJ+CuvWqdYPHESnSl JpgOBxDUpusau0XWNT5ZyCDTmLv4oMGaybgfTX9Q= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 1904E384F6E8 for ; Mon, 21 Nov 2022 19:36:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1904E384F6E8 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2ALJaenL024987 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Nov 2022 14:36:45 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2ALJaenL024987 Received: from simark.localdomain (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8C9AC1E0CB; Mon, 21 Nov 2022 14:36:40 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: add "set debug solib" and use it Date: Mon, 21 Nov 2022 14:36:36 -0500 Message-Id: <20221121193636.1479004-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 21 Nov 2022 19:36:40 +0000 X-Spam-Status: No, score=-3189.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi I'd like to add some debug output to solib-svr4. Add a "set debug solib" knob, which can then be used in all solib-* files. Then, add the debug output I needed, related to the svr4 shared library event breakpoint probes. Change-Id: Ic20744f9fc80a90f196896b0829949411620c540 --- gdb/NEWS | 4 ++++ gdb/doc/gdb.texinfo | 6 ++++++ gdb/solib-svr4.c | 23 ++++++++++++++++++++++- gdb/solib.c | 8 ++------ gdb/solib.h | 12 ++++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) base-commit: 1a7e622b82fa621ab505dd911bc30c1efcb4a9b0 diff --git a/gdb/NEWS b/gdb/NEWS index dddef6525de8..d36aa0707629 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -145,6 +145,10 @@ set debug infcall on|off show debug infcall Print additional debug messages about inferior function calls. +set debug solib on|off +show debug solib + Print additional debug messages about shared library handling. + set style tui-current-position [on|off] Whether to style the source and assembly code highlighted by the TUI's current position indicator. The default is off. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bababf3c7ff8..ce4dae11f0d2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -27812,6 +27812,12 @@ A value greater than 1 provides more verbose information. @item show debug symbol-lookup Show the current state of symbol lookup debugging messages. +@item set debug solib +Turns on or off display of debugging messages related to shared libraries. +The default is off. +@item show debug solib +Show the current state of solib debugging messages. + @item set debug symfile @cindex symbol file functions Turns on or off display of debugging messages related to symbol file functions. diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 6acaf87960bf..d2c1cfa7851e 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -34,6 +34,7 @@ #include "regcache.h" #include "gdbthread.h" #include "observable.h" +#include "cli/cli-cmds.h" #include "solist.h" #include "solib.h" @@ -2168,6 +2169,9 @@ svr4_create_probe_breakpoints (svr4_info *info, struct gdbarch *gdbarch, { CORE_ADDR address = p->get_relocated_address (objfile); + solib_debug_printf ("name=%s, addr=%s", probe_info[i].name, + paddress (gdbarch, address)); + create_solib_event_breakpoint (gdbarch, address); register_solib_event_probe (info, objfile, p, address, action); } @@ -2185,6 +2189,9 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info, struct obj_section *os, bool with_prefix) { + SOLIB_SCOPED_DEBUG_START_END ("objfile=%s, with_prefix=%d", + os->objfile->original_name, with_prefix); + std::vector probes[NUM_PROBES]; for (int i = 0; i < NUM_PROBES; i++) @@ -2204,6 +2211,7 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info, } probes[i] = find_probes_in_objfile (os->objfile, "rtld", name); + solib_debug_printf ("probe=%s, num found=%zu", name, probes[i].size ()); /* The "map_failed" probe did not exist in early versions of the probes code in which the probes' @@ -2237,6 +2245,7 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info, } /* All probes found. Now create them. */ + solib_debug_printf ("using probes interface"); svr4_create_probe_breakpoints (info, gdbarch, probes, os->objfile); return true; } @@ -2262,7 +2271,11 @@ svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch, if (os == nullptr || (!svr4_find_and_create_probe_breakpoints (info, gdbarch, os, false) && !svr4_find_and_create_probe_breakpoints (info, gdbarch, os, true))) - create_solib_event_breakpoint (gdbarch, address); + { + solib_debug_printf ("falling back to r_brk breakpoint: addr=%s", + paddress (gdbarch, address)); + create_solib_event_breakpoint (gdbarch, address); + } } /* Helper function for gdb_bfd_lookup_symbol. */ @@ -3449,6 +3462,14 @@ void _initialize_svr4_solib (); void _initialize_svr4_solib () { + add_setshow_boolean_cmd ("solib", class_maintenance, + &debug_solib, _("\ +Set solib debugging."), _("\ +Show solib debugging."), _("\ +When true, solib-related debugging output is enabled."), + nullptr, nullptr, + &setdebuglist, &showdebuglist); + gdb::observers::free_objfile.attach (svr4_free_objfile_observer, "solib-svr4"); } diff --git a/gdb/solib.c b/gdb/solib.c index 7cfdd81114c4..aafdb85db3be 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -55,13 +55,9 @@ #include "cli/cli-style.h" #include "solib-target.h" -/* Architecture-specific operations. */ - - - -/* external data declarations */ +/* See solib.h. */ -/* Local function prototypes */ +bool debug_solib; /* If non-empty, this is a search path for loading non-absolute shared library symbol files. This takes precedence over the environment variables PATH diff --git a/gdb/solib.h b/gdb/solib.h index a7e751ed9b31..74066680ef9c 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -29,6 +29,18 @@ struct program_space; #include "gdb_bfd.h" #include "symfile-add-flags.h" +/* Value of the 'set debug solib' configuration variable. */ + +extern bool debug_solib; + +/* Print an "solib" debug statement. */ + +#define solib_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (debug_solib, "solib", fmt, ##__VA_ARGS__) + +#define SOLIB_SCOPED_DEBUG_START_END(fmt, ...) \ + scoped_debug_start_end (debug_solib, "solib", fmt, ##__VA_ARGS__) + /* Called when we free all symtabs, to free the shared library information as well. */