2 # ===-- armv7_cortex_m_target_definition.py.py ------------------*- C++ -*-===//
4 # The LLVM Compiler Infrastructure
6 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 # See https://llvm.org/LICENSE.txt for license information.
8 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 # ===----------------------------------------------------------------------===//
12 # ----------------------------------------------------------------------
15 # This file can be used with the following setting:
16 # plugin.process.gdb-remote.target-definition-file
17 # This setting should be used when you are trying to connect to a
18 # remote GDB server that doesn't support any of the register discovery
19 # packets that LLDB normally uses.
21 # Why is this necessary? LLDB doesn't require a new build of LLDB that
22 # targets each new architecture you will debug with. Instead, all
23 # architectures are supported and LLDB relies on extra GDB server
24 # packets to discover the target we are connecting to so that is can
25 # show the right registers for each target. This allows the GDB server
26 # to change and add new registers without requiring a new LLDB build
27 # just so we can see new registers.
29 # This file implements the x86_64 registers for the darwin version of
30 # GDB and allows you to connect to servers that use this register set.
34 # (lldb) settings set plugin.process.gdb-remote.target-definition-file /path/to/armv7_cortex_m_target_definition.py
35 # (lldb) gdb-remote other.baz.com:1234
37 # The target definition file will get used if and only if the
38 # qRegisterInfo packets are not supported when connecting to a remote
40 # ----------------------------------------------------------------------
44 # DWARF register numbers
45 name_to_dwarf_regnum
= {
65 name_to_generic_regnum
= {
66 "pc": LLDB_REGNUM_GENERIC_PC
,
67 "sp": LLDB_REGNUM_GENERIC_SP
,
68 "r7": LLDB_REGNUM_GENERIC_FP
,
69 "lr": LLDB_REGNUM_GENERIC_RA
,
70 "r0": LLDB_REGNUM_GENERIC_ARG1
,
71 "r1": LLDB_REGNUM_GENERIC_ARG2
,
72 "r2": LLDB_REGNUM_GENERIC_ARG3
,
73 "r3": LLDB_REGNUM_GENERIC_ARG4
,
77 def get_reg_num(reg_num_dict
, reg_name
):
78 if reg_name
in reg_num_dict
:
79 return reg_num_dict
[reg_name
]
80 return LLDB_INVALID_REGNUM
83 def get_reg_num(reg_num_dict
, reg_name
):
84 if reg_name
in reg_num_dict
:
85 return reg_num_dict
[reg_name
]
86 return LLDB_INVALID_REGNUM
89 armv7_register_infos
= [
94 "encoding": eEncodingUint
,
95 "format": eFormatAddressInfo
,
102 "encoding": eEncodingUint
,
103 "format": eFormatAddressInfo
,
110 "encoding": eEncodingUint
,
111 "format": eFormatAddressInfo
,
118 "encoding": eEncodingUint
,
119 "format": eFormatAddressInfo
,
126 "encoding": eEncodingUint
,
127 "format": eFormatAddressInfo
,
133 "encoding": eEncodingUint
,
134 "format": eFormatAddressInfo
,
140 "encoding": eEncodingUint
,
141 "format": eFormatAddressInfo
,
147 "encoding": eEncodingUint
,
148 "format": eFormatAddressInfo
,
155 "encoding": eEncodingUint
,
156 "format": eFormatAddressInfo
,
162 "encoding": eEncodingUint
,
163 "format": eFormatAddressInfo
,
169 "encoding": eEncodingUint
,
170 "format": eFormatAddressInfo
,
176 "encoding": eEncodingUint
,
177 "format": eFormatAddressInfo
,
183 "encoding": eEncodingUint
,
184 "format": eFormatAddressInfo
,
190 "encoding": eEncodingUint
,
191 "format": eFormatAddressInfo
,
198 "encoding": eEncodingUint
,
199 "format": eFormatAddressInfo
,
206 "encoding": eEncodingUint
,
207 "format": eFormatAddressInfo
,
214 "encoding": eEncodingUint
,
215 "format": eFormatAddressInfo
,
220 g_target_definition
= None
223 def get_target_definition():
224 global g_target_definition
225 if g_target_definition
is None:
226 g_target_definition
= {}
228 for reg_info
in armv7_register_infos
:
229 reg_name
= reg_info
["name"]
231 if "slice" not in reg_info
and "composite" not in reg_info
:
232 reg_info
["offset"] = offset
233 offset
+= reg_info
["bitsize"] / 8
235 # Set the DWARF/eh_frame register number for this register if it has one
236 reg_num
= get_reg_num(name_to_dwarf_regnum
, reg_name
)
237 if reg_num
!= LLDB_INVALID_REGNUM
:
238 reg_info
["gcc"] = reg_num
239 reg_info
["ehframe"] = reg_num
241 # Set the generic register number for this register if it has one
242 reg_num
= get_reg_num(name_to_generic_regnum
, reg_name
)
243 if reg_num
!= LLDB_INVALID_REGNUM
:
244 reg_info
["generic"] = reg_num
246 g_target_definition
["sets"] = ["General Purpose Registers"]
247 g_target_definition
["registers"] = armv7_register_infos
248 g_target_definition
["host-info"] = {
249 "triple": "armv7em--",
250 "endian": eByteOrderLittle
,
252 g_target_definition
["g-packet-size"] = offset
253 return g_target_definition
256 def get_dynamic_setting(target
, setting_name
):
257 if setting_name
== "gdb-server-target-definition":
258 return get_target_definition()