gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
[deliverable/binutils-gdb.git] / gdb / elf-none-tdep.c
1 /* Common code for targets with the none ABI (bare-metal), but where the
2 BFD library is build with ELF support.
3
4 Copyright (C) 2020-2021 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "elf-none-tdep.h"
23 #include "regset.h"
24 #include "elf-bfd.h" /* for elfcore_write_* */
25 #include "inferior.h"
26 #include "regcache.h"
27 #include "gdbarch.h"
28 #include "gcore.h"
29 #include "gcore-elf.h"
30
31 /* Build the note section for a corefile, and return it in a malloc
32 buffer. Currently this just dumps all available registers for each
33 thread. */
34
35 static gdb::unique_xmalloc_ptr<char>
36 elf_none_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
37 int *note_size)
38 {
39 gdb::unique_xmalloc_ptr<char> note_data;
40
41 /* Add note information about the executable and its arguments. */
42 std::string fname;
43 std::string psargs;
44 static const size_t fname_len = 16;
45 static const size_t psargs_len = 80;
46 if (get_exec_file (0))
47 {
48 const char *exe = get_exec_file (0);
49 fname = lbasename (exe);
50 psargs = std::string (exe);
51
52 const char *infargs = get_inferior_args ();
53 if (infargs != nullptr)
54 psargs += " " + std::string (infargs);
55
56 /* All existing targets that handle writing out prpsinfo expect the
57 fname and psargs strings to be at least 16 and 80 characters long
58 respectively, including a null terminator at the end. Resize to
59 the expected length minus one to ensure there is a null within the
60 required length. */
61 fname.resize (fname_len - 1);
62 psargs.resize (psargs_len - 1);
63 }
64
65 /* Resize the buffers up to their required lengths. This will fill any
66 remaining space with the null character. */
67 fname.resize (fname_len);
68 psargs.resize (psargs_len);
69
70 /* Now write out the prpsinfo structure. */
71 note_data.reset (elfcore_write_prpsinfo (obfd, note_data.release (),
72 note_size, fname.c_str (),
73 psargs.c_str ()));
74 if (note_data == nullptr)
75 return nullptr;
76
77 /* Thread register information. */
78 try
79 {
80 update_thread_list ();
81 }
82 catch (const gdb_exception_error &e)
83 {
84 exception_print (gdb_stderr, e);
85 }
86
87 /* Like the Linux kernel, prefer dumping the signalled thread first.
88 "First thread" is what tools use to infer the signalled thread. */
89 thread_info *signalled_thr = gcore_find_signalled_thread ();
90
91 /* All threads are reported as having been stopped by the same signal
92 that stopped SIGNALLED_THR. */
93 gdb_signal stop_signal;
94 if (signalled_thr != nullptr)
95 stop_signal = signalled_thr->suspend.stop_signal;
96 else
97 stop_signal = GDB_SIGNAL_0;
98
99 if (signalled_thr != nullptr)
100 gcore_elf_build_thread_register_notes (gdbarch, signalled_thr,
101 stop_signal, obfd, &note_data,
102 note_size);
103 for (thread_info *thr : current_inferior ()->non_exited_threads ())
104 {
105 if (thr == signalled_thr)
106 continue;
107
108 gcore_elf_build_thread_register_notes (gdbarch, thr, stop_signal, obfd,
109 &note_data, note_size);
110 }
111
112
113 /* Target description. */
114 gcore_elf_make_tdesc_note (obfd, &note_data, note_size);
115
116 return note_data;
117 }
118
119 /* See none-tdep.h. */
120
121 void
122 elf_none_init_abi (struct gdbarch *gdbarch)
123 {
124 /* Default core file support. */
125 set_gdbarch_make_corefile_notes (gdbarch, elf_none_make_corefile_notes);
126 }
This page took 0.030998 seconds and 4 git commands to generate.