From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 1B8EC3858428 for ; Mon, 13 Mar 2023 18:35:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B8EC3858428 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678732524; x=1710268524; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1zYrHjTwHLOcCKHCh+M2D87u1pyFaTyHLBOKfM/edR8=; b=BKx9TcZ8Us0+RM/WbyMuvxYAn8ixNEHc6LxDz0VpFcrtr4G1IeJVFHS6 t5epD9uGZCnprBIjkOGaJkZgww5YXkwhJgr4+vbkLBqv+jj3DQStlN8jQ Rxe9f2Q953EDHD/zqpUQ8UQkhOKut4SylUimj+ipPv1ellrNMBCktYsCw pkSWtORWPrCMqEqjMQ1nSZOpjASSgqDa3ytMpjhu/3L/TciiWlRvjUwjN KQ+REdzG1SKkbRHgSq7ts5okJpZDHSB8JZHWcfx6G3PBwSGud7JP8JgfH 2gr9uyGfGMXSHFxlzhwgKj7dBdi5bW6cAeP0VoElDy7atu4yNjZqVF5pC A==; X-IronPort-AV: E=McAfee;i="6500,9779,10648"; a="325594321" X-IronPort-AV: E=Sophos;i="5.98,257,1673942400"; d="scan'208";a="325594321" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2023 11:35:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10648"; a="656065347" X-IronPort-AV: E=Sophos;i="5.98,257,1673942400"; d="scan'208";a="656065347" 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; 13 Mar 2023 11:35:21 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Cc: eliz@gnu.org, blarsen@redhat.com, Christina Schimpe Subject: [PATCH v2 1/1] gdb, breakpoint: add breakpoint location debugging logs Date: Mon, 13 Mar 2023 19:34:27 +0100 Message-Id: <20230313183427.2735278-2-christina.schimpe@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230313183427.2735278-1-christina.schimpe@intel.com> References: <20230313183427.2735278-1-christina.schimpe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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: UGLL_MAY_INSERT (gdb) c Continuing. [breakpoints] update_global_location_list: UGLL_INSERT [breakpoints] insert_bp_location: bp_location (0x562881637fb0) at address 0x555555555137 in main at main.c:4 [breakpoints] insert_bp_location: bp_location (0x56288179a4f0) at address 0x7ffff7fd37b5 [breakpoints] insert_bp_location: bp_location (0x56288179ea60) at address 0x7ffff7fe509e [breakpoints] insert_bp_location: bp_location (0x5628817184d0) at address 0x7ffff7fe63f4 <_dl_close_worker+2356> [breakpoints] remove_breakpoint_1: bp_location (0x562881637fb0) due to regular remove at address 0x555555555137 in main at main.c:4 [breakpoints] remove_breakpoint_1: bp_location (0x56288179a4f0) due to regular remove at address 0x7ffff7fd37b5 [breakpoints] remove_breakpoint_1: bp_location (0x56288179ea60) due to regular remove at address 0x7ffff7fe509e [breakpoints] remove_breakpoint_1: bp_location (0x5628817184d0) due to regular remove at address 0x7ffff7fe63f4 <_dl_close_worker+2356> Breakpoint 2, 0x0000555555555137 in main () at main.c:4 4 } ~~~ Co-Authored-By: Christina Schimpe --- gdb/NEWS | 4 +++ gdb/breakpoint.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ gdb/doc/gdb.texinfo | 8 ++++++ 3 files changed, 78 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index cc262f1f8a6..f413cd5aeb4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,10 @@ *** Changes since GDB 13 +* set debug breakpoints on|off + show debug breakpoints + Print additional debug messages about breakpoint insertion and removal. + * Removed targets and native configurations GDB no longer supports AIX 4.x, AIX 5.x and AIX 6.x. The minimum supported diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index abee22cd162..e3666c34bee 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -163,6 +163,8 @@ static bool bl_address_is_meaningful (bp_location *loc); static int find_loc_num_by_location (const bp_location *loc); +static std::string breakpoint_location_to_buffer (bp_location *bl); + /* update_global_location_list's modes of operation wrt to whether to insert locations now. */ enum ugll_insert_mode @@ -198,6 +200,22 @@ enum ugll_insert_mode UGLL_INSERT }; +static const char * +ugll_insert_mode_text (ugll_insert_mode insert_mode) +{ + 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"; + } + + gdb_assert_not_reached ("must handle all enum values"); +} + static void update_global_location_list (enum ugll_insert_mode); static void update_global_location_list_nothrow (enum ugll_insert_mode); @@ -508,6 +526,19 @@ show_always_inserted_mode (struct ui_file *file, int from_tty, value); } +static bool debug_breakpoints = false; + +#define breakpoint_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (debug_breakpoints, "breakpoints",fmt,\ + ##__VA_ARGS__) + +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 @@ -2710,6 +2741,11 @@ insert_bp_location (struct bp_location *bl, if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) return 0; + breakpoint_debug_printf ("bp_location (%s) at address %s %s", + host_address_to_string (bl), + paddress (bl->gdbarch, bl->address), + breakpoint_location_to_buffer (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 @@ -3264,6 +3300,8 @@ remove_breakpoints_inf (inferior *inf) { int val; + breakpoint_debug_printf ("remove_breakpoints_inf (%d)", inf->num); + for (bp_location *bl : all_bp_locations ()) { if (bl->pspace != inf->pspace) @@ -3908,6 +3946,13 @@ detach_breakpoints (ptid_t ptid) static int remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) { + breakpoint_debug_printf ("bp_location (%s) due to %s at address %s %s", + host_address_to_string (bl), + (reason == REMOVE_BREAKPOINT + ? "regular remove" : "detach"), + paddress (bl->gdbarch, bl->address), + breakpoint_location_to_buffer (bl).c_str ()); + int val; /* BL is never in moribund_locations by our callers. */ @@ -6210,6 +6255,16 @@ print_breakpoint_location (const breakpoint *b, } } +static std::string +breakpoint_location_to_buffer (bp_location *bl) +{ + string_file stb; + current_uiout->redirect (&stb); + print_breakpoint_location (bl->owner, bl); + current_uiout->redirect (nullptr); + return stb.string (); +} + static const char * bptype_string (enum bptype type) { @@ -11140,6 +11195,8 @@ 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 ("%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 @@ -14870,6 +14927,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 non-zero, 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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 98b7c984aa7..fe52acdf5dd 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -28283,6 +28283,14 @@ debugging info. Turn on or off debugging messages for built-in XML parsers. @item show debug xml Displays the current state of XML debugging messages. + +@item set debug breakpoints +@cindex breakpoint debugging info +Turns on or off display of @value{GDBN} debugging info for breakpoint insertion +and removal. The default is off. +@item show debug breakpoints +Displays the current state of displaying @value{GDBN} debugging info for +breakpoint insertion and removal. @end table @node Other Misc Settings -- 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928