Initial revision
[deliverable/binutils-gdb.git] / gdb / solib.c
CommitLineData
bd5635a1
RP
1/* Copyright (C) 1990 Free Software Foundation, Inc.
2
3This file is part of GDB.
4
5GDB is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 1, or (at your option)
8any later version.
9
10GDB is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GDB; see the file COPYING. If not, write to
17the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19/*
20** symbol definitions
21*/
22#include <sys/types.h>
23#include <string.h>
24#include <link.h>
25#include "defs.h"
26#include "param.h"
27#include "symtab.h"
28#include "gdbcore.h"
29#include "command.h"
30
31/*
32** local data declarations
33*/
34#define MAX_PATH_SIZE 256
35struct so_list {
36 struct link_map inferior_lm; /* inferior link map */
37 struct link_map *inferior_lm_add;
38 long ld_text;
39 char inferior_so_name[MAX_PATH_SIZE]; /* Shared Object Library Name */
40 struct so_list *next; /* Next Structure */
41 int symbols_loaded;
42};
43
44static struct so_list *so_list_head = 0;
45
46/*=======================================================================*/
47
48/* find_solib
49**
50**Description:
51**
52** This module contains the routine which finds the names of any loaded
53** "images" in the current process. The argument in must be NULL on the
54** first call, and then the returned value must be passed in on
55** subsequent calls. This provides the capability to "step" down the
56** list of loaded objects. On the last object, a NULL value is returned.
57** The arg and return value are "struct link_map" pointers, as defined
58** in <link.h>.
59**
60** NOTE: This only works under SunOS4.0.
61*/
62
63struct so_list *find_solib(so_list_ptr)
64struct so_list *so_list_ptr; /* so_list_head position ptr */
65{
66struct so_list *so_list_next = 0;
67CORE_ADDR inferior_dynamic_ptr = 0;
68struct link_map *inferior_lm = 0;
69struct link_dynamic inferior_dynamic_cpy;
70struct link_dynamic_2 inferior_ld_2_cpy;
71struct so_list *new;
72int i;
73
74 if (!so_list_ptr) {
75 if (!(so_list_next = so_list_head)) {
76 for (i = 0; i < misc_function_count; i++) {
77 if (!strcmp (misc_function_vector[i].name, "_DYNAMIC")) {
78 inferior_dynamic_ptr = misc_function_vector[i].address;
79 break;
80 }
81 }
82 if (inferior_dynamic_ptr) {
83 read_memory(inferior_dynamic_ptr, &inferior_dynamic_cpy, sizeof(struct link_dynamic));
84 if (inferior_dynamic_cpy.ld_version == 3) {
85 read_memory((CORE_ADDR)inferior_dynamic_cpy.ld_un.ld_2,
86 &inferior_ld_2_cpy,
87 sizeof(struct link_dynamic_2));
88 inferior_lm = inferior_ld_2_cpy.ld_loaded;
89 }
90 }
91 }
92 } else {
93 /*
94 ** Advance to next local abbreviated load_map structure
95 */
96 if (!(inferior_lm = so_list_ptr->inferior_lm.lm_next)) {
97 /*
98 ** See if any were added
99 */
100 read_memory((CORE_ADDR)so_list_ptr->inferior_lm_add,
101 &so_list_ptr->inferior_lm,
102 sizeof(struct link_map));
103 inferior_lm = so_list_ptr->inferior_lm.lm_next;
104 }
105 so_list_next = so_list_ptr->next;
106 }
107 if ((!so_list_next) && inferior_lm) {
108 /*
109 ** Get Next LM Structure from inferior image and build
110 ** an local abbreviated load_map structure
111 */
112 new = (struct so_list *) xmalloc(sizeof(struct so_list));
113 new->inferior_lm_add = inferior_lm;
114 read_memory((CORE_ADDR)inferior_lm,
115 &new->inferior_lm,
116 sizeof(struct link_map));
117
118 read_memory((CORE_ADDR)new->inferior_lm.lm_name,
119 new->inferior_so_name,
120 MAX_PATH_SIZE - 1);
121 new->inferior_so_name[MAX_PATH_SIZE - 1] = 0;
122 /* Zero everything after the first terminating null */
123 strncpy(new->inferior_so_name, new->inferior_so_name, MAX_PATH_SIZE);
124
125 read_memory((CORE_ADDR)new->inferior_lm.lm_ld,
126 &inferior_dynamic_cpy,
127 sizeof(struct link_dynamic));
128 read_memory((CORE_ADDR)inferior_dynamic_cpy.ld_un.ld_2,
129 &inferior_ld_2_cpy,
130 sizeof(struct link_dynamic_2));
131 new->ld_text = inferior_ld_2_cpy.ld_text;
132
133 new->next = 0;
134 new->symbols_loaded = 0;
135 if (so_list_ptr)
136 so_list_ptr->next = new;
137 else
138 so_list_head = new;
139 so_list_next = new;
140 }
141 return(so_list_next);
142}
143/*=======================================================================*/
144
145static void solib_add(arg_string, from_tty)
146char *arg_string;
147int from_tty;
148{
149 register struct so_list *so = 0; /* link map state variable */
150 char *val;
151 int sz;
152
153 if (arg_string == 0)
154 re_comp (".");
155 else if (val = (char *) re_comp (arg_string)) {
156 error ("Invalid regexp: %s", val);
157 }
158
159 printf_filtered ("All shared libraries");
160 if (arg_string)
161 printf_filtered (" matching regular expresion \"%s\"", arg_string);
162 printf_filtered (":\n");
163
164 dont_repeat();
165
166 while (so = find_solib(so)) {
167 if (re_exec(so->inferior_so_name)) {
168 if (so->symbols_loaded) {
169 printf("Symbols already loaded for %s\n", so->inferior_so_name);
170 } else {
171 /* File Name String Freed by processing */
172 sz = strlen(so->inferior_so_name) + 1;
173 val = (char *) xmalloc(sz);
174 bcopy(so->inferior_so_name, val, sz);
175 symbol_file_add (val, from_tty,
176 (unsigned int)so->inferior_lm.lm_addr, 0);
177 so->symbols_loaded = 1;
178 }
179 }
180 }
181}
182/*=======================================================================*/
183
184static void solib_info()
185{
186register struct so_list *so = 0; /* link map state variable */
187
188 while (so = find_solib(so)) {
189 if (so == so_list_head) {
190 printf(" Address Range Symbols Shared Object Library\n");
191 }
192 printf(" 0x%08x - 0x%08x %s %s\n",
193 so->inferior_lm.lm_addr,
194 so->inferior_lm.lm_addr + so->ld_text - 1,
195 (so->symbols_loaded ? "Yes" : "No "),
196 so->inferior_so_name);
197 }
198 if (!so_list_head) {
199 printf("No shared libraries loaded at this time.\n");
200 }
201}
202
203/*
204** Called by Insert Breakpoint to see if Address is Shared Library Address
205*/
206int
207solib_address(address)
208 CORE_ADDR address;
209{
210register struct so_list *so = 0; /* link map state variable */
211
212 while (so = find_solib(so)) {
213 if ((address >= (CORE_ADDR) so->inferior_lm.lm_addr) &&
214 (address < (CORE_ADDR) so->inferior_lm.lm_addr + so->ld_text))
215 return 1;
216 }
217 return 0;
218}
219
220/*
221** Called by free_all_symtabs
222*/
223void
224clear_solib()
225{
226struct so_list *next;
227
228 while (so_list_head) {
229 next = so_list_head->next;
230 free(so_list_head);
231 so_list_head = next;
232 }
233
234}
235
236void
237_initialize_solib()
238{
239
240 add_com("sharedlibrary", class_files, solib_add,
241 "Load shared object library symbols for files matching REGEXP.");
242 add_info("sharedlibrary", solib_info,
243 "Status of loaded shared object libraries");
244
245}
This page took 0.03084 seconds and 4 git commands to generate.