summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch')
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch301
1 files changed, 301 insertions, 0 deletions
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch
new file mode 100644
index 00000000..a871b582
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0002-Patch-MicroBlaze-Initial-port-of-core-reading-suppor.patch
@@ -0,0 +1,301 @@
1From 7da397cae8c0f8826184d6e12fda9ccd11f92753 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Mon, 10 Oct 2022 16:37:53 +0530
4Subject: [PATCH 2/8] [Patch,MicroBlaze]: Initial port of core reading support
5 Added support for reading notes in linux core dumps Support for reading of
6 PRSTATUS and PSINFO information for rebuilding ".reg" sections of core dumps
7 at run time.
8
9Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
10Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
11Signed-off-by: Mahesh Bodapati <mbodapat@xilinx.com>
12---
13 bfd/elf32-microblaze.c | 84 +++++++++++++++++++++++++++++++++++++
14 gdb/configure.tgt | 2 +-
15 gdb/microblaze-linux-tdep.c | 17 +++++++-
16 gdb/microblaze-tdep.c | 48 +++++++++++++++++++++
17 gdb/microblaze-tdep.h | 28 +++++++++++++
18 5 files changed, 177 insertions(+), 2 deletions(-)
19
20diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
21index d09b3f7095d..d3b3c66cf00 100644
22--- a/bfd/elf32-microblaze.c
23+++ b/bfd/elf32-microblaze.c
24@@ -713,6 +713,87 @@ microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
25 return _bfd_elf_is_local_label_name (abfd, name);
26 }
27
28+/* Support for core dump NOTE sections. */
29+static bool
30+microblaze_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
31+{
32+ int offset;
33+ unsigned int size;
34+
35+ switch (note->descsz)
36+ {
37+ default:
38+ return false;
39+
40+ case 228: /* Linux/MicroBlaze */
41+ /* pr_cursig */
42+ elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
43+
44+ /* pr_pid */
45+ elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
46+
47+ /* pr_reg */
48+ offset = 72;
49+ size = 50 * 4;
50+
51+ break;
52+ }
53+
54+ /* Make a ".reg/999" section. */
55+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
56+ size, note->descpos + offset);
57+}
58+
59+static bool
60+microblaze_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
61+{
62+ switch (note->descsz)
63+ {
64+ default:
65+ return false;
66+
67+ case 128: /* Linux/MicroBlaze elf_prpsinfo */
68+ elf_tdata (abfd)->core->program
69+ = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
70+ elf_tdata (abfd)->core->command
71+ = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
72+ }
73+
74+ /* Note that for some reason, a spurious space is tacked
75+ onto the end of the args in some (at least one anyway)
76+ implementations, so strip it off if it exists. */
77+
78+ {
79+ char *command = elf_tdata (abfd)->core->command;
80+ int n = strlen (command);
81+
82+ if (0 < n && command[n - 1] == ' ')
83+ command[n - 1] = '\0';
84+ }
85+
86+ return true;
87+}
88+
89+/* The microblaze linker (like many others) needs to keep track of
90+ the number of relocs that it decides to copy as dynamic relocs in
91+ check_relocs for each symbol. This is so that it can later discard
92+ them if they are found to be unnecessary. We store the information
93+ in a field extending the regular ELF linker hash table. */
94+
95+struct elf32_mb_dyn_relocs
96+{
97+ struct elf32_mb_dyn_relocs *next;
98+
99+ /* The input section of the reloc. */
100+ asection *sec;
101+
102+ /* Total number of relocs copied for the input section. */
103+ bfd_size_type count;
104+
105+ /* Number of pc-relative relocs copied for the input section. */
106+ bfd_size_type pc_count;
107+};
108+
109 /* ELF linker hash entry. */
110
111 struct elf32_mb_link_hash_entry
112@@ -3434,4 +3515,7 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
113 #define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
114 #define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
115
116+#define elf_backend_grok_prstatus microblaze_elf_grok_prstatus
117+#define elf_backend_grok_psinfo microblaze_elf_grok_psinfo
118+
119 #include "elf32-target.h"
120diff --git a/gdb/configure.tgt b/gdb/configure.tgt
121index 0705ccf32b8..7ea186481f3 100644
122--- a/gdb/configure.tgt
123+++ b/gdb/configure.tgt
124@@ -400,7 +400,7 @@ mep-*-*)
125
126 microblaze*-linux-*|microblaze*-*-linux*)
127 # Target: Xilinx MicroBlaze running Linux
128- gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o solib-svr4.o \
129+ gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o solib-svr4.o glibc-tdep.o \
130 symfile-mem.o linux-tdep.o"
131 ;;
132 microblaze*-*-*)
133diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
134index 5748556a556..d6197c49dfd 100644
135--- a/gdb/microblaze-linux-tdep.c
136+++ b/gdb/microblaze-linux-tdep.c
137@@ -36,6 +36,7 @@
138 #include "frame-unwind.h"
139 #include "tramp-frame.h"
140 #include "linux-tdep.h"
141+#include "glibc-tdep.h"
142
143 static int microblaze_debug_flag = 0;
144
145@@ -135,11 +136,14 @@ static struct tramp_frame microblaze_linux_sighandler_tramp_frame =
146 microblaze_linux_sighandler_cache_init
147 };
148
149-
150 static void
151 microblaze_linux_init_abi (struct gdbarch_info info,
152 struct gdbarch *gdbarch)
153 {
154+ struct microblaze_gdbarch_tdep *tdep =(microblaze_gdbarch_tdep *) gdbarch_tdep (gdbarch);
155+
156+ tdep->sizeof_gregset = 200;
157+
158 linux_init_abi (info, gdbarch, 0);
159
160 set_gdbarch_memory_remove_breakpoint (gdbarch,
161@@ -153,6 +157,17 @@ microblaze_linux_init_abi (struct gdbarch_info info,
162 tramp_frame_prepend_unwinder (gdbarch,
163 &microblaze_linux_sighandler_tramp_frame);
164
165+ /* BFD target for core files. */
166+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
167+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblaze");
168+ else
169+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblazeel");
170+
171+
172+ /* Shared library handling. */
173+ set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
174+ set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
175+
176 /* Enable TLS support. */
177 set_gdbarch_fetch_tls_load_module_address (gdbarch,
178 svr4_fetch_objfile_link_map);
179diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
180index 3e8e8fe35b9..ccd37d085d6 100644
181--- a/gdb/microblaze-tdep.c
182+++ b/gdb/microblaze-tdep.c
183@@ -666,6 +666,43 @@ microblaze_register_g_packet_guesses (struct gdbarch *gdbarch)
184 tdesc_microblaze_with_stack_protect);
185 }
186
187+void
188+microblaze_supply_gregset (const struct regset *regset,
189+ struct regcache *regcache,
190+ int regnum, const void *gregs)
191+{
192+ const unsigned int *regs = (const unsigned int *)gregs;
193+ if (regnum >= 0)
194+ regcache->raw_supply (regnum, regs + regnum);
195+
196+ if (regnum == -1) {
197+ int i;
198+
199+ for (i = 0; i < 50; i++) {
200+ regcache->raw_supply (i, regs + i);
201+ }
202+ }
203+}
204+
205+
206+/* Return the appropriate register set for the core section identified
207+ by SECT_NAME and SECT_SIZE. */
208+
209+static void
210+microblaze_iterate_over_regset_sections (struct gdbarch *gdbarch,
211+ iterate_over_regset_sections_cb *cb,
212+ void *cb_data,
213+ const struct regcache *regcache)
214+{
215+ struct microblaze_gdbarch_tdep *tdep =(microblaze_gdbarch_tdep *) gdbarch_tdep (gdbarch);
216+
217+ cb(".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL, cb_data);
218+
219+ cb(".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, tdep->fpregset, NULL, cb_data);
220+}
221+
222+
223+
224 static struct gdbarch *
225 microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
226 {
227@@ -718,6 +755,10 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
228 microblaze_gdbarch_tdep *tdep = new microblaze_gdbarch_tdep;
229 gdbarch = gdbarch_alloc (&info, tdep);
230
231+ tdep->gregset = NULL;
232+ tdep->sizeof_gregset = 0;
233+ tdep->fpregset = NULL;
234+ tdep->sizeof_fpregset = 0;
235 set_gdbarch_long_double_bit (gdbarch, 128);
236
237 set_gdbarch_num_regs (gdbarch, MICROBLAZE_NUM_REGS);
238@@ -766,6 +807,13 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
239 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
240 if (tdesc_data != NULL)
241 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
242+ //frame_base_append_sniffer (gdbarch, microblaze_frame_sniffer);
243+
244+ /* If we have register sets, enable the generic core file support. */
245+ if (tdep->gregset) {
246+ set_gdbarch_iterate_over_regset_sections (gdbarch,
247+ microblaze_iterate_over_regset_sections);
248+ }
249
250 return gdbarch;
251 }
252diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
253index 53fcb2297e6..2e853d84d72 100644
254--- a/gdb/microblaze-tdep.h
255+++ b/gdb/microblaze-tdep.h
256@@ -23,8 +23,23 @@
257 #include "gdbarch.h"
258
259 /* Microblaze architecture-specific information. */
260+struct microblaze_gregset
261+{
262+ microblaze_gregset() {}
263+ unsigned int gregs[32];
264+ unsigned int fpregs[32];
265+ unsigned int pregs[16];
266+};
267+
268 struct microblaze_gdbarch_tdep : gdbarch_tdep
269 {
270+ int dummy; // declare something.
271+
272+ /* Register sets. */
273+ struct regset *gregset;
274+ size_t sizeof_gregset;
275+ struct regset *fpregset;
276+ size_t sizeof_fpregset;
277 };
278
279 /* Register numbers. */
280@@ -121,5 +136,18 @@ struct microblaze_frame_cache
281 #define MICROBLAZE_BREAKPOINT {0xba, 0x0c, 0x00, 0x18}
282 #define MICROBLAZE_BREAKPOINT_LE {0x18, 0x00, 0x0c, 0xba}
283
284+extern void microblaze_supply_gregset (const struct regset *regset,
285+ struct regcache *regcache,
286+ int regnum, const void *gregs);
287+extern void microblaze_collect_gregset (const struct regset *regset,
288+ const struct regcache *regcache,
289+ int regnum, void *gregs);
290+extern void microblaze_supply_fpregset (struct regcache *regcache,
291+ int regnum, const void *fpregs);
292+extern void microblaze_collect_fpregset (const struct regcache *regcache,
293+ int regnum, void *fpregs);
294+
295+extern const struct regset * microblaze_regset_from_core_section (struct gdbarch *gdbarch,
296+ const char *sect_name, size_t sect_size);
297
298 #endif /* microblaze-tdep.h */
299--
3002.37.1 (Apple Git-137.1)
301