[9e633f5] | 1 | /*===============================================================*\ |
---|
| 2 | | Project: RTEMS remote gdb over serial line | |
---|
| 3 | +-----------------------------------------------------------------+ |
---|
| 4 | | File: serdbg.c | |
---|
| 5 | +-----------------------------------------------------------------+ |
---|
| 6 | | Copyright (c) 2002 IMD | |
---|
| 7 | | Ingenieurbuero fuer Microcomputertechnik Th. Doerfler | |
---|
| 8 | | <Thomas.Doerfler@imd-systems.de> | |
---|
| 9 | | all rights reserved | |
---|
| 10 | +-----------------------------------------------------------------+ |
---|
| 11 | | this file contains intialization and utility functions to add | |
---|
| 12 | | a gdb remote debug stub to an RTEMS system | |
---|
| 13 | | | |
---|
| 14 | +-----------------------------------------------------------------+ |
---|
| 15 | | date history ID | |
---|
| 16 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
| 17 | | 04.04.02 creation doe | |
---|
| 18 | \*===============================================================*/ |
---|
| 19 | /* |
---|
| 20 | * $Id$ |
---|
| 21 | */ |
---|
| 22 | #include <rtems.h> |
---|
| 23 | #include <stdio.h> |
---|
| 24 | #include <string.h> |
---|
| 25 | #include <fcntl.h> |
---|
| 26 | #include <errno.h> |
---|
| 27 | #include <serdbg.h> |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /*=========================================================================*\ |
---|
| 31 | | Function: | |
---|
| 32 | \*-------------------------------------------------------------------------*/ |
---|
| 33 | int serdbg_init_dbg |
---|
| 34 | ( |
---|
| 35 | /*-------------------------------------------------------------------------*\ |
---|
| 36 | | Purpose: | |
---|
| 37 | | initialize remote gdb session over serial line | |
---|
| 38 | +---------------------------------------------------------------------------+ |
---|
| 39 | | Input Parameters: | |
---|
| 40 | \*-------------------------------------------------------------------------*/ |
---|
| 41 | void |
---|
| 42 | ) |
---|
| 43 | /*-------------------------------------------------------------------------*\ |
---|
| 44 | | Return Value: | |
---|
| 45 | | rtems_status_code | |
---|
| 46 | \*=========================================================================*/ |
---|
| 47 | { |
---|
| 48 | static boolean is_initialized = FALSE; |
---|
| 49 | |
---|
| 50 | rtems_status_code rc = RTEMS_SUCCESSFUL; |
---|
| 51 | extern void set_debug_traps(void); |
---|
| 52 | extern void breakpoint(void); |
---|
| 53 | |
---|
| 54 | if (is_initialized) { |
---|
| 55 | return RTEMS_SUCCESSFUL; |
---|
| 56 | } |
---|
| 57 | is_initialized = TRUE; |
---|
| 58 | /* |
---|
| 59 | * try to open serial device |
---|
| 60 | */ |
---|
| 61 | if (rc == RTEMS_SUCCESSFUL) { |
---|
| 62 | if ((serdbg_conf.open_io != NULL) && |
---|
| 63 | (0 > serdbg_conf.open_io(serdbg_conf.devname,serdbg_conf.baudrate))) { |
---|
| 64 | fprintf(stderr, |
---|
| 65 | "remote_gdb_init: cannot open device %s " |
---|
| 66 | "for gdb connection:%s\n",serdbg_conf.devname,strerror(errno)); |
---|
| 67 | rc = RTEMS_IO_ERROR; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | /* |
---|
| 71 | * initialize gdb stub |
---|
| 72 | */ |
---|
| 73 | if (rc == RTEMS_SUCCESSFUL) { |
---|
| 74 | set_debug_traps(); |
---|
| 75 | } |
---|
| 76 | /* |
---|
| 77 | * now activate gdb stub |
---|
| 78 | */ |
---|
| 79 | if ((rc == RTEMS_SUCCESSFUL) && |
---|
| 80 | !serdbg_conf.skip_init_bkpt) { |
---|
| 81 | breakpoint(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /* |
---|
| 85 | * return to original function |
---|
| 86 | * this may be already unter gdb control |
---|
| 87 | */ |
---|
| 88 | return rc; |
---|
| 89 | } |
---|
| 90 | |
---|