1 | /* -----------------------------------------------------------------------
|
---|
2 | debug.c - Copyright (c) 1996 Cygnus Solutions
|
---|
3 |
|
---|
4 | Permission is hereby granted, free of charge, to any person obtaining
|
---|
5 | a copy of this software and associated documentation files (the
|
---|
6 | ``Software''), to deal in the Software without restriction, including
|
---|
7 | without limitation the rights to use, copy, modify, merge, publish,
|
---|
8 | distribute, sublicense, and/or sell copies of the Software, and to
|
---|
9 | permit persons to whom the Software is furnished to do so, subject to
|
---|
10 | the following conditions:
|
---|
11 |
|
---|
12 | The above copyright notice and this permission notice shall be included
|
---|
13 | in all copies or substantial portions of the Software.
|
---|
14 |
|
---|
15 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
---|
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
---|
18 | IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
20 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
21 | OTHER DEALINGS IN THE SOFTWARE.
|
---|
22 | ----------------------------------------------------------------------- */
|
---|
23 |
|
---|
24 | #include <ffi.h>
|
---|
25 | #include <ffi_common.h>
|
---|
26 | #include <stdlib.h>
|
---|
27 | #include <stdio.h>
|
---|
28 |
|
---|
29 | /* General debugging routines */
|
---|
30 |
|
---|
31 | void ffi_stop_here(void)
|
---|
32 | {
|
---|
33 | /* This function is only useful for debugging purposes.
|
---|
34 | Place a breakpoint on ffi_stop_here to be notified of
|
---|
35 | significant events. */
|
---|
36 | }
|
---|
37 |
|
---|
38 | /* This function should only be called via the FFI_ASSERT() macro */
|
---|
39 |
|
---|
40 | int ffi_assert(char *file, int line)
|
---|
41 | {
|
---|
42 | fprintf(stderr, "ASSERTION FAILURE: %s line %d\n", file, line);
|
---|
43 | ffi_stop_here();
|
---|
44 | abort();
|
---|
45 |
|
---|
46 | /* This has to return something for the compiler not to complain */
|
---|
47 | /*@notreached@*/
|
---|
48 | return 0;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /* Perform a sanity check on an ffi_type structure */
|
---|
52 |
|
---|
53 | bool ffi_type_test(ffi_type *a)
|
---|
54 | {
|
---|
55 | /*@-usedef@*/
|
---|
56 | FFI_ASSERT(a->type <= FFI_TYPE_LAST);
|
---|
57 | FFI_ASSERT(a->type > FFI_TYPE_VOID ? a->size > 0 : 1);
|
---|
58 | FFI_ASSERT(a->type > FFI_TYPE_VOID ? a->alignment > 0 : 1);
|
---|
59 | FFI_ASSERT(a->type == FFI_TYPE_STRUCT ? a->elements != NULL : 1);
|
---|
60 | /*@=usedef@*/
|
---|
61 |
|
---|
62 | /* This is a silly thing to return, but it keeps the compiler from
|
---|
63 | issuing warnings about "a" not being used in non-debug builds. */
|
---|
64 | return (a != NULL);
|
---|
65 | }
|
---|