From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by sourceware.org (Postfix) with ESMTPS id C588B385734B for ; Mon, 16 May 2022 18:41:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C588B385734B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f54.google.com with SMTP id d21so5778616wra.10 for ; Mon, 16 May 2022 11:41:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6PcUzSkk4jM9924WzEPtlmHLiqMNRJUxV9QmbUG19Yk=; b=KTWeu1HR1R9CvohJyXuglrfcjfEQG8yalexmIQ/p5x22EqPO5K6PRfGbPz7TWlOJhW 2b4t67k7LA3Rb22CI5VzAOdiYe7Ochg1ud7RT6S/66Z6z0MRycMEJyPrwZYSE5EOEmLN v8h1k0YXhIfD2jKvaMkknolj5MtfQVXe3nAPpOTFI9/n2FAFptOemx2Cw/u+fVnhLNWi ECGvSqgQ0M8JwkFoyd9BJHXhfnDDO9n2gJLlC3COG5bO+bcUl6IqsQPcHq3QNORTOpcq rbjU47/YahrXLZaOjPGr06J9L7nUq8TYO6tf3Gunz8W5U8Fg54DTBR7RQQRZ83Gg4wnE auYg== X-Gm-Message-State: AOAM533Atldy/M9uLKkrWZN574n2shCGRSwuZskZjkAlbZ/GXLpqy4gg EyKyVwWecEcoOTCQWtS1WsCX33codks= X-Google-Smtp-Source: ABdhPJz9TL1c6xS+AIDWBq2EK18eR+rNSZJSsIfNjllLMOxlRNoQPmWjLk6HbKXzoQ7nhpUB632Jbg== X-Received: by 2002:a5d:4886:0:b0:20d:527:f98b with SMTP id g6-20020a5d4886000000b0020d0527f98bmr7101379wrq.70.1652726464783; Mon, 16 May 2022 11:41:04 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id v8-20020adfa1c8000000b0020d050461c9sm5907537wrv.54.2022.05.16.11.41.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 May 2022 11:41:03 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 15/23] Make breakpoint_address_bits look at the location kind Date: Mon, 16 May 2022 19:40:22 +0100 Message-Id: <20220516184030.665489-16-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220516184030.665489-1-pedro@palves.net> References: <20220516184030.665489-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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-List-Received-Date: Mon, 16 May 2022 18:41:08 -0000 Software watchpoints allocate a special dummy location using software_watchpoint_add_no_memory_location, and then breakpoint_address_bits checks whether the location is that special location to decide whether the location has a meaninful address to print. Introduce a new bp_loc_software_watchpoint location kind, and make breakpoint_address_bits use bl_address_is_meaningful instead, which returns false for bp_loc_other, which is in accordance with we document for bp_location::address: /* (... snip ...) Valid for all types except bp_loc_other. */ CORE_ADDR address = 0; Rename software_watchpoint_add_no_memory_location to add_dummy_location, and simplify it. This will be used by catchpoints too in a following patch. Note that neither "info breakpoints" nor "maint info breakpoints" actually prints the addresses of watchpoints, but I think it would be useful to do so in "maint info breakpoints". This approach let's us implement that in the future. Change-Id: I50e398f66ef618c31ffa662da755eaba6295aed7 --- gdb/breakpoint.c | 59 ++++++++++++++++++------------------------------ gdb/breakpoint.h | 1 + 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 6e24137ec4b..6dfb89f51bc 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -164,6 +164,8 @@ static std::vector bkpt_probe_decode_location struct event_location *location, struct program_space *search_pspace); +static bool bl_address_is_meaningful (bp_location *loc); + /* update_global_location_list's modes of operation wrt to whether to insert locations now. */ enum ugll_insert_mode @@ -1830,34 +1832,18 @@ extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) return bit_val; } -/* Allocate a dummy location and add it to B, which must be a software - watchpoint. This is required because even if a software watchpoint - is not watching any memory, bpstat_stop_status requires a location - to be able to report stops. */ +/* Allocate a dummy location and add it to B. This is required + because bpstat_stop_status requires a location to be able to report + stops. */ static void -software_watchpoint_add_no_memory_location (struct breakpoint *b, - struct program_space *pspace) +add_dummy_location (struct breakpoint *b, + struct program_space *pspace) { - gdb_assert (b->type == bp_watchpoint && b->loc == NULL); + gdb_assert (b->loc == NULL); - b->loc = b->allocate_location (); + b->loc = new bp_location (b, bp_loc_other); b->loc->pspace = pspace; - b->loc->address = -1; - b->loc->length = -1; -} - -/* Returns true if B is a software watchpoint that is not watching any - memory (e.g., "watch $pc"). */ - -static bool -is_no_memory_software_watchpoint (struct breakpoint *b) -{ - return (b->type == bp_watchpoint - && b->loc != NULL - && b->loc->next == NULL - && b->loc->address == -1 - && b->loc->length == -1); } /* Assuming that B is a watchpoint: @@ -2197,7 +2183,7 @@ update_watchpoint (struct watchpoint *b, int reparse) else b->type = bp_watchpoint; - loc_type = (b->type == bp_watchpoint? bp_loc_other + loc_type = (b->type == bp_watchpoint? bp_loc_software_watchpoint : bp_loc_hardware_watchpoint); for (bp_location *bl : b->locations ()) bl->loc_type = loc_type; @@ -2208,7 +2194,7 @@ update_watchpoint (struct watchpoint *b, int reparse) bpstat_stop_status requires a location to be able to report stops, so make sure there's at least a dummy one. */ if (b->type == bp_watchpoint && b->loc == NULL) - software_watchpoint_add_no_memory_location (b, frame_pspace); + add_dummy_location (b, frame_pspace); } else if (!within_current_scope) { @@ -3840,11 +3826,12 @@ detach_breakpoints (ptid_t ptid) /* This function must physically remove breakpoints locations from the specified ptid, without modifying the breakpoint - package's state. Locations of type bp_loc_other are only - maintained at GDB side. So, there is no need to remove - these bp_loc_other locations. Moreover, removing these + package's state. Locations of type bp_loc_other and + bp_loc_software_watchpoint are only maintained at GDB side, + so there is no need to remove them. Moreover, removing these would modify the breakpoint package's state. */ - if (bl->loc_type == bp_loc_other) + if (bl->loc_type == bp_loc_other + || bl->loc_type == bp_loc_software_watchpoint) continue; if (bl->inserted) @@ -5798,7 +5785,8 @@ bpstat_what (bpstat *bs_head) { /* Some catchpoints are implemented with breakpoints. For those, we need to step over the breakpoint. */ - if (bs->bp_location_at->loc_type != bp_loc_other) + if (bs->bp_location_at->loc_type == bp_loc_software_breakpoint + || bs->bp_location_at->loc_type == bp_loc_hardware_breakpoint) this_action = BPSTAT_WHAT_SINGLE; } break; @@ -6557,16 +6545,12 @@ breakpoint_address_bits (struct breakpoint *b) { int print_address_bits = 0; - /* Software watchpoints that aren't watching memory don't have an - address to print. */ - if (is_no_memory_software_watchpoint (b)) - return 0; - for (bp_location *loc : b->locations ()) { - int addr_bit; + if (!bl_address_is_meaningful (loc)) + continue; - addr_bit = gdbarch_addr_bit (loc->gdbarch); + int addr_bit = gdbarch_addr_bit (loc->gdbarch); if (addr_bit > print_address_bits) print_address_bits = addr_bit; } @@ -7161,6 +7145,7 @@ bp_location_from_bp_type (bptype type) case bp_access_watchpoint: return bp_loc_hardware_watchpoint; case bp_watchpoint: + return bp_loc_software_watchpoint; case bp_catchpoint: case bp_tracepoint: case bp_fast_tracepoint: diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index a4ead8b4d4e..7375e976dc6 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -314,6 +314,7 @@ enum bp_loc_type { bp_loc_software_breakpoint, bp_loc_hardware_breakpoint, + bp_loc_software_watchpoint, bp_loc_hardware_watchpoint, bp_loc_other /* Miscellaneous... */ }; -- 2.36.0