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 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <rtems.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <string.h> |
---|
30 | #include <fcntl.h> |
---|
31 | #include <errno.h> |
---|
32 | #include <rtems/serdbg.h> |
---|
33 | |
---|
34 | |
---|
35 | /*=========================================================================*\ |
---|
36 | | Function: | |
---|
37 | \*-------------------------------------------------------------------------*/ |
---|
38 | int serdbg_init_dbg |
---|
39 | ( |
---|
40 | /*-------------------------------------------------------------------------*\ |
---|
41 | | Purpose: | |
---|
42 | | initialize remote gdb session over serial line | |
---|
43 | +---------------------------------------------------------------------------+ |
---|
44 | | Input Parameters: | |
---|
45 | \*-------------------------------------------------------------------------*/ |
---|
46 | void |
---|
47 | ) |
---|
48 | /*-------------------------------------------------------------------------*\ |
---|
49 | | Return Value: | |
---|
50 | | rtems_status_code | |
---|
51 | \*=========================================================================*/ |
---|
52 | { |
---|
53 | static boolean is_initialized = FALSE; |
---|
54 | |
---|
55 | rtems_status_code rc = RTEMS_SUCCESSFUL; |
---|
56 | |
---|
57 | if (is_initialized) { |
---|
58 | return RTEMS_SUCCESSFUL; |
---|
59 | } |
---|
60 | is_initialized = TRUE; |
---|
61 | /* |
---|
62 | * try to open serial device |
---|
63 | */ |
---|
64 | if (rc == RTEMS_SUCCESSFUL) { |
---|
65 | if ((serdbg_conf.open_io != NULL) && |
---|
66 | (0 > serdbg_conf.open_io(serdbg_conf.devname,serdbg_conf.baudrate))) { |
---|
67 | fprintf(stderr, |
---|
68 | "remote_gdb_init: cannot open device %s " |
---|
69 | "for gdb connection:%s\n",serdbg_conf.devname,strerror(errno)); |
---|
70 | rc = RTEMS_IO_ERROR; |
---|
71 | } |
---|
72 | } |
---|
73 | /* |
---|
74 | * initialize gdb stub |
---|
75 | */ |
---|
76 | if (rc == RTEMS_SUCCESSFUL) { |
---|
77 | set_debug_traps(); |
---|
78 | } |
---|
79 | /* |
---|
80 | * now activate gdb stub |
---|
81 | */ |
---|
82 | if ((rc == RTEMS_SUCCESSFUL) && |
---|
83 | !serdbg_conf.skip_init_bkpt) { |
---|
84 | breakpoint(); |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * return to original function |
---|
89 | * this may be already unter gdb control |
---|
90 | */ |
---|
91 | return rc; |
---|
92 | } |
---|