From patchwork Tue May 15 18:19:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 135913 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1369892lji; Tue, 15 May 2018 11:20:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq8WSs+M7fbwPpa/Fqfp081VemAAGqrKBrJQz2Uf4+TFK3cJgQDsnQsi6yv+OnjJ8V9ecmt X-Received: by 2002:adf:ba91:: with SMTP id p17-v6mr10950462wrg.125.1526408400978; Tue, 15 May 2018 11:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526408400; cv=none; d=google.com; s=arc-20160816; b=Mg3WMOd7y2m3Pr7BJKkYNrIrjQN0Fg2fT8BnKau1JfdbR5tZirR4tSh/ycq/ihzVb9 kqbJJpBQGRfWbLreFCE0AdRYPNjy71rFExb2kse5MX/mG+hAeJnjr7RwS27NEM41jkyX lA8Oo2avfomUp2O09c9hxgag7Ure992QrX6lTojNUXBudJrXrC8/+V84qlzuTjr+Jsy/ J3+tOo6gaF/O/cLgB7m5LR27uJ7otCHib9OhhOL++3utIeQWxlJDJf7Q9xuiyw6xA4Pw Xe4T/1s4A1YXrYjLsAHNDS69hRfwshyc8p7CW6TZycfDo05pB12E7aJw5t0rS0EE5pt9 n2Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=5JysN1rOu3UZZF1B3EjJ2RU2X7ErFPBV6JcUJFAeQQU=; b=TlMkRZIyUgQ1gyGRdBucL65vC7hjoRw4xawwfAHpZcRY+CZkfWOt/o8WRquWznPCYn 7KMYJQuVFmIWVdhYNgrIxJk0gS/OS71sPQnSS3aOoo6YxwGCjkZ59ippvkqf1Q54ohsb F75MJu0w1MetDBMfr5NqZGHjym9XSZI9RmOnk9wrreXMuhGOk1A3Mi9IHgiorF8jTqVz 0ixGRPPYwBLLsaVfZ9AliHO8vUXsVgReWZmnYYB7HY/z+ULKNAo3HA66brzG4Xj+VY54 p/nRE3sIzqcmWNuVj2mMqoLwjUATqdh1Wm1toeXa7LkOQ3mH1GcWbjf8w5wBHRmuv64U mE5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id 67-v6si545505wrk.312.2018.05.15.11.20.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 11:20:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fIeYJ-0001gp-Hp; Tue, 15 May 2018 19:19:59 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Laurent Vivier , Riku Voipio Subject: [PATCH] gdbstub: Clarify what gdb_handlesig() is doing Date: Tue, 15 May 2018 19:19:58 +0100 Message-Id: <20180515181958.25837-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.0 gdb_handlesig()'s behaviour is not entirely obvious at first glance. Add a doc comment for it, and also add a comment explaining why it's ok for gdb_do_syscallv() to ignore gdb_handlesig()'s return value. (Coverity complains about this: CID 1390850.) Signed-off-by: Peter Maydell --- This took me a little while to figure out, so we might as well write it down. Incidentally, a lot of the code in the per-target main loops doesn't really use gdb_handlesig() correctly either: for instance in the arm main loop we (a) forget to tell gdb about SIGSEGV and (b) assume that if we tell gdb about a SIGTRAP then the signal we get back on resume is either 0 or SIGTRAP, when it could really be anything. Ideally we'd push the gdb_handlesig calls into target-independent code, ie queue_signal(). I'm not sure what sort of fake siginfo we need to generate for the "generate a different signal" codepath, though: probably need to look at eg what the gdb gdbstub does. --- include/exec/gdbstub.h | 15 +++++++++++++++ gdbstub.c | 6 ++++++ 2 files changed, 21 insertions(+) -- 2.17.0 diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 2e8a4b83b9..08363969c1 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -48,6 +48,21 @@ int use_gdb_syscalls(void); void gdb_set_stop_cpu(CPUState *cpu); void gdb_exit(CPUArchState *, int); #ifdef CONFIG_USER_ONLY +/** + * gdb_handlesig: yield control to gdb + * @cpu: CPU + * @sig: if non-zero, the signal number which caused us to stop + * + * This function yields control to gdb, when a user-mode-only target + * needs to stop execution. If @sig is non-zero, then we will send a + * stop packet to tell gdb that we have stopped because of this signal. + * + * This function will block (handling protocol requests from gdb) + * until gdb tells us to continue target execution. When it does + * return, the return value is a signal to deliver to the target, + * or 0 if no signal should be delivered, ie the signal that caused + * us to stop should be ignored. + */ int gdb_handlesig(CPUState *, int); void gdb_signalled(CPUArchState *, int); void gdbserver_fork(CPUState *); diff --git a/gdbstub.c b/gdbstub.c index 3c3807358c..c9a63090ea 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1548,6 +1548,12 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) *p = 0; #ifdef CONFIG_USER_ONLY put_packet(s, s->syscall_buf); + /* Return control to gdb for it to process the syscall request. + * Since the protocol requires that gdb hands control back to us + * using a "here are the results" F packet, we don't need to check + * gdb_handlesig's return value (which is the signal to deliver if + * execution was resumed via a continue packet). + */ gdb_handlesig(s->c_cpu, 0); #else /* In this case wait to send the syscall packet until notification that