From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E3A993858404 for ; Wed, 7 Jun 2023 08:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3A993858404 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686127547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fI7zdubxf6KbvRbRM4CXA3c6pgD6fN25V70FrGgNM6k=; b=cjt6Zs9ycQthvNpOvGSI/Tow8QgjwF0ibkSgUj/tw4wqgG6QVawgSPVNY23xrTgji9Mvae XnEl2kwm/XkO1mrVzzgaAQtcqHN4g2vsPdKlZ8+32FkiNykC6WslN0gFjFmVKOdrwIY0VV JZJ3WcXRZSxaLjBACAPtZnL+B8w/A04= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-61Hs8sFAO76gwbucFfKRVQ-1; Wed, 07 Jun 2023 04:45:45 -0400 X-MC-Unique: 61Hs8sFAO76gwbucFfKRVQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f5df65f9f4so33903195e9.2 for ; Wed, 07 Jun 2023 01:45:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686127544; x=1688719544; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fI7zdubxf6KbvRbRM4CXA3c6pgD6fN25V70FrGgNM6k=; b=ja6KGngTVnt/GJEXi8dzLQp/Eqgcu+8MYPmKJoLrV/H4CDzjeU1C0Hfon/UaZZGByB EC4MMfr2LAgpzICqDxewzdzHjnUH0ifGNGnL3Vz2vYAYX5AGv2qmZXatKWpsJmcxVS0q XqjNEuplifg8wXoMwPB9cw5LRu4pqF0AJxR09QfhaKXqtZYcePFPp9zWiUZe+LUC1o7h wEUFx3p0NozvB3B/7MaHhXhA05LKGCzA1/jmfAPatETZ3W9LxhcyKclqwXcdvqrY2u92 dc2keOiKwzhBCEsTUppOZ9FD9USUZ40lv5qTlw/hx8N4sKJIW7o3aNMns6kCR5GPSqmd PQow== X-Gm-Message-State: AC+VfDyVgy47cKWfuABgx5eIAuRSFbQBNkmrOkpbCOuc1UMcv4/56i+q UaoV5GNGPEXMUaW2UndVfwET8CyZe76XaA+KOKwbguPBRYtZe9cCp+kW5rLMq3jKtWr7DGrYPhv 44O66HEYhyA2KmNLnWRcQfA== X-Received: by 2002:a05:600c:2117:b0:3f4:2328:b5c2 with SMTP id u23-20020a05600c211700b003f42328b5c2mr3967796wml.35.1686127544189; Wed, 07 Jun 2023 01:45:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lxjzs7N1uJt2WODAbbFMqIa79Pz7W0O0eF9UqwATZQG0X2EWFyRi39m87K3iULxtZLhuNKw== X-Received: by 2002:a05:600c:2117:b0:3f4:2328:b5c2 with SMTP id u23-20020a05600c211700b003f42328b5c2mr3967773wml.35.1686127543721; Wed, 07 Jun 2023 01:45:43 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id u25-20020a7bcb19000000b003f73a101f88sm1377392wmj.16.2023.06.07.01.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 01:45:43 -0700 (PDT) From: Andrew Burgess To: Christina Schimpe , gdb-patches@sourceware.org Cc: eliz@gnu.org, simark@simark.ca Subject: Re: [PATCH v4 1/1] gdb, breakpoint: add breakpoint location debugging logs In-Reply-To: <20230601163345.3895525-2-christina.schimpe@intel.com> References: <20230601163345.3895525-1-christina.schimpe@intel.com> <20230601163345.3895525-2-christina.schimpe@intel.com> Date: Wed, 07 Jun 2023 09:45:42 +0100 Message-ID: <87a5xb3bk9.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: Christina Schimpe writes: > From: Mihails Strasuns > > Add new commands: > > set debug breakpoints on|off > show debug breakpoints I'd like to suggest (but don't require) that we drop the 's' here, so breakpoints -> breakpoint. I'd point to other debug settings like frame (not frames), expression (not expressions), and target (not targets) for precedent. However there is also threads (not thread) which is why I don't think it would be fair to require this change -- it's up to you. > > 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 > --- > 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. I think this line was not intended to be part of this commit. > +* set debug breakpoints on|off > + show debug breakpoints > + Print additional debug messages about breakpoint insertion and removal. I think this should be moved into the '* New commands' section of the NEWS file, see for example, how and where 'set always-read-ctf on|off' is documented in this file. > + > * 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)); I can't help but think using 'location' in this string is a bad idea, 'location' already has a meaning for GDB breakpoints. How about just dropping the work 'location'? > + > + 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) > { > } > Missing a comment '/* See breakpoint.h. */'. Thanks, Andrew > +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 > /* The objfile the symbol or minimal symbol were found in. */ > const struct objfile *objfile = NULL; > + > + /* Return a string representation of the bp_location. > + This is only meant to be used in debug messages. */ > + std::string to_string () const; > }; > > /* A policy class for bp_location reference counting. */ > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index fc55c4e7b43..8c91ecab209 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -28356,6 +28356,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