GDB (xrefs)
Loading...
Searching...
No Matches
solib-dsbt.c
Go to the documentation of this file.
1/* Handle TIC6X (DSBT) shared libraries for GDB, the GNU Debugger.
2 Copyright (C) 2010-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19
20#include "defs.h"
21#include "inferior.h"
22#include "gdbcore.h"
23#include "solib.h"
24#include "solist.h"
25#include "objfiles.h"
26#include "symtab.h"
27#include "command.h"
28#include "gdb_bfd.h"
29#include "solib-dsbt.h"
30#include "elf/common.h"
31#include "cli/cli-cmds.h"
32
33#define GOT_MODULE_OFFSET 4
34
35/* Flag which indicates whether internal debug messages should be printed. */
36static unsigned int solib_dsbt_debug = 0;
37
38/* TIC6X pointers are four bytes wide. */
39enum { TIC6X_PTR_SIZE = 4 };
40
41/* Representation of loadmap and related structs for the TIC6X DSBT. */
42
43/* External versions; the size and alignment of the fields should be
44 the same as those on the target. When loaded, the placement of
45 the bits in each field will be the same as on the target. */
46typedef gdb_byte ext_Elf32_Half[2];
47typedef gdb_byte ext_Elf32_Addr[4];
48typedef gdb_byte ext_Elf32_Word[4];
49
51{
52 /* Core address to which the segment is mapped. */
54 /* VMA recorded in the program header. */
56 /* Size of this segment in memory. */
58};
59
61 /* Protocol version number, must be zero. */
63 /* A pointer to the DSBT table; the DSBT size and the index of this
64 module. */
68 /* Number of segments in this map. */
70 /* The actual memory map. */
71 struct ext_elf32_dsbt_loadseg segs[1 /* nsegs, actually */];
72};
73
74/* Internal versions; the types are GDB types and the data in each
75 of the fields is (or will be) decoded from the external struct
76 for ease of consumption. */
78{
79 /* Core address to which the segment is mapped. */
80 CORE_ADDR addr;
81 /* VMA recorded in the program header. */
82 CORE_ADDR p_vaddr;
83 /* Size of this segment in memory. */
84 long p_memsz;
85};
86
88{
89 /* Protocol version number, must be zero. */
91 CORE_ADDR dsbt_table_ptr;
92 /* A pointer to the DSBT table; the DSBT size and the index of this
93 module. */
95 /* Number of segments in this map. */
96 int nsegs;
97 /* The actual memory map. */
98 struct int_elf32_dsbt_loadseg segs[1 /* nsegs, actually */];
99};
100
101/* External link_map and elf32_dsbt_loadaddr struct definitions. */
102
103typedef gdb_byte ext_ptr[4];
104
106{
107 ext_ptr map; /* struct elf32_dsbt_loadmap *map; */
108};
109
111{
113
114 /* Absolute file name object was found in. */
115 ext_ptr l_name; /* char *l_name; */
116
117 /* Dynamic section of the shared object. */
118 ext_ptr l_ld; /* ElfW(Dyn) *l_ld; */
119
120 /* Chain of loaded objects. */
121 ext_ptr l_next, l_prev; /* struct link_map *l_next, *l_prev; */
122};
123
124/* Link map info to include in an allocated so_list entry */
125
127{
129 {
130 xfree (this->map);
131 }
132
133 /* The loadmap, digested into an easier to use form. */
135};
136
137/* Per pspace dsbt specific data. */
138
140{
141 /* The load map, got value, etc. are not available from the chain
142 of loaded shared objects. ``main_executable_lm_info'' provides
143 a way to get at this information so that it doesn't need to be
144 frequently recomputed. Initialized by dsbt_relocate_main_executable. */
146
147 /* Load maps for the main executable and the interpreter. These are obtained
148 from ptrace. They are the starting point for getting into the program,
149 and are required to find the solib list with the individual load maps for
150 each module. */
153
154 /* Cached value for lm_base, below. */
155 CORE_ADDR lm_base_cache = 0;
156
157 /* Link map address for main module. */
158 CORE_ADDR main_lm_addr = 0;
159
160 CORE_ADDR interp_text_sect_low = 0;
162 CORE_ADDR interp_plt_sect_low = 0;
163 CORE_ADDR interp_plt_sect_high = 0;
164};
165
166/* Per-program-space data key. */
168
169/* Get the current dsbt data. If none is found yet, add it now. This
170 function always returns a valid object. */
171
172static struct dsbt_info *
174{
175 struct dsbt_info *info;
176
178 if (info != NULL)
179 return info;
180
182}
183
184
185static void
187{
188 int i;
189
190 if (map == NULL)
191 gdb_printf ("(null)\n");
192 else if (map->version != 0)
193 gdb_printf (_("Unsupported map version: %d\n"), map->version);
194 else
195 {
196 gdb_printf ("version %d\n", map->version);
197
198 for (i = 0; i < map->nsegs; i++)
199 gdb_printf ("%s:%s -> %s:%s\n",
201 map->segs[i].p_vaddr),
203 map->segs[i].p_vaddr
204 + map->segs[i].p_memsz),
207 + map->segs[i].p_memsz));
208 }
209}
210
211/* Decode int_elf32_dsbt_loadmap from BUF. */
212
213static struct int_elf32_dsbt_loadmap *
214decode_loadmap (const gdb_byte *buf)
215{
216 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
217 const struct ext_elf32_dsbt_loadmap *ext_ldmbuf;
218 struct int_elf32_dsbt_loadmap *int_ldmbuf;
219
220 int version, seg, nsegs;
221 int int_ldmbuf_size;
222
223 ext_ldmbuf = (struct ext_elf32_dsbt_loadmap *) buf;
224
225 /* Extract the version. */
227 sizeof ext_ldmbuf->version,
228 byte_order);
229 if (version != 0)
230 {
231 /* We only handle version 0. */
232 return NULL;
233 }
234
235 /* Extract the number of segments. */
236 nsegs = extract_unsigned_integer (ext_ldmbuf->nsegs,
237 sizeof ext_ldmbuf->nsegs,
238 byte_order);
239
240 if (nsegs <= 0)
241 return NULL;
242
243 /* Allocate space into which to put information extract from the
244 external loadsegs. I.e, allocate the internal loadsegs. */
245 int_ldmbuf_size = (sizeof (struct int_elf32_dsbt_loadmap)
246 + (nsegs - 1) * sizeof (struct int_elf32_dsbt_loadseg));
247 int_ldmbuf = (struct int_elf32_dsbt_loadmap *) xmalloc (int_ldmbuf_size);
248
249 /* Place extracted information in internal structs. */
250 int_ldmbuf->version = version;
251 int_ldmbuf->nsegs = nsegs;
252 for (seg = 0; seg < nsegs; seg++)
253 {
254 int_ldmbuf->segs[seg].addr
255 = extract_unsigned_integer (ext_ldmbuf->segs[seg].addr,
256 sizeof (ext_ldmbuf->segs[seg].addr),
257 byte_order);
258 int_ldmbuf->segs[seg].p_vaddr
259 = extract_unsigned_integer (ext_ldmbuf->segs[seg].p_vaddr,
260 sizeof (ext_ldmbuf->segs[seg].p_vaddr),
261 byte_order);
262 int_ldmbuf->segs[seg].p_memsz
263 = extract_unsigned_integer (ext_ldmbuf->segs[seg].p_memsz,
264 sizeof (ext_ldmbuf->segs[seg].p_memsz),
265 byte_order);
266 }
267
268 return int_ldmbuf;
269}
270
271
272static struct dsbt_info *get_dsbt_info (void);
273
274/* Interrogate the Linux kernel to find out where the program was loaded.
275 There are two load maps; one for the executable and one for the
276 interpreter (only in the case of a dynamically linked executable). */
277
278static void
280{
281 struct dsbt_info *info = get_dsbt_info ();
282 gdb::optional<gdb::byte_vector> buf
283 = target_read_alloc (current_inferior ()->top_target (),
284 TARGET_OBJECT_FDPIC, "exec");
285
286 if (!buf || buf->empty ())
287 {
288 info->exec_loadmap = NULL;
289 error (_("Error reading DSBT exec loadmap"));
290 }
291 info->exec_loadmap = decode_loadmap (buf->data ());
293 dsbt_print_loadmap (info->exec_loadmap);
294
295 buf = target_read_alloc (current_inferior ()->top_target (),
296 TARGET_OBJECT_FDPIC, "exec");
297 if (!buf || buf->empty ())
298 {
299 info->interp_loadmap = NULL;
300 error (_("Error reading DSBT interp loadmap"));
301 }
302 info->interp_loadmap = decode_loadmap (buf->data ());
304 dsbt_print_loadmap (info->interp_loadmap);
305}
306
307/* Given address LDMADDR, fetch and decode the loadmap at that address.
308 Return NULL if there is a problem reading the target memory or if
309 there doesn't appear to be a loadmap at the given address. The
310 allocated space (representing the loadmap) returned by this
311 function may be freed via a single call to xfree. */
312
313static struct int_elf32_dsbt_loadmap *
314fetch_loadmap (CORE_ADDR ldmaddr)
315{
316 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
317 struct ext_elf32_dsbt_loadmap ext_ldmbuf_partial;
318 struct ext_elf32_dsbt_loadmap *ext_ldmbuf;
319 struct int_elf32_dsbt_loadmap *int_ldmbuf;
320 int ext_ldmbuf_size, int_ldmbuf_size;
321 int version, seg, nsegs;
322
323 /* Fetch initial portion of the loadmap. */
324 if (target_read_memory (ldmaddr, (gdb_byte *) &ext_ldmbuf_partial,
325 sizeof ext_ldmbuf_partial))
326 {
327 /* Problem reading the target's memory. */
328 return NULL;
329 }
330
331 /* Extract the version. */
332 version = extract_unsigned_integer (ext_ldmbuf_partial.version,
333 sizeof ext_ldmbuf_partial.version,
334 byte_order);
335 if (version != 0)
336 {
337 /* We only handle version 0. */
338 return NULL;
339 }
340
341 /* Extract the number of segments. */
342 nsegs = extract_unsigned_integer (ext_ldmbuf_partial.nsegs,
343 sizeof ext_ldmbuf_partial.nsegs,
344 byte_order);
345
346 if (nsegs <= 0)
347 return NULL;
348
349 /* Allocate space for the complete (external) loadmap. */
350 ext_ldmbuf_size = sizeof (struct ext_elf32_dsbt_loadmap)
351 + (nsegs - 1) * sizeof (struct ext_elf32_dsbt_loadseg);
352 ext_ldmbuf = (struct ext_elf32_dsbt_loadmap *) xmalloc (ext_ldmbuf_size);
353
354 /* Copy over the portion of the loadmap that's already been read. */
355 memcpy (ext_ldmbuf, &ext_ldmbuf_partial, sizeof ext_ldmbuf_partial);
356
357 /* Read the rest of the loadmap from the target. */
358 if (target_read_memory (ldmaddr + sizeof ext_ldmbuf_partial,
359 (gdb_byte *) ext_ldmbuf + sizeof ext_ldmbuf_partial,
360 ext_ldmbuf_size - sizeof ext_ldmbuf_partial))
361 {
362 /* Couldn't read rest of the loadmap. */
363 xfree (ext_ldmbuf);
364 return NULL;
365 }
366
367 /* Allocate space into which to put information extract from the
368 external loadsegs. I.e, allocate the internal loadsegs. */
369 int_ldmbuf_size = sizeof (struct int_elf32_dsbt_loadmap)
370 + (nsegs - 1) * sizeof (struct int_elf32_dsbt_loadseg);
371 int_ldmbuf = (struct int_elf32_dsbt_loadmap *) xmalloc (int_ldmbuf_size);
372
373 /* Place extracted information in internal structs. */
374 int_ldmbuf->version = version;
375 int_ldmbuf->nsegs = nsegs;
376 for (seg = 0; seg < nsegs; seg++)
377 {
378 int_ldmbuf->segs[seg].addr
379 = extract_unsigned_integer (ext_ldmbuf->segs[seg].addr,
380 sizeof (ext_ldmbuf->segs[seg].addr),
381 byte_order);
382 int_ldmbuf->segs[seg].p_vaddr
383 = extract_unsigned_integer (ext_ldmbuf->segs[seg].p_vaddr,
384 sizeof (ext_ldmbuf->segs[seg].p_vaddr),
385 byte_order);
386 int_ldmbuf->segs[seg].p_memsz
387 = extract_unsigned_integer (ext_ldmbuf->segs[seg].p_memsz,
388 sizeof (ext_ldmbuf->segs[seg].p_memsz),
389 byte_order);
390 }
391
392 xfree (ext_ldmbuf);
393 return int_ldmbuf;
394}
395
396static void dsbt_relocate_main_executable (void);
397static int enable_break (void);
398
399/* See solist.h. */
400
401static int
403{
404 /* Unimplemented. */
405 return 0;
406}
407
408/* Given a loadmap and an address, return the displacement needed
409 to relocate the address. */
410
411static CORE_ADDR
413 CORE_ADDR addr)
414{
415 int seg;
416
417 for (seg = 0; seg < map->nsegs; seg++)
418 if (map->segs[seg].p_vaddr <= addr
419 && addr < map->segs[seg].p_vaddr + map->segs[seg].p_memsz)
420 return map->segs[seg].addr - map->segs[seg].p_vaddr;
421
422 return 0;
423}
424
425/* Return the address from which the link map chain may be found. On
426 DSBT, a pointer to the start of the link map will be located at the
427 word found at base of GOT + GOT_MODULE_OFFSET.
428
429 The base of GOT may be found in a number of ways. Assuming that the
430 main executable has already been relocated,
431 1 The easiest way to find this value is to look up the address of
432 _GLOBAL_OFFSET_TABLE_.
433 2 The other way is to look for tag DT_PLTGOT, which contains the virtual
434 address of Global Offset Table. .*/
435
436static CORE_ADDR
438{
439 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
440 struct bound_minimal_symbol got_sym;
441 CORE_ADDR addr;
442 gdb_byte buf[TIC6X_PTR_SIZE];
443 struct dsbt_info *info = get_dsbt_info ();
444
445 /* One of our assumptions is that the main executable has been relocated.
446 Bail out if this has not happened. (Note that post_create_inferior
447 in infcmd.c will call solib_add prior to solib_create_inferior_hook.
448 If we allow this to happen, lm_base_cache will be initialized with
449 a bogus value. */
450 if (info->main_executable_lm_info == 0)
451 return 0;
452
453 /* If we already have a cached value, return it. */
454 if (info->lm_base_cache)
455 return info->lm_base_cache;
456
457 got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL,
459
460 if (got_sym.minsym != 0)
461 {
462 addr = got_sym.value_address ();
465 "lm_base: get addr %x by _GLOBAL_OFFSET_TABLE_.\n",
466 (unsigned int) addr);
467 }
468 else if (gdb_bfd_scan_elf_dyntag (DT_PLTGOT,
470 &addr, NULL))
471 {
472 struct int_elf32_dsbt_loadmap *ldm;
473
475 ldm = info->exec_loadmap;
476 addr += displacement_from_map (ldm, addr);
479 "lm_base: get addr %x by DT_PLTGOT.\n",
480 (unsigned int) addr);
481 }
482 else
483 {
486 "lm_base: _GLOBAL_OFFSET_TABLE_ not found.\n");
487 return 0;
488 }
489 addr += GOT_MODULE_OFFSET;
490
493 "lm_base: _GLOBAL_OFFSET_TABLE_ + %d = %s\n",
494 GOT_MODULE_OFFSET, hex_string_custom (addr, 8));
495
496 if (target_read_memory (addr, buf, sizeof buf) != 0)
497 return 0;
498 info->lm_base_cache = extract_unsigned_integer (buf, sizeof buf, byte_order);
499
502 "lm_base: lm_base_cache = %s\n",
503 hex_string_custom (info->lm_base_cache, 8));
504
505 return info->lm_base_cache;
506}
507
508
509/* Build a list of `struct so_list' objects describing the shared
510 objects currently loaded in the inferior. This list does not
511 include an entry for the main executable file.
512
513 Note that we only gather information directly available from the
514 inferior --- we don't examine any of the shared library files
515 themselves. The declaration of `struct so_list' says which fields
516 we provide values for. */
517
518static struct so_list *
520{
521 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
522 CORE_ADDR lm_addr;
523 struct so_list *sos_head = NULL;
524 struct so_list **sos_next_ptr = &sos_head;
525 struct dsbt_info *info = get_dsbt_info ();
526
527 /* Make sure that the main executable has been relocated. This is
528 required in order to find the address of the global offset table,
529 which in turn is used to find the link map info. (See lm_base
530 for details.)
531
532 Note that the relocation of the main executable is also performed
533 by solib_create_inferior_hook, however, in the case of core
534 files, this hook is called too late in order to be of benefit to
535 solib_add. solib_add eventually calls this function,
536 dsbt_current_sos, and also precedes the call to
537 solib_create_inferior_hook. (See post_create_inferior in
538 infcmd.c.) */
539 if (info->main_executable_lm_info == 0 && core_bfd != NULL)
541
542 /* Locate the address of the first link map struct. */
543 lm_addr = lm_base ();
544
545 /* We have at least one link map entry. Fetch the lot of them,
546 building the solist chain. */
547 while (lm_addr)
548 {
549 struct dbst_ext_link_map lm_buf;
550 ext_Elf32_Word indexword;
551 CORE_ADDR map_addr;
552 int dsbt_index;
553 int ret;
554
557 "current_sos: reading link_map entry at %s\n",
558 hex_string_custom (lm_addr, 8));
559
560 ret = target_read_memory (lm_addr, (gdb_byte *) &lm_buf, sizeof (lm_buf));
561 if (ret)
562 {
563 warning (_("dsbt_current_sos: Unable to read link map entry."
564 " Shared object chain may be incomplete."));
565 break;
566 }
567
568 /* Fetch the load map address. */
569 map_addr = extract_unsigned_integer (lm_buf.l_addr.map,
570 sizeof lm_buf.l_addr.map,
571 byte_order);
572
573 ret = target_read_memory (map_addr + 12, (gdb_byte *) &indexword,
574 sizeof indexword);
575 if (ret)
576 {
577 warning (_("dsbt_current_sos: Unable to read dsbt index."
578 " Shared object chain may be incomplete."));
579 break;
580 }
581 dsbt_index = extract_unsigned_integer (indexword, sizeof indexword,
582 byte_order);
583
584 /* If the DSBT index is zero, then we're looking at the entry
585 for the main executable. By convention, we don't include
586 this in the list of shared objects. */
587 if (dsbt_index != 0)
588 {
589 struct int_elf32_dsbt_loadmap *loadmap;
590 struct so_list *sop;
591 CORE_ADDR addr;
592
593 loadmap = fetch_loadmap (map_addr);
594 if (loadmap == NULL)
595 {
596 warning (_("dsbt_current_sos: Unable to fetch load map."
597 " Shared object chain may be incomplete."));
598 break;
599 }
600
601 sop = XCNEW (struct so_list);
602 lm_info_dsbt *li = new lm_info_dsbt;
603 sop->lm_info = li;
604 li->map = loadmap;
605 /* Fetch the name. */
606 addr = extract_unsigned_integer (lm_buf.l_name,
607 sizeof (lm_buf.l_name),
608 byte_order);
609 gdb::unique_xmalloc_ptr<char> name_buf
611
612 if (name_buf == nullptr)
613 warning (_("Can't read pathname for link map entry."));
614 else
615 {
617 gdb_printf (gdb_stdlog, "current_sos: name = %s\n",
618 name_buf.get ());
619
620 strncpy (sop->so_name, name_buf.get (), SO_NAME_MAX_PATH_SIZE - 1);
621 sop->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
622 strcpy (sop->so_original_name, sop->so_name);
623 }
624
625 *sos_next_ptr = sop;
626 sos_next_ptr = &sop->next;
627 }
628 else
629 {
630 info->main_lm_addr = lm_addr;
631 }
632
634 sizeof (lm_buf.l_next), byte_order);
635 }
636
637 return sos_head;
638}
639
640/* Return 1 if PC lies in the dynamic symbol resolution code of the
641 run time loader. */
642
643static int
645{
646 struct dsbt_info *info = get_dsbt_info ();
647
648 return ((pc >= info->interp_text_sect_low && pc < info->interp_text_sect_high)
649 || (pc >= info->interp_plt_sect_low && pc < info->interp_plt_sect_high)
650 || in_plt_section (pc));
651}
652
653/* Print a warning about being unable to set the dynamic linker
654 breakpoint. */
655
656static void
658{
659 warning (_("Unable to find dynamic linker breakpoint function.\n"
660 "GDB will be unable to debug shared library initializers\n"
661 "and track explicitly loaded dynamic code."));
662}
663
664/* The dynamic linkers has, as part of its debugger interface, support
665 for arranging for the inferior to hit a breakpoint after mapping in
666 the shared libraries. This function enables that breakpoint.
667
668 On the TIC6X, using the shared library (DSBT), GDB can try to place
669 a breakpoint on '_dl_debug_state' to monitor the shared library
670 event. */
671
672static int
674{
675 asection *interp_sect;
676 struct dsbt_info *info;
677
678 if (current_program_space->exec_bfd () == NULL)
679 return 0;
680
681 if (!target_has_execution ())
682 return 0;
683
684 info = get_dsbt_info ();
685
686 info->interp_text_sect_low = 0;
687 info->interp_text_sect_high = 0;
688 info->interp_plt_sect_low = 0;
689 info->interp_plt_sect_high = 0;
690
691 /* Find the .interp section; if not found, warn the user and drop
692 into the old breakpoint at symbol code. */
693 interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
694 ".interp");
695 if (interp_sect)
696 {
697 unsigned int interp_sect_size;
698 char *buf;
699 CORE_ADDR addr;
700 struct int_elf32_dsbt_loadmap *ldm;
701 int ret;
702
703 /* Read the contents of the .interp section into a local buffer;
704 the contents specify the dynamic linker this program uses. */
705 interp_sect_size = bfd_section_size (interp_sect);
706 buf = (char *) alloca (interp_sect_size);
707 bfd_get_section_contents (current_program_space->exec_bfd (),
708 interp_sect, buf, 0, interp_sect_size);
709
710 /* Now we need to figure out where the dynamic linker was
711 loaded so that we can load its symbols and place a breakpoint
712 in the dynamic linker itself. */
713
714 gdb_bfd_ref_ptr tmp_bfd;
715 try
716 {
717 tmp_bfd = solib_bfd_open (buf);
718 }
719 catch (const gdb_exception &ex)
720 {
721 }
722
723 if (tmp_bfd == NULL)
724 {
726 return 0;
727 }
728
730 ldm = info->interp_loadmap;
731
732 /* Record the relocated start and end address of the dynamic linker
733 text and plt section for dsbt_in_dynsym_resolve_code. */
734 interp_sect = bfd_get_section_by_name (tmp_bfd.get (), ".text");
735 if (interp_sect)
736 {
737 info->interp_text_sect_low = bfd_section_vma (interp_sect);
738 info->interp_text_sect_low
739 += displacement_from_map (ldm, info->interp_text_sect_low);
740 info->interp_text_sect_high
741 = info->interp_text_sect_low + bfd_section_size (interp_sect);
742 }
743 interp_sect = bfd_get_section_by_name (tmp_bfd.get (), ".plt");
744 if (interp_sect)
745 {
746 info->interp_plt_sect_low = bfd_section_vma (interp_sect);
747 info->interp_plt_sect_low
748 += displacement_from_map (ldm, info->interp_plt_sect_low);
749 info->interp_plt_sect_high
750 = info->interp_plt_sect_low + bfd_section_size (interp_sect);
751 }
752
754 (tmp_bfd.get (),
755 [] (const asymbol *sym)
756 {
757 return strcmp (sym->name, "_dl_debug_state") == 0;
758 }));
759
760 if (addr != 0)
761 {
764 "enable_break: _dl_debug_state (prior to relocation) = %s\n",
765 hex_string_custom (addr, 8));
766 addr += displacement_from_map (ldm, addr);
767
770 "enable_break: _dl_debug_state (after relocation) = %s\n",
771 hex_string_custom (addr, 8));
772
773 /* Now (finally!) create the solib breakpoint. */
775
776 ret = 1;
777 }
778 else
779 {
782 "enable_break: _dl_debug_state is not found\n");
783 ret = 0;
784 }
785
786 /* We're done with the loadmap. */
787 xfree (ldm);
788
789 return ret;
790 }
791
792 /* Tell the user we couldn't set a dynamic linker breakpoint. */
794
795 /* Failure return. */
796 return 0;
797}
798
799static void
801{
802 struct int_elf32_dsbt_loadmap *ldm;
803 int changed;
804 struct dsbt_info *info = get_dsbt_info ();
805
807 ldm = info->exec_loadmap;
808
809 delete info->main_executable_lm_info;
810 info->main_executable_lm_info = new lm_info_dsbt;
811 info->main_executable_lm_info->map = ldm;
812
814 section_offsets new_offsets (objf->section_offsets.size ());
815 changed = 0;
816
817 for (obj_section *osect : objf->sections ())
818 {
819 CORE_ADDR orig_addr, addr, offset;
820 int osect_idx;
821 int seg;
822
823 osect_idx = osect - objf->sections_start;
824
825 /* Current address of section. */
826 addr = osect->addr ();
827 /* Offset from where this section started. */
828 offset = objf->section_offsets[osect_idx];
829 /* Original address prior to any past relocations. */
830 orig_addr = addr - offset;
831
832 for (seg = 0; seg < ldm->nsegs; seg++)
833 {
834 if (ldm->segs[seg].p_vaddr <= orig_addr
835 && orig_addr < ldm->segs[seg].p_vaddr + ldm->segs[seg].p_memsz)
836 {
837 new_offsets[osect_idx]
838 = ldm->segs[seg].addr - ldm->segs[seg].p_vaddr;
839
840 if (new_offsets[osect_idx] != offset)
841 changed = 1;
842 break;
843 }
844 }
845 }
846
847 if (changed)
848 objfile_relocate (objf, new_offsets);
849
850 /* Now that OBJF has been relocated, we can compute the GOT value
851 and stash it away. */
852}
853
854/* When gdb starts up the inferior, it nurses it along (through the
855 shell) until it is ready to execute its first instruction. At this
856 point, this function gets called via solib_create_inferior_hook.
857
858 For the DSBT shared library, the main executable needs to be relocated.
859 The shared library breakpoints also need to be enabled. */
860
861static void
863{
864 /* Relocate main executable. */
866
867 /* Enable shared library breakpoints. */
868 if (!enable_break ())
869 {
870 warning (_("shared library handler failed to enable breakpoint"));
871 return;
872 }
873}
874
875static void
877{
878 struct dsbt_info *info = get_dsbt_info ();
879
880 info->lm_base_cache = 0;
881 info->main_lm_addr = 0;
882
883 delete info->main_executable_lm_info;
884 info->main_executable_lm_info = NULL;
885}
886
887static void
889{
890 lm_info_dsbt *li = (lm_info_dsbt *) so->lm_info;
891
892 delete li;
893}
894
895static void
897 struct target_section *sec)
898{
899 int seg;
900 lm_info_dsbt *li = (lm_info_dsbt *) so->lm_info;
901 int_elf32_dsbt_loadmap *map = li->map;
902
903 for (seg = 0; seg < map->nsegs; seg++)
904 {
905 if (map->segs[seg].p_vaddr <= sec->addr
906 && sec->addr < map->segs[seg].p_vaddr + map->segs[seg].p_memsz)
907 {
908 CORE_ADDR displ = map->segs[seg].addr - map->segs[seg].p_vaddr;
909
910 sec->addr += displ;
911 sec->endaddr += displ;
912 break;
913 }
914 }
915}
916static void
917show_dsbt_debug (struct ui_file *file, int from_tty,
918 struct cmd_list_element *c, const char *value)
919{
920 gdb_printf (file, _("solib-dsbt debugging is %s.\n"), value);
921}
922
935
937void
939{
940 /* Debug this file's internals. */
942 &solib_dsbt_debug, _("\
943Set internal debugging of shared library code for DSBT ELF."), _("\
944Show internal debugging of shared library code for DSBT ELF."), _("\
945When non-zero, DSBT solib specific internal debugging is enabled."),
946 NULL,
949}
void * xmalloc(YYSIZE_T)
void xfree(void *)
struct gdbarch * target_gdbarch(void)
struct breakpoint * create_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
void * get(unsigned key)
Definition registry.h:211
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
set_show_commands add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
@ class_maintenance
Definition command.h:65
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition gdb_bfd.h:79
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
#define core_bfd
Definition gdbcore.h:130
struct inferior * current_inferior(void)
Definition inferior.c:55
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
static CORE_ADDR lm_addr(struct so_list *so)
Definition nto-tdep.c:246
void objfile_relocate(struct objfile *objfile, const section_offsets &new_offsets)
Definition objfiles.c:676
static int in_plt_section(CORE_ADDR pc)
Definition objfiles.h:972
struct program_space * current_program_space
Definition progspace.c:40
static unsigned int solib_dsbt_debug
Definition solib-dsbt.c:36
static void dsbt_print_loadmap(struct int_elf32_dsbt_loadmap *map)
Definition solib-dsbt.c:186
static CORE_ADDR lm_base(void)
Definition solib-dsbt.c:437
static void show_dsbt_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition solib-dsbt.c:917
static void dsbt_relocate_section_addresses(struct so_list *so, struct target_section *sec)
Definition solib-dsbt.c:896
static void enable_break_failure_warning(void)
Definition solib-dsbt.c:657
static void dsbt_clear_solib(void)
Definition solib-dsbt.c:876
static int enable_break(void)
Definition solib-dsbt.c:673
gdb_byte ext_Elf32_Addr[4]
Definition solib-dsbt.c:47
static void dsbt_get_initial_loadmaps(void)
Definition solib-dsbt.c:279
static struct dsbt_info * get_dsbt_info(void)
Definition solib-dsbt.c:173
static const registry< program_space >::key< dsbt_info > solib_dsbt_pspace_data
Definition solib-dsbt.c:167
static struct int_elf32_dsbt_loadmap * fetch_loadmap(CORE_ADDR ldmaddr)
Definition solib-dsbt.c:314
@ TIC6X_PTR_SIZE
Definition solib-dsbt.c:39
static int dsbt_in_dynsym_resolve_code(CORE_ADDR pc)
Definition solib-dsbt.c:644
static int open_symbol_file_object(int from_tty)
Definition solib-dsbt.c:402
const struct target_so_ops dsbt_so_ops
Definition solib-dsbt.c:923
#define GOT_MODULE_OFFSET
Definition solib-dsbt.c:33
static void dsbt_relocate_main_executable(void)
Definition solib-dsbt.c:800
gdb_byte ext_Elf32_Half[2]
Definition solib-dsbt.c:46
gdb_byte ext_Elf32_Word[4]
Definition solib-dsbt.c:48
static void dsbt_solib_create_inferior_hook(int from_tty)
Definition solib-dsbt.c:862
void _initialize_dsbt_solib()
Definition solib-dsbt.c:938
static CORE_ADDR displacement_from_map(struct int_elf32_dsbt_loadmap *map, CORE_ADDR addr)
Definition solib-dsbt.c:412
static struct int_elf32_dsbt_loadmap * decode_loadmap(const gdb_byte *buf)
Definition solib-dsbt.c:214
static void dsbt_free_so(struct so_list *so)
Definition solib-dsbt.c:888
static struct so_list * dsbt_current_sos(void)
Definition solib-dsbt.c:519
gdb_byte ext_ptr[4]
Definition solib-dsbt.c:103
static CORE_ADDR interp_text_sect_high
Definition solib-frv.c:427
static CORE_ADDR interp_plt_sect_high
Definition solib-frv.c:429
gdb_bfd_ref_ptr solib_bfd_open(const char *pathname)
Definition solib.c:440
CORE_ADDR gdb_bfd_lookup_symbol(bfd *abfd, gdb::function_view< bool(const asymbol *)> match_sym)
Definition solib.c:1720
int gdb_bfd_scan_elf_dyntag(const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr, CORE_ADDR *ptr_addr)
Definition solib.c:1541
#define SO_NAME_MAX_PATH_SIZE
Definition solist.h:22
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
CORE_ADDR interp_text_sect_low
Definition solib-dsbt.c:160
CORE_ADDR lm_base_cache
Definition solib-dsbt.c:155
CORE_ADDR interp_plt_sect_low
Definition solib-dsbt.c:162
struct lm_info_dsbt * main_executable_lm_info
Definition solib-dsbt.c:145
struct int_elf32_dsbt_loadmap * interp_loadmap
Definition solib-dsbt.c:152
struct int_elf32_dsbt_loadmap * exec_loadmap
Definition solib-dsbt.c:151
CORE_ADDR interp_text_sect_high
Definition solib-dsbt.c:161
CORE_ADDR main_lm_addr
Definition solib-dsbt.c:158
CORE_ADDR interp_plt_sect_high
Definition solib-dsbt.c:163
ext_Elf32_Word dsbt_size
Definition solib-dsbt.c:66
ext_Elf32_Word version
Definition solib-dsbt.c:62
ext_Elf32_Word dsbt_index
Definition solib-dsbt.c:67
struct ext_elf32_dsbt_loadseg segs[1]
Definition solib-dsbt.c:71
ext_Elf32_Word dsbt_table_ptr
Definition solib-dsbt.c:65
ext_Elf32_Word nsegs
Definition solib-dsbt.c:69
ext_Elf32_Word p_memsz
Definition solib-dsbt.c:57
ext_Elf32_Addr p_vaddr
Definition solib-dsbt.c:55
ext_Elf32_Addr addr
Definition solib-dsbt.c:53
struct int_elf32_dsbt_loadseg segs[1]
Definition solib-dsbt.c:98
int_elf32_dsbt_loadmap * map
Definition solib-dsbt.c:134
CORE_ADDR addr() const
Definition objfiles.h:385
struct obj_section * sections_start
Definition objfiles.h:812
iterator_range< section_iterator > sections()
Definition objfiles.h:685
::section_offsets section_offsets
Definition objfiles.h:786
bfd * exec_bfd() const
Definition progspace.h:268
struct objfile * symfile_object_file
Definition progspace.h:357
char so_name[SO_NAME_MAX_PATH_SIZE]
Definition solist.h:56
struct so_list * next
Definition solist.h:40
char so_original_name[SO_NAME_MAX_PATH_SIZE]
Definition solist.h:53
lm_info_base * lm_info
Definition solist.h:46
CORE_ADDR endaddr
Definition value.h:130
std::vector< CORE_ADDR > section_offsets
Definition symtab.h:1669
int target_read_string(CORE_ADDR addr, int len, int width, unsigned int fetchlimit, gdb::unique_xmalloc_ptr< gdb_byte > *buffer, int *bytes_read)
Definition target.c:65
bool target_has_execution(inferior *inf)
Definition target.c:201
gdb::optional< gdb::byte_vector > target_read_alloc(struct target_ops *ops, enum target_object object, const char *annex)
Definition target.c:2312
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
@ TARGET_OBJECT_FDPIC
Definition target.h:195
const char * print_core_address(struct gdbarch *gdbarch, CORE_ADDR address)
Definition utils.c:3187
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stdlog
Definition utils.h:190
const char version[]
Definition version.c:2