From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOuVc-0005bK-2w for qemu-devel@nongnu.org; Thu, 28 Jan 2016 16:53:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOuVX-0004oK-LP for qemu-devel@nongnu.org; Thu, 28 Jan 2016 16:53:44 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:56466 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOuVX-0004oA-9Y for qemu-devel@nongnu.org; Thu, 28 Jan 2016 16:53:39 -0500 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Thu, 28 Jan 2016 22:53:37 +0100 Message-Id: <145401801748.13643.3385451025415689964.stgit@localhost> In-Reply-To: <145401801194.13643.11789300006832270147.stgit@localhost> References: <145401801194.13643.11789300006832270147.stgit@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v5 1/5] util: Introduce error reporting functions with fatal/abort List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Thomas Huth , "Dr . David Alan Gilbert" , Markus Armbruster Provide two lean functions to report error messages that fatal/abort QEMU. Signed-off-by: Llu=C3=ADs Vilanova --- include/qemu/error-report.h | 19 +++++++++++++++++++ util/qemu-error.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 7ab2355..6c2f142 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -43,4 +43,23 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1= , 2); const char *error_get_progname(void); extern bool enable_timestamp_msg; =20 +/* Report message and exit with error */ +void QEMU_NORETURN error_vreport_fatal(const char *fmt, va_list ap) GCC_= FMT_ATTR(1, 0); +void QEMU_NORETURN error_report_fatal(const char *fmt, ...) GCC_FMT_ATTR= (1, 2); +/* Report message with caller location and abort */ +#define error_vreport_abort(fmt, ap) = \ + do { = \ + error_report_abort_caller_internal(__FILE__, __LINE__, __func__)= ; \ + error_vreport_abort_internal(fmt, ap); = \ + } while (0) +#define error_report_abort(fmt, ...) = \ + do { = \ + error_report_abort_caller_internal(__FILE__, __LINE__, __func__)= ; \ + error_report_abort_internal(fmt, ##__VA_ARGS__); = \ + } while (0) + +void error_report_abort_caller_internal(const char *file, int line, cons= t char *func); +void QEMU_NORETURN error_vreport_abort_internal(const char *fmt, va_list= ap) GCC_FMT_ATTR(1, 0); +void QEMU_NORETURN error_report_abort_internal(const char *fmt, ...) GCC= _FMT_ATTR(1, 2); + #endif diff --git a/util/qemu-error.c b/util/qemu-error.c index ecf5708..3de002b 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -237,3 +237,36 @@ void error_report(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); } + +void error_vreport_fatal(const char *fmt, va_list ap) +{ + error_vreport(fmt, ap); + exit(1); +} + +void error_report_fatal(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + error_vreport_fatal(fmt, ap); + va_end(ap); +} + +void error_report_abort_caller_internal(const char *file, int line, cons= t char *func) +{ + error_report("Unexpected error in %s() at %s:%d:", func, file, line)= ; +} + +void error_vreport_abort_internal(const char *fmt, va_list ap) +{ + error_vreport(fmt, ap); + abort(); +} + +void error_report_abort_internal(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + error_vreport_abort_internal(fmt, ap); + va_end(ap); +}