From patchwork Wed May 31 14:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 70390 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 DCC7F385735E for ; Wed, 31 May 2023 14:40:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCC7F385735E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685544013; bh=CD+vjM7Hp/Ex5CGCwEzT1wa5IM19NMRKcR4+J7OQ0hE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ihcf/G20Mc6XX066yxA8j5BV3L1HV4Woki4DsVAETjOsrZ17jO53bvziUswAVnuVN VGFV7GKxMTnQLpCcSPRCJjEYmA2ZUCVpgCinu7ocujFICkk3StIev13pkqOcYKgGQE cigdJ0u7EkTdhCBDVsP3GWGyY8e7v06CVrdWNrdg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 430593858D20 for ; Wed, 31 May 2023 14:39:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 430593858D20 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-33bbb78248fso8658685ab.0 for ; Wed, 31 May 2023 07:39:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685543982; x=1688135982; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CD+vjM7Hp/Ex5CGCwEzT1wa5IM19NMRKcR4+J7OQ0hE=; b=Sn9BkTkzmqJei5IWLRq3k3S+agm5JLTxtLuGDSopctC0CDcqNcjB1owXL2pmlM0A2x 3JgxL5rZ8yx1AfQVadzgRyqzPKE4AtRyTGPnp695ru/aLDyHXaUwuPCrE6gx2QAng64M D6MuE7Nftwt/ydTrA2D9MDFduR4FHFSGhcDfgh6G5zteVFY34eWkoOB3PTOtY9zfg245 TtyL0ZvQMSwfS/q4OMP4ODPJA/0MB8vL5jx8fs3gxJuQd2t5llwe7+K6esWT3BHIDPpb dJtjP2yXR3VH5NhYNc7fYKx3SwUbdZVaskonuH0nSYn25e8t5YtiAxJ3xUR4GEMxZ5GV wRCA== X-Gm-Message-State: AC+VfDzJs5UGmmwG4XscOBMo0DyFDE5Ky4hIyoJqdPmbyr0tGt38orX3 ljnYjszgh1YARor/Y46FM2ss0RNPMj2HrWXlM1gnkQ== X-Google-Smtp-Source: ACHHUZ7/QlFTtuyEKJsykM+dMlkeLAuL3xQWqNjB8WIEQ/4sgbmoI1KvSBSAJqAbzkQ4aPz5lkeIgQ== X-Received: by 2002:a92:cf02:0:b0:338:d50f:f5e2 with SMTP id c2-20020a92cf02000000b00338d50ff5e2mr2880257ilo.18.1685543982324; Wed, 31 May 2023 07:39:42 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id y3-20020a92d0c3000000b0033c01c407fbsm288853ila.31.2023.05.31.07.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 07:39:42 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Improve MI -dprintf-insert documentation Date: Wed, 31 May 2023 08:39:32 -0600 Message-Id: <20230531143932.3487356-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I found the documentation for -dprintf-insert a bit unclear. It didn't mention the possibility of multiple arguments, and I also noticed that it implied that the format parameter is optional, which it is not. While looking into this I also noticed a few comments in the implementation that could also be improved. Then, I noticed a repeated call to strlen in a loop condition, so I fixed this up as well. Reviewed-By: Eli Zaretskii Reviewed-By: Andrew Burgess --- gdb/doc/gdb.texinfo | 9 +++++++-- gdb/mi/mi-cmd-break.c | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a179af77224..fc55c4e7b43 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -32328,10 +32328,15 @@ times="0"@}]@} @smallexample -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ] [ -c @var{condition} ] [--force-condition] [ -i @var{ignore-count} ] - [ -p @var{thread-id} ] [ @var{locspec} ] [ @var{format} ] - [ @var{argument} ] + [ -p @var{thread-id} ] [ @var{locspec} ] @var{format} + [ @var{argument}@dots{} ] @end smallexample +@noindent +Insert a new dynamic print breakpoint at the given location. +@xref{Dynamic Printf}. @var{format} is the format to use, and any +remaining arguments are passed as expressions to substitute. + @noindent If supplied, @var{locspec} and @code{--qualified} may be specified the same way as for the @code{-break-insert} command. diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 082c4da58a3..0777fcbd35e 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -93,8 +93,8 @@ setup_breakpoint_reporting (void) } -/* Convert arguments in ARGV to the string in "format",argv,argv... - and return it. */ +/* Convert arguments in ARGV to a string suitable for parsing by + dprintf like "FORMAT",ARG,ARG... and return it. */ static std::string mi_argv_to_format (const char *const *argv, int argc) @@ -102,9 +102,9 @@ mi_argv_to_format (const char *const *argv, int argc) int i; std::string result; - /* Convert ARGV[OIND + 1] to format string and save to FORMAT. */ + /* Convert ARGV[0] to format string and save to FORMAT. */ result += '\"'; - for (i = 0; i < strlen (argv[0]); i++) + for (i = 0; argv[0][i] != '\0'; i++) { switch (argv[0][i]) { @@ -151,7 +151,7 @@ mi_argv_to_format (const char *const *argv, int argc) } result += '\"'; - /* Apply other argv to FORMAT. */ + /* Append other arguments. */ for (i = 1; i < argc; i++) { result += ',';