From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 79D1738582BD for ; Fri, 15 Dec 2023 14:36:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79D1738582BD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 79D1738582BD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702650987; cv=none; b=oiRwuKT5BGI/h1qzBARHgLQNeBGnrNI3o7TtnI+03YYv9Yxr/mYP5TmjUDtI+N1wCgloZNG77J5khINtfJj/ixB3xNq2em0kjNARMl+412/mq8dzBsdlp+0JZIIUzFoQDF2iuufdEyvNEkJu15N0voS8HkVGC0kPRO43+sqywN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702650987; c=relaxed/simple; bh=UAm/LVfIwYIRO+SIrILVnIKPc1wIlrLKeMPOcLyuE0c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GZFTMLn+q8hDWvTLVJcXw9MgmfB3P/uH3XDQ6yh5gu0KSTDwsHtpvIUi2BUUwbqULgH1d+DdxKOa0HZPh3qoKK63LH0OQHeSwsTYjO1IvN6Wb08QZLW6TBZUcwjBdjORLtHu2GqtopP8lnVgx7Dd54UqRc/Hnv6Y1BnrpEzAAaA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BFEIFoN022021 for ; Fri, 15 Dec 2023 14:36:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JbusOv72r8kUTdoIhtHh8NR/AAxzxFbgI2OrQoEu9Hg=; b=D8pH060qHdcjw7JAtDfs//wbjUlSXYS4HiPqoJ50BcZDbwZrf6fZdctxsKzhkD76OK8F oaHn/YURGzs2O9qj50DvJQEWpdDQ5gAbFl182OERaQcOB685u1kAG5QkWU+vo/lOgukH PCQo6waZkrXNX4NmuLDql6DfZrKchDXfWLWh4xX69u3JxowTAoeXR74qQYO3Or5MzF0v 9WVjOVp4gFNxWqKU+NVKjAHBulPQX1nfe/ZTpAJE4qZprOLORe3r2NDwIGImP71zbKuE CUvjavCD/Cz/CUMeexgTArNKzfBKBXmavR6xVLbztLyZR79rtcDeePTWSR/dbzQb3U4t eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v0rekrf9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Dec 2023 14:36:23 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BFEIe6O023346 for ; Fri, 15 Dec 2023 14:36:23 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v0rekrf9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 14:36:23 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BF5tV39014813; Fri, 15 Dec 2023 14:36:22 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3uw42kkdau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 14:36:22 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BFEaJYd15008432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Dec 2023 14:36:19 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9010820040; Fri, 15 Dec 2023 14:36:19 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63F3B20043; Fri, 15 Dec 2023 14:36:19 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2023 14:36:19 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org Cc: Jens Remus , Andreas Krebbel , Nick Clifton Subject: [PATCH v2 4/7] s390: Enhance error handling in s390-mkopc Date: Fri, 15 Dec 2023 15:36:13 +0100 Message-Id: <20231215143616.820185-5-jremus@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215143616.820185-1-jremus@linux.ibm.com> References: <20231215143616.820185-1-jremus@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: N27Nt5uJAxNz-Xy7VyZ1Zmw0DOc2B31i X-Proofpoint-GUID: boxbGgkVt-N9mSalVyaBPo1ZvkVVqn5q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-15_08,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxlogscore=750 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312150099 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When the s390-mkopc utility detects an error it prints an error message to strerr and either continues processing or exists with a non-zero return code. If it continues without detecting any further error the final return code was zero, potentially hiding the detected error. Introduce a global variable to hold the final return code and initialize it to EXIT_SUCCESS. Introduce a helper function print_error() that prints an error message to stderr and sets the final return code to EXIT_FAILURE. Use it to print all error messages. Return the final return code at the end of the processing. While at it enhance error messages to state more clearly which mnemonic an error was detected for. Also continue processing for cases where subsequent mnemonics can be processed. opcodes/ * s390-mkopc.c: Enhance error handling. Return EXIT_FAILURE in case of an error, otherwise EXIT_SUCCESS. Signed-off-by: Jens Remus Reviewed-by: Andreas Krebbel --- opcodes/s390-mkopc.c | 49 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/opcodes/s390-mkopc.c b/opcodes/s390-mkopc.c index 5f921ee0628..aad093f18ff 100644 --- a/opcodes/s390-mkopc.c +++ b/opcodes/s390-mkopc.c @@ -21,9 +21,27 @@ #include #include +#include #include #include "opcode/s390.h" +/* Return code. */ +int return_code = EXIT_SUCCESS; + +/* Helper to print an error message and set the return code. */ +static void __attribute__ ((format (printf, 1, 2))) +print_error (const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fprintf(stderr, "Error: "); + vfprintf(stderr, fmt, ap); + va_end(ap); + + return_code = EXIT_FAILURE; +} + struct op_struct { char opcode[16]; @@ -223,8 +241,7 @@ insertExpandedMnemonic (char *opcode, char *mnemonic, char *format, if (mask_start & 3) { - fprintf (stderr, "Conditional mask not at nibble boundary in: %s\n", - mnemonic); + print_error ("Mnemonic \"%s\": Conditional mask not at nibble boundary\n", mnemonic); return; } @@ -257,7 +274,7 @@ insertExpandedMnemonic (char *opcode, char *mnemonic, char *format, return; malformed_mnemonic: - fprintf (stderr, "Malformed mnemonic: %s\n", mnemonic); + print_error ("Malformed mnemonic: %s\n", mnemonic); } static const char file_header[] = @@ -343,8 +360,8 @@ main (void) cpu_string, modes_string, flags_string); if (num_matched != 6 && num_matched != 7) { - fprintf (stderr, "Couldn't scan line %s\n", currentLine); - exit (1); + print_error ("Couldn't scan line %s\n", currentLine); + exit (EXIT_FAILURE); } if (strcmp (cpu_string, "g5") == 0 @@ -385,8 +402,9 @@ main (void) || strcmp (cpu_string, "arch14") == 0) min_cpu = S390_OPCODE_ARCH14; else { - fprintf (stderr, "Couldn't parse cpu string %s\n", cpu_string); - exit (1); + print_error ("Mnemonic \"%s\": Couldn't parse CPU string: %s\n", + mnemonic, cpu_string); + goto continue_loop; } str = modes_string; @@ -401,9 +419,9 @@ main (void) mode_bits |= 1 << S390_OPCODE_ZARCH; str += 5; } else { - fprintf (stderr, "Couldn't parse modes string %s\n", - modes_string); - exit (1); + print_error ("Mnemonic \"%s\": Couldn't parse modes string: %s\n", + mnemonic, modes_string); + goto continue_loop; } if (*str == ',') str++; @@ -444,17 +462,20 @@ main (void) flag_bits |= S390_INSTR_FLAGS_CLASS_JUMPSR; str += 6; } else { - fprintf (stderr, "Couldn't parse flags string %s\n", - flags_string); - exit (1); + print_error ("Mnemonic \"%s\": Couldn't parse flags string: %s\n", + mnemonic, flags_string); + goto continue_loop; } if (*str == ',') str++; } while (*str != 0); } insertExpandedMnemonic (opcode, mnemonic, format, min_cpu, mode_bits, flag_bits); + + continue_loop: + ; } dumpTable (); - return 0; + return return_code; } -- 2.40.1