2 # ===-- x86_64_linux_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_linux_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 x86_64_register_infos
= [
202 "encoding": eEncodingUint
,
203 "format": eFormatAddressInfo
,
209 "encoding": eEncodingUint
,
210 "format": eFormatAddressInfo
,
216 "encoding": eEncodingUint
,
217 "format": eFormatAddressInfo
,
224 "encoding": eEncodingUint
,
225 "format": eFormatAddressInfo
,
232 "encoding": eEncodingUint
,
233 "format": eFormatAddressInfo
,
240 "encoding": eEncodingUint
,
241 "format": eFormatAddressInfo
,
248 "encoding": eEncodingUint
,
249 "format": eFormatAddressInfo
,
256 "encoding": eEncodingUint
,
257 "format": eFormatAddressInfo
,
264 "encoding": eEncodingUint
,
265 "format": eFormatAddressInfo
,
272 "encoding": eEncodingUint
,
273 "format": eFormatAddressInfo
,
280 "encoding": eEncodingUint
,
281 "format": eFormatAddressInfo
,
287 "encoding": eEncodingUint
,
288 "format": eFormatAddressInfo
,
294 "encoding": eEncodingUint
,
295 "format": eFormatAddressInfo
,
301 "encoding": eEncodingUint
,
302 "format": eFormatAddressInfo
,
308 "encoding": eEncodingUint
,
309 "format": eFormatAddressInfo
,
315 "encoding": eEncodingUint
,
316 "format": eFormatAddressInfo
,
322 "encoding": eEncodingUint
,
323 "format": eFormatAddressInfo
,
330 "encoding": eEncodingUint
,
331 "format": eFormatHex
,
337 "encoding": eEncodingUint
,
338 "format": eFormatHex
,
344 "encoding": eEncodingUint
,
345 "format": eFormatHex
,
351 "encoding": eEncodingUint
,
352 "format": eFormatHex
,
358 "encoding": eEncodingUint
,
359 "format": eFormatHex
,
365 "encoding": eEncodingUint
,
366 "format": eFormatHex
,
372 "encoding": eEncodingUint
,
373 "format": eFormatHex
,
379 "encoding": eEncodingVector
,
380 "format": eFormatVectorOfUInt8
,
386 "encoding": eEncodingVector
,
387 "format": eFormatVectorOfUInt8
,
393 "encoding": eEncodingVector
,
394 "format": eFormatVectorOfUInt8
,
400 "encoding": eEncodingVector
,
401 "format": eFormatVectorOfUInt8
,
407 "encoding": eEncodingVector
,
408 "format": eFormatVectorOfUInt8
,
414 "encoding": eEncodingVector
,
415 "format": eFormatVectorOfUInt8
,
421 "encoding": eEncodingVector
,
422 "format": eFormatVectorOfUInt8
,
428 "encoding": eEncodingVector
,
429 "format": eFormatVectorOfUInt8
,
435 "encoding": eEncodingUint
,
436 "format": eFormatHex
,
442 "encoding": eEncodingUint
,
443 "format": eFormatHex
,
449 "encoding": eEncodingUint
,
450 "format": eFormatHex
,
456 "encoding": eEncodingUint
,
457 "format": eFormatHex
,
463 "encoding": eEncodingUint
,
464 "format": eFormatHex
,
470 "encoding": eEncodingUint
,
471 "format": eFormatHex
,
477 "encoding": eEncodingUint
,
478 "format": eFormatHex
,
484 "encoding": eEncodingUint
,
485 "format": eFormatHex
,
491 "encoding": eEncodingVector
,
492 "format": eFormatVectorOfUInt8
,
498 "encoding": eEncodingVector
,
499 "format": eFormatVectorOfUInt8
,
505 "encoding": eEncodingVector
,
506 "format": eFormatVectorOfUInt8
,
512 "encoding": eEncodingVector
,
513 "format": eFormatVectorOfUInt8
,
519 "encoding": eEncodingVector
,
520 "format": eFormatVectorOfUInt8
,
526 "encoding": eEncodingVector
,
527 "format": eFormatVectorOfUInt8
,
533 "encoding": eEncodingVector
,
534 "format": eFormatVectorOfUInt8
,
540 "encoding": eEncodingVector
,
541 "format": eFormatVectorOfUInt8
,
547 "encoding": eEncodingVector
,
548 "format": eFormatVectorOfUInt8
,
554 "encoding": eEncodingVector
,
555 "format": eFormatVectorOfUInt8
,
561 "encoding": eEncodingVector
,
562 "format": eFormatVectorOfUInt8
,
568 "encoding": eEncodingVector
,
569 "format": eFormatVectorOfUInt8
,
575 "encoding": eEncodingVector
,
576 "format": eFormatVectorOfUInt8
,
582 "encoding": eEncodingVector
,
583 "format": eFormatVectorOfUInt8
,
589 "encoding": eEncodingVector
,
590 "format": eFormatVectorOfUInt8
,
596 "encoding": eEncodingVector
,
597 "format": eFormatVectorOfUInt8
,
603 "encoding": eEncodingUint
,
604 "format": eFormatHex
,
610 "encoding": eEncodingUint
,
611 "format": eFormatHex
,
613 # Registers that are contained in or composed of one of more other
619 "encoding": eEncodingUint
,
620 "format": eFormatHex
,
621 "slice": "rax[31:0]",
627 "encoding": eEncodingUint
,
628 "format": eFormatHex
,
629 "slice": "rbx[31:0]",
635 "encoding": eEncodingUint
,
636 "format": eFormatHex
,
637 "slice": "rcx[31:0]",
643 "encoding": eEncodingUint
,
644 "format": eFormatHex
,
645 "slice": "rdx[31:0]",
651 "encoding": eEncodingUint
,
652 "format": eFormatHex
,
653 "slice": "rdi[31:0]",
659 "encoding": eEncodingUint
,
660 "format": eFormatHex
,
661 "slice": "rsi[31:0]",
667 "encoding": eEncodingUint
,
668 "format": eFormatHex
,
669 "slice": "rbp[31:0]",
675 "encoding": eEncodingUint
,
676 "format": eFormatHex
,
677 "slice": "rsp[31:0]",
683 "encoding": eEncodingUint
,
684 "format": eFormatHex
,
691 "encoding": eEncodingUint
,
692 "format": eFormatHex
,
699 "encoding": eEncodingUint
,
700 "format": eFormatHex
,
701 "slice": "r10[31:0]",
707 "encoding": eEncodingUint
,
708 "format": eFormatHex
,
709 "slice": "r11[31:0]",
715 "encoding": eEncodingUint
,
716 "format": eFormatHex
,
717 "slice": "r12[31:0]",
723 "encoding": eEncodingUint
,
724 "format": eFormatHex
,
725 "slice": "r13[31:0]",
731 "encoding": eEncodingUint
,
732 "format": eFormatHex
,
733 "slice": "r14[31:0]",
739 "encoding": eEncodingUint
,
740 "format": eFormatHex
,
741 "slice": "r15[31:0]",
747 "encoding": eEncodingUint
,
748 "format": eFormatHex
,
749 "slice": "rax[15:0]",
755 "encoding": eEncodingUint
,
756 "format": eFormatHex
,
757 "slice": "rbx[15:0]",
763 "encoding": eEncodingUint
,
764 "format": eFormatHex
,
765 "slice": "rcx[15:0]",
771 "encoding": eEncodingUint
,
772 "format": eFormatHex
,
773 "slice": "rdx[15:0]",
779 "encoding": eEncodingUint
,
780 "format": eFormatHex
,
781 "slice": "rdi[15:0]",
787 "encoding": eEncodingUint
,
788 "format": eFormatHex
,
789 "slice": "rsi[15:0]",
795 "encoding": eEncodingUint
,
796 "format": eFormatHex
,
797 "slice": "rbp[15:0]",
803 "encoding": eEncodingUint
,
804 "format": eFormatHex
,
805 "slice": "rsp[15:0]",
811 "encoding": eEncodingUint
,
812 "format": eFormatHex
,
819 "encoding": eEncodingUint
,
820 "format": eFormatHex
,
827 "encoding": eEncodingUint
,
828 "format": eFormatHex
,
829 "slice": "r10[15:0]",
835 "encoding": eEncodingUint
,
836 "format": eFormatHex
,
837 "slice": "r11[15:0]",
843 "encoding": eEncodingUint
,
844 "format": eFormatHex
,
845 "slice": "r12[15:0]",
851 "encoding": eEncodingUint
,
852 "format": eFormatHex
,
853 "slice": "r13[15:0]",
859 "encoding": eEncodingUint
,
860 "format": eFormatHex
,
861 "slice": "r14[15:0]",
867 "encoding": eEncodingUint
,
868 "format": eFormatHex
,
869 "slice": "r15[15:0]",
875 "encoding": eEncodingUint
,
876 "format": eFormatHex
,
877 "slice": "rax[15:8]",
883 "encoding": eEncodingUint
,
884 "format": eFormatHex
,
885 "slice": "rbx[15:8]",
891 "encoding": eEncodingUint
,
892 "format": eFormatHex
,
893 "slice": "rcx[15:8]",
899 "encoding": eEncodingUint
,
900 "format": eFormatHex
,
901 "slice": "rdx[15:8]",
907 "encoding": eEncodingUint
,
908 "format": eFormatHex
,
915 "encoding": eEncodingUint
,
916 "format": eFormatHex
,
923 "encoding": eEncodingUint
,
924 "format": eFormatHex
,
931 "encoding": eEncodingUint
,
932 "format": eFormatHex
,
939 "encoding": eEncodingUint
,
940 "format": eFormatHex
,
947 "encoding": eEncodingUint
,
948 "format": eFormatHex
,
955 "encoding": eEncodingUint
,
956 "format": eFormatHex
,
963 "encoding": eEncodingUint
,
964 "format": eFormatHex
,
971 "encoding": eEncodingUint
,
972 "format": eFormatHex
,
979 "encoding": eEncodingUint
,
980 "format": eFormatHex
,
987 "encoding": eEncodingUint
,
988 "format": eFormatHex
,
995 "encoding": eEncodingUint
,
996 "format": eFormatHex
,
1003 "encoding": eEncodingUint
,
1004 "format": eFormatHex
,
1005 "slice": "r12[7:0]",
1011 "encoding": eEncodingUint
,
1012 "format": eFormatHex
,
1013 "slice": "r13[7:0]",
1019 "encoding": eEncodingUint
,
1020 "format": eFormatHex
,
1021 "slice": "r14[7:0]",
1027 "encoding": eEncodingUint
,
1028 "format": eFormatHex
,
1029 "slice": "r15[7:0]",
1033 g_target_definition
= None
1036 def get_target_definition():
1037 global g_target_definition
1038 if g_target_definition
is None:
1039 g_target_definition
= {}
1041 for reg_info
in x86_64_register_infos
:
1042 reg_name
= reg_info
["name"]
1044 # Only fill in the offset if there is no 'slice' in the register
1046 if "slice" not in reg_info
and "composite" not in reg_info
:
1047 reg_info
["offset"] = offset
1048 offset
+= reg_info
["bitsize"] // 8
1050 # Set the GCC/DWARF register number for this register if it has one
1051 reg_num
= get_reg_num(name_to_gcc_dwarf_regnum
, reg_name
)
1052 if reg_num
!= LLDB_INVALID_REGNUM
:
1053 reg_info
["gcc"] = reg_num
1054 reg_info
["dwarf"] = reg_num
1056 # Set the generic register number for this register if it has one
1057 reg_num
= get_reg_num(name_to_generic_regnum
, reg_name
)
1058 if reg_num
!= LLDB_INVALID_REGNUM
:
1059 reg_info
["generic"] = reg_num
1061 # Set the GDB register number for this register if it has one
1062 reg_num
= get_reg_num(name_to_gdb_regnum
, reg_name
)
1063 if reg_num
!= LLDB_INVALID_REGNUM
:
1064 reg_info
["gdb"] = reg_num
1066 g_target_definition
["sets"] = [
1067 "General Purpose Registers",
1068 "Floating Point Registers",
1070 g_target_definition
["registers"] = x86_64_register_infos
1071 g_target_definition
["host-info"] = {
1072 "triple": "x86_64-*-linux",
1073 "endian": eByteOrderLittle
,
1075 g_target_definition
["g-packet-size"] = offset
1076 g_target_definition
["breakpoint-pc-offset"] = -1
1077 return g_target_definition
1080 def get_dynamic_setting(target
, setting_name
):
1081 if setting_name
== "gdb-server-target-definition":
1082 return get_target_definition()