From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 DC3603858C52 for ; Wed, 4 Oct 2023 14:40:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC3603858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696430449; 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: in-reply-to:in-reply-to:references:references; bh=EdKEDlgPgJM7WjBRfTxY/Q0FQfinveovqLOm2qNF0tw=; b=JBUBcjrcy62OPd3wSYwdG/wK0G4t3geiYuubGC92xECCJieb0GJYmTkA3o0cachByzfrla DTb+oG3rl+GIm1hcvfGtG5MbE+YrNHj+Kl/jPnPv3/5p6afEFtWw5tA9snETWjxpe094ex 7w+OrxhQ9CQUchEUA1ykEGXTMmzOlKQ= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-dFWITRneN4-QZvVXn1ey3w-1; Wed, 04 Oct 2023 10:40:37 -0400 X-MC-Unique: dFWITRneN4-QZvVXn1ey3w-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5378cd83621so1968011a12.1 for ; Wed, 04 Oct 2023 07:40:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696430436; x=1697035236; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EdKEDlgPgJM7WjBRfTxY/Q0FQfinveovqLOm2qNF0tw=; b=XhNyZJZxcUWcnT1WS93TAFvvKgX6Ec6QlN4wHLzSq5h5bpwvk/COj3wjwYYtgWVCbC f1o/31WnMAw5xjHxs5ySBmk9lB2sWd6JJSXYX2iLyEk0zCnC5t+FU+70feHn6MQbFdey Mrs9/cZ+6OItE6q+h370lTuWfMDPRicwNaGoIClwJXKrwCDMuBabY86cWT3FznG5SXBe zxdgOY3QVPQg0AtpflVAh2OqFpUVkqCndSQrZAyQwFvQ8lUzTH+LbbG8F55jHuou7kA9 pPzvQkbGHS/z7/LOW5rxhxJq1fSvlzmTx5+HwUO3UXuz/c00LPLOx8FH+eXcUxRXV/Da Vn7w== X-Gm-Message-State: AOJu0YyxMDTJBth0Dp9Hgr6tfr7MPQXDMs7yNDAJaHmFGlxMjmsXWRoS L3pPheeCs2lc2w+8McVVKrXCmUKs+822p+IuLCkuzcuiHNfZ8bO2Po+BraBNRuOlh7y69veexzX 96kKYuAzdUxJPrXjr/ZUuFx2UiH0XpA== X-Received: by 2002:a05:6402:344a:b0:525:bbc0:2a8c with SMTP id l10-20020a056402344a00b00525bbc02a8cmr2279267edc.33.1696430435961; Wed, 04 Oct 2023 07:40:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENUMhfbKCK79mzQAZVxtx5a4RksWUUC95RkuWkQkanal1jYXhzUU7J7Y3U7OHfWERTYj0W3g== X-Received: by 2002:a05:6402:344a:b0:525:bbc0:2a8c with SMTP id l10-20020a056402344a00b00525bbc02a8cmr2279255edc.33.1696430435639; Wed, 04 Oct 2023 07:40:35 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id o18-20020aa7c512000000b00537efd5f1a8sm2526309edq.69.2023.10.04.07.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 07:40:35 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , Andrew Burgess via Gdb-patches Cc: Andreas Schwab Subject: Re: [PATCHv2 4/5] gdbserver: cleanup in handle_v_run In-Reply-To: <87y1gjy0xq.fsf@tromey.com> References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> <101de2688bc146244f0ae89477cfd4adf3606551.1695835626.git.aburgess@redhat.com> <87y1gjy0xq.fsf@tromey.com> Date: Wed, 04 Oct 2023 15:40:33 +0100 Message-ID: <87v8bmwivy.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tom Tromey writes: >>>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: > > Andrew> After the previous commit there is now a redundant string copy in > Andrew> handle_v_run, this commit cleans that up. > > Andrew> + /* Buffer to decode the argument into. */ > Andrew> char *arg = (char *) xmalloc (len + 1); > ... > Andrew> hex2bin (p, (gdb_byte *) arg, len); > Andrew> arg[len] = '\0'; > > Not really your problem, but since you're changing it anyway, using the > byte_vector form of hex2bin would remove some manual memory management > here. I see two problems with that plan. First, we currently run hex2bin on a slice of a larger string buffer, the slice is not null-terminated. The current hex2bin that returns a gdb::byte_vector expects a null-terminated string (it uses strlen internally). We can easily solve this by adding an overload of hex2bin that takes a gdb::string_view, except... ... for the second problem, which is the result of calling hex2bin is passed off to either new_program_name or the new_argv vector. There's no way to "release" the memory from a gdb::byte_vector, so we'd end up copying the contents into a malloc'd buffer anyway, like: gdb::byte_vector vec = hex2bin (gdb::string_view (p, (next_p - p))); const char *arg = xstrdup ((const char *) vec.data ()); Which I'm not sure is really any better than we have right now? Did you have something else in mind? Let me know and I'm happy to have a look at an alternative approach. Thanks, Andrew