2 # ===-- x86_64_qemu_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 remote stub
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 user mode qemu on linux.
28 # The only difference with the Linux file is the absense of orig_rax register.
32 # (lldb) settings set plugin.process.gdb-remote.target-definition-file /path/to/x86_64_qemu_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
,
606 # Registers that are contained in or composed of one of more other
612 "encoding": eEncodingUint
,
613 "format": eFormatHex
,
614 "slice": "rax[31:0]",
620 "encoding": eEncodingUint
,
621 "format": eFormatHex
,
622 "slice": "rbx[31:0]",
628 "encoding": eEncodingUint
,
629 "format": eFormatHex
,
630 "slice": "rcx[31:0]",
636 "encoding": eEncodingUint
,
637 "format": eFormatHex
,
638 "slice": "rdx[31:0]",
644 "encoding": eEncodingUint
,
645 "format": eFormatHex
,
646 "slice": "rdi[31:0]",
652 "encoding": eEncodingUint
,
653 "format": eFormatHex
,
654 "slice": "rsi[31:0]",
660 "encoding": eEncodingUint
,
661 "format": eFormatHex
,
662 "slice": "rbp[31:0]",
668 "encoding": eEncodingUint
,
669 "format": eFormatHex
,
670 "slice": "rsp[31:0]",
676 "encoding": eEncodingUint
,
677 "format": eFormatHex
,
684 "encoding": eEncodingUint
,
685 "format": eFormatHex
,
692 "encoding": eEncodingUint
,
693 "format": eFormatHex
,
694 "slice": "r10[31:0]",
700 "encoding": eEncodingUint
,
701 "format": eFormatHex
,
702 "slice": "r11[31:0]",
708 "encoding": eEncodingUint
,
709 "format": eFormatHex
,
710 "slice": "r12[31:0]",
716 "encoding": eEncodingUint
,
717 "format": eFormatHex
,
718 "slice": "r13[31:0]",
724 "encoding": eEncodingUint
,
725 "format": eFormatHex
,
726 "slice": "r14[31:0]",
732 "encoding": eEncodingUint
,
733 "format": eFormatHex
,
734 "slice": "r15[31:0]",
740 "encoding": eEncodingUint
,
741 "format": eFormatHex
,
742 "slice": "rax[15:0]",
748 "encoding": eEncodingUint
,
749 "format": eFormatHex
,
750 "slice": "rbx[15:0]",
756 "encoding": eEncodingUint
,
757 "format": eFormatHex
,
758 "slice": "rcx[15:0]",
764 "encoding": eEncodingUint
,
765 "format": eFormatHex
,
766 "slice": "rdx[15:0]",
772 "encoding": eEncodingUint
,
773 "format": eFormatHex
,
774 "slice": "rdi[15:0]",
780 "encoding": eEncodingUint
,
781 "format": eFormatHex
,
782 "slice": "rsi[15:0]",
788 "encoding": eEncodingUint
,
789 "format": eFormatHex
,
790 "slice": "rbp[15:0]",
796 "encoding": eEncodingUint
,
797 "format": eFormatHex
,
798 "slice": "rsp[15:0]",
804 "encoding": eEncodingUint
,
805 "format": eFormatHex
,
812 "encoding": eEncodingUint
,
813 "format": eFormatHex
,
820 "encoding": eEncodingUint
,
821 "format": eFormatHex
,
822 "slice": "r10[15:0]",
828 "encoding": eEncodingUint
,
829 "format": eFormatHex
,
830 "slice": "r11[15:0]",
836 "encoding": eEncodingUint
,
837 "format": eFormatHex
,
838 "slice": "r12[15:0]",
844 "encoding": eEncodingUint
,
845 "format": eFormatHex
,
846 "slice": "r13[15:0]",
852 "encoding": eEncodingUint
,
853 "format": eFormatHex
,
854 "slice": "r14[15:0]",
860 "encoding": eEncodingUint
,
861 "format": eFormatHex
,
862 "slice": "r15[15:0]",
868 "encoding": eEncodingUint
,
869 "format": eFormatHex
,
870 "slice": "rax[15:8]",
876 "encoding": eEncodingUint
,
877 "format": eFormatHex
,
878 "slice": "rbx[15:8]",
884 "encoding": eEncodingUint
,
885 "format": eFormatHex
,
886 "slice": "rcx[15:8]",
892 "encoding": eEncodingUint
,
893 "format": eFormatHex
,
894 "slice": "rdx[15:8]",
900 "encoding": eEncodingUint
,
901 "format": eFormatHex
,
908 "encoding": eEncodingUint
,
909 "format": eFormatHex
,
916 "encoding": eEncodingUint
,
917 "format": eFormatHex
,
924 "encoding": eEncodingUint
,
925 "format": eFormatHex
,
932 "encoding": eEncodingUint
,
933 "format": eFormatHex
,
940 "encoding": eEncodingUint
,
941 "format": eFormatHex
,
948 "encoding": eEncodingUint
,
949 "format": eFormatHex
,
956 "encoding": eEncodingUint
,
957 "format": eFormatHex
,
964 "encoding": eEncodingUint
,
965 "format": eFormatHex
,
972 "encoding": eEncodingUint
,
973 "format": eFormatHex
,
980 "encoding": eEncodingUint
,
981 "format": eFormatHex
,
988 "encoding": eEncodingUint
,
989 "format": eFormatHex
,
996 "encoding": eEncodingUint
,
997 "format": eFormatHex
,
1004 "encoding": eEncodingUint
,
1005 "format": eFormatHex
,
1006 "slice": "r13[7:0]",
1012 "encoding": eEncodingUint
,
1013 "format": eFormatHex
,
1014 "slice": "r14[7:0]",
1020 "encoding": eEncodingUint
,
1021 "format": eFormatHex
,
1022 "slice": "r15[7:0]",
1026 g_target_definition
= None
1029 def get_target_definition():
1030 global g_target_definition
1031 if g_target_definition
is None:
1032 g_target_definition
= {}
1034 for reg_info
in x86_64_register_infos
:
1035 reg_name
= reg_info
["name"]
1037 # Only fill in the offset if there is no 'slice' in the register
1039 if "slice" not in reg_info
and "composite" not in reg_info
:
1040 reg_info
["offset"] = offset
1041 offset
+= reg_info
["bitsize"] // 8
1043 # Set the GCC/DWARF register number for this register if it has one
1044 reg_num
= get_reg_num(name_to_gcc_dwarf_regnum
, reg_name
)
1045 if reg_num
!= LLDB_INVALID_REGNUM
:
1046 reg_info
["gcc"] = reg_num
1047 reg_info
["dwarf"] = reg_num
1049 # Set the generic register number for this register if it has one
1050 reg_num
= get_reg_num(name_to_generic_regnum
, reg_name
)
1051 if reg_num
!= LLDB_INVALID_REGNUM
:
1052 reg_info
["generic"] = reg_num
1054 # Set the GDB register number for this register if it has one
1055 reg_num
= get_reg_num(name_to_gdb_regnum
, reg_name
)
1056 if reg_num
!= LLDB_INVALID_REGNUM
:
1057 reg_info
["gdb"] = reg_num
1059 g_target_definition
["sets"] = [
1060 "General Purpose Registers",
1061 "Floating Point Registers",
1063 g_target_definition
["registers"] = x86_64_register_infos
1064 g_target_definition
["host-info"] = {
1065 "triple": "x86_64-*-linux",
1066 "endian": eByteOrderLittle
,
1068 g_target_definition
["g-packet-size"] = offset
1069 g_target_definition
["breakpoint-pc-offset"] = -1
1070 return g_target_definition
1073 def get_dynamic_setting(target
, setting_name
):
1074 if setting_name
== "gdb-server-target-definition":
1075 return get_target_definition()