2 #===-- x86_64_qemu_target_definition.py -----------------------------*- C++ -*-===//
4 # The LLVM Compiler Infrastructure
6 # This file is distributed under the University of Illinois Open Source
7 # License. See LICENSE.TXT for details.
9 #===----------------------------------------------------------------------===//
11 #----------------------------------------------------------------------
14 # This file can be used with the following setting:
15 # plugin.process.gdb-remote.target-definition-file
16 # This setting should be used when you are trying to connect to a
17 # remote GDB server that doesn't support any of the register discovery
18 # packets that LLDB normally uses.
20 # Why is this necessary? LLDB doesn't require a new build of LLDB that
21 # targets each new architecture you will debug with. Instead, all
22 # architectures are supported and LLDB relies on extra GDB server
23 # packets to discover the target we are connecting to so that is can
24 # show the right registers for each target. This allows the remote stub
25 # to change and add new registers without requiring a new LLDB build
26 # just so we can see new registers.
28 # This file implements the x86_64 registers for the user mode qemu on linux.
29 # The only difference with the Linux file is the absense of orig_rax register.
33 # (lldb) settings set plugin.process.gdb-remote.target-definition-file /path/to/x86_64_qemu_target_definition.py
34 # (lldb) gdb-remote other.baz.com:1234
36 # The target definition file will get used if and only if the
37 # qRegisterInfo packets are not supported when connecting to a remote
39 #----------------------------------------------------------------------
42 # Compiler and DWARF register numbers
43 name_to_gcc_dwarf_regnum = {
103 name_to_gdb_regnum = {
179 name_to_generic_regnum = {
180 'rip': LLDB_REGNUM_GENERIC_PC,
181 'rsp': LLDB_REGNUM_GENERIC_SP,
182 'rbp': LLDB_REGNUM_GENERIC_FP,
183 'rdi': LLDB_REGNUM_GENERIC_ARG1,
184 'rsi': LLDB_REGNUM_GENERIC_ARG2,
185 'rdx': LLDB_REGNUM_GENERIC_ARG3,
186 'rcx': LLDB_REGNUM_GENERIC_ARG4,
187 'r8': LLDB_REGNUM_GENERIC_ARG5,
188 'r9': LLDB_REGNUM_GENERIC_ARG6
192 def get_reg_num(reg_num_dict, reg_name):
193 if reg_name in reg_num_dict:
194 return reg_num_dict[reg_name]
195 return LLDB_INVALID_REGNUM
197 x86_64_register_infos = [
201 'encoding': eEncodingUint,
202 'format': eFormatAddressInfo},
206 'encoding': eEncodingUint,
207 'format': eFormatAddressInfo},
208 {'name': 'rcx', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
209 'format': eFormatAddressInfo, 'alt-name': 'arg4'},
210 {'name': 'rdx', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
211 'format': eFormatAddressInfo, 'alt-name': 'arg3'},
212 {'name': 'rsi', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
213 'format': eFormatAddressInfo, 'alt-name': 'arg2'},
214 {'name': 'rdi', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
215 'format': eFormatAddressInfo, 'alt-name': 'arg1'},
216 {'name': 'rbp', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
217 'format': eFormatAddressInfo, 'alt-name': 'fp'},
218 {'name': 'rsp', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
219 'format': eFormatAddressInfo, 'alt-name': 'sp'},
220 {'name': 'r8', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
221 'format': eFormatAddressInfo, 'alt-name': 'arg5'},
222 {'name': 'r9', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
223 'format': eFormatAddressInfo, 'alt-name': 'arg6'},
227 'encoding': eEncodingUint,
228 'format': eFormatAddressInfo},
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},
254 {'name': 'rip', 'set': 0, 'bitsize': 64, 'encoding': eEncodingUint,
255 'format': eFormatAddressInfo, 'alt-name': 'pc'},
256 {'name': 'rflags', 'set': 0, 'bitsize': 32,
257 'encoding': eEncodingUint, 'format': eFormatHex},
258 {'name': 'cs', 'set': 0, 'bitsize': 32,
259 'encoding': eEncodingUint, 'format': eFormatHex},
260 {'name': 'ss', 'set': 0, 'bitsize': 32,
261 'encoding': eEncodingUint, 'format': eFormatHex},
262 {'name': 'ds', 'set': 0, 'bitsize': 32,
263 'encoding': eEncodingUint, 'format': eFormatHex},
264 {'name': 'es', 'set': 0, 'bitsize': 32,
265 'encoding': eEncodingUint, 'format': eFormatHex},
266 {'name': 'fs', 'set': 0, 'bitsize': 32,
267 'encoding': eEncodingUint, 'format': eFormatHex},
268 {'name': 'gs', 'set': 0, 'bitsize': 32,
269 'encoding': eEncodingUint, 'format': eFormatHex},
273 'encoding': eEncodingVector,
274 'format': eFormatVectorOfUInt8},
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},
310 {'name': 'fctrl', 'set': 1, 'bitsize': 32,
311 'encoding': eEncodingUint, 'format': eFormatHex},
312 {'name': 'fstat', 'set': 1, 'bitsize': 32,
313 'encoding': eEncodingUint, 'format': eFormatHex},
314 {'name': 'ftag', 'set': 1, 'bitsize': 32,
315 'encoding': eEncodingUint, 'format': eFormatHex},
316 {'name': 'fiseg', 'set': 1, 'bitsize': 32,
317 'encoding': eEncodingUint, 'format': eFormatHex},
318 {'name': 'fioff', 'set': 1, 'bitsize': 32,
319 'encoding': eEncodingUint, 'format': eFormatHex},
320 {'name': 'foseg', 'set': 1, 'bitsize': 32,
321 'encoding': eEncodingUint, 'format': eFormatHex},
322 {'name': 'fooff', 'set': 1, 'bitsize': 32,
323 'encoding': eEncodingUint, 'format': eFormatHex},
324 {'name': 'fop', 'set': 1, 'bitsize': 32,
325 'encoding': eEncodingUint, 'format': eFormatHex},
329 'encoding': eEncodingVector,
330 'format': eFormatVectorOfUInt8},
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},
406 {'name': 'mxcsr', 'set': 1, 'bitsize': 32,
407 'encoding': eEncodingUint, 'format': eFormatHex},
408 # Registers that are contained in or composed of one of more other
413 'encoding': eEncodingUint,
414 'format': eFormatHex,
415 'slice': 'rax[31:0]'},
419 'encoding': eEncodingUint,
420 'format': eFormatHex,
421 'slice': 'rbx[31:0]'},
425 'encoding': eEncodingUint,
426 'format': eFormatHex,
427 'slice': 'rcx[31:0]'},
431 'encoding': eEncodingUint,
432 'format': eFormatHex,
433 'slice': 'rdx[31:0]'},
437 'encoding': eEncodingUint,
438 'format': eFormatHex,
439 'slice': 'rdi[31:0]'},
443 'encoding': eEncodingUint,
444 'format': eFormatHex,
445 'slice': 'rsi[31:0]'},
449 'encoding': eEncodingUint,
450 'format': eFormatHex,
451 'slice': 'rbp[31:0]'},
455 'encoding': eEncodingUint,
456 'format': eFormatHex,
457 'slice': 'rsp[31:0]'},
461 'encoding': eEncodingUint,
462 'format': eFormatHex,
463 'slice': 'r8[31:0]'},
467 'encoding': eEncodingUint,
468 'format': eFormatHex,
469 'slice': 'r9[31:0]'},
473 'encoding': eEncodingUint,
474 'format': eFormatHex,
475 'slice': 'r10[31:0]'},
479 'encoding': eEncodingUint,
480 'format': eFormatHex,
481 'slice': 'r11[31:0]'},
485 'encoding': eEncodingUint,
486 'format': eFormatHex,
487 'slice': 'r12[31:0]'},
491 'encoding': eEncodingUint,
492 'format': eFormatHex,
493 'slice': 'r13[31:0]'},
497 'encoding': eEncodingUint,
498 'format': eFormatHex,
499 'slice': 'r14[31:0]'},
503 'encoding': eEncodingUint,
504 'format': eFormatHex,
505 'slice': 'r15[31:0]'},
510 'encoding': eEncodingUint,
511 'format': eFormatHex,
512 'slice': 'rax[15:0]'},
516 'encoding': eEncodingUint,
517 'format': eFormatHex,
518 'slice': 'rbx[15:0]'},
522 'encoding': eEncodingUint,
523 'format': eFormatHex,
524 'slice': 'rcx[15:0]'},
528 'encoding': eEncodingUint,
529 'format': eFormatHex,
530 'slice': 'rdx[15:0]'},
534 'encoding': eEncodingUint,
535 'format': eFormatHex,
536 'slice': 'rdi[15:0]'},
540 'encoding': eEncodingUint,
541 'format': eFormatHex,
542 'slice': 'rsi[15:0]'},
546 'encoding': eEncodingUint,
547 'format': eFormatHex,
548 'slice': 'rbp[15:0]'},
552 'encoding': eEncodingUint,
553 'format': eFormatHex,
554 'slice': 'rsp[15:0]'},
558 'encoding': eEncodingUint,
559 'format': eFormatHex,
560 'slice': 'r8[15:0]'},
564 'encoding': eEncodingUint,
565 'format': eFormatHex,
566 'slice': 'r9[15:0]'},
570 'encoding': eEncodingUint,
571 'format': eFormatHex,
572 'slice': 'r10[15:0]'},
576 'encoding': eEncodingUint,
577 'format': eFormatHex,
578 'slice': 'r11[15:0]'},
582 'encoding': eEncodingUint,
583 'format': eFormatHex,
584 'slice': 'r12[15:0]'},
588 'encoding': eEncodingUint,
589 'format': eFormatHex,
590 'slice': 'r13[15:0]'},
594 'encoding': eEncodingUint,
595 'format': eFormatHex,
596 'slice': 'r14[15:0]'},
600 'encoding': eEncodingUint,
601 'format': eFormatHex,
602 'slice': 'r15[15:0]'},
607 'encoding': eEncodingUint,
608 'format': eFormatHex,
609 'slice': 'rax[15:8]'},
613 'encoding': eEncodingUint,
614 'format': eFormatHex,
615 'slice': 'rbx[15:8]'},
619 'encoding': eEncodingUint,
620 'format': eFormatHex,
621 'slice': 'rcx[15:8]'},
625 'encoding': eEncodingUint,
626 'format': eFormatHex,
627 'slice': 'rdx[15:8]'},
632 'encoding': eEncodingUint,
633 'format': eFormatHex,
634 'slice': 'rax[7:0]'},
638 'encoding': eEncodingUint,
639 'format': eFormatHex,
640 'slice': 'rbx[7:0]'},
644 'encoding': eEncodingUint,
645 'format': eFormatHex,
646 'slice': 'rcx[7:0]'},
650 'encoding': eEncodingUint,
651 'format': eFormatHex,
652 'slice': 'rdx[7:0]'},
656 'encoding': eEncodingUint,
657 'format': eFormatHex,
658 'slice': 'rdi[7:0]'},
662 'encoding': eEncodingUint,
663 'format': eFormatHex,
664 'slice': 'rsi[7:0]'},
668 'encoding': eEncodingUint,
669 'format': eFormatHex,
670 'slice': 'rbp[7:0]'},
674 'encoding': eEncodingUint,
675 'format': eFormatHex,
676 'slice': 'rsp[7:0]'},
680 'encoding': eEncodingUint,
681 'format': eFormatHex,
686 'encoding': eEncodingUint,
687 'format': eFormatHex,
692 'encoding': eEncodingUint,
693 'format': eFormatHex,
694 'slice': 'r10[7:0]'},
698 'encoding': eEncodingUint,
699 'format': eFormatHex,
700 'slice': 'r11[7:0]'},
704 'encoding': eEncodingUint,
705 'format': eFormatHex,
706 'slice': 'r12[7:0]'},
710 'encoding': eEncodingUint,
711 'format': eFormatHex,
712 'slice': 'r13[7:0]'},
716 'encoding': eEncodingUint,
717 'format': eFormatHex,
718 'slice': 'r14[7:0]'},
722 'encoding': eEncodingUint,
723 'format': eFormatHex,
724 'slice': 'r15[7:0]'},
727 g_target_definition = None
730 def get_target_definition():
731 global g_target_definition
732 if g_target_definition is None:
733 g_target_definition = {}
735 for reg_info in x86_64_register_infos:
736 reg_name = reg_info['name']
738 # Only fill in the offset if there is no 'slice' in the register
740 if 'slice' not in reg_info and 'composite' not in reg_info:
741 reg_info['offset'] = offset
742 offset += reg_info['bitsize'] / 8
744 # Set the GCC/DWARF register number for this register if it has one
745 reg_num = get_reg_num(name_to_gcc_dwarf_regnum, reg_name)
746 if reg_num != LLDB_INVALID_REGNUM:
747 reg_info['gcc'] = reg_num
748 reg_info['dwarf'] = reg_num
750 # Set the generic register number for this register if it has one
751 reg_num = get_reg_num(name_to_generic_regnum, reg_name)
752 if reg_num != LLDB_INVALID_REGNUM:
753 reg_info['generic'] = reg_num
755 # Set the GDB register number for this register if it has one
756 reg_num = get_reg_num(name_to_gdb_regnum, reg_name)
757 if reg_num != LLDB_INVALID_REGNUM:
758 reg_info['gdb'] = reg_num
760 g_target_definition['sets'] = [
761 'General Purpose Registers',
762 'Floating Point Registers']
763 g_target_definition['registers'] = x86_64_register_infos
765 'host-info'] = {'triple': 'x86_64-*-linux', 'endian': eByteOrderLittle}
766 g_target_definition['g-packet-size'] = offset
767 g_target_definition['breakpoint-pc-offset'] = -1
768 return g_target_definition
771 def get_dynamic_setting(target, setting_name):
772 if setting_name == 'gdb-server-target-definition':
773 return get_target_definition()