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
202 x86_64_register_infos
= [
206 'encoding': eEncodingUint
,
207 'format': eFormatAddressInfo
},
211 'encoding': eEncodingUint
,
212 'format': eFormatAddressInfo
},
213 {'name': 'rcx', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
214 'format': eFormatAddressInfo
, 'alt-name': 'arg4'},
215 {'name': 'rdx', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
216 'format': eFormatAddressInfo
, 'alt-name': 'arg3'},
217 {'name': 'rsi', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
218 'format': eFormatAddressInfo
, 'alt-name': 'arg2'},
219 {'name': 'rdi', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
220 'format': eFormatAddressInfo
, 'alt-name': 'arg1'},
221 {'name': 'rbp', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
222 'format': eFormatAddressInfo
, 'alt-name': 'fp'},
223 {'name': 'rsp', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
224 'format': eFormatAddressInfo
, 'alt-name': 'sp'},
225 {'name': 'r8', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
226 'format': eFormatAddressInfo
, 'alt-name': 'arg5'},
227 {'name': 'r9', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
228 'format': eFormatAddressInfo
, 'alt-name': 'arg6'},
232 'encoding': eEncodingUint
,
233 'format': eFormatAddressInfo
},
237 'encoding': eEncodingUint
,
238 'format': eFormatAddressInfo
},
242 'encoding': eEncodingUint
,
243 'format': eFormatAddressInfo
},
247 'encoding': eEncodingUint
,
248 'format': eFormatAddressInfo
},
252 'encoding': eEncodingUint
,
253 'format': eFormatAddressInfo
},
257 'encoding': eEncodingUint
,
258 'format': eFormatAddressInfo
},
259 {'name': 'rip', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint
,
260 'format': eFormatAddressInfo
, 'alt-name': 'pc'},
261 {'name': 'rflags', 'set': 0, 'bitsize': 32,
262 'encoding': eEncodingUint
, 'format': eFormatHex
},
263 {'name': 'cs', 'set': 0, 'bitsize': 32,
264 'encoding': eEncodingUint
, 'format': eFormatHex
},
265 {'name': 'ss', 'set': 0, 'bitsize': 32,
266 'encoding': eEncodingUint
, 'format': eFormatHex
},
267 {'name': 'ds', 'set': 0, 'bitsize': 32,
268 'encoding': eEncodingUint
, 'format': eFormatHex
},
269 {'name': 'es', 'set': 0, 'bitsize': 32,
270 'encoding': eEncodingUint
, 'format': eFormatHex
},
271 {'name': 'fs', 'set': 0, 'bitsize': 32,
272 'encoding': eEncodingUint
, 'format': eFormatHex
},
273 {'name': 'gs', 'set': 0, 'bitsize': 32,
274 'encoding': eEncodingUint
, 'format': eFormatHex
},
278 'encoding': eEncodingVector
,
279 'format': eFormatVectorOfUInt8
},
283 'encoding': eEncodingVector
,
284 'format': eFormatVectorOfUInt8
},
288 'encoding': eEncodingVector
,
289 'format': eFormatVectorOfUInt8
},
293 'encoding': eEncodingVector
,
294 'format': eFormatVectorOfUInt8
},
298 'encoding': eEncodingVector
,
299 'format': eFormatVectorOfUInt8
},
303 'encoding': eEncodingVector
,
304 'format': eFormatVectorOfUInt8
},
308 'encoding': eEncodingVector
,
309 'format': eFormatVectorOfUInt8
},
313 'encoding': eEncodingVector
,
314 'format': eFormatVectorOfUInt8
},
315 {'name': 'fctrl', 'set': 1, 'bitsize': 32,
316 'encoding': eEncodingUint
, 'format': eFormatHex
},
317 {'name': 'fstat', 'set': 1, 'bitsize': 32,
318 'encoding': eEncodingUint
, 'format': eFormatHex
},
319 {'name': 'ftag', 'set': 1, 'bitsize': 32,
320 'encoding': eEncodingUint
, 'format': eFormatHex
},
321 {'name': 'fiseg', 'set': 1, 'bitsize': 32,
322 'encoding': eEncodingUint
, 'format': eFormatHex
},
323 {'name': 'fioff', 'set': 1, 'bitsize': 32,
324 'encoding': eEncodingUint
, 'format': eFormatHex
},
325 {'name': 'foseg', 'set': 1, 'bitsize': 32,
326 'encoding': eEncodingUint
, 'format': eFormatHex
},
327 {'name': 'fooff', 'set': 1, 'bitsize': 32,
328 'encoding': eEncodingUint
, 'format': eFormatHex
},
329 {'name': 'fop', 'set': 1, 'bitsize': 32,
330 'encoding': eEncodingUint
, 'format': eFormatHex
},
334 'encoding': eEncodingVector
,
335 'format': eFormatVectorOfUInt8
},
339 'encoding': eEncodingVector
,
340 'format': eFormatVectorOfUInt8
},
344 'encoding': eEncodingVector
,
345 'format': eFormatVectorOfUInt8
},
349 'encoding': eEncodingVector
,
350 'format': eFormatVectorOfUInt8
},
354 'encoding': eEncodingVector
,
355 'format': eFormatVectorOfUInt8
},
359 'encoding': eEncodingVector
,
360 'format': eFormatVectorOfUInt8
},
364 'encoding': eEncodingVector
,
365 'format': eFormatVectorOfUInt8
},
369 'encoding': eEncodingVector
,
370 'format': eFormatVectorOfUInt8
},
374 'encoding': eEncodingVector
,
375 'format': eFormatVectorOfUInt8
},
379 'encoding': eEncodingVector
,
380 'format': eFormatVectorOfUInt8
},
384 'encoding': eEncodingVector
,
385 'format': eFormatVectorOfUInt8
},
389 'encoding': eEncodingVector
,
390 'format': eFormatVectorOfUInt8
},
394 'encoding': eEncodingVector
,
395 'format': eFormatVectorOfUInt8
},
399 'encoding': eEncodingVector
,
400 'format': eFormatVectorOfUInt8
},
404 'encoding': eEncodingVector
,
405 'format': eFormatVectorOfUInt8
},
409 'encoding': eEncodingVector
,
410 'format': eFormatVectorOfUInt8
},
411 {'name': 'mxcsr', 'set': 1, 'bitsize': 32,
412 'encoding': eEncodingUint
, 'format': eFormatHex
},
413 # Registers that are contained in or composed of one of more other
418 'encoding': eEncodingUint
,
419 'format': eFormatHex
,
420 'slice': 'rax[31:0]'},
424 'encoding': eEncodingUint
,
425 'format': eFormatHex
,
426 'slice': 'rbx[31:0]'},
430 'encoding': eEncodingUint
,
431 'format': eFormatHex
,
432 'slice': 'rcx[31:0]'},
436 'encoding': eEncodingUint
,
437 'format': eFormatHex
,
438 'slice': 'rdx[31:0]'},
442 'encoding': eEncodingUint
,
443 'format': eFormatHex
,
444 'slice': 'rdi[31:0]'},
448 'encoding': eEncodingUint
,
449 'format': eFormatHex
,
450 'slice': 'rsi[31:0]'},
454 'encoding': eEncodingUint
,
455 'format': eFormatHex
,
456 'slice': 'rbp[31:0]'},
460 'encoding': eEncodingUint
,
461 'format': eFormatHex
,
462 'slice': 'rsp[31:0]'},
466 'encoding': eEncodingUint
,
467 'format': eFormatHex
,
468 'slice': 'r8[31:0]'},
472 'encoding': eEncodingUint
,
473 'format': eFormatHex
,
474 'slice': 'r9[31:0]'},
478 'encoding': eEncodingUint
,
479 'format': eFormatHex
,
480 'slice': 'r10[31:0]'},
484 'encoding': eEncodingUint
,
485 'format': eFormatHex
,
486 'slice': 'r11[31:0]'},
490 'encoding': eEncodingUint
,
491 'format': eFormatHex
,
492 'slice': 'r12[31:0]'},
496 'encoding': eEncodingUint
,
497 'format': eFormatHex
,
498 'slice': 'r13[31:0]'},
502 'encoding': eEncodingUint
,
503 'format': eFormatHex
,
504 'slice': 'r14[31:0]'},
508 'encoding': eEncodingUint
,
509 'format': eFormatHex
,
510 'slice': 'r15[31:0]'},
515 'encoding': eEncodingUint
,
516 'format': eFormatHex
,
517 'slice': 'rax[15:0]'},
521 'encoding': eEncodingUint
,
522 'format': eFormatHex
,
523 'slice': 'rbx[15:0]'},
527 'encoding': eEncodingUint
,
528 'format': eFormatHex
,
529 'slice': 'rcx[15:0]'},
533 'encoding': eEncodingUint
,
534 'format': eFormatHex
,
535 'slice': 'rdx[15:0]'},
539 'encoding': eEncodingUint
,
540 'format': eFormatHex
,
541 'slice': 'rdi[15:0]'},
545 'encoding': eEncodingUint
,
546 'format': eFormatHex
,
547 'slice': 'rsi[15:0]'},
551 'encoding': eEncodingUint
,
552 'format': eFormatHex
,
553 'slice': 'rbp[15:0]'},
557 'encoding': eEncodingUint
,
558 'format': eFormatHex
,
559 'slice': 'rsp[15:0]'},
563 'encoding': eEncodingUint
,
564 'format': eFormatHex
,
565 'slice': 'r8[15:0]'},
569 'encoding': eEncodingUint
,
570 'format': eFormatHex
,
571 'slice': 'r9[15:0]'},
575 'encoding': eEncodingUint
,
576 'format': eFormatHex
,
577 'slice': 'r10[15:0]'},
581 'encoding': eEncodingUint
,
582 'format': eFormatHex
,
583 'slice': 'r11[15:0]'},
587 'encoding': eEncodingUint
,
588 'format': eFormatHex
,
589 'slice': 'r12[15:0]'},
593 'encoding': eEncodingUint
,
594 'format': eFormatHex
,
595 'slice': 'r13[15:0]'},
599 'encoding': eEncodingUint
,
600 'format': eFormatHex
,
601 'slice': 'r14[15:0]'},
605 'encoding': eEncodingUint
,
606 'format': eFormatHex
,
607 'slice': 'r15[15:0]'},
612 'encoding': eEncodingUint
,
613 'format': eFormatHex
,
614 'slice': 'rax[15:8]'},
618 'encoding': eEncodingUint
,
619 'format': eFormatHex
,
620 'slice': 'rbx[15:8]'},
624 'encoding': eEncodingUint
,
625 'format': eFormatHex
,
626 'slice': 'rcx[15:8]'},
630 'encoding': eEncodingUint
,
631 'format': eFormatHex
,
632 'slice': 'rdx[15:8]'},
637 'encoding': eEncodingUint
,
638 'format': eFormatHex
,
639 'slice': 'rax[7:0]'},
643 'encoding': eEncodingUint
,
644 'format': eFormatHex
,
645 'slice': 'rbx[7:0]'},
649 'encoding': eEncodingUint
,
650 'format': eFormatHex
,
651 'slice': 'rcx[7:0]'},
655 'encoding': eEncodingUint
,
656 'format': eFormatHex
,
657 'slice': 'rdx[7:0]'},
661 'encoding': eEncodingUint
,
662 'format': eFormatHex
,
663 'slice': 'rdi[7:0]'},
667 'encoding': eEncodingUint
,
668 'format': eFormatHex
,
669 'slice': 'rsi[7:0]'},
673 'encoding': eEncodingUint
,
674 'format': eFormatHex
,
675 'slice': 'rbp[7:0]'},
679 'encoding': eEncodingUint
,
680 'format': eFormatHex
,
681 'slice': 'rsp[7:0]'},
685 'encoding': eEncodingUint
,
686 'format': eFormatHex
,
691 'encoding': eEncodingUint
,
692 'format': eFormatHex
,
697 'encoding': eEncodingUint
,
698 'format': eFormatHex
,
699 'slice': 'r10[7:0]'},
703 'encoding': eEncodingUint
,
704 'format': eFormatHex
,
705 'slice': 'r11[7:0]'},
709 'encoding': eEncodingUint
,
710 'format': eFormatHex
,
711 'slice': 'r12[7:0]'},
715 'encoding': eEncodingUint
,
716 'format': eFormatHex
,
717 'slice': 'r13[7:0]'},
721 'encoding': eEncodingUint
,
722 'format': eFormatHex
,
723 'slice': 'r14[7:0]'},
727 'encoding': eEncodingUint
,
728 'format': eFormatHex
,
729 'slice': 'r15[7:0]'},
732 g_target_definition
= None
735 def get_target_definition():
736 global g_target_definition
737 if g_target_definition
is None:
738 g_target_definition
= {}
740 for reg_info
in x86_64_register_infos
:
741 reg_name
= reg_info
['name']
743 # Only fill in the offset if there is no 'slice' in the register
745 if 'slice' not in reg_info
and 'composite' not in reg_info
:
746 reg_info
['offset'] = offset
747 offset
+= reg_info
['bitsize'] // 8
749 # Set the GCC/DWARF register number for this register if it has one
750 reg_num
= get_reg_num(name_to_gcc_dwarf_regnum
, reg_name
)
751 if reg_num
!= LLDB_INVALID_REGNUM
:
752 reg_info
['gcc'] = reg_num
753 reg_info
['dwarf'] = reg_num
755 # Set the generic register number for this register if it has one
756 reg_num
= get_reg_num(name_to_generic_regnum
, reg_name
)
757 if reg_num
!= LLDB_INVALID_REGNUM
:
758 reg_info
['generic'] = reg_num
760 # Set the GDB register number for this register if it has one
761 reg_num
= get_reg_num(name_to_gdb_regnum
, reg_name
)
762 if reg_num
!= LLDB_INVALID_REGNUM
:
763 reg_info
['gdb'] = reg_num
765 g_target_definition
['sets'] = [
766 'General Purpose Registers',
767 'Floating Point Registers']
768 g_target_definition
['registers'] = x86_64_register_infos
770 'host-info'] = {'triple': 'x86_64-apple-macosx', 'endian': eByteOrderLittle
}
771 g_target_definition
['g-packet-size'] = offset
772 return g_target_definition
775 def get_dynamic_setting(target
, setting_name
):
776 if setting_name
== 'gdb-server-target-definition':
777 return get_target_definition()