1 | /* |
---|
2 | * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.com/license/LICENSE. |
---|
7 | */ |
---|
8 | /** |
---|
9 | * @file |
---|
10 | * |
---|
11 | * @ingroup rtl |
---|
12 | * |
---|
13 | * @brief RTEMS Module Loading Debugger Interface. |
---|
14 | * |
---|
15 | * Inspection of run-time linkers in NetBSD and Android show a common type of |
---|
16 | * structure that is used to interface to GDB. The NetBSD definition of this |
---|
17 | * interface is being used and is defined in <link.h>. It defines a protocol |
---|
18 | * that is used by GDB to inspect the state of dynamic libraries. I have not |
---|
19 | * checked GDB code at when writing this comment but I suspect GDB sets a break |
---|
20 | * point on the r_brk field of _rtld_debug and it has code that detects this |
---|
21 | * break point being hit. When this happens it reads the state and performs the |
---|
22 | * operation based on the r_state field. |
---|
23 | */ |
---|
24 | |
---|
25 | #if HAVE_CONFIG_H |
---|
26 | #include "config.h" |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | #include <link.h> |
---|
31 | #include <rtems/rtl/rtl.h> |
---|
32 | #include "rtl-trace.h" |
---|
33 | #include "rtl-obj-fwd.h" |
---|
34 | |
---|
35 | struct r_debug _rtld_debug; |
---|
36 | |
---|
37 | void |
---|
38 | _rtld_debug_state (void) |
---|
39 | { |
---|
40 | /* |
---|
41 | * Empty. GDB only needs to hit this location. |
---|
42 | */ |
---|
43 | } |
---|
44 | |
---|
45 | int |
---|
46 | _rtld_linkmap_add (rtems_rtl_obj_t* obj) |
---|
47 | { |
---|
48 | struct link_map* l = (struct link_map*)obj->detail; |
---|
49 | struct link_map* prev; |
---|
50 | uint32_t obj_num = obj->obj_num; |
---|
51 | int i; |
---|
52 | |
---|
53 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL)) |
---|
54 | printf ("rtl: linkmap_add\n"); |
---|
55 | |
---|
56 | for (i = 0; i < obj_num; ++i) |
---|
57 | { |
---|
58 | l[i].sec_addr[rap_text] = obj->text_base; |
---|
59 | l[i].sec_addr[rap_const] = obj->const_base; |
---|
60 | l[i].sec_addr[rap_data] = obj->data_base; |
---|
61 | l[i].sec_addr[rap_bss] = obj->bss_base; |
---|
62 | } |
---|
63 | |
---|
64 | if (_rtld_debug.r_map == NULL) |
---|
65 | { |
---|
66 | _rtld_debug.r_map = l; |
---|
67 | return true; |
---|
68 | } |
---|
69 | |
---|
70 | for (prev = _rtld_debug.r_map; prev->l_next != NULL; prev = prev->l_next); |
---|
71 | |
---|
72 | l->l_prev = prev; |
---|
73 | prev->l_next = l; |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | void |
---|
79 | _rtld_linkmap_delete (rtems_rtl_obj_t* obj) |
---|
80 | { |
---|
81 | struct link_map* l = (struct link_map*)obj->detail; |
---|
82 | /* link_maps are allocated together if not 1 */ |
---|
83 | struct link_map* e = l + obj->obj_num - 1; |
---|
84 | |
---|
85 | while (e && e->l_next) e = e->l_next; |
---|
86 | |
---|
87 | if (l->l_prev == NULL) |
---|
88 | { |
---|
89 | if ((_rtld_debug.r_map = e->l_next) != NULL) |
---|
90 | e->l_next->l_prev = NULL; |
---|
91 | return; |
---|
92 | } |
---|
93 | if ((l->l_prev->l_next = e->l_next) != NULL) |
---|
94 | e->l_next->l_prev = l->l_prev; |
---|
95 | return; |
---|
96 | } |
---|