2 # ===-- x86_64_target_definition.py -----------------------------*- C++ -*-===//
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # ===----------------------------------------------------------------------===//
10 # ----------------------------------------------------------------------
13 # This file can be used with the following setting:
14 # plugin.process.gdb-remote.target-definition-file
15 # This setting should be used when you are trying to connect to a
16 # remote GDB server that doesn't support any of the register discovery
17 # packets that LLDB normally uses.
19 # Why is this necessary? LLDB doesn't require a new build of LLDB that
20 # targets each new architecture you will debug with. Instead, all
21 # architectures are supported and LLDB relies on extra GDB server
22 # packets to discover the target we are connecting to so that is can
23 # show the right registers for each target. This allows the GDB server
24 # to change and add new registers without requiring a new LLDB build
25 # just so we can see new registers.
27 # This file implements the x86_64 registers for the darwin version of
28 # GDB and allows you to connect to servers that use this register set.
32 # (lldb) settings set plugin.process.gdb-remote.target-definition-file /path/to/x86_64_target_definition.py
33 # (lldb) gdb-remote other.baz.com:1234
35 # The target definition file will get used if and only if the
36 # qRegisterInfo packets are not supported when connecting to a remote
38 # ----------------------------------------------------------------------
41 # Compiler and DWARF register numbers
42 name_to_gcc_dwarf_regnum
= {
102 name_to_gdb_regnum
= {
178 name_to_generic_regnum
= {
179 "rip": LLDB_REGNUM_GENERIC_PC
,
180 "rsp": LLDB_REGNUM_GENERIC_SP
,
181 "rbp": LLDB_REGNUM_GENERIC_FP
,
182 "rdi": LLDB_REGNUM_GENERIC_ARG1
,
183 "rsi": LLDB_REGNUM_GENERIC_ARG2
,
184 "rdx": LLDB_REGNUM_GENERIC_ARG3
,
185 "rcx": LLDB_REGNUM_GENERIC_ARG4
,
186 "r8": LLDB_REGNUM_GENERIC_ARG5
,
187 "r9": LLDB_REGNUM_GENERIC_ARG6
,
191 def get_reg_num(reg_num_dict
, reg_name
):
192 if reg_name
in reg_num_dict
:
193 return reg_num_dict
[reg_name
]
194 return LLDB_INVALID_REGNUM
197 def get_reg_num(reg_num_dict
, reg_name
):
198 if reg_name
in reg_num_dict
:
199 return reg_num_dict
[reg_name
]
200 return LLDB_INVALID_REGNUM
203 x86_64_register_infos
= [
208 "encoding": eEncodingUint
,
209 "format": eFormatAddressInfo
,
215 "encoding": eEncodingUint
,
216 "format": eFormatAddressInfo
,
222 "encoding": eEncodingUint
,
223 "format": eFormatAddressInfo
,
230 "encoding": eEncodingUint
,
231 "format": eFormatAddressInfo
,
238 "encoding": eEncodingUint
,
239 "format": eFormatAddressInfo
,
246 "encoding": eEncodingUint
,
247 "format": eFormatAddressInfo
,
254 "encoding": eEncodingUint
,
255 "format": eFormatAddressInfo
,
262 "encoding": eEncodingUint
,
263 "format": eFormatAddressInfo
,
270 "encoding": eEncodingUint
,
271 "format": eFormatAddressInfo
,
278 "encoding": eEncodingUint
,
279 "format": eFormatAddressInfo
,
286 "encoding": eEncodingUint
,
287 "format": eFormatAddressInfo
,
293 "encoding": eEncodingUint
,
294 "format": eFormatAddressInfo
,
300 "encoding": eEncodingUint
,
301 "format": eFormatAddressInfo
,
307 "encoding": eEncodingUint
,
308 "format": eFormatAddressInfo
,
314 "encoding": eEncodingUint
,
315 "format": eFormatAddressInfo
,
321 "encoding": eEncodingUint
,
322 "format": eFormatAddressInfo
,
328 "encoding": eEncodingUint
,
329 "format": eFormatAddressInfo
,
336 "encoding": eEncodingUint
,
337 "format": eFormatHex
,
343 "encoding": eEncodingUint
,
344 "format": eFormatHex
,
350 "encoding": eEncodingUint
,
351 "format": eFormatHex
,
357 "encoding": eEncodingUint
,
358 "format": eFormatHex
,
364 "encoding": eEncodingUint
,
365 "format": eFormatHex
,
371 "encoding": eEncodingUint
,
372 "format": eFormatHex
,
378 "encoding": eEncodingUint
,
379 "format": eFormatHex
,
385 "encoding": eEncodingVector
,
386 "format": eFormatVectorOfUInt8
,
392 "encoding": eEncodingVector
,
393 "format": eFormatVectorOfUInt8
,
399 "encoding": eEncodingVector
,
400 "format": eFormatVectorOfUInt8
,
406 "encoding": eEncodingVector
,
407 "format": eFormatVectorOfUInt8
,
413 "encoding": eEncodingVector
,
414 "format": eFormatVectorOfUInt8
,
420 "encoding": eEncodingVector
,
421 "format": eFormatVectorOfUInt8
,
427 "encoding": eEncodingVector
,
428 "format": eFormatVectorOfUInt8
,
434 "encoding": eEncodingVector
,
435 "format": eFormatVectorOfUInt8
,
441 "encoding": eEncodingUint
,
442 "format": eFormatHex
,
448 "encoding": eEncodingUint
,
449 "format": eFormatHex
,
455 "encoding": eEncodingUint
,
456 "format": eFormatHex
,
462 "encoding": eEncodingUint
,
463 "format": eFormatHex
,
469 "encoding": eEncodingUint
,
470 "format": eFormatHex
,
476 "encoding": eEncodingUint
,
477 "format": eFormatHex
,
483 "encoding": eEncodingUint
,
484 "format": eFormatHex
,
490 "encoding": eEncodingUint
,
491 "format": eFormatHex
,
497 "encoding": eEncodingVector
,
498 "format": eFormatVectorOfUInt8
,
504 "encoding": eEncodingVector
,
505 "format": eFormatVectorOfUInt8
,
511 "encoding": eEncodingVector
,
512 "format": eFormatVectorOfUInt8
,
518 "encoding": eEncodingVector
,
519 "format": eFormatVectorOfUInt8
,
525 "encoding": eEncodingVector
,
526 "format": eFormatVectorOfUInt8
,
532 "encoding": eEncodingVector
,
533 "format": eFormatVectorOfUInt8
,
539 "encoding": eEncodingVector
,
540 "format": eFormatVectorOfUInt8
,
546 "encoding": eEncodingVector
,
547 "format": eFormatVectorOfUInt8
,
553 "encoding": eEncodingVector
,
554 "format": eFormatVectorOfUInt8
,
560 "encoding": eEncodingVector
,
561 "format": eFormatVectorOfUInt8
,
567 "encoding": eEncodingVector
,
568 "format": eFormatVectorOfUInt8
,
574 "encoding": eEncodingVector
,
575 "format": eFormatVectorOfUInt8
,
581 "encoding": eEncodingVector
,
582 "format": eFormatVectorOfUInt8
,
588 "encoding": eEncodingVector
,
589 "format": eFormatVectorOfUInt8
,
595 "encoding": eEncodingVector
,
596 "format": eFormatVectorOfUInt8
,
602 "encoding": eEncodingVector
,
603 "format": eFormatVectorOfUInt8
,
609 "encoding": eEncodingUint
,
610 "format": eFormatHex
,
612 # Registers that are contained in or composed of one of more other
618 "encoding": eEncodingUint
,
619 "format": eFormatHex
,
620 "slice": "rax[31:0]",
626 "encoding": eEncodingUint
,
627 "format": eFormatHex
,
628 "slice": "rbx[31:0]",
634 "encoding": eEncodingUint
,
635 "format": eFormatHex
,
636 "slice": "rcx[31:0]",
642 "encoding": eEncodingUint
,
643 "format": eFormatHex
,
644 "slice": "rdx[31:0]",
650 "encoding": eEncodingUint
,
651 "format": eFormatHex
,
652 "slice": "rdi[31:0]",
658 "encoding": eEncodingUint
,
659 "format": eFormatHex
,
660 "slice": "rsi[31:0]",
666 "encoding": eEncodingUint
,
667 "format": eFormatHex
,
668 "slice": "rbp[31:0]",
674 "encoding": eEncodingUint
,
675 "format": eFormatHex
,
676 "slice": "rsp[31:0]",
682 "encoding": eEncodingUint
,
683 "format": eFormatHex
,
690 "encoding": eEncodingUint
,
691 "format": eFormatHex
,
698 "encoding": eEncodingUint
,
699 "format": eFormatHex
,
700 "slice": "r10[31:0]",
706 "encoding": eEncodingUint
,
707 "format": eFormatHex
,
708 "slice": "r11[31:0]",
714 "encoding": eEncodingUint
,
715 "format": eFormatHex
,
716 "slice": "r12[31:0]",
722 "encoding": eEncodingUint
,
723 "format": eFormatHex
,
724 "slice": "r13[31:0]",
730 "encoding": eEncodingUint
,
731 "format": eFormatHex
,
732 "slice": "r14[31:0]",
738 "encoding": eEncodingUint
,
739 "format": eFormatHex
,
740 "slice": "r15[31:0]",
746 "encoding": eEncodingUint
,
747 "format": eFormatHex
,
748 "slice": "rax[15:0]",
754 "encoding": eEncodingUint
,
755 "format": eFormatHex
,
756 "slice": "rbx[15:0]",
762 "encoding": eEncodingUint
,
763 "format": eFormatHex
,
764 "slice": "rcx[15:0]",
770 "encoding": eEncodingUint
,
771 "format": eFormatHex
,
772 "slice": "rdx[15:0]",
778 "encoding": eEncodingUint
,
779 "format": eFormatHex
,
780 "slice": "rdi[15:0]",
786 "encoding": eEncodingUint
,
787 "format": eFormatHex
,
788 "slice": "rsi[15:0]",
794 "encoding": eEncodingUint
,
795 "format": eFormatHex
,
796 "slice": "rbp[15:0]",
802 "encoding": eEncodingUint
,
803 "format": eFormatHex
,
804 "slice": "rsp[15:0]",
810 "encoding": eEncodingUint
,
811 "format": eFormatHex
,
818 "encoding": eEncodingUint
,
819 "format": eFormatHex
,
826 "encoding": eEncodingUint
,
827 "format": eFormatHex
,
828 "slice": "r10[15:0]",
834 "encoding": eEncodingUint
,
835 "format": eFormatHex
,
836 "slice": "r11[15:0]",
842 "encoding": eEncodingUint
,
843 "format": eFormatHex
,
844 "slice": "r12[15:0]",
850 "encoding": eEncodingUint
,
851 "format": eFormatHex
,
852 "slice": "r13[15:0]",
858 "encoding": eEncodingUint
,
859 "format": eFormatHex
,
860 "slice": "r14[15:0]",
866 "encoding": eEncodingUint
,
867 "format": eFormatHex
,
868 "slice": "r15[15:0]",
874 "encoding": eEncodingUint
,
875 "format": eFormatHex
,
876 "slice": "rax[15:8]",
882 "encoding": eEncodingUint
,
883 "format": eFormatHex
,
884 "slice": "rbx[15:8]",
890 "encoding": eEncodingUint
,
891 "format": eFormatHex
,
892 "slice": "rcx[15:8]",
898 "encoding": eEncodingUint
,
899 "format": eFormatHex
,
900 "slice": "rdx[15:8]",
906 "encoding": eEncodingUint
,
907 "format": eFormatHex
,
914 "encoding": eEncodingUint
,
915 "format": eFormatHex
,
922 "encoding": eEncodingUint
,
923 "format": eFormatHex
,
930 "encoding": eEncodingUint
,
931 "format": eFormatHex
,
938 "encoding": eEncodingUint
,
939 "format": eFormatHex
,
946 "encoding": eEncodingUint
,
947 "format": eFormatHex
,
954 "encoding": eEncodingUint
,
955 "format": eFormatHex
,
962 "encoding": eEncodingUint
,
963 "format": eFormatHex
,
970 "encoding": eEncodingUint
,
971 "format": eFormatHex
,
978 "encoding": eEncodingUint
,
979 "format": eFormatHex
,
986 "encoding": eEncodingUint
,
987 "format": eFormatHex
,
994 "encoding": eEncodingUint
,
995 "format": eFormatHex
,
1002 "encoding": eEncodingUint
,
1003 "format": eFormatHex
,
1004 "slice": "r12[7:0]",
1010 "encoding": eEncodingUint
,
1011 "format": eFormatHex
,
1012 "slice": "r13[7:0]",
1018 "encoding": eEncodingUint
,
1019 "format": eFormatHex
,
1020 "slice": "r14[7:0]",
1026 "encoding": eEncodingUint
,
1027 "format": eFormatHex
,
1028 "slice": "r15[7:0]",
1032 g_target_definition
= None
1035 def get_target_definition():
1036 global g_target_definition
1037 if g_target_definition
is None:
1038 g_target_definition
= {}
1040 for reg_info
in x86_64_register_infos
:
1041 reg_name
= reg_info
["name"]
1043 # Only fill in the offset if there is no 'slice' in the register
1045 if "slice" not in reg_info
and "composite" not in reg_info
:
1046 reg_info
["offset"] = offset
1047 offset
+= reg_info
["bitsize"] // 8
1049 # Set the GCC/DWARF register number for this register if it has one
1050 reg_num
= get_reg_num(name_to_gcc_dwarf_regnum
, reg_name
)
1051 if reg_num
!= LLDB_INVALID_REGNUM
:
1052 reg_info
["gcc"] = reg_num
1053 reg_info
["dwarf"] = reg_num
1055 # Set the generic register number for this register if it has one
1056 reg_num
= get_reg_num(name_to_generic_regnum
, reg_name
)
1057 if reg_num
!= LLDB_INVALID_REGNUM
:
1058 reg_info
["generic"] = reg_num
1060 # Set the GDB register number for this register if it has one
1061 reg_num
= get_reg_num(name_to_gdb_regnum
, reg_name
)
1062 if reg_num
!= LLDB_INVALID_REGNUM
:
1063 reg_info
["gdb"] = reg_num
1065 g_target_definition
["sets"] = [
1066 "General Purpose Registers",
1067 "Floating Point Registers",
1069 g_target_definition
["registers"] = x86_64_register_infos
1070 g_target_definition
["host-info"] = {
1071 "triple": "x86_64-apple-macosx",
1072 "endian": eByteOrderLittle
,
1074 g_target_definition
["g-packet-size"] = offset
1075 return g_target_definition
1078 def get_dynamic_setting(target
, setting_name
):
1079 if setting_name
== "gdb-server-target-definition":
1080 return get_target_definition()