From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by sourceware.org (Postfix) with ESMTPS id CF4043858D1E for ; Mon, 4 Apr 2022 14:34:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CF4043858D1E 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-f53.google.com with SMTP id d29so8760178wra.10 for ; Mon, 04 Apr 2022 07:34:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=7NLkDJpIqCxU9vBhGFwHsuS/Ek5PlT8sEqziYRSXCjw=; b=eKl+Dg/APJ5VsU7SajUsQBsPRX4iA6O9iO4itChdZekcBkBdhLm4FF/X8uvSi6J7rJ sJTb/gPLfPi8+TZuexzgLCq21zcOW2IbHThMbGUHi42zqZSDiAfeXvjoMP6U82MgjOrs f3VeBinW6g+4U/a3UCLvD2Cc9z0za50R3f70rEuqUuI9/misTxvCVrF+edT5P7Xgid88 PCylAPfecglgbOI7nmaAq53odVBnrQ3h9CIPeqwgjLvLESh3jLmEmwaXDORhZv4EiDSU 5FnxDhtiRQLibv8j9Aq84J3xxxy1mngWFXa5Wp32TxVcRPoGYRq+1FyjX61xQIgutGZX fzSw== X-Gm-Message-State: AOAM531Im6jL2K41fDIpzgfIkfCI9Nu+29fdbfnTL7pdyM1gs/L1cxgu RMGPAtmHTYORYsbY6L1GGyMGBqXUiyo= X-Google-Smtp-Source: ABdhPJyILRzKAMmyuRBi+ysluSYVTxaH/a7toi2qhoJOGQtpT9bTlkNVI2jXmWmUXaBSxucGqV3NZQ== X-Received: by 2002:adf:e542:0:b0:206:1795:4984 with SMTP id z2-20020adfe542000000b0020617954984mr1825561wrm.575.1649082886755; Mon, 04 Apr 2022 07:34:46 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id e8-20020a056000178800b00203da3bb4d2sm10905614wrg.41.2022.04.04.07.34.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 07:34:45 -0700 (PDT) Message-ID: <542fdf92-fe28-b9eb-9d7e-d46805400b42@palves.net> Date: Mon, 4 Apr 2022 15:34:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 2/3] gdbserver/linux: Access memory even if threads are running Content-Language: en-US From: Pedro Alves To: Lancelot SIX Cc: gdb-patches@sourceware.org References: <20220330124319.2804582-1-pedro@palves.net> <20220330124319.2804582-3-pedro@palves.net> <20220330132033.y3w4iyuedj76rfxd@ubuntu> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 04 Apr 2022 14:34:50 -0000 On 2022-03-31 12:39, Pedro Alves wrote: > On 2022-03-30 14:22, Lancelot SIX wrote: >>> +/* Helper for read_memory/write_memory using /proc/PID/mem. Because >>> + we can use a single read/write call, this can be much more >>> + efficient than banging away at PTRACE_PEEKTEXT. Also, unlike >>> + PTRACE_PEEKTEXT/PTRACE_POKETEXT, this works with running threads. >>> + One an only one of READBUF and WRITEBUF is non-null. If READBUF is >>> + not null, then we're reading, otherwise we're writing. */ >> >> Hi, >> >> Seems to me that this property can be asserted. WDYT? >> >> Something like >> >> gdb_assert ((readbuf == nullptr) != (writebuf == nullptr)); >> >> should do. >> > > Doesn't hurt. I've added that locally. Thanks. Funny enough, it does hurt... Running the testsuite with that change shows the assertion triggering. This is because GDB may ask to write LEN==0 bytes, and we have this int target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, ssize_t len) { /* Make a copy of the data because check_mem_write may need to update it. */ gdb::byte_vector buffer (myaddr, myaddr + len); check_mem_write (memaddr, buffer.data (), myaddr, len); return the_target->write_memory (memaddr, buffer.data (), len); } ... and buffer.data() may return NULL if the vector is empty. I've added a new patch to the series to add an early return if len==0. I'll send a v2 series in a bit.