From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by sourceware.org (Postfix) with ESMTPS id 420E13851C35 for ; Thu, 22 Oct 2020 16:09:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 420E13851C35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wm1-f65.google.com with SMTP id l15so2890784wmi.3 for ; Thu, 22 Oct 2020 09:09:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JL+DTd5LzGmjkABJ+TIdcFFnXoDpX+ZF9rpFVG2wmGI=; b=lhw1MeXhbvKJPShiuYqMDAtMScawvnpTg3EjL7+u5v+BahzJ9iY0eDUMI2OB7pBxkY YOuAbyZLilH0ize/lIncb141X1Gt6nMCBgSJ3KwTn6PSthglj/injCJF8TU7isLgje6k mCM5DMU146Avh3pGjBcT6mz/7+MOEa4MWjSChFFHfyQiLusvfWG64JM1EKhY4WfykNSa ZOOKDResD2LIJ3VcLFwEm1fmPxYnIHKeGq/ffv6Z5iyfwBG6/gzAwuoYNTob9naUbHZS C3f+ABLtKymcul9LWlldECIkjtTfvjd+L4cEf+neUTmdSl4BP4I4duY9DQMAU62+GKuK fVgA== X-Gm-Message-State: AOAM533KSYIwVBk/UebX+jSFyqUGAEGdZtjvWFDBaPvbm1hZSsam6/eS +YnHSPJRgRAMb5vFgSN2/zQjQiRWz2zMkQ== X-Google-Smtp-Source: ABdhPJy2ZESWePe3GSB/Ts8nrvznkOgXppCekFR/n3wFsw0UFflajcYIhUhuv1Q5Or6/vniR8oxcsA== X-Received: by 2002:a1c:49c2:: with SMTP id w185mr3226431wma.70.1603382957555; Thu, 22 Oct 2020 09:09:17 -0700 (PDT) Received: from ?IPv6:2001:8a0:f91e:6d00:f223:ef68:24e0:af8f? ([2001:8a0:f91e:6d00:f223:ef68:24e0:af8f]) by smtp.gmail.com with ESMTPSA id u195sm4889950wmu.18.2020.10.22.09.09.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Oct 2020 09:09:16 -0700 (PDT) Subject: Re: [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out To: Tankut Baris Aktemur , gdb-patches@sourceware.org References: <1601998842-22089-1-git-send-email-tankut.baris.aktemur@intel.com> From: Pedro Alves Message-ID: Date: Thu, 22 Oct 2020 17:09:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1601998842-22089-1-git-send-email-tankut.baris.aktemur@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 22 Oct 2020 16:09:23 -0000 On 10/6/20 4:40 PM, Tankut Baris Aktemur via Gdb-patches wrote: > When executing commands from Python, the API provides an option to > capture the command output in a string and return this to the user. > See the `gdb.execute` function at > > https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html#Basic-Python > > When the `to_string` argument is True, the output of the executed > command is supposed to be captured and returned to the caller. For > this, GDB temporarily redirects the ui-outs to a string file. > > However, output does not get captured if the executed command prints > its output through the top-level interpreter's ui-out. E.g., in the > following we still see the output being printed. > > (gdb) python gdb.execute("inferior 1", from_tty=False, to_string=True) > [Switching to inferior 1 [] ()] Note this output is not really considered output of the command. It's asynchronous output sent to all UIs in reaction to the inferior-switching event. If e.g., the top interpreter is MI (say, you run that python from a breakpoint command), then you get: (gdb) python gdb.execute("inferior 1", from_tty=False, to_string=True) &"python gdb.execute(\"inferior 1\", from_tty=False, to_string=True)\n" ~"[Switching to inferior 1 [] (/home/pedro/gdb/binutils-gdb/build/gdb/gdb)]\n" ^done (gdb) And your patch won't capture that: python str=gdb.execute("inferior 1", from_tty=False, to_string=True) &"python str=gdb.execute(\"inferior 1\", from_tty=False, to_string=True)\n" ~"[Switching to inferior 1 [] ()]\n" ^done (gdb) python print(str) &"python print(str)\n" ~"\n" ^done (gdb)