From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 6E03C3858D39; Sun, 31 Mar 2024 10:28:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E03C3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711880898; bh=K/g42fOqviyzwelss9yyIw0sps3kvTWe378g9obqxvE=; h=From:To:Subject:Date:From; b=Q56Xhm1oo06U2L8oy0P1N+sBDJGhsx+tF6XPpw7Sn9wkUDCZWKsyCNkhjp2ATQKqK jb5GYN/CsLoT3R2UlDNLEK9KbMqlmgoPBqA4kik1qgb4f1bahGyY9P/j0mtnFeNjO1 6dbZMJu6gCU+dzC2hJ71+zAXjt7Fd1+teJg/mGxM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: change 'if' to gdb_assert in update_dprintf_command_list X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: ea020765286f1573abf95753c3f66c7e5e20a551 X-Git-Newrev: 3d42db971fc7cb0a5fe9b4526b12539019b5c27e Message-Id: <20240331102818.6E03C3858D39@sourceware.org> Date: Sun, 31 Mar 2024 10:28:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3d42db971fc7= cb0a5fe9b4526b12539019b5c27e commit 3d42db971fc7cb0a5fe9b4526b12539019b5c27e Author: Andrew Burgess Date: Wed Apr 5 15:37:00 2023 +0100 gdb: change 'if' to gdb_assert in update_dprintf_command_list =20 I noticed in update_dprintf_command_list that we handle the case where the bp_dprintf style breakpoint doesn't have a format and args string. =20 However, I don't believe such a situation is possible. The obvious approach certainly already catches this case: =20 (gdb) dprintf main Format string required =20 If it is possible to create a dprintf breakpoint without a format and args string then I think we should be catching this case and handling it at creation time, rather than having GDB just ignore the situation later on. =20 And so, I propose that we change the 'if' that ignores the case where the format/args string is empty, and instead assert that we do always have a format/args string. The original code, that handled an empty format/args string has existed since commit e7e0cddfb0d4, which is when dprintf support was added to GDB. =20 If I'm correct and this situation can't ever happen then there should be no user visible changes after this commit. Diff: --- gdb/breakpoint.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 044d424d06c..8346c43925c 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8529,8 +8529,9 @@ update_dprintf_command_list (struct breakpoint *b) const char *dprintf_args =3D b->extra_string.get (); gdb::unique_xmalloc_ptr printf_line =3D nullptr; =20 - if (!dprintf_args) - return; + /* Trying to create a dprintf breakpoint without a format and args + string should be detected at creation time. */ + gdb_assert (dprintf_args !=3D nullptr); =20 dprintf_args =3D skip_spaces (dprintf_args);