Skip to contentSkip to conversation

btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON

PATCH Applied Goldwyn Rodrigues 3 participants 9 messages Nov 29, 2016 – Dec 7, 2016 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON

From: Goldwyn Rodrigues <[email protected]>

The values passed to BUG_ON/WARN_ON are negated(!) and printed, which results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion ret failed, value 0

This is not useful. Instead changed to print the value of the parameter passed to BUG_ON()/WARN_ON(). The value needed to be changed to long to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

---
 kerncompat.h | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
kerncompat.h +15 -20
index ed9a042..9bd25bd 100644
@@ -88,39 +88,36 @@ static inline void print_trace(void)
 }
 
 static inline void assert_trace(const char *assertion, const char *filename,
-			      const char *func, unsigned line, int val)
+			      const char *func, unsigned line, long val)
 {
-	if (val)
+	if (!val)
 		return;
 	if (assertion)
-		fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %d\n",
+		fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %ld\n",
 			filename, line, func, assertion, val);
 	else
-		fprintf(stderr, "%s:%d: %s: Assertion failed, value %d.\n",
+		fprintf(stderr, "%s:%d: %s: Assertion failed, value %ld.\n",
 			filename, line, func, val);
 	print_trace();
 	abort();
 	exit(1);
 }
 
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
-#else
-#define BUG() assert(0)
 #endif
 
 static inline void warning_trace(const char *assertion, const char *filename,
-			      const char *func, unsigned line, int val,
+			      const char *func, unsigned line, long val,
 			      int trace)
 {
-	if (val)
+	if (!val)
 		return;
 	if (assertion)
 		fprintf(stderr,
-			"%s:%d: %s: Warning: assertion `%s` failed, value %d\n",
+			"%s:%d: %s: Warning: assertion `%s` failed, value %ld\n",
 			filename, line, func, assertion, val);
 	else
 		fprintf(stderr,
-			"%s:%d: %s: Warning: assertion failed, value %d.\n",
+			"%s:%d: %s: Warning: assertion failed, value %ld.\n",
 			filename, line, func, val);
 #ifndef BTRFS_DISABLE_BACKTRACE
 	if (trace)
@@ -299,17 +296,15 @@ static inline long IS_ERR(const void *ptr)
 #define vfree(x) free(x)
 
 #ifndef BTRFS_DISABLE_BACKTRACE
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 1)
+#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c), 1)
+#define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
+#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
 #define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 0)
-#endif
-
-#ifndef BTRFS_DISABLE_BACKTRACE
-#define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
-#else
-#define ASSERT(c) assert(c)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c), 0)
+#define ASSERT(c) assert(!(c))
+#define BUG() assert(0)
 #endif
 
 #define container_of(ptr, type, member) ({                      \
Signature · 1 line
2.10.0
Applied
#1 lore raw
Quoted 6 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

The values passed to BUG_ON/WARN_ON are negated(!) and printed, which results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion ret failed, value 0

Quoted 7 lines

This is not useful. Instead changed to print the value of the parameter passed to BUG_ON()/WARN_ON(). The value needed to be changed to long to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

Applied, thanks.

#2 lore raw
In reply to Goldwyn Rodrigues

Hi, Goldwyn and David,

This patch seems to cause btrfs test case 023 to fail.

Bisect leads me to this patch.

$ ./btrfs check ~/quota_balance_loop_backref.raw.restored
Checking filesystem on /home/adam/quota_balance_loop_backref.raw.restored
UUID: c33c5ce3-3ad9-4320-9201-c337c04e0051
checking extents
btrfs: cmds-check.c:12284: build_roots_info_cache: Assertion `!(ret == 0)' failed.
Aborted (core dumped)

And gdb backref:

#0  0x00007ffff6fd204f in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6fd347a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff6fcaea7 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff6fcaf52 in __assert_fail () from /usr/lib/libc.so.6
#4  0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at cmds-check.c:12284
#5  0x0000000000440945 in repair_root_items (info=0x6f43c0) at cmds-check.c:12412
#6  0x00000000004418c3 in cmd_check (argc=2, argv=0x7fffffffe100) at cmds-check.c:12892
#7  0x000000000040a74c in main (argc=2, argv=0x7fffffffe100) at btrfs.c:301

For frame 4:
(gdb) frame 4
#4 0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at cmds-check.c:12284
12284 ASSERT(ret == 0);
(gdb) list
12279 rii->cache_extent.start = root_id;
12280 rii->cache_extent.size = 1;
12281 rii->level = (u8)-1;
12282 entry = &rii->cache_extent;
12283 ret = insert_cache_extent(roots_info_cache, entry);
12284 ASSERT(ret == 0);
12285 } else {
12286 rii = container_of(entry, struct root_item_info,
12287 cache_extent);
12288 }
(gdb) print ret
$1 = 0

For me, ASSERT(ret == 0) seems quite safe and common here. Doesn't the patch changed the ASSERT() behavior?

Thanks,
Qu

Quoted 95 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

The values passed to BUG_ON/WARN_ON are negated(!) and printed, which results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion ret failed, value 0

This is not useful. Instead changed to print the value of the parameter passed to BUG_ON()/WARN_ON(). The value needed to be changed to long to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

---
 kerncompat.h | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
kerncompat.h +15 -20
index ed9a042..9bd25bd 100644
@@ -88,39 +88,36 @@ static inline void print_trace(void)
 }
 
 static inline void assert_trace(const char *assertion, const char *filename,
-			      const char *func, unsigned line, int val)
+			      const char *func, unsigned line, long val)
 {
-	if (val)
+	if (!val)
 		return;
 	if (assertion)
-		fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %d\n",
+		fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %ld\n",
 			filename, line, func, assertion, val);
 	else
-		fprintf(stderr, "%s:%d: %s: Assertion failed, value %d.\n",
+		fprintf(stderr, "%s:%d: %s: Assertion failed, value %ld.\n",
 			filename, line, func, val);
 	print_trace();
 	abort();
 	exit(1);
 }
 
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
-#else
-#define BUG() assert(0)
 #endif
 
 static inline void warning_trace(const char *assertion, const char *filename,
-			      const char *func, unsigned line, int val,
+			      const char *func, unsigned line, long val,
 			      int trace)
 {
-	if (val)
+	if (!val)
 		return;
 	if (assertion)
 		fprintf(stderr,
-			"%s:%d: %s: Warning: assertion `%s` failed, value %d\n",
+			"%s:%d: %s: Warning: assertion `%s` failed, value %ld\n",
 			filename, line, func, assertion, val);
 	else
 		fprintf(stderr,
-			"%s:%d: %s: Warning: assertion failed, value %d.\n",
+			"%s:%d: %s: Warning: assertion failed, value %ld.\n",
 			filename, line, func, val);
 #ifndef BTRFS_DISABLE_BACKTRACE
 	if (trace)
@@ -299,17 +296,15 @@ static inline long IS_ERR(const void *ptr)
 #define vfree(x) free(x)
 
 #ifndef BTRFS_DISABLE_BACKTRACE
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 1)
+#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c), 1)
+#define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
+#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
 #define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 0)
-#endif
-
-#ifndef BTRFS_DISABLE_BACKTRACE
-#define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
-#else
-#define ASSERT(c) assert(c)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c), 0)
+#define ASSERT(c) assert(!(c))
+#define BUG() assert(0)
 #endif
 
 #define container_of(ptr, type, member) ({                      \
#3 lore raw

Hi Qu,

Yes, the assert for ifdef BTRFS_DIABLE_BACKTRACE is not correct. The condition should not have a not(!).

Thanks for reporting.

Quoted 146 lines · Qu Wenruo

Hi, Goldwyn and David,

This patch seems to cause btrfs test case 023 to fail.

Bisect leads me to this patch.

$ ./btrfs check ~/quota_balance_loop_backref.raw.restored
Checking filesystem on /home/adam/quota_balance_loop_backref.raw.restored
UUID: c33c5ce3-3ad9-4320-9201-c337c04e0051
checking extents
btrfs: cmds-check.c:12284: build_roots_info_cache: Assertion `!(ret ==
0)' failed.
Aborted (core dumped)

And gdb backref:

#0  0x00007ffff6fd204f in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6fd347a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff6fcaea7 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff6fcaf52 in __assert_fail () from /usr/lib/libc.so.6
#4  0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at

cmds-check.c:12284
#5 0x0000000000440945 in repair_root_items (info=0x6f43c0) at cmds-check.c:12412
#6 0x00000000004418c3 in cmd_check (argc=2, argv=0x7fffffffe100) at cmds-check.c:12892
#7 0x000000000040a74c in main (argc=2, argv=0x7fffffffe100) at btrfs.c:301

For frame 4:
(gdb) frame 4
#4 0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at cmds-check.c:12284
12284 ASSERT(ret == 0);
(gdb) list

12279                rii->cache_extent.start = root_id;
12280                rii->cache_extent.size = 1;
12281                rii->level = (u8)-1;
12282                entry = &rii->cache_extent;
12283                ret = insert_cache_extent(roots_info_cache, entry);
12284                ASSERT(ret == 0);

12285 } else {
12286 rii = container_of(entry, struct root_item_info,
12287 cache_extent);
12288 }
(gdb) print ret
$1 = 0

For me, ASSERT(ret == 0) seems quite safe and common here. Doesn't the patch changed the ASSERT() behavior?

Thanks,
Qu

Quoted 90 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

The values passed to BUG_ON/WARN_ON are negated(!) and printed, which results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion ret failed, value 0

This is not useful. Instead changed to print the value of the parameter passed to BUG_ON()/WARN_ON(). The value needed to be changed to long to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

---
 kerncompat.h | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
kerncompat.h +8 -11
index ed9a042..9bd25bd 100644
@@ -88,39 +88,36 @@ static inline void print_trace(void)
 }
 
 static inline void assert_trace(const char *assertion, const char
 *filename,
-                  const char *func, unsigned line, int val)
+                  const char *func, unsigned line, long val)
 {
-    if (val)
+    if (!val)
         return;
     if (assertion)
-        fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %d\n",
+        fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %ld\n",
             filename, line, func, assertion, val);
     else
-        fprintf(stderr, "%s:%d: %s: Assertion failed, value %d.\n",
+        fprintf(stderr, "%s:%d: %s: Assertion failed, value %ld.\n",
             filename, line, func, val);
     print_trace();
     abort();
     exit(1);
 }
 
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
-#else
-#define BUG() assert(0)
 #endif
 
 static inline void warning_trace(const char *assertion, const char
 *filename,
-                  const char *func, unsigned line, int val,
+                  const char *func, unsigned line, long val,
                   int trace)
 {
-    if (val)
+    if (!val)
         return;
     if (assertion)
         fprintf(stderr,
-            "%s:%d: %s: Warning: assertion `%s` failed, value %d\n",
+            "%s:%d: %s: Warning: assertion `%s` failed, value %ld\n",
             filename, line, func, assertion, val);
     else
         fprintf(stderr,
-            "%s:%d: %s: Warning: assertion failed, value %d.\n",
+            "%s:%d: %s: Warning: assertion failed, value %ld.\n",
             filename, line, func, val);

#ifndef BTRFS_DISABLE_BACKTRACE
if (trace)

kerncompat.h +4 -4
@@ -299,17 +296,15 @@ static inline long IS_ERR(const void *ptr)
 #define vfree(x) free(x)
 
 #ifndef BTRFS_DISABLE_BACKTRACE
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 !(c), 1)
+#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c))
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c), 1)
+#define    ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)!(c))
+#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
 #define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 !(c), 0)
-#endif
Quoted 8 lines
Quoted 8 lines
kerncompat.h +1 -5
-
-#ifndef BTRFS_DISABLE_BACKTRACE
-#define    ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
-#else
-#define ASSERT(c) assert(c)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,

(long)(c), 0)
+#define ASSERT(c) assert(!(c))

This should be assert(c), without the not(!)

Quoted 7 lines
Quoted 5 lines

+#define BUG() assert(0)
#endif

#define container_of(ptr, type, member) ({ \

Signature · 1 line
Goldwyn
#4 lore raw

BTW, the DISABLE_BACKTRACE branch seems quite different from backtrace one.

#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c)) #define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) #else
#define BUG_ON(c) assert(!(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define ASSERT(c) assert(!(c))
#define BUG() assert(0)

Condition of BUG_ON/ASSERT/BUG are all logical notted for DISABLE_BACKTRACE. While WARN_ON() of both branch are the same condition.

This seems quite confusing to me.

Any idea to make it more straightforward?

Thanks,
Qu

Quoted 173 lines · Goldwyn Rodrigues

Hi Qu,

Yes, the assert for ifdef BTRFS_DIABLE_BACKTRACE is not correct. The condition should not have a not(!).

Thanks for reporting.

Quoted 146 lines · Qu Wenruo

Hi, Goldwyn and David,

This patch seems to cause btrfs test case 023 to fail.

Bisect leads me to this patch.

$ ./btrfs check ~/quota_balance_loop_backref.raw.restored
Checking filesystem on /home/adam/quota_balance_loop_backref.raw.restored
UUID: c33c5ce3-3ad9-4320-9201-c337c04e0051
checking extents
btrfs: cmds-check.c:12284: build_roots_info_cache: Assertion `!(ret ==
0)' failed.
Aborted (core dumped)

And gdb backref:

#0  0x00007ffff6fd204f in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6fd347a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff6fcaea7 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff6fcaf52 in __assert_fail () from /usr/lib/libc.so.6
#4  0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at

cmds-check.c:12284
#5 0x0000000000440945 in repair_root_items (info=0x6f43c0) at cmds-check.c:12412
#6 0x00000000004418c3 in cmd_check (argc=2, argv=0x7fffffffe100) at cmds-check.c:12892
#7 0x000000000040a74c in main (argc=2, argv=0x7fffffffe100) at btrfs.c:301

For frame 4:
(gdb) frame 4
#4 0x0000000000440426 in build_roots_info_cache (info=0x6f43c0) at cmds-check.c:12284
12284 ASSERT(ret == 0);
(gdb) list

12279                rii->cache_extent.start = root_id;
12280                rii->cache_extent.size = 1;
12281                rii->level = (u8)-1;
12282                entry = &rii->cache_extent;
12283                ret = insert_cache_extent(roots_info_cache, entry);
12284                ASSERT(ret == 0);

12285 } else {
12286 rii = container_of(entry, struct root_item_info,
12287 cache_extent);
12288 }
(gdb) print ret
$1 = 0

For me, ASSERT(ret == 0) seems quite safe and common here. Doesn't the patch changed the ASSERT() behavior?

Thanks,
Qu

Quoted 90 lines · Goldwyn Rodrigues

From: Goldwyn Rodrigues <[email protected]>

The values passed to BUG_ON/WARN_ON are negated(!) and printed, which results in printing the value zero for each bug/warning. For example:
volumes.c:988: btrfs_alloc_chunk: Assertion ret failed, value 0

This is not useful. Instead changed to print the value of the parameter passed to BUG_ON()/WARN_ON(). The value needed to be changed to long to accomodate pointers being passed.

Also, consolidated assert() and BUG() into ifndef.

---
 kerncompat.h | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
kerncompat.h +8 -11
index ed9a042..9bd25bd 100644
@@ -88,39 +88,36 @@ static inline void print_trace(void)
 }
 
 static inline void assert_trace(const char *assertion, const char
 *filename,
-                  const char *func, unsigned line, int val)
+                  const char *func, unsigned line, long val)
 {
-    if (val)
+    if (!val)
         return;
     if (assertion)
-        fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %d\n",
+        fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %ld\n",
             filename, line, func, assertion, val);
     else
-        fprintf(stderr, "%s:%d: %s: Assertion failed, value %d.\n",
+        fprintf(stderr, "%s:%d: %s: Assertion failed, value %ld.\n",
             filename, line, func, val);
     print_trace();
     abort();
     exit(1);
 }
 
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
-#else
-#define BUG() assert(0)
 #endif
 
 static inline void warning_trace(const char *assertion, const char
 *filename,
-                  const char *func, unsigned line, int val,
+                  const char *func, unsigned line, long val,
                   int trace)
 {
-    if (val)
+    if (!val)
         return;
     if (assertion)
         fprintf(stderr,
-            "%s:%d: %s: Warning: assertion `%s` failed, value %d\n",
+            "%s:%d: %s: Warning: assertion `%s` failed, value %ld\n",
             filename, line, func, assertion, val);
     else
         fprintf(stderr,
-            "%s:%d: %s: Warning: assertion failed, value %d.\n",
+            "%s:%d: %s: Warning: assertion failed, value %ld.\n",
             filename, line, func, val);

#ifndef BTRFS_DISABLE_BACKTRACE
if (trace)

kerncompat.h +4 -4
@@ -299,17 +296,15 @@ static inline long IS_ERR(const void *ptr)
 #define vfree(x) free(x)
 
 #ifndef BTRFS_DISABLE_BACKTRACE
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 !(c), 1)
+#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c))
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c), 1)
+#define    ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)!(c))
+#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
 #define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 !(c), 0)
-#endif
Quoted 8 lines
Quoted 8 lines
kerncompat.h +1 -5
-
-#ifndef BTRFS_DISABLE_BACKTRACE
-#define    ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
-#else
-#define ASSERT(c) assert(c)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,

(long)(c), 0)
+#define ASSERT(c) assert(!(c))

This should be assert(c), without the not(!)

Quoted 7 lines
Quoted 5 lines

+#define BUG() assert(0)
#endif

#define container_of(ptr, type, member) ({ \

#5 lore raw
Quoted 15 lines · Qu Wenruo

BTW, the DISABLE_BACKTRACE branch seems quite different from backtrace one.

#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) #else
#define BUG_ON(c) assert(!(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert(!(c))
#define BUG() assert(0)

Quoted 3 lines

Condition of BUG_ON/ASSERT/BUG are all logical notted for DISABLE_BACKTRACE.
While WARN_ON() of both branch are the same condition.

WARN_ON is using warning_trace as opposed to assert, and that is the reason it is not notted.

Quoted 5 lines

This seems quite confusing to me.

Any idea to make it more straightforward?

I just kept it the same as before. warning_trace was using an extra variable, trace, which was not needed because the print_trace was already in ifndefs.

If you are talking about keeping WARN_ON outside of ifndef, yes, that will reduce the code further by another line.

Signature · 1 line
Goldwyn
#6 lore raw
Quoted 26 lines · Goldwyn Rodrigues
Quoted 15 lines · Qu Wenruo

BTW, the DISABLE_BACKTRACE branch seems quite different from backtrace one.

#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) #else
#define BUG_ON(c) assert(!(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert(!(c))
#define BUG() assert(0)

Quoted 3 lines

Condition of BUG_ON/ASSERT/BUG are all logical notted for DISABLE_BACKTRACE.
While WARN_ON() of both branch are the same condition.

WARN_ON is using warning_trace as opposed to assert, and that is the reason it is not notted.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

This seems quite confusing to me.

Any idea to make it more straightforward?

I just kept it the same as before. warning_trace was using an extra variable, trace, which was not needed because the print_trace was already in ifndefs.

I mean, better make the condition the same for both BUG/BUG_ON/ASSERT. So that we don't need to manually logical not the condition.

For example:
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,(long)(c)) and
#define ASSERT(c) assert((c))

This looks much more straightforward, and easier to expose bug at review time.

Thanks,
Qu

Quoted 4 lines

If you are talking about keeping WARN_ON outside of ifndef, yes, that will reduce the code further by another line.

#7 lore raw
Quoted 36 lines · Qu Wenruo
Quoted 33 lines · Goldwyn Rodrigues
Quoted 17 lines · Qu Wenruo

BTW, the DISABLE_BACKTRACE branch seems quite different from backtrace one.

#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) #else
#define BUG_ON(c) assert(!(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert(!(c))
#define BUG() assert(0)

Quoted 3 lines

Condition of BUG_ON/ASSERT/BUG are all logical notted for DISABLE_BACKTRACE.
While WARN_ON() of both branch are the same condition.

WARN_ON is using warning_trace as opposed to assert, and that is the reason it is not notted.

Quoted 5 lines

This seems quite confusing to me.

Any idea to make it more straightforward?

Quoted 6 lines
Quoted 3 lines

I just kept it the same as before. warning_trace was using an extra variable, trace, which was not needed because the print_trace was already in ifndefs.

I mean, better make the condition the same for both BUG/BUG_ON/ASSERT. So that we don't need to manually logical not the condition.

First of all, ASSERT and BUG_ON have opposite meanings. ASSERT() checks if the condition is true and continues (halts if false). BUG_ON() "bugs" if condition is true and halts (continues if false). So you would have to use opposite conditions.

Quoted 9 lines

For example:
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,(long) (c))
and
#define ASSERT(c) assert((c))

This looks much more straightforward, and easier to expose bug at review time.

Could you explain with a patch? You idea seems to add more code than reduce it.

Signature · 1 line
Goldwyn
#8 lore raw
Quoted 43 lines · Goldwyn Rodrigues
Quoted 40 lines · Qu Wenruo
Quoted 36 lines · Goldwyn Rodrigues
Quoted 17 lines · Qu Wenruo

BTW, the DISABLE_BACKTRACE branch seems quite different from backtrace one.

#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) #else
#define BUG_ON(c) assert(!(c))
#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
#define ASSERT(c) assert(!(c))
#define BUG() assert(0)

Quoted 3 lines

Condition of BUG_ON/ASSERT/BUG are all logical notted for DISABLE_BACKTRACE.
While WARN_ON() of both branch are the same condition.

WARN_ON is using warning_trace as opposed to assert, and that is the reason it is not notted.

Quoted 5 lines

This seems quite confusing to me.

Any idea to make it more straightforward?

I just kept it the same as before. warning_trace was using an extra variable, trace, which was not needed because the print_trace was already in ifndefs.

Quoted 7 lines
Quoted 2 lines

I mean, better make the condition the same for both BUG/BUG_ON/ASSERT. So that we don't need to manually logical not the condition.

First of all, ASSERT and BUG_ON have opposite meanings. ASSERT() checks if the condition is true and continues (halts if false). BUG_ON() "bugs" if condition is true and halts (continues if false). So you would have to use opposite conditions.

I know, I mean, for both backtrace disabled and enabled case, the condition should be the same.

If not the same condition, it means assert_trace() has different meaning than original assert.

Quoted 8 lines
Quoted 8 lines

For example:
#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,(long) (c))
and
#define ASSERT(c) assert((c))

Quoted 5 lines
Quoted 2 lines

This looks much more straightforward, and easier to expose bug at review time.

Could you explain with a patch? You idea seems to add more code than reduce it.

Sure, will submit one soon.

Thanks,
Qu