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