debugging


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1214 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/examples/sample.makefile.regen b/examples/sample.makefile.regen
index b3b0e0d..57a0dae 100755
--- a/examples/sample.makefile.regen
+++ b/examples/sample.makefile.regen
@@ -57,8 +57,8 @@
 	echo "	$0"
 	echo
 	echo 'check: ${TARGET}'
-	echo "	@if test -f ./sample-${ASN1PDU}-1.[db]er ; then \\"
-	echo "	for f in ./sample-${ASN1PDU}-*.[db]er; do \\"
+	echo "	@if test -f sample-${ASN1PDU}-1.[db]er ; then \\"
+	echo "	for f in sample-${ASN1PDU}-*.[db]er; do \\"
 	echo '	echo "Recoding $$f into XER and back..."; \'
 	echo '	./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
 	echo '	./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \'
@@ -69,8 +69,8 @@
 	echo '	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
 	echo '	rm -f ./.tmp.[12].$$$$; \'
 	echo '	done; fi'
-	echo "	@if test -f ./sample-${ASN1PDU}-1.xer ; then \\"
-	echo "	for f in ./sample-${ASN1PDU}-*.xer; do \\"
+	echo "	@if test -f sample-${ASN1PDU}-1.xer ; then \\"
+	echo "	for f in sample-${ASN1PDU}-*.xer; do \\"
 	echo '	echo "Recoding $$f into DER and back..."; \'
 	echo '	./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
 	echo '	./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \'
@@ -81,8 +81,8 @@
 	echo '	diff $$f ./.tmp.2.$$$$ || exit 2; \'
 	echo '	rm -f ./.tmp.[12].$$$$; \'
 	echo '	done; fi'
-	echo "	@if test -f ./sample-${ASN1PDU}-1.per ; then \\"
-	echo "	for f in ./sample-${ASN1PDU}-[1-9].per; do \\"
+	echo "	@if test -f sample-${ASN1PDU}-1.per ; then \\"
+	echo "	for f in sample-${ASN1PDU}-[1-9].per; do \\"
 	echo '	echo "Recoding $$f into DER into XER and back..."; \'
 	echo '	./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
 	echo '	./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \'
@@ -97,19 +97,20 @@
 	echo '	diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \'
 	echo '	rm -f ./.tmp.[1234].$$$$; \'
 	echo '	done; fi'
-	echo "	@if test -f ./sample-${ASN1PDU}-1-padded.per ; then \\"
-	echo "	for f in ./sample-${ASN1PDU}-[1-9]-padded.per; do \\"
+	echo "	@if test -f sample-${ASN1PDU}-1-padded.per ; then \\"
+	echo "	for f in sample-*-[1-9]-padded.per; do \\"
+	echo '	pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \'
 	echo '	echo "Recoding byte-padded $$f into DER into XER and back..."; \'
-	echo '	./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
-	echo '	./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \'
-	echo '	./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \'
-	echo '	./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \'
+	echo '	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
+	echo '	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \'
+	echo '	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \'
+	echo '	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \'
 	echo '	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
 	echo '	diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \'
 	echo '	diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \'
-	echo '	./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
-	echo '	./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
-	echo '	./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
+	echo '	./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
+	echo '	./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
+	echo '	./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
 	echo '	diff $$f ./.tmp.1.$$$$ || exit 2; \'
 	echo '	rm -f ./.tmp.[1234].$$$$; \'
 	echo '	done; fi'
diff --git a/examples/sample.source.LDAP3/Makefile b/examples/sample.source.LDAP3/Makefile
index 6de7245..86a7917 100644
--- a/examples/sample.source.LDAP3/Makefile
+++ b/examples/sample.source.LDAP3/Makefile
@@ -200,8 +200,8 @@
 	../sample.makefile.regen
 
 check: ${TARGET}
-	@if test -f ./sample-LDAPMessage-1.[db]er ; then \
-	for f in ./sample-LDAPMessage-*.[db]er; do \
+	@if test -f sample-LDAPMessage-1.[db]er ; then \
+	for f in sample-LDAPMessage-*.[db]er; do \
 	echo "Recoding $$f into XER and back..."; \
 	./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \
@@ -212,8 +212,8 @@
 	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \
 	rm -f ./.tmp.[12].$$$$; \
 	done; fi
-	@if test -f ./sample-LDAPMessage-1.xer ; then \
-	for f in ./sample-LDAPMessage-*.xer; do \
+	@if test -f sample-LDAPMessage-1.xer ; then \
+	for f in sample-LDAPMessage-*.xer; do \
 	echo "Recoding $$f into DER and back..."; \
 	./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \
@@ -224,8 +224,8 @@
 	diff $$f ./.tmp.2.$$$$ || exit 2; \
 	rm -f ./.tmp.[12].$$$$; \
 	done; fi
-	@if test -f ./sample-LDAPMessage-1.per ; then \
-	for f in ./sample-LDAPMessage-[1-9].per; do \
+	@if test -f sample-LDAPMessage-1.per ; then \
+	for f in sample-LDAPMessage-[1-9].per; do \
 	echo "Recoding $$f into DER into XER and back..."; \
 	./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
@@ -240,19 +240,20 @@
 	diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \
 	rm -f ./.tmp.[1234].$$$$; \
 	done; fi
-	@if test -f ./sample-LDAPMessage-1-padded.per ; then \
-	for f in ./sample-LDAPMessage-[1-9]-padded.per; do \
+	@if test -f sample-LDAPMessage-1-padded.per ; then \
+	for f in sample-*-[1-9]-padded.per; do \
+	pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \
 	echo "Recoding byte-padded $$f into DER into XER and back..."; \
-	./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \
 	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \
 	diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \
 	diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \
-	./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \
-	./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \
+	./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \
+	./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \
+	./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \
 	diff $$f ./.tmp.1.$$$$ || exit 2; \
 	rm -f ./.tmp.[1234].$$$$; \
 	done; fi
diff --git a/examples/sample.source.RRC/Makefile b/examples/sample.source.RRC/Makefile
index 6e62389..313abb1 100644
--- a/examples/sample.source.RRC/Makefile
+++ b/examples/sample.source.RRC/Makefile
@@ -4777,8 +4777,8 @@
 	../sample.makefile.regen
 
 check: ${TARGET}
-	@if test -f ./sample-DL-DCCH-Message-1.[db]er ; then \
-	for f in ./sample-DL-DCCH-Message-*.[db]er; do \
+	@if test -f sample-DL-DCCH-Message-1.[db]er ; then \
+	for f in sample-DL-DCCH-Message-*.[db]er; do \
 	echo "Recoding $$f into XER and back..."; \
 	./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \
@@ -4789,8 +4789,8 @@
 	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \
 	rm -f ./.tmp.[12].$$$$; \
 	done; fi
-	@if test -f ./sample-DL-DCCH-Message-1.xer ; then \
-	for f in ./sample-DL-DCCH-Message-*.xer; do \
+	@if test -f sample-DL-DCCH-Message-1.xer ; then \
+	for f in sample-DL-DCCH-Message-*.xer; do \
 	echo "Recoding $$f into DER and back..."; \
 	./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \
@@ -4801,8 +4801,8 @@
 	diff $$f ./.tmp.2.$$$$ || exit 2; \
 	rm -f ./.tmp.[12].$$$$; \
 	done; fi
-	@if test -f ./sample-DL-DCCH-Message-1.per ; then \
-	for f in ./sample-DL-DCCH-Message-[1-9].per; do \
+	@if test -f sample-DL-DCCH-Message-1.per ; then \
+	for f in sample-DL-DCCH-Message-[1-9].per; do \
 	echo "Recoding $$f into DER into XER and back..."; \
 	./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
 	./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
@@ -4817,20 +4817,28 @@
 	diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \
 	rm -f ./.tmp.[1234].$$$$; \
 	done; fi
-	@if test -f ./sample-DL-DCCH-Message-1-padded.per ; then \
-	for f in ./sample-DL-DCCH-Message-[1-9]-padded.per; do \
+	@if test -f sample-DL-DCCH-Message-1-padded.per ; then \
+	for f in sample-*-[1-9]-padded.per; do \
+	pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \
 	echo "Recoding byte-padded $$f into DER into XER and back..."; \
-	./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \
-	./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \
-	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 1; \
+	echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$"; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \
+	echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$"; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \
+	echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$"; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \
+	echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$"; \
+	./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \
+	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \
 	diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \
-	diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 3; \
-	./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \
-	./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \
-	./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \
-	diff $$f ./.tmp.1.$$$$ || exit 4; \
+	diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \
+	echo "./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$"; \
+	./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \
+	echo "./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$"; \
+	./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \
+	echo "./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$"; \
+	./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \
+	diff $$f ./.tmp.1.$$$$ || exit 2; \
 	rm -f ./.tmp.[1234].$$$$; \
 	done; fi
 	@echo ================
diff --git a/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per b/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per
new file mode 100644
index 0000000..0d6babc
--- /dev/null
+++ b/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per
Binary files differ
diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c
index 3bef560..3a83bd9 100644
--- a/skeletons/OCTET_STRING.c
+++ b/skeletons/OCTET_STRING.c
@@ -1328,8 +1328,11 @@
 		sizeinunits = sizeinunits * 8 - (st->bits_unused & 0x07);
 	}
 
-	ASN_DEBUG("Encoding %s into %d units of %d bits",
-		td->name, sizeinunits, unit_bits);
+	ASN_DEBUG("Encoding %s into %d units of %d bits"
+		" (%d..%d, effective %d)%s",
+		td->name, sizeinunits, unit_bits,
+		ct->lower_bound, ct->upper_bound,
+		ct->effective_bits, ct_extensible ? " EXT" : "");
 
 	/* Figure out wheter size lies within PER visible consrtaint */
 
diff --git a/skeletons/asn_codecs.h b/skeletons/asn_codecs.h
index 1ee7377..4a251d9 100644
--- a/skeletons/asn_codecs.h
+++ b/skeletons/asn_codecs.h
@@ -62,6 +62,7 @@
 	tmp_error.encoded = -1;					\
 	tmp_error.failed_type = td;				\
 	tmp_error.structure_ptr = sptr;				\
+	ASN_DEBUG("Failed to encode element %s", td->name);	\
 	return tmp_error;					\
 } while(0)
 #define	_ASN_ENCODED_OK(rval) do {				\
@@ -91,6 +92,7 @@
 	asn_dec_rval_t tmp_error;				\
 	tmp_error.code = RC_FAIL;				\
 	tmp_error.consumed = 0;					\
+	ASN_DEBUG("Failed to decode element %s", td->name);	\
 	return tmp_error;					\
 } while(0)
 #define	_ASN_DECODE_STARVED do {				\
diff --git a/skeletons/asn_codecs_prim.c b/skeletons/asn_codecs_prim.c
index 97dc22a..4e5c639 100644
--- a/skeletons/asn_codecs_prim.c
+++ b/skeletons/asn_codecs_prim.c
@@ -22,11 +22,7 @@
 	 */
 	if(st == NULL) {
 		st = (ASN__PRIMITIVE_TYPE_t *)CALLOC(1, sizeof(*st));
-		if(st == NULL) {
-			rval.code = RC_FAIL;
-			rval.consumed = 0;
-			return rval;
-		}
+		if(st == NULL) _ASN_DECODE_FAILED;
 		*sptr = (void *)st;
 	}
 
@@ -59,17 +55,13 @@
 	if(sizeof(st->size) != sizeof(length)
 			&& (ber_tlv_len_t)st->size != length) {
 		st->size = 0;
-		rval.code = RC_FAIL;
-		rval.consumed = 0;
-		return rval;
+		_ASN_DECODE_FAILED;
 	}
 
 	st->buf = (uint8_t *)MALLOC(length + 1);
 	if(!st->buf) {
 		st->size = 0;
-		rval.code = RC_FAIL;
-		rval.consumed = 0;
-		return rval;
+		_ASN_DECODE_FAILED;
 	}
 
 	memcpy(st->buf, buf_ptr, length);
@@ -249,12 +241,7 @@
 	 */
 	if(!*sptr) {
 		*sptr = CALLOC(1, struct_size);
-		if(!*sptr) {
-			asn_dec_rval_t rval;
-			rval.code = RC_FAIL;
-			rval.consumed = 0;
-			return rval;
-		}
+		if(!*sptr) _ASN_DECODE_FAILED;
 	}
 
 	memset(&s_ctx, 0, sizeof(s_ctx));
@@ -284,8 +271,7 @@
 				/*
 				 * This decoder does not like empty stuff.
 				 */
-				rc.code = RC_FAIL;
-				rc.consumed = 0;
+				_ASN_DECODE_FAILED;
 			}
 		}
 		break;
@@ -300,6 +286,8 @@
 		rc.consumed = 0;
 		if(s_arg.want_more)
 			rc.code = RC_WMORE;
+		else
+			_ASN_DECODE_FAILED;
 		break;
 	}
 	return rc;
diff --git a/skeletons/converter-sample.c b/skeletons/converter-sample.c
index 7ed49df..1013e65 100644
--- a/skeletons/converter-sample.c
+++ b/skeletons/converter-sample.c
@@ -665,8 +665,10 @@
 	 * Print a message and return failure only if not EOF,
 	 * unless this is our first PDU (empty file).
 	 */
-	if((on_first_pdu || new_offset != old_offset || DynamicBuffer.length)
-	&& (iform != INP_XER || on_first_pdu)) {
+	if(on_first_pdu
+	|| DynamicBuffer.length
+	|| new_offset - old_offset > ((iform == INP_XER)?sizeof("\r\n")-1:0)
+	) {
 		DEBUG("ofp %d, no=%ld, oo=%ld, dbl=%ld",
 			on_first_pdu, (long)new_offset, (long)old_offset,
 			(long)DynamicBuffer.length);
diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c
index 2b3f16a..161dc78 100644
--- a/skeletons/xer_decoder.c
+++ b/skeletons/xer_decoder.c
@@ -173,6 +173,8 @@
 #define	RETURN(_code)	do {					\
 		rval.code = _code;				\
 		rval.consumed = consumed_myself;		\
+		if(rval.code != RC_OK)				\
+			ASN_DEBUG("Failed with %d", rval.code);	\
 		return rval;					\
 	} while(0)