From patchwork Wed Dec 13 22:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 82097 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 25EB33861000 for ; Wed, 13 Dec 2023 22:39:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 C4171385C6E0 for ; Wed, 13 Dec 2023 22:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4171385C6E0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4171385C6E0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702507132; cv=none; b=MApwRWcwEnA79N8qqTSo/XqeQq9aLn7DTZ8JH3jCIG3yA+z3mmQmATgZFEpoKXroL79xNs6X2nKeYYzzVuRr1aKGGs2sHwbrQbizevd7QcSjPblXVZuhZ44zCsRX7TQGCP+X4AVhtyy8Tht/lJSDSnt+Em495ZaY27AbD/xc/UA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702507132; c=relaxed/simple; bh=WL2vzNcGbA9duxDL5Ss09R2PeoByOp42LJQ9dL3dDVM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GDPzVZPaFIGCtVgcIO4rteZ7tUNPjsqCj7CI+qxu6jqCWh0wowZlGuCN4VEk1ItSlB022Vet4/8teUyWwW+pC9eHwhuyskf65rER5G5+Cb5oVjUDNXI+xyChyb4shVOPJMich+9pZe4DUNazOpOn5LwWKYlnl5JB/mkwgsGZfrs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702507128; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r91q39Gb3yiy63VkTCFx0h8JiVomMBzPoMvopGQcEVs=; b=AgpI2NTeqjCLDEURC7qo55/oQhgYPRKoHKrfJMjm+XwJvqA+faQhBKPlzpUpb4HKoWE8U7 MiSbriU2Xlo4TkofqYYqaaKWerLwD8nARqX6j4UptTtqCH73u/EFM/wi3/rfDM1zHOa4EW Bq7XL63THUy2jsbB9wzu5ZFhocX+osk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-88iN35NlOXGtngt5SSfstA-1; Wed, 13 Dec 2023 17:38:47 -0500 X-MC-Unique: 88iN35NlOXGtngt5SSfstA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-333524816e1so4928523f8f.2 for ; Wed, 13 Dec 2023 14:38:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702507125; x=1703111925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r91q39Gb3yiy63VkTCFx0h8JiVomMBzPoMvopGQcEVs=; b=kpEEeu0/u2xFxdBLs2wlckjACfALRYGBQWGmdhkOF3Tb7MRVbL6DrviTh42DaH4uQp jy8qfpEW4q2nnzJwHQiT2mrjQEFVoEw/vL3vuZZEFhobFn8GeC5oDT+xNPTtLzoL8oez cHpgkMZjCIEbXMbHrogcKlFgdKPA3BN+Cmv3HKUg926t/0mbBqgEnyK/ofo7ms8z+hQP cpuRpYzPdkUYjwRQa5i5YtAK4yThCUBu/xZ47oa/+apsDZKtGQME7u6VRHHnDpczG2kP M8vFAa+gd+9LJzGxS2uLiw4Z9gH5UUst1XwCGITMFpGE7BANy6AIphwJyJ3NkIYMxYQW p8hQ== X-Gm-Message-State: AOJu0Yztbwjls160VUO7mtSWdiQZhL4BxudhaRc2M/7UBONofvwmsWAg EWu8rm8vZoJBOaMtJ2Ndk9S4G5115R1aLDZlmX/+LNtyhQ+uyQluWyhdNVIxwoaGXwrbpxeHgWT 8I/rri/YnCFNLUuWIDtER0HNie25ATzxFKbsCh1CJc3n6OlJFooZpDa+YKrfZ8YhrHHL6p4kDGb 4Lmk1xGg== X-Received: by 2002:a05:600c:1ca1:b0:40b:5e22:958 with SMTP id k33-20020a05600c1ca100b0040b5e220958mr4834055wms.71.1702507124915; Wed, 13 Dec 2023 14:38:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm7zhAEYiEugLb0jqRNfnIyYQh5hZ4fuUAR6J07EHwbvcnH1ZrdsdWpkI6bKLch8KBV9Bmdw== X-Received: by 2002:a05:600c:1ca1:b0:40b:5e22:958 with SMTP id k33-20020a05600c1ca100b0040b5e220958mr4834051wms.71.1702507124604; Wed, 13 Dec 2023 14:38:44 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id a11-20020a05600c348b00b0040b400711f5sm24608763wmq.7.2023.12.13.14.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:38:43 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv7 04/11] gdb: the extra_string in a dprintf breakpoint is never nullptr Date: Wed, 13 Dec 2023 22:38:28 +0000 Message-Id: <3d01f4928a27024040242cd0b64c43a912512e6e.1702507015.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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, RCVD_IN_MSPIKE_H4, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Given the changes in the previous couple of commits, this commit cleans up some of the asserts and 'if' checks related to the extra_string within a dprintf breakpoint. This commit: 1. Adds some asserts to update_dprintf_command_list about the breakpoint type, and that the extra_string is not nullptr, 2. Given that we know extra_string is not nullptr (this is enforced when the breakpoint is created), we can simplify code_breakpoint::code_breakpoint -- it no longer needs to check for the extra_string is nullptr case, 3. In dprintf_breakpoint::re_set we can remove the assert (this will be checked within update_dprintf_command_list, we can also remove the redundant 'if' check. There should be no user visible changes after this commit. --- gdb/breakpoint.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 31abf3e34ca..783a05d9a6b 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8535,6 +8535,9 @@ bp_loc_is_permanent (struct bp_location *loc) static void update_dprintf_command_list (struct breakpoint *b) { + gdb_assert (b->type == bp_dprintf); + gdb_assert (b->extra_string != nullptr); + const char *dprintf_args = b->extra_string.get (); gdb::unique_xmalloc_ptr printf_line = nullptr; @@ -8708,12 +8711,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, /* Dynamic printf requires and uses additional arguments on the command line, otherwise it's an error. */ if (type == bp_dprintf) - { - if (extra_string != nullptr) - update_dprintf_command_list (this); - else - error (_("Format string required")); - } + update_dprintf_command_list (this); else if (extra_string != nullptr) error (_("Garbage '%s' at end of command"), extra_string.get ()); } @@ -12428,9 +12426,6 @@ dprintf_breakpoint::re_set () { re_set_default (); - /* extra_string should never be non-NULL for dprintf. */ - gdb_assert (extra_string != NULL); - /* 1 - connect to target 1, that can run breakpoint commands. 2 - create a dprintf, which resolves fine. 3 - disconnect from target 1 @@ -12441,8 +12436,7 @@ dprintf_breakpoint::re_set () answers for target_can_run_breakpoint_commands(). Given absence of finer grained resetting, we get to do it all the time. */ - if (extra_string != NULL) - update_dprintf_command_list (this); + update_dprintf_command_list (this); } /* Implement the "print_recreate" method for dprintf. */