From patchwork Fri Jun 30 18:04:20 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: 697974 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp597090wrs; Fri, 30 Jun 2023 11:14:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlEPTxlDGMOuUR+zMKlL/e2g0KOmNTo4QVW72CFnHgqt1aIQbaEzfRtyx5Cm8lUH+IExMZIX X-Received: by 2002:a05:6359:67a3:b0:134:e301:2c21 with SMTP id sq35-20020a05635967a300b00134e3012c21mr3747068rwb.15.1688148895863; Fri, 30 Jun 2023 11:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688148895; cv=none; d=google.com; s=arc-20160816; b=amranCgFeMqocq6JZBu2h036dUz1fxjv0iiPhW/o5yi36lDbHyu24rDMiMykWsNysR ZGkW06aA5OVmkk3ABSsDT3p1KZhu4gyv3jb3b0FXo5CKgZtDWNpPyya/5MkG+VIqeLMz QksTWVmWdiNZfgTYzhlslRnrliz2Pt634Yg+PvVV0dE9rxY0nDt4L/sDPBGrOKRbXsrO GID09X0GRx/fDtLYXsOvpk3YSSTHIJzRE915bjjgYg0chj5wXTNDkIVCe5UXq1v+z1C3 lofKVH5SS9xLkc5D9w7eyCQzOKspf5jICDC4j+4vvGKCP35TZWuw64t79D+tcKso1VGP 8tVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oenQvTjQMNLdspNzkaNvCWQ+SG7wcPXLwQUq75k2j/o=; fh=WuTBZDcfojtFbKfkJjfEwZ/JCpHxFhyq5cXQ7fdJG7M=; b=GcnTHlaIRGEqQQwAB9asaMwjzCRrh43OKQKwAs66i1s2oj0f0zVdxzNHDzafmP897B 34QjekjSR/j3NtpC+7eTAPRzaSAkJa0oUQv/O/+5Ig4Cud3FkSqRSLHNREOBwPD7ouOU vEYZvInXlbj9c7zheI+ZaJDEb/mV7pR3nKJ9EQ9KJGFjOoqIdF9fIXjD8OO3gTNkVA+/ NwEgbiyPKWuUIupUP0rAe/WinJ6QGGgcEtZNM8i8PzPXGijgCQ0NLVB87AVMHa855waH Y0O5lmYxd61pL9vR+ezAhgLokRBjXGfPaI7sXZfd2UZ6X3ErgtK6m6m8Bamt5fuJ3M9P c1Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qddmp1xb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id qz10-20020a05620a8c0a00b00765b3212b78si6483010qkn.564.2023.06.30.11.14.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 11:14:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qddmp1xb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qFId9-0005oV-In; Fri, 30 Jun 2023 14:14:03 -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 1qFIcm-0005at-Pd for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:43 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFIci-0003Yk-H3 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:40 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso4388015e9.3 for ; Fri, 30 Jun 2023 11:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688148815; x=1690740815; 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=qddmp1xbc6xCFtXNg6HPx+/yEITPjZ7FmfWXcpyu8GOdwqfQNX1wWjNHkzEYyjP/0Y CjRzjpMRFhVYkpjQC4AGC1BC6m1HV3L0DJ203NqRhb99xEjFXuK8RfYwU/dYGFuK5IST KkS6uKM4Mc3LmTXfYojoVozWN7qV1wQXRzWN2K5ABJ42Q6XRtirMKIvA1tE9ktvo7wZF o0z5QbC95CYpGFnbj3+CJ4q6bViIsbNeepfWv6929CaajyhXij0uOIHrkhCwZaAwsReu 72EVM5leGW/32wFikyQcf4mE+hPX6bNL2oAnzzKbFc9JS/V8YWL+eZ5b4Tqg5WedhS0B Zk8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688148815; x=1690740815; 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=Bvfuyp/doTdC/E1sPmtKF6duEPa6T6dP8XY5b909+kUAyVhwD63+JAKvmVOR9ypApu /q4nF6jJ4DcD1EJ5L7igLjblo8qvnKG9QTT61wdVc8P3i+LQW9QJkwvDt5kJgr5JFAaq W/fKLk3Kuex3+o69gQdq8nSzn8MBqFsaDDnWbiW8Epl7BhYvVKS3hLn+MlhoaM4PA+4J 0H70u2IgooE8a/IhTdwWsTS7NydvrewyGYQRcc9KoxY61ajVxb6J/x5euKdst86SA22R xyrf8hu1h4Y2aPN2HFreBRNz7PXwShtSEKP3ZmwqZMWdFugTWDaHu7lxIRNEBHLTLP2m hwnA== X-Gm-Message-State: AC+VfDw7CMm49vBXQXcmiJrGOQqk7AD/vkJP56Hu6JVTAG8AJAFIijJM SvUnjVfdQ78sf1nF0NtMrfhiug== X-Received: by 2002:a05:600c:2253:b0:3fb:a5b3:4f02 with SMTP id a19-20020a05600c225300b003fba5b34f02mr2623714wmm.36.1688148814971; Fri, 30 Jun 2023 11:13:34 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id c13-20020a7bc00d000000b003f735ba7736sm19916239wmb.46.2023.06.30.11.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 11:13:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EE3751FFDC; Fri, 30 Jun 2023 19:04:27 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Paolo Bonzini , Stefan Hajnoczi , Leonardo Bras , Laurent Vivier , Peter Xu , Juan Quintela , Beraldo Leal , Radoslaw Biernacki , Qiuhao Li , Peter Maydell , Yanan Wang , Riku Voipio , Wainer dos Santos Moschetta , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Thomas Huth , Laurent Vivier , Bin Meng , Marcel Apfelbaum , Bandan Das , Cleber Rosa , Richard Henderson , Leif Lindholm , Marcin Juszkiewicz , qemu-arm@nongnu.org, Darren Kenny , Alexander Bulekov , Ilya Leoshkevich Subject: [PATCH v4 35/38] gdbstub: Report the actual qemu-user pid Date: Fri, 30 Jun 2023 19:04:20 +0100 Message-Id: <20230630180423.558337-36-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230630180423.558337-1-alex.bennee@linaro.org> References: <20230630180423.558337-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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'; }