From patchwork Tue Jun 27 16:09:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1800700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ih2wexnc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qr8xM45zTz242H for ; Wed, 28 Jun 2023 02:17:11 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEBMH-00011q-Cj; Tue, 27 Jun 2023 12:16:01 -0400 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 1qEBME-0000ya-Du for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:15:58 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEBMA-00088p-Fd for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:15:58 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-313e34ab99fso3936693f8f.1 for ; Tue, 27 Jun 2023 09:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687882552; x=1690474552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oenQvTjQMNLdspNzkaNvCWQ+SG7wcPXLwQUq75k2j/o=; b=Ih2wexncfGfDwD/HAFokzszaawhjM6uXNHK7B6jp2MzfjbW9DldwHEyzIji3TXQl1E 5WBYFZznMG5OEMZd4XnACFVvna6jclk2uDjNJtmIpIY8FjrRYYZmZYTGCTcMXhl3fCg4 /sFik4pCIs4FgGanbatBlgfpTiVunY9tKbi76zC5qKzSNUAA+QPUI99LZhRqYC9IBLRY SBEXA/6agLb/T5ikQl8nzgqpCZk0r6DK8rLhLPoShxLeTpMhxm2yljngOhK/MVF+6xWT y0IZa9AgBBkVv/Gh7sWhxDa0rGhLTgC7/Wr22A8XsJzGIWC0Iohqxgr89xYZgc1Br3oF qrPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687882552; x=1690474552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oenQvTjQMNLdspNzkaNvCWQ+SG7wcPXLwQUq75k2j/o=; b=DzzxDOt70iN2MBjyls0ZFPO4qQ5Dz9tT75jKAMnDvE5X2xgLLWO69LbmlSpPyKsjMG KsJQy10vKzR2TBoOpK8UOoocdEMUKTJUhsVad5eGllHcXfTa1tJ7vmDTnQ8tN1es5OSO HEAngZkepNoIhFbAJJ3dRiZpyg2seZuW1rjkpqn7+GNJRUKpOWirQuo0UaOhXv2PT9Xx KAnanQqep6v568UjFTME7ZbaP05/GQ9vOPVy4YoEfDIc4jmzK7icX/s3MPl+w3YeX33K Md1TpKt2RyOHl/uG7mBZ/+r17UhSh1ybBuVl4x0SDQF/9VEbfK78iIev1EWoVbAsdnkn rMYQ== X-Gm-Message-State: AC+VfDw9UqPe98fso0KzmppbxR40n/rx9QFurn28IybbNU4QiNEBHnGv TIAlaw4Tji/vJxPjVIhsnyLicA== X-Google-Smtp-Source: ACHHUZ5hTecw3uehCRTZDg7qKugQXb9yF53OPXqoVVolUsJB+qo+YqnFEuji2gzIPviec/LiIYQLxA== X-Received: by 2002:a5d:4a0e:0:b0:30a:e6d2:3ce3 with SMTP id m14-20020a5d4a0e000000b0030ae6d23ce3mr23425908wrq.16.1687882552435; Tue, 27 Jun 2023 09:15:52 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id n2-20020a5d67c2000000b003127741d7desm10713516wrw.58.2023.06.27.09.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 09:15:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C2A7D1FFDB; Tue, 27 Jun 2023 17:09:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Juan Quintela , Thomas Huth , Cleber Rosa , Leonardo Bras , Beraldo Leal , Peter Maydell , Bin Meng , Yanan Wang , Darren Kenny , Alexander Bulekov , Marcel Apfelbaum , Peter Xu , Radoslaw Biernacki , Laurent Vivier , Paolo Bonzini , Eduardo Habkost , qemu-arm@nongnu.org, Stefan Hajnoczi , Richard Henderson , Bandan Das , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Alexandre Iooss , Marcin Juszkiewicz , Leif Lindholm , Laurent Vivier , Qiuhao Li , Mahmoud Mandour , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Ilya Leoshkevich Subject: [PATCH v3 33/36] gdbstub: Report the actual qemu-user pid Date: Tue, 27 Jun 2023 17:09:40 +0100 Message-Id: <20230627160943.2956928-34-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627160943.2956928-1-alex.bennee@linaro.org> References: <20230627160943.2956928-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ilya Leoshkevich Currently qemu-user reports pid 1 to GDB. Resolve the TODO and report the actual PID. Using getpid() relies on the assumption that there is only one GDBProcess. Add an assertion to make sure that future changes don't break it. Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20230621203627.1808446-6-iii@linux.ibm.com> Signed-off-by: Alex Bennée --- gdbstub/gdbstub.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ce3e4a2671..697dd4bbad 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -202,13 +202,16 @@ void gdb_memtox(GString *buf, const char *mem, int len) static uint32_t gdb_get_cpu_pid(CPUState *cpu) { - /* TODO: In user mode, we should use the task state PID */ +#ifdef CONFIG_USER_ONLY + return getpid(); +#else if (cpu->cluster_index == UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ int index = gdbserver_state.process_num - 1; return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; +#endif } GDBProcess *gdb_get_process(uint32_t pid) @@ -2137,19 +2140,25 @@ void gdb_read_byte(uint8_t ch) void gdb_create_default_process(GDBState *s) { GDBProcess *process; - int max_pid = 0; + int pid; +#ifdef CONFIG_USER_ONLY + assert(gdbserver_state.process_num == 0); + pid = getpid(); +#else if (gdbserver_state.process_num) { - max_pid = s->processes[s->process_num - 1].pid; + pid = s->processes[s->process_num - 1].pid; + } else { + pid = 0; } + /* We need an available PID slot for this process */ + assert(pid < UINT32_MAX); + pid++; +#endif s->processes = g_renew(GDBProcess, s->processes, ++s->process_num); process = &s->processes[s->process_num - 1]; - - /* We need an available PID slot for this process */ - assert(max_pid < UINT32_MAX); - - process->pid = max_pid + 1; + process->pid = pid; process->attached = false; process->target_xml[0] = '\0'; }