source: rtems/cpukit/libdl/rtl-debugger.c @ 4408603

Last change on this file since 4408603 was f59d435d, checked in by Chris Johns <chrisj@…>, on Apr 12, 2018 at 7:46:49 AM

libdl: Remove _t from all structures as this is reserved for the standards

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 2012, 2018 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.org/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 <rtems/rtl/rtl-trace.h>
33#include <rtems/rtl/rtl-obj-fwd.h>
34
35struct r_debug  _rtld_debug;
36
37void
38_rtld_debug_state (void)
39{
40  /*
41   * Empty. GDB only needs to hit this location.
42   */
43}
44
45int
46_rtld_linkmap_add (rtems_rtl_obj* obj)
47{
48  struct link_map* l = obj->linkmap;
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
78void
79_rtld_linkmap_delete (rtems_rtl_obj* obj)
80{
81  struct link_map* l = obj->linkmap;
82  /*
83   *  link_maps are allocated together if not 1
84   */
85  struct link_map* e = l + obj->obj_num - 1;
86
87  while (e && e->l_next) e = e->l_next;
88
89  if (l->l_prev == NULL)
90  {
91    if ((_rtld_debug.r_map = e->l_next) != NULL)
92      e->l_next->l_prev = NULL;
93    return;
94  }
95
96  if ((l->l_prev->l_next = e->l_next) != NULL)
97    e->l_next->l_prev = l->l_prev;
98}
Note: See TracBrowser for help on using the repository browser.