diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 47bf9969469..a68975b4b59 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-05-31 Frederic Konrad + + * tracebak.c (STOP_FRAME): Harden condition. + (is_return_from, EXTRA_STOP_CONDITION): New helpers for VxWorks in RTP + mode. + 2018-05-31 Ed Schonberg * checks.adb (Apply_Discriminant_Check): Do not apply discriminant diff --git a/gcc/ada/tracebak.c b/gcc/ada/tracebak.c index 1f41810bbfb..9918123d948 100644 --- a/gcc/ada/tracebak.c +++ b/gcc/ada/tracebak.c @@ -478,10 +478,11 @@ struct layout #define PC_ADJUST -2 #define STOP_FRAME(CURRENT, TOP_STACK) \ (IS_BAD_PTR((long)(CURRENT)) \ + || (void *) (CURRENT) < (TOP_STACK) \ || IS_BAD_PTR((long)(CURRENT)->return_address) \ || (CURRENT)->return_address == 0 \ || (void *) ((CURRENT)->next) < (TOP_STACK) \ - || (void *) (CURRENT) < (TOP_STACK)) + || EXTRA_STOP_CONDITION(CURRENT)) #define BASE_SKIP (1+FRAME_LEVEL) @@ -504,6 +505,37 @@ struct layout || ((*((ptr) - 1) & 0xff) == 0xff) \ || (((*(ptr) & 0xd0ff) == 0xd0ff)))) +#if defined (__vxworks) && defined (__RTP__) + +/* For VxWorks following backchains past the "main" frame gets us into the + kernel space, where it can't be dereferenced. So lets stop at the main + symbol. */ +extern void main(); + +static int +is_return_from(void *symbol_addr, void *ret_addr) +{ + int ret = 0; + char *ptr = (char *)ret_addr; + + if ((*(ptr - 5) & 0xff) == 0xe8) + { + /* call addr16 E8 xx xx xx xx */ + int32_t offset = *(int32_t *)(ptr - 4); + ret = (ptr + offset) == symbol_addr; + } + + /* Others not implemented yet... But it is very likely that call addr16 + is used here. */ + return ret; +} + +#define EXTRA_STOP_CONDITION(CURRENT) \ + (is_return_from(&main, (CURRENT)->return_address)) +#else /* not (defined (__vxworks) && defined (__RTP__)) */ +#define EXTRA_STOP_CONDITION(CURRENT) (0) +#endif /* not (defined (__vxworks) && defined (__RTP__)) */ + /*----------------------------- qnx ----------------------------------*/ #elif defined (__QNX__)