From nobody Tue Nov 26 06:41:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709705877; cv=none; d=zohomail.com; s=zohoarc; b=Z3jPUriQrWzaVzjAmsxjNquYEfMAFBqIhq7sjdIZd5M8IHRuuQtNvKdu7FokEn7sKe4ZJZ1Bn1A7PvC4l3jumGx6DkbWOOZjkhssG9dUQDNZAzT83t+BQrJmwgXT4iGZEMTBI/t08mKZr49dmeP/OI/yaTQ40WZ+7doUGPGYF/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705877; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=iQjqYKs847rav3KkBII9aG/GxUwNXDk74Lvwmwu5SoqiuY3M+I2Ednk1OEoCmDZKNcYmbF7scuYqSmOBv3g7TvT32hBNfjo1O15CwV3T1ImpqgomWCFKORa7ZVGjKr2RxF+gexxrfrIOEerMSvo6yot0r/Q/rKlX4SnBIO0Uip0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709705877527838.6883666676136; Tue, 5 Mar 2024 22:17:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkXA-0006GN-DQ; Wed, 06 Mar 2024 01:13:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWc-0005Ni-Ai for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:14 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWa-0006K1-Cl for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:09 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dd178fc492so21316255ad.2 for ; Tue, 05 Mar 2024 22:13:07 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id s9-20020a170902988900b001dc3ef786f9sm11617879plp.308.2024.03.05.22.13.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705586; x=1710310386; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=awIkjGG97cQD04nPmjSlI9R2DPp5Xo80X02aSklKkEsQWa8aAOh5Yj3O2TalRF5Xpo t2/pecNc7G/+0ksulMzFbfjZvwgO7RtTiC9YDxFaMzHUERZxIUaAMYN2q/hgj0qUoXtt frUk1bFBq+bwAsoi1hKqoHe8OorbvNSD00gI/OOddIr0Fg5aBB/zT8TjwgY3JcVmOJyr XJyyruoHlAIfagigTAXjaHgL/DYfyU/u2piAgiOkMyN06C542DiVzlU8hgdPT8LTzGX8 4tY+ypyxzByDvtC20fiXeFjN+cJx8gqSTDwlqCK3F6U51KYzC7Z5+1Jr4F6exVqfb6Lk GYJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705586; x=1710310386; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=FI6EbCy56Nk2lAQgb/Shhos5kesvhgZTokumoBrVv6c03S+jHSB/J1XwSzt8sq0WB/ wMsEjRUO1VTFVquq+zv0ItvH3xtdDXlj97V9QpRqVSOP8mZyyqm3GO6tas8YhLwJfgEc FKilE8afETbMGI/SXL/8NVnORzHDQ1xOLlGUtQFrjqrQo4owmwOtugkktizAlgVLud2x bRICfqyHmapqJ2zhYmHTKYKntk+S+UEs95NaKzTDncGS1PwVyw67TYgWWTguzfQNWFNA ksBZLO9lM2eNueLSvpB9tJ4cKN5yBcC4IMpfcvVUnUnUFM0RBEqSnlO9StNKccengnMi SVig== X-Gm-Message-State: AOJu0YxAh1fjRgRMvfv2l165F9BUlhtb2+c9csWGvN9jXsnG2SGVXbNC rHVn7cfARsFMlpTJ90eaAe8+ZyAEoIn2QzuiIiclkHgQ5ucgWH0432upgtiVEc4= X-Google-Smtp-Source: AGHT+IH9pIVIF0ENYYG9PeRqLVnU1y/kU+LQR7lftfdwgK3RObineI/3jGNd83iaYMyO+qRGISfa9g== X-Received: by 2002:a17:902:c1c5:b0:1d9:8f6e:86e8 with SMTP id c5-20020a170902c1c500b001d98f6e86e8mr4057960plc.69.1709705585988; Tue, 05 Mar 2024 22:13:05 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:23 +0900 Subject: [PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-17-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705878359100001 This removes the need to enumarate QEMUCPUState twice and saves code. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index a22c057d3ec3..7d896cac5b15 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -66,7 +66,7 @@ static bool init_states(QEMU_Elf *qe) Elf64_Nhdr *start =3D (void *)((uint8_t *)qe->map + phdr[0].p_offset); Elf64_Nhdr *end =3D (void *)((uint8_t *)start + phdr[0].p_memsz); Elf64_Nhdr *nhdr; - size_t cpu_nr =3D 0; + GPtrArray *states; =20 if (phdr[0].p_type !=3D PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,38 +74,29 @@ static bool init_states(QEMU_Elf *qe) } =20 qe->has_kernel_gs_base =3D 1; + states =3D g_ptr_array_new(); =20 for (nhdr =3D start; nhdr < end; nhdr =3D nhdr_get_next(nhdr)) { if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { QEMUCPUState *state =3D nhdr_get_desc(nhdr); =20 if (state->size < sizeof(*state)) { - eprintf("CPU #%zu: QEMU CPU state size %u doesn't match\n", - cpu_nr, state->size); + eprintf("CPU #%u: QEMU CPU state size %u doesn't match\n", + states->len, state->size); /* * We assume either every QEMU CPU state has KERNEL_GS_BAS= E or * no one has. */ qe->has_kernel_gs_base =3D 0; } - cpu_nr++; + g_ptr_array_add(states, state); } } =20 - printf("%zu CPU states has been found\n", cpu_nr); + printf("%u CPU states has been found\n", states->len); =20 - qe->state =3D g_new(QEMUCPUState*, cpu_nr); - - cpu_nr =3D 0; - - for (nhdr =3D start; nhdr < end; nhdr =3D nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - qe->state[cpu_nr] =3D nhdr_get_desc(nhdr); - cpu_nr++; - } - } - - qe->state_nr =3D cpu_nr; + qe->state_nr =3D states->len; + qe->state =3D (void *)g_ptr_array_free(states, FALSE); =20 return true; } --=20 2.44.0