1 /* Common code for targets with the none ABI (bare-metal), but where the
2 BFD library is build with ELF support.
4 Copyright (C) 2020-2023 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
22 #include "elf-none-tdep.h"
29 #include "gcore-elf.h"
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
35 static gdb::unique_xmalloc_ptr
<char>
36 elf_none_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
,
39 gdb::unique_xmalloc_ptr
<char> note_data
;
41 /* Add note information about the executable and its arguments. */
44 static const size_t fname_len
= 16;
45 static const size_t psargs_len
= 80;
46 if (get_exec_file (0))
48 const char *exe
= get_exec_file (0);
49 fname
= lbasename (exe
);
50 psargs
= std::string (exe
);
52 const std::string
&infargs
= current_inferior ()->args ();
53 if (!infargs
.empty ())
54 psargs
+= ' ' + infargs
;
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
61 fname
.resize (fname_len
- 1);
62 psargs
.resize (psargs_len
- 1);
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
);
70 /* Now write out the prpsinfo structure. */
71 note_data
.reset (elfcore_write_prpsinfo (obfd
, note_data
.release (),
72 note_size
, fname
.c_str (),
74 if (note_data
== nullptr)
77 /* Thread register information. */
80 update_thread_list ();
82 catch (const gdb_exception_error
&e
)
84 exception_print (gdb_stderr
, e
);
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 ();
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
->stop_signal ();
97 stop_signal
= GDB_SIGNAL_0
;
99 if (signalled_thr
!= nullptr)
100 gcore_elf_build_thread_register_notes (gdbarch
, signalled_thr
,
101 stop_signal
, obfd
, ¬e_data
,
103 for (thread_info
*thr
: current_inferior ()->non_exited_threads ())
105 if (thr
== signalled_thr
)
108 gcore_elf_build_thread_register_notes (gdbarch
, thr
, stop_signal
, obfd
,
109 ¬e_data
, note_size
);
113 /* Include the target description when possible. Some architectures
114 allow for per-thread gdbarch so we should really be emitting a tdesc
115 per-thread, however, we don't currently support reading in a
116 per-thread tdesc, so just emit the tdesc for the signalled thread. */
117 gdbarch
= target_thread_architecture (signalled_thr
->ptid
);
118 gcore_elf_make_tdesc_note (gdbarch
, obfd
, ¬e_data
, note_size
);
123 /* See none-tdep.h. */
126 elf_none_init_abi (struct gdbarch
*gdbarch
)
128 /* Default core file support. */
129 set_gdbarch_make_corefile_notes (gdbarch
, elf_none_make_corefile_notes
);