GDB (xrefs)
Loading...
Searching...
No Matches
disassemble.py
Go to the documentation of this file.
1# Copyright 2022-2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import gdb
17
18from .server import request, capability
19from .startup import in_gdb_thread
20
21
22@in_gdb_thread
23def _disassemble(pc, skip_insns, count):
24 inf = gdb.selected_inferior()
25 try:
26 arch = gdb.selected_frame().architecture()
27 except gdb.error:
28 # Maybe there was no frame.
29 arch = inf.architecture()
30 result = []
31 total_count = skip_insns + count
32 for elt in arch.disassemble(pc, count=total_count)[skip_insns:]:
33 mem = inf.read_memory(elt["addr"], elt["length"])
34 result.append(
35 {
36 "address": hex(elt["addr"]),
37 "instruction": elt["asm"],
38 "instructionBytes": mem.hex(),
39 }
40 )
41 return {
42 "instructions": result,
43 }
44
45
46@request("disassemble")
47@capability("supportsDisassembleRequest")
48def disassemble(
49 *,
50 memoryReference: str,
51 offset: int = 0,
52 instructionOffset: int = 0,
53 instructionCount: int,
54 **extra
55):
56 pc = int(memoryReference, 0) + offset
57 return _disassemble(pc, instructionOffset, instructionCount)
_disassemble(pc, skip_insns, count)