Merge pull request #3488 from OlegHahm/libcoap_debug_fixes
libcoap: some fixes for debugging enabled
This commit is contained in:
commit
465321fc8c
@ -1,7 +1,7 @@
|
|||||||
From b3ef68af33cb65f36666a416b71d7eb768715eca Mon Sep 17 00:00:00 2001
|
From b3ef68af33cb65f36666a416b71d7eb768715eca Mon Sep 17 00:00:00 2001
|
||||||
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
Date: Thu, 31 Oct 2013 13:36:10 +0100
|
Date: Thu, 31 Oct 2013 13:36:10 +0100
|
||||||
Subject: [PATCH 1/4] Add RIOT Makefile
|
Subject: [PATCH 1/8] Add RIOT Makefile
|
||||||
|
|
||||||
---
|
---
|
||||||
Makefile | 5 +++++
|
Makefile | 5 +++++
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 8be22676f13bd7d254378e2c04119e1632ed55d7 Mon Sep 17 00:00:00 2001
|
From 8be22676f13bd7d254378e2c04119e1632ed55d7 Mon Sep 17 00:00:00 2001
|
||||||
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
Date: Thu, 31 Oct 2013 14:02:07 +0100
|
Date: Thu, 31 Oct 2013 14:02:07 +0100
|
||||||
Subject: [PATCH 2/4] Add config.h
|
Subject: [PATCH 2/8] Add config.h
|
||||||
|
|
||||||
---
|
---
|
||||||
config.h | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
config.h | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From e53472f0a5f15d2459bf9a9ef40d2b302bb80f8b Mon Sep 17 00:00:00 2001
|
From e53472f0a5f15d2459bf9a9ef40d2b302bb80f8b Mon Sep 17 00:00:00 2001
|
||||||
From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||||
Date: Tue, 15 Jul 2014 16:57:07 +0200
|
Date: Tue, 15 Jul 2014 16:57:07 +0200
|
||||||
Subject: [PATCH 3/4] Remove two example programs in root
|
Subject: [PATCH 3/8] Remove two example programs in root
|
||||||
|
|
||||||
---
|
---
|
||||||
coap-observer.c | 185 -----------------------------------------------
|
coap-observer.c | 185 -----------------------------------------------
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 48906fde395dc05c18606ddf3abce5947ab6a1c6 Mon Sep 17 00:00:00 2001
|
From 48906fde395dc05c18606ddf3abce5947ab6a1c6 Mon Sep 17 00:00:00 2001
|
||||||
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
From: Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||||
Date: Wed, 19 Feb 2014 02:24:50 +0100
|
Date: Wed, 19 Feb 2014 02:24:50 +0100
|
||||||
Subject: [PATCH 4/4] Eliminate some compiler warnings and errors
|
Subject: [PATCH 4/5] Eliminate some compiler warnings and errors
|
||||||
|
|
||||||
---
|
---
|
||||||
address.h | 4 ++++
|
address.h | 4 ++++
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From e6d36f466b2c1568cb4cfc3a3f1f9348e71db037 Mon Sep 17 00:00:00 2001
|
From e6d36f466b2c1568cb4cfc3a3f1f9348e71db037 Mon Sep 17 00:00:00 2001
|
||||||
From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||||
Date: Tue, 15 Jul 2014 17:06:51 +0200
|
Date: Tue, 15 Jul 2014 17:06:51 +0200
|
||||||
Subject: [PATCH] fix old-style function declarations
|
Subject: [PATCH 5/8] fix old-style function declarations
|
||||||
|
|
||||||
---
|
---
|
||||||
async.c | 2 +-
|
async.c | 2 +-
|
||||||
|
|||||||
263
pkg/libcoap/0006-debug-do-not-misuse-NDEBUG.patch
Normal file
263
pkg/libcoap/0006-debug-do-not-misuse-NDEBUG.patch
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
From ca876797dbe6ba05f75a451e8724495a0770fe86 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Oleg Hahm <oleg@hobbykeller.org>
|
||||||
|
Date: Thu, 23 Jul 2015 10:20:38 +0200
|
||||||
|
Subject: [PATCH 6/8] debug: do not misuse NDEBUG
|
||||||
|
|
||||||
|
---
|
||||||
|
coap_list.c | 2 +-
|
||||||
|
debug.c | 4 ++--
|
||||||
|
debug.h | 3 +++
|
||||||
|
encode.c | 2 +-
|
||||||
|
examples/client.c | 4 ++--
|
||||||
|
net.c | 12 ++++++------
|
||||||
|
pdu.c | 2 +-
|
||||||
|
resource.c | 2 +-
|
||||||
|
str.c | 2 +-
|
||||||
|
subscribe.c | 14 +++++++-------
|
||||||
|
10 files changed, 25 insertions(+), 22 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/coap_list.c b/coap_list.c
|
||||||
|
index e93003c..95da094 100644
|
||||||
|
--- a/coap_list.c
|
||||||
|
+++ b/coap_list.c
|
||||||
|
@@ -74,7 +74,7 @@ coap_list_t *
|
||||||
|
coap_new_listnode(void *data, void (*delete_func)(void *) ) {
|
||||||
|
coap_list_t *node = coap_malloc( sizeof(coap_list_t) );
|
||||||
|
if ( ! node ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_CRIT, "coap_new_listnode: malloc\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
diff --git a/debug.c b/debug.c
|
||||||
|
index adff3c2..e043225 100644
|
||||||
|
--- a/debug.c
|
||||||
|
+++ b/debug.c
|
||||||
|
@@ -86,7 +86,7 @@ print_timestamp(char *s, size_t len, coap_tick_t t) {
|
||||||
|
|
||||||
|
#endif /* HAVE_TIME_H */
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNLEN
|
||||||
|
/**
|
||||||
|
@@ -326,7 +326,7 @@ coap_show_pdu(const coap_pdu_t *pdu) {
|
||||||
|
}
|
||||||
|
#endif /* WITH_CONTIKI */
|
||||||
|
|
||||||
|
-#endif /* NDEBUG */
|
||||||
|
+#endif /* DEBUG_ENABLED */
|
||||||
|
|
||||||
|
#ifndef WITH_CONTIKI
|
||||||
|
void
|
||||||
|
diff --git a/debug.h b/debug.h
|
||||||
|
index d18558f..edf4b86 100644
|
||||||
|
--- a/debug.h
|
||||||
|
+++ b/debug.h
|
||||||
|
@@ -54,7 +54,10 @@ void coap_log_impl(coap_log_t level, const char *format, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
+#define DEBUG_ENABLED
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
/* A set of convenience macros for common log levels. */
|
||||||
|
#define info(...) coap_log(LOG_INFO, __VA_ARGS__)
|
||||||
|
#define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
|
||||||
|
diff --git a/encode.c b/encode.c
|
||||||
|
index b034b6b..cdd9a20 100644
|
||||||
|
--- a/encode.c
|
||||||
|
+++ b/encode.c
|
||||||
|
@@ -6,7 +6,7 @@
|
||||||
|
* README for terms of use.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
# include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
diff --git a/examples/client.c b/examples/client.c
|
||||||
|
index bd75deb..7872c35 100644
|
||||||
|
--- a/examples/client.c
|
||||||
|
+++ b/examples/client.c
|
||||||
|
@@ -282,7 +282,7 @@ message_handler(struct coap_context_t *ctx,
|
||||||
|
unsigned char *databuf;
|
||||||
|
coap_tid_t tid;
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (LOG_DEBUG <= coap_get_log_level()) {
|
||||||
|
debug("** process incoming %d.%02d response:\n",
|
||||||
|
(received->hdr->code >> 5), received->hdr->code & 0x1F);
|
||||||
|
@@ -1075,7 +1075,7 @@ main(int argc, char **argv) {
|
||||||
|
if (! (pdu = coap_new_request(ctx, method, optlist)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (LOG_DEBUG <= coap_get_log_level()) {
|
||||||
|
debug("sending CoAP request:\n");
|
||||||
|
coap_show_pdu(pdu);
|
||||||
|
diff --git a/net.c b/net.c
|
||||||
|
index 7338802..9372570 100644
|
||||||
|
--- a/net.c
|
||||||
|
+++ b/net.c
|
||||||
|
@@ -243,7 +243,7 @@ coap_new_node() {
|
||||||
|
node = coap_malloc_node();
|
||||||
|
|
||||||
|
if ( ! node ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_WARNING, "coap_new_node: malloc\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
@@ -327,7 +327,7 @@ coap_new_context(
|
||||||
|
|
||||||
|
#ifndef WITH_CONTIKI
|
||||||
|
if ( !c ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_EMERG, "coap_init: malloc:\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
@@ -362,20 +362,20 @@ coap_new_context(
|
||||||
|
#ifdef WITH_POSIX
|
||||||
|
c->sockfd = socket(listen_addr->addr.sa.sa_family, SOCK_DGRAM, 0);
|
||||||
|
if ( c->sockfd < 0 ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_EMERG, "coap_new_context: socket\n");
|
||||||
|
#endif /* WITH_POSIX */
|
||||||
|
goto onerror;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( setsockopt( c->sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse) ) < 0 ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_WARNING, "setsockopt SO_REUSEADDR\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bind(c->sockfd, &listen_addr->addr.sa, listen_addr->size) < 0) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_EMERG, "coap_new_context: bind\n");
|
||||||
|
#endif
|
||||||
|
goto onerror;
|
||||||
|
@@ -923,7 +923,7 @@ if (!coap_pdu_parse((unsigned char *)buf, bytes_read, node->pdu)) {
|
||||||
|
coap_transaction_id(&node->remote, node->pdu, &node->id);
|
||||||
|
coap_insert_node(&ctx->recvqueue, node);
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (LOG_DEBUG <= coap_get_log_level()) {
|
||||||
|
#ifndef INET6_ADDRSTRLEN
|
||||||
|
#define INET6_ADDRSTRLEN 40
|
||||||
|
diff --git a/pdu.c b/pdu.c
|
||||||
|
index 04ef9c6..05d8537 100644
|
||||||
|
--- a/pdu.c
|
||||||
|
+++ b/pdu.c
|
||||||
|
@@ -132,7 +132,7 @@ coap_new_pdu() {
|
||||||
|
pdu = coap_pdu_init(0, 0, uip_ntohs(COAP_INVALID_TID), COAP_MAX_PDU_SIZE);
|
||||||
|
#endif /* WITH_CONTIKI */
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (!pdu)
|
||||||
|
coap_log(LOG_CRIT, "coap_new_pdu: cannot allocate memory for new PDU\n");
|
||||||
|
#endif
|
||||||
|
diff --git a/resource.c b/resource.c
|
||||||
|
index 1d9cf34..101ea4d 100644
|
||||||
|
--- a/resource.c
|
||||||
|
+++ b/resource.c
|
||||||
|
@@ -821,4 +821,4 @@ coap_remove_failed_observers(coap_context_t *context,
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (LOG_DEBUG <= coap_get_log_level()) {
|
||||||
|
#ifndef INET6_ADDRSTRLEN
|
||||||
|
#define INET6_ADDRSTRLEN 40
|
||||||
|
diff --git a/str.c b/str.c
|
||||||
|
index 0956789..f997ced 100644
|
||||||
|
--- a/str.c
|
||||||
|
+++ b/str.c
|
||||||
|
@@ -17,7 +17,7 @@
|
||||||
|
str *coap_new_string(size_t size) {
|
||||||
|
str *s = coap_malloc(sizeof(str) + size + 1);
|
||||||
|
if ( !s ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
coap_log(LOG_CRIT, "coap_new_string: malloc\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
diff --git a/subscribe.c b/subscribe.c
|
||||||
|
index d683419..37d4e20 100644
|
||||||
|
--- a/subscribe.c
|
||||||
|
+++ b/subscribe.c
|
||||||
|
@@ -43,7 +43,7 @@ notify(coap_context_t *context, coap_resource_t *res,
|
||||||
|
int ls, finished=0;
|
||||||
|
unsigned char ct, d;
|
||||||
|
unsigned int length;
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
char addr[INET6_ADDRSTRLEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ notify(coap_context_t *context, coap_resource_t *res,
|
||||||
|
/* TODO: add mediatype */
|
||||||
|
}
|
||||||
|
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if ( inet_ntop(sub->subscriber.addr.sa.sa_family,
|
||||||
|
&sub->subscriber.addr, addr, sizeof(addr)) ) {
|
||||||
|
debug("*** notify for %s to [%s]\n", res->uri->path.s, addr);
|
||||||
|
@@ -100,7 +100,7 @@ notify(coap_context_t *context, coap_resource_t *res,
|
||||||
|
&sub->subscriber.addr.sa,
|
||||||
|
sub->subscriber.size, pdu)
|
||||||
|
== COAP_INVALID_TID) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
debug("coap_check_resource_list: error sending notification\n");
|
||||||
|
#endif
|
||||||
|
coap_delete_pdu(pdu);
|
||||||
|
@@ -164,7 +164,7 @@ coap_get_resource_from_key(coap_context_t *ctx, coap_key_t key) {
|
||||||
|
|
||||||
|
coap_resource_t *
|
||||||
|
coap_get_resource(coap_context_t *ctx, coap_uri_t *uri) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
int i;
|
||||||
|
printf("search resource %ux", coap_uri_hash(uri));
|
||||||
|
for (i=0; i < uri->path.length; ++i) {
|
||||||
|
@@ -180,7 +180,7 @@ void
|
||||||
|
coap_check_subscriptions(coap_context_t *context) {
|
||||||
|
time_t now;
|
||||||
|
coap_list_t *node;
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
char addr[INET6_ADDRSTRLEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@@ -191,7 +191,7 @@ coap_check_subscriptions(coap_context_t *context) {
|
||||||
|
|
||||||
|
node = context->subscriptions;
|
||||||
|
while ( node && COAP_SUBSCRIPTION(node)->expires < now ) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
if (inet_ntop(COAP_SUBSCRIPTION(node)->subscriber.addr.sa.sa_family,
|
||||||
|
&COAP_SUBSCRIPTION(node)->subscriber.addr,
|
||||||
|
addr, sizeof(addr))) {
|
||||||
|
@@ -236,7 +236,7 @@ coap_delete_resource(coap_context_t *context, coap_key_t key) {
|
||||||
|
for (prev = NULL, node = context->resources; node;
|
||||||
|
prev = node, node = node->next) {
|
||||||
|
if (coap_uri_hash(COAP_RESOURCE(node)->uri) == key) {
|
||||||
|
-#ifndef NDEBUG
|
||||||
|
+#ifdef DEBUG_ENABLED
|
||||||
|
debug("removed key %lu (%s)\n",key,COAP_RESOURCE(node)->uri->path.s);
|
||||||
|
#endif
|
||||||
|
if (!prev)
|
||||||
|
--
|
||||||
|
2.5.0
|
||||||
26
pkg/libcoap/0007-fix-option-parsing-with-debug-enabled.patch
Normal file
26
pkg/libcoap/0007-fix-option-parsing-with-debug-enabled.patch
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
From e5adb25f18ff979b2777f7161b1038611c84a450 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Oleg Hahm <oleg@hobbykeller.org>
|
||||||
|
Date: Tue, 4 Aug 2015 23:07:24 +0200
|
||||||
|
Subject: [PATCH 7/8] fix option parsing with debug enabled
|
||||||
|
|
||||||
|
---
|
||||||
|
option.c | 3 ++-
|
||||||
|
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/option.c b/option.c
|
||||||
|
index a03fc9e..b825eac 100644
|
||||||
|
--- a/option.c
|
||||||
|
+++ b/option.c
|
||||||
|
@@ -57,8 +57,9 @@ coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
|
||||||
|
|
||||||
|
switch(result->delta) {
|
||||||
|
case 15:
|
||||||
|
- if (*opt != COAP_PAYLOAD_START)
|
||||||
|
+ if (*opt != COAP_PAYLOAD_START) {
|
||||||
|
debug("ignored reserved option delta 15\n");
|
||||||
|
+ }
|
||||||
|
return 0;
|
||||||
|
case 14:
|
||||||
|
/* Handle two-byte value: First, the MSB + 269 is stored as delta value.
|
||||||
|
--
|
||||||
|
2.5.0
|
||||||
27
pkg/libcoap/0008-fix-debug-out-in-PDU-parsing.patch
Normal file
27
pkg/libcoap/0008-fix-debug-out-in-PDU-parsing.patch
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
From 3409c3834022c9e7cd73ac69e34dfaa101947cf0 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Oleg Hahm <oleg@hobbykeller.org>
|
||||||
|
Date: Tue, 4 Aug 2015 23:09:27 +0200
|
||||||
|
Subject: [PATCH 8/8] fix debug out in PDU parsing
|
||||||
|
|
||||||
|
---
|
||||||
|
net.c | 3 ++-
|
||||||
|
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/net.c b/net.c
|
||||||
|
index 9372570..86c7793 100644
|
||||||
|
--- a/net.c
|
||||||
|
+++ b/net.c
|
||||||
|
@@ -930,9 +930,10 @@ if (!coap_pdu_parse((unsigned char *)buf, bytes_read, node->pdu)) {
|
||||||
|
#endif
|
||||||
|
unsigned char addr[INET6_ADDRSTRLEN+8];
|
||||||
|
|
||||||
|
- if (coap_print_addr(&src, addr, INET6_ADDRSTRLEN+8))
|
||||||
|
+ if (coap_print_addr(&src, addr, INET6_ADDRSTRLEN+8)) {
|
||||||
|
debug("** received %d bytes from %s:\n", (int)bytes_read, addr);
|
||||||
|
|
||||||
|
+ }
|
||||||
|
coap_show_pdu( node->pdu );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
--
|
||||||
|
2.5.0
|
||||||
Loading…
x
Reference in New Issue
Block a user