| 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, EXPRESS |
|---|
| 16 | n/a | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|---|
| 17 | n/a | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|---|
| 18 | n/a | IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
|---|
| 19 | n/a | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
|---|
| 20 | n/a | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|---|
| 21 | n/a | OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 22 | n/a | ----------------------------------------------------------------------- */ |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | #include <ffi.h> |
|---|
| 25 | n/a | #include <ffi_common.h> |
|---|
| 26 | n/a | #include <stdlib.h> |
|---|
| 27 | n/a | #include <stdio.h> |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | /* General debugging routines */ |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | void ffi_stop_here(void) |
|---|
| 32 | n/a | { |
|---|
| 33 | n/a | /* This function is only useful for debugging purposes. |
|---|
| 34 | n/a | Place a breakpoint on ffi_stop_here to be notified of |
|---|
| 35 | n/a | significant events. */ |
|---|
| 36 | n/a | } |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | /* This function should only be called via the FFI_ASSERT() macro */ |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | void ffi_assert(char *expr, char *file, int line) |
|---|
| 41 | n/a | { |
|---|
| 42 | n/a | fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line); |
|---|
| 43 | n/a | ffi_stop_here(); |
|---|
| 44 | n/a | abort(); |
|---|
| 45 | n/a | } |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | /* Perform a sanity check on an ffi_type structure */ |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | void ffi_type_test(ffi_type *a, char *file, int line) |
|---|
| 50 | n/a | { |
|---|
| 51 | n/a | FFI_ASSERT_AT(a != NULL, file, line); |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | /*@-usedef@*/ |
|---|
| 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 | /*@=usedef@*/ |
|---|
| 59 | n/a | } |
|---|