From patchwork Thu Jun 1 16:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schimpe, Christina" X-Patchwork-Id: 70468 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 777CB3856969 for ; Thu, 1 Jun 2023 16:35:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 777CB3856969 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685637323; bh=D/cxCKk+DkcCgpYo7BDrLl3p9gnMz+V0LPwWu5HdR08=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=wOdNbxyz54s2cwymYjGRmL8uik2uBD2gtc9JWFFEAMuYF5zraZ56HSHULJVgSBGMl 5Pav3IgLPE8Cion+imsBeGMbhsnsQ2SYf73g/UZNxrAWP4X5aLpKzuIJJ4/7rqCooZ SvSCp5aYr0ONyIPfnZcArbsf9Es9ngmplNiT8c1g= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id DE7C83857400 for ; Thu, 1 Jun 2023 16:34:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE7C83857400 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="383886172" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="383886172" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 09:34:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="684913134" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="684913134" Received: from labpc2315.iul.intel.com (HELO localhost) ([172.28.50.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 09:34:38 -0700 To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, eliz@gnu.org, simark@simark.ca Subject: [PATCH v4 1/1] gdb, breakpoint: add breakpoint location debugging logs Date: Thu, 1 Jun 2023 18:33:45 +0200 Message-Id: <20230601163345.3895525-2-christina.schimpe@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601163345.3895525-1-christina.schimpe@intel.com> References: <20230601163345.3895525-1-christina.schimpe@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Christina Schimpe via Gdb-patches From: "Schimpe, Christina" Reply-To: Christina Schimpe Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Mihails Strasuns Add new commands: set debug breakpoints on|off show debug breakpoints This patch introduces new debugging information that prints breakpoint location insertion and removal flow. The debug output looks like: ~~~ (gdb) set debug breakpoints on (gdb) disassemble main Dump of assembler code for function main: 0x0000555555555129 <+0>: endbr64 0x000055555555512d <+4>: push %rbp 0x000055555555512e <+5>: mov %rsp,%rbp => 0x0000555555555131 <+8>: mov $0x0,%eax 0x0000555555555136 <+13>: pop %rbp 0x0000555555555137 <+14>: ret End of assembler dump. (gdb) break *0x0000555555555137 Breakpoint 2 at 0x555555555137: file main.c, line 4. [breakpoints] update_global_location_list: insert_mode = UGLL_MAY_INSERT (gdb) c Continuing. [breakpoints] update_global_location_list: insert_mode = UGLL_INSERT [breakpoints] insert_bp_location: Breakpoint 2, location (0x5572b98a6db0) at address 0x555555555137 in main at main.c:4 [breakpoints] insert_bp_location: Breakpoint -2, location (0x5572b961d450) at address 0x7ffff7fd37b5 [breakpoints] insert_bp_location: Breakpoint -5, location (0x5572b9634680) at address 0x7ffff7fe509e [breakpoints] insert_bp_location: Breakpoint -7, location (0x5572b9634a00) at address 0x7ffff7fe63f4 [breakpoints] remove_breakpoint_1: Breakpoint 2, location (0x5572b98a6db0) at address 0x555555555137 in main at main.c:4 due to regular remove [breakpoints] remove_breakpoint_1: Breakpoint -2, location (0x5572b961d450) at address 0x7ffff7fd37b5 due to regular remove [breakpoints] remove_breakpoint_1: Breakpoint -5, location (0x5572b9634680) at address 0x7ffff7fe509e due to regular remove [breakpoints] remove_breakpoint_1: Breakpoint -7, location (0x5572b9634a00) at address 0x7ffff7fe63f4 due to regular remove Breakpoint 2, 0x0000555555555137 in main () at main.c:4 4 } ~~~ Co-Authored-By: Christina Schimpe Reviewed-By: Eli Zaretskii --- gdb/NEWS | 5 +++ gdb/breakpoint.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ gdb/breakpoint.h | 4 ++ gdb/doc/gdb.texinfo | 8 ++++ 4 files changed, 124 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 649a3a9824a..c66fde54e85 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,11 @@ *** Changes since GDB 13 +* GDB now has some support for integer types larger than 64 bits. +* set debug breakpoints on|off + show debug breakpoints + Print additional debug messages about breakpoint insertion and removal. + * The AArch64 'org.gnu.gdb.aarch64.pauth' Pointer Authentication feature string has been deprecated in favor of the 'org.gnu.gdb.aarch64.pauth_v2' feature string. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 0a520cfc169..dd8fac2f1ba 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -83,6 +83,7 @@ #include "progspace-and-thread.h" #include "gdbsupport/array-view.h" #include "gdbsupport/gdb_optional.h" +#include "gdbsupport/common-utils.h" /* Prototypes for local functions. */ @@ -200,6 +201,68 @@ enum ugll_insert_mode UGLL_INSERT }; +/* Return a textual version of INSERT_MODE. */ + +static const char * +ugll_insert_mode_text (ugll_insert_mode insert_mode) +{ +/* Make sure the compiler warns if a new ugll_insert_mode enumerator is added + but not handled here. */ +DIAGNOSTIC_PUSH +DIAGNOSTIC_ERROR_SWITCH + switch (insert_mode) + { + case UGLL_DONT_INSERT: + return "UGLL_DONT_INSERT"; + case UGLL_MAY_INSERT: + return "UGLL_MAY_INSERT"; + case UGLL_INSERT: + return "UGLL_INSERT"; + } +DIAGNOSTIC_POP + + gdb_assert_not_reached ("must handle all enum values"); +} + +/* Return a textual version of REASON. */ + +static const char * +remove_bp_reason_str (remove_bp_reason reason) +{ +/* Make sure the compiler warns if a new remove_bp_reason enumerator is added + but not handled here. */ +DIAGNOSTIC_PUSH +DIAGNOSTIC_ERROR_SWITCH + switch (reason) + { + case REMOVE_BREAKPOINT: + return "regular remove"; + case DETACH_BREAKPOINT: + return "detach"; + } +DIAGNOSTIC_POP + + gdb_assert_not_reached ("must handle all enum values"); +} + +/* Return a textual version of breakpoint BL describing number, location and + address. */ + +static std::string +breakpoint_location_address_str (const bp_location* bl) +{ + std::string str = string_printf ("Breakpoint %d, location (%s) at address %s", + bl->owner->number, + host_address_to_string (bl), + paddress (bl->gdbarch, bl->address)); + + std::string loc_string = bl->to_string (); + if (!loc_string.empty ()) + str += string_printf (" %s", loc_string.c_str ()); + + return str; +} + static void update_global_location_list (enum ugll_insert_mode); static void update_global_location_list_nothrow (enum ugll_insert_mode); @@ -510,6 +573,22 @@ show_always_inserted_mode (struct ui_file *file, int from_tty, value); } +/* True if breakpoints debug output is enabled. */ +static bool debug_breakpoints = false; + +/* Print a "breakpoints" debug statement. */ +#define breakpoint_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (debug_breakpoints, "breakpoints", fmt, \ + ##__VA_ARGS__) + +/* "show debug breakpoints" implementation. */ +static void +show_debug_breakpoints (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("Breakpoint location debugging is %s.\n"), value); +} + /* See breakpoint.h. */ int @@ -2728,6 +2807,8 @@ insert_bp_location (struct bp_location *bl, if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) return 0; + breakpoint_debug_printf ("%s", breakpoint_location_address_str (bl).c_str ()); + /* Note we don't initialize bl->target_info, as that wipes out the breakpoint location's shadow_contents if the breakpoint is still inserted at that location. This in turn breaks @@ -3270,6 +3351,8 @@ remove_breakpoints_inf (inferior *inf) { int val; + breakpoint_debug_printf ("inf->num = %d", inf->num); + for (bp_location *bl : all_bp_locations ()) { if (bl->pspace != inf->pspace) @@ -3914,6 +3997,10 @@ detach_breakpoints (ptid_t ptid) static int remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) { + breakpoint_debug_printf ("%s due to %s", + breakpoint_location_address_str (bl).c_str (), + remove_bp_reason_str (reason)); + int val; /* BL is never in moribund_locations by our callers. */ @@ -7424,6 +7511,14 @@ bp_location::bp_location (breakpoint *owner) { } +std::string bp_location::to_string () const +{ + string_file stb; + ui_out_redirect_pop redir (current_uiout, &stb); + print_breakpoint_location (this->owner, this); + return stb.string (); +} + /* Decrement reference count. If the reference count reaches 0, destroy the bp_location. Sets *BLP to NULL. */ @@ -11157,6 +11252,9 @@ update_global_location_list (enum ugll_insert_mode insert_mode) /* Last breakpoint location program space that was marked for update. */ int last_pspace_num = -1; + breakpoint_debug_printf ("insert_mode = %s", + ugll_insert_mode_text (insert_mode)); + /* Used in the duplicates detection below. When iterating over all bp_locations, points to the first bp_location of a given address. Breakpoints and watchpoints of different types are never @@ -14899,6 +14997,15 @@ when execution stops."), &breakpoint_set_cmdlist, &breakpoint_show_cmdlist); + add_setshow_boolean_cmd ("breakpoints", class_maintenance, + &debug_breakpoints, _("\ +Set breakpoint location debugging."), _("\ +Show breakpoint location debugging."), _("\ +When on, breakpoint location specific debugging is enabled."), + NULL, + show_debug_breakpoints, + &setdebuglist, &showdebuglist); + add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, condition_evaluation_enums, &condition_evaluation_mode_1, _("\ diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index da150585f73..f4896293bb7 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -509,6 +509,10 @@ class bp_location : public refcounted_object, public intrusive_list_node