All of lore.kernel.org
 help / color / mirror / Atom feed
* assert
@ 2016-06-27 16:16 Sage Weil
  2016-06-27 16:20 ` assert Ramesh Chander
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Sage Weil @ 2016-06-27 16:16 UTC (permalink / raw)
  To: ceph-devel

We have a problem with assert.  Actually, a few problems.

1. Our code is written assuming that assert is never compiled out.  We 
have lots of assert(0) and assert(0 == "informative failure message") 
instances all over the code that should really be something like abort().  
If you compile out assert, things won't work (well, fail) as expected.

2. We have a special implementation of assert in include/assert.h that 
will log the assertion failure to the global debug log, along with a stack 
track, before crashing.  This is normally fine, except that lots of random 
library or system headers include the system assert 
(/usr/include/assert.h), which is written such that it does not lib nicely 
with another definition.  From /usr/include/assert.h:

#ifdef  _ASSERT_H

# undef _ASSERT_H
# undef assert
# undef __ASSERT_VOID_CAST

# ifdef __USE_GNU
#  undef assert_perror
# endif

#endif /* assert.h      */

#define _ASSERT_H       1

That means that if you include our assert, and then some other random 
header includes /usr/include/assert, it will (silently!) clobber ours.

3. This is all highlighted by the switch to cmake.  The current defautl 
build does not define NDEBUG, which means that assert is compiled away, 
and we get a bunch of unused variable warnings from code like

  r = read(...);
  assert(r > 0);

So... what do to?  We can fix these instances when we find them, but the 
#include order is inherently fragile.

Note that using the system assert isn't a total disaster: system assert 
will trigger an abort, which will trigger the SIGABRT handler which *also* 
dumps a stack trace to the debug log.  The problem is that it 
doesn't show the assertion condition and line number.


I suggest:

0. Switch cmake to a debug but optimized build.  Ensure the release builds 
do the same.

1. Do an audit and replace assert(0) et al with ceph_abort(const char 
*msg), or similar.

2. Replace all other instances of assert with ceph_assert.

That's a lot of work, though.  Other ideas?

sage

^ permalink raw reply	[flat|nested] 22+ messages in thread
* assert
@ 2013-09-25 13:18 Jon Grant
       [not found] ` <CAGc9EvdE4Fd5QaJ_Rj+CsZkwvktTCPcnupJmSwNfM5SJRefAJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Jon Grant @ 2013-09-25 13:18 UTC (permalink / raw)
  To: Michael Kerrisk; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hello mtk

Would it be better to replace "his" with "their", in the interests of equality?

http://man7.org/linux/man-pages/man3/assert.3.html

       "The purpose of this macro is to help the programmer find bugs in his
       program.  The message "assertion failed in file foo.c, function
       do_bar(), line 1287" is of no help at all to a user."


NB. This may apply to other man pages.

Best regards, Jon
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-08-28 17:54 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-27 16:16 assert Sage Weil
2016-06-27 16:20 ` assert Ramesh Chander
2016-06-27 16:39 ` assert John Spray
2016-06-27 16:45   ` assert Sage Weil
2016-06-27 16:52     ` assert Allen Samuels
2016-06-27 18:10     ` assert Somnath Roy
2016-08-24 14:34     ` assert Matt Benjamin
2016-08-24 15:45       ` assert Adam C. Emerson
2016-08-24 16:17         ` assert Casey Bodley
2016-08-24 16:26           ` assert Sage Weil
2016-08-24 16:23         ` assert Sage Weil
2016-08-24 16:26           ` assert Adam C. Emerson
2016-08-24 16:38             ` assert Yehuda Sadeh-Weinraub
2016-08-24 17:05               ` assert Matt Benjamin
2016-08-24 17:10               ` assert Adam C. Emerson
2016-08-24 17:22                 ` assert Matt Benjamin
2016-08-24 17:26                   ` assert Adam C. Emerson
2016-08-24 17:13             ` assert Willem Jan Withagen
2016-06-28 14:10 ` assert kefu chai
  -- strict thread matches above, loose matches on Subject: below --
2013-09-25 13:18 assert Jon Grant
     [not found] ` <CAGc9EvdE4Fd5QaJ_Rj+CsZkwvktTCPcnupJmSwNfM5SJRefAJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-09-26 16:31   ` assert Michael Kerrisk (man-pages)
     [not found]     ` <5244617E.3000306-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-09-27 22:42       ` assert Jonny Grant

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.